Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

Commit 9df2723

Browse files
committed
feat: TypeScript types for Sheet, Column, Row, Cell and pagination options & responses
1 parent b993697 commit 9df2723

File tree

6 files changed

+241
-10
lines changed

6 files changed

+241
-10
lines changed

index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import {
44
ClientLoggerOptions,
55
} from "./lib/types/client";
66
export { SmartsheetClient } from "./lib/types/client";
7+
export { SheetData } from "./lib/types/sheets/get";
8+
export { Column } from "./lib/types/sheets/columns";
9+
export {
10+
RowData,
11+
CellHistoryCellData,
12+
GetCellHistoryResponse,
13+
} from "./lib/types/sheets/rows";
714
import { NPMLoggingLevel } from "winston";
815
import * as _ from "underscore";
916
import * as winston from "winston";

lib/types/date.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* The Smartsheet API returns all dates and times in the UTC time zone in ISO-8601 format, that is, YYYY-MM-DDTHH:MM:SSZ.
3+
*/
4+
export type DateString = string;

lib/types/pagination.d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Members included in a paged response.
3+
*/
4+
export interface PagedResponse {
5+
pageNumber: number;
6+
pageSize: number;
7+
totalPages: number;
8+
totalCount: number;
9+
}
10+
11+
/**
12+
* Options that can be included in requests that return a paged result.
13+
*/
14+
export type PageOptions = PageOptionsIncludeAll | PageOptionsPaged;
15+
16+
export interface PageOptionsIncludeAll {
17+
includeAll: boolean;
18+
}
19+
20+
export interface PageOptionsPaged {
21+
page?: number;
22+
pageSize?: number;
23+
}

lib/types/sheets/columns.d.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,55 @@ export interface ColumnsResource {
1212
export type GetColumnsOptions = any;
1313
export type GetColumnsResponse = any;
1414
/* eslint-enable @typescript-eslint/no-explicit-any */
15+
16+
/**
17+
* Represents a column within a sheet or report.
18+
*/
19+
export interface Column {
20+
id: number;
21+
version: number;
22+
index: number;
23+
title: string;
24+
type:
25+
| "ABSTRACT_DATETIME"
26+
| "CHECKBOX"
27+
| "CONTACT_LIST"
28+
| "DATE"
29+
| "DATETIME"
30+
| "DURATION"
31+
| "MULTI_CONTACT_LIST"
32+
| "MULTI_PICKLIST"
33+
| "PICKLIST"
34+
| "PREDECESSOR"
35+
| "TEXT_NUMBER"
36+
| string;
37+
systemColumnType?:
38+
| "AUTO_NUMBER"
39+
| "CREATED_BY"
40+
| "CREATED_DATE"
41+
| "MODIFIED_BY"
42+
| "MODIFIED_DATE"
43+
| string;
44+
primary: boolean;
45+
validation: boolean;
46+
width: number;
47+
autoNumberFormat?: AutoNumberFormat;
48+
contactOptions?: ContactOption[];
49+
format?: string;
50+
formula?: string;
51+
hidden?: boolean;
52+
locked?: boolean;
53+
lockedForUser?: boolean;
54+
options?: string[];
55+
symbol?: string;
56+
tags?: string[];
57+
}
58+
59+
export interface ContactOption {
60+
email: string;
61+
name: string;
62+
}
63+
64+
/* eslint-disable @typescript-eslint/no-explicit-any */
65+
export type AutoNumberFormat = any;
66+
/* eslint-enable @typescript-eslint/no-explicit-any */

lib/types/sheets/get.d.ts

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,113 @@
11
import { DefaultSDKFunction } from "../defaults";
2+
import { DateString } from "../date";
3+
import { Column } from "./columns";
4+
import { RowData } from "./rows";
5+
import { PageOptions } from "../pagination";
26

37
export interface SheetResource {
4-
getSheet: DefaultSDKFunction;
8+
getSheet: DefaultSDKFunction<GetSheetOptions, SheetData>;
59
listSheets: DefaultSDKFunction;
610
getSheetAsCSV: DefaultSDKFunction;
711
getSheetAsExcel: DefaultSDKFunction;
812
getSheetAsPDF: DefaultSDKFunction;
913
getSheetVersion: DefaultSDKFunction;
1014
listOrganizationSheets: DefaultSDKFunction;
1115
}
16+
17+
export type GetSheetOptions = PageOptions & {
18+
id: number;
19+
include?: string;
20+
exclude?: string;
21+
columnIds?: string;
22+
filterId?: number;
23+
ifVersionAfter?: number;
24+
level?: number;
25+
};
26+
27+
/**
28+
* Represents the sheet data returned from `GET /sheets/{sheetId}`
29+
* References:
30+
* - https://smartsheet-platform.github.io/api-docs/#objects-23
31+
*/
32+
export interface SheetData {
33+
id: number;
34+
name: string;
35+
version: number;
36+
totalRowCount: number;
37+
accessLevel:
38+
| "ADMIN"
39+
| "EDITOR"
40+
| "EDITOR_SHARE"
41+
| "OWNER"
42+
| "VIEWER"
43+
| string;
44+
effectiveAttachmentOptions: string[];
45+
ganttEnabled: boolean;
46+
dependenciesEnabled: boolean;
47+
resourceManagementEnabled: boolean;
48+
cellImageUploadEnabled: boolean;
49+
favorite: boolean;
50+
userSettings: {
51+
criticalPathEnabled: boolean;
52+
displaySummaryTasks: boolean;
53+
appliedSheetFilterId: number;
54+
};
55+
userPermissions: {
56+
summaryPermissions: "ADMIN" | "READ_DELETE" | "READ_ONLY" | "READ_WRITE";
57+
};
58+
workspace: { id: number; name: string };
59+
hasSummaryFields: boolean;
60+
permalink: string;
61+
createdAt: DateString;
62+
modifiedAt: DateString;
63+
isMultiPicklistEnabled: boolean;
64+
columns: Column[];
65+
filters?: Filter[];
66+
rows: RowData[];
67+
}
68+
69+
export interface Filter {
70+
name: string;
71+
id: number;
72+
filterType: "PERSONAL" | "SHARED";
73+
excludeSelected?: boolean;
74+
query: {
75+
operator: FilterOperator;
76+
criteria: FilterCriteria[];
77+
includeParent: boolean;
78+
};
79+
}
80+
81+
interface FilterCriteria {
82+
operator: FilterOperator;
83+
values: string[];
84+
columnId: number;
85+
}
86+
87+
type FilterOperator =
88+
| "BETWEEN"
89+
| "CONTAINS"
90+
| "EQUAL"
91+
| "NOT_EQUAL"
92+
| "FUTURE"
93+
| "GREATER_THAN"
94+
| "LESS_THAN"
95+
| "HAS_ANY_OF"
96+
| "HAS_NONE_OF"
97+
| "HAS_ALL_OF"
98+
| "IS_BLANK"
99+
| "IS_NOT_BLANK"
100+
| "IS_CHECKED"
101+
| "IS_NOT_CHECKED"
102+
| "IS_DATE"
103+
| "IS_NOT_DATE"
104+
| "IS_NUMBER"
105+
| "IS_NOT_NUMBER"
106+
| "LAST_N_DAYS"
107+
| "NEXT_N_DAYS"
108+
| "MULTI_IS_EQUAL"
109+
| "MULTI_IS_NOT_EQUAL"
110+
| "NOT_ALL_OF"
111+
| "PAST"
112+
| "TODAY"
113+
| "AND";

lib/types/sheets/rows.d.ts

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1+
import { DateString } from "../date";
12
import { DefaultSDKFunction } from "../defaults";
3+
import { Column } from "./columns";
4+
import { PagedResponse, PageOptions } from "../pagination";
25

36
export interface RowsResource {
47
getRow: DefaultSDKFunction<GetRowOptions, GetRowResponse>;
58
getRowAttachments: DefaultSDKFunction;
69
getRowDiscussions: DefaultSDKFunction;
7-
getCellHistory: DefaultSDKFunction;
10+
getCellHistory: DefaultSDKFunction<
11+
GetCellHistoryOptions,
12+
GetCellHistoryResponse
13+
>;
814
copyRowToAnotherSheet: DefaultSDKFunction;
915
moveRowToAnotherSheet: DefaultSDKFunction;
1016
addRow: DefaultSDKFunction;
@@ -23,25 +29,62 @@ export interface RowsResource {
2329
>;
2430
}
2531

32+
export interface GetRowOptions {
33+
sheetId: number;
34+
rowId: number;
35+
include?: string;
36+
level?: number;
37+
}
38+
39+
export type GetCellHistoryOptions = GetRowOptions &
40+
PageOptions & {
41+
columnId: number;
42+
};
43+
44+
export type GetCellHistoryResponse = PagedResponse & {
45+
data: CellHistoryCellData[];
46+
};
47+
48+
export interface CellHistoryCellData extends CellData {
49+
modifiedAt: DateString;
50+
modifiedBy: RowUser;
51+
}
52+
2653
/* eslint-disable @typescript-eslint/no-explicit-any */
27-
export type GetRowOptions = { sheetId: number; rowId: number } | any;
2854
export type AddImageToCellOptions = any;
2955
export type AddImageToCellResult = any;
3056
export type UpdateRowOptions = any;
3157
export type UpdateRowResponse = any;
58+
export type RowAttachment = any;
59+
export type RowDiscussion = any;
60+
export type RowUser = any;
3261
/* eslint-enable @typescript-eslint/no-explicit-any */
3362

34-
export type GetRowResponse = {
63+
// GET /sheets/{sheetId}/rows/{rowId} returns sheetId too
64+
export type GetRowResponse = RowData & { sheetId: number };
65+
66+
export interface RowData {
3567
id: number;
36-
sheetId: number;
68+
version: number;
3769
rowNumber: number;
3870
expanded: boolean;
39-
cells: CellObject[];
40-
createdAt: string;
41-
modifiedAt: string;
42-
};
71+
cells: CellData[];
72+
createdAt: DateString;
73+
modifiedAt: DateString;
74+
attachments?: RowAttachment[];
75+
columns?: Column;
76+
conditionalFormat?: string;
77+
discussions?: RowDiscussion[];
78+
filteredOut?: boolean;
79+
format?: string;
80+
inCriticalPath?: boolean;
81+
locked?: boolean;
82+
lockedForUser?: boolean;
83+
modifiedBy?: RowUser;
84+
permalink?: string;
85+
}
4386

44-
export interface CellObject {
87+
export interface CellData {
4588
columnType: ColumnType;
4689
value: string;
4790
displayValue: string;

0 commit comments

Comments
 (0)