@doist/comms-sdk 2.0.2 → 3.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 (49) hide show
  1. package/dist/esm/transport/fetch-with-retry.js +44 -2
  2. package/dist/esm/types/errors.js +2 -2
  3. package/dist/esm/utils/url-helpers.js +104 -16
  4. package/dist/types/types/errors.d.ts +1 -1
  5. package/dist/types/utils/url-helpers.d.ts +41 -0
  6. package/package.json +5 -10
  7. package/dist/cjs/authentication.js +0 -256
  8. package/dist/cjs/clients/add-comment-helper.js +0 -43
  9. package/dist/cjs/clients/attachments-client.js +0 -71
  10. package/dist/cjs/clients/base-client.js +0 -33
  11. package/dist/cjs/clients/channels-client.js +0 -211
  12. package/dist/cjs/clients/comments-client.js +0 -175
  13. package/dist/cjs/clients/conversation-messages-client.js +0 -169
  14. package/dist/cjs/clients/conversations-client.js +0 -283
  15. package/dist/cjs/clients/groups-client.js +0 -172
  16. package/dist/cjs/clients/hooks-client.js +0 -52
  17. package/dist/cjs/clients/inbox-client.js +0 -184
  18. package/dist/cjs/clients/notify-audience.js +0 -45
  19. package/dist/cjs/clients/reactions-client.js +0 -97
  20. package/dist/cjs/clients/search-client.js +0 -138
  21. package/dist/cjs/clients/threads-client.js +0 -364
  22. package/dist/cjs/clients/users-client.js +0 -326
  23. package/dist/cjs/clients/workspace-users-client.js +0 -252
  24. package/dist/cjs/clients/workspaces-client.js +0 -174
  25. package/dist/cjs/comms-api.js +0 -70
  26. package/dist/cjs/consts/endpoints.js +0 -34
  27. package/dist/cjs/index.js +0 -53
  28. package/dist/cjs/migration.js +0 -96
  29. package/dist/cjs/package.json +0 -1
  30. package/dist/cjs/testUtils/msw-handlers.js +0 -51
  31. package/dist/cjs/testUtils/msw-setup.js +0 -35
  32. package/dist/cjs/testUtils/obsidian-fetch-adapter.js +0 -53
  33. package/dist/cjs/testUtils/test-defaults.js +0 -106
  34. package/dist/cjs/transport/fetch-with-retry.js +0 -146
  35. package/dist/cjs/transport/http-client.js +0 -56
  36. package/dist/cjs/transport/http-dispatcher.js +0 -190
  37. package/dist/cjs/types/api-version.js +0 -8
  38. package/dist/cjs/types/entities.js +0 -496
  39. package/dist/cjs/types/enums.js +0 -37
  40. package/dist/cjs/types/errors.js +0 -12
  41. package/dist/cjs/types/http.js +0 -4
  42. package/dist/cjs/types/index.js +0 -22
  43. package/dist/cjs/types/requests.js +0 -183
  44. package/dist/cjs/utils/case-conversion.js +0 -54
  45. package/dist/cjs/utils/index.js +0 -19
  46. package/dist/cjs/utils/multipart-upload.js +0 -202
  47. package/dist/cjs/utils/timestamp-conversion.js +0 -58
  48. package/dist/cjs/utils/url-helpers.js +0 -133
  49. package/dist/cjs/utils/uuidv7.js +0 -182
@@ -1,174 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WorkspacesClient = exports.ChannelListSchema = void 0;
4
- const zod_1 = require("zod");
5
- const endpoints_1 = require("../consts/endpoints");
6
- const http_client_1 = require("../transport/http-client");
7
- const entities_1 = require("../types/entities");
8
- const base_client_1 = require("./base-client");
9
- exports.ChannelListSchema = zod_1.z.array(entities_1.ChannelSchema);
10
- /**
11
- * Client for `/api/v1/workspaces/`. Workspace IDs are integers. The backend
12
- * currently rejects any `color` other than `1` on add/update.
13
- */
14
- class WorkspacesClient extends base_client_1.BaseClient {
15
- constructor() {
16
- super(...arguments);
17
- this.linkBaseUrl = this.getLinkBaseUrl();
18
- // Reuse the shared singleton when no custom base is configured.
19
- this.channelListSchema = this.linkBaseUrl
20
- ? zod_1.z.array((0, entities_1.createChannelSchema)(this.linkBaseUrl))
21
- : exports.ChannelListSchema;
22
- }
23
- /**
24
- * Gets all the user's workspaces.
25
- *
26
- * @returns An array of all workspaces the user belongs to.
27
- *
28
- * @example
29
- * ```typescript
30
- * const workspaces = await api.workspaces.getWorkspaces()
31
- * workspaces.forEach(ws => console.log(ws.name))
32
- * ```
33
- */
34
- getWorkspaces() {
35
- return (0, http_client_1.request)({
36
- httpMethod: 'GET',
37
- baseUri: this.getBaseUri(),
38
- relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get`,
39
- apiToken: this.apiToken,
40
- payload: undefined,
41
- customFetch: this.customFetch,
42
- }).then((response) => response.data.map((workspace) => entities_1.WorkspaceSchema.parse(workspace)));
43
- }
44
- /**
45
- * Gets a single workspace object by id.
46
- *
47
- * @param id - The workspace ID.
48
- * @returns The workspace object.
49
- *
50
- * @example
51
- * ```typescript
52
- * const workspace = await api.workspaces.getWorkspace(123)
53
- * console.log(workspace.name)
54
- * ```
55
- */
56
- getWorkspace(id) {
57
- return (0, http_client_1.request)({
58
- httpMethod: 'GET',
59
- baseUri: this.getBaseUri(),
60
- relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/getone`,
61
- apiToken: this.apiToken,
62
- payload: { id },
63
- customFetch: this.customFetch,
64
- }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
65
- }
66
- /**
67
- * Gets the user's default workspace.
68
- *
69
- * @returns The default workspace object.
70
- *
71
- * @example
72
- * ```typescript
73
- * const workspace = await api.workspaces.getDefaultWorkspace()
74
- * console.log(workspace.name)
75
- * ```
76
- */
77
- getDefaultWorkspace() {
78
- return (0, http_client_1.request)({
79
- httpMethod: 'GET',
80
- baseUri: this.getBaseUri(),
81
- relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get_default`,
82
- apiToken: this.apiToken,
83
- payload: undefined,
84
- customFetch: this.customFetch,
85
- }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
86
- }
87
- /**
88
- * Creates a new workspace.
89
- *
90
- * @param name - The name of the new workspace.
91
- * @returns The created workspace object.
92
- *
93
- * @example
94
- * ```typescript
95
- * const workspace = await api.workspaces.createWorkspace('My Team')
96
- * console.log('Created:', workspace.name)
97
- * ```
98
- */
99
- createWorkspace(name) {
100
- return (0, http_client_1.request)({
101
- httpMethod: 'POST',
102
- baseUri: this.getBaseUri(),
103
- relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/add`,
104
- apiToken: this.apiToken,
105
- payload: { name },
106
- customFetch: this.customFetch,
107
- }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
108
- }
109
- /**
110
- * Updates an existing workspace.
111
- *
112
- * @param id - The workspace ID.
113
- * @param name - The new name for the workspace.
114
- * @returns The updated workspace object.
115
- *
116
- * @example
117
- * ```typescript
118
- * const workspace = await api.workspaces.updateWorkspace(123, 'New Team Name')
119
- * ```
120
- */
121
- updateWorkspace(id, name) {
122
- return (0, http_client_1.request)({
123
- httpMethod: 'POST',
124
- baseUri: this.getBaseUri(),
125
- relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/update`,
126
- apiToken: this.apiToken,
127
- payload: { id, name },
128
- customFetch: this.customFetch,
129
- }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
130
- }
131
- /**
132
- * Removes a workspace and all its data (not recoverable).
133
- *
134
- * @param id - The workspace ID.
135
- *
136
- * @example
137
- * ```typescript
138
- * await api.workspaces.removeWorkspace(123)
139
- * ```
140
- */
141
- removeWorkspace(id) {
142
- return (0, http_client_1.request)({
143
- httpMethod: 'POST',
144
- baseUri: this.getBaseUri(),
145
- relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/remove`,
146
- apiToken: this.apiToken,
147
- payload: { id },
148
- customFetch: this.customFetch,
149
- }).then(() => undefined);
150
- }
151
- /**
152
- * Gets the public channels of a workspace.
153
- *
154
- * @param id - The workspace ID.
155
- * @returns An array of public channel objects.
156
- *
157
- * @example
158
- * ```typescript
159
- * const channels = await api.workspaces.getPublicChannels(123)
160
- * channels.forEach(ch => console.log(ch.name))
161
- * ```
162
- */
163
- getPublicChannels(id) {
164
- return (0, http_client_1.request)({
165
- httpMethod: 'GET',
166
- baseUri: this.getBaseUri(),
167
- relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get_public_channels`,
168
- apiToken: this.apiToken,
169
- payload: { id },
170
- customFetch: this.customFetch,
171
- }).then((response) => this.channelListSchema.parse(response.data));
172
- }
173
- }
174
- exports.WorkspacesClient = WorkspacesClient;
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommsApi = void 0;
4
- const attachments_client_1 = require("./clients/attachments-client");
5
- const channels_client_1 = require("./clients/channels-client");
6
- const comments_client_1 = require("./clients/comments-client");
7
- const conversation_messages_client_1 = require("./clients/conversation-messages-client");
8
- const conversations_client_1 = require("./clients/conversations-client");
9
- const groups_client_1 = require("./clients/groups-client");
10
- const hooks_client_1 = require("./clients/hooks-client");
11
- const inbox_client_1 = require("./clients/inbox-client");
12
- const reactions_client_1 = require("./clients/reactions-client");
13
- const search_client_1 = require("./clients/search-client");
14
- const threads_client_1 = require("./clients/threads-client");
15
- const users_client_1 = require("./clients/users-client");
16
- const workspace_users_client_1 = require("./clients/workspace-users-client");
17
- const workspaces_client_1 = require("./clients/workspaces-client");
18
- const http_dispatcher_1 = require("./transport/http-dispatcher");
19
- /**
20
- * The main API client for interacting with the Comms REST API.
21
- *
22
- * @example
23
- * ```typescript
24
- * import { CommsApi } from '@doist/comms-sdk'
25
- *
26
- * const api = new CommsApi('your-api-token')
27
- * const user = await api.users.getSessionUser()
28
- * ```
29
- */
30
- class CommsApi {
31
- /**
32
- * Creates a new Comms API client.
33
- *
34
- * @param authToken - Your Comms API token.
35
- * @param options - Optional configuration options.
36
- */
37
- constructor(authToken, options) {
38
- const clientConfig = {
39
- apiToken: authToken,
40
- baseUrl: options?.baseUrl,
41
- version: options?.version,
42
- customFetch: options?.customFetch,
43
- };
44
- this.users = new users_client_1.UsersClient(clientConfig);
45
- this.workspaces = new workspaces_client_1.WorkspacesClient(clientConfig);
46
- this.workspaceUsers = new workspace_users_client_1.WorkspaceUsersClient(clientConfig);
47
- this.channels = new channels_client_1.ChannelsClient(clientConfig);
48
- this.threads = new threads_client_1.ThreadsClient(clientConfig);
49
- this.groups = new groups_client_1.GroupsClient(clientConfig);
50
- this.conversations = new conversations_client_1.ConversationsClient(clientConfig);
51
- this.comments = new comments_client_1.CommentsClient(clientConfig);
52
- this.conversationMessages = new conversation_messages_client_1.ConversationMessagesClient(clientConfig);
53
- this.inbox = new inbox_client_1.InboxClient(clientConfig);
54
- this.reactions = new reactions_client_1.ReactionsClient(clientConfig);
55
- this.search = new search_client_1.SearchClient(clientConfig);
56
- this.attachments = new attachments_client_1.AttachmentsClient(clientConfig);
57
- this.hooks = new hooks_client_1.HooksClient(clientConfig);
58
- }
59
- /**
60
- * Drains the SDK's process-global connection pool. CLIs and scripts
61
- * should `await api.close()` before exit so Node's event loop empties
62
- * immediately instead of waiting ~4s on keep-alive. Affects every
63
- * `CommsApi` and OAuth helper in the same process — it's a
64
- * process-shutdown gesture, not an instance teardown. Browser-safe.
65
- */
66
- async close() {
67
- await (0, http_dispatcher_1.closeDefaultDispatcher)();
68
- }
69
- }
70
- exports.CommsApi = CommsApi;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENDPOINT_HOOKS = exports.ENDPOINT_ATTACHMENTS = exports.ENDPOINT_CONVERSATION_MESSAGES = exports.ENDPOINT_SEARCH = exports.ENDPOINT_REACTIONS = exports.ENDPOINT_INBOX = exports.ENDPOINT_NOTIFICATIONS = exports.ENDPOINT_COMMENTS = exports.ENDPOINT_CONVERSATIONS = exports.ENDPOINT_GROUPS = exports.ENDPOINT_THREADS = exports.ENDPOINT_CHANNELS = exports.ENDPOINT_WORKSPACES = exports.ENDPOINT_USERS = void 0;
4
- exports.getCommsBaseUri = getCommsBaseUri;
5
- const api_version_1 = require("../types/api-version");
6
- const BASE_URI = 'https://comms.todoist.com';
7
- /**
8
- * Gets the base URI for Comms API requests.
9
- *
10
- * Preserves any path component on `domainBase` so callers can route through
11
- * a proxy (e.g. `https://proxy.example.com/comms` → `.../comms/api/v1/`).
12
- *
13
- * @param version - API version. Defaults to 'v1'.
14
- * @param domainBase - Custom domain base URL. Defaults to Comms' API domain.
15
- * @returns Complete base URI with trailing slash (e.g., 'https://comms.todoist.com/api/v1/')
16
- */
17
- function getCommsBaseUri(version = api_version_1.DEFAULT_API_VERSION, domainBase = BASE_URI) {
18
- const base = domainBase.endsWith('/') ? domainBase : `${domainBase}/`;
19
- return new URL(`api/${version}/`, base).toString();
20
- }
21
- exports.ENDPOINT_USERS = 'users';
22
- exports.ENDPOINT_WORKSPACES = 'workspaces';
23
- exports.ENDPOINT_CHANNELS = 'channels';
24
- exports.ENDPOINT_THREADS = 'threads';
25
- exports.ENDPOINT_GROUPS = 'groups';
26
- exports.ENDPOINT_CONVERSATIONS = 'conversations';
27
- exports.ENDPOINT_COMMENTS = 'comments';
28
- exports.ENDPOINT_NOTIFICATIONS = 'notifications';
29
- exports.ENDPOINT_INBOX = 'inbox';
30
- exports.ENDPOINT_REACTIONS = 'reactions';
31
- exports.ENDPOINT_SEARCH = 'search';
32
- exports.ENDPOINT_CONVERSATION_MESSAGES = 'conversation_messages';
33
- exports.ENDPOINT_ATTACHMENTS = 'attachments';
34
- exports.ENDPOINT_HOOKS = 'hooks';
package/dist/cjs/index.js DELETED
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.closeDefaultDispatcher = exports.CommsApi = exports.WorkspacesClient = exports.WorkspaceUsersClient = exports.UsersClient = exports.ThreadsClient = exports.SearchClient = exports.ReactionsClient = exports.InboxClient = exports.HooksClient = exports.GroupsClient = exports.ConversationsClient = exports.ConversationMessagesClient = exports.CommentsClient = exports.ChannelsClient = exports.AttachmentsClient = void 0;
18
- __exportStar(require("./authentication"), exports);
19
- __exportStar(require("./migration"), exports);
20
- var attachments_client_1 = require("./clients/attachments-client");
21
- Object.defineProperty(exports, "AttachmentsClient", { enumerable: true, get: function () { return attachments_client_1.AttachmentsClient; } });
22
- var channels_client_1 = require("./clients/channels-client");
23
- Object.defineProperty(exports, "ChannelsClient", { enumerable: true, get: function () { return channels_client_1.ChannelsClient; } });
24
- var comments_client_1 = require("./clients/comments-client");
25
- Object.defineProperty(exports, "CommentsClient", { enumerable: true, get: function () { return comments_client_1.CommentsClient; } });
26
- var conversation_messages_client_1 = require("./clients/conversation-messages-client");
27
- Object.defineProperty(exports, "ConversationMessagesClient", { enumerable: true, get: function () { return conversation_messages_client_1.ConversationMessagesClient; } });
28
- var conversations_client_1 = require("./clients/conversations-client");
29
- Object.defineProperty(exports, "ConversationsClient", { enumerable: true, get: function () { return conversations_client_1.ConversationsClient; } });
30
- var groups_client_1 = require("./clients/groups-client");
31
- Object.defineProperty(exports, "GroupsClient", { enumerable: true, get: function () { return groups_client_1.GroupsClient; } });
32
- var hooks_client_1 = require("./clients/hooks-client");
33
- Object.defineProperty(exports, "HooksClient", { enumerable: true, get: function () { return hooks_client_1.HooksClient; } });
34
- var inbox_client_1 = require("./clients/inbox-client");
35
- Object.defineProperty(exports, "InboxClient", { enumerable: true, get: function () { return inbox_client_1.InboxClient; } });
36
- var reactions_client_1 = require("./clients/reactions-client");
37
- Object.defineProperty(exports, "ReactionsClient", { enumerable: true, get: function () { return reactions_client_1.ReactionsClient; } });
38
- var search_client_1 = require("./clients/search-client");
39
- Object.defineProperty(exports, "SearchClient", { enumerable: true, get: function () { return search_client_1.SearchClient; } });
40
- var threads_client_1 = require("./clients/threads-client");
41
- Object.defineProperty(exports, "ThreadsClient", { enumerable: true, get: function () { return threads_client_1.ThreadsClient; } });
42
- var users_client_1 = require("./clients/users-client");
43
- Object.defineProperty(exports, "UsersClient", { enumerable: true, get: function () { return users_client_1.UsersClient; } });
44
- var workspace_users_client_1 = require("./clients/workspace-users-client");
45
- Object.defineProperty(exports, "WorkspaceUsersClient", { enumerable: true, get: function () { return workspace_users_client_1.WorkspaceUsersClient; } });
46
- var workspaces_client_1 = require("./clients/workspaces-client");
47
- Object.defineProperty(exports, "WorkspacesClient", { enumerable: true, get: function () { return workspaces_client_1.WorkspacesClient; } });
48
- var comms_api_1 = require("./comms-api");
49
- Object.defineProperty(exports, "CommsApi", { enumerable: true, get: function () { return comms_api_1.CommsApi; } });
50
- var http_dispatcher_1 = require("./transport/http-dispatcher");
51
- Object.defineProperty(exports, "closeDefaultDispatcher", { enumerable: true, get: function () { return http_dispatcher_1.closeDefaultDispatcher; } });
52
- __exportStar(require("./types/index"), exports);
53
- __exportStar(require("./utils/index"), exports);
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fetchNewCommsUrl = fetchNewCommsUrl;
4
- exports.fetchNewCommsUrls = fetchNewCommsUrls;
5
- const http_client_1 = require("./transport/http-client");
6
- const errors_1 = require("./types/errors");
7
- /**
8
- * Default origin of the Twist migration backend.
9
- *
10
- * The `fetch_new_url` endpoint lives on Twist (`twist.com`) and authenticates
11
- * with a **Twist** token, not a Comms one. This is why the migration helpers are
12
- * standalone functions rather than methods on {@link CommsApi} (which is
13
- * constructed with a Comms token).
14
- */
15
- const DEFAULT_TWIST_BASE_URL = 'https://twist.com';
16
- function getTwistMigrationUrl(baseUrl) {
17
- const base = baseUrl ?? DEFAULT_TWIST_BASE_URL;
18
- const trimmed = base.endsWith('/') ? base.slice(0, -1) : base;
19
- return `${trimmed}/api/comms_migration/fetch_new_url`;
20
- }
21
- /**
22
- * Translates a Twist URL to its equivalent Comms URL using Twist's
23
- * `comms_migration/fetch_new_url` endpoint.
24
- *
25
- * Authenticates with a **Twist** token (external to the Comms SDK), so this is a
26
- * standalone helper rather than a method on {@link CommsApi}.
27
- *
28
- * @example
29
- * ```typescript
30
- * const newUrl = await fetchNewCommsUrl({
31
- * oldUrl: 'https://twist.com/a/123/ch/456/t/789',
32
- * twistToken: process.env.TWIST_AUTH_TOKEN,
33
- * })
34
- * ```
35
- *
36
- * @returns The equivalent Comms URL.
37
- * @throws {@link CommsRequestError} If the request fails. URLs that cannot be
38
- * migrated surface as a thrown error too: `400` with `responseData.error.code`
39
- * of `'invalid_url'`, or `404` with `'not_imported'`.
40
- */
41
- async function fetchNewCommsUrl(args, options) {
42
- const response = await (0, http_client_1.request)({
43
- httpMethod: 'POST',
44
- baseUri: getTwistMigrationUrl(options?.baseUrl),
45
- relativePath: '',
46
- apiToken: args.twistToken,
47
- payload: { oldUrl: args.oldUrl },
48
- customFetch: options?.customFetch,
49
- });
50
- const newUrl = response.data?.newUrl;
51
- if (!newUrl) {
52
- throw new errors_1.CommsRequestError('Migration response did not contain a new URL.', response.status, response.data);
53
- }
54
- return newUrl;
55
- }
56
- /**
57
- * Translates multiple Twist URLs to their equivalent Comms URLs.
58
- *
59
- * URLs are processed **sequentially** to stay friendly to the rate-sensitive
60
- * migration endpoint. A failure on one URL does not abort the run: each result
61
- * carries either a `newUrl` (success) or a `CommsRequestError` (failure), in the
62
- * same order as the input.
63
- *
64
- * @example
65
- * ```typescript
66
- * const results = await fetchNewCommsUrls({
67
- * oldUrls: ['https://twist.com/a/1/ch/2/t/3', 'https://twist.com/bad'],
68
- * twistToken: process.env.TWIST_AUTH_TOKEN,
69
- * })
70
- * for (const result of results) {
71
- * if (result.newUrl) console.log(`${result.oldUrl} -> ${result.newUrl}`)
72
- * else console.warn(`${result.oldUrl} failed`, result.error)
73
- * }
74
- * ```
75
- *
76
- * @returns One {@link MigrationResult} per input URL, in input order.
77
- * @throws Re-throws any error that is not a {@link CommsRequestError}.
78
- */
79
- async function fetchNewCommsUrls(args, options) {
80
- const results = [];
81
- for (const oldUrl of args.oldUrls) {
82
- try {
83
- const newUrl = await fetchNewCommsUrl({ oldUrl, twistToken: args.twistToken }, options);
84
- results.push({ oldUrl, newUrl });
85
- }
86
- catch (error) {
87
- if (error instanceof errors_1.CommsRequestError) {
88
- results.push({ oldUrl, error });
89
- }
90
- else {
91
- throw error;
92
- }
93
- }
94
- }
95
- return results;
96
- }
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpResponse = exports.http = void 0;
4
- exports.createSuccessResponse = createSuccessResponse;
5
- exports.createErrorResponse = createErrorResponse;
6
- exports.apiUrl = apiUrl;
7
- exports.createGetHandler = createGetHandler;
8
- exports.createPostHandler = createPostHandler;
9
- const msw_1 = require("msw");
10
- Object.defineProperty(exports, "HttpResponse", { enumerable: true, get: function () { return msw_1.HttpResponse; } });
11
- Object.defineProperty(exports, "http", { enumerable: true, get: function () { return msw_1.http; } });
12
- const BASE_URL = 'https://comms.todoist.com';
13
- /**
14
- * Creates a successful API response with the given data
15
- */
16
- function createSuccessResponse(data) {
17
- return msw_1.HttpResponse.json(data, { status: 200 });
18
- }
19
- /**
20
- * Creates an error API response
21
- */
22
- function createErrorResponse(errorCode, errorMessage, status = 400) {
23
- return msw_1.HttpResponse.json({
24
- error_code: errorCode,
25
- error_string: errorMessage,
26
- }, { status });
27
- }
28
- /**
29
- * Helper to create API endpoint URL
30
- */
31
- function apiUrl(path) {
32
- // Remove leading slash if present
33
- const cleanPath = path.startsWith('/') ? path.slice(1) : path;
34
- return `${BASE_URL}/${cleanPath}`;
35
- }
36
- /**
37
- * Creates a handler for a GET endpoint
38
- */
39
- function createGetHandler(endpoint, responseData) {
40
- return msw_1.http.get(apiUrl(endpoint), () => {
41
- return createSuccessResponse(responseData);
42
- });
43
- }
44
- /**
45
- * Creates a handler for a POST endpoint
46
- */
47
- function createPostHandler(endpoint, responseData) {
48
- return msw_1.http.post(apiUrl(endpoint), () => {
49
- return createSuccessResponse(responseData);
50
- });
51
- }
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.server = void 0;
4
- const node_1 = require("msw/node");
5
- const vitest_1 = require("vitest");
6
- // In production the transport uses undici's own `fetch` (paired with the
7
- // dispatcher) so the request client and dispatcher stay on one undici version.
8
- // MSW intercepts the *global* `fetch`, not that separate undici instance, so
9
- // force the transport onto the global `fetch` for every test in the suite;
10
- // MSW then intercepts requests as usual. The real undici transport is covered
11
- // directly by `http-dispatcher.test.ts` and `fetch-with-retry.test.ts`, which
12
- // opt out of this seam.
13
- vitest_1.vi.mock('../transport/http-dispatcher', async (importOriginal) => {
14
- const actual = await importOriginal();
15
- return {
16
- ...actual,
17
- getDefaultTransport: vitest_1.vi.fn(async () => undefined),
18
- };
19
- });
20
- // Create MSW server instance
21
- exports.server = (0, node_1.setupServer)();
22
- // Start server before all tests
23
- (0, vitest_1.beforeAll)(() => {
24
- // Only warn on unhandled requests instead of error, since transport/http-client.test.ts
25
- // uses direct fetch mocking which bypasses MSW
26
- exports.server.listen({ onUnhandledRequest: 'warn' });
27
- });
28
- // Reset handlers after each test
29
- (0, vitest_1.afterEach)(() => {
30
- exports.server.resetHandlers();
31
- });
32
- // Clean up after all tests
33
- (0, vitest_1.afterAll)(() => {
34
- exports.server.close();
35
- });
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createObsidianFetchAdapter = createObsidianFetchAdapter;
4
- /**
5
- * Creates a CustomFetch adapter for Obsidian's requestUrl API.
6
- *
7
- * This adapter bridges the gap between Obsidian's requestUrl interface and the
8
- * standard fetch-like interface expected by the Comms API SDK.
9
- *
10
- * Key differences handled by this adapter:
11
- * - Obsidian returns response data as properties (response.json, response.text)
12
- * while the SDK expects methods (response.json(), response.text())
13
- * - Obsidian's requestUrl bypasses CORS restrictions that would block standard fetch
14
- * - Obsidian throws on HTTP errors by default; we set throw: false to handle manually
15
- * - Obsidian doesn't provide statusText; we default to empty string
16
- *
17
- * @example
18
- * ```typescript
19
- * import { requestUrl } from 'obsidian'
20
- * import { createObsidianFetchAdapter } from './obsidian-fetch-adapter'
21
- *
22
- * const api = new CommsApi('your-token', {
23
- * customFetch: createObsidianFetchAdapter(requestUrl)
24
- * })
25
- * ```
26
- *
27
- * @param requestUrl - The Obsidian requestUrl function
28
- * @returns A CustomFetch function compatible with the Comms API SDK
29
- */
30
- function createObsidianFetchAdapter(requestUrl) {
31
- return async (url, options) => {
32
- // Build the request parameters in Obsidian's format
33
- const requestParams = {
34
- url,
35
- method: options?.method || 'GET',
36
- headers: options?.headers,
37
- body: options?.body,
38
- throw: false, // Don't throw on HTTP errors; let the SDK handle status codes
39
- };
40
- // Make the request using Obsidian's requestUrl
41
- const response = await requestUrl(requestParams);
42
- // Transform Obsidian's response format to match CustomFetchResponse interface
43
- return {
44
- ok: response.status >= 200 && response.status < 300,
45
- status: response.status,
46
- statusText: '', // Obsidian doesn't provide statusText
47
- headers: response.headers,
48
- // Wrap Obsidian's direct properties as methods returning promises
49
- text: () => Promise.resolve(response.text),
50
- json: () => Promise.resolve(response.json),
51
- };
52
- };
53
- }