@intuned/runtime-dev 0.1.0-test.13 → 0.1.0-test.15

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.
Files changed (97) hide show
  1. package/bin/intuned-api-run +1 -1
  2. package/bin/intuned-auth-session-check +1 -1
  3. package/bin/intuned-auth-session-create +1 -1
  4. package/bin/intuned-auth-session-load +1 -1
  5. package/bin/intuned-auth-session-refresh +1 -1
  6. package/bin/intuned-browser-save-state +1 -1
  7. package/bin/intuned-browser-start +1 -1
  8. package/bin/intuned-build +1 -1
  9. package/bin/intuned-ts-check +1 -1
  10. package/dist/commands/api/run.js +83 -156
  11. package/dist/commands/auth-sessions/load.js +20 -20
  12. package/dist/commands/auth-sessions/run-check.js +39 -45
  13. package/dist/commands/auth-sessions/run-create.js +74 -84
  14. package/dist/commands/browser/save-state.js +7 -12
  15. package/dist/commands/browser/start-browser.js +4 -7
  16. package/dist/commands/build.js +62 -96
  17. package/dist/commands/common/browserUtils.js +30 -41
  18. package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
  19. package/dist/commands/common/getDefaultExportFromFile.js +0 -12
  20. package/dist/commands/common/getFirstLineNumber.js +83 -90
  21. package/dist/commands/common/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +2 -1
  22. package/dist/commands/common/sendMessageToClient.js +2 -4
  23. package/dist/commands/common/utils/fileUtils.js +16 -16
  24. package/dist/commands/common/utils/settings.js +18 -16
  25. package/dist/commands/common/utils/unixSocket.js +36 -43
  26. package/dist/commands/common/utils/webTemplate.js +19 -25
  27. package/dist/commands/interface/run.js +133 -139
  28. package/dist/commands/ts-check.js +41 -44
  29. package/dist/common/Logger/Logger/index.js +46 -40
  30. package/dist/common/Logger/Logger/types.js +1 -1
  31. package/dist/common/Logger/index.js +46 -40
  32. package/dist/common/Logger/types.js +1 -1
  33. package/dist/common/asyncLocalStorage/index.js +4 -4
  34. package/dist/common/cleanEnvironmentVariables.js +9 -11
  35. package/dist/common/constants.js +1 -1
  36. package/dist/common/contextStorageStateHelpers.js +38 -36
  37. package/dist/common/getPlaywrightConstructs.js +158 -187
  38. package/dist/common/jwtTokenManager.js +61 -74
  39. package/dist/common/runApi/errors.js +121 -130
  40. package/dist/common/runApi/index.js +231 -217
  41. package/dist/common/runApi/types.js +41 -55
  42. package/dist/common/settingsSchema.js +6 -9
  43. package/dist/common/telemetry.js +16 -27
  44. package/dist/index.js +3 -3
  45. package/dist/runtime/RunError.js +10 -10
  46. package/dist/runtime/downloadDirectory.js +10 -10
  47. package/dist/runtime/enums.d.ts +11 -1
  48. package/dist/runtime/enums.js +12 -12
  49. package/dist/runtime/export.d.ts +202 -1
  50. package/dist/runtime/extendPayload.js +12 -12
  51. package/dist/runtime/extendTimeout.js +20 -19
  52. package/dist/runtime/index.js +1 -1
  53. package/dist/runtime/requestMoreInfo.js +14 -14
  54. package/dist/runtime/runInfo.js +12 -11
  55. package/package.json +2 -3
  56. package/dist/commands/api/run.ts +0 -105
  57. package/dist/commands/auth-sessions/load.ts +0 -30
  58. package/dist/commands/auth-sessions/run-check.ts +0 -51
  59. package/dist/commands/auth-sessions/run-create.ts +0 -91
  60. package/dist/commands/browser/save-state.ts +0 -14
  61. package/dist/commands/browser/start-browser.ts +0 -11
  62. package/dist/commands/build.ts +0 -78
  63. package/dist/commands/common/browserUtils.ts +0 -45
  64. package/dist/commands/common/getDefaultExportFromFile.ts +0 -11
  65. package/dist/commands/common/getFirstLineNumber.ts +0 -96
  66. package/dist/commands/common/sendMessageToClient.ts +0 -3
  67. package/dist/commands/common/utils/fileUtils.ts +0 -23
  68. package/dist/commands/common/utils/settings.ts +0 -22
  69. package/dist/commands/common/utils/unixSocket.ts +0 -38
  70. package/dist/commands/common/utils/webTemplate.ts +0 -22
  71. package/dist/commands/interface/run.ts +0 -156
  72. package/dist/commands/ts-check.ts +0 -50
  73. package/dist/common/Logger/Logger/index.ts +0 -53
  74. package/dist/common/Logger/index.ts +0 -53
  75. package/dist/common/asyncLocalStorage/index.ts +0 -9
  76. package/dist/common/cleanEnvironmentVariables.ts +0 -10
  77. package/dist/common/constants.ts +0 -1
  78. package/dist/common/contextStorageStateHelpers.ts +0 -43
  79. package/dist/common/getPlaywrightConstructs.ts +0 -181
  80. package/dist/common/jwtTokenManager.ts +0 -71
  81. package/dist/common/runApi/errors.ts +0 -154
  82. package/dist/common/runApi/index.ts +0 -253
  83. package/dist/common/runApi/types.ts +0 -43
  84. package/dist/common/settingsSchema.ts +0 -9
  85. package/dist/common/telemetry.ts +0 -23
  86. package/dist/index.ts +0 -4
  87. package/dist/runtime/RunError.ts +0 -12
  88. package/dist/runtime/downloadDirectory.ts +0 -13
  89. package/dist/runtime/enums.ts +0 -12
  90. package/dist/runtime/extendPayload.ts +0 -15
  91. package/dist/runtime/extendTimeout.ts +0 -24
  92. package/dist/runtime/index.ts +0 -6
  93. package/dist/runtime/requestMoreInfo.ts +0 -18
  94. package/dist/runtime/runInfo.ts +0 -15
  95. /package/dist/{common/Logger/Logger/types.ts → runtime/enums.d.js} +0 -0
  96. /package/dist/runtime/{executionHelpers.test.ts → executionHelpers.test.js} +0 -0
  97. /package/dist/{common/Logger/types.ts → runtime/export.d.js} +0 -0
@@ -1,12 +1,12 @@
1
1
  export class RunError extends Error {
2
- constructor(message, options) {
3
- super(message);
4
- this.message = message;
5
- this.name = "USER_GENERATED_ERROR";
6
- this.options = options ?? {
7
- retryable: false,
8
- };
9
- Object.setPrototypeOf(this, RunError.prototype);
10
- }
2
+ constructor(message, options) {
3
+ super(message);
4
+ this.message = message;
5
+ this.name = "USER_GENERATED_ERROR";
6
+ this.options = options ?? {
7
+ retryable: false
8
+ };
9
+ Object.setPrototypeOf(this, RunError.prototype);
10
+ }
11
11
  }
12
- new RunError("", {});
12
+ new RunError("", {});
@@ -1,13 +1,13 @@
1
1
  import { getExecutionContext } from "..";
2
2
  import { ensureDirSync } from "fs-extra";
3
3
  export function getDownloadDirectoryPath() {
4
- const context = getExecutionContext();
5
- if (!context) {
6
- throw new Error("ExecutionContext not found");
7
- }
8
- const path = `/tmp/downloads/${context.runId}`;
9
- ensureDirSync(path, {
10
- mode: 0o2775,
11
- });
12
- return path;
13
- }
4
+ const context = getExecutionContext();
5
+ if (!context) {
6
+ throw new Error("ExecutionContext not found");
7
+ }
8
+ const path = `/tmp/downloads/${context.runId}`;
9
+ ensureDirSync(path, {
10
+ mode: 0o2775
11
+ });
12
+ return path;
13
+ }
@@ -1 +1,11 @@
1
- export {};
1
+ export declare enum RunEnvironment {
2
+ IDE = "IDE",
3
+ DEPLOYED = "DEPLOYED",
4
+ }
5
+
6
+ export declare enum RunType {
7
+ SYNC = "SYNC",
8
+ ASYNC = "ASYNC",
9
+ JOB = "JOB",
10
+ QUEUE = "QUEUE",
11
+ }
@@ -1,12 +1,12 @@
1
- export var RunEnvironment;
2
- (function (RunEnvironment) {
3
- RunEnvironment["IDE"] = "IDE";
4
- RunEnvironment["DEPLOYED"] = "DEPLOYED";
5
- })(RunEnvironment || (RunEnvironment = {}));
6
- export var RunType;
7
- (function (RunType) {
8
- RunType["SYNC"] = "SYNC";
9
- RunType["ASYNC"] = "ASYNC";
10
- RunType["JOB"] = "JOB";
11
- RunType["QUEUE"] = "QUEUE";
12
- })(RunType || (RunType = {}));
1
+ export let RunEnvironment = function (RunEnvironment) {
2
+ RunEnvironment["IDE"] = "IDE";
3
+ RunEnvironment["DEPLOYED"] = "DEPLOYED";
4
+ return RunEnvironment;
5
+ }({});
6
+ export let RunType = function (RunType) {
7
+ RunType["SYNC"] = "SYNC";
8
+ RunType["ASYNC"] = "ASYNC";
9
+ RunType["JOB"] = "JOB";
10
+ RunType["QUEUE"] = "QUEUE";
11
+ return RunType;
12
+ }({});
@@ -1 +1,202 @@
1
- export {};
1
+ import { RunEnvironment } from "./enums.js";
2
+
3
+ /**
4
+ * ## Description
5
+ * In the context of a job, extendTimeout will increase the timeout of the currently executing payload.
6
+ * This is useful when the payload is expected to take a long time. For example, when running pagination code.
7
+ *
8
+ * @example
9
+ * ```typescript Example
10
+ * import { extendTimeout } from "@intuned/sdk/runtime"
11
+ *
12
+ * extendTimeout();
13
+ * ```
14
+ *
15
+ */
16
+ export declare function extendTimeout(): void;
17
+
18
+ /**
19
+ * ## Description
20
+ * In the context of a job or queue execution, extendPayload appends new payloads to the end of the queue of job.
21
+ * Calling extendPayload will also call extendTimeout.
22
+ *
23
+ * @param {Payload | Payload[]} payload - The payload or array of payloads to extend. you can specify the api name and what parameters you want to pass it, the new added apis will use the same proxy and auth-session settings as the api that extended them
24
+ *
25
+ * @example
26
+ * ```typescript Single payload
27
+ * import { extendPayload } from "@intuned/sdk/runtime"
28
+ *
29
+ * // this function will append the exampleApi to the end of the queue or job it's executing in.
30
+ * extendPayload({ api: 'exampleApi', parameters: { key: 'value' } });
31
+ * ```
32
+ *
33
+ * @example
34
+ * ```typescript Array of payloads
35
+ * import { extendPayload } from "@intuned/sdk/runtime"
36
+ *
37
+ * const payloadArray: Payload[] = [
38
+ * { api: 'exampleApi1', parameters: { key1: 'value1' } },
39
+ * { api: 'exampleApi2', parameters: { key2: 'value2' } }
40
+ * ];
41
+ *
42
+ * // this function will append 2 apis to the end of the queue or job it's executing in.
43
+ * extendPayload(payloadArray);
44
+ * ```
45
+ */
46
+ export declare function extendPayload(payload: Payload | Payload[]): void;
47
+
48
+ /**
49
+ * @interface Payload
50
+ * @property {string} api - The API path you want to extend.
51
+ * @property {Record<string, any>} parameters - A record of key-value pairs representing the parameters to be sent to the API
52
+ *
53
+ * @example
54
+ *
55
+ * ```typescript payload
56
+ * import { Payload } from "@intuned/sdk/runtime"
57
+ *
58
+ * const payload: Payload = {
59
+ * api: 'exampleApi',
60
+ * parameters: {
61
+ * key1: 'value1',
62
+ * key2: 'value2'
63
+ * }
64
+ * };
65
+ * ```
66
+ */
67
+ export interface Payload {
68
+ api: string;
69
+ parameters: Record<string, any>;
70
+ }
71
+
72
+ /**
73
+ * Retrieves information about the current run environment.
74
+ *
75
+ * @returns {RunInfo} An object containing details about the run environment and the run ID.
76
+ *
77
+ * @example
78
+ * ```typescript runInfo
79
+ * import { runInfo } from "@intuned/sdk/runtime"
80
+ *
81
+ * const info = runInfo();
82
+ * console.log(info.runEnvironment); // Outputs the run environment, IDE or DEPLOYED
83
+ * console.log(info.runId); // Outputs the run ID, if available, in IDE run id will be undefined
84
+ * ```
85
+ */
86
+ export declare function runInfo(): RunInfo;
87
+
88
+ /**
89
+ * Represents information about the current run.
90
+ *
91
+ * @interface RunInfo
92
+ * @property {RunEnvironment} runEnvironment - the run environment `IDE` or `DEPLOYED`
93
+ * @property {string} [runId] - Optional. The ID of the current run, in IDE environment, run id will be undefined
94
+ */
95
+ export interface RunInfo {
96
+ runEnvironment: RunEnvironment;
97
+ runId?: string;
98
+ jobId?: string;
99
+ jobRunId?: string;
100
+ queueId?: string;
101
+ proxy?: string;
102
+ }
103
+
104
+ /**
105
+ * @interface RunErrorOptions
106
+ * @property {boolean} [retryable] - Optional. Indicates whether the error is retryable.
107
+ * @property {number} [status_code] - Optional. The HTTP status code associated with the error.
108
+ * @property {string} [error_code] - Optional. A specific error code to identify the type of error.
109
+ *
110
+ * @example
111
+ * ```typescript RunErrorOptions
112
+ * import { RunErrorOptions } from "@intuned/sdk/runtime"
113
+ *
114
+ * const options: RunErrorOptions = {
115
+ * retryable: true,
116
+ * status_code: 500,
117
+ * error_code: 'SERVER_ERROR'
118
+ * };
119
+ * ```
120
+ */
121
+ export interface RunErrorOptions {
122
+ retryable?: boolean;
123
+ status_code?: number;
124
+ error_code?: string;
125
+ }
126
+
127
+ /**
128
+ * Represents an error that occurs during a run.
129
+ *
130
+ * @class
131
+ * @extends Error
132
+ *
133
+ * @param {string} message - The error message.
134
+ * @param {RunErrorOptions} [options] - Optional. Additional options for the error.
135
+ *
136
+ * @property {RunErrorOptions} options - The options associated with the error.
137
+ *
138
+ * @example
139
+ * ```typescript RunError
140
+ * import { RunError } from "@intuned/sdk/runtime"
141
+ *
142
+ * throw new RunError('An error occurred', {
143
+ * retryable: true,
144
+ * status_code: 500,
145
+ * error_code: 'SERVER_ERROR'
146
+ * });
147
+ *
148
+ * ```
149
+ */
150
+ export declare class RunError extends Error {
151
+ constructor(message: string, options?: RunErrorOptions);
152
+ options: RunErrorOptions;
153
+ }
154
+
155
+ /**
156
+ * in the create auth session flow, you might to need a multiple choice answer from the user, requestMultipleChoice prompts the user with the question and possible options and returns their selection.
157
+ *
158
+ * **Note:** This function is currently in beta and may be subject to changes.
159
+ *
160
+ * @param {string} message - The message to display to the user.
161
+ * @param {string[]} choices - An array of choices to present to the user.
162
+ *
163
+ * @example
164
+ * ```typescript requestMultipleChoice
165
+ * // in auth-sessions/create.ts
166
+ *
167
+ * import { requestMultipleChoice } from "@intuned/sdk/runtime"
168
+ *
169
+ * const message = "What is your favorite color?";
170
+ * const choices = ["Red", "Blue", "Green", "Yellow"];
171
+ *
172
+ * const selectedChoice = yield requestMultipleChoice(message, choices);
173
+ *
174
+ * console.log(selectedChoice);
175
+ * ```
176
+ */
177
+ export declare function requestMultipleChoice(
178
+ message: string,
179
+ choices: string[]
180
+ ): unknown;
181
+
182
+ /**
183
+ * **Note:** This function is currently in beta and may be subject to changes.
184
+ *
185
+ * requestOTP help you to ask the user for an otp in the create auth-session flow.
186
+ *
187
+ * @param {string} message - The message to display to the user.
188
+ *
189
+ * @example
190
+ * ```typescript requestOTP
191
+ * // in auth-sessions/create.ts
192
+ *
193
+ * import { requestOTP } from "@intuned/sdk/runtime"
194
+ *
195
+ * const message = "please submit and OTP from your authenticator app";
196
+ *
197
+ * const otp = yield requestOTP(message);
198
+ *
199
+ * console.log(otp);
200
+ * ```
201
+ */
202
+ export declare function requestOTP(message: string): unknown;
@@ -1,15 +1,15 @@
1
1
  import { getExecutionContext } from "../common/asyncLocalStorage";
2
2
  import { extendTimeout } from "./extendTimeout.js";
3
3
  export function extendPayload(payload) {
4
- const context = getExecutionContext();
5
- if (!context) {
6
- throw new Error("extendPayload failed due to an internal error.");
7
- }
8
- const items = Array.isArray(payload) ? payload : [payload];
9
- if (!context.extendedPayloads) {
10
- context.extendedPayloads = [...items];
11
- return;
12
- }
13
- context?.extendedPayloads.push(...items);
14
- extendTimeout();
15
- }
4
+ const context = getExecutionContext();
5
+ if (!context) {
6
+ throw new Error("extendPayload failed due to an internal error.");
7
+ }
8
+ const items = Array.isArray(payload) ? payload : [payload];
9
+ if (!context.extendedPayloads) {
10
+ context.extendedPayloads = [...items];
11
+ return;
12
+ }
13
+ context === null || context === void 0 || context.extendedPayloads.push(...items);
14
+ extendTimeout();
15
+ }
@@ -1,23 +1,24 @@
1
1
  import { getExecutionContext } from "../common/asyncLocalStorage";
2
2
  const _DEBOUNCE_TIME = 60_000;
3
3
  export function extendTimeout() {
4
- const context = getExecutionContext();
5
- if (!context) {
6
- throw new Error("extendTimeout failed due to an internal error.");
4
+ const context = getExecutionContext();
5
+ if (!context) {
6
+ throw new Error("extendTimeout failed due to an internal error.");
7
+ }
8
+ const {
9
+ timeoutInfo
10
+ } = context;
11
+ if (!timeoutInfo) {
12
+ return;
13
+ }
14
+ if (timeoutInfo.timeoutTimestamp !== undefined && timeoutInfo.timeoutDuration !== undefined) {
15
+ const newTimeoutStamp = Date.now() + timeoutInfo.timeoutDuration;
16
+ if (newTimeoutStamp - timeoutInfo.timeoutTimestamp < _DEBOUNCE_TIME) {
17
+ return;
7
18
  }
8
- const { timeoutInfo } = context;
9
- if (!timeoutInfo) {
10
- return;
11
- }
12
- if (timeoutInfo.timeoutTimestamp !== undefined &&
13
- timeoutInfo.timeoutDuration !== undefined) {
14
- const newTimeoutStamp = Date.now() + timeoutInfo.timeoutDuration;
15
- if (newTimeoutStamp - timeoutInfo.timeoutTimestamp < _DEBOUNCE_TIME) {
16
- return;
17
- }
18
- timeoutInfo.timeoutTimestamp = newTimeoutStamp;
19
- }
20
- if (timeoutInfo.extendTimeoutCallback !== undefined) {
21
- void timeoutInfo.extendTimeoutCallback().catch(() => undefined);
22
- }
23
- }
19
+ timeoutInfo.timeoutTimestamp = newTimeoutStamp;
20
+ }
21
+ if (timeoutInfo.extendTimeoutCallback !== undefined) {
22
+ void timeoutInfo.extendTimeoutCallback().catch(() => undefined);
23
+ }
24
+ }
@@ -3,4 +3,4 @@ export { extendTimeout } from "./extendTimeout.js";
3
3
  export { runInfo } from "./runInfo.js";
4
4
  export { RunError } from "./RunError.js";
5
5
  export { requestMultipleChoice, requestOTP } from "./requestMoreInfo.js";
6
- export { getDownloadDirectoryPath } from "./downloadDirectory.js";
6
+ export { getDownloadDirectoryPath } from "./downloadDirectory.js";
@@ -1,18 +1,18 @@
1
1
  const REQUEST_MORE_INFO_KEY = Symbol("REQUEST_MORE_INFO");
2
2
  export function requestOTP(messageToUser) {
3
- return {
4
- [REQUEST_MORE_INFO_KEY]: true,
5
- action: "request_more_info",
6
- messageToUser,
7
- requestType: "otp",
8
- };
3
+ return {
4
+ [REQUEST_MORE_INFO_KEY]: true,
5
+ action: "request_more_info",
6
+ messageToUser,
7
+ requestType: "otp"
8
+ };
9
9
  }
10
10
  export function requestMultipleChoice(messageToUser, choices) {
11
- return {
12
- [REQUEST_MORE_INFO_KEY]: true,
13
- action: "request_more_info",
14
- messageToUser,
15
- requestType: "multiple_choice",
16
- choices,
17
- };
18
- }
11
+ return {
12
+ [REQUEST_MORE_INFO_KEY]: true,
13
+ action: "request_more_info",
14
+ messageToUser,
15
+ requestType: "multiple_choice",
16
+ choices
17
+ };
18
+ }
@@ -1,14 +1,15 @@
1
1
  import { getExecutionContext } from "../common/asyncLocalStorage";
2
2
  import { RunEnvironment } from "./enums.js";
3
3
  export function runInfo() {
4
- const context = getExecutionContext();
5
- if (!context) {
6
- return {
7
- runEnvironment: RunEnvironment.IDE,
8
- // runType: RunType.SYNC,
9
- };
10
- }
11
- //remove extendedPayloads from the user exposed data
12
- const { extendedPayloads: _extendedPayloads, ...rest } = context;
13
- return rest;
14
- }
4
+ const context = getExecutionContext();
5
+ if (!context) {
6
+ return {
7
+ runEnvironment: RunEnvironment.IDE
8
+ };
9
+ }
10
+ const {
11
+ extendedPayloads: _extendedPayloads,
12
+ ...rest
13
+ } = context;
14
+ return rest;
15
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
3
  "type": "module",
4
- "version": "0.1.0-test.13",
4
+ "version": "0.1.0-test.15",
5
5
  "description": "Intuned runtime",
6
6
  "exports": {
7
7
  ".": "./dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "intuned-auth-session-refresh": "vite-node ./src/commands/auth/run-refresh.ts",
30
30
  "intuned-auth-session-load": "vite-node ./src/commands/auth/load.ts",
31
31
  "intuned-ts-check": "yarn prepublishOnly && vite-node ./src/commands/ts-check.ts",
32
- "build": "rm -rf dist && tsc -p tsconfig.json && yarn copy-dts && babel src --out-dir dist --extensions '.ts' --keep-file-extension && cp -r ./src/common/assets dist/common/assets",
32
+ "build": "rm -rf dist && tsc -p tsconfig.json && yarn copy-dts && babel src --out-dir dist --extensions '.ts' && cp -r ./src/common/assets dist/common/assets",
33
33
  "test": "vitest run",
34
34
  "test:watch": "vitest",
35
35
  "e2e": "yarn playwright test --config ./playwright.config.ts",
@@ -92,7 +92,6 @@
92
92
  "source-map": "^0.7.4",
93
93
  "stack-utils": "^2.0.6",
94
94
  "ts-morph": "^21.0.1",
95
- "ts-node": "^10.9.1",
96
95
  "tslib": "^2.6.0",
97
96
  "typescript": "^5.1.6",
98
97
  "wait-on": "^7.2.0",
@@ -1,105 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program, Argument } from "commander";
3
- import * as fs from "fs-extra";
4
- import { getSettings } from "../common/utils/settings";
5
- import dotenv from "dotenv";
6
- import { runWithContext } from "../../common/asyncLocalStorage";
7
- import { RunEnvironment } from "../../runtime/enums";
8
- import { cleanEnvironmentVariables } from "../../common/cleanEnvironmentVariables";
9
- import { logger } from "../../common/Logger";
10
- import { nanoid } from "nanoid";
11
- import chalk from "chalk";
12
- import { runApi } from "../../common/runApi";
13
- import { AutomationError } from "../../common/runApi";
14
- dotenv.config({
15
- path: `.env`
16
- });
17
- export async function executeCLI(apiName, mode, inputData, options) {
18
- cleanEnvironmentVariables();
19
- let authSessionPathToUse = null;
20
- const settings = await getSettings();
21
- if (settings.authSessions.enabled) {
22
- if (!options.authSessionPath) {
23
- throw new Error("Auth session is enabled but no auth session provided");
24
- }
25
- authSessionPathToUse = options.authSessionPath;
26
- } else {
27
- if (options.authSessionPath) {
28
- throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
29
- }
30
- }
31
- const runApiResult = await runApi({
32
- automationFunction: {
33
- name: `api/${apiName}`,
34
- params: inputData ?? {}
35
- },
36
- auth: authSessionPathToUse ? {
37
- session: {
38
- type: "file",
39
- path: authSessionPathToUse
40
- },
41
- runCheck: false
42
- } : undefined,
43
- runOptions: {
44
- environment: "ide",
45
- cdpAddress: options.cdpAddress,
46
- mode
47
- }
48
- });
49
- if (runApiResult.isErr()) {
50
- if (runApiResult.error instanceof AutomationError) {
51
- throw runApiResult.error.error;
52
- }
53
- console.error("An error occurred while running the API", runApiResult.error);
54
- return;
55
- }
56
- const {
57
- result,
58
- extendedPayloads: payloadToAppend
59
- } = runApiResult.value;
60
- const isResponseObject = typeof result === "object" && result !== null;
61
- const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
62
- const hasNestedObjects = isResponseObject && Object.values(result).some(value => typeof value === "object");
63
- const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
64
- const resultsDir = "/tmp/run-results";
65
- if (options.outputFileId && shouldWriteToFile) {
66
- logger.info(chalk.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
67
- fs.ensureDirSync(resultsDir);
68
- const path = `${resultsDir}/${options.outputFileId}.json`;
69
- await fs.writeJson(path, result, {
70
- spaces: 2
71
- });
72
- } else {
73
- console.log("result:", result);
74
- }
75
- const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
76
- if (hasPayloadToAppend && options.outputFileId) {
77
- logger.info(chalk.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
78
- fs.ensureDirSync(resultsDir);
79
- const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
80
- await fs.writeJson(path, payloadToAppend, {
81
- spaces: 2
82
- });
83
- } else if (hasPayloadToAppend) {
84
- logger.info("payload to append:", payloadToAppend);
85
- logger.info("This will only take an effect if this API run was part of a job.");
86
- }
87
- }
88
- program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
89
- let inputData = null;
90
- if (options.input) {
91
- inputData = await fs.readJSON(options.input);
92
- } else if (options.json) {
93
- inputData = JSON.parse(options.json);
94
- } else {
95
- inputData = {};
96
- }
97
- await runWithContext({
98
- runEnvironment: RunEnvironment.IDE,
99
- extendedPayloads: [],
100
- runId: nanoid(),
101
- proxy: options.proxy
102
- }, () => executeCLI(apiName, mode, inputData, options));
103
- process.exit(0);
104
- });
105
- program.parse(process.argv);
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program } from "commander";
3
- import { getRemotePlaywrightContext } from "../../common/getPlaywrightConstructs";
4
- import { getSettings } from "../common/utils/settings";
5
- import dotenv from "dotenv";
6
- import { loadSessionToContext } from "../../common/getPlaywrightConstructs";
7
- dotenv.config({
8
- path: `.env`
9
- });
10
- program.description("load auth session to browser").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").allowUnknownOption().action(async ({
11
- cdpAddress,
12
- authSessionPath
13
- }) => {
14
- const setting = await getSettings();
15
- if (!setting.authSessions.enabled) {
16
- throw new Error("Auth session is not enabled");
17
- }
18
- const {
19
- context
20
- } = await getRemotePlaywrightContext(cdpAddress);
21
- await loadSessionToContext({
22
- context,
23
- session: {
24
- type: "file",
25
- path: authSessionPath
26
- }
27
- });
28
- process.exit(0);
29
- });
30
- program.parse(process.argv);
@@ -1,51 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Argument, program } from "commander";
3
- import * as fs from "fs-extra";
4
- import { getFullPathInProject } from "../common/utils/fileUtils";
5
- import { getSettings } from "../common/utils/settings";
6
- import dotenv from "dotenv";
7
- import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
8
- import { runApi } from "../../common/runApi";
9
- dotenv.config({
10
- path: `.env`
11
- });
12
- program.description("run auth session check").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the check").allowUnknownOption().addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
13
- cdpAddress,
14
- authSessionPath
15
- }) => {
16
- const setting = await getSettings();
17
- if (!setting.authSessions.enabled) {
18
- throw new Error("auth session is not enabled");
19
- }
20
- const checkFilePath = getFullPathInProject(AUTH_SESSIONS_FOLDER_NAME, "check");
21
- if (!fs.exists(checkFilePath)) {
22
- throw new Error("auth session check file not found");
23
- }
24
- const runApiResult = await runApi({
25
- automationFunction: {
26
- name: `${AUTH_SESSIONS_FOLDER_NAME}/check`
27
- },
28
- runOptions: {
29
- environment: "ide",
30
- mode,
31
- cdpAddress
32
- },
33
- auth: {
34
- session: {
35
- type: "file",
36
- path: authSessionPath
37
- },
38
- runCheck: false
39
- }
40
- });
41
- if (runApiResult.isErr()) {
42
- throw new Error(runApiResult.error);
43
- }
44
- const result = runApiResult.value.result;
45
- console.log("check result", result);
46
- if (!result) {
47
- throw new Error("auth session check failed");
48
- }
49
- process.exit(0);
50
- });
51
- program.parse(process.argv);