@doist/twist-sdk 2.1.2 → 2.1.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.
- package/dist/cjs/authentication.js +90 -5
- package/dist/cjs/batch-builder.js +2 -2
- package/dist/cjs/clients/base-client.js +2 -1
- package/dist/cjs/clients/channels-client.js +14 -14
- package/dist/cjs/clients/comments-client.js +7 -7
- package/dist/cjs/clients/conversation-messages-client.js +6 -6
- package/dist/cjs/clients/conversations-client.js +16 -16
- package/dist/cjs/clients/groups-client.js +10 -10
- package/dist/cjs/clients/inbox-client.js +7 -7
- package/dist/cjs/clients/reactions-client.js +4 -4
- package/dist/cjs/clients/search-client.js +4 -4
- package/dist/cjs/clients/threads-client.js +21 -21
- package/dist/cjs/clients/users-client.js +15 -15
- package/dist/cjs/clients/workspace-users-client.js +11 -11
- package/dist/cjs/clients/workspaces-client.js +8 -8
- package/dist/cjs/consts/endpoints.js +3 -2
- package/dist/cjs/testUtils/msw-setup.js +1 -1
- package/dist/cjs/{rest-client.js → transport/fetch-with-retry.js} +108 -153
- package/dist/cjs/transport/http-client.js +108 -0
- package/dist/cjs/transport/http-dispatcher.js +128 -0
- package/dist/cjs/types/api-version.js +6 -0
- package/dist/cjs/types/entities.js +4 -4
- package/dist/cjs/types/http.js +2 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/esm/authentication.js +85 -1
- package/dist/esm/batch-builder.js +1 -1
- package/dist/esm/clients/base-client.js +2 -1
- package/dist/esm/clients/channels-client.js +1 -1
- package/dist/esm/clients/comments-client.js +1 -1
- package/dist/esm/clients/conversation-messages-client.js +1 -1
- package/dist/esm/clients/conversations-client.js +1 -1
- package/dist/esm/clients/groups-client.js +1 -1
- package/dist/esm/clients/inbox-client.js +1 -1
- package/dist/esm/clients/reactions-client.js +1 -1
- package/dist/esm/clients/search-client.js +1 -1
- package/dist/esm/clients/threads-client.js +1 -1
- package/dist/esm/clients/users-client.js +1 -1
- package/dist/esm/clients/workspace-users-client.js +1 -1
- package/dist/esm/clients/workspaces-client.js +1 -1
- package/dist/esm/consts/endpoints.js +3 -2
- package/dist/esm/testUtils/msw-setup.js +1 -1
- package/dist/esm/{rest-client.js → transport/fetch-with-retry.js} +108 -150
- package/dist/esm/transport/http-client.js +103 -0
- package/dist/esm/transport/http-dispatcher.js +91 -0
- package/dist/esm/types/api-version.js +5 -1
- package/dist/esm/types/entities.js +1 -1
- package/dist/esm/types/http.js +1 -1
- package/dist/esm/types/index.js +1 -0
- package/dist/types/authentication.d.ts +5 -1
- package/dist/types/consts/endpoints.d.ts +2 -2
- package/dist/types/transport/fetch-with-retry.d.ts +4 -0
- package/dist/types/{rest-client.d.ts → transport/http-client.d.ts} +1 -4
- package/dist/types/transport/http-dispatcher.d.ts +3 -0
- package/dist/types/types/api-version.d.ts +3 -1
- package/dist/types/types/entities.d.ts +25 -0
- package/dist/types/types/http.d.ts +2 -1
- package/dist/types/types/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
23
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { snakeCaseKeys } from '../utils/case-conversion.js';
|
|
49
|
+
import { fetchWithRetry } from './fetch-with-retry.js';
|
|
50
|
+
export function paramsSerializer(params) {
|
|
51
|
+
var qs = new URLSearchParams();
|
|
52
|
+
Object.keys(params).forEach(function (key) {
|
|
53
|
+
var value = params[key];
|
|
54
|
+
if (value != null) {
|
|
55
|
+
if (Array.isArray(value)) {
|
|
56
|
+
qs.append(key, value.join(','));
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
qs.append(key, String(value));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return qs.toString();
|
|
64
|
+
}
|
|
65
|
+
var defaultHeaders = {
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
};
|
|
68
|
+
function getAuthHeader(apiToken) {
|
|
69
|
+
return "Bearer ".concat(apiToken);
|
|
70
|
+
}
|
|
71
|
+
function getRequestConfiguration(baseURL, apiToken, requestId) {
|
|
72
|
+
var authHeader = apiToken ? { Authorization: getAuthHeader(apiToken) } : undefined;
|
|
73
|
+
var requestIdHeader = requestId ? { 'X-Request-Id': requestId } : undefined;
|
|
74
|
+
var headers = __assign(__assign(__assign({}, defaultHeaders), authHeader), requestIdHeader);
|
|
75
|
+
return { baseURL: baseURL, headers: headers, timeout: 30000 };
|
|
76
|
+
}
|
|
77
|
+
export function request(args) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
79
|
+
var httpMethod, baseUri, relativePath, apiToken, payload, requestId, customFetch, config, url, options, searchParams, urlWithParams;
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
httpMethod = args.httpMethod, baseUri = args.baseUri, relativePath = args.relativePath, apiToken = args.apiToken, payload = args.payload, requestId = args.requestId, customFetch = args.customFetch;
|
|
82
|
+
config = getRequestConfiguration(baseUri, apiToken, requestId);
|
|
83
|
+
url = new URL(relativePath, config.baseURL).toString();
|
|
84
|
+
options = {
|
|
85
|
+
method: httpMethod,
|
|
86
|
+
headers: config.headers,
|
|
87
|
+
timeout: config.timeout,
|
|
88
|
+
};
|
|
89
|
+
if (httpMethod === 'GET' && payload) {
|
|
90
|
+
searchParams = paramsSerializer(snakeCaseKeys(payload));
|
|
91
|
+
urlWithParams = searchParams ? "".concat(url, "?").concat(searchParams) : url;
|
|
92
|
+
return [2 /*return*/, fetchWithRetry(urlWithParams, options, 3, customFetch)];
|
|
93
|
+
}
|
|
94
|
+
if (payload && httpMethod !== 'GET') {
|
|
95
|
+
options.body = JSON.stringify(snakeCaseKeys(payload));
|
|
96
|
+
}
|
|
97
|
+
return [2 /*return*/, fetchWithRetry(url, options, 3, customFetch)];
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
export function isSuccess(response) {
|
|
102
|
+
return response.status >= 200 && response.status < 300;
|
|
103
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
// Use effectively-disabled keep-alive so short-lived CLI processes do not stay
|
|
38
|
+
// open waiting on idle sockets. Undici requires positive values, so we use 1ms.
|
|
39
|
+
var keepAliveOptions = {
|
|
40
|
+
keepAliveTimeout: 1,
|
|
41
|
+
keepAliveMaxTimeout: 1,
|
|
42
|
+
};
|
|
43
|
+
var defaultDispatcher;
|
|
44
|
+
var defaultDispatcherPromise;
|
|
45
|
+
export function getDefaultDispatcher() {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
47
|
+
return __generator(this, function (_a) {
|
|
48
|
+
if (defaultDispatcher) {
|
|
49
|
+
return [2 /*return*/, defaultDispatcher];
|
|
50
|
+
}
|
|
51
|
+
if (!defaultDispatcherPromise) {
|
|
52
|
+
defaultDispatcherPromise = createDefaultDispatcher()
|
|
53
|
+
.then(function (dispatcher) {
|
|
54
|
+
defaultDispatcher = dispatcher;
|
|
55
|
+
return dispatcher;
|
|
56
|
+
})
|
|
57
|
+
.catch(function (error) {
|
|
58
|
+
defaultDispatcher = undefined;
|
|
59
|
+
defaultDispatcherPromise = undefined;
|
|
60
|
+
throw error;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return [2 /*return*/, defaultDispatcherPromise];
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
export function resetDefaultDispatcherForTests() {
|
|
68
|
+
defaultDispatcher = undefined;
|
|
69
|
+
defaultDispatcherPromise = undefined;
|
|
70
|
+
}
|
|
71
|
+
function isNodeEnvironment() {
|
|
72
|
+
var _a;
|
|
73
|
+
return typeof process !== 'undefined' && typeof ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node) === 'string';
|
|
74
|
+
}
|
|
75
|
+
function createDefaultDispatcher() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
77
|
+
var EnvHttpProxyAgent;
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
switch (_a.label) {
|
|
80
|
+
case 0:
|
|
81
|
+
if (!isNodeEnvironment()) {
|
|
82
|
+
return [2 /*return*/, undefined];
|
|
83
|
+
}
|
|
84
|
+
return [4 /*yield*/, import('undici')];
|
|
85
|
+
case 1:
|
|
86
|
+
EnvHttpProxyAgent = (_a.sent()).EnvHttpProxyAgent;
|
|
87
|
+
return [2 /*return*/, new EnvHttpProxyAgent(keepAliveOptions)];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
@@ -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(),
|
package/dist/esm/types/http.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var HTTP_METHODS = ['POST', 'GET', 'PUT', 'PATCH', 'DELETE'];
|
package/dist/esm/types/index.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
6
|
+
export declare const API_BASE_URI: string;
|
|
7
7
|
/**
|
|
8
8
|
* Gets the base URI for Twist API requests.
|
|
9
9
|
*
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { CustomFetch, HttpMethod, HttpResponse } from '
|
|
1
|
+
import type { CustomFetch, HttpMethod, HttpResponse } from '../types/http.js';
|
|
2
2
|
export declare function paramsSerializer(params: Record<string, unknown>): string;
|
|
3
|
-
export declare function fetchWithRetry<T>(url: string, options: RequestInit & {
|
|
4
|
-
timeout?: number;
|
|
5
|
-
}, maxRetries?: number, customFetch?: CustomFetch): Promise<HttpResponse<T>>;
|
|
6
3
|
export type RequestArgs = {
|
|
7
4
|
httpMethod: HttpMethod;
|
|
8
5
|
baseUri: string;
|
|
@@ -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
|
|
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;
|