@doist/todoist-sdk 9.1.0-next.1 → 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 -6
- package/dist/cjs/test-utils/test-defaults.js +77 -1
- package/dist/cjs/todoist-api.js +422 -1665
- package/dist/cjs/transport/http-client.js +1 -0
- package/dist/cjs/transport/sync-request.js +75 -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/headers.js +16 -0
- package/dist/cjs/utils/request-helpers.js +21 -0
- package/dist/cjs/utils/validators.js +45 -33
- 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 -5
- package/dist/esm/test-utils/test-defaults.js +75 -0
- package/dist/esm/todoist-api.js +425 -1668
- package/dist/esm/transport/http-client.js +1 -0
- package/dist/esm/transport/sync-request.js +72 -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/headers.js +13 -0
- package/dist/esm/utils/request-helpers.js +17 -0
- package/dist/esm/utils/validators.js +14 -2
- 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 -5
- package/dist/types/test-utils/test-defaults.d.ts +16 -1
- package/dist/types/todoist-api.d.ts +238 -28
- 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 -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/headers.d.ts +7 -0
- package/dist/types/utils/request-helpers.d.ts +13 -0
- package/dist/types/utils/validators.d.ts +231 -55
- package/package.json +1 -1
- package/dist/cjs/types/goals/types.js +0 -29
- package/dist/esm/types/goals/types.js +0 -26
- package/dist/types/types/goals/requests.d.ts +0 -33
- package/dist/types/types/goals/types.d.ts +0 -41
- 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,63 @@
|
|
|
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.ActivityClient = void 0;
|
|
15
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
16
|
+
const http_client_1 = require("../transport/http-client");
|
|
17
|
+
const activity_helpers_1 = require("../utils/activity-helpers");
|
|
18
|
+
const url_helpers_1 = require("../utils/url-helpers");
|
|
19
|
+
const validators_1 = require("../utils/validators");
|
|
20
|
+
const base_client_1 = require("./base-client");
|
|
21
|
+
/**
|
|
22
|
+
* Internal sub-client handling the activity-log endpoint.
|
|
23
|
+
*
|
|
24
|
+
* Instantiated by `TodoistApi`; the public `getActivityLogs` method on
|
|
25
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
26
|
+
* JSDoc.
|
|
27
|
+
*/
|
|
28
|
+
class ActivityClient extends base_client_1.BaseClient {
|
|
29
|
+
async getActivityLogs(args = {}) {
|
|
30
|
+
// Convert Date objects to YYYY-MM-DD strings
|
|
31
|
+
const dateFrom = args.dateFrom instanceof Date ? (0, url_helpers_1.formatDateToYYYYMMDD)(args.dateFrom) : args.dateFrom;
|
|
32
|
+
const dateTo = args.dateTo instanceof Date ? (0, url_helpers_1.formatDateToYYYYMMDD)(args.dateTo) : args.dateTo;
|
|
33
|
+
// Destructure out raw date, filter-type, and removed legacy fields so they don't leak into payload
|
|
34
|
+
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"]);
|
|
35
|
+
// Build normalized objectEventTypes for the API
|
|
36
|
+
let normalizedObjectEventTypes;
|
|
37
|
+
if (objectEventTypes !== undefined) {
|
|
38
|
+
const arr = Array.isArray(objectEventTypes) ? objectEventTypes : [objectEventTypes];
|
|
39
|
+
normalizedObjectEventTypes = arr.map(activity_helpers_1.normalizeObjectEventTypeForApi);
|
|
40
|
+
}
|
|
41
|
+
const processedArgs = Object.assign(Object.assign(Object.assign(Object.assign({}, rest), (dateFrom !== undefined ? { dateFrom } : {})), (dateTo !== undefined ? { dateTo } : {})), (normalizedObjectEventTypes !== undefined
|
|
42
|
+
? { objectEventTypes: normalizedObjectEventTypes }
|
|
43
|
+
: {}));
|
|
44
|
+
const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
|
|
45
|
+
httpMethod: 'GET',
|
|
46
|
+
baseUri: this.syncApiBase,
|
|
47
|
+
relativePath: endpoints_1.ENDPOINT_REST_ACTIVITIES,
|
|
48
|
+
apiToken: this.authToken,
|
|
49
|
+
customFetch: this.customFetch,
|
|
50
|
+
payload: processedArgs,
|
|
51
|
+
});
|
|
52
|
+
// Convert legacy API object types back to modern SDK types
|
|
53
|
+
const normalizedResults = results.map((event) => {
|
|
54
|
+
const normalizedType = (0, activity_helpers_1.denormalizeObjectTypeFromApi)(event.objectType);
|
|
55
|
+
return Object.assign(Object.assign({}, event), { objectType: normalizedType || event.objectType });
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
results: (0, validators_1.validateActivityEventArray)(normalizedResults),
|
|
59
|
+
nextCursor,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ActivityClient = ActivityClient;
|
|
@@ -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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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.syncApiBase,
|
|
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;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BackupClient = void 0;
|
|
4
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
5
|
+
const http_client_1 = require("../transport/http-client");
|
|
6
|
+
const headers_1 = require("../utils/headers");
|
|
7
|
+
const validators_1 = require("../utils/validators");
|
|
8
|
+
const base_client_1 = require("./base-client");
|
|
9
|
+
/**
|
|
10
|
+
* Internal sub-client handling backup-domain endpoints.
|
|
11
|
+
*
|
|
12
|
+
* Instantiated by `TodoistApi`; every public backup method on
|
|
13
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
14
|
+
* JSDoc.
|
|
15
|
+
*/
|
|
16
|
+
class BackupClient extends base_client_1.BaseClient {
|
|
17
|
+
async getBackups(args = {}) {
|
|
18
|
+
const response = await (0, http_client_1.request)({
|
|
19
|
+
httpMethod: 'GET',
|
|
20
|
+
baseUri: this.syncApiBase,
|
|
21
|
+
relativePath: endpoints_1.ENDPOINT_REST_BACKUPS,
|
|
22
|
+
apiToken: this.authToken,
|
|
23
|
+
customFetch: this.customFetch,
|
|
24
|
+
payload: args,
|
|
25
|
+
});
|
|
26
|
+
return (0, validators_1.validateBackupArray)(response.data);
|
|
27
|
+
}
|
|
28
|
+
async downloadBackup(args) {
|
|
29
|
+
const url = `${this.syncApiBase}${endpoints_1.ENDPOINT_REST_BACKUPS_DOWNLOAD}?file=${encodeURIComponent(args.file)}`;
|
|
30
|
+
const fetchOptions = {
|
|
31
|
+
headers: { Authorization: `Bearer ${this.authToken}` },
|
|
32
|
+
};
|
|
33
|
+
if (this.customFetch) {
|
|
34
|
+
const response = await this.customFetch(url, fetchOptions);
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
throw new Error(`Failed to download backup: ${response.status} ${response.statusText}`);
|
|
37
|
+
}
|
|
38
|
+
const text = await response.text();
|
|
39
|
+
const buffer = new TextEncoder().encode(text).buffer;
|
|
40
|
+
return {
|
|
41
|
+
ok: response.ok,
|
|
42
|
+
status: response.status,
|
|
43
|
+
statusText: response.statusText,
|
|
44
|
+
headers: response.headers,
|
|
45
|
+
text: () => Promise.resolve(text),
|
|
46
|
+
json: () => response.json(),
|
|
47
|
+
arrayBuffer: () => Promise.resolve(buffer),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const response = await fetch(url, fetchOptions);
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
throw new Error(`Failed to download backup: ${response.status} ${response.statusText}`);
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
ok: response.ok,
|
|
56
|
+
status: response.status,
|
|
57
|
+
statusText: response.statusText,
|
|
58
|
+
headers: (0, headers_1.headersToRecord)(response.headers),
|
|
59
|
+
text: () => response.text(),
|
|
60
|
+
json: () => response.json(),
|
|
61
|
+
arrayBuffer: () => response.arrayBuffer(),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.BackupClient = BackupClient;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseClient = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Internal base class for every domain sub-client (tasks, projects, …).
|
|
6
|
+
*
|
|
7
|
+
* Not exported from the package — sub-clients are an implementation detail
|
|
8
|
+
* of `TodoistApi`. Holds the three pieces of HTTP identity every sub-client
|
|
9
|
+
* needs and exposes a typed accessor to feed the Sync API helper.
|
|
10
|
+
*
|
|
11
|
+
* The constructor takes a {@link SyncRequestContext} — the same record
|
|
12
|
+
* shape used by `performSyncRequest` — so there is a single type describing
|
|
13
|
+
* "the HTTP identity an SDK component needs", not two types that must stay
|
|
14
|
+
* in sync.
|
|
15
|
+
*/
|
|
16
|
+
class BaseClient {
|
|
17
|
+
constructor(context) {
|
|
18
|
+
this.authToken = context.authToken;
|
|
19
|
+
this.syncApiBase = context.syncApiBase;
|
|
20
|
+
this.customFetch = context.customFetch;
|
|
21
|
+
}
|
|
22
|
+
get syncContext() {
|
|
23
|
+
return {
|
|
24
|
+
authToken: this.authToken,
|
|
25
|
+
syncApiBase: this.syncApiBase,
|
|
26
|
+
customFetch: this.customFetch,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.BaseClient = BaseClient;
|
|
@@ -0,0 +1,92 @@
|
|
|
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.CommentClient = 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 request_helpers_1 = require("../utils/request-helpers");
|
|
19
|
+
const validators_1 = require("../utils/validators");
|
|
20
|
+
const base_client_1 = require("./base-client");
|
|
21
|
+
/**
|
|
22
|
+
* Internal sub-client handling all comment-domain endpoints.
|
|
23
|
+
*
|
|
24
|
+
* Instantiated by `TodoistApi`; every public comment method on `TodoistApi`
|
|
25
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
26
|
+
*/
|
|
27
|
+
class CommentClient extends base_client_1.BaseClient {
|
|
28
|
+
async getComments(args) {
|
|
29
|
+
const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
|
|
30
|
+
httpMethod: 'GET',
|
|
31
|
+
baseUri: this.syncApiBase,
|
|
32
|
+
relativePath: endpoints_1.ENDPOINT_REST_COMMENTS,
|
|
33
|
+
apiToken: this.authToken,
|
|
34
|
+
customFetch: this.customFetch,
|
|
35
|
+
payload: args,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
results: (0, validators_1.validateCommentArray)(results),
|
|
39
|
+
nextCursor,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async getComment(id) {
|
|
43
|
+
zod_1.z.string().parse(id);
|
|
44
|
+
const response = await (0, http_client_1.request)({
|
|
45
|
+
httpMethod: 'GET',
|
|
46
|
+
baseUri: this.syncApiBase,
|
|
47
|
+
relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_COMMENTS, id),
|
|
48
|
+
apiToken: this.authToken,
|
|
49
|
+
customFetch: this.customFetch,
|
|
50
|
+
});
|
|
51
|
+
return (0, validators_1.validateComment)(response.data);
|
|
52
|
+
}
|
|
53
|
+
async addComment(args, requestId) {
|
|
54
|
+
const { uidsToNotify } = args, rest = __rest(args, ["uidsToNotify"]);
|
|
55
|
+
const response = await (0, http_client_1.request)({
|
|
56
|
+
httpMethod: 'POST',
|
|
57
|
+
baseUri: this.syncApiBase,
|
|
58
|
+
relativePath: endpoints_1.ENDPOINT_REST_COMMENTS,
|
|
59
|
+
apiToken: this.authToken,
|
|
60
|
+
customFetch: this.customFetch,
|
|
61
|
+
payload: Object.assign(Object.assign({}, rest), (uidsToNotify ? { uidsToNotify: uidsToNotify.join(',') } : {})),
|
|
62
|
+
requestId: requestId,
|
|
63
|
+
});
|
|
64
|
+
return (0, validators_1.validateComment)(response.data);
|
|
65
|
+
}
|
|
66
|
+
async updateComment(id, args, requestId) {
|
|
67
|
+
zod_1.z.string().parse(id);
|
|
68
|
+
const response = await (0, http_client_1.request)({
|
|
69
|
+
httpMethod: 'POST',
|
|
70
|
+
baseUri: this.syncApiBase,
|
|
71
|
+
relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_COMMENTS, id),
|
|
72
|
+
apiToken: this.authToken,
|
|
73
|
+
customFetch: this.customFetch,
|
|
74
|
+
payload: args,
|
|
75
|
+
requestId: requestId,
|
|
76
|
+
});
|
|
77
|
+
return (0, validators_1.validateComment)(response.data);
|
|
78
|
+
}
|
|
79
|
+
async deleteComment(id, requestId) {
|
|
80
|
+
zod_1.z.string().parse(id);
|
|
81
|
+
const response = await (0, http_client_1.request)({
|
|
82
|
+
httpMethod: 'DELETE',
|
|
83
|
+
baseUri: this.syncApiBase,
|
|
84
|
+
relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_COMMENTS, id),
|
|
85
|
+
apiToken: this.authToken,
|
|
86
|
+
customFetch: this.customFetch,
|
|
87
|
+
requestId: requestId,
|
|
88
|
+
});
|
|
89
|
+
return (0, http_client_1.isSuccess)(response);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.CommentClient = CommentClient;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EmailClient = void 0;
|
|
4
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
5
|
+
const http_client_1 = require("../transport/http-client");
|
|
6
|
+
const base_client_1 = require("./base-client");
|
|
7
|
+
/**
|
|
8
|
+
* Internal sub-client handling email-forwarding endpoints.
|
|
9
|
+
*
|
|
10
|
+
* Instantiated by `TodoistApi`; every public email-forwarding method on
|
|
11
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
12
|
+
* JSDoc.
|
|
13
|
+
*/
|
|
14
|
+
class EmailClient extends base_client_1.BaseClient {
|
|
15
|
+
async getOrCreateEmailForwarding(args, requestId) {
|
|
16
|
+
const { data } = await (0, http_client_1.request)({
|
|
17
|
+
httpMethod: 'PUT',
|
|
18
|
+
baseUri: this.syncApiBase,
|
|
19
|
+
relativePath: endpoints_1.ENDPOINT_REST_EMAILS,
|
|
20
|
+
apiToken: this.authToken,
|
|
21
|
+
customFetch: this.customFetch,
|
|
22
|
+
payload: args,
|
|
23
|
+
requestId: requestId,
|
|
24
|
+
});
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
async disableEmailForwarding(args, requestId) {
|
|
28
|
+
const queryParams = new URLSearchParams({
|
|
29
|
+
obj_type: args.objType,
|
|
30
|
+
obj_id: args.objId,
|
|
31
|
+
});
|
|
32
|
+
const response = await (0, http_client_1.request)({
|
|
33
|
+
httpMethod: 'DELETE',
|
|
34
|
+
baseUri: this.syncApiBase,
|
|
35
|
+
relativePath: `${endpoints_1.ENDPOINT_REST_EMAILS}?${queryParams.toString()}`,
|
|
36
|
+
apiToken: this.authToken,
|
|
37
|
+
customFetch: this.customFetch,
|
|
38
|
+
requestId: requestId,
|
|
39
|
+
});
|
|
40
|
+
return (0, http_client_1.isSuccess)(response);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.EmailClient = EmailClient;
|