@intuned/runtime-dev 1.2.0-cli.2 → 1.2.0-cli.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.
@@ -7,6 +7,9 @@ export declare class CLIError extends Error {
7
7
  autoColor?: boolean;
8
8
  });
9
9
  }
10
+ export declare class AutomationTimeoutError extends AutomationError {
11
+ constructor(message: string);
12
+ }
10
13
  export declare class CLIAssertionError extends CLIError {
11
14
  constructor(message: string, options?: {
12
15
  autoColor?: boolean;
@@ -22,7 +25,7 @@ export declare function parseUrlProxy(proxyUrl: string): {
22
25
  username: string;
23
26
  server: string;
24
27
  } | 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>;
28
+ export declare function withTimeout<R>(fn: () => Promise<R>, timeout: number): Promise<Awaited<R>>;
29
+ export declare function withCLIContext<R>(fn: () => Promise<R>): Promise<R>;
27
30
  export declare function assertApiFileExists(dirname: typeof AUTH_SESSIONS_FOLDER_NAME, api: "create" | "check"): Promise<void>;
28
31
  export declare function assertApiFileExists(dirname: typeof API_FOLDER_NAME, api: string): Promise<void>;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.CLIError = exports.CLIAssertionError = void 0;
6
+ exports.CLIError = exports.CLIAssertionError = exports.AutomationTimeoutError = void 0;
7
7
  exports.assertApiFileExists = assertApiFileExists;
8
8
  exports.assertAuthConsistent = assertAuthConsistent;
9
9
  exports.assertAuthEnabled = assertAuthEnabled;
@@ -30,6 +30,12 @@ class CLIError extends Error {
30
30
  }
31
31
  }
32
32
  exports.CLIError = CLIError;
33
+ class AutomationTimeoutError extends _runApi.AutomationError {
34
+ constructor(message) {
35
+ super(message);
36
+ }
37
+ }
38
+ exports.AutomationTimeoutError = AutomationTimeoutError;
33
39
  class CLIAssertionError extends CLIError {
34
40
  constructor(message, options) {
35
41
  super(message, options);
@@ -58,11 +64,11 @@ async function assertAuthConsistent(authSession) {
58
64
  }
59
65
  function logAutomationError(error) {
60
66
  (0, _terminal.terminal)(`^r^+An error occurred while running the API:^:\n`);
61
- (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
62
67
  if (error.error.stack) {
63
- (0, _terminal.terminal)(`^r^+Stack trace:^:\n`);
64
68
  const stackLines = error.error.stack.split("\n").filter(line => !line.includes("@intuned/runtime"));
65
69
  (0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
70
+ } else {
71
+ (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
66
72
  }
67
73
  }
68
74
  function withErrorLogging(fn) {
@@ -109,24 +115,21 @@ function withTimeout(fn, timeout) {
109
115
  reject = _reject;
110
116
  });
111
117
  const timeoutId = setTimeout(() => {
112
- reject(new CLIError("Timed out"));
118
+ reject(new AutomationTimeoutError("Timed out"));
113
119
  }, timeout);
114
- const fnWithWrapper = async (...args) => {
115
- return Promise.race([fn(...args), timeoutPromise]);
116
- };
117
120
  (0, _asyncLocalStorage.getExecutionContext)().timeoutInfo.extendTimeoutCallback = async () => {
118
121
  timeoutId.refresh();
119
122
  };
120
- return fnWithWrapper;
123
+ return Promise.race([fn(), timeoutPromise]);
121
124
  }
122
- function withCLIContext(fn) {
125
+ async function withCLIContext(fn) {
123
126
  const runId = (0, _nanoid.nanoid)();
124
- return async (...args) => (0, _asyncLocalStorage.runWithContext)({
127
+ return await (0, _asyncLocalStorage.runWithContext)({
125
128
  runEnvironment: _enums.RunEnvironment.IDE,
126
129
  runId,
127
130
  extendedPayloads: [],
128
131
  timeoutInfo: {}
129
- }, fn, ...args);
132
+ }, fn);
130
133
  }
131
134
  async function assertApiFileExists(dirname, api) {
132
135
  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,
@@ -169,7 +169,7 @@ async function attemptApi({
169
169
  if (runApiResult.error instanceof _runApi.AutomationError) {
170
170
  throw runApiResult.error;
171
171
  }
172
- throw new _helpers.CLIError(`An error occurred while running the API: ${runApiResult.error.message}`);
172
+ throw runApiResult.error;
173
173
  }
174
174
  const {
175
175
  result,
@@ -179,5 +179,5 @@ async function attemptApi({
179
179
  result,
180
180
  payloadToAppend
181
181
  };
182
- }, timeout)();
182
+ }, timeout);
183
183
  }
@@ -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,
@@ -209,7 +211,7 @@ async function runCheck({
209
211
  return false;
210
212
  }
211
213
  return result;
212
- }, timeout)();
214
+ }, timeout);
213
215
  }
214
216
  async function runCreate({
215
217
  authSessionInput,
@@ -240,7 +242,7 @@ async function runCreate({
240
242
  throw new Error("Error while running create");
241
243
  }
242
244
  return result.value.session;
243
- }, timeout)();
245
+ }, timeout);
244
246
  }
245
247
  async function runCheckWithRetries({
246
248
  authSessionPath,
@@ -259,8 +261,11 @@ async function runCheckWithRetries({
259
261
  return true;
260
262
  }
261
263
  } catch (error) {
262
- (0, _terminal.terminal)(`^+^yAuth session check failed with error ^:${error.message}^:\n`);
263
- continue;
264
+ if (error instanceof _runApi.AutomationError) {
265
+ (0, _helpers.logAutomationError)(error);
266
+ continue;
267
+ }
268
+ throw error;
264
269
  }
265
270
  (0, _terminal.terminal)(`^+^yAuth session check failed^:\n`);
266
271
  }
@@ -284,8 +289,11 @@ async function runCreateWithRetries({
284
289
  (0, _terminal.terminal)(`^+^gAuth session create succeeded^:\n`);
285
290
  break;
286
291
  } catch (error) {
287
- (0, _terminal.terminal)(`^+^yAuth session create failed with error ^:${error.message}^:\n`);
288
- continue;
292
+ if (error instanceof _runApi.AutomationError) {
293
+ (0, _helpers.logAutomationError)(error);
294
+ continue;
295
+ }
296
+ throw error;
289
297
  }
290
298
  }
291
299
  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.3",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",