@doist/comms-sdk 0.0.1 → 0.2.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 (115) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -45
  3. package/dist/cjs/authentication.js +211 -0
  4. package/dist/cjs/clients/add-comment-helper.js +70 -0
  5. package/dist/cjs/clients/base-client.js +25 -0
  6. package/dist/cjs/clients/channels-client.js +200 -0
  7. package/dist/cjs/clients/comments-client.js +159 -0
  8. package/dist/cjs/clients/conversation-messages-client.js +158 -0
  9. package/dist/cjs/clients/conversations-client.js +243 -0
  10. package/dist/cjs/clients/groups-client.js +164 -0
  11. package/dist/cjs/clients/inbox-client.js +171 -0
  12. package/dist/cjs/clients/reactions-client.js +97 -0
  13. package/dist/cjs/clients/search-client.js +138 -0
  14. package/dist/cjs/clients/threads-client.js +330 -0
  15. package/dist/cjs/clients/users-client.js +326 -0
  16. package/dist/cjs/clients/workspace-users-client.js +240 -0
  17. package/dist/cjs/clients/workspaces-client.js +166 -0
  18. package/dist/cjs/comms-api.js +66 -0
  19. package/dist/cjs/consts/endpoints.js +32 -0
  20. package/dist/cjs/index.js +48 -0
  21. package/dist/cjs/package.json +1 -0
  22. package/dist/cjs/testUtils/msw-handlers.js +51 -0
  23. package/dist/cjs/testUtils/msw-setup.js +21 -0
  24. package/dist/cjs/testUtils/obsidian-fetch-adapter.js +53 -0
  25. package/dist/cjs/testUtils/test-defaults.js +104 -0
  26. package/dist/cjs/transport/fetch-with-retry.js +136 -0
  27. package/dist/cjs/transport/http-client.js +56 -0
  28. package/dist/cjs/transport/http-dispatcher.js +143 -0
  29. package/dist/cjs/types/api-version.js +8 -0
  30. package/dist/cjs/types/entities.js +411 -0
  31. package/dist/cjs/types/enums.js +37 -0
  32. package/dist/cjs/types/errors.js +12 -0
  33. package/dist/cjs/types/http.js +4 -0
  34. package/dist/cjs/types/index.js +22 -0
  35. package/dist/cjs/types/requests.js +116 -0
  36. package/dist/cjs/utils/case-conversion.js +54 -0
  37. package/dist/cjs/utils/index.js +19 -0
  38. package/dist/cjs/utils/timestamp-conversion.js +49 -0
  39. package/dist/cjs/utils/url-helpers.js +131 -0
  40. package/dist/cjs/utils/uuidv7.js +174 -0
  41. package/dist/esm/authentication.js +203 -0
  42. package/dist/esm/clients/add-comment-helper.js +67 -0
  43. package/dist/esm/clients/base-client.js +21 -0
  44. package/dist/esm/clients/channels-client.js +196 -0
  45. package/dist/esm/clients/comments-client.js +155 -0
  46. package/dist/esm/clients/conversation-messages-client.js +154 -0
  47. package/dist/esm/clients/conversations-client.js +239 -0
  48. package/dist/esm/clients/groups-client.js +160 -0
  49. package/dist/esm/clients/inbox-client.js +167 -0
  50. package/dist/esm/clients/reactions-client.js +93 -0
  51. package/dist/esm/clients/search-client.js +134 -0
  52. package/dist/esm/clients/threads-client.js +326 -0
  53. package/dist/esm/clients/users-client.js +322 -0
  54. package/dist/esm/clients/workspace-users-client.js +236 -0
  55. package/dist/esm/clients/workspaces-client.js +162 -0
  56. package/dist/esm/comms-api.js +62 -0
  57. package/dist/esm/consts/endpoints.js +28 -0
  58. package/dist/esm/index.js +17 -0
  59. package/dist/esm/testUtils/msw-handlers.js +45 -0
  60. package/dist/esm/testUtils/msw-setup.js +18 -0
  61. package/dist/esm/testUtils/obsidian-fetch-adapter.js +50 -0
  62. package/dist/esm/testUtils/test-defaults.js +101 -0
  63. package/dist/esm/transport/fetch-with-retry.js +133 -0
  64. package/dist/esm/transport/http-client.js +51 -0
  65. package/dist/esm/transport/http-dispatcher.js +104 -0
  66. package/dist/esm/types/api-version.js +5 -0
  67. package/dist/esm/types/entities.js +408 -0
  68. package/dist/esm/types/enums.js +34 -0
  69. package/dist/esm/types/errors.js +8 -0
  70. package/dist/esm/types/http.js +1 -0
  71. package/dist/esm/types/index.js +6 -0
  72. package/dist/esm/types/requests.js +113 -0
  73. package/dist/esm/utils/case-conversion.js +47 -0
  74. package/dist/esm/utils/index.js +3 -0
  75. package/dist/esm/utils/timestamp-conversion.js +45 -0
  76. package/dist/esm/utils/url-helpers.js +112 -0
  77. package/dist/esm/utils/uuidv7.js +163 -0
  78. package/dist/types/authentication.d.ts +160 -0
  79. package/dist/types/clients/add-comment-helper.d.ts +29 -0
  80. package/dist/types/clients/base-client.d.ts +28 -0
  81. package/dist/types/clients/channels-client.d.ts +208 -0
  82. package/dist/types/clients/comments-client.d.ts +224 -0
  83. package/dist/types/clients/conversation-messages-client.d.ts +198 -0
  84. package/dist/types/clients/conversations-client.d.ts +346 -0
  85. package/dist/types/clients/groups-client.d.ts +148 -0
  86. package/dist/types/clients/inbox-client.d.ts +96 -0
  87. package/dist/types/clients/reactions-client.d.ts +57 -0
  88. package/dist/types/clients/search-client.d.ts +70 -0
  89. package/dist/types/clients/threads-client.d.ts +536 -0
  90. package/dist/types/clients/users-client.d.ts +250 -0
  91. package/dist/types/clients/workspace-users-client.d.ts +147 -0
  92. package/dist/types/clients/workspaces-client.d.ts +152 -0
  93. package/dist/types/comms-api.d.ts +62 -0
  94. package/dist/types/consts/endpoints.d.ts +24 -0
  95. package/dist/types/index.d.ts +18 -0
  96. package/dist/types/testUtils/msw-handlers.d.ts +28 -0
  97. package/dist/types/testUtils/msw-setup.d.ts +1 -0
  98. package/dist/types/testUtils/obsidian-fetch-adapter.d.ts +29 -0
  99. package/dist/types/testUtils/test-defaults.d.ts +17 -0
  100. package/dist/types/transport/fetch-with-retry.d.ts +4 -0
  101. package/dist/types/transport/http-client.d.ts +13 -0
  102. package/dist/types/transport/http-dispatcher.d.ts +10 -0
  103. package/dist/types/types/api-version.d.ts +6 -0
  104. package/dist/types/types/entities.d.ts +1288 -0
  105. package/dist/types/types/enums.d.ts +55 -0
  106. package/dist/types/types/errors.d.ts +6 -0
  107. package/dist/types/types/http.d.ts +54 -0
  108. package/dist/types/types/index.d.ts +6 -0
  109. package/dist/types/types/requests.d.ts +366 -0
  110. package/dist/types/utils/case-conversion.d.ts +8 -0
  111. package/dist/types/utils/index.d.ts +3 -0
  112. package/dist/types/utils/timestamp-conversion.d.ts +13 -0
  113. package/dist/types/utils/url-helpers.d.ts +88 -0
  114. package/dist/types/utils/uuidv7.d.ts +40 -0
  115. package/package.json +91 -8
@@ -0,0 +1,166 @@
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
+ /**
16
+ * Gets all the user's workspaces.
17
+ *
18
+ * @returns An array of all workspaces the user belongs to.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const workspaces = await api.workspaces.getWorkspaces()
23
+ * workspaces.forEach(ws => console.log(ws.name))
24
+ * ```
25
+ */
26
+ getWorkspaces() {
27
+ return (0, http_client_1.request)({
28
+ httpMethod: 'GET',
29
+ baseUri: this.getBaseUri(),
30
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get`,
31
+ apiToken: this.apiToken,
32
+ payload: undefined,
33
+ customFetch: this.customFetch,
34
+ }).then((response) => response.data.map((workspace) => entities_1.WorkspaceSchema.parse(workspace)));
35
+ }
36
+ /**
37
+ * Gets a single workspace object by id.
38
+ *
39
+ * @param id - The workspace ID.
40
+ * @returns The workspace object.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const workspace = await api.workspaces.getWorkspace(123)
45
+ * console.log(workspace.name)
46
+ * ```
47
+ */
48
+ getWorkspace(id) {
49
+ return (0, http_client_1.request)({
50
+ httpMethod: 'GET',
51
+ baseUri: this.getBaseUri(),
52
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/getone`,
53
+ apiToken: this.apiToken,
54
+ payload: { id },
55
+ customFetch: this.customFetch,
56
+ }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
57
+ }
58
+ /**
59
+ * Gets the user's default workspace.
60
+ *
61
+ * @returns The default workspace object.
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const workspace = await api.workspaces.getDefaultWorkspace()
66
+ * console.log(workspace.name)
67
+ * ```
68
+ */
69
+ getDefaultWorkspace() {
70
+ return (0, http_client_1.request)({
71
+ httpMethod: 'GET',
72
+ baseUri: this.getBaseUri(),
73
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get_default`,
74
+ apiToken: this.apiToken,
75
+ payload: undefined,
76
+ customFetch: this.customFetch,
77
+ }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
78
+ }
79
+ /**
80
+ * Creates a new workspace.
81
+ *
82
+ * @param name - The name of the new workspace.
83
+ * @returns The created workspace object.
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const workspace = await api.workspaces.createWorkspace('My Team')
88
+ * console.log('Created:', workspace.name)
89
+ * ```
90
+ */
91
+ createWorkspace(name) {
92
+ return (0, http_client_1.request)({
93
+ httpMethod: 'POST',
94
+ baseUri: this.getBaseUri(),
95
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/add`,
96
+ apiToken: this.apiToken,
97
+ payload: { name },
98
+ customFetch: this.customFetch,
99
+ }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
100
+ }
101
+ /**
102
+ * Updates an existing workspace.
103
+ *
104
+ * @param id - The workspace ID.
105
+ * @param name - The new name for the workspace.
106
+ * @returns The updated workspace object.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const workspace = await api.workspaces.updateWorkspace(123, 'New Team Name')
111
+ * ```
112
+ */
113
+ updateWorkspace(id, name) {
114
+ return (0, http_client_1.request)({
115
+ httpMethod: 'POST',
116
+ baseUri: this.getBaseUri(),
117
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/update`,
118
+ apiToken: this.apiToken,
119
+ payload: { id, name },
120
+ customFetch: this.customFetch,
121
+ }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
122
+ }
123
+ /**
124
+ * Removes a workspace and all its data (not recoverable).
125
+ *
126
+ * @param id - The workspace ID.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * await api.workspaces.removeWorkspace(123)
131
+ * ```
132
+ */
133
+ removeWorkspace(id) {
134
+ return (0, http_client_1.request)({
135
+ httpMethod: 'POST',
136
+ baseUri: this.getBaseUri(),
137
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/remove`,
138
+ apiToken: this.apiToken,
139
+ payload: { id },
140
+ customFetch: this.customFetch,
141
+ }).then(() => undefined);
142
+ }
143
+ /**
144
+ * Gets the public channels of a workspace.
145
+ *
146
+ * @param id - The workspace ID.
147
+ * @returns An array of public channel objects.
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const channels = await api.workspaces.getPublicChannels(123)
152
+ * channels.forEach(ch => console.log(ch.name))
153
+ * ```
154
+ */
155
+ getPublicChannels(id) {
156
+ return (0, http_client_1.request)({
157
+ httpMethod: 'GET',
158
+ baseUri: this.getBaseUri(),
159
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get_public_channels`,
160
+ apiToken: this.apiToken,
161
+ payload: { id },
162
+ customFetch: this.customFetch,
163
+ }).then((response) => exports.ChannelListSchema.parse(response.data));
164
+ }
165
+ }
166
+ exports.WorkspacesClient = WorkspacesClient;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommsApi = void 0;
4
+ const channels_client_1 = require("./clients/channels-client");
5
+ const comments_client_1 = require("./clients/comments-client");
6
+ const conversation_messages_client_1 = require("./clients/conversation-messages-client");
7
+ const conversations_client_1 = require("./clients/conversations-client");
8
+ const groups_client_1 = require("./clients/groups-client");
9
+ const inbox_client_1 = require("./clients/inbox-client");
10
+ const reactions_client_1 = require("./clients/reactions-client");
11
+ const search_client_1 = require("./clients/search-client");
12
+ const threads_client_1 = require("./clients/threads-client");
13
+ const users_client_1 = require("./clients/users-client");
14
+ const workspace_users_client_1 = require("./clients/workspace-users-client");
15
+ const workspaces_client_1 = require("./clients/workspaces-client");
16
+ const http_dispatcher_1 = require("./transport/http-dispatcher");
17
+ /**
18
+ * The main API client for interacting with the Comms REST API.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * import { CommsApi } from '@doist/comms-sdk'
23
+ *
24
+ * const api = new CommsApi('your-api-token')
25
+ * const user = await api.users.getSessionUser()
26
+ * ```
27
+ */
28
+ class CommsApi {
29
+ /**
30
+ * Creates a new Comms API client.
31
+ *
32
+ * @param authToken - Your Comms API token.
33
+ * @param options - Optional configuration options.
34
+ */
35
+ constructor(authToken, options) {
36
+ const clientConfig = {
37
+ apiToken: authToken,
38
+ baseUrl: options?.baseUrl,
39
+ version: options?.version,
40
+ customFetch: options?.customFetch,
41
+ };
42
+ this.users = new users_client_1.UsersClient(clientConfig);
43
+ this.workspaces = new workspaces_client_1.WorkspacesClient(clientConfig);
44
+ this.workspaceUsers = new workspace_users_client_1.WorkspaceUsersClient(clientConfig);
45
+ this.channels = new channels_client_1.ChannelsClient(clientConfig);
46
+ this.threads = new threads_client_1.ThreadsClient(clientConfig);
47
+ this.groups = new groups_client_1.GroupsClient(clientConfig);
48
+ this.conversations = new conversations_client_1.ConversationsClient(clientConfig);
49
+ this.comments = new comments_client_1.CommentsClient(clientConfig);
50
+ this.conversationMessages = new conversation_messages_client_1.ConversationMessagesClient(clientConfig);
51
+ this.inbox = new inbox_client_1.InboxClient(clientConfig);
52
+ this.reactions = new reactions_client_1.ReactionsClient(clientConfig);
53
+ this.search = new search_client_1.SearchClient(clientConfig);
54
+ }
55
+ /**
56
+ * Drains the SDK's process-global connection pool. CLIs and scripts
57
+ * should `await api.close()` before exit so Node's event loop empties
58
+ * immediately instead of waiting ~4s on keep-alive. Affects every
59
+ * `CommsApi` and OAuth helper in the same process — it's a
60
+ * process-shutdown gesture, not an instance teardown. Browser-safe.
61
+ */
62
+ async close() {
63
+ await (0, http_dispatcher_1.closeDefaultDispatcher)();
64
+ }
65
+ }
66
+ exports.CommsApi = CommsApi;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ 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';
@@ -0,0 +1,48 @@
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.GroupsClient = exports.ConversationsClient = exports.ConversationMessagesClient = exports.CommentsClient = exports.ChannelsClient = void 0;
18
+ __exportStar(require("./authentication"), exports);
19
+ var channels_client_1 = require("./clients/channels-client");
20
+ Object.defineProperty(exports, "ChannelsClient", { enumerable: true, get: function () { return channels_client_1.ChannelsClient; } });
21
+ var comments_client_1 = require("./clients/comments-client");
22
+ Object.defineProperty(exports, "CommentsClient", { enumerable: true, get: function () { return comments_client_1.CommentsClient; } });
23
+ var conversation_messages_client_1 = require("./clients/conversation-messages-client");
24
+ Object.defineProperty(exports, "ConversationMessagesClient", { enumerable: true, get: function () { return conversation_messages_client_1.ConversationMessagesClient; } });
25
+ var conversations_client_1 = require("./clients/conversations-client");
26
+ Object.defineProperty(exports, "ConversationsClient", { enumerable: true, get: function () { return conversations_client_1.ConversationsClient; } });
27
+ var groups_client_1 = require("./clients/groups-client");
28
+ Object.defineProperty(exports, "GroupsClient", { enumerable: true, get: function () { return groups_client_1.GroupsClient; } });
29
+ var inbox_client_1 = require("./clients/inbox-client");
30
+ Object.defineProperty(exports, "InboxClient", { enumerable: true, get: function () { return inbox_client_1.InboxClient; } });
31
+ var reactions_client_1 = require("./clients/reactions-client");
32
+ Object.defineProperty(exports, "ReactionsClient", { enumerable: true, get: function () { return reactions_client_1.ReactionsClient; } });
33
+ var search_client_1 = require("./clients/search-client");
34
+ Object.defineProperty(exports, "SearchClient", { enumerable: true, get: function () { return search_client_1.SearchClient; } });
35
+ var threads_client_1 = require("./clients/threads-client");
36
+ Object.defineProperty(exports, "ThreadsClient", { enumerable: true, get: function () { return threads_client_1.ThreadsClient; } });
37
+ var users_client_1 = require("./clients/users-client");
38
+ Object.defineProperty(exports, "UsersClient", { enumerable: true, get: function () { return users_client_1.UsersClient; } });
39
+ var workspace_users_client_1 = require("./clients/workspace-users-client");
40
+ Object.defineProperty(exports, "WorkspaceUsersClient", { enumerable: true, get: function () { return workspace_users_client_1.WorkspaceUsersClient; } });
41
+ var workspaces_client_1 = require("./clients/workspaces-client");
42
+ Object.defineProperty(exports, "WorkspacesClient", { enumerable: true, get: function () { return workspaces_client_1.WorkspacesClient; } });
43
+ var comms_api_1 = require("./comms-api");
44
+ Object.defineProperty(exports, "CommsApi", { enumerable: true, get: function () { return comms_api_1.CommsApi; } });
45
+ var http_dispatcher_1 = require("./transport/http-dispatcher");
46
+ Object.defineProperty(exports, "closeDefaultDispatcher", { enumerable: true, get: function () { return http_dispatcher_1.closeDefaultDispatcher; } });
47
+ __exportStar(require("./types/index"), exports);
48
+ __exportStar(require("./utils/index"), exports);
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,51 @@
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
+ }
@@ -0,0 +1,21 @@
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
+ // Create MSW server instance
7
+ exports.server = (0, node_1.setupServer)();
8
+ // Start server before all tests
9
+ (0, vitest_1.beforeAll)(() => {
10
+ // Only warn on unhandled requests instead of error, since transport/http-client.test.ts
11
+ // uses direct fetch mocking which bypasses MSW
12
+ exports.server.listen({ onUnhandledRequest: 'warn' });
13
+ });
14
+ // Reset handlers after each test
15
+ (0, vitest_1.afterEach)(() => {
16
+ exports.server.resetHandlers();
17
+ });
18
+ // Clean up after all tests
19
+ (0, vitest_1.afterAll)(() => {
20
+ exports.server.close();
21
+ });
@@ -0,0 +1,53 @@
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
+ }
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mockWorkspaceUser = exports.mockComment = exports.mockConversation = exports.mockGroup = exports.mockThread = exports.mockChannel = exports.mockWorkspace = exports.mockUser = exports.TEST_GROUP_ID = exports.TEST_MESSAGE_ID = exports.TEST_CONVERSATION_ID = exports.TEST_COMMENT_ID = exports.TEST_THREAD_ID = exports.TEST_CHANNEL_ID = exports.TEST_API_BASE_URL = exports.TEST_API_TOKEN = void 0;
4
+ const endpoints_1 = require("../consts/endpoints");
5
+ exports.TEST_API_TOKEN = 'test-api-token';
6
+ exports.TEST_API_BASE_URL = (0, endpoints_1.getCommsBaseUri)().replace(/\/$/, '');
7
+ // Canonical test IDs — shaped so they pass SDK-side validation.
8
+ exports.TEST_CHANNEL_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3y';
9
+ exports.TEST_THREAD_ID = '7YpL3oZ4kZ9vP7Q1tR2sX3z';
10
+ exports.TEST_COMMENT_ID = '7YpL3oZ4kZ9vP7Q1tR2sX41';
11
+ exports.TEST_CONVERSATION_ID = '7YpL3oZ4kZ9vP7Q1tR2sX42';
12
+ exports.TEST_MESSAGE_ID = '7YpL3oZ4kZ9vP7Q1tR2sX43';
13
+ exports.TEST_GROUP_ID = '7YpL3oZ4kZ9vP7Q1tR2sX44';
14
+ exports.mockUser = {
15
+ id: 1,
16
+ email: 'test@example.com',
17
+ fullName: 'Test User',
18
+ shortName: 'TU',
19
+ timezone: 'America/New_York',
20
+ removed: false,
21
+ lang: 'en',
22
+ };
23
+ exports.mockWorkspace = {
24
+ id: 1,
25
+ name: 'Test Workspace',
26
+ creator: 1,
27
+ created: new Date('2021-01-01T00:00:00Z'),
28
+ };
29
+ exports.mockChannel = {
30
+ id: exports.TEST_CHANNEL_ID,
31
+ name: 'general',
32
+ creator: 1,
33
+ public: true,
34
+ workspaceId: 1,
35
+ archived: false,
36
+ created: new Date('2021-01-01T00:00:00Z'),
37
+ version: 0,
38
+ url: `https://comms.todoist.com/a/1/ch/${exports.TEST_CHANNEL_ID}/`,
39
+ };
40
+ exports.mockThread = {
41
+ id: exports.TEST_THREAD_ID,
42
+ title: 'Test Thread',
43
+ content: 'This is a test thread',
44
+ creator: 1,
45
+ channelId: exports.TEST_CHANNEL_ID,
46
+ workspaceId: 1,
47
+ commentCount: 0,
48
+ lastUpdated: new Date('2021-01-01T00:00:00Z'),
49
+ pinned: false,
50
+ posted: new Date('2021-01-01T00:00:00Z'),
51
+ snippet: 'This is a test thread',
52
+ snippetCreator: 1,
53
+ isArchived: false,
54
+ url: `https://comms.todoist.com/a/1/ch/${exports.TEST_CHANNEL_ID}/t/${exports.TEST_THREAD_ID}/`,
55
+ };
56
+ exports.mockGroup = {
57
+ id: exports.TEST_GROUP_ID,
58
+ name: 'Test Group',
59
+ workspaceId: 1,
60
+ userIds: [1, 2, 3],
61
+ version: 0,
62
+ };
63
+ exports.mockConversation = {
64
+ id: exports.TEST_CONVERSATION_ID,
65
+ workspaceId: 1,
66
+ userIds: [1, 2],
67
+ messageCount: 1,
68
+ lastObjIndex: 0,
69
+ snippet: 'Hello there',
70
+ snippetCreators: [1],
71
+ lastActive: new Date('2021-01-01T00:00:00Z'),
72
+ archived: false,
73
+ created: new Date('2021-01-01T00:00:00Z'),
74
+ creator: 1,
75
+ url: `https://comms.todoist.com/a/1/msg/${exports.TEST_CONVERSATION_ID}/`,
76
+ };
77
+ exports.mockComment = {
78
+ id: exports.TEST_COMMENT_ID,
79
+ content: 'This is a comment',
80
+ creator: 1,
81
+ threadId: exports.TEST_THREAD_ID,
82
+ workspaceId: 1,
83
+ channelId: exports.TEST_CHANNEL_ID,
84
+ posted: new Date('2021-01-01T00:00:00Z'),
85
+ url: `https://comms.todoist.com/a/1/ch/${exports.TEST_CHANNEL_ID}/t/${exports.TEST_THREAD_ID}/c/${exports.TEST_COMMENT_ID}`,
86
+ };
87
+ exports.mockWorkspaceUser = {
88
+ id: 1,
89
+ fullName: 'Test User',
90
+ email: 'test@example.com',
91
+ userType: 'USER',
92
+ shortName: 'TU',
93
+ firstName: 'Test',
94
+ imageId: null,
95
+ avatarUrls: null,
96
+ dateFormat: null,
97
+ removed: false,
98
+ restricted: null,
99
+ setupPending: null,
100
+ theme: null,
101
+ timeFormat: null,
102
+ timezone: 'America/New_York',
103
+ version: 1,
104
+ };