@doist/todoist-sdk 14.2.0 → 15.0.1

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 (174) hide show
  1. package/dist/esm/types/sync/resources/index.js +1 -0
  2. package/dist/esm/types/sync/resources/labels.js +7 -0
  3. package/dist/esm/types/sync/resources/reminders.js +11 -0
  4. package/dist/esm/types/sync/response.js +3 -4
  5. package/dist/esm/utils/index.js +1 -1
  6. package/dist/esm/utils/url-helpers.js +151 -23
  7. package/dist/types/types/sync/resources/index.d.ts +1 -0
  8. package/dist/types/types/sync/resources/labels.d.ts +12 -0
  9. package/dist/types/types/sync/resources/reminders.d.ts +87 -0
  10. package/dist/types/types/sync/response.d.ts +8 -7
  11. package/dist/types/utils/index.d.ts +2 -1
  12. package/dist/types/utils/url-helpers.d.ts +88 -0
  13. package/package.json +5 -10
  14. package/dist/cjs/authentication.js +0 -317
  15. package/dist/cjs/clients/activity-client.js +0 -63
  16. package/dist/cjs/clients/app-client.js +0 -345
  17. package/dist/cjs/clients/backup-client.js +0 -47
  18. package/dist/cjs/clients/base-client.js +0 -31
  19. package/dist/cjs/clients/billing-client.js +0 -152
  20. package/dist/cjs/clients/comment-client.js +0 -91
  21. package/dist/cjs/clients/email-client.js +0 -43
  22. package/dist/cjs/clients/folder-client.js +0 -79
  23. package/dist/cjs/clients/id-mapping-client.js +0 -39
  24. package/dist/cjs/clients/insights-client.js +0 -87
  25. package/dist/cjs/clients/label-client.js +0 -126
  26. package/dist/cjs/clients/productivity-client.js +0 -27
  27. package/dist/cjs/clients/project-client.js +0 -235
  28. package/dist/cjs/clients/reminder-client.js +0 -198
  29. package/dist/cjs/clients/section-client.js +0 -117
  30. package/dist/cjs/clients/task-client.js +0 -254
  31. package/dist/cjs/clients/template-client.js +0 -88
  32. package/dist/cjs/clients/ui-extension-client.js +0 -107
  33. package/dist/cjs/clients/upload-client.js +0 -155
  34. package/dist/cjs/clients/view-options-client.js +0 -25
  35. package/dist/cjs/clients/workspace-client.js +0 -366
  36. package/dist/cjs/consts/endpoints.js +0 -224
  37. package/dist/cjs/index.js +0 -24
  38. package/dist/cjs/package.json +0 -1
  39. package/dist/cjs/test-utils/asserts.js +0 -11
  40. package/dist/cjs/test-utils/msw-setup.js +0 -97
  41. package/dist/cjs/test-utils/obsidian-fetch-adapter.js +0 -54
  42. package/dist/cjs/test-utils/test-defaults.js +0 -371
  43. package/dist/cjs/test-utils/transport-seam.js +0 -17
  44. package/dist/cjs/test-utils/webhook-fixtures.js +0 -32
  45. package/dist/cjs/todoist-api.js +0 -1711
  46. package/dist/cjs/transport/fetch-with-retry.js +0 -219
  47. package/dist/cjs/transport/http-client.js +0 -134
  48. package/dist/cjs/transport/http-dispatcher.js +0 -198
  49. package/dist/cjs/transport/sync-request.js +0 -83
  50. package/dist/cjs/types/activity/index.js +0 -18
  51. package/dist/cjs/types/activity/requests.js +0 -2
  52. package/dist/cjs/types/activity/types.js +0 -28
  53. package/dist/cjs/types/apps/index.js +0 -18
  54. package/dist/cjs/types/apps/requests.js +0 -2
  55. package/dist/cjs/types/apps/types.js +0 -254
  56. package/dist/cjs/types/backups/index.js +0 -18
  57. package/dist/cjs/types/backups/requests.js +0 -2
  58. package/dist/cjs/types/backups/types.js +0 -8
  59. package/dist/cjs/types/billing/index.js +0 -18
  60. package/dist/cjs/types/billing/requests.js +0 -2
  61. package/dist/cjs/types/billing/types.js +0 -92
  62. package/dist/cjs/types/comments/index.js +0 -18
  63. package/dist/cjs/types/comments/requests.js +0 -2
  64. package/dist/cjs/types/comments/types.js +0 -60
  65. package/dist/cjs/types/common.js +0 -10
  66. package/dist/cjs/types/emails/index.js +0 -17
  67. package/dist/cjs/types/emails/requests.js +0 -5
  68. package/dist/cjs/types/errors.js +0 -29
  69. package/dist/cjs/types/folders/index.js +0 -17
  70. package/dist/cjs/types/folders/requests.js +0 -2
  71. package/dist/cjs/types/http.js +0 -24
  72. package/dist/cjs/types/id-mappings/index.js +0 -18
  73. package/dist/cjs/types/id-mappings/requests.js +0 -20
  74. package/dist/cjs/types/id-mappings/types.js +0 -12
  75. package/dist/cjs/types/index.js +0 -40
  76. package/dist/cjs/types/insights/index.js +0 -18
  77. package/dist/cjs/types/insights/requests.js +0 -2
  78. package/dist/cjs/types/insights/types.js +0 -80
  79. package/dist/cjs/types/labels/index.js +0 -18
  80. package/dist/cjs/types/labels/requests.js +0 -2
  81. package/dist/cjs/types/labels/types.js +0 -11
  82. package/dist/cjs/types/productivity/index.js +0 -17
  83. package/dist/cjs/types/productivity/types.js +0 -68
  84. package/dist/cjs/types/projects/index.js +0 -18
  85. package/dist/cjs/types/projects/requests.js +0 -2
  86. package/dist/cjs/types/projects/types.js +0 -66
  87. package/dist/cjs/types/reminders/index.js +0 -17
  88. package/dist/cjs/types/reminders/requests.js +0 -95
  89. package/dist/cjs/types/sections/index.js +0 -18
  90. package/dist/cjs/types/sections/requests.js +0 -2
  91. package/dist/cjs/types/sections/types.js +0 -25
  92. package/dist/cjs/types/sync/commands/calendars.js +0 -2
  93. package/dist/cjs/types/sync/commands/filters.js +0 -2
  94. package/dist/cjs/types/sync/commands/folders.js +0 -2
  95. package/dist/cjs/types/sync/commands/index.js +0 -34
  96. package/dist/cjs/types/sync/commands/labels.js +0 -5
  97. package/dist/cjs/types/sync/commands/notes.js +0 -2
  98. package/dist/cjs/types/sync/commands/notifications.js +0 -2
  99. package/dist/cjs/types/sync/commands/others.js +0 -2
  100. package/dist/cjs/types/sync/commands/project-view-options.js +0 -2
  101. package/dist/cjs/types/sync/commands/projects.js +0 -2
  102. package/dist/cjs/types/sync/commands/reminders.js +0 -2
  103. package/dist/cjs/types/sync/commands/sections.js +0 -2
  104. package/dist/cjs/types/sync/commands/shared.js +0 -20
  105. package/dist/cjs/types/sync/commands/sharing.js +0 -2
  106. package/dist/cjs/types/sync/commands/tasks.js +0 -2
  107. package/dist/cjs/types/sync/commands/view-options.js +0 -2
  108. package/dist/cjs/types/sync/commands/workspace-filters.js +0 -2
  109. package/dist/cjs/types/sync/commands/workspaces.js +0 -2
  110. package/dist/cjs/types/sync/index.js +0 -22
  111. package/dist/cjs/types/sync/request.js +0 -2
  112. package/dist/cjs/types/sync/resource-types.js +0 -39
  113. package/dist/cjs/types/sync/resources/calendars.js +0 -27
  114. package/dist/cjs/types/sync/resources/collaborators.js +0 -21
  115. package/dist/cjs/types/sync/resources/completed-info.js +0 -24
  116. package/dist/cjs/types/sync/resources/filters.js +0 -14
  117. package/dist/cjs/types/sync/resources/folders.js +0 -12
  118. package/dist/cjs/types/sync/resources/index.js +0 -32
  119. package/dist/cjs/types/sync/resources/live-notifications.js +0 -38
  120. package/dist/cjs/types/sync/resources/notes.js +0 -21
  121. package/dist/cjs/types/sync/resources/reminders.js +0 -50
  122. package/dist/cjs/types/sync/resources/suggestions.js +0 -36
  123. package/dist/cjs/types/sync/resources/tooltips.js +0 -8
  124. package/dist/cjs/types/sync/resources/user-plan-limits.js +0 -20
  125. package/dist/cjs/types/sync/resources/user-settings.js +0 -40
  126. package/dist/cjs/types/sync/resources/user.js +0 -110
  127. package/dist/cjs/types/sync/resources/view-options.js +0 -86
  128. package/dist/cjs/types/sync/resources/workspace-filters.js +0 -19
  129. package/dist/cjs/types/sync/resources/workspaces.js +0 -72
  130. package/dist/cjs/types/sync/response.js +0 -54
  131. package/dist/cjs/types/sync/user-preferences.js +0 -71
  132. package/dist/cjs/types/tasks/index.js +0 -18
  133. package/dist/cjs/types/tasks/requests.js +0 -2
  134. package/dist/cjs/types/tasks/types.js +0 -59
  135. package/dist/cjs/types/templates/index.js +0 -17
  136. package/dist/cjs/types/templates/requests.js +0 -2
  137. package/dist/cjs/types/ui-extensions/index.js +0 -18
  138. package/dist/cjs/types/ui-extensions/requests.js +0 -2
  139. package/dist/cjs/types/ui-extensions/types.js +0 -77
  140. package/dist/cjs/types/uploads/index.js +0 -17
  141. package/dist/cjs/types/uploads/requests.js +0 -2
  142. package/dist/cjs/types/users/index.js +0 -17
  143. package/dist/cjs/types/users/types.js +0 -51
  144. package/dist/cjs/types/webhooks/comments.js +0 -96
  145. package/dist/cjs/types/webhooks/envelope.js +0 -26
  146. package/dist/cjs/types/webhooks/filters.js +0 -30
  147. package/dist/cjs/types/webhooks/index.js +0 -25
  148. package/dist/cjs/types/webhooks/labels.js +0 -54
  149. package/dist/cjs/types/webhooks/projects.js +0 -36
  150. package/dist/cjs/types/webhooks/reminders.js +0 -35
  151. package/dist/cjs/types/webhooks/sections.js +0 -53
  152. package/dist/cjs/types/webhooks/tasks.js +0 -68
  153. package/dist/cjs/types/webhooks/types.js +0 -55
  154. package/dist/cjs/types/workspaces/index.js +0 -18
  155. package/dist/cjs/types/workspaces/requests.js +0 -2
  156. package/dist/cjs/types/workspaces/types.js +0 -154
  157. package/dist/cjs/utils/activity-helpers.js +0 -58
  158. package/dist/cjs/utils/case-conversion.js +0 -69
  159. package/dist/cjs/utils/colors.js +0 -143
  160. package/dist/cjs/utils/file-response.js +0 -32
  161. package/dist/cjs/utils/headers.js +0 -16
  162. package/dist/cjs/utils/index.js +0 -31
  163. package/dist/cjs/utils/multipart-upload.js +0 -293
  164. package/dist/cjs/utils/processing-helpers.js +0 -18
  165. package/dist/cjs/utils/project-helpers.js +0 -20
  166. package/dist/cjs/utils/request-helpers.js +0 -21
  167. package/dist/cjs/utils/sanitization.js +0 -116
  168. package/dist/cjs/utils/sync-helpers.js +0 -22
  169. package/dist/cjs/utils/task-sorting.js +0 -281
  170. package/dist/cjs/utils/uncompletable-helpers.js +0 -60
  171. package/dist/cjs/utils/url-helpers.js +0 -74
  172. package/dist/cjs/utils/validators.js +0 -108
  173. package/dist/cjs/utils/view-options.js +0 -19
  174. package/dist/cjs/utils/webhook-parser.js +0 -60
@@ -1,4 +1,5 @@
1
1
  export * from './filters.js';
2
+ export * from './labels.js';
2
3
  export * from './collaborators.js';
3
4
  export * from './folders.js';
4
5
  export * from './tooltips.js';
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+ import { LabelSchema } from '../../labels/types.js';
3
+ /** A label returned by the Sync API. */
4
+ export const SyncLabelSchema = LabelSchema.extend({
5
+ order: z.number().int().nullable().optional(),
6
+ isDeleted: z.boolean().optional(),
7
+ });
@@ -45,3 +45,14 @@ export const ReminderSchema = z.discriminatedUnion('type', [
45
45
  AbsoluteReminderSchema,
46
46
  RelativeReminderSchema,
47
47
  ]);
48
+ export const SyncAbsoluteReminderSchema = AbsoluteReminderSchema.extend({
49
+ due: DueDateSchema.nullable(),
50
+ });
51
+ export const SyncRelativeReminderSchema = RelativeReminderSchema.extend({
52
+ due: DueDateSchema.nullable().optional(),
53
+ });
54
+ export const SyncReminderSchema = z.discriminatedUnion('type', [
55
+ LocationReminderSchema,
56
+ SyncAbsoluteReminderSchema,
57
+ SyncRelativeReminderSchema,
58
+ ]);
@@ -1,10 +1,9 @@
1
1
  import { z } from 'zod';
2
- import { LabelSchema } from '../labels/types.js';
3
2
  import { ProjectSchema } from '../projects/types.js';
4
3
  import { SectionSchema } from '../sections/types.js';
5
4
  import { TaskSchema } from '../tasks/types.js';
6
5
  import { WorkspaceUserSchema } from '../workspaces/types.js';
7
- import { FilterSchema, CollaboratorSchema, CollaboratorStateSchema, FolderSchema, NoteSchema, TooltipsSchema, WorkspaceFilterSchema, CalendarSchema, CalendarAccountSchema, ReminderSchema, LocationReminderSchema, CompletedInfoSchema, ViewOptionsSchema, ProjectViewOptionsDefaultsSchema, UserPlanLimitsSchema, LiveNotificationSchema, SyncWorkspaceSchema, SyncUserSchema, UserSettingsSchema, SuggestionSchema, } from './resources/index.js';
6
+ import { FilterSchema, CollaboratorSchema, CollaboratorStateSchema, FolderSchema, NoteSchema, TooltipsSchema, WorkspaceFilterSchema, CalendarSchema, CalendarAccountSchema, SyncLabelSchema, SyncReminderSchema, LocationReminderSchema, CompletedInfoSchema, ViewOptionsSchema, ProjectViewOptionsDefaultsSchema, UserPlanLimitsSchema, LiveNotificationSchema, SyncWorkspaceSchema, SyncUserSchema, UserSettingsSchema, SuggestionSchema, } from './resources/index.js';
8
7
  export const SyncErrorSchema = z.object({
9
8
  error: z.string(),
10
9
  errorCode: z.number(),
@@ -20,11 +19,11 @@ export const SyncResponseSchema = z.looseObject({
20
19
  items: z.array(TaskSchema).optional(),
21
20
  projects: z.array(ProjectSchema).optional(),
22
21
  sections: z.array(SectionSchema).optional(),
23
- labels: z.array(LabelSchema).optional(),
22
+ labels: z.array(SyncLabelSchema).optional(),
24
23
  notes: z.array(NoteSchema).optional(),
25
24
  projectNotes: z.array(NoteSchema).optional(),
26
25
  filters: z.array(FilterSchema).optional(),
27
- reminders: z.array(ReminderSchema).optional(),
26
+ reminders: z.array(SyncReminderSchema).optional(),
28
27
  remindersLocation: z.array(LocationReminderSchema).optional(),
29
28
  locations: z.array(z.record(z.string(), z.unknown())).optional(),
30
29
  user: SyncUserSchema.optional(),
@@ -1,6 +1,6 @@
1
1
  export * from './colors.js';
2
2
  export * from './sanitization.js';
3
- export { getTaskUrl, getProjectUrl, getSectionUrl } from './url-helpers.js';
3
+ export { getTaskUrl, getProjectUrl, getSectionUrl, getLabelUrl, getFilterUrl, getWorkspaceFilterUrl, getWorkspaceUrl, getTaskCommentsUrl, getProjectCommentsUrl, getTaskCommentUrl, getProjectCommentUrl, parseTodoistUrl, TODOIST_LINK_TYPES, } from './url-helpers.js';
4
4
  export { createCommand } from './sync-helpers.js';
5
5
  export * from './project-helpers.js';
6
6
  export * from './task-sorting.js';
@@ -1,3 +1,5 @@
1
+ import { LinkEnvironment } from '@doist/sdk-kmp/common';
2
+ import { parseTodoistLink, todoistFilterUrl, todoistLabelUrl, todoistProjectCommentsUrl, todoistProjectCommentUrl, todoistProjectUrl, todoistSectionUrl, todoistTaskCommentsUrl, todoistTaskCommentUrl, todoistTaskUrl, todoistWorkspaceFilterUrl, todoistWorkspaceUrl, } from '@doist/sdk-kmp/todoist';
1
3
  import { TODOIST_WEB_URI } from '../consts/endpoints.js';
2
4
  /**
3
5
  * Formats a Date object to YYYY-MM-DD string format.
@@ -12,6 +14,23 @@ export function formatDateToYYYYMMDD(date) {
12
14
  const day = String(date.getDate()).padStart(2, '0');
13
15
  return `${year}-${month}-${day}`;
14
16
  }
17
+ /**
18
+ * Builds a URL, falling back to a bare-id URL when the link builder rejects the
19
+ * given id. These helpers are called while parsing API responses, so generating
20
+ * a URL must never fail the parse.
21
+ *
22
+ * @param build Builds the URL.
23
+ * @param fallbackPath The path to fall back to, relative to the Todoist web app.
24
+ * @returns The built URL, or a bare-id URL if the id was rejected.
25
+ */
26
+ function buildUrl(build, fallbackPath) {
27
+ try {
28
+ return build();
29
+ }
30
+ catch (_a) {
31
+ return `${TODOIST_WEB_URI}/${fallbackPath}`;
32
+ }
33
+ }
15
34
  /**
16
35
  * Generate the URL for a given task.
17
36
  *
@@ -20,9 +39,7 @@ export function formatDateToYYYYMMDD(date) {
20
39
  * @returns The URL string for the task view.
21
40
  */
22
41
  export function getTaskUrl(taskId, content) {
23
- const slug = content ? slugify(content) : undefined;
24
- const path = slug ? `${slug}-${taskId}` : taskId;
25
- return `${TODOIST_WEB_URI}/task/${path}`;
42
+ return buildUrl(() => todoistTaskUrl(taskId, content !== null && content !== void 0 ? content : '', LinkEnvironment.Production), `task/${taskId}`);
26
43
  }
27
44
  /**
28
45
  * Generate the URL for a given project.
@@ -32,9 +49,7 @@ export function getTaskUrl(taskId, content) {
32
49
  * @returns The URL string for the project view.
33
50
  */
34
51
  export function getProjectUrl(projectId, name) {
35
- const slug = name ? slugify(name) : undefined;
36
- const path = slug ? `${slug}-${projectId}` : projectId;
37
- return `${TODOIST_WEB_URI}/project/${path}`;
52
+ return buildUrl(() => todoistProjectUrl(projectId, name !== null && name !== void 0 ? name : '', LinkEnvironment.Production), `project/${projectId}`);
38
53
  }
39
54
  /**
40
55
  * Generate the URL for a given section.
@@ -44,25 +59,138 @@ export function getProjectUrl(projectId, name) {
44
59
  * @returns The URL string for the section view.
45
60
  */
46
61
  export function getSectionUrl(sectionId, name) {
47
- const slug = name ? slugify(name) : undefined;
48
- const path = slug ? `${slug}-${sectionId}` : sectionId;
49
- return `${TODOIST_WEB_URI}/section/${path}`;
62
+ return buildUrl(() => todoistSectionUrl(sectionId, name !== null && name !== void 0 ? name : '', LinkEnvironment.Production), `section/${sectionId}`);
63
+ }
64
+ /**
65
+ * Generate the URL for a given label.
66
+ *
67
+ * @param labelId The ID of the label.
68
+ * @param name The name of the label.
69
+ * @returns The URL string for the label view.
70
+ */
71
+ export function getLabelUrl(labelId, name) {
72
+ return buildUrl(() => todoistLabelUrl(labelId, name !== null && name !== void 0 ? name : '', LinkEnvironment.Production), `label/${labelId}`);
73
+ }
74
+ /**
75
+ * Generate the URL for a given filter.
76
+ *
77
+ * @param filterId The ID of the filter.
78
+ * @param name The name of the filter.
79
+ * @returns The URL string for the filter view.
80
+ */
81
+ export function getFilterUrl(filterId, name) {
82
+ return buildUrl(() => todoistFilterUrl(filterId, name !== null && name !== void 0 ? name : '', LinkEnvironment.Production), `filter/${filterId}`);
83
+ }
84
+ /**
85
+ * Generate the URL for a filter belonging to a workspace.
86
+ *
87
+ * @param workspaceId The ID of the workspace the filter belongs to.
88
+ * @param filterId The ID of the filter.
89
+ * @param name The name of the filter.
90
+ * @returns The URL string for the workspace filter view.
91
+ */
92
+ export function getWorkspaceFilterUrl(workspaceId, filterId, name) {
93
+ return buildUrl(() => todoistWorkspaceFilterUrl(workspaceId, filterId, name !== null && name !== void 0 ? name : '', LinkEnvironment.Production), `${workspaceId}/filter/${filterId}`);
94
+ }
95
+ /**
96
+ * Generate the URL for a given workspace.
97
+ *
98
+ * @param workspaceId The ID of the workspace.
99
+ * @returns The URL string for the workspace view.
100
+ */
101
+ export function getWorkspaceUrl(workspaceId) {
102
+ return buildUrl(() => todoistWorkspaceUrl(workspaceId, LinkEnvironment.Production), workspaceId);
103
+ }
104
+ /**
105
+ * Generate the URL for the comments on a given task.
106
+ *
107
+ * @param taskId The ID of the task.
108
+ * @param content The content of the task.
109
+ * @returns The URL string for the task's comments.
110
+ */
111
+ export function getTaskCommentsUrl(taskId, content) {
112
+ return buildUrl(() => todoistTaskCommentsUrl(taskId, content !== null && content !== void 0 ? content : '', LinkEnvironment.Production), `task/${taskId}/comments`);
113
+ }
114
+ /**
115
+ * Generate the URL for the comments on a given project.
116
+ *
117
+ * @param projectId The ID of the project.
118
+ * @param name The name of the project.
119
+ * @returns The URL string for the project's comments.
120
+ */
121
+ export function getProjectCommentsUrl(projectId, name) {
122
+ return buildUrl(() => todoistProjectCommentsUrl(projectId, name !== null && name !== void 0 ? name : '', LinkEnvironment.Production), `project/${projectId}/comments`);
50
123
  }
51
124
  /**
52
- * Slugify function borrowed from Django.
125
+ * Generate the URL for a single comment on a given task.
126
+ *
127
+ * @param taskId The ID of the task.
128
+ * @param commentId The ID of the comment.
129
+ * @param content The content of the task.
130
+ * @returns The URL string for the comment.
131
+ */
132
+ export function getTaskCommentUrl(taskId, commentId, content) {
133
+ return buildUrl(() => todoistTaskCommentUrl(taskId, content !== null && content !== void 0 ? content : '', commentId, LinkEnvironment.Production), `task/${taskId}#comment-${commentId}`);
134
+ }
135
+ /**
136
+ * Generate the URL for a single comment on a given project.
137
+ *
138
+ * @param projectId The ID of the project.
139
+ * @param commentId The ID of the comment.
140
+ * @param name The name of the project.
141
+ * @returns The URL string for the comment.
142
+ */
143
+ export function getProjectCommentUrl(projectId, commentId, name) {
144
+ return buildUrl(() => todoistProjectCommentUrl(projectId, name !== null && name !== void 0 ? name : '', commentId, LinkEnvironment.Production), `project/${projectId}#comment-${commentId}`);
145
+ }
146
+ /** The kinds of Todoist entity a URL can point at. */
147
+ export const TODOIST_LINK_TYPES = [
148
+ 'task',
149
+ 'project',
150
+ 'filter',
151
+ 'label',
152
+ 'section',
153
+ 'workspace',
154
+ 'template',
155
+ 'comment',
156
+ 'label_by_name',
157
+ ];
158
+ /**
159
+ * Maps the link parser's type names onto the types this SDK exposes. A name
160
+ * that is missing here is one this SDK does not know about, and is treated as
161
+ * an unrecognised URL rather than surfaced as a value outside the union.
162
+ */
163
+ const LINK_TYPE_BY_PARSED_NAME = {
164
+ Task: 'task',
165
+ Project: 'project',
166
+ Filter: 'filter',
167
+ Label: 'label',
168
+ Section: 'section',
169
+ Workspace: 'workspace',
170
+ Template: 'template',
171
+ Comment: 'comment',
172
+ LabelByName: 'label_by_name',
173
+ };
174
+ /**
175
+ * Parse a Todoist URL into the entity it points at.
53
176
  *
54
- * @param value The string to slugify.
55
- * @returns The slugified string.
177
+ * @param url The URL to parse.
178
+ * @returns The entity the URL points at, or `null` if it is not a Todoist URL.
56
179
  */
57
- function slugify(value) {
58
- // Convert to ASCII
59
- let result = value.normalize('NFKD').replace(/[\u0300-\u036f]/g, '');
60
- // Remove non-ASCII characters
61
- result = result.replace(/[^\x20-\x7E]/g, '');
62
- // Convert to lowercase and replace non-alphanumeric characters with dashes
63
- result = result.toLowerCase().replace(/[^\w\s-]/g, '');
64
- // Replace spaces and repeated dashes with single dashes
65
- result = result.replace(/[-\s]+/g, '-');
66
- // Strip dashes from the beginning and end
67
- return result.replace(/^-+|-+$/g, '');
180
+ export function parseTodoistUrl(url) {
181
+ var _a, _b;
182
+ const link = parseTodoistLink(url);
183
+ if (!link) {
184
+ return null;
185
+ }
186
+ const type = LINK_TYPE_BY_PARSED_NAME[link.type.name];
187
+ if (!type) {
188
+ return null;
189
+ }
190
+ return {
191
+ type,
192
+ id: link.id,
193
+ workspaceId: (_a = link.workspaceId) !== null && _a !== void 0 ? _a : null,
194
+ commentId: (_b = link.commentId) !== null && _b !== void 0 ? _b : null,
195
+ };
68
196
  }
@@ -1,4 +1,5 @@
1
1
  export * from './filters.js';
2
+ export * from './labels.js';
2
3
  export * from './collaborators.js';
3
4
  export * from './folders.js';
4
5
  export * from './tooltips.js';
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ /** A label returned by the Sync API. */
3
+ export declare const SyncLabelSchema: z.ZodObject<{
4
+ id: z.ZodString;
5
+ name: z.ZodString;
6
+ color: z.ZodString;
7
+ isFavorite: z.ZodBoolean;
8
+ order: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
9
+ isDeleted: z.ZodOptional<z.ZodBoolean>;
10
+ }, z.core.$strip>;
11
+ /** Represents a label returned by the Sync API. */
12
+ export type SyncLabel = z.infer<typeof SyncLabelSchema>;
@@ -124,3 +124,90 @@ export declare const ReminderSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
124
124
  isUrgent: z.ZodOptional<z.ZodBoolean>;
125
125
  }, z.core.$loose>], "type">;
126
126
  export type Reminder = z.infer<typeof ReminderSchema>;
127
+ export declare const SyncAbsoluteReminderSchema: z.ZodObject<{
128
+ id: z.ZodString;
129
+ notifyUid: z.ZodString;
130
+ itemId: z.ZodString;
131
+ projectId: z.ZodOptional<z.ZodString>;
132
+ isDeleted: z.ZodBoolean;
133
+ type: z.ZodLiteral<"absolute">;
134
+ isUrgent: z.ZodOptional<z.ZodBoolean>;
135
+ due: z.ZodNullable<z.ZodObject<{
136
+ isRecurring: z.ZodBoolean;
137
+ string: z.ZodString;
138
+ date: z.ZodString;
139
+ datetime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
140
+ timezone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
141
+ lang: z.ZodOptional<z.ZodNullable<z.ZodString>>;
142
+ }, z.core.$strip>>;
143
+ }, z.core.$loose>;
144
+ export type SyncAbsoluteReminder = z.infer<typeof SyncAbsoluteReminderSchema>;
145
+ export declare const SyncRelativeReminderSchema: z.ZodObject<{
146
+ id: z.ZodString;
147
+ notifyUid: z.ZodString;
148
+ itemId: z.ZodString;
149
+ projectId: z.ZodOptional<z.ZodString>;
150
+ isDeleted: z.ZodBoolean;
151
+ type: z.ZodLiteral<"relative">;
152
+ minuteOffset: z.ZodNumber;
153
+ isUrgent: z.ZodOptional<z.ZodBoolean>;
154
+ due: z.ZodOptional<z.ZodNullable<z.ZodObject<{
155
+ isRecurring: z.ZodBoolean;
156
+ string: z.ZodString;
157
+ date: z.ZodString;
158
+ datetime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
159
+ timezone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
160
+ lang: z.ZodOptional<z.ZodNullable<z.ZodString>>;
161
+ }, z.core.$strip>>>;
162
+ }, z.core.$loose>;
163
+ export type SyncRelativeReminder = z.infer<typeof SyncRelativeReminderSchema>;
164
+ export declare const SyncReminderSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
165
+ id: z.ZodString;
166
+ notifyUid: z.ZodString;
167
+ itemId: z.ZodString;
168
+ projectId: z.ZodOptional<z.ZodString>;
169
+ isDeleted: z.ZodBoolean;
170
+ type: z.ZodLiteral<"location">;
171
+ name: z.ZodString;
172
+ locLat: z.ZodString;
173
+ locLong: z.ZodString;
174
+ locTrigger: z.ZodEnum<{
175
+ on_enter: "on_enter";
176
+ on_leave: "on_leave";
177
+ }>;
178
+ radius: z.ZodNumber;
179
+ }, z.core.$loose>, z.ZodObject<{
180
+ id: z.ZodString;
181
+ notifyUid: z.ZodString;
182
+ itemId: z.ZodString;
183
+ projectId: z.ZodOptional<z.ZodString>;
184
+ isDeleted: z.ZodBoolean;
185
+ type: z.ZodLiteral<"absolute">;
186
+ isUrgent: z.ZodOptional<z.ZodBoolean>;
187
+ due: z.ZodNullable<z.ZodObject<{
188
+ isRecurring: z.ZodBoolean;
189
+ string: z.ZodString;
190
+ date: z.ZodString;
191
+ datetime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
192
+ timezone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
193
+ lang: z.ZodOptional<z.ZodNullable<z.ZodString>>;
194
+ }, z.core.$strip>>;
195
+ }, z.core.$loose>, z.ZodObject<{
196
+ id: z.ZodString;
197
+ notifyUid: z.ZodString;
198
+ itemId: z.ZodString;
199
+ projectId: z.ZodOptional<z.ZodString>;
200
+ isDeleted: z.ZodBoolean;
201
+ type: z.ZodLiteral<"relative">;
202
+ minuteOffset: z.ZodNumber;
203
+ isUrgent: z.ZodOptional<z.ZodBoolean>;
204
+ due: z.ZodOptional<z.ZodNullable<z.ZodObject<{
205
+ isRecurring: z.ZodBoolean;
206
+ string: z.ZodString;
207
+ date: z.ZodString;
208
+ datetime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
209
+ timezone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
210
+ lang: z.ZodOptional<z.ZodNullable<z.ZodString>>;
211
+ }, z.core.$strip>>>;
212
+ }, z.core.$loose>], "type">;
213
+ export type SyncReminder = z.infer<typeof SyncReminderSchema>;
@@ -229,10 +229,11 @@ export declare const SyncResponseSchema: z.ZodObject<{
229
229
  }>>>>;
230
230
  labels: z.ZodOptional<z.ZodArray<z.ZodObject<{
231
231
  id: z.ZodString;
232
- order: z.ZodNullable<z.ZodNumber>;
233
232
  name: z.ZodString;
234
233
  color: z.ZodString;
235
234
  isFavorite: z.ZodBoolean;
235
+ order: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
236
+ isDeleted: z.ZodOptional<z.ZodBoolean>;
236
237
  }, z.core.$strip>>>;
237
238
  notes: z.ZodOptional<z.ZodArray<z.ZodObject<{
238
239
  id: z.ZodString;
@@ -322,15 +323,15 @@ export declare const SyncResponseSchema: z.ZodObject<{
322
323
  projectId: z.ZodOptional<z.ZodString>;
323
324
  isDeleted: z.ZodBoolean;
324
325
  type: z.ZodLiteral<"absolute">;
325
- due: z.ZodObject<{
326
+ isUrgent: z.ZodOptional<z.ZodBoolean>;
327
+ due: z.ZodNullable<z.ZodObject<{
326
328
  isRecurring: z.ZodBoolean;
327
329
  string: z.ZodString;
328
330
  date: z.ZodString;
329
331
  datetime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
330
332
  timezone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
331
333
  lang: z.ZodOptional<z.ZodNullable<z.ZodString>>;
332
- }, z.core.$strip>;
333
- isUrgent: z.ZodOptional<z.ZodBoolean>;
334
+ }, z.core.$strip>>;
334
335
  }, z.core.$loose>, z.ZodObject<{
335
336
  id: z.ZodString;
336
337
  notifyUid: z.ZodString;
@@ -339,15 +340,15 @@ export declare const SyncResponseSchema: z.ZodObject<{
339
340
  isDeleted: z.ZodBoolean;
340
341
  type: z.ZodLiteral<"relative">;
341
342
  minuteOffset: z.ZodNumber;
342
- due: z.ZodOptional<z.ZodObject<{
343
+ isUrgent: z.ZodOptional<z.ZodBoolean>;
344
+ due: z.ZodOptional<z.ZodNullable<z.ZodObject<{
343
345
  isRecurring: z.ZodBoolean;
344
346
  string: z.ZodString;
345
347
  date: z.ZodString;
346
348
  datetime: z.ZodOptional<z.ZodNullable<z.ZodString>>;
347
349
  timezone: z.ZodOptional<z.ZodNullable<z.ZodString>>;
348
350
  lang: z.ZodOptional<z.ZodNullable<z.ZodString>>;
349
- }, z.core.$strip>>;
350
- isUrgent: z.ZodOptional<z.ZodBoolean>;
351
+ }, z.core.$strip>>>;
351
352
  }, z.core.$loose>], "type">>>;
352
353
  remindersLocation: z.ZodOptional<z.ZodArray<z.ZodObject<{
353
354
  id: z.ZodString;
@@ -1,6 +1,7 @@
1
1
  export * from './colors.js';
2
2
  export * from './sanitization.js';
3
- export { getTaskUrl, getProjectUrl, getSectionUrl } from './url-helpers.js';
3
+ export { getTaskUrl, getProjectUrl, getSectionUrl, getLabelUrl, getFilterUrl, getWorkspaceFilterUrl, getWorkspaceUrl, getTaskCommentsUrl, getProjectCommentsUrl, getTaskCommentUrl, getProjectCommentUrl, parseTodoistUrl, TODOIST_LINK_TYPES, } from './url-helpers.js';
4
+ export type { TodoistLinkType, TodoistUrlInfo } from './url-helpers.js';
4
5
  export { createCommand } from './sync-helpers.js';
5
6
  export * from './project-helpers.js';
6
7
  export * from './task-sorting.js';
@@ -30,3 +30,91 @@ export declare function getProjectUrl(projectId: string, name?: string): string;
30
30
  * @returns The URL string for the section view.
31
31
  */
32
32
  export declare function getSectionUrl(sectionId: string, name?: string): string;
33
+ /**
34
+ * Generate the URL for a given label.
35
+ *
36
+ * @param labelId The ID of the label.
37
+ * @param name The name of the label.
38
+ * @returns The URL string for the label view.
39
+ */
40
+ export declare function getLabelUrl(labelId: string, name?: string): string;
41
+ /**
42
+ * Generate the URL for a given filter.
43
+ *
44
+ * @param filterId The ID of the filter.
45
+ * @param name The name of the filter.
46
+ * @returns The URL string for the filter view.
47
+ */
48
+ export declare function getFilterUrl(filterId: string, name?: string): string;
49
+ /**
50
+ * Generate the URL for a filter belonging to a workspace.
51
+ *
52
+ * @param workspaceId The ID of the workspace the filter belongs to.
53
+ * @param filterId The ID of the filter.
54
+ * @param name The name of the filter.
55
+ * @returns The URL string for the workspace filter view.
56
+ */
57
+ export declare function getWorkspaceFilterUrl(workspaceId: string, filterId: string, name?: string): string;
58
+ /**
59
+ * Generate the URL for a given workspace.
60
+ *
61
+ * @param workspaceId The ID of the workspace.
62
+ * @returns The URL string for the workspace view.
63
+ */
64
+ export declare function getWorkspaceUrl(workspaceId: string): string;
65
+ /**
66
+ * Generate the URL for the comments on a given task.
67
+ *
68
+ * @param taskId The ID of the task.
69
+ * @param content The content of the task.
70
+ * @returns The URL string for the task's comments.
71
+ */
72
+ export declare function getTaskCommentsUrl(taskId: string, content?: string): string;
73
+ /**
74
+ * Generate the URL for the comments on a given project.
75
+ *
76
+ * @param projectId The ID of the project.
77
+ * @param name The name of the project.
78
+ * @returns The URL string for the project's comments.
79
+ */
80
+ export declare function getProjectCommentsUrl(projectId: string, name?: string): string;
81
+ /**
82
+ * Generate the URL for a single comment on a given task.
83
+ *
84
+ * @param taskId The ID of the task.
85
+ * @param commentId The ID of the comment.
86
+ * @param content The content of the task.
87
+ * @returns The URL string for the comment.
88
+ */
89
+ export declare function getTaskCommentUrl(taskId: string, commentId: string, content?: string): string;
90
+ /**
91
+ * Generate the URL for a single comment on a given project.
92
+ *
93
+ * @param projectId The ID of the project.
94
+ * @param commentId The ID of the comment.
95
+ * @param name The name of the project.
96
+ * @returns The URL string for the comment.
97
+ */
98
+ export declare function getProjectCommentUrl(projectId: string, commentId: string, name?: string): string;
99
+ /** The kinds of Todoist entity a URL can point at. */
100
+ export declare const TODOIST_LINK_TYPES: readonly ["task", "project", "filter", "label", "section", "workspace", "template", "comment", "label_by_name"];
101
+ /** The kind of Todoist entity a URL points at. */
102
+ export type TodoistLinkType = (typeof TODOIST_LINK_TYPES)[number];
103
+ /** The entity a Todoist URL points at. */
104
+ export type TodoistUrlInfo = {
105
+ /** The kind of entity the URL points at. */
106
+ type: TodoistLinkType;
107
+ /** The ID of the entity. */
108
+ id: string;
109
+ /** The ID of the workspace the entity belongs to, when the URL names one. */
110
+ workspaceId: string | null;
111
+ /** The ID of the comment the URL points at, when the URL names one. */
112
+ commentId: string | null;
113
+ };
114
+ /**
115
+ * Parse a Todoist URL into the entity it points at.
116
+ *
117
+ * @param url The URL to parse.
118
+ * @returns The entity the URL points at, or `null` if it is not a Todoist URL.
119
+ */
120
+ export declare function parseTodoistUrl(url: string): TodoistUrlInfo | null;
package/package.json CHANGED
@@ -1,20 +1,17 @@
1
1
  {
2
2
  "name": "@doist/todoist-sdk",
3
- "version": "14.2.0",
3
+ "version": "15.0.1",
4
4
  "description": "The official TypeScript SDK for the Todoist REST API.",
5
5
  "author": "Doist developers",
6
6
  "repository": "https://github.com/Doist/todoist-sdk-typescript",
7
7
  "homepage": "https://doist.github.io/todoist-sdk-typescript/",
8
8
  "license": "MIT",
9
9
  "type": "module",
10
- "main": "dist/cjs/index.js",
11
- "module": "dist/esm/index.js",
12
10
  "types": "dist/types/index.d.ts",
13
11
  "exports": {
14
12
  ".": {
15
13
  "types": "./dist/types/index.d.ts",
16
- "import": "./dist/esm/index.js",
17
- "require": "./dist/cjs/index.js"
14
+ "default": "./dist/esm/index.js"
18
15
  }
19
16
  },
20
17
  "publishConfig": {
@@ -36,13 +33,11 @@
36
33
  "test:watch": "vitest",
37
34
  "test:coverage": "vitest run --coverage",
38
35
  "api:request": "node ./scripts/todoist-api-request.cjs",
39
- "build:cjs": "npx tsc -p tsconfig.cjs.json",
40
36
  "build:esm": "npx tsc -p tsconfig.esm.json",
41
37
  "build:fix-esm": "node scripts/fix-esm-imports.cjs",
42
38
  "build:fix-dts": "node scripts/fix-dts-imports.cjs",
43
- "build:post": "echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
44
- "build": "npm-run-all clean build:cjs build:esm build:fix-esm build:fix-dts build:post",
45
- "attw": "attw --pack --ignore-rules fallback-condition false-esm",
39
+ "build": "npm-run-all clean build:esm build:fix-esm build:fix-dts",
40
+ "attw": "attw --pack --ignore-rules cjs-resolves-to-esm",
46
41
  "integrity-checks": "npm-run-all clean check test build attw",
47
42
  "prepublishOnly": "npm run integrity-checks",
48
43
  "prepare": "npm run build"
@@ -51,6 +46,7 @@
51
46
  "fflate": "0.8.2"
52
47
  },
53
48
  "dependencies": {
49
+ "@doist/sdk-kmp": "0.2.3",
54
50
  "camelcase": "6.3.0",
55
51
  "emoji-regex": "10.6.0",
56
52
  "ts-custom-error": "^3.2.0",
@@ -91,7 +87,6 @@
91
87
  "*.{ts,tsx,json,md,yml,yaml}": "oxfmt --no-error-on-unmatched-pattern"
92
88
  },
93
89
  "files": [
94
- "dist/cjs/**/*",
95
90
  "dist/esm/**/*",
96
91
  "dist/types/**/*",
97
92
  "!dist/**/*.test.js",