@doist/todoist-sdk 14.2.0 → 15.0.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 (166) hide show
  1. package/dist/esm/utils/index.js +1 -1
  2. package/dist/esm/utils/url-helpers.js +151 -23
  3. package/dist/types/utils/index.d.ts +2 -1
  4. package/dist/types/utils/url-helpers.d.ts +88 -0
  5. package/package.json +5 -10
  6. package/dist/cjs/authentication.js +0 -317
  7. package/dist/cjs/clients/activity-client.js +0 -63
  8. package/dist/cjs/clients/app-client.js +0 -345
  9. package/dist/cjs/clients/backup-client.js +0 -47
  10. package/dist/cjs/clients/base-client.js +0 -31
  11. package/dist/cjs/clients/billing-client.js +0 -152
  12. package/dist/cjs/clients/comment-client.js +0 -91
  13. package/dist/cjs/clients/email-client.js +0 -43
  14. package/dist/cjs/clients/folder-client.js +0 -79
  15. package/dist/cjs/clients/id-mapping-client.js +0 -39
  16. package/dist/cjs/clients/insights-client.js +0 -87
  17. package/dist/cjs/clients/label-client.js +0 -126
  18. package/dist/cjs/clients/productivity-client.js +0 -27
  19. package/dist/cjs/clients/project-client.js +0 -235
  20. package/dist/cjs/clients/reminder-client.js +0 -198
  21. package/dist/cjs/clients/section-client.js +0 -117
  22. package/dist/cjs/clients/task-client.js +0 -254
  23. package/dist/cjs/clients/template-client.js +0 -88
  24. package/dist/cjs/clients/ui-extension-client.js +0 -107
  25. package/dist/cjs/clients/upload-client.js +0 -155
  26. package/dist/cjs/clients/view-options-client.js +0 -25
  27. package/dist/cjs/clients/workspace-client.js +0 -366
  28. package/dist/cjs/consts/endpoints.js +0 -224
  29. package/dist/cjs/index.js +0 -24
  30. package/dist/cjs/package.json +0 -1
  31. package/dist/cjs/test-utils/asserts.js +0 -11
  32. package/dist/cjs/test-utils/msw-setup.js +0 -97
  33. package/dist/cjs/test-utils/obsidian-fetch-adapter.js +0 -54
  34. package/dist/cjs/test-utils/test-defaults.js +0 -371
  35. package/dist/cjs/test-utils/transport-seam.js +0 -17
  36. package/dist/cjs/test-utils/webhook-fixtures.js +0 -32
  37. package/dist/cjs/todoist-api.js +0 -1711
  38. package/dist/cjs/transport/fetch-with-retry.js +0 -219
  39. package/dist/cjs/transport/http-client.js +0 -134
  40. package/dist/cjs/transport/http-dispatcher.js +0 -198
  41. package/dist/cjs/transport/sync-request.js +0 -83
  42. package/dist/cjs/types/activity/index.js +0 -18
  43. package/dist/cjs/types/activity/requests.js +0 -2
  44. package/dist/cjs/types/activity/types.js +0 -28
  45. package/dist/cjs/types/apps/index.js +0 -18
  46. package/dist/cjs/types/apps/requests.js +0 -2
  47. package/dist/cjs/types/apps/types.js +0 -254
  48. package/dist/cjs/types/backups/index.js +0 -18
  49. package/dist/cjs/types/backups/requests.js +0 -2
  50. package/dist/cjs/types/backups/types.js +0 -8
  51. package/dist/cjs/types/billing/index.js +0 -18
  52. package/dist/cjs/types/billing/requests.js +0 -2
  53. package/dist/cjs/types/billing/types.js +0 -92
  54. package/dist/cjs/types/comments/index.js +0 -18
  55. package/dist/cjs/types/comments/requests.js +0 -2
  56. package/dist/cjs/types/comments/types.js +0 -60
  57. package/dist/cjs/types/common.js +0 -10
  58. package/dist/cjs/types/emails/index.js +0 -17
  59. package/dist/cjs/types/emails/requests.js +0 -5
  60. package/dist/cjs/types/errors.js +0 -29
  61. package/dist/cjs/types/folders/index.js +0 -17
  62. package/dist/cjs/types/folders/requests.js +0 -2
  63. package/dist/cjs/types/http.js +0 -24
  64. package/dist/cjs/types/id-mappings/index.js +0 -18
  65. package/dist/cjs/types/id-mappings/requests.js +0 -20
  66. package/dist/cjs/types/id-mappings/types.js +0 -12
  67. package/dist/cjs/types/index.js +0 -40
  68. package/dist/cjs/types/insights/index.js +0 -18
  69. package/dist/cjs/types/insights/requests.js +0 -2
  70. package/dist/cjs/types/insights/types.js +0 -80
  71. package/dist/cjs/types/labels/index.js +0 -18
  72. package/dist/cjs/types/labels/requests.js +0 -2
  73. package/dist/cjs/types/labels/types.js +0 -11
  74. package/dist/cjs/types/productivity/index.js +0 -17
  75. package/dist/cjs/types/productivity/types.js +0 -68
  76. package/dist/cjs/types/projects/index.js +0 -18
  77. package/dist/cjs/types/projects/requests.js +0 -2
  78. package/dist/cjs/types/projects/types.js +0 -66
  79. package/dist/cjs/types/reminders/index.js +0 -17
  80. package/dist/cjs/types/reminders/requests.js +0 -95
  81. package/dist/cjs/types/sections/index.js +0 -18
  82. package/dist/cjs/types/sections/requests.js +0 -2
  83. package/dist/cjs/types/sections/types.js +0 -25
  84. package/dist/cjs/types/sync/commands/calendars.js +0 -2
  85. package/dist/cjs/types/sync/commands/filters.js +0 -2
  86. package/dist/cjs/types/sync/commands/folders.js +0 -2
  87. package/dist/cjs/types/sync/commands/index.js +0 -34
  88. package/dist/cjs/types/sync/commands/labels.js +0 -5
  89. package/dist/cjs/types/sync/commands/notes.js +0 -2
  90. package/dist/cjs/types/sync/commands/notifications.js +0 -2
  91. package/dist/cjs/types/sync/commands/others.js +0 -2
  92. package/dist/cjs/types/sync/commands/project-view-options.js +0 -2
  93. package/dist/cjs/types/sync/commands/projects.js +0 -2
  94. package/dist/cjs/types/sync/commands/reminders.js +0 -2
  95. package/dist/cjs/types/sync/commands/sections.js +0 -2
  96. package/dist/cjs/types/sync/commands/shared.js +0 -20
  97. package/dist/cjs/types/sync/commands/sharing.js +0 -2
  98. package/dist/cjs/types/sync/commands/tasks.js +0 -2
  99. package/dist/cjs/types/sync/commands/view-options.js +0 -2
  100. package/dist/cjs/types/sync/commands/workspace-filters.js +0 -2
  101. package/dist/cjs/types/sync/commands/workspaces.js +0 -2
  102. package/dist/cjs/types/sync/index.js +0 -22
  103. package/dist/cjs/types/sync/request.js +0 -2
  104. package/dist/cjs/types/sync/resource-types.js +0 -39
  105. package/dist/cjs/types/sync/resources/calendars.js +0 -27
  106. package/dist/cjs/types/sync/resources/collaborators.js +0 -21
  107. package/dist/cjs/types/sync/resources/completed-info.js +0 -24
  108. package/dist/cjs/types/sync/resources/filters.js +0 -14
  109. package/dist/cjs/types/sync/resources/folders.js +0 -12
  110. package/dist/cjs/types/sync/resources/index.js +0 -32
  111. package/dist/cjs/types/sync/resources/live-notifications.js +0 -38
  112. package/dist/cjs/types/sync/resources/notes.js +0 -21
  113. package/dist/cjs/types/sync/resources/reminders.js +0 -50
  114. package/dist/cjs/types/sync/resources/suggestions.js +0 -36
  115. package/dist/cjs/types/sync/resources/tooltips.js +0 -8
  116. package/dist/cjs/types/sync/resources/user-plan-limits.js +0 -20
  117. package/dist/cjs/types/sync/resources/user-settings.js +0 -40
  118. package/dist/cjs/types/sync/resources/user.js +0 -110
  119. package/dist/cjs/types/sync/resources/view-options.js +0 -86
  120. package/dist/cjs/types/sync/resources/workspace-filters.js +0 -19
  121. package/dist/cjs/types/sync/resources/workspaces.js +0 -72
  122. package/dist/cjs/types/sync/response.js +0 -54
  123. package/dist/cjs/types/sync/user-preferences.js +0 -71
  124. package/dist/cjs/types/tasks/index.js +0 -18
  125. package/dist/cjs/types/tasks/requests.js +0 -2
  126. package/dist/cjs/types/tasks/types.js +0 -59
  127. package/dist/cjs/types/templates/index.js +0 -17
  128. package/dist/cjs/types/templates/requests.js +0 -2
  129. package/dist/cjs/types/ui-extensions/index.js +0 -18
  130. package/dist/cjs/types/ui-extensions/requests.js +0 -2
  131. package/dist/cjs/types/ui-extensions/types.js +0 -77
  132. package/dist/cjs/types/uploads/index.js +0 -17
  133. package/dist/cjs/types/uploads/requests.js +0 -2
  134. package/dist/cjs/types/users/index.js +0 -17
  135. package/dist/cjs/types/users/types.js +0 -51
  136. package/dist/cjs/types/webhooks/comments.js +0 -96
  137. package/dist/cjs/types/webhooks/envelope.js +0 -26
  138. package/dist/cjs/types/webhooks/filters.js +0 -30
  139. package/dist/cjs/types/webhooks/index.js +0 -25
  140. package/dist/cjs/types/webhooks/labels.js +0 -54
  141. package/dist/cjs/types/webhooks/projects.js +0 -36
  142. package/dist/cjs/types/webhooks/reminders.js +0 -35
  143. package/dist/cjs/types/webhooks/sections.js +0 -53
  144. package/dist/cjs/types/webhooks/tasks.js +0 -68
  145. package/dist/cjs/types/webhooks/types.js +0 -55
  146. package/dist/cjs/types/workspaces/index.js +0 -18
  147. package/dist/cjs/types/workspaces/requests.js +0 -2
  148. package/dist/cjs/types/workspaces/types.js +0 -154
  149. package/dist/cjs/utils/activity-helpers.js +0 -58
  150. package/dist/cjs/utils/case-conversion.js +0 -69
  151. package/dist/cjs/utils/colors.js +0 -143
  152. package/dist/cjs/utils/file-response.js +0 -32
  153. package/dist/cjs/utils/headers.js +0 -16
  154. package/dist/cjs/utils/index.js +0 -31
  155. package/dist/cjs/utils/multipart-upload.js +0 -293
  156. package/dist/cjs/utils/processing-helpers.js +0 -18
  157. package/dist/cjs/utils/project-helpers.js +0 -20
  158. package/dist/cjs/utils/request-helpers.js +0 -21
  159. package/dist/cjs/utils/sanitization.js +0 -116
  160. package/dist/cjs/utils/sync-helpers.js +0 -22
  161. package/dist/cjs/utils/task-sorting.js +0 -281
  162. package/dist/cjs/utils/uncompletable-helpers.js +0 -60
  163. package/dist/cjs/utils/url-helpers.js +0 -74
  164. package/dist/cjs/utils/validators.js +0 -108
  165. package/dist/cjs/utils/view-options.js +0 -19
  166. package/dist/cjs/utils/webhook-parser.js +0 -60
@@ -1,198 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReminderClient = void 0;
4
- const endpoints_1 = require("../consts/endpoints");
5
- const http_client_1 = require("../transport/http-client");
6
- const types_1 = require("../types");
7
- const reminders_1 = require("../types/reminders");
8
- const reminders_2 = require("../types/sync/resources/reminders");
9
- const request_helpers_1 = require("../utils/request-helpers");
10
- const validators_1 = require("../utils/validators");
11
- const base_client_1 = require("./base-client");
12
- /**
13
- * Internal sub-client handling all reminder-domain endpoints
14
- * (both time-based and location-based reminders).
15
- *
16
- * Instantiated by `TodoistApi`; every public reminder method on
17
- * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
18
- * JSDoc. The time-vs-location 404 translation is preserved here so a
19
- * caller who used the wrong endpoint gets a TodoistArgumentError
20
- * pointing at the correct method, rather than a bare 404.
21
- */
22
- class ReminderClient extends base_client_1.BaseClient {
23
- async getReminders(args = {}) {
24
- const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
25
- httpMethod: 'GET',
26
- baseUri: this.syncApiBase,
27
- relativePath: endpoints_1.ENDPOINT_REST_REMINDERS,
28
- apiToken: this.authToken,
29
- customFetch: this.customFetch,
30
- payload: args,
31
- });
32
- return {
33
- results: (0, validators_1.validateReminderArray)(results),
34
- nextCursor,
35
- };
36
- }
37
- async getLocationReminders(args = {}) {
38
- const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
39
- httpMethod: 'GET',
40
- baseUri: this.syncApiBase,
41
- relativePath: endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS,
42
- apiToken: this.authToken,
43
- customFetch: this.customFetch,
44
- payload: args,
45
- });
46
- return {
47
- results: (0, validators_1.validateLocationReminderArray)(results),
48
- nextCursor,
49
- };
50
- }
51
- async getReminder(id) {
52
- reminders_1.ReminderIdSchema.parse(id);
53
- try {
54
- const response = await (0, http_client_1.request)({
55
- httpMethod: 'GET',
56
- baseUri: this.syncApiBase,
57
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_REMINDERS, id),
58
- apiToken: this.authToken,
59
- customFetch: this.customFetch,
60
- });
61
- return (0, validators_1.validateReminder)(response.data);
62
- }
63
- catch (error) {
64
- if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
65
- throw error;
66
- }
67
- throw new types_1.TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use getLocationReminder instead.`);
68
- }
69
- }
70
- async getLocationReminder(id) {
71
- reminders_1.ReminderIdSchema.parse(id);
72
- try {
73
- const response = await (0, http_client_1.request)({
74
- httpMethod: 'GET',
75
- baseUri: this.syncApiBase,
76
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS, id),
77
- apiToken: this.authToken,
78
- customFetch: this.customFetch,
79
- });
80
- return (0, validators_1.validateReminder)(response.data);
81
- }
82
- catch (error) {
83
- if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
84
- throw error;
85
- }
86
- throw new types_1.TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use getReminder instead.`);
87
- }
88
- }
89
- async addReminder(args, requestId) {
90
- const response = await (0, http_client_1.request)({
91
- httpMethod: 'POST',
92
- baseUri: this.syncApiBase,
93
- relativePath: endpoints_1.ENDPOINT_REST_REMINDERS,
94
- apiToken: this.authToken,
95
- customFetch: this.customFetch,
96
- payload: args,
97
- requestId: requestId,
98
- });
99
- return (0, validators_1.validateReminder)(response.data);
100
- }
101
- async addLocationReminder(args, requestId) {
102
- const response = await (0, http_client_1.request)({
103
- httpMethod: 'POST',
104
- baseUri: this.syncApiBase,
105
- relativePath: endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS,
106
- apiToken: this.authToken,
107
- customFetch: this.customFetch,
108
- payload: Object.assign(Object.assign({}, args), { reminderType: reminders_2.ReminderTypeEnum.Location }),
109
- requestId: requestId,
110
- });
111
- return (0, validators_1.validateReminder)(response.data);
112
- }
113
- async updateReminder(id, args, requestId) {
114
- reminders_1.ReminderIdSchema.parse(id);
115
- const payload = reminders_1.UpdateReminderArgsSchema.parse(args);
116
- try {
117
- const response = await (0, http_client_1.request)({
118
- httpMethod: 'POST',
119
- baseUri: this.syncApiBase,
120
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_REMINDERS, id),
121
- apiToken: this.authToken,
122
- customFetch: this.customFetch,
123
- payload,
124
- requestId: requestId,
125
- });
126
- return (0, validators_1.validateReminder)(response.data);
127
- }
128
- catch (error) {
129
- if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
130
- throw error;
131
- }
132
- throw new types_1.TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use updateLocationReminder instead.`);
133
- }
134
- }
135
- async updateLocationReminder(id, args, requestId) {
136
- reminders_1.ReminderIdSchema.parse(id);
137
- const payload = reminders_1.UpdateLocationReminderArgsSchema.parse(args);
138
- try {
139
- const response = await (0, http_client_1.request)({
140
- httpMethod: 'POST',
141
- baseUri: this.syncApiBase,
142
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS, id),
143
- apiToken: this.authToken,
144
- customFetch: this.customFetch,
145
- payload,
146
- requestId: requestId,
147
- });
148
- return (0, validators_1.validateReminder)(response.data);
149
- }
150
- catch (error) {
151
- if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
152
- throw error;
153
- }
154
- throw new types_1.TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use updateReminder instead.`);
155
- }
156
- }
157
- async deleteReminder(id, requestId) {
158
- reminders_1.ReminderIdSchema.parse(id);
159
- try {
160
- const response = await (0, http_client_1.request)({
161
- httpMethod: 'DELETE',
162
- baseUri: this.syncApiBase,
163
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_REMINDERS, id),
164
- apiToken: this.authToken,
165
- customFetch: this.customFetch,
166
- requestId: requestId,
167
- });
168
- return (0, http_client_1.isSuccess)(response);
169
- }
170
- catch (error) {
171
- if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
172
- throw error;
173
- }
174
- throw new types_1.TodoistArgumentError(`Reminder ${id} was not found on the time-based reminder endpoint. If this is a location reminder, use deleteLocationReminder instead.`);
175
- }
176
- }
177
- async deleteLocationReminder(id, requestId) {
178
- reminders_1.ReminderIdSchema.parse(id);
179
- try {
180
- const response = await (0, http_client_1.request)({
181
- httpMethod: 'DELETE',
182
- baseUri: this.syncApiBase,
183
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_LOCATION_REMINDERS, id),
184
- apiToken: this.authToken,
185
- customFetch: this.customFetch,
186
- requestId: requestId,
187
- });
188
- return (0, http_client_1.isSuccess)(response);
189
- }
190
- catch (error) {
191
- if (!(error instanceof types_1.TodoistRequestError) || error.httpStatusCode !== 404) {
192
- throw error;
193
- }
194
- throw new types_1.TodoistArgumentError(`Location reminder ${id} was not found on the location reminder endpoint. If this is a time-based reminder, use deleteReminder instead.`);
195
- }
196
- }
197
- }
198
- exports.ReminderClient = ReminderClient;
@@ -1,117 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SectionClient = void 0;
4
- const endpoints_1 = require("../consts/endpoints");
5
- const http_client_1 = require("../transport/http-client");
6
- const request_helpers_1 = require("../utils/request-helpers");
7
- const validators_1 = require("../utils/validators");
8
- const base_client_1 = require("./base-client");
9
- /**
10
- * Internal sub-client handling all section-domain endpoints.
11
- *
12
- * Instantiated by `TodoistApi`; every public section method on `TodoistApi`
13
- * delegates here. See `todoist-api.ts` for the user-facing JSDoc.
14
- */
15
- class SectionClient extends base_client_1.BaseClient {
16
- async getSections(args) {
17
- const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
18
- httpMethod: 'GET',
19
- baseUri: this.syncApiBase,
20
- relativePath: endpoints_1.ENDPOINT_REST_SECTIONS,
21
- apiToken: this.authToken,
22
- customFetch: this.customFetch,
23
- payload: args,
24
- });
25
- return {
26
- results: (0, validators_1.validateSectionArray)(results),
27
- nextCursor,
28
- };
29
- }
30
- async searchSections(args) {
31
- const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
32
- httpMethod: 'GET',
33
- baseUri: this.syncApiBase,
34
- relativePath: endpoints_1.ENDPOINT_REST_SECTIONS_SEARCH,
35
- apiToken: this.authToken,
36
- customFetch: this.customFetch,
37
- payload: args,
38
- });
39
- return {
40
- results: (0, validators_1.validateSectionArray)(results),
41
- nextCursor,
42
- };
43
- }
44
- async getSection(id) {
45
- validators_1.IdSchema.parse(id);
46
- const response = await (0, http_client_1.request)({
47
- httpMethod: 'GET',
48
- baseUri: this.syncApiBase,
49
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id),
50
- apiToken: this.authToken,
51
- customFetch: this.customFetch,
52
- });
53
- return (0, validators_1.validateSection)(response.data);
54
- }
55
- async addSection(args, requestId) {
56
- const response = await (0, http_client_1.request)({
57
- httpMethod: 'POST',
58
- baseUri: this.syncApiBase,
59
- relativePath: endpoints_1.ENDPOINT_REST_SECTIONS,
60
- apiToken: this.authToken,
61
- customFetch: this.customFetch,
62
- payload: args,
63
- requestId: requestId,
64
- });
65
- return (0, validators_1.validateSection)(response.data);
66
- }
67
- async updateSection(id, args, requestId) {
68
- validators_1.IdSchema.parse(id);
69
- const response = await (0, http_client_1.request)({
70
- httpMethod: 'POST',
71
- baseUri: this.syncApiBase,
72
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id),
73
- apiToken: this.authToken,
74
- customFetch: this.customFetch,
75
- payload: args,
76
- requestId: requestId,
77
- });
78
- return (0, validators_1.validateSection)(response.data);
79
- }
80
- async deleteSection(id, requestId) {
81
- validators_1.IdSchema.parse(id);
82
- const response = await (0, http_client_1.request)({
83
- httpMethod: 'DELETE',
84
- baseUri: this.syncApiBase,
85
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id),
86
- apiToken: this.authToken,
87
- customFetch: this.customFetch,
88
- requestId: requestId,
89
- });
90
- return (0, http_client_1.isSuccess)(response);
91
- }
92
- async archiveSection(id, requestId) {
93
- validators_1.IdSchema.parse(id);
94
- const response = await (0, http_client_1.request)({
95
- httpMethod: 'POST',
96
- baseUri: this.syncApiBase,
97
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id, endpoints_1.SECTION_ARCHIVE),
98
- apiToken: this.authToken,
99
- customFetch: this.customFetch,
100
- requestId: requestId,
101
- });
102
- return (0, validators_1.validateSection)(response.data);
103
- }
104
- async unarchiveSection(id, requestId) {
105
- validators_1.IdSchema.parse(id);
106
- const response = await (0, http_client_1.request)({
107
- httpMethod: 'POST',
108
- baseUri: this.syncApiBase,
109
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_SECTIONS, id, endpoints_1.SECTION_UNARCHIVE),
110
- apiToken: this.authToken,
111
- customFetch: this.customFetch,
112
- requestId: requestId,
113
- });
114
- return (0, validators_1.validateSection)(response.data);
115
- }
116
- }
117
- exports.SectionClient = SectionClient;
@@ -1,254 +0,0 @@
1
- "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.TaskClient = void 0;
15
- const uuid_1 = require("uuid");
16
- const endpoints_1 = require("../consts/endpoints");
17
- const http_client_1 = require("../transport/http-client");
18
- const sync_request_1 = require("../transport/sync-request");
19
- const types_1 = require("../types");
20
- const request_helpers_1 = require("../utils/request-helpers");
21
- const uncompletable_helpers_1 = require("../utils/uncompletable-helpers");
22
- const validators_1 = require("../utils/validators");
23
- const base_client_1 = require("./base-client");
24
- const MAX_COMMAND_COUNT = 100;
25
- /**
26
- * Internal sub-client handling all task-domain endpoints.
27
- *
28
- * Instantiated by `TodoistApi`; every public task method on `TodoistApi`
29
- * delegates here. See `todoist-api.ts` for the user-facing JSDoc.
30
- */
31
- class TaskClient extends base_client_1.BaseClient {
32
- async getTask(id) {
33
- validators_1.IdSchema.parse(id);
34
- const response = await (0, http_client_1.request)({
35
- httpMethod: 'GET',
36
- baseUri: this.syncApiBase,
37
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id),
38
- apiToken: this.authToken,
39
- customFetch: this.customFetch,
40
- });
41
- return (0, validators_1.validateTask)(response.data);
42
- }
43
- async getTasks(args = {}) {
44
- const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
45
- httpMethod: 'GET',
46
- baseUri: this.syncApiBase,
47
- relativePath: endpoints_1.ENDPOINT_REST_TASKS,
48
- apiToken: this.authToken,
49
- customFetch: this.customFetch,
50
- payload: Object.assign(Object.assign({}, args), (0, request_helpers_1.spreadIfDefined)(args.ids, (ids) => ({ ids: ids.join(',') }))),
51
- });
52
- return {
53
- results: (0, validators_1.validateTaskArray)(results),
54
- nextCursor,
55
- };
56
- }
57
- async getTasksByFilter(args) {
58
- const { data: { results, nextCursor }, } = await (0, http_client_1.request)({
59
- httpMethod: 'GET',
60
- baseUri: this.syncApiBase,
61
- relativePath: endpoints_1.ENDPOINT_REST_TASKS_FILTER,
62
- apiToken: this.authToken,
63
- customFetch: this.customFetch,
64
- payload: args,
65
- });
66
- return {
67
- results: (0, validators_1.validateTaskArray)(results),
68
- nextCursor,
69
- };
70
- }
71
- async getCompletedTasksByCompletionDate(args) {
72
- const { data: { items, nextCursor }, } = await (0, http_client_1.request)({
73
- httpMethod: 'GET',
74
- baseUri: this.syncApiBase,
75
- relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_COMPLETION_DATE,
76
- apiToken: this.authToken,
77
- customFetch: this.customFetch,
78
- payload: args,
79
- });
80
- return {
81
- items: (0, validators_1.validateTaskArray)(items),
82
- nextCursor,
83
- };
84
- }
85
- async getCompletedTasksByDueDate(args) {
86
- const { data: { items, nextCursor }, } = await (0, http_client_1.request)({
87
- httpMethod: 'GET',
88
- baseUri: this.syncApiBase,
89
- relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_BY_DUE_DATE,
90
- apiToken: this.authToken,
91
- customFetch: this.customFetch,
92
- payload: args,
93
- });
94
- return {
95
- items: (0, validators_1.validateTaskArray)(items),
96
- nextCursor,
97
- };
98
- }
99
- async searchCompletedTasks(args) {
100
- const { data: { items, nextCursor }, } = await (0, http_client_1.request)({
101
- httpMethod: 'GET',
102
- baseUri: this.syncApiBase,
103
- relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED_SEARCH,
104
- apiToken: this.authToken,
105
- customFetch: this.customFetch,
106
- payload: args,
107
- });
108
- return {
109
- items: (0, validators_1.validateTaskArray)(items),
110
- nextCursor,
111
- };
112
- }
113
- async getAllCompletedTasks(args = {}) {
114
- const { since, until } = args, rest = __rest(args, ["since", "until"]);
115
- const { data } = await (0, http_client_1.request)({
116
- httpMethod: 'GET',
117
- baseUri: this.syncApiBase,
118
- relativePath: endpoints_1.ENDPOINT_REST_TASKS_COMPLETED,
119
- apiToken: this.authToken,
120
- customFetch: this.customFetch,
121
- payload: Object.assign(Object.assign(Object.assign({}, rest), (since ? { since: since.toISOString() } : {})), (until ? { until: until.toISOString() } : {})),
122
- });
123
- return {
124
- projects: data.projects,
125
- sections: data.sections,
126
- items: (0, validators_1.validateTaskArray)(data.items),
127
- };
128
- }
129
- async addTask(args, requestId) {
130
- // Process content based on isUncompletable flag
131
- const processedArgs = Object.assign(Object.assign({}, args), { content: (0, uncompletable_helpers_1.processTaskContent)(args.content, args.isUncompletable) });
132
- const response = await (0, http_client_1.request)({
133
- httpMethod: 'POST',
134
- baseUri: this.syncApiBase,
135
- relativePath: endpoints_1.ENDPOINT_REST_TASKS,
136
- apiToken: this.authToken,
137
- customFetch: this.customFetch,
138
- payload: processedArgs,
139
- requestId: requestId,
140
- });
141
- return (0, validators_1.validateTask)(response.data);
142
- }
143
- async quickAddTask(args) {
144
- // Process text based on isUncompletable flag
145
- const processedArgs = Object.assign(Object.assign({}, args), { text: (0, uncompletable_helpers_1.processTaskContent)(args.text, args.isUncompletable) });
146
- const response = await (0, http_client_1.request)({
147
- httpMethod: 'POST',
148
- baseUri: this.syncApiBase,
149
- relativePath: endpoints_1.ENDPOINT_SYNC_QUICK_ADD,
150
- apiToken: this.authToken,
151
- customFetch: this.customFetch,
152
- payload: processedArgs,
153
- });
154
- return (0, validators_1.validateTask)(response.data);
155
- }
156
- async updateTask(id, args, requestId) {
157
- validators_1.IdSchema.parse(id);
158
- // Translate SDK alias for due-date clearing to Todoist's accepted payload value.
159
- const normalizedArgs = args.dueString === null ? Object.assign(Object.assign({}, args), { dueString: 'no date' }) : args;
160
- // Process content if both content and isUncompletable are provided
161
- const processedArgs = normalizedArgs.content && normalizedArgs.isUncompletable !== undefined
162
- ? Object.assign(Object.assign({}, normalizedArgs), { content: (0, uncompletable_helpers_1.processTaskContent)(normalizedArgs.content, normalizedArgs.isUncompletable) }) : normalizedArgs;
163
- // Remap `order` → `childOrder` so snakeCaseKeys() produces `child_order`
164
- const { order } = processedArgs, argsWithoutOrder = __rest(processedArgs, ["order"]);
165
- const remappedArgs = order !== undefined ? Object.assign(Object.assign({}, argsWithoutOrder), { childOrder: order }) : argsWithoutOrder;
166
- const response = await (0, http_client_1.request)({
167
- httpMethod: 'POST',
168
- baseUri: this.syncApiBase,
169
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id),
170
- apiToken: this.authToken,
171
- customFetch: this.customFetch,
172
- payload: remappedArgs,
173
- requestId: requestId,
174
- });
175
- return (0, validators_1.validateTask)(response.data);
176
- }
177
- async moveTasks(ids, args, requestId) {
178
- var _a;
179
- if (ids.length > MAX_COMMAND_COUNT) {
180
- throw new types_1.TodoistRequestError(`Maximum number of items is ${MAX_COMMAND_COUNT}`, 400);
181
- }
182
- const commands = ids.map((id) => ({
183
- type: 'item_move',
184
- uuid: (0, uuid_1.v4)(),
185
- args: Object.assign(Object.assign(Object.assign({ id }, (0, request_helpers_1.spreadIfDefined)(args.projectId, (v) => ({ projectId: v }))), (0, request_helpers_1.spreadIfDefined)(args.sectionId, (v) => ({ sectionId: v }))), (0, request_helpers_1.spreadIfDefined)(args.parentId, (v) => ({ parentId: v }))),
186
- }));
187
- const syncRequest = {
188
- commands,
189
- resourceTypes: ['items'],
190
- };
191
- const syncResponse = await (0, sync_request_1.performSyncRequest)(this.syncContext, syncRequest, {
192
- requestId,
193
- hasSyncCommands: true,
194
- });
195
- if (!((_a = syncResponse.items) === null || _a === void 0 ? void 0 : _a.length)) {
196
- throw new types_1.TodoistRequestError('Tasks not found', 404);
197
- }
198
- const syncTasks = syncResponse.items.filter((task) => ids.includes(task.id));
199
- if (!syncTasks.length) {
200
- throw new types_1.TodoistRequestError('Tasks not found', 404);
201
- }
202
- return (0, validators_1.validateTaskArray)(syncTasks);
203
- }
204
- async moveTask(id, args, requestId) {
205
- validators_1.IdSchema.parse(id);
206
- const response = await (0, http_client_1.request)({
207
- httpMethod: 'POST',
208
- baseUri: this.syncApiBase,
209
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_MOVE),
210
- apiToken: this.authToken,
211
- customFetch: this.customFetch,
212
- payload: Object.assign(Object.assign(Object.assign({}, (0, request_helpers_1.spreadIfDefined)(args.projectId, (v) => ({ project_id: v }))), (0, request_helpers_1.spreadIfDefined)(args.sectionId, (v) => ({ section_id: v }))), (0, request_helpers_1.spreadIfDefined)(args.parentId, (v) => ({ parent_id: v }))),
213
- requestId: requestId,
214
- });
215
- return (0, validators_1.validateTask)(response.data);
216
- }
217
- async closeTask(id, requestId) {
218
- validators_1.IdSchema.parse(id);
219
- const response = await (0, http_client_1.request)({
220
- httpMethod: 'POST',
221
- baseUri: this.syncApiBase,
222
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_CLOSE),
223
- apiToken: this.authToken,
224
- customFetch: this.customFetch,
225
- requestId: requestId,
226
- });
227
- return (0, http_client_1.isSuccess)(response);
228
- }
229
- async reopenTask(id, requestId) {
230
- validators_1.IdSchema.parse(id);
231
- const response = await (0, http_client_1.request)({
232
- httpMethod: 'POST',
233
- baseUri: this.syncApiBase,
234
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id, endpoints_1.ENDPOINT_REST_TASK_REOPEN),
235
- apiToken: this.authToken,
236
- customFetch: this.customFetch,
237
- requestId: requestId,
238
- });
239
- return (0, http_client_1.isSuccess)(response);
240
- }
241
- async deleteTask(id, requestId) {
242
- validators_1.IdSchema.parse(id);
243
- const response = await (0, http_client_1.request)({
244
- httpMethod: 'DELETE',
245
- baseUri: this.syncApiBase,
246
- relativePath: (0, request_helpers_1.generatePath)(endpoints_1.ENDPOINT_REST_TASKS, id),
247
- apiToken: this.authToken,
248
- customFetch: this.customFetch,
249
- requestId: requestId,
250
- });
251
- return (0, http_client_1.isSuccess)(response);
252
- }
253
- }
254
- exports.TaskClient = TaskClient;
@@ -1,88 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TemplateClient = void 0;
4
- const endpoints_1 = require("../consts/endpoints");
5
- const http_client_1 = require("../transport/http-client");
6
- const multipart_upload_1 = require("../utils/multipart-upload");
7
- const validators_1 = require("../utils/validators");
8
- const base_client_1 = require("./base-client");
9
- /**
10
- * Internal sub-client handling all template-domain endpoints.
11
- *
12
- * Instantiated by `TodoistApi`; every public template method on
13
- * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
14
- * JSDoc.
15
- */
16
- class TemplateClient extends base_client_1.BaseClient {
17
- async exportTemplateAsFile(args) {
18
- const response = await (0, http_client_1.request)({
19
- httpMethod: 'GET',
20
- baseUri: this.syncApiBase,
21
- relativePath: endpoints_1.ENDPOINT_REST_TEMPLATES_FILE,
22
- apiToken: this.authToken,
23
- customFetch: this.customFetch,
24
- payload: args,
25
- });
26
- return response.data;
27
- }
28
- async exportTemplateAsUrl(args) {
29
- const { data } = await (0, http_client_1.request)({
30
- httpMethod: 'GET',
31
- baseUri: this.syncApiBase,
32
- relativePath: endpoints_1.ENDPOINT_REST_TEMPLATES_URL,
33
- apiToken: this.authToken,
34
- customFetch: this.customFetch,
35
- payload: args,
36
- });
37
- return data;
38
- }
39
- async createProjectFromTemplate(args, requestId) {
40
- const { file, fileName, name, workspaceId } = args;
41
- const additionalFields = { name };
42
- if (workspaceId !== undefined && workspaceId !== null) {
43
- additionalFields.workspace_id = workspaceId;
44
- }
45
- const data = await (0, multipart_upload_1.uploadMultipartFile)({
46
- baseUrl: this.syncApiBase,
47
- authToken: this.authToken,
48
- endpoint: endpoints_1.ENDPOINT_REST_TEMPLATES_CREATE_FROM_FILE,
49
- file,
50
- fileName,
51
- additionalFields,
52
- customFetch: this.customFetch,
53
- requestId,
54
- });
55
- return this.validateTemplateResponse(data);
56
- }
57
- async importTemplateIntoProject(args, requestId) {
58
- const { file, fileName, projectId } = args;
59
- const data = await (0, multipart_upload_1.uploadMultipartFile)({
60
- baseUrl: this.syncApiBase,
61
- authToken: this.authToken,
62
- endpoint: endpoints_1.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_FILE,
63
- file,
64
- fileName,
65
- additionalFields: { project_id: projectId },
66
- customFetch: this.customFetch,
67
- requestId,
68
- });
69
- return this.validateTemplateResponse(data);
70
- }
71
- async importTemplateFromId(args, requestId) {
72
- const { data } = await (0, http_client_1.request)({
73
- httpMethod: 'POST',
74
- baseUri: this.syncApiBase,
75
- relativePath: endpoints_1.ENDPOINT_REST_TEMPLATES_IMPORT_FROM_ID,
76
- apiToken: this.authToken,
77
- customFetch: this.customFetch,
78
- payload: args,
79
- requestId: requestId,
80
- });
81
- return this.validateTemplateResponse(data);
82
- }
83
- validateTemplateResponse(data) {
84
- var _a, _b, _c, _d;
85
- return Object.assign(Object.assign({}, data), { projects: (0, validators_1.validateProjectArray)((_a = data.projects) !== null && _a !== void 0 ? _a : []), sections: (0, validators_1.validateSectionArray)((_b = data.sections) !== null && _b !== void 0 ? _b : []), tasks: (0, validators_1.validateTaskArray)((_c = data.tasks) !== null && _c !== void 0 ? _c : []), comments: (0, validators_1.validateCommentArray)((_d = data.comments) !== null && _d !== void 0 ? _d : []) });
86
- }
87
- }
88
- exports.TemplateClient = TemplateClient;