@intuned/runtime-dev 0.0.1 → 0.1.0-test.0
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/InterfaceTemplate/index.ts +1 -0
- package/Intuned.json +5 -0
- package/WebTemplate/api.ts +92 -90
- package/WebTemplate/controllers/authSessions/check.ts +23 -29
- package/WebTemplate/controllers/authSessions/create.ts +46 -71
- package/WebTemplate/controllers/authSessions/index.ts +4 -4
- package/WebTemplate/controllers/authSessions/killOperation.ts +1 -1
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +28 -52
- package/WebTemplate/controllers/authSessions/store.ts +11 -6
- package/WebTemplate/controllers/runApi/helpers.ts +47 -146
- package/WebTemplate/index.playwright.ts +42 -32
- package/WebTemplate/index.vanilla.ts +2 -20
- package/WebTemplate/jobs.ts +2 -13
- package/WebTemplate/utils.ts +1 -85
- package/WebTemplate.zip +0 -0
- package/api/authed.ts +12 -0
- package/api/test.ts +3 -0
- package/api/test2.ts +25 -0
- package/auth-sessions/check.ts +9 -0
- package/auth-sessions/create.ts +32 -0
- package/authSessions +1 -0
- package/bin/intuned-api-run +2 -0
- package/bin/intuned-auth-session-check +2 -0
- package/bin/intuned-auth-session-create +2 -0
- package/bin/intuned-auth-session-load +2 -0
- package/bin/intuned-auth-session-refresh +2 -0
- package/bin/intuned-browser-save-state +2 -0
- package/bin/intuned-browser-start +2 -0
- package/bin/intuned-build +2 -0
- package/bin/intuned-ts-check +2 -0
- package/dist/commands/api/run.d.ts +6 -0
- package/dist/commands/api/run.js +113 -0
- package/dist/commands/auth-sessions/load.d.ts +2 -0
- package/dist/commands/auth-sessions/load.js +32 -0
- package/dist/commands/auth-sessions/run-check.d.ts +2 -0
- package/dist/commands/auth-sessions/run-check.js +56 -0
- package/dist/commands/auth-sessions/run-create.d.ts +2 -0
- package/dist/commands/auth-sessions/run-create.js +96 -0
- package/dist/commands/browser/save-state.d.ts +2 -0
- package/dist/commands/browser/save-state.js +17 -0
- package/dist/commands/browser/start-browser.d.ts +2 -0
- package/dist/commands/browser/start-browser.js +14 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +83 -0
- package/dist/commands/common/browserUtils.d.ts +14 -0
- package/dist/commands/common/browserUtils.js +58 -0
- package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
- package/dist/commands/common/getDefaultExportFromFile.js +19 -0
- package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
- package/dist/commands/common/getFirstLineNumber.js +103 -0
- package/{src/commands/common/getFirstLineNumber.test.ts → dist/commands/common/getFirstLineNumber.test.js} +75 -121
- package/dist/commands/common/sendMessageToClient.d.ts +1 -0
- package/dist/commands/common/sendMessageToClient.js +10 -0
- package/dist/commands/common/utils/fileUtils.d.ts +6 -0
- package/dist/commands/common/utils/fileUtils.js +33 -0
- package/dist/commands/common/utils/settings.d.ts +2 -0
- package/dist/commands/common/utils/settings.js +28 -0
- package/dist/commands/common/utils/unixSocket.d.ts +9 -0
- package/dist/commands/common/utils/unixSocket.js +45 -0
- package/dist/commands/common/utils/webTemplate.d.ts +1 -0
- package/dist/commands/common/utils/webTemplate.js +31 -0
- package/dist/commands/interface/run.d.ts +2 -0
- package/dist/commands/interface/run.js +161 -0
- package/dist/commands/ts-check.d.ts +2 -0
- package/dist/commands/ts-check.js +54 -0
- package/dist/common/Logger/Logger/index.d.ts +12 -0
- package/dist/common/Logger/Logger/index.js +60 -0
- package/{src/common/Logger/Logger/types.ts → dist/common/Logger/Logger/types.d.ts} +4 -5
- package/dist/common/Logger/Logger/types.js +5 -0
- package/dist/common/Logger/index.d.ts +12 -0
- package/dist/common/Logger/index.js +60 -0
- package/{src/common/Logger/types.ts → dist/common/Logger/types.d.ts} +4 -5
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/asyncLocalStorage/index.d.ts +16 -0
- package/dist/common/asyncLocalStorage/index.js +17 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
- package/dist/common/cleanEnvironmentVariables.js +16 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +7 -0
- package/dist/common/contextStorageStateHelpers.d.ts +14 -0
- package/dist/common/contextStorageStateHelpers.js +50 -0
- package/dist/common/getPlaywrightConstructs.d.ts +30 -0
- package/dist/common/getPlaywrightConstructs.js +192 -0
- package/dist/common/jwtTokenManager.d.ts +16 -0
- package/dist/common/jwtTokenManager.js +81 -0
- package/dist/common/runApi/errors.d.ts +71 -0
- package/dist/common/runApi/errors.js +172 -0
- package/dist/common/runApi/index.d.ts +12 -0
- package/dist/common/runApi/index.js +288 -0
- package/dist/common/runApi/types.d.ts +486 -0
- package/dist/common/runApi/types.js +50 -0
- package/dist/common/settingsSchema.d.ts +19 -0
- package/dist/common/settingsSchema.js +17 -0
- package/dist/common/telemetry.d.ts +3 -0
- package/dist/common/telemetry.js +32 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +69 -0
- package/dist/runtime/RunError.d.ts +5 -0
- package/dist/runtime/RunError.js +19 -0
- package/dist/runtime/downloadDirectory.d.ts +1 -0
- package/dist/runtime/downloadDirectory.js +19 -0
- package/dist/runtime/enums.d.js +5 -0
- package/dist/runtime/enums.js +18 -0
- package/dist/runtime/executionHelpers.test.js +53 -0
- package/dist/runtime/export.d.js +5 -0
- package/dist/runtime/extendPayload.d.ts +2 -0
- package/dist/runtime/extendPayload.js +21 -0
- package/dist/runtime/extendTimeout.d.ts +1 -0
- package/dist/runtime/extendTimeout.js +30 -0
- package/{src/runtime/index.ts → dist/runtime/index.d.ts} +2 -3
- package/dist/runtime/index.js +53 -0
- package/dist/runtime/requestMoreInfo.d.ts +18 -0
- package/dist/runtime/requestMoreInfo.js +25 -0
- package/dist/runtime/runInfo.d.ts +2 -0
- package/dist/runtime/runInfo.js +21 -0
- package/output.txt +39 -0
- package/package.json +9 -7
- package/testing +0 -0
- package/tsconfig.json +2 -1
- package/.vite/deps_temp_01af7156/package.json +0 -3
- package/.vscode/extensions.json +0 -3
- package/.vscode/launch.json +0 -102
- package/.vscode/settings.json +0 -12
- package/playwright.config.ts +0 -48
- package/src/commands/api/run.ts +0 -225
- package/src/commands/auth-sessions/load.ts +0 -42
- package/src/commands/auth-sessions/run-check.ts +0 -70
- package/src/commands/auth-sessions/run-create.ts +0 -124
- package/src/commands/browser/save-state.ts +0 -22
- package/src/commands/browser/start-browser.ts +0 -17
- package/src/commands/build.ts +0 -125
- package/src/commands/common/browserUtils.ts +0 -80
- package/src/commands/common/getDefaultExportFromFile.ts +0 -13
- package/src/commands/common/getFirstLineNumber.ts +0 -146
- package/src/commands/common/sendMessageToClient.ts +0 -8
- package/src/commands/common/utils/fileUtils.ts +0 -25
- package/src/commands/common/utils/settings.ts +0 -23
- package/src/commands/common/utils/webTemplate.ts +0 -46
- package/src/commands/testing/saveVisibleHtml.ts +0 -29
- package/src/commands/ts-check.ts +0 -88
- package/src/common/Logger/Logger/index.ts +0 -64
- package/src/common/Logger/index.ts +0 -64
- package/src/common/asyncLocalStorage/index.ts +0 -29
- package/src/common/cleanEnvironmentVariables.ts +0 -13
- package/src/common/constants.ts +0 -1
- package/src/common/contextStorageStateHelpers.ts +0 -71
- package/src/common/getPlaywrightConstructs.ts +0 -283
- package/src/common/jwtTokenManager.ts +0 -111
- package/src/common/settingsSchema.ts +0 -16
- package/src/common/telemetry.ts +0 -49
- package/src/index.ts +0 -14
- package/src/runtime/RunError.ts +0 -16
- package/src/runtime/downloadDirectory.ts +0 -14
- package/src/runtime/enums.ts +0 -11
- package/src/runtime/executionHelpers.test.ts +0 -70
- package/src/runtime/extendPayload.ts +0 -22
- package/src/runtime/extendTimeout.ts +0 -32
- package/src/runtime/requestMoreInfo.ts +0 -40
- package/src/runtime/runInfo.ts +0 -19
- package/vite.config.ts +0 -17
- /package/{src → dist}/common/assets/browser_scripts.js +0 -0
- /package/{src → dist}/runtime/enums.d.ts +0 -0
- /package/{src → dist}/runtime/export.d.ts +0 -0
|
@@ -1,124 +0,0 @@
|
|
|
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);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program } from "commander";
|
|
3
|
-
import { saveSessionFromOpenedBrowser } from "../common/browserUtils";
|
|
4
|
-
import dotenv from "dotenv";
|
|
5
|
-
|
|
6
|
-
dotenv.config({
|
|
7
|
-
path: `.env`,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
program
|
|
11
|
-
.description("save browser state to file storage.json")
|
|
12
|
-
.option("-p, --path [file]", "path for file", "./localSessions/default.json")
|
|
13
|
-
.allowUnknownOption()
|
|
14
|
-
.action(async ({ path }) => {
|
|
15
|
-
await saveSessionFromOpenedBrowser(path);
|
|
16
|
-
// playwright keeps an open handle to the connected browser and it stops the process from exiting
|
|
17
|
-
// there is no way to close the connection gracefully without destroying the context/browser
|
|
18
|
-
// https://github.com/microsoft/playwright/issues/4956
|
|
19
|
-
process.exit(0);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
program.parse(process.argv);
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program } from "commander";
|
|
3
|
-
import { startOrRestartBrowser } from "../common/browserUtils";
|
|
4
|
-
import dotenv from "dotenv";
|
|
5
|
-
|
|
6
|
-
dotenv.config({
|
|
7
|
-
path: `.env`,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
program
|
|
11
|
-
.description("start browser testing purposes")
|
|
12
|
-
.allowUnknownOption()
|
|
13
|
-
.action(async () => {
|
|
14
|
-
await startOrRestartBrowser();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
program.parse(process.argv);
|
package/src/commands/build.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program, Argument } from "commander";
|
|
3
|
-
import { RollupBuild, RollupLog, rollup } from "rollup";
|
|
4
|
-
import typescript from "@rollup/plugin-typescript";
|
|
5
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
6
|
-
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
7
|
-
import dynamicImportVars from "@rollup/plugin-dynamic-import-vars";
|
|
8
|
-
import json from "@rollup/plugin-json";
|
|
9
|
-
import * as fs from "fs-extra";
|
|
10
|
-
import * as path from "path";
|
|
11
|
-
import { moveWebTemplateFiles } from "./common/utils/webTemplate";
|
|
12
|
-
|
|
13
|
-
function isThirdPartyWarning(warning: RollupLog) {
|
|
14
|
-
if (warning.id && /node_modules/.test(warning.id)) return true;
|
|
15
|
-
if (warning.ids && warning.ids.every((id) => /node_modules/.test(id)))
|
|
16
|
-
return true;
|
|
17
|
-
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
import dotenv from "dotenv";
|
|
22
|
-
dotenv.config();
|
|
23
|
-
|
|
24
|
-
program
|
|
25
|
-
.description("build the intuned server")
|
|
26
|
-
.addArgument(
|
|
27
|
-
new Argument("<mode>", "mode of execution")
|
|
28
|
-
.choices(["vanilla", "playwright"])
|
|
29
|
-
.default("playwright")
|
|
30
|
-
.argOptional()
|
|
31
|
-
)
|
|
32
|
-
.argument("[outfile]", "output bundle", "./output/bundle_v2.js")
|
|
33
|
-
.allowUnknownOption()
|
|
34
|
-
.action(async (mode, outfile) => {
|
|
35
|
-
await moveWebTemplateFiles();
|
|
36
|
-
|
|
37
|
-
const currentTemplateTsConfig = path.resolve(
|
|
38
|
-
__dirname,
|
|
39
|
-
"..",
|
|
40
|
-
"..",
|
|
41
|
-
"template.tsconfig.json"
|
|
42
|
-
);
|
|
43
|
-
await fs.copy(
|
|
44
|
-
currentTemplateTsConfig,
|
|
45
|
-
"./intuned/WebTemplate/tsconfig.json"
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
await build(outfile, mode);
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
async function build(outfile: string, mode: "playwright" | "vanilla") {
|
|
52
|
-
let bundle: RollupBuild | null = null;
|
|
53
|
-
let buildFailed = false;
|
|
54
|
-
|
|
55
|
-
try {
|
|
56
|
-
// create a bundle
|
|
57
|
-
bundle = await rollup({
|
|
58
|
-
input: `./intuned/WebTemplate/index.${mode}.ts`,
|
|
59
|
-
output: {
|
|
60
|
-
globals: { crypto: "crypto" },
|
|
61
|
-
},
|
|
62
|
-
plugins: [
|
|
63
|
-
json(),
|
|
64
|
-
nodeResolve({ exportConditions: ["node"], preferBuiltins: true }),
|
|
65
|
-
typescript({ tsconfig: "./intuned/WebTemplate/tsconfig.json" }),
|
|
66
|
-
commonjs({
|
|
67
|
-
include: [
|
|
68
|
-
"node_modules/**",
|
|
69
|
-
"intuned/WebTemplate/**",
|
|
70
|
-
"dist",
|
|
71
|
-
"../runner/**",
|
|
72
|
-
],
|
|
73
|
-
extensions: [".js"],
|
|
74
|
-
ignoreGlobal: false,
|
|
75
|
-
sourceMap: false,
|
|
76
|
-
}),
|
|
77
|
-
dynamicImportVars({
|
|
78
|
-
include: ["**/*.js", "**/*.ts"],
|
|
79
|
-
exclude: ["**/*.d.ts", "**/*.js.map"],
|
|
80
|
-
}),
|
|
81
|
-
],
|
|
82
|
-
onwarn: (warning, warn) => {
|
|
83
|
-
if (isThirdPartyWarning(warning)) return;
|
|
84
|
-
warn(warning);
|
|
85
|
-
},
|
|
86
|
-
external: [
|
|
87
|
-
"@intuned/playwright",
|
|
88
|
-
"@intuned/playwright-core",
|
|
89
|
-
"jsdom",
|
|
90
|
-
"canvas",
|
|
91
|
-
"pdfjs-dist",
|
|
92
|
-
"pdf-to-png-converter",
|
|
93
|
-
"crypto",
|
|
94
|
-
"applicationinsights",
|
|
95
|
-
"fingerprint-generator",
|
|
96
|
-
"fingerprint-injector",
|
|
97
|
-
],
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
console.log(`📦 Building ${outfile}`);
|
|
101
|
-
const outfileFolder = path.dirname(outfile);
|
|
102
|
-
|
|
103
|
-
// copy assets to outfile folder
|
|
104
|
-
const assetsDir = path.resolve(__dirname, "..", "common", "assets");
|
|
105
|
-
await fs.copy(assetsDir, `${outfileFolder}/assets`);
|
|
106
|
-
|
|
107
|
-
await bundle.write({
|
|
108
|
-
format: "cjs",
|
|
109
|
-
file: outfile,
|
|
110
|
-
inlineDynamicImports: true,
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
console.log(`✨ Build succeeded: ${outfile}`);
|
|
114
|
-
} catch (error) {
|
|
115
|
-
buildFailed = true;
|
|
116
|
-
console.error("error", error);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (buildFailed) {
|
|
120
|
-
console.error("build failed");
|
|
121
|
-
process.exit(1);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
program.parse(process.argv);
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// this file is to make testing easier only.
|
|
2
|
-
|
|
3
|
-
import { spawn } from "child_process";
|
|
4
|
-
import * as playwright from "@intuned/playwright-core";
|
|
5
|
-
import * as fs from "fs-extra";
|
|
6
|
-
import { BrowserContext } from "@intuned/playwright-core";
|
|
7
|
-
import { getFullPathInProject } from "./utils/fileUtils";
|
|
8
|
-
import { getContextStorageState } from "../../common/contextStorageStateHelpers";
|
|
9
|
-
|
|
10
|
-
export const REMOTE_DEBUGGING_PORT = 9222;
|
|
11
|
-
|
|
12
|
-
export const getChromiumLaunchArgs = () => [
|
|
13
|
-
"--no-sandbox",
|
|
14
|
-
`--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`,
|
|
15
|
-
`--user-data-dir=/tmp/${Date.now()}`,
|
|
16
|
-
"--new-window",
|
|
17
|
-
"--start-maximized",
|
|
18
|
-
"--disable-popup-blocking",
|
|
19
|
-
];
|
|
20
|
-
|
|
21
|
-
// this is needed cause we need to keep the same browser instance alive between start recording and stop recording calls.
|
|
22
|
-
async function getBrowser() {
|
|
23
|
-
let playwrightBrowser: playwright.Browser | null = null;
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
playwrightBrowser = await playwright.chromium.connectOverCDP(
|
|
27
|
-
`http://localhost:${REMOTE_DEBUGGING_PORT}`
|
|
28
|
-
);
|
|
29
|
-
} catch (e) {
|
|
30
|
-
throw new Error("Browser is not running");
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return playwrightBrowser;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function startOrRestartBrowser() {
|
|
37
|
-
const chromiumPath = await playwright.chromium.executablePath();
|
|
38
|
-
|
|
39
|
-
const chromeInstanceProcess = spawn(chromiumPath, getChromiumLaunchArgs());
|
|
40
|
-
|
|
41
|
-
chromeInstanceProcess.stdout.on("data", (data) => {
|
|
42
|
-
console.log(`Chrome stdout: ${data}`);
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
chromeInstanceProcess.stderr.on("data", (data) => {
|
|
46
|
-
console.error(`Chrome stderr: ${data}`);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface SessionState {
|
|
51
|
-
cookies: any[];
|
|
52
|
-
storage: Record<string, { localStorage: any; sessionStorage: any }>;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export async function saveSessionFromOpenedBrowser(path: string) {
|
|
56
|
-
const browser = await getBrowser();
|
|
57
|
-
const context = await browser.contexts()[0];
|
|
58
|
-
|
|
59
|
-
return saveSession(path, context);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export async function loadState(path: string, context: BrowserContext) {
|
|
63
|
-
const fullPath = getFullPathInProject(path);
|
|
64
|
-
if (!(await fs.pathExists(fullPath))) {
|
|
65
|
-
throw new Error("session file does not exist");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const data: SessionState = await fs.readJson(fullPath);
|
|
69
|
-
|
|
70
|
-
await context.addCookies(data.cookies);
|
|
71
|
-
|
|
72
|
-
// ToDo: logic to load storage without using the page.
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export async function saveSession(path: string, context: BrowserContext) {
|
|
76
|
-
const fullState = await getContextStorageState(context);
|
|
77
|
-
const fullPath = getFullPathInProject(path);
|
|
78
|
-
fs.ensureFileSync(fullPath);
|
|
79
|
-
await fs.writeJSON(fullPath, fullState);
|
|
80
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export async function getDefaultExportFromFile(apiFilePath: string) {
|
|
2
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
3
|
-
require("ts-node").register({
|
|
4
|
-
transpileOnly: true,
|
|
5
|
-
compilerOptions: {
|
|
6
|
-
lib: ["dom", "es2020"],
|
|
7
|
-
},
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
const imported = await import(apiFilePath);
|
|
11
|
-
const defaultExport = imported.default;
|
|
12
|
-
return defaultExport;
|
|
13
|
-
}
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ts,
|
|
3
|
-
Project,
|
|
4
|
-
CompilerOptions,
|
|
5
|
-
ModuleKind,
|
|
6
|
-
ScriptTarget,
|
|
7
|
-
FunctionDeclaration,
|
|
8
|
-
SourceFile,
|
|
9
|
-
Node,
|
|
10
|
-
} from "ts-morph";
|
|
11
|
-
import { SourceMapConsumer } from "source-map";
|
|
12
|
-
|
|
13
|
-
function compileTypeScript(apiFilePath: string) {
|
|
14
|
-
const compilerOptions: CompilerOptions = {
|
|
15
|
-
lib: ["dom", "es2020"],
|
|
16
|
-
sourceMap: true,
|
|
17
|
-
inlineSourceMap: true,
|
|
18
|
-
inlineSources: true,
|
|
19
|
-
declaration: false,
|
|
20
|
-
noEmit: false,
|
|
21
|
-
module: ModuleKind.CommonJS,
|
|
22
|
-
target: ScriptTarget.ES2020,
|
|
23
|
-
};
|
|
24
|
-
const project = new Project({
|
|
25
|
-
compilerOptions,
|
|
26
|
-
});
|
|
27
|
-
const sourceFile = project.addSourceFileAtPath(apiFilePath);
|
|
28
|
-
const outputJS = project.emitToMemory({ targetSourceFile: sourceFile });
|
|
29
|
-
const outputJSText = outputJS.getFiles()[0].text;
|
|
30
|
-
return { sourceFile, outputJSText };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function findFirstExecutableLine(sourceFile: SourceFile) {
|
|
34
|
-
let functionBody: ReturnType<FunctionDeclaration["getBody"]>;
|
|
35
|
-
|
|
36
|
-
// Directly find the default exported function's body
|
|
37
|
-
const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
|
|
38
|
-
const defaultExportDeclaration = defaultExportSymbol?.getDeclarations()?.[0];
|
|
39
|
-
if (defaultExportDeclaration) {
|
|
40
|
-
// Check if the default export is a function
|
|
41
|
-
if (
|
|
42
|
-
defaultExportDeclaration.getKind() === ts.SyntaxKind.FunctionDeclaration
|
|
43
|
-
) {
|
|
44
|
-
functionBody = (
|
|
45
|
-
defaultExportDeclaration as FunctionDeclaration
|
|
46
|
-
).getBody();
|
|
47
|
-
} else {
|
|
48
|
-
// Handle ExportAssignment specifically for cases like `export default identifier;`
|
|
49
|
-
const exportAssignments = sourceFile.getExportAssignments();
|
|
50
|
-
for (const exportAssignment of exportAssignments) {
|
|
51
|
-
const expression = exportAssignment.getExpression();
|
|
52
|
-
if (!expression) continue;
|
|
53
|
-
|
|
54
|
-
if (
|
|
55
|
-
expression.getKind() === ts.SyntaxKind.Identifier ||
|
|
56
|
-
expression.getKind() === ts.SyntaxKind.FunctionExpression ||
|
|
57
|
-
expression.getKind() === ts.SyntaxKind.ArrowFunction
|
|
58
|
-
) {
|
|
59
|
-
const identifier = expression.getText();
|
|
60
|
-
const possiblyExportedFunction =
|
|
61
|
-
sourceFile.getFunction(identifier) ||
|
|
62
|
-
(sourceFile
|
|
63
|
-
.getVariableStatement(identifier)
|
|
64
|
-
?.getDescendants()
|
|
65
|
-
.find(
|
|
66
|
-
(node) =>
|
|
67
|
-
node.getKind() === ts.SyntaxKind.FunctionExpression ||
|
|
68
|
-
node.getKind() === ts.SyntaxKind.ArrowFunction
|
|
69
|
-
) as FunctionDeclaration);
|
|
70
|
-
if (possiblyExportedFunction) {
|
|
71
|
-
functionBody = possiblyExportedFunction.getBody();
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
if (
|
|
76
|
-
Node.hasBody(expression) &&
|
|
77
|
-
(expression.getKind() === ts.SyntaxKind.FunctionExpression ||
|
|
78
|
-
expression.getKind() === ts.SyntaxKind.ArrowFunction)
|
|
79
|
-
) {
|
|
80
|
-
// As these are anonymous, we directly access their body
|
|
81
|
-
functionBody = expression.getBody() as ReturnType<
|
|
82
|
-
FunctionDeclaration["getBody"]
|
|
83
|
-
>;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (!functionBody || !Node.isStatemented(functionBody)) {
|
|
90
|
-
return -1;
|
|
91
|
-
}
|
|
92
|
-
if (functionBody.getStatements().length === 0) {
|
|
93
|
-
return -1;
|
|
94
|
-
}
|
|
95
|
-
const position = functionBody.getStatements()[0].getStart();
|
|
96
|
-
return sourceFile.getLineAndColumnAtPos(position);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
async function getSourceMap(jsCode: string) {
|
|
100
|
-
const sourceMapBase64 = jsCode.substring(
|
|
101
|
-
jsCode.lastIndexOf("//# sourceMappingURL=data:application/json;base64,") +
|
|
102
|
-
"//# sourceMappingURL=data:application/json;base64,".length
|
|
103
|
-
);
|
|
104
|
-
const sourceMapText = Buffer.from(sourceMapBase64, "base64").toString(
|
|
105
|
-
"utf-8"
|
|
106
|
-
);
|
|
107
|
-
const sourceMap = JSON.parse(sourceMapText);
|
|
108
|
-
return new SourceMapConsumer(sourceMap);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async function mapFirstLineNumberBySourceMap(
|
|
112
|
-
sourceFileName: string,
|
|
113
|
-
jsCode: string,
|
|
114
|
-
line: number,
|
|
115
|
-
column: number
|
|
116
|
-
) {
|
|
117
|
-
const sourceMap = await getSourceMap(jsCode);
|
|
118
|
-
const generatedLineNumber = sourceMap.generatedPositionFor({
|
|
119
|
-
source: sourceFileName,
|
|
120
|
-
line,
|
|
121
|
-
column,
|
|
122
|
-
}).line;
|
|
123
|
-
if (!generatedLineNumber) return -1;
|
|
124
|
-
return generatedLineNumber;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export default async function getFirstLineNumber(apiFilePath: string) {
|
|
128
|
-
const sourceFileName = apiFilePath.split("/").pop() ?? apiFilePath;
|
|
129
|
-
|
|
130
|
-
// Compile TypeScript to JavaScript and get the Typescript AST
|
|
131
|
-
const { sourceFile, outputJSText } = compileTypeScript(apiFilePath);
|
|
132
|
-
|
|
133
|
-
// Find the first line of code in the default export ts code
|
|
134
|
-
const result = findFirstExecutableLine(sourceFile);
|
|
135
|
-
if (result === -1) return { sourceFileName, lineNumber: -1 };
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
sourceFileName,
|
|
139
|
-
lineNumber: await mapFirstLineNumberBySourceMap(
|
|
140
|
-
sourceFileName,
|
|
141
|
-
outputJSText,
|
|
142
|
-
result.line,
|
|
143
|
-
result.column
|
|
144
|
-
),
|
|
145
|
-
};
|
|
146
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
// Send information to the parent process where it should continue the debugger
|
|
2
|
-
// This is handled by DebuggingProcessManager
|
|
3
|
-
export const sendBreakPointOnToClient = (
|
|
4
|
-
sourceFileName: string,
|
|
5
|
-
lineNumber: number
|
|
6
|
-
) => {
|
|
7
|
-
console.log(`breakpoint on ${sourceFileName}:${lineNumber}`);
|
|
8
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import * as path from "path";
|
|
2
|
-
import * as fs from "fs-extra";
|
|
3
|
-
import dotenv from "dotenv";
|
|
4
|
-
|
|
5
|
-
dotenv.config();
|
|
6
|
-
|
|
7
|
-
// TODO: todo-identity handle identity instances
|
|
8
|
-
export function getFullPathInProject(...paths: string[]) {
|
|
9
|
-
return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function listProjectFilesAndFolders() {
|
|
13
|
-
const projectPath = path.resolve(process.cwd(), process.env.ROOT || "./");
|
|
14
|
-
try {
|
|
15
|
-
const files = await fs.readdir(projectPath, { withFileTypes: true });
|
|
16
|
-
return files.map((file) => ({
|
|
17
|
-
type: file.isDirectory() ? ("Folder" as const) : ("File" as const),
|
|
18
|
-
fullPath: path.join(projectPath, file.name),
|
|
19
|
-
name: file.name,
|
|
20
|
-
}));
|
|
21
|
-
} catch (err) {
|
|
22
|
-
console.error("Error reading the directory:", err);
|
|
23
|
-
throw err;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { getFullPathInProject } from "./fileUtils";
|
|
2
|
-
import {
|
|
3
|
-
IntunedSettings,
|
|
4
|
-
settingsSchema,
|
|
5
|
-
} from "../../../common/settingsSchema";
|
|
6
|
-
|
|
7
|
-
export async function getSettings(): Promise<IntunedSettings> {
|
|
8
|
-
const settingsFilePath = getFullPathInProject("Intuned.json");
|
|
9
|
-
console.log("loading settings");
|
|
10
|
-
|
|
11
|
-
const settings = await import(settingsFilePath);
|
|
12
|
-
if (settings.default) {
|
|
13
|
-
const parsed = settingsSchema.safeParse(settings.default);
|
|
14
|
-
if (parsed.success) {
|
|
15
|
-
return parsed.data;
|
|
16
|
-
} else {
|
|
17
|
-
// ToDo: why does the type not work here?
|
|
18
|
-
throw new Error((parsed as any).error.message);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return { authSessions: { enabled: false } };
|
|
23
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs-extra";
|
|
2
|
-
import * as path from "path";
|
|
3
|
-
|
|
4
|
-
import { getFullPathInProject, listProjectFilesAndFolders } from "./fileUtils";
|
|
5
|
-
|
|
6
|
-
export const moveWebTemplateFiles = async () => {
|
|
7
|
-
await fs.remove("./intuned");
|
|
8
|
-
await fs.ensureDir("./intuned");
|
|
9
|
-
|
|
10
|
-
const currentFileLocation = path.resolve(
|
|
11
|
-
__dirname,
|
|
12
|
-
"..",
|
|
13
|
-
"..",
|
|
14
|
-
"..",
|
|
15
|
-
"..",
|
|
16
|
-
"WebTemplate"
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
// copy WebTemplate to ./intuned
|
|
20
|
-
await fs.copy(`${currentFileLocation}`, "./intuned/WebTemplate", {
|
|
21
|
-
filter: (src, dest) => {
|
|
22
|
-
if (src.includes(".d.ts")) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return true;
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const filesAndFolders = await listProjectFilesAndFolders();
|
|
31
|
-
const pathsIgnoreList = [
|
|
32
|
-
getFullPathInProject("intuned"),
|
|
33
|
-
getFullPathInProject("node_modules"),
|
|
34
|
-
getFullPathInProject("package.json"),
|
|
35
|
-
getFullPathInProject("yarn.lock"),
|
|
36
|
-
getFullPathInProject(".env"),
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
const filesToCopy = filesAndFolders.filter(
|
|
40
|
-
(file) => !pathsIgnoreList.includes(file.fullPath)
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
for (const file of filesToCopy) {
|
|
44
|
-
await fs.copy(file.fullPath, `./intuned/WebTemplate/${file.name}`);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs-extra";
|
|
2
|
-
import dotenv from "dotenv";
|
|
3
|
-
// import { getPageVisiblePageHtml } from "../../common/playwrightPageHelpers";
|
|
4
|
-
import { getPlaywrightConstructsForMode } from "../../common/getPlaywrightConstructs";
|
|
5
|
-
|
|
6
|
-
dotenv.config({
|
|
7
|
-
path: `.env`,
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
async function main() {
|
|
11
|
-
const { page } = await getPlaywrightConstructsForMode(
|
|
12
|
-
"playwright",
|
|
13
|
-
undefined
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
await page.goto(
|
|
17
|
-
"https://www.marriott.com/search/findHotels.mi?roomTypeCode=&recordsPerPage=20&autoSuggestItemType=&destinationAddress.types=locality,political&destinationAddress.latitude=47.6061389&propertyCode=&destinationAddress.stateProvinceShort=&isInternalSearch=true&destinationAddress.cityPopulation=&vsInitialRequest=false&searchType=InCity&destinationAddress.locality=&showAddressPin=&miniStoreFormSubmit=&destinationAddress.stateProvinceDisplayName=&destinationAddress.destinationPageDestinationAddress=&countryName=&destinationAddress.stateProvince=WA&searchRadius=50.0&singleSearchAutoSuggest=Unmatched&missingcheckInDateMsg=Please+enter+a+check-in+date.&destinationAddress.placeId=ChIJVTPokywQkFQRmtVEaUZlJRA&is-hotelsnearme-clicked=false&destinationAddress.addressline1=&airportName=&for-hotels-nearme=Near&missingcheckOutDateMsg=Please+enter+a+check-out+date.&suggestionsPropertyCode=&pageType=advanced&destinationAddress.country=US&destinationAddress.name=&poiCity=&destinationAddress.countryShort=&marriottBrands=&poiName=&destinationAddress.address=Seattle,+WA,+USA&search-countryRegion=&collapseAccordian=is-hidden&singleSearch=true&destinationAddress.cityPopulationDensity=&destinationAddress.secondaryText=WA,+USA&destinationAddress.postalCode=&destinationAddress.city=Seattle&destinationAddress.mainText=Seattle&airportCode=&isTransient=true&destinationAddress.longitude=-122.3328481&initialRequest=false&destinationAddress.website=https://maps.google.com/?q=Seattle,+WA,+USA&ftid=0x5490102c93e83355:0x102565466944d59a&search-locality=&dimensions=0&roomTypeCode=&propertyCode=&flexibleDateSearchRateDisplay=false&propertyName=&isSearch=true&marriottRewardsNumber=&isRateCalendar=false&incentiveType_Number=&incentiveType=&flexibleDateLowestRateMonth=&flexibleDateLowestRateDate=&marrOfferId=&isMultiRateSearch=&multiRateMaxCount=&multiRateCorpCodes=&useMultiRateRewardsPoints=&multiRateClusterCodes=&multiRateCorpCodesEntered=&lowestRegularRate=&js-location-nearme-values=&destinationAddress.destination=Seattle,+WA,+USA&fromToDate=10/07/2023&fromToDate_submit=10/08/2023&fromDate=10/07/2023&toDate=10/08/2023&toDateDefaultFormat=10/08/2023&fromDateDefaultFormat=10/07/2023&flexibleDateSearch=false&isHideFlexibleDateCalendar=false&t-start=2023-10-07&t-end=2023-10-08&lengthOfStay=1&roomCountBox=1+Room&roomCount=1&guestCountBox=1+Adult+Per+Room&numAdultsPerRoom=1&childrenCountBox=0+Children+Per+Room&childrenCount=0&childrenAges=&clusterCode=none&corporateCode=&useRewardsPoints=true&view=list#/0/",
|
|
18
|
-
{ waitUntil: "load" }
|
|
19
|
-
);
|
|
20
|
-
await page.waitForTimeout(10000);
|
|
21
|
-
|
|
22
|
-
const html = ""; // await getPageVisiblePageHtml(page);
|
|
23
|
-
|
|
24
|
-
await fs.writeFile("./htmlFiles/marriott.html", html);
|
|
25
|
-
|
|
26
|
-
process.exit();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
void main();
|