@doist/twist-sdk 2.1.3 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/dist/cjs/authentication.js +5 -5
  2. package/dist/cjs/batch-builder.js +2 -2
  3. package/dist/cjs/clients/add-comment-helper.js +35 -0
  4. package/dist/cjs/clients/channels-client.js +14 -14
  5. package/dist/cjs/clients/comments-client.js +8 -21
  6. package/dist/cjs/clients/conversation-messages-client.js +6 -6
  7. package/dist/cjs/clients/conversations-client.js +16 -16
  8. package/dist/cjs/clients/groups-client.js +10 -10
  9. package/dist/cjs/clients/inbox-client.js +7 -7
  10. package/dist/cjs/clients/reactions-client.js +4 -4
  11. package/dist/cjs/clients/search-client.js +4 -4
  12. package/dist/cjs/clients/threads-client.js +54 -21
  13. package/dist/cjs/clients/users-client.js +15 -15
  14. package/dist/cjs/clients/workspace-users-client.js +11 -11
  15. package/dist/cjs/clients/workspaces-client.js +8 -8
  16. package/dist/cjs/testUtils/msw-setup.js +1 -1
  17. package/dist/cjs/{rest-client.js → transport/fetch-with-retry.js} +108 -153
  18. package/dist/cjs/transport/http-client.js +108 -0
  19. package/dist/cjs/transport/http-dispatcher.js +128 -0
  20. package/dist/cjs/types/requests.js +3 -1
  21. package/dist/esm/authentication.js +1 -1
  22. package/dist/esm/batch-builder.js +1 -1
  23. package/dist/esm/clients/add-comment-helper.js +32 -0
  24. package/dist/esm/clients/channels-client.js +1 -1
  25. package/dist/esm/clients/comments-client.js +3 -16
  26. package/dist/esm/clients/conversation-messages-client.js +1 -1
  27. package/dist/esm/clients/conversations-client.js +1 -1
  28. package/dist/esm/clients/groups-client.js +1 -1
  29. package/dist/esm/clients/inbox-client.js +1 -1
  30. package/dist/esm/clients/reactions-client.js +1 -1
  31. package/dist/esm/clients/search-client.js +1 -1
  32. package/dist/esm/clients/threads-client.js +35 -2
  33. package/dist/esm/clients/users-client.js +1 -1
  34. package/dist/esm/clients/workspace-users-client.js +1 -1
  35. package/dist/esm/clients/workspaces-client.js +1 -1
  36. package/dist/esm/testUtils/msw-setup.js +1 -1
  37. package/dist/esm/{rest-client.js → transport/fetch-with-retry.js} +108 -150
  38. package/dist/esm/transport/http-client.js +103 -0
  39. package/dist/esm/transport/http-dispatcher.js +91 -0
  40. package/dist/esm/types/requests.js +2 -0
  41. package/dist/types/clients/add-comment-helper.d.ts +14 -0
  42. package/dist/types/clients/threads-client.d.ts +57 -2
  43. package/dist/types/transport/fetch-with-retry.d.ts +4 -0
  44. package/dist/types/{rest-client.d.ts → transport/http-client.d.ts} +1 -4
  45. package/dist/types/transport/http-dispatcher.d.ts +3 -0
  46. package/dist/types/types/requests.d.ts +18 -0
  47. package/package.json +1 -1
@@ -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
+ }
@@ -88,3 +88,5 @@ export var GetOrCreateConversationArgsSchema = z.object({
88
88
  userIds: z.array(z.number()),
89
89
  });
90
90
  export var AWAY_MODE_TYPES = ['parental', 'vacation', 'sickleave', 'other'];
91
+ // Threads
92
+ export var THREAD_ACTIONS = ['close', 'reopen'];
@@ -0,0 +1,14 @@
1
+ import type { BatchRequestDescriptor } from '../types/batch.js';
2
+ import { type Comment } from '../types/entities.js';
3
+ import type { CustomFetch } from '../types/http.js';
4
+ import type { ThreadAction } from '../types/requests.js';
5
+ type ClientContext = {
6
+ baseUri: string;
7
+ apiToken: string;
8
+ customFetch?: CustomFetch;
9
+ };
10
+ export declare function addCommentRequest(context: ClientContext, params: Record<string, unknown>, options?: {
11
+ batch?: boolean;
12
+ threadAction?: ThreadAction;
13
+ }): Promise<Comment> | BatchRequestDescriptor<Comment>;
14
+ export {};
@@ -1,6 +1,6 @@
1
1
  import type { BatchRequestDescriptor } from '../types/batch.js';
2
- import { type Thread, type UnreadThread } from '../types/entities.js';
3
- import { type CreateThreadArgs, type GetThreadsArgs, type MarkThreadReadArgs, type MarkThreadUnreadArgs, type MarkThreadUnreadForOthersArgs, type MoveThreadToChannelArgs, type MuteThreadArgs, type UpdateThreadArgs } from '../types/requests.js';
2
+ import { type Comment, type Thread, type UnreadThread } from '../types/entities.js';
3
+ import { type CloseThreadArgs, type CreateThreadArgs, type GetThreadsArgs, type MarkThreadReadArgs, type MarkThreadUnreadArgs, type MarkThreadUnreadForOthersArgs, type MoveThreadToChannelArgs, type MuteThreadArgs, type ReopenThreadArgs, type UpdateThreadArgs } from '../types/requests.js';
4
4
  import { BaseClient } from './base-client.js';
5
5
  /**
6
6
  * Client for interacting with Twist thread endpoints.
@@ -319,4 +319,59 @@ export declare class ThreadsClient extends BaseClient {
319
319
  unmuteThread(id: number, options?: {
320
320
  batch?: false;
321
321
  }): Promise<Thread>;
322
+ /**
323
+ * Closes a thread by adding a comment with a close action.
324
+ *
325
+ * @param args - The arguments for closing a thread.
326
+ * @param args.id - The thread ID.
327
+ * @param args.content - The comment content.
328
+ * @param args.tempId - Optional temporary identifier.
329
+ * @param args.attachments - Optional array of attachment objects.
330
+ * @param args.actions - Optional array of action objects.
331
+ * @param args.recipients - Optional array of user IDs to notify.
332
+ * @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
333
+ * @returns The created comment object.
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * const comment = await api.threads.closeThread({
338
+ * id: 789,
339
+ * content: 'Closing this thread — resolved.'
340
+ * })
341
+ * ```
342
+ */
343
+ closeThread(args: CloseThreadArgs, options: {
344
+ batch: true;
345
+ }): BatchRequestDescriptor<Comment>;
346
+ closeThread(args: CloseThreadArgs, options?: {
347
+ batch?: false;
348
+ }): Promise<Comment>;
349
+ /**
350
+ * Reopens a thread by adding a comment with a reopen action.
351
+ *
352
+ * @param args - The arguments for reopening a thread.
353
+ * @param args.id - The thread ID.
354
+ * @param args.content - The comment content.
355
+ * @param args.tempId - Optional temporary identifier.
356
+ * @param args.attachments - Optional array of attachment objects.
357
+ * @param args.actions - Optional array of action objects.
358
+ * @param args.recipients - Optional array of user IDs to notify.
359
+ * @param options - Optional configuration. Set `batch: true` to return a descriptor for batch requests.
360
+ * @returns The created comment object.
361
+ *
362
+ * @example
363
+ * ```typescript
364
+ * const comment = await api.threads.reopenThread({
365
+ * id: 789,
366
+ * content: 'Reopening — need further discussion.'
367
+ * })
368
+ * ```
369
+ */
370
+ reopenThread(args: ReopenThreadArgs, options: {
371
+ batch: true;
372
+ }): BatchRequestDescriptor<Comment>;
373
+ reopenThread(args: ReopenThreadArgs, options?: {
374
+ batch?: false;
375
+ }): Promise<Comment>;
376
+ private addCommentWithAction;
322
377
  }
@@ -0,0 +1,4 @@
1
+ import type { CustomFetch, HttpResponse } from '../types/http.js';
2
+ export declare function fetchWithRetry<T>(url: string, options: RequestInit & {
3
+ timeout?: number;
4
+ }, maxRetries?: number, customFetch?: CustomFetch): Promise<HttpResponse<T>>;
@@ -1,8 +1,5 @@
1
- import { CustomFetch, HttpMethod, HttpResponse } from './types/http.js';
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;
@@ -0,0 +1,3 @@
1
+ import type { Dispatcher } from 'undici';
2
+ export declare function getDefaultDispatcher(): Promise<Dispatcher | undefined>;
3
+ export declare function resetDefaultDispatcherForTests(): void;
@@ -202,6 +202,24 @@ export type RemoveChannelUsersArgs = {
202
202
  id: number;
203
203
  userIds: number[];
204
204
  };
205
+ export declare const THREAD_ACTIONS: readonly ["close", "reopen"];
206
+ export type ThreadAction = (typeof THREAD_ACTIONS)[number];
207
+ export type CloseThreadArgs = {
208
+ id: number;
209
+ content: string;
210
+ tempId?: number | null;
211
+ attachments?: unknown | null;
212
+ actions?: unknown | null;
213
+ recipients?: number[] | null;
214
+ };
215
+ export type ReopenThreadArgs = {
216
+ id: number;
217
+ content: string;
218
+ tempId?: number | null;
219
+ attachments?: unknown | null;
220
+ actions?: unknown | null;
221
+ recipients?: number[] | null;
222
+ };
205
223
  export type MoveThreadToChannelArgs = {
206
224
  id: number;
207
225
  toChannel: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/twist-sdk",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
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/",