@doist/comms-sdk 2.0.1 → 3.0.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 (48) hide show
  1. package/dist/esm/utils/multipart-upload.js +73 -15
  2. package/dist/esm/utils/url-helpers.js +104 -16
  3. package/dist/types/utils/multipart-upload.d.ts +3 -4
  4. package/dist/types/utils/url-helpers.d.ts +41 -0
  5. package/package.json +5 -10
  6. package/dist/cjs/authentication.js +0 -256
  7. package/dist/cjs/clients/add-comment-helper.js +0 -43
  8. package/dist/cjs/clients/attachments-client.js +0 -71
  9. package/dist/cjs/clients/base-client.js +0 -33
  10. package/dist/cjs/clients/channels-client.js +0 -211
  11. package/dist/cjs/clients/comments-client.js +0 -175
  12. package/dist/cjs/clients/conversation-messages-client.js +0 -169
  13. package/dist/cjs/clients/conversations-client.js +0 -283
  14. package/dist/cjs/clients/groups-client.js +0 -172
  15. package/dist/cjs/clients/hooks-client.js +0 -52
  16. package/dist/cjs/clients/inbox-client.js +0 -184
  17. package/dist/cjs/clients/notify-audience.js +0 -45
  18. package/dist/cjs/clients/reactions-client.js +0 -97
  19. package/dist/cjs/clients/search-client.js +0 -138
  20. package/dist/cjs/clients/threads-client.js +0 -364
  21. package/dist/cjs/clients/users-client.js +0 -326
  22. package/dist/cjs/clients/workspace-users-client.js +0 -252
  23. package/dist/cjs/clients/workspaces-client.js +0 -174
  24. package/dist/cjs/comms-api.js +0 -70
  25. package/dist/cjs/consts/endpoints.js +0 -34
  26. package/dist/cjs/index.js +0 -53
  27. package/dist/cjs/migration.js +0 -96
  28. package/dist/cjs/package.json +0 -1
  29. package/dist/cjs/testUtils/msw-handlers.js +0 -51
  30. package/dist/cjs/testUtils/msw-setup.js +0 -35
  31. package/dist/cjs/testUtils/obsidian-fetch-adapter.js +0 -53
  32. package/dist/cjs/testUtils/test-defaults.js +0 -106
  33. package/dist/cjs/transport/fetch-with-retry.js +0 -146
  34. package/dist/cjs/transport/http-client.js +0 -56
  35. package/dist/cjs/transport/http-dispatcher.js +0 -190
  36. package/dist/cjs/types/api-version.js +0 -8
  37. package/dist/cjs/types/entities.js +0 -496
  38. package/dist/cjs/types/enums.js +0 -37
  39. package/dist/cjs/types/errors.js +0 -12
  40. package/dist/cjs/types/http.js +0 -4
  41. package/dist/cjs/types/index.js +0 -22
  42. package/dist/cjs/types/requests.js +0 -183
  43. package/dist/cjs/utils/case-conversion.js +0 -54
  44. package/dist/cjs/utils/index.js +0 -19
  45. package/dist/cjs/utils/multipart-upload.js +0 -144
  46. package/dist/cjs/utils/timestamp-conversion.js +0 -58
  47. package/dist/cjs/utils/url-helpers.js +0 -133
  48. package/dist/cjs/utils/uuidv7.js +0 -182
@@ -1,184 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InboxClient = exports.InboxThreadListSchema = 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.InboxThreadListSchema = zod_1.z.array(entities_1.InboxThreadSchema);
10
- /** Client for `/api/v1/inbox/`. */
11
- class InboxClient extends base_client_1.BaseClient {
12
- constructor() {
13
- super(...arguments);
14
- this.linkBaseUrl = this.getLinkBaseUrl();
15
- // Reuse the shared singletons when no custom base is configured.
16
- this.inboxThreadSchema = this.linkBaseUrl
17
- ? (0, entities_1.createInboxThreadSchema)(this.linkBaseUrl)
18
- : entities_1.InboxThreadSchema;
19
- this.inboxThreadListSchema = this.linkBaseUrl
20
- ? zod_1.z.array(this.inboxThreadSchema)
21
- : exports.InboxThreadListSchema;
22
- }
23
- /**
24
- * Gets inbox items (threads).
25
- *
26
- * @param args - The arguments for getting inbox.
27
- * @param args.workspaceId - The workspace ID.
28
- * @param args.newerThan - Optional date to get items newer than.
29
- * @param args.olderThan - Optional date to get items older than.
30
- * @param args.limit - Optional limit on number of items returned.
31
- * @param args.cursor - Optional cursor for pagination.
32
- * @param args.archiveFilter - Optional filter: 'active' (default), 'archived', or 'all'.
33
- * @returns Inbox threads.
34
- *
35
- * @example
36
- * ```typescript
37
- * const inbox = await api.inbox.getInbox({
38
- * workspaceId: 123,
39
- * newerThan: new Date('2024-01-01'),
40
- * })
41
- *
42
- * // Include archived (done) items alongside active ones
43
- * const allInbox = await api.inbox.getInbox({
44
- * workspaceId: 123,
45
- * archiveFilter: 'all',
46
- * })
47
- * ```
48
- */
49
- getInbox(args) {
50
- const params = { workspace_id: args.workspaceId };
51
- if (args.newerThan)
52
- params.newer_than_ts = Math.floor(args.newerThan.getTime() / 1000);
53
- if (args.olderThan)
54
- params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
55
- if (args.limit)
56
- params.limit = args.limit;
57
- if (args.cursor)
58
- params.cursor = args.cursor;
59
- if (args.archiveFilter)
60
- params.archive_filter = args.archiveFilter;
61
- return (0, http_client_1.request)({
62
- httpMethod: 'GET',
63
- baseUri: this.getBaseUri(),
64
- relativePath: `${endpoints_1.ENDPOINT_INBOX}/get`,
65
- apiToken: this.apiToken,
66
- payload: params,
67
- customFetch: this.customFetch,
68
- }).then((response) => this.inboxThreadListSchema.parse(response.data));
69
- }
70
- /**
71
- * Gets unread count for inbox.
72
- *
73
- * @param workspaceId - The workspace ID.
74
- * @returns The unread count.
75
- *
76
- * @example
77
- * ```typescript
78
- * const count = await api.inbox.getCount(123)
79
- * console.log(`Unread items: ${count}`)
80
- * ```
81
- */
82
- getCount(workspaceId) {
83
- return (0, http_client_1.request)({
84
- httpMethod: 'GET',
85
- baseUri: this.getBaseUri(),
86
- relativePath: `${endpoints_1.ENDPOINT_INBOX}/get_count`,
87
- apiToken: this.apiToken,
88
- payload: { workspace_id: workspaceId },
89
- customFetch: this.customFetch,
90
- }).then((response) => response.data.data);
91
- }
92
- /**
93
- * Archives a thread in the inbox.
94
- *
95
- * @param id - The thread ID.
96
- *
97
- * @example
98
- * ```typescript
99
- * await api.inbox.archiveThread('7YpL3oZ4kZ9vP7Q1tR2sX3z')
100
- * ```
101
- */
102
- archiveThread(id) {
103
- return (0, http_client_1.request)({
104
- httpMethod: 'POST',
105
- baseUri: this.getBaseUri(),
106
- relativePath: `${endpoints_1.ENDPOINT_INBOX}/archive`,
107
- apiToken: this.apiToken,
108
- payload: { id },
109
- customFetch: this.customFetch,
110
- }).then(() => undefined);
111
- }
112
- /**
113
- * Unarchives a thread in the inbox.
114
- *
115
- * @param id - The thread ID.
116
- *
117
- * @example
118
- * ```typescript
119
- * await api.inbox.unarchiveThread('7YpL3oZ4kZ9vP7Q1tR2sX3z')
120
- * ```
121
- */
122
- unarchiveThread(id) {
123
- return (0, http_client_1.request)({
124
- httpMethod: 'POST',
125
- baseUri: this.getBaseUri(),
126
- relativePath: `${endpoints_1.ENDPOINT_INBOX}/unarchive`,
127
- apiToken: this.apiToken,
128
- payload: { id },
129
- customFetch: this.customFetch,
130
- }).then(() => undefined);
131
- }
132
- /**
133
- * Marks all inbox items as read in a workspace.
134
- *
135
- * @param workspaceId - The workspace ID.
136
- *
137
- * @example
138
- * ```typescript
139
- * await api.inbox.markAllRead(123)
140
- * ```
141
- */
142
- markAllRead(workspaceId) {
143
- return (0, http_client_1.request)({
144
- httpMethod: 'POST',
145
- baseUri: this.getBaseUri(),
146
- relativePath: `${endpoints_1.ENDPOINT_INBOX}/mark_all_read`,
147
- apiToken: this.apiToken,
148
- payload: { workspace_id: workspaceId },
149
- customFetch: this.customFetch,
150
- }).then(() => undefined);
151
- }
152
- /**
153
- * Archives all inbox items in a workspace.
154
- *
155
- * @param args - The arguments for archiving all.
156
- * @param args.workspaceId - The workspace ID.
157
- * @param args.channelIds - Optional array of channel IDs to filter by.
158
- * @param args.olderThan - Optional date to filter items older than.
159
- *
160
- * @example
161
- * ```typescript
162
- * await api.inbox.archiveAll({
163
- * workspaceId: 123,
164
- * olderThan: new Date('2024-01-01'),
165
- * })
166
- * ```
167
- */
168
- archiveAll(args) {
169
- const params = { workspace_id: args.workspaceId };
170
- if (args.channelIds)
171
- params.channel_ids = args.channelIds;
172
- if (args.olderThan)
173
- params.older_than_ts = Math.floor(args.olderThan.getTime() / 1000);
174
- return (0, http_client_1.request)({
175
- httpMethod: 'POST',
176
- baseUri: this.getBaseUri(),
177
- relativePath: `${endpoints_1.ENDPOINT_INBOX}/archive_all`,
178
- apiToken: this.apiToken,
179
- payload: params,
180
- customFetch: this.customFetch,
181
- }).then(() => undefined);
182
- }
183
- }
184
- exports.InboxClient = InboxClient;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyNotifyAudience = applyNotifyAudience;
4
- const enums_1 = require("../types/enums");
5
- const SENTINEL_GROUP_IDS = new Set(Object.values(enums_1.NOTIFY_AUDIENCE_GROUP_IDS));
6
- function isNotifyAudience(value) {
7
- return typeof value === 'string' && enums_1.NOTIFY_AUDIENCES.includes(value);
8
- }
9
- function collectMarkerOffenses(field, values) {
10
- if (!values)
11
- return null;
12
- const offending = values.filter((id) => SENTINEL_GROUP_IDS.has(id));
13
- return offending.length > 0 ? { field, offending } : null;
14
- }
15
- /**
16
- * Normalizes a `notifyAudience` flag into a sentinel `groups` entry
17
- * (`EVERYONE` / `EVERYONE_IN_THREAD`) and rejects callers who put those
18
- * reserved markers directly into `groups` / `directGroupMentions`.
19
- *
20
- * When `notifyAudience` is set it is stripped and its sentinel is appended to
21
- * `groups`; the backend only understands the marker in `groups`. When it is
22
- * unset the params are returned unchanged, preserving any explicit
23
- * `groups` / `directGroupMentions` (including a `null`) on the wire.
24
- */
25
- function applyNotifyAudience(params) {
26
- const offenses = [
27
- collectMarkerOffenses('groups', params.groups ?? undefined),
28
- collectMarkerOffenses('directGroupMentions', params.directGroupMentions ?? undefined),
29
- ].filter((o) => o !== null);
30
- if (offenses.length > 0) {
31
- const details = offenses
32
- .map(({ field, offending }) => `\`${field}\` contains ${offending.join(', ')}`)
33
- .join('; ');
34
- throw new Error(`Reserved broadcast marker IDs found: ${details}. Pass these via \`notifyAudience\` (e.g. \`notifyAudience: 'channel'\` for EVERYONE) instead of populating \`groups\` / \`directGroupMentions\` directly.`);
35
- }
36
- if (params.notifyAudience == null) {
37
- return params;
38
- }
39
- if (!isNotifyAudience(params.notifyAudience)) {
40
- throw new Error(`Invalid \`notifyAudience\` value "${String(params.notifyAudience)}". Expected one of: ${enums_1.NOTIFY_AUDIENCES.join(', ')}.`);
41
- }
42
- const sentinel = enums_1.NOTIFY_AUDIENCE_GROUP_IDS[params.notifyAudience];
43
- const { notifyAudience: _stripped, groups, ...rest } = params;
44
- return { ...rest, groups: [...(groups ?? []), sentinel] };
45
- }
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ReactionsClient = void 0;
4
- const endpoints_1 = require("../consts/endpoints");
5
- const http_client_1 = require("../transport/http-client");
6
- const base_client_1 = require("./base-client");
7
- function reactionTarget(args) {
8
- if (args.threadId)
9
- return { threadId: args.threadId };
10
- if (args.commentId)
11
- return { commentId: args.commentId };
12
- if (args.messageId)
13
- return { messageId: args.messageId };
14
- throw new Error('Must provide one of: threadId, commentId, or messageId');
15
- }
16
- /**
17
- * Client for interacting with Comms reaction endpoints.
18
- */
19
- class ReactionsClient extends base_client_1.BaseClient {
20
- /**
21
- * Adds an emoji reaction to a thread, comment, or conversation message.
22
- *
23
- * @param args - The arguments for adding a reaction.
24
- * @param args.threadId - Optional thread ID.
25
- * @param args.commentId - Optional comment ID.
26
- * @param args.messageId - Optional message ID (for conversation messages).
27
- * @param args.reaction - The reaction emoji to add.
28
- *
29
- * @example
30
- * ```typescript
31
- * await api.reactions.add({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z', reaction: '👍' })
32
- * ```
33
- */
34
- add(args) {
35
- return (0, http_client_1.request)({
36
- httpMethod: 'POST',
37
- baseUri: this.getBaseUri(),
38
- relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/add`,
39
- apiToken: this.apiToken,
40
- payload: { ...reactionTarget(args), reaction: args.reaction },
41
- customFetch: this.customFetch,
42
- }).then(() => undefined);
43
- }
44
- /**
45
- * Gets reactions for a thread, comment, or conversation message.
46
- *
47
- * Returns an object with emoji reactions as keys and arrays of user IDs as
48
- * values, or null if no reactions.
49
- *
50
- * @param args - The arguments for getting reactions.
51
- * @param args.threadId - Optional thread ID.
52
- * @param args.commentId - Optional comment ID.
53
- * @param args.messageId - Optional message ID (for conversation messages).
54
- * @returns A reaction object with emoji reactions as keys and arrays of user IDs as values, or null if no reactions.
55
- *
56
- * @example
57
- * ```typescript
58
- * const reactions = await api.reactions.get({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z' })
59
- * // Returns: { "👍": [101, 202, 303], "❤️": [101, 202] }
60
- * ```
61
- */
62
- get(args) {
63
- return (0, http_client_1.request)({
64
- httpMethod: 'GET',
65
- baseUri: this.getBaseUri(),
66
- relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/get`,
67
- apiToken: this.apiToken,
68
- payload: reactionTarget(args),
69
- customFetch: this.customFetch,
70
- }).then((response) => response.data);
71
- }
72
- /**
73
- * Removes an emoji reaction from a thread, comment, or conversation message.
74
- *
75
- * @param args - The arguments for removing a reaction.
76
- * @param args.threadId - Optional thread ID.
77
- * @param args.commentId - Optional comment ID.
78
- * @param args.messageId - Optional message ID (for conversation messages).
79
- * @param args.reaction - The reaction emoji to remove.
80
- *
81
- * @example
82
- * ```typescript
83
- * await api.reactions.remove({ threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z', reaction: '👍' })
84
- * ```
85
- */
86
- remove(args) {
87
- return (0, http_client_1.request)({
88
- httpMethod: 'POST',
89
- baseUri: this.getBaseUri(),
90
- relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/remove`,
91
- apiToken: this.apiToken,
92
- payload: { ...reactionTarget(args), reaction: args.reaction },
93
- customFetch: this.customFetch,
94
- }).then(() => undefined);
95
- }
96
- }
97
- exports.ReactionsClient = ReactionsClient;
@@ -1,138 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SearchClient = 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 interacting with Comms search endpoints.
10
- */
11
- class SearchClient extends base_client_1.BaseClient {
12
- /**
13
- * Searches across all threads and conversations in a workspace.
14
- *
15
- * @param args - The arguments for searching.
16
- * @param args.query - The search query string. Optional when `mentionSelf: true` is set; required otherwise.
17
- * @param args.workspaceId - The workspace ID to search in.
18
- * @param args.channelIds - Optional array of channel IDs to filter by.
19
- * @param args.authorIds - Optional array of author user IDs to filter by.
20
- * @param args.mentionSelf - Optional flag to filter by mentions of the current user. When true, `query` may be omitted.
21
- * @param args.dateFrom - Optional start date for filtering (YYYY-MM-DD).
22
- * @param args.dateTo - Optional end date for filtering (YYYY-MM-DD).
23
- * @param args.limit - Optional limit on number of results returned.
24
- * @param args.cursor - Optional cursor for pagination.
25
- * @returns Search results with pagination.
26
- *
27
- * @example
28
- * ```typescript
29
- * const results = await api.search.search({
30
- * query: 'important meeting',
31
- * workspaceId: 123,
32
- * })
33
- * ```
34
- */
35
- search(args) {
36
- const params = { workspace_id: args.workspaceId };
37
- if (args.query !== undefined)
38
- params.query = args.query;
39
- if (args.channelIds)
40
- params.channel_ids = args.channelIds;
41
- if (args.authorIds)
42
- params.author_ids = args.authorIds;
43
- if (args.mentionSelf !== undefined)
44
- params.mention_self = args.mentionSelf;
45
- if (args.dateFrom)
46
- params.date_from = args.dateFrom;
47
- if (args.dateTo)
48
- params.date_to = args.dateTo;
49
- if (args.limit)
50
- params.limit = args.limit;
51
- if (args.cursor)
52
- params.cursor = args.cursor;
53
- return (0, http_client_1.request)({
54
- httpMethod: 'GET',
55
- baseUri: this.getBaseUri(),
56
- relativePath: endpoints_1.ENDPOINT_SEARCH,
57
- apiToken: this.apiToken,
58
- payload: params,
59
- customFetch: this.customFetch,
60
- }).then((response) => ({
61
- ...response.data,
62
- items: response.data.items.map((result) => entities_1.SearchResultSchema.parse(result)),
63
- }));
64
- }
65
- /**
66
- * Searches within comments of a specific thread.
67
- *
68
- * @param args - The arguments for searching within a thread.
69
- * @param args.query - The search query string.
70
- * @param args.threadId - The thread ID to search in.
71
- * @param args.limit - Optional limit on number of results returned.
72
- * @param args.cursor - Optional cursor for pagination.
73
- * @returns Comment IDs that match the search query.
74
- *
75
- * @example
76
- * ```typescript
77
- * const results = await api.search.searchThread({
78
- * query: 'deadline',
79
- * threadId: '7YpL3oZ4kZ9vP7Q1tR2sX3z',
80
- * })
81
- * ```
82
- */
83
- searchThread(args) {
84
- const params = {
85
- query: args.query,
86
- thread_id: args.threadId,
87
- };
88
- if (args.limit)
89
- params.limit = args.limit;
90
- if (args.cursor)
91
- params.cursor = args.cursor;
92
- return (0, http_client_1.request)({
93
- httpMethod: 'GET',
94
- baseUri: this.getBaseUri(),
95
- relativePath: `${endpoints_1.ENDPOINT_SEARCH}/thread`,
96
- apiToken: this.apiToken,
97
- payload: params,
98
- customFetch: this.customFetch,
99
- }).then((response) => response.data);
100
- }
101
- /**
102
- * Searches within messages of a specific conversation.
103
- *
104
- * @param args - The arguments for searching within a conversation.
105
- * @param args.query - The search query string.
106
- * @param args.conversationId - The conversation ID to search in.
107
- * @param args.limit - Optional limit on number of results returned.
108
- * @param args.cursor - Optional cursor for pagination.
109
- * @returns Message IDs that match the search query.
110
- *
111
- * @example
112
- * ```typescript
113
- * const results = await api.search.searchConversation({
114
- * query: 'budget',
115
- * conversationId: '7YpL3oZ4kZ9vP7Q1tR2sX42',
116
- * })
117
- * ```
118
- */
119
- searchConversation(args) {
120
- const params = {
121
- query: args.query,
122
- conversation_id: args.conversationId,
123
- };
124
- if (args.limit)
125
- params.limit = args.limit;
126
- if (args.cursor)
127
- params.cursor = args.cursor;
128
- return (0, http_client_1.request)({
129
- httpMethod: 'GET',
130
- baseUri: this.getBaseUri(),
131
- relativePath: `${endpoints_1.ENDPOINT_SEARCH}/conversation`,
132
- apiToken: this.apiToken,
133
- payload: params,
134
- customFetch: this.customFetch,
135
- }).then((response) => response.data);
136
- }
137
- }
138
- exports.SearchClient = SearchClient;