@doist/twist-sdk 0.1.0-alpha.3 → 0.1.0-alpha.4

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 (34) hide show
  1. package/dist/batch-builder.d.ts +2 -5
  2. package/dist/batch-builder.js +21 -8
  3. package/dist/clients/base-client.d.ts +27 -0
  4. package/dist/clients/base-client.js +34 -0
  5. package/dist/clients/channels-client.d.ts +2 -5
  6. package/dist/clients/channels-client.js +21 -8
  7. package/dist/clients/comments-client.d.ts +2 -5
  8. package/dist/clients/comments-client.js +21 -8
  9. package/dist/clients/conversation-messages-client.d.ts +2 -5
  10. package/dist/clients/conversation-messages-client.js +21 -8
  11. package/dist/clients/conversations-client.d.ts +2 -5
  12. package/dist/clients/conversations-client.js +21 -8
  13. package/dist/clients/groups-client.d.ts +2 -5
  14. package/dist/clients/groups-client.js +21 -8
  15. package/dist/clients/inbox-client.d.ts +2 -5
  16. package/dist/clients/inbox-client.js +21 -8
  17. package/dist/clients/reactions-client.d.ts +2 -5
  18. package/dist/clients/reactions-client.js +21 -8
  19. package/dist/clients/search-client.d.ts +3 -5
  20. package/dist/clients/search-client.js +21 -8
  21. package/dist/clients/threads-client.d.ts +2 -5
  22. package/dist/clients/threads-client.js +21 -8
  23. package/dist/clients/users-client.d.ts +2 -5
  24. package/dist/clients/users-client.js +21 -8
  25. package/dist/clients/workspace-users-client.d.ts +2 -5
  26. package/dist/clients/workspace-users-client.js +31 -18
  27. package/dist/clients/workspaces-client.d.ts +2 -5
  28. package/dist/clients/workspaces-client.js +21 -8
  29. package/dist/consts/endpoints.d.ts +12 -1
  30. package/dist/consts/endpoints.js +13 -2
  31. package/dist/twist-api.js +15 -13
  32. package/dist/types/api-version.d.ts +4 -0
  33. package/dist/types/api-version.js +2 -0
  34. package/package.json +5 -5
@@ -1,3 +1,4 @@
1
+ import { BaseClient } from './clients/base-client';
1
2
  import type { BatchRequestDescriptor, BatchResponseArray } from './types/batch';
2
3
  /**
3
4
  * Executes multiple API requests in a single HTTP call.
@@ -10,11 +11,7 @@ import type { BatchRequestDescriptor, BatchResponseArray } from './types/batch';
10
11
  * )
11
12
  * ```
12
13
  */
13
- export declare class BatchBuilder {
14
- private apiToken;
15
- private baseUrl?;
16
- constructor(apiToken: string, baseUrl?: string | undefined);
17
- private getBaseUri;
14
+ export declare class BatchBuilder extends BaseClient {
18
15
  /**
19
16
  * Executes an array of batch request descriptors in a single API call.
20
17
  *
@@ -1,4 +1,19 @@
1
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
+ })();
2
17
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
18
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
19
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,6 +52,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
52
  };
38
53
  Object.defineProperty(exports, "__esModule", { value: true });
39
54
  exports.BatchBuilder = void 0;
55
+ var base_client_1 = require("./clients/base-client");
40
56
  var errors_1 = require("./types/errors");
41
57
  var case_conversion_1 = require("./utils/case-conversion");
42
58
  var timestamp_conversion_1 = require("./utils/timestamp-conversion");
@@ -51,14 +67,11 @@ var timestamp_conversion_1 = require("./utils/timestamp-conversion");
51
67
  * )
52
68
  * ```
53
69
  */
54
- var BatchBuilder = /** @class */ (function () {
55
- function BatchBuilder(apiToken, baseUrl) {
56
- this.apiToken = apiToken;
57
- this.baseUrl = baseUrl;
70
+ var BatchBuilder = /** @class */ (function (_super) {
71
+ __extends(BatchBuilder, _super);
72
+ function BatchBuilder() {
73
+ return _super !== null && _super.apply(this, arguments) || this;
58
74
  }
59
- BatchBuilder.prototype.getBaseUri = function () {
60
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : 'https://api.twist.com/api/v3/';
61
- };
62
75
  /**
63
76
  * Executes an array of batch request descriptors in a single API call.
64
77
  *
@@ -187,5 +200,5 @@ var BatchBuilder = /** @class */ (function () {
187
200
  });
188
201
  };
189
202
  return BatchBuilder;
190
- }());
203
+ }(base_client_1.BaseClient));
191
204
  exports.BatchBuilder = BatchBuilder;
@@ -0,0 +1,27 @@
1
+ import type { ApiVersion } from '../types/api-version';
2
+ export interface ClientConfig {
3
+ /** API token for authentication */
4
+ apiToken: string;
5
+ /** Optional custom base URL. If not provided, uses the default Twist API URL */
6
+ baseUrl?: string;
7
+ /** Optional API version. Defaults to 'v3' */
8
+ version?: ApiVersion;
9
+ }
10
+ /**
11
+ * Base client class that provides centralized URL management and configuration
12
+ * for all Twist API clients. Fixes the trailing slash bug and eliminates code duplication.
13
+ */
14
+ export declare class BaseClient {
15
+ protected readonly apiToken: string;
16
+ protected readonly baseUrl?: string;
17
+ protected readonly defaultVersion: ApiVersion;
18
+ constructor(config: ClientConfig);
19
+ /**
20
+ * Gets the base URI for API requests with proper trailing slash handling.
21
+ * This method fixes the trailing slash bug that occurred when using custom baseUrl.
22
+ *
23
+ * @param version - Optional API version override. Defaults to the configured version or 'v3'
24
+ * @returns Base URI with guaranteed trailing slash for proper URL resolution
25
+ */
26
+ protected getBaseUri(version?: ApiVersion): string;
27
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseClient = void 0;
4
+ var endpoints_1 = require("../consts/endpoints");
5
+ /**
6
+ * Base client class that provides centralized URL management and configuration
7
+ * for all Twist API clients. Fixes the trailing slash bug and eliminates code duplication.
8
+ */
9
+ var BaseClient = /** @class */ (function () {
10
+ function BaseClient(config) {
11
+ this.apiToken = config.apiToken;
12
+ this.baseUrl = config.baseUrl;
13
+ this.defaultVersion = config.version || 'v3';
14
+ }
15
+ /**
16
+ * Gets the base URI for API requests with proper trailing slash handling.
17
+ * This method fixes the trailing slash bug that occurred when using custom baseUrl.
18
+ *
19
+ * @param version - Optional API version override. Defaults to the configured version or 'v3'
20
+ * @returns Base URI with guaranteed trailing slash for proper URL resolution
21
+ */
22
+ BaseClient.prototype.getBaseUri = function (version) {
23
+ var apiVersion = version || this.defaultVersion;
24
+ if (this.baseUrl) {
25
+ // Ensure trailing slash to fix URL resolution bug
26
+ var normalizedBaseUrl = this.baseUrl.endsWith('/') ? this.baseUrl : "".concat(this.baseUrl, "/");
27
+ return "".concat(normalizedBaseUrl, "api/").concat(apiVersion, "/");
28
+ }
29
+ // Use centralized helper function for default Twist API URL
30
+ return (0, endpoints_1.getTwistBaseUri)(apiVersion);
31
+ };
32
+ return BaseClient;
33
+ }());
34
+ exports.BaseClient = BaseClient;
@@ -1,6 +1,7 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { Channel } from '../types/entities';
3
3
  import { CreateChannelArgs, GetChannelsArgs, UpdateChannelArgs } from '../types/requests';
4
+ import { BaseClient } from './base-client';
4
5
  export type AddChannelUserArgs = {
5
6
  id: number;
6
7
  userId: number;
@@ -20,11 +21,7 @@ export type RemoveChannelUsersArgs = {
20
21
  /**
21
22
  * Client for interacting with Twist channel endpoints.
22
23
  */
23
- export declare class ChannelsClient {
24
- private apiToken;
25
- private baseUrl?;
26
- constructor(apiToken: string, baseUrl?: string | undefined);
27
- private getBaseUri;
24
+ export declare class ChannelsClient extends BaseClient {
28
25
  /**
29
26
  * Gets all channels for a given workspace.
30
27
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.ChannelsClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist channel endpoints.
9
25
  */
10
- var ChannelsClient = /** @class */ (function () {
11
- function ChannelsClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var ChannelsClient = /** @class */ (function (_super) {
27
+ __extends(ChannelsClient, _super);
28
+ function ChannelsClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- ChannelsClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  ChannelsClient.prototype.getChannels = function (args, options) {
19
32
  var method = 'GET';
20
33
  var url = "".concat(endpoints_1.ENDPOINT_CHANNELS, "/get");
@@ -136,5 +149,5 @@ var ChannelsClient = /** @class */ (function () {
136
149
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
137
150
  };
138
151
  return ChannelsClient;
139
- }());
152
+ }(base_client_1.BaseClient));
140
153
  exports.ChannelsClient = ChannelsClient;
@@ -1,6 +1,7 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { Comment } from '../types/entities';
3
3
  import { CreateCommentArgs, GetCommentsArgs, UpdateCommentArgs } from '../types/requests';
4
+ import { BaseClient } from './base-client';
4
5
  export type MarkCommentPositionArgs = {
5
6
  threadId: number;
6
7
  commentId: number;
@@ -8,11 +9,7 @@ export type MarkCommentPositionArgs = {
8
9
  /**
9
10
  * Client for interacting with Twist comment endpoints.
10
11
  */
11
- export declare class CommentsClient {
12
- private apiToken;
13
- private baseUrl?;
14
- constructor(apiToken: string, baseUrl?: string | undefined);
15
- private getBaseUri;
12
+ export declare class CommentsClient extends BaseClient {
16
13
  /**
17
14
  * Gets all comments for a thread.
18
15
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.CommentsClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist comment endpoints.
9
25
  */
10
- var CommentsClient = /** @class */ (function () {
11
- function CommentsClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var CommentsClient = /** @class */ (function (_super) {
27
+ __extends(CommentsClient, _super);
28
+ function CommentsClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- CommentsClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  CommentsClient.prototype.getComments = function (args, options) {
19
32
  var params = {
20
33
  thread_id: args.threadId,
@@ -82,5 +95,5 @@ var CommentsClient = /** @class */ (function () {
82
95
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
83
96
  };
84
97
  return CommentsClient;
85
- }());
98
+ }(base_client_1.BaseClient));
86
99
  exports.CommentsClient = CommentsClient;
@@ -1,5 +1,6 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { ConversationMessage } from '../types/entities';
3
+ import { BaseClient } from './base-client';
3
4
  type GetConversationMessagesArgs = {
4
5
  conversationId: number;
5
6
  newerThan?: Date;
@@ -21,11 +22,7 @@ type UpdateConversationMessageArgs = {
21
22
  /**
22
23
  * Client for interacting with Twist conversation message endpoints.
23
24
  */
24
- export declare class ConversationMessagesClient {
25
- private apiToken;
26
- private baseUrl?;
27
- constructor(apiToken: string, baseUrl?: string | undefined);
28
- private getBaseUri;
25
+ export declare class ConversationMessagesClient extends BaseClient {
29
26
  /**
30
27
  * Gets all messages in a conversation.
31
28
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.ConversationMessagesClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist conversation message endpoints.
9
25
  */
10
- var ConversationMessagesClient = /** @class */ (function () {
11
- function ConversationMessagesClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var ConversationMessagesClient = /** @class */ (function (_super) {
27
+ __extends(ConversationMessagesClient, _super);
28
+ function ConversationMessagesClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- ConversationMessagesClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  ConversationMessagesClient.prototype.getMessages = function (args, options) {
19
32
  var params = {
20
33
  conversation_id: args.conversationId,
@@ -88,5 +101,5 @@ var ConversationMessagesClient = /** @class */ (function () {
88
101
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
89
102
  };
90
103
  return ConversationMessagesClient;
91
- }());
104
+ }(base_client_1.BaseClient));
92
105
  exports.ConversationMessagesClient = ConversationMessagesClient;
@@ -1,6 +1,7 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { Conversation, UnreadConversation } from '../types/entities';
3
3
  import { GetConversationsArgs, GetOrCreateConversationArgs } from '../types/requests';
4
+ import { BaseClient } from './base-client';
4
5
  export type UpdateConversationArgs = {
5
6
  id: number;
6
7
  title: string;
@@ -29,11 +30,7 @@ export type MuteConversationArgs = {
29
30
  /**
30
31
  * Client for interacting with Twist conversation endpoints.
31
32
  */
32
- export declare class ConversationsClient {
33
- private apiToken;
34
- private baseUrl?;
35
- constructor(apiToken: string, baseUrl?: string | undefined);
36
- private getBaseUri;
33
+ export declare class ConversationsClient extends BaseClient {
37
34
  /**
38
35
  * Gets all conversations for a workspace.
39
36
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.ConversationsClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist conversation endpoints.
9
25
  */
10
- var ConversationsClient = /** @class */ (function () {
11
- function ConversationsClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var ConversationsClient = /** @class */ (function (_super) {
27
+ __extends(ConversationsClient, _super);
28
+ function ConversationsClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- ConversationsClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  ConversationsClient.prototype.getConversations = function (args, options) {
19
32
  var method = 'GET';
20
33
  var url = "".concat(endpoints_1.ENDPOINT_CONVERSATIONS, "/get");
@@ -170,5 +183,5 @@ var ConversationsClient = /** @class */ (function () {
170
183
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
171
184
  };
172
185
  return ConversationsClient;
173
- }());
186
+ }(base_client_1.BaseClient));
174
187
  exports.ConversationsClient = ConversationsClient;
@@ -1,5 +1,6 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { Group } from '../types/entities';
3
+ import { BaseClient } from './base-client';
3
4
  export type AddGroupUserArgs = {
4
5
  id: number;
5
6
  userId: number;
@@ -19,11 +20,7 @@ export type RemoveGroupUsersArgs = {
19
20
  /**
20
21
  * Client for interacting with Twist group endpoints.
21
22
  */
22
- export declare class GroupsClient {
23
- private apiToken;
24
- private baseUrl?;
25
- constructor(apiToken: string, baseUrl?: string | undefined);
26
- private getBaseUri;
23
+ export declare class GroupsClient extends BaseClient {
27
24
  /**
28
25
  * Gets all groups for a given workspace.
29
26
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.GroupsClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist group endpoints.
9
25
  */
10
- var GroupsClient = /** @class */ (function () {
11
- function GroupsClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var GroupsClient = /** @class */ (function (_super) {
27
+ __extends(GroupsClient, _super);
28
+ function GroupsClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- GroupsClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  GroupsClient.prototype.getGroups = function (workspaceId, options) {
19
32
  var method = 'GET';
20
33
  var url = "".concat(endpoints_1.ENDPOINT_GROUPS, "/get");
@@ -100,5 +113,5 @@ var GroupsClient = /** @class */ (function () {
100
113
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
101
114
  };
102
115
  return GroupsClient;
103
- }());
116
+ }(base_client_1.BaseClient));
104
117
  exports.GroupsClient = GroupsClient;
@@ -1,5 +1,6 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { InboxThread } from '../types/entities';
3
+ import { BaseClient } from './base-client';
3
4
  type GetInboxArgs = {
4
5
  workspaceId: number;
5
6
  since?: Date;
@@ -16,11 +17,7 @@ type ArchiveAllArgs = {
16
17
  /**
17
18
  * Client for interacting with Twist inbox endpoints.
18
19
  */
19
- export declare class InboxClient {
20
- private apiToken;
21
- private baseUrl?;
22
- constructor(apiToken: string, baseUrl?: string | undefined);
23
- private getBaseUri;
20
+ export declare class InboxClient extends BaseClient {
24
21
  /**
25
22
  * Gets inbox items (threads).
26
23
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.InboxClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist inbox endpoints.
9
25
  */
10
- var InboxClient = /** @class */ (function () {
11
- function InboxClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var InboxClient = /** @class */ (function (_super) {
27
+ __extends(InboxClient, _super);
28
+ function InboxClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- InboxClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  InboxClient.prototype.getInbox = function (args, options) {
19
32
  var params = {
20
33
  workspace_id: args.workspaceId,
@@ -88,5 +101,5 @@ var InboxClient = /** @class */ (function () {
88
101
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
89
102
  };
90
103
  return InboxClient;
91
- }());
104
+ }(base_client_1.BaseClient));
92
105
  exports.InboxClient = InboxClient;
@@ -1,4 +1,5 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
+ import { BaseClient } from './base-client';
2
3
  type AddReactionArgs = {
3
4
  threadId?: number;
4
5
  commentId?: number;
@@ -20,11 +21,7 @@ type ReactionObject = Record<string, number[]> | null;
20
21
  /**
21
22
  * Client for interacting with Twist reaction endpoints.
22
23
  */
23
- export declare class ReactionsClient {
24
- private apiToken;
25
- private baseUrl?;
26
- constructor(apiToken: string, baseUrl?: string | undefined);
27
- private getBaseUri;
24
+ export declare class ReactionsClient extends BaseClient {
28
25
  /**
29
26
  * Adds an emoji reaction to a thread, comment, or conversation message.
30
27
  *
@@ -1,19 +1,32 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.ReactionsClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
21
+ var base_client_1 = require("./base-client");
6
22
  /**
7
23
  * Client for interacting with Twist reaction endpoints.
8
24
  */
9
- var ReactionsClient = /** @class */ (function () {
10
- function ReactionsClient(apiToken, baseUrl) {
11
- this.apiToken = apiToken;
12
- this.baseUrl = baseUrl;
25
+ var ReactionsClient = /** @class */ (function (_super) {
26
+ __extends(ReactionsClient, _super);
27
+ function ReactionsClient() {
28
+ return _super !== null && _super.apply(this, arguments) || this;
13
29
  }
14
- ReactionsClient.prototype.getBaseUri = function () {
15
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
16
- };
17
30
  ReactionsClient.prototype.add = function (args, options) {
18
31
  var params = {
19
32
  reaction: args.reaction,
@@ -82,5 +95,5 @@ var ReactionsClient = /** @class */ (function () {
82
95
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
83
96
  };
84
97
  return ReactionsClient;
85
- }());
98
+ }(base_client_1.BaseClient));
86
99
  exports.ReactionsClient = ReactionsClient;
@@ -1,5 +1,6 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { SearchResult } from '../types/entities';
3
+ import { BaseClient } from './base-client';
3
4
  type SearchArgs = {
4
5
  query: string;
5
6
  workspaceId: number;
@@ -38,11 +39,7 @@ type SearchConversationResponse = {
38
39
  /**
39
40
  * Client for interacting with Twist search endpoints.
40
41
  */
41
- export declare class SearchClient {
42
- private apiToken;
43
- private baseUrl?;
44
- constructor(apiToken: string, baseUrl?: string | undefined);
45
- private getBaseUri;
42
+ export declare class SearchClient extends BaseClient {
46
43
  /**
47
44
  * Searches across all threads and conversations in a workspace.
48
45
  *
@@ -63,6 +60,7 @@ export declare class SearchClient {
63
60
  * ```typescript
64
61
  * const results = await api.search.search({
65
62
  * query: 'important meeting',
63
+ import { BaseClient, type ClientConfig } from './base-client'
66
64
  * workspaceId: 123
67
65
  * })
68
66
  * ```
@@ -1,4 +1,19 @@
1
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
+ })();
2
17
  var __assign = (this && this.__assign) || function () {
3
18
  __assign = Object.assign || function(t) {
4
19
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -15,17 +30,15 @@ exports.SearchClient = void 0;
15
30
  var endpoints_1 = require("../consts/endpoints");
16
31
  var rest_client_1 = require("../rest-client");
17
32
  var entities_1 = require("../types/entities");
33
+ var base_client_1 = require("./base-client");
18
34
  /**
19
35
  * Client for interacting with Twist search endpoints.
20
36
  */
21
- var SearchClient = /** @class */ (function () {
22
- function SearchClient(apiToken, baseUrl) {
23
- this.apiToken = apiToken;
24
- this.baseUrl = baseUrl;
37
+ var SearchClient = /** @class */ (function (_super) {
38
+ __extends(SearchClient, _super);
39
+ function SearchClient() {
40
+ return _super !== null && _super.apply(this, arguments) || this;
25
41
  }
26
- SearchClient.prototype.getBaseUri = function () {
27
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
28
- };
29
42
  SearchClient.prototype.search = function (args, options) {
30
43
  var params = {
31
44
  query: args.query,
@@ -85,5 +98,5 @@ var SearchClient = /** @class */ (function () {
85
98
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data; });
86
99
  };
87
100
  return SearchClient;
88
- }());
101
+ }(base_client_1.BaseClient));
89
102
  exports.SearchClient = SearchClient;
@@ -1,6 +1,7 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { Thread, UnreadThread } from '../types/entities';
3
3
  import { CreateThreadArgs, GetThreadsArgs, UpdateThreadArgs } from '../types/requests';
4
+ import { BaseClient } from './base-client';
4
5
  export type MoveThreadToChannelArgs = {
5
6
  id: number;
6
7
  toChannel: number;
@@ -24,11 +25,7 @@ export type MuteThreadArgs = {
24
25
  /**
25
26
  * Client for interacting with Twist thread endpoints.
26
27
  */
27
- export declare class ThreadsClient {
28
- private apiToken;
29
- private baseUrl?;
30
- constructor(apiToken: string, baseUrl?: string | undefined);
31
- private getBaseUri;
28
+ export declare class ThreadsClient extends BaseClient {
32
29
  /**
33
30
  * Gets all threads in a channel.
34
31
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.ThreadsClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist thread endpoints.
9
25
  */
10
- var ThreadsClient = /** @class */ (function () {
11
- function ThreadsClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var ThreadsClient = /** @class */ (function (_super) {
27
+ __extends(ThreadsClient, _super);
28
+ function ThreadsClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- ThreadsClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  ThreadsClient.prototype.getThreads = function (args, options) {
19
32
  var method = 'GET';
20
33
  var url = "".concat(endpoints_1.ENDPOINT_THREADS, "/get");
@@ -208,5 +221,5 @@ var ThreadsClient = /** @class */ (function () {
208
221
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
209
222
  };
210
223
  return ThreadsClient;
211
- }());
224
+ }(base_client_1.BaseClient));
212
225
  exports.ThreadsClient = ThreadsClient;
@@ -1,5 +1,6 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { User } from '../types/entities';
3
+ import { BaseClient } from './base-client';
3
4
  type AwayMode = {
4
5
  type: 'parental' | 'vacation' | 'sickleave' | 'other';
5
6
  dateFrom?: string;
@@ -26,11 +27,7 @@ type GoogleConnectionStatus = {
26
27
  /**
27
28
  * Client for interacting with Twist user endpoints.
28
29
  */
29
- export declare class UsersClient {
30
- private apiToken;
31
- private baseUrl?;
32
- constructor(apiToken: string, baseUrl?: string | undefined);
33
- private getBaseUri;
30
+ export declare class UsersClient extends BaseClient {
34
31
  /**
35
32
  * Logs in an existing user.
36
33
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.UsersClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist user endpoints.
9
25
  */
10
- var UsersClient = /** @class */ (function () {
11
- function UsersClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var UsersClient = /** @class */ (function (_super) {
27
+ __extends(UsersClient, _super);
28
+ function UsersClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- UsersClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  UsersClient.prototype.login = function (args, options) {
19
32
  var method = 'POST';
20
33
  var url = "".concat(endpoints_1.ENDPOINT_USERS, "/login");
@@ -151,5 +164,5 @@ var UsersClient = /** @class */ (function () {
151
164
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data; });
152
165
  };
153
166
  return UsersClient;
154
- }());
167
+ }(base_client_1.BaseClient));
155
168
  exports.UsersClient = UsersClient;
@@ -1,6 +1,7 @@
1
1
  import { BatchRequestDescriptor } from '../types/batch';
2
2
  import { WorkspaceUser } from '../types/entities';
3
3
  import { UserType } from '../types/enums';
4
+ import { BaseClient } from './base-client';
4
5
  export type GetWorkspaceUsersArgs = {
5
6
  workspaceId: number;
6
7
  archived?: boolean;
@@ -24,11 +25,7 @@ export type GetUserLocalTimeArgs = {
24
25
  /**
25
26
  * Client for interacting with Twist workspace users endpoints (v4 API).
26
27
  */
27
- export declare class WorkspaceUsersClient {
28
- private apiToken;
29
- private baseUrl?;
30
- constructor(apiToken: string, baseUrl?: string | undefined);
31
- private getBaseUri;
28
+ export declare class WorkspaceUsersClient extends BaseClient {
32
29
  /**
33
30
  * Returns a list of workspace user objects for the given workspace id.
34
31
  *
@@ -1,19 +1,32 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.WorkspaceUsersClient = void 0;
4
19
  var rest_client_1 = require("../rest-client");
5
20
  var entities_1 = require("../types/entities");
21
+ var base_client_1 = require("./base-client");
6
22
  /**
7
23
  * Client for interacting with Twist workspace users endpoints (v4 API).
8
24
  */
9
- var WorkspaceUsersClient = /** @class */ (function () {
10
- function WorkspaceUsersClient(apiToken, baseUrl) {
11
- this.apiToken = apiToken;
12
- this.baseUrl = baseUrl;
25
+ var WorkspaceUsersClient = /** @class */ (function (_super) {
26
+ __extends(WorkspaceUsersClient, _super);
27
+ function WorkspaceUsersClient() {
28
+ return _super !== null && _super.apply(this, arguments) || this;
13
29
  }
14
- WorkspaceUsersClient.prototype.getBaseUri = function () {
15
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v4") : 'https://api.twist.com/api/v4/';
16
- };
17
30
  WorkspaceUsersClient.prototype.getWorkspaceUsers = function (args, options) {
18
31
  var method = 'GET';
19
32
  var url = 'workspace_users/get';
@@ -21,7 +34,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
21
34
  if (options === null || options === void 0 ? void 0 : options.batch) {
22
35
  return { method: method, url: url, params: params };
23
36
  }
24
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data.map(function (user) { return entities_1.WorkspaceUserSchema.parse(user); }); });
37
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function (response) { return response.data.map(function (user) { return entities_1.WorkspaceUserSchema.parse(user); }); });
25
38
  };
26
39
  WorkspaceUsersClient.prototype.getWorkspaceUserIds = function (workspaceId, options) {
27
40
  var method = 'GET';
@@ -30,7 +43,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
30
43
  if (options === null || options === void 0 ? void 0 : options.batch) {
31
44
  return { method: method, url: url, params: params };
32
45
  }
33
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data; });
46
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function (response) { return response.data; });
34
47
  };
35
48
  WorkspaceUsersClient.prototype.getUserById = function (args, options) {
36
49
  var method = 'GET';
@@ -40,7 +53,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
40
53
  if (options === null || options === void 0 ? void 0 : options.batch) {
41
54
  return { method: method, url: url, params: params, schema: schema };
42
55
  }
43
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
56
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
44
57
  };
45
58
  WorkspaceUsersClient.prototype.getUserByEmail = function (args, options) {
46
59
  var method = 'GET';
@@ -50,7 +63,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
50
63
  if (options === null || options === void 0 ? void 0 : options.batch) {
51
64
  return { method: method, url: url, params: params, schema: schema };
52
65
  }
53
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
66
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
54
67
  };
55
68
  WorkspaceUsersClient.prototype.getUserInfo = function (args, options) {
56
69
  var method = 'GET';
@@ -59,7 +72,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
59
72
  if (options === null || options === void 0 ? void 0 : options.batch) {
60
73
  return { method: method, url: url, params: params };
61
74
  }
62
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data; });
75
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function (response) { return response.data; });
63
76
  };
64
77
  WorkspaceUsersClient.prototype.getUserLocalTime = function (args, options) {
65
78
  var method = 'GET';
@@ -68,7 +81,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
68
81
  if (options === null || options === void 0 ? void 0 : options.batch) {
69
82
  return { method: method, url: url, params: params };
70
83
  }
71
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data; });
84
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function (response) { return response.data; });
72
85
  };
73
86
  WorkspaceUsersClient.prototype.addUser = function (args, options) {
74
87
  var params = {
@@ -84,7 +97,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
84
97
  if (options === null || options === void 0 ? void 0 : options.batch) {
85
98
  return { method: method, url: url, params: params, schema: schema };
86
99
  }
87
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
100
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
88
101
  };
89
102
  WorkspaceUsersClient.prototype.updateUser = function (args, options) {
90
103
  var params = {
@@ -99,7 +112,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
99
112
  if (options === null || options === void 0 ? void 0 : options.batch) {
100
113
  return { method: method, url: url, params: params, schema: schema };
101
114
  }
102
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
115
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function (response) { return schema.parse(response.data); });
103
116
  };
104
117
  WorkspaceUsersClient.prototype.removeUser = function (args, options) {
105
118
  var params = {
@@ -112,7 +125,7 @@ var WorkspaceUsersClient = /** @class */ (function () {
112
125
  if (options === null || options === void 0 ? void 0 : options.batch) {
113
126
  return { method: method, url: url, params: params };
114
127
  }
115
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
128
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function () { return undefined; });
116
129
  };
117
130
  WorkspaceUsersClient.prototype.resendInvite = function (args, options) {
118
131
  var params = {
@@ -125,8 +138,8 @@ var WorkspaceUsersClient = /** @class */ (function () {
125
138
  if (options === null || options === void 0 ? void 0 : options.batch) {
126
139
  return { method: method, url: url, params: params };
127
140
  }
128
- return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function () { return undefined; });
141
+ return (0, rest_client_1.request)(method, this.getBaseUri('v4'), url, this.apiToken, params).then(function () { return undefined; });
129
142
  };
130
143
  return WorkspaceUsersClient;
131
- }());
144
+ }(base_client_1.BaseClient));
132
145
  exports.WorkspaceUsersClient = WorkspaceUsersClient;
@@ -1,13 +1,10 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch';
2
2
  import { Channel, Workspace } from '../types/entities';
3
+ import { BaseClient } from './base-client';
3
4
  /**
4
5
  * Client for interacting with Twist workspace endpoints.
5
6
  */
6
- export declare class WorkspacesClient {
7
- private apiToken;
8
- private baseUrl?;
9
- constructor(apiToken: string, baseUrl?: string | undefined);
10
- private getBaseUri;
7
+ export declare class WorkspacesClient extends BaseClient {
11
8
  /**
12
9
  * Gets all the user's workspaces.
13
10
  *
@@ -1,20 +1,33 @@
1
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
+ })();
2
17
  Object.defineProperty(exports, "__esModule", { value: true });
3
18
  exports.WorkspacesClient = void 0;
4
19
  var endpoints_1 = require("../consts/endpoints");
5
20
  var rest_client_1 = require("../rest-client");
6
21
  var entities_1 = require("../types/entities");
22
+ var base_client_1 = require("./base-client");
7
23
  /**
8
24
  * Client for interacting with Twist workspace endpoints.
9
25
  */
10
- var WorkspacesClient = /** @class */ (function () {
11
- function WorkspacesClient(apiToken, baseUrl) {
12
- this.apiToken = apiToken;
13
- this.baseUrl = baseUrl;
26
+ var WorkspacesClient = /** @class */ (function (_super) {
27
+ __extends(WorkspacesClient, _super);
28
+ function WorkspacesClient() {
29
+ return _super !== null && _super.apply(this, arguments) || this;
14
30
  }
15
- WorkspacesClient.prototype.getBaseUri = function () {
16
- return this.baseUrl ? "".concat(this.baseUrl, "/api/v3") : (0, endpoints_1.getTwistBaseUri)();
17
- };
18
31
  WorkspacesClient.prototype.getWorkspaces = function (options) {
19
32
  var method = 'GET';
20
33
  var url = "".concat(endpoints_1.ENDPOINT_WORKSPACES, "/get");
@@ -85,5 +98,5 @@ var WorkspacesClient = /** @class */ (function () {
85
98
  return (0, rest_client_1.request)(method, this.getBaseUri(), url, this.apiToken, params).then(function (response) { return response.data.map(function (channel) { return entities_1.ChannelSchema.parse(channel); }); });
86
99
  };
87
100
  return WorkspacesClient;
88
- }());
101
+ }(base_client_1.BaseClient));
89
102
  exports.WorkspacesClient = WorkspacesClient;
@@ -1,6 +1,17 @@
1
+ import type { ApiVersion } from '../types/api-version';
1
2
  export declare const API_VERSION = "v3";
3
+ /**
4
+ * @deprecated Use getTwistBaseUri() instead. This constant is kept for backward compatibility.
5
+ */
2
6
  export declare const API_BASE_URI = "/api/v3/";
3
- export declare function getTwistBaseUri(domainBase?: string): string;
7
+ /**
8
+ * Gets the base URI for Twist API requests.
9
+ *
10
+ * @param version - API version ('v3' or 'v4'). Defaults to 'v3'.
11
+ * @param domainBase - Custom domain base URL. Defaults to Twist's API domain.
12
+ * @returns Complete base URI with trailing slash (e.g., 'https://api.twist.com/api/v3/')
13
+ */
14
+ export declare function getTwistBaseUri(version?: ApiVersion, domainBase?: string): string;
4
15
  export declare const ENDPOINT_USERS = "users";
5
16
  export declare const ENDPOINT_WORKSPACES = "workspaces";
6
17
  export declare const ENDPOINT_CHANNELS = "channels";
@@ -4,10 +4,21 @@ exports.ENDPOINT_CONVERSATION_MESSAGES = exports.ENDPOINT_SEARCH = exports.ENDPO
4
4
  exports.getTwistBaseUri = getTwistBaseUri;
5
5
  var BASE_URI = 'https://api.twist.com';
6
6
  exports.API_VERSION = 'v3';
7
+ /**
8
+ * @deprecated Use getTwistBaseUri() instead. This constant is kept for backward compatibility.
9
+ */
7
10
  exports.API_BASE_URI = "/api/".concat(exports.API_VERSION, "/");
8
- function getTwistBaseUri(domainBase) {
11
+ /**
12
+ * Gets the base URI for Twist API requests.
13
+ *
14
+ * @param version - API version ('v3' or 'v4'). Defaults to 'v3'.
15
+ * @param domainBase - Custom domain base URL. Defaults to Twist's API domain.
16
+ * @returns Complete base URI with trailing slash (e.g., 'https://api.twist.com/api/v3/')
17
+ */
18
+ function getTwistBaseUri(version, domainBase) {
19
+ if (version === void 0) { version = 'v3'; }
9
20
  if (domainBase === void 0) { domainBase = BASE_URI; }
10
- return new URL(exports.API_BASE_URI, domainBase).toString();
21
+ return new URL("/api/".concat(version, "/"), domainBase).toString();
11
22
  }
12
23
  exports.ENDPOINT_USERS = 'users';
13
24
  exports.ENDPOINT_WORKSPACES = 'workspaces';
package/dist/twist-api.js CHANGED
@@ -35,18 +35,20 @@ var TwistApi = /** @class */ (function () {
35
35
  function TwistApi(authToken, baseUrl) {
36
36
  this.authToken = authToken;
37
37
  this.baseUrl = baseUrl;
38
- this.users = new users_client_1.UsersClient(authToken, baseUrl);
39
- this.workspaces = new workspaces_client_1.WorkspacesClient(authToken, baseUrl);
40
- this.workspaceUsers = new workspace_users_client_1.WorkspaceUsersClient(authToken, baseUrl);
41
- this.channels = new channels_client_1.ChannelsClient(authToken, baseUrl);
42
- this.threads = new threads_client_1.ThreadsClient(authToken, baseUrl);
43
- this.groups = new groups_client_1.GroupsClient(authToken, baseUrl);
44
- this.conversations = new conversations_client_1.ConversationsClient(authToken, baseUrl);
45
- this.comments = new comments_client_1.CommentsClient(authToken, baseUrl);
46
- this.conversationMessages = new conversation_messages_client_1.ConversationMessagesClient(authToken, baseUrl);
47
- this.inbox = new inbox_client_1.InboxClient(authToken, baseUrl);
48
- this.reactions = new reactions_client_1.ReactionsClient(authToken, baseUrl);
49
- this.search = new search_client_1.SearchClient(authToken, baseUrl);
38
+ var clientConfig = { apiToken: authToken, baseUrl: baseUrl };
39
+ var workspaceUserConfig = { apiToken: authToken, baseUrl: baseUrl, version: 'v4' };
40
+ this.users = new users_client_1.UsersClient(clientConfig);
41
+ this.workspaces = new workspaces_client_1.WorkspacesClient(clientConfig);
42
+ this.workspaceUsers = new workspace_users_client_1.WorkspaceUsersClient(workspaceUserConfig);
43
+ this.channels = new channels_client_1.ChannelsClient(clientConfig);
44
+ this.threads = new threads_client_1.ThreadsClient(clientConfig);
45
+ this.groups = new groups_client_1.GroupsClient(clientConfig);
46
+ this.conversations = new conversations_client_1.ConversationsClient(clientConfig);
47
+ this.comments = new comments_client_1.CommentsClient(clientConfig);
48
+ this.conversationMessages = new conversation_messages_client_1.ConversationMessagesClient(clientConfig);
49
+ this.inbox = new inbox_client_1.InboxClient(clientConfig);
50
+ this.reactions = new reactions_client_1.ReactionsClient(clientConfig);
51
+ this.search = new search_client_1.SearchClient(clientConfig);
50
52
  }
51
53
  /**
52
54
  * Executes multiple API requests in a single HTTP call using the batch endpoint.
@@ -68,7 +70,7 @@ var TwistApi = /** @class */ (function () {
68
70
  for (var _i = 0; _i < arguments.length; _i++) {
69
71
  requests[_i] = arguments[_i];
70
72
  }
71
- var builder = new batch_builder_1.BatchBuilder(this.authToken, this.baseUrl);
73
+ var builder = new batch_builder_1.BatchBuilder({ apiToken: this.authToken, baseUrl: this.baseUrl });
72
74
  return builder.execute(requests);
73
75
  };
74
76
  return TwistApi;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Supported Twist API versions
3
+ */
4
+ export type ApiVersion = 'v3' | 'v4';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/twist-sdk",
3
- "version": "0.1.0-alpha.3",
3
+ "version": "0.1.0-alpha.4",
4
4
  "description": "A TypeScript wrapper for the Twist REST API.",
5
5
  "author": "Doist developers",
6
6
  "homepage": "https://doist.github.io/twist-sdk-typescript/",
@@ -44,17 +44,17 @@
44
44
  "@biomejs/biome": "2.2.5",
45
45
  "@types/uuid": "9.0.8",
46
46
  "husky": "9.1.7",
47
- "lint-staged": "13.3.0",
47
+ "lint-staged": "16.2.6",
48
48
  "msw": "^2.11.3",
49
49
  "npm-run-all2": "8.0.4",
50
- "rimraf": "3.0.2",
50
+ "rimraf": "6.0.1",
51
51
  "ts-node": "10.9.2",
52
- "type-fest": "^4.12.0",
52
+ "type-fest": "^5.0.0",
53
53
  "typescript": "5.9.3",
54
54
  "vitest": "3.2.4"
55
55
  },
56
56
  "peerDependencies": {
57
- "type-fest": "^4.12.0"
57
+ "type-fest": "^4.12.0 || ^5.1.0"
58
58
  },
59
59
  "husky": {
60
60
  "hooks": {