@intuned/runtime-dev 0.1.0-test.10 → 0.1.0-test.12

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 (103) hide show
  1. package/.babelrc +1 -2
  2. package/dist/commands/api/run.js +170 -105
  3. package/dist/commands/api/run.ts +105 -0
  4. package/dist/commands/auth-sessions/load.js +26 -28
  5. package/dist/commands/auth-sessions/load.ts +30 -0
  6. package/dist/commands/auth-sessions/run-check.js +53 -52
  7. package/dist/commands/auth-sessions/run-check.ts +51 -0
  8. package/dist/commands/auth-sessions/run-create.js +96 -91
  9. package/dist/commands/auth-sessions/run-create.ts +91 -0
  10. package/dist/commands/browser/save-state.js +16 -14
  11. package/dist/commands/browser/save-state.ts +14 -0
  12. package/dist/commands/browser/start-browser.js +11 -11
  13. package/dist/commands/browser/start-browser.ts +11 -0
  14. package/dist/commands/build.js +108 -75
  15. package/dist/commands/build.ts +78 -0
  16. package/dist/commands/common/browserUtils.js +51 -53
  17. package/dist/commands/common/browserUtils.ts +45 -0
  18. package/dist/commands/common/getDefaultExportFromFile.js +12 -17
  19. package/dist/commands/common/getDefaultExportFromFile.ts +11 -0
  20. package/dist/commands/common/getFirstLineNumber.js +93 -93
  21. package/dist/commands/common/{getFirstLineNumber.test.js → getFirstLineNumber.test.ts} +46 -51
  22. package/dist/commands/common/getFirstLineNumber.ts +96 -0
  23. package/dist/commands/common/sendMessageToClient.js +4 -9
  24. package/dist/commands/common/sendMessageToClient.ts +3 -0
  25. package/dist/commands/common/utils/fileUtils.js +22 -32
  26. package/dist/commands/common/utils/fileUtils.ts +23 -0
  27. package/dist/commands/common/utils/settings.js +19 -27
  28. package/dist/commands/common/utils/settings.ts +22 -0
  29. package/dist/commands/common/utils/unixSocket.js +43 -43
  30. package/dist/commands/common/utils/unixSocket.ts +38 -0
  31. package/dist/commands/common/utils/webTemplate.js +27 -29
  32. package/dist/commands/common/utils/webTemplate.ts +22 -0
  33. package/dist/commands/interface/run.js +151 -150
  34. package/dist/commands/interface/run.ts +156 -0
  35. package/dist/commands/ts-check.js +49 -49
  36. package/dist/commands/ts-check.ts +50 -0
  37. package/dist/common/Logger/Logger/index.d.ts +1 -1
  38. package/dist/common/Logger/Logger/index.js +42 -55
  39. package/dist/common/Logger/Logger/index.ts +53 -0
  40. package/dist/common/Logger/Logger/types.js +1 -5
  41. package/dist/common/Logger/Logger/types.ts +1 -0
  42. package/dist/common/Logger/index.d.ts +1 -1
  43. package/dist/common/Logger/index.js +42 -55
  44. package/dist/common/Logger/index.ts +53 -0
  45. package/dist/common/Logger/types.js +1 -5
  46. package/dist/common/Logger/types.ts +1 -0
  47. package/dist/common/asyncLocalStorage/index.js +8 -16
  48. package/dist/common/asyncLocalStorage/index.ts +9 -0
  49. package/dist/common/cleanEnvironmentVariables.js +12 -16
  50. package/dist/common/cleanEnvironmentVariables.ts +10 -0
  51. package/dist/common/constants.js +1 -7
  52. package/dist/common/constants.ts +1 -0
  53. package/dist/common/contextStorageStateHelpers.js +38 -47
  54. package/dist/common/contextStorageStateHelpers.ts +43 -0
  55. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  56. package/dist/common/getPlaywrightConstructs.js +196 -177
  57. package/dist/common/getPlaywrightConstructs.ts +181 -0
  58. package/dist/common/jwtTokenManager.js +79 -76
  59. package/dist/common/jwtTokenManager.ts +71 -0
  60. package/dist/common/runApi/errors.d.ts +1 -1
  61. package/dist/common/runApi/errors.js +150 -159
  62. package/dist/common/runApi/errors.ts +154 -0
  63. package/dist/common/runApi/index.d.ts +4 -4
  64. package/dist/common/runApi/index.js +220 -269
  65. package/dist/common/runApi/index.ts +253 -0
  66. package/dist/common/runApi/types.d.ts +1 -1
  67. package/dist/common/runApi/types.js +56 -49
  68. package/dist/common/runApi/types.ts +43 -0
  69. package/dist/common/settingsSchema.js +10 -15
  70. package/dist/common/settingsSchema.ts +9 -0
  71. package/dist/common/telemetry.js +30 -28
  72. package/dist/common/telemetry.ts +23 -0
  73. package/dist/index.d.ts +4 -4
  74. package/dist/index.js +4 -69
  75. package/dist/index.ts +4 -0
  76. package/dist/runtime/RunError.d.ts +1 -1
  77. package/dist/runtime/RunError.js +11 -18
  78. package/dist/runtime/RunError.ts +12 -0
  79. package/dist/runtime/downloadDirectory.js +13 -19
  80. package/dist/runtime/downloadDirectory.ts +13 -0
  81. package/dist/runtime/enums.d.ts +1 -11
  82. package/dist/runtime/enums.js +12 -18
  83. package/dist/runtime/enums.ts +12 -0
  84. package/dist/runtime/executionHelpers.test.ts +51 -0
  85. package/dist/runtime/export.d.ts +1 -202
  86. package/dist/runtime/extendPayload.d.ts +1 -1
  87. package/dist/runtime/extendPayload.js +15 -21
  88. package/dist/runtime/extendPayload.ts +15 -0
  89. package/dist/runtime/extendTimeout.js +21 -28
  90. package/dist/runtime/extendTimeout.ts +24 -0
  91. package/dist/runtime/index.d.ts +7 -7
  92. package/dist/runtime/index.js +6 -53
  93. package/dist/runtime/index.ts +6 -0
  94. package/dist/runtime/requestMoreInfo.js +16 -23
  95. package/dist/runtime/requestMoreInfo.ts +18 -0
  96. package/dist/runtime/runInfo.d.ts +1 -1
  97. package/dist/runtime/runInfo.js +14 -21
  98. package/dist/runtime/runInfo.ts +15 -0
  99. package/package.json +3 -2
  100. package/tsconfig.json +1 -1
  101. package/dist/runtime/enums.d.js +0 -5
  102. package/dist/runtime/executionHelpers.test.js +0 -53
  103. package/dist/runtime/export.d.js +0 -5
package/.babelrc CHANGED
@@ -7,13 +7,12 @@
7
7
  "chrome": 115,
8
8
  "node": "16"
9
9
  },
10
- "modules": "commonjs"
10
+ "modules": false
11
11
  }
12
12
  ],
13
13
  "@babel/preset-typescript"
14
14
  ],
15
15
  "plugins": [
16
- ["./preserve-dynamic-imports.js"],
17
16
  "babel-plugin-macros",
18
17
  "@babel/plugin-syntax-dynamic-import",
19
18
  "@babel/plugin-transform-export-namespace-from"
@@ -1,113 +1,178 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
-
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
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`,
6
16
  });
7
- exports.executeCLI = executeCLI;
8
- var _commander = require("commander");
9
- var fs = _interopRequireWildcard(require("fs-extra"));
10
- var _settings = require("../common/utils/settings");
11
- var _dotenv = _interopRequireDefault(require("dotenv"));
12
- var _asyncLocalStorage = require("../../common/asyncLocalStorage");
13
- var _enums = require("../../runtime/enums");
14
- var _cleanEnvironmentVariables = require("../../common/cleanEnvironmentVariables");
15
- var _Logger = require("../../common/Logger");
16
- var _nanoid = require("nanoid");
17
- var _chalk = _interopRequireDefault(require("chalk"));
18
- var _runApi = require("../../common/runApi");
19
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
21
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
22
- _dotenv.default.config({
23
- path: `.env`
24
- });
25
- async function executeCLI(apiName, mode, inputData, options) {
26
- (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
27
- let authSessionPathToUse = null;
28
- const settings = await (0, _settings.getSettings)();
29
- if (settings.authSessions.enabled) {
30
- if (!options.authSessionPath) {
31
- throw new Error("Auth session is enabled but no auth session provided");
17
+ export async function executeCLI(apiName, mode, inputData, options) {
18
+ // cleanup environment variables before running the user code
19
+ cleanEnvironmentVariables();
20
+ let authSessionPathToUse = null;
21
+ // check auth session
22
+ const settings = await getSettings();
23
+ if (settings.authSessions.enabled) {
24
+ // if auth session enabled, check if the auth session is provided
25
+ if (!options.authSessionPath) {
26
+ throw new Error("Auth session is enabled but no auth session provided");
27
+ }
28
+ authSessionPathToUse = options.authSessionPath;
32
29
  }
33
- authSessionPathToUse = options.authSessionPath;
34
- } else {
35
- if (options.authSessionPath) {
36
- throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
30
+ else {
31
+ // if auth session is not enabled, check if the auth session is provided
32
+ if (options.authSessionPath) {
33
+ throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
34
+ }
37
35
  }
38
- }
39
- const runApiResult = await (0, _runApi.runApi)({
40
- automationFunction: {
41
- name: `api/${apiName}`,
42
- params: inputData ?? {}
43
- },
44
- auth: authSessionPathToUse ? {
45
- session: {
46
- type: "file",
47
- path: authSessionPathToUse
48
- },
49
- runCheck: false
50
- } : undefined,
51
- runOptions: {
52
- environment: "ide",
53
- cdpAddress: options.cdpAddress,
54
- mode
36
+ // Dynamically import the TypeScript file
37
+ // const defaultExport = await getDefaultExportFromFile(apiFilePath);
38
+ // const isDebug = process.execArgv.some((arg) => arg.includes("--inspect"));
39
+ // if (isDebug) {
40
+ // const { sourceFileName, lineNumber } = await getFirstLineNumber(
41
+ // apiFilePath
42
+ // );
43
+ // sendBreakPointOnToClient(sourceFileName, lineNumber);
44
+ // }
45
+ // if (mode === "vanilla") {
46
+ // Execute the function with the input data
47
+ // const result = await defaultExport(inputData);
48
+ // return result;
49
+ // }
50
+ // const { page, context } = await getPlaywrightConstructsForMode(
51
+ // mode,
52
+ // options.cdpAddress,
53
+ // authSessionPathToUse ? authSessionPathToUse : undefined
54
+ // );
55
+ // // wait for the page to get stable, this is a workaround for a bug in playwright when you try to do something
56
+ // // on a page after connecting to it immediately, the page needs some time to get stable.
57
+ // let isPageStable = false;
58
+ // let retry = 0;
59
+ // // will wait maximum 2 seconds before failing.
60
+ // while (!isPageStable && retry < 10) {
61
+ // try {
62
+ // await page.locator("html").all();
63
+ // isPageStable = true;
64
+ // break;
65
+ // } catch (error) {
66
+ // if (error?.message?.includes("Execution context was destroyed")) {
67
+ // await new Promise((resolve) => setTimeout(resolve, 200));
68
+ // } else {
69
+ // // throwing to make sure we do not hide any other unexpected issues.
70
+ // throw error;
71
+ // }
72
+ // }
73
+ // retry++;
74
+ // }
75
+ // if (!isPageStable) {
76
+ // throw new Error("The page is not stable, try to run again.");
77
+ // }
78
+ const runApiResult = await runApi({
79
+ automationFunction: {
80
+ name: `api/${apiName}`,
81
+ params: inputData ?? {},
82
+ },
83
+ auth: authSessionPathToUse
84
+ ? {
85
+ session: {
86
+ type: "file",
87
+ path: authSessionPathToUse,
88
+ },
89
+ runCheck: false,
90
+ }
91
+ : undefined,
92
+ runOptions: {
93
+ environment: "ide",
94
+ cdpAddress: options.cdpAddress,
95
+ mode,
96
+ },
97
+ });
98
+ if (runApiResult.isErr()) {
99
+ if (runApiResult.error instanceof AutomationError) {
100
+ throw runApiResult.error.error;
101
+ }
102
+ console.error("An error occurred while running the API", runApiResult.error);
103
+ return;
55
104
  }
56
- });
57
- if (runApiResult.isErr()) {
58
- if (runApiResult.error instanceof _runApi.AutomationError) {
59
- throw runApiResult.error.error;
105
+ const { result, extendedPayloads: payloadToAppend } = runApiResult.value;
106
+ const isResponseObject = typeof result === "object" && result !== null;
107
+ const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
108
+ const hasNestedObjects = isResponseObject &&
109
+ Object.values(result).some((value) => typeof value === "object");
110
+ const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
111
+ const resultsDir = "/tmp/run-results";
112
+ if (options.outputFileId && shouldWriteToFile) {
113
+ logger.info(chalk.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
114
+ fs.ensureDirSync(resultsDir);
115
+ const path = `${resultsDir}/${options.outputFileId}.json`;
116
+ await fs.writeJson(path, result, {
117
+ spaces: 2,
118
+ });
119
+ }
120
+ else {
121
+ console.log("result:", result);
122
+ }
123
+ const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
124
+ if (hasPayloadToAppend && options.outputFileId) {
125
+ logger.info(chalk.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
126
+ fs.ensureDirSync(resultsDir);
127
+ const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
128
+ await fs.writeJson(path, payloadToAppend, {
129
+ spaces: 2,
130
+ });
131
+ }
132
+ else if (hasPayloadToAppend) {
133
+ logger.info("payload to append:", payloadToAppend);
134
+ logger.info("This will only take an effect if this API run was part of a job.");
60
135
  }
61
- console.error("An error occurred while running the API", runApiResult.error);
62
- return;
63
- }
64
- const {
65
- result,
66
- extendedPayloads: payloadToAppend
67
- } = runApiResult.value;
68
- const isResponseObject = typeof result === "object" && result !== null;
69
- const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
70
- const hasNestedObjects = isResponseObject && Object.values(result).some(value => typeof value === "object");
71
- const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
72
- const resultsDir = "/tmp/run-results";
73
- if (options.outputFileId && shouldWriteToFile) {
74
- _Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
75
- fs.ensureDirSync(resultsDir);
76
- const path = `${resultsDir}/${options.outputFileId}.json`;
77
- await fs.writeJson(path, result, {
78
- spaces: 2
79
- });
80
- } else {
81
- console.log("result:", result);
82
- }
83
- const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
84
- if (hasPayloadToAppend && options.outputFileId) {
85
- _Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
86
- fs.ensureDirSync(resultsDir);
87
- const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
88
- await fs.writeJson(path, payloadToAppend, {
89
- spaces: 2
90
- });
91
- } else if (hasPayloadToAppend) {
92
- _Logger.logger.info("payload to append:", payloadToAppend);
93
- _Logger.logger.info("This will only take an effect if this API run was part of a job.");
94
- }
95
136
  }
96
- _commander.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 _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
97
- let inputData = null;
98
- if (options.input) {
99
- inputData = await fs.readJSON(options.input);
100
- } else if (options.json) {
101
- inputData = JSON.parse(options.json);
102
- } else {
103
- inputData = {};
104
- }
105
- await (0, _asyncLocalStorage.runWithContext)({
106
- runEnvironment: _enums.RunEnvironment.IDE,
107
- extendedPayloads: [],
108
- runId: (0, _nanoid.nanoid)(),
109
- proxy: options.proxy
110
- }, () => executeCLI(apiName, mode, inputData, options));
111
- process.exit(0);
137
+ program
138
+ .description("run the user function in the cli for testing purposes")
139
+ .option("-i, --input [file]", "input json file")
140
+ .option("-j, --json [json]", "input json string")
141
+ .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
142
+ .option("--authSessionPath <authSession>", "auth session to use when executing the api")
143
+ .option("--outputFileId <outputFileId>", "the output file id to save the result in")
144
+ .option("--proxy <proxy>", "proxy to use")
145
+ .argument("[apiName]", "name of the api", "default")
146
+ .allowUnknownOption()
147
+ .addArgument(new Argument("<mode>", "mode of execution")
148
+ .choices([
149
+ "vanilla",
150
+ "playwright",
151
+ "playwright-standalone",
152
+ "playwright-headless",
153
+ ])
154
+ .default("playwright-standalone")
155
+ .argOptional())
156
+ .action(async (apiName, mode, options) => {
157
+ let inputData = null;
158
+ if (options.input) {
159
+ inputData = await fs.readJSON(options.input);
160
+ }
161
+ else if (options.json) {
162
+ inputData = JSON.parse(options.json);
163
+ }
164
+ else {
165
+ inputData = {};
166
+ }
167
+ await runWithContext({
168
+ runEnvironment: RunEnvironment.IDE,
169
+ extendedPayloads: [],
170
+ runId: nanoid(),
171
+ proxy: options.proxy,
172
+ }, () => executeCLI(apiName, mode, inputData, options));
173
+ // playwright keeps an open handle to the connected browser and it stops the process from exiting
174
+ // there is no way to close the connection gracefully without destroying the context/browser
175
+ // https://github.com/microsoft/playwright/issues/4956
176
+ process.exit(0);
112
177
  });
113
- _commander.program.parse(process.argv);
178
+ program.parse(process.argv);
@@ -0,0 +1,105 @@
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,32 +1,30 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _commander = require("commander");
5
- var _getPlaywrightConstructs = require("../../common/getPlaywrightConstructs");
6
- var _settings = require("../common/utils/settings");
7
- var _dotenv = _interopRequireDefault(require("dotenv"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- _dotenv.default.config({
10
- path: `.env`
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`,
11
9
  });
12
- _commander.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 ({
13
- cdpAddress,
14
- authSessionPath
15
- }) => {
16
- const setting = await (0, _settings.getSettings)();
17
- if (!setting.authSessions.enabled) {
18
- throw new Error("Auth session is not enabled");
19
- }
20
- const {
21
- context
22
- } = await (0, _getPlaywrightConstructs.getRemotePlaywrightContext)(cdpAddress);
23
- await (0, _getPlaywrightConstructs.loadSessionToContext)({
24
- context,
25
- session: {
26
- type: "file",
27
- path: authSessionPath
10
+ program
11
+ .description("load auth session to browser")
12
+ .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
13
+ .option("--authSessionPath <authSession>", "auth session to use when executing the api")
14
+ .allowUnknownOption()
15
+ .action(async ({ cdpAddress, authSessionPath, }) => {
16
+ const setting = await getSettings();
17
+ if (!setting.authSessions.enabled) {
18
+ throw new Error("Auth session is not enabled");
28
19
  }
29
- });
30
- process.exit(0);
20
+ const { context } = await getRemotePlaywrightContext(cdpAddress);
21
+ await loadSessionToContext({
22
+ context,
23
+ session: {
24
+ type: "file",
25
+ path: authSessionPath,
26
+ },
27
+ });
28
+ process.exit(0);
31
29
  });
32
- _commander.program.parse(process.argv);
30
+ program.parse(process.argv);
@@ -0,0 +1,30 @@
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,56 +1,57 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _commander = require("commander");
5
- var fs = _interopRequireWildcard(require("fs-extra"));
6
- var _fileUtils = require("../common/utils/fileUtils");
7
- var _settings = require("../common/utils/settings");
8
- var _dotenv = _interopRequireDefault(require("dotenv"));
9
- var _constants = require("../../common/constants");
10
- var _runApi = require("../../common/runApi");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
- _dotenv.default.config({
15
- path: `.env`
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`,
16
11
  });
17
- _commander.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 _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
18
- cdpAddress,
19
- authSessionPath
20
- }) => {
21
- const setting = await (0, _settings.getSettings)();
22
- if (!setting.authSessions.enabled) {
23
- throw new Error("auth session is not enabled");
24
- }
25
- const checkFilePath = (0, _fileUtils.getFullPathInProject)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
26
- if (!fs.exists(checkFilePath)) {
27
- throw new Error("auth session check file not found");
28
- }
29
- const runApiResult = await (0, _runApi.runApi)({
30
- automationFunction: {
31
- name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
32
- },
33
- runOptions: {
34
- environment: "ide",
35
- mode,
36
- cdpAddress
37
- },
38
- auth: {
39
- session: {
40
- type: "file",
41
- path: authSessionPath
42
- },
43
- runCheck: false
12
+ program
13
+ .description("run auth session check")
14
+ .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
15
+ .option("--authSessionPath <authSession>", "auth session to use when executing the check")
16
+ .allowUnknownOption()
17
+ .addArgument(new Argument("<mode>", "mode of execution")
18
+ .choices(["vanilla", "playwright", "playwright-standalone"])
19
+ .default("playwright-standalone")
20
+ .argOptional())
21
+ .action(async (mode, { cdpAddress, authSessionPath, }) => {
22
+ const setting = await getSettings();
23
+ if (!setting.authSessions.enabled) {
24
+ throw new Error("auth session is not enabled");
44
25
  }
45
- });
46
- if (runApiResult.isErr()) {
47
- throw new Error(runApiResult.error);
48
- }
49
- const result = runApiResult.value.result;
50
- console.log("check result", result);
51
- if (!result) {
52
- throw new Error("auth session check failed");
53
- }
54
- process.exit(0);
26
+ const checkFilePath = getFullPathInProject(AUTH_SESSIONS_FOLDER_NAME, "check");
27
+ if (!fs.exists(checkFilePath)) {
28
+ throw new Error("auth session check file not found");
29
+ }
30
+ const runApiResult = await runApi({
31
+ automationFunction: {
32
+ name: `${AUTH_SESSIONS_FOLDER_NAME}/check`,
33
+ },
34
+ runOptions: {
35
+ environment: "ide",
36
+ mode,
37
+ cdpAddress,
38
+ },
39
+ auth: {
40
+ session: {
41
+ type: "file",
42
+ path: authSessionPath,
43
+ },
44
+ runCheck: false,
45
+ },
46
+ });
47
+ if (runApiResult.isErr()) {
48
+ throw new Error(runApiResult.error);
49
+ }
50
+ const result = runApiResult.value.result;
51
+ console.log("check result", result);
52
+ if (!result) {
53
+ throw new Error("auth session check failed");
54
+ }
55
+ process.exit(0);
55
56
  });
56
- _commander.program.parse(process.argv);
57
+ program.parse(process.argv);