@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
|
@@ -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 {
|
|
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
|
-
|
|
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(
|
|
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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 {
|
|
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
|
-
|
|
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(
|
|
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
|
|
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 {
|
|
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
|
-
|
|
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(
|
|
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
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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({
|
|
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
|
|
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 {
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
|
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(
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
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
|
-
|
|
298
|
-
.object({
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
|
|
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.
|
|
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(
|
|
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
|
}
|