@doist/todoist-api-typescript 6.5.0 → 6.6.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.
Files changed (144) hide show
  1. package/dist/cjs/todoist-api.js +32 -4
  2. package/dist/cjs/types/index.js +1 -0
  3. package/dist/cjs/types/sync/commands/calendars.js +2 -0
  4. package/dist/cjs/types/sync/commands/filters.js +2 -0
  5. package/dist/cjs/types/sync/commands/folders.js +2 -0
  6. package/dist/cjs/types/sync/commands/index.js +35 -0
  7. package/dist/cjs/types/sync/commands/labels.js +2 -0
  8. package/dist/cjs/types/sync/commands/notes.js +2 -0
  9. package/dist/cjs/types/sync/commands/notifications.js +2 -0
  10. package/dist/cjs/types/sync/commands/others.js +2 -0
  11. package/dist/cjs/types/sync/commands/project-view-options.js +2 -0
  12. package/dist/cjs/types/sync/commands/projects.js +2 -0
  13. package/dist/cjs/types/sync/commands/reminders.js +2 -0
  14. package/dist/cjs/types/sync/commands/sections.js +2 -0
  15. package/dist/cjs/types/sync/commands/shared.js +5 -0
  16. package/dist/cjs/types/sync/commands/sharing.js +2 -0
  17. package/dist/cjs/types/sync/commands/tasks.js +2 -0
  18. package/dist/cjs/types/sync/commands/view-options.js +2 -0
  19. package/dist/cjs/types/sync/commands/workspace-filters.js +2 -0
  20. package/dist/cjs/types/sync/commands/workspace-goals.js +2 -0
  21. package/dist/cjs/types/sync/commands/workspaces.js +2 -0
  22. package/dist/cjs/types/sync/index.js +21 -0
  23. package/dist/cjs/types/sync/request.js +2 -0
  24. package/dist/cjs/types/{sync.js → sync/resource-types.js} +9 -0
  25. package/dist/cjs/types/sync/resources/calendars.js +27 -0
  26. package/dist/cjs/types/sync/resources/collaborators.js +23 -0
  27. package/dist/cjs/types/sync/resources/completed-info.js +30 -0
  28. package/dist/cjs/types/sync/resources/filters.js +16 -0
  29. package/dist/cjs/types/sync/resources/folders.js +14 -0
  30. package/dist/cjs/types/sync/resources/index.js +33 -0
  31. package/dist/cjs/types/sync/resources/live-notifications.js +28 -0
  32. package/dist/cjs/types/sync/resources/notes.js +23 -0
  33. package/dist/cjs/types/sync/resources/reminders.js +34 -0
  34. package/dist/cjs/types/sync/resources/suggestions.js +38 -0
  35. package/dist/cjs/types/sync/resources/tooltips.js +10 -0
  36. package/dist/cjs/types/sync/resources/user-plan-limits.js +24 -0
  37. package/dist/cjs/types/sync/resources/user-settings.js +42 -0
  38. package/dist/cjs/types/sync/resources/user.js +123 -0
  39. package/dist/cjs/types/sync/resources/view-options.js +75 -0
  40. package/dist/cjs/types/sync/resources/workspace-filters.js +21 -0
  41. package/dist/cjs/types/sync/resources/workspace-goals.js +32 -0
  42. package/dist/cjs/types/sync/resources/workspaces.js +49 -0
  43. package/dist/cjs/types/sync/response.js +2 -0
  44. package/dist/cjs/utils/index.js +3 -1
  45. package/dist/cjs/utils/multipart-upload.js +93 -42
  46. package/dist/cjs/utils/sync-helpers.js +22 -0
  47. package/dist/cjs/utils/validators.js +69 -88
  48. package/dist/esm/todoist-api.js +32 -4
  49. package/dist/esm/types/index.js +1 -0
  50. package/dist/esm/types/sync/commands/calendars.js +1 -0
  51. package/dist/esm/types/sync/commands/filters.js +1 -0
  52. package/dist/esm/types/sync/commands/folders.js +1 -0
  53. package/dist/esm/types/sync/commands/index.js +19 -0
  54. package/dist/esm/types/sync/commands/labels.js +1 -0
  55. package/dist/esm/types/sync/commands/notes.js +1 -0
  56. package/dist/esm/types/sync/commands/notifications.js +1 -0
  57. package/dist/esm/types/sync/commands/others.js +1 -0
  58. package/dist/esm/types/sync/commands/project-view-options.js +1 -0
  59. package/dist/esm/types/sync/commands/projects.js +1 -0
  60. package/dist/esm/types/sync/commands/reminders.js +1 -0
  61. package/dist/esm/types/sync/commands/sections.js +1 -0
  62. package/dist/esm/types/sync/commands/shared.js +4 -0
  63. package/dist/esm/types/sync/commands/sharing.js +1 -0
  64. package/dist/esm/types/sync/commands/tasks.js +1 -0
  65. package/dist/esm/types/sync/commands/view-options.js +1 -0
  66. package/dist/esm/types/sync/commands/workspace-filters.js +1 -0
  67. package/dist/esm/types/sync/commands/workspace-goals.js +1 -0
  68. package/dist/esm/types/sync/commands/workspaces.js +1 -0
  69. package/dist/esm/types/sync/index.js +5 -0
  70. package/dist/esm/types/sync/request.js +1 -0
  71. package/dist/esm/types/{sync.js → sync/resource-types.js} +9 -0
  72. package/dist/esm/types/sync/resources/calendars.js +24 -0
  73. package/dist/esm/types/sync/resources/collaborators.js +20 -0
  74. package/dist/esm/types/sync/resources/completed-info.js +27 -0
  75. package/dist/esm/types/sync/resources/filters.js +13 -0
  76. package/dist/esm/types/sync/resources/folders.js +11 -0
  77. package/dist/esm/types/sync/resources/index.js +17 -0
  78. package/dist/esm/types/sync/resources/live-notifications.js +25 -0
  79. package/dist/esm/types/sync/resources/notes.js +20 -0
  80. package/dist/esm/types/sync/resources/reminders.js +31 -0
  81. package/dist/esm/types/sync/resources/suggestions.js +35 -0
  82. package/dist/esm/types/sync/resources/tooltips.js +7 -0
  83. package/dist/esm/types/sync/resources/user-plan-limits.js +21 -0
  84. package/dist/esm/types/sync/resources/user-settings.js +39 -0
  85. package/dist/esm/types/sync/resources/user.js +120 -0
  86. package/dist/esm/types/sync/resources/view-options.js +72 -0
  87. package/dist/esm/types/sync/resources/workspace-filters.js +18 -0
  88. package/dist/esm/types/sync/resources/workspace-goals.js +29 -0
  89. package/dist/esm/types/sync/resources/workspaces.js +46 -0
  90. package/dist/esm/types/sync/response.js +1 -0
  91. package/dist/esm/utils/index.js +1 -0
  92. package/dist/esm/utils/multipart-upload.js +60 -39
  93. package/dist/esm/utils/sync-helpers.js +19 -0
  94. package/dist/esm/utils/validators.js +65 -64
  95. package/dist/types/todoist-api.d.ts +26 -0
  96. package/dist/types/types/index.d.ts +1 -0
  97. package/dist/types/types/requests.d.ts +3 -3
  98. package/dist/types/types/sync/commands/calendars.d.ts +14 -0
  99. package/dist/types/types/sync/commands/filters.d.ts +21 -0
  100. package/dist/types/types/sync/commands/folders.d.ts +18 -0
  101. package/dist/types/types/sync/commands/index.d.ts +172 -0
  102. package/dist/types/types/sync/commands/labels.d.ts +27 -0
  103. package/dist/types/types/sync/commands/notes.d.ts +27 -0
  104. package/dist/types/types/sync/commands/notifications.d.ts +10 -0
  105. package/dist/types/types/sync/commands/others.d.ts +14 -0
  106. package/dist/types/types/sync/commands/project-view-options.d.ts +14 -0
  107. package/dist/types/types/sync/commands/projects.d.ts +88 -0
  108. package/dist/types/types/sync/commands/reminders.d.ts +27 -0
  109. package/dist/types/types/sync/commands/sections.d.ts +31 -0
  110. package/dist/types/types/sync/commands/shared.d.ts +46 -0
  111. package/dist/types/types/sync/commands/sharing.d.ts +16 -0
  112. package/dist/types/types/sync/commands/tasks.d.ts +78 -0
  113. package/dist/types/types/sync/commands/view-options.d.ts +19 -0
  114. package/dist/types/types/sync/commands/workspace-filters.d.ts +22 -0
  115. package/dist/types/types/sync/commands/workspace-goals.d.ts +24 -0
  116. package/dist/types/types/sync/commands/workspaces.d.ts +79 -0
  117. package/dist/types/types/sync/index.d.ts +5 -0
  118. package/dist/types/types/sync/request.d.ts +7 -0
  119. package/dist/types/types/sync/resource-types.d.ts +5 -0
  120. package/dist/types/types/sync/resources/calendars.d.ts +30 -0
  121. package/dist/types/types/sync/resources/collaborators.d.ts +24 -0
  122. package/dist/types/types/sync/resources/completed-info.d.ts +33 -0
  123. package/dist/types/types/sync/resources/filters.d.ts +12 -0
  124. package/dist/types/types/sync/resources/folders.d.ts +10 -0
  125. package/dist/types/types/sync/resources/index.d.ts +17 -0
  126. package/dist/types/types/sync/resources/live-notifications.d.ts +23 -0
  127. package/dist/types/types/sync/resources/notes.d.ts +34 -0
  128. package/dist/types/types/sync/resources/reminders.d.ts +101 -0
  129. package/dist/types/types/sync/resources/suggestions.d.ts +54 -0
  130. package/dist/types/types/sync/resources/tooltips.d.ts +6 -0
  131. package/dist/types/types/sync/resources/user-plan-limits.d.ts +41 -0
  132. package/dist/types/types/sync/resources/user-settings.d.ts +32 -0
  133. package/dist/types/types/sync/resources/user.d.ts +104 -0
  134. package/dist/types/types/sync/resources/view-options.d.ts +94 -0
  135. package/dist/types/types/sync/resources/workspace-filters.d.ts +17 -0
  136. package/dist/types/types/sync/resources/workspace-goals.d.ts +29 -0
  137. package/dist/types/types/sync/resources/workspaces.d.ts +52 -0
  138. package/dist/types/types/sync/response.d.ts +47 -0
  139. package/dist/types/utils/index.d.ts +1 -0
  140. package/dist/types/utils/multipart-upload.d.ts +5 -3
  141. package/dist/types/utils/sync-helpers.d.ts +17 -0
  142. package/dist/types/utils/validators.d.ts +1163 -23
  143. package/package.json +8 -8
  144. package/dist/types/types/sync.d.ts +0 -30
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ const NavigationFeatureSchema = z.object({
3
+ name: z.string(),
4
+ shown: z.boolean(),
5
+ });
6
+ const QuickAddFeatureSchema = z.object({
7
+ name: z.string(),
8
+ shown: z.boolean(),
9
+ });
10
+ /**
11
+ * Sync API user settings resource.
12
+ */
13
+ export const UserSettingsSchema = z
14
+ .object({
15
+ completedSoundDesktop: z.boolean(),
16
+ completedSoundMobile: z.boolean(),
17
+ debugLogSendingEnabledUntil: z.string().nullable(),
18
+ legacyPricing: z.boolean(),
19
+ navigation: z
20
+ .object({
21
+ countsShown: z.boolean(),
22
+ features: z.array(NavigationFeatureSchema),
23
+ })
24
+ .passthrough(),
25
+ reminderDesktop: z.boolean(),
26
+ reminderEmail: z.boolean(),
27
+ reminderPush: z.boolean(),
28
+ resetRecurringSubtasks: z.boolean(),
29
+ aiEmailAssist: z.boolean(),
30
+ theme: z.string().nullable().optional(),
31
+ syncTheme: z.boolean().optional(),
32
+ quickAdd: z
33
+ .object({
34
+ labelsShown: z.boolean(),
35
+ features: z.array(QuickAddFeatureSchema),
36
+ })
37
+ .passthrough(),
38
+ })
39
+ .passthrough();
@@ -0,0 +1,120 @@
1
+ import { z } from 'zod';
2
+ const FeaturesSchema = z
3
+ .object({
4
+ karmaDisabled: z.boolean(),
5
+ restriction: z.number().int(),
6
+ karmaVacation: z.boolean(),
7
+ dateistLang: z.any(),
8
+ beta: z.union([z.literal(0), z.literal(1)]),
9
+ hasPushReminders: z.boolean(),
10
+ dateistInlineDisabled: z.boolean(),
11
+ autoInviteDisabled: z.boolean().optional(),
12
+ goldTheme: z.boolean().optional(),
13
+ migratedFromTdb: z.boolean().optional(),
14
+ })
15
+ .passthrough();
16
+ const TzInfoSchema = z
17
+ .object({
18
+ timezone: z.string(),
19
+ hours: z.number().int(),
20
+ minutes: z.number().int(),
21
+ isDst: z.union([z.literal(0), z.literal(1)]),
22
+ gmtString: z.string(),
23
+ })
24
+ .passthrough();
25
+ const JoinableWorkspaceSchema = z
26
+ .object({
27
+ workspaceId: z.string(),
28
+ workspaceName: z.string(),
29
+ memberCount: z.number().int(),
30
+ })
31
+ .passthrough();
32
+ const GettingStartedGuideProjectSchema = z
33
+ .object({
34
+ onboardingUseCase: z.string(),
35
+ projectId: z.string(),
36
+ completed: z.boolean(),
37
+ closed: z.boolean(),
38
+ })
39
+ .passthrough();
40
+ /**
41
+ * Sync API user resource.
42
+ *
43
+ * This is a superset of the REST `CurrentUserSchema` — the Sync API returns
44
+ * many additional fields for features, onboarding state, and account details.
45
+ */
46
+ export const SyncUserSchema = z
47
+ .object({
48
+ id: z.string(),
49
+ email: z.string(),
50
+ fullName: z.string(),
51
+ activatedUser: z.boolean(),
52
+ autoReminder: z.number().int(),
53
+ avatarBig: z.string().optional(),
54
+ avatarMedium: z.string().optional(),
55
+ avatarS640: z.string().optional(),
56
+ avatarSmall: z.string().optional(),
57
+ businessAccountId: z.string().nullable(),
58
+ dailyGoal: z.number().int(),
59
+ dateFormat: z.number().int(),
60
+ dateistLang: z.string().nullable(),
61
+ daysOff: z.array(z.number().int()),
62
+ featureIdentifier: z.string(),
63
+ features: FeaturesSchema,
64
+ freeTrailExpires: z.string().optional(),
65
+ hasMagicNumber: z.boolean(),
66
+ hasPassword: z.boolean(),
67
+ hasStartedATrial: z.boolean().optional(),
68
+ imageId: z.string().nullable(),
69
+ inboxProjectId: z.string(),
70
+ isCelebrationsEnabled: z.boolean(),
71
+ isPremium: z.boolean(),
72
+ joinableWorkspace: JoinableWorkspaceSchema.nullable(),
73
+ joinedAt: z.string(),
74
+ gettingStartedGuideProjects: z.array(GettingStartedGuideProjectSchema).nullable(),
75
+ karma: z.number(),
76
+ karmaTrend: z.string(),
77
+ lang: z.string(),
78
+ mfaEnabled: z.boolean().optional(),
79
+ mobileHost: z.string().nullable(),
80
+ mobileNumber: z.string().nullable(),
81
+ nextWeek: z.number().int(),
82
+ onboardingLevel: z.string().nullable().optional(),
83
+ onboardingRole: z.string().nullable().optional(),
84
+ onboardingPersona: z.string().nullable().optional(),
85
+ onboardingInitiated: z.boolean().nullable().optional(),
86
+ onboardingCompleted: z.boolean().nullable().optional(),
87
+ onboardingSkipped: z.boolean().optional(),
88
+ onboardingTeamMode: z.boolean().nullable().optional(),
89
+ onboardingUseCases: z.array(z.string()).nullable().optional(),
90
+ premiumStatus: z.enum([
91
+ 'not_premium',
92
+ 'current_personal_plan',
93
+ 'legacy_personal_plan',
94
+ 'teams_business_member',
95
+ ]),
96
+ premiumUntil: z.string().nullable(),
97
+ rambleSessionsUsage: z
98
+ .object({
99
+ currentCount: z.number().int(),
100
+ limit: z.number().int(),
101
+ remaining: z.number().int(),
102
+ resetDate: z.string(),
103
+ })
104
+ .nullable()
105
+ .optional(),
106
+ shareLimit: z.number().int(),
107
+ sortOrder: z.number().int(),
108
+ startDay: z.number().int(),
109
+ startPage: z.string(),
110
+ themeId: z.string(),
111
+ timeFormat: z.number().int(),
112
+ token: z.string(),
113
+ tzInfo: TzInfoSchema,
114
+ uniquePrefix: z.number().int(),
115
+ verificationStatus: z.string(),
116
+ websocketUrl: z.string(),
117
+ weekendStartDay: z.number().int(),
118
+ weeklyGoal: z.number().int(),
119
+ })
120
+ .passthrough();
@@ -0,0 +1,72 @@
1
+ import { z } from 'zod';
2
+ const ViewTypeSchema = z.enum([
3
+ 'TODAY',
4
+ 'UPCOMING',
5
+ 'PROJECT',
6
+ 'LABEL',
7
+ 'FILTER',
8
+ 'WORKSPACE_FILTER',
9
+ 'SEARCH',
10
+ 'TEMPLATE_PREVIEW',
11
+ 'TASK_DETAIL',
12
+ 'AUTOMATION',
13
+ 'ASSIGNED',
14
+ 'OVERDUE',
15
+ 'WORKSPACE_OVERVIEW',
16
+ ]);
17
+ const ViewModeSchema = z.enum(['LIST', 'BOARD', 'CALENDAR']);
18
+ const GroupedBySchema = z
19
+ .enum([
20
+ 'ASSIGNEE',
21
+ 'ADDED_DATE',
22
+ 'DUE_DATE',
23
+ 'DEADLINE',
24
+ 'LABEL',
25
+ 'PRIORITY',
26
+ 'PROJECT',
27
+ 'WORKSPACE',
28
+ ])
29
+ .nullable();
30
+ const SortedBySchema = z
31
+ .enum([
32
+ 'MANUAL',
33
+ 'ALPHABETICALLY',
34
+ 'ASSIGNEE',
35
+ 'DUE_DATE',
36
+ 'DEADLINE',
37
+ 'ADDED_DATE',
38
+ 'PRIORITY',
39
+ 'PROJECT',
40
+ 'WORKSPACE',
41
+ ])
42
+ .nullable();
43
+ const SortOrderSchema = z.enum(['ASC', 'DESC']).nullable();
44
+ const CalendarSettingsSchema = z
45
+ .object({
46
+ layout: z.enum(['WEEK', 'MONTH']).optional(),
47
+ })
48
+ .passthrough();
49
+ export const ViewOptionsSchema = z
50
+ .object({
51
+ viewType: ViewTypeSchema,
52
+ objectId: z.string().optional(),
53
+ groupedBy: GroupedBySchema.optional(),
54
+ filteredBy: z.string().nullable().optional(),
55
+ viewMode: ViewModeSchema.optional(),
56
+ showCompletedTasks: z.boolean().optional(),
57
+ sortedBy: SortedBySchema.optional(),
58
+ sortOrder: SortOrderSchema.optional(),
59
+ })
60
+ .passthrough();
61
+ export const ProjectViewOptionsDefaultsSchema = z
62
+ .object({
63
+ projectId: z.string(),
64
+ viewMode: ViewModeSchema.nullable().optional(),
65
+ groupedBy: GroupedBySchema.optional(),
66
+ sortedBy: SortedBySchema.optional(),
67
+ sortOrder: SortOrderSchema.optional(),
68
+ showCompletedTasks: z.boolean().optional(),
69
+ filteredBy: z.string().nullable().optional(),
70
+ calendarSettings: CalendarSettingsSchema.nullable().optional(),
71
+ })
72
+ .passthrough();
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+ export const WorkspaceFilterSchema = z
3
+ .object({
4
+ id: z.string(),
5
+ workspaceId: z.string(),
6
+ name: z.string(),
7
+ query: z.string(),
8
+ color: z.string(),
9
+ itemOrder: z.number().int(),
10
+ isDeleted: z.boolean(),
11
+ isFavorite: z.boolean(),
12
+ isFrozen: z.boolean(),
13
+ creatorUid: z.string(),
14
+ updaterUid: z.string(),
15
+ createdAt: z.string(),
16
+ updatedAt: z.string(),
17
+ })
18
+ .passthrough();
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ export const WorkspaceGoalMilestoneSchema = z
3
+ .object({
4
+ id: z.string(),
5
+ title: z.string(),
6
+ isCompleted: z.boolean(),
7
+ })
8
+ .passthrough();
9
+ export const WorkspaceGoalProgressSchema = z
10
+ .object({
11
+ completedItems: z.number().int(),
12
+ totalItems: z.number().int(),
13
+ })
14
+ .passthrough();
15
+ export const WorkspaceGoalSchema = z
16
+ .object({
17
+ id: z.string(),
18
+ workspaceId: z.string(),
19
+ title: z.string(),
20
+ description: z.string().nullable(),
21
+ deadline: z.string().nullable(),
22
+ isDeleted: z.boolean(),
23
+ projectIds: z.array(z.string()),
24
+ progress: WorkspaceGoalProgressSchema.nullable(),
25
+ creatorUid: z.string(),
26
+ createdAt: z.string(),
27
+ updatedAt: z.string(),
28
+ })
29
+ .passthrough();
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+ import { WorkspaceRoleSchema, WorkspacePlanSchema, WorkspaceLimitsSchema, WorkspacePropertiesSchema, } from '../../entities.js';
3
+ /**
4
+ * Sync API workspace resource.
5
+ *
6
+ * This is a superset of the REST `WorkspaceSchema` — the Sync API returns
7
+ * additional fields like description, isDeleted, isCollapsed, member counts,
8
+ * domain settings, and sorting preferences.
9
+ */
10
+ export const SyncWorkspaceSchema = z
11
+ .object({
12
+ id: z.string(),
13
+ name: z.string(),
14
+ description: z.string(),
15
+ logoBig: z.string().optional(),
16
+ logoMedium: z.string().optional(),
17
+ logoSmall: z.string().optional(),
18
+ logoS640: z.string().optional(),
19
+ creatorId: z.string(),
20
+ createdAt: z.string(),
21
+ isDeleted: z.boolean(),
22
+ isCollapsed: z.boolean(),
23
+ role: WorkspaceRoleSchema,
24
+ plan: WorkspacePlanSchema,
25
+ limits: WorkspaceLimitsSchema,
26
+ inviteCode: z.string().nullable().optional(),
27
+ isLinkSharingEnabled: z.boolean().nullable().optional(),
28
+ isGuestAllowed: z.boolean().nullable().optional(),
29
+ currentActiveProjects: z.number().nullable(),
30
+ currentMemberCount: z.number().nullable(),
31
+ currentTemplateCount: z.number().nullable(),
32
+ pendingInvitations: z.array(z.string()).nullable().optional(),
33
+ domainName: z.string().optional(),
34
+ domainDiscovery: z.boolean().optional(),
35
+ restrictEmailDomains: z.boolean().optional(),
36
+ adminSortingApplied: z.boolean(),
37
+ projectSortPreference: z.string().optional(),
38
+ defaultCollaborators: z
39
+ .object({
40
+ predefinedGroupIds: z.array(z.string()),
41
+ userIds: z.array(z.number()),
42
+ })
43
+ .optional(),
44
+ properties: WorkspacePropertiesSchema.optional(),
45
+ })
46
+ .passthrough();
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,4 @@
1
1
  export * from './colors.js';
2
2
  export * from './sanitization.js';
3
3
  export { getTaskUrl, getProjectUrl, getSectionUrl } from './url-helpers.js';
4
+ export { createCommand } from './sync-helpers.js';
@@ -1,6 +1,3 @@
1
- import FormData from 'form-data';
2
- import { createReadStream } from 'fs';
3
- import { basename } from 'path';
4
1
  import { fetchWithRetry } from './fetch-with-retry.js';
5
2
  /**
6
3
  * Helper function to determine content-type from filename extension.
@@ -31,11 +28,13 @@ function getContentTypeFromFileName(fileName) {
31
28
  * This is a shared utility for uploading files to Todoist endpoints that require
32
29
  * multipart/form-data content type (e.g., file uploads, workspace logo uploads).
33
30
  *
31
+ * Supports both browser (Blob/File) and Node.js (Buffer/ReadableStream/path) environments.
32
+ *
34
33
  * @param baseUrl - The base API URL (e.g., https://api.todoist.com/api/v1/)
35
34
  * @param authToken - The authentication token
36
35
  * @param endpoint - The relative endpoint path (e.g., 'uploads', 'workspaces/logo')
37
- * @param file - The file content (Buffer, ReadableStream, or file system path)
38
- * @param fileName - Optional file name (required for Buffer/Stream, optional for paths)
36
+ * @param file - The file content (Blob/File for browser, or Buffer/ReadableStream/path for Node)
37
+ * @param fileName - Optional file name (required for Buffer/Stream, optional for paths and File objects)
39
38
  * @param additionalFields - Additional form fields to include (e.g., project_id, workspace_id)
40
39
  * @param requestId - Optional request ID for idempotency
41
40
  * @returns The response data from the server
@@ -66,52 +65,74 @@ function getContentTypeFromFileName(fileName) {
66
65
  */
67
66
  export async function uploadMultipartFile(args) {
68
67
  const { baseUrl, authToken, endpoint, file, fileName, additionalFields, requestId, customFetch, } = args;
69
- const form = new FormData();
70
- // Determine file type and add to form data
71
- if (typeof file === 'string') {
72
- // File path - create read stream
73
- const filePath = file;
74
- const resolvedFileName = fileName || basename(filePath);
75
- form.append('file', createReadStream(filePath), resolvedFileName);
68
+ // Build the full URL
69
+ const url = `${baseUrl}${endpoint}`;
70
+ let body;
71
+ const headers = {
72
+ Authorization: `Bearer ${authToken}`,
73
+ };
74
+ if (requestId) {
75
+ headers['X-Request-Id'] = requestId;
76
76
  }
77
- else if (Buffer.isBuffer(file)) {
78
- // Buffer - require fileName
79
- if (!fileName) {
80
- throw new Error('fileName is required when uploading from a Buffer');
77
+ if (file instanceof Blob) {
78
+ // Browser path: use native FormData
79
+ const form = new globalThis.FormData();
80
+ const resolvedFileName = fileName || (file instanceof File ? file.name : undefined) || 'upload';
81
+ form.append('file', file, resolvedFileName);
82
+ for (const [key, value] of Object.entries(additionalFields)) {
83
+ if (value !== undefined && value !== null) {
84
+ form.append(key, value.toString());
85
+ }
81
86
  }
82
- // Detect content-type from filename extension
83
- const contentType = getContentTypeFromFileName(fileName);
84
- form.append('file', file, {
85
- filename: fileName,
86
- contentType: contentType,
87
- });
87
+ // Don't set Content-Type let fetch set it with the correct multipart boundary
88
+ body = form;
88
89
  }
89
90
  else {
90
- // Stream - require fileName
91
- if (!fileName) {
92
- throw new Error('fileName is required when uploading from a stream');
91
+ // Node path: dynamically import Node-only modules
92
+ const [FormDataModule, fsModule, pathModule] = await Promise.all([
93
+ import('form-data'),
94
+ import('fs'),
95
+ import('path'),
96
+ ]);
97
+ const FormData = FormDataModule.default;
98
+ const form = new FormData();
99
+ if (typeof file === 'string') {
100
+ // File path - create read stream
101
+ const resolvedFileName = fileName || pathModule.basename(file);
102
+ form.append('file', fsModule.createReadStream(file), resolvedFileName);
93
103
  }
94
- form.append('file', file, fileName);
95
- }
96
- // Add additional fields to the form
97
- for (const [key, value] of Object.entries(additionalFields)) {
98
- if (value !== undefined && value !== null) {
99
- form.append(key, value.toString());
104
+ else if (Buffer.isBuffer(file)) {
105
+ // Buffer - require fileName
106
+ if (!fileName) {
107
+ throw new Error('fileName is required when uploading from a Buffer');
108
+ }
109
+ const contentType = getContentTypeFromFileName(fileName);
110
+ form.append('file', file, {
111
+ filename: fileName,
112
+ contentType: contentType,
113
+ });
100
114
  }
101
- }
102
- // Build the full URL
103
- const url = `${baseUrl}${endpoint}`;
104
- // Prepare headers
105
- const headers = Object.assign({ Authorization: `Bearer ${authToken}` }, form.getHeaders());
106
- if (requestId) {
107
- headers['X-Request-Id'] = requestId;
115
+ else {
116
+ // Stream - require fileName
117
+ if (!fileName) {
118
+ throw new Error('fileName is required when uploading from a stream');
119
+ }
120
+ form.append('file', file, fileName);
121
+ }
122
+ for (const [key, value] of Object.entries(additionalFields)) {
123
+ if (value !== undefined && value !== null) {
124
+ form.append(key, value.toString());
125
+ }
126
+ }
127
+ Object.assign(headers, form.getHeaders());
128
+ body = form;
108
129
  }
109
130
  // Make the request using fetch
110
131
  const response = await fetchWithRetry({
111
132
  url,
112
133
  options: {
113
134
  method: 'POST',
114
- body: form, // FormData from 'form-data' package is compatible with fetch
135
+ body,
115
136
  headers,
116
137
  timeout: 30000, // 30 second timeout for file uploads
117
138
  },
@@ -0,0 +1,19 @@
1
+ import { v4 as uuidv4 } from 'uuid';
2
+ /**
3
+ * Creates a strongly-typed Sync API command with an auto-generated UUID.
4
+ *
5
+ * @param type - The command type (e.g. `'item_add'`, `'project_update'`).
6
+ * @param args - The command arguments, constrained by the command type.
7
+ * @param tempId - Optional temporary ID for referencing the created resource in subsequent commands.
8
+ * @returns A fully formed `SyncCommand` ready to include in a sync request.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * const cmd = createCommand('item_add', { content: 'Buy milk', priority: 2 })
13
+ * // cmd.type === 'item_add'
14
+ * // cmd.args is typed as TaskAddArgs
15
+ * ```
16
+ */
17
+ export function createCommand(type, args, tempId) {
18
+ return Object.assign({ type, uuid: uuidv4(), args: args }, (tempId !== undefined ? { tempId } : {}));
19
+ }
@@ -1,10 +1,14 @@
1
1
  import { AttachmentSchema, SectionSchema, LabelSchema, CommentSchema, UserSchema, CurrentUserSchema, TaskSchema, PersonalProjectSchema, WorkspaceProjectSchema, ProductivityStatsSchema, ActivityEventSchema, WorkspaceUserSchema, WorkspaceInvitationSchema, WorkspacePlanDetailsSchema, JoinWorkspaceResultSchema, WorkspaceSchema, } from '../types/entities.js';
2
- export function validateTask(input) {
3
- return TaskSchema.parse(input);
2
+ import { FilterSchema, CollaboratorSchema, CollaboratorStateSchema, FolderSchema, NoteSchema, TooltipsSchema, WorkspaceFilterSchema, WorkspaceGoalSchema, CalendarSchema, CalendarAccountSchema, ReminderSchema, CompletedInfoSchema, ViewOptionsSchema, ProjectViewOptionsDefaultsSchema, UserPlanLimitsSchema, LiveNotificationSchema, SyncWorkspaceSchema, SyncUserSchema, UserSettingsSchema, SuggestionSchema, } from '../types/sync/resources/index.js';
3
+ function createValidator(schema) {
4
+ return (input) => schema.parse(input);
4
5
  }
5
- export function validateTaskArray(input) {
6
- return input.map(validateTask);
6
+ function createArrayValidator(validateItem) {
7
+ return (input) => input.map(validateItem);
7
8
  }
9
+ // Entity validators
10
+ export const validateTask = createValidator(TaskSchema);
11
+ export const validateTaskArray = createArrayValidator(validateTask);
8
12
  /**
9
13
  * Type guard to check if a project is a workspace project.
10
14
  * @param project The project to check
@@ -35,69 +39,66 @@ export function validateProject(input) {
35
39
  export function validateProjectArray(input) {
36
40
  return input.map(validateProject);
37
41
  }
38
- export function validateSection(input) {
39
- return SectionSchema.parse(input);
40
- }
41
- export function validateSectionArray(input) {
42
- return input.map(validateSection);
43
- }
44
- export function validateLabel(input) {
45
- return LabelSchema.parse(input);
46
- }
47
- export function validateLabelArray(input) {
48
- return input.map(validateLabel);
49
- }
50
- export function validateComment(input) {
51
- return CommentSchema.parse(input);
52
- }
53
- export function validateCommentArray(input) {
54
- return input.map(validateComment);
55
- }
56
- export function validateUser(input) {
57
- return UserSchema.parse(input);
58
- }
59
- export function validateUserArray(input) {
60
- return input.map(validateUser);
61
- }
62
- export function validateProductivityStats(input) {
63
- return ProductivityStatsSchema.parse(input);
64
- }
65
- export function validateCurrentUser(input) {
66
- return CurrentUserSchema.parse(input);
67
- }
68
- export function validateActivityEvent(input) {
69
- return ActivityEventSchema.parse(input);
70
- }
71
- export function validateActivityEventArray(input) {
72
- return input.map(validateActivityEvent);
73
- }
74
- export function validateAttachment(input) {
75
- return AttachmentSchema.parse(input);
76
- }
77
- export function validateWorkspaceUser(input) {
78
- return WorkspaceUserSchema.parse(input);
79
- }
42
+ export const validateSection = createValidator(SectionSchema);
43
+ export const validateSectionArray = createArrayValidator(validateSection);
44
+ export const validateLabel = createValidator(LabelSchema);
45
+ export const validateLabelArray = createArrayValidator(validateLabel);
46
+ export const validateComment = createValidator(CommentSchema);
47
+ export const validateCommentArray = createArrayValidator(validateComment);
48
+ export const validateUser = createValidator(UserSchema);
49
+ export const validateUserArray = createArrayValidator(validateUser);
50
+ export const validateProductivityStats = createValidator(ProductivityStatsSchema);
51
+ export const validateCurrentUser = createValidator(CurrentUserSchema);
52
+ export const validateActivityEvent = createValidator(ActivityEventSchema);
53
+ export const validateActivityEventArray = createArrayValidator(validateActivityEvent);
54
+ export const validateAttachment = createValidator(AttachmentSchema);
55
+ export const validateWorkspaceUser = createValidator(WorkspaceUserSchema);
80
56
  export function validateWorkspaceUserArray(input) {
81
57
  if (!Array.isArray(input)) {
82
58
  throw new Error(`Expected array for workspace users, got ${typeof input}`);
83
59
  }
84
60
  return input.map(validateWorkspaceUser);
85
61
  }
86
- export function validateWorkspaceInvitation(input) {
87
- return WorkspaceInvitationSchema.parse(input);
88
- }
89
- export function validateWorkspaceInvitationArray(input) {
90
- return input.map(validateWorkspaceInvitation);
91
- }
92
- export function validateWorkspacePlanDetails(input) {
93
- return WorkspacePlanDetailsSchema.parse(input);
94
- }
95
- export function validateJoinWorkspaceResult(input) {
96
- return JoinWorkspaceResultSchema.parse(input);
97
- }
98
- export function validateWorkspace(input) {
99
- return WorkspaceSchema.parse(input);
100
- }
101
- export function validateWorkspaceArray(input) {
102
- return input.map(validateWorkspace);
103
- }
62
+ export const validateWorkspaceInvitation = createValidator(WorkspaceInvitationSchema);
63
+ export const validateWorkspaceInvitationArray = createArrayValidator(validateWorkspaceInvitation);
64
+ export const validateWorkspacePlanDetails = createValidator(WorkspacePlanDetailsSchema);
65
+ export const validateJoinWorkspaceResult = createValidator(JoinWorkspaceResultSchema);
66
+ export const validateWorkspace = createValidator(WorkspaceSchema);
67
+ export const validateWorkspaceArray = createArrayValidator(validateWorkspace);
68
+ // Sync resource validators
69
+ export const validateFilter = createValidator(FilterSchema);
70
+ export const validateFilterArray = createArrayValidator(validateFilter);
71
+ export const validateCollaborator = createValidator(CollaboratorSchema);
72
+ export const validateCollaboratorArray = createArrayValidator(validateCollaborator);
73
+ export const validateCollaboratorState = createValidator(CollaboratorStateSchema);
74
+ export const validateCollaboratorStateArray = createArrayValidator(validateCollaboratorState);
75
+ export const validateFolder = createValidator(FolderSchema);
76
+ export const validateFolderArray = createArrayValidator(validateFolder);
77
+ export const validateNote = createValidator(NoteSchema);
78
+ export const validateNoteArray = createArrayValidator(validateNote);
79
+ export const validateTooltips = createValidator(TooltipsSchema);
80
+ export const validateWorkspaceFilter = createValidator(WorkspaceFilterSchema);
81
+ export const validateWorkspaceFilterArray = createArrayValidator(validateWorkspaceFilter);
82
+ export const validateWorkspaceGoal = createValidator(WorkspaceGoalSchema);
83
+ export const validateWorkspaceGoalArray = createArrayValidator(validateWorkspaceGoal);
84
+ export const validateCalendar = createValidator(CalendarSchema);
85
+ export const validateCalendarArray = createArrayValidator(validateCalendar);
86
+ export const validateCalendarAccount = createValidator(CalendarAccountSchema);
87
+ export const validateCalendarAccountArray = createArrayValidator(validateCalendarAccount);
88
+ export const validateReminder = createValidator(ReminderSchema);
89
+ export const validateReminderArray = createArrayValidator(validateReminder);
90
+ export const validateCompletedInfo = createValidator(CompletedInfoSchema);
91
+ export const validateCompletedInfoArray = createArrayValidator(validateCompletedInfo);
92
+ export const validateViewOptions = createValidator(ViewOptionsSchema);
93
+ export const validateViewOptionsArray = createArrayValidator(validateViewOptions);
94
+ export const validateProjectViewOptionsDefaults = createValidator(ProjectViewOptionsDefaultsSchema);
95
+ export const validateProjectViewOptionsDefaultsArray = createArrayValidator(validateProjectViewOptionsDefaults);
96
+ export const validateUserPlanLimits = createValidator(UserPlanLimitsSchema);
97
+ export const validateLiveNotification = createValidator(LiveNotificationSchema);
98
+ export const validateLiveNotificationArray = createArrayValidator(validateLiveNotification);
99
+ export const validateSyncWorkspace = createValidator(SyncWorkspaceSchema);
100
+ export const validateSyncWorkspaceArray = createArrayValidator(validateSyncWorkspace);
101
+ export const validateSyncUser = createValidator(SyncUserSchema);
102
+ export const validateUserSettings = createValidator(UserSettingsSchema);
103
+ export const validateSuggestion = createValidator(SuggestionSchema);
104
+ export const validateSuggestionArray = createArrayValidator(validateSuggestion);