@doist/twist-sdk 2.7.0 → 2.9.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.
Files changed (50) hide show
  1. package/dist/cjs/clients/add-comment-helper.js +1 -2
  2. package/dist/cjs/clients/attachments-client.js +124 -0
  3. package/dist/cjs/clients/base-client.js +10 -0
  4. package/dist/cjs/clients/channels-client.js +9 -6
  5. package/dist/cjs/clients/comments-client.js +16 -6
  6. package/dist/cjs/clients/conversation-messages-client.js +9 -8
  7. package/dist/cjs/clients/conversations-client.js +11 -8
  8. package/dist/cjs/clients/inbox-client.js +6 -3
  9. package/dist/cjs/clients/threads-client.js +18 -9
  10. package/dist/cjs/clients/workspace-users-client.js +9 -2
  11. package/dist/cjs/clients/workspaces-client.js +7 -3
  12. package/dist/cjs/consts/endpoints.js +2 -1
  13. package/dist/cjs/index.js +3 -1
  14. package/dist/cjs/twist-api.js +2 -0
  15. package/dist/cjs/types/entities.js +99 -79
  16. package/dist/cjs/utils/multipart-upload.js +154 -0
  17. package/dist/esm/clients/add-comment-helper.js +1 -2
  18. package/dist/esm/clients/attachments-client.js +121 -0
  19. package/dist/esm/clients/base-client.js +10 -0
  20. package/dist/esm/clients/channels-client.js +10 -7
  21. package/dist/esm/clients/comments-client.js +17 -7
  22. package/dist/esm/clients/conversation-messages-client.js +10 -9
  23. package/dist/esm/clients/conversations-client.js +12 -9
  24. package/dist/esm/clients/inbox-client.js +7 -4
  25. package/dist/esm/clients/threads-client.js +19 -10
  26. package/dist/esm/clients/workspace-users-client.js +9 -2
  27. package/dist/esm/clients/workspaces-client.js +8 -4
  28. package/dist/esm/consts/endpoints.js +1 -0
  29. package/dist/esm/index.js +1 -0
  30. package/dist/esm/twist-api.js +2 -0
  31. package/dist/esm/types/entities.js +92 -78
  32. package/dist/esm/utils/multipart-upload.js +150 -0
  33. package/dist/types/clients/add-comment-helper.d.ts +3 -1
  34. package/dist/types/clients/attachments-client.d.ts +39 -0
  35. package/dist/types/clients/base-client.d.ts +4 -0
  36. package/dist/types/clients/channels-client.d.ts +1 -0
  37. package/dist/types/clients/comments-client.d.ts +1 -0
  38. package/dist/types/clients/conversation-messages-client.d.ts +1 -0
  39. package/dist/types/clients/conversations-client.d.ts +1 -0
  40. package/dist/types/clients/inbox-client.d.ts +1 -0
  41. package/dist/types/clients/threads-client.d.ts +2 -0
  42. package/dist/types/clients/workspace-users-client.d.ts +5 -0
  43. package/dist/types/clients/workspaces-client.d.ts +1 -0
  44. package/dist/types/consts/endpoints.d.ts +1 -0
  45. package/dist/types/index.d.ts +1 -0
  46. package/dist/types/twist-api.d.ts +2 -0
  47. package/dist/types/types/entities.d.ts +1539 -185
  48. package/dist/types/types/requests.d.ts +22 -0
  49. package/dist/types/utils/multipart-upload.d.ts +53 -0
  50. package/package.json +6 -2
@@ -34,7 +34,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
34
34
  exports.addCommentRequest = addCommentRequest;
35
35
  var endpoints_1 = require("../consts/endpoints");
36
36
  var http_client_1 = require("../transport/http-client");
37
- var entities_1 = require("../types/entities");
38
37
  var enums_1 = require("../types/enums");
39
38
  var SENTINEL_GROUP_IDS = new Set(Object.values(enums_1.NOTIFY_AUDIENCE_GROUP_IDS));
40
39
  function isNotifyAudience(value) {
@@ -62,7 +61,7 @@ function addCommentRequest(context, params, options) {
62
61
  var normalized = applyNotifyAudience(params);
63
62
  var payload = (options === null || options === void 0 ? void 0 : options.threadAction)
64
63
  ? __assign(__assign({}, normalized), { threadAction: options.threadAction }) : normalized;
65
- var schema = entities_1.CommentSchema;
64
+ var schema = context.schema;
66
65
  if (options === null || options === void 0 ? void 0 : options.batch) {
67
66
  return { method: method, url: url, params: payload, schema: schema };
68
67
  }
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
18
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
19
+ return new (P || (P = Promise))(function (resolve, reject) {
20
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
21
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
22
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
23
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
24
+ });
25
+ };
26
+ var __generator = (this && this.__generator) || function (thisArg, body) {
27
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
28
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
29
+ function verb(n) { return function (v) { return step([n, v]); }; }
30
+ function step(op) {
31
+ if (f) throw new TypeError("Generator is already executing.");
32
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
33
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
34
+ if (y = 0, t) op = [op[0] & 2, t.value];
35
+ switch (op[0]) {
36
+ case 0: case 1: t = op; break;
37
+ case 4: _.label++; return { value: op[1], done: false };
38
+ case 5: _.label++; y = op[1]; op = [0]; continue;
39
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
40
+ default:
41
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
42
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
43
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
44
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
45
+ if (t[2]) _.ops.pop();
46
+ _.trys.pop(); continue;
47
+ }
48
+ op = body.call(thisArg, _);
49
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
50
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
51
+ }
52
+ };
53
+ Object.defineProperty(exports, "__esModule", { value: true });
54
+ exports.AttachmentsClient = void 0;
55
+ var uuid_1 = require("uuid");
56
+ var endpoints_1 = require("../consts/endpoints");
57
+ var entities_1 = require("../types/entities");
58
+ var multipart_upload_1 = require("../utils/multipart-upload");
59
+ var base_client_1 = require("./base-client");
60
+ /**
61
+ * Client for uploading file attachments to Twist.
62
+ *
63
+ * Attachments are uploaded independently, then referenced by passing the returned
64
+ * {@link Attachment} into the `attachments` array of `comments.createComment`,
65
+ * `conversationMessages.createMessage`, and similar calls.
66
+ */
67
+ var AttachmentsClient = /** @class */ (function (_super) {
68
+ __extends(AttachmentsClient, _super);
69
+ function AttachmentsClient() {
70
+ return _super !== null && _super.apply(this, arguments) || this;
71
+ }
72
+ /**
73
+ * Uploads a file and returns the created {@link Attachment}.
74
+ *
75
+ * Mirrors the canonical multipart upload used by twist-web: `POST /attachments/upload`
76
+ * with the `file` binary plus `file_name`, `file_size`, `attachment_id`, and
77
+ * `underlying_type` form fields.
78
+ *
79
+ * @param args - The file to upload and optional metadata.
80
+ * @returns The created attachment, ready to attach to a comment or message.
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { readFile } from 'node:fs/promises'
85
+ *
86
+ * const attachment = await api.attachments.upload({
87
+ * file: await readFile('./diagram.png'),
88
+ * fileName: 'diagram.png',
89
+ * })
90
+ *
91
+ * await api.comments.createComment({
92
+ * threadId: 789,
93
+ * content: 'See attached',
94
+ * attachments: [attachment],
95
+ * })
96
+ * ```
97
+ */
98
+ AttachmentsClient.prototype.upload = function (args) {
99
+ return __awaiter(this, void 0, void 0, function () {
100
+ var data;
101
+ return __generator(this, function (_a) {
102
+ switch (_a.label) {
103
+ case 0: return [4 /*yield*/, (0, multipart_upload_1.uploadMultipartFile)({
104
+ baseUrl: this.getBaseUri(),
105
+ authToken: this.apiToken,
106
+ endpoint: "".concat(endpoints_1.ENDPOINT_ATTACHMENTS, "/upload"),
107
+ file: args.file,
108
+ fileName: args.fileName,
109
+ contentType: args.contentType,
110
+ additionalFields: {
111
+ attachment_id: args.attachmentId || (0, uuid_1.v4)(),
112
+ },
113
+ customFetch: this.customFetch,
114
+ })];
115
+ case 1:
116
+ data = _a.sent();
117
+ return [2 /*return*/, entities_1.AttachmentSchema.parse(data)];
118
+ }
119
+ });
120
+ });
121
+ };
122
+ return AttachmentsClient;
123
+ }(base_client_1.BaseClient));
124
+ exports.AttachmentsClient = AttachmentsClient;
@@ -31,6 +31,16 @@ var BaseClient = /** @class */ (function () {
31
31
  // Use centralized helper function for default Twist API URL
32
32
  return (0, endpoints_1.getTwistBaseUri)(apiVersion);
33
33
  };
34
+ /**
35
+ * Base URL for entity web links, or `undefined` to use getFullTwistURL's default web app.
36
+ */
37
+ BaseClient.prototype.getLinkBaseUrl = function () {
38
+ if (!this.baseUrl) {
39
+ return undefined;
40
+ }
41
+ // Strip a trailing slash so links don't double up, since entity paths start with '/'.
42
+ return this.baseUrl.endsWith('/') ? this.baseUrl.slice(0, -1) : this.baseUrl;
43
+ };
34
44
  return BaseClient;
35
45
  }());
36
46
  exports.BaseClient = BaseClient;
@@ -27,14 +27,17 @@ var base_client_1 = require("./base-client");
27
27
  var ChannelsClient = /** @class */ (function (_super) {
28
28
  __extends(ChannelsClient, _super);
29
29
  function ChannelsClient() {
30
- return _super !== null && _super.apply(this, arguments) || this;
30
+ var _this = _super !== null && _super.apply(this, arguments) || this;
31
+ _this.channelSchema = (0, entities_1.createChannelSchema)(_this.getLinkBaseUrl());
32
+ return _this;
31
33
  }
32
34
  ChannelsClient.prototype.getChannels = function (args, options) {
35
+ var _this = this;
33
36
  var method = 'GET';
34
37
  var url = "".concat(endpoints_1.ENDPOINT_CHANNELS, "/get");
35
38
  var params = args;
36
39
  if (options === null || options === void 0 ? void 0 : options.batch) {
37
- return { method: method, url: url, params: params, schema: zod_1.z.array(entities_1.ChannelSchema) };
40
+ return { method: method, url: url, params: params, schema: zod_1.z.array(this.channelSchema) };
38
41
  }
39
42
  return (0, http_client_1.request)({
40
43
  httpMethod: method,
@@ -43,13 +46,13 @@ var ChannelsClient = /** @class */ (function (_super) {
43
46
  apiToken: this.apiToken,
44
47
  payload: params,
45
48
  customFetch: this.customFetch,
46
- }).then(function (response) { return response.data.map(function (channel) { return entities_1.ChannelSchema.parse(channel); }); });
49
+ }).then(function (response) { return response.data.map(function (channel) { return _this.channelSchema.parse(channel); }); });
47
50
  };
48
51
  ChannelsClient.prototype.getChannel = function (id, options) {
49
52
  var method = 'GET';
50
53
  var url = "".concat(endpoints_1.ENDPOINT_CHANNELS, "/getone");
51
54
  var params = { id: id };
52
- var schema = entities_1.ChannelSchema;
55
+ var schema = this.channelSchema;
53
56
  if (options === null || options === void 0 ? void 0 : options.batch) {
54
57
  return { method: method, url: url, params: params, schema: schema };
55
58
  }
@@ -66,7 +69,7 @@ var ChannelsClient = /** @class */ (function (_super) {
66
69
  var method = 'POST';
67
70
  var url = "".concat(endpoints_1.ENDPOINT_CHANNELS, "/add");
68
71
  var params = args;
69
- var schema = entities_1.ChannelSchema;
72
+ var schema = this.channelSchema;
70
73
  if (options === null || options === void 0 ? void 0 : options.batch) {
71
74
  return { method: method, url: url, params: params, schema: schema };
72
75
  }
@@ -83,7 +86,7 @@ var ChannelsClient = /** @class */ (function (_super) {
83
86
  var method = 'POST';
84
87
  var url = "".concat(endpoints_1.ENDPOINT_CHANNELS, "/update");
85
88
  var params = args;
86
- var schema = entities_1.ChannelSchema;
89
+ var schema = this.channelSchema;
87
90
  if (options === null || options === void 0 ? void 0 : options.batch) {
88
91
  return { method: method, url: url, params: params, schema: schema };
89
92
  }
@@ -28,9 +28,12 @@ var base_client_1 = require("./base-client");
28
28
  var CommentsClient = /** @class */ (function (_super) {
29
29
  __extends(CommentsClient, _super);
30
30
  function CommentsClient() {
31
- return _super !== null && _super.apply(this, arguments) || this;
31
+ var _this = _super !== null && _super.apply(this, arguments) || this;
32
+ _this.commentSchema = (0, entities_1.createCommentSchema)(_this.getLinkBaseUrl());
33
+ return _this;
32
34
  }
33
35
  CommentsClient.prototype.getComments = function (args, options) {
36
+ var _this = this;
34
37
  var _a;
35
38
  var params = {
36
39
  thread_id: args.threadId,
@@ -45,7 +48,7 @@ var CommentsClient = /** @class */ (function (_super) {
45
48
  var method = 'GET';
46
49
  var url = "".concat(endpoints_1.ENDPOINT_COMMENTS, "/get");
47
50
  if (options === null || options === void 0 ? void 0 : options.batch) {
48
- return { method: method, url: url, params: params, schema: zod_1.z.array(entities_1.CommentSchema) };
51
+ return { method: method, url: url, params: params, schema: zod_1.z.array(this.commentSchema) };
49
52
  }
50
53
  return (0, http_client_1.request)({
51
54
  httpMethod: method,
@@ -54,14 +57,16 @@ var CommentsClient = /** @class */ (function (_super) {
54
57
  apiToken: this.apiToken,
55
58
  payload: params,
56
59
  customFetch: this.customFetch,
57
- }).then(function (response) { return response.data.map(function (comment) { return entities_1.CommentSchema.parse(comment); }); });
60
+ }).then(function (response) { return response.data.map(function (comment) { return _this.commentSchema.parse(comment); }); });
58
61
  };
59
62
  CommentsClient.prototype.getComment = function (id, options) {
60
63
  var method = 'GET';
61
64
  var url = "".concat(endpoints_1.ENDPOINT_COMMENTS, "/getone");
62
65
  var params = { id: id };
63
66
  // The API wraps the response in {"comment": {...}}, so we need to unwrap it
64
- var wrappedSchema = zod_1.z.object({ comment: entities_1.CommentSchema }).transform(function (data) { return data.comment; });
67
+ var wrappedSchema = zod_1.z
68
+ .object({ comment: this.commentSchema })
69
+ .transform(function (data) { return data.comment; });
65
70
  if (options === null || options === void 0 ? void 0 : options.batch) {
66
71
  return { method: method, url: url, params: params, schema: wrappedSchema };
67
72
  }
@@ -75,13 +80,18 @@ var CommentsClient = /** @class */ (function (_super) {
75
80
  }).then(function (response) { return wrappedSchema.parse(response.data); });
76
81
  };
77
82
  CommentsClient.prototype.createComment = function (args, options) {
78
- return (0, add_comment_helper_1.addCommentRequest)({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, args, options);
83
+ return (0, add_comment_helper_1.addCommentRequest)({
84
+ baseUri: this.getBaseUri(),
85
+ apiToken: this.apiToken,
86
+ customFetch: this.customFetch,
87
+ schema: this.commentSchema,
88
+ }, args, options);
79
89
  };
80
90
  CommentsClient.prototype.updateComment = function (args, options) {
81
91
  var method = 'POST';
82
92
  var url = "".concat(endpoints_1.ENDPOINT_COMMENTS, "/update");
83
93
  var params = args;
84
- var schema = entities_1.CommentSchema;
94
+ var schema = this.commentSchema;
85
95
  if (options === null || options === void 0 ? void 0 : options.batch) {
86
96
  return { method: method, url: url, params: params, schema: schema };
87
97
  }
@@ -27,9 +27,12 @@ var base_client_1 = require("./base-client");
27
27
  var ConversationMessagesClient = /** @class */ (function (_super) {
28
28
  __extends(ConversationMessagesClient, _super);
29
29
  function ConversationMessagesClient() {
30
- return _super !== null && _super.apply(this, arguments) || this;
30
+ var _this = _super !== null && _super.apply(this, arguments) || this;
31
+ _this.messageSchema = (0, entities_1.createConversationMessageSchema)(_this.getLinkBaseUrl());
32
+ return _this;
31
33
  }
32
34
  ConversationMessagesClient.prototype.getMessages = function (args, options) {
35
+ var _this = this;
33
36
  var params = {
34
37
  conversation_id: args.conversationId,
35
38
  };
@@ -44,7 +47,7 @@ var ConversationMessagesClient = /** @class */ (function (_super) {
44
47
  var method = 'GET';
45
48
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATION_MESSAGES, "/get");
46
49
  if (options === null || options === void 0 ? void 0 : options.batch) {
47
- return { method: method, url: url, params: params, schema: zod_1.z.array(entities_1.ConversationMessageSchema) };
50
+ return { method: method, url: url, params: params, schema: zod_1.z.array(this.messageSchema) };
48
51
  }
49
52
  return (0, http_client_1.request)({
50
53
  httpMethod: method,
@@ -53,15 +56,13 @@ var ConversationMessagesClient = /** @class */ (function (_super) {
53
56
  apiToken: this.apiToken,
54
57
  payload: params,
55
58
  customFetch: this.customFetch,
56
- }).then(function (response) {
57
- return response.data.map(function (message) { return entities_1.ConversationMessageSchema.parse(message); });
58
- });
59
+ }).then(function (response) { return response.data.map(function (message) { return _this.messageSchema.parse(message); }); });
59
60
  };
60
61
  ConversationMessagesClient.prototype.getMessage = function (id, options) {
61
62
  var method = 'GET';
62
63
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATION_MESSAGES, "/getone");
63
64
  var params = { id: id };
64
- var schema = entities_1.ConversationMessageSchema;
65
+ var schema = this.messageSchema;
65
66
  if (options === null || options === void 0 ? void 0 : options.batch) {
66
67
  return { method: method, url: url, params: params, schema: schema };
67
68
  }
@@ -85,7 +86,7 @@ var ConversationMessagesClient = /** @class */ (function (_super) {
85
86
  params.actions = args.actions;
86
87
  var method = 'POST';
87
88
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATION_MESSAGES, "/add");
88
- var schema = entities_1.ConversationMessageSchema;
89
+ var schema = this.messageSchema;
89
90
  if (options === null || options === void 0 ? void 0 : options.batch) {
90
91
  return { method: method, url: url, params: params, schema: schema };
91
92
  }
@@ -107,7 +108,7 @@ var ConversationMessagesClient = /** @class */ (function (_super) {
107
108
  params.attachments = args.attachments;
108
109
  var method = 'POST';
109
110
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATION_MESSAGES, "/update");
110
- var schema = entities_1.ConversationMessageSchema;
111
+ var schema = this.messageSchema;
111
112
  if (options === null || options === void 0 ? void 0 : options.batch) {
112
113
  return { method: method, url: url, params: params, schema: schema };
113
114
  }
@@ -27,14 +27,17 @@ var base_client_1 = require("./base-client");
27
27
  var ConversationsClient = /** @class */ (function (_super) {
28
28
  __extends(ConversationsClient, _super);
29
29
  function ConversationsClient() {
30
- return _super !== null && _super.apply(this, arguments) || this;
30
+ var _this = _super !== null && _super.apply(this, arguments) || this;
31
+ _this.conversationSchema = (0, entities_1.createConversationSchema)(_this.getLinkBaseUrl());
32
+ return _this;
31
33
  }
32
34
  ConversationsClient.prototype.getConversations = function (args, options) {
35
+ var _this = this;
33
36
  var method = 'GET';
34
37
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATIONS, "/get");
35
38
  var params = args;
36
39
  if (options === null || options === void 0 ? void 0 : options.batch) {
37
- return { method: method, url: url, params: params, schema: zod_1.z.array(entities_1.ConversationSchema) };
40
+ return { method: method, url: url, params: params, schema: zod_1.z.array(this.conversationSchema) };
38
41
  }
39
42
  return (0, http_client_1.request)({
40
43
  httpMethod: method,
@@ -44,14 +47,14 @@ var ConversationsClient = /** @class */ (function (_super) {
44
47
  payload: params,
45
48
  customFetch: this.customFetch,
46
49
  }).then(function (response) {
47
- return response.data.map(function (conversation) { return entities_1.ConversationSchema.parse(conversation); });
50
+ return response.data.map(function (conversation) { return _this.conversationSchema.parse(conversation); });
48
51
  });
49
52
  };
50
53
  ConversationsClient.prototype.getConversation = function (id, options) {
51
54
  var method = 'GET';
52
55
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATIONS, "/getone");
53
56
  var params = { id: id };
54
- var schema = entities_1.ConversationSchema;
57
+ var schema = this.conversationSchema;
55
58
  if (options === null || options === void 0 ? void 0 : options.batch) {
56
59
  return { method: method, url: url, params: params, schema: schema };
57
60
  }
@@ -68,7 +71,7 @@ var ConversationsClient = /** @class */ (function (_super) {
68
71
  var method = 'POST';
69
72
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATIONS, "/get_or_create");
70
73
  var params = args;
71
- var schema = entities_1.ConversationSchema;
74
+ var schema = this.conversationSchema;
72
75
  if (options === null || options === void 0 ? void 0 : options.batch) {
73
76
  return { method: method, url: url, params: params, schema: schema };
74
77
  }
@@ -87,7 +90,7 @@ var ConversationsClient = /** @class */ (function (_super) {
87
90
  params.archived = args.archived;
88
91
  var method = 'POST';
89
92
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATIONS, "/update");
90
- var schema = entities_1.ConversationSchema;
93
+ var schema = this.conversationSchema;
91
94
  if (options === null || options === void 0 ? void 0 : options.batch) {
92
95
  return { method: method, url: url, params: params, schema: schema };
93
96
  }
@@ -258,7 +261,7 @@ var ConversationsClient = /** @class */ (function (_super) {
258
261
  var method = 'POST';
259
262
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATIONS, "/mute");
260
263
  var params = { id: args.id, minutes: args.minutes };
261
- var schema = entities_1.ConversationSchema;
264
+ var schema = this.conversationSchema;
262
265
  if (options === null || options === void 0 ? void 0 : options.batch) {
263
266
  return { method: method, url: url, params: params, schema: schema };
264
267
  }
@@ -275,7 +278,7 @@ var ConversationsClient = /** @class */ (function (_super) {
275
278
  var method = 'POST';
276
279
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATIONS, "/unmute");
277
280
  var params = { id: id };
278
- var schema = entities_1.ConversationSchema;
281
+ var schema = this.conversationSchema;
279
282
  if (options === null || options === void 0 ? void 0 : options.batch) {
280
283
  return { method: method, url: url, params: params, schema: schema };
281
284
  }
@@ -27,9 +27,12 @@ var base_client_1 = require("./base-client");
27
27
  var InboxClient = /** @class */ (function (_super) {
28
28
  __extends(InboxClient, _super);
29
29
  function InboxClient() {
30
- return _super !== null && _super.apply(this, arguments) || this;
30
+ var _this = _super !== null && _super.apply(this, arguments) || this;
31
+ _this.inboxThreadSchema = (0, entities_1.createInboxThreadSchema)(_this.getLinkBaseUrl());
32
+ return _this;
31
33
  }
32
34
  InboxClient.prototype.getInbox = function (args, options) {
35
+ var _this = this;
33
36
  var _a, _b;
34
37
  var params = {
35
38
  workspace_id: args.workspaceId,
@@ -49,7 +52,7 @@ var InboxClient = /** @class */ (function (_super) {
49
52
  var method = 'GET';
50
53
  var url = "".concat(endpoints_1.ENDPOINT_INBOX, "/get");
51
54
  if (options === null || options === void 0 ? void 0 : options.batch) {
52
- return { method: method, url: url, params: params, schema: zod_1.z.array(entities_1.InboxThreadSchema) };
55
+ return { method: method, url: url, params: params, schema: zod_1.z.array(this.inboxThreadSchema) };
53
56
  }
54
57
  return (0, http_client_1.request)({
55
58
  httpMethod: method,
@@ -58,7 +61,7 @@ var InboxClient = /** @class */ (function (_super) {
58
61
  apiToken: this.apiToken,
59
62
  payload: params,
60
63
  customFetch: this.customFetch,
61
- }).then(function (response) { return response.data.map(function (thread) { return entities_1.InboxThreadSchema.parse(thread); }); });
64
+ }).then(function (response) { return response.data.map(function (thread) { return _this.inboxThreadSchema.parse(thread); }); });
62
65
  };
63
66
  InboxClient.prototype.getCount = function (workspaceId, options) {
64
67
  var method = 'GET';
@@ -50,9 +50,13 @@ var base_client_1 = require("./base-client");
50
50
  var ThreadsClient = /** @class */ (function (_super) {
51
51
  __extends(ThreadsClient, _super);
52
52
  function ThreadsClient() {
53
- return _super !== null && _super.apply(this, arguments) || this;
53
+ var _this = _super !== null && _super.apply(this, arguments) || this;
54
+ _this.threadSchema = (0, entities_1.createThreadSchema)(_this.getLinkBaseUrl());
55
+ _this.commentSchema = (0, entities_1.createCommentSchema)(_this.getLinkBaseUrl());
56
+ return _this;
54
57
  }
55
58
  ThreadsClient.prototype.getThreads = function (args, options) {
59
+ var _this = this;
56
60
  var method = 'GET';
57
61
  var url = "".concat(endpoints_1.ENDPOINT_THREADS, "/get");
58
62
  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"]);
@@ -60,7 +64,7 @@ var ThreadsClient = /** @class */ (function (_super) {
60
64
  var resolvedOlderThan = olderThan ? Math.floor(olderThan.getTime() / 1000) : older_than_ts;
61
65
  var params = __assign(__assign(__assign({}, rest), (resolvedNewerThan != null ? { newer_than_ts: resolvedNewerThan } : {})), (resolvedOlderThan != null ? { older_than_ts: resolvedOlderThan } : {}));
62
66
  if (options === null || options === void 0 ? void 0 : options.batch) {
63
- return { method: method, url: url, params: params, schema: zod_1.z.array(entities_1.ThreadSchema) };
67
+ return { method: method, url: url, params: params, schema: zod_1.z.array(this.threadSchema) };
64
68
  }
65
69
  return (0, http_client_1.request)({
66
70
  httpMethod: method,
@@ -69,13 +73,13 @@ var ThreadsClient = /** @class */ (function (_super) {
69
73
  apiToken: this.apiToken,
70
74
  payload: params,
71
75
  customFetch: this.customFetch,
72
- }).then(function (response) { return response.data.map(function (thread) { return entities_1.ThreadSchema.parse(thread); }); });
76
+ }).then(function (response) { return response.data.map(function (thread) { return _this.threadSchema.parse(thread); }); });
73
77
  };
74
78
  ThreadsClient.prototype.getThread = function (id, options) {
75
79
  var method = 'GET';
76
80
  var url = "".concat(endpoints_1.ENDPOINT_THREADS, "/getone");
77
81
  var params = { id: id };
78
- var schema = entities_1.ThreadSchema;
82
+ var schema = this.threadSchema;
79
83
  if (options === null || options === void 0 ? void 0 : options.batch) {
80
84
  return { method: method, url: url, params: params, schema: schema };
81
85
  }
@@ -92,7 +96,7 @@ var ThreadsClient = /** @class */ (function (_super) {
92
96
  var method = 'POST';
93
97
  var url = "".concat(endpoints_1.ENDPOINT_THREADS, "/add");
94
98
  var params = args;
95
- var schema = entities_1.ThreadSchema;
99
+ var schema = this.threadSchema;
96
100
  if (options === null || options === void 0 ? void 0 : options.batch) {
97
101
  return { method: method, url: url, params: params, schema: schema };
98
102
  }
@@ -109,7 +113,7 @@ var ThreadsClient = /** @class */ (function (_super) {
109
113
  var method = 'POST';
110
114
  var url = "".concat(endpoints_1.ENDPOINT_THREADS, "/update");
111
115
  var params = args;
112
- var schema = entities_1.ThreadSchema;
116
+ var schema = this.threadSchema;
113
117
  if (options === null || options === void 0 ? void 0 : options.batch) {
114
118
  return { method: method, url: url, params: params, schema: schema };
115
119
  }
@@ -357,7 +361,7 @@ var ThreadsClient = /** @class */ (function (_super) {
357
361
  var method = 'POST';
358
362
  var url = "".concat(endpoints_1.ENDPOINT_THREADS, "/mute");
359
363
  var params = { id: args.id, minutes: args.minutes };
360
- var schema = entities_1.ThreadSchema;
364
+ var schema = this.threadSchema;
361
365
  if (options === null || options === void 0 ? void 0 : options.batch) {
362
366
  return { method: method, url: url, params: params, schema: schema };
363
367
  }
@@ -374,7 +378,7 @@ var ThreadsClient = /** @class */ (function (_super) {
374
378
  var method = 'POST';
375
379
  var url = "".concat(endpoints_1.ENDPOINT_THREADS, "/unmute");
376
380
  var params = { id: id };
377
- var schema = entities_1.ThreadSchema;
381
+ var schema = this.threadSchema;
378
382
  if (options === null || options === void 0 ? void 0 : options.batch) {
379
383
  return { method: method, url: url, params: params, schema: schema };
380
384
  }
@@ -395,7 +399,12 @@ var ThreadsClient = /** @class */ (function (_super) {
395
399
  };
396
400
  ThreadsClient.prototype.addCommentWithAction = function (args, threadAction, options) {
397
401
  var id = args.id, rest = __rest(args, ["id"]);
398
- return (0, add_comment_helper_1.addCommentRequest)({ baseUri: this.getBaseUri(), apiToken: this.apiToken, customFetch: this.customFetch }, __assign({ threadId: id }, rest), __assign(__assign({}, options), { threadAction: threadAction }));
402
+ return (0, add_comment_helper_1.addCommentRequest)({
403
+ baseUri: this.getBaseUri(),
404
+ apiToken: this.apiToken,
405
+ customFetch: this.customFetch,
406
+ schema: this.commentSchema,
407
+ }, __assign({ threadId: id }, rest), __assign(__assign({}, options), { threadAction: threadAction }));
399
408
  };
400
409
  return ThreadsClient;
401
410
  }(base_client_1.BaseClient));
@@ -16,6 +16,7 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.WorkspaceUsersClient = void 0;
19
+ var zod_1 = require("zod");
19
20
  var http_client_1 = require("../transport/http-client");
20
21
  var entities_1 = require("../types/entities");
21
22
  var base_client_1 = require("./base-client");
@@ -28,11 +29,17 @@ var WorkspaceUsersClient = /** @class */ (function (_super) {
28
29
  return _super !== null && _super.apply(this, arguments) || this;
29
30
  }
30
31
  WorkspaceUsersClient.prototype.getWorkspaceUsers = function (args, options) {
32
+ var _a;
31
33
  var method = 'GET';
32
34
  var url = 'workspace_users/get';
33
35
  var params = { id: args.workspaceId, archived: args.archived };
36
+ var includeRemoved = (_a = args.includeRemoved) !== null && _a !== void 0 ? _a : false;
37
+ function filterRemoved(users) {
38
+ return includeRemoved ? users : users.filter(function (user) { return !user.removed; });
39
+ }
40
+ var responseSchema = zod_1.z.array(entities_1.WorkspaceUserSchema).transform(filterRemoved);
34
41
  if (options === null || options === void 0 ? void 0 : options.batch) {
35
- return { method: method, url: url, params: params };
42
+ return { method: method, url: url, params: params, schema: responseSchema };
36
43
  }
37
44
  return (0, http_client_1.request)({
38
45
  httpMethod: method,
@@ -41,7 +48,7 @@ var WorkspaceUsersClient = /** @class */ (function (_super) {
41
48
  apiToken: this.apiToken,
42
49
  payload: params,
43
50
  customFetch: this.customFetch,
44
- }).then(function (response) { return response.data.map(function (user) { return entities_1.WorkspaceUserSchema.parse(user); }); });
51
+ }).then(function (response) { return responseSchema.parse(response.data); });
45
52
  };
46
53
  WorkspaceUsersClient.prototype.getWorkspaceUserIds = function (workspaceId, options) {
47
54
  var method = 'GET';
@@ -16,6 +16,7 @@ var __extends = (this && this.__extends) || (function () {
16
16
  })();
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.WorkspacesClient = void 0;
19
+ var zod_1 = require("zod");
19
20
  var endpoints_1 = require("../consts/endpoints");
20
21
  var http_client_1 = require("../transport/http-client");
21
22
  var entities_1 = require("../types/entities");
@@ -26,7 +27,9 @@ var base_client_1 = require("./base-client");
26
27
  var WorkspacesClient = /** @class */ (function (_super) {
27
28
  __extends(WorkspacesClient, _super);
28
29
  function WorkspacesClient() {
29
- return _super !== null && _super.apply(this, arguments) || this;
30
+ var _this = _super !== null && _super.apply(this, arguments) || this;
31
+ _this.channelSchema = (0, entities_1.createChannelSchema)(_this.getLinkBaseUrl());
32
+ return _this;
30
33
  }
31
34
  WorkspacesClient.prototype.getWorkspaces = function (options) {
32
35
  var method = 'GET';
@@ -129,11 +132,12 @@ var WorkspacesClient = /** @class */ (function (_super) {
129
132
  }).then(function () { return undefined; });
130
133
  };
131
134
  WorkspacesClient.prototype.getPublicChannels = function (id, options) {
135
+ var _this = this;
132
136
  var method = 'GET';
133
137
  var url = "".concat(endpoints_1.ENDPOINT_WORKSPACES, "/get_public_channels");
134
138
  var params = { id: id };
135
139
  if (options === null || options === void 0 ? void 0 : options.batch) {
136
- return { method: method, url: url, params: params };
140
+ return { method: method, url: url, params: params, schema: zod_1.z.array(this.channelSchema) };
137
141
  }
138
142
  return (0, http_client_1.request)({
139
143
  httpMethod: method,
@@ -142,7 +146,7 @@ var WorkspacesClient = /** @class */ (function (_super) {
142
146
  apiToken: this.apiToken,
143
147
  payload: params,
144
148
  customFetch: this.customFetch,
145
- }).then(function (response) { return response.data.map(function (channel) { return entities_1.ChannelSchema.parse(channel); }); });
149
+ }).then(function (response) { return response.data.map(function (channel) { return _this.channelSchema.parse(channel); }); });
146
150
  };
147
151
  return WorkspacesClient;
148
152
  }(base_client_1.BaseClient));
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ENDPOINT_CONVERSATION_MESSAGES = exports.ENDPOINT_SEARCH = exports.ENDPOINT_REACTIONS = exports.ENDPOINT_INBOX = exports.ENDPOINT_NOTIFICATIONS = exports.ENDPOINT_COMMENTS = exports.ENDPOINT_CONVERSATIONS = exports.ENDPOINT_GROUPS = exports.ENDPOINT_THREADS = exports.ENDPOINT_CHANNELS = exports.ENDPOINT_WORKSPACES = exports.ENDPOINT_USERS = exports.API_BASE_URI = exports.API_VERSION = void 0;
3
+ exports.ENDPOINT_ATTACHMENTS = exports.ENDPOINT_CONVERSATION_MESSAGES = exports.ENDPOINT_SEARCH = exports.ENDPOINT_REACTIONS = exports.ENDPOINT_INBOX = exports.ENDPOINT_NOTIFICATIONS = exports.ENDPOINT_COMMENTS = exports.ENDPOINT_CONVERSATIONS = exports.ENDPOINT_GROUPS = exports.ENDPOINT_THREADS = exports.ENDPOINT_CHANNELS = exports.ENDPOINT_WORKSPACES = exports.ENDPOINT_USERS = exports.API_BASE_URI = exports.API_VERSION = void 0;
4
4
  exports.getTwistBaseUri = getTwistBaseUri;
5
5
  var api_version_1 = require("../types/api-version");
6
6
  var BASE_URI = 'https://api.twist.com';
@@ -33,3 +33,4 @@ exports.ENDPOINT_INBOX = 'inbox';
33
33
  exports.ENDPOINT_REACTIONS = 'reactions';
34
34
  exports.ENDPOINT_SEARCH = 'search';
35
35
  exports.ENDPOINT_CONVERSATION_MESSAGES = 'conversation_messages';
36
+ exports.ENDPOINT_ATTACHMENTS = 'attachments';
package/dist/cjs/index.js CHANGED
@@ -14,10 +14,12 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.TwistApi = exports.SearchClient = exports.ReactionsClient = exports.InboxClient = exports.ConversationMessagesClient = exports.BatchBuilder = void 0;
17
+ exports.TwistApi = exports.SearchClient = exports.ReactionsClient = exports.InboxClient = exports.ConversationMessagesClient = exports.AttachmentsClient = exports.BatchBuilder = void 0;
18
18
  __exportStar(require("./authentication"), exports);
19
19
  var batch_builder_1 = require("./batch-builder");
20
20
  Object.defineProperty(exports, "BatchBuilder", { enumerable: true, get: function () { return batch_builder_1.BatchBuilder; } });
21
+ var attachments_client_1 = require("./clients/attachments-client");
22
+ Object.defineProperty(exports, "AttachmentsClient", { enumerable: true, get: function () { return attachments_client_1.AttachmentsClient; } });
21
23
  var conversation_messages_client_1 = require("./clients/conversation-messages-client");
22
24
  Object.defineProperty(exports, "ConversationMessagesClient", { enumerable: true, get: function () { return conversation_messages_client_1.ConversationMessagesClient; } });
23
25
  var inbox_client_1 = require("./clients/inbox-client");