@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,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversationMessagesClient = exports.ConversationMessageListSchema = 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 uuidv7_1 = require("../utils/uuidv7");
9
+ const base_client_1 = require("./base-client");
10
+ exports.ConversationMessageListSchema = zod_1.z.array(entities_1.ConversationMessageSchema);
11
+ /**
12
+ * Client for `/api/v1/conversation_messages/`. The SDK auto-generates the
13
+ * message `id` on `createMessage` when the caller doesn't supply one.
14
+ */
15
+ class ConversationMessagesClient extends base_client_1.BaseClient {
16
+ /** Lists messages in a conversation. */
17
+ getMessages(args) {
18
+ const params = { conversationId: args.conversationId };
19
+ if (args.newerThan)
20
+ params.newerThanTs = Math.floor(args.newerThan.getTime() / 1000);
21
+ if (args.olderThan)
22
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
23
+ if (args.limit)
24
+ params.limit = args.limit;
25
+ if (args.cursor)
26
+ params.cursor = args.cursor;
27
+ return (0, http_client_1.request)({
28
+ httpMethod: 'GET',
29
+ baseUri: this.getBaseUri(),
30
+ relativePath: `${endpoints_1.ENDPOINT_CONVERSATION_MESSAGES}/get`,
31
+ apiToken: this.apiToken,
32
+ payload: params,
33
+ customFetch: this.customFetch,
34
+ }).then((response) => exports.ConversationMessageListSchema.parse(response.data));
35
+ }
36
+ /** Fetches a single message by ID. */
37
+ getMessage(id) {
38
+ return this.simple('GET', 'getone', { id }, entities_1.ConversationMessageSchema);
39
+ }
40
+ /** Creates a new message. `id` is auto-generated if not supplied. */
41
+ createMessage(args) {
42
+ const params = {
43
+ conversationId: args.conversationId,
44
+ content: args.content,
45
+ id: (0, uuidv7_1.resolveCreateId)(args.id),
46
+ };
47
+ if (args.attachments)
48
+ params.attachments = args.attachments;
49
+ if (args.actions)
50
+ params.actions = args.actions;
51
+ if (args.directMentions)
52
+ params.directMentions = args.directMentions;
53
+ if (args.directGroupMentions)
54
+ params.directGroupMentions = args.directGroupMentions;
55
+ if (args.notify !== undefined)
56
+ params.notify = args.notify;
57
+ return this.simple('POST', 'add', params, entities_1.ConversationMessageSchema);
58
+ }
59
+ /** Updates a message. */
60
+ updateMessage(args) {
61
+ const params = { id: args.id, content: args.content };
62
+ if (args.attachments)
63
+ params.attachments = args.attachments;
64
+ if (args.actions)
65
+ params.actions = args.actions;
66
+ if (args.directMentions)
67
+ params.directMentions = args.directMentions;
68
+ if (args.directGroupMentions)
69
+ params.directGroupMentions = args.directGroupMentions;
70
+ return this.simple('POST', 'update', params, entities_1.ConversationMessageSchema);
71
+ }
72
+ /** Permanently deletes a message. */
73
+ deleteMessage(id) {
74
+ return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
75
+ }
76
+ simple(httpMethod, suffix, params, schema) {
77
+ return (0, http_client_1.request)({
78
+ httpMethod,
79
+ baseUri: this.getBaseUri(),
80
+ relativePath: `${endpoints_1.ENDPOINT_CONVERSATION_MESSAGES}/${suffix}`,
81
+ apiToken: this.apiToken,
82
+ payload: params,
83
+ customFetch: this.customFetch,
84
+ }).then((response) => schema.parse(response.data));
85
+ }
86
+ }
87
+ exports.ConversationMessagesClient = ConversationMessagesClient;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConversationsClient = exports.ConversationListSchema = 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 uuidv7_1 = require("../utils/uuidv7");
9
+ const base_client_1 = require("./base-client");
10
+ exports.ConversationListSchema = zod_1.z.array(entities_1.ConversationSchema);
11
+ const GetUnreadResponseSchema = zod_1.z.object({
12
+ data: zod_1.z.array(entities_1.UnreadConversationSchema),
13
+ version: zod_1.z.number().int(),
14
+ });
15
+ /**
16
+ * Client for `/api/v1/conversations/`. `getOrCreate` requires an `id` (the
17
+ * SDK auto-generates one for new conversations); the backend dedupes on
18
+ * `userIds`, so an existing conversation will be returned with its own
19
+ * already-assigned `id` and your generated one is silently dropped.
20
+ */
21
+ class ConversationsClient extends base_client_1.BaseClient {
22
+ /** Lists conversations in a workspace. */
23
+ getConversations(args) {
24
+ return (0, http_client_1.request)({
25
+ httpMethod: 'GET',
26
+ baseUri: this.getBaseUri(),
27
+ relativePath: `${endpoints_1.ENDPOINT_CONVERSATIONS}/get`,
28
+ apiToken: this.apiToken,
29
+ payload: args,
30
+ customFetch: this.customFetch,
31
+ }).then((response) => exports.ConversationListSchema.parse(response.data));
32
+ }
33
+ /** Fetches a single conversation by ID. */
34
+ getConversation(id) {
35
+ return this.simple('GET', 'getone', { id }, entities_1.ConversationSchema);
36
+ }
37
+ /**
38
+ * Gets an existing 1:1 / group conversation with `userIds`, or creates a
39
+ * new one. `id` is auto-generated if not supplied — on dedupe, the
40
+ * backend returns the existing conversation's `id` instead.
41
+ */
42
+ getOrCreateConversation(args) {
43
+ return this.simple('GET', 'get_or_create', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ConversationSchema);
44
+ }
45
+ /** Updates a conversation's title. */
46
+ updateConversation(args) {
47
+ const params = { id: args.id, title: args.title };
48
+ if (args.archived !== undefined)
49
+ params.archived = args.archived;
50
+ return this.simple('POST', 'update', params, entities_1.ConversationSchema);
51
+ }
52
+ archiveConversation(id) {
53
+ return this.simple('GET', 'archive', { id }, entities_1.ConversationSchema);
54
+ }
55
+ unarchiveConversation(id) {
56
+ return this.simple('GET', 'unarchive', { id }, entities_1.ConversationSchema);
57
+ }
58
+ addUser(args) {
59
+ return this.simple('POST', 'add_user', { ...args }, entities_1.ConversationSchema);
60
+ }
61
+ addUsers(args) {
62
+ return this.simple('POST', 'add_users', { ...args }, entities_1.ConversationSchema);
63
+ }
64
+ removeUser(args) {
65
+ return this.simple('POST', 'remove_user', { ...args }, entities_1.ConversationSchema);
66
+ }
67
+ removeUsers(args) {
68
+ return this.simple('POST', 'remove_users', { ...args }, entities_1.ConversationSchema);
69
+ }
70
+ markRead(args) {
71
+ return this.simple('POST', 'mark_read', { ...args }, entities_1.StatusOkSchema);
72
+ }
73
+ markUnread(args) {
74
+ return this.simple('POST', 'mark_unread', { ...args }, entities_1.StatusOkSchema);
75
+ }
76
+ /**
77
+ * Returns unread conversations for a workspace, paired with the unread
78
+ * version counter.
79
+ */
80
+ getUnread(workspaceId) {
81
+ return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
82
+ }
83
+ clearUnread(workspaceId) {
84
+ return this.simple('GET', 'clear_unread', { workspaceId }, entities_1.StatusOkSchema);
85
+ }
86
+ muteConversation(args) {
87
+ return this.simple('GET', 'mute', { ...args }, entities_1.ConversationSchema);
88
+ }
89
+ unmuteConversation(id) {
90
+ return this.simple('GET', 'unmute', { id }, entities_1.ConversationSchema);
91
+ }
92
+ simple(httpMethod, suffix, params, schema) {
93
+ return (0, http_client_1.request)({
94
+ httpMethod,
95
+ baseUri: this.getBaseUri(),
96
+ relativePath: `${endpoints_1.ENDPOINT_CONVERSATIONS}/${suffix}`,
97
+ apiToken: this.apiToken,
98
+ payload: params,
99
+ customFetch: this.customFetch,
100
+ }).then((response) => schema.parse(response.data));
101
+ }
102
+ }
103
+ exports.ConversationsClient = ConversationsClient;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GroupsClient = exports.GroupListSchema = 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 uuidv7_1 = require("../utils/uuidv7");
9
+ const base_client_1 = require("./base-client");
10
+ exports.GroupListSchema = zod_1.z.array(entities_1.GroupSchema);
11
+ /**
12
+ * Client for `/api/v1/groups/`. The broadcast markers `EVERYONE` /
13
+ * `EVERYONE_IN_THREAD` are NOT addressable through these endpoints — they
14
+ * only appear as members of `direct_group_mentions` / `groups` lists on
15
+ * thread/comment writes.
16
+ *
17
+ * `getone` / `update` / `remove` and the member-management ops all require
18
+ * `workspace_id` alongside the group `id`.
19
+ */
20
+ class GroupsClient extends base_client_1.BaseClient {
21
+ /** Lists groups in a workspace. */
22
+ getGroups(workspaceId) {
23
+ return (0, http_client_1.request)({
24
+ httpMethod: 'GET',
25
+ baseUri: this.getBaseUri(),
26
+ relativePath: `${endpoints_1.ENDPOINT_GROUPS}/get`,
27
+ apiToken: this.apiToken,
28
+ payload: { workspaceId },
29
+ customFetch: this.customFetch,
30
+ }).then((response) => exports.GroupListSchema.parse(response.data));
31
+ }
32
+ /** Fetches a single group by ID (requires `workspaceId`). */
33
+ getGroup(args) {
34
+ return this.simple('GET', 'getone', { ...args }, entities_1.GroupSchema);
35
+ }
36
+ /** Creates a new group. `id` is auto-generated if not supplied. */
37
+ createGroup(args) {
38
+ return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.GroupSchema);
39
+ }
40
+ /** Updates a group. Requires `workspaceId`. */
41
+ updateGroup(args) {
42
+ return this.simple('POST', 'update', { ...args }, entities_1.GroupSchema);
43
+ }
44
+ /** Permanently deletes a group. Requires `workspaceId`. */
45
+ deleteGroup(args) {
46
+ return this.simple('POST', 'remove', { ...args }, entities_1.StatusOkSchema);
47
+ }
48
+ addUser(args) {
49
+ return this.simple('POST', 'add_user', { ...args }, entities_1.StatusOkSchema);
50
+ }
51
+ addUsers(args) {
52
+ return this.simple('POST', 'add_users', { ...args }, entities_1.StatusOkSchema);
53
+ }
54
+ removeUser(args) {
55
+ return this.simple('POST', 'remove_user', { ...args }, entities_1.StatusOkSchema);
56
+ }
57
+ removeUsers(args) {
58
+ return this.simple('POST', 'remove_users', { ...args }, entities_1.StatusOkSchema);
59
+ }
60
+ simple(httpMethod, suffix, params, schema) {
61
+ return (0, http_client_1.request)({
62
+ httpMethod,
63
+ baseUri: this.getBaseUri(),
64
+ relativePath: `${endpoints_1.ENDPOINT_GROUPS}/${suffix}`,
65
+ apiToken: this.apiToken,
66
+ payload: params,
67
+ customFetch: this.customFetch,
68
+ }).then((response) => schema.parse(response.data));
69
+ }
70
+ }
71
+ exports.GroupsClient = GroupsClient;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InboxClient = 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
+ /** Client for `/api/v1/inbox/`. */
9
+ class InboxClient extends base_client_1.BaseClient {
10
+ /**
11
+ * Gets inbox items (threads).
12
+ */
13
+ getInbox(args) {
14
+ const params = { workspace_id: args.workspaceId };
15
+ const newerThan = args.newerThan ?? args.since;
16
+ if (newerThan)
17
+ params.newer_than_ts = Math.floor(newerThan.getTime() / 1000);
18
+ const olderThan = args.olderThan ?? args.until;
19
+ if (olderThan)
20
+ params.older_than_ts = Math.floor(olderThan.getTime() / 1000);
21
+ if (args.limit)
22
+ params.limit = args.limit;
23
+ if (args.cursor)
24
+ params.cursor = args.cursor;
25
+ if (args.archiveFilter)
26
+ params.archive_filter = args.archiveFilter;
27
+ return (0, http_client_1.request)({
28
+ httpMethod: 'GET',
29
+ baseUri: this.getBaseUri(),
30
+ relativePath: `${endpoints_1.ENDPOINT_INBOX}/get`,
31
+ apiToken: this.apiToken,
32
+ payload: params,
33
+ customFetch: this.customFetch,
34
+ }).then((response) => response.data.map((thread) => entities_1.InboxThreadSchema.parse(thread)));
35
+ }
36
+ /** Gets unread count for inbox. */
37
+ getCount(workspaceId) {
38
+ return (0, http_client_1.request)({
39
+ httpMethod: 'GET',
40
+ baseUri: this.getBaseUri(),
41
+ relativePath: `${endpoints_1.ENDPOINT_INBOX}/get_count`,
42
+ apiToken: this.apiToken,
43
+ payload: { workspace_id: workspaceId },
44
+ customFetch: this.customFetch,
45
+ }).then((response) => response.data.data);
46
+ }
47
+ /** Archives a thread in the inbox. */
48
+ archiveThread(id) {
49
+ return (0, http_client_1.request)({
50
+ httpMethod: 'POST',
51
+ baseUri: this.getBaseUri(),
52
+ relativePath: `${endpoints_1.ENDPOINT_INBOX}/archive`,
53
+ apiToken: this.apiToken,
54
+ payload: { id },
55
+ customFetch: this.customFetch,
56
+ }).then(() => undefined);
57
+ }
58
+ /** Unarchives a thread in the inbox. */
59
+ unarchiveThread(id) {
60
+ return (0, http_client_1.request)({
61
+ httpMethod: 'POST',
62
+ baseUri: this.getBaseUri(),
63
+ relativePath: `${endpoints_1.ENDPOINT_INBOX}/unarchive`,
64
+ apiToken: this.apiToken,
65
+ payload: { id },
66
+ customFetch: this.customFetch,
67
+ }).then(() => undefined);
68
+ }
69
+ /** Marks all inbox items as read in a workspace. */
70
+ markAllRead(workspaceId) {
71
+ return (0, http_client_1.request)({
72
+ httpMethod: 'POST',
73
+ baseUri: this.getBaseUri(),
74
+ relativePath: `${endpoints_1.ENDPOINT_INBOX}/mark_all_read`,
75
+ apiToken: this.apiToken,
76
+ payload: { workspace_id: workspaceId },
77
+ customFetch: this.customFetch,
78
+ }).then(() => undefined);
79
+ }
80
+ /** Archives all inbox items in a workspace. */
81
+ archiveAll(args) {
82
+ const params = { workspace_id: args.workspaceId };
83
+ if (args.channelIds)
84
+ params.channel_ids = args.channelIds;
85
+ const olderThan = args.olderThan ?? args.until;
86
+ if (olderThan)
87
+ params.older_than_ts = Math.floor(olderThan.getTime() / 1000);
88
+ return (0, http_client_1.request)({
89
+ httpMethod: 'POST',
90
+ baseUri: this.getBaseUri(),
91
+ relativePath: `${endpoints_1.ENDPOINT_INBOX}/archive_all`,
92
+ apiToken: this.apiToken,
93
+ payload: params,
94
+ customFetch: this.customFetch,
95
+ }).then(() => undefined);
96
+ }
97
+ }
98
+ exports.InboxClient = InboxClient;
@@ -0,0 +1,59 @@
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
+ /** Adds an emoji reaction to a thread, comment, or conversation message. */
21
+ add(args) {
22
+ return (0, http_client_1.request)({
23
+ httpMethod: 'POST',
24
+ baseUri: this.getBaseUri(),
25
+ relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/add`,
26
+ apiToken: this.apiToken,
27
+ payload: { ...reactionTarget(args), reaction: args.reaction },
28
+ customFetch: this.customFetch,
29
+ }).then(() => undefined);
30
+ }
31
+ /**
32
+ * Gets reactions for a thread, comment, or conversation message.
33
+ *
34
+ * Returns an object with emoji reactions as keys and arrays of user IDs as
35
+ * values, or null if no reactions.
36
+ */
37
+ get(args) {
38
+ return (0, http_client_1.request)({
39
+ httpMethod: 'GET',
40
+ baseUri: this.getBaseUri(),
41
+ relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/get`,
42
+ apiToken: this.apiToken,
43
+ payload: reactionTarget(args),
44
+ customFetch: this.customFetch,
45
+ }).then((response) => response.data);
46
+ }
47
+ /** Removes an emoji reaction from a thread, comment, or conversation message. */
48
+ remove(args) {
49
+ return (0, http_client_1.request)({
50
+ httpMethod: 'POST',
51
+ baseUri: this.getBaseUri(),
52
+ relativePath: `${endpoints_1.ENDPOINT_REACTIONS}/remove`,
53
+ apiToken: this.apiToken,
54
+ payload: { ...reactionTarget(args), reaction: args.reaction },
55
+ customFetch: this.customFetch,
56
+ }).then(() => undefined);
57
+ }
58
+ }
59
+ exports.ReactionsClient = ReactionsClient;
@@ -0,0 +1,88 @@
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
+ search(args) {
16
+ const params = { workspace_id: args.workspaceId };
17
+ if (args.query !== undefined)
18
+ params.query = args.query;
19
+ if (args.channelIds)
20
+ params.channel_ids = args.channelIds;
21
+ if (args.authorIds)
22
+ params.author_ids = args.authorIds;
23
+ if (args.mentionSelf !== undefined)
24
+ params.mention_self = args.mentionSelf;
25
+ if (args.dateFrom)
26
+ params.date_from = args.dateFrom;
27
+ if (args.dateTo)
28
+ params.date_to = args.dateTo;
29
+ if (args.limit)
30
+ params.limit = args.limit;
31
+ if (args.cursor)
32
+ params.cursor = args.cursor;
33
+ return (0, http_client_1.request)({
34
+ httpMethod: 'GET',
35
+ baseUri: this.getBaseUri(),
36
+ relativePath: endpoints_1.ENDPOINT_SEARCH,
37
+ apiToken: this.apiToken,
38
+ payload: params,
39
+ customFetch: this.customFetch,
40
+ }).then((response) => ({
41
+ ...response.data,
42
+ items: response.data.items.map((result) => entities_1.SearchResultSchema.parse(result)),
43
+ }));
44
+ }
45
+ /**
46
+ * Searches within comments of a specific thread.
47
+ */
48
+ searchThread(args) {
49
+ const params = {
50
+ query: args.query,
51
+ thread_id: args.threadId,
52
+ };
53
+ if (args.limit)
54
+ params.limit = args.limit;
55
+ if (args.cursor)
56
+ params.cursor = args.cursor;
57
+ return (0, http_client_1.request)({
58
+ httpMethod: 'GET',
59
+ baseUri: this.getBaseUri(),
60
+ relativePath: `${endpoints_1.ENDPOINT_SEARCH}/thread`,
61
+ apiToken: this.apiToken,
62
+ payload: params,
63
+ customFetch: this.customFetch,
64
+ }).then((response) => response.data);
65
+ }
66
+ /**
67
+ * Searches within messages of a specific conversation.
68
+ */
69
+ searchConversation(args) {
70
+ const params = {
71
+ query: args.query,
72
+ conversation_id: args.conversationId,
73
+ };
74
+ if (args.limit)
75
+ params.limit = args.limit;
76
+ if (args.cursor)
77
+ params.cursor = args.cursor;
78
+ return (0, http_client_1.request)({
79
+ httpMethod: 'GET',
80
+ baseUri: this.getBaseUri(),
81
+ relativePath: `${endpoints_1.ENDPOINT_SEARCH}/conversation`,
82
+ apiToken: this.apiToken,
83
+ payload: params,
84
+ customFetch: this.customFetch,
85
+ }).then((response) => response.data);
86
+ }
87
+ }
88
+ exports.SearchClient = SearchClient;
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThreadsClient = exports.ThreadListSchema = 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 uuidv7_1 = require("../utils/uuidv7");
9
+ const add_comment_helper_1 = require("./add-comment-helper");
10
+ const base_client_1 = require("./base-client");
11
+ exports.ThreadListSchema = zod_1.z.array(entities_1.ThreadSchema);
12
+ const GetUnreadResponseSchema = zod_1.z.object({
13
+ data: zod_1.z.array(entities_1.UnreadThreadSchema),
14
+ version: zod_1.z.number().int(),
15
+ inboxUnread: zod_1.z.number().int().nullable().optional(),
16
+ });
17
+ /**
18
+ * Client for `/api/v1/threads/`. The SDK auto-generates the thread `id` on
19
+ * `createThread` when the caller doesn't supply one.
20
+ */
21
+ class ThreadsClient extends base_client_1.BaseClient {
22
+ /**
23
+ * Lists threads. At least one of `channelId` / `workspaceId` is required.
24
+ * `newerThan` / `olderThan` (`Date`) are converted to the
25
+ * `newer_than_ts` / `older_than_ts` epoch-second params on the wire.
26
+ */
27
+ getThreads(args) {
28
+ const { newerThan, olderThan, newer_than_ts, older_than_ts, ...rest } = args;
29
+ const resolvedNewerThan = newerThan ? Math.floor(newerThan.getTime() / 1000) : newer_than_ts;
30
+ const resolvedOlderThan = olderThan ? Math.floor(olderThan.getTime() / 1000) : older_than_ts;
31
+ const params = {
32
+ ...rest,
33
+ ...(resolvedNewerThan != null ? { newer_than_ts: resolvedNewerThan } : {}),
34
+ ...(resolvedOlderThan != null ? { older_than_ts: resolvedOlderThan } : {}),
35
+ };
36
+ return (0, http_client_1.request)({
37
+ httpMethod: 'GET',
38
+ baseUri: this.getBaseUri(),
39
+ relativePath: `${endpoints_1.ENDPOINT_THREADS}/get`,
40
+ apiToken: this.apiToken,
41
+ payload: params,
42
+ customFetch: this.customFetch,
43
+ }).then((response) => exports.ThreadListSchema.parse(response.data));
44
+ }
45
+ /** Fetches a single thread by ID. */
46
+ getThread(id) {
47
+ return this.simple('GET', 'getone', { id }, entities_1.ThreadSchema);
48
+ }
49
+ /** Creates a new thread. `id` is auto-generated if not supplied. */
50
+ createThread(args) {
51
+ return this.simple('POST', 'add', { ...args, id: (0, uuidv7_1.resolveCreateId)(args.id) }, entities_1.ThreadSchema);
52
+ }
53
+ /** Partial update of an existing thread. */
54
+ updateThread(args) {
55
+ return this.simple('POST', 'update', { ...args }, entities_1.ThreadSchema);
56
+ }
57
+ /** Permanently deletes a thread. */
58
+ deleteThread(id) {
59
+ return this.simple('POST', 'remove', { id }, entities_1.StatusOkSchema);
60
+ }
61
+ /** Saves a thread (formerly "star"). */
62
+ saveThread(id) {
63
+ return this.simple('GET', 'save', { id }, entities_1.StatusOkSchema);
64
+ }
65
+ /** Unsaves a thread (formerly "unstar"). */
66
+ unsaveThread(id) {
67
+ return this.simple('GET', 'unsave', { id }, entities_1.StatusOkSchema);
68
+ }
69
+ pinThread(id) {
70
+ return this.simple('GET', 'pin', { id }, entities_1.StatusOkSchema);
71
+ }
72
+ unpinThread(id) {
73
+ return this.simple('GET', 'unpin', { id }, entities_1.StatusOkSchema);
74
+ }
75
+ /** Moves a thread to another channel. */
76
+ moveToChannel(args) {
77
+ return this.simple('GET', 'move_to_channel', { ...args }, entities_1.ThreadSchema);
78
+ }
79
+ markRead(args) {
80
+ return this.simple('POST', 'mark_read', { ...args }, entities_1.StatusOkSchema);
81
+ }
82
+ markUnread(args) {
83
+ return this.simple('POST', 'mark_unread', { ...args }, entities_1.StatusOkSchema);
84
+ }
85
+ markUnreadForOthers(args) {
86
+ return this.simple('POST', 'mark_unread_for_others', { ...args }, entities_1.StatusOkSchema);
87
+ }
88
+ /**
89
+ * Marks every thread in a workspace or channel as read. Exactly one of
90
+ * `workspaceId` / `channelId` should be set.
91
+ */
92
+ markAllRead(args) {
93
+ if (!args.workspaceId && !args.channelId) {
94
+ throw new Error('Either workspaceId or channelId is required');
95
+ }
96
+ return this.simple('POST', 'mark_all_read', { ...args }, entities_1.StatusOkSchema);
97
+ }
98
+ clearUnread(workspaceId) {
99
+ return this.simple('GET', 'clear_unread', { workspaceId }, entities_1.StatusOkSchema);
100
+ }
101
+ /**
102
+ * Returns unread threads for a workspace, paired with the unread version
103
+ * counter and (optionally) the inbox unread count.
104
+ */
105
+ getUnread(workspaceId) {
106
+ return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
107
+ }
108
+ muteThread(args) {
109
+ return this.simple('GET', 'mute', { ...args }, entities_1.ThreadSchema);
110
+ }
111
+ unmuteThread(id) {
112
+ return this.simple('GET', 'unmute', { id }, entities_1.ThreadSchema);
113
+ }
114
+ closeThread(args) {
115
+ return this.addCommentWithAction(args, 'close');
116
+ }
117
+ reopenThread(args) {
118
+ return this.addCommentWithAction(args, 'reopen');
119
+ }
120
+ addCommentWithAction(args, threadAction) {
121
+ const { id, ...rest } = args;
122
+ return (0, add_comment_helper_1.addCommentRequest)({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, { threadId: id, ...rest }, { threadAction });
123
+ }
124
+ simple(httpMethod, suffix, params, schema) {
125
+ return (0, http_client_1.request)({
126
+ httpMethod,
127
+ baseUri: this.getBaseUri(),
128
+ relativePath: `${endpoints_1.ENDPOINT_THREADS}/${suffix}`,
129
+ apiToken: this.apiToken,
130
+ payload: params,
131
+ customFetch: this.customFetch,
132
+ }).then((response) => schema.parse(response.data));
133
+ }
134
+ }
135
+ exports.ThreadsClient = ThreadsClient;