@doist/todoist-sdk 9.0.0 → 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/consts/endpoints.js +6 -1
- package/dist/cjs/test-utils/test-defaults.js +25 -1
- package/dist/cjs/todoist-api.js +186 -1537
- package/dist/cjs/transport/sync-request.js +75 -0
- package/dist/cjs/types/goals/index.js +18 -0
- package/dist/cjs/types/goals/requests.js +2 -0
- package/dist/cjs/types/goals/types.js +56 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/sync/commands/goals.js +2 -0
- package/dist/cjs/types/sync/commands/index.js +1 -0
- package/dist/cjs/types/sync/resource-types.js +1 -0
- package/dist/cjs/types/sync/response.js +12 -10
- package/dist/cjs/utils/headers.js +16 -0
- package/dist/cjs/utils/request-helpers.js +21 -0
- package/dist/cjs/utils/validators.js +48 -46
- 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/consts/endpoints.js +5 -0
- package/dist/esm/test-utils/test-defaults.js +24 -0
- package/dist/esm/todoist-api.js +189 -1540
- package/dist/esm/transport/sync-request.js +72 -0
- package/dist/esm/types/goals/index.js +2 -0
- package/dist/esm/types/goals/requests.js +1 -0
- package/dist/esm/types/goals/types.js +53 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/sync/commands/goals.js +1 -0
- package/dist/esm/types/sync/commands/index.js +1 -0
- package/dist/esm/types/sync/resource-types.js +1 -0
- package/dist/esm/types/sync/response.js +2 -0
- package/dist/esm/utils/headers.js +13 -0
- package/dist/esm/utils/request-helpers.js +17 -0
- package/dist/esm/utils/validators.js +2 -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/consts/endpoints.d.ts +5 -0
- package/dist/types/test-utils/test-defaults.d.ts +4 -1
- package/dist/types/todoist-api.d.ts +48 -17
- package/dist/types/transport/sync-request.d.ts +27 -0
- package/dist/types/types/goals/index.d.ts +2 -0
- package/dist/types/types/goals/requests.d.ts +33 -0
- package/dist/types/types/goals/types.d.ts +51 -0
- package/dist/types/types/http.d.ts +7 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/sync/commands/goals.d.ts +33 -0
- package/dist/types/types/sync/commands/index.d.ts +9 -0
- package/dist/types/types/sync/resource-types.d.ts +1 -1
- package/dist/types/types/sync/resources/view-options.d.ts +6 -6
- package/dist/types/types/sync/response.d.ts +29 -4
- package/dist/types/types/tasks/requests.d.ts +1 -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 +55 -8
- 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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./requests"), exports);
|
|
@@ -0,0 +1,56 @@
|
|
|
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.GoalSchema = exports.GoalProgressSchema = exports.GOAL_OWNER_TYPES = void 0;
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
/** Available goal owner types. */
|
|
17
|
+
exports.GOAL_OWNER_TYPES = ['USER', 'WORKSPACE'];
|
|
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({
|
|
35
|
+
totalTaskCount: zod_1.z.number().int(),
|
|
36
|
+
completedTaskCount: zod_1.z.number().int(),
|
|
37
|
+
percentage: zod_1.z.number(),
|
|
38
|
+
}));
|
|
39
|
+
exports.GoalSchema = zod_1.z.looseObject({
|
|
40
|
+
id: zod_1.z.string(),
|
|
41
|
+
ownerType: zod_1.z.enum(exports.GOAL_OWNER_TYPES),
|
|
42
|
+
ownerId: zod_1.z.string(),
|
|
43
|
+
name: zod_1.z.string(),
|
|
44
|
+
description: zod_1.z.string().nullable(),
|
|
45
|
+
deadline: zod_1.z.string().nullable(),
|
|
46
|
+
parentGoalId: zod_1.z.string().nullable(),
|
|
47
|
+
childOrder: zod_1.z.number().int(),
|
|
48
|
+
isCompleted: zod_1.z.boolean(),
|
|
49
|
+
completedAt: zod_1.z.coerce.date().nullable(),
|
|
50
|
+
responsibleUid: zod_1.z.string().nullable(),
|
|
51
|
+
isDeleted: zod_1.z.boolean(),
|
|
52
|
+
progress: exports.GoalProgressSchema.optional(),
|
|
53
|
+
creatorUid: zod_1.z.string(),
|
|
54
|
+
createdAt: zod_1.z.coerce.date(),
|
|
55
|
+
updatedAt: zod_1.z.coerce.date(),
|
|
56
|
+
});
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __exportStar(require("./productivity"), exports);
|
|
|
25
25
|
__exportStar(require("./activity"), exports);
|
|
26
26
|
__exportStar(require("./workspaces"), exports);
|
|
27
27
|
__exportStar(require("./folders"), exports);
|
|
28
|
+
__exportStar(require("./goals"), exports);
|
|
28
29
|
__exportStar(require("./insights"), exports);
|
|
29
30
|
__exportStar(require("./backups"), exports);
|
|
30
31
|
__exportStar(require("./id-mappings"), exports);
|
|
@@ -27,6 +27,7 @@ __exportStar(require("./workspaces"), exports);
|
|
|
27
27
|
__exportStar(require("./folders"), exports);
|
|
28
28
|
__exportStar(require("./workspace-filters"), exports);
|
|
29
29
|
__exportStar(require("./workspace-goals"), exports);
|
|
30
|
+
__exportStar(require("./goals"), exports);
|
|
30
31
|
__exportStar(require("./notifications"), exports);
|
|
31
32
|
__exportStar(require("./sharing"), exports);
|
|
32
33
|
__exportStar(require("./view-options"), exports);
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SyncResponseSchema = exports.SyncErrorSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const types_1 = require("../
|
|
6
|
-
const types_2 = require("../
|
|
7
|
-
const types_3 = require("../
|
|
8
|
-
const types_4 = require("../
|
|
9
|
-
const types_5 = require("../
|
|
5
|
+
const types_1 = require("../goals/types");
|
|
6
|
+
const types_2 = require("../labels/types");
|
|
7
|
+
const types_3 = require("../projects/types");
|
|
8
|
+
const types_4 = require("../sections/types");
|
|
9
|
+
const types_5 = require("../tasks/types");
|
|
10
|
+
const types_6 = require("../workspaces/types");
|
|
10
11
|
const resources_1 = require("./resources");
|
|
11
12
|
exports.SyncErrorSchema = zod_1.z.object({
|
|
12
13
|
error: zod_1.z.string(),
|
|
@@ -20,10 +21,10 @@ exports.SyncResponseSchema = zod_1.z.looseObject({
|
|
|
20
21
|
fullSync: zod_1.z.boolean().optional(),
|
|
21
22
|
syncStatus: zod_1.z.record(zod_1.z.string(), zod_1.z.union([zod_1.z.literal('ok'), exports.SyncErrorSchema])).optional(),
|
|
22
23
|
tempIdMapping: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).optional(),
|
|
23
|
-
items: zod_1.z.array(
|
|
24
|
-
projects: zod_1.z.array(
|
|
25
|
-
sections: zod_1.z.array(
|
|
26
|
-
labels: zod_1.z.array(
|
|
24
|
+
items: zod_1.z.array(types_5.TaskSchema).optional(),
|
|
25
|
+
projects: zod_1.z.array(types_3.ProjectSchema).optional(),
|
|
26
|
+
sections: zod_1.z.array(types_4.SectionSchema).optional(),
|
|
27
|
+
labels: zod_1.z.array(types_2.LabelSchema).optional(),
|
|
27
28
|
notes: zod_1.z.array(resources_1.NoteSchema).optional(),
|
|
28
29
|
projectNotes: zod_1.z.array(resources_1.NoteSchema).optional(),
|
|
29
30
|
filters: zod_1.z.array(resources_1.FilterSchema).optional(),
|
|
@@ -40,12 +41,13 @@ exports.SyncResponseSchema = zod_1.z.looseObject({
|
|
|
40
41
|
completedInfo: zod_1.z.array(resources_1.CompletedInfoSchema).optional(),
|
|
41
42
|
stats: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
|
|
42
43
|
workspaces: zod_1.z.array(resources_1.SyncWorkspaceSchema).optional(),
|
|
43
|
-
workspaceUsers: zod_1.z.array(
|
|
44
|
+
workspaceUsers: zod_1.z.array(types_6.WorkspaceUserSchema).optional(),
|
|
44
45
|
workspaceFilters: zod_1.z.array(resources_1.WorkspaceFilterSchema).optional(),
|
|
45
46
|
viewOptions: zod_1.z.array(resources_1.ViewOptionsSchema).optional(),
|
|
46
47
|
projectViewOptionsDefaults: zod_1.z.array(resources_1.ProjectViewOptionsDefaultsSchema).optional(),
|
|
47
48
|
roleActions: zod_1.z.array(zod_1.z.record(zod_1.z.string(), zod_1.z.unknown())).optional(),
|
|
48
49
|
folders: zod_1.z.array(resources_1.FolderSchema).optional(),
|
|
50
|
+
goals: zod_1.z.array(types_1.GoalSchema).optional(),
|
|
49
51
|
workspaceGoals: zod_1.z.array(resources_1.WorkspaceGoalSchema).optional(),
|
|
50
52
|
dayOrders: zod_1.z.record(zod_1.z.string(), zod_1.z.number()).optional(),
|
|
51
53
|
calendars: zod_1.z.array(resources_1.CalendarSchema).optional(),
|
|
@@ -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
|
+
}
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8;
|
|
2
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9;
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.validateFolderArray = exports.validateFolder = exports.validateCollaboratorStateArray = exports.validateCollaboratorState = exports.validateCollaboratorArray = exports.validateCollaborator = exports.validateFilterArray = exports.validateFilter = exports.validateMovedIdArray = exports.validateMovedId = exports.validateIdMappingArray = exports.validateIdMapping = exports.validateBackupArray = exports.validateBackup = exports.validateWorkspaceInsights = exports.validateProjectProgress = exports.validateProjectHealthContext = exports.validateProjectHealth = exports.validateProjectActivityStats = exports.validateWorkspaceUserTaskArray = exports.validateWorkspaceUserTask = exports.validateMemberActivityInfoArray = exports.validateMemberActivityInfo = exports.validateWorkspaceArray = exports.validateWorkspace = exports.validateJoinWorkspaceResult = exports.validateWorkspacePlanDetails = exports.validateWorkspaceInvitationArray = exports.validateWorkspaceInvitation = exports.validateWorkspaceUserArray = exports.validateWorkspaceUser = exports.validateAttachment = exports.validateActivityEventArray = exports.validateActivityEvent = exports.validateCurrentUser = exports.validateProductivityStats = exports.validateUserArray = exports.validateUser = exports.validateCommentArray = exports.validateComment = exports.validateLabelArray = exports.validateLabel = exports.validateSectionArray = exports.validateSection = exports.validateWorkspaceProjectArray = exports.validateWorkspaceProject = exports.validateProjectArray = exports.validateProject = exports.validateTaskArray = exports.validateTask = void 0;
|
|
5
|
-
exports.validateSuggestionArray = exports.validateSuggestion = exports.validateUserSettings = exports.validateSyncUser = exports.validateSyncWorkspaceArray = exports.validateSyncWorkspace = exports.validateLiveNotificationArray = exports.validateLiveNotification = exports.validateUserPlanLimits = exports.validateProjectViewOptionsDefaultsArray = exports.validateProjectViewOptionsDefaults = exports.validateViewOptionsArray = exports.validateViewOptions = exports.validateCompletedInfoArray = exports.validateCompletedInfo = exports.validateLocationReminderArray = exports.validateLocationReminder = exports.validateReminderArray = exports.validateReminder = exports.validateCalendarAccountArray = exports.validateCalendarAccount = exports.validateCalendarArray = exports.validateCalendar = exports.validateWorkspaceGoalArray = exports.validateWorkspaceGoal = exports.validateWorkspaceFilterArray = exports.validateWorkspaceFilter = exports.validateTooltips = exports.validateNoteArray = exports.validateNote = void 0;
|
|
5
|
+
exports.validateSuggestionArray = exports.validateSuggestion = exports.validateUserSettings = exports.validateSyncUser = exports.validateSyncWorkspaceArray = exports.validateSyncWorkspace = exports.validateLiveNotificationArray = exports.validateLiveNotification = exports.validateUserPlanLimits = exports.validateProjectViewOptionsDefaultsArray = exports.validateProjectViewOptionsDefaults = exports.validateViewOptionsArray = exports.validateViewOptions = exports.validateCompletedInfoArray = exports.validateCompletedInfo = exports.validateLocationReminderArray = exports.validateLocationReminder = exports.validateReminderArray = exports.validateReminder = exports.validateCalendarAccountArray = exports.validateCalendarAccount = exports.validateCalendarArray = exports.validateCalendar = exports.validateWorkspaceGoalArray = exports.validateWorkspaceGoal = exports.validateWorkspaceFilterArray = exports.validateWorkspaceFilter = exports.validateTooltips = exports.validateNoteArray = exports.validateNote = exports.validateGoalArray = exports.validateGoal = void 0;
|
|
6
6
|
exports.parseSyncResponse = parseSyncResponse;
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const types_1 = require("../types/activity/types");
|
|
9
9
|
const types_2 = require("../types/backups/types");
|
|
10
10
|
const types_3 = require("../types/comments/types");
|
|
11
|
-
const types_4 = require("../types/
|
|
12
|
-
const types_5 = require("../types/
|
|
13
|
-
const types_6 = require("../types/
|
|
14
|
-
const types_7 = require("../types/
|
|
15
|
-
const types_8 = require("../types/
|
|
16
|
-
const types_9 = require("../types/
|
|
11
|
+
const types_4 = require("../types/goals/types");
|
|
12
|
+
const types_5 = require("../types/id-mappings/types");
|
|
13
|
+
const types_6 = require("../types/insights/types");
|
|
14
|
+
const types_7 = require("../types/labels/types");
|
|
15
|
+
const types_8 = require("../types/productivity/types");
|
|
16
|
+
const types_9 = require("../types/projects/types");
|
|
17
|
+
const types_10 = require("../types/sections/types");
|
|
17
18
|
const response_1 = require("../types/sync/response");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const types_11 = require("../types/tasks/types");
|
|
20
|
+
const types_12 = require("../types/users/types");
|
|
21
|
+
const types_13 = require("../types/workspaces/types");
|
|
21
22
|
const resources_1 = require("../types/sync/resources");
|
|
22
23
|
function createValidator(schema) {
|
|
23
24
|
return {
|
|
@@ -26,59 +27,60 @@ function createValidator(schema) {
|
|
|
26
27
|
};
|
|
27
28
|
}
|
|
28
29
|
// Entity validators
|
|
29
|
-
_a = createValidator(
|
|
30
|
+
_a = createValidator(types_11.TaskSchema), exports.validateTask = _a.validate, exports.validateTaskArray = _a.validateArray;
|
|
30
31
|
/**
|
|
31
32
|
* Validates and parses a project input.
|
|
32
33
|
* @param input The input to validate
|
|
33
34
|
* @returns A validated project (either PersonalProject or WorkspaceProject)
|
|
34
35
|
*/
|
|
35
|
-
_b = createValidator(
|
|
36
|
-
_c = createValidator(
|
|
37
|
-
_d = createValidator(
|
|
38
|
-
_e = createValidator(
|
|
36
|
+
_b = createValidator(types_9.ProjectSchema), exports.validateProject = _b.validate, exports.validateProjectArray = _b.validateArray;
|
|
37
|
+
_c = createValidator(types_9.WorkspaceProjectSchema), exports.validateWorkspaceProject = _c.validate, exports.validateWorkspaceProjectArray = _c.validateArray;
|
|
38
|
+
_d = createValidator(types_10.SectionSchema), exports.validateSection = _d.validate, exports.validateSectionArray = _d.validateArray;
|
|
39
|
+
_e = createValidator(types_7.LabelSchema), exports.validateLabel = _e.validate, exports.validateLabelArray = _e.validateArray;
|
|
39
40
|
_f = createValidator(types_3.CommentSchema), exports.validateComment = _f.validate, exports.validateCommentArray = _f.validateArray;
|
|
40
|
-
_g = createValidator(
|
|
41
|
-
exports.validateProductivityStats = createValidator(
|
|
42
|
-
exports.validateCurrentUser = createValidator(
|
|
41
|
+
_g = createValidator(types_12.UserSchema), exports.validateUser = _g.validate, exports.validateUserArray = _g.validateArray;
|
|
42
|
+
exports.validateProductivityStats = createValidator(types_8.ProductivityStatsSchema).validate;
|
|
43
|
+
exports.validateCurrentUser = createValidator(types_12.CurrentUserSchema).validate;
|
|
43
44
|
_h = createValidator(types_1.ActivityEventSchema), exports.validateActivityEvent = _h.validate, exports.validateActivityEventArray = _h.validateArray;
|
|
44
45
|
exports.validateAttachment = createValidator(types_3.AttachmentSchema).validate;
|
|
45
|
-
_j = createValidator(
|
|
46
|
-
_k = createValidator(
|
|
47
|
-
exports.validateWorkspacePlanDetails = createValidator(
|
|
48
|
-
exports.validateJoinWorkspaceResult = createValidator(
|
|
49
|
-
_l = createValidator(
|
|
50
|
-
_m = createValidator(
|
|
51
|
-
_o = createValidator(
|
|
52
|
-
exports.validateProjectActivityStats = createValidator(
|
|
53
|
-
exports.validateProjectHealth = createValidator(
|
|
54
|
-
exports.validateProjectHealthContext = createValidator(
|
|
55
|
-
exports.validateProjectProgress = createValidator(
|
|
56
|
-
exports.validateWorkspaceInsights = createValidator(
|
|
46
|
+
_j = createValidator(types_13.WorkspaceUserSchema), exports.validateWorkspaceUser = _j.validate, exports.validateWorkspaceUserArray = _j.validateArray;
|
|
47
|
+
_k = createValidator(types_13.WorkspaceInvitationSchema), exports.validateWorkspaceInvitation = _k.validate, exports.validateWorkspaceInvitationArray = _k.validateArray;
|
|
48
|
+
exports.validateWorkspacePlanDetails = createValidator(types_13.WorkspacePlanDetailsSchema).validate;
|
|
49
|
+
exports.validateJoinWorkspaceResult = createValidator(types_13.JoinWorkspaceResultSchema).validate;
|
|
50
|
+
_l = createValidator(types_13.WorkspaceSchema), exports.validateWorkspace = _l.validate, exports.validateWorkspaceArray = _l.validateArray;
|
|
51
|
+
_m = createValidator(types_13.MemberActivityInfoSchema), exports.validateMemberActivityInfo = _m.validate, exports.validateMemberActivityInfoArray = _m.validateArray;
|
|
52
|
+
_o = createValidator(types_13.WorkspaceUserTaskSchema), exports.validateWorkspaceUserTask = _o.validate, exports.validateWorkspaceUserTaskArray = _o.validateArray;
|
|
53
|
+
exports.validateProjectActivityStats = createValidator(types_6.ProjectActivityStatsSchema).validate;
|
|
54
|
+
exports.validateProjectHealth = createValidator(types_6.ProjectHealthSchema).validate;
|
|
55
|
+
exports.validateProjectHealthContext = createValidator(types_6.ProjectHealthContextSchema).validate;
|
|
56
|
+
exports.validateProjectProgress = createValidator(types_6.ProjectProgressSchema).validate;
|
|
57
|
+
exports.validateWorkspaceInsights = createValidator(types_6.WorkspaceInsightsSchema).validate;
|
|
57
58
|
_p = createValidator(types_2.BackupSchema), exports.validateBackup = _p.validate, exports.validateBackupArray = _p.validateArray;
|
|
58
|
-
_q = createValidator(
|
|
59
|
-
_r = createValidator(
|
|
59
|
+
_q = createValidator(types_5.IdMappingSchema), exports.validateIdMapping = _q.validate, exports.validateIdMappingArray = _q.validateArray;
|
|
60
|
+
_r = createValidator(types_5.MovedIdSchema), exports.validateMovedId = _r.validate, exports.validateMovedIdArray = _r.validateArray;
|
|
60
61
|
// Sync resource validators
|
|
61
62
|
_s = createValidator(resources_1.FilterSchema), exports.validateFilter = _s.validate, exports.validateFilterArray = _s.validateArray;
|
|
62
63
|
_t = createValidator(resources_1.CollaboratorSchema), exports.validateCollaborator = _t.validate, exports.validateCollaboratorArray = _t.validateArray;
|
|
63
64
|
_u = createValidator(resources_1.CollaboratorStateSchema), exports.validateCollaboratorState = _u.validate, exports.validateCollaboratorStateArray = _u.validateArray;
|
|
64
65
|
_v = createValidator(resources_1.FolderSchema), exports.validateFolder = _v.validate, exports.validateFolderArray = _v.validateArray;
|
|
65
|
-
_w = createValidator(
|
|
66
|
+
_w = createValidator(types_4.GoalSchema), exports.validateGoal = _w.validate, exports.validateGoalArray = _w.validateArray;
|
|
67
|
+
_x = createValidator(resources_1.NoteSchema), exports.validateNote = _x.validate, exports.validateNoteArray = _x.validateArray;
|
|
66
68
|
exports.validateTooltips = createValidator(resources_1.TooltipsSchema).validate;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
_y = createValidator(resources_1.WorkspaceFilterSchema), exports.validateWorkspaceFilter = _y.validate, exports.validateWorkspaceFilterArray = _y.validateArray;
|
|
70
|
+
_z = createValidator(resources_1.WorkspaceGoalSchema), exports.validateWorkspaceGoal = _z.validate, exports.validateWorkspaceGoalArray = _z.validateArray;
|
|
71
|
+
_0 = createValidator(resources_1.CalendarSchema), exports.validateCalendar = _0.validate, exports.validateCalendarArray = _0.validateArray;
|
|
72
|
+
_1 = createValidator(resources_1.CalendarAccountSchema), exports.validateCalendarAccount = _1.validate, exports.validateCalendarAccountArray = _1.validateArray;
|
|
73
|
+
_2 = createValidator(resources_1.ReminderSchema), exports.validateReminder = _2.validate, exports.validateReminderArray = _2.validateArray;
|
|
74
|
+
_3 = createValidator(resources_1.LocationReminderSchema), exports.validateLocationReminder = _3.validate, exports.validateLocationReminderArray = _3.validateArray;
|
|
75
|
+
_4 = createValidator(resources_1.CompletedInfoSchema), exports.validateCompletedInfo = _4.validate, exports.validateCompletedInfoArray = _4.validateArray;
|
|
76
|
+
_5 = createValidator(resources_1.ViewOptionsSchema), exports.validateViewOptions = _5.validate, exports.validateViewOptionsArray = _5.validateArray;
|
|
77
|
+
_6 = createValidator(resources_1.ProjectViewOptionsDefaultsSchema), exports.validateProjectViewOptionsDefaults = _6.validate, exports.validateProjectViewOptionsDefaultsArray = _6.validateArray;
|
|
76
78
|
exports.validateUserPlanLimits = createValidator(resources_1.UserPlanLimitsSchema).validate;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
_7 = createValidator(resources_1.LiveNotificationSchema), exports.validateLiveNotification = _7.validate, exports.validateLiveNotificationArray = _7.validateArray;
|
|
80
|
+
_8 = createValidator(resources_1.SyncWorkspaceSchema), exports.validateSyncWorkspace = _8.validate, exports.validateSyncWorkspaceArray = _8.validateArray;
|
|
79
81
|
exports.validateSyncUser = createValidator(resources_1.SyncUserSchema).validate;
|
|
80
82
|
exports.validateUserSettings = createValidator(resources_1.UserSettingsSchema).validate;
|
|
81
|
-
|
|
83
|
+
_9 = createValidator(resources_1.SuggestionSchema), exports.validateSuggestion = _9.validate, exports.validateSuggestionArray = _9.validateArray;
|
|
82
84
|
function parseSyncResponse(raw) {
|
|
83
85
|
return response_1.SyncResponseSchema.parse(raw);
|
|
84
86
|
}
|
|
@@ -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
|
+
}
|