@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,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;