@doist/twist-sdk 2.1.2 → 2.1.3

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.
@@ -47,6 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
47
47
  }
48
48
  };
49
49
  Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.TWIST_SCOPES = void 0;
50
51
  exports.getAuthStateParameter = getAuthStateParameter;
51
52
  exports.getAuthorizationUrl = getAuthorizationUrl;
52
53
  exports.getAuthToken = getAuthToken;
@@ -54,6 +55,90 @@ exports.revokeAuthToken = revokeAuthToken;
54
55
  var uuid_1 = require("uuid");
55
56
  var rest_client_1 = require("./rest-client");
56
57
  var errors_1 = require("./types/errors");
58
+ /**
59
+ * OAuth scopes for the Twist API.
60
+ *
61
+ * @remarks
62
+ * Request only the scopes your application needs:
63
+ *
64
+ * **User Scopes:**
65
+ * - `user:read` - Access user's personal settings
66
+ * - `user:write` - Access and update user's personal settings
67
+ *
68
+ * **Workspace Scopes:**
69
+ * - `workspaces:read` - Access teams the user is part of
70
+ * - `workspaces:write` - Access and update teams the user is part of
71
+ *
72
+ * **Channel Scopes:**
73
+ * - `channels:read` - Access channels
74
+ * - `channels:write` - Access and update channels
75
+ * - `channels:remove` - Access, update, and delete channels
76
+ *
77
+ * **Thread Scopes:**
78
+ * - `threads:read` - Access threads
79
+ * - `threads:write` - Access and update threads
80
+ * - `threads:remove` - Access, update, and delete threads
81
+ *
82
+ * **Comment Scopes:**
83
+ * - `comments:read` - Access comments
84
+ * - `comments:write` - Access and update comments
85
+ * - `comments:remove` - Access, update, and delete comments
86
+ *
87
+ * **Group Scopes:**
88
+ * - `groups:read` - Access groups
89
+ * - `groups:write` - Access and update groups
90
+ * - `groups:remove` - Access, update, and delete groups
91
+ *
92
+ * **Message Scopes:**
93
+ * - `messages:read` - Access messages
94
+ * - `messages:write` - Access and update messages
95
+ * - `messages:remove` - Access, update, and delete messages
96
+ *
97
+ * **Reaction Scopes:**
98
+ * - `reactions:read` - Access reactions
99
+ * - `reactions:write` - Access and update reactions
100
+ * - `reactions:remove` - Access, update, and delete reactions
101
+ *
102
+ * **Search Scopes:**
103
+ * - `search:read` - Search
104
+ *
105
+ * **Attachment Scopes:**
106
+ * - `attachments:read` - Access attachments
107
+ * - `attachments:write` - Access and update attachments
108
+ *
109
+ * **Notification Scopes:**
110
+ * - `notifications:read` - Read user's notifications settings
111
+ * - `notifications:write` - Read and update user's notifications settings
112
+ */
113
+ exports.TWIST_SCOPES = [
114
+ 'user:read',
115
+ 'user:write',
116
+ 'workspaces:read',
117
+ 'workspaces:write',
118
+ 'channels:read',
119
+ 'channels:write',
120
+ 'channels:remove',
121
+ 'threads:read',
122
+ 'threads:write',
123
+ 'threads:remove',
124
+ 'comments:read',
125
+ 'comments:write',
126
+ 'comments:remove',
127
+ 'groups:read',
128
+ 'groups:write',
129
+ 'groups:remove',
130
+ 'messages:read',
131
+ 'messages:write',
132
+ 'messages:remove',
133
+ 'reactions:read',
134
+ 'reactions:write',
135
+ 'reactions:remove',
136
+ 'search:read',
137
+ 'attachments:read',
138
+ 'attachments:write',
139
+ 'notifications:read',
140
+ 'notifications:write',
141
+ ];
57
142
  function getAuthStateParameter() {
58
143
  return (0, uuid_1.v4)();
59
144
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BaseClient = void 0;
4
4
  var endpoints_1 = require("../consts/endpoints");
5
+ var api_version_1 = require("../types/api-version");
5
6
  /**
6
7
  * Base client class that provides centralized URL management and configuration
7
8
  * for all Twist API clients. Fixes the trailing slash bug and eliminates code duplication.
@@ -10,7 +11,7 @@ var BaseClient = /** @class */ (function () {
10
11
  function BaseClient(config) {
11
12
  this.apiToken = config.apiToken;
12
13
  this.baseUrl = config.baseUrl;
13
- this.defaultVersion = config.version || 'v3';
14
+ this.defaultVersion = config.version || api_version_1.DEFAULT_API_VERSION;
14
15
  this.customFetch = config.customFetch;
15
16
  }
16
17
  /**
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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;
4
4
  exports.getTwistBaseUri = getTwistBaseUri;
5
+ var api_version_1 = require("../types/api-version");
5
6
  var BASE_URI = 'https://api.twist.com';
6
- exports.API_VERSION = 'v3';
7
+ exports.API_VERSION = api_version_1.DEFAULT_API_VERSION;
7
8
  /**
8
9
  * @deprecated Use getTwistBaseUri() instead. This constant is kept for backward compatibility.
9
10
  */
@@ -16,7 +17,7 @@ exports.API_BASE_URI = "/api/".concat(exports.API_VERSION, "/");
16
17
  * @returns Complete base URI with trailing slash (e.g., 'https://api.twist.com/api/v3/')
17
18
  */
18
19
  function getTwistBaseUri(version, domainBase) {
19
- if (version === void 0) { version = 'v3'; }
20
+ if (version === void 0) { version = api_version_1.DEFAULT_API_VERSION; }
20
21
  if (domainBase === void 0) { domainBase = BASE_URI; }
21
22
  return new URL("/api/".concat(version, "/"), domainBase).toString();
22
23
  }
@@ -1,2 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_API_VERSION = exports.API_VERSIONS = void 0;
4
+ /**
5
+ * Supported Twist API versions
6
+ */
7
+ exports.API_VERSIONS = ['v3', 'v4'];
8
+ exports.DEFAULT_API_VERSION = 'v3';
@@ -11,14 +11,14 @@ var __assign = (this && this.__assign) || function () {
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.SearchResultSchema = exports.SEARCH_RESULT_TYPES = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.ConversationSchema = exports.GroupSchema = exports.ThreadSchema = exports.ChannelSchema = exports.WorkspaceSchema = exports.UserSchema = exports.SystemMessageSchema = void 0;
14
+ exports.SearchResultSchema = exports.SEARCH_RESULT_TYPES = exports.UnreadConversationSchema = exports.UnreadThreadSchema = exports.InboxThreadSchema = exports.ConversationMessageSchema = exports.WorkspaceUserSchema = exports.CommentSchema = exports.ConversationSchema = exports.GroupSchema = exports.ThreadSchema = exports.ChannelSchema = exports.WorkspaceSchema = exports.UserSchema = exports.BaseUserSchema = exports.SystemMessageSchema = void 0;
15
15
  var zod_1 = require("zod");
16
16
  var url_helpers_1 = require("../utils/url-helpers");
17
17
  var enums_1 = require("./enums");
18
18
  // Reusable schema for system messages that can be either a string or an object
19
19
  exports.SystemMessageSchema = zod_1.z.union([zod_1.z.string(), zod_1.z.unknown()]).nullable().optional();
20
20
  // Base user schema with common fields shared between User and WorkspaceUser
21
- var BaseUserSchema = zod_1.z.object({
21
+ exports.BaseUserSchema = zod_1.z.object({
22
22
  id: zod_1.z.number(),
23
23
  name: zod_1.z.string(),
24
24
  shortName: zod_1.z.string(),
@@ -50,7 +50,7 @@ var BaseUserSchema = zod_1.z.object({
50
50
  setupPending: zod_1.z.union([zod_1.z.boolean(), zod_1.z.number()]).nullable().optional(),
51
51
  });
52
52
  // User entity from API
53
- exports.UserSchema = BaseUserSchema.extend({
53
+ exports.UserSchema = exports.BaseUserSchema.extend({
54
54
  email: zod_1.z.email(),
55
55
  snoozeDndStart: zod_1.z.string().nullable().optional(),
56
56
  clientId: zod_1.z.string().nullable().optional(),
@@ -262,7 +262,7 @@ exports.CommentSchema = zod_1.z
262
262
  commentId: data.id,
263
263
  }) })); });
264
264
  // WorkspaceUser entity from v4 API
265
- exports.WorkspaceUserSchema = BaseUserSchema.extend({
265
+ exports.WorkspaceUserSchema = exports.BaseUserSchema.extend({
266
266
  email: zod_1.z.string().nullable().optional(),
267
267
  userType: zod_1.z.enum(enums_1.USER_TYPES),
268
268
  dateFormat: zod_1.z.string().nullable().optional(),
@@ -1,2 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HTTP_METHODS = void 0;
4
+ exports.HTTP_METHODS = ['POST', 'GET', 'PUT', 'PATCH', 'DELETE'];
@@ -14,6 +14,7 @@ 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
+ __exportStar(require("./api-version"), exports);
17
18
  __exportStar(require("./batch"), exports);
18
19
  __exportStar(require("./entities"), exports);
19
20
  __exportStar(require("./enums"), exports);
@@ -48,6 +48,90 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
48
48
  import { v4 as uuid } from 'uuid';
49
49
  import { isSuccess, request } from './rest-client.js';
50
50
  import { TwistRequestError } from './types/errors.js';
51
+ /**
52
+ * OAuth scopes for the Twist API.
53
+ *
54
+ * @remarks
55
+ * Request only the scopes your application needs:
56
+ *
57
+ * **User Scopes:**
58
+ * - `user:read` - Access user's personal settings
59
+ * - `user:write` - Access and update user's personal settings
60
+ *
61
+ * **Workspace Scopes:**
62
+ * - `workspaces:read` - Access teams the user is part of
63
+ * - `workspaces:write` - Access and update teams the user is part of
64
+ *
65
+ * **Channel Scopes:**
66
+ * - `channels:read` - Access channels
67
+ * - `channels:write` - Access and update channels
68
+ * - `channels:remove` - Access, update, and delete channels
69
+ *
70
+ * **Thread Scopes:**
71
+ * - `threads:read` - Access threads
72
+ * - `threads:write` - Access and update threads
73
+ * - `threads:remove` - Access, update, and delete threads
74
+ *
75
+ * **Comment Scopes:**
76
+ * - `comments:read` - Access comments
77
+ * - `comments:write` - Access and update comments
78
+ * - `comments:remove` - Access, update, and delete comments
79
+ *
80
+ * **Group Scopes:**
81
+ * - `groups:read` - Access groups
82
+ * - `groups:write` - Access and update groups
83
+ * - `groups:remove` - Access, update, and delete groups
84
+ *
85
+ * **Message Scopes:**
86
+ * - `messages:read` - Access messages
87
+ * - `messages:write` - Access and update messages
88
+ * - `messages:remove` - Access, update, and delete messages
89
+ *
90
+ * **Reaction Scopes:**
91
+ * - `reactions:read` - Access reactions
92
+ * - `reactions:write` - Access and update reactions
93
+ * - `reactions:remove` - Access, update, and delete reactions
94
+ *
95
+ * **Search Scopes:**
96
+ * - `search:read` - Search
97
+ *
98
+ * **Attachment Scopes:**
99
+ * - `attachments:read` - Access attachments
100
+ * - `attachments:write` - Access and update attachments
101
+ *
102
+ * **Notification Scopes:**
103
+ * - `notifications:read` - Read user's notifications settings
104
+ * - `notifications:write` - Read and update user's notifications settings
105
+ */
106
+ export var TWIST_SCOPES = [
107
+ 'user:read',
108
+ 'user:write',
109
+ 'workspaces:read',
110
+ 'workspaces:write',
111
+ 'channels:read',
112
+ 'channels:write',
113
+ 'channels:remove',
114
+ 'threads:read',
115
+ 'threads:write',
116
+ 'threads:remove',
117
+ 'comments:read',
118
+ 'comments:write',
119
+ 'comments:remove',
120
+ 'groups:read',
121
+ 'groups:write',
122
+ 'groups:remove',
123
+ 'messages:read',
124
+ 'messages:write',
125
+ 'messages:remove',
126
+ 'reactions:read',
127
+ 'reactions:write',
128
+ 'reactions:remove',
129
+ 'search:read',
130
+ 'attachments:read',
131
+ 'attachments:write',
132
+ 'notifications:read',
133
+ 'notifications:write',
134
+ ];
51
135
  export function getAuthStateParameter() {
52
136
  return uuid();
53
137
  }
@@ -1,4 +1,5 @@
1
1
  import { getTwistBaseUri } from '../consts/endpoints.js';
2
+ import { DEFAULT_API_VERSION } from '../types/api-version.js';
2
3
  /**
3
4
  * Base client class that provides centralized URL management and configuration
4
5
  * for all Twist API clients. Fixes the trailing slash bug and eliminates code duplication.
@@ -7,7 +8,7 @@ var BaseClient = /** @class */ (function () {
7
8
  function BaseClient(config) {
8
9
  this.apiToken = config.apiToken;
9
10
  this.baseUrl = config.baseUrl;
10
- this.defaultVersion = config.version || 'v3';
11
+ this.defaultVersion = config.version || DEFAULT_API_VERSION;
11
12
  this.customFetch = config.customFetch;
12
13
  }
13
14
  /**
@@ -1,5 +1,6 @@
1
+ import { DEFAULT_API_VERSION } from '../types/api-version.js';
1
2
  var BASE_URI = 'https://api.twist.com';
2
- export var API_VERSION = 'v3';
3
+ export var API_VERSION = DEFAULT_API_VERSION;
3
4
  /**
4
5
  * @deprecated Use getTwistBaseUri() instead. This constant is kept for backward compatibility.
5
6
  */
@@ -12,7 +13,7 @@ export var API_BASE_URI = "/api/".concat(API_VERSION, "/");
12
13
  * @returns Complete base URI with trailing slash (e.g., 'https://api.twist.com/api/v3/')
13
14
  */
14
15
  export function getTwistBaseUri(version, domainBase) {
15
- if (version === void 0) { version = 'v3'; }
16
+ if (version === void 0) { version = DEFAULT_API_VERSION; }
16
17
  if (domainBase === void 0) { domainBase = BASE_URI; }
17
18
  return new URL("/api/".concat(version, "/"), domainBase).toString();
18
19
  }
@@ -1 +1,5 @@
1
- export {};
1
+ /**
2
+ * Supported Twist API versions
3
+ */
4
+ export var API_VERSIONS = ['v3', 'v4'];
5
+ export var DEFAULT_API_VERSION = 'v3';
@@ -15,7 +15,7 @@ import { USER_TYPES, WORKSPACE_PLANS } from './enums.js';
15
15
  // Reusable schema for system messages that can be either a string or an object
16
16
  export var SystemMessageSchema = z.union([z.string(), z.unknown()]).nullable().optional();
17
17
  // Base user schema with common fields shared between User and WorkspaceUser
18
- var BaseUserSchema = z.object({
18
+ export var BaseUserSchema = z.object({
19
19
  id: z.number(),
20
20
  name: z.string(),
21
21
  shortName: z.string(),
@@ -1 +1 @@
1
- export {};
1
+ export var HTTP_METHODS = ['POST', 'GET', 'PUT', 'PATCH', 'DELETE'];
@@ -1,3 +1,4 @@
1
+ export * from './api-version.js';
1
2
  export * from './batch.js';
2
3
  export * from './entities.js';
3
4
  export * from './enums.js';
@@ -60,7 +60,11 @@ export type AuthOptions = {
60
60
  * - `notifications:read` - Read user's notifications settings
61
61
  * - `notifications:write` - Read and update user's notifications settings
62
62
  */
63
- export type TwistScope = 'user:read' | 'user:write' | 'workspaces:read' | 'workspaces:write' | 'channels:read' | 'channels:write' | 'channels:remove' | 'threads:read' | 'threads:write' | 'threads:remove' | 'comments:read' | 'comments:write' | 'comments:remove' | 'groups:read' | 'groups:write' | 'groups:remove' | 'messages:read' | 'messages:write' | 'messages:remove' | 'reactions:read' | 'reactions:write' | 'reactions:remove' | 'search:read' | 'attachments:read' | 'attachments:write' | 'notifications:read' | 'notifications:write';
63
+ export declare const TWIST_SCOPES: readonly ["user:read", "user:write", "workspaces:read", "workspaces:write", "channels:read", "channels:write", "channels:remove", "threads:read", "threads:write", "threads:remove", "comments:read", "comments:write", "comments:remove", "groups:read", "groups:write", "groups:remove", "messages:read", "messages:write", "messages:remove", "reactions:read", "reactions:write", "reactions:remove", "search:read", "attachments:read", "attachments:write", "notifications:read", "notifications:write"];
64
+ /**
65
+ * Scopes determine what access a token has to the Twist API.
66
+ */
67
+ export type TwistScope = (typeof TWIST_SCOPES)[number];
64
68
  export type AuthTokenRequestArgs = {
65
69
  clientId: string;
66
70
  clientSecret: string;
@@ -1,9 +1,9 @@
1
1
  import type { ApiVersion } from '../types/api-version.js';
2
- export declare const API_VERSION = "v3";
2
+ export declare const API_VERSION: "v3" | "v4";
3
3
  /**
4
4
  * @deprecated Use getTwistBaseUri() instead. This constant is kept for backward compatibility.
5
5
  */
6
- export declare const API_BASE_URI = "/api/v3/";
6
+ export declare const API_BASE_URI: string;
7
7
  /**
8
8
  * Gets the base URI for Twist API requests.
9
9
  *
@@ -1,4 +1,6 @@
1
1
  /**
2
2
  * Supported Twist API versions
3
3
  */
4
- export type ApiVersion = 'v3' | 'v4';
4
+ export declare const API_VERSIONS: readonly ["v3", "v4"];
5
+ export type ApiVersion = (typeof API_VERSIONS)[number];
6
+ export declare const DEFAULT_API_VERSION: ApiVersion;
@@ -1,5 +1,30 @@
1
1
  import { z } from 'zod';
2
2
  export declare const SystemMessageSchema: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodUnknown]>>>;
3
+ export declare const BaseUserSchema: z.ZodObject<{
4
+ id: z.ZodNumber;
5
+ name: z.ZodString;
6
+ shortName: z.ZodString;
7
+ firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
8
+ contactInfo: z.ZodOptional<z.ZodNullable<z.ZodString>>;
9
+ bot: z.ZodBoolean;
10
+ profession: z.ZodOptional<z.ZodNullable<z.ZodString>>;
11
+ timezone: z.ZodString;
12
+ removed: z.ZodBoolean;
13
+ avatarId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
14
+ avatarUrls: z.ZodOptional<z.ZodNullable<z.ZodObject<{
15
+ s35: z.ZodString;
16
+ s60: z.ZodString;
17
+ s195: z.ZodString;
18
+ s640: z.ZodString;
19
+ }, z.core.$strip>>>;
20
+ awayMode: z.ZodOptional<z.ZodNullable<z.ZodObject<{
21
+ dateFrom: z.ZodString;
22
+ type: z.ZodString;
23
+ dateTo: z.ZodString;
24
+ }, z.core.$strip>>>;
25
+ restricted: z.ZodOptional<z.ZodNullable<z.ZodBoolean>>;
26
+ setupPending: z.ZodOptional<z.ZodNullable<z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber]>>>;
27
+ }, z.core.$strip>;
3
28
  export declare const UserSchema: z.ZodObject<{
4
29
  id: z.ZodNumber;
5
30
  name: z.ZodString;
@@ -1,4 +1,5 @@
1
- export type HttpMethod = 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
1
+ export declare const HTTP_METHODS: readonly ["POST", "GET", "PUT", "PATCH", "DELETE"];
2
+ export type HttpMethod = (typeof HTTP_METHODS)[number];
2
3
  export type HttpResponse<T = unknown> = {
3
4
  data: T;
4
5
  status: number;
@@ -1,3 +1,4 @@
1
+ export * from './api-version.js';
1
2
  export * from './batch.js';
2
3
  export * from './entities.js';
3
4
  export * from './enums.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/twist-sdk",
3
- "version": "2.1.2",
3
+ "version": "2.1.3",
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/",