@doist/comms-sdk 0.9.0 → 0.11.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.
@@ -31,26 +31,55 @@ class ConversationsClient extends base_client_1.BaseClient {
31
31
  : exports.ConversationListSchema;
32
32
  }
33
33
  /**
34
- * Gets all conversations for a workspace.
34
+ * Gets a page of conversations for a workspace, newest activity first.
35
+ * The server returns at most 500 rows per request (20 by default); pass
36
+ * the last row's `lastActive`/`id` as `olderThan`/`beforeId` to fetch
37
+ * the next page. Paired, they form a strict compound boundary, so pages
38
+ * never repeat rows. Omitting `archived` returns active and archived
39
+ * conversations mixed.
35
40
  *
36
41
  * @param args - The arguments for getting conversations.
37
42
  * @param args.workspaceId - The workspace ID.
38
- * @param args.archived - Optional flag to include archived conversations.
43
+ * @param args.archived - Optional flag to filter archived (true) or active (false) conversations.
44
+ * @param args.olderThan - Optional date to get conversations last active before.
45
+ * @param args.beforeId - Optional conversation id. Paired with olderThan it forms the
46
+ * strict compound cursor; alone it pages by conversation id order instead.
47
+ * @param args.limit - Optional page size (server default 20, max 500).
39
48
  * @returns An array of conversation objects.
40
49
  *
41
50
  * @example
42
51
  * ```typescript
43
- * const conversations = await api.conversations.getConversations({ workspaceId: 123 })
44
- * conversations.forEach(c => console.log(c.title))
52
+ * const page = await api.conversations.getConversations({ workspaceId: 123, limit: 500 })
53
+ * const last = page.at(-1)
54
+ * const nextPage = last
55
+ * ? await api.conversations.getConversations({
56
+ * workspaceId: 123,
57
+ * limit: 500,
58
+ * olderThan: last.lastActive,
59
+ * beforeId: last.id,
60
+ * })
61
+ * : []
45
62
  * ```
46
63
  */
47
64
  getConversations(args) {
65
+ // Fields are picked explicitly (matching getThreads/getComments) so a
66
+ // future Date field can't silently reach the generic snake-casing,
67
+ // which would turn it into an empty object on the wire.
68
+ const params = { workspaceId: args.workspaceId };
69
+ if (args.archived != null)
70
+ params.archived = args.archived;
71
+ if (args.olderThan)
72
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
73
+ if (args.beforeId != null)
74
+ params.beforeId = args.beforeId;
75
+ if (args.limit != null)
76
+ params.limit = args.limit;
48
77
  return (0, http_client_1.request)({
49
78
  httpMethod: 'GET',
50
79
  baseUri: this.getBaseUri(),
51
80
  relativePath: `${endpoints_1.ENDPOINT_CONVERSATIONS}/get`,
52
81
  apiToken: this.apiToken,
53
- payload: args,
82
+ payload: params,
54
83
  customFetch: this.customFetch,
55
84
  }).then((response) => this.conversationListSchema.parse(response.data));
56
85
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SearchResultSchema = exports.SEARCH_RESULT_TYPES = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.ConversationMessageObjectSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.CommentObjectSchema = exports.ConversationSchema = exports.ConversationObjectSchema = exports.GroupSchema = exports.ThreadSchema = exports.ThreadObjectSchema = exports.ChannelSchema = exports.ChannelObjectSchema = exports.WorkspaceSchema = exports.UserSchema = exports.BaseUserSchema = exports.RequestAttachmentSchema = exports.AttachmentSchema = exports.HookSubscribeResponseSchema = exports.StatusOkSchema = exports.SystemMessageSchema = void 0;
3
+ exports.SearchResultSchema = exports.ConversationSearchResultSchema = exports.ThreadSearchResultSchema = exports.SEARCH_RESULT_TYPES = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.ConversationMessageObjectSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.CommentObjectSchema = exports.ConversationSchema = exports.ConversationObjectSchema = exports.GroupSchema = exports.ThreadSchema = exports.ThreadObjectSchema = exports.ChannelSchema = exports.ChannelObjectSchema = exports.WorkspaceSchema = exports.UserSchema = exports.BaseUserSchema = exports.RequestAttachmentSchema = exports.AttachmentSchema = exports.HookSubscribeResponseSchema = exports.StatusOkSchema = exports.SystemMessageSchema = void 0;
4
4
  exports.createChannelSchema = createChannelSchema;
5
5
  exports.createThreadSchema = createThreadSchema;
6
6
  exports.createConversationSchema = createConversationSchema;
@@ -420,32 +420,43 @@ exports.UnreadConversationSchema = zod_1.z.object({
420
420
  directMention: zod_1.z.boolean(),
421
421
  });
422
422
  // SearchResult entity from API.
423
- // The API currently only emits 'thread' and 'conversation' results: a match inside a
423
+ // The API emits 'thread' and 'conversation' results: a match inside a
424
424
  // comment is returned as a 'thread' result with `commentId` set, and a match inside a
425
425
  // message as a 'conversation' result with `messageId` set.
426
- exports.SEARCH_RESULT_TYPES = ['thread', 'comment', 'message', 'conversation'];
427
- exports.SearchResultSchema = zod_1.z.object({
426
+ const searchResultBaseShape = {
428
427
  /**
429
428
  * Opaque search-result key in the form `thread_<threadId>` or
430
429
  * `conversation_<conversationId>`. Unique per result; not a Comms object id — use
431
430
  * `threadId`, `conversationId`, `commentId`, or `messageId` to reference objects.
432
431
  */
433
432
  id: zod_1.z.string(),
434
- type: zod_1.z.enum(exports.SEARCH_RESULT_TYPES),
435
433
  snippet: zod_1.z.string(),
436
434
  snippetCreatorId: zod_1.z.number(),
437
435
  snippetLastUpdated: zod_1.z.date(),
438
- /** The owning thread id. Set by the API on 'thread' results. */
439
- threadId: zod_1.z.string().nullable().optional(),
440
- /** The owning conversation id. Set by the API on 'conversation' results. */
441
- conversationId: zod_1.z.string().nullable().optional(),
442
- /** The matched comment id, set on 'thread' results when the match is a comment. */
443
- commentId: zod_1.z.string().nullable().optional(),
444
- /** The matched message id, set by the API on 'conversation' results. */
445
- messageId: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).transform(String).nullable().optional(),
446
436
  channelId: zod_1.z.string().nullable().optional(),
447
437
  channelName: zod_1.z.string().nullable().optional(),
448
438
  channelColor: zod_1.z.number().nullable().optional(),
449
439
  title: zod_1.z.string().nullable().optional(),
450
440
  closed: zod_1.z.boolean().nullable().optional(),
441
+ };
442
+ exports.SEARCH_RESULT_TYPES = ['thread', 'conversation'];
443
+ exports.ThreadSearchResultSchema = zod_1.z.object({
444
+ ...searchResultBaseShape,
445
+ type: zod_1.z.literal('thread'),
446
+ /** The owning thread id. */
447
+ threadId: zod_1.z.string(),
448
+ /** The matched comment id, set when the match is a comment. */
449
+ commentId: zod_1.z.string().nullable().optional(),
450
+ });
451
+ exports.ConversationSearchResultSchema = zod_1.z.object({
452
+ ...searchResultBaseShape,
453
+ type: zod_1.z.literal('conversation'),
454
+ /** The owning conversation id. */
455
+ conversationId: zod_1.z.string(),
456
+ /** The matched message id. */
457
+ messageId: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).transform(String).nullable().optional(),
451
458
  });
459
+ exports.SearchResultSchema = zod_1.z.discriminatedUnion('type', [
460
+ exports.ThreadSearchResultSchema,
461
+ exports.ConversationSearchResultSchema,
462
+ ]);
@@ -106,6 +106,9 @@ exports.GetCommentsArgsSchema = zod_1.z.object({
106
106
  exports.GetConversationsArgsSchema = zod_1.z.object({
107
107
  workspaceId: zod_1.z.number(),
108
108
  archived: zod_1.z.boolean().nullable().optional(),
109
+ olderThan: zod_1.z.date().nullable().optional(),
110
+ beforeId: zod_1.z.string().nullable().optional(),
111
+ limit: zod_1.z.number().nullable().optional(),
109
112
  });
110
113
  exports.GetOrCreateConversationArgsSchema = zod_1.z.object({
111
114
  workspaceId: zod_1.z.number(),
@@ -28,26 +28,55 @@ export class ConversationsClient extends BaseClient {
28
28
  : ConversationListSchema;
29
29
  }
30
30
  /**
31
- * Gets all conversations for a workspace.
31
+ * Gets a page of conversations for a workspace, newest activity first.
32
+ * The server returns at most 500 rows per request (20 by default); pass
33
+ * the last row's `lastActive`/`id` as `olderThan`/`beforeId` to fetch
34
+ * the next page. Paired, they form a strict compound boundary, so pages
35
+ * never repeat rows. Omitting `archived` returns active and archived
36
+ * conversations mixed.
32
37
  *
33
38
  * @param args - The arguments for getting conversations.
34
39
  * @param args.workspaceId - The workspace ID.
35
- * @param args.archived - Optional flag to include archived conversations.
40
+ * @param args.archived - Optional flag to filter archived (true) or active (false) conversations.
41
+ * @param args.olderThan - Optional date to get conversations last active before.
42
+ * @param args.beforeId - Optional conversation id. Paired with olderThan it forms the
43
+ * strict compound cursor; alone it pages by conversation id order instead.
44
+ * @param args.limit - Optional page size (server default 20, max 500).
36
45
  * @returns An array of conversation objects.
37
46
  *
38
47
  * @example
39
48
  * ```typescript
40
- * const conversations = await api.conversations.getConversations({ workspaceId: 123 })
41
- * conversations.forEach(c => console.log(c.title))
49
+ * const page = await api.conversations.getConversations({ workspaceId: 123, limit: 500 })
50
+ * const last = page.at(-1)
51
+ * const nextPage = last
52
+ * ? await api.conversations.getConversations({
53
+ * workspaceId: 123,
54
+ * limit: 500,
55
+ * olderThan: last.lastActive,
56
+ * beforeId: last.id,
57
+ * })
58
+ * : []
42
59
  * ```
43
60
  */
44
61
  getConversations(args) {
62
+ // Fields are picked explicitly (matching getThreads/getComments) so a
63
+ // future Date field can't silently reach the generic snake-casing,
64
+ // which would turn it into an empty object on the wire.
65
+ const params = { workspaceId: args.workspaceId };
66
+ if (args.archived != null)
67
+ params.archived = args.archived;
68
+ if (args.olderThan)
69
+ params.olderThanTs = Math.floor(args.olderThan.getTime() / 1000);
70
+ if (args.beforeId != null)
71
+ params.beforeId = args.beforeId;
72
+ if (args.limit != null)
73
+ params.limit = args.limit;
45
74
  return request({
46
75
  httpMethod: 'GET',
47
76
  baseUri: this.getBaseUri(),
48
77
  relativePath: `${ENDPOINT_CONVERSATIONS}/get`,
49
78
  apiToken: this.apiToken,
50
- payload: args,
79
+ payload: params,
51
80
  customFetch: this.customFetch,
52
81
  }).then((response) => this.conversationListSchema.parse(response.data));
53
82
  }
@@ -410,32 +410,43 @@ export const UnreadConversationSchema = z.object({
410
410
  directMention: z.boolean(),
411
411
  });
412
412
  // SearchResult entity from API.
413
- // The API currently only emits 'thread' and 'conversation' results: a match inside a
413
+ // The API emits 'thread' and 'conversation' results: a match inside a
414
414
  // comment is returned as a 'thread' result with `commentId` set, and a match inside a
415
415
  // message as a 'conversation' result with `messageId` set.
416
- export const SEARCH_RESULT_TYPES = ['thread', 'comment', 'message', 'conversation'];
417
- export const SearchResultSchema = z.object({
416
+ const searchResultBaseShape = {
418
417
  /**
419
418
  * Opaque search-result key in the form `thread_<threadId>` or
420
419
  * `conversation_<conversationId>`. Unique per result; not a Comms object id — use
421
420
  * `threadId`, `conversationId`, `commentId`, or `messageId` to reference objects.
422
421
  */
423
422
  id: z.string(),
424
- type: z.enum(SEARCH_RESULT_TYPES),
425
423
  snippet: z.string(),
426
424
  snippetCreatorId: z.number(),
427
425
  snippetLastUpdated: z.date(),
428
- /** The owning thread id. Set by the API on 'thread' results. */
429
- threadId: z.string().nullable().optional(),
430
- /** The owning conversation id. Set by the API on 'conversation' results. */
431
- conversationId: z.string().nullable().optional(),
432
- /** The matched comment id, set on 'thread' results when the match is a comment. */
433
- commentId: z.string().nullable().optional(),
434
- /** The matched message id, set by the API on 'conversation' results. */
435
- messageId: z.union([z.string(), z.number()]).transform(String).nullable().optional(),
436
426
  channelId: z.string().nullable().optional(),
437
427
  channelName: z.string().nullable().optional(),
438
428
  channelColor: z.number().nullable().optional(),
439
429
  title: z.string().nullable().optional(),
440
430
  closed: z.boolean().nullable().optional(),
431
+ };
432
+ export const SEARCH_RESULT_TYPES = ['thread', 'conversation'];
433
+ export const ThreadSearchResultSchema = z.object({
434
+ ...searchResultBaseShape,
435
+ type: z.literal('thread'),
436
+ /** The owning thread id. */
437
+ threadId: z.string(),
438
+ /** The matched comment id, set when the match is a comment. */
439
+ commentId: z.string().nullable().optional(),
440
+ });
441
+ export const ConversationSearchResultSchema = z.object({
442
+ ...searchResultBaseShape,
443
+ type: z.literal('conversation'),
444
+ /** The owning conversation id. */
445
+ conversationId: z.string(),
446
+ /** The matched message id. */
447
+ messageId: z.union([z.string(), z.number()]).transform(String).nullable().optional(),
441
448
  });
449
+ export const SearchResultSchema = z.discriminatedUnion('type', [
450
+ ThreadSearchResultSchema,
451
+ ConversationSearchResultSchema,
452
+ ]);
@@ -103,6 +103,9 @@ export const GetCommentsArgsSchema = z.object({
103
103
  export const GetConversationsArgsSchema = z.object({
104
104
  workspaceId: z.number(),
105
105
  archived: z.boolean().nullable().optional(),
106
+ olderThan: z.date().nullable().optional(),
107
+ beforeId: z.string().nullable().optional(),
108
+ limit: z.number().nullable().optional(),
106
109
  });
107
110
  export const GetOrCreateConversationArgsSchema = z.object({
108
111
  workspaceId: z.number(),
@@ -167,17 +167,34 @@ export declare class ConversationsClient extends BaseClient {
167
167
  private readonly conversationSchema;
168
168
  private readonly conversationListSchema;
169
169
  /**
170
- * Gets all conversations for a workspace.
170
+ * Gets a page of conversations for a workspace, newest activity first.
171
+ * The server returns at most 500 rows per request (20 by default); pass
172
+ * the last row's `lastActive`/`id` as `olderThan`/`beforeId` to fetch
173
+ * the next page. Paired, they form a strict compound boundary, so pages
174
+ * never repeat rows. Omitting `archived` returns active and archived
175
+ * conversations mixed.
171
176
  *
172
177
  * @param args - The arguments for getting conversations.
173
178
  * @param args.workspaceId - The workspace ID.
174
- * @param args.archived - Optional flag to include archived conversations.
179
+ * @param args.archived - Optional flag to filter archived (true) or active (false) conversations.
180
+ * @param args.olderThan - Optional date to get conversations last active before.
181
+ * @param args.beforeId - Optional conversation id. Paired with olderThan it forms the
182
+ * strict compound cursor; alone it pages by conversation id order instead.
183
+ * @param args.limit - Optional page size (server default 20, max 500).
175
184
  * @returns An array of conversation objects.
176
185
  *
177
186
  * @example
178
187
  * ```typescript
179
- * const conversations = await api.conversations.getConversations({ workspaceId: 123 })
180
- * conversations.forEach(c => console.log(c.title))
188
+ * const page = await api.conversations.getConversations({ workspaceId: 123, limit: 500 })
189
+ * const last = page.at(-1)
190
+ * const nextPage = last
191
+ * ? await api.conversations.getConversations({
192
+ * workspaceId: 123,
193
+ * limit: 500,
194
+ * olderThan: last.lastActive,
195
+ * beforeId: last.id,
196
+ * })
197
+ * : []
181
198
  * ```
182
199
  */
183
200
  getConversations(args: GetConversationsArgs): Promise<Conversation[]>;
@@ -2802,29 +2802,65 @@ export declare const UnreadConversationSchema: z.ZodObject<{
2802
2802
  directMention: z.ZodBoolean;
2803
2803
  }, z.core.$strip>;
2804
2804
  export type UnreadConversation = z.infer<typeof UnreadConversationSchema>;
2805
- export declare const SEARCH_RESULT_TYPES: readonly ["thread", "comment", "message", "conversation"];
2805
+ export declare const SEARCH_RESULT_TYPES: readonly ["thread", "conversation"];
2806
2806
  export type SearchResultType = (typeof SEARCH_RESULT_TYPES)[number];
2807
- export declare const SearchResultSchema: z.ZodObject<{
2807
+ export declare const ThreadSearchResultSchema: z.ZodObject<{
2808
+ type: z.ZodLiteral<"thread">;
2809
+ threadId: z.ZodString;
2810
+ commentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2808
2811
  id: z.ZodString;
2809
- type: z.ZodEnum<{
2810
- thread: "thread";
2811
- message: "message";
2812
- comment: "comment";
2813
- conversation: "conversation";
2814
- }>;
2815
2812
  snippet: z.ZodString;
2816
2813
  snippetCreatorId: z.ZodNumber;
2817
2814
  snippetLastUpdated: z.ZodDate;
2818
- threadId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2819
- conversationId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2820
- commentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2815
+ channelId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2816
+ channelName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2817
+ channelColor: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
2818
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2819
+ closed: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
2820
+ }, z.core.$strip>;
2821
+ export type ThreadSearchResult = z.infer<typeof ThreadSearchResultSchema>;
2822
+ export declare const ConversationSearchResultSchema: z.ZodObject<{
2823
+ type: z.ZodLiteral<"conversation">;
2824
+ conversationId: z.ZodString;
2821
2825
  messageId: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>>;
2826
+ id: z.ZodString;
2827
+ snippet: z.ZodString;
2828
+ snippetCreatorId: z.ZodNumber;
2829
+ snippetLastUpdated: z.ZodDate;
2822
2830
  channelId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2823
2831
  channelName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2824
2832
  channelColor: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
2825
2833
  title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2826
2834
  closed: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
2827
2835
  }, z.core.$strip>;
2836
+ export type ConversationSearchResult = z.infer<typeof ConversationSearchResultSchema>;
2837
+ export declare const SearchResultSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
2838
+ type: z.ZodLiteral<"thread">;
2839
+ threadId: z.ZodString;
2840
+ commentId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2841
+ id: z.ZodString;
2842
+ snippet: z.ZodString;
2843
+ snippetCreatorId: z.ZodNumber;
2844
+ snippetLastUpdated: z.ZodDate;
2845
+ channelId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2846
+ channelName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2847
+ channelColor: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
2848
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2849
+ closed: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
2850
+ }, z.core.$strip>, z.ZodObject<{
2851
+ type: z.ZodLiteral<"conversation">;
2852
+ conversationId: z.ZodString;
2853
+ messageId: z.ZodOptional<z.ZodNullable<z.ZodPipe<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>, z.ZodTransform<string, string | number>>>>;
2854
+ id: z.ZodString;
2855
+ snippet: z.ZodString;
2856
+ snippetCreatorId: z.ZodNumber;
2857
+ snippetLastUpdated: z.ZodDate;
2858
+ channelId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2859
+ channelName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2860
+ channelColor: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
2861
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2862
+ closed: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
2863
+ }, z.core.$strip>], "type">;
2828
2864
  export type SearchResult = z.infer<typeof SearchResultSchema>;
2829
2865
  export type SearchResponse = {
2830
2866
  items: SearchResult[];
@@ -164,6 +164,9 @@ export type GetCommentsArgs = z.infer<typeof GetCommentsArgsSchema>;
164
164
  export declare const GetConversationsArgsSchema: z.ZodObject<{
165
165
  workspaceId: z.ZodNumber;
166
166
  archived: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
167
+ olderThan: z.ZodOptional<z.ZodNullable<z.ZodDate>>;
168
+ beforeId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
169
+ limit: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
167
170
  }, z.core.$strip>;
168
171
  export type GetConversationsArgs = z.infer<typeof GetConversationsArgsSchema>;
169
172
  export declare const GetOrCreateConversationArgsSchema: z.ZodObject<{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/comms-sdk",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "A TypeScript wrapper for the Comms REST API.",
5
5
  "author": "Doist developers",
6
6
  "homepage": "https://doist.github.io/comms-sdk-typescript/",