@doist/todoist-sdk 9.0.0 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/authentication.js +1 -0
- package/dist/cjs/clients/activity-client.js +63 -0
- package/dist/cjs/clients/app-client.js +347 -0
- package/dist/cjs/clients/backup-client.js +65 -0
- package/dist/cjs/clients/base-client.js +30 -0
- package/dist/cjs/clients/comment-client.js +92 -0
- package/dist/cjs/clients/email-client.js +43 -0
- package/dist/cjs/clients/folder-client.js +80 -0
- package/dist/cjs/clients/id-mapping-client.js +39 -0
- package/dist/cjs/clients/insights-client.js +88 -0
- package/dist/cjs/clients/label-client.js +127 -0
- package/dist/cjs/clients/productivity-client.js +27 -0
- package/dist/cjs/clients/project-client.js +232 -0
- package/dist/cjs/clients/reminder-client.js +198 -0
- package/dist/cjs/clients/section-client.js +118 -0
- package/dist/cjs/clients/task-client.js +255 -0
- package/dist/cjs/clients/template-client.js +89 -0
- package/dist/cjs/clients/ui-extension-client.js +109 -0
- package/dist/cjs/clients/upload-client.js +102 -0
- package/dist/cjs/clients/workspace-client.js +367 -0
- package/dist/cjs/consts/endpoints.js +66 -1
- package/dist/cjs/test-utils/test-defaults.js +77 -1
- package/dist/cjs/todoist-api.js +422 -1537
- package/dist/cjs/transport/http-client.js +1 -0
- package/dist/cjs/transport/sync-request.js +75 -0
- package/dist/cjs/types/apps/index.js +18 -0
- package/dist/cjs/types/apps/requests.js +2 -0
- package/dist/cjs/types/apps/types.js +253 -0
- package/dist/cjs/types/index.js +2 -0
- package/dist/cjs/types/ui-extensions/index.js +18 -0
- package/dist/cjs/types/ui-extensions/requests.js +2 -0
- package/dist/cjs/types/ui-extensions/types.js +77 -0
- package/dist/cjs/utils/headers.js +16 -0
- package/dist/cjs/utils/request-helpers.js +21 -0
- package/dist/cjs/utils/validators.js +52 -38
- package/dist/esm/authentication.js +1 -0
- package/dist/esm/clients/activity-client.js +59 -0
- package/dist/esm/clients/app-client.js +343 -0
- package/dist/esm/clients/backup-client.js +61 -0
- package/dist/esm/clients/base-client.js +26 -0
- package/dist/esm/clients/comment-client.js +88 -0
- package/dist/esm/clients/email-client.js +39 -0
- package/dist/esm/clients/folder-client.js +76 -0
- package/dist/esm/clients/id-mapping-client.js +35 -0
- package/dist/esm/clients/insights-client.js +84 -0
- package/dist/esm/clients/label-client.js +123 -0
- package/dist/esm/clients/productivity-client.js +23 -0
- package/dist/esm/clients/project-client.js +228 -0
- package/dist/esm/clients/reminder-client.js +194 -0
- package/dist/esm/clients/section-client.js +114 -0
- package/dist/esm/clients/task-client.js +251 -0
- package/dist/esm/clients/template-client.js +85 -0
- package/dist/esm/clients/ui-extension-client.js +105 -0
- package/dist/esm/clients/upload-client.js +98 -0
- package/dist/esm/clients/workspace-client.js +363 -0
- package/dist/esm/consts/endpoints.js +51 -0
- package/dist/esm/test-utils/test-defaults.js +75 -0
- package/dist/esm/todoist-api.js +425 -1540
- package/dist/esm/transport/http-client.js +1 -0
- package/dist/esm/transport/sync-request.js +72 -0
- package/dist/esm/types/apps/index.js +2 -0
- package/dist/esm/types/apps/requests.js +1 -0
- package/dist/esm/types/apps/types.js +248 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/ui-extensions/index.js +2 -0
- package/dist/esm/types/ui-extensions/requests.js +1 -0
- package/dist/esm/types/ui-extensions/types.js +74 -0
- package/dist/esm/utils/headers.js +13 -0
- package/dist/esm/utils/request-helpers.js +17 -0
- package/dist/esm/utils/validators.js +14 -0
- package/dist/types/authentication.d.ts +1 -1
- package/dist/types/clients/activity-client.d.ts +12 -0
- package/dist/types/clients/app-client.d.ts +37 -0
- package/dist/types/clients/backup-client.d.ts +14 -0
- package/dist/types/clients/base-client.d.ts +21 -0
- package/dist/types/clients/comment-client.d.ts +15 -0
- package/dist/types/clients/email-client.d.ts +13 -0
- package/dist/types/clients/folder-client.d.ts +16 -0
- package/dist/types/clients/id-mapping-client.d.ts +13 -0
- package/dist/types/clients/insights-client.d.ts +18 -0
- package/dist/types/clients/label-client.d.ts +19 -0
- package/dist/types/clients/productivity-client.d.ts +12 -0
- package/dist/types/clients/project-client.d.ts +26 -0
- package/dist/types/clients/reminder-client.d.ts +25 -0
- package/dist/types/clients/section-client.d.ts +18 -0
- package/dist/types/clients/task-client.d.ts +25 -0
- package/dist/types/clients/template-client.d.ts +17 -0
- package/dist/types/clients/ui-extension-client.d.ts +18 -0
- package/dist/types/clients/upload-client.d.ts +17 -0
- package/dist/types/clients/workspace-client.d.ts +43 -0
- package/dist/types/consts/endpoints.d.ts +24 -0
- package/dist/types/test-utils/test-defaults.d.ts +16 -1
- package/dist/types/todoist-api.d.ts +238 -17
- package/dist/types/transport/sync-request.d.ts +27 -0
- package/dist/types/types/apps/index.d.ts +2 -0
- package/dist/types/types/apps/requests.d.ts +89 -0
- package/dist/types/types/apps/types.d.ts +414 -0
- package/dist/types/types/http.d.ts +8 -1
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/sync/resources/user.d.ts +2 -2
- package/dist/types/types/sync/response.d.ts +2 -2
- package/dist/types/types/sync/user-preferences.d.ts +1 -1
- package/dist/types/types/ui-extensions/index.d.ts +2 -0
- package/dist/types/types/ui-extensions/requests.d.ts +108 -0
- package/dist/types/types/ui-extensions/types.d.ts +185 -0
- package/dist/types/utils/headers.d.ts +7 -0
- package/dist/types/utils/request-helpers.d.ts +13 -0
- package/dist/types/utils/validators.d.ts +223 -0
- package/package.json +1 -1
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { ENDPOINT_REST_ACTIVITIES } from '../consts/endpoints.js';
|
|
13
|
+
import { request } from '../transport/http-client.js';
|
|
14
|
+
import { denormalizeObjectTypeFromApi, normalizeObjectEventTypeForApi, } from '../utils/activity-helpers.js';
|
|
15
|
+
import { formatDateToYYYYMMDD } from '../utils/url-helpers.js';
|
|
16
|
+
import { validateActivityEventArray } from '../utils/validators.js';
|
|
17
|
+
import { BaseClient } from './base-client.js';
|
|
18
|
+
/**
|
|
19
|
+
* Internal sub-client handling the activity-log endpoint.
|
|
20
|
+
*
|
|
21
|
+
* Instantiated by `TodoistApi`; the public `getActivityLogs` method on
|
|
22
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
23
|
+
* JSDoc.
|
|
24
|
+
*/
|
|
25
|
+
export class ActivityClient extends BaseClient {
|
|
26
|
+
async getActivityLogs(args = {}) {
|
|
27
|
+
// Convert Date objects to YYYY-MM-DD strings
|
|
28
|
+
const dateFrom = args.dateFrom instanceof Date ? formatDateToYYYYMMDD(args.dateFrom) : args.dateFrom;
|
|
29
|
+
const dateTo = args.dateTo instanceof Date ? formatDateToYYYYMMDD(args.dateTo) : args.dateTo;
|
|
30
|
+
// Destructure out raw date, filter-type, and removed legacy fields so they don't leak into payload
|
|
31
|
+
const _a = args, { dateFrom: _dateFrom, dateTo: _dateTo, objectEventTypes, objectType: _objectType, eventType: _eventType, since: _since, until: _until } = _a, rest = __rest(_a, ["dateFrom", "dateTo", "objectEventTypes", "objectType", "eventType", "since", "until"]);
|
|
32
|
+
// Build normalized objectEventTypes for the API
|
|
33
|
+
let normalizedObjectEventTypes;
|
|
34
|
+
if (objectEventTypes !== undefined) {
|
|
35
|
+
const arr = Array.isArray(objectEventTypes) ? objectEventTypes : [objectEventTypes];
|
|
36
|
+
normalizedObjectEventTypes = arr.map(normalizeObjectEventTypeForApi);
|
|
37
|
+
}
|
|
38
|
+
const processedArgs = Object.assign(Object.assign(Object.assign(Object.assign({}, rest), (dateFrom !== undefined ? { dateFrom } : {})), (dateTo !== undefined ? { dateTo } : {})), (normalizedObjectEventTypes !== undefined
|
|
39
|
+
? { objectEventTypes: normalizedObjectEventTypes }
|
|
40
|
+
: {}));
|
|
41
|
+
const { data: { results, nextCursor }, } = await request({
|
|
42
|
+
httpMethod: 'GET',
|
|
43
|
+
baseUri: this.syncApiBase,
|
|
44
|
+
relativePath: ENDPOINT_REST_ACTIVITIES,
|
|
45
|
+
apiToken: this.authToken,
|
|
46
|
+
customFetch: this.customFetch,
|
|
47
|
+
payload: processedArgs,
|
|
48
|
+
});
|
|
49
|
+
// Convert legacy API object types back to modern SDK types
|
|
50
|
+
const normalizedResults = results.map((event) => {
|
|
51
|
+
const normalizedType = denormalizeObjectTypeFromApi(event.objectType);
|
|
52
|
+
return Object.assign(Object.assign({}, event), { objectType: normalizedType || event.objectType });
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
results: validateActivityEventArray(normalizedResults),
|
|
56
|
+
nextCursor,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { ENDPOINT_REST_APPS, ENDPOINT_REST_APPS_INSTALLATIONS, ENDPOINT_REST_USER_AUTHORIZATIONS, ENDPOINT_REST_USER_AUTHORIZATIONS_DELETE, getAppByDistributionTokenEndpoint, getAppClientSecretEndpoint, getAppDistributionTokenEndpoint, getAppEndpoint, getAppIconEndpoint, getAppInstallationEndpoint, getAppSecretsEndpoint, getAppTestTokenEndpoint, getAppTokensEndpoint, getAppVerificationTokenEndpoint, getAppWebhookEndpoint, } from '../consts/endpoints.js';
|
|
14
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
15
|
+
import { webhookEventToWireName } from '../types/apps/index.js';
|
|
16
|
+
import { camelCaseKeys } from '../utils/case-conversion.js';
|
|
17
|
+
import { uploadMultipartFile } from '../utils/multipart-upload.js';
|
|
18
|
+
import { validateApp, validateAppArray, validateAppByDistributionToken, validateAppDistributionToken, validateAppInstallation, validateAppInstallationArray, validateAppSecrets, validateAppTestToken, validateAppVerificationToken, validateAppWebhook, validateAppWithUserCount, validateUserAuthorizationArray, } from '../utils/validators.js';
|
|
19
|
+
import { BaseClient } from './base-client.js';
|
|
20
|
+
/**
|
|
21
|
+
* Internal sub-client handling all developer-app management endpoints
|
|
22
|
+
* (apps, secrets, tokens, webhooks, installations, user authorizations).
|
|
23
|
+
* All endpoints require the `dev:app_console` OAuth scope.
|
|
24
|
+
*
|
|
25
|
+
* Instantiated by `TodoistApi`; every public app-management method on
|
|
26
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing JSDoc.
|
|
27
|
+
*/
|
|
28
|
+
export class AppClient extends BaseClient {
|
|
29
|
+
async getApps(requestId) {
|
|
30
|
+
const response = await request({
|
|
31
|
+
httpMethod: 'GET',
|
|
32
|
+
baseUri: this.syncApiBase,
|
|
33
|
+
relativePath: ENDPOINT_REST_APPS,
|
|
34
|
+
apiToken: this.authToken,
|
|
35
|
+
customFetch: this.customFetch,
|
|
36
|
+
requestId: requestId,
|
|
37
|
+
});
|
|
38
|
+
return validateAppArray(response.data);
|
|
39
|
+
}
|
|
40
|
+
async getApp(appId, requestId) {
|
|
41
|
+
z.string().parse(appId);
|
|
42
|
+
const response = await request({
|
|
43
|
+
httpMethod: 'GET',
|
|
44
|
+
baseUri: this.syncApiBase,
|
|
45
|
+
relativePath: getAppEndpoint(appId),
|
|
46
|
+
apiToken: this.authToken,
|
|
47
|
+
customFetch: this.customFetch,
|
|
48
|
+
requestId: requestId,
|
|
49
|
+
});
|
|
50
|
+
return validateAppWithUserCount(response.data);
|
|
51
|
+
}
|
|
52
|
+
async addApp(args, requestId) {
|
|
53
|
+
const response = await request({
|
|
54
|
+
httpMethod: 'POST',
|
|
55
|
+
baseUri: this.syncApiBase,
|
|
56
|
+
relativePath: ENDPOINT_REST_APPS,
|
|
57
|
+
apiToken: this.authToken,
|
|
58
|
+
customFetch: this.customFetch,
|
|
59
|
+
payload: args,
|
|
60
|
+
requestId: requestId,
|
|
61
|
+
});
|
|
62
|
+
return validateApp(response.data);
|
|
63
|
+
}
|
|
64
|
+
async updateApp(appId, args, requestId) {
|
|
65
|
+
z.string().parse(appId);
|
|
66
|
+
const { appTokenScopes } = args, rest = __rest(args, ["appTokenScopes"]);
|
|
67
|
+
const payload = Object.assign({}, rest);
|
|
68
|
+
if (appTokenScopes !== undefined) {
|
|
69
|
+
payload.appTokenScopes = appTokenScopes === null ? null : appTokenScopes.join(',');
|
|
70
|
+
}
|
|
71
|
+
const response = await request({
|
|
72
|
+
httpMethod: 'POST',
|
|
73
|
+
baseUri: this.syncApiBase,
|
|
74
|
+
relativePath: getAppEndpoint(appId),
|
|
75
|
+
apiToken: this.authToken,
|
|
76
|
+
customFetch: this.customFetch,
|
|
77
|
+
payload: payload,
|
|
78
|
+
requestId: requestId,
|
|
79
|
+
});
|
|
80
|
+
return validateAppWithUserCount(response.data);
|
|
81
|
+
}
|
|
82
|
+
async deleteApp(appId, requestId) {
|
|
83
|
+
z.string().parse(appId);
|
|
84
|
+
const response = await request({
|
|
85
|
+
httpMethod: 'DELETE',
|
|
86
|
+
baseUri: this.syncApiBase,
|
|
87
|
+
relativePath: getAppEndpoint(appId),
|
|
88
|
+
apiToken: this.authToken,
|
|
89
|
+
customFetch: this.customFetch,
|
|
90
|
+
requestId: requestId,
|
|
91
|
+
});
|
|
92
|
+
return isSuccess(response);
|
|
93
|
+
}
|
|
94
|
+
async getAppSecrets(appId, requestId) {
|
|
95
|
+
z.string().parse(appId);
|
|
96
|
+
const response = await request({
|
|
97
|
+
httpMethod: 'GET',
|
|
98
|
+
baseUri: this.syncApiBase,
|
|
99
|
+
relativePath: getAppSecretsEndpoint(appId),
|
|
100
|
+
apiToken: this.authToken,
|
|
101
|
+
customFetch: this.customFetch,
|
|
102
|
+
requestId: requestId,
|
|
103
|
+
});
|
|
104
|
+
return validateAppSecrets(response.data);
|
|
105
|
+
}
|
|
106
|
+
async resetAppClientSecret(appId, requestId) {
|
|
107
|
+
z.string().parse(appId);
|
|
108
|
+
const response = await request({
|
|
109
|
+
httpMethod: 'DELETE',
|
|
110
|
+
baseUri: this.syncApiBase,
|
|
111
|
+
relativePath: getAppClientSecretEndpoint(appId),
|
|
112
|
+
apiToken: this.authToken,
|
|
113
|
+
customFetch: this.customFetch,
|
|
114
|
+
requestId: requestId,
|
|
115
|
+
});
|
|
116
|
+
return validateAppWithUserCount(response.data);
|
|
117
|
+
}
|
|
118
|
+
async revokeAppTokens(appId, requestId) {
|
|
119
|
+
z.string().parse(appId);
|
|
120
|
+
const response = await request({
|
|
121
|
+
httpMethod: 'DELETE',
|
|
122
|
+
baseUri: this.syncApiBase,
|
|
123
|
+
relativePath: getAppTokensEndpoint(appId),
|
|
124
|
+
apiToken: this.authToken,
|
|
125
|
+
customFetch: this.customFetch,
|
|
126
|
+
requestId: requestId,
|
|
127
|
+
});
|
|
128
|
+
return validateAppWithUserCount(response.data);
|
|
129
|
+
}
|
|
130
|
+
async uploadAppIcon(args, requestId) {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
if (Buffer.isBuffer(args.file) && args.file.length === 0) {
|
|
133
|
+
throw new Error('Cannot upload empty image file');
|
|
134
|
+
}
|
|
135
|
+
const size = (_a = args.size) !== null && _a !== void 0 ? _a : 'medium';
|
|
136
|
+
const data = await uploadMultipartFile({
|
|
137
|
+
baseUrl: this.syncApiBase,
|
|
138
|
+
authToken: this.authToken,
|
|
139
|
+
endpoint: getAppIconEndpoint(args.appId, size),
|
|
140
|
+
file: args.file,
|
|
141
|
+
fileName: args.fileName,
|
|
142
|
+
additionalFields: { file_name: (_b = args.fileName) !== null && _b !== void 0 ? _b : '' },
|
|
143
|
+
requestId: requestId,
|
|
144
|
+
customFetch: this.customFetch,
|
|
145
|
+
});
|
|
146
|
+
return validateAppWithUserCount(camelCaseKeys(data));
|
|
147
|
+
}
|
|
148
|
+
async getAppTestToken(appId, requestId) {
|
|
149
|
+
z.string().parse(appId);
|
|
150
|
+
const response = await request({
|
|
151
|
+
httpMethod: 'GET',
|
|
152
|
+
baseUri: this.syncApiBase,
|
|
153
|
+
relativePath: getAppTestTokenEndpoint(appId),
|
|
154
|
+
apiToken: this.authToken,
|
|
155
|
+
customFetch: this.customFetch,
|
|
156
|
+
requestId: requestId,
|
|
157
|
+
});
|
|
158
|
+
return validateAppTestToken(response.data);
|
|
159
|
+
}
|
|
160
|
+
async createAppTestToken(appId, requestId) {
|
|
161
|
+
z.string().parse(appId);
|
|
162
|
+
const response = await request({
|
|
163
|
+
httpMethod: 'PUT',
|
|
164
|
+
baseUri: this.syncApiBase,
|
|
165
|
+
relativePath: getAppTestTokenEndpoint(appId),
|
|
166
|
+
apiToken: this.authToken,
|
|
167
|
+
customFetch: this.customFetch,
|
|
168
|
+
requestId: requestId,
|
|
169
|
+
});
|
|
170
|
+
return validateAppTestToken(response.data);
|
|
171
|
+
}
|
|
172
|
+
async getAppDistributionToken(appId, requestId) {
|
|
173
|
+
z.string().parse(appId);
|
|
174
|
+
const response = await request({
|
|
175
|
+
httpMethod: 'GET',
|
|
176
|
+
baseUri: this.syncApiBase,
|
|
177
|
+
relativePath: getAppDistributionTokenEndpoint(appId),
|
|
178
|
+
apiToken: this.authToken,
|
|
179
|
+
customFetch: this.customFetch,
|
|
180
|
+
requestId: requestId,
|
|
181
|
+
});
|
|
182
|
+
return validateAppDistributionToken(response.data);
|
|
183
|
+
}
|
|
184
|
+
async getAppVerificationToken(appId, requestId) {
|
|
185
|
+
z.string().parse(appId);
|
|
186
|
+
const response = await request({
|
|
187
|
+
httpMethod: 'GET',
|
|
188
|
+
baseUri: this.syncApiBase,
|
|
189
|
+
relativePath: getAppVerificationTokenEndpoint(appId),
|
|
190
|
+
apiToken: this.authToken,
|
|
191
|
+
customFetch: this.customFetch,
|
|
192
|
+
requestId: requestId,
|
|
193
|
+
});
|
|
194
|
+
return validateAppVerificationToken(response.data);
|
|
195
|
+
}
|
|
196
|
+
async resetAppVerificationToken(appId, requestId) {
|
|
197
|
+
z.string().parse(appId);
|
|
198
|
+
const response = await request({
|
|
199
|
+
httpMethod: 'DELETE',
|
|
200
|
+
baseUri: this.syncApiBase,
|
|
201
|
+
relativePath: getAppVerificationTokenEndpoint(appId),
|
|
202
|
+
apiToken: this.authToken,
|
|
203
|
+
customFetch: this.customFetch,
|
|
204
|
+
requestId: requestId,
|
|
205
|
+
});
|
|
206
|
+
return validateAppVerificationToken(response.data);
|
|
207
|
+
}
|
|
208
|
+
async getAppByDistributionToken(distributionToken, requestId) {
|
|
209
|
+
z.string().parse(distributionToken);
|
|
210
|
+
const response = await request({
|
|
211
|
+
httpMethod: 'GET',
|
|
212
|
+
baseUri: this.syncApiBase,
|
|
213
|
+
relativePath: getAppByDistributionTokenEndpoint(distributionToken),
|
|
214
|
+
apiToken: this.authToken,
|
|
215
|
+
customFetch: this.customFetch,
|
|
216
|
+
requestId: requestId,
|
|
217
|
+
});
|
|
218
|
+
return validateAppByDistributionToken(response.data);
|
|
219
|
+
}
|
|
220
|
+
// --- App webhooks ---
|
|
221
|
+
async getAppWebhook(appId, requestId) {
|
|
222
|
+
z.string().parse(appId);
|
|
223
|
+
const response = await request({
|
|
224
|
+
httpMethod: 'GET',
|
|
225
|
+
baseUri: this.syncApiBase,
|
|
226
|
+
relativePath: getAppWebhookEndpoint(appId),
|
|
227
|
+
apiToken: this.authToken,
|
|
228
|
+
customFetch: this.customFetch,
|
|
229
|
+
requestId: requestId,
|
|
230
|
+
});
|
|
231
|
+
return response.data ? validateAppWebhook(response.data) : null;
|
|
232
|
+
}
|
|
233
|
+
async updateAppWebhook(args, requestId) {
|
|
234
|
+
const { appId, events } = args, rest = __rest(args, ["appId", "events"]);
|
|
235
|
+
const response = await request({
|
|
236
|
+
httpMethod: 'POST',
|
|
237
|
+
baseUri: this.syncApiBase,
|
|
238
|
+
relativePath: getAppWebhookEndpoint(appId),
|
|
239
|
+
apiToken: this.authToken,
|
|
240
|
+
customFetch: this.customFetch,
|
|
241
|
+
payload: Object.assign(Object.assign({}, rest), { events: events.map(webhookEventToWireName) }),
|
|
242
|
+
requestId: requestId,
|
|
243
|
+
});
|
|
244
|
+
return validateAppWebhook(response.data);
|
|
245
|
+
}
|
|
246
|
+
async deleteAppWebhook(appId, requestId) {
|
|
247
|
+
z.string().parse(appId);
|
|
248
|
+
const response = await request({
|
|
249
|
+
httpMethod: 'DELETE',
|
|
250
|
+
baseUri: this.syncApiBase,
|
|
251
|
+
relativePath: getAppWebhookEndpoint(appId),
|
|
252
|
+
apiToken: this.authToken,
|
|
253
|
+
customFetch: this.customFetch,
|
|
254
|
+
requestId: requestId,
|
|
255
|
+
});
|
|
256
|
+
return isSuccess(response);
|
|
257
|
+
}
|
|
258
|
+
// --- App installations ---
|
|
259
|
+
async getAppInstallations(requestId) {
|
|
260
|
+
const response = await request({
|
|
261
|
+
httpMethod: 'GET',
|
|
262
|
+
baseUri: this.syncApiBase,
|
|
263
|
+
relativePath: ENDPOINT_REST_APPS_INSTALLATIONS,
|
|
264
|
+
apiToken: this.authToken,
|
|
265
|
+
customFetch: this.customFetch,
|
|
266
|
+
requestId: requestId,
|
|
267
|
+
});
|
|
268
|
+
return validateAppInstallationArray(response.data);
|
|
269
|
+
}
|
|
270
|
+
async installApp(args, requestId) {
|
|
271
|
+
const response = await request({
|
|
272
|
+
httpMethod: 'POST',
|
|
273
|
+
baseUri: this.syncApiBase,
|
|
274
|
+
relativePath: ENDPOINT_REST_APPS_INSTALLATIONS,
|
|
275
|
+
apiToken: this.authToken,
|
|
276
|
+
customFetch: this.customFetch,
|
|
277
|
+
payload: args,
|
|
278
|
+
requestId: requestId,
|
|
279
|
+
});
|
|
280
|
+
return validateAppInstallation(response.data);
|
|
281
|
+
}
|
|
282
|
+
async getAppInstallation(installationId, requestId) {
|
|
283
|
+
z.string().parse(installationId);
|
|
284
|
+
const response = await request({
|
|
285
|
+
httpMethod: 'GET',
|
|
286
|
+
baseUri: this.syncApiBase,
|
|
287
|
+
relativePath: getAppInstallationEndpoint(installationId),
|
|
288
|
+
apiToken: this.authToken,
|
|
289
|
+
customFetch: this.customFetch,
|
|
290
|
+
requestId: requestId,
|
|
291
|
+
});
|
|
292
|
+
return validateAppInstallation(response.data);
|
|
293
|
+
}
|
|
294
|
+
async updateAppInstallation(installationId, args, requestId) {
|
|
295
|
+
z.string().parse(installationId);
|
|
296
|
+
const response = await request({
|
|
297
|
+
httpMethod: 'POST',
|
|
298
|
+
baseUri: this.syncApiBase,
|
|
299
|
+
relativePath: getAppInstallationEndpoint(installationId),
|
|
300
|
+
apiToken: this.authToken,
|
|
301
|
+
customFetch: this.customFetch,
|
|
302
|
+
payload: args,
|
|
303
|
+
requestId: requestId,
|
|
304
|
+
});
|
|
305
|
+
return validateAppInstallation(response.data);
|
|
306
|
+
}
|
|
307
|
+
async uninstallApp(installationId, requestId) {
|
|
308
|
+
z.string().parse(installationId);
|
|
309
|
+
const response = await request({
|
|
310
|
+
httpMethod: 'DELETE',
|
|
311
|
+
baseUri: this.syncApiBase,
|
|
312
|
+
relativePath: getAppInstallationEndpoint(installationId),
|
|
313
|
+
apiToken: this.authToken,
|
|
314
|
+
customFetch: this.customFetch,
|
|
315
|
+
requestId: requestId,
|
|
316
|
+
});
|
|
317
|
+
return isSuccess(response);
|
|
318
|
+
}
|
|
319
|
+
// --- User authorizations ---
|
|
320
|
+
async getUserAuthorizations(requestId) {
|
|
321
|
+
const response = await request({
|
|
322
|
+
httpMethod: 'GET',
|
|
323
|
+
baseUri: this.syncApiBase,
|
|
324
|
+
relativePath: ENDPOINT_REST_USER_AUTHORIZATIONS,
|
|
325
|
+
apiToken: this.authToken,
|
|
326
|
+
customFetch: this.customFetch,
|
|
327
|
+
requestId: requestId,
|
|
328
|
+
});
|
|
329
|
+
return validateUserAuthorizationArray(response.data);
|
|
330
|
+
}
|
|
331
|
+
async revokeUserAuthorization(args, requestId) {
|
|
332
|
+
const response = await request({
|
|
333
|
+
httpMethod: 'POST',
|
|
334
|
+
baseUri: this.syncApiBase,
|
|
335
|
+
relativePath: ENDPOINT_REST_USER_AUTHORIZATIONS_DELETE,
|
|
336
|
+
apiToken: this.authToken,
|
|
337
|
+
customFetch: this.customFetch,
|
|
338
|
+
payload: args,
|
|
339
|
+
requestId: requestId,
|
|
340
|
+
});
|
|
341
|
+
return isSuccess(response);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ENDPOINT_REST_BACKUPS, ENDPOINT_REST_BACKUPS_DOWNLOAD } from '../consts/endpoints.js';
|
|
2
|
+
import { request } from '../transport/http-client.js';
|
|
3
|
+
import { headersToRecord } from '../utils/headers.js';
|
|
4
|
+
import { validateBackupArray } from '../utils/validators.js';
|
|
5
|
+
import { BaseClient } from './base-client.js';
|
|
6
|
+
/**
|
|
7
|
+
* Internal sub-client handling backup-domain endpoints.
|
|
8
|
+
*
|
|
9
|
+
* Instantiated by `TodoistApi`; every public backup method on
|
|
10
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
11
|
+
* JSDoc.
|
|
12
|
+
*/
|
|
13
|
+
export class BackupClient extends BaseClient {
|
|
14
|
+
async getBackups(args = {}) {
|
|
15
|
+
const response = await request({
|
|
16
|
+
httpMethod: 'GET',
|
|
17
|
+
baseUri: this.syncApiBase,
|
|
18
|
+
relativePath: ENDPOINT_REST_BACKUPS,
|
|
19
|
+
apiToken: this.authToken,
|
|
20
|
+
customFetch: this.customFetch,
|
|
21
|
+
payload: args,
|
|
22
|
+
});
|
|
23
|
+
return validateBackupArray(response.data);
|
|
24
|
+
}
|
|
25
|
+
async downloadBackup(args) {
|
|
26
|
+
const url = `${this.syncApiBase}${ENDPOINT_REST_BACKUPS_DOWNLOAD}?file=${encodeURIComponent(args.file)}`;
|
|
27
|
+
const fetchOptions = {
|
|
28
|
+
headers: { Authorization: `Bearer ${this.authToken}` },
|
|
29
|
+
};
|
|
30
|
+
if (this.customFetch) {
|
|
31
|
+
const response = await this.customFetch(url, fetchOptions);
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`Failed to download backup: ${response.status} ${response.statusText}`);
|
|
34
|
+
}
|
|
35
|
+
const text = await response.text();
|
|
36
|
+
const buffer = new TextEncoder().encode(text).buffer;
|
|
37
|
+
return {
|
|
38
|
+
ok: response.ok,
|
|
39
|
+
status: response.status,
|
|
40
|
+
statusText: response.statusText,
|
|
41
|
+
headers: response.headers,
|
|
42
|
+
text: () => Promise.resolve(text),
|
|
43
|
+
json: () => response.json(),
|
|
44
|
+
arrayBuffer: () => Promise.resolve(buffer),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const response = await fetch(url, fetchOptions);
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new Error(`Failed to download backup: ${response.status} ${response.statusText}`);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
ok: response.ok,
|
|
53
|
+
status: response.status,
|
|
54
|
+
statusText: response.statusText,
|
|
55
|
+
headers: headersToRecord(response.headers),
|
|
56
|
+
text: () => response.text(),
|
|
57
|
+
json: () => response.json(),
|
|
58
|
+
arrayBuffer: () => response.arrayBuffer(),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal base class for every domain sub-client (tasks, projects, …).
|
|
3
|
+
*
|
|
4
|
+
* Not exported from the package — sub-clients are an implementation detail
|
|
5
|
+
* of `TodoistApi`. Holds the three pieces of HTTP identity every sub-client
|
|
6
|
+
* needs and exposes a typed accessor to feed the Sync API helper.
|
|
7
|
+
*
|
|
8
|
+
* The constructor takes a {@link SyncRequestContext} — the same record
|
|
9
|
+
* shape used by `performSyncRequest` — so there is a single type describing
|
|
10
|
+
* "the HTTP identity an SDK component needs", not two types that must stay
|
|
11
|
+
* in sync.
|
|
12
|
+
*/
|
|
13
|
+
export class BaseClient {
|
|
14
|
+
constructor(context) {
|
|
15
|
+
this.authToken = context.authToken;
|
|
16
|
+
this.syncApiBase = context.syncApiBase;
|
|
17
|
+
this.customFetch = context.customFetch;
|
|
18
|
+
}
|
|
19
|
+
get syncContext() {
|
|
20
|
+
return {
|
|
21
|
+
authToken: this.authToken,
|
|
22
|
+
syncApiBase: this.syncApiBase,
|
|
23
|
+
customFetch: this.customFetch,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { ENDPOINT_REST_COMMENTS } from '../consts/endpoints.js';
|
|
14
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
15
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
16
|
+
import { validateComment, validateCommentArray } from '../utils/validators.js';
|
|
17
|
+
import { BaseClient } from './base-client.js';
|
|
18
|
+
/**
|
|
19
|
+
* Internal sub-client handling all comment-domain endpoints.
|
|
20
|
+
*
|
|
21
|
+
* Instantiated by `TodoistApi`; every public comment method on `TodoistApi`
|
|
22
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
23
|
+
*/
|
|
24
|
+
export class CommentClient extends BaseClient {
|
|
25
|
+
async getComments(args) {
|
|
26
|
+
const { data: { results, nextCursor }, } = await request({
|
|
27
|
+
httpMethod: 'GET',
|
|
28
|
+
baseUri: this.syncApiBase,
|
|
29
|
+
relativePath: ENDPOINT_REST_COMMENTS,
|
|
30
|
+
apiToken: this.authToken,
|
|
31
|
+
customFetch: this.customFetch,
|
|
32
|
+
payload: args,
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
results: validateCommentArray(results),
|
|
36
|
+
nextCursor,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
async getComment(id) {
|
|
40
|
+
z.string().parse(id);
|
|
41
|
+
const response = await request({
|
|
42
|
+
httpMethod: 'GET',
|
|
43
|
+
baseUri: this.syncApiBase,
|
|
44
|
+
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
45
|
+
apiToken: this.authToken,
|
|
46
|
+
customFetch: this.customFetch,
|
|
47
|
+
});
|
|
48
|
+
return validateComment(response.data);
|
|
49
|
+
}
|
|
50
|
+
async addComment(args, requestId) {
|
|
51
|
+
const { uidsToNotify } = args, rest = __rest(args, ["uidsToNotify"]);
|
|
52
|
+
const response = await request({
|
|
53
|
+
httpMethod: 'POST',
|
|
54
|
+
baseUri: this.syncApiBase,
|
|
55
|
+
relativePath: ENDPOINT_REST_COMMENTS,
|
|
56
|
+
apiToken: this.authToken,
|
|
57
|
+
customFetch: this.customFetch,
|
|
58
|
+
payload: Object.assign(Object.assign({}, rest), (uidsToNotify ? { uidsToNotify: uidsToNotify.join(',') } : {})),
|
|
59
|
+
requestId: requestId,
|
|
60
|
+
});
|
|
61
|
+
return validateComment(response.data);
|
|
62
|
+
}
|
|
63
|
+
async updateComment(id, args, requestId) {
|
|
64
|
+
z.string().parse(id);
|
|
65
|
+
const response = await request({
|
|
66
|
+
httpMethod: 'POST',
|
|
67
|
+
baseUri: this.syncApiBase,
|
|
68
|
+
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
69
|
+
apiToken: this.authToken,
|
|
70
|
+
customFetch: this.customFetch,
|
|
71
|
+
payload: args,
|
|
72
|
+
requestId: requestId,
|
|
73
|
+
});
|
|
74
|
+
return validateComment(response.data);
|
|
75
|
+
}
|
|
76
|
+
async deleteComment(id, requestId) {
|
|
77
|
+
z.string().parse(id);
|
|
78
|
+
const response = await request({
|
|
79
|
+
httpMethod: 'DELETE',
|
|
80
|
+
baseUri: this.syncApiBase,
|
|
81
|
+
relativePath: generatePath(ENDPOINT_REST_COMMENTS, id),
|
|
82
|
+
apiToken: this.authToken,
|
|
83
|
+
customFetch: this.customFetch,
|
|
84
|
+
requestId: requestId,
|
|
85
|
+
});
|
|
86
|
+
return isSuccess(response);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ENDPOINT_REST_EMAILS } from '../consts/endpoints.js';
|
|
2
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
3
|
+
import { BaseClient } from './base-client.js';
|
|
4
|
+
/**
|
|
5
|
+
* Internal sub-client handling email-forwarding endpoints.
|
|
6
|
+
*
|
|
7
|
+
* Instantiated by `TodoistApi`; every public email-forwarding method on
|
|
8
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
9
|
+
* JSDoc.
|
|
10
|
+
*/
|
|
11
|
+
export class EmailClient extends BaseClient {
|
|
12
|
+
async getOrCreateEmailForwarding(args, requestId) {
|
|
13
|
+
const { data } = await request({
|
|
14
|
+
httpMethod: 'PUT',
|
|
15
|
+
baseUri: this.syncApiBase,
|
|
16
|
+
relativePath: ENDPOINT_REST_EMAILS,
|
|
17
|
+
apiToken: this.authToken,
|
|
18
|
+
customFetch: this.customFetch,
|
|
19
|
+
payload: args,
|
|
20
|
+
requestId: requestId,
|
|
21
|
+
});
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
async disableEmailForwarding(args, requestId) {
|
|
25
|
+
const queryParams = new URLSearchParams({
|
|
26
|
+
obj_type: args.objType,
|
|
27
|
+
obj_id: args.objId,
|
|
28
|
+
});
|
|
29
|
+
const response = await request({
|
|
30
|
+
httpMethod: 'DELETE',
|
|
31
|
+
baseUri: this.syncApiBase,
|
|
32
|
+
relativePath: `${ENDPOINT_REST_EMAILS}?${queryParams.toString()}`,
|
|
33
|
+
apiToken: this.authToken,
|
|
34
|
+
customFetch: this.customFetch,
|
|
35
|
+
requestId: requestId,
|
|
36
|
+
});
|
|
37
|
+
return isSuccess(response);
|
|
38
|
+
}
|
|
39
|
+
}
|