@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.
- package/dist/cjs/authentication.js +1 -0
- package/dist/cjs/clients/activity-client.js +63 -0
- package/dist/cjs/clients/app-client.js +347 -0
- package/dist/cjs/clients/backup-client.js +65 -0
- package/dist/cjs/clients/base-client.js +30 -0
- package/dist/cjs/clients/comment-client.js +92 -0
- package/dist/cjs/clients/email-client.js +43 -0
- package/dist/cjs/clients/folder-client.js +80 -0
- package/dist/cjs/clients/id-mapping-client.js +39 -0
- package/dist/cjs/clients/insights-client.js +88 -0
- package/dist/cjs/clients/label-client.js +127 -0
- package/dist/cjs/clients/productivity-client.js +27 -0
- package/dist/cjs/clients/project-client.js +232 -0
- package/dist/cjs/clients/reminder-client.js +198 -0
- package/dist/cjs/clients/section-client.js +118 -0
- package/dist/cjs/clients/task-client.js +255 -0
- package/dist/cjs/clients/template-client.js +89 -0
- package/dist/cjs/clients/ui-extension-client.js +109 -0
- package/dist/cjs/clients/upload-client.js +102 -0
- package/dist/cjs/clients/workspace-client.js +367 -0
- package/dist/cjs/consts/endpoints.js +66 -1
- package/dist/cjs/test-utils/test-defaults.js +77 -1
- package/dist/cjs/todoist-api.js +422 -1537
- package/dist/cjs/transport/http-client.js +1 -0
- package/dist/cjs/transport/sync-request.js +75 -0
- package/dist/cjs/types/apps/index.js +18 -0
- package/dist/cjs/types/apps/requests.js +2 -0
- package/dist/cjs/types/apps/types.js +253 -0
- package/dist/cjs/types/index.js +2 -0
- package/dist/cjs/types/ui-extensions/index.js +18 -0
- package/dist/cjs/types/ui-extensions/requests.js +2 -0
- package/dist/cjs/types/ui-extensions/types.js +77 -0
- package/dist/cjs/utils/headers.js +16 -0
- package/dist/cjs/utils/request-helpers.js +21 -0
- package/dist/cjs/utils/validators.js +52 -38
- package/dist/esm/authentication.js +1 -0
- package/dist/esm/clients/activity-client.js +59 -0
- package/dist/esm/clients/app-client.js +343 -0
- package/dist/esm/clients/backup-client.js +61 -0
- package/dist/esm/clients/base-client.js +26 -0
- package/dist/esm/clients/comment-client.js +88 -0
- package/dist/esm/clients/email-client.js +39 -0
- package/dist/esm/clients/folder-client.js +76 -0
- package/dist/esm/clients/id-mapping-client.js +35 -0
- package/dist/esm/clients/insights-client.js +84 -0
- package/dist/esm/clients/label-client.js +123 -0
- package/dist/esm/clients/productivity-client.js +23 -0
- package/dist/esm/clients/project-client.js +228 -0
- package/dist/esm/clients/reminder-client.js +194 -0
- package/dist/esm/clients/section-client.js +114 -0
- package/dist/esm/clients/task-client.js +251 -0
- package/dist/esm/clients/template-client.js +85 -0
- package/dist/esm/clients/ui-extension-client.js +105 -0
- package/dist/esm/clients/upload-client.js +98 -0
- package/dist/esm/clients/workspace-client.js +363 -0
- package/dist/esm/consts/endpoints.js +51 -0
- package/dist/esm/test-utils/test-defaults.js +75 -0
- package/dist/esm/todoist-api.js +425 -1540
- package/dist/esm/transport/http-client.js +1 -0
- package/dist/esm/transport/sync-request.js +72 -0
- package/dist/esm/types/apps/index.js +2 -0
- package/dist/esm/types/apps/requests.js +1 -0
- package/dist/esm/types/apps/types.js +248 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/ui-extensions/index.js +2 -0
- package/dist/esm/types/ui-extensions/requests.js +1 -0
- package/dist/esm/types/ui-extensions/types.js +74 -0
- package/dist/esm/utils/headers.js +13 -0
- package/dist/esm/utils/request-helpers.js +17 -0
- package/dist/esm/utils/validators.js +14 -0
- package/dist/types/authentication.d.ts +1 -1
- package/dist/types/clients/activity-client.d.ts +12 -0
- package/dist/types/clients/app-client.d.ts +37 -0
- package/dist/types/clients/backup-client.d.ts +14 -0
- package/dist/types/clients/base-client.d.ts +21 -0
- package/dist/types/clients/comment-client.d.ts +15 -0
- package/dist/types/clients/email-client.d.ts +13 -0
- package/dist/types/clients/folder-client.d.ts +16 -0
- package/dist/types/clients/id-mapping-client.d.ts +13 -0
- package/dist/types/clients/insights-client.d.ts +18 -0
- package/dist/types/clients/label-client.d.ts +19 -0
- package/dist/types/clients/productivity-client.d.ts +12 -0
- package/dist/types/clients/project-client.d.ts +26 -0
- package/dist/types/clients/reminder-client.d.ts +25 -0
- package/dist/types/clients/section-client.d.ts +18 -0
- package/dist/types/clients/task-client.d.ts +25 -0
- package/dist/types/clients/template-client.d.ts +17 -0
- package/dist/types/clients/ui-extension-client.d.ts +18 -0
- package/dist/types/clients/upload-client.d.ts +17 -0
- package/dist/types/clients/workspace-client.d.ts +43 -0
- package/dist/types/consts/endpoints.d.ts +24 -0
- package/dist/types/test-utils/test-defaults.d.ts +16 -1
- package/dist/types/todoist-api.d.ts +238 -17
- package/dist/types/transport/sync-request.d.ts +27 -0
- package/dist/types/types/apps/index.d.ts +2 -0
- package/dist/types/types/apps/requests.d.ts +89 -0
- package/dist/types/types/apps/types.d.ts +414 -0
- package/dist/types/types/http.d.ts +8 -1
- package/dist/types/types/index.d.ts +2 -0
- package/dist/types/types/sync/resources/user.d.ts +2 -2
- package/dist/types/types/sync/response.d.ts +2 -2
- package/dist/types/types/sync/user-preferences.d.ts +1 -1
- package/dist/types/types/ui-extensions/index.d.ts +2 -0
- package/dist/types/types/ui-extensions/requests.d.ts +108 -0
- package/dist/types/types/ui-extensions/types.d.ts +185 -0
- package/dist/types/utils/headers.d.ts +7 -0
- package/dist/types/utils/request-helpers.d.ts +13 -0
- package/dist/types/utils/validators.d.ts +223 -0
- package/package.json +1 -1
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ENDPOINT_REST_APPS_UI_EXTENSIONS, ENDPOINT_REST_APPS_UI_EXTENSIONS_INSTALLED, getUiExtensionEndpoint, getUiExtensionIconEndpoint, getUiExtensionsByIntegrationEndpoint, } from '../consts/endpoints.js';
|
|
3
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
4
|
+
import { camelCaseKeys } from '../utils/case-conversion.js';
|
|
5
|
+
import { uploadMultipartFile } from '../utils/multipart-upload.js';
|
|
6
|
+
import { validateUiExtension, validateUiExtensionArray } from '../utils/validators.js';
|
|
7
|
+
import { BaseClient } from './base-client.js';
|
|
8
|
+
/**
|
|
9
|
+
* Internal sub-client handling all UI-extension endpoints for developer
|
|
10
|
+
* applications. All endpoints require the `dev:app_console` OAuth scope.
|
|
11
|
+
*
|
|
12
|
+
* Instantiated by `TodoistApi`; every public UI-extension method on
|
|
13
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing JSDoc.
|
|
14
|
+
*/
|
|
15
|
+
export class UiExtensionClient extends BaseClient {
|
|
16
|
+
async getUiExtension(uiExtensionId, requestId) {
|
|
17
|
+
z.string().parse(uiExtensionId);
|
|
18
|
+
const response = await request({
|
|
19
|
+
httpMethod: 'GET',
|
|
20
|
+
baseUri: this.syncApiBase,
|
|
21
|
+
relativePath: getUiExtensionEndpoint(uiExtensionId),
|
|
22
|
+
apiToken: this.authToken,
|
|
23
|
+
customFetch: this.customFetch,
|
|
24
|
+
requestId: requestId,
|
|
25
|
+
});
|
|
26
|
+
return validateUiExtension(response.data);
|
|
27
|
+
}
|
|
28
|
+
async getInstalledUiExtensions(requestId) {
|
|
29
|
+
const response = await request({
|
|
30
|
+
httpMethod: 'GET',
|
|
31
|
+
baseUri: this.syncApiBase,
|
|
32
|
+
relativePath: ENDPOINT_REST_APPS_UI_EXTENSIONS_INSTALLED,
|
|
33
|
+
apiToken: this.authToken,
|
|
34
|
+
customFetch: this.customFetch,
|
|
35
|
+
requestId: requestId,
|
|
36
|
+
});
|
|
37
|
+
return validateUiExtensionArray(response.data);
|
|
38
|
+
}
|
|
39
|
+
async getUiExtensionsForApp(appId, requestId) {
|
|
40
|
+
z.string().parse(appId);
|
|
41
|
+
const response = await request({
|
|
42
|
+
httpMethod: 'GET',
|
|
43
|
+
baseUri: this.syncApiBase,
|
|
44
|
+
relativePath: getUiExtensionsByIntegrationEndpoint(appId),
|
|
45
|
+
apiToken: this.authToken,
|
|
46
|
+
customFetch: this.customFetch,
|
|
47
|
+
requestId: requestId,
|
|
48
|
+
});
|
|
49
|
+
return validateUiExtensionArray(response.data);
|
|
50
|
+
}
|
|
51
|
+
async addUiExtension(args, requestId) {
|
|
52
|
+
const response = await request({
|
|
53
|
+
httpMethod: 'POST',
|
|
54
|
+
baseUri: this.syncApiBase,
|
|
55
|
+
relativePath: ENDPOINT_REST_APPS_UI_EXTENSIONS,
|
|
56
|
+
apiToken: this.authToken,
|
|
57
|
+
customFetch: this.customFetch,
|
|
58
|
+
payload: args,
|
|
59
|
+
requestId: requestId,
|
|
60
|
+
});
|
|
61
|
+
return validateUiExtension(response.data);
|
|
62
|
+
}
|
|
63
|
+
async updateUiExtension(uiExtensionId, args, requestId) {
|
|
64
|
+
z.string().parse(uiExtensionId);
|
|
65
|
+
const response = await request({
|
|
66
|
+
httpMethod: 'PATCH',
|
|
67
|
+
baseUri: this.syncApiBase,
|
|
68
|
+
relativePath: getUiExtensionEndpoint(uiExtensionId),
|
|
69
|
+
apiToken: this.authToken,
|
|
70
|
+
customFetch: this.customFetch,
|
|
71
|
+
payload: args,
|
|
72
|
+
requestId: requestId,
|
|
73
|
+
});
|
|
74
|
+
return validateUiExtension(response.data);
|
|
75
|
+
}
|
|
76
|
+
async deleteUiExtension(uiExtensionId, requestId) {
|
|
77
|
+
z.string().parse(uiExtensionId);
|
|
78
|
+
const response = await request({
|
|
79
|
+
httpMethod: 'DELETE',
|
|
80
|
+
baseUri: this.syncApiBase,
|
|
81
|
+
relativePath: getUiExtensionEndpoint(uiExtensionId),
|
|
82
|
+
apiToken: this.authToken,
|
|
83
|
+
customFetch: this.customFetch,
|
|
84
|
+
requestId: requestId,
|
|
85
|
+
});
|
|
86
|
+
return isSuccess(response);
|
|
87
|
+
}
|
|
88
|
+
async uploadUiExtensionIcon(args, requestId) {
|
|
89
|
+
var _a;
|
|
90
|
+
if (Buffer.isBuffer(args.file) && args.file.length === 0) {
|
|
91
|
+
throw new Error('Cannot upload empty image file');
|
|
92
|
+
}
|
|
93
|
+
const data = await uploadMultipartFile({
|
|
94
|
+
baseUrl: this.syncApiBase,
|
|
95
|
+
authToken: this.authToken,
|
|
96
|
+
endpoint: getUiExtensionIconEndpoint(args.uiExtensionId),
|
|
97
|
+
file: args.file,
|
|
98
|
+
fileName: args.fileName,
|
|
99
|
+
additionalFields: { file_name: (_a = args.fileName) !== null && _a !== void 0 ? _a : '' },
|
|
100
|
+
requestId: requestId,
|
|
101
|
+
customFetch: this.customFetch,
|
|
102
|
+
});
|
|
103
|
+
return validateUiExtension(camelCaseKeys(data));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { ENDPOINT_REST_UPLOADS } from '../consts/endpoints.js';
|
|
2
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
3
|
+
import { headersToRecord } from '../utils/headers.js';
|
|
4
|
+
import { uploadMultipartFile } from '../utils/multipart-upload.js';
|
|
5
|
+
import { validateAttachment } from '../utils/validators.js';
|
|
6
|
+
import { BaseClient } from './base-client.js';
|
|
7
|
+
/**
|
|
8
|
+
* Internal sub-client handling upload + attachment endpoints
|
|
9
|
+
* (file upload, upload delete, attachment view).
|
|
10
|
+
*
|
|
11
|
+
* Instantiated by `TodoistApi`; every public upload method on
|
|
12
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
13
|
+
* JSDoc.
|
|
14
|
+
*/
|
|
15
|
+
export class UploadClient extends BaseClient {
|
|
16
|
+
async uploadFile(args, requestId) {
|
|
17
|
+
const additionalFields = {};
|
|
18
|
+
if (args.projectId) {
|
|
19
|
+
additionalFields.project_id = args.projectId;
|
|
20
|
+
}
|
|
21
|
+
const data = await uploadMultipartFile({
|
|
22
|
+
baseUrl: this.syncApiBase,
|
|
23
|
+
authToken: this.authToken,
|
|
24
|
+
endpoint: ENDPOINT_REST_UPLOADS,
|
|
25
|
+
file: args.file,
|
|
26
|
+
fileName: args.fileName,
|
|
27
|
+
additionalFields: additionalFields,
|
|
28
|
+
requestId: requestId,
|
|
29
|
+
customFetch: this.customFetch,
|
|
30
|
+
});
|
|
31
|
+
return validateAttachment(data);
|
|
32
|
+
}
|
|
33
|
+
async deleteUpload(args, requestId) {
|
|
34
|
+
const response = await request({
|
|
35
|
+
httpMethod: 'DELETE',
|
|
36
|
+
baseUri: this.syncApiBase,
|
|
37
|
+
relativePath: ENDPOINT_REST_UPLOADS,
|
|
38
|
+
apiToken: this.authToken,
|
|
39
|
+
customFetch: this.customFetch,
|
|
40
|
+
payload: args,
|
|
41
|
+
requestId: requestId,
|
|
42
|
+
});
|
|
43
|
+
return isSuccess(response);
|
|
44
|
+
}
|
|
45
|
+
async viewAttachment(commentOrUrl) {
|
|
46
|
+
var _a;
|
|
47
|
+
let fileUrl;
|
|
48
|
+
if (typeof commentOrUrl === 'string') {
|
|
49
|
+
fileUrl = commentOrUrl;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
if (!((_a = commentOrUrl.fileAttachment) === null || _a === void 0 ? void 0 : _a.fileUrl)) {
|
|
53
|
+
throw new Error('Comment does not have a file attachment');
|
|
54
|
+
}
|
|
55
|
+
fileUrl = commentOrUrl.fileAttachment.fileUrl;
|
|
56
|
+
}
|
|
57
|
+
// Validate the URL belongs to Todoist to prevent leaking the auth token
|
|
58
|
+
const urlHostname = new URL(fileUrl).hostname;
|
|
59
|
+
if (!urlHostname.endsWith('.todoist.com')) {
|
|
60
|
+
throw new Error('Attachment URLs must be on a todoist.com domain');
|
|
61
|
+
}
|
|
62
|
+
const fetchOptions = {
|
|
63
|
+
method: 'GET',
|
|
64
|
+
headers: { Authorization: `Bearer ${this.authToken}` },
|
|
65
|
+
};
|
|
66
|
+
if (this.customFetch) {
|
|
67
|
+
const response = await this.customFetch(fileUrl, fetchOptions);
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new Error(`Failed to fetch attachment: ${response.status} ${response.statusText}`);
|
|
70
|
+
}
|
|
71
|
+
// Convert text to ArrayBuffer for custom fetch implementations that lack arrayBuffer()
|
|
72
|
+
const text = await response.text();
|
|
73
|
+
const buffer = new TextEncoder().encode(text).buffer;
|
|
74
|
+
return {
|
|
75
|
+
ok: response.ok,
|
|
76
|
+
status: response.status,
|
|
77
|
+
statusText: response.statusText,
|
|
78
|
+
headers: response.headers,
|
|
79
|
+
text: () => Promise.resolve(text),
|
|
80
|
+
json: () => response.json(),
|
|
81
|
+
arrayBuffer: () => Promise.resolve(buffer),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const response = await fetch(fileUrl, fetchOptions);
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
throw new Error(`Failed to fetch attachment: ${response.status} ${response.statusText}`);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
ok: response.ok,
|
|
90
|
+
status: response.status,
|
|
91
|
+
statusText: response.statusText,
|
|
92
|
+
headers: headersToRecord(response.headers),
|
|
93
|
+
text: () => response.text(),
|
|
94
|
+
json: () => response.json(),
|
|
95
|
+
arrayBuffer: () => response.arrayBuffer(),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
import { ENDPOINT_REST_WORKSPACES, ENDPOINT_WORKSPACE_INVITATIONS, ENDPOINT_WORKSPACE_INVITATIONS_ALL, ENDPOINT_WORKSPACE_INVITATIONS_DELETE, ENDPOINT_WORKSPACE_JOIN, ENDPOINT_WORKSPACE_LOGO, ENDPOINT_WORKSPACE_MEMBERS, ENDPOINT_WORKSPACE_PLAN_DETAILS, ENDPOINT_WORKSPACE_USERS, getWorkspaceActiveProjectsEndpoint, getWorkspaceArchivedProjectsEndpoint, getWorkspaceInvitationAcceptEndpoint, getWorkspaceInvitationRejectEndpoint, getWorkspaceInviteUsersEndpoint, getWorkspaceUserEndpoint, getWorkspaceUserTasksEndpoint, } from '../consts/endpoints.js';
|
|
14
|
+
import { isSuccess, request } from '../transport/http-client.js';
|
|
15
|
+
import { uploadMultipartFile } from '../utils/multipart-upload.js';
|
|
16
|
+
import { generatePath } from '../utils/request-helpers.js';
|
|
17
|
+
import { validateJoinWorkspaceResult, validateMemberActivityInfoArray, validateProject, validateWorkspace, validateWorkspaceArray, validateWorkspaceInvitation, validateWorkspaceInvitationArray, validateWorkspacePlanDetails, validateWorkspaceUserArray, validateWorkspaceUserTaskArray, } from '../utils/validators.js';
|
|
18
|
+
import { BaseClient } from './base-client.js';
|
|
19
|
+
/**
|
|
20
|
+
* Internal sub-client handling all workspace-domain endpoints —
|
|
21
|
+
* workspaces, invitations, users, plans, logos, and workspace project
|
|
22
|
+
* pagination.
|
|
23
|
+
*
|
|
24
|
+
* Instantiated by `TodoistApi`; every public workspace method on
|
|
25
|
+
* `TodoistApi` delegates here. See `todoist-api.ts` for user-facing
|
|
26
|
+
* JSDoc.
|
|
27
|
+
*/
|
|
28
|
+
export class WorkspaceClient extends BaseClient {
|
|
29
|
+
async getWorkspaceInvitations(args, requestId) {
|
|
30
|
+
const response = await request({
|
|
31
|
+
httpMethod: 'GET',
|
|
32
|
+
baseUri: this.syncApiBase,
|
|
33
|
+
relativePath: ENDPOINT_WORKSPACE_INVITATIONS,
|
|
34
|
+
apiToken: this.authToken,
|
|
35
|
+
customFetch: this.customFetch,
|
|
36
|
+
payload: { workspace_id: args.workspaceId },
|
|
37
|
+
requestId: requestId,
|
|
38
|
+
});
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
async getAllWorkspaceInvitations(args = {}, requestId) {
|
|
42
|
+
const queryParams = {};
|
|
43
|
+
if (args.workspaceId) {
|
|
44
|
+
queryParams.workspace_id = args.workspaceId;
|
|
45
|
+
}
|
|
46
|
+
const response = await request({
|
|
47
|
+
httpMethod: 'GET',
|
|
48
|
+
baseUri: this.syncApiBase,
|
|
49
|
+
relativePath: ENDPOINT_WORKSPACE_INVITATIONS_ALL,
|
|
50
|
+
apiToken: this.authToken,
|
|
51
|
+
customFetch: this.customFetch,
|
|
52
|
+
payload: queryParams,
|
|
53
|
+
requestId: requestId,
|
|
54
|
+
});
|
|
55
|
+
return validateWorkspaceInvitationArray(response.data);
|
|
56
|
+
}
|
|
57
|
+
async deleteWorkspaceInvitation(args, requestId) {
|
|
58
|
+
const response = await request({
|
|
59
|
+
httpMethod: 'POST',
|
|
60
|
+
baseUri: this.syncApiBase,
|
|
61
|
+
relativePath: ENDPOINT_WORKSPACE_INVITATIONS_DELETE,
|
|
62
|
+
apiToken: this.authToken,
|
|
63
|
+
customFetch: this.customFetch,
|
|
64
|
+
payload: {
|
|
65
|
+
workspace_id: args.workspaceId,
|
|
66
|
+
user_email: args.userEmail,
|
|
67
|
+
},
|
|
68
|
+
requestId: requestId,
|
|
69
|
+
});
|
|
70
|
+
return validateWorkspaceInvitation(response.data);
|
|
71
|
+
}
|
|
72
|
+
async acceptWorkspaceInvitation(args, requestId) {
|
|
73
|
+
const response = await request({
|
|
74
|
+
httpMethod: 'PUT',
|
|
75
|
+
baseUri: this.syncApiBase,
|
|
76
|
+
relativePath: getWorkspaceInvitationAcceptEndpoint(args.inviteCode),
|
|
77
|
+
apiToken: this.authToken,
|
|
78
|
+
customFetch: this.customFetch,
|
|
79
|
+
requestId: requestId,
|
|
80
|
+
});
|
|
81
|
+
return validateWorkspaceInvitation(response.data);
|
|
82
|
+
}
|
|
83
|
+
async rejectWorkspaceInvitation(args, requestId) {
|
|
84
|
+
const response = await request({
|
|
85
|
+
httpMethod: 'PUT',
|
|
86
|
+
baseUri: this.syncApiBase,
|
|
87
|
+
relativePath: getWorkspaceInvitationRejectEndpoint(args.inviteCode),
|
|
88
|
+
apiToken: this.authToken,
|
|
89
|
+
customFetch: this.customFetch,
|
|
90
|
+
requestId: requestId,
|
|
91
|
+
});
|
|
92
|
+
return validateWorkspaceInvitation(response.data);
|
|
93
|
+
}
|
|
94
|
+
async joinWorkspace(args, requestId) {
|
|
95
|
+
const response = await request({
|
|
96
|
+
httpMethod: 'POST',
|
|
97
|
+
baseUri: this.syncApiBase,
|
|
98
|
+
relativePath: ENDPOINT_WORKSPACE_JOIN,
|
|
99
|
+
apiToken: this.authToken,
|
|
100
|
+
customFetch: this.customFetch,
|
|
101
|
+
payload: {
|
|
102
|
+
invite_code: args.inviteCode,
|
|
103
|
+
workspace_id: args.workspaceId,
|
|
104
|
+
},
|
|
105
|
+
requestId: requestId,
|
|
106
|
+
});
|
|
107
|
+
return validateJoinWorkspaceResult(response.data);
|
|
108
|
+
}
|
|
109
|
+
async uploadWorkspaceLogo(args, requestId) {
|
|
110
|
+
if (args.delete) {
|
|
111
|
+
// Delete logo
|
|
112
|
+
const data = await uploadMultipartFile({
|
|
113
|
+
baseUrl: this.syncApiBase,
|
|
114
|
+
authToken: this.authToken,
|
|
115
|
+
endpoint: ENDPOINT_WORKSPACE_LOGO,
|
|
116
|
+
file: Buffer.alloc(0), // Empty buffer for delete
|
|
117
|
+
fileName: 'delete',
|
|
118
|
+
additionalFields: {
|
|
119
|
+
workspace_id: args.workspaceId,
|
|
120
|
+
delete: true,
|
|
121
|
+
},
|
|
122
|
+
requestId: requestId,
|
|
123
|
+
customFetch: this.customFetch,
|
|
124
|
+
});
|
|
125
|
+
return data;
|
|
126
|
+
}
|
|
127
|
+
if (!args.file) {
|
|
128
|
+
throw new Error('file is required when not deleting logo');
|
|
129
|
+
}
|
|
130
|
+
// Validate buffer is not empty if it's a Buffer
|
|
131
|
+
if (Buffer.isBuffer(args.file) && args.file.length === 0) {
|
|
132
|
+
throw new Error('Cannot upload empty image file');
|
|
133
|
+
}
|
|
134
|
+
const additionalFields = {
|
|
135
|
+
workspace_id: args.workspaceId,
|
|
136
|
+
};
|
|
137
|
+
const data = await uploadMultipartFile({
|
|
138
|
+
baseUrl: this.syncApiBase,
|
|
139
|
+
authToken: this.authToken,
|
|
140
|
+
endpoint: ENDPOINT_WORKSPACE_LOGO,
|
|
141
|
+
file: args.file,
|
|
142
|
+
fileName: args.fileName,
|
|
143
|
+
additionalFields: additionalFields,
|
|
144
|
+
requestId: requestId,
|
|
145
|
+
customFetch: this.customFetch,
|
|
146
|
+
});
|
|
147
|
+
return data;
|
|
148
|
+
}
|
|
149
|
+
async getWorkspacePlanDetails(args, requestId) {
|
|
150
|
+
const response = await request({
|
|
151
|
+
httpMethod: 'GET',
|
|
152
|
+
baseUri: this.syncApiBase,
|
|
153
|
+
relativePath: ENDPOINT_WORKSPACE_PLAN_DETAILS,
|
|
154
|
+
apiToken: this.authToken,
|
|
155
|
+
customFetch: this.customFetch,
|
|
156
|
+
payload: { workspace_id: args.workspaceId },
|
|
157
|
+
requestId: requestId,
|
|
158
|
+
});
|
|
159
|
+
return validateWorkspacePlanDetails(response.data);
|
|
160
|
+
}
|
|
161
|
+
async getWorkspaceUsers(args = {}, requestId) {
|
|
162
|
+
const queryParams = {};
|
|
163
|
+
if (args.workspaceId !== undefined && args.workspaceId !== null) {
|
|
164
|
+
queryParams.workspace_id = args.workspaceId;
|
|
165
|
+
}
|
|
166
|
+
if (args.cursor) {
|
|
167
|
+
queryParams.cursor = args.cursor;
|
|
168
|
+
}
|
|
169
|
+
if (args.limit) {
|
|
170
|
+
queryParams.limit = args.limit;
|
|
171
|
+
}
|
|
172
|
+
const response = await request({
|
|
173
|
+
httpMethod: 'GET',
|
|
174
|
+
baseUri: this.syncApiBase,
|
|
175
|
+
relativePath: ENDPOINT_WORKSPACE_USERS,
|
|
176
|
+
apiToken: this.authToken,
|
|
177
|
+
customFetch: this.customFetch,
|
|
178
|
+
payload: queryParams,
|
|
179
|
+
requestId: requestId,
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
hasMore: response.data.hasMore || false,
|
|
183
|
+
nextCursor: response.data.nextCursor,
|
|
184
|
+
workspaceUsers: validateWorkspaceUserArray(response.data.workspaceUsers || []),
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
async getWorkspaces(requestId) {
|
|
188
|
+
const response = await request({
|
|
189
|
+
httpMethod: 'GET',
|
|
190
|
+
baseUri: this.syncApiBase,
|
|
191
|
+
relativePath: ENDPOINT_REST_WORKSPACES,
|
|
192
|
+
apiToken: this.authToken,
|
|
193
|
+
customFetch: this.customFetch,
|
|
194
|
+
requestId: requestId,
|
|
195
|
+
});
|
|
196
|
+
return validateWorkspaceArray(response.data);
|
|
197
|
+
}
|
|
198
|
+
async getWorkspace(id, requestId) {
|
|
199
|
+
z.string().parse(id);
|
|
200
|
+
const response = await request({
|
|
201
|
+
httpMethod: 'GET',
|
|
202
|
+
baseUri: this.syncApiBase,
|
|
203
|
+
relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
|
|
204
|
+
apiToken: this.authToken,
|
|
205
|
+
customFetch: this.customFetch,
|
|
206
|
+
requestId: requestId,
|
|
207
|
+
});
|
|
208
|
+
return validateWorkspace(response.data);
|
|
209
|
+
}
|
|
210
|
+
async addWorkspace(args, requestId) {
|
|
211
|
+
const response = await request({
|
|
212
|
+
httpMethod: 'POST',
|
|
213
|
+
baseUri: this.syncApiBase,
|
|
214
|
+
relativePath: ENDPOINT_REST_WORKSPACES,
|
|
215
|
+
apiToken: this.authToken,
|
|
216
|
+
customFetch: this.customFetch,
|
|
217
|
+
payload: args,
|
|
218
|
+
requestId: requestId,
|
|
219
|
+
});
|
|
220
|
+
return validateWorkspace(response.data);
|
|
221
|
+
}
|
|
222
|
+
async updateWorkspace(id, args, requestId) {
|
|
223
|
+
z.string().parse(id);
|
|
224
|
+
const response = await request({
|
|
225
|
+
httpMethod: 'POST',
|
|
226
|
+
baseUri: this.syncApiBase,
|
|
227
|
+
relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
|
|
228
|
+
apiToken: this.authToken,
|
|
229
|
+
customFetch: this.customFetch,
|
|
230
|
+
payload: args,
|
|
231
|
+
requestId: requestId,
|
|
232
|
+
});
|
|
233
|
+
return validateWorkspace(response.data);
|
|
234
|
+
}
|
|
235
|
+
async deleteWorkspace(id, requestId) {
|
|
236
|
+
z.string().parse(id);
|
|
237
|
+
const response = await request({
|
|
238
|
+
httpMethod: 'DELETE',
|
|
239
|
+
baseUri: this.syncApiBase,
|
|
240
|
+
relativePath: generatePath(ENDPOINT_REST_WORKSPACES, id),
|
|
241
|
+
apiToken: this.authToken,
|
|
242
|
+
customFetch: this.customFetch,
|
|
243
|
+
requestId: requestId,
|
|
244
|
+
});
|
|
245
|
+
return isSuccess(response);
|
|
246
|
+
}
|
|
247
|
+
async getWorkspaceMembersActivity(args, requestId) {
|
|
248
|
+
const { workspaceId } = args, queryParams = __rest(args, ["workspaceId"]);
|
|
249
|
+
const { data } = await request({
|
|
250
|
+
httpMethod: 'GET',
|
|
251
|
+
baseUri: this.syncApiBase,
|
|
252
|
+
relativePath: ENDPOINT_WORKSPACE_MEMBERS,
|
|
253
|
+
apiToken: this.authToken,
|
|
254
|
+
customFetch: this.customFetch,
|
|
255
|
+
payload: Object.assign({ workspaceId }, queryParams),
|
|
256
|
+
requestId: requestId,
|
|
257
|
+
});
|
|
258
|
+
return {
|
|
259
|
+
members: validateMemberActivityInfoArray(data.members),
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
async getWorkspaceUserTasks(args, requestId) {
|
|
263
|
+
const { workspaceId, userId } = args, queryParams = __rest(args, ["workspaceId", "userId"]);
|
|
264
|
+
const { data } = await request({
|
|
265
|
+
httpMethod: 'GET',
|
|
266
|
+
baseUri: this.syncApiBase,
|
|
267
|
+
relativePath: getWorkspaceUserTasksEndpoint(workspaceId, userId),
|
|
268
|
+
apiToken: this.authToken,
|
|
269
|
+
customFetch: this.customFetch,
|
|
270
|
+
payload: queryParams,
|
|
271
|
+
requestId: requestId,
|
|
272
|
+
});
|
|
273
|
+
return {
|
|
274
|
+
tasks: validateWorkspaceUserTaskArray(data.tasks),
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
async inviteWorkspaceUsers(args, requestId) {
|
|
278
|
+
const { workspaceId } = args, payload = __rest(args, ["workspaceId"]);
|
|
279
|
+
const { data } = await request({
|
|
280
|
+
httpMethod: 'POST',
|
|
281
|
+
baseUri: this.syncApiBase,
|
|
282
|
+
relativePath: getWorkspaceInviteUsersEndpoint(workspaceId),
|
|
283
|
+
apiToken: this.authToken,
|
|
284
|
+
customFetch: this.customFetch,
|
|
285
|
+
payload: payload,
|
|
286
|
+
requestId: requestId,
|
|
287
|
+
});
|
|
288
|
+
return data;
|
|
289
|
+
}
|
|
290
|
+
async updateWorkspaceUser(args, requestId) {
|
|
291
|
+
const { workspaceId, userId } = args, payload = __rest(args, ["workspaceId", "userId"]);
|
|
292
|
+
const response = await request({
|
|
293
|
+
httpMethod: 'POST',
|
|
294
|
+
baseUri: this.syncApiBase,
|
|
295
|
+
relativePath: getWorkspaceUserEndpoint(workspaceId, userId),
|
|
296
|
+
apiToken: this.authToken,
|
|
297
|
+
customFetch: this.customFetch,
|
|
298
|
+
payload: payload,
|
|
299
|
+
requestId: requestId,
|
|
300
|
+
});
|
|
301
|
+
return validateJoinWorkspaceResult(response.data);
|
|
302
|
+
}
|
|
303
|
+
async removeWorkspaceUser(args, requestId) {
|
|
304
|
+
const { workspaceId, userId } = args;
|
|
305
|
+
const response = await request({
|
|
306
|
+
httpMethod: 'DELETE',
|
|
307
|
+
baseUri: this.syncApiBase,
|
|
308
|
+
relativePath: getWorkspaceUserEndpoint(workspaceId, userId),
|
|
309
|
+
apiToken: this.authToken,
|
|
310
|
+
customFetch: this.customFetch,
|
|
311
|
+
requestId: requestId,
|
|
312
|
+
});
|
|
313
|
+
return isSuccess(response);
|
|
314
|
+
}
|
|
315
|
+
async getWorkspaceActiveProjects(args, requestId) {
|
|
316
|
+
var _a;
|
|
317
|
+
const queryParams = {};
|
|
318
|
+
if (args.cursor) {
|
|
319
|
+
queryParams.cursor = args.cursor;
|
|
320
|
+
}
|
|
321
|
+
if (args.limit) {
|
|
322
|
+
queryParams.limit = args.limit;
|
|
323
|
+
}
|
|
324
|
+
const response = await request({
|
|
325
|
+
httpMethod: 'GET',
|
|
326
|
+
baseUri: this.syncApiBase,
|
|
327
|
+
relativePath: getWorkspaceActiveProjectsEndpoint(args.workspaceId),
|
|
328
|
+
apiToken: this.authToken,
|
|
329
|
+
customFetch: this.customFetch,
|
|
330
|
+
payload: queryParams,
|
|
331
|
+
requestId: requestId,
|
|
332
|
+
});
|
|
333
|
+
// oxlint-disable-next-line no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access
|
|
334
|
+
const validatedProjects = (_a = response.data.results) === null || _a === void 0 ? void 0 : _a.map((project) => validateProject(project));
|
|
335
|
+
return Object.assign(Object.assign({}, response.data), {
|
|
336
|
+
// oxlint-disable-next-line no-unsafe-assignment
|
|
337
|
+
results: validatedProjects || [] });
|
|
338
|
+
}
|
|
339
|
+
async getWorkspaceArchivedProjects(args, requestId) {
|
|
340
|
+
var _a;
|
|
341
|
+
const queryParams = {};
|
|
342
|
+
if (args.cursor) {
|
|
343
|
+
queryParams.cursor = args.cursor;
|
|
344
|
+
}
|
|
345
|
+
if (args.limit) {
|
|
346
|
+
queryParams.limit = args.limit;
|
|
347
|
+
}
|
|
348
|
+
const response = await request({
|
|
349
|
+
httpMethod: 'GET',
|
|
350
|
+
baseUri: this.syncApiBase,
|
|
351
|
+
relativePath: getWorkspaceArchivedProjectsEndpoint(args.workspaceId),
|
|
352
|
+
apiToken: this.authToken,
|
|
353
|
+
customFetch: this.customFetch,
|
|
354
|
+
payload: queryParams,
|
|
355
|
+
requestId: requestId,
|
|
356
|
+
});
|
|
357
|
+
// oxlint-disable-next-line no-unsafe-assignment, no-unsafe-call, no-unsafe-member-access
|
|
358
|
+
const validatedProjects = (_a = response.data.results) === null || _a === void 0 ? void 0 : _a.map((project) => validateProject(project));
|
|
359
|
+
return Object.assign(Object.assign({}, response.data), {
|
|
360
|
+
// oxlint-disable-next-line no-unsafe-assignment
|
|
361
|
+
results: validatedProjects || [] });
|
|
362
|
+
}
|
|
363
|
+
}
|
|
@@ -121,3 +121,54 @@ export function getWorkspaceActiveProjectsEndpoint(workspaceId) {
|
|
|
121
121
|
export function getWorkspaceArchivedProjectsEndpoint(workspaceId) {
|
|
122
122
|
return `workspaces/${workspaceId}/projects/archived`;
|
|
123
123
|
}
|
|
124
|
+
// App management endpoints (dev:app_console scope)
|
|
125
|
+
export const ENDPOINT_REST_APPS = 'apps';
|
|
126
|
+
export const ENDPOINT_REST_APPS_INSTALLATIONS = 'apps/installations';
|
|
127
|
+
export const ENDPOINT_REST_APPS_UI_EXTENSIONS = 'apps/ui_extensions';
|
|
128
|
+
export const ENDPOINT_REST_APPS_UI_EXTENSIONS_INSTALLED = 'apps/ui_extensions/installed';
|
|
129
|
+
export const ENDPOINT_REST_USER_AUTHORIZATIONS = 'user/authorizations';
|
|
130
|
+
export const ENDPOINT_REST_USER_AUTHORIZATIONS_DELETE = 'user/authorizations/delete';
|
|
131
|
+
/** Available app icon sizes (small 60x60, medium 300x300, large 600x600). */
|
|
132
|
+
export const APP_ICON_SIZES = ['small', 'medium', 'large'];
|
|
133
|
+
export function getAppEndpoint(appId) {
|
|
134
|
+
return `apps/${appId}`;
|
|
135
|
+
}
|
|
136
|
+
export function getAppSecretsEndpoint(appId) {
|
|
137
|
+
return `apps/${appId}/secrets`;
|
|
138
|
+
}
|
|
139
|
+
export function getAppClientSecretEndpoint(appId) {
|
|
140
|
+
return `apps/${appId}/client_secret`;
|
|
141
|
+
}
|
|
142
|
+
export function getAppTokensEndpoint(appId) {
|
|
143
|
+
return `apps/${appId}/tokens`;
|
|
144
|
+
}
|
|
145
|
+
export function getAppTestTokenEndpoint(appId) {
|
|
146
|
+
return `apps/${appId}/test_token`;
|
|
147
|
+
}
|
|
148
|
+
export function getAppDistributionTokenEndpoint(appId) {
|
|
149
|
+
return `apps/${appId}/distribution_token`;
|
|
150
|
+
}
|
|
151
|
+
export function getAppVerificationTokenEndpoint(appId) {
|
|
152
|
+
return `apps/${appId}/verification_token`;
|
|
153
|
+
}
|
|
154
|
+
export function getAppWebhookEndpoint(appId) {
|
|
155
|
+
return `apps/${appId}/webhook`;
|
|
156
|
+
}
|
|
157
|
+
export function getAppIconEndpoint(appId, size) {
|
|
158
|
+
return size === 'medium' ? `apps/${appId}/icon` : `apps/${appId}/icon/${size}`;
|
|
159
|
+
}
|
|
160
|
+
export function getAppInstallationEndpoint(installationId) {
|
|
161
|
+
return `apps/installations/${installationId}`;
|
|
162
|
+
}
|
|
163
|
+
export function getAppByDistributionTokenEndpoint(distributionToken) {
|
|
164
|
+
return `apps/by_distribution_token/${distributionToken}`;
|
|
165
|
+
}
|
|
166
|
+
export function getUiExtensionEndpoint(uiExtensionId) {
|
|
167
|
+
return `apps/ui_extensions/${uiExtensionId}`;
|
|
168
|
+
}
|
|
169
|
+
export function getUiExtensionIconEndpoint(uiExtensionId) {
|
|
170
|
+
return `apps/ui_extensions/${uiExtensionId}/icon`;
|
|
171
|
+
}
|
|
172
|
+
export function getUiExtensionsByIntegrationEndpoint(integrationId) {
|
|
173
|
+
return `apps/ui_extensions/integration/${integrationId}`;
|
|
174
|
+
}
|