@doist/twist-sdk 2.5.1 → 2.7.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.
- package/dist/cjs/clients/add-comment-helper.js +43 -1
- package/dist/cjs/types/entities.js +33 -7
- package/dist/cjs/types/enums.js +15 -1
- package/dist/cjs/types/requests.js +7 -2
- package/dist/esm/clients/add-comment-helper.js +43 -1
- package/dist/esm/types/entities.js +32 -6
- package/dist/esm/types/enums.js +14 -0
- package/dist/esm/types/requests.js +7 -2
- package/dist/types/clients/add-comment-helper.d.ts +2 -2
- package/dist/types/clients/comments-client.d.ts +12 -4
- package/dist/types/clients/conversation-messages-client.d.ts +2 -2
- package/dist/types/clients/threads-client.d.ts +16 -6
- package/dist/types/types/entities.d.ts +450 -24
- package/dist/types/types/enums.d.ts +19 -0
- package/dist/types/types/requests.d.ts +53 -18
- package/package.json +1 -1
|
@@ -10,16 +10,58 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
24
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
25
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
26
|
+
if (ar || !(i in from)) {
|
|
27
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
28
|
+
ar[i] = from[i];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
32
|
+
};
|
|
13
33
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
34
|
exports.addCommentRequest = addCommentRequest;
|
|
15
35
|
var endpoints_1 = require("../consts/endpoints");
|
|
16
36
|
var http_client_1 = require("../transport/http-client");
|
|
17
37
|
var entities_1 = require("../types/entities");
|
|
38
|
+
var enums_1 = require("../types/enums");
|
|
39
|
+
var SENTINEL_GROUP_IDS = new Set(Object.values(enums_1.NOTIFY_AUDIENCE_GROUP_IDS));
|
|
40
|
+
function isNotifyAudience(value) {
|
|
41
|
+
return typeof value === 'string' && enums_1.NOTIFY_AUDIENCES.includes(value);
|
|
42
|
+
}
|
|
43
|
+
function applyNotifyAudience(params) {
|
|
44
|
+
if (params.groups) {
|
|
45
|
+
var offending = params.groups.filter(function (id) { return SENTINEL_GROUP_IDS.has(id); });
|
|
46
|
+
if (offending.length > 0) {
|
|
47
|
+
throw new Error("`groups` must not contain reserved sentinel IDs (".concat(offending.join(', '), "). Use `notifyAudience` instead."));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (params.notifyAudience == null)
|
|
51
|
+
return params;
|
|
52
|
+
if (!isNotifyAudience(params.notifyAudience)) {
|
|
53
|
+
throw new Error("Invalid `notifyAudience` value \"".concat(String(params.notifyAudience), "\". Expected one of: ").concat(enums_1.NOTIFY_AUDIENCES.join(', '), "."));
|
|
54
|
+
}
|
|
55
|
+
var sentinel = enums_1.NOTIFY_AUDIENCE_GROUP_IDS[params.notifyAudience];
|
|
56
|
+
var _stripped = params.notifyAudience, groups = params.groups, rest = __rest(params, ["notifyAudience", "groups"]);
|
|
57
|
+
return __assign(__assign({}, rest), { groups: __spreadArray(__spreadArray([], (groups !== null && groups !== void 0 ? groups : []), true), [sentinel], false) });
|
|
58
|
+
}
|
|
18
59
|
function addCommentRequest(context, params, options) {
|
|
19
60
|
var method = 'POST';
|
|
20
61
|
var url = "".concat(endpoints_1.ENDPOINT_COMMENTS, "/add");
|
|
62
|
+
var normalized = applyNotifyAudience(params);
|
|
21
63
|
var payload = (options === null || options === void 0 ? void 0 : options.threadAction)
|
|
22
|
-
? __assign(__assign({},
|
|
64
|
+
? __assign(__assign({}, normalized), { threadAction: options.threadAction }) : normalized;
|
|
23
65
|
var schema = entities_1.CommentSchema;
|
|
24
66
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
25
67
|
return { method: method, url: url, params: payload, schema: schema };
|
|
@@ -11,12 +11,38 @@ 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.WorkspaceUserSchema = exports.CommentSchema = exports.ConversationSchema = exports.GroupSchema = exports.ThreadSchema = exports.ChannelSchema = exports.WorkspaceSchema = exports.UserSchema = exports.BaseUserSchema = exports.AttachmentSchema = exports.SystemMessageSchema = void 0;
|
|
15
15
|
var zod_1 = require("zod");
|
|
16
16
|
var url_helpers_1 = require("../utils/url-helpers");
|
|
17
17
|
var enums_1 = require("./enums");
|
|
18
18
|
// Reusable schema for system messages that can be either a string or an object
|
|
19
19
|
exports.SystemMessageSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.unknown()]).nullable().optional();
|
|
20
|
+
// Attachment entity from API. Mirrors the canonical backend shape produced by
|
|
21
|
+
// `unify_attachments` / `validate_file_attachment_json` in the Twist backend.
|
|
22
|
+
// Only `attachmentId` and `urlType` are guaranteed; everything else depends on
|
|
23
|
+
// the attachment kind (file vs image vs link preview vs unfurled GIF).
|
|
24
|
+
// Loose: unknown keys from the backend pass through rather than being stripped,
|
|
25
|
+
// so newly-added or off-spec fields stay accessible to callers.
|
|
26
|
+
exports.AttachmentSchema = zod_1.z
|
|
27
|
+
.object({
|
|
28
|
+
attachmentId: zod_1.z.string(),
|
|
29
|
+
urlType: zod_1.z.string(),
|
|
30
|
+
title: zod_1.z.string().nullable().optional(),
|
|
31
|
+
url: zod_1.z.string().nullable().optional(),
|
|
32
|
+
fileName: zod_1.z.string().nullable().optional(),
|
|
33
|
+
fileSize: zod_1.z.number().int().nonnegative().nullable().optional(),
|
|
34
|
+
underlyingType: zod_1.z.string().nullable().optional(),
|
|
35
|
+
description: zod_1.z.string().nullable().optional(),
|
|
36
|
+
image: zod_1.z.string().nullable().optional(),
|
|
37
|
+
imageWidth: zod_1.z.number().int().nonnegative().nullable().optional(),
|
|
38
|
+
imageHeight: zod_1.z.number().int().nonnegative().nullable().optional(),
|
|
39
|
+
duration: zod_1.z.string().nullable().optional(),
|
|
40
|
+
uploadState: zod_1.z.string().nullable().optional(),
|
|
41
|
+
video: zod_1.z.string().nullable().optional(),
|
|
42
|
+
videoType: zod_1.z.string().nullable().optional(),
|
|
43
|
+
videoAutoPlay: zod_1.z.boolean().nullable().optional(),
|
|
44
|
+
})
|
|
45
|
+
.loose();
|
|
20
46
|
// Base user schema with common fields shared between User and WorkspaceUser
|
|
21
47
|
exports.BaseUserSchema = zod_1.z.object({
|
|
22
48
|
id: zod_1.z.number(),
|
|
@@ -118,7 +144,7 @@ exports.ThreadSchema = zod_1.z
|
|
|
118
144
|
channelId: zod_1.z.number(),
|
|
119
145
|
workspaceId: zod_1.z.number(),
|
|
120
146
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
121
|
-
attachments: zod_1.z.array(
|
|
147
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
122
148
|
commentCount: zod_1.z.number(),
|
|
123
149
|
closed: zod_1.z.boolean().nullable().optional(),
|
|
124
150
|
directGroupMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
@@ -155,7 +181,7 @@ exports.ThreadSchema = zod_1.z
|
|
|
155
181
|
channelId: zod_1.z.number(),
|
|
156
182
|
posted: zod_1.z.date(),
|
|
157
183
|
systemMessage: exports.SystemMessageSchema,
|
|
158
|
-
attachments: zod_1.z.array(
|
|
184
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
159
185
|
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.number())).nullable().optional(),
|
|
160
186
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
161
187
|
objIndex: zod_1.z.number(),
|
|
@@ -212,7 +238,7 @@ exports.ConversationSchema = zod_1.z
|
|
|
212
238
|
conversationId: zod_1.z.number(),
|
|
213
239
|
posted: zod_1.z.date(),
|
|
214
240
|
systemMessage: exports.SystemMessageSchema,
|
|
215
|
-
attachments: zod_1.z.array(
|
|
241
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
216
242
|
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.number())).nullable().optional(),
|
|
217
243
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
218
244
|
objIndex: zod_1.z.number().nullable().optional(),
|
|
@@ -241,7 +267,7 @@ exports.CommentSchema = zod_1.z
|
|
|
241
267
|
directMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
242
268
|
directGroupMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
243
269
|
systemMessage: exports.SystemMessageSchema,
|
|
244
|
-
attachments: zod_1.z.array(
|
|
270
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
245
271
|
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).nullable().optional(),
|
|
246
272
|
objIndex: zod_1.z.number().nullable().optional(),
|
|
247
273
|
// Extended fields that may appear in some API responses (like inbox)
|
|
@@ -280,7 +306,7 @@ exports.ConversationMessageSchema = zod_1.z
|
|
|
280
306
|
conversationId: zod_1.z.number(),
|
|
281
307
|
posted: zod_1.z.date(),
|
|
282
308
|
systemMessage: exports.SystemMessageSchema,
|
|
283
|
-
attachments: zod_1.z.array(
|
|
309
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
284
310
|
reactions: zod_1.z.record(zod_1.z.string(), zod_1.z.array(zod_1.z.number())).nullable().optional(),
|
|
285
311
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
286
312
|
objIndex: zod_1.z.number().nullable().optional(),
|
|
@@ -307,7 +333,7 @@ exports.InboxThreadSchema = zod_1.z
|
|
|
307
333
|
channelId: zod_1.z.number(),
|
|
308
334
|
workspaceId: zod_1.z.number(),
|
|
309
335
|
actions: zod_1.z.array(zod_1.z.unknown()).nullable().optional(),
|
|
310
|
-
attachments: zod_1.z.array(
|
|
336
|
+
attachments: zod_1.z.array(exports.AttachmentSchema).nullable().optional(),
|
|
311
337
|
commentCount: zod_1.z.number(),
|
|
312
338
|
directGroupMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
313
339
|
directMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
package/dist/cjs/types/enums.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WORKSPACE_PLANS = exports.USER_TYPES = void 0;
|
|
3
|
+
exports.NOTIFY_AUDIENCE_GROUP_IDS = exports.NOTIFY_AUDIENCES = exports.WORKSPACE_PLANS = exports.USER_TYPES = void 0;
|
|
4
4
|
// User types for workspace users
|
|
5
5
|
exports.USER_TYPES = ['USER', 'GUEST', 'ADMIN'];
|
|
6
6
|
// Workspace plans
|
|
7
7
|
exports.WORKSPACE_PLANS = ['free', 'unlimited'];
|
|
8
|
+
// Audiences that comment-creating endpoints can target alongside (or instead
|
|
9
|
+
// of) individual `recipients` / custom `groups`.
|
|
10
|
+
exports.NOTIFY_AUDIENCES = ['channel', 'thread'];
|
|
11
|
+
/**
|
|
12
|
+
* Internal mapping from {@link NotifyAudience} to the magic group IDs that
|
|
13
|
+
* Twist's `comments/add` endpoint uses on the wire. Exposed here so the
|
|
14
|
+
* audience constants and their encoding stay in a single source of truth;
|
|
15
|
+
* SDK consumers should use {@link NotifyAudience} via `notifyAudience` on the
|
|
16
|
+
* request args rather than passing these IDs directly.
|
|
17
|
+
*/
|
|
18
|
+
exports.NOTIFY_AUDIENCE_GROUP_IDS = {
|
|
19
|
+
channel: 1,
|
|
20
|
+
thread: 2,
|
|
21
|
+
};
|
|
@@ -2,6 +2,8 @@
|
|
|
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");
|
|
6
|
+
var enums_1 = require("./enums");
|
|
5
7
|
exports.CreateChannelArgsSchema = zod_1.z.object({
|
|
6
8
|
workspaceId: zod_1.z.number(),
|
|
7
9
|
name: zod_1.z.string(),
|
|
@@ -43,9 +45,12 @@ exports.CreateCommentArgsSchema = zod_1.z.object({
|
|
|
43
45
|
threadId: zod_1.z.number(),
|
|
44
46
|
content: zod_1.z.string(),
|
|
45
47
|
tempId: zod_1.z.number().nullable().optional(),
|
|
46
|
-
attachments: zod_1.z.
|
|
48
|
+
attachments: zod_1.z.array(entities_1.AttachmentSchema).nullable().optional(),
|
|
47
49
|
actions: zod_1.z.unknown().nullable().optional(),
|
|
48
50
|
recipients: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
51
|
+
groups: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
52
|
+
directMentions: zod_1.z.array(zod_1.z.number()).nullable().optional(),
|
|
53
|
+
notifyAudience: zod_1.z.enum(enums_1.NOTIFY_AUDIENCES).nullable().optional(),
|
|
49
54
|
});
|
|
50
55
|
exports.UpdateCommentArgsSchema = zod_1.z.object({
|
|
51
56
|
id: zod_1.z.number(),
|
|
@@ -61,7 +66,7 @@ exports.CreateMessageArgsSchema = zod_1.z
|
|
|
61
66
|
conversationId: zod_1.z.number().nullable().optional(),
|
|
62
67
|
threadId: zod_1.z.number().nullable().optional(),
|
|
63
68
|
content: zod_1.z.string(),
|
|
64
|
-
attachments: zod_1.z.array(
|
|
69
|
+
attachments: zod_1.z.array(entities_1.AttachmentSchema).nullable().optional(),
|
|
65
70
|
})
|
|
66
71
|
.refine(function (data) {
|
|
67
72
|
return ((data.conversationId && !data.threadId) || (!data.conversationId && data.threadId));
|
|
@@ -9,14 +9,56 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
23
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
24
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
25
|
+
if (ar || !(i in from)) {
|
|
26
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
27
|
+
ar[i] = from[i];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
31
|
+
};
|
|
12
32
|
import { ENDPOINT_COMMENTS } from '../consts/endpoints.js';
|
|
13
33
|
import { request } from '../transport/http-client.js';
|
|
14
34
|
import { CommentSchema } from '../types/entities.js';
|
|
35
|
+
import { NOTIFY_AUDIENCE_GROUP_IDS, NOTIFY_AUDIENCES } from '../types/enums.js';
|
|
36
|
+
var SENTINEL_GROUP_IDS = new Set(Object.values(NOTIFY_AUDIENCE_GROUP_IDS));
|
|
37
|
+
function isNotifyAudience(value) {
|
|
38
|
+
return typeof value === 'string' && NOTIFY_AUDIENCES.includes(value);
|
|
39
|
+
}
|
|
40
|
+
function applyNotifyAudience(params) {
|
|
41
|
+
if (params.groups) {
|
|
42
|
+
var offending = params.groups.filter(function (id) { return SENTINEL_GROUP_IDS.has(id); });
|
|
43
|
+
if (offending.length > 0) {
|
|
44
|
+
throw new Error("`groups` must not contain reserved sentinel IDs (".concat(offending.join(', '), "). Use `notifyAudience` instead."));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (params.notifyAudience == null)
|
|
48
|
+
return params;
|
|
49
|
+
if (!isNotifyAudience(params.notifyAudience)) {
|
|
50
|
+
throw new Error("Invalid `notifyAudience` value \"".concat(String(params.notifyAudience), "\". Expected one of: ").concat(NOTIFY_AUDIENCES.join(', '), "."));
|
|
51
|
+
}
|
|
52
|
+
var sentinel = NOTIFY_AUDIENCE_GROUP_IDS[params.notifyAudience];
|
|
53
|
+
var _stripped = params.notifyAudience, groups = params.groups, rest = __rest(params, ["notifyAudience", "groups"]);
|
|
54
|
+
return __assign(__assign({}, rest), { groups: __spreadArray(__spreadArray([], (groups !== null && groups !== void 0 ? groups : []), true), [sentinel], false) });
|
|
55
|
+
}
|
|
15
56
|
export function addCommentRequest(context, params, options) {
|
|
16
57
|
var method = 'POST';
|
|
17
58
|
var url = "".concat(ENDPOINT_COMMENTS, "/add");
|
|
59
|
+
var normalized = applyNotifyAudience(params);
|
|
18
60
|
var payload = (options === null || options === void 0 ? void 0 : options.threadAction)
|
|
19
|
-
? __assign(__assign({},
|
|
61
|
+
? __assign(__assign({}, normalized), { threadAction: options.threadAction }) : normalized;
|
|
20
62
|
var schema = CommentSchema;
|
|
21
63
|
if (options === null || options === void 0 ? void 0 : options.batch) {
|
|
22
64
|
return { method: method, url: url, params: payload, schema: schema };
|
|
@@ -14,6 +14,32 @@ import { getFullTwistURL } from '../utils/url-helpers.js';
|
|
|
14
14
|
import { USER_TYPES, WORKSPACE_PLANS } from './enums.js';
|
|
15
15
|
// Reusable schema for system messages that can be either a string or an object
|
|
16
16
|
export var SystemMessageSchema = z.union([z.string(), z.unknown()]).nullable().optional();
|
|
17
|
+
// Attachment entity from API. Mirrors the canonical backend shape produced by
|
|
18
|
+
// `unify_attachments` / `validate_file_attachment_json` in the Twist backend.
|
|
19
|
+
// Only `attachmentId` and `urlType` are guaranteed; everything else depends on
|
|
20
|
+
// the attachment kind (file vs image vs link preview vs unfurled GIF).
|
|
21
|
+
// Loose: unknown keys from the backend pass through rather than being stripped,
|
|
22
|
+
// so newly-added or off-spec fields stay accessible to callers.
|
|
23
|
+
export var AttachmentSchema = z
|
|
24
|
+
.object({
|
|
25
|
+
attachmentId: z.string(),
|
|
26
|
+
urlType: z.string(),
|
|
27
|
+
title: z.string().nullable().optional(),
|
|
28
|
+
url: z.string().nullable().optional(),
|
|
29
|
+
fileName: z.string().nullable().optional(),
|
|
30
|
+
fileSize: z.number().int().nonnegative().nullable().optional(),
|
|
31
|
+
underlyingType: z.string().nullable().optional(),
|
|
32
|
+
description: z.string().nullable().optional(),
|
|
33
|
+
image: z.string().nullable().optional(),
|
|
34
|
+
imageWidth: z.number().int().nonnegative().nullable().optional(),
|
|
35
|
+
imageHeight: z.number().int().nonnegative().nullable().optional(),
|
|
36
|
+
duration: z.string().nullable().optional(),
|
|
37
|
+
uploadState: z.string().nullable().optional(),
|
|
38
|
+
video: z.string().nullable().optional(),
|
|
39
|
+
videoType: z.string().nullable().optional(),
|
|
40
|
+
videoAutoPlay: z.boolean().nullable().optional(),
|
|
41
|
+
})
|
|
42
|
+
.loose();
|
|
17
43
|
// Base user schema with common fields shared between User and WorkspaceUser
|
|
18
44
|
export var BaseUserSchema = z.object({
|
|
19
45
|
id: z.number(),
|
|
@@ -115,7 +141,7 @@ export var ThreadSchema = z
|
|
|
115
141
|
channelId: z.number(),
|
|
116
142
|
workspaceId: z.number(),
|
|
117
143
|
actions: z.array(z.unknown()).nullable().optional(),
|
|
118
|
-
attachments: z.array(
|
|
144
|
+
attachments: z.array(AttachmentSchema).nullable().optional(),
|
|
119
145
|
commentCount: z.number(),
|
|
120
146
|
closed: z.boolean().nullable().optional(),
|
|
121
147
|
directGroupMentions: z.array(z.number()).nullable().optional(),
|
|
@@ -152,7 +178,7 @@ export var ThreadSchema = z
|
|
|
152
178
|
channelId: z.number(),
|
|
153
179
|
posted: z.date(),
|
|
154
180
|
systemMessage: SystemMessageSchema,
|
|
155
|
-
attachments: z.array(
|
|
181
|
+
attachments: z.array(AttachmentSchema).nullable().optional(),
|
|
156
182
|
reactions: z.record(z.string(), z.array(z.number())).nullable().optional(),
|
|
157
183
|
actions: z.array(z.unknown()).nullable().optional(),
|
|
158
184
|
objIndex: z.number(),
|
|
@@ -209,7 +235,7 @@ export var ConversationSchema = z
|
|
|
209
235
|
conversationId: z.number(),
|
|
210
236
|
posted: z.date(),
|
|
211
237
|
systemMessage: SystemMessageSchema,
|
|
212
|
-
attachments: z.array(
|
|
238
|
+
attachments: z.array(AttachmentSchema).nullable().optional(),
|
|
213
239
|
reactions: z.record(z.string(), z.array(z.number())).nullable().optional(),
|
|
214
240
|
actions: z.array(z.unknown()).nullable().optional(),
|
|
215
241
|
objIndex: z.number().nullable().optional(),
|
|
@@ -238,7 +264,7 @@ export var CommentSchema = z
|
|
|
238
264
|
directMentions: z.array(z.number()).nullable().optional(),
|
|
239
265
|
directGroupMentions: z.array(z.number()).nullable().optional(),
|
|
240
266
|
systemMessage: SystemMessageSchema,
|
|
241
|
-
attachments: z.array(
|
|
267
|
+
attachments: z.array(AttachmentSchema).nullable().optional(),
|
|
242
268
|
reactions: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
243
269
|
objIndex: z.number().nullable().optional(),
|
|
244
270
|
// Extended fields that may appear in some API responses (like inbox)
|
|
@@ -277,7 +303,7 @@ export var ConversationMessageSchema = z
|
|
|
277
303
|
conversationId: z.number(),
|
|
278
304
|
posted: z.date(),
|
|
279
305
|
systemMessage: SystemMessageSchema,
|
|
280
|
-
attachments: z.array(
|
|
306
|
+
attachments: z.array(AttachmentSchema).nullable().optional(),
|
|
281
307
|
reactions: z.record(z.string(), z.array(z.number())).nullable().optional(),
|
|
282
308
|
actions: z.array(z.unknown()).nullable().optional(),
|
|
283
309
|
objIndex: z.number().nullable().optional(),
|
|
@@ -304,7 +330,7 @@ export var InboxThreadSchema = z
|
|
|
304
330
|
channelId: z.number(),
|
|
305
331
|
workspaceId: z.number(),
|
|
306
332
|
actions: z.array(z.unknown()).nullable().optional(),
|
|
307
|
-
attachments: z.array(
|
|
333
|
+
attachments: z.array(AttachmentSchema).nullable().optional(),
|
|
308
334
|
commentCount: z.number(),
|
|
309
335
|
directGroupMentions: z.array(z.number()).nullable().optional(),
|
|
310
336
|
directMentions: z.array(z.number()).nullable().optional(),
|
package/dist/esm/types/enums.js
CHANGED
|
@@ -2,3 +2,17 @@
|
|
|
2
2
|
export var USER_TYPES = ['USER', 'GUEST', 'ADMIN'];
|
|
3
3
|
// Workspace plans
|
|
4
4
|
export var WORKSPACE_PLANS = ['free', 'unlimited'];
|
|
5
|
+
// Audiences that comment-creating endpoints can target alongside (or instead
|
|
6
|
+
// of) individual `recipients` / custom `groups`.
|
|
7
|
+
export var NOTIFY_AUDIENCES = ['channel', 'thread'];
|
|
8
|
+
/**
|
|
9
|
+
* Internal mapping from {@link NotifyAudience} to the magic group IDs that
|
|
10
|
+
* Twist's `comments/add` endpoint uses on the wire. Exposed here so the
|
|
11
|
+
* audience constants and their encoding stay in a single source of truth;
|
|
12
|
+
* SDK consumers should use {@link NotifyAudience} via `notifyAudience` on the
|
|
13
|
+
* request args rather than passing these IDs directly.
|
|
14
|
+
*/
|
|
15
|
+
export var NOTIFY_AUDIENCE_GROUP_IDS = {
|
|
16
|
+
channel: 1,
|
|
17
|
+
thread: 2,
|
|
18
|
+
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { AttachmentSchema } from './entities.js';
|
|
3
|
+
import { NOTIFY_AUDIENCES } from './enums.js';
|
|
2
4
|
export var CreateChannelArgsSchema = z.object({
|
|
3
5
|
workspaceId: z.number(),
|
|
4
6
|
name: z.string(),
|
|
@@ -40,9 +42,12 @@ export var CreateCommentArgsSchema = z.object({
|
|
|
40
42
|
threadId: z.number(),
|
|
41
43
|
content: z.string(),
|
|
42
44
|
tempId: z.number().nullable().optional(),
|
|
43
|
-
attachments: z.
|
|
45
|
+
attachments: z.array(AttachmentSchema).nullable().optional(),
|
|
44
46
|
actions: z.unknown().nullable().optional(),
|
|
45
47
|
recipients: z.array(z.number()).nullable().optional(),
|
|
48
|
+
groups: z.array(z.number()).nullable().optional(),
|
|
49
|
+
directMentions: z.array(z.number()).nullable().optional(),
|
|
50
|
+
notifyAudience: z.enum(NOTIFY_AUDIENCES).nullable().optional(),
|
|
46
51
|
});
|
|
47
52
|
export var UpdateCommentArgsSchema = z.object({
|
|
48
53
|
id: z.number(),
|
|
@@ -58,7 +63,7 @@ export var CreateMessageArgsSchema = z
|
|
|
58
63
|
conversationId: z.number().nullable().optional(),
|
|
59
64
|
threadId: z.number().nullable().optional(),
|
|
60
65
|
content: z.string(),
|
|
61
|
-
attachments: z.array(
|
|
66
|
+
attachments: z.array(AttachmentSchema).nullable().optional(),
|
|
62
67
|
})
|
|
63
68
|
.refine(function (data) {
|
|
64
69
|
return ((data.conversationId && !data.threadId) || (!data.conversationId && data.threadId));
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { BatchRequestDescriptor } from '../types/batch.js';
|
|
2
2
|
import { type Comment } from '../types/entities.js';
|
|
3
3
|
import type { CustomFetch } from '../types/http.js';
|
|
4
|
-
import type { ThreadAction } from '../types/requests.js';
|
|
4
|
+
import type { CreateCommentArgs, ThreadAction } from '../types/requests.js';
|
|
5
5
|
type ClientContext = {
|
|
6
6
|
baseUri: string;
|
|
7
7
|
apiToken: string;
|
|
8
8
|
customFetch?: CustomFetch;
|
|
9
9
|
};
|
|
10
|
-
export declare function addCommentRequest(context: ClientContext, params:
|
|
10
|
+
export declare function addCommentRequest(context: ClientContext, params: CreateCommentArgs, options?: {
|
|
11
11
|
batch?: boolean;
|
|
12
12
|
threadAction?: ThreadAction;
|
|
13
13
|
}): Promise<Comment> | BatchRequestDescriptor<Comment>;
|
|
@@ -52,17 +52,26 @@ export declare class CommentsClient extends BaseClient {
|
|
|
52
52
|
* @param args - The arguments for creating a comment.
|
|
53
53
|
* @param args.threadId - The thread ID.
|
|
54
54
|
* @param args.content - The comment content.
|
|
55
|
-
* @param args.recipients - Optional array of user IDs to notify.
|
|
56
|
-
* @param args.
|
|
55
|
+
* @param args.recipients - Optional array of user IDs to notify directly.
|
|
56
|
+
* @param args.groups - Optional array of custom group IDs to notify.
|
|
57
|
+
* @param args.directMentions - Optional array of user IDs that were @-mentioned in
|
|
58
|
+
* `content`.
|
|
59
|
+
* @param args.notifyAudience - Optional broader audience to notify in addition to
|
|
60
|
+
* `recipients` and `groups`. `'channel'` notifies everyone in the channel;
|
|
61
|
+
* `'thread'` notifies everyone who has interacted with the thread.
|
|
62
|
+
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
57
63
|
* @param args.sendAsIntegration - Optional flag to send as integration.
|
|
58
64
|
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
59
65
|
* @returns The created comment object.
|
|
60
66
|
*
|
|
61
67
|
* @example
|
|
62
68
|
* ```typescript
|
|
69
|
+
* // Notify everyone who has interacted with the thread, plus two extra users.
|
|
63
70
|
* const comment = await api.comments.createComment({
|
|
64
71
|
* threadId: 789,
|
|
65
|
-
* content: 'Great idea! Let\'s proceed
|
|
72
|
+
* content: 'Great idea! Let\'s proceed.',
|
|
73
|
+
* notifyAudience: 'thread',
|
|
74
|
+
* recipients: [12345, 67890],
|
|
66
75
|
* })
|
|
67
76
|
* ```
|
|
68
77
|
*/
|
|
@@ -79,7 +88,6 @@ export declare class CommentsClient extends BaseClient {
|
|
|
79
88
|
* @param args.id - The comment ID.
|
|
80
89
|
* @param args.content - Optional new comment content.
|
|
81
90
|
* @param args.recipients - Optional array of user IDs to notify.
|
|
82
|
-
* @param args.attachments - Optional array of attachment objects.
|
|
83
91
|
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
84
92
|
* @returns The updated comment object.
|
|
85
93
|
*/
|
|
@@ -56,7 +56,7 @@ export declare class ConversationMessagesClient extends BaseClient {
|
|
|
56
56
|
* @param args - The arguments for creating a message.
|
|
57
57
|
* @param args.conversationId - The conversation ID.
|
|
58
58
|
* @param args.content - The message content.
|
|
59
|
-
* @param args.attachments - Optional array of
|
|
59
|
+
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
60
60
|
* @param args.actions - Optional array of action objects.
|
|
61
61
|
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
62
62
|
* @returns The created message object.
|
|
@@ -81,7 +81,7 @@ export declare class ConversationMessagesClient extends BaseClient {
|
|
|
81
81
|
* @param args - The arguments for updating a message.
|
|
82
82
|
* @param args.id - The message ID.
|
|
83
83
|
* @param args.content - The new message content.
|
|
84
|
-
* @param args.attachments - Optional array of
|
|
84
|
+
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
85
85
|
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
86
86
|
* @returns The updated message object.
|
|
87
87
|
*
|
|
@@ -54,7 +54,6 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
54
54
|
* @param args.title - The thread title.
|
|
55
55
|
* @param args.content - The thread content.
|
|
56
56
|
* @param args.recipients - Optional array of user IDs to notify.
|
|
57
|
-
* @param args.attachments - Optional array of attachment objects.
|
|
58
57
|
* @param args.sendAsIntegration - Optional flag to send as integration.
|
|
59
58
|
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
60
59
|
* @returns The created thread object.
|
|
@@ -82,7 +81,6 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
82
81
|
* @param args.title - Optional new thread title.
|
|
83
82
|
* @param args.content - Optional new thread content.
|
|
84
83
|
* @param args.recipients - Optional array of user IDs to notify.
|
|
85
|
-
* @param args.attachments - Optional array of attachment objects.
|
|
86
84
|
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
87
85
|
* @returns The updated thread object.
|
|
88
86
|
*/
|
|
@@ -328,9 +326,15 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
328
326
|
* @param args.id - The thread ID.
|
|
329
327
|
* @param args.content - The comment content.
|
|
330
328
|
* @param args.tempId - Optional temporary identifier.
|
|
331
|
-
* @param args.attachments - Optional array of
|
|
329
|
+
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
332
330
|
* @param args.actions - Optional array of action objects.
|
|
333
|
-
* @param args.recipients - Optional array of user IDs to notify.
|
|
331
|
+
* @param args.recipients - Optional array of user IDs to notify directly.
|
|
332
|
+
* @param args.groups - Optional array of custom group IDs to notify.
|
|
333
|
+
* @param args.directMentions - Optional array of user IDs that were @-mentioned in
|
|
334
|
+
* `content`.
|
|
335
|
+
* @param args.notifyAudience - Optional broader audience to notify in addition to
|
|
336
|
+
* `recipients` and `groups`. `'channel'` notifies everyone in the channel;
|
|
337
|
+
* `'thread'` notifies everyone who has interacted with the thread.
|
|
334
338
|
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
335
339
|
* @returns The created comment object.
|
|
336
340
|
*
|
|
@@ -355,9 +359,15 @@ export declare class ThreadsClient extends BaseClient {
|
|
|
355
359
|
* @param args.id - The thread ID.
|
|
356
360
|
* @param args.content - The comment content.
|
|
357
361
|
* @param args.tempId - Optional temporary identifier.
|
|
358
|
-
* @param args.attachments - Optional array of
|
|
362
|
+
* @param args.attachments - Optional array of {@link Attachment} objects.
|
|
359
363
|
* @param args.actions - Optional array of action objects.
|
|
360
|
-
* @param args.recipients - Optional array of user IDs to notify.
|
|
364
|
+
* @param args.recipients - Optional array of user IDs to notify directly.
|
|
365
|
+
* @param args.groups - Optional array of custom group IDs to notify.
|
|
366
|
+
* @param args.directMentions - Optional array of user IDs that were @-mentioned in
|
|
367
|
+
* `content`.
|
|
368
|
+
* @param args.notifyAudience - Optional broader audience to notify in addition to
|
|
369
|
+
* `recipients` and `groups`. `'channel'` notifies everyone in the channel;
|
|
370
|
+
* `'thread'` notifies everyone who has interacted with the thread.
|
|
361
371
|
* @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
|
|
362
372
|
* @returns The created comment object.
|
|
363
373
|
*
|