@doist/todoist-sdk 9.0.0 → 9.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/cjs/authentication.js +1 -0
  2. package/dist/cjs/clients/activity-client.js +63 -0
  3. package/dist/cjs/clients/app-client.js +347 -0
  4. package/dist/cjs/clients/backup-client.js +65 -0
  5. package/dist/cjs/clients/base-client.js +30 -0
  6. package/dist/cjs/clients/comment-client.js +92 -0
  7. package/dist/cjs/clients/email-client.js +43 -0
  8. package/dist/cjs/clients/folder-client.js +80 -0
  9. package/dist/cjs/clients/id-mapping-client.js +39 -0
  10. package/dist/cjs/clients/insights-client.js +88 -0
  11. package/dist/cjs/clients/label-client.js +127 -0
  12. package/dist/cjs/clients/productivity-client.js +27 -0
  13. package/dist/cjs/clients/project-client.js +232 -0
  14. package/dist/cjs/clients/reminder-client.js +198 -0
  15. package/dist/cjs/clients/section-client.js +118 -0
  16. package/dist/cjs/clients/task-client.js +255 -0
  17. package/dist/cjs/clients/template-client.js +89 -0
  18. package/dist/cjs/clients/ui-extension-client.js +109 -0
  19. package/dist/cjs/clients/upload-client.js +102 -0
  20. package/dist/cjs/clients/workspace-client.js +367 -0
  21. package/dist/cjs/consts/endpoints.js +66 -1
  22. package/dist/cjs/test-utils/test-defaults.js +77 -1
  23. package/dist/cjs/todoist-api.js +422 -1537
  24. package/dist/cjs/transport/http-client.js +1 -0
  25. package/dist/cjs/transport/sync-request.js +75 -0
  26. package/dist/cjs/types/apps/index.js +18 -0
  27. package/dist/cjs/types/apps/requests.js +2 -0
  28. package/dist/cjs/types/apps/types.js +253 -0
  29. package/dist/cjs/types/index.js +2 -0
  30. package/dist/cjs/types/ui-extensions/index.js +18 -0
  31. package/dist/cjs/types/ui-extensions/requests.js +2 -0
  32. package/dist/cjs/types/ui-extensions/types.js +77 -0
  33. package/dist/cjs/utils/headers.js +16 -0
  34. package/dist/cjs/utils/request-helpers.js +21 -0
  35. package/dist/cjs/utils/validators.js +52 -38
  36. package/dist/esm/authentication.js +1 -0
  37. package/dist/esm/clients/activity-client.js +59 -0
  38. package/dist/esm/clients/app-client.js +343 -0
  39. package/dist/esm/clients/backup-client.js +61 -0
  40. package/dist/esm/clients/base-client.js +26 -0
  41. package/dist/esm/clients/comment-client.js +88 -0
  42. package/dist/esm/clients/email-client.js +39 -0
  43. package/dist/esm/clients/folder-client.js +76 -0
  44. package/dist/esm/clients/id-mapping-client.js +35 -0
  45. package/dist/esm/clients/insights-client.js +84 -0
  46. package/dist/esm/clients/label-client.js +123 -0
  47. package/dist/esm/clients/productivity-client.js +23 -0
  48. package/dist/esm/clients/project-client.js +228 -0
  49. package/dist/esm/clients/reminder-client.js +194 -0
  50. package/dist/esm/clients/section-client.js +114 -0
  51. package/dist/esm/clients/task-client.js +251 -0
  52. package/dist/esm/clients/template-client.js +85 -0
  53. package/dist/esm/clients/ui-extension-client.js +105 -0
  54. package/dist/esm/clients/upload-client.js +98 -0
  55. package/dist/esm/clients/workspace-client.js +363 -0
  56. package/dist/esm/consts/endpoints.js +51 -0
  57. package/dist/esm/test-utils/test-defaults.js +75 -0
  58. package/dist/esm/todoist-api.js +425 -1540
  59. package/dist/esm/transport/http-client.js +1 -0
  60. package/dist/esm/transport/sync-request.js +72 -0
  61. package/dist/esm/types/apps/index.js +2 -0
  62. package/dist/esm/types/apps/requests.js +1 -0
  63. package/dist/esm/types/apps/types.js +248 -0
  64. package/dist/esm/types/index.js +2 -0
  65. package/dist/esm/types/ui-extensions/index.js +2 -0
  66. package/dist/esm/types/ui-extensions/requests.js +1 -0
  67. package/dist/esm/types/ui-extensions/types.js +74 -0
  68. package/dist/esm/utils/headers.js +13 -0
  69. package/dist/esm/utils/request-helpers.js +17 -0
  70. package/dist/esm/utils/validators.js +14 -0
  71. package/dist/types/authentication.d.ts +1 -1
  72. package/dist/types/clients/activity-client.d.ts +12 -0
  73. package/dist/types/clients/app-client.d.ts +37 -0
  74. package/dist/types/clients/backup-client.d.ts +14 -0
  75. package/dist/types/clients/base-client.d.ts +21 -0
  76. package/dist/types/clients/comment-client.d.ts +15 -0
  77. package/dist/types/clients/email-client.d.ts +13 -0
  78. package/dist/types/clients/folder-client.d.ts +16 -0
  79. package/dist/types/clients/id-mapping-client.d.ts +13 -0
  80. package/dist/types/clients/insights-client.d.ts +18 -0
  81. package/dist/types/clients/label-client.d.ts +19 -0
  82. package/dist/types/clients/productivity-client.d.ts +12 -0
  83. package/dist/types/clients/project-client.d.ts +26 -0
  84. package/dist/types/clients/reminder-client.d.ts +25 -0
  85. package/dist/types/clients/section-client.d.ts +18 -0
  86. package/dist/types/clients/task-client.d.ts +25 -0
  87. package/dist/types/clients/template-client.d.ts +17 -0
  88. package/dist/types/clients/ui-extension-client.d.ts +18 -0
  89. package/dist/types/clients/upload-client.d.ts +17 -0
  90. package/dist/types/clients/workspace-client.d.ts +43 -0
  91. package/dist/types/consts/endpoints.d.ts +24 -0
  92. package/dist/types/test-utils/test-defaults.d.ts +16 -1
  93. package/dist/types/todoist-api.d.ts +238 -17
  94. package/dist/types/transport/sync-request.d.ts +27 -0
  95. package/dist/types/types/apps/index.d.ts +2 -0
  96. package/dist/types/types/apps/requests.d.ts +89 -0
  97. package/dist/types/types/apps/types.d.ts +414 -0
  98. package/dist/types/types/http.d.ts +8 -1
  99. package/dist/types/types/index.d.ts +2 -0
  100. package/dist/types/types/sync/resources/user.d.ts +2 -2
  101. package/dist/types/types/sync/response.d.ts +2 -2
  102. package/dist/types/types/sync/user-preferences.d.ts +1 -1
  103. package/dist/types/types/ui-extensions/index.d.ts +2 -0
  104. package/dist/types/types/ui-extensions/requests.d.ts +108 -0
  105. package/dist/types/types/ui-extensions/types.d.ts +185 -0
  106. package/dist/types/utils/headers.d.ts +7 -0
  107. package/dist/types/utils/request-helpers.d.ts +13 -0
  108. package/dist/types/utils/validators.d.ts +223 -0
  109. package/package.json +1 -1
@@ -0,0 +1,76 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_REST_FOLDERS } from '../consts/endpoints.js';
3
+ import { isSuccess, request } from '../transport/http-client.js';
4
+ import { generatePath } from '../utils/request-helpers.js';
5
+ import { validateFolder, validateFolderArray } from '../utils/validators.js';
6
+ import { BaseClient } from './base-client.js';
7
+ /**
8
+ * Internal sub-client handling all folder-domain endpoints.
9
+ *
10
+ * Instantiated by `TodoistApi`; every public folder method on `TodoistApi`
11
+ * delegates here. See `todoist-api.ts` for the user-facing JSDoc.
12
+ */
13
+ export class FolderClient extends BaseClient {
14
+ async getFolders(args) {
15
+ const { data: { results, nextCursor }, } = await request({
16
+ httpMethod: 'GET',
17
+ baseUri: this.syncApiBase,
18
+ relativePath: ENDPOINT_REST_FOLDERS,
19
+ apiToken: this.authToken,
20
+ customFetch: this.customFetch,
21
+ payload: args,
22
+ });
23
+ return {
24
+ results: validateFolderArray(results),
25
+ nextCursor,
26
+ };
27
+ }
28
+ async getFolder(id) {
29
+ z.string().parse(id);
30
+ const response = await request({
31
+ httpMethod: 'GET',
32
+ baseUri: this.syncApiBase,
33
+ relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
34
+ apiToken: this.authToken,
35
+ customFetch: this.customFetch,
36
+ });
37
+ return validateFolder(response.data);
38
+ }
39
+ async addFolder(args, requestId) {
40
+ const response = await request({
41
+ httpMethod: 'POST',
42
+ baseUri: this.syncApiBase,
43
+ relativePath: ENDPOINT_REST_FOLDERS,
44
+ apiToken: this.authToken,
45
+ customFetch: this.customFetch,
46
+ payload: args,
47
+ requestId: requestId,
48
+ });
49
+ return validateFolder(response.data);
50
+ }
51
+ async updateFolder(id, args, requestId) {
52
+ z.string().parse(id);
53
+ const response = await request({
54
+ httpMethod: 'POST',
55
+ baseUri: this.syncApiBase,
56
+ relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
57
+ apiToken: this.authToken,
58
+ customFetch: this.customFetch,
59
+ payload: args,
60
+ requestId: requestId,
61
+ });
62
+ return validateFolder(response.data);
63
+ }
64
+ async deleteFolder(id, requestId) {
65
+ z.string().parse(id);
66
+ const response = await request({
67
+ httpMethod: 'DELETE',
68
+ baseUri: this.syncApiBase,
69
+ relativePath: generatePath(ENDPOINT_REST_FOLDERS, id),
70
+ apiToken: this.authToken,
71
+ customFetch: this.customFetch,
72
+ requestId: requestId,
73
+ });
74
+ return isSuccess(response);
75
+ }
76
+ }
@@ -0,0 +1,35 @@
1
+ import { ENDPOINT_REST_ID_MAPPINGS, ENDPOINT_REST_MOVED_IDS } from '../consts/endpoints.js';
2
+ import { request } from '../transport/http-client.js';
3
+ import { generatePath } from '../utils/request-helpers.js';
4
+ import { validateIdMappingArray, validateMovedIdArray } from '../utils/validators.js';
5
+ import { BaseClient } from './base-client.js';
6
+ /**
7
+ * Internal sub-client handling ID-mapping endpoints.
8
+ *
9
+ * Instantiated by `TodoistApi`; every public id-mapping method on
10
+ * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
11
+ * JSDoc.
12
+ */
13
+ export class IdMappingClient extends BaseClient {
14
+ async getIdMappings(args) {
15
+ const response = await request({
16
+ httpMethod: 'GET',
17
+ baseUri: this.syncApiBase,
18
+ relativePath: generatePath(ENDPOINT_REST_ID_MAPPINGS, args.objName, args.objIds.join(',')),
19
+ apiToken: this.authToken,
20
+ customFetch: this.customFetch,
21
+ });
22
+ return validateIdMappingArray(response.data);
23
+ }
24
+ async getMovedIds(args) {
25
+ const response = await request({
26
+ httpMethod: 'GET',
27
+ baseUri: this.syncApiBase,
28
+ relativePath: generatePath(ENDPOINT_REST_MOVED_IDS, args.objName),
29
+ apiToken: this.authToken,
30
+ customFetch: this.customFetch,
31
+ payload: args.oldIds ? { oldIds: args.oldIds.join(',') } : undefined,
32
+ });
33
+ return validateMovedIdArray(response.data);
34
+ }
35
+ }
@@ -0,0 +1,84 @@
1
+ import { z } from 'zod';
2
+ import { getProjectInsightsActivityStatsEndpoint, getProjectInsightsHealthAnalyzeEndpoint, getProjectInsightsHealthContextEndpoint, getProjectInsightsHealthEndpoint, getProjectInsightsProgressEndpoint, getWorkspaceInsightsEndpoint, } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { validateProjectActivityStats, validateProjectHealth, validateProjectHealthContext, validateProjectProgress, validateWorkspaceInsights, } from '../utils/validators.js';
5
+ import { BaseClient } from './base-client.js';
6
+ /**
7
+ * Internal sub-client handling all insights-domain endpoints
8
+ * (project activity stats, health, progress, workspace insights).
9
+ *
10
+ * Instantiated by `TodoistApi`; every public insights method on
11
+ * `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
12
+ * JSDoc.
13
+ */
14
+ export class InsightsClient extends BaseClient {
15
+ async getProjectActivityStats(projectId, args = {}) {
16
+ z.string().parse(projectId);
17
+ const response = await request({
18
+ httpMethod: 'GET',
19
+ baseUri: this.syncApiBase,
20
+ relativePath: getProjectInsightsActivityStatsEndpoint(projectId),
21
+ apiToken: this.authToken,
22
+ customFetch: this.customFetch,
23
+ payload: Object.assign({ objectType: 'ITEM', eventType: 'COMPLETED' }, args),
24
+ });
25
+ return validateProjectActivityStats(response.data);
26
+ }
27
+ async getProjectHealth(projectId) {
28
+ z.string().parse(projectId);
29
+ const response = await request({
30
+ httpMethod: 'GET',
31
+ baseUri: this.syncApiBase,
32
+ relativePath: getProjectInsightsHealthEndpoint(projectId),
33
+ apiToken: this.authToken,
34
+ customFetch: this.customFetch,
35
+ });
36
+ return validateProjectHealth(response.data);
37
+ }
38
+ async getProjectHealthContext(projectId) {
39
+ z.string().parse(projectId);
40
+ const response = await request({
41
+ httpMethod: 'GET',
42
+ baseUri: this.syncApiBase,
43
+ relativePath: getProjectInsightsHealthContextEndpoint(projectId),
44
+ apiToken: this.authToken,
45
+ customFetch: this.customFetch,
46
+ });
47
+ return validateProjectHealthContext(response.data);
48
+ }
49
+ async getProjectProgress(projectId) {
50
+ z.string().parse(projectId);
51
+ const response = await request({
52
+ httpMethod: 'GET',
53
+ baseUri: this.syncApiBase,
54
+ relativePath: getProjectInsightsProgressEndpoint(projectId),
55
+ apiToken: this.authToken,
56
+ customFetch: this.customFetch,
57
+ });
58
+ return validateProjectProgress(response.data);
59
+ }
60
+ async getWorkspaceInsights(workspaceId, args = {}) {
61
+ z.string().parse(workspaceId);
62
+ const response = await request({
63
+ httpMethod: 'GET',
64
+ baseUri: this.syncApiBase,
65
+ relativePath: getWorkspaceInsightsEndpoint(workspaceId),
66
+ apiToken: this.authToken,
67
+ customFetch: this.customFetch,
68
+ payload: Object.assign(Object.assign({}, args), (args.projectIds ? { projectIds: args.projectIds.join(',') } : {})),
69
+ });
70
+ return validateWorkspaceInsights(response.data);
71
+ }
72
+ async analyzeProjectHealth(projectId, requestId) {
73
+ z.string().parse(projectId);
74
+ const response = await request({
75
+ httpMethod: 'POST',
76
+ baseUri: this.syncApiBase,
77
+ relativePath: getProjectInsightsHealthAnalyzeEndpoint(projectId),
78
+ apiToken: this.authToken,
79
+ customFetch: this.customFetch,
80
+ requestId: requestId,
81
+ });
82
+ return validateProjectHealth(response.data);
83
+ }
84
+ }
@@ -0,0 +1,123 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_REST_LABELS, ENDPOINT_REST_LABELS_SEARCH, ENDPOINT_REST_LABELS_SHARED, ENDPOINT_REST_LABELS_SHARED_REMOVE, ENDPOINT_REST_LABELS_SHARED_RENAME, } from '../consts/endpoints.js';
3
+ import { isSuccess, request } from '../transport/http-client.js';
4
+ import { generatePath } from '../utils/request-helpers.js';
5
+ import { validateLabel, validateLabelArray } from '../utils/validators.js';
6
+ import { BaseClient } from './base-client.js';
7
+ /**
8
+ * Internal sub-client handling all label-domain endpoints.
9
+ *
10
+ * Instantiated by `TodoistApi`; every public label method on `TodoistApi`
11
+ * delegates here. See `todoist-api.ts` for the user-facing JSDoc.
12
+ */
13
+ export class LabelClient extends BaseClient {
14
+ async getLabel(id) {
15
+ z.string().parse(id);
16
+ const response = await request({
17
+ httpMethod: 'GET',
18
+ baseUri: this.syncApiBase,
19
+ relativePath: generatePath(ENDPOINT_REST_LABELS, id),
20
+ apiToken: this.authToken,
21
+ customFetch: this.customFetch,
22
+ });
23
+ return validateLabel(response.data);
24
+ }
25
+ async getLabels(args = {}) {
26
+ const { data: { results, nextCursor }, } = await request({
27
+ httpMethod: 'GET',
28
+ baseUri: this.syncApiBase,
29
+ relativePath: ENDPOINT_REST_LABELS,
30
+ apiToken: this.authToken,
31
+ customFetch: this.customFetch,
32
+ payload: args,
33
+ });
34
+ return {
35
+ results: validateLabelArray(results),
36
+ nextCursor,
37
+ };
38
+ }
39
+ async searchLabels(args) {
40
+ const { data: { results, nextCursor }, } = await request({
41
+ httpMethod: 'GET',
42
+ baseUri: this.syncApiBase,
43
+ relativePath: ENDPOINT_REST_LABELS_SEARCH,
44
+ apiToken: this.authToken,
45
+ customFetch: this.customFetch,
46
+ payload: args,
47
+ });
48
+ return {
49
+ results: validateLabelArray(results),
50
+ nextCursor,
51
+ };
52
+ }
53
+ async addLabel(args, requestId) {
54
+ const response = await request({
55
+ httpMethod: 'POST',
56
+ baseUri: this.syncApiBase,
57
+ relativePath: ENDPOINT_REST_LABELS,
58
+ apiToken: this.authToken,
59
+ customFetch: this.customFetch,
60
+ payload: args,
61
+ requestId: requestId,
62
+ });
63
+ return validateLabel(response.data);
64
+ }
65
+ async updateLabel(id, args, requestId) {
66
+ z.string().parse(id);
67
+ const response = await request({
68
+ httpMethod: 'POST',
69
+ baseUri: this.syncApiBase,
70
+ relativePath: generatePath(ENDPOINT_REST_LABELS, id),
71
+ apiToken: this.authToken,
72
+ customFetch: this.customFetch,
73
+ payload: args,
74
+ requestId: requestId,
75
+ });
76
+ return validateLabel(response.data);
77
+ }
78
+ async deleteLabel(id, requestId) {
79
+ z.string().parse(id);
80
+ const response = await request({
81
+ httpMethod: 'DELETE',
82
+ baseUri: this.syncApiBase,
83
+ relativePath: generatePath(ENDPOINT_REST_LABELS, id),
84
+ apiToken: this.authToken,
85
+ customFetch: this.customFetch,
86
+ requestId: requestId,
87
+ });
88
+ return isSuccess(response);
89
+ }
90
+ async getSharedLabels(args) {
91
+ const { data: { results, nextCursor }, } = await request({
92
+ httpMethod: 'GET',
93
+ baseUri: this.syncApiBase,
94
+ relativePath: ENDPOINT_REST_LABELS_SHARED,
95
+ apiToken: this.authToken,
96
+ customFetch: this.customFetch,
97
+ payload: args,
98
+ });
99
+ return { results, nextCursor };
100
+ }
101
+ async renameSharedLabel(args) {
102
+ const response = await request({
103
+ httpMethod: 'POST',
104
+ baseUri: this.syncApiBase,
105
+ relativePath: ENDPOINT_REST_LABELS_SHARED_RENAME,
106
+ apiToken: this.authToken,
107
+ customFetch: this.customFetch,
108
+ payload: args,
109
+ });
110
+ return isSuccess(response);
111
+ }
112
+ async removeSharedLabel(args) {
113
+ const response = await request({
114
+ httpMethod: 'POST',
115
+ baseUri: this.syncApiBase,
116
+ relativePath: ENDPOINT_REST_LABELS_SHARED_REMOVE,
117
+ apiToken: this.authToken,
118
+ customFetch: this.customFetch,
119
+ payload: args,
120
+ });
121
+ return isSuccess(response);
122
+ }
123
+ }
@@ -0,0 +1,23 @@
1
+ import { ENDPOINT_REST_PRODUCTIVITY } from '../consts/endpoints.js';
2
+ import { request } from '../transport/http-client.js';
3
+ import { validateProductivityStats } from '../utils/validators.js';
4
+ import { BaseClient } from './base-client.js';
5
+ /**
6
+ * Internal sub-client handling the productivity-stats endpoint.
7
+ *
8
+ * Instantiated by `TodoistApi`; the public `getProductivityStats` method
9
+ * on `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
10
+ * JSDoc.
11
+ */
12
+ export class ProductivityClient extends BaseClient {
13
+ async getProductivityStats() {
14
+ const response = await request({
15
+ httpMethod: 'GET',
16
+ baseUri: this.syncApiBase,
17
+ relativePath: ENDPOINT_REST_PRODUCTIVITY,
18
+ apiToken: this.authToken,
19
+ customFetch: this.customFetch,
20
+ });
21
+ return validateProductivityStats(response.data);
22
+ }
23
+ }
@@ -0,0 +1,228 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_REST_PROJECTS, ENDPOINT_REST_PROJECTS_ARCHIVED, ENDPOINT_REST_PROJECTS_ARCHIVED_COUNT, ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL, ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE, ENDPOINT_REST_PROJECTS_PERMISSIONS, ENDPOINT_REST_PROJECTS_SEARCH, ENDPOINT_REST_PROJECT_COLLABORATORS, ENDPOINT_REST_PROJECT_FULL, ENDPOINT_REST_PROJECT_JOIN, PROJECT_ARCHIVE, PROJECT_UNARCHIVE, } from '../consts/endpoints.js';
3
+ import { isSuccess, request } from '../transport/http-client.js';
4
+ import { generatePath } from '../utils/request-helpers.js';
5
+ import { validateCollaboratorArray, validateCollaboratorStateArray, validateCommentArray, validateFolder, validateNoteArray, validateProject, validateProjectArray, validateSectionArray, validateTaskArray, validateUserArray, validateWorkspaceProject, validateWorkspaceProjectArray, } from '../utils/validators.js';
6
+ import { BaseClient } from './base-client.js';
7
+ /**
8
+ * Internal sub-client handling all project-domain endpoints.
9
+ *
10
+ * Instantiated by `TodoistApi`; every public project method on `TodoistApi`
11
+ * delegates here. See `todoist-api.ts` for the user-facing JSDoc.
12
+ */
13
+ export class ProjectClient extends BaseClient {
14
+ async getProject(id) {
15
+ z.string().parse(id);
16
+ const response = await request({
17
+ httpMethod: 'GET',
18
+ baseUri: this.syncApiBase,
19
+ relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
20
+ apiToken: this.authToken,
21
+ customFetch: this.customFetch,
22
+ });
23
+ return validateProject(response.data);
24
+ }
25
+ async getProjects(args = {}) {
26
+ const { data: { results, nextCursor }, } = await request({
27
+ httpMethod: 'GET',
28
+ baseUri: this.syncApiBase,
29
+ relativePath: ENDPOINT_REST_PROJECTS,
30
+ apiToken: this.authToken,
31
+ customFetch: this.customFetch,
32
+ payload: args,
33
+ });
34
+ return {
35
+ results: validateProjectArray(results),
36
+ nextCursor,
37
+ };
38
+ }
39
+ async searchProjects(args) {
40
+ const { data: { results, nextCursor }, } = await request({
41
+ httpMethod: 'GET',
42
+ baseUri: this.syncApiBase,
43
+ relativePath: ENDPOINT_REST_PROJECTS_SEARCH,
44
+ apiToken: this.authToken,
45
+ customFetch: this.customFetch,
46
+ payload: args,
47
+ });
48
+ return {
49
+ results: validateProjectArray(results),
50
+ nextCursor,
51
+ };
52
+ }
53
+ async getArchivedProjects(args = {}) {
54
+ const { data: { results, nextCursor }, } = await request({
55
+ httpMethod: 'GET',
56
+ baseUri: this.syncApiBase,
57
+ relativePath: ENDPOINT_REST_PROJECTS_ARCHIVED,
58
+ apiToken: this.authToken,
59
+ customFetch: this.customFetch,
60
+ payload: args,
61
+ });
62
+ return {
63
+ results: validateProjectArray(results),
64
+ nextCursor,
65
+ };
66
+ }
67
+ async addProject(args, requestId) {
68
+ const response = await request({
69
+ httpMethod: 'POST',
70
+ baseUri: this.syncApiBase,
71
+ relativePath: ENDPOINT_REST_PROJECTS,
72
+ apiToken: this.authToken,
73
+ customFetch: this.customFetch,
74
+ payload: args,
75
+ requestId: requestId,
76
+ });
77
+ return validateProject(response.data);
78
+ }
79
+ async updateProject(id, args, requestId) {
80
+ z.string().parse(id);
81
+ const response = await request({
82
+ httpMethod: 'POST',
83
+ baseUri: this.syncApiBase,
84
+ relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
85
+ apiToken: this.authToken,
86
+ customFetch: this.customFetch,
87
+ payload: args,
88
+ requestId: requestId,
89
+ });
90
+ return validateProject(response.data);
91
+ }
92
+ async deleteProject(id, requestId) {
93
+ z.string().parse(id);
94
+ const response = await request({
95
+ httpMethod: 'DELETE',
96
+ baseUri: this.syncApiBase,
97
+ relativePath: generatePath(ENDPOINT_REST_PROJECTS, id),
98
+ apiToken: this.authToken,
99
+ customFetch: this.customFetch,
100
+ requestId: requestId,
101
+ });
102
+ return isSuccess(response);
103
+ }
104
+ async archiveProject(id, requestId) {
105
+ z.string().parse(id);
106
+ const response = await request({
107
+ httpMethod: 'POST',
108
+ baseUri: this.syncApiBase,
109
+ relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, PROJECT_ARCHIVE),
110
+ apiToken: this.authToken,
111
+ customFetch: this.customFetch,
112
+ requestId: requestId,
113
+ });
114
+ return validateProject(response.data);
115
+ }
116
+ async unarchiveProject(id, requestId) {
117
+ z.string().parse(id);
118
+ const response = await request({
119
+ httpMethod: 'POST',
120
+ baseUri: this.syncApiBase,
121
+ relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, PROJECT_UNARCHIVE),
122
+ apiToken: this.authToken,
123
+ customFetch: this.customFetch,
124
+ requestId: requestId,
125
+ });
126
+ return validateProject(response.data);
127
+ }
128
+ async moveProjectToWorkspace(args, requestId) {
129
+ const response = await request({
130
+ httpMethod: 'POST',
131
+ baseUri: this.syncApiBase,
132
+ relativePath: ENDPOINT_REST_PROJECTS_MOVE_TO_WORKSPACE,
133
+ apiToken: this.authToken,
134
+ customFetch: this.customFetch,
135
+ payload: args,
136
+ requestId: requestId,
137
+ });
138
+ return validateProject(response.data.project);
139
+ }
140
+ async moveProjectToPersonal(args, requestId) {
141
+ const response = await request({
142
+ httpMethod: 'POST',
143
+ baseUri: this.syncApiBase,
144
+ relativePath: ENDPOINT_REST_PROJECTS_MOVE_TO_PERSONAL,
145
+ apiToken: this.authToken,
146
+ customFetch: this.customFetch,
147
+ payload: args,
148
+ requestId: requestId,
149
+ });
150
+ return validateProject(response.data.project);
151
+ }
152
+ async getArchivedProjectsCount(args = {}) {
153
+ const { data } = await request({
154
+ httpMethod: 'GET',
155
+ baseUri: this.syncApiBase,
156
+ relativePath: ENDPOINT_REST_PROJECTS_ARCHIVED_COUNT,
157
+ apiToken: this.authToken,
158
+ customFetch: this.customFetch,
159
+ payload: args,
160
+ });
161
+ return data;
162
+ }
163
+ async getProjectPermissions() {
164
+ const { data } = await request({
165
+ httpMethod: 'GET',
166
+ baseUri: this.syncApiBase,
167
+ relativePath: ENDPOINT_REST_PROJECTS_PERMISSIONS,
168
+ apiToken: this.authToken,
169
+ customFetch: this.customFetch,
170
+ });
171
+ return data;
172
+ }
173
+ async getFullProject(id, args = {}) {
174
+ z.string().parse(id);
175
+ const { data } = await request({
176
+ httpMethod: 'GET',
177
+ baseUri: this.syncApiBase,
178
+ relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, ENDPOINT_REST_PROJECT_FULL),
179
+ apiToken: this.authToken,
180
+ customFetch: this.customFetch,
181
+ payload: args,
182
+ });
183
+ return {
184
+ project: data.project ? validateProject(data.project) : null,
185
+ commentsCount: data.commentsCount,
186
+ tasks: validateTaskArray(data.tasks),
187
+ sections: validateSectionArray(data.sections),
188
+ collaborators: validateUserArray(data.collaborators),
189
+ notes: validateCommentArray(data.notes),
190
+ };
191
+ }
192
+ async joinProject(id, requestId) {
193
+ z.string().parse(id);
194
+ const { data } = await request({
195
+ httpMethod: 'POST',
196
+ baseUri: this.syncApiBase,
197
+ relativePath: generatePath(ENDPOINT_REST_PROJECTS, id, ENDPOINT_REST_PROJECT_JOIN),
198
+ apiToken: this.authToken,
199
+ customFetch: this.customFetch,
200
+ requestId: requestId,
201
+ });
202
+ return {
203
+ project: validateWorkspaceProject(data.project),
204
+ tasks: validateTaskArray(data.tasks),
205
+ sections: validateSectionArray(data.sections),
206
+ comments: validateNoteArray(data.comments),
207
+ collaborators: validateCollaboratorArray(data.collaborators),
208
+ collaboratorStates: validateCollaboratorStateArray(data.collaboratorStates),
209
+ folder: data.folder ? validateFolder(data.folder) : null,
210
+ subprojects: validateWorkspaceProjectArray(data.subprojects),
211
+ };
212
+ }
213
+ async getProjectCollaborators(projectId, args = {}) {
214
+ z.string().parse(projectId);
215
+ const { data: { results, nextCursor }, } = await request({
216
+ httpMethod: 'GET',
217
+ baseUri: this.syncApiBase,
218
+ relativePath: generatePath(ENDPOINT_REST_PROJECTS, projectId, ENDPOINT_REST_PROJECT_COLLABORATORS),
219
+ apiToken: this.authToken,
220
+ customFetch: this.customFetch,
221
+ payload: args,
222
+ });
223
+ return {
224
+ results: validateUserArray(results),
225
+ nextCursor,
226
+ };
227
+ }
228
+ }