@doist/todoist-sdk 9.1.0-next.2 → 9.1.1
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/app-client.js +347 -0
- package/dist/cjs/clients/base-client.js +1 -0
- package/dist/cjs/clients/ui-extension-client.js +109 -0
- package/dist/cjs/consts/endpoints.js +70 -6
- package/dist/cjs/test-utils/test-defaults.js +75 -23
- package/dist/cjs/todoist-api.js +269 -33
- package/dist/cjs/transport/http-client.js +1 -0
- package/dist/cjs/types/apps/types.js +253 -0
- package/dist/cjs/types/index.js +2 -1
- package/dist/cjs/types/sync/commands/index.js +0 -1
- package/dist/cjs/types/sync/resource-types.js +0 -1
- package/dist/cjs/types/sync/response.js +10 -12
- package/dist/cjs/types/ui-extensions/index.js +18 -0
- package/dist/cjs/types/ui-extensions/types.js +77 -0
- package/dist/cjs/utils/validators.js +45 -33
- package/dist/esm/authentication.js +1 -0
- package/dist/esm/clients/app-client.js +343 -0
- package/dist/esm/clients/base-client.js +1 -0
- package/dist/esm/clients/ui-extension-client.js +105 -0
- package/dist/esm/consts/endpoints.js +54 -5
- package/dist/esm/test-utils/test-defaults.js +73 -22
- package/dist/esm/todoist-api.js +269 -33
- package/dist/esm/transport/http-client.js +1 -0
- package/dist/esm/types/apps/types.js +248 -0
- package/dist/esm/types/index.js +2 -1
- package/dist/esm/types/sync/commands/index.js +0 -1
- package/dist/esm/types/sync/resource-types.js +0 -1
- package/dist/esm/types/sync/response.js +0 -2
- package/dist/esm/types/ui-extensions/types.js +74 -0
- package/dist/esm/utils/validators.js +14 -2
- package/dist/types/authentication.d.ts +1 -1
- package/dist/types/clients/app-client.d.ts +37 -0
- package/dist/types/clients/base-client.d.ts +1 -0
- package/dist/types/clients/ui-extension-client.d.ts +18 -0
- package/dist/types/consts/endpoints.d.ts +25 -5
- package/dist/types/test-utils/test-defaults.d.ts +16 -4
- package/dist/types/todoist-api.d.ts +202 -12
- 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 +1 -1
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types/types/sync/commands/index.d.ts +0 -9
- package/dist/types/types/sync/resource-types.d.ts +1 -1
- package/dist/types/types/sync/resources/user.d.ts +2 -2
- package/dist/types/types/sync/resources/view-options.d.ts +6 -6
- package/dist/types/types/sync/response.d.ts +6 -31
- package/dist/types/types/sync/user-preferences.d.ts +1 -1
- package/dist/types/types/tasks/requests.d.ts +0 -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/validators.d.ts +231 -55
- package/package.json +1 -1
- package/dist/cjs/clients/goals-client.js +0 -145
- package/dist/cjs/types/goals/types.js +0 -56
- package/dist/esm/clients/goals-client.js +0 -141
- package/dist/esm/types/goals/types.js +0 -53
- package/dist/types/clients/goals-client.d.ts +0 -20
- package/dist/types/types/goals/requests.d.ts +0 -33
- package/dist/types/types/goals/types.d.ts +0 -51
- package/dist/types/types/sync/commands/goals.d.ts +0 -33
- /package/dist/cjs/types/{goals → apps}/index.js +0 -0
- /package/dist/cjs/types/{goals → apps}/requests.js +0 -0
- /package/dist/cjs/types/{sync/commands/goals.js → ui-extensions/requests.js} +0 -0
- /package/dist/esm/types/{goals → apps}/index.js +0 -0
- /package/dist/esm/types/{goals → apps}/requests.js +0 -0
- /package/dist/{types/types/goals/index.d.ts → esm/types/ui-extensions/index.js} +0 -0
- /package/dist/esm/types/{sync/commands/goals.js → ui-extensions/requests.js} +0 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.AppClient = void 0;
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
17
|
+
const http_client_1 = require("../transport/http-client");
|
|
18
|
+
const apps_1 = require("../types/apps");
|
|
19
|
+
const case_conversion_1 = require("../utils/case-conversion");
|
|
20
|
+
const multipart_upload_1 = require("../utils/multipart-upload");
|
|
21
|
+
const validators_1 = require("../utils/validators");
|
|
22
|
+
const base_client_1 = require("./base-client");
|
|
23
|
+
/**
|
|
24
|
+
* Internal sub-client handling all developer-app management endpoints
|
|
25
|
+
* (apps, secrets, tokens, webhooks, installations, user authorizations).
|
|
26
|
+
* All endpoints require the `dev:app_console` OAuth scope.
|
|
27
|
+
*
|
|
28
|
+
* Instantiated by `TodoistApi`; every public app-management method on
|
|
29
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing JSDoc.
|
|
30
|
+
*/
|
|
31
|
+
class AppClient extends base_client_1.BaseClient {
|
|
32
|
+
async getApps(requestId) {
|
|
33
|
+
const response = await (0, http_client_1.request)({
|
|
34
|
+
httpMethod: 'GET',
|
|
35
|
+
baseUri: this.apiRootBase,
|
|
36
|
+
relativePath: endpoints_1.ENDPOINT_REST_APPS,
|
|
37
|
+
apiToken: this.authToken,
|
|
38
|
+
customFetch: this.customFetch,
|
|
39
|
+
requestId: requestId,
|
|
40
|
+
});
|
|
41
|
+
return (0, validators_1.validateAppArray)(response.data);
|
|
42
|
+
}
|
|
43
|
+
async getApp(appId, requestId) {
|
|
44
|
+
zod_1.z.string().parse(appId);
|
|
45
|
+
const response = await (0, http_client_1.request)({
|
|
46
|
+
httpMethod: 'GET',
|
|
47
|
+
baseUri: this.apiRootBase,
|
|
48
|
+
relativePath: (0, endpoints_1.getAppEndpoint)(appId),
|
|
49
|
+
apiToken: this.authToken,
|
|
50
|
+
customFetch: this.customFetch,
|
|
51
|
+
requestId: requestId,
|
|
52
|
+
});
|
|
53
|
+
return (0, validators_1.validateAppWithUserCount)(response.data);
|
|
54
|
+
}
|
|
55
|
+
async addApp(args, requestId) {
|
|
56
|
+
const response = await (0, http_client_1.request)({
|
|
57
|
+
httpMethod: 'POST',
|
|
58
|
+
baseUri: this.apiRootBase,
|
|
59
|
+
relativePath: endpoints_1.ENDPOINT_REST_APPS,
|
|
60
|
+
apiToken: this.authToken,
|
|
61
|
+
customFetch: this.customFetch,
|
|
62
|
+
payload: args,
|
|
63
|
+
requestId: requestId,
|
|
64
|
+
});
|
|
65
|
+
return (0, validators_1.validateApp)(response.data);
|
|
66
|
+
}
|
|
67
|
+
async updateApp(appId, args, requestId) {
|
|
68
|
+
zod_1.z.string().parse(appId);
|
|
69
|
+
const { appTokenScopes } = args, rest = __rest(args, ["appTokenScopes"]);
|
|
70
|
+
const payload = Object.assign({}, rest);
|
|
71
|
+
if (appTokenScopes !== undefined) {
|
|
72
|
+
payload.appTokenScopes = appTokenScopes === null ? null : appTokenScopes.join(',');
|
|
73
|
+
}
|
|
74
|
+
const response = await (0, http_client_1.request)({
|
|
75
|
+
httpMethod: 'POST',
|
|
76
|
+
baseUri: this.apiRootBase,
|
|
77
|
+
relativePath: (0, endpoints_1.getAppEndpoint)(appId),
|
|
78
|
+
apiToken: this.authToken,
|
|
79
|
+
customFetch: this.customFetch,
|
|
80
|
+
payload: payload,
|
|
81
|
+
requestId: requestId,
|
|
82
|
+
});
|
|
83
|
+
return (0, validators_1.validateAppWithUserCount)(response.data);
|
|
84
|
+
}
|
|
85
|
+
async deleteApp(appId, requestId) {
|
|
86
|
+
zod_1.z.string().parse(appId);
|
|
87
|
+
const response = await (0, http_client_1.request)({
|
|
88
|
+
httpMethod: 'DELETE',
|
|
89
|
+
baseUri: this.apiRootBase,
|
|
90
|
+
relativePath: (0, endpoints_1.getAppEndpoint)(appId),
|
|
91
|
+
apiToken: this.authToken,
|
|
92
|
+
customFetch: this.customFetch,
|
|
93
|
+
requestId: requestId,
|
|
94
|
+
});
|
|
95
|
+
return (0, http_client_1.isSuccess)(response);
|
|
96
|
+
}
|
|
97
|
+
async getAppSecrets(appId, requestId) {
|
|
98
|
+
zod_1.z.string().parse(appId);
|
|
99
|
+
const response = await (0, http_client_1.request)({
|
|
100
|
+
httpMethod: 'GET',
|
|
101
|
+
baseUri: this.apiRootBase,
|
|
102
|
+
relativePath: (0, endpoints_1.getAppSecretsEndpoint)(appId),
|
|
103
|
+
apiToken: this.authToken,
|
|
104
|
+
customFetch: this.customFetch,
|
|
105
|
+
requestId: requestId,
|
|
106
|
+
});
|
|
107
|
+
return (0, validators_1.validateAppSecrets)(response.data);
|
|
108
|
+
}
|
|
109
|
+
async resetAppClientSecret(appId, requestId) {
|
|
110
|
+
zod_1.z.string().parse(appId);
|
|
111
|
+
const response = await (0, http_client_1.request)({
|
|
112
|
+
httpMethod: 'DELETE',
|
|
113
|
+
baseUri: this.apiRootBase,
|
|
114
|
+
relativePath: (0, endpoints_1.getAppClientSecretEndpoint)(appId),
|
|
115
|
+
apiToken: this.authToken,
|
|
116
|
+
customFetch: this.customFetch,
|
|
117
|
+
requestId: requestId,
|
|
118
|
+
});
|
|
119
|
+
return (0, validators_1.validateAppWithUserCount)(response.data);
|
|
120
|
+
}
|
|
121
|
+
async revokeAppTokens(appId, requestId) {
|
|
122
|
+
zod_1.z.string().parse(appId);
|
|
123
|
+
const response = await (0, http_client_1.request)({
|
|
124
|
+
httpMethod: 'DELETE',
|
|
125
|
+
baseUri: this.apiRootBase,
|
|
126
|
+
relativePath: (0, endpoints_1.getAppTokensEndpoint)(appId),
|
|
127
|
+
apiToken: this.authToken,
|
|
128
|
+
customFetch: this.customFetch,
|
|
129
|
+
requestId: requestId,
|
|
130
|
+
});
|
|
131
|
+
return (0, validators_1.validateAppWithUserCount)(response.data);
|
|
132
|
+
}
|
|
133
|
+
async uploadAppIcon(args, requestId) {
|
|
134
|
+
var _a, _b;
|
|
135
|
+
if (Buffer.isBuffer(args.file) && args.file.length === 0) {
|
|
136
|
+
throw new Error('Cannot upload empty image file');
|
|
137
|
+
}
|
|
138
|
+
const size = (_a = args.size) !== null && _a !== void 0 ? _a : 'medium';
|
|
139
|
+
const data = await (0, multipart_upload_1.uploadMultipartFile)({
|
|
140
|
+
baseUrl: this.apiRootBase,
|
|
141
|
+
authToken: this.authToken,
|
|
142
|
+
endpoint: (0, endpoints_1.getAppIconEndpoint)(args.appId, size),
|
|
143
|
+
file: args.file,
|
|
144
|
+
fileName: args.fileName,
|
|
145
|
+
additionalFields: { file_name: (_b = args.fileName) !== null && _b !== void 0 ? _b : '' },
|
|
146
|
+
requestId: requestId,
|
|
147
|
+
customFetch: this.customFetch,
|
|
148
|
+
});
|
|
149
|
+
return (0, validators_1.validateAppWithUserCount)((0, case_conversion_1.camelCaseKeys)(data));
|
|
150
|
+
}
|
|
151
|
+
async getAppTestToken(appId, requestId) {
|
|
152
|
+
zod_1.z.string().parse(appId);
|
|
153
|
+
const response = await (0, http_client_1.request)({
|
|
154
|
+
httpMethod: 'GET',
|
|
155
|
+
baseUri: this.apiRootBase,
|
|
156
|
+
relativePath: (0, endpoints_1.getAppTestTokenEndpoint)(appId),
|
|
157
|
+
apiToken: this.authToken,
|
|
158
|
+
customFetch: this.customFetch,
|
|
159
|
+
requestId: requestId,
|
|
160
|
+
});
|
|
161
|
+
return (0, validators_1.validateAppTestToken)(response.data);
|
|
162
|
+
}
|
|
163
|
+
async createAppTestToken(appId, requestId) {
|
|
164
|
+
zod_1.z.string().parse(appId);
|
|
165
|
+
const response = await (0, http_client_1.request)({
|
|
166
|
+
httpMethod: 'PUT',
|
|
167
|
+
baseUri: this.apiRootBase,
|
|
168
|
+
relativePath: (0, endpoints_1.getAppTestTokenEndpoint)(appId),
|
|
169
|
+
apiToken: this.authToken,
|
|
170
|
+
customFetch: this.customFetch,
|
|
171
|
+
requestId: requestId,
|
|
172
|
+
});
|
|
173
|
+
return (0, validators_1.validateAppTestToken)(response.data);
|
|
174
|
+
}
|
|
175
|
+
async getAppDistributionToken(appId, requestId) {
|
|
176
|
+
zod_1.z.string().parse(appId);
|
|
177
|
+
const response = await (0, http_client_1.request)({
|
|
178
|
+
httpMethod: 'GET',
|
|
179
|
+
baseUri: this.apiRootBase,
|
|
180
|
+
relativePath: (0, endpoints_1.getAppDistributionTokenEndpoint)(appId),
|
|
181
|
+
apiToken: this.authToken,
|
|
182
|
+
customFetch: this.customFetch,
|
|
183
|
+
requestId: requestId,
|
|
184
|
+
});
|
|
185
|
+
return (0, validators_1.validateAppDistributionToken)(response.data);
|
|
186
|
+
}
|
|
187
|
+
async getAppVerificationToken(appId, requestId) {
|
|
188
|
+
zod_1.z.string().parse(appId);
|
|
189
|
+
const response = await (0, http_client_1.request)({
|
|
190
|
+
httpMethod: 'GET',
|
|
191
|
+
baseUri: this.apiRootBase,
|
|
192
|
+
relativePath: (0, endpoints_1.getAppVerificationTokenEndpoint)(appId),
|
|
193
|
+
apiToken: this.authToken,
|
|
194
|
+
customFetch: this.customFetch,
|
|
195
|
+
requestId: requestId,
|
|
196
|
+
});
|
|
197
|
+
return (0, validators_1.validateAppVerificationToken)(response.data);
|
|
198
|
+
}
|
|
199
|
+
async resetAppVerificationToken(appId, requestId) {
|
|
200
|
+
zod_1.z.string().parse(appId);
|
|
201
|
+
const response = await (0, http_client_1.request)({
|
|
202
|
+
httpMethod: 'DELETE',
|
|
203
|
+
baseUri: this.apiRootBase,
|
|
204
|
+
relativePath: (0, endpoints_1.getAppVerificationTokenEndpoint)(appId),
|
|
205
|
+
apiToken: this.authToken,
|
|
206
|
+
customFetch: this.customFetch,
|
|
207
|
+
requestId: requestId,
|
|
208
|
+
});
|
|
209
|
+
return (0, validators_1.validateAppVerificationToken)(response.data);
|
|
210
|
+
}
|
|
211
|
+
async getAppByDistributionToken(distributionToken, requestId) {
|
|
212
|
+
zod_1.z.string().parse(distributionToken);
|
|
213
|
+
const response = await (0, http_client_1.request)({
|
|
214
|
+
httpMethod: 'GET',
|
|
215
|
+
baseUri: this.apiRootBase,
|
|
216
|
+
relativePath: (0, endpoints_1.getAppByDistributionTokenEndpoint)(distributionToken),
|
|
217
|
+
apiToken: this.authToken,
|
|
218
|
+
customFetch: this.customFetch,
|
|
219
|
+
requestId: requestId,
|
|
220
|
+
});
|
|
221
|
+
return (0, validators_1.validateAppByDistributionToken)(response.data);
|
|
222
|
+
}
|
|
223
|
+
// --- App webhooks ---
|
|
224
|
+
async getAppWebhook(appId, requestId) {
|
|
225
|
+
zod_1.z.string().parse(appId);
|
|
226
|
+
const response = await (0, http_client_1.request)({
|
|
227
|
+
httpMethod: 'GET',
|
|
228
|
+
baseUri: this.apiRootBase,
|
|
229
|
+
relativePath: (0, endpoints_1.getAppWebhookEndpoint)(appId),
|
|
230
|
+
apiToken: this.authToken,
|
|
231
|
+
customFetch: this.customFetch,
|
|
232
|
+
requestId: requestId,
|
|
233
|
+
});
|
|
234
|
+
return response.data ? (0, validators_1.validateAppWebhook)(response.data) : null;
|
|
235
|
+
}
|
|
236
|
+
async updateAppWebhook(args, requestId) {
|
|
237
|
+
const { appId, events } = args, rest = __rest(args, ["appId", "events"]);
|
|
238
|
+
const response = await (0, http_client_1.request)({
|
|
239
|
+
httpMethod: 'POST',
|
|
240
|
+
baseUri: this.apiRootBase,
|
|
241
|
+
relativePath: (0, endpoints_1.getAppWebhookEndpoint)(appId),
|
|
242
|
+
apiToken: this.authToken,
|
|
243
|
+
customFetch: this.customFetch,
|
|
244
|
+
payload: Object.assign(Object.assign({}, rest), { events: events.map(apps_1.webhookEventToWireName) }),
|
|
245
|
+
requestId: requestId,
|
|
246
|
+
});
|
|
247
|
+
return (0, validators_1.validateAppWebhook)(response.data);
|
|
248
|
+
}
|
|
249
|
+
async deleteAppWebhook(appId, requestId) {
|
|
250
|
+
zod_1.z.string().parse(appId);
|
|
251
|
+
const response = await (0, http_client_1.request)({
|
|
252
|
+
httpMethod: 'DELETE',
|
|
253
|
+
baseUri: this.apiRootBase,
|
|
254
|
+
relativePath: (0, endpoints_1.getAppWebhookEndpoint)(appId),
|
|
255
|
+
apiToken: this.authToken,
|
|
256
|
+
customFetch: this.customFetch,
|
|
257
|
+
requestId: requestId,
|
|
258
|
+
});
|
|
259
|
+
return (0, http_client_1.isSuccess)(response);
|
|
260
|
+
}
|
|
261
|
+
// --- App installations ---
|
|
262
|
+
async getAppInstallations(requestId) {
|
|
263
|
+
const response = await (0, http_client_1.request)({
|
|
264
|
+
httpMethod: 'GET',
|
|
265
|
+
baseUri: this.apiRootBase,
|
|
266
|
+
relativePath: endpoints_1.ENDPOINT_REST_APPS_INSTALLATIONS,
|
|
267
|
+
apiToken: this.authToken,
|
|
268
|
+
customFetch: this.customFetch,
|
|
269
|
+
requestId: requestId,
|
|
270
|
+
});
|
|
271
|
+
return (0, validators_1.validateAppInstallationArray)(response.data);
|
|
272
|
+
}
|
|
273
|
+
async installApp(args, requestId) {
|
|
274
|
+
const response = await (0, http_client_1.request)({
|
|
275
|
+
httpMethod: 'POST',
|
|
276
|
+
baseUri: this.apiRootBase,
|
|
277
|
+
relativePath: endpoints_1.ENDPOINT_REST_APPS_INSTALLATIONS,
|
|
278
|
+
apiToken: this.authToken,
|
|
279
|
+
customFetch: this.customFetch,
|
|
280
|
+
payload: args,
|
|
281
|
+
requestId: requestId,
|
|
282
|
+
});
|
|
283
|
+
return (0, validators_1.validateAppInstallation)(response.data);
|
|
284
|
+
}
|
|
285
|
+
async getAppInstallation(installationId, requestId) {
|
|
286
|
+
zod_1.z.string().parse(installationId);
|
|
287
|
+
const response = await (0, http_client_1.request)({
|
|
288
|
+
httpMethod: 'GET',
|
|
289
|
+
baseUri: this.apiRootBase,
|
|
290
|
+
relativePath: (0, endpoints_1.getAppInstallationEndpoint)(installationId),
|
|
291
|
+
apiToken: this.authToken,
|
|
292
|
+
customFetch: this.customFetch,
|
|
293
|
+
requestId: requestId,
|
|
294
|
+
});
|
|
295
|
+
return (0, validators_1.validateAppInstallation)(response.data);
|
|
296
|
+
}
|
|
297
|
+
async updateAppInstallation(installationId, args, requestId) {
|
|
298
|
+
zod_1.z.string().parse(installationId);
|
|
299
|
+
const response = await (0, http_client_1.request)({
|
|
300
|
+
httpMethod: 'POST',
|
|
301
|
+
baseUri: this.apiRootBase,
|
|
302
|
+
relativePath: (0, endpoints_1.getAppInstallationEndpoint)(installationId),
|
|
303
|
+
apiToken: this.authToken,
|
|
304
|
+
customFetch: this.customFetch,
|
|
305
|
+
payload: args,
|
|
306
|
+
requestId: requestId,
|
|
307
|
+
});
|
|
308
|
+
return (0, validators_1.validateAppInstallation)(response.data);
|
|
309
|
+
}
|
|
310
|
+
async uninstallApp(installationId, requestId) {
|
|
311
|
+
zod_1.z.string().parse(installationId);
|
|
312
|
+
const response = await (0, http_client_1.request)({
|
|
313
|
+
httpMethod: 'DELETE',
|
|
314
|
+
baseUri: this.apiRootBase,
|
|
315
|
+
relativePath: (0, endpoints_1.getAppInstallationEndpoint)(installationId),
|
|
316
|
+
apiToken: this.authToken,
|
|
317
|
+
customFetch: this.customFetch,
|
|
318
|
+
requestId: requestId,
|
|
319
|
+
});
|
|
320
|
+
return (0, http_client_1.isSuccess)(response);
|
|
321
|
+
}
|
|
322
|
+
// --- User authorizations ---
|
|
323
|
+
async getUserAuthorizations(requestId) {
|
|
324
|
+
const response = await (0, http_client_1.request)({
|
|
325
|
+
httpMethod: 'GET',
|
|
326
|
+
baseUri: this.apiRootBase,
|
|
327
|
+
relativePath: endpoints_1.ENDPOINT_REST_USER_AUTHORIZATIONS,
|
|
328
|
+
apiToken: this.authToken,
|
|
329
|
+
customFetch: this.customFetch,
|
|
330
|
+
requestId: requestId,
|
|
331
|
+
});
|
|
332
|
+
return (0, validators_1.validateUserAuthorizationArray)(response.data);
|
|
333
|
+
}
|
|
334
|
+
async revokeUserAuthorization(args, requestId) {
|
|
335
|
+
const response = await (0, http_client_1.request)({
|
|
336
|
+
httpMethod: 'POST',
|
|
337
|
+
baseUri: this.apiRootBase,
|
|
338
|
+
relativePath: endpoints_1.ENDPOINT_REST_USER_AUTHORIZATIONS_DELETE,
|
|
339
|
+
apiToken: this.authToken,
|
|
340
|
+
customFetch: this.customFetch,
|
|
341
|
+
payload: args,
|
|
342
|
+
requestId: requestId,
|
|
343
|
+
});
|
|
344
|
+
return (0, http_client_1.isSuccess)(response);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
exports.AppClient = AppClient;
|
|
@@ -17,6 +17,7 @@ class BaseClient {
|
|
|
17
17
|
constructor(context) {
|
|
18
18
|
this.authToken = context.authToken;
|
|
19
19
|
this.syncApiBase = context.syncApiBase;
|
|
20
|
+
this.apiRootBase = new URL('/', context.syncApiBase).toString();
|
|
20
21
|
this.customFetch = context.customFetch;
|
|
21
22
|
}
|
|
22
23
|
get syncContext() {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UiExtensionClient = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
6
|
+
const http_client_1 = require("../transport/http-client");
|
|
7
|
+
const case_conversion_1 = require("../utils/case-conversion");
|
|
8
|
+
const multipart_upload_1 = require("../utils/multipart-upload");
|
|
9
|
+
const validators_1 = require("../utils/validators");
|
|
10
|
+
const base_client_1 = require("./base-client");
|
|
11
|
+
/**
|
|
12
|
+
* Internal sub-client handling all UI-extension endpoints for developer
|
|
13
|
+
* applications. All endpoints require the `dev:app_console` OAuth scope.
|
|
14
|
+
*
|
|
15
|
+
* Instantiated by `TodoistApi`; every public UI-extension method on
|
|
16
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing JSDoc.
|
|
17
|
+
*/
|
|
18
|
+
class UiExtensionClient extends base_client_1.BaseClient {
|
|
19
|
+
async getUiExtension(uiExtensionId, requestId) {
|
|
20
|
+
zod_1.z.string().parse(uiExtensionId);
|
|
21
|
+
const response = await (0, http_client_1.request)({
|
|
22
|
+
httpMethod: 'GET',
|
|
23
|
+
baseUri: this.apiRootBase,
|
|
24
|
+
relativePath: (0, endpoints_1.getUiExtensionEndpoint)(uiExtensionId),
|
|
25
|
+
apiToken: this.authToken,
|
|
26
|
+
customFetch: this.customFetch,
|
|
27
|
+
requestId: requestId,
|
|
28
|
+
});
|
|
29
|
+
return (0, validators_1.validateUiExtension)(response.data);
|
|
30
|
+
}
|
|
31
|
+
async getInstalledUiExtensions(requestId) {
|
|
32
|
+
const response = await (0, http_client_1.request)({
|
|
33
|
+
httpMethod: 'GET',
|
|
34
|
+
baseUri: this.apiRootBase,
|
|
35
|
+
relativePath: endpoints_1.ENDPOINT_REST_APPS_UI_EXTENSIONS_INSTALLED,
|
|
36
|
+
apiToken: this.authToken,
|
|
37
|
+
customFetch: this.customFetch,
|
|
38
|
+
requestId: requestId,
|
|
39
|
+
});
|
|
40
|
+
return (0, validators_1.validateUiExtensionArray)(response.data);
|
|
41
|
+
}
|
|
42
|
+
async getUiExtensionsForApp(appId, requestId) {
|
|
43
|
+
zod_1.z.string().parse(appId);
|
|
44
|
+
const response = await (0, http_client_1.request)({
|
|
45
|
+
httpMethod: 'GET',
|
|
46
|
+
baseUri: this.apiRootBase,
|
|
47
|
+
relativePath: (0, endpoints_1.getUiExtensionsByIntegrationEndpoint)(appId),
|
|
48
|
+
apiToken: this.authToken,
|
|
49
|
+
customFetch: this.customFetch,
|
|
50
|
+
requestId: requestId,
|
|
51
|
+
});
|
|
52
|
+
return (0, validators_1.validateUiExtensionArray)(response.data);
|
|
53
|
+
}
|
|
54
|
+
async addUiExtension(args, requestId) {
|
|
55
|
+
const response = await (0, http_client_1.request)({
|
|
56
|
+
httpMethod: 'POST',
|
|
57
|
+
baseUri: this.apiRootBase,
|
|
58
|
+
relativePath: endpoints_1.ENDPOINT_REST_APPS_UI_EXTENSIONS,
|
|
59
|
+
apiToken: this.authToken,
|
|
60
|
+
customFetch: this.customFetch,
|
|
61
|
+
payload: args,
|
|
62
|
+
requestId: requestId,
|
|
63
|
+
});
|
|
64
|
+
return (0, validators_1.validateUiExtension)(response.data);
|
|
65
|
+
}
|
|
66
|
+
async updateUiExtension(uiExtensionId, args, requestId) {
|
|
67
|
+
zod_1.z.string().parse(uiExtensionId);
|
|
68
|
+
const response = await (0, http_client_1.request)({
|
|
69
|
+
httpMethod: 'PATCH',
|
|
70
|
+
baseUri: this.apiRootBase,
|
|
71
|
+
relativePath: (0, endpoints_1.getUiExtensionEndpoint)(uiExtensionId),
|
|
72
|
+
apiToken: this.authToken,
|
|
73
|
+
customFetch: this.customFetch,
|
|
74
|
+
payload: args,
|
|
75
|
+
requestId: requestId,
|
|
76
|
+
});
|
|
77
|
+
return (0, validators_1.validateUiExtension)(response.data);
|
|
78
|
+
}
|
|
79
|
+
async deleteUiExtension(uiExtensionId, requestId) {
|
|
80
|
+
zod_1.z.string().parse(uiExtensionId);
|
|
81
|
+
const response = await (0, http_client_1.request)({
|
|
82
|
+
httpMethod: 'DELETE',
|
|
83
|
+
baseUri: this.apiRootBase,
|
|
84
|
+
relativePath: (0, endpoints_1.getUiExtensionEndpoint)(uiExtensionId),
|
|
85
|
+
apiToken: this.authToken,
|
|
86
|
+
customFetch: this.customFetch,
|
|
87
|
+
requestId: requestId,
|
|
88
|
+
});
|
|
89
|
+
return (0, http_client_1.isSuccess)(response);
|
|
90
|
+
}
|
|
91
|
+
async uploadUiExtensionIcon(args, requestId) {
|
|
92
|
+
var _a;
|
|
93
|
+
if (Buffer.isBuffer(args.file) && args.file.length === 0) {
|
|
94
|
+
throw new Error('Cannot upload empty image file');
|
|
95
|
+
}
|
|
96
|
+
const data = await (0, multipart_upload_1.uploadMultipartFile)({
|
|
97
|
+
baseUrl: this.apiRootBase,
|
|
98
|
+
authToken: this.authToken,
|
|
99
|
+
endpoint: (0, endpoints_1.getUiExtensionIconEndpoint)(args.uiExtensionId),
|
|
100
|
+
file: args.file,
|
|
101
|
+
fileName: args.fileName,
|
|
102
|
+
additionalFields: { file_name: (_a = args.fileName) !== null && _a !== void 0 ? _a : '' },
|
|
103
|
+
requestId: requestId,
|
|
104
|
+
customFetch: this.customFetch,
|
|
105
|
+
});
|
|
106
|
+
return (0, validators_1.validateUiExtension)((0, case_conversion_1.camelCaseKeys)(data));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
exports.UiExtensionClient = UiExtensionClient;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ENDPOINT_REST_ID_MAPPINGS = exports.ENDPOINT_REST_EMAILS = exports.ENDPOINT_REST_BACKUPS_DOWNLOAD = exports.ENDPOINT_REST_BACKUPS = exports.ENDPOINT_REST_ACCESS_TOKENS_MIGRATE = exports.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_ID = exports.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_FILE = exports.ENDPOINT_REST_TEMPLATES_CREATE_FROM_FILE = exports.ENDPOINT_REST_TEMPLATES_URL = exports.ENDPOINT_REST_TEMPLATES_FILE = exports.ENDPOINT_REST_TASKS_COMPLETED = exports.ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL = exports.ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE = exports.SECTION_UNARCHIVE = exports.SECTION_ARCHIVE = exports.ENDPOINT_REST_PROJECT_JOIN = exports.ENDPOINT_REST_PROJECT_FULL = exports.ENDPOINT_REST_PROJECTS_PERMISSIONS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED_COUNT = exports.PROJECT_UNARCHIVE = exports.PROJECT_ARCHIVE = exports.ENDPOINT_REST_UPLOADS = exports.ENDPOINT_REST_ACTIVITIES = exports.ENDPOINT_REST_PRODUCTIVITY = exports.ENDPOINT_REST_USER = exports.ENDPOINT_REST_PROJECT_COLLABORATORS = exports.ENDPOINT_REST_PROJECTS_ARCHIVED = exports.ENDPOINT_REST_PROJECTS_SEARCH = exports.ENDPOINT_REST_PROJECTS = exports.ENDPOINT_REST_TASK_MOVE = exports.ENDPOINT_REST_TASK_REOPEN = exports.ENDPOINT_REST_TASK_CLOSE = exports.ENDPOINT_REST_LOCATION_REMINDERS = exports.ENDPOINT_REST_REMINDERS = exports.ENDPOINT_REST_COMMENTS = exports.ENDPOINT_REST_LABELS_SHARED_REMOVE = exports.ENDPOINT_REST_LABELS_SHARED_RENAME = exports.ENDPOINT_REST_LABELS_SHARED = exports.ENDPOINT_REST_LABELS_SEARCH = exports.ENDPOINT_REST_LABELS = exports.ENDPOINT_REST_SECTIONS_SEARCH = exports.ENDPOINT_REST_SECTIONS = exports.ENDPOINT_REST_TASKS_COMPLETED_SEARCH = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE = exports.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE = exports.ENDPOINT_REST_TASKS_FILTER = exports.ENDPOINT_REST_TASKS = exports.API_BASE_URI = exports.API_VERSION = exports.TODOIST_WEB_URI = void 0;
|
|
4
|
-
exports.
|
|
4
|
+
exports.APP_ICON_SIZES = exports.ENDPOINT_REST_USER_AUTHORIZATIONS_DELETE = exports.ENDPOINT_REST_USER_AUTHORIZATIONS = exports.ENDPOINT_REST_APPS_UI_EXTENSIONS_INSTALLED = exports.ENDPOINT_REST_APPS_UI_EXTENSIONS = exports.ENDPOINT_REST_APPS_INSTALLATIONS = exports.ENDPOINT_REST_APPS = exports.ENDPOINT_WORKSPACE_MEMBERS = exports.ENDPOINT_WORKSPACE_USERS = exports.ENDPOINT_WORKSPACE_PLAN_DETAILS = exports.ENDPOINT_WORKSPACE_LOGO = exports.ENDPOINT_WORKSPACE_JOIN = exports.ENDPOINT_WORKSPACE_INVITATIONS_DELETE = exports.ENDPOINT_WORKSPACE_INVITATIONS_ALL = exports.ENDPOINT_WORKSPACE_INVITATIONS = exports.ENDPOINT_REST_WORKSPACES = exports.ENDPOINT_REST_FOLDERS = exports.ENDPOINT_REGISTER = exports.ENDPOINT_REVOKE = exports.ENDPOINT_GET_TOKEN = exports.ENDPOINT_AUTHORIZATION = exports.ENDPOINT_SYNC = exports.ENDPOINT_SYNC_QUICK_ADD = exports.ENDPOINT_REST_MOVED_IDS = void 0;
|
|
5
5
|
exports.getSyncBaseUri = getSyncBaseUri;
|
|
6
|
+
exports.getApiRootBaseUri = getApiRootBaseUri;
|
|
6
7
|
exports.getAuthBaseUri = getAuthBaseUri;
|
|
7
8
|
exports.getWorkspaceInvitationAcceptEndpoint = getWorkspaceInvitationAcceptEndpoint;
|
|
8
9
|
exports.getWorkspaceInvitationRejectEndpoint = getWorkspaceInvitationRejectEndpoint;
|
|
@@ -17,6 +18,20 @@ exports.getWorkspaceInviteUsersEndpoint = getWorkspaceInviteUsersEndpoint;
|
|
|
17
18
|
exports.getWorkspaceUserEndpoint = getWorkspaceUserEndpoint;
|
|
18
19
|
exports.getWorkspaceActiveProjectsEndpoint = getWorkspaceActiveProjectsEndpoint;
|
|
19
20
|
exports.getWorkspaceArchivedProjectsEndpoint = getWorkspaceArchivedProjectsEndpoint;
|
|
21
|
+
exports.getAppEndpoint = getAppEndpoint;
|
|
22
|
+
exports.getAppSecretsEndpoint = getAppSecretsEndpoint;
|
|
23
|
+
exports.getAppClientSecretEndpoint = getAppClientSecretEndpoint;
|
|
24
|
+
exports.getAppTokensEndpoint = getAppTokensEndpoint;
|
|
25
|
+
exports.getAppTestTokenEndpoint = getAppTestTokenEndpoint;
|
|
26
|
+
exports.getAppDistributionTokenEndpoint = getAppDistributionTokenEndpoint;
|
|
27
|
+
exports.getAppVerificationTokenEndpoint = getAppVerificationTokenEndpoint;
|
|
28
|
+
exports.getAppWebhookEndpoint = getAppWebhookEndpoint;
|
|
29
|
+
exports.getAppIconEndpoint = getAppIconEndpoint;
|
|
30
|
+
exports.getAppInstallationEndpoint = getAppInstallationEndpoint;
|
|
31
|
+
exports.getAppByDistributionTokenEndpoint = getAppByDistributionTokenEndpoint;
|
|
32
|
+
exports.getUiExtensionEndpoint = getUiExtensionEndpoint;
|
|
33
|
+
exports.getUiExtensionIconEndpoint = getUiExtensionIconEndpoint;
|
|
34
|
+
exports.getUiExtensionsByIntegrationEndpoint = getUiExtensionsByIntegrationEndpoint;
|
|
20
35
|
const BASE_URI = 'https://api.todoist.com';
|
|
21
36
|
const TODOIST_URI = 'https://todoist.com';
|
|
22
37
|
exports.TODOIST_WEB_URI = 'https://app.todoist.com/app';
|
|
@@ -28,6 +43,9 @@ const API_AUTHORIZATION_BASE_URI = '/oauth/';
|
|
|
28
43
|
function getSyncBaseUri(domainBase = BASE_URI) {
|
|
29
44
|
return new URL(exports.API_BASE_URI, domainBase).toString();
|
|
30
45
|
}
|
|
46
|
+
function getApiRootBaseUri(domainBase = BASE_URI) {
|
|
47
|
+
return new URL('/', domainBase).toString();
|
|
48
|
+
}
|
|
31
49
|
function getAuthBaseUri(domainBase = TODOIST_URI) {
|
|
32
50
|
return new URL(API_AUTHORIZATION_BASE_URI, domainBase).toString();
|
|
33
51
|
}
|
|
@@ -86,11 +104,6 @@ exports.ENDPOINT_GET_TOKEN = 'access_token';
|
|
|
86
104
|
exports.ENDPOINT_REVOKE = 'revoke';
|
|
87
105
|
exports.ENDPOINT_REGISTER = 'register';
|
|
88
106
|
exports.ENDPOINT_REST_FOLDERS = 'folders';
|
|
89
|
-
exports.ENDPOINT_REST_GOALS = 'goals';
|
|
90
|
-
exports.ENDPOINT_REST_GOALS_SEARCH = exports.ENDPOINT_REST_GOALS + '/search';
|
|
91
|
-
exports.GOAL_COMPLETE = 'complete';
|
|
92
|
-
exports.GOAL_UNCOMPLETE = 'uncomplete';
|
|
93
|
-
exports.GOAL_TASKS = 'items';
|
|
94
107
|
// Workspace endpoints
|
|
95
108
|
exports.ENDPOINT_REST_WORKSPACES = 'workspaces';
|
|
96
109
|
exports.ENDPOINT_WORKSPACE_INVITATIONS = 'workspaces/invitations';
|
|
@@ -145,3 +158,54 @@ function getWorkspaceActiveProjectsEndpoint(workspaceId) {
|
|
|
145
158
|
function getWorkspaceArchivedProjectsEndpoint(workspaceId) {
|
|
146
159
|
return `workspaces/${workspaceId}/projects/archived`;
|
|
147
160
|
}
|
|
161
|
+
// App management endpoints (dev:app_console scope)
|
|
162
|
+
exports.ENDPOINT_REST_APPS = 'apps';
|
|
163
|
+
exports.ENDPOINT_REST_APPS_INSTALLATIONS = 'apps/installations';
|
|
164
|
+
exports.ENDPOINT_REST_APPS_UI_EXTENSIONS = 'apps/ui_extensions';
|
|
165
|
+
exports.ENDPOINT_REST_APPS_UI_EXTENSIONS_INSTALLED = 'apps/ui_extensions/installed';
|
|
166
|
+
exports.ENDPOINT_REST_USER_AUTHORIZATIONS = 'user/authorizations';
|
|
167
|
+
exports.ENDPOINT_REST_USER_AUTHORIZATIONS_DELETE = 'user/authorizations/delete';
|
|
168
|
+
/** Available app icon sizes (small 60x60, medium 300x300, large 600x600). */
|
|
169
|
+
exports.APP_ICON_SIZES = ['small', 'medium', 'large'];
|
|
170
|
+
function getAppEndpoint(appId) {
|
|
171
|
+
return `apps/${appId}`;
|
|
172
|
+
}
|
|
173
|
+
function getAppSecretsEndpoint(appId) {
|
|
174
|
+
return `apps/${appId}/secrets`;
|
|
175
|
+
}
|
|
176
|
+
function getAppClientSecretEndpoint(appId) {
|
|
177
|
+
return `apps/${appId}/client_secret`;
|
|
178
|
+
}
|
|
179
|
+
function getAppTokensEndpoint(appId) {
|
|
180
|
+
return `apps/${appId}/tokens`;
|
|
181
|
+
}
|
|
182
|
+
function getAppTestTokenEndpoint(appId) {
|
|
183
|
+
return `apps/${appId}/test_token`;
|
|
184
|
+
}
|
|
185
|
+
function getAppDistributionTokenEndpoint(appId) {
|
|
186
|
+
return `apps/${appId}/distribution_token`;
|
|
187
|
+
}
|
|
188
|
+
function getAppVerificationTokenEndpoint(appId) {
|
|
189
|
+
return `apps/${appId}/verification_token`;
|
|
190
|
+
}
|
|
191
|
+
function getAppWebhookEndpoint(appId) {
|
|
192
|
+
return `apps/${appId}/webhook`;
|
|
193
|
+
}
|
|
194
|
+
function getAppIconEndpoint(appId, size) {
|
|
195
|
+
return size === 'medium' ? `apps/${appId}/icon` : `apps/${appId}/icon/${size}`;
|
|
196
|
+
}
|
|
197
|
+
function getAppInstallationEndpoint(installationId) {
|
|
198
|
+
return `apps/installations/${installationId}`;
|
|
199
|
+
}
|
|
200
|
+
function getAppByDistributionTokenEndpoint(distributionToken) {
|
|
201
|
+
return `apps/by_distribution_token/${distributionToken}`;
|
|
202
|
+
}
|
|
203
|
+
function getUiExtensionEndpoint(uiExtensionId) {
|
|
204
|
+
return `apps/ui_extensions/${uiExtensionId}`;
|
|
205
|
+
}
|
|
206
|
+
function getUiExtensionIconEndpoint(uiExtensionId) {
|
|
207
|
+
return `apps/ui_extensions/${uiExtensionId}/icon`;
|
|
208
|
+
}
|
|
209
|
+
function getUiExtensionsByIntegrationEndpoint(integrationId) {
|
|
210
|
+
return `apps/ui_extensions/integration/${integrationId}`;
|
|
211
|
+
}
|