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

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 +21 -8
  2. package/dist/batch-builder.js +99 -13
  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,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 });