@intuned/runtime-dev 1.2.0-cli.2 → 1.2.0-cli.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.
@@ -22,7 +22,7 @@ export declare function parseUrlProxy(proxyUrl: string): {
22
22
  username: string;
23
23
  server: string;
24
24
  } | undefined;
25
- export declare function withTimeout<R, P extends any[]>(fn: (...args: P) => Promise<R>, timeout: number): (...args: P) => Promise<R>;
26
- export declare function withCLIContext<R, P extends any[]>(fn: (...args: P) => Promise<R>): (...args: P) => Promise<R>;
25
+ export declare function withTimeout<R>(fn: (abortSignal: AbortSignal) => Promise<R>, timeout: number): Promise<Awaited<R>>;
26
+ export declare function withCLIContext<R>(fn: () => Promise<R>): Promise<R>;
27
27
  export declare function assertApiFileExists(dirname: typeof AUTH_SESSIONS_FOLDER_NAME, api: "create" | "check"): Promise<void>;
28
28
  export declare function assertApiFileExists(dirname: typeof API_FOLDER_NAME, api: string): Promise<void>;
@@ -58,11 +58,11 @@ async function assertAuthConsistent(authSession) {
58
58
  }
59
59
  function logAutomationError(error) {
60
60
  (0, _terminal.terminal)(`^r^+An error occurred while running the API:^:\n`);
61
- (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
62
61
  if (error.error.stack) {
63
- (0, _terminal.terminal)(`^r^+Stack trace:^:\n`);
64
62
  const stackLines = error.error.stack.split("\n").filter(line => !line.includes("@intuned/runtime"));
65
63
  (0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
64
+ } else {
65
+ (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
66
66
  }
67
67
  }
68
68
  function withErrorLogging(fn) {
@@ -105,28 +105,27 @@ function parseUrlProxy(proxyUrl) {
105
105
  }
106
106
  function withTimeout(fn, timeout) {
107
107
  let reject;
108
+ const abortController = new AbortController();
108
109
  const timeoutPromise = new Promise((_, _reject) => {
109
110
  reject = _reject;
110
111
  });
111
112
  const timeoutId = setTimeout(() => {
112
- reject(new CLIError("Timed out"));
113
+ abortController.abort();
114
+ reject(new _runApi.AutomationError(new Error("Timed out")));
113
115
  }, timeout);
114
- const fnWithWrapper = async (...args) => {
115
- return Promise.race([fn(...args), timeoutPromise]);
116
- };
117
116
  (0, _asyncLocalStorage.getExecutionContext)().timeoutInfo.extendTimeoutCallback = async () => {
118
117
  timeoutId.refresh();
119
118
  };
120
- return fnWithWrapper;
119
+ return Promise.race([fn(abortController.signal), timeoutPromise]);
121
120
  }
122
- function withCLIContext(fn) {
121
+ async function withCLIContext(fn) {
123
122
  const runId = (0, _nanoid.nanoid)();
124
- return async (...args) => (0, _asyncLocalStorage.runWithContext)({
123
+ return await (0, _asyncLocalStorage.runWithContext)({
125
124
  runEnvironment: _enums.RunEnvironment.IDE,
126
125
  runId,
127
126
  extendedPayloads: [],
128
127
  timeoutInfo: {}
129
- }, fn, ...args);
128
+ }, fn);
130
129
  }
131
130
  async function assertApiFileExists(dirname, api) {
132
131
  const file = `${dirname}/${api}.ts`;
@@ -58,7 +58,7 @@ async function executeRunApiCLI({
58
58
  throw error;
59
59
  }
60
60
  }
61
- })();
61
+ });
62
62
  if (apiResult === undefined) {
63
63
  throw new _helpers.CLIError(`^r^+Failed to run API ^:^+${apiName}^:: ^RExceeded maximum retries of ^+${retries}^:\n`, {
64
64
  autoColor: false
@@ -101,7 +101,7 @@ async function executeAttemptApiCLI({
101
101
  apiResult,
102
102
  outputFile
103
103
  });
104
- })();
104
+ });
105
105
  }
106
106
  async function handleApiResult({
107
107
  apiResult,
@@ -151,7 +151,7 @@ async function attemptApi({
151
151
  headless,
152
152
  timeout
153
153
  }) {
154
- return await (0, _helpers.withTimeout)(async () => {
154
+ return await (0, _helpers.withTimeout)(async abortSignal => {
155
155
  const runApiResult = await (0, _runApi.runApi)({
156
156
  automationFunction: {
157
157
  name: `api/${apiName}`,
@@ -163,13 +163,14 @@ async function attemptApi({
163
163
  proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
164
164
  },
165
165
  auth,
166
- importFunction: _tsNodeImport.tsNodeImport
166
+ importFunction: _tsNodeImport.tsNodeImport,
167
+ abortSignal
167
168
  });
168
169
  if (runApiResult.isErr()) {
169
170
  if (runApiResult.error instanceof _runApi.AutomationError) {
170
171
  throw runApiResult.error;
171
172
  }
172
- throw new _helpers.CLIError(`An error occurred while running the API: ${runApiResult.error.message}`);
173
+ throw runApiResult.error;
173
174
  }
174
175
  const {
175
176
  result,
@@ -179,5 +180,5 @@ async function attemptApi({
179
180
  result,
180
181
  payloadToAppend
181
182
  };
182
- }, timeout)();
183
+ }, timeout);
183
184
  }
@@ -71,7 +71,7 @@ async function executeRunValidateAuthSessionCLI({
71
71
  if (useExistingContext) {
72
72
  return await validate();
73
73
  } else {
74
- return await (0, _helpers.withCLIContext)(validate)();
74
+ return await (0, _helpers.withCLIContext)(validate);
75
75
  }
76
76
  }
77
77
  async function executeRunCreateAuthSessionCLI({
@@ -104,7 +104,7 @@ async function executeRunCreateAuthSessionCLI({
104
104
  (0, _terminal.terminal)(`^+^gAuth session created successfully^:\n`);
105
105
  }
106
106
  return authSessionPath;
107
- })();
107
+ });
108
108
  }
109
109
  async function executeRunUpdateAuthSessionCLI({
110
110
  id,
@@ -135,7 +135,7 @@ async function executeRunUpdateAuthSessionCLI({
135
135
  });
136
136
  (0, _terminal.terminal)(`^+^gAuth session updated successfully^:\n`);
137
137
  return authSession;
138
- })();
138
+ });
139
139
  }
140
140
  async function executeAttemptCreateAuthSessionCLI({
141
141
  id,
@@ -158,20 +158,22 @@ async function executeAttemptCheckAuthSessionCLI({
158
158
  }) {
159
159
  (0, _terminal.terminal)(`^+Executing check auth session attempt with id ^c${id}^:\n`);
160
160
  await (0, _helpers.assertApiFileExists)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
161
- const {
162
- authSessionInstanceStoragePath
163
- } = await (0, _utils.retrieveAuthSessionInstance)(id, true);
164
- const authSessionPathToUse = authSessionInstanceStoragePath;
165
- const checkResult = await runCheckWithRetries({
166
- authSessionPath: authSessionPathToUse,
167
- retries: 1,
168
- ...rest
161
+ return await (0, _helpers.withCLIContext)(async () => {
162
+ const {
163
+ authSessionInstanceStoragePath
164
+ } = await (0, _utils.retrieveAuthSessionInstance)(id, true);
165
+ const authSessionPathToUse = authSessionInstanceStoragePath;
166
+ const checkResult = await runCheckWithRetries({
167
+ authSessionPath: authSessionPathToUse,
168
+ retries: 1,
169
+ ...rest
170
+ });
171
+ if (!checkResult) {
172
+ throw new _helpers.CLIError("Check failed");
173
+ }
174
+ (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
175
+ return authSessionPathToUse;
169
176
  });
170
- if (!checkResult) {
171
- throw new Error("Check failed");
172
- }
173
- (0, _terminal.terminal)(`^+^gAuth session check passed^:\n`);
174
- return authSessionPathToUse;
175
177
  }
176
178
  async function runCheck({
177
179
  authSessionPath,
@@ -179,7 +181,7 @@ async function runCheck({
179
181
  headless,
180
182
  timeout
181
183
  }) {
182
- return await (0, _helpers.withTimeout)(async () => {
184
+ return await (0, _helpers.withTimeout)(async abortSignal => {
183
185
  const runApiResult = await (0, _runApi.runApi)({
184
186
  automationFunction: {
185
187
  name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
@@ -196,7 +198,8 @@ async function runCheck({
196
198
  },
197
199
  runCheck: false
198
200
  },
199
- importFunction: _tsNodeImport.tsNodeImport
201
+ importFunction: _tsNodeImport.tsNodeImport,
202
+ abortSignal
200
203
  });
201
204
  if (runApiResult.isErr()) {
202
205
  if (runApiResult.error instanceof _runApi.AutomationError) {
@@ -209,7 +212,7 @@ async function runCheck({
209
212
  return false;
210
213
  }
211
214
  return result;
212
- }, timeout)();
215
+ }, timeout);
213
216
  }
214
217
  async function runCreate({
215
218
  authSessionInput,
@@ -217,7 +220,7 @@ async function runCreate({
217
220
  headless,
218
221
  timeout
219
222
  }) {
220
- return await (0, _helpers.withTimeout)(async () => {
223
+ return await (0, _helpers.withTimeout)(async abortSignal => {
221
224
  const createApiName = `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`;
222
225
  const result = await (0, _runApi.runApi)({
223
226
  automationFunction: {
@@ -230,7 +233,8 @@ async function runCreate({
230
233
  proxy: proxy ? (0, _helpers.parseUrlProxy)(proxy) : undefined
231
234
  },
232
235
  retrieveSession: true,
233
- importFunction: _tsNodeImport.tsNodeImport
236
+ importFunction: _tsNodeImport.tsNodeImport,
237
+ abortSignal
234
238
  });
235
239
  if (result.isErr()) {
236
240
  if (result.error instanceof _runApi.AutomationError) {
@@ -240,7 +244,7 @@ async function runCreate({
240
244
  throw new Error("Error while running create");
241
245
  }
242
246
  return result.value.session;
243
- }, timeout)();
247
+ }, timeout);
244
248
  }
245
249
  async function runCheckWithRetries({
246
250
  authSessionPath,
@@ -259,8 +263,11 @@ async function runCheckWithRetries({
259
263
  return true;
260
264
  }
261
265
  } catch (error) {
262
- (0, _terminal.terminal)(`^+^yAuth session check failed with error ^:${error.message}^:\n`);
263
- continue;
266
+ if (error instanceof _runApi.AutomationError) {
267
+ (0, _helpers.logAutomationError)(error);
268
+ continue;
269
+ }
270
+ throw error;
264
271
  }
265
272
  (0, _terminal.terminal)(`^+^yAuth session check failed^:\n`);
266
273
  }
@@ -284,8 +291,11 @@ async function runCreateWithRetries({
284
291
  (0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
285
292
  break;
286
293
  } catch (error) {
287
- (0, _terminal.terminal)(`^+^yAuth session create failed with error ^:${error.message}^:\n`);
288
- continue;
294
+ if (error instanceof _runApi.AutomationError) {
295
+ (0, _helpers.logAutomationError)(error);
296
+ continue;
297
+ }
298
+ throw error;
289
299
  }
290
300
  }
291
301
  if (!newAuthSessionInstance) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.2.0-cli.2",
3
+ "version": "1.2.0-cli.4",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",