@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,79 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_CHANNELS } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { ChannelSchema, StatusOkSchema } from '../types/entities.js';
5
+ import { resolveCreateId } from '../utils/uuidv7.js';
6
+ import { BaseClient } from './base-client.js';
7
+ export const ChannelListSchema = z.array(ChannelSchema);
8
+ /**
9
+ * Client for `/api/v1/channels/`. The SDK auto-generates an `id` on
10
+ * `createChannel` when the caller doesn't supply one — pass your own `id`
11
+ * to keep an optimistic-UI ID stable through the round-trip.
12
+ */
13
+ export class ChannelsClient extends BaseClient {
14
+ /** Lists channels in a workspace. */
15
+ getChannels(args) {
16
+ return request({
17
+ httpMethod: 'GET',
18
+ baseUri: this.getBaseUri(),
19
+ relativePath: `${ENDPOINT_CHANNELS}/get`,
20
+ apiToken: this.apiToken,
21
+ payload: args,
22
+ customFetch: this.customFetch,
23
+ }).then((response) => ChannelListSchema.parse(response.data));
24
+ }
25
+ /** Fetches a single channel by ID. */
26
+ getChannel(id) {
27
+ return this.simple('GET', 'getone', { id }, ChannelSchema);
28
+ }
29
+ /** Creates a new channel. `id` is auto-generated if not supplied. */
30
+ createChannel(args) {
31
+ return this.simple('POST', 'add', { ...args, id: resolveCreateId(args.id) }, ChannelSchema);
32
+ }
33
+ /** Partial update of an existing channel. */
34
+ updateChannel(args) {
35
+ return this.simple('POST', 'update', { ...args }, ChannelSchema);
36
+ }
37
+ /** Updates the channel's view filter (`only_open` / `all` / `only_closed`). */
38
+ updateFilters(args) {
39
+ return this.simple('POST', 'update_filters', { ...args }, StatusOkSchema);
40
+ }
41
+ /** Permanently deletes a channel. */
42
+ deleteChannel(id) {
43
+ return this.simple('POST', 'remove', { id }, StatusOkSchema);
44
+ }
45
+ archiveChannel(id) {
46
+ return this.simple('POST', 'archive', { id }, StatusOkSchema);
47
+ }
48
+ unarchiveChannel(id) {
49
+ return this.simple('POST', 'unarchive', { id }, StatusOkSchema);
50
+ }
51
+ favoriteChannel(id) {
52
+ return this.simple('POST', 'favorite', { id }, StatusOkSchema);
53
+ }
54
+ unfavoriteChannel(id) {
55
+ return this.simple('POST', 'unfavorite', { id }, StatusOkSchema);
56
+ }
57
+ addUser(args) {
58
+ return this.simple('POST', 'add_user', { ...args }, ChannelSchema);
59
+ }
60
+ addUsers(args) {
61
+ return this.simple('POST', 'add_users', { ...args }, ChannelSchema);
62
+ }
63
+ removeUser(args) {
64
+ return this.simple('POST', 'remove_user', { ...args }, ChannelSchema);
65
+ }
66
+ removeUsers(args) {
67
+ return this.simple('POST', 'remove_users', { ...args }, ChannelSchema);
68
+ }
69
+ simple(httpMethod, suffix, params, schema) {
70
+ return request({
71
+ httpMethod,
72
+ baseUri: this.getBaseUri(),
73
+ relativePath: `${ENDPOINT_CHANNELS}/${suffix}`,
74
+ apiToken: this.apiToken,
75
+ payload: params,
76
+ customFetch: this.customFetch,
77
+ }).then((response) => schema.parse(response.data));
78
+ }
79
+ }
@@ -0,0 +1,89 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_COMMENTS } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { CommentSchema, StatusOkSchema } from '../types/entities.js';
5
+ import { addCommentRequest } from './add-comment-helper.js';
6
+ import { BaseClient } from './base-client.js';
7
+ export const CommentListSchema = z.array(CommentSchema);
8
+ /**
9
+ * Client for `/api/v1/comments/`. The SDK auto-generates the comment `id`
10
+ * on `createComment` when the caller doesn't supply one.
11
+ */
12
+ export class CommentsClient extends BaseClient {
13
+ /**
14
+ * Lists comments in a thread. `newerThan` / `olderThan` (`Date`) are
15
+ * converted to `newer_than_ts` / `older_than_ts` epoch seconds on the
16
+ * wire.
17
+ */
18
+ getComments(args) {
19
+ const params = { threadId: args.threadId };
20
+ const newerThan = args.newerThan ?? args.from;
21
+ if (newerThan)
22
+ params.newerThanTs = Math.floor(newerThan.getTime() / 1000);
23
+ if (args.olderThan)
24
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
25
+ if (args.limit)
26
+ params.limit = args.limit;
27
+ return request({
28
+ httpMethod: 'GET',
29
+ baseUri: this.getBaseUri(),
30
+ relativePath: `${ENDPOINT_COMMENTS}/get`,
31
+ apiToken: this.apiToken,
32
+ payload: params,
33
+ customFetch: this.customFetch,
34
+ }).then((response) => CommentListSchema.parse(response.data));
35
+ }
36
+ /** Fetches a single comment by ID. The API wraps it in `{comment: ...}`. */
37
+ getComment(id) {
38
+ const wrappedSchema = z.object({ comment: CommentSchema }).transform((data) => data.comment);
39
+ return request({
40
+ httpMethod: 'GET',
41
+ baseUri: this.getBaseUri(),
42
+ relativePath: `${ENDPOINT_COMMENTS}/getone`,
43
+ apiToken: this.apiToken,
44
+ payload: { id },
45
+ customFetch: this.customFetch,
46
+ }).then((response) => wrappedSchema.parse(response.data));
47
+ }
48
+ /**
49
+ * Creates a new comment. `id` is auto-generated if not supplied.
50
+ */
51
+ createComment(args) {
52
+ return addCommentRequest({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, args);
53
+ }
54
+ /** Updates a comment. */
55
+ updateComment(args) {
56
+ return request({
57
+ httpMethod: 'POST',
58
+ baseUri: this.getBaseUri(),
59
+ relativePath: `${ENDPOINT_COMMENTS}/update`,
60
+ apiToken: this.apiToken,
61
+ payload: { ...args },
62
+ customFetch: this.customFetch,
63
+ }).then((response) => CommentSchema.parse(response.data));
64
+ }
65
+ /** Permanently deletes a comment. */
66
+ deleteComment(id) {
67
+ return request({
68
+ httpMethod: 'POST',
69
+ baseUri: this.getBaseUri(),
70
+ relativePath: `${ENDPOINT_COMMENTS}/remove`,
71
+ apiToken: this.apiToken,
72
+ payload: { id },
73
+ customFetch: this.customFetch,
74
+ }).then((response) => StatusOkSchema.parse(response.data));
75
+ }
76
+ /**
77
+ * Marks the user's read position in a thread. Comment IDs are strings.
78
+ */
79
+ markPosition(args) {
80
+ return request({
81
+ httpMethod: 'POST',
82
+ baseUri: this.getBaseUri(),
83
+ relativePath: `${ENDPOINT_COMMENTS}/mark_position`,
84
+ apiToken: this.apiToken,
85
+ payload: { threadId: args.threadId, commentId: args.commentId },
86
+ customFetch: this.customFetch,
87
+ }).then((response) => StatusOkSchema.parse(response.data));
88
+ }
89
+ }
@@ -0,0 +1,83 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_CONVERSATION_MESSAGES } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { ConversationMessageSchema, StatusOkSchema, } from '../types/entities.js';
5
+ import { resolveCreateId } from '../utils/uuidv7.js';
6
+ import { BaseClient } from './base-client.js';
7
+ export const ConversationMessageListSchema = z.array(ConversationMessageSchema);
8
+ /**
9
+ * Client for `/api/v1/conversation_messages/`. The SDK auto-generates the
10
+ * message `id` on `createMessage` when the caller doesn't supply one.
11
+ */
12
+ export class ConversationMessagesClient extends BaseClient {
13
+ /** Lists messages in a conversation. */
14
+ getMessages(args) {
15
+ const params = { conversationId: args.conversationId };
16
+ if (args.newerThan)
17
+ params.newerThanTs = Math.floor(args.newerThan.getTime() / 1000);
18
+ if (args.olderThan)
19
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
20
+ if (args.limit)
21
+ params.limit = args.limit;
22
+ if (args.cursor)
23
+ params.cursor = args.cursor;
24
+ return request({
25
+ httpMethod: 'GET',
26
+ baseUri: this.getBaseUri(),
27
+ relativePath: `${ENDPOINT_CONVERSATION_MESSAGES}/get`,
28
+ apiToken: this.apiToken,
29
+ payload: params,
30
+ customFetch: this.customFetch,
31
+ }).then((response) => ConversationMessageListSchema.parse(response.data));
32
+ }
33
+ /** Fetches a single message by ID. */
34
+ getMessage(id) {
35
+ return this.simple('GET', 'getone', { id }, ConversationMessageSchema);
36
+ }
37
+ /** Creates a new message. `id` is auto-generated if not supplied. */
38
+ createMessage(args) {
39
+ const params = {
40
+ conversationId: args.conversationId,
41
+ content: args.content,
42
+ id: resolveCreateId(args.id),
43
+ };
44
+ if (args.attachments)
45
+ params.attachments = args.attachments;
46
+ if (args.actions)
47
+ params.actions = args.actions;
48
+ if (args.directMentions)
49
+ params.directMentions = args.directMentions;
50
+ if (args.directGroupMentions)
51
+ params.directGroupMentions = args.directGroupMentions;
52
+ if (args.notify !== undefined)
53
+ params.notify = args.notify;
54
+ return this.simple('POST', 'add', params, ConversationMessageSchema);
55
+ }
56
+ /** Updates a message. */
57
+ updateMessage(args) {
58
+ const params = { id: args.id, content: args.content };
59
+ if (args.attachments)
60
+ params.attachments = args.attachments;
61
+ if (args.actions)
62
+ params.actions = args.actions;
63
+ if (args.directMentions)
64
+ params.directMentions = args.directMentions;
65
+ if (args.directGroupMentions)
66
+ params.directGroupMentions = args.directGroupMentions;
67
+ return this.simple('POST', 'update', params, ConversationMessageSchema);
68
+ }
69
+ /** Permanently deletes a message. */
70
+ deleteMessage(id) {
71
+ return this.simple('POST', 'remove', { id }, StatusOkSchema);
72
+ }
73
+ simple(httpMethod, suffix, params, schema) {
74
+ return request({
75
+ httpMethod,
76
+ baseUri: this.getBaseUri(),
77
+ relativePath: `${ENDPOINT_CONVERSATION_MESSAGES}/${suffix}`,
78
+ apiToken: this.apiToken,
79
+ payload: params,
80
+ customFetch: this.customFetch,
81
+ }).then((response) => schema.parse(response.data));
82
+ }
83
+ }
@@ -0,0 +1,99 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_CONVERSATIONS } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { ConversationSchema, StatusOkSchema, UnreadConversationSchema, } from '../types/entities.js';
5
+ import { resolveCreateId } from '../utils/uuidv7.js';
6
+ import { BaseClient } from './base-client.js';
7
+ export const ConversationListSchema = z.array(ConversationSchema);
8
+ const GetUnreadResponseSchema = z.object({
9
+ data: z.array(UnreadConversationSchema),
10
+ version: z.number().int(),
11
+ });
12
+ /**
13
+ * Client for `/api/v1/conversations/`. `getOrCreate` requires an `id` (the
14
+ * SDK auto-generates one for new conversations); the backend dedupes on
15
+ * `userIds`, so an existing conversation will be returned with its own
16
+ * already-assigned `id` and your generated one is silently dropped.
17
+ */
18
+ export class ConversationsClient extends BaseClient {
19
+ /** Lists conversations in a workspace. */
20
+ getConversations(args) {
21
+ return request({
22
+ httpMethod: 'GET',
23
+ baseUri: this.getBaseUri(),
24
+ relativePath: `${ENDPOINT_CONVERSATIONS}/get`,
25
+ apiToken: this.apiToken,
26
+ payload: args,
27
+ customFetch: this.customFetch,
28
+ }).then((response) => ConversationListSchema.parse(response.data));
29
+ }
30
+ /** Fetches a single conversation by ID. */
31
+ getConversation(id) {
32
+ return this.simple('GET', 'getone', { id }, ConversationSchema);
33
+ }
34
+ /**
35
+ * Gets an existing 1:1 / group conversation with `userIds`, or creates a
36
+ * new one. `id` is auto-generated if not supplied — on dedupe, the
37
+ * backend returns the existing conversation's `id` instead.
38
+ */
39
+ getOrCreateConversation(args) {
40
+ return this.simple('GET', 'get_or_create', { ...args, id: resolveCreateId(args.id) }, ConversationSchema);
41
+ }
42
+ /** Updates a conversation's title. */
43
+ updateConversation(args) {
44
+ const params = { id: args.id, title: args.title };
45
+ if (args.archived !== undefined)
46
+ params.archived = args.archived;
47
+ return this.simple('POST', 'update', params, ConversationSchema);
48
+ }
49
+ archiveConversation(id) {
50
+ return this.simple('GET', 'archive', { id }, ConversationSchema);
51
+ }
52
+ unarchiveConversation(id) {
53
+ return this.simple('GET', 'unarchive', { id }, ConversationSchema);
54
+ }
55
+ addUser(args) {
56
+ return this.simple('POST', 'add_user', { ...args }, ConversationSchema);
57
+ }
58
+ addUsers(args) {
59
+ return this.simple('POST', 'add_users', { ...args }, ConversationSchema);
60
+ }
61
+ removeUser(args) {
62
+ return this.simple('POST', 'remove_user', { ...args }, ConversationSchema);
63
+ }
64
+ removeUsers(args) {
65
+ return this.simple('POST', 'remove_users', { ...args }, ConversationSchema);
66
+ }
67
+ markRead(args) {
68
+ return this.simple('POST', 'mark_read', { ...args }, StatusOkSchema);
69
+ }
70
+ markUnread(args) {
71
+ return this.simple('POST', 'mark_unread', { ...args }, StatusOkSchema);
72
+ }
73
+ /**
74
+ * Returns unread conversations for a workspace, paired with the unread
75
+ * version counter.
76
+ */
77
+ getUnread(workspaceId) {
78
+ return this.simple('GET', 'get_unread', { workspaceId }, GetUnreadResponseSchema);
79
+ }
80
+ clearUnread(workspaceId) {
81
+ return this.simple('GET', 'clear_unread', { workspaceId }, StatusOkSchema);
82
+ }
83
+ muteConversation(args) {
84
+ return this.simple('GET', 'mute', { ...args }, ConversationSchema);
85
+ }
86
+ unmuteConversation(id) {
87
+ return this.simple('GET', 'unmute', { id }, ConversationSchema);
88
+ }
89
+ simple(httpMethod, suffix, params, schema) {
90
+ return request({
91
+ httpMethod,
92
+ baseUri: this.getBaseUri(),
93
+ relativePath: `${ENDPOINT_CONVERSATIONS}/${suffix}`,
94
+ apiToken: this.apiToken,
95
+ payload: params,
96
+ customFetch: this.customFetch,
97
+ }).then((response) => schema.parse(response.data));
98
+ }
99
+ }
@@ -0,0 +1,67 @@
1
+ import { z } from 'zod';
2
+ import { ENDPOINT_GROUPS } from '../consts/endpoints.js';
3
+ import { request } from '../transport/http-client.js';
4
+ import { GroupSchema, StatusOkSchema } from '../types/entities.js';
5
+ import { resolveCreateId } from '../utils/uuidv7.js';
6
+ import { BaseClient } from './base-client.js';
7
+ export const GroupListSchema = z.array(GroupSchema);
8
+ /**
9
+ * Client for `/api/v1/groups/`. The broadcast markers `EVERYONE` /
10
+ * `EVERYONE_IN_THREAD` are NOT addressable through these endpoints — they
11
+ * only appear as members of `direct_group_mentions` / `groups` lists on
12
+ * thread/comment writes.
13
+ *
14
+ * `getone` / `update` / `remove` and the member-management ops all require
15
+ * `workspace_id` alongside the group `id`.
16
+ */
17
+ export class GroupsClient extends BaseClient {
18
+ /** Lists groups in a workspace. */
19
+ getGroups(workspaceId) {
20
+ return request({
21
+ httpMethod: 'GET',
22
+ baseUri: this.getBaseUri(),
23
+ relativePath: `${ENDPOINT_GROUPS}/get`,
24
+ apiToken: this.apiToken,
25
+ payload: { workspaceId },
26
+ customFetch: this.customFetch,
27
+ }).then((response) => GroupListSchema.parse(response.data));
28
+ }
29
+ /** Fetches a single group by ID (requires `workspaceId`). */
30
+ getGroup(args) {
31
+ return this.simple('GET', 'getone', { ...args }, GroupSchema);
32
+ }
33
+ /** Creates a new group. `id` is auto-generated if not supplied. */
34
+ createGroup(args) {
35
+ return this.simple('POST', 'add', { ...args, id: resolveCreateId(args.id) }, GroupSchema);
36
+ }
37
+ /** Updates a group. Requires `workspaceId`. */
38
+ updateGroup(args) {
39
+ return this.simple('POST', 'update', { ...args }, GroupSchema);
40
+ }
41
+ /** Permanently deletes a group. Requires `workspaceId`. */
42
+ deleteGroup(args) {
43
+ return this.simple('POST', 'remove', { ...args }, StatusOkSchema);
44
+ }
45
+ addUser(args) {
46
+ return this.simple('POST', 'add_user', { ...args }, StatusOkSchema);
47
+ }
48
+ addUsers(args) {
49
+ return this.simple('POST', 'add_users', { ...args }, StatusOkSchema);
50
+ }
51
+ removeUser(args) {
52
+ return this.simple('POST', 'remove_user', { ...args }, StatusOkSchema);
53
+ }
54
+ removeUsers(args) {
55
+ return this.simple('POST', 'remove_users', { ...args }, StatusOkSchema);
56
+ }
57
+ simple(httpMethod, suffix, params, schema) {
58
+ return request({
59
+ httpMethod,
60
+ baseUri: this.getBaseUri(),
61
+ relativePath: `${ENDPOINT_GROUPS}/${suffix}`,
62
+ apiToken: this.apiToken,
63
+ payload: params,
64
+ customFetch: this.customFetch,
65
+ }).then((response) => schema.parse(response.data));
66
+ }
67
+ }
@@ -0,0 +1,94 @@
1
+ import { ENDPOINT_INBOX } from '../consts/endpoints.js';
2
+ import { request } from '../transport/http-client.js';
3
+ import { InboxThreadSchema } from '../types/entities.js';
4
+ import { BaseClient } from './base-client.js';
5
+ /** Client for `/api/v1/inbox/`. */
6
+ export class InboxClient extends BaseClient {
7
+ /**
8
+ * Gets inbox items (threads).
9
+ */
10
+ getInbox(args) {
11
+ const params = { workspace_id: args.workspaceId };
12
+ const newerThan = args.newerThan ?? args.since;
13
+ if (newerThan)
14
+ params.newer_than_ts = Math.floor(newerThan.getTime() / 1000);
15
+ const olderThan = args.olderThan ?? args.until;
16
+ if (olderThan)
17
+ params.older_than_ts = Math.floor(olderThan.getTime() / 1000);
18
+ if (args.limit)
19
+ params.limit = args.limit;
20
+ if (args.cursor)
21
+ params.cursor = args.cursor;
22
+ if (args.archiveFilter)
23
+ params.archive_filter = args.archiveFilter;
24
+ return request({
25
+ httpMethod: 'GET',
26
+ baseUri: this.getBaseUri(),
27
+ relativePath: `${ENDPOINT_INBOX}/get`,
28
+ apiToken: this.apiToken,
29
+ payload: params,
30
+ customFetch: this.customFetch,
31
+ }).then((response) => response.data.map((thread) => InboxThreadSchema.parse(thread)));
32
+ }
33
+ /** Gets unread count for inbox. */
34
+ getCount(workspaceId) {
35
+ return request({
36
+ httpMethod: 'GET',
37
+ baseUri: this.getBaseUri(),
38
+ relativePath: `${ENDPOINT_INBOX}/get_count`,
39
+ apiToken: this.apiToken,
40
+ payload: { workspace_id: workspaceId },
41
+ customFetch: this.customFetch,
42
+ }).then((response) => response.data.data);
43
+ }
44
+ /** Archives a thread in the inbox. */
45
+ archiveThread(id) {
46
+ return request({
47
+ httpMethod: 'POST',
48
+ baseUri: this.getBaseUri(),
49
+ relativePath: `${ENDPOINT_INBOX}/archive`,
50
+ apiToken: this.apiToken,
51
+ payload: { id },
52
+ customFetch: this.customFetch,
53
+ }).then(() => undefined);
54
+ }
55
+ /** Unarchives a thread in the inbox. */
56
+ unarchiveThread(id) {
57
+ return request({
58
+ httpMethod: 'POST',
59
+ baseUri: this.getBaseUri(),
60
+ relativePath: `${ENDPOINT_INBOX}/unarchive`,
61
+ apiToken: this.apiToken,
62
+ payload: { id },
63
+ customFetch: this.customFetch,
64
+ }).then(() => undefined);
65
+ }
66
+ /** Marks all inbox items as read in a workspace. */
67
+ markAllRead(workspaceId) {
68
+ return request({
69
+ httpMethod: 'POST',
70
+ baseUri: this.getBaseUri(),
71
+ relativePath: `${ENDPOINT_INBOX}/mark_all_read`,
72
+ apiToken: this.apiToken,
73
+ payload: { workspace_id: workspaceId },
74
+ customFetch: this.customFetch,
75
+ }).then(() => undefined);
76
+ }
77
+ /** Archives all inbox items in a workspace. */
78
+ archiveAll(args) {
79
+ const params = { workspace_id: args.workspaceId };
80
+ if (args.channelIds)
81
+ params.channel_ids = args.channelIds;
82
+ const olderThan = args.olderThan ?? args.until;
83
+ if (olderThan)
84
+ params.older_than_ts = Math.floor(olderThan.getTime() / 1000);
85
+ return request({
86
+ httpMethod: 'POST',
87
+ baseUri: this.getBaseUri(),
88
+ relativePath: `${ENDPOINT_INBOX}/archive_all`,
89
+ apiToken: this.apiToken,
90
+ payload: params,
91
+ customFetch: this.customFetch,
92
+ }).then(() => undefined);
93
+ }
94
+ }
@@ -0,0 +1,55 @@
1
+ import { ENDPOINT_REACTIONS } from '../consts/endpoints.js';
2
+ import { request } from '../transport/http-client.js';
3
+ import { BaseClient } from './base-client.js';
4
+ function reactionTarget(args) {
5
+ if (args.threadId)
6
+ return { threadId: args.threadId };
7
+ if (args.commentId)
8
+ return { commentId: args.commentId };
9
+ if (args.messageId)
10
+ return { messageId: args.messageId };
11
+ throw new Error('Must provide one of: threadId, commentId, or messageId');
12
+ }
13
+ /**
14
+ * Client for interacting with Comms reaction endpoints.
15
+ */
16
+ export class ReactionsClient extends BaseClient {
17
+ /** Adds an emoji reaction to a thread, comment, or conversation message. */
18
+ add(args) {
19
+ return request({
20
+ httpMethod: 'POST',
21
+ baseUri: this.getBaseUri(),
22
+ relativePath: `${ENDPOINT_REACTIONS}/add`,
23
+ apiToken: this.apiToken,
24
+ payload: { ...reactionTarget(args), reaction: args.reaction },
25
+ customFetch: this.customFetch,
26
+ }).then(() => undefined);
27
+ }
28
+ /**
29
+ * Gets reactions for a thread, comment, or conversation message.
30
+ *
31
+ * Returns an object with emoji reactions as keys and arrays of user IDs as
32
+ * values, or null if no reactions.
33
+ */
34
+ get(args) {
35
+ return request({
36
+ httpMethod: 'GET',
37
+ baseUri: this.getBaseUri(),
38
+ relativePath: `${ENDPOINT_REACTIONS}/get`,
39
+ apiToken: this.apiToken,
40
+ payload: reactionTarget(args),
41
+ customFetch: this.customFetch,
42
+ }).then((response) => response.data);
43
+ }
44
+ /** Removes an emoji reaction from a thread, comment, or conversation message. */
45
+ remove(args) {
46
+ return request({
47
+ httpMethod: 'POST',
48
+ baseUri: this.getBaseUri(),
49
+ relativePath: `${ENDPOINT_REACTIONS}/remove`,
50
+ apiToken: this.apiToken,
51
+ payload: { ...reactionTarget(args), reaction: args.reaction },
52
+ customFetch: this.customFetch,
53
+ }).then(() => undefined);
54
+ }
55
+ }
@@ -0,0 +1,84 @@
1
+ import { ENDPOINT_SEARCH } from '../consts/endpoints.js';
2
+ import { request } from '../transport/http-client.js';
3
+ import { SearchResultSchema, } from '../types/entities.js';
4
+ import { BaseClient } from './base-client.js';
5
+ /**
6
+ * Client for interacting with Comms search endpoints.
7
+ */
8
+ export class SearchClient extends BaseClient {
9
+ /**
10
+ * Searches across all threads and conversations in a workspace.
11
+ */
12
+ search(args) {
13
+ const params = { workspace_id: args.workspaceId };
14
+ if (args.query !== undefined)
15
+ params.query = args.query;
16
+ if (args.channelIds)
17
+ params.channel_ids = args.channelIds;
18
+ if (args.authorIds)
19
+ params.author_ids = args.authorIds;
20
+ if (args.mentionSelf !== undefined)
21
+ params.mention_self = args.mentionSelf;
22
+ if (args.dateFrom)
23
+ params.date_from = args.dateFrom;
24
+ if (args.dateTo)
25
+ params.date_to = args.dateTo;
26
+ if (args.limit)
27
+ params.limit = args.limit;
28
+ if (args.cursor)
29
+ params.cursor = args.cursor;
30
+ return request({
31
+ httpMethod: 'GET',
32
+ baseUri: this.getBaseUri(),
33
+ relativePath: ENDPOINT_SEARCH,
34
+ apiToken: this.apiToken,
35
+ payload: params,
36
+ customFetch: this.customFetch,
37
+ }).then((response) => ({
38
+ ...response.data,
39
+ items: response.data.items.map((result) => SearchResultSchema.parse(result)),
40
+ }));
41
+ }
42
+ /**
43
+ * Searches within comments of a specific thread.
44
+ */
45
+ searchThread(args) {
46
+ const params = {
47
+ query: args.query,
48
+ thread_id: args.threadId,
49
+ };
50
+ if (args.limit)
51
+ params.limit = args.limit;
52
+ if (args.cursor)
53
+ params.cursor = args.cursor;
54
+ return request({
55
+ httpMethod: 'GET',
56
+ baseUri: this.getBaseUri(),
57
+ relativePath: `${ENDPOINT_SEARCH}/thread`,
58
+ apiToken: this.apiToken,
59
+ payload: params,
60
+ customFetch: this.customFetch,
61
+ }).then((response) => response.data);
62
+ }
63
+ /**
64
+ * Searches within messages of a specific conversation.
65
+ */
66
+ searchConversation(args) {
67
+ const params = {
68
+ query: args.query,
69
+ conversation_id: args.conversationId,
70
+ };
71
+ if (args.limit)
72
+ params.limit = args.limit;
73
+ if (args.cursor)
74
+ params.cursor = args.cursor;
75
+ return request({
76
+ httpMethod: 'GET',
77
+ baseUri: this.getBaseUri(),
78
+ relativePath: `${ENDPOINT_SEARCH}/conversation`,
79
+ apiToken: this.apiToken,
80
+ payload: params,
81
+ customFetch: this.customFetch,
82
+ }).then((response) => response.data);
83
+ }
84
+ }