@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.
- package/bin/intuned-api-run +1 -1
- package/bin/intuned-auth-session-check +1 -1
- package/bin/intuned-auth-session-create +1 -1
- package/bin/intuned-auth-session-load +1 -1
- package/bin/intuned-auth-session-refresh +1 -1
- package/bin/intuned-browser-save-state +1 -1
- package/bin/intuned-browser-start +1 -1
- package/bin/intuned-build +1 -1
- package/bin/intuned-ts-check +1 -1
- package/dist/commands/api/run.js +83 -156
- package/dist/commands/auth-sessions/load.js +20 -20
- package/dist/commands/auth-sessions/run-check.js +39 -45
- package/dist/commands/auth-sessions/run-create.js +74 -84
- package/dist/commands/browser/save-state.js +7 -12
- package/dist/commands/browser/start-browser.js +4 -7
- package/dist/commands/build.js +62 -96
- package/dist/commands/common/browserUtils.js +30 -41
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
- package/dist/commands/common/getDefaultExportFromFile.js +0 -12
- package/dist/commands/common/getFirstLineNumber.js +83 -90
- package/dist/commands/common/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +2 -1
- package/dist/commands/common/sendMessageToClient.js +2 -4
- package/dist/commands/common/utils/fileUtils.js +16 -16
- package/dist/commands/common/utils/settings.js +18 -16
- package/dist/commands/common/utils/unixSocket.js +36 -43
- package/dist/commands/common/utils/webTemplate.js +19 -25
- package/dist/commands/interface/run.js +133 -139
- package/dist/commands/ts-check.js +41 -44
- package/dist/common/Logger/Logger/index.js +46 -40
- package/dist/common/Logger/Logger/types.js +1 -1
- package/dist/common/Logger/index.js +46 -40
- package/dist/common/Logger/types.js +1 -1
- package/dist/common/asyncLocalStorage/index.js +4 -4
- package/dist/common/cleanEnvironmentVariables.js +9 -11
- package/dist/common/constants.js +1 -1
- package/dist/common/contextStorageStateHelpers.js +38 -36
- package/dist/common/getPlaywrightConstructs.js +158 -187
- package/dist/common/jwtTokenManager.js +61 -74
- package/dist/common/runApi/errors.js +121 -130
- package/dist/common/runApi/index.js +231 -217
- package/dist/common/runApi/types.js +41 -55
- package/dist/common/settingsSchema.js +6 -9
- package/dist/common/telemetry.js +16 -27
- package/dist/index.js +3 -3
- package/dist/runtime/RunError.js +10 -10
- package/dist/runtime/downloadDirectory.js +10 -10
- package/dist/runtime/enums.d.ts +11 -1
- package/dist/runtime/enums.js +12 -12
- package/dist/runtime/export.d.ts +202 -1
- package/dist/runtime/extendPayload.js +12 -12
- package/dist/runtime/extendTimeout.js +20 -19
- package/dist/runtime/index.js +1 -1
- package/dist/runtime/requestMoreInfo.js +14 -14
- package/dist/runtime/runInfo.js +12 -11
- package/package.json +2 -3
- package/dist/commands/api/run.ts +0 -105
- package/dist/commands/auth-sessions/load.ts +0 -30
- package/dist/commands/auth-sessions/run-check.ts +0 -51
- package/dist/commands/auth-sessions/run-create.ts +0 -91
- package/dist/commands/browser/save-state.ts +0 -14
- package/dist/commands/browser/start-browser.ts +0 -11
- package/dist/commands/build.ts +0 -78
- package/dist/commands/common/browserUtils.ts +0 -45
- package/dist/commands/common/getDefaultExportFromFile.ts +0 -11
- package/dist/commands/common/getFirstLineNumber.ts +0 -96
- package/dist/commands/common/sendMessageToClient.ts +0 -3
- package/dist/commands/common/utils/fileUtils.ts +0 -23
- package/dist/commands/common/utils/settings.ts +0 -22
- package/dist/commands/common/utils/unixSocket.ts +0 -38
- package/dist/commands/common/utils/webTemplate.ts +0 -22
- package/dist/commands/interface/run.ts +0 -156
- package/dist/commands/ts-check.ts +0 -50
- package/dist/common/Logger/Logger/index.ts +0 -53
- package/dist/common/Logger/index.ts +0 -53
- package/dist/common/asyncLocalStorage/index.ts +0 -9
- package/dist/common/cleanEnvironmentVariables.ts +0 -10
- package/dist/common/constants.ts +0 -1
- package/dist/common/contextStorageStateHelpers.ts +0 -43
- package/dist/common/getPlaywrightConstructs.ts +0 -181
- package/dist/common/jwtTokenManager.ts +0 -71
- package/dist/common/runApi/errors.ts +0 -154
- package/dist/common/runApi/index.ts +0 -253
- package/dist/common/runApi/types.ts +0 -43
- package/dist/common/settingsSchema.ts +0 -9
- package/dist/common/telemetry.ts +0 -23
- package/dist/index.ts +0 -4
- package/dist/runtime/RunError.ts +0 -12
- package/dist/runtime/downloadDirectory.ts +0 -13
- package/dist/runtime/enums.ts +0 -12
- package/dist/runtime/extendPayload.ts +0 -15
- package/dist/runtime/extendTimeout.ts +0 -24
- package/dist/runtime/index.ts +0 -6
- package/dist/runtime/requestMoreInfo.ts +0 -18
- package/dist/runtime/runInfo.ts +0 -15
- /package/dist/{common/Logger/Logger/types.ts → runtime/enums.d.js} +0 -0
- /package/dist/runtime/{executionHelpers.test.ts → executionHelpers.test.js} +0 -0
- /package/dist/{common/Logger/types.ts → runtime/export.d.js} +0 -0
package/bin/intuned-api-run
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
void import("../dist/commands/api/run.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
void import("../dist/commands/auth-sessions/run-check.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
void import("../dist/commands/auth-sessions/run-create.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
void import("../dist/commands/auth-sessions/load.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
void import("../dist/commands/auth-sessions/run-refresh.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
void import("../dist/commands/browser/save-state.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
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
|
-
|
|
2
|
+
void import("../dist/commands/build.js");
|
package/bin/intuned-ts-check
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
void import("../dist/commands/ts-check.js");
|
package/dist/commands/api/run.js
CHANGED
|
@@ -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
|
-
|
|
15
|
+
path: `.env`
|
|
16
16
|
});
|
|
17
17
|
export async function executeCLI(apiName, mode, inputData, options) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
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
|
-
|
|
8
|
+
path: `.env`
|
|
9
9
|
});
|
|
10
|
-
program
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
10
|
+
path: `.env`
|
|
11
11
|
});
|
|
12
|
-
program
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
14
|
+
path: `.env`
|
|
15
15
|
});
|
|
16
|
-
program
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
6
|
+
path: `.env`
|
|
7
7
|
});
|
|
8
|
-
program
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
6
|
+
path: `.env`
|
|
7
7
|
});
|
|
8
|
-
program
|
|
9
|
-
|
|
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);
|