@doist/twist-sdk 2.4.1 → 2.5.1

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.
@@ -41,9 +41,10 @@ var SearchClient = /** @class */ (function (_super) {
41
41
  }
42
42
  SearchClient.prototype.search = function (args, options) {
43
43
  var params = {
44
- query: args.query,
45
44
  workspace_id: args.workspaceId,
46
45
  };
46
+ if (args.query !== undefined)
47
+ params.query = args.query;
47
48
  if (args.channelIds)
48
49
  params.channel_ids = args.channelIds;
49
50
  if (args.authorIds)
@@ -68,9 +68,19 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
68
68
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
69
  }
70
70
  };
71
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
73
+ if (ar || !(i in from)) {
74
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
75
+ ar[i] = from[i];
76
+ }
77
+ }
78
+ return to.concat(ar || Array.prototype.slice.call(from));
79
+ };
71
80
  Object.defineProperty(exports, "__esModule", { value: true });
72
81
  exports.getDefaultDispatcher = getDefaultDispatcher;
73
82
  exports.resetDefaultDispatcherForTests = resetDefaultDispatcherForTests;
83
+ exports.suppressExperimentalWarningsSync = suppressExperimentalWarningsSync;
74
84
  // Use effectively-disabled keep-alive so short-lived CLI processes do not stay
75
85
  // open waiting on idle sockets. Undici requires positive values, so we use 1ms.
76
86
  var keepAliveOptions = {
@@ -111,18 +121,61 @@ function isNodeEnvironment() {
111
121
  }
112
122
  function createDefaultDispatcher() {
113
123
  return __awaiter(this, void 0, void 0, function () {
114
- var EnvHttpProxyAgent;
115
- return __generator(this, function (_a) {
116
- switch (_a.label) {
124
+ var _a, EnvHttpProxyAgent, interceptors, decompress;
125
+ return __generator(this, function (_b) {
126
+ switch (_b.label) {
117
127
  case 0:
118
128
  if (!isNodeEnvironment()) {
119
129
  return [2 /*return*/, undefined];
120
130
  }
121
131
  return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require('undici')); })];
122
132
  case 1:
123
- EnvHttpProxyAgent = (_a.sent()).EnvHttpProxyAgent;
124
- return [2 /*return*/, new EnvHttpProxyAgent(keepAliveOptions)];
133
+ _a = _b.sent(), EnvHttpProxyAgent = _a.EnvHttpProxyAgent, interceptors = _a.interceptors;
134
+ decompress = suppressExperimentalWarningsSync(function () { return interceptors.decompress(); });
135
+ return [2 /*return*/, new EnvHttpProxyAgent(keepAliveOptions).compose(decompress)];
125
136
  }
126
137
  });
127
138
  });
128
139
  }
140
+ // undici emits an `ExperimentalWarning` the first time `interceptors.decompress()`
141
+ // runs. The interceptor is stable for our gzipped-JSON-over-HTTPS use case;
142
+ // silence the warning during dispatcher init only so it does not leak to every
143
+ // consumer's stderr on the first request.
144
+ //
145
+ // `fn` must be synchronous so the override covers a single critical section
146
+ // (microseconds) — no unrelated `ExperimentalWarning` from elsewhere can
147
+ // interleave and be lost. We suppress every `ExperimentalWarning` rather than
148
+ // pattern-matching the message text: the message wording is an undici
149
+ // implementation detail (not a stable API), and the suppression window is
150
+ // narrow enough that a coarse type filter is safe.
151
+ //
152
+ // Exported for direct unit testing — the integration path through
153
+ // `getDefaultDispatcher()` cannot reliably exercise the helper because both
154
+ // the dispatcher singleton and undici's internal `warningEmitted` flag are
155
+ // once-per-process.
156
+ function suppressExperimentalWarningsSync(fn) {
157
+ var originalEmit = process.emitWarning;
158
+ process.emitWarning = (function (warning, typeOrOptions) {
159
+ var _a;
160
+ var rest = [];
161
+ for (var _i = 2; _i < arguments.length; _i++) {
162
+ rest[_i - 2] = arguments[_i];
163
+ }
164
+ var type = typeof typeOrOptions === 'string'
165
+ ? typeOrOptions
166
+ : typeof typeOrOptions === 'object' && typeOrOptions !== null
167
+ ? typeOrOptions.type
168
+ : undefined;
169
+ if (type === 'ExperimentalWarning')
170
+ return;
171
+ (_a = originalEmit).call.apply(_a, __spreadArray([process,
172
+ warning,
173
+ typeOrOptions], rest, false));
174
+ });
175
+ try {
176
+ return fn();
177
+ }
178
+ finally {
179
+ process.emitWarning = originalEmit;
180
+ }
181
+ }
@@ -38,9 +38,10 @@ var SearchClient = /** @class */ (function (_super) {
38
38
  }
39
39
  SearchClient.prototype.search = function (args, options) {
40
40
  var params = {
41
- query: args.query,
42
41
  workspace_id: args.workspaceId,
43
42
  };
43
+ if (args.query !== undefined)
44
+ params.query = args.query;
44
45
  if (args.channelIds)
45
46
  params.channel_ids = args.channelIds;
46
47
  if (args.authorIds)
@@ -34,6 +34,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
34
34
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
35
  }
36
36
  };
37
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39
+ if (ar || !(i in from)) {
40
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41
+ ar[i] = from[i];
42
+ }
43
+ }
44
+ return to.concat(ar || Array.prototype.slice.call(from));
45
+ };
37
46
  // Use effectively-disabled keep-alive so short-lived CLI processes do not stay
38
47
  // open waiting on idle sockets. Undici requires positive values, so we use 1ms.
39
48
  var keepAliveOptions = {
@@ -74,18 +83,68 @@ function isNodeEnvironment() {
74
83
  }
75
84
  function createDefaultDispatcher() {
76
85
  return __awaiter(this, void 0, void 0, function () {
77
- var EnvHttpProxyAgent;
78
- return __generator(this, function (_a) {
79
- switch (_a.label) {
86
+ var _a, EnvHttpProxyAgent, interceptors, decompress;
87
+ return __generator(this, function (_b) {
88
+ switch (_b.label) {
80
89
  case 0:
81
90
  if (!isNodeEnvironment()) {
82
91
  return [2 /*return*/, undefined];
83
92
  }
84
- return [4 /*yield*/, import('undici')];
93
+ return [4 /*yield*/, import('undici')
94
+ // Compose the response-decompression interceptor so gzip/deflate/br/zstd
95
+ // bodies are decoded before consumers parse them. Required on Node 24+:
96
+ // attaching any custom dispatcher to the global `fetch` strips the
97
+ // `content-encoding` header but does not actually decompress the body,
98
+ // so callers receive raw gzipped bytes and `JSON.parse` fails.
99
+ // See https://github.com/Doist/todoist-cli/issues/318.
100
+ ];
85
101
  case 1:
86
- EnvHttpProxyAgent = (_a.sent()).EnvHttpProxyAgent;
87
- return [2 /*return*/, new EnvHttpProxyAgent(keepAliveOptions)];
102
+ _a = _b.sent(), EnvHttpProxyAgent = _a.EnvHttpProxyAgent, interceptors = _a.interceptors;
103
+ decompress = suppressExperimentalWarningsSync(function () { return interceptors.decompress(); });
104
+ return [2 /*return*/, new EnvHttpProxyAgent(keepAliveOptions).compose(decompress)];
88
105
  }
89
106
  });
90
107
  });
91
108
  }
109
+ // undici emits an `ExperimentalWarning` the first time `interceptors.decompress()`
110
+ // runs. The interceptor is stable for our gzipped-JSON-over-HTTPS use case;
111
+ // silence the warning during dispatcher init only so it does not leak to every
112
+ // consumer's stderr on the first request.
113
+ //
114
+ // `fn` must be synchronous so the override covers a single critical section
115
+ // (microseconds) — no unrelated `ExperimentalWarning` from elsewhere can
116
+ // interleave and be lost. We suppress every `ExperimentalWarning` rather than
117
+ // pattern-matching the message text: the message wording is an undici
118
+ // implementation detail (not a stable API), and the suppression window is
119
+ // narrow enough that a coarse type filter is safe.
120
+ //
121
+ // Exported for direct unit testing — the integration path through
122
+ // `getDefaultDispatcher()` cannot reliably exercise the helper because both
123
+ // the dispatcher singleton and undici's internal `warningEmitted` flag are
124
+ // once-per-process.
125
+ export function suppressExperimentalWarningsSync(fn) {
126
+ var originalEmit = process.emitWarning;
127
+ process.emitWarning = (function (warning, typeOrOptions) {
128
+ var _a;
129
+ var rest = [];
130
+ for (var _i = 2; _i < arguments.length; _i++) {
131
+ rest[_i - 2] = arguments[_i];
132
+ }
133
+ var type = typeof typeOrOptions === 'string'
134
+ ? typeOrOptions
135
+ : typeof typeOrOptions === 'object' && typeOrOptions !== null
136
+ ? typeOrOptions.type
137
+ : undefined;
138
+ if (type === 'ExperimentalWarning')
139
+ return;
140
+ (_a = originalEmit).call.apply(_a, __spreadArray([process,
141
+ warning,
142
+ typeOrOptions], rest, false));
143
+ });
144
+ try {
145
+ return fn();
146
+ }
147
+ finally {
148
+ process.emitWarning = originalEmit;
149
+ }
150
+ }
@@ -10,11 +10,11 @@ export declare class SearchClient extends BaseClient {
10
10
  * Searches across all threads and conversations in a workspace.
11
11
  *
12
12
  * @param args - The arguments for searching.
13
- * @param args.query - The search query string.
13
+ * @param args.query - The search query string. Optional when `mentionSelf: true` is set; required otherwise.
14
14
  * @param args.workspaceId - The workspace ID to search in.
15
15
  * @param args.channelIds - Optional array of channel IDs to filter by.
16
16
  * @param args.authorIds - Optional array of author user IDs to filter by.
17
- * @param args.mentionSelf - Optional flag to filter by mentions of the current user.
17
+ * @param args.mentionSelf - Optional flag to filter by mentions of the current user. When true, `query` may be omitted.
18
18
  * @param args.dateFrom - Optional start date for filtering (YYYY-MM-DD).
19
19
  * @param args.dateTo - Optional end date for filtering (YYYY-MM-DD).
20
20
  * @param args.limit - Optional limit on number of results returned.
@@ -1,3 +1,4 @@
1
1
  import type { Dispatcher } from 'undici';
2
2
  export declare function getDefaultDispatcher(): Promise<Dispatcher | undefined>;
3
3
  export declare function resetDefaultDispatcherForTests(): void;
4
+ export declare function suppressExperimentalWarningsSync<T>(fn: () => T): T;
@@ -130,17 +130,22 @@ export type UpdateUserArgs = {
130
130
  awayMode?: AwayMode;
131
131
  offDays?: number[];
132
132
  };
133
- export type SearchArgs = {
134
- query: string;
133
+ type SearchArgsCommon = {
135
134
  workspaceId: number;
136
135
  channelIds?: number[];
137
136
  authorIds?: number[];
138
- mentionSelf?: boolean;
139
137
  dateFrom?: string;
140
138
  dateTo?: string;
141
139
  limit?: number;
142
140
  cursor?: string;
143
141
  };
142
+ export type SearchArgs = (SearchArgsCommon & {
143
+ query: string;
144
+ mentionSelf?: boolean;
145
+ }) | (SearchArgsCommon & {
146
+ query?: string;
147
+ mentionSelf: true;
148
+ });
144
149
  export type SearchThreadArgs = {
145
150
  query: string;
146
151
  threadId: number;
@@ -330,3 +335,4 @@ export type GetUserLocalTimeArgs = {
330
335
  workspaceId: number;
331
336
  userId: number;
332
337
  };
338
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/twist-sdk",
3
- "version": "2.4.1",
3
+ "version": "2.5.1",
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/",