@intuned/runtime-dev 1.2.0-cli.0 → 1.2.0-cli.2

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,5 +1,6 @@
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?: {
@@ -14,6 +15,7 @@ export declare class CLIAssertionError extends CLIError {
14
15
  export declare function logInvalidInput(result: z.SafeParseError<unknown>): void;
15
16
  export declare function assertAuthEnabled(): Promise<void>;
16
17
  export declare function assertAuthConsistent(authSession: string | undefined): Promise<void>;
18
+ export declare function logAutomationError(error: AutomationError): void;
17
19
  export declare function withErrorLogging<T extends any[]>(fn: (...args: T) => Promise<unknown>): (...args: T) => Promise<never>;
18
20
  export declare function parseUrlProxy(proxyUrl: string): {
19
21
  password: string;
@@ -7,6 +7,7 @@ exports.CLIError = exports.CLIAssertionError = 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;
@@ -19,6 +20,7 @@ var _enums = require("../../../runtime/enums");
19
20
  var _terminal = require("../terminal");
20
21
  var _path = _interopRequireDefault(require("path"));
21
22
  var _fsExtra = require("fs-extra");
23
+ var _runApi = require("../../../common/runApi");
22
24
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
25
  class CLIError extends Error {
24
26
  constructor(message, options) {
@@ -54,6 +56,15 @@ async function assertAuthConsistent(authSession) {
54
56
  throw new CLIAssertionError("Auth session is not enabled, enable it in Intuned.json to use it");
55
57
  }
56
58
  }
59
+ function logAutomationError(error) {
60
+ (0, _terminal.terminal)(`^r^+An error occurred while running the API:^:\n`);
61
+ (0, _terminal.terminal)(`^r${error.error.message}^:\n`);
62
+ if (error.error.stack) {
63
+ (0, _terminal.terminal)(`^r^+Stack trace:^:\n`);
64
+ const stackLines = error.error.stack.split("\n").filter(line => !line.includes("@intuned/runtime"));
65
+ (0, _terminal.terminal)(`^r${stackLines.join("\n")}^:\n`);
66
+ }
67
+ }
57
68
  function withErrorLogging(fn) {
58
69
  return async (...args) => {
59
70
  try {
@@ -66,6 +77,8 @@ function withErrorLogging(fn) {
66
77
  } else {
67
78
  (0, _terminal.terminal)(`${error.message}\n`);
68
79
  }
80
+ } else if (error instanceof _runApi.AutomationError) {
81
+ logAutomationError(error);
69
82
  } else {
70
83
  (0, _terminal.terminal)(`^r^+An error occurred:^: ^R${error.message}^:\n^r^+Please report this issue to the Intuned team.^:\n`);
71
84
  }
@@ -50,8 +50,12 @@ async function executeRunApiCLI({
50
50
  ...rest
51
51
  });
52
52
  } catch (error) {
53
- (0, _terminal.terminal)(`^r^+Failed to run API ^:^+${apiName}^:: ^R${error.message}^:\n`);
54
- continue;
53
+ if (error instanceof _runApi.AutomationError) {
54
+ (0, _helpers.logAutomationError)(error);
55
+ (0, _terminal.terminal)(`^r^+Attempt ${i + 1} failed^:\n`);
56
+ continue;
57
+ }
58
+ throw error;
55
59
  }
56
60
  }
57
61
  })();
@@ -116,7 +120,7 @@ async function handleApiResult({
116
120
  (0, _terminal.terminal)(`${JSON.stringify(result, null, 2)}\n`);
117
121
  }
118
122
  if (payloadToAppend && payloadToAppend.length > 0) {
119
- (0, _terminal.terminal)(`^+^gExtended payloads:^ ^/^G(This will only take effect if this API run was part of a job.)^:\n:\n`);
123
+ (0, _terminal.terminal)(`^+^gExtended payloads:^ ^/^G(This will only take effect if this API run was part of a job.)^:\n`);
120
124
  (0, _terminal.terminal)(`${JSON.stringify(payloadToAppend, null, 2)}\n`);
121
125
  }
122
126
  return;
@@ -163,7 +167,7 @@ async function attemptApi({
163
167
  });
164
168
  if (runApiResult.isErr()) {
165
169
  if (runApiResult.error instanceof _runApi.AutomationError) {
166
- throw runApiResult.error.error;
170
+ throw runApiResult.error;
167
171
  }
168
172
  throw new _helpers.CLIError(`An error occurred while running the API: ${runApiResult.error.message}`);
169
173
  }
@@ -200,7 +200,7 @@ async function runCheck({
200
200
  });
201
201
  if (runApiResult.isErr()) {
202
202
  if (runApiResult.error instanceof _runApi.AutomationError) {
203
- throw runApiResult.error.error;
203
+ throw runApiResult.error;
204
204
  }
205
205
  return false;
206
206
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "1.2.0-cli.0",
3
+ "version": "1.2.0-cli.2",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",