@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.
Files changed (37) hide show
  1. package/dist/cjs/clients/add-comment-helper.js +1 -2
  2. package/dist/cjs/clients/base-client.js +10 -0
  3. package/dist/cjs/clients/channels-client.js +9 -6
  4. package/dist/cjs/clients/comments-client.js +16 -6
  5. package/dist/cjs/clients/conversation-messages-client.js +9 -8
  6. package/dist/cjs/clients/conversations-client.js +11 -8
  7. package/dist/cjs/clients/inbox-client.js +6 -3
  8. package/dist/cjs/clients/threads-client.js +18 -9
  9. package/dist/cjs/clients/workspace-users-client.js +9 -2
  10. package/dist/cjs/clients/workspaces-client.js +7 -3
  11. package/dist/cjs/types/entities.js +130 -84
  12. package/dist/cjs/types/requests.js +3 -2
  13. package/dist/esm/clients/add-comment-helper.js +1 -2
  14. package/dist/esm/clients/base-client.js +10 -0
  15. package/dist/esm/clients/channels-client.js +10 -7
  16. package/dist/esm/clients/comments-client.js +17 -7
  17. package/dist/esm/clients/conversation-messages-client.js +10 -9
  18. package/dist/esm/clients/conversations-client.js +12 -9
  19. package/dist/esm/clients/inbox-client.js +7 -4
  20. package/dist/esm/clients/threads-client.js +19 -10
  21. package/dist/esm/clients/workspace-users-client.js +9 -2
  22. package/dist/esm/clients/workspaces-client.js +8 -4
  23. package/dist/esm/types/entities.js +123 -83
  24. package/dist/esm/types/requests.js +3 -2
  25. package/dist/types/clients/add-comment-helper.d.ts +3 -1
  26. package/dist/types/clients/base-client.d.ts +4 -0
  27. package/dist/types/clients/channels-client.d.ts +1 -0
  28. package/dist/types/clients/comments-client.d.ts +2 -2
  29. package/dist/types/clients/conversation-messages-client.d.ts +3 -2
  30. package/dist/types/clients/conversations-client.d.ts +1 -0
  31. package/dist/types/clients/inbox-client.d.ts +1 -0
  32. package/dist/types/clients/threads-client.d.ts +4 -4
  33. package/dist/types/clients/workspace-users-client.d.ts +5 -0
  34. package/dist/types/clients/workspaces-client.d.ts +1 -0
  35. package/dist/types/types/entities.d.ts +1845 -65
  36. package/dist/types/types/requests.d.ts +44 -4
  37. package/package.json +6 -2
@@ -16,7 +16,7 @@ var __extends = (this && this.__extends) || (function () {
16
16
  import { z } from 'zod';
17
17
  import { ENDPOINT_CONVERSATIONS } from '../consts/endpoints.js';
18
18
  import { request } from '../transport/http-client.js';
19
- import { ConversationSchema, UnreadConversationSchema, } from '../types/entities.js';
19
+ import { createConversationSchema, UnreadConversationSchema, } from '../types/entities.js';
20
20
  import { BaseClient } from './base-client.js';
21
21
  /**
22
22
  * Client for interacting with Twist conversation endpoints.
@@ -24,14 +24,17 @@ import { BaseClient } from './base-client.js';
24
24
  var ConversationsClient = /** @class */ (function (_super) {
25
25
  __extends(ConversationsClient, _super);
26
26
  function ConversationsClient() {
27
- return _super !== null && _super.apply(this, arguments) || this;
27
+ var _this = _super !== null && _super.apply(this, arguments) || this;
28
+ _this.conversationSchema = createConversationSchema(_this.getLinkBaseUrl());
29
+ return _this;
28
30
  }
29
31
  ConversationsClient.prototype.getConversations = function (args, options) {
32
+ var _this = this;
30
33
  var method = 'GET';
31
34
  var url = "".concat(ENDPOINT_CONVERSATIONS, "/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(ConversationSchema) };
37
+ return { method: method, url: url, params: params, schema: z.array(this.conversationSchema) };
35
38
  }
36
39
  return request({
37
40
  httpMethod: method,
@@ -41,14 +44,14 @@ var ConversationsClient = /** @class */ (function (_super) {
41
44
  payload: params,
42
45
  customFetch: this.customFetch,
43
46
  }).then(function (response) {
44
- return response.data.map(function (conversation) { return ConversationSchema.parse(conversation); });
47
+ return response.data.map(function (conversation) { return _this.conversationSchema.parse(conversation); });
45
48
  });
46
49
  };
47
50
  ConversationsClient.prototype.getConversation = function (id, options) {
48
51
  var method = 'GET';
49
52
  var url = "".concat(ENDPOINT_CONVERSATIONS, "/getone");
50
53
  var params = { id: id };
51
- var schema = ConversationSchema;
54
+ var schema = this.conversationSchema;
52
55
  if (options === null || options === void 0 ? void 0 : options.batch) {
53
56
  return { method: method, url: url, params: params, schema: schema };
54
57
  }
@@ -65,7 +68,7 @@ var ConversationsClient = /** @class */ (function (_super) {
65
68
  var method = 'POST';
66
69
  var url = "".concat(ENDPOINT_CONVERSATIONS, "/get_or_create");
67
70
  var params = args;
68
- var schema = ConversationSchema;
71
+ var schema = this.conversationSchema;
69
72
  if (options === null || options === void 0 ? void 0 : options.batch) {
70
73
  return { method: method, url: url, params: params, schema: schema };
71
74
  }
@@ -84,7 +87,7 @@ var ConversationsClient = /** @class */ (function (_super) {
84
87
  params.archived = args.archived;
85
88
  var method = 'POST';
86
89
  var url = "".concat(ENDPOINT_CONVERSATIONS, "/update");
87
- var schema = ConversationSchema;
90
+ var schema = this.conversationSchema;
88
91
  if (options === null || options === void 0 ? void 0 : options.batch) {
89
92
  return { method: method, url: url, params: params, schema: schema };
90
93
  }
@@ -255,7 +258,7 @@ var ConversationsClient = /** @class */ (function (_super) {
255
258
  var method = 'POST';
256
259
  var url = "".concat(ENDPOINT_CONVERSATIONS, "/mute");
257
260
  var params = { id: args.id, minutes: args.minutes };
258
- var schema = ConversationSchema;
261
+ var schema = this.conversationSchema;
259
262
  if (options === null || options === void 0 ? void 0 : options.batch) {
260
263
  return { method: method, url: url, params: params, schema: schema };
261
264
  }
@@ -272,7 +275,7 @@ var ConversationsClient = /** @class */ (function (_super) {
272
275
  var method = 'POST';
273
276
  var url = "".concat(ENDPOINT_CONVERSATIONS, "/unmute");
274
277
  var params = { id: id };
275
- var schema = ConversationSchema;
278
+ var schema = this.conversationSchema;
276
279
  if (options === null || options === void 0 ? void 0 : options.batch) {
277
280
  return { method: method, url: url, params: params, schema: schema };
278
281
  }
@@ -16,7 +16,7 @@ var __extends = (this && this.__extends) || (function () {
16
16
  import { z } from 'zod';
17
17
  import { ENDPOINT_INBOX } from '../consts/endpoints.js';
18
18
  import { request } from '../transport/http-client.js';
19
- import { InboxThreadSchema } from '../types/entities.js';
19
+ import { createInboxThreadSchema } from '../types/entities.js';
20
20
  import { BaseClient } from './base-client.js';
21
21
  /**
22
22
  * Client for interacting with Twist inbox endpoints.
@@ -24,9 +24,12 @@ import { BaseClient } from './base-client.js';
24
24
  var InboxClient = /** @class */ (function (_super) {
25
25
  __extends(InboxClient, _super);
26
26
  function InboxClient() {
27
- return _super !== null && _super.apply(this, arguments) || this;
27
+ var _this = _super !== null && _super.apply(this, arguments) || this;
28
+ _this.inboxThreadSchema = createInboxThreadSchema(_this.getLinkBaseUrl());
29
+ return _this;
28
30
  }
29
31
  InboxClient.prototype.getInbox = function (args, options) {
32
+ var _this = this;
30
33
  var _a, _b;
31
34
  var params = {
32
35
  workspace_id: args.workspaceId,
@@ -46,7 +49,7 @@ var InboxClient = /** @class */ (function (_super) {
46
49
  var method = 'GET';
47
50
  var url = "".concat(ENDPOINT_INBOX, "/get");
48
51
  if (options === null || options === void 0 ? void 0 : options.batch) {
49
- return { method: method, url: url, params: params, schema: z.array(InboxThreadSchema) };
52
+ return { method: method, url: url, params: params, schema: z.array(this.inboxThreadSchema) };
50
53
  }
51
54
  return request({
52
55
  httpMethod: method,
@@ -55,7 +58,7 @@ var InboxClient = /** @class */ (function (_super) {
55
58
  apiToken: this.apiToken,
56
59
  payload: params,
57
60
  customFetch: this.customFetch,
58
- }).then(function (response) { return response.data.map(function (thread) { return InboxThreadSchema.parse(thread); }); });
61
+ }).then(function (response) { return response.data.map(function (thread) { return _this.inboxThreadSchema.parse(thread); }); });
59
62
  };
60
63
  InboxClient.prototype.getCount = function (workspaceId, options) {
61
64
  var method = 'GET';
@@ -38,7 +38,7 @@ var __rest = (this && this.__rest) || function (s, e) {
38
38
  import { z } from 'zod';
39
39
  import { ENDPOINT_THREADS } from '../consts/endpoints.js';
40
40
  import { request } from '../transport/http-client.js';
41
- import { ThreadSchema, UnreadThreadSchema, } from '../types/entities.js';
41
+ import { createCommentSchema, createThreadSchema, UnreadThreadSchema, } from '../types/entities.js';
42
42
  import { addCommentRequest } from './add-comment-helper.js';
43
43
  import { BaseClient } from './base-client.js';
44
44
  /**
@@ -47,9 +47,13 @@ import { BaseClient } from './base-client.js';
47
47
  var ThreadsClient = /** @class */ (function (_super) {
48
48
  __extends(ThreadsClient, _super);
49
49
  function ThreadsClient() {
50
- return _super !== null && _super.apply(this, arguments) || this;
50
+ var _this = _super !== null && _super.apply(this, arguments) || this;
51
+ _this.threadSchema = createThreadSchema(_this.getLinkBaseUrl());
52
+ _this.commentSchema = createCommentSchema(_this.getLinkBaseUrl());
53
+ return _this;
51
54
  }
52
55
  ThreadsClient.prototype.getThreads = function (args, options) {
56
+ var _this = this;
53
57
  var method = 'GET';
54
58
  var url = "".concat(ENDPOINT_THREADS, "/get");
55
59
  var newerThan = args.newerThan, olderThan = args.olderThan, newer_than_ts = args.newer_than_ts, older_than_ts = args.older_than_ts, rest = __rest(args, ["newerThan", "olderThan", "newer_than_ts", "older_than_ts"]);
@@ -57,7 +61,7 @@ var ThreadsClient = /** @class */ (function (_super) {
57
61
  var resolvedOlderThan = olderThan ? Math.floor(olderThan.getTime() / 1000) : older_than_ts;
58
62
  var params = __assign(__assign(__assign({}, rest), (resolvedNewerThan != null ? { newer_than_ts: resolvedNewerThan } : {})), (resolvedOlderThan != null ? { older_than_ts: resolvedOlderThan } : {}));
59
63
  if (options === null || options === void 0 ? void 0 : options.batch) {
60
- return { method: method, url: url, params: params, schema: z.array(ThreadSchema) };
64
+ return { method: method, url: url, params: params, schema: z.array(this.threadSchema) };
61
65
  }
62
66
  return request({
63
67
  httpMethod: method,
@@ -66,13 +70,13 @@ var ThreadsClient = /** @class */ (function (_super) {
66
70
  apiToken: this.apiToken,
67
71
  payload: params,
68
72
  customFetch: this.customFetch,
69
- }).then(function (response) { return response.data.map(function (thread) { return ThreadSchema.parse(thread); }); });
73
+ }).then(function (response) { return response.data.map(function (thread) { return _this.threadSchema.parse(thread); }); });
70
74
  };
71
75
  ThreadsClient.prototype.getThread = function (id, options) {
72
76
  var method = 'GET';
73
77
  var url = "".concat(ENDPOINT_THREADS, "/getone");
74
78
  var params = { id: id };
75
- var schema = ThreadSchema;
79
+ var schema = this.threadSchema;
76
80
  if (options === null || options === void 0 ? void 0 : options.batch) {
77
81
  return { method: method, url: url, params: params, schema: schema };
78
82
  }
@@ -89,7 +93,7 @@ var ThreadsClient = /** @class */ (function (_super) {
89
93
  var method = 'POST';
90
94
  var url = "".concat(ENDPOINT_THREADS, "/add");
91
95
  var params = args;
92
- var schema = ThreadSchema;
96
+ var schema = this.threadSchema;
93
97
  if (options === null || options === void 0 ? void 0 : options.batch) {
94
98
  return { method: method, url: url, params: params, schema: schema };
95
99
  }
@@ -106,7 +110,7 @@ var ThreadsClient = /** @class */ (function (_super) {
106
110
  var method = 'POST';
107
111
  var url = "".concat(ENDPOINT_THREADS, "/update");
108
112
  var params = args;
109
- var schema = ThreadSchema;
113
+ var schema = this.threadSchema;
110
114
  if (options === null || options === void 0 ? void 0 : options.batch) {
111
115
  return { method: method, url: url, params: params, schema: schema };
112
116
  }
@@ -354,7 +358,7 @@ var ThreadsClient = /** @class */ (function (_super) {
354
358
  var method = 'POST';
355
359
  var url = "".concat(ENDPOINT_THREADS, "/mute");
356
360
  var params = { id: args.id, minutes: args.minutes };
357
- var schema = ThreadSchema;
361
+ var schema = this.threadSchema;
358
362
  if (options === null || options === void 0 ? void 0 : options.batch) {
359
363
  return { method: method, url: url, params: params, schema: schema };
360
364
  }
@@ -371,7 +375,7 @@ var ThreadsClient = /** @class */ (function (_super) {
371
375
  var method = 'POST';
372
376
  var url = "".concat(ENDPOINT_THREADS, "/unmute");
373
377
  var params = { id: id };
374
- var schema = ThreadSchema;
378
+ var schema = this.threadSchema;
375
379
  if (options === null || options === void 0 ? void 0 : options.batch) {
376
380
  return { method: method, url: url, params: params, schema: schema };
377
381
  }
@@ -392,7 +396,12 @@ var ThreadsClient = /** @class */ (function (_super) {
392
396
  };
393
397
  ThreadsClient.prototype.addCommentWithAction = function (args, threadAction, options) {
394
398
  var id = args.id, rest = __rest(args, ["id"]);
395
- return addCommentRequest({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, __assign({ threadId: id }, rest), __assign(__assign({}, options), { threadAction: threadAction }));
399
+ return addCommentRequest({
400
+ baseUri: this.getBaseUri(),
401
+ apiToken: this.apiToken,
402
+ customFetch: this.customFetch,
403
+ schema: this.commentSchema,
404
+ }, __assign({ threadId: id }, rest), __assign(__assign({}, options), { threadAction: threadAction }));
396
405
  };
397
406
  return ThreadsClient;
398
407
  }(BaseClient));
@@ -13,6 +13,7 @@ var __extends = (this && this.__extends) || (function () {
13
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
14
  };
15
15
  })();
16
+ import { z } from 'zod';
16
17
  import { request } from '../transport/http-client.js';
17
18
  import { WorkspaceUserSchema } from '../types/entities.js';
18
19
  import { BaseClient } from './base-client.js';
@@ -25,11 +26,17 @@ var WorkspaceUsersClient = /** @class */ (function (_super) {
25
26
  return _super !== null && _super.apply(this, arguments) || this;
26
27
  }
27
28
  WorkspaceUsersClient.prototype.getWorkspaceUsers = function (args, options) {
29
+ var _a;
28
30
  var method = 'GET';
29
31
  var url = 'workspace_users/get';
30
32
  var params = { id: args.workspaceId, archived: args.archived };
33
+ var includeRemoved = (_a = args.includeRemoved) !== null && _a !== void 0 ? _a : false;
34
+ function filterRemoved(users) {
35
+ return includeRemoved ? users : users.filter(function (user) { return !user.removed; });
36
+ }
37
+ var responseSchema = z.array(WorkspaceUserSchema).transform(filterRemoved);
31
38
  if (options === null || options === void 0 ? void 0 : options.batch) {
32
- return { method: method, url: url, params: params };
39
+ return { method: method, url: url, params: params, schema: responseSchema };
33
40
  }
34
41
  return request({
35
42
  httpMethod: method,
@@ -38,7 +45,7 @@ var WorkspaceUsersClient = /** @class */ (function (_super) {
38
45
  apiToken: this.apiToken,
39
46
  payload: params,
40
47
  customFetch: this.customFetch,
41
- }).then(function (response) { return response.data.map(function (user) { return WorkspaceUserSchema.parse(user); }); });
48
+ }).then(function (response) { return responseSchema.parse(response.data); });
42
49
  };
43
50
  WorkspaceUsersClient.prototype.getWorkspaceUserIds = function (workspaceId, options) {
44
51
  var method = 'GET';
@@ -13,9 +13,10 @@ var __extends = (this && this.__extends) || (function () {
13
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
14
  };
15
15
  })();
16
+ import { z } from 'zod';
16
17
  import { ENDPOINT_WORKSPACES } from '../consts/endpoints.js';
17
18
  import { request } from '../transport/http-client.js';
18
- import { ChannelSchema, WorkspaceSchema } from '../types/entities.js';
19
+ import { createChannelSchema, WorkspaceSchema } from '../types/entities.js';
19
20
  import { BaseClient } from './base-client.js';
20
21
  /**
21
22
  * Client for interacting with Twist workspace endpoints.
@@ -23,7 +24,9 @@ import { BaseClient } from './base-client.js';
23
24
  var WorkspacesClient = /** @class */ (function (_super) {
24
25
  __extends(WorkspacesClient, _super);
25
26
  function WorkspacesClient() {
26
- return _super !== null && _super.apply(this, arguments) || this;
27
+ var _this = _super !== null && _super.apply(this, arguments) || this;
28
+ _this.channelSchema = createChannelSchema(_this.getLinkBaseUrl());
29
+ return _this;
27
30
  }
28
31
  WorkspacesClient.prototype.getWorkspaces = function (options) {
29
32
  var method = 'GET';
@@ -126,11 +129,12 @@ var WorkspacesClient = /** @class */ (function (_super) {
126
129
  }).then(function () { return undefined; });
127
130
  };
128
131
  WorkspacesClient.prototype.getPublicChannels = function (id, options) {
132
+ var _this = this;
129
133
  var method = 'GET';
130
134
  var url = "".concat(ENDPOINT_WORKSPACES, "/get_public_channels");
131
135
  var params = { id: id };
132
136
  if (options === null || options === void 0 ? void 0 : options.batch) {
133
- return { method: method, url: url, params: params };
137
+ return { method: method, url: url, params: params, schema: z.array(this.channelSchema) };
134
138
  }
135
139
  return request({
136
140
  httpMethod: method,
@@ -139,7 +143,7 @@ var WorkspacesClient = /** @class */ (function (_super) {
139
143
  apiToken: this.apiToken,
140
144
  payload: params,
141
145
  customFetch: this.customFetch,
142
- }).then(function (response) { return response.data.map(function (channel) { return ChannelSchema.parse(channel); }); });
146
+ }).then(function (response) { return response.data.map(function (channel) { return _this.channelSchema.parse(channel); }); });
143
147
  };
144
148
  return WorkspacesClient;
145
149
  }(BaseClient));
@@ -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(),
@@ -83,8 +109,7 @@ export var WorkspaceSchema = z.object({
83
109
  plan: z.enum(WORKSPACE_PLANS).nullable().optional(),
84
110
  });
85
111
  // Channel entity from API
86
- export var ChannelSchema = z
87
- .object({
112
+ export var ChannelObjectSchema = z.object({
88
113
  id: z.number(),
89
114
  name: z.string(),
90
115
  description: z.string().nullable().optional(),
@@ -102,11 +127,13 @@ export var ChannelSchema = z
102
127
  icon: z.number().nullable().optional(),
103
128
  version: z.number(),
104
129
  filters: z.record(z.string(), z.string()).nullable().optional(),
105
- })
106
- .transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({ workspaceId: data.workspaceId, channelId: data.id }) })); });
130
+ });
131
+ export function createChannelSchema(linkBaseUrl) {
132
+ return ChannelObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({ workspaceId: data.workspaceId, channelId: data.id }, linkBaseUrl) })); });
133
+ }
134
+ export var ChannelSchema = createChannelSchema();
107
135
  // Thread entity from API
108
- export var ThreadSchema = z
109
- .object({
136
+ export var ThreadObjectSchema = z.object({
110
137
  id: z.number(),
111
138
  title: z.string(),
112
139
  content: z.string(),
@@ -115,7 +142,7 @@ export var ThreadSchema = z
115
142
  channelId: z.number(),
116
143
  workspaceId: z.number(),
117
144
  actions: z.array(z.unknown()).nullable().optional(),
118
- attachments: z.array(z.unknown()).nullable().optional(),
145
+ attachments: z.array(AttachmentSchema).nullable().optional(),
119
146
  commentCount: z.number(),
120
147
  closed: z.boolean().nullable().optional(),
121
148
  directGroupMentions: z.array(z.number()).nullable().optional(),
@@ -152,7 +179,7 @@ export var ThreadSchema = z
152
179
  channelId: z.number(),
153
180
  posted: z.date(),
154
181
  systemMessage: SystemMessageSchema,
155
- attachments: z.array(z.unknown()).nullable().optional(),
182
+ attachments: z.array(AttachmentSchema).nullable().optional(),
156
183
  reactions: z.record(z.string(), z.array(z.number())).nullable().optional(),
157
184
  actions: z.array(z.unknown()).nullable().optional(),
158
185
  objIndex: z.number(),
@@ -169,12 +196,15 @@ export var ThreadSchema = z
169
196
  })
170
197
  .nullable()
171
198
  .optional(),
172
- })
173
- .transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({
174
- workspaceId: data.workspaceId,
175
- channelId: data.channelId,
176
- threadId: data.id,
177
- }) })); });
199
+ });
200
+ export function createThreadSchema(linkBaseUrl) {
201
+ return ThreadObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({
202
+ workspaceId: data.workspaceId,
203
+ channelId: data.channelId,
204
+ threadId: data.id,
205
+ }, linkBaseUrl) })); });
206
+ }
207
+ export var ThreadSchema = createThreadSchema();
178
208
  // Group entity from API
179
209
  export var GroupSchema = z.object({
180
210
  id: z.number(),
@@ -185,8 +215,7 @@ export var GroupSchema = z.object({
185
215
  version: z.number(),
186
216
  });
187
217
  // Conversation entity from API
188
- export var ConversationSchema = z
189
- .object({
218
+ export var ConversationObjectSchema = z.object({
190
219
  id: z.number(),
191
220
  workspaceId: z.number(),
192
221
  userIds: z.array(z.number()),
@@ -209,7 +238,7 @@ export var ConversationSchema = z
209
238
  conversationId: z.number(),
210
239
  posted: z.date(),
211
240
  systemMessage: SystemMessageSchema,
212
- attachments: z.array(z.unknown()).nullable().optional(),
241
+ attachments: z.array(AttachmentSchema).nullable().optional(),
213
242
  reactions: z.record(z.string(), z.array(z.number())).nullable().optional(),
214
243
  actions: z.array(z.unknown()).nullable().optional(),
215
244
  objIndex: z.number().nullable().optional(),
@@ -222,11 +251,13 @@ export var ConversationSchema = z
222
251
  })
223
252
  .nullable()
224
253
  .optional(),
225
- })
226
- .transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({ workspaceId: data.workspaceId, conversationId: data.id }) })); });
254
+ });
255
+ export function createConversationSchema(linkBaseUrl) {
256
+ return ConversationObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({ workspaceId: data.workspaceId, conversationId: data.id }, linkBaseUrl) })); });
257
+ }
258
+ export var ConversationSchema = createConversationSchema();
227
259
  // Comment entity from API
228
- export var CommentSchema = z
229
- .object({
260
+ export var CommentObjectSchema = z.object({
230
261
  id: z.number(),
231
262
  content: z.string(),
232
263
  creator: z.number(),
@@ -238,7 +269,7 @@ export var CommentSchema = z
238
269
  directMentions: z.array(z.number()).nullable().optional(),
239
270
  directGroupMentions: z.array(z.number()).nullable().optional(),
240
271
  systemMessage: SystemMessageSchema,
241
- attachments: z.array(z.unknown()).nullable().optional(),
272
+ attachments: z.array(AttachmentSchema).nullable().optional(),
242
273
  reactions: z.record(z.string(), z.unknown()).nullable().optional(),
243
274
  objIndex: z.number().nullable().optional(),
244
275
  // Extended fields that may appear in some API responses (like inbox)
@@ -251,13 +282,16 @@ export var CommentSchema = z
251
282
  deletedBy: z.number().nullable().optional(),
252
283
  version: z.number().nullable().optional(),
253
284
  actions: z.array(z.unknown()).nullable().optional(),
254
- })
255
- .transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({
256
- workspaceId: data.workspaceId,
257
- channelId: data.channelId,
258
- threadId: data.threadId,
259
- commentId: data.id,
260
- }) })); });
285
+ });
286
+ export function createCommentSchema(linkBaseUrl) {
287
+ return CommentObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({
288
+ workspaceId: data.workspaceId,
289
+ channelId: data.channelId,
290
+ threadId: data.threadId,
291
+ commentId: data.id,
292
+ }, linkBaseUrl) })); });
293
+ }
294
+ export var CommentSchema = createCommentSchema();
261
295
  // WorkspaceUser entity from v4 API
262
296
  export var WorkspaceUserSchema = BaseUserSchema.extend({
263
297
  email: z.string().nullable().optional(),
@@ -269,15 +303,14 @@ export var WorkspaceUserSchema = BaseUserSchema.extend({
269
303
  version: z.number(),
270
304
  });
271
305
  // ConversationMessage entity from API
272
- export var ConversationMessageSchema = z
273
- .object({
306
+ export var ConversationMessageObjectSchema = z.object({
274
307
  id: z.number(),
275
308
  content: z.string(),
276
309
  creator: z.number(),
277
310
  conversationId: z.number(),
278
311
  posted: z.date(),
279
312
  systemMessage: SystemMessageSchema,
280
- attachments: z.array(z.unknown()).nullable().optional(),
313
+ attachments: z.array(AttachmentSchema).nullable().optional(),
281
314
  reactions: z.record(z.string(), z.array(z.number())).nullable().optional(),
282
315
  actions: z.array(z.unknown()).nullable().optional(),
283
316
  objIndex: z.number().nullable().optional(),
@@ -287,58 +320,65 @@ export var ConversationMessageSchema = z
287
320
  directMentions: z.array(z.number()).nullable().optional(),
288
321
  version: z.number().nullable().optional(),
289
322
  workspaceId: z.number(),
290
- })
291
- .transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({
292
- workspaceId: data.workspaceId,
293
- conversationId: data.conversationId,
294
- messageId: data.id,
295
- }) })); });
323
+ });
324
+ export function createConversationMessageSchema(linkBaseUrl) {
325
+ return ConversationMessageObjectSchema.transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({
326
+ workspaceId: data.workspaceId,
327
+ conversationId: data.conversationId,
328
+ messageId: data.id,
329
+ }, linkBaseUrl) })); });
330
+ }
331
+ export var ConversationMessageSchema = createConversationMessageSchema();
296
332
  // InboxThread entity from API - returns full Thread objects with additional inbox metadata
297
- export var InboxThreadSchema = z
298
- .object({
299
- id: z.number(),
300
- title: z.string(),
301
- content: z.string(),
302
- creator: z.number(),
303
- creatorName: z.string().nullable().optional(),
304
- channelId: z.number(),
305
- workspaceId: z.number(),
306
- actions: z.array(z.unknown()).nullable().optional(),
307
- attachments: z.array(z.unknown()).nullable().optional(),
308
- commentCount: z.number(),
309
- directGroupMentions: z.array(z.number()).nullable().optional(),
310
- directMentions: z.array(z.number()).nullable().optional(),
311
- groups: z.array(z.number()).nullable().optional(),
312
- lastEdited: z.date().nullable().optional(),
313
- lastObjIndex: z.number().nullable().optional(),
314
- lastUpdated: z.date(),
315
- mutedUntil: z.date().nullable().optional(),
316
- participants: z.array(z.number()).nullable().optional(),
317
- pinned: z.boolean(),
318
- pinnedDate: z.date().nullable().optional(),
319
- posted: z.date(),
320
- reactions: z.record(z.string(), z.array(z.number())).nullable().optional(),
321
- recipients: z.array(z.number()).nullable().optional(),
322
- snippet: z.string(),
323
- snippetCreator: z.number(),
324
- snippetMaskAvatarUrl: z.string().nullable().optional(),
325
- snippetMaskPoster: z.string().nullable().optional(),
326
- starred: z.boolean(),
327
- systemMessage: SystemMessageSchema,
328
- isArchived: z.boolean(),
329
- inInbox: z.boolean(),
330
- isSaved: z.boolean().nullable().optional(),
331
- closed: z.boolean(),
332
- responders: z.array(z.number()).nullable().optional(),
333
- lastComment: CommentSchema.nullable().optional(),
334
- toEmails: z.array(z.string()).nullable().optional(),
335
- version: z.number().nullable().optional(),
336
- })
337
- .transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({
338
- workspaceId: data.workspaceId,
339
- channelId: data.channelId,
340
- threadId: data.id,
341
- }) })); });
333
+ function createInboxThreadObjectSchema(linkBaseUrl) {
334
+ return z.object({
335
+ id: z.number(),
336
+ title: z.string(),
337
+ content: z.string(),
338
+ creator: z.number(),
339
+ creatorName: z.string().nullable().optional(),
340
+ channelId: z.number(),
341
+ workspaceId: z.number(),
342
+ actions: z.array(z.unknown()).nullable().optional(),
343
+ attachments: z.array(AttachmentSchema).nullable().optional(),
344
+ commentCount: z.number(),
345
+ directGroupMentions: z.array(z.number()).nullable().optional(),
346
+ directMentions: z.array(z.number()).nullable().optional(),
347
+ groups: z.array(z.number()).nullable().optional(),
348
+ lastEdited: z.date().nullable().optional(),
349
+ lastObjIndex: z.number().nullable().optional(),
350
+ lastUpdated: z.date(),
351
+ mutedUntil: z.date().nullable().optional(),
352
+ participants: z.array(z.number()).nullable().optional(),
353
+ pinned: z.boolean(),
354
+ pinnedDate: z.date().nullable().optional(),
355
+ posted: z.date(),
356
+ reactions: z.record(z.string(), z.array(z.number())).nullable().optional(),
357
+ recipients: z.array(z.number()).nullable().optional(),
358
+ snippet: z.string(),
359
+ snippetCreator: z.number(),
360
+ snippetMaskAvatarUrl: z.string().nullable().optional(),
361
+ snippetMaskPoster: z.string().nullable().optional(),
362
+ starred: z.boolean(),
363
+ systemMessage: SystemMessageSchema,
364
+ isArchived: z.boolean(),
365
+ inInbox: z.boolean(),
366
+ isSaved: z.boolean().nullable().optional(),
367
+ closed: z.boolean(),
368
+ responders: z.array(z.number()).nullable().optional(),
369
+ lastComment: createCommentSchema(linkBaseUrl).nullable().optional(),
370
+ toEmails: z.array(z.string()).nullable().optional(),
371
+ version: z.number().nullable().optional(),
372
+ });
373
+ }
374
+ export function createInboxThreadSchema(linkBaseUrl) {
375
+ return createInboxThreadObjectSchema(linkBaseUrl).transform(function (data) { return (__assign(__assign({}, data), { url: getFullTwistURL({
376
+ workspaceId: data.workspaceId,
377
+ channelId: data.channelId,
378
+ threadId: data.id,
379
+ }, linkBaseUrl) })); });
380
+ }
381
+ export var InboxThreadSchema = createInboxThreadSchema();
342
382
  // UnreadThread entity from API - simplified thread reference for unread threads
343
383
  export var UnreadThreadSchema = z.object({
344
384
  threadId: z.number(),
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { AttachmentSchema } from './entities.js';
2
3
  import { NOTIFY_AUDIENCES } from './enums.js';
3
4
  export var CreateChannelArgsSchema = z.object({
4
5
  workspaceId: z.number(),
@@ -41,7 +42,7 @@ export var CreateCommentArgsSchema = z.object({
41
42
  threadId: z.number(),
42
43
  content: z.string(),
43
44
  tempId: z.number().nullable().optional(),
44
- attachments: z.unknown().nullable().optional(),
45
+ attachments: z.array(AttachmentSchema).nullable().optional(),
45
46
  actions: z.unknown().nullable().optional(),
46
47
  recipients: z.array(z.number()).nullable().optional(),
47
48
  groups: z.array(z.number()).nullable().optional(),
@@ -62,7 +63,7 @@ export var CreateMessageArgsSchema = z
62
63
  conversationId: z.number().nullable().optional(),
63
64
  threadId: z.number().nullable().optional(),
64
65
  content: z.string(),
65
- attachments: z.array(z.number()).nullable().optional(),
66
+ attachments: z.array(AttachmentSchema).nullable().optional(),
66
67
  })
67
68
  .refine(function (data) {
68
69
  return ((data.conversationId && !data.threadId) || (!data.conversationId && data.threadId));
@@ -1,11 +1,13 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch.js';
2
- import { type Comment } from '../types/entities.js';
2
+ import { type Comment, type createCommentSchema } from '../types/entities.js';
3
3
  import type { CustomFetch } from '../types/http.js';
4
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
+ /** Per-client Comment schema, base-bound for the returned comment's web `url`. */
10
+ schema: ReturnType<typeof createCommentSchema>;
9
11
  };
10
12
  export declare function addCommentRequest(context: ClientContext, params: CreateCommentArgs, options?: {
11
13
  batch?: boolean;
@@ -28,4 +28,8 @@ export declare class BaseClient {
28
28
  * @returns Base URI with guaranteed trailing slash for proper URL resolution
29
29
  */
30
30
  protected getBaseUri(version?: ApiVersion): string;
31
+ /**
32
+ * Base URL for entity web links, or `undefined` to use getFullTwistURL's default web app.
33
+ */
34
+ protected getLinkBaseUrl(): string | undefined;
31
35
  }