@doist/twist-sdk 2.6.0 → 2.8.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.
- package/dist/cjs/clients/add-comment-helper.js +1 -2
- package/dist/cjs/clients/base-client.js +10 -0
- package/dist/cjs/clients/channels-client.js +9 -6
- package/dist/cjs/clients/comments-client.js +16 -6
- package/dist/cjs/clients/conversation-messages-client.js +9 -8
- package/dist/cjs/clients/conversations-client.js +11 -8
- package/dist/cjs/clients/inbox-client.js +6 -3
- package/dist/cjs/clients/threads-client.js +18 -9
- package/dist/cjs/clients/workspace-users-client.js +9 -2
- package/dist/cjs/clients/workspaces-client.js +7 -3
- package/dist/cjs/types/entities.js +130 -84
- package/dist/cjs/types/requests.js +3 -2
- package/dist/esm/clients/add-comment-helper.js +1 -2
- package/dist/esm/clients/base-client.js +10 -0
- package/dist/esm/clients/channels-client.js +10 -7
- package/dist/esm/clients/comments-client.js +17 -7
- package/dist/esm/clients/conversation-messages-client.js +10 -9
- package/dist/esm/clients/conversations-client.js +12 -9
- package/dist/esm/clients/inbox-client.js +7 -4
- package/dist/esm/clients/threads-client.js +19 -10
- package/dist/esm/clients/workspace-users-client.js +9 -2
- package/dist/esm/clients/workspaces-client.js +8 -4
- package/dist/esm/types/entities.js +123 -83
- package/dist/esm/types/requests.js +3 -2
- package/dist/types/clients/add-comment-helper.d.ts +3 -1
- package/dist/types/clients/base-client.d.ts +4 -0
- package/dist/types/clients/channels-client.d.ts +1 -0
- package/dist/types/clients/comments-client.d.ts +2 -2
- package/dist/types/clients/conversation-messages-client.d.ts +3 -2
- package/dist/types/clients/conversations-client.d.ts +1 -0
- package/dist/types/clients/inbox-client.d.ts +1 -0
- package/dist/types/clients/threads-client.d.ts +4 -4
- package/dist/types/clients/workspace-users-client.d.ts +5 -0
- package/dist/types/clients/workspaces-client.d.ts +1 -0
- package/dist/types/types/entities.d.ts +1845 -65
- package/dist/types/types/requests.d.ts +44 -4
- package/package.json +6 -2
|
@@ -11,12 +11,44 @@ var __assign = (this && this.__assign) || function () {
|
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.SearchResultSchema = exports.SEARCH_RESULT_TYPES = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.ConversationSchema = exports.GroupSchema = exports.ThreadSchema = exports.ChannelSchema = exports.WorkspaceSchema = exports.UserSchema = exports.BaseUserSchema = exports.SystemMessageSchema = void 0;
|
|
14
|
+
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.AttachmentSchema = exports.SystemMessageSchema = void 0;
|
|
15
|
+
exports.createChannelSchema = createChannelSchema;
|
|
16
|
+
exports.createThreadSchema = createThreadSchema;
|
|
17
|
+
exports.createConversationSchema = createConversationSchema;
|
|
18
|
+
exports.createCommentSchema = createCommentSchema;
|
|
19
|
+
exports.createConversationMessageSchema = createConversationMessageSchema;
|
|
20
|
+
exports.createInboxThreadSchema = createInboxThreadSchema;
|
|
15
21
|
var zod_1 = require("zod");
|
|
16
22
|
var url_helpers_1 = require("../utils/url-helpers");
|
|
17
23
|
var enums_1 = require("./enums");
|
|
18
24
|
// Reusable schema for system messages that can be either a string or an object
|
|
19
25
|
exports.SystemMessageSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.unknown()]).nullable().optional();
|
|
26
|
+
// Attachment entity from API. Mirrors the canonical backend shape produced by
|
|
27
|
+
// `unify_attachments` / `validate_file_attachment_json` in the Twist backend.
|
|
28
|
+
// Only `attachmentId` and `urlType` are guaranteed; everything else depends on
|
|
29
|
+
// the attachment kind (file vs image vs link preview vs unfurled GIF).
|
|
30
|
+
// Loose: unknown keys from the backend pass through rather than being stripped,
|
|
31
|
+
// so newly-added or off-spec fields stay accessible to callers.
|
|
32
|
+
exports.AttachmentSchema = zod_1.z
|
|
33
|
+
.object({
|
|
34
|
+
attachmentId: zod_1.z.string(),
|
|
35
|
+
urlType: zod_1.z.string(),
|
|
36
|
+
title: zod_1.z.string().nullable().optional(),
|
|
37
|
+
url: zod_1.z.string().nullable().optional(),
|
|
38
|
+
fileName: zod_1.z.string().nullable().optional(),
|
|
39
|
+
fileSize: zod_1.z.number().int().nonnegative().nullable().optional(),
|
|
40
|
+
underlyingType: zod_1.z.string().nullable().optional(),
|
|
41
|
+
description: zod_1.z.string().nullable().optional(),
|
|
42
|
+
image: zod_1.z.string().nullable().optional(),
|
|
43
|
+
imageWidth: zod_1.z.number().int().nonnegative().nullable().optional(),
|
|
44
|
+
imageHeight: zod_1.z.number().int().nonnegative().nullable().optional(),
|
|
45
|
+
duration: zod_1.z.string().nullable().optional(),
|
|
46
|
+
uploadState: zod_1.z.string().nullable().optional(),
|
|
47
|
+
video: zod_1.z.string().nullable().optional(),
|
|
48
|
+
videoType: zod_1.z.string().nullable().optional(),
|
|
49
|
+
videoAutoPlay: zod_1.z.boolean().nullable().optional(),
|
|
50
|
+
})
|
|
51
|
+
.loose();
|
|
20
52
|
// Base user schema with common fields shared between User and WorkspaceUser
|
|
21
53
|
exports.BaseUserSchema = zod_1.z.object({
|
|
22
54
|
id: zod_1.z.number(),
|
|
@@ -86,8 +118,7 @@ exports.WorkspaceSchema = zod_1.z.object({
|
|
|
86
118
|
plan: zod_1.z.enum(enums_1.WORKSPACE_PLANS).nullable().optional(),
|
|
87
119
|
});
|
|
88
120
|
// Channel entity from API
|
|
89
|
-
exports.
|
|
90
|
-
.object({
|
|
121
|
+
exports.ChannelObjectSchema = zod_1.z.object({
|
|
91
122
|
id: zod_1.z.number(),
|
|
92
123
|
name: zod_1.z.string(),
|
|
93
124
|
description: zod_1.z.string().nullable().optional(),
|
|
@@ -105,11 +136,13 @@ exports.ChannelSchema = zod_1.z
|
|
|
105
136
|
icon: zod_1.z.number().nullable().optional(),
|
|
106
137
|
version: zod_1.z.number(),
|
|
107
138
|
filters: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).nullable().optional(),
|
|
108
|
-
})
|
|
109
|
-
|
|
139
|
+
});
|
|
140
|
+
function createChannelSchema(linkBaseUrl) {
|
|
141
|
+
return exports.ChannelObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: (0, url_helpers_1.getFullTwistURL)({ workspaceId: data.workspaceId, channelId: data.id }, linkBaseUrl) })); });
|
|
142
|
+
}
|
|
143
|
+
exports.ChannelSchema = createChannelSchema();
|
|
110
144
|
// Thread entity from API
|
|
111
|
-
exports.
|
|
112
|
-
.object({
|
|
145
|
+
exports.ThreadObjectSchema = zod_1.z.object({
|
|
113
146
|
id: zod_1.z.number(),
|
|
114
147
|
title: zod_1.z.string(),
|
|
115
148
|
content: zod_1.z.string(),
|
|
@@ -118,7 +151,7 @@ exports.ThreadSchema = zod_1.z
|
|
|
118
151
|
channelId: zod_1.z.number(),
|
|
119
152
|
workspaceId: zod_1.z.number(),
|
|
120
153
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
121
|
-
attachments: zod_1.z.array(
|
|
154
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
122
155
|
commentCount: zod_1.z.number(),
|
|
123
156
|
closed: zod_1.z.boolean().nullable().optional(),
|
|
124
157
|
directGroupMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
@@ -155,7 +188,7 @@ exports.ThreadSchema = zod_1.z
|
|
|
155
188
|
channelId: zod_1.z.number(),
|
|
156
189
|
posted: zod_1.z.date(),
|
|
157
190
|
systemMessage: exports.SystemMessageSchema,
|
|
158
|
-
attachments: zod_1.z.array(
|
|
191
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
159
192
|
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.number())).nullable().optional(),
|
|
160
193
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
161
194
|
objIndex: zod_1.z.number(),
|
|
@@ -172,12 +205,15 @@ exports.ThreadSchema = zod_1.z
|
|
|
172
205
|
})
|
|
173
206
|
.nullable()
|
|
174
207
|
.optional(),
|
|
175
|
-
})
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
208
|
+
});
|
|
209
|
+
function createThreadSchema(linkBaseUrl) {
|
|
210
|
+
return exports.ThreadObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: (0, url_helpers_1.getFullTwistURL)({
|
|
211
|
+
workspaceId: data.workspaceId,
|
|
212
|
+
channelId: data.channelId,
|
|
213
|
+
threadId: data.id,
|
|
214
|
+
}, linkBaseUrl) })); });
|
|
215
|
+
}
|
|
216
|
+
exports.ThreadSchema = createThreadSchema();
|
|
181
217
|
// Group entity from API
|
|
182
218
|
exports.GroupSchema = zod_1.z.object({
|
|
183
219
|
id: zod_1.z.number(),
|
|
@@ -188,8 +224,7 @@ exports.GroupSchema = zod_1.z.object({
|
|
|
188
224
|
version: zod_1.z.number(),
|
|
189
225
|
});
|
|
190
226
|
// Conversation entity from API
|
|
191
|
-
exports.
|
|
192
|
-
.object({
|
|
227
|
+
exports.ConversationObjectSchema = zod_1.z.object({
|
|
193
228
|
id: zod_1.z.number(),
|
|
194
229
|
workspaceId: zod_1.z.number(),
|
|
195
230
|
userIds: zod_1.z.array(zod_1.z.number()),
|
|
@@ -212,7 +247,7 @@ exports.ConversationSchema = zod_1.z
|
|
|
212
247
|
conversationId: zod_1.z.number(),
|
|
213
248
|
posted: zod_1.z.date(),
|
|
214
249
|
systemMessage: exports.SystemMessageSchema,
|
|
215
|
-
attachments: zod_1.z.array(
|
|
250
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
216
251
|
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.number())).nullable().optional(),
|
|
217
252
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
218
253
|
objIndex: zod_1.z.number().nullable().optional(),
|
|
@@ -225,11 +260,13 @@ exports.ConversationSchema = zod_1.z
|
|
|
225
260
|
})
|
|
226
261
|
.nullable()
|
|
227
262
|
.optional(),
|
|
228
|
-
})
|
|
229
|
-
|
|
263
|
+
});
|
|
264
|
+
function createConversationSchema(linkBaseUrl) {
|
|
265
|
+
return exports.ConversationObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: (0, url_helpers_1.getFullTwistURL)({ workspaceId: data.workspaceId, conversationId: data.id }, linkBaseUrl) })); });
|
|
266
|
+
}
|
|
267
|
+
exports.ConversationSchema = createConversationSchema();
|
|
230
268
|
// Comment entity from API
|
|
231
|
-
exports.
|
|
232
|
-
.object({
|
|
269
|
+
exports.CommentObjectSchema = zod_1.z.object({
|
|
233
270
|
id: zod_1.z.number(),
|
|
234
271
|
content: zod_1.z.string(),
|
|
235
272
|
creator: zod_1.z.number(),
|
|
@@ -241,7 +278,7 @@ exports.CommentSchema = zod_1.z
|
|
|
241
278
|
directMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
242
279
|
directGroupMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
243
280
|
systemMessage: exports.SystemMessageSchema,
|
|
244
|
-
attachments: zod_1.z.array(
|
|
281
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
245
282
|
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable().optional(),
|
|
246
283
|
objIndex: zod_1.z.number().nullable().optional(),
|
|
247
284
|
// Extended fields that may appear in some API responses (like inbox)
|
|
@@ -254,13 +291,16 @@ exports.CommentSchema = zod_1.z
|
|
|
254
291
|
deletedBy: zod_1.z.number().nullable().optional(),
|
|
255
292
|
version: zod_1.z.number().nullable().optional(),
|
|
256
293
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
294
|
+
});
|
|
295
|
+
function createCommentSchema(linkBaseUrl) {
|
|
296
|
+
return exports.CommentObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: (0, url_helpers_1.getFullTwistURL)({
|
|
297
|
+
workspaceId: data.workspaceId,
|
|
298
|
+
channelId: data.channelId,
|
|
299
|
+
threadId: data.threadId,
|
|
300
|
+
commentId: data.id,
|
|
301
|
+
}, linkBaseUrl) })); });
|
|
302
|
+
}
|
|
303
|
+
exports.CommentSchema = createCommentSchema();
|
|
264
304
|
// WorkspaceUser entity from v4 API
|
|
265
305
|
exports.WorkspaceUserSchema = exports.BaseUserSchema.extend({
|
|
266
306
|
email: zod_1.z.string().nullable().optional(),
|
|
@@ -272,15 +312,14 @@ exports.WorkspaceUserSchema = exports.BaseUserSchema.extend({
|
|
|
272
312
|
version: zod_1.z.number(),
|
|
273
313
|
});
|
|
274
314
|
// ConversationMessage entity from API
|
|
275
|
-
exports.
|
|
276
|
-
.object({
|
|
315
|
+
exports.ConversationMessageObjectSchema = zod_1.z.object({
|
|
277
316
|
id: zod_1.z.number(),
|
|
278
317
|
content: zod_1.z.string(),
|
|
279
318
|
creator: zod_1.z.number(),
|
|
280
319
|
conversationId: zod_1.z.number(),
|
|
281
320
|
posted: zod_1.z.date(),
|
|
282
321
|
systemMessage: exports.SystemMessageSchema,
|
|
283
|
-
attachments: zod_1.z.array(
|
|
322
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
284
323
|
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.number())).nullable().optional(),
|
|
285
324
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
286
325
|
objIndex: zod_1.z.number().nullable().optional(),
|
|
@@ -290,58 +329,65 @@ exports.ConversationMessageSchema = zod_1.z
|
|
|
290
329
|
directMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
291
330
|
version: zod_1.z.number().nullable().optional(),
|
|
292
331
|
workspaceId: zod_1.z.number(),
|
|
293
|
-
})
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
332
|
+
});
|
|
333
|
+
function createConversationMessageSchema(linkBaseUrl) {
|
|
334
|
+
return exports.ConversationMessageObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: (0, url_helpers_1.getFullTwistURL)({
|
|
335
|
+
workspaceId: data.workspaceId,
|
|
336
|
+
conversationId: data.conversationId,
|
|
337
|
+
messageId: data.id,
|
|
338
|
+
}, linkBaseUrl) })); });
|
|
339
|
+
}
|
|
340
|
+
exports.ConversationMessageSchema = createConversationMessageSchema();
|
|
299
341
|
// InboxThread entity from API - returns full Thread objects with additional inbox metadata
|
|
300
|
-
|
|
301
|
-
.object({
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
})
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
342
|
+
function createInboxThreadObjectSchema(linkBaseUrl) {
|
|
343
|
+
return zod_1.z.object({
|
|
344
|
+
id: zod_1.z.number(),
|
|
345
|
+
title: zod_1.z.string(),
|
|
346
|
+
content: zod_1.z.string(),
|
|
347
|
+
creator: zod_1.z.number(),
|
|
348
|
+
creatorName: zod_1.z.string().nullable().optional(),
|
|
349
|
+
channelId: zod_1.z.number(),
|
|
350
|
+
workspaceId: zod_1.z.number(),
|
|
351
|
+
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
352
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
353
|
+
commentCount: zod_1.z.number(),
|
|
354
|
+
directGroupMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
355
|
+
directMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
356
|
+
groups: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
357
|
+
lastEdited: zod_1.z.date().nullable().optional(),
|
|
358
|
+
lastObjIndex: zod_1.z.number().nullable().optional(),
|
|
359
|
+
lastUpdated: zod_1.z.date(),
|
|
360
|
+
mutedUntil: zod_1.z.date().nullable().optional(),
|
|
361
|
+
participants: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
362
|
+
pinned: zod_1.z.boolean(),
|
|
363
|
+
pinnedDate: zod_1.z.date().nullable().optional(),
|
|
364
|
+
posted: zod_1.z.date(),
|
|
365
|
+
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.number())).nullable().optional(),
|
|
366
|
+
recipients: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
367
|
+
snippet: zod_1.z.string(),
|
|
368
|
+
snippetCreator: zod_1.z.number(),
|
|
369
|
+
snippetMaskAvatarUrl: zod_1.z.string().nullable().optional(),
|
|
370
|
+
snippetMaskPoster: zod_1.z.string().nullable().optional(),
|
|
371
|
+
starred: zod_1.z.boolean(),
|
|
372
|
+
systemMessage: exports.SystemMessageSchema,
|
|
373
|
+
isArchived: zod_1.z.boolean(),
|
|
374
|
+
inInbox: zod_1.z.boolean(),
|
|
375
|
+
isSaved: zod_1.z.boolean().nullable().optional(),
|
|
376
|
+
closed: zod_1.z.boolean(),
|
|
377
|
+
responders: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
378
|
+
lastComment: createCommentSchema(linkBaseUrl).nullable().optional(),
|
|
379
|
+
toEmails: zod_1.z.array(zod_1.z.string()).nullable().optional(),
|
|
380
|
+
version: zod_1.z.number().nullable().optional(),
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
function createInboxThreadSchema(linkBaseUrl) {
|
|
384
|
+
return createInboxThreadObjectSchema(linkBaseUrl).transform(function (data) { return (__assign(__assign({}, data), { url: (0, url_helpers_1.getFullTwistURL)({
|
|
385
|
+
workspaceId: data.workspaceId,
|
|
386
|
+
channelId: data.channelId,
|
|
387
|
+
threadId: data.id,
|
|
388
|
+
}, linkBaseUrl) })); });
|
|
389
|
+
}
|
|
390
|
+
exports.InboxThreadSchema = createInboxThreadSchema();
|
|
345
391
|
// UnreadThread entity from API - simplified thread reference for unread threads
|
|
346
392
|
exports.UnreadThreadSchema = zod_1.z.object({
|
|
347
393
|
threadId: zod_1.z.number(),
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.THREAD_ACTIONS = exports.ARCHIVE_FILTER_VALUES = exports.AWAY_MODE_TYPES = exports.GetOrCreateConversationArgsSchema = exports.GetConversationsArgsSchema = exports.GetCommentsArgsSchema = exports.GetThreadsArgsSchema = exports.GetChannelsArgsSchema = exports.CreateMessageArgsSchema = exports.CreateConversationArgsSchema = exports.UpdateCommentArgsSchema = exports.CreateCommentArgsSchema = exports.UpdateThreadArgsSchema = exports.CreateThreadArgsSchema = exports.UpdateChannelArgsSchema = exports.CreateChannelArgsSchema = void 0;
|
|
4
4
|
var zod_1 = require("zod");
|
|
5
|
+
var entities_1 = require("./entities");
|
|
5
6
|
var enums_1 = require("./enums");
|
|
6
7
|
exports.CreateChannelArgsSchema = zod_1.z.object({
|
|
7
8
|
workspaceId: zod_1.z.number(),
|
|
@@ -44,7 +45,7 @@ exports.CreateCommentArgsSchema = zod_1.z.object({
|
|
|
44
45
|
threadId: zod_1.z.number(),
|
|
45
46
|
content: zod_1.z.string(),
|
|
46
47
|
tempId: zod_1.z.number().nullable().optional(),
|
|
47
|
-
attachments: zod_1.z.
|
|
48
|
+
attachments: zod_1.z.array(entities_1.AttachmentSchema).nullable().optional(),
|
|
48
49
|
actions: zod_1.z.unknown().nullable().optional(),
|
|
49
50
|
recipients: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
50
51
|
groups: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
@@ -65,7 +66,7 @@ exports.CreateMessageArgsSchema = zod_1.z
|
|
|
65
66
|
conversationId: zod_1.z.number().nullable().optional(),
|
|
66
67
|
threadId: zod_1.z.number().nullable().optional(),
|
|
67
68
|
content: zod_1.z.string(),
|
|
68
|
-
attachments: zod_1.z.array(
|
|
69
|
+
attachments: zod_1.z.array(entities_1.AttachmentSchema).nullable().optional(),
|
|
69
70
|
})
|
|
70
71
|
.refine(function (data) {
|
|
71
72
|
return ((data.conversationId && !data.threadId) || (!data.conversationId && data.threadId));
|
|
@@ -31,7 +31,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
31
31
|
};
|
|
32
32
|
import { ENDPOINT_COMMENTS } from '../consts/endpoints.js';
|
|
33
33
|
import { request } from '../transport/http-client.js';
|
|
34
|
-
import { CommentSchema } from '../types/entities.js';
|
|
35
34
|
import { NOTIFY_AUDIENCE_GROUP_IDS, NOTIFY_AUDIENCES } from '../types/enums.js';
|
|
36
35
|
var SENTINEL_GROUP_IDS = new Set(Object.values(NOTIFY_AUDIENCE_GROUP_IDS));
|
|
37
36
|
function isNotifyAudience(value) {
|
|
@@ -59,7 +58,7 @@ export function addCommentRequest(context, params, options) {
|
|
|
59
58
|
var normalized = applyNotifyAudience(params);
|
|
60
59
|
var payload = (options === null || options === void 0 ? void 0 : options.threadAction)
|
|
61
60
|
? __assign(__assign({}, normalized), { threadAction: options.threadAction }) : normalized;
|
|
62
|
-
var schema =
|
|
61
|
+
var schema = context.schema;
|
|
63
62
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
64
63
|
return { method: method, url: url, params: payload, schema: schema };
|
|
65
64
|
}
|
|
@@ -28,6 +28,16 @@ var BaseClient = /** @class */ (function () {
|
|
|
28
28
|
// Use centralized helper function for default Twist API URL
|
|
29
29
|
return getTwistBaseUri(apiVersion);
|
|
30
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Base URL for entity web links, or `undefined` to use getFullTwistURL's default web app.
|
|
33
|
+
*/
|
|
34
|
+
BaseClient.prototype.getLinkBaseUrl = function () {
|
|
35
|
+
if (!this.baseUrl) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
// Strip a trailing slash so links don't double up, since entity paths start with '/'.
|
|
39
|
+
return this.baseUrl.endsWith('/') ? this.baseUrl.slice(0, -1) : this.baseUrl;
|
|
40
|
+
};
|
|
31
41
|
return BaseClient;
|
|
32
42
|
}());
|
|
33
43
|
export { BaseClient };
|
|
@@ -16,7 +16,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
import { z } from 'zod';
|
|
17
17
|
import { ENDPOINT_CHANNELS } from '../consts/endpoints.js';
|
|
18
18
|
import { request } from '../transport/http-client.js';
|
|
19
|
-
import {
|
|
19
|
+
import { createChannelSchema } from '../types/entities.js';
|
|
20
20
|
import { BaseClient } from './base-client.js';
|
|
21
21
|
/**
|
|
22
22
|
* Client for interacting with Twist channel endpoints.
|
|
@@ -24,14 +24,17 @@ import { BaseClient } from './base-client.js';
|
|
|
24
24
|
var ChannelsClient = /** @class */ (function (_super) {
|
|
25
25
|
__extends(ChannelsClient, _super);
|
|
26
26
|
function ChannelsClient() {
|
|
27
|
-
|
|
27
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
28
|
+
_this.channelSchema = createChannelSchema(_this.getLinkBaseUrl());
|
|
29
|
+
return _this;
|
|
28
30
|
}
|
|
29
31
|
ChannelsClient.prototype.getChannels = function (args, options) {
|
|
32
|
+
var _this = this;
|
|
30
33
|
var method = 'GET';
|
|
31
34
|
var url = "".concat(ENDPOINT_CHANNELS, "/get");
|
|
32
35
|
var params = args;
|
|
33
36
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
34
|
-
return { method: method, url: url, params: params, schema: z.array(
|
|
37
|
+
return { method: method, url: url, params: params, schema: z.array(this.channelSchema) };
|
|
35
38
|
}
|
|
36
39
|
return request({
|
|
37
40
|
httpMethod: method,
|
|
@@ -40,13 +43,13 @@ var ChannelsClient = /** @class */ (function (_super) {
|
|
|
40
43
|
apiToken: this.apiToken,
|
|
41
44
|
payload: params,
|
|
42
45
|
customFetch: this.customFetch,
|
|
43
|
-
}).then(function (response) { return response.data.map(function (channel) { return
|
|
46
|
+
}).then(function (response) { return response.data.map(function (channel) { return _this.channelSchema.parse(channel); }); });
|
|
44
47
|
};
|
|
45
48
|
ChannelsClient.prototype.getChannel = function (id, options) {
|
|
46
49
|
var method = 'GET';
|
|
47
50
|
var url = "".concat(ENDPOINT_CHANNELS, "/getone");
|
|
48
51
|
var params = { id: id };
|
|
49
|
-
var schema =
|
|
52
|
+
var schema = this.channelSchema;
|
|
50
53
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
51
54
|
return { method: method, url: url, params: params, schema: schema };
|
|
52
55
|
}
|
|
@@ -63,7 +66,7 @@ var ChannelsClient = /** @class */ (function (_super) {
|
|
|
63
66
|
var method = 'POST';
|
|
64
67
|
var url = "".concat(ENDPOINT_CHANNELS, "/add");
|
|
65
68
|
var params = args;
|
|
66
|
-
var schema =
|
|
69
|
+
var schema = this.channelSchema;
|
|
67
70
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
68
71
|
return { method: method, url: url, params: params, schema: schema };
|
|
69
72
|
}
|
|
@@ -80,7 +83,7 @@ var ChannelsClient = /** @class */ (function (_super) {
|
|
|
80
83
|
var method = 'POST';
|
|
81
84
|
var url = "".concat(ENDPOINT_CHANNELS, "/update");
|
|
82
85
|
var params = args;
|
|
83
|
-
var schema =
|
|
86
|
+
var schema = this.channelSchema;
|
|
84
87
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
85
88
|
return { method: method, url: url, params: params, schema: schema };
|
|
86
89
|
}
|
|
@@ -16,7 +16,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
import { z } from 'zod';
|
|
17
17
|
import { ENDPOINT_COMMENTS } from '../consts/endpoints.js';
|
|
18
18
|
import { request } from '../transport/http-client.js';
|
|
19
|
-
import {
|
|
19
|
+
import { createCommentSchema } from '../types/entities.js';
|
|
20
20
|
import { addCommentRequest } from './add-comment-helper.js';
|
|
21
21
|
import { BaseClient } from './base-client.js';
|
|
22
22
|
/**
|
|
@@ -25,9 +25,12 @@ import { BaseClient } from './base-client.js';
|
|
|
25
25
|
var CommentsClient = /** @class */ (function (_super) {
|
|
26
26
|
__extends(CommentsClient, _super);
|
|
27
27
|
function CommentsClient() {
|
|
28
|
-
|
|
28
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
29
|
+
_this.commentSchema = createCommentSchema(_this.getLinkBaseUrl());
|
|
30
|
+
return _this;
|
|
29
31
|
}
|
|
30
32
|
CommentsClient.prototype.getComments = function (args, options) {
|
|
33
|
+
var _this = this;
|
|
31
34
|
var _a;
|
|
32
35
|
var params = {
|
|
33
36
|
thread_id: args.threadId,
|
|
@@ -42,7 +45,7 @@ var CommentsClient = /** @class */ (function (_super) {
|
|
|
42
45
|
var method = 'GET';
|
|
43
46
|
var url = "".concat(ENDPOINT_COMMENTS, "/get");
|
|
44
47
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
45
|
-
return { method: method, url: url, params: params, schema: z.array(
|
|
48
|
+
return { method: method, url: url, params: params, schema: z.array(this.commentSchema) };
|
|
46
49
|
}
|
|
47
50
|
return request({
|
|
48
51
|
httpMethod: method,
|
|
@@ -51,14 +54,16 @@ var CommentsClient = /** @class */ (function (_super) {
|
|
|
51
54
|
apiToken: this.apiToken,
|
|
52
55
|
payload: params,
|
|
53
56
|
customFetch: this.customFetch,
|
|
54
|
-
}).then(function (response) { return response.data.map(function (comment) { return
|
|
57
|
+
}).then(function (response) { return response.data.map(function (comment) { return _this.commentSchema.parse(comment); }); });
|
|
55
58
|
};
|
|
56
59
|
CommentsClient.prototype.getComment = function (id, options) {
|
|
57
60
|
var method = 'GET';
|
|
58
61
|
var url = "".concat(ENDPOINT_COMMENTS, "/getone");
|
|
59
62
|
var params = { id: id };
|
|
60
63
|
// The API wraps the response in {"comment": {...}}, so we need to unwrap it
|
|
61
|
-
var wrappedSchema = z
|
|
64
|
+
var wrappedSchema = z
|
|
65
|
+
.object({ comment: this.commentSchema })
|
|
66
|
+
.transform(function (data) { return data.comment; });
|
|
62
67
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
63
68
|
return { method: method, url: url, params: params, schema: wrappedSchema };
|
|
64
69
|
}
|
|
@@ -72,13 +77,18 @@ var CommentsClient = /** @class */ (function (_super) {
|
|
|
72
77
|
}).then(function (response) { return wrappedSchema.parse(response.data); });
|
|
73
78
|
};
|
|
74
79
|
CommentsClient.prototype.createComment = function (args, options) {
|
|
75
|
-
return addCommentRequest({
|
|
80
|
+
return addCommentRequest({
|
|
81
|
+
baseUri: this.getBaseUri(),
|
|
82
|
+
apiToken: this.apiToken,
|
|
83
|
+
customFetch: this.customFetch,
|
|
84
|
+
schema: this.commentSchema,
|
|
85
|
+
}, args, options);
|
|
76
86
|
};
|
|
77
87
|
CommentsClient.prototype.updateComment = function (args, options) {
|
|
78
88
|
var method = 'POST';
|
|
79
89
|
var url = "".concat(ENDPOINT_COMMENTS, "/update");
|
|
80
90
|
var params = args;
|
|
81
|
-
var schema =
|
|
91
|
+
var schema = this.commentSchema;
|
|
82
92
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
83
93
|
return { method: method, url: url, params: params, schema: schema };
|
|
84
94
|
}
|
|
@@ -16,7 +16,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
16
16
|
import { z } from 'zod';
|
|
17
17
|
import { ENDPOINT_CONVERSATION_MESSAGES } from '../consts/endpoints.js';
|
|
18
18
|
import { request } from '../transport/http-client.js';
|
|
19
|
-
import {
|
|
19
|
+
import { createConversationMessageSchema } from '../types/entities.js';
|
|
20
20
|
import { BaseClient } from './base-client.js';
|
|
21
21
|
/**
|
|
22
22
|
* Client for interacting with Twist conversation message endpoints.
|
|
@@ -24,9 +24,12 @@ import { BaseClient } from './base-client.js';
|
|
|
24
24
|
var ConversationMessagesClient = /** @class */ (function (_super) {
|
|
25
25
|
__extends(ConversationMessagesClient, _super);
|
|
26
26
|
function ConversationMessagesClient() {
|
|
27
|
-
|
|
27
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
28
|
+
_this.messageSchema = createConversationMessageSchema(_this.getLinkBaseUrl());
|
|
29
|
+
return _this;
|
|
28
30
|
}
|
|
29
31
|
ConversationMessagesClient.prototype.getMessages = function (args, options) {
|
|
32
|
+
var _this = this;
|
|
30
33
|
var params = {
|
|
31
34
|
conversation_id: args.conversationId,
|
|
32
35
|
};
|
|
@@ -41,7 +44,7 @@ var ConversationMessagesClient = /** @class */ (function (_super) {
|
|
|
41
44
|
var method = 'GET';
|
|
42
45
|
var url = "".concat(ENDPOINT_CONVERSATION_MESSAGES, "/get");
|
|
43
46
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
44
|
-
return { method: method, url: url, params: params, schema: z.array(
|
|
47
|
+
return { method: method, url: url, params: params, schema: z.array(this.messageSchema) };
|
|
45
48
|
}
|
|
46
49
|
return request({
|
|
47
50
|
httpMethod: method,
|
|
@@ -50,15 +53,13 @@ var ConversationMessagesClient = /** @class */ (function (_super) {
|
|
|
50
53
|
apiToken: this.apiToken,
|
|
51
54
|
payload: params,
|
|
52
55
|
customFetch: this.customFetch,
|
|
53
|
-
}).then(function (response) {
|
|
54
|
-
return response.data.map(function (message) { return ConversationMessageSchema.parse(message); });
|
|
55
|
-
});
|
|
56
|
+
}).then(function (response) { return response.data.map(function (message) { return _this.messageSchema.parse(message); }); });
|
|
56
57
|
};
|
|
57
58
|
ConversationMessagesClient.prototype.getMessage = function (id, options) {
|
|
58
59
|
var method = 'GET';
|
|
59
60
|
var url = "".concat(ENDPOINT_CONVERSATION_MESSAGES, "/getone");
|
|
60
61
|
var params = { id: id };
|
|
61
|
-
var schema =
|
|
62
|
+
var schema = this.messageSchema;
|
|
62
63
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
63
64
|
return { method: method, url: url, params: params, schema: schema };
|
|
64
65
|
}
|
|
@@ -82,7 +83,7 @@ var ConversationMessagesClient = /** @class */ (function (_super) {
|
|
|
82
83
|
params.actions = args.actions;
|
|
83
84
|
var method = 'POST';
|
|
84
85
|
var url = "".concat(ENDPOINT_CONVERSATION_MESSAGES, "/add");
|
|
85
|
-
var schema =
|
|
86
|
+
var schema = this.messageSchema;
|
|
86
87
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
87
88
|
return { method: method, url: url, params: params, schema: schema };
|
|
88
89
|
}
|
|
@@ -104,7 +105,7 @@ var ConversationMessagesClient = /** @class */ (function (_super) {
|
|
|
104
105
|
params.attachments = args.attachments;
|
|
105
106
|
var method = 'POST';
|
|
106
107
|
var url = "".concat(ENDPOINT_CONVERSATION_MESSAGES, "/update");
|
|
107
|
-
var schema =
|
|
108
|
+
var schema = this.messageSchema;
|
|
108
109
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
109
110
|
return { method: method, url: url, params: params, schema: schema };
|
|
110
111
|
}
|