@doist/todoist-sdk 9.1.0-next.1 → 9.1.0-next.2
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/clients/activity-client.js +63 -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/goals-client.js +145 -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/upload-client.js +102 -0
- package/dist/cjs/clients/workspace-client.js +367 -0
- package/dist/cjs/test-utils/test-defaults.js +25 -1
- package/dist/cjs/todoist-api.js +167 -1646
- package/dist/cjs/transport/sync-request.js +75 -0
- package/dist/cjs/types/goals/types.js +29 -2
- package/dist/cjs/utils/headers.js +16 -0
- package/dist/cjs/utils/request-helpers.js +21 -0
- package/dist/esm/clients/activity-client.js +59 -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/goals-client.js +141 -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/upload-client.js +98 -0
- package/dist/esm/clients/workspace-client.js +363 -0
- package/dist/esm/test-utils/test-defaults.js +24 -0
- package/dist/esm/todoist-api.js +170 -1649
- package/dist/esm/transport/sync-request.js +72 -0
- package/dist/esm/types/goals/types.js +29 -2
- package/dist/esm/utils/headers.js +13 -0
- package/dist/esm/utils/request-helpers.js +17 -0
- package/dist/types/clients/activity-client.d.ts +12 -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/goals-client.d.ts +20 -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/upload-client.d.ts +17 -0
- package/dist/types/clients/workspace-client.d.ts +43 -0
- package/dist/types/test-utils/test-defaults.d.ts +4 -1
- package/dist/types/todoist-api.d.ts +40 -20
- package/dist/types/transport/sync-request.d.ts +27 -0
- package/dist/types/types/goals/types.d.ts +14 -4
- package/dist/types/types/http.d.ts +7 -0
- package/dist/types/types/sync/response.d.ts +2 -2
- package/dist/types/utils/headers.d.ts +7 -0
- package/dist/types/utils/request-helpers.d.ts +13 -0
- package/package.json +1 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.performSyncRequest = performSyncRequest;
|
|
4
|
+
const endpoints_1 = require("../consts/endpoints");
|
|
5
|
+
const types_1 = require("../types");
|
|
6
|
+
const sync_1 = require("../types/sync");
|
|
7
|
+
const request_helpers_1 = require("../utils/request-helpers");
|
|
8
|
+
const validators_1 = require("../utils/validators");
|
|
9
|
+
const http_client_1 = require("./http-client");
|
|
10
|
+
function serializeUserUpdateArgs(args) {
|
|
11
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, args), (0, request_helpers_1.spreadIfDefined)(args.dateFormat, (v) => ({
|
|
12
|
+
dateFormat: sync_1.DATE_FORMAT_TO_API[v],
|
|
13
|
+
}))), (0, request_helpers_1.spreadIfDefined)(args.timeFormat, (v) => ({
|
|
14
|
+
timeFormat: sync_1.TIME_FORMAT_TO_API[v],
|
|
15
|
+
}))), (0, request_helpers_1.spreadIfDefined)(args.startDay, (v) => ({
|
|
16
|
+
startDay: sync_1.DAY_OF_WEEK_TO_API[v],
|
|
17
|
+
}))), (0, request_helpers_1.spreadIfDefined)(args.nextWeek, (v) => ({
|
|
18
|
+
nextWeek: sync_1.DAY_OF_WEEK_TO_API[v],
|
|
19
|
+
})));
|
|
20
|
+
}
|
|
21
|
+
function serializeTaskUpdateDateCompleteArgs(args) {
|
|
22
|
+
return Object.assign(Object.assign(Object.assign({}, args), { isForward: args.isForward ? 1 : 0 }), (0, request_helpers_1.spreadIfDefined)(args.resetSubtasks, (v) => ({
|
|
23
|
+
resetSubtasks: v ? 1 : 0,
|
|
24
|
+
})));
|
|
25
|
+
}
|
|
26
|
+
function serializeUpdateGoalsArgs(args) {
|
|
27
|
+
return Object.assign(Object.assign(Object.assign({}, args), (0, request_helpers_1.spreadIfDefined)(args.vacationMode, (v) => ({ vacationMode: v ? 1 : 0 }))), (0, request_helpers_1.spreadIfDefined)(args.karmaDisabled, (v) => ({
|
|
28
|
+
karmaDisabled: v ? 1 : 0,
|
|
29
|
+
})));
|
|
30
|
+
}
|
|
31
|
+
function preprocessSyncCommands(commands) {
|
|
32
|
+
return commands.map((cmd) => {
|
|
33
|
+
if (cmd.type === 'user_update')
|
|
34
|
+
return Object.assign(Object.assign({}, cmd), { args: serializeUserUpdateArgs(cmd.args) });
|
|
35
|
+
if (cmd.type === 'item_update_date_complete')
|
|
36
|
+
return Object.assign(Object.assign({}, cmd), { args: serializeTaskUpdateDateCompleteArgs(cmd.args) });
|
|
37
|
+
if (cmd.type === 'update_goals')
|
|
38
|
+
return Object.assign(Object.assign({}, cmd), { args: serializeUpdateGoalsArgs(cmd.args) });
|
|
39
|
+
return cmd;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Makes a request to the Sync API and handles error checking.
|
|
44
|
+
*
|
|
45
|
+
* @param ctx - HTTP identity (auth token, sync API base URI, optional custom fetch).
|
|
46
|
+
* @param syncRequest - The sync request payload.
|
|
47
|
+
* @param options - Optional request identifier and commands flag.
|
|
48
|
+
* @returns The sync response data.
|
|
49
|
+
* @throws TodoistRequestError if sync status contains errors.
|
|
50
|
+
*/
|
|
51
|
+
async function performSyncRequest(ctx, syncRequest, options = {}) {
|
|
52
|
+
var _a;
|
|
53
|
+
const { requestId, hasSyncCommands = false } = options;
|
|
54
|
+
const processedRequest = ((_a = syncRequest.commands) === null || _a === void 0 ? void 0 : _a.length)
|
|
55
|
+
? Object.assign(Object.assign({}, syncRequest), { commands: preprocessSyncCommands(syncRequest.commands) }) : syncRequest;
|
|
56
|
+
const response = await (0, http_client_1.request)({
|
|
57
|
+
httpMethod: 'POST',
|
|
58
|
+
baseUri: ctx.syncApiBase,
|
|
59
|
+
relativePath: endpoints_1.ENDPOINT_SYNC,
|
|
60
|
+
apiToken: ctx.authToken,
|
|
61
|
+
customFetch: ctx.customFetch,
|
|
62
|
+
payload: processedRequest,
|
|
63
|
+
requestId: requestId,
|
|
64
|
+
hasSyncCommands: hasSyncCommands,
|
|
65
|
+
});
|
|
66
|
+
// Check for sync errors and throw if any are found
|
|
67
|
+
if (response.data.syncStatus) {
|
|
68
|
+
Object.entries(response.data.syncStatus).forEach(([_, value]) => {
|
|
69
|
+
if (value === 'ok')
|
|
70
|
+
return;
|
|
71
|
+
throw new types_1.TodoistRequestError(value.error, value.httpCode, value.errorExtra);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return (0, validators_1.parseSyncResponse)(response.data);
|
|
75
|
+
}
|
|
@@ -1,14 +1,41 @@
|
|
|
1
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
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
14
|
exports.GoalSchema = exports.GoalProgressSchema = exports.GOAL_OWNER_TYPES = void 0;
|
|
4
15
|
const zod_1 = require("zod");
|
|
5
16
|
/** Available goal owner types. */
|
|
6
17
|
exports.GOAL_OWNER_TYPES = ['USER', 'WORKSPACE'];
|
|
7
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Progress of a {@link Goal}.
|
|
20
|
+
*
|
|
21
|
+
* The REST API returns these counts under `total_item_count` / `completed_item_count`,
|
|
22
|
+
* reflecting the backend's generic "item" terminology. The SDK normalizes them to
|
|
23
|
+
* `totalTaskCount` / `completedTaskCount` so the public surface consistently speaks
|
|
24
|
+
* in "tasks" (matching the rest of the SDK). The `preprocess` step below performs
|
|
25
|
+
* that rename after the transport layer's snake_case → camelCase conversion — do not
|
|
26
|
+
* remove it without also changing the downstream field names.
|
|
27
|
+
*/
|
|
28
|
+
exports.GoalProgressSchema = zod_1.z.preprocess((raw) => {
|
|
29
|
+
if (raw === null || raw === undefined || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
30
|
+
return raw;
|
|
31
|
+
}
|
|
32
|
+
const _a = raw, { totalItemCount, completedItemCount, totalTaskCount, completedTaskCount } = _a, rest = __rest(_a, ["totalItemCount", "completedItemCount", "totalTaskCount", "completedTaskCount"]);
|
|
33
|
+
return Object.assign(Object.assign({}, rest), { totalTaskCount: totalTaskCount !== null && totalTaskCount !== void 0 ? totalTaskCount : totalItemCount, completedTaskCount: completedTaskCount !== null && completedTaskCount !== void 0 ? completedTaskCount : completedItemCount });
|
|
34
|
+
}, zod_1.z.looseObject({
|
|
8
35
|
totalTaskCount: zod_1.z.number().int(),
|
|
9
36
|
completedTaskCount: zod_1.z.number().int(),
|
|
10
37
|
percentage: zod_1.z.number(),
|
|
11
|
-
});
|
|
38
|
+
}));
|
|
12
39
|
exports.GoalSchema = zod_1.z.looseObject({
|
|
13
40
|
id: zod_1.z.string(),
|
|
14
41
|
ownerType: zod_1.z.enum(exports.GOAL_OWNER_TYPES),
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.headersToRecord = headersToRecord;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a native Fetch `Headers` object into a plain `Record<string, string>`.
|
|
6
|
+
* Used when wrapping a native `fetch` response into the SDK's `FileResponse`
|
|
7
|
+
* shape (which expects headers as a plain record for symmetry with
|
|
8
|
+
* `CustomFetchResponse`).
|
|
9
|
+
*/
|
|
10
|
+
function headersToRecord(headers) {
|
|
11
|
+
const result = {};
|
|
12
|
+
headers.forEach((value, key) => {
|
|
13
|
+
result[key] = value;
|
|
14
|
+
});
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatePath = generatePath;
|
|
4
|
+
exports.spreadIfDefined = spreadIfDefined;
|
|
5
|
+
/**
|
|
6
|
+
* Joins path segments using `/` separator.
|
|
7
|
+
* @param segments A list of **valid** path segments.
|
|
8
|
+
* @returns A joined path.
|
|
9
|
+
*/
|
|
10
|
+
function generatePath(...segments) {
|
|
11
|
+
return segments.join('/');
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns `fn(value)` spread into an object if `value` is defined, otherwise an empty object.
|
|
15
|
+
*
|
|
16
|
+
* Used to conditionally include a property on a payload object without
|
|
17
|
+
* resorting to mutation or ternary-built object literals.
|
|
18
|
+
*/
|
|
19
|
+
function spreadIfDefined(value, fn) {
|
|
20
|
+
return value !== undefined ? fn(value) : {};
|
|
21
|
+
}
|
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ENDPOINT_REST_FOLDERS } from '../consts/endpoints.js';
|
|
3
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
4
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
5
|
+
import { validateFolder, validateFolderArray } from '../utils/validators.js';
|
|
6
|
+
import { BaseClient } from './base-client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Internal sub-client handling all folder-domain endpoints.
|
|
9
|
+
*
|
|
10
|
+
* Instantiated by `TodoistApi`; every public folder method on `TodoistApi`
|
|
11
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
12
|
+
*/
|
|
13
|
+
export class FolderClient extends BaseClient {
|
|
14
|
+
async getFolders(args) {
|
|
15
|
+
const { data: { results, nextCursor }, } = await request({
|
|
16
|
+
httpMethod: 'GET',
|
|
17
|
+
baseUri: this.syncApiBase,
|
|
18
|
+
relativePath: ENDPOINT_REST_FOLDERS,
|
|
19
|
+
apiToken: this.authToken,
|
|
20
|
+
customFetch: this.customFetch,
|
|
21
|
+
payload: args,
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
results: validateFolderArray(results),
|
|
25
|
+
nextCursor,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async getFolder(id) {
|
|
29
|
+
z.string().parse(id);
|
|
30
|
+
const response = await request({
|
|
31
|
+
httpMethod: 'GET',
|
|
32
|
+
baseUri: this.syncApiBase,
|
|
33
|
+
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
34
|
+
apiToken: this.authToken,
|
|
35
|
+
customFetch: this.customFetch,
|
|
36
|
+
});
|
|
37
|
+
return validateFolder(response.data);
|
|
38
|
+
}
|
|
39
|
+
async addFolder(args, requestId) {
|
|
40
|
+
const response = await request({
|
|
41
|
+
httpMethod: 'POST',
|
|
42
|
+
baseUri: this.syncApiBase,
|
|
43
|
+
relativePath: ENDPOINT_REST_FOLDERS,
|
|
44
|
+
apiToken: this.authToken,
|
|
45
|
+
customFetch: this.customFetch,
|
|
46
|
+
payload: args,
|
|
47
|
+
requestId: requestId,
|
|
48
|
+
});
|
|
49
|
+
return validateFolder(response.data);
|
|
50
|
+
}
|
|
51
|
+
async updateFolder(id, args, requestId) {
|
|
52
|
+
z.string().parse(id);
|
|
53
|
+
const response = await request({
|
|
54
|
+
httpMethod: 'POST',
|
|
55
|
+
baseUri: this.syncApiBase,
|
|
56
|
+
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
57
|
+
apiToken: this.authToken,
|
|
58
|
+
customFetch: this.customFetch,
|
|
59
|
+
payload: args,
|
|
60
|
+
requestId: requestId,
|
|
61
|
+
});
|
|
62
|
+
return validateFolder(response.data);
|
|
63
|
+
}
|
|
64
|
+
async deleteFolder(id, requestId) {
|
|
65
|
+
z.string().parse(id);
|
|
66
|
+
const response = await request({
|
|
67
|
+
httpMethod: 'DELETE',
|
|
68
|
+
baseUri: this.syncApiBase,
|
|
69
|
+
relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
|
|
70
|
+
apiToken: this.authToken,
|
|
71
|
+
customFetch: this.customFetch,
|
|
72
|
+
requestId: requestId,
|
|
73
|
+
});
|
|
74
|
+
return isSuccess(response);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ENDPOINT_REST_GOALS, ENDPOINT_REST_GOALS_SEARCH, GOAL_COMPLETE, GOAL_TASKS, GOAL_UNCOMPLETE, } from '../consts/endpoints.js';
|
|
3
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
4
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
5
|
+
import { validateGoal, validateGoalArray } from '../utils/validators.js';
|
|
6
|
+
import { BaseClient } from './base-client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Internal sub-client handling all goal-domain endpoints.
|
|
9
|
+
*
|
|
10
|
+
* Instantiated by `TodoistApi`; every public goal method on `TodoistApi`
|
|
11
|
+
* delegates here. See `todoist-api.ts` for the user-facing JSDoc.
|
|
12
|
+
*/
|
|
13
|
+
export class GoalsClient extends BaseClient {
|
|
14
|
+
async getGoals(args) {
|
|
15
|
+
const { data: { results, nextCursor }, } = await request({
|
|
16
|
+
httpMethod: 'GET',
|
|
17
|
+
baseUri: this.syncApiBase,
|
|
18
|
+
relativePath: ENDPOINT_REST_GOALS,
|
|
19
|
+
apiToken: this.authToken,
|
|
20
|
+
customFetch: this.customFetch,
|
|
21
|
+
payload: args,
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
results: validateGoalArray(results),
|
|
25
|
+
nextCursor,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
async searchGoals(args) {
|
|
29
|
+
const { data: { results, nextCursor }, } = await request({
|
|
30
|
+
httpMethod: 'GET',
|
|
31
|
+
baseUri: this.syncApiBase,
|
|
32
|
+
relativePath: ENDPOINT_REST_GOALS_SEARCH,
|
|
33
|
+
apiToken: this.authToken,
|
|
34
|
+
customFetch: this.customFetch,
|
|
35
|
+
payload: args,
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
results: validateGoalArray(results),
|
|
39
|
+
nextCursor,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
async getGoal(id) {
|
|
43
|
+
z.string().parse(id);
|
|
44
|
+
const response = await request({
|
|
45
|
+
httpMethod: 'GET',
|
|
46
|
+
baseUri: this.syncApiBase,
|
|
47
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id),
|
|
48
|
+
apiToken: this.authToken,
|
|
49
|
+
customFetch: this.customFetch,
|
|
50
|
+
});
|
|
51
|
+
return validateGoal(response.data);
|
|
52
|
+
}
|
|
53
|
+
async addGoal(args, requestId) {
|
|
54
|
+
const response = await request({
|
|
55
|
+
httpMethod: 'POST',
|
|
56
|
+
baseUri: this.syncApiBase,
|
|
57
|
+
relativePath: ENDPOINT_REST_GOALS,
|
|
58
|
+
apiToken: this.authToken,
|
|
59
|
+
customFetch: this.customFetch,
|
|
60
|
+
payload: args,
|
|
61
|
+
requestId: requestId,
|
|
62
|
+
});
|
|
63
|
+
return validateGoal(response.data);
|
|
64
|
+
}
|
|
65
|
+
async updateGoal(id, args, requestId) {
|
|
66
|
+
z.string().parse(id);
|
|
67
|
+
const response = await request({
|
|
68
|
+
httpMethod: 'POST',
|
|
69
|
+
baseUri: this.syncApiBase,
|
|
70
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id),
|
|
71
|
+
apiToken: this.authToken,
|
|
72
|
+
customFetch: this.customFetch,
|
|
73
|
+
payload: args,
|
|
74
|
+
requestId: requestId,
|
|
75
|
+
});
|
|
76
|
+
return validateGoal(response.data);
|
|
77
|
+
}
|
|
78
|
+
async deleteGoal(id, requestId) {
|
|
79
|
+
z.string().parse(id);
|
|
80
|
+
const response = await request({
|
|
81
|
+
httpMethod: 'DELETE',
|
|
82
|
+
baseUri: this.syncApiBase,
|
|
83
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id),
|
|
84
|
+
apiToken: this.authToken,
|
|
85
|
+
customFetch: this.customFetch,
|
|
86
|
+
requestId: requestId,
|
|
87
|
+
});
|
|
88
|
+
return isSuccess(response);
|
|
89
|
+
}
|
|
90
|
+
async completeGoal(id, requestId) {
|
|
91
|
+
z.string().parse(id);
|
|
92
|
+
const response = await request({
|
|
93
|
+
httpMethod: 'POST',
|
|
94
|
+
baseUri: this.syncApiBase,
|
|
95
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id, GOAL_COMPLETE),
|
|
96
|
+
apiToken: this.authToken,
|
|
97
|
+
customFetch: this.customFetch,
|
|
98
|
+
requestId: requestId,
|
|
99
|
+
});
|
|
100
|
+
return validateGoal(response.data);
|
|
101
|
+
}
|
|
102
|
+
async uncompleteGoal(id, requestId) {
|
|
103
|
+
z.string().parse(id);
|
|
104
|
+
const response = await request({
|
|
105
|
+
httpMethod: 'POST',
|
|
106
|
+
baseUri: this.syncApiBase,
|
|
107
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, id, GOAL_UNCOMPLETE),
|
|
108
|
+
apiToken: this.authToken,
|
|
109
|
+
customFetch: this.customFetch,
|
|
110
|
+
requestId: requestId,
|
|
111
|
+
});
|
|
112
|
+
return validateGoal(response.data);
|
|
113
|
+
}
|
|
114
|
+
async linkTaskToGoal({ goalId, taskId }, requestId) {
|
|
115
|
+
z.string().parse(goalId);
|
|
116
|
+
z.string().parse(taskId);
|
|
117
|
+
const response = await request({
|
|
118
|
+
httpMethod: 'POST',
|
|
119
|
+
baseUri: this.syncApiBase,
|
|
120
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, goalId, GOAL_TASKS),
|
|
121
|
+
apiToken: this.authToken,
|
|
122
|
+
customFetch: this.customFetch,
|
|
123
|
+
payload: { itemId: taskId },
|
|
124
|
+
requestId: requestId,
|
|
125
|
+
});
|
|
126
|
+
return validateGoal(response.data);
|
|
127
|
+
}
|
|
128
|
+
async unlinkTaskFromGoal({ goalId, taskId }, requestId) {
|
|
129
|
+
z.string().parse(goalId);
|
|
130
|
+
z.string().parse(taskId);
|
|
131
|
+
const response = await request({
|
|
132
|
+
httpMethod: 'DELETE',
|
|
133
|
+
baseUri: this.syncApiBase,
|
|
134
|
+
relativePath: generatePath(ENDPOINT_REST_GOALS, goalId, GOAL_TASKS, taskId),
|
|
135
|
+
apiToken: this.authToken,
|
|
136
|
+
customFetch: this.customFetch,
|
|
137
|
+
requestId: requestId,
|
|
138
|
+
});
|
|
139
|
+
return isSuccess(response);
|
|
140
|
+
}
|
|
141
|
+
}
|