@intuned/runtime-dev 0.0.1-split.7 → 0.0.1
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/.vscode/extensions.json +3 -0
- package/.vscode/launch.json +102 -0
- package/.vscode/settings.json +12 -0
- package/WebTemplate/controllers/authSessions/create.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +3 -1
- package/package.json +1 -2
- package/playwright.config.ts +48 -0
- package/src/commands/api/run.ts +225 -0
- package/src/commands/auth-sessions/load.ts +42 -0
- package/src/commands/auth-sessions/run-check.ts +70 -0
- package/src/commands/auth-sessions/run-create.ts +124 -0
- package/src/commands/browser/save-state.ts +22 -0
- package/src/commands/browser/start-browser.ts +17 -0
- package/src/commands/build.ts +125 -0
- package/src/commands/common/browserUtils.ts +80 -0
- package/src/commands/common/getDefaultExportFromFile.ts +13 -0
- package/{dist/commands/common/getFirstLineNumber.test.js → src/commands/common/getFirstLineNumber.test.ts} +121 -75
- package/src/commands/common/getFirstLineNumber.ts +146 -0
- package/src/commands/common/sendMessageToClient.ts +8 -0
- package/src/commands/common/utils/fileUtils.ts +25 -0
- package/src/commands/common/utils/settings.ts +23 -0
- package/src/commands/common/utils/webTemplate.ts +46 -0
- package/src/commands/testing/saveVisibleHtml.ts +29 -0
- package/src/commands/ts-check.ts +88 -0
- package/src/common/Logger/Logger/index.ts +64 -0
- package/{dist/common/Logger/types.d.ts → src/common/Logger/Logger/types.ts} +5 -4
- package/src/common/Logger/index.ts +64 -0
- package/{dist/common/Logger/Logger/types.d.ts → src/common/Logger/types.ts} +5 -4
- package/src/common/asyncLocalStorage/index.ts +29 -0
- package/src/common/cleanEnvironmentVariables.ts +13 -0
- package/src/common/constants.ts +1 -0
- package/src/common/contextStorageStateHelpers.ts +71 -0
- package/src/common/getPlaywrightConstructs.ts +283 -0
- package/src/common/jwtTokenManager.ts +111 -0
- package/src/common/settingsSchema.ts +16 -0
- package/src/common/telemetry.ts +49 -0
- package/src/index.ts +14 -0
- package/src/runtime/RunError.ts +16 -0
- package/src/runtime/downloadDirectory.ts +14 -0
- package/src/runtime/enums.ts +11 -0
- package/src/runtime/executionHelpers.test.ts +70 -0
- package/src/runtime/extendPayload.ts +22 -0
- package/src/runtime/extendTimeout.ts +32 -0
- package/{dist/runtime/index.d.ts → src/runtime/index.ts} +3 -1
- package/src/runtime/requestMoreInfo.ts +40 -0
- package/src/runtime/runInfo.ts +19 -0
- package/vite.config.ts +17 -0
- package/bin/intuned-api-run +0 -2
- package/bin/intuned-auth-session-check +0 -2
- package/bin/intuned-auth-session-create +0 -2
- package/bin/intuned-auth-session-load +0 -2
- package/bin/intuned-auth-session-refresh +0 -2
- package/bin/intuned-browser-save-state +0 -2
- package/bin/intuned-browser-start +0 -2
- package/bin/intuned-build +0 -2
- package/bin/intuned-ts-check +0 -2
- package/dist/commands/api/run.d.ts +0 -6
- package/dist/commands/api/run.js +0 -135
- package/dist/commands/auth-sessions/load.d.ts +0 -2
- package/dist/commands/auth-sessions/load.js +0 -26
- package/dist/commands/auth-sessions/run-check.d.ts +0 -2
- package/dist/commands/auth-sessions/run-check.js +0 -42
- package/dist/commands/auth-sessions/run-create.d.ts +0 -2
- package/dist/commands/auth-sessions/run-create.js +0 -75
- package/dist/commands/browser/save-state.d.ts +0 -2
- package/dist/commands/browser/save-state.js +0 -17
- package/dist/commands/browser/start-browser.d.ts +0 -2
- package/dist/commands/browser/start-browser.js +0 -14
- package/dist/commands/build.d.ts +0 -2
- package/dist/commands/build.js +0 -80
- package/dist/commands/common/browserUtils.d.ts +0 -14
- package/dist/commands/common/browserUtils.js +0 -58
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
- package/dist/commands/common/getDefaultExportFromFile.js +0 -19
- package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
- package/dist/commands/common/getFirstLineNumber.js +0 -103
- package/dist/commands/common/sendMessageToClient.d.ts +0 -1
- package/dist/commands/common/sendMessageToClient.js +0 -10
- package/dist/commands/common/utils/fileUtils.d.ts +0 -6
- package/dist/commands/common/utils/fileUtils.js +0 -33
- package/dist/commands/common/utils/settings.d.ts +0 -2
- package/dist/commands/common/utils/settings.js +0 -28
- package/dist/commands/common/utils/webTemplate.d.ts +0 -1
- package/dist/commands/common/utils/webTemplate.js +0 -31
- package/dist/commands/testing/saveVisibleHtml.d.ts +0 -1
- package/dist/commands/testing/saveVisibleHtml.js +0 -24
- package/dist/commands/ts-check.d.ts +0 -2
- package/dist/commands/ts-check.js +0 -54
- package/dist/common/Logger/Logger/index.d.ts +0 -12
- package/dist/common/Logger/Logger/index.js +0 -60
- package/dist/common/Logger/Logger/types.js +0 -5
- package/dist/common/Logger/index.d.ts +0 -12
- package/dist/common/Logger/index.js +0 -60
- package/dist/common/Logger/types.js +0 -5
- package/dist/common/asyncLocalStorage/index.d.ts +0 -16
- package/dist/common/asyncLocalStorage/index.js +0 -17
- package/dist/common/cleanEnvironmentVariables.d.ts +0 -1
- package/dist/common/cleanEnvironmentVariables.js +0 -16
- package/dist/common/constants.d.ts +0 -1
- package/dist/common/constants.js +0 -7
- package/dist/common/contextStorageStateHelpers.d.ts +0 -15
- package/dist/common/contextStorageStateHelpers.js +0 -48
- package/dist/common/getPlaywrightConstructs.d.ts +0 -28
- package/dist/common/getPlaywrightConstructs.js +0 -175
- package/dist/common/jwtTokenManager.d.ts +0 -16
- package/dist/common/jwtTokenManager.js +0 -81
- package/dist/common/settingsSchema.d.ts +0 -19
- package/dist/common/settingsSchema.js +0 -17
- package/dist/common/telemetry.d.ts +0 -3
- package/dist/common/telemetry.js +0 -32
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -69
- package/dist/runtime/RunError.d.ts +0 -5
- package/dist/runtime/RunError.js +0 -19
- package/dist/runtime/downloadDirectory.d.ts +0 -1
- package/dist/runtime/downloadDirectory.js +0 -19
- package/dist/runtime/enums.d.js +0 -5
- package/dist/runtime/enums.js +0 -18
- package/dist/runtime/executionHelpers.test.js +0 -53
- package/dist/runtime/export.d.js +0 -5
- package/dist/runtime/extendPayload.d.ts +0 -2
- package/dist/runtime/extendPayload.js +0 -21
- package/dist/runtime/extendTimeout.d.ts +0 -1
- package/dist/runtime/extendTimeout.js +0 -26
- package/dist/runtime/index.js +0 -53
- package/dist/runtime/requestMoreInfo.d.ts +0 -17
- package/dist/runtime/requestMoreInfo.js +0 -25
- package/dist/runtime/runInfo.d.ts +0 -2
- package/dist/runtime/runInfo.js +0 -21
- /package/{dist → src}/common/assets/browser_scripts.js +0 -0
- /package/{dist → src}/runtime/enums.d.ts +0 -0
- /package/{dist → src}/runtime/export.d.ts +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Use IntelliSense to learn about possible attributes.
|
|
3
|
+
// Hover to view descriptions of existing attributes.
|
|
4
|
+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"name": "Hiltion api",
|
|
9
|
+
"type": "node",
|
|
10
|
+
"request": "launch",
|
|
11
|
+
"runtimeExecutable": "node",
|
|
12
|
+
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
|
|
13
|
+
|
|
14
|
+
"args": ["src/commands/api/run.ts", "hilton", "-j", "{}", "playwright"],
|
|
15
|
+
|
|
16
|
+
"cwd": "${workspaceRoot}",
|
|
17
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
18
|
+
"skipFiles": ["<node_internals>/**", "node_modules/**"]
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"name": "Books Extractor",
|
|
22
|
+
"type": "node",
|
|
23
|
+
"request": "launch",
|
|
24
|
+
"runtimeExecutable": "node",
|
|
25
|
+
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
|
|
26
|
+
|
|
27
|
+
"args": [
|
|
28
|
+
"src/commands/api/run.ts",
|
|
29
|
+
"books-array",
|
|
30
|
+
"-j",
|
|
31
|
+
"{}",
|
|
32
|
+
"playwright"
|
|
33
|
+
],
|
|
34
|
+
|
|
35
|
+
"cwd": "${workspaceRoot}",
|
|
36
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
37
|
+
"skipFiles": ["<node_internals>/**", "node_modules/**"]
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"name": "Run execution-info",
|
|
41
|
+
"type": "node",
|
|
42
|
+
"request": "launch",
|
|
43
|
+
"runtimeExecutable": "node",
|
|
44
|
+
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
|
|
45
|
+
|
|
46
|
+
"args": [
|
|
47
|
+
"src/commands/api/run.ts",
|
|
48
|
+
"execution-info",
|
|
49
|
+
"-j",
|
|
50
|
+
"{}",
|
|
51
|
+
"playwright"
|
|
52
|
+
],
|
|
53
|
+
|
|
54
|
+
"cwd": "${workspaceRoot}",
|
|
55
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
56
|
+
"skipFiles": ["<node_internals>/**", "node_modules/**"]
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "Run progressive",
|
|
60
|
+
"type": "node",
|
|
61
|
+
"request": "launch",
|
|
62
|
+
"runtimeExecutable": "node",
|
|
63
|
+
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
|
|
64
|
+
|
|
65
|
+
"args": [
|
|
66
|
+
"src/commands/api/run.ts",
|
|
67
|
+
"progressive",
|
|
68
|
+
"-j",
|
|
69
|
+
"{}",
|
|
70
|
+
"playwright"
|
|
71
|
+
],
|
|
72
|
+
|
|
73
|
+
"cwd": "${workspaceRoot}",
|
|
74
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
75
|
+
"skipFiles": ["<node_internals>/**", "node_modules/**"]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"name": "Run progressive - standalone",
|
|
79
|
+
"type": "node",
|
|
80
|
+
"request": "launch",
|
|
81
|
+
"runtimeExecutable": "node",
|
|
82
|
+
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
|
|
83
|
+
|
|
84
|
+
"args": ["src/commands/api/run.ts", "progressive", "-j", "{}"],
|
|
85
|
+
"cwd": "${workspaceRoot}",
|
|
86
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
87
|
+
"skipFiles": ["<node_internals>/**", "node_modules/**"]
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
"name": "Run progressive extract - standalone",
|
|
91
|
+
"type": "node",
|
|
92
|
+
"request": "launch",
|
|
93
|
+
"runtimeExecutable": "node",
|
|
94
|
+
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
|
|
95
|
+
|
|
96
|
+
"args": ["src/commands/api/run.ts", "progressive-extract", "-j", "{}"],
|
|
97
|
+
"cwd": "${workspaceRoot}",
|
|
98
|
+
"internalConsoleOptions": "openOnSessionStart",
|
|
99
|
+
"skipFiles": ["<node_internals>/**", "node_modules/**"]
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"editor.formatOnSave": true,
|
|
3
|
+
"cSpell.words": ["backcompat", "ـget", "INFINITI", "neverthrow"],
|
|
4
|
+
"editor.detectIndentation": true,
|
|
5
|
+
"files.exclude": {
|
|
6
|
+
"dist": false,
|
|
7
|
+
"node_modules": false,
|
|
8
|
+
"output": false,
|
|
9
|
+
"intuned": false,
|
|
10
|
+
"htmlFiles": true
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { authSessionsContextsStore } from "./store";
|
|
2
2
|
import { AUTH_SESSIONS_FOLDER_NAME } from "@intuned/runtime/dist/common/constants";
|
|
3
3
|
import { getDownloadDirectoryPath } from "@intuned/runtime";
|
|
4
|
-
import { getProductionPlaywrightConstructs } from "
|
|
4
|
+
import { getProductionPlaywrightConstructs } from "../../../src/common/getPlaywrightConstructs";
|
|
5
5
|
import { callFunction, getTraceFilePath, isHeadless } from "../../utils";
|
|
6
6
|
import * as fs from "fs-extra";
|
|
7
7
|
import { getContextStorageState } from "@intuned/runtime/dist/common/contextStorageStateHelpers";
|
|
@@ -8,6 +8,8 @@ import { IntunedSettings } from "@intuned/runtime/dist/common/settingsSchema";
|
|
|
8
8
|
import { getDownloadDirectoryPath } from "@intuned/runtime";
|
|
9
9
|
import { getProductionPlaywrightConstructs } from "@intuned/runtime";
|
|
10
10
|
import * as fs from "fs-extra";
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
import { PayloadItem } from "../../../src/common/types";
|
|
11
13
|
import { getTelemetryClient } from "@intuned/runtime/dist/common/telemetry";
|
|
12
14
|
import { getExecutionContext } from "@intuned/runtime";
|
|
13
15
|
import { backendFunctionsTokenManager } from "@intuned/runtime/dist/common/jwtTokenManager";
|
|
@@ -172,7 +174,7 @@ export async function runApi({
|
|
|
172
174
|
const response: {
|
|
173
175
|
result: any;
|
|
174
176
|
updatedSession?: object;
|
|
175
|
-
payloadToAppend:
|
|
177
|
+
payloadToAppend: PayloadItem[] | null;
|
|
176
178
|
// TODO: remove
|
|
177
179
|
metadata?: {
|
|
178
180
|
startTime: number;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"version": "0.0.1
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"./dist/common/cleanEnvironmentVariables": "./dist/common/cleanEnvironmentVariables.js",
|
|
14
14
|
"./dist/common/constants": "./dist/common/constants.js"
|
|
15
15
|
},
|
|
16
|
-
"types": "./dist/index.d.ts",
|
|
17
16
|
"author": "Intuned Team",
|
|
18
17
|
"license": "MIT",
|
|
19
18
|
"scripts": {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { defineConfig, devices } from "@intuned/playwright-test";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Read environment variables from file.
|
|
5
|
+
* https://github.com/motdotla/dotenv
|
|
6
|
+
*/
|
|
7
|
+
// require('dotenv').config();
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* See https://playwright.dev/docs/test-configuration.
|
|
11
|
+
*/
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
testDir: "./e2e-tests",
|
|
14
|
+
/* Run tests in files in parallel */
|
|
15
|
+
fullyParallel: true,
|
|
16
|
+
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
17
|
+
forbidOnly: !!process.env.CI,
|
|
18
|
+
/* Retry on CI only */
|
|
19
|
+
retries: process.env.CI ? 2 : 0,
|
|
20
|
+
/* Opt out of parallel tests on CI. */
|
|
21
|
+
workers: process.env.CI ? 1 : undefined,
|
|
22
|
+
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
23
|
+
reporter: "html",
|
|
24
|
+
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
25
|
+
use: {
|
|
26
|
+
/* Base URL to use in actions like `await page.goto('/')`. */
|
|
27
|
+
// baseURL: 'http://127.0.0.1:3000',
|
|
28
|
+
|
|
29
|
+
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
30
|
+
trace: "on-first-retry",
|
|
31
|
+
// headless: false,
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
/* Configure projects for major browsers */
|
|
35
|
+
projects: [
|
|
36
|
+
{
|
|
37
|
+
name: "chromium",
|
|
38
|
+
use: { ...devices["Desktop Chrome"] },
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
|
|
42
|
+
/* Run your local dev server before starting the tests */
|
|
43
|
+
// webServer: {
|
|
44
|
+
// command: 'npm run start',
|
|
45
|
+
// url: 'http://127.0.0.1:3000',
|
|
46
|
+
// reuseExistingServer: !process.env.CI,
|
|
47
|
+
// },
|
|
48
|
+
});
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program, Argument } from "commander";
|
|
3
|
+
import * as fs from "fs-extra";
|
|
4
|
+
import { getDefaultExportFromFile } from "../common/getDefaultExportFromFile";
|
|
5
|
+
import { getFullPathInProject } from "../common/utils/fileUtils";
|
|
6
|
+
import { getSettings } from "../common/utils/settings";
|
|
7
|
+
import getFirstLineNumber from "../common/getFirstLineNumber";
|
|
8
|
+
import { sendBreakPointOnToClient } from "../common/sendMessageToClient";
|
|
9
|
+
import dotenv from "dotenv";
|
|
10
|
+
import {
|
|
11
|
+
getExecutionContext,
|
|
12
|
+
runWithContext,
|
|
13
|
+
} from "../../common/asyncLocalStorage";
|
|
14
|
+
import { RunEnvironment } from "../../runtime/enums";
|
|
15
|
+
import { cleanEnvironmentVariables } from "../../common/cleanEnvironmentVariables";
|
|
16
|
+
import { logger } from "../../common/Logger";
|
|
17
|
+
import { nanoid } from "nanoid";
|
|
18
|
+
import chalk from "chalk";
|
|
19
|
+
import { getDownloadDirectoryPath } from "../../runtime";
|
|
20
|
+
import { getPlaywrightConstructsForMode } from "../../common/getPlaywrightConstructs";
|
|
21
|
+
|
|
22
|
+
dotenv.config({
|
|
23
|
+
path: `.env`,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
export async function executeCLI(
|
|
27
|
+
apiName: string,
|
|
28
|
+
mode:
|
|
29
|
+
| "vanilla"
|
|
30
|
+
| "playwright"
|
|
31
|
+
| "playwright-standalone"
|
|
32
|
+
| "playwright-headless",
|
|
33
|
+
inputData: object | null | undefined,
|
|
34
|
+
options: {
|
|
35
|
+
cdpAddress: string;
|
|
36
|
+
authSessionPath: undefined | string;
|
|
37
|
+
outputFileId: string | undefined;
|
|
38
|
+
}
|
|
39
|
+
) {
|
|
40
|
+
// cleanup environment variables before running the user code
|
|
41
|
+
cleanEnvironmentVariables();
|
|
42
|
+
// Path to the TypeScript file
|
|
43
|
+
const apiFilePath = getFullPathInProject("api", `${apiName}.ts`);
|
|
44
|
+
|
|
45
|
+
let authSessionPathToUse: string | null = null;
|
|
46
|
+
|
|
47
|
+
// check auth session
|
|
48
|
+
const settings = await getSettings();
|
|
49
|
+
|
|
50
|
+
if (settings.authSessions.enabled) {
|
|
51
|
+
// if auth session enabled, check if the auth session is provided
|
|
52
|
+
if (!options.authSessionPath) {
|
|
53
|
+
throw new Error("Auth session is enabled but no auth session provided");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
authSessionPathToUse = options.authSessionPath as string;
|
|
57
|
+
} else {
|
|
58
|
+
// if auth session is not enabled, check if the auth session is provided
|
|
59
|
+
if (options.authSessionPath) {
|
|
60
|
+
throw new Error(
|
|
61
|
+
"Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json"
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Dynamically import the TypeScript file
|
|
67
|
+
const defaultExport = await getDefaultExportFromFile(apiFilePath);
|
|
68
|
+
const isDebug = process.execArgv.some((arg) => arg.includes("--inspect"));
|
|
69
|
+
if (isDebug) {
|
|
70
|
+
const { sourceFileName, lineNumber } = await getFirstLineNumber(
|
|
71
|
+
apiFilePath
|
|
72
|
+
);
|
|
73
|
+
sendBreakPointOnToClient(sourceFileName, lineNumber);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (mode === "vanilla") {
|
|
77
|
+
// Execute the function with the input data
|
|
78
|
+
const result = await defaultExport(inputData);
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { page, context } = await getPlaywrightConstructsForMode(
|
|
83
|
+
mode,
|
|
84
|
+
options.cdpAddress,
|
|
85
|
+
authSessionPathToUse ? authSessionPathToUse : undefined
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// wait for the page to get stable, this is a workaround for a bug in playwright when you try to do something
|
|
89
|
+
// on a page after connecting to it immediately, the page needs some time to get stable.
|
|
90
|
+
let isPageStable = false;
|
|
91
|
+
let retry = 0;
|
|
92
|
+
// will wait maximum 2 seconds before failing.
|
|
93
|
+
while (!isPageStable && retry < 10) {
|
|
94
|
+
try {
|
|
95
|
+
await page.locator("html").all();
|
|
96
|
+
isPageStable = true;
|
|
97
|
+
break;
|
|
98
|
+
} catch (error) {
|
|
99
|
+
if (error?.message?.includes("Execution context was destroyed")) {
|
|
100
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
101
|
+
} else {
|
|
102
|
+
// throwing to make sure we do not hide any other unexpected issues.
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
retry++;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!isPageStable) {
|
|
110
|
+
throw new Error("The page is not stable, try to run again.");
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const result = await defaultExport(inputData, page, context);
|
|
114
|
+
const downloadsPath = getDownloadDirectoryPath();
|
|
115
|
+
await fs.remove(downloadsPath);
|
|
116
|
+
if (mode == "playwright") {
|
|
117
|
+
await context.close();
|
|
118
|
+
}
|
|
119
|
+
const isResponseObject = typeof result === "object" && result !== null;
|
|
120
|
+
|
|
121
|
+
const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
|
|
122
|
+
const hasNestedObjects =
|
|
123
|
+
isResponseObject &&
|
|
124
|
+
Object.values(result).some((value) => typeof value === "object");
|
|
125
|
+
|
|
126
|
+
const shouldWriteToFile =
|
|
127
|
+
isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
|
|
128
|
+
|
|
129
|
+
const resultsDir = "/tmp/run-results";
|
|
130
|
+
|
|
131
|
+
if (options.outputFileId && shouldWriteToFile) {
|
|
132
|
+
logger.info(
|
|
133
|
+
chalk.underline.bgBlue.white(
|
|
134
|
+
`Click to Open: Results saved (Run: ${options.outputFileId})`
|
|
135
|
+
)
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
fs.ensureDirSync(resultsDir);
|
|
139
|
+
const path = `${resultsDir}/${options.outputFileId}.json`;
|
|
140
|
+
await fs.writeJson(path, result, {
|
|
141
|
+
spaces: 2,
|
|
142
|
+
});
|
|
143
|
+
} else {
|
|
144
|
+
console.log("result:", result);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const payloadToAppend = getExecutionContext()?.extendedPayloads;
|
|
148
|
+
const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
|
|
149
|
+
|
|
150
|
+
if (hasPayloadToAppend && options.outputFileId) {
|
|
151
|
+
logger.info(
|
|
152
|
+
chalk.underline.bgBlue.white(
|
|
153
|
+
`Click to Open: payloads to append (Run: ${options.outputFileId})`
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
fs.ensureDirSync(resultsDir);
|
|
158
|
+
|
|
159
|
+
const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
|
|
160
|
+
await fs.writeJson(path, payloadToAppend, {
|
|
161
|
+
spaces: 2,
|
|
162
|
+
});
|
|
163
|
+
} else if (hasPayloadToAppend) {
|
|
164
|
+
logger.info("payload to append:", payloadToAppend);
|
|
165
|
+
logger.info(
|
|
166
|
+
"This will only take an effect if this API run was part of a job."
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
program
|
|
172
|
+
.description("run the user function in the cli for testing purposes")
|
|
173
|
+
.option("-i, --input [file]", "input json file")
|
|
174
|
+
.option("-j, --json [json]", "input json string")
|
|
175
|
+
.option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
|
|
176
|
+
.option(
|
|
177
|
+
"--authSessionPath <authSession>",
|
|
178
|
+
"auth session to use when executing the api"
|
|
179
|
+
)
|
|
180
|
+
.option(
|
|
181
|
+
"--outputFileId <outputFileId>",
|
|
182
|
+
"the output file id to save the result in"
|
|
183
|
+
)
|
|
184
|
+
.option("--proxy <proxy>", "proxy to use")
|
|
185
|
+
.argument("[apiName]", "name of the api", "default")
|
|
186
|
+
.allowUnknownOption()
|
|
187
|
+
.addArgument(
|
|
188
|
+
new Argument("<mode>", "mode of execution")
|
|
189
|
+
.choices([
|
|
190
|
+
"vanilla",
|
|
191
|
+
"playwright",
|
|
192
|
+
"playwright-standalone",
|
|
193
|
+
"playwright-headless",
|
|
194
|
+
])
|
|
195
|
+
.default("playwright-standalone")
|
|
196
|
+
.argOptional()
|
|
197
|
+
)
|
|
198
|
+
.action(async (apiName, mode, options) => {
|
|
199
|
+
let inputData: null | object = null;
|
|
200
|
+
|
|
201
|
+
if (options.input) {
|
|
202
|
+
inputData = await fs.readJSON(options.input);
|
|
203
|
+
} else if (options.json) {
|
|
204
|
+
inputData = JSON.parse(options.json);
|
|
205
|
+
} else {
|
|
206
|
+
inputData = {};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
await runWithContext(
|
|
210
|
+
{
|
|
211
|
+
runEnvironment: RunEnvironment.IDE,
|
|
212
|
+
extendedPayloads: [],
|
|
213
|
+
runId: nanoid(),
|
|
214
|
+
proxy: options.proxy,
|
|
215
|
+
},
|
|
216
|
+
() => executeCLI(apiName, mode, inputData as object, options)
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// playwright keeps an open handle to the connected browser and it stops the process from exiting
|
|
220
|
+
// there is no way to close the connection gracefully without destroying the context/browser
|
|
221
|
+
// https://github.com/microsoft/playwright/issues/4956
|
|
222
|
+
process.exit(0);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import { getRemotePlaywrightContext } from "../../common/getPlaywrightConstructs";
|
|
4
|
+
import { getSettings } from "../common/utils/settings";
|
|
5
|
+
|
|
6
|
+
import dotenv from "dotenv";
|
|
7
|
+
import { loadAuthSessionToContext } from "../../common/getPlaywrightConstructs";
|
|
8
|
+
|
|
9
|
+
dotenv.config({
|
|
10
|
+
path: `.env`,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
program
|
|
14
|
+
.description("load auth session to browser")
|
|
15
|
+
.option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
|
|
16
|
+
.option(
|
|
17
|
+
"--authSessionPath <authSession>",
|
|
18
|
+
"auth session to use when executing the api"
|
|
19
|
+
)
|
|
20
|
+
.allowUnknownOption()
|
|
21
|
+
.action(
|
|
22
|
+
async ({
|
|
23
|
+
cdpAddress,
|
|
24
|
+
authSessionPath,
|
|
25
|
+
}: {
|
|
26
|
+
cdpAddress: string;
|
|
27
|
+
authSessionPath: string;
|
|
28
|
+
}) => {
|
|
29
|
+
const setting = await getSettings();
|
|
30
|
+
|
|
31
|
+
if (!setting.authSessions.enabled) {
|
|
32
|
+
throw new Error("Auth session is not enabled");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const { context } = await getRemotePlaywrightContext(cdpAddress);
|
|
36
|
+
await loadAuthSessionToContext(context, authSessionPath);
|
|
37
|
+
|
|
38
|
+
process.exit(0);
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Argument, program } from "commander";
|
|
3
|
+
import { getDefaultExportFromFile } from "../common/getDefaultExportFromFile";
|
|
4
|
+
import * as fs from "fs-extra";
|
|
5
|
+
import { getFullPathInProject } from "../common/utils/fileUtils";
|
|
6
|
+
import { getSettings } from "../common/utils/settings";
|
|
7
|
+
import dotenv from "dotenv";
|
|
8
|
+
import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
|
|
9
|
+
import { getPlaywrightConstructsForMode } from "../../common/getPlaywrightConstructs";
|
|
10
|
+
|
|
11
|
+
dotenv.config({
|
|
12
|
+
path: `.env`,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
program
|
|
16
|
+
.description("run auth session check")
|
|
17
|
+
.option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
|
|
18
|
+
.option(
|
|
19
|
+
"--authSessionPath <authSession>",
|
|
20
|
+
"auth session to use when executing the check"
|
|
21
|
+
)
|
|
22
|
+
.allowUnknownOption()
|
|
23
|
+
.addArgument(
|
|
24
|
+
new Argument("<mode>", "mode of execution")
|
|
25
|
+
.choices(["vanilla", "playwright", "playwright-standalone"])
|
|
26
|
+
.default("playwright-standalone")
|
|
27
|
+
.argOptional()
|
|
28
|
+
)
|
|
29
|
+
.action(
|
|
30
|
+
async (
|
|
31
|
+
mode: "vanilla" | "playwright" | "playwright-standalone",
|
|
32
|
+
{
|
|
33
|
+
cdpAddress,
|
|
34
|
+
authSessionPath,
|
|
35
|
+
}: { cdpAddress: string; authSessionPath?: string }
|
|
36
|
+
) => {
|
|
37
|
+
const setting = await getSettings();
|
|
38
|
+
if (!setting.authSessions.enabled) {
|
|
39
|
+
throw new Error("auth session is not enabled");
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const checkFilePath = getFullPathInProject(
|
|
43
|
+
AUTH_SESSIONS_FOLDER_NAME,
|
|
44
|
+
"check.ts"
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (!fs.exists(checkFilePath)) {
|
|
48
|
+
throw new Error("auth session check file not found");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Dynamically import the TypeScript file
|
|
52
|
+
const defaultExport = await getDefaultExportFromFile(checkFilePath);
|
|
53
|
+
const { page, context } = await getPlaywrightConstructsForMode(
|
|
54
|
+
mode,
|
|
55
|
+
cdpAddress,
|
|
56
|
+
authSessionPath
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const result: boolean = await defaultExport(page, context);
|
|
60
|
+
console.log("check result", result);
|
|
61
|
+
|
|
62
|
+
if (!result) {
|
|
63
|
+
throw new Error("auth session check failed");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
process.exit(0);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
program.parse(process.argv);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Argument, program } from "commander";
|
|
3
|
+
import { getDefaultExportFromFile } from "../common/getDefaultExportFromFile";
|
|
4
|
+
import * as fs from "fs-extra";
|
|
5
|
+
import { saveSession } from "../common/browserUtils";
|
|
6
|
+
import { prompt } from "promptly";
|
|
7
|
+
import { getFullPathInProject } from "../common/utils/fileUtils";
|
|
8
|
+
import { getSettings } from "../common/utils/settings";
|
|
9
|
+
import dotenv from "dotenv";
|
|
10
|
+
import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
|
|
11
|
+
import { getPlaywrightConstructsForMode } from "../../common/getPlaywrightConstructs";
|
|
12
|
+
|
|
13
|
+
dotenv.config({
|
|
14
|
+
path: `.env`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
program
|
|
18
|
+
.description("run auth session create")
|
|
19
|
+
.option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
|
|
20
|
+
.option("-i, --input [file]", "input json file")
|
|
21
|
+
.option("-j, --json [json]", "input json string")
|
|
22
|
+
.option(
|
|
23
|
+
"--authSessionPath <authSession>",
|
|
24
|
+
"auth session to use when executing the api"
|
|
25
|
+
)
|
|
26
|
+
.option(
|
|
27
|
+
"--pathToSave <pathToSave>",
|
|
28
|
+
"path to save the auth session, if not provided, will discard the auth session"
|
|
29
|
+
)
|
|
30
|
+
.allowUnknownOption()
|
|
31
|
+
.addArgument(
|
|
32
|
+
new Argument("<mode>", "mode of execution")
|
|
33
|
+
.choices(["vanilla", "playwright", "playwright-standalone"])
|
|
34
|
+
.default("playwright-standalone")
|
|
35
|
+
.argOptional()
|
|
36
|
+
)
|
|
37
|
+
.action(
|
|
38
|
+
async (
|
|
39
|
+
mode: "vanilla" | "playwright" | "playwright-standalone",
|
|
40
|
+
{
|
|
41
|
+
cdpAddress,
|
|
42
|
+
pathToSave,
|
|
43
|
+
input,
|
|
44
|
+
json,
|
|
45
|
+
}: {
|
|
46
|
+
cdpAddress: string;
|
|
47
|
+
pathToSave: string | undefined;
|
|
48
|
+
input: string;
|
|
49
|
+
json: string;
|
|
50
|
+
}
|
|
51
|
+
) => {
|
|
52
|
+
let inputData: null | object = null;
|
|
53
|
+
if (input) {
|
|
54
|
+
inputData = await fs.readJSON(input);
|
|
55
|
+
} else if (json) {
|
|
56
|
+
inputData = JSON.parse(json);
|
|
57
|
+
} else {
|
|
58
|
+
inputData = {};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const setting = await getSettings();
|
|
62
|
+
|
|
63
|
+
if (!setting.authSessions.enabled) {
|
|
64
|
+
throw new Error("auth sessions feature is not enabled");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const createFilePath = getFullPathInProject(
|
|
68
|
+
AUTH_SESSIONS_FOLDER_NAME,
|
|
69
|
+
"create.ts"
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (!fs.exists(createFilePath)) {
|
|
73
|
+
throw new Error("auth session create file not found");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Dynamically import the TypeScript file
|
|
77
|
+
const defaultExport = await getDefaultExportFromFile(createFilePath);
|
|
78
|
+
const { page, context } = await getPlaywrightConstructsForMode(
|
|
79
|
+
mode,
|
|
80
|
+
cdpAddress
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const generator = await defaultExport(inputData, page, context, false);
|
|
84
|
+
let nextGeneratorParam: string | undefined = undefined;
|
|
85
|
+
|
|
86
|
+
// eslint-disable-next-line no-constant-condition
|
|
87
|
+
while (true) {
|
|
88
|
+
const { value, done } = await generator.next(nextGeneratorParam);
|
|
89
|
+
|
|
90
|
+
if (done) {
|
|
91
|
+
if (pathToSave) {
|
|
92
|
+
await saveSession(pathToSave, context);
|
|
93
|
+
}
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (
|
|
98
|
+
value.action === "request_more_info" &&
|
|
99
|
+
value.requestType == "multiple_choice"
|
|
100
|
+
) {
|
|
101
|
+
nextGeneratorParam = await prompt(
|
|
102
|
+
value.messageToUser + `, choices: ${value.choices}`,
|
|
103
|
+
{
|
|
104
|
+
validator: (input) => {
|
|
105
|
+
if (!value.choices.includes(input)) {
|
|
106
|
+
throw new Error("Please type on of the allowed choices");
|
|
107
|
+
}
|
|
108
|
+
return input;
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
);
|
|
112
|
+
} else if (
|
|
113
|
+
value.action === "request_more_info" &&
|
|
114
|
+
value.requestType == "otp"
|
|
115
|
+
) {
|
|
116
|
+
nextGeneratorParam = await prompt(value.messageToUser, {});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
process.exit(0);
|
|
121
|
+
}
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
program.parse(process.argv);
|