@intuned/runtime-dev 1.2.0-cli.1 → 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.
@@ -1,11 +1,15 @@
1
1
  import { z } from "zod";
2
2
  import { API_FOLDER_NAME, AUTH_SESSIONS_FOLDER_NAME } from "../../../common/constants";
3
+ import { AutomationError } from "../../../common/runApi";
3
4
  export declare class CLIError extends Error {
4
5
  autoColor: boolean;
5
6
  constructor(message: string, options?: {
6
7
  autoColor?: boolean;
7
8
  });
8
9
  }
10
+ export declare class AutomationTimeoutError extends AutomationError {
11
+ constructor(message: string);
12
+ }
9
13
  export declare class CLIAssertionError extends CLIError {
10
14
  constructor(message: string, options?: {
11
15
  autoColor?: boolean;
@@ -14,13 +18,14 @@ export declare class CLIAssertionError extends CLIError {
14
18
  export declare function logInvalidInput(result: z.SafeParseError<unknown>): void;
15
19
  export declare function assertAuthEnabled(): Promise<void>;
16
20
  export declare function assertAuthConsistent(authSession: string | undefined): Promise<void>;
21
+ export declare function logAutomationError(error: AutomationError): void;
17
22
  export declare function withErrorLogging<T extends any[]>(fn: (...args: T) => Promise<unknown>): (...args: T) => Promise<never>;
18
23
  export declare function parseUrlProxy(proxyUrl: string): {
19
24
  password: string;
20
25
  username: string;
21
26
  server: string;
22
27
  } | undefined;
23
- export declare function withTimeout<R, P extends any[]>(fn: (...args: P) => Promise<R>, timeout: number): (...args: P) => Promise<R>;
24
- 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>;
25
30
  export declare function assertApiFileExists(dirname: typeof AUTH_SESSIONS_FOLDER_NAME, api: "create" | "check"): Promise<void>;
26
31
  export declare function assertApiFileExists(dirname: typeof API_FOLDER_NAME, api: string): Promise<void>;
@@ -3,10 +3,11 @@
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;
10
+ exports.logAutomationError = logAutomationError;
10
11
  exports.logInvalidInput = logInvalidInput;
11
12
  exports.parseUrlProxy = parseUrlProxy;
12
13
  exports.withCLIContext = withCLIContext;
@@ -29,6 +30,12 @@ class CLIError extends Error {
29
30
  }
30
31
  }
31
32
  exports.CLIError = CLIError;
33
+ class AutomationTimeoutError extends _runApi.AutomationError {
34
+ constructor(message) {
35
+ super(message);
36
+ }
37
+ }
38
+ exports.AutomationTimeoutError = AutomationTimeoutError;
32
39
  class CLIAssertionError extends CLIError {
33
40
  constructor(message, options) {
34
41
  super(message, options);
@@ -55,6 +62,15 @@ async function assertAuthConsistent(authSession) {
55
62
  throw new CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
56
63
  }
57
64
  }
65
+ function logAutomationError(error) {
66
+ (0, _terminal.terminal)(`^r^+An error occurred while running the API:^:\n`);
67
+ if (error.error.stack) {
68
+ const stackLines = error.error.stack.split("\n").filter(line => !line.includes("@intuned/runtime"));
69
+ (0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
70
+ } else {
71
+ (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
72
+ }
73
+ }
58
74
  function withErrorLogging(fn) {
59
75
  return async (...args) => {
60
76
  try {
@@ -68,12 +84,7 @@ function withErrorLogging(fn) {
68
84
  (0, _terminal.terminal)(`${error.message}\n`);
69
85
  }
70
86
  } else if (error instanceof _runApi.AutomationError) {
71
- (0, _terminal.terminal)(`^r^+An error occurred while running the API:^:\n`);
72
- (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
73
- if (error.error.stack) {
74
- (0, _terminal.terminal)(`^r^+Stack trace:^:\n`);
75
- (0, _terminal.terminal)(`^r${error.error.stack}^:\n`);
76
- }
87
+ logAutomationError(error);
77
88
  } else {
78
89
  (0, _terminal.terminal)(`^r^+An error occurred:^: ^R${error.message}^:\n^r^+Please report this issue to the Intuned team.^:\n`);
79
90
  }
@@ -104,24 +115,21 @@ function withTimeout(fn, timeout) {
104
115
  reject = _reject;
105
116
  });
106
117
  const timeoutId = setTimeout(() => {
107
- reject(new CLIError("Timed out"));
118
+ reject(new AutomationTimeoutError("Timed out"));
108
119
  }, timeout);
109
- const fnWithWrapper = async (...args) => {
110
- return Promise.race([fn(...args), timeoutPromise]);
111
- };
112
120
  (0, _asyncLocalStorage.getExecutionContext)().timeoutInfo.extendTimeoutCallback = async () => {
113
121
  timeoutId.refresh();
114
122
  };
115
- return fnWithWrapper;
123
+ return Promise.race([fn(), timeoutPromise]);
116
124
  }
117
- function withCLIContext(fn) {
125
+ async function withCLIContext(fn) {
118
126
  const runId = (0, _nanoid.nanoid)();
119
- return async (...args) => (0, _asyncLocalStorage.runWithContext)({
127
+ return await (0, _asyncLocalStorage.runWithContext)({
120
128
  runEnvironment: _enums.RunEnvironment.IDE,
121
129
  runId,
122
130
  extendedPayloads: [],
123
131
  timeoutInfo: {}
124
- }, fn, ...args);
132
+ }, fn);
125
133
  }
126
134
  async function assertApiFileExists(dirname, api) {
127
135
  const file = `${dirname}/${api}.ts`;
@@ -51,13 +51,14 @@ async function executeRunApiCLI({
51
51
  });
52
52
  } catch (error) {
53
53
  if (error instanceof _runApi.AutomationError) {
54
- (0, _terminal.terminal)(`^r^+Attempt ${i + 1} failed ^:^+${apiName}^:: ^R${error.error.message}^:\n`);
54
+ (0, _helpers.logAutomationError)(error);
55
+ (0, _terminal.terminal)(`^r^+Attempt ${i + 1} failed^:\n`);
55
56
  continue;
56
57
  }
57
58
  throw error;
58
59
  }
59
60
  }
60
- })();
61
+ });
61
62
  if (apiResult === undefined) {
62
63
  throw new _helpers.CLIError(`^r^+Failed to run API ^:^+${apiName}^:: ^RExceeded maximum retries of ^+${retries}^:\n`, {
63
64
  autoColor: false
@@ -100,7 +101,7 @@ async function executeAttemptApiCLI({
100
101
  apiResult,
101
102
  outputFile
102
103
  });
103
- })();
104
+ });
104
105
  }
105
106
  async function handleApiResult({
106
107
  apiResult,
@@ -168,7 +169,7 @@ async function attemptApi({
168
169
  if (runApiResult.error instanceof _runApi.AutomationError) {
169
170
  throw runApiResult.error;
170
171
  }
171
- throw new _helpers.CLIError(`An error occurred while running the API: ${runApiResult.error.message}`);
172
+ throw runApiResult.error;
172
173
  }
173
174
  const {
174
175
  result,
@@ -178,5 +179,5 @@ async function attemptApi({
178
179
  result,
179
180
  payloadToAppend
180
181
  };
181
- }, timeout)();
182
+ }, timeout);
182
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.1",
3
+ "version": "1.2.0-cli.3",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",