@doist/comms-sdk 0.1.0-alpha.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 (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +143 -0
  3. package/dist/cjs/authentication.js +211 -0
  4. package/dist/cjs/clients/add-comment-helper.js +53 -0
  5. package/dist/cjs/clients/base-client.js +27 -0
  6. package/dist/cjs/clients/channels-client.js +83 -0
  7. package/dist/cjs/clients/comments-client.js +93 -0
  8. package/dist/cjs/clients/conversation-messages-client.js +87 -0
  9. package/dist/cjs/clients/conversations-client.js +103 -0
  10. package/dist/cjs/clients/groups-client.js +71 -0
  11. package/dist/cjs/clients/inbox-client.js +98 -0
  12. package/dist/cjs/clients/reactions-client.js +59 -0
  13. package/dist/cjs/clients/search-client.js +88 -0
  14. package/dist/cjs/clients/threads-client.js +135 -0
  15. package/dist/cjs/clients/users-client.js +199 -0
  16. package/dist/cjs/clients/workspace-users-client.js +140 -0
  17. package/dist/cjs/clients/workspaces-client.js +93 -0
  18. package/dist/cjs/comms-api.js +65 -0
  19. package/dist/cjs/consts/endpoints.js +27 -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 +102 -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/entities.js +411 -0
  30. package/dist/cjs/types/enums.js +37 -0
  31. package/dist/cjs/types/errors.js +12 -0
  32. package/dist/cjs/types/http.js +4 -0
  33. package/dist/cjs/types/index.js +21 -0
  34. package/dist/cjs/types/requests.js +117 -0
  35. package/dist/cjs/utils/case-conversion.js +54 -0
  36. package/dist/cjs/utils/index.js +19 -0
  37. package/dist/cjs/utils/timestamp-conversion.js +49 -0
  38. package/dist/cjs/utils/url-helpers.js +131 -0
  39. package/dist/cjs/utils/uuidv7.js +174 -0
  40. package/dist/esm/authentication.js +203 -0
  41. package/dist/esm/clients/add-comment-helper.js +50 -0
  42. package/dist/esm/clients/base-client.js +23 -0
  43. package/dist/esm/clients/channels-client.js +79 -0
  44. package/dist/esm/clients/comments-client.js +89 -0
  45. package/dist/esm/clients/conversation-messages-client.js +83 -0
  46. package/dist/esm/clients/conversations-client.js +99 -0
  47. package/dist/esm/clients/groups-client.js +67 -0
  48. package/dist/esm/clients/inbox-client.js +94 -0
  49. package/dist/esm/clients/reactions-client.js +55 -0
  50. package/dist/esm/clients/search-client.js +84 -0
  51. package/dist/esm/clients/threads-client.js +131 -0
  52. package/dist/esm/clients/users-client.js +195 -0
  53. package/dist/esm/clients/workspace-users-client.js +136 -0
  54. package/dist/esm/clients/workspaces-client.js +89 -0
  55. package/dist/esm/comms-api.js +61 -0
  56. package/dist/esm/consts/endpoints.js +23 -0
  57. package/dist/esm/index.js +17 -0
  58. package/dist/esm/testUtils/msw-handlers.js +45 -0
  59. package/dist/esm/testUtils/msw-setup.js +18 -0
  60. package/dist/esm/testUtils/obsidian-fetch-adapter.js +50 -0
  61. package/dist/esm/testUtils/test-defaults.js +99 -0
  62. package/dist/esm/transport/fetch-with-retry.js +133 -0
  63. package/dist/esm/transport/http-client.js +51 -0
  64. package/dist/esm/transport/http-dispatcher.js +104 -0
  65. package/dist/esm/types/entities.js +408 -0
  66. package/dist/esm/types/enums.js +34 -0
  67. package/dist/esm/types/errors.js +8 -0
  68. package/dist/esm/types/http.js +1 -0
  69. package/dist/esm/types/index.js +5 -0
  70. package/dist/esm/types/requests.js +114 -0
  71. package/dist/esm/utils/case-conversion.js +47 -0
  72. package/dist/esm/utils/index.js +3 -0
  73. package/dist/esm/utils/timestamp-conversion.js +45 -0
  74. package/dist/esm/utils/url-helpers.js +112 -0
  75. package/dist/esm/utils/uuidv7.js +163 -0
  76. package/dist/types/authentication.d.ts +160 -0
  77. package/dist/types/clients/add-comment-helper.d.ts +12 -0
  78. package/dist/types/clients/base-client.d.ts +24 -0
  79. package/dist/types/clients/channels-client.d.ts +91 -0
  80. package/dist/types/clients/comments-client.d.ts +157 -0
  81. package/dist/types/clients/conversation-messages-client.d.ts +127 -0
  82. package/dist/types/clients/conversations-client.d.ts +206 -0
  83. package/dist/types/clients/groups-client.d.ts +55 -0
  84. package/dist/types/clients/inbox-client.d.ts +20 -0
  85. package/dist/types/clients/reactions-client.d.ts +19 -0
  86. package/dist/types/clients/search-client.d.ts +20 -0
  87. package/dist/types/clients/threads-client.d.ts +344 -0
  88. package/dist/types/clients/users-client.d.ts +123 -0
  89. package/dist/types/clients/workspace-users-client.d.ts +47 -0
  90. package/dist/types/clients/workspaces-client.d.ts +79 -0
  91. package/dist/types/comms-api.d.ts +59 -0
  92. package/dist/types/consts/endpoints.d.ts +19 -0
  93. package/dist/types/index.d.ts +18 -0
  94. package/dist/types/testUtils/msw-handlers.d.ts +28 -0
  95. package/dist/types/testUtils/msw-setup.d.ts +1 -0
  96. package/dist/types/testUtils/obsidian-fetch-adapter.d.ts +29 -0
  97. package/dist/types/testUtils/test-defaults.d.ts +16 -0
  98. package/dist/types/transport/fetch-with-retry.d.ts +4 -0
  99. package/dist/types/transport/http-client.d.ts +13 -0
  100. package/dist/types/transport/http-dispatcher.d.ts +10 -0
  101. package/dist/types/types/entities.d.ts +1288 -0
  102. package/dist/types/types/enums.d.ts +55 -0
  103. package/dist/types/types/errors.d.ts +6 -0
  104. package/dist/types/types/http.d.ts +54 -0
  105. package/dist/types/types/index.d.ts +5 -0
  106. package/dist/types/types/requests.d.ts +385 -0
  107. package/dist/types/utils/case-conversion.d.ts +8 -0
  108. package/dist/types/utils/index.d.ts +3 -0
  109. package/dist/types/utils/timestamp-conversion.d.ts +13 -0
  110. package/dist/types/utils/url-helpers.d.ts +88 -0
  111. package/dist/types/utils/uuidv7.d.ts +40 -0
  112. package/package.json +93 -0
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UsersClient = void 0;
4
+ const endpoints_1 = require("../consts/endpoints");
5
+ const http_client_1 = require("../transport/http-client");
6
+ const entities_1 = require("../types/entities");
7
+ const base_client_1 = require("./base-client");
8
+ /**
9
+ * Client for the `/api/v1/users/` endpoints. Authentication flows through
10
+ * Todoist-ID; `register` / `login` / `loginWithGoogle` / `loginWithToken` /
11
+ * `loginWithTodoist` are the available entry points.
12
+ */
13
+ class UsersClient extends base_client_1.BaseClient {
14
+ /** Registers a new user via the Todoist-ID bridge. */
15
+ register(args) {
16
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/register`, args, entities_1.UserSchema, { authed: false });
17
+ }
18
+ /** Logs in an existing user. */
19
+ login(args) {
20
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/login`, args, entities_1.UserSchema, { authed: false });
21
+ }
22
+ /**
23
+ * Logs in using a valid token (sent via Authorization header). The SDK
24
+ * client is already configured with the token, so no args are needed.
25
+ */
26
+ loginWithToken() {
27
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_token`, undefined, entities_1.UserSchema);
28
+ }
29
+ /**
30
+ * Exchanges the browser's Todoist web-session cookie for a Comms session.
31
+ * Only useful when running in a browser context on the shared Todoist
32
+ * registrable domain — the cookie is sent automatically by the browser.
33
+ */
34
+ loginWithTodoist() {
35
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_todoist`, {}, entities_1.UserSchema, { authed: false });
36
+ }
37
+ /** Logs in (and auto-signs-up) via a Google ID token. */
38
+ loginWithGoogle(args) {
39
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/login_with_google`, args, entities_1.UserSchema, { authed: false });
40
+ }
41
+ /**
42
+ * Completes an MFA challenge issued by `loginWithGoogle` (returns an MFA
43
+ * token to pass back to `loginWithGoogle.mfaToken`).
44
+ */
45
+ mfaChallenge(args) {
46
+ return (0, http_client_1.request)({
47
+ httpMethod: 'POST',
48
+ baseUri: this.getBaseUri(),
49
+ relativePath: `${endpoints_1.ENDPOINT_USERS}/mfa/challenge`,
50
+ apiToken: undefined,
51
+ payload: args,
52
+ customFetch: this.customFetch,
53
+ }).then((response) => response.data);
54
+ }
55
+ /** Logs out the current user and clears the session cookie. */
56
+ logout() {
57
+ return (0, http_client_1.request)({
58
+ httpMethod: 'POST',
59
+ baseUri: this.getBaseUri(),
60
+ relativePath: `${endpoints_1.ENDPOINT_USERS}/logout`,
61
+ apiToken: this.apiToken,
62
+ payload: undefined,
63
+ customFetch: this.customFetch,
64
+ }).then(() => undefined);
65
+ }
66
+ /** Returns the user associated with the current access token. */
67
+ getSessionUser() {
68
+ return this.get(`${endpoints_1.ENDPOINT_USERS}/get_session_user`, undefined, entities_1.UserSchema);
69
+ }
70
+ /**
71
+ * Fetches a single user. Defaults to the session user when no `id` is
72
+ * passed. Cross-workspace lookups require that the caller and the target
73
+ * share a workspace.
74
+ */
75
+ getUser(args) {
76
+ return this.get(`${endpoints_1.ENDPOINT_USERS}/getone`, args ?? {}, entities_1.UserSchema);
77
+ }
78
+ /** Looks up a user by their email address. */
79
+ getUserByEmail(email) {
80
+ return this.get(`${endpoints_1.ENDPOINT_USERS}/get_by_email`, { email }, entities_1.UserSchema);
81
+ }
82
+ /**
83
+ * Updates the logged-in user's profile. Most fields are proxied to
84
+ * Todoist (full name, password, language, timezone, etc.).
85
+ */
86
+ update(args) {
87
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/update`, args, entities_1.UserSchema);
88
+ }
89
+ /** Updates the user's password. Requires `currentPassword`. */
90
+ updatePassword(args) {
91
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/update_password`, args, entities_1.UserSchema);
92
+ }
93
+ /** Removes the user's avatar. */
94
+ removeAvatar() {
95
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/remove_avatar`, undefined, entities_1.UserSchema);
96
+ }
97
+ /**
98
+ * Invalidates the current API token and returns the user with a fresh
99
+ * token.
100
+ */
101
+ invalidateToken() {
102
+ return this.post(`${endpoints_1.ENDPOINT_USERS}/invalidate_token`, undefined, entities_1.UserSchema);
103
+ }
104
+ /**
105
+ * Validates that an arbitrary token is still active. Note this is sent
106
+ * as a GET — the token is read from the query string, not the
107
+ * Authorization header.
108
+ */
109
+ validateToken(token) {
110
+ return (0, http_client_1.request)({
111
+ httpMethod: 'GET',
112
+ baseUri: this.getBaseUri(),
113
+ relativePath: `${endpoints_1.ENDPOINT_USERS}/validate_token`,
114
+ apiToken: undefined,
115
+ payload: { token },
116
+ customFetch: this.customFetch,
117
+ }).then(() => undefined);
118
+ }
119
+ /** Marks the user as active on a workspace (presence beacon). */
120
+ heartbeat(args) {
121
+ return (0, http_client_1.request)({
122
+ httpMethod: 'GET',
123
+ baseUri: this.getBaseUri(),
124
+ relativePath: `${endpoints_1.ENDPOINT_USERS}/heartbeat`,
125
+ apiToken: this.apiToken,
126
+ payload: args,
127
+ customFetch: this.customFetch,
128
+ }).then(() => undefined);
129
+ }
130
+ /** Resets the user's presence for a workspace. */
131
+ resetPresence(workspaceId) {
132
+ return (0, http_client_1.request)({
133
+ httpMethod: 'POST',
134
+ baseUri: this.getBaseUri(),
135
+ relativePath: `${endpoints_1.ENDPOINT_USERS}/reset_presence`,
136
+ apiToken: this.apiToken,
137
+ payload: { workspaceId },
138
+ customFetch: this.customFetch,
139
+ }).then(() => undefined);
140
+ }
141
+ /** Checks whether an email address is registered (and verified). */
142
+ checkEmail(email) {
143
+ return (0, http_client_1.request)({
144
+ httpMethod: 'POST',
145
+ baseUri: this.getBaseUri(),
146
+ relativePath: `${endpoints_1.ENDPOINT_USERS}/check_email`,
147
+ apiToken: undefined,
148
+ payload: { email },
149
+ customFetch: this.customFetch,
150
+ }).then((response) => response.data);
151
+ }
152
+ /**
153
+ * Returns the current per-channel mail unsubscribe settings for the
154
+ * caller's primary email.
155
+ */
156
+ getUnsubscribeSettings() {
157
+ return (0, http_client_1.request)({
158
+ httpMethod: 'GET',
159
+ baseUri: this.getBaseUri(),
160
+ relativePath: `${endpoints_1.ENDPOINT_USERS}/get_unsubscribe_settings`,
161
+ apiToken: this.apiToken,
162
+ payload: undefined,
163
+ customFetch: this.customFetch,
164
+ }).then((response) => response.data);
165
+ }
166
+ /** Toggles per-email-type opt-out settings. */
167
+ updateUnsubscribeSettings(settings) {
168
+ return (0, http_client_1.request)({
169
+ httpMethod: 'POST',
170
+ baseUri: this.getBaseUri(),
171
+ relativePath: `${endpoints_1.ENDPOINT_USERS}/update_unsubscribe_settings`,
172
+ apiToken: this.apiToken,
173
+ payload: settings,
174
+ customFetch: this.customFetch,
175
+ }).then((response) => response.data);
176
+ }
177
+ get(url, params, schema) {
178
+ return (0, http_client_1.request)({
179
+ httpMethod: 'GET',
180
+ baseUri: this.getBaseUri(),
181
+ relativePath: url,
182
+ apiToken: this.apiToken,
183
+ payload: params,
184
+ customFetch: this.customFetch,
185
+ }).then((response) => schema.parse(response.data));
186
+ }
187
+ post(url, params, schema, options = {}) {
188
+ const authed = options.authed ?? true;
189
+ return (0, http_client_1.request)({
190
+ httpMethod: 'POST',
191
+ baseUri: this.getBaseUri(),
192
+ relativePath: url,
193
+ apiToken: authed ? this.apiToken : undefined,
194
+ payload: params,
195
+ customFetch: this.customFetch,
196
+ }).then((response) => schema.parse(response.data));
197
+ }
198
+ }
199
+ exports.UsersClient = UsersClient;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WorkspaceUsersClient = void 0;
4
+ const http_client_1 = require("../transport/http-client");
5
+ const entities_1 = require("../types/entities");
6
+ const base_client_1 = require("./base-client");
7
+ /**
8
+ * Client for `/api/v1/workspace_users/`. The backend's `add` endpoint
9
+ * rejects non-empty `name` and `channelIds` — set neither.
10
+ */
11
+ class WorkspaceUsersClient extends base_client_1.BaseClient {
12
+ /** Returns workspace user objects for the given workspace id. */
13
+ getWorkspaceUsers(args) {
14
+ return (0, http_client_1.request)({
15
+ httpMethod: 'GET',
16
+ baseUri: this.getBaseUri(),
17
+ relativePath: 'workspace_users/get',
18
+ apiToken: this.apiToken,
19
+ payload: { id: args.workspaceId, archived: args.archived },
20
+ customFetch: this.customFetch,
21
+ }).then((response) => response.data.map((user) => entities_1.WorkspaceUserSchema.parse(user)));
22
+ }
23
+ /** Returns workspace user IDs for the given workspace id. */
24
+ getWorkspaceUserIds(workspaceId) {
25
+ return (0, http_client_1.request)({
26
+ httpMethod: 'GET',
27
+ baseUri: this.getBaseUri(),
28
+ relativePath: 'workspace_users/get_ids',
29
+ apiToken: this.apiToken,
30
+ payload: { id: workspaceId },
31
+ customFetch: this.customFetch,
32
+ }).then((response) => response.data);
33
+ }
34
+ /** Gets a user by id. */
35
+ getUserById(args) {
36
+ return (0, http_client_1.request)({
37
+ httpMethod: 'GET',
38
+ baseUri: this.getBaseUri(),
39
+ relativePath: 'workspace_users/getone',
40
+ apiToken: this.apiToken,
41
+ payload: { id: args.workspaceId, user_id: args.userId },
42
+ customFetch: this.customFetch,
43
+ }).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
44
+ }
45
+ /** Gets a user by email. */
46
+ getUserByEmail(args) {
47
+ return (0, http_client_1.request)({
48
+ httpMethod: 'GET',
49
+ baseUri: this.getBaseUri(),
50
+ relativePath: 'workspace_users/get_by_email',
51
+ apiToken: this.apiToken,
52
+ payload: { id: args.workspaceId, email: args.email },
53
+ customFetch: this.customFetch,
54
+ }).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
55
+ }
56
+ /** Gets the user's info in the context of the workspace. */
57
+ getUserInfo(args) {
58
+ return (0, http_client_1.request)({
59
+ httpMethod: 'GET',
60
+ baseUri: this.getBaseUri(),
61
+ relativePath: 'workspace_users/get_info',
62
+ apiToken: this.apiToken,
63
+ payload: { id: args.workspaceId, user_id: args.userId },
64
+ customFetch: this.customFetch,
65
+ }).then((response) => response.data);
66
+ }
67
+ /** Gets the user's local time (e.g., "2017-05-10 07:55:40"). */
68
+ getUserLocalTime(args) {
69
+ return (0, http_client_1.request)({
70
+ httpMethod: 'GET',
71
+ baseUri: this.getBaseUri(),
72
+ relativePath: 'workspace_users/get_local_time',
73
+ apiToken: this.apiToken,
74
+ payload: { id: args.workspaceId, user_id: args.userId },
75
+ customFetch: this.customFetch,
76
+ }).then((response) => response.data);
77
+ }
78
+ /** Adds a person to a workspace. */
79
+ addUser(args) {
80
+ return (0, http_client_1.request)({
81
+ httpMethod: 'POST',
82
+ baseUri: this.getBaseUri(),
83
+ relativePath: 'workspace_users/add',
84
+ apiToken: this.apiToken,
85
+ payload: {
86
+ id: args.workspaceId,
87
+ email: args.email,
88
+ userType: args.userType,
89
+ },
90
+ customFetch: this.customFetch,
91
+ }).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
92
+ }
93
+ /** Updates a person in a workspace. */
94
+ updateUser(args) {
95
+ return (0, http_client_1.request)({
96
+ httpMethod: 'POST',
97
+ baseUri: this.getBaseUri(),
98
+ relativePath: 'workspace_users/update',
99
+ apiToken: this.apiToken,
100
+ payload: {
101
+ id: args.workspaceId,
102
+ userType: args.userType,
103
+ email: args.email,
104
+ userId: args.userId,
105
+ },
106
+ customFetch: this.customFetch,
107
+ }).then((response) => entities_1.WorkspaceUserSchema.parse(response.data));
108
+ }
109
+ /** Removes a person from a workspace. */
110
+ removeUser(args) {
111
+ return (0, http_client_1.request)({
112
+ httpMethod: 'POST',
113
+ baseUri: this.getBaseUri(),
114
+ relativePath: 'workspace_users/remove',
115
+ apiToken: this.apiToken,
116
+ payload: {
117
+ id: args.workspaceId,
118
+ email: args.email,
119
+ userId: args.userId,
120
+ },
121
+ customFetch: this.customFetch,
122
+ }).then(() => undefined);
123
+ }
124
+ /** Sends a new workspace invitation to the selected user. */
125
+ resendInvite(args) {
126
+ return (0, http_client_1.request)({
127
+ httpMethod: 'POST',
128
+ baseUri: this.getBaseUri(),
129
+ relativePath: 'workspace_users/resend_invite',
130
+ apiToken: this.apiToken,
131
+ payload: {
132
+ id: args.workspaceId,
133
+ email: args.email,
134
+ userId: args.userId,
135
+ },
136
+ customFetch: this.customFetch,
137
+ }).then(() => undefined);
138
+ }
139
+ }
140
+ exports.WorkspaceUsersClient = WorkspaceUsersClient;
@@ -0,0 +1,93 @@
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
+ /** Gets all the user's workspaces. */
16
+ getWorkspaces() {
17
+ return (0, http_client_1.request)({
18
+ httpMethod: 'GET',
19
+ baseUri: this.getBaseUri(),
20
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get`,
21
+ apiToken: this.apiToken,
22
+ payload: undefined,
23
+ customFetch: this.customFetch,
24
+ }).then((response) => response.data.map((workspace) => entities_1.WorkspaceSchema.parse(workspace)));
25
+ }
26
+ /** Gets a single workspace object by id. */
27
+ getWorkspace(id) {
28
+ return (0, http_client_1.request)({
29
+ httpMethod: 'GET',
30
+ baseUri: this.getBaseUri(),
31
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/getone`,
32
+ apiToken: this.apiToken,
33
+ payload: { id },
34
+ customFetch: this.customFetch,
35
+ }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
36
+ }
37
+ /** Gets the user's default workspace. */
38
+ getDefaultWorkspace() {
39
+ return (0, http_client_1.request)({
40
+ httpMethod: 'GET',
41
+ baseUri: this.getBaseUri(),
42
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get_default`,
43
+ apiToken: this.apiToken,
44
+ payload: undefined,
45
+ customFetch: this.customFetch,
46
+ }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
47
+ }
48
+ /** Creates a new workspace. */
49
+ createWorkspace(name) {
50
+ return (0, http_client_1.request)({
51
+ httpMethod: 'POST',
52
+ baseUri: this.getBaseUri(),
53
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/add`,
54
+ apiToken: this.apiToken,
55
+ payload: { name },
56
+ customFetch: this.customFetch,
57
+ }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
58
+ }
59
+ /** Updates an existing workspace. */
60
+ updateWorkspace(id, name) {
61
+ return (0, http_client_1.request)({
62
+ httpMethod: 'POST',
63
+ baseUri: this.getBaseUri(),
64
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/update`,
65
+ apiToken: this.apiToken,
66
+ payload: { id, name },
67
+ customFetch: this.customFetch,
68
+ }).then((response) => entities_1.WorkspaceSchema.parse(response.data));
69
+ }
70
+ /** Removes a workspace and all its data (not recoverable). */
71
+ removeWorkspace(id) {
72
+ return (0, http_client_1.request)({
73
+ httpMethod: 'POST',
74
+ baseUri: this.getBaseUri(),
75
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/remove`,
76
+ apiToken: this.apiToken,
77
+ payload: { id },
78
+ customFetch: this.customFetch,
79
+ }).then(() => undefined);
80
+ }
81
+ /** Gets the public channels of a workspace. */
82
+ getPublicChannels(id) {
83
+ return (0, http_client_1.request)({
84
+ httpMethod: 'GET',
85
+ baseUri: this.getBaseUri(),
86
+ relativePath: `${endpoints_1.ENDPOINT_WORKSPACES}/get_public_channels`,
87
+ apiToken: this.apiToken,
88
+ payload: { id },
89
+ customFetch: this.customFetch,
90
+ }).then((response) => exports.ChannelListSchema.parse(response.data));
91
+ }
92
+ }
93
+ exports.WorkspacesClient = WorkspacesClient;
@@ -0,0 +1,65 @@
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
+ customFetch: options?.customFetch,
40
+ };
41
+ this.users = new users_client_1.UsersClient(clientConfig);
42
+ this.workspaces = new workspaces_client_1.WorkspacesClient(clientConfig);
43
+ this.workspaceUsers = new workspace_users_client_1.WorkspaceUsersClient(clientConfig);
44
+ this.channels = new channels_client_1.ChannelsClient(clientConfig);
45
+ this.threads = new threads_client_1.ThreadsClient(clientConfig);
46
+ this.groups = new groups_client_1.GroupsClient(clientConfig);
47
+ this.conversations = new conversations_client_1.ConversationsClient(clientConfig);
48
+ this.comments = new comments_client_1.CommentsClient(clientConfig);
49
+ this.conversationMessages = new conversation_messages_client_1.ConversationMessagesClient(clientConfig);
50
+ this.inbox = new inbox_client_1.InboxClient(clientConfig);
51
+ this.reactions = new reactions_client_1.ReactionsClient(clientConfig);
52
+ this.search = new search_client_1.SearchClient(clientConfig);
53
+ }
54
+ /**
55
+ * Drains the SDK's process-global connection pool. CLIs and scripts
56
+ * should `await api.close()` before exit so Node's event loop empties
57
+ * immediately instead of waiting ~4s on keep-alive. Affects every
58
+ * `CommsApi` and OAuth helper in the same process — it's a
59
+ * process-shutdown gesture, not an instance teardown. Browser-safe.
60
+ */
61
+ async close() {
62
+ await (0, http_dispatcher_1.closeDefaultDispatcher)();
63
+ }
64
+ }
65
+ exports.CommsApi = CommsApi;
@@ -0,0 +1,27 @@
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 BASE_URI = 'https://comms.todoist.com';
6
+ const API_VERSION = 'v1';
7
+ /**
8
+ * Gets the base URI for Comms API requests.
9
+ *
10
+ * @param domainBase - Custom domain base URL. Defaults to Comms' API domain.
11
+ * @returns Complete base URI with trailing slash (e.g., 'https://comms.todoist.com/api/v1/')
12
+ */
13
+ function getCommsBaseUri(domainBase = BASE_URI) {
14
+ return new URL(`/api/${API_VERSION}/`, domainBase).toString();
15
+ }
16
+ exports.ENDPOINT_USERS = 'users';
17
+ exports.ENDPOINT_WORKSPACES = 'workspaces';
18
+ exports.ENDPOINT_CHANNELS = 'channels';
19
+ exports.ENDPOINT_THREADS = 'threads';
20
+ exports.ENDPOINT_GROUPS = 'groups';
21
+ exports.ENDPOINT_CONVERSATIONS = 'conversations';
22
+ exports.ENDPOINT_COMMENTS = 'comments';
23
+ exports.ENDPOINT_NOTIFICATIONS = 'notifications';
24
+ exports.ENDPOINT_INBOX = 'inbox';
25
+ exports.ENDPOINT_REACTIONS = 'reactions';
26
+ exports.ENDPOINT_SEARCH = 'search';
27
+ 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
+ });