@intuned/runtime-dev 0.1.0-test.14 → 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 +61 -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/sendMessageToClient.js +2 -4
  22. package/dist/commands/common/utils/fileUtils.js +16 -16
  23. package/dist/commands/common/utils/settings.js +18 -16
  24. package/dist/commands/common/utils/unixSocket.js +36 -43
  25. package/dist/commands/common/utils/webTemplate.js +18 -25
  26. package/dist/commands/interface/run.js +133 -139
  27. package/dist/commands/ts-check.js +40 -44
  28. package/dist/common/Logger/Logger/index.js +46 -40
  29. package/dist/common/Logger/Logger/types.js +1 -1
  30. package/dist/common/Logger/index.js +46 -40
  31. package/dist/common/Logger/types.js +1 -1
  32. package/dist/common/asyncLocalStorage/index.js +4 -4
  33. package/dist/common/cleanEnvironmentVariables.js +9 -11
  34. package/dist/common/constants.js +1 -1
  35. package/dist/common/contextStorageStateHelpers.js +38 -36
  36. package/dist/common/getPlaywrightConstructs.js +156 -186
  37. package/dist/common/jwtTokenManager.js +61 -74
  38. package/dist/common/runApi/errors.js +121 -130
  39. package/dist/common/runApi/index.js +231 -217
  40. package/dist/common/runApi/types.js +41 -55
  41. package/dist/common/settingsSchema.js +6 -9
  42. package/dist/common/telemetry.js +16 -27
  43. package/dist/index.js +3 -3
  44. package/dist/runtime/RunError.js +10 -10
  45. package/dist/runtime/downloadDirectory.js +10 -10
  46. package/dist/runtime/enums.d.ts +11 -1
  47. package/dist/runtime/enums.js +12 -12
  48. package/dist/runtime/export.d.ts +202 -1
  49. package/dist/runtime/extendPayload.js +12 -12
  50. package/dist/runtime/extendTimeout.js +20 -19
  51. package/dist/runtime/index.js +1 -1
  52. package/dist/runtime/requestMoreInfo.js +14 -14
  53. package/dist/runtime/runInfo.js +12 -11
  54. package/package.json +2 -3
  55. package/dist/commands/api/run.ts +0 -105
  56. package/dist/commands/auth-sessions/load.ts +0 -30
  57. package/dist/commands/auth-sessions/run-check.ts +0 -51
  58. package/dist/commands/auth-sessions/run-create.ts +0 -91
  59. package/dist/commands/browser/save-state.ts +0 -14
  60. package/dist/commands/browser/start-browser.ts +0 -11
  61. package/dist/commands/build.ts +0 -79
  62. package/dist/commands/common/browserUtils.ts +0 -45
  63. package/dist/commands/common/getDefaultExportFromFile.ts +0 -11
  64. package/dist/commands/common/getFirstLineNumber.ts +0 -96
  65. package/dist/commands/common/sendMessageToClient.ts +0 -3
  66. package/dist/commands/common/utils/fileUtils.ts +0 -23
  67. package/dist/commands/common/utils/settings.ts +0 -22
  68. package/dist/commands/common/utils/unixSocket.ts +0 -38
  69. package/dist/commands/common/utils/webTemplate.ts +0 -23
  70. package/dist/commands/interface/run.ts +0 -156
  71. package/dist/commands/ts-check.ts +0 -51
  72. package/dist/common/Logger/Logger/index.ts +0 -53
  73. package/dist/common/Logger/index.ts +0 -53
  74. package/dist/common/asyncLocalStorage/index.ts +0 -9
  75. package/dist/common/cleanEnvironmentVariables.ts +0 -10
  76. package/dist/common/constants.ts +0 -1
  77. package/dist/common/contextStorageStateHelpers.ts +0 -43
  78. package/dist/common/getPlaywrightConstructs.ts +0 -182
  79. package/dist/common/jwtTokenManager.ts +0 -71
  80. package/dist/common/runApi/errors.ts +0 -154
  81. package/dist/common/runApi/index.ts +0 -253
  82. package/dist/common/runApi/types.ts +0 -43
  83. package/dist/common/settingsSchema.ts +0 -9
  84. package/dist/common/telemetry.ts +0 -23
  85. package/dist/index.ts +0 -4
  86. package/dist/runtime/RunError.ts +0 -12
  87. package/dist/runtime/downloadDirectory.ts +0 -13
  88. package/dist/runtime/enums.ts +0 -12
  89. package/dist/runtime/extendPayload.ts +0 -15
  90. package/dist/runtime/extendTimeout.ts +0 -24
  91. package/dist/runtime/index.ts +0 -6
  92. package/dist/runtime/requestMoreInfo.ts +0 -18
  93. package/dist/runtime/runInfo.ts +0 -15
  94. /package/dist/commands/common/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +0 -0
  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,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/api/run.js");
2
+ void import("../dist/commands/api/run.js");
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/auth-sessions/run-check.js");
2
+ void import("../dist/commands/auth-sessions/run-check.js");
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/auth-sessions/run-create.js");
2
+ void import("../dist/commands/auth-sessions/run-create.js");
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/auth-sessions/load.js");
2
+ void import("../dist/commands/auth-sessions/load.js");
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/auth-sessions/run-refresh.js");
2
+ void import("../dist/commands/auth-sessions/run-refresh.js");
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/browser/save-state.js");
2
+ void import("../dist/commands/browser/save-state.js");
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/browser/start-browser.js");
2
+ void import("../dist/commands/browser/start-browser.js");
package/bin/intuned-build CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/build.js");
2
+ void import("../dist/commands/build.js");
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require("../dist/commands/ts-check.js");
2
+ void import("../dist/commands/ts-check.js");
@@ -12,167 +12,94 @@ import chalk from "chalk";
12
12
  import { runApi } from "../../common/runApi";
13
13
  import { AutomationError } from "../../common/runApi";
14
14
  dotenv.config({
15
- path: `.env`,
15
+ path: `.env`
16
16
  });
17
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;
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");
29
24
  }
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
- }
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");
35
29
  }
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;
104
- }
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);
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
122
47
  }
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.");
48
+ });
49
+ if (runApiResult.isErr()) {
50
+ if (runApiResult.error instanceof AutomationError) {
51
+ throw runApiResult.error.error;
135
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
+ }
136
87
  }
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);
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);
177
104
  });
178
- program.parse(process.argv);
105
+ program.parse(process.argv);
@@ -5,26 +5,26 @@ import { getSettings } from "../common/utils/settings";
5
5
  import dotenv from "dotenv";
6
6
  import { loadSessionToContext } from "../../common/getPlaywrightConstructs";
7
7
  dotenv.config({
8
- path: `.env`,
8
+ path: `.env`
9
9
  });
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");
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
19
26
  }
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);
27
+ });
28
+ process.exit(0);
29
29
  });
30
- program.parse(process.argv);
30
+ program.parse(process.argv);
@@ -7,51 +7,45 @@ import dotenv from "dotenv";
7
7
  import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
8
8
  import { runApi } from "../../common/runApi";
9
9
  dotenv.config({
10
- path: `.env`,
10
+ path: `.env`
11
11
  });
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");
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
25
39
  }
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);
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);
56
50
  });
57
- program.parse(process.argv);
51
+ program.parse(process.argv);
@@ -11,91 +11,81 @@ import { runWithContext } from "../../common/asyncLocalStorage";
11
11
  import { nanoid } from "nanoid";
12
12
  import { RunEnvironment } from "../../runtime/enums";
13
13
  dotenv.config({
14
- path: `.env`,
14
+ path: `.env`
15
15
  });
16
- program
17
- .description("run auth session create")
18
- .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
19
- .option("-i, --input [file]", "input json file")
20
- .option("-j, --json [json]", "input json string")
21
- .option("--authSessionPath <authSession>", "auth session to use when executing the api")
22
- .option("--pathToSave <pathToSave>", "path to save the auth session, if not provided, will discard the auth session")
23
- .allowUnknownOption()
24
- .addArgument(new Argument("<mode>", "mode of execution")
25
- .choices(["vanilla", "playwright", "playwright-standalone"])
26
- .default("playwright-standalone")
27
- .argOptional())
28
- .action(async (mode, { cdpAddress, pathToSave, input, json, }) => {
29
- let inputData = null;
30
- if (input) {
31
- inputData = await fs.readJSON(input);
32
- }
33
- else if (json) {
34
- inputData = JSON.parse(json);
35
- }
36
- else {
37
- inputData = {};
38
- }
39
- const setting = await getSettings();
40
- if (!setting.authSessions.enabled) {
41
- throw new Error("auth sessions feature is not enabled");
42
- }
43
- const createFilePath = getFullPathInProject(AUTH_SESSIONS_FOLDER_NAME, "create.ts");
44
- if (!fs.exists(createFilePath)) {
45
- throw new Error("auth session create file not found");
46
- }
47
- async function runCreate() {
48
- const generator = runApiGenerator({
49
- automationFunction: {
50
- name: "auth-sessions/create",
51
- params: inputData ?? {},
52
- },
53
- runOptions: {
54
- environment: "ide",
55
- mode,
56
- cdpAddress,
57
- },
58
- retrieveSession: true,
59
- });
60
- let nextGeneratorParam = undefined;
61
- // eslint-disable-next-line no-constant-condition
62
- while (true) {
63
- const { value, done } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
64
- if (done) {
65
- if (value.isErr()) {
66
- console.log(value.error);
67
- throw new Error(value.error);
68
- }
69
- const fullState = value.value.session;
70
- if (pathToSave) {
71
- const fullPath = getFullPathInProject(pathToSave);
72
- fs.ensureFileSync(fullPath);
73
- await fs.writeJSON(fullPath, fullState);
74
- }
75
- break;
76
- }
77
- if (value.action === "request_more_info" &&
78
- value.requestType == "multiple_choice") {
79
- nextGeneratorParam = await prompt(value.messageToUser + `, choices: ${value.choices}`, {
80
- validator: (input) => {
81
- if (!value.choices.includes(input)) {
82
- throw new Error("Please type on of the allowed choices");
83
- }
84
- return input;
85
- },
86
- });
87
- }
88
- else if (value.action === "request_more_info" &&
89
- value.requestType == "otp") {
90
- nextGeneratorParam = await prompt(value.messageToUser, {});
91
- }
16
+ program.description("run auth session create").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--pathToSave <pathToSave>", "path to save the auth session, if not provided, will discard the auth session").allowUnknownOption().addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
17
+ cdpAddress,
18
+ pathToSave,
19
+ input,
20
+ json
21
+ }) => {
22
+ let inputData = null;
23
+ if (input) {
24
+ inputData = await fs.readJSON(input);
25
+ } else if (json) {
26
+ inputData = JSON.parse(json);
27
+ } else {
28
+ inputData = {};
29
+ }
30
+ const setting = await getSettings();
31
+ if (!setting.authSessions.enabled) {
32
+ throw new Error("auth sessions feature is not enabled");
33
+ }
34
+ const createFilePath = getFullPathInProject(AUTH_SESSIONS_FOLDER_NAME, "create.ts");
35
+ if (!fs.exists(createFilePath)) {
36
+ throw new Error("auth session create file not found");
37
+ }
38
+ async function runCreate() {
39
+ const generator = runApiGenerator({
40
+ automationFunction: {
41
+ name: "auth-sessions/create",
42
+ params: inputData ?? {}
43
+ },
44
+ runOptions: {
45
+ environment: "ide",
46
+ mode,
47
+ cdpAddress
48
+ },
49
+ retrieveSession: true
50
+ });
51
+ let nextGeneratorParam = undefined;
52
+ while (true) {
53
+ const {
54
+ value,
55
+ done
56
+ } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
57
+ if (done) {
58
+ if (value.isErr()) {
59
+ console.log(value.error);
60
+ throw new Error(value.error);
92
61
  }
62
+ const fullState = value.value.session;
63
+ if (pathToSave) {
64
+ const fullPath = getFullPathInProject(pathToSave);
65
+ fs.ensureFileSync(fullPath);
66
+ await fs.writeJSON(fullPath, fullState);
67
+ }
68
+ break;
69
+ }
70
+ if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
71
+ nextGeneratorParam = await prompt(value.messageToUser + `, choices: ${value.choices}`, {
72
+ validator: input => {
73
+ if (!value.choices.includes(input)) {
74
+ throw new Error("Please type on of the allowed choices");
75
+ }
76
+ return input;
77
+ }
78
+ });
79
+ } else if (value.action === "request_more_info" && value.requestType == "otp") {
80
+ nextGeneratorParam = await prompt(value.messageToUser, {});
81
+ }
93
82
  }
94
- await runWithContext({
95
- runEnvironment: RunEnvironment.IDE,
96
- extendedPayloads: [],
97
- runId: nanoid(),
98
- }, runCreate);
99
- process.exit(0);
83
+ }
84
+ await runWithContext({
85
+ runEnvironment: RunEnvironment.IDE,
86
+ extendedPayloads: [],
87
+ runId: nanoid()
88
+ }, runCreate);
89
+ process.exit(0);
100
90
  });
101
- program.parse(process.argv);
91
+ program.parse(process.argv);
@@ -3,17 +3,12 @@ import { program } from "commander";
3
3
  import { saveSessionFromOpenedBrowser } from "../common/browserUtils";
4
4
  import dotenv from "dotenv";
5
5
  dotenv.config({
6
- path: `.env`,
6
+ path: `.env`
7
7
  });
8
- program
9
- .description("save browser state to file storage.json")
10
- .option("-p, --path [file]", "path for file", "./localSessions/default.json")
11
- .allowUnknownOption()
12
- .action(async ({ path }) => {
13
- await saveSessionFromOpenedBrowser(path);
14
- // playwright keeps an open handle to the connected browser and it stops the process from exiting
15
- // there is no way to close the connection gracefully without destroying the context/browser
16
- // https://github.com/microsoft/playwright/issues/4956
17
- process.exit(0);
8
+ program.description("save browser state to file storage.json").option("-p, --path [file]", "path for file", "./localSessions/default.json").allowUnknownOption().action(async ({
9
+ path
10
+ }) => {
11
+ await saveSessionFromOpenedBrowser(path);
12
+ process.exit(0);
18
13
  });
19
- program.parse(process.argv);
14
+ program.parse(process.argv);
@@ -3,12 +3,9 @@ import { program } from "commander";
3
3
  import { startOrRestartBrowser } from "../common/browserUtils";
4
4
  import dotenv from "dotenv";
5
5
  dotenv.config({
6
- path: `.env`,
6
+ path: `.env`
7
7
  });
8
- program
9
- .description("start browser testing purposes")
10
- .allowUnknownOption()
11
- .action(async () => {
12
- await startOrRestartBrowser();
8
+ program.description("start browser testing purposes").allowUnknownOption().action(async () => {
9
+ await startOrRestartBrowser();
13
10
  });
14
- program.parse(process.argv);
11
+ program.parse(process.argv);