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

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 (100) hide show
  1. package/.babelrc +0 -1
  2. package/dist/commands/api/run.js +156 -83
  3. package/dist/commands/api/run.ts +105 -0
  4. package/dist/commands/auth-sessions/load.js +20 -20
  5. package/dist/commands/auth-sessions/load.ts +30 -0
  6. package/dist/commands/auth-sessions/run-check.js +45 -39
  7. package/dist/commands/auth-sessions/run-check.ts +51 -0
  8. package/dist/commands/auth-sessions/run-create.js +84 -74
  9. package/dist/commands/auth-sessions/run-create.ts +91 -0
  10. package/dist/commands/browser/save-state.js +12 -7
  11. package/dist/commands/browser/save-state.ts +14 -0
  12. package/dist/commands/browser/start-browser.js +7 -4
  13. package/dist/commands/browser/start-browser.ts +11 -0
  14. package/dist/commands/build.js +97 -61
  15. package/dist/commands/build.ts +78 -0
  16. package/dist/commands/common/browserUtils.js +42 -31
  17. package/dist/commands/common/browserUtils.ts +45 -0
  18. package/dist/commands/common/getDefaultExportFromFile.js +11 -10
  19. package/dist/commands/common/getDefaultExportFromFile.ts +11 -0
  20. package/dist/commands/common/getFirstLineNumber.js +90 -83
  21. package/dist/commands/common/{getFirstLineNumber.test.js → getFirstLineNumber.test.ts} +2 -2
  22. package/dist/commands/common/getFirstLineNumber.ts +96 -0
  23. package/dist/commands/common/sendMessageToClient.js +4 -2
  24. package/dist/commands/common/sendMessageToClient.ts +3 -0
  25. package/dist/commands/common/utils/fileUtils.js +16 -16
  26. package/dist/commands/common/utils/fileUtils.ts +23 -0
  27. package/dist/commands/common/utils/settings.js +17 -19
  28. package/dist/commands/common/utils/settings.ts +22 -0
  29. package/dist/commands/common/utils/unixSocket.js +43 -36
  30. package/dist/commands/common/utils/unixSocket.ts +38 -0
  31. package/dist/commands/common/utils/webTemplate.js +25 -18
  32. package/dist/commands/common/utils/webTemplate.ts +22 -0
  33. package/dist/commands/interface/run.js +139 -133
  34. package/dist/commands/interface/run.ts +156 -0
  35. package/dist/commands/ts-check.js +45 -41
  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 +40 -46
  39. package/dist/common/Logger/Logger/index.ts +53 -0
  40. package/dist/common/Logger/Logger/types.js +1 -1
  41. package/dist/common/Logger/index.d.ts +1 -1
  42. package/dist/common/Logger/index.js +40 -46
  43. package/dist/common/Logger/index.ts +53 -0
  44. package/dist/common/Logger/types.js +1 -1
  45. package/dist/common/asyncLocalStorage/index.js +4 -4
  46. package/dist/common/asyncLocalStorage/index.ts +9 -0
  47. package/dist/common/cleanEnvironmentVariables.js +11 -9
  48. package/dist/common/cleanEnvironmentVariables.ts +10 -0
  49. package/dist/common/constants.js +1 -1
  50. package/dist/common/constants.ts +1 -0
  51. package/dist/common/contextStorageStateHelpers.js +36 -38
  52. package/dist/common/contextStorageStateHelpers.ts +43 -0
  53. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  54. package/dist/common/getPlaywrightConstructs.js +187 -157
  55. package/dist/common/getPlaywrightConstructs.ts +181 -0
  56. package/dist/common/jwtTokenManager.js +74 -61
  57. package/dist/common/jwtTokenManager.ts +71 -0
  58. package/dist/common/runApi/errors.d.ts +1 -1
  59. package/dist/common/runApi/errors.js +130 -121
  60. package/dist/common/runApi/errors.ts +154 -0
  61. package/dist/common/runApi/index.d.ts +4 -4
  62. package/dist/common/runApi/index.js +219 -233
  63. package/dist/common/runApi/index.ts +253 -0
  64. package/dist/common/runApi/types.d.ts +1 -1
  65. package/dist/common/runApi/types.js +55 -41
  66. package/dist/common/runApi/types.ts +43 -0
  67. package/dist/common/settingsSchema.js +9 -6
  68. package/dist/common/settingsSchema.ts +9 -0
  69. package/dist/common/telemetry.js +27 -16
  70. package/dist/common/telemetry.ts +23 -0
  71. package/dist/index.d.ts +4 -4
  72. package/dist/index.js +4 -4
  73. package/dist/index.ts +4 -0
  74. package/dist/runtime/RunError.d.ts +1 -1
  75. package/dist/runtime/RunError.js +10 -10
  76. package/dist/runtime/RunError.ts +12 -0
  77. package/dist/runtime/downloadDirectory.js +10 -10
  78. package/dist/runtime/downloadDirectory.ts +13 -0
  79. package/dist/runtime/enums.d.ts +1 -11
  80. package/dist/runtime/enums.js +12 -12
  81. package/dist/runtime/enums.ts +12 -0
  82. package/dist/runtime/{executionHelpers.test.js → executionHelpers.test.ts} +2 -2
  83. package/dist/runtime/export.d.ts +1 -202
  84. package/dist/runtime/extendPayload.d.ts +1 -1
  85. package/dist/runtime/extendPayload.js +13 -13
  86. package/dist/runtime/extendPayload.ts +15 -0
  87. package/dist/runtime/extendTimeout.js +19 -20
  88. package/dist/runtime/extendTimeout.ts +24 -0
  89. package/dist/runtime/index.d.ts +7 -7
  90. package/dist/runtime/index.js +6 -6
  91. package/dist/runtime/index.ts +6 -0
  92. package/dist/runtime/requestMoreInfo.js +14 -14
  93. package/dist/runtime/requestMoreInfo.ts +18 -0
  94. package/dist/runtime/runInfo.d.ts +1 -1
  95. package/dist/runtime/runInfo.js +12 -13
  96. package/dist/runtime/runInfo.ts +15 -0
  97. package/package.json +3 -2
  98. package/tsconfig.json +1 -1
  99. /package/dist/{runtime/enums.d.js → common/Logger/Logger/types.ts} +0 -0
  100. /package/dist/{runtime/export.d.js → common/Logger/types.ts} +0 -0
package/.babelrc CHANGED
@@ -13,7 +13,6 @@
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"
@@ -12,94 +12,167 @@ 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
- 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");
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;
24
29
  }
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");
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
+ }
29
35
  }
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
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;
47
104
  }
48
- });
49
- if (runApiResult.isErr()) {
50
- if (runApiResult.error instanceof AutomationError) {
51
- 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.");
52
135
  }
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
136
  }
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);
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);
104
177
  });
105
- 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);
@@ -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.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
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");
26
19
  }
27
- });
28
- 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);
29
29
  });
30
- 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);
@@ -7,45 +7,51 @@ 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.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
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");
39
25
  }
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);
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);
50
56
  });
51
- program.parse(process.argv);
57
+ program.parse(process.argv);
@@ -0,0 +1,51 @@
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);