@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
|
@@ -1,14 +1,14 @@
|
|
|
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, _9;
|
|
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, _10, _11, _12;
|
|
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 =
|
|
5
|
+
exports.validateUiExtensionArray = exports.validateUiExtension = exports.validateUserAuthorizationArray = exports.validateUserAuthorization = exports.validateAppInstallationArray = exports.validateAppInstallation = exports.validateAppWebhook = exports.validateAppByDistributionToken = exports.validateAppDistributionToken = exports.validateAppTestToken = exports.validateAppVerificationToken = exports.validateAppSecrets = exports.validateAppWithUserCount = exports.validateAppArray = exports.validateApp = 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;
|
|
6
6
|
exports.parseSyncResponse = parseSyncResponse;
|
|
7
7
|
const zod_1 = require("zod");
|
|
8
8
|
const types_1 = require("../types/activity/types");
|
|
9
|
-
const types_2 = require("../types/
|
|
10
|
-
const types_3 = require("../types/
|
|
11
|
-
const types_4 = require("../types/
|
|
9
|
+
const types_2 = require("../types/apps/types");
|
|
10
|
+
const types_3 = require("../types/backups/types");
|
|
11
|
+
const types_4 = require("../types/comments/types");
|
|
12
12
|
const types_5 = require("../types/id-mappings/types");
|
|
13
13
|
const types_6 = require("../types/insights/types");
|
|
14
14
|
const types_7 = require("../types/labels/types");
|
|
@@ -17,8 +17,9 @@ const types_9 = require("../types/projects/types");
|
|
|
17
17
|
const types_10 = require("../types/sections/types");
|
|
18
18
|
const response_1 = require("../types/sync/response");
|
|
19
19
|
const types_11 = require("../types/tasks/types");
|
|
20
|
-
const types_12 = require("../types/
|
|
21
|
-
const types_13 = require("../types/
|
|
20
|
+
const types_12 = require("../types/ui-extensions/types");
|
|
21
|
+
const types_13 = require("../types/users/types");
|
|
22
|
+
const types_14 = require("../types/workspaces/types");
|
|
22
23
|
const resources_1 = require("../types/sync/resources");
|
|
23
24
|
function createValidator(schema) {
|
|
24
25
|
return {
|
|
@@ -37,25 +38,25 @@ _b = createValidator(types_9.ProjectSchema), exports.validateProject = _b.valida
|
|
|
37
38
|
_c = createValidator(types_9.WorkspaceProjectSchema), exports.validateWorkspaceProject = _c.validate, exports.validateWorkspaceProjectArray = _c.validateArray;
|
|
38
39
|
_d = createValidator(types_10.SectionSchema), exports.validateSection = _d.validate, exports.validateSectionArray = _d.validateArray;
|
|
39
40
|
_e = createValidator(types_7.LabelSchema), exports.validateLabel = _e.validate, exports.validateLabelArray = _e.validateArray;
|
|
40
|
-
_f = createValidator(
|
|
41
|
-
_g = createValidator(
|
|
41
|
+
_f = createValidator(types_4.CommentSchema), exports.validateComment = _f.validate, exports.validateCommentArray = _f.validateArray;
|
|
42
|
+
_g = createValidator(types_13.UserSchema), exports.validateUser = _g.validate, exports.validateUserArray = _g.validateArray;
|
|
42
43
|
exports.validateProductivityStats = createValidator(types_8.ProductivityStatsSchema).validate;
|
|
43
|
-
exports.validateCurrentUser = createValidator(
|
|
44
|
+
exports.validateCurrentUser = createValidator(types_13.CurrentUserSchema).validate;
|
|
44
45
|
_h = createValidator(types_1.ActivityEventSchema), exports.validateActivityEvent = _h.validate, exports.validateActivityEventArray = _h.validateArray;
|
|
45
|
-
exports.validateAttachment = createValidator(
|
|
46
|
-
_j = createValidator(
|
|
47
|
-
_k = createValidator(
|
|
48
|
-
exports.validateWorkspacePlanDetails = createValidator(
|
|
49
|
-
exports.validateJoinWorkspaceResult = createValidator(
|
|
50
|
-
_l = createValidator(
|
|
51
|
-
_m = createValidator(
|
|
52
|
-
_o = createValidator(
|
|
46
|
+
exports.validateAttachment = createValidator(types_4.AttachmentSchema).validate;
|
|
47
|
+
_j = createValidator(types_14.WorkspaceUserSchema), exports.validateWorkspaceUser = _j.validate, exports.validateWorkspaceUserArray = _j.validateArray;
|
|
48
|
+
_k = createValidator(types_14.WorkspaceInvitationSchema), exports.validateWorkspaceInvitation = _k.validate, exports.validateWorkspaceInvitationArray = _k.validateArray;
|
|
49
|
+
exports.validateWorkspacePlanDetails = createValidator(types_14.WorkspacePlanDetailsSchema).validate;
|
|
50
|
+
exports.validateJoinWorkspaceResult = createValidator(types_14.JoinWorkspaceResultSchema).validate;
|
|
51
|
+
_l = createValidator(types_14.WorkspaceSchema), exports.validateWorkspace = _l.validate, exports.validateWorkspaceArray = _l.validateArray;
|
|
52
|
+
_m = createValidator(types_14.MemberActivityInfoSchema), exports.validateMemberActivityInfo = _m.validate, exports.validateMemberActivityInfoArray = _m.validateArray;
|
|
53
|
+
_o = createValidator(types_14.WorkspaceUserTaskSchema), exports.validateWorkspaceUserTask = _o.validate, exports.validateWorkspaceUserTaskArray = _o.validateArray;
|
|
53
54
|
exports.validateProjectActivityStats = createValidator(types_6.ProjectActivityStatsSchema).validate;
|
|
54
55
|
exports.validateProjectHealth = createValidator(types_6.ProjectHealthSchema).validate;
|
|
55
56
|
exports.validateProjectHealthContext = createValidator(types_6.ProjectHealthContextSchema).validate;
|
|
56
57
|
exports.validateProjectProgress = createValidator(types_6.ProjectProgressSchema).validate;
|
|
57
58
|
exports.validateWorkspaceInsights = createValidator(types_6.WorkspaceInsightsSchema).validate;
|
|
58
|
-
_p = createValidator(
|
|
59
|
+
_p = createValidator(types_3.BackupSchema), exports.validateBackup = _p.validate, exports.validateBackupArray = _p.validateArray;
|
|
59
60
|
_q = createValidator(types_5.IdMappingSchema), exports.validateIdMapping = _q.validate, exports.validateIdMappingArray = _q.validateArray;
|
|
60
61
|
_r = createValidator(types_5.MovedIdSchema), exports.validateMovedId = _r.validate, exports.validateMovedIdArray = _r.validateArray;
|
|
61
62
|
// Sync resource validators
|
|
@@ -63,24 +64,35 @@ _s = createValidator(resources_1.FilterSchema), exports.validateFilter = _s.vali
|
|
|
63
64
|
_t = createValidator(resources_1.CollaboratorSchema), exports.validateCollaborator = _t.validate, exports.validateCollaboratorArray = _t.validateArray;
|
|
64
65
|
_u = createValidator(resources_1.CollaboratorStateSchema), exports.validateCollaboratorState = _u.validate, exports.validateCollaboratorStateArray = _u.validateArray;
|
|
65
66
|
_v = createValidator(resources_1.FolderSchema), exports.validateFolder = _v.validate, exports.validateFolderArray = _v.validateArray;
|
|
66
|
-
_w = createValidator(
|
|
67
|
-
_x = createValidator(resources_1.NoteSchema), exports.validateNote = _x.validate, exports.validateNoteArray = _x.validateArray;
|
|
67
|
+
_w = createValidator(resources_1.NoteSchema), exports.validateNote = _w.validate, exports.validateNoteArray = _w.validateArray;
|
|
68
68
|
exports.validateTooltips = createValidator(resources_1.TooltipsSchema).validate;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
69
|
+
_x = createValidator(resources_1.WorkspaceFilterSchema), exports.validateWorkspaceFilter = _x.validate, exports.validateWorkspaceFilterArray = _x.validateArray;
|
|
70
|
+
_y = createValidator(resources_1.WorkspaceGoalSchema), exports.validateWorkspaceGoal = _y.validate, exports.validateWorkspaceGoalArray = _y.validateArray;
|
|
71
|
+
_z = createValidator(resources_1.CalendarSchema), exports.validateCalendar = _z.validate, exports.validateCalendarArray = _z.validateArray;
|
|
72
|
+
_0 = createValidator(resources_1.CalendarAccountSchema), exports.validateCalendarAccount = _0.validate, exports.validateCalendarAccountArray = _0.validateArray;
|
|
73
|
+
_1 = createValidator(resources_1.ReminderSchema), exports.validateReminder = _1.validate, exports.validateReminderArray = _1.validateArray;
|
|
74
|
+
_2 = createValidator(resources_1.LocationReminderSchema), exports.validateLocationReminder = _2.validate, exports.validateLocationReminderArray = _2.validateArray;
|
|
75
|
+
_3 = createValidator(resources_1.CompletedInfoSchema), exports.validateCompletedInfo = _3.validate, exports.validateCompletedInfoArray = _3.validateArray;
|
|
76
|
+
_4 = createValidator(resources_1.ViewOptionsSchema), exports.validateViewOptions = _4.validate, exports.validateViewOptionsArray = _4.validateArray;
|
|
77
|
+
_5 = createValidator(resources_1.ProjectViewOptionsDefaultsSchema), exports.validateProjectViewOptionsDefaults = _5.validate, exports.validateProjectViewOptionsDefaultsArray = _5.validateArray;
|
|
78
78
|
exports.validateUserPlanLimits = createValidator(resources_1.UserPlanLimitsSchema).validate;
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
_6 = createValidator(resources_1.LiveNotificationSchema), exports.validateLiveNotification = _6.validate, exports.validateLiveNotificationArray = _6.validateArray;
|
|
80
|
+
_7 = createValidator(resources_1.SyncWorkspaceSchema), exports.validateSyncWorkspace = _7.validate, exports.validateSyncWorkspaceArray = _7.validateArray;
|
|
81
81
|
exports.validateSyncUser = createValidator(resources_1.SyncUserSchema).validate;
|
|
82
82
|
exports.validateUserSettings = createValidator(resources_1.UserSettingsSchema).validate;
|
|
83
|
-
|
|
83
|
+
_8 = createValidator(resources_1.SuggestionSchema), exports.validateSuggestion = _8.validate, exports.validateSuggestionArray = _8.validateArray;
|
|
84
84
|
function parseSyncResponse(raw) {
|
|
85
85
|
return response_1.SyncResponseSchema.parse(raw);
|
|
86
86
|
}
|
|
87
|
+
// App management validators
|
|
88
|
+
_9 = createValidator(types_2.AppSchema), exports.validateApp = _9.validate, exports.validateAppArray = _9.validateArray;
|
|
89
|
+
exports.validateAppWithUserCount = createValidator(types_2.AppWithUserCountSchema).validate;
|
|
90
|
+
exports.validateAppSecrets = createValidator(types_2.AppSecretsSchema).validate;
|
|
91
|
+
exports.validateAppVerificationToken = createValidator(types_2.AppVerificationTokenSchema).validate;
|
|
92
|
+
exports.validateAppTestToken = createValidator(types_2.AppTestTokenSchema).validate;
|
|
93
|
+
exports.validateAppDistributionToken = createValidator(types_2.AppDistributionTokenSchema).validate;
|
|
94
|
+
exports.validateAppByDistributionToken = createValidator(types_2.AppByDistributionTokenSchema).validate;
|
|
95
|
+
exports.validateAppWebhook = createValidator(types_2.AppWebhookSchema).validate;
|
|
96
|
+
_10 = createValidator(types_2.AppInstallationSchema), exports.validateAppInstallation = _10.validate, exports.validateAppInstallationArray = _10.validateArray;
|
|
97
|
+
_11 = createValidator(types_2.UserAuthorizationSchema), exports.validateUserAuthorization = _11.validate, exports.validateUserAuthorizationArray = _11.validateArray;
|
|
98
|
+
_12 = createValidator(types_12.UiExtensionSchema), exports.validateUiExtension = _12.validate, exports.validateUiExtensionArray = _12.validateArray;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { ENDPOINT_REST_ACTIVITIES } from '../consts/endpoints.js';
|
|
13
|
+
import { request } from '../transport/http-client.js';
|
|
14
|
+
import { denormalizeObjectTypeFromApi, normalizeObjectEventTypeForApi, } from '../utils/activity-helpers.js';
|
|
15
|
+
import { formatDateToYYYYMMDD } from '../utils/url-helpers.js';
|
|
16
|
+
import { validateActivityEventArray } from '../utils/validators.js';
|
|
17
|
+
import { BaseClient } from './base-client.js';
|
|
18
|
+
/**
|
|
19
|
+
* Internal sub-client handling the activity-log endpoint.
|
|
20
|
+
*
|
|
21
|
+
* Instantiated by `TodoistApi`; the public `getActivityLogs` method on
|
|
22
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
23
|
+
* JSDoc.
|
|
24
|
+
*/
|
|
25
|
+
export class ActivityClient extends BaseClient {
|
|
26
|
+
async getActivityLogs(args = {}) {
|
|
27
|
+
// Convert Date objects to YYYY-MM-DD strings
|
|
28
|
+
const dateFrom = args.dateFrom instanceof Date ? formatDateToYYYYMMDD(args.dateFrom) : args.dateFrom;
|
|
29
|
+
const dateTo = args.dateTo instanceof Date ? formatDateToYYYYMMDD(args.dateTo) : args.dateTo;
|
|
30
|
+
// Destructure out raw date, filter-type, and removed legacy fields so they don't leak into payload
|
|
31
|
+
const _a = args, { dateFrom: _dateFrom, dateTo: _dateTo, objectEventTypes, objectType: _objectType, eventType: _eventType, since: _since, until: _until } = _a, rest = __rest(_a, ["dateFrom", "dateTo", "objectEventTypes", "objectType", "eventType", "since", "until"]);
|
|
32
|
+
// Build normalized objectEventTypes for the API
|
|
33
|
+
let normalizedObjectEventTypes;
|
|
34
|
+
if (objectEventTypes !== undefined) {
|
|
35
|
+
const arr = Array.isArray(objectEventTypes) ? objectEventTypes : [objectEventTypes];
|
|
36
|
+
normalizedObjectEventTypes = arr.map(normalizeObjectEventTypeForApi);
|
|
37
|
+
}
|
|
38
|
+
const processedArgs = Object.assign(Object.assign(Object.assign(Object.assign({}, rest), (dateFrom !== undefined ? { dateFrom } : {})), (dateTo !== undefined ? { dateTo } : {})), (normalizedObjectEventTypes !== undefined
|
|
39
|
+
? { objectEventTypes: normalizedObjectEventTypes }
|
|
40
|
+
: {}));
|
|
41
|
+
const { data: { results, nextCursor }, } = await request({
|
|
42
|
+
httpMethod: 'GET',
|
|
43
|
+
baseUri: this.syncApiBase,
|
|
44
|
+
relativePath: ENDPOINT_REST_ACTIVITIES,
|
|
45
|
+
apiToken: this.authToken,
|
|
46
|
+
customFetch: this.customFetch,
|
|
47
|
+
payload: processedArgs,
|
|
48
|
+
});
|
|
49
|
+
// Convert legacy API object types back to modern SDK types
|
|
50
|
+
const normalizedResults = results.map((event) => {
|
|
51
|
+
const normalizedType = denormalizeObjectTypeFromApi(event.objectType);
|
|
52
|
+
return Object.assign(Object.assign({}, event), { objectType: normalizedType || event.objectType });
|
|
53
|
+
});
|
|
54
|
+
return {
|
|
55
|
+
results: validateActivityEventArray(normalizedResults),
|
|
56
|
+
nextCursor,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { ENDPOINT_REST_APPS, ENDPOINT_REST_APPS_INSTALLATIONS, ENDPOINT_REST_USER_AUTHORIZATIONS, ENDPOINT_REST_USER_AUTHORIZATIONS_DELETE, getAppByDistributionTokenEndpoint, getAppClientSecretEndpoint, getAppDistributionTokenEndpoint, getAppEndpoint, getAppIconEndpoint, getAppInstallationEndpoint, getAppSecretsEndpoint, getAppTestTokenEndpoint, getAppTokensEndpoint, getAppVerificationTokenEndpoint, getAppWebhookEndpoint, } from '../consts/endpoints.js';
|
|
14
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
15
|
+
import { webhookEventToWireName } from '../types/apps/index.js';
|
|
16
|
+
import { camelCaseKeys } from '../utils/case-conversion.js';
|
|
17
|
+
import { uploadMultipartFile } from '../utils/multipart-upload.js';
|
|
18
|
+
import { validateApp, validateAppArray, validateAppByDistributionToken, validateAppDistributionToken, validateAppInstallation, validateAppInstallationArray, validateAppSecrets, validateAppTestToken, validateAppVerificationToken, validateAppWebhook, validateAppWithUserCount, validateUserAuthorizationArray, } from '../utils/validators.js';
|
|
19
|
+
import { BaseClient } from './base-client.js';
|
|
20
|
+
/**
|
|
21
|
+
* Internal sub-client handling all developer-app management endpoints
|
|
22
|
+
* (apps, secrets, tokens, webhooks, installations, user authorizations).
|
|
23
|
+
* All endpoints require the `dev:app_console` OAuth scope.
|
|
24
|
+
*
|
|
25
|
+
* Instantiated by `TodoistApi`; every public app-management method on
|
|
26
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing JSDoc.
|
|
27
|
+
*/
|
|
28
|
+
export class AppClient extends BaseClient {
|
|
29
|
+
async getApps(requestId) {
|
|
30
|
+
const response = await request({
|
|
31
|
+
httpMethod: 'GET',
|
|
32
|
+
baseUri: this.syncApiBase,
|
|
33
|
+
relativePath: ENDPOINT_REST_APPS,
|
|
34
|
+
apiToken: this.authToken,
|
|
35
|
+
customFetch: this.customFetch,
|
|
36
|
+
requestId: requestId,
|
|
37
|
+
});
|
|
38
|
+
return validateAppArray(response.data);
|
|
39
|
+
}
|
|
40
|
+
async getApp(appId, requestId) {
|
|
41
|
+
z.string().parse(appId);
|
|
42
|
+
const response = await request({
|
|
43
|
+
httpMethod: 'GET',
|
|
44
|
+
baseUri: this.syncApiBase,
|
|
45
|
+
relativePath: getAppEndpoint(appId),
|
|
46
|
+
apiToken: this.authToken,
|
|
47
|
+
customFetch: this.customFetch,
|
|
48
|
+
requestId: requestId,
|
|
49
|
+
});
|
|
50
|
+
return validateAppWithUserCount(response.data);
|
|
51
|
+
}
|
|
52
|
+
async addApp(args, requestId) {
|
|
53
|
+
const response = await request({
|
|
54
|
+
httpMethod: 'POST',
|
|
55
|
+
baseUri: this.syncApiBase,
|
|
56
|
+
relativePath: ENDPOINT_REST_APPS,
|
|
57
|
+
apiToken: this.authToken,
|
|
58
|
+
customFetch: this.customFetch,
|
|
59
|
+
payload: args,
|
|
60
|
+
requestId: requestId,
|
|
61
|
+
});
|
|
62
|
+
return validateApp(response.data);
|
|
63
|
+
}
|
|
64
|
+
async updateApp(appId, args, requestId) {
|
|
65
|
+
z.string().parse(appId);
|
|
66
|
+
const { appTokenScopes } = args, rest = __rest(args, ["appTokenScopes"]);
|
|
67
|
+
const payload = Object.assign({}, rest);
|
|
68
|
+
if (appTokenScopes !== undefined) {
|
|
69
|
+
payload.appTokenScopes = appTokenScopes === null ? null : appTokenScopes.join(',');
|
|
70
|
+
}
|
|
71
|
+
const response = await request({
|
|
72
|
+
httpMethod: 'POST',
|
|
73
|
+
baseUri: this.syncApiBase,
|
|
74
|
+
relativePath: getAppEndpoint(appId),
|
|
75
|
+
apiToken: this.authToken,
|
|
76
|
+
customFetch: this.customFetch,
|
|
77
|
+
payload: payload,
|
|
78
|
+
requestId: requestId,
|
|
79
|
+
});
|
|
80
|
+
return validateAppWithUserCount(response.data);
|
|
81
|
+
}
|
|
82
|
+
async deleteApp(appId, requestId) {
|
|
83
|
+
z.string().parse(appId);
|
|
84
|
+
const response = await request({
|
|
85
|
+
httpMethod: 'DELETE',
|
|
86
|
+
baseUri: this.syncApiBase,
|
|
87
|
+
relativePath: getAppEndpoint(appId),
|
|
88
|
+
apiToken: this.authToken,
|
|
89
|
+
customFetch: this.customFetch,
|
|
90
|
+
requestId: requestId,
|
|
91
|
+
});
|
|
92
|
+
return isSuccess(response);
|
|
93
|
+
}
|
|
94
|
+
async getAppSecrets(appId, requestId) {
|
|
95
|
+
z.string().parse(appId);
|
|
96
|
+
const response = await request({
|
|
97
|
+
httpMethod: 'GET',
|
|
98
|
+
baseUri: this.syncApiBase,
|
|
99
|
+
relativePath: getAppSecretsEndpoint(appId),
|
|
100
|
+
apiToken: this.authToken,
|
|
101
|
+
customFetch: this.customFetch,
|
|
102
|
+
requestId: requestId,
|
|
103
|
+
});
|
|
104
|
+
return validateAppSecrets(response.data);
|
|
105
|
+
}
|
|
106
|
+
async resetAppClientSecret(appId, requestId) {
|
|
107
|
+
z.string().parse(appId);
|
|
108
|
+
const response = await request({
|
|
109
|
+
httpMethod: 'DELETE',
|
|
110
|
+
baseUri: this.syncApiBase,
|
|
111
|
+
relativePath: getAppClientSecretEndpoint(appId),
|
|
112
|
+
apiToken: this.authToken,
|
|
113
|
+
customFetch: this.customFetch,
|
|
114
|
+
requestId: requestId,
|
|
115
|
+
});
|
|
116
|
+
return validateAppWithUserCount(response.data);
|
|
117
|
+
}
|
|
118
|
+
async revokeAppTokens(appId, requestId) {
|
|
119
|
+
z.string().parse(appId);
|
|
120
|
+
const response = await request({
|
|
121
|
+
httpMethod: 'DELETE',
|
|
122
|
+
baseUri: this.syncApiBase,
|
|
123
|
+
relativePath: getAppTokensEndpoint(appId),
|
|
124
|
+
apiToken: this.authToken,
|
|
125
|
+
customFetch: this.customFetch,
|
|
126
|
+
requestId: requestId,
|
|
127
|
+
});
|
|
128
|
+
return validateAppWithUserCount(response.data);
|
|
129
|
+
}
|
|
130
|
+
async uploadAppIcon(args, requestId) {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
if (Buffer.isBuffer(args.file) && args.file.length === 0) {
|
|
133
|
+
throw new Error('Cannot upload empty image file');
|
|
134
|
+
}
|
|
135
|
+
const size = (_a = args.size) !== null && _a !== void 0 ? _a : 'medium';
|
|
136
|
+
const data = await uploadMultipartFile({
|
|
137
|
+
baseUrl: this.syncApiBase,
|
|
138
|
+
authToken: this.authToken,
|
|
139
|
+
endpoint: getAppIconEndpoint(args.appId, size),
|
|
140
|
+
file: args.file,
|
|
141
|
+
fileName: args.fileName,
|
|
142
|
+
additionalFields: { file_name: (_b = args.fileName) !== null && _b !== void 0 ? _b : '' },
|
|
143
|
+
requestId: requestId,
|
|
144
|
+
customFetch: this.customFetch,
|
|
145
|
+
});
|
|
146
|
+
return validateAppWithUserCount(camelCaseKeys(data));
|
|
147
|
+
}
|
|
148
|
+
async getAppTestToken(appId, requestId) {
|
|
149
|
+
z.string().parse(appId);
|
|
150
|
+
const response = await request({
|
|
151
|
+
httpMethod: 'GET',
|
|
152
|
+
baseUri: this.syncApiBase,
|
|
153
|
+
relativePath: getAppTestTokenEndpoint(appId),
|
|
154
|
+
apiToken: this.authToken,
|
|
155
|
+
customFetch: this.customFetch,
|
|
156
|
+
requestId: requestId,
|
|
157
|
+
});
|
|
158
|
+
return validateAppTestToken(response.data);
|
|
159
|
+
}
|
|
160
|
+
async createAppTestToken(appId, requestId) {
|
|
161
|
+
z.string().parse(appId);
|
|
162
|
+
const response = await request({
|
|
163
|
+
httpMethod: 'PUT',
|
|
164
|
+
baseUri: this.syncApiBase,
|
|
165
|
+
relativePath: getAppTestTokenEndpoint(appId),
|
|
166
|
+
apiToken: this.authToken,
|
|
167
|
+
customFetch: this.customFetch,
|
|
168
|
+
requestId: requestId,
|
|
169
|
+
});
|
|
170
|
+
return validateAppTestToken(response.data);
|
|
171
|
+
}
|
|
172
|
+
async getAppDistributionToken(appId, requestId) {
|
|
173
|
+
z.string().parse(appId);
|
|
174
|
+
const response = await request({
|
|
175
|
+
httpMethod: 'GET',
|
|
176
|
+
baseUri: this.syncApiBase,
|
|
177
|
+
relativePath: getAppDistributionTokenEndpoint(appId),
|
|
178
|
+
apiToken: this.authToken,
|
|
179
|
+
customFetch: this.customFetch,
|
|
180
|
+
requestId: requestId,
|
|
181
|
+
});
|
|
182
|
+
return validateAppDistributionToken(response.data);
|
|
183
|
+
}
|
|
184
|
+
async getAppVerificationToken(appId, requestId) {
|
|
185
|
+
z.string().parse(appId);
|
|
186
|
+
const response = await request({
|
|
187
|
+
httpMethod: 'GET',
|
|
188
|
+
baseUri: this.syncApiBase,
|
|
189
|
+
relativePath: getAppVerificationTokenEndpoint(appId),
|
|
190
|
+
apiToken: this.authToken,
|
|
191
|
+
customFetch: this.customFetch,
|
|
192
|
+
requestId: requestId,
|
|
193
|
+
});
|
|
194
|
+
return validateAppVerificationToken(response.data);
|
|
195
|
+
}
|
|
196
|
+
async resetAppVerificationToken(appId, requestId) {
|
|
197
|
+
z.string().parse(appId);
|
|
198
|
+
const response = await request({
|
|
199
|
+
httpMethod: 'DELETE',
|
|
200
|
+
baseUri: this.syncApiBase,
|
|
201
|
+
relativePath: getAppVerificationTokenEndpoint(appId),
|
|
202
|
+
apiToken: this.authToken,
|
|
203
|
+
customFetch: this.customFetch,
|
|
204
|
+
requestId: requestId,
|
|
205
|
+
});
|
|
206
|
+
return validateAppVerificationToken(response.data);
|
|
207
|
+
}
|
|
208
|
+
async getAppByDistributionToken(distributionToken, requestId) {
|
|
209
|
+
z.string().parse(distributionToken);
|
|
210
|
+
const response = await request({
|
|
211
|
+
httpMethod: 'GET',
|
|
212
|
+
baseUri: this.syncApiBase,
|
|
213
|
+
relativePath: getAppByDistributionTokenEndpoint(distributionToken),
|
|
214
|
+
apiToken: this.authToken,
|
|
215
|
+
customFetch: this.customFetch,
|
|
216
|
+
requestId: requestId,
|
|
217
|
+
});
|
|
218
|
+
return validateAppByDistributionToken(response.data);
|
|
219
|
+
}
|
|
220
|
+
// --- App webhooks ---
|
|
221
|
+
async getAppWebhook(appId, requestId) {
|
|
222
|
+
z.string().parse(appId);
|
|
223
|
+
const response = await request({
|
|
224
|
+
httpMethod: 'GET',
|
|
225
|
+
baseUri: this.syncApiBase,
|
|
226
|
+
relativePath: getAppWebhookEndpoint(appId),
|
|
227
|
+
apiToken: this.authToken,
|
|
228
|
+
customFetch: this.customFetch,
|
|
229
|
+
requestId: requestId,
|
|
230
|
+
});
|
|
231
|
+
return response.data ? validateAppWebhook(response.data) : null;
|
|
232
|
+
}
|
|
233
|
+
async updateAppWebhook(args, requestId) {
|
|
234
|
+
const { appId, events } = args, rest = __rest(args, ["appId", "events"]);
|
|
235
|
+
const response = await request({
|
|
236
|
+
httpMethod: 'POST',
|
|
237
|
+
baseUri: this.syncApiBase,
|
|
238
|
+
relativePath: getAppWebhookEndpoint(appId),
|
|
239
|
+
apiToken: this.authToken,
|
|
240
|
+
customFetch: this.customFetch,
|
|
241
|
+
payload: Object.assign(Object.assign({}, rest), { events: events.map(webhookEventToWireName) }),
|
|
242
|
+
requestId: requestId,
|
|
243
|
+
});
|
|
244
|
+
return validateAppWebhook(response.data);
|
|
245
|
+
}
|
|
246
|
+
async deleteAppWebhook(appId, requestId) {
|
|
247
|
+
z.string().parse(appId);
|
|
248
|
+
const response = await request({
|
|
249
|
+
httpMethod: 'DELETE',
|
|
250
|
+
baseUri: this.syncApiBase,
|
|
251
|
+
relativePath: getAppWebhookEndpoint(appId),
|
|
252
|
+
apiToken: this.authToken,
|
|
253
|
+
customFetch: this.customFetch,
|
|
254
|
+
requestId: requestId,
|
|
255
|
+
});
|
|
256
|
+
return isSuccess(response);
|
|
257
|
+
}
|
|
258
|
+
// --- App installations ---
|
|
259
|
+
async getAppInstallations(requestId) {
|
|
260
|
+
const response = await request({
|
|
261
|
+
httpMethod: 'GET',
|
|
262
|
+
baseUri: this.syncApiBase,
|
|
263
|
+
relativePath: ENDPOINT_REST_APPS_INSTALLATIONS,
|
|
264
|
+
apiToken: this.authToken,
|
|
265
|
+
customFetch: this.customFetch,
|
|
266
|
+
requestId: requestId,
|
|
267
|
+
});
|
|
268
|
+
return validateAppInstallationArray(response.data);
|
|
269
|
+
}
|
|
270
|
+
async installApp(args, requestId) {
|
|
271
|
+
const response = await request({
|
|
272
|
+
httpMethod: 'POST',
|
|
273
|
+
baseUri: this.syncApiBase,
|
|
274
|
+
relativePath: ENDPOINT_REST_APPS_INSTALLATIONS,
|
|
275
|
+
apiToken: this.authToken,
|
|
276
|
+
customFetch: this.customFetch,
|
|
277
|
+
payload: args,
|
|
278
|
+
requestId: requestId,
|
|
279
|
+
});
|
|
280
|
+
return validateAppInstallation(response.data);
|
|
281
|
+
}
|
|
282
|
+
async getAppInstallation(installationId, requestId) {
|
|
283
|
+
z.string().parse(installationId);
|
|
284
|
+
const response = await request({
|
|
285
|
+
httpMethod: 'GET',
|
|
286
|
+
baseUri: this.syncApiBase,
|
|
287
|
+
relativePath: getAppInstallationEndpoint(installationId),
|
|
288
|
+
apiToken: this.authToken,
|
|
289
|
+
customFetch: this.customFetch,
|
|
290
|
+
requestId: requestId,
|
|
291
|
+
});
|
|
292
|
+
return validateAppInstallation(response.data);
|
|
293
|
+
}
|
|
294
|
+
async updateAppInstallation(installationId, args, requestId) {
|
|
295
|
+
z.string().parse(installationId);
|
|
296
|
+
const response = await request({
|
|
297
|
+
httpMethod: 'POST',
|
|
298
|
+
baseUri: this.syncApiBase,
|
|
299
|
+
relativePath: getAppInstallationEndpoint(installationId),
|
|
300
|
+
apiToken: this.authToken,
|
|
301
|
+
customFetch: this.customFetch,
|
|
302
|
+
payload: args,
|
|
303
|
+
requestId: requestId,
|
|
304
|
+
});
|
|
305
|
+
return validateAppInstallation(response.data);
|
|
306
|
+
}
|
|
307
|
+
async uninstallApp(installationId, requestId) {
|
|
308
|
+
z.string().parse(installationId);
|
|
309
|
+
const response = await request({
|
|
310
|
+
httpMethod: 'DELETE',
|
|
311
|
+
baseUri: this.syncApiBase,
|
|
312
|
+
relativePath: getAppInstallationEndpoint(installationId),
|
|
313
|
+
apiToken: this.authToken,
|
|
314
|
+
customFetch: this.customFetch,
|
|
315
|
+
requestId: requestId,
|
|
316
|
+
});
|
|
317
|
+
return isSuccess(response);
|
|
318
|
+
}
|
|
319
|
+
// --- User authorizations ---
|
|
320
|
+
async getUserAuthorizations(requestId) {
|
|
321
|
+
const response = await request({
|
|
322
|
+
httpMethod: 'GET',
|
|
323
|
+
baseUri: this.syncApiBase,
|
|
324
|
+
relativePath: ENDPOINT_REST_USER_AUTHORIZATIONS,
|
|
325
|
+
apiToken: this.authToken,
|
|
326
|
+
customFetch: this.customFetch,
|
|
327
|
+
requestId: requestId,
|
|
328
|
+
});
|
|
329
|
+
return validateUserAuthorizationArray(response.data);
|
|
330
|
+
}
|
|
331
|
+
async revokeUserAuthorization(args, requestId) {
|
|
332
|
+
const response = await request({
|
|
333
|
+
httpMethod: 'POST',
|
|
334
|
+
baseUri: this.syncApiBase,
|
|
335
|
+
relativePath: ENDPOINT_REST_USER_AUTHORIZATIONS_DELETE,
|
|
336
|
+
apiToken: this.authToken,
|
|
337
|
+
customFetch: this.customFetch,
|
|
338
|
+
payload: args,
|
|
339
|
+
requestId: requestId,
|
|
340
|
+
});
|
|
341
|
+
return isSuccess(response);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ENDPOINT_REST_BACKUPS, ENDPOINT_REST_BACKUPS_DOWNLOAD } from '../consts/endpoints.js';
|
|
2
|
+
import { request } from '../transport/http-client.js';
|
|
3
|
+
import { headersToRecord } from '../utils/headers.js';
|
|
4
|
+
import { validateBackupArray } from '../utils/validators.js';
|
|
5
|
+
import { BaseClient } from './base-client.js';
|
|
6
|
+
/**
|
|
7
|
+
* Internal sub-client handling backup-domain endpoints.
|
|
8
|
+
*
|
|
9
|
+
* Instantiated by `TodoistApi`; every public backup method on
|
|
10
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
11
|
+
* JSDoc.
|
|
12
|
+
*/
|
|
13
|
+
export class BackupClient extends BaseClient {
|
|
14
|
+
async getBackups(args = {}) {
|
|
15
|
+
const response = await request({
|
|
16
|
+
httpMethod: 'GET',
|
|
17
|
+
baseUri: this.syncApiBase,
|
|
18
|
+
relativePath: ENDPOINT_REST_BACKUPS,
|
|
19
|
+
apiToken: this.authToken,
|
|
20
|
+
customFetch: this.customFetch,
|
|
21
|
+
payload: args,
|
|
22
|
+
});
|
|
23
|
+
return validateBackupArray(response.data);
|
|
24
|
+
}
|
|
25
|
+
async downloadBackup(args) {
|
|
26
|
+
const url = `${this.syncApiBase}${ENDPOINT_REST_BACKUPS_DOWNLOAD}?file=${encodeURIComponent(args.file)}`;
|
|
27
|
+
const fetchOptions = {
|
|
28
|
+
headers: { Authorization: `Bearer ${this.authToken}` },
|
|
29
|
+
};
|
|
30
|
+
if (this.customFetch) {
|
|
31
|
+
const response = await this.customFetch(url, fetchOptions);
|
|
32
|
+
if (!response.ok) {
|
|
33
|
+
throw new Error(`Failed to download backup: ${response.status} ${response.statusText}`);
|
|
34
|
+
}
|
|
35
|
+
const text = await response.text();
|
|
36
|
+
const buffer = new TextEncoder().encode(text).buffer;
|
|
37
|
+
return {
|
|
38
|
+
ok: response.ok,
|
|
39
|
+
status: response.status,
|
|
40
|
+
statusText: response.statusText,
|
|
41
|
+
headers: response.headers,
|
|
42
|
+
text: () => Promise.resolve(text),
|
|
43
|
+
json: () => response.json(),
|
|
44
|
+
arrayBuffer: () => Promise.resolve(buffer),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const response = await fetch(url, fetchOptions);
|
|
48
|
+
if (!response.ok) {
|
|
49
|
+
throw new Error(`Failed to download backup: ${response.status} ${response.statusText}`);
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
ok: response.ok,
|
|
53
|
+
status: response.status,
|
|
54
|
+
statusText: response.statusText,
|
|
55
|
+
headers: headersToRecord(response.headers),
|
|
56
|
+
text: () => response.text(),
|
|
57
|
+
json: () => response.json(),
|
|
58
|
+
arrayBuffer: () => response.arrayBuffer(),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal base class for every domain sub-client (tasks, projects, …).
|
|
3
|
+
*
|
|
4
|
+
* Not exported from the package — sub-clients are an implementation detail
|
|
5
|
+
* of `TodoistApi`. Holds the three pieces of HTTP identity every sub-client
|
|
6
|
+
* needs and exposes a typed accessor to feed the Sync API helper.
|
|
7
|
+
*
|
|
8
|
+
* The constructor takes a {@link SyncRequestContext} — the same record
|
|
9
|
+
* shape used by `performSyncRequest` — so there is a single type describing
|
|
10
|
+
* "the HTTP identity an SDK component needs", not two types that must stay
|
|
11
|
+
* in sync.
|
|
12
|
+
*/
|
|
13
|
+
export class BaseClient {
|
|
14
|
+
constructor(context) {
|
|
15
|
+
this.authToken = context.authToken;
|
|
16
|
+
this.syncApiBase = context.syncApiBase;
|
|
17
|
+
this.customFetch = context.customFetch;
|
|
18
|
+
}
|
|
19
|
+
get syncContext() {
|
|
20
|
+
return {
|
|
21
|
+
authToken: this.authToken,
|
|
22
|
+
syncApiBase: this.syncApiBase,
|
|
23
|
+
customFetch: this.customFetch,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|