@intuned/runtime-dev 0.1.0-test.14 → 0.1.0-test.16
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/.babelrc +1 -2
- package/WebTemplate/api.ts +90 -92
- package/WebTemplate/controllers/authSessions/create.ts +2 -2
- package/WebTemplate/controllers/authSessions/store.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +14 -12
- package/WebTemplate/index.playwright.ts +32 -42
- package/WebTemplate/jobs.ts +13 -2
- package/WebTemplate/utils.ts +53 -1
- package/api/test2.ts +6 -1
- package/auth-sessions/check.ts +3 -1
- package/auth-sessions/create.ts +10 -10
- 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 +109 -170
- package/dist/commands/auth-sessions/load.js +28 -26
- package/dist/commands/auth-sessions/run-check.js +54 -53
- package/dist/commands/auth-sessions/run-create.js +93 -96
- package/dist/commands/browser/save-state.js +14 -16
- package/dist/commands/browser/start-browser.js +11 -11
- package/dist/commands/build.js +79 -109
- package/dist/commands/common/browserUtils.js +53 -51
- package/dist/commands/common/getFirstLineNumber.js +93 -93
- package/dist/commands/common/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +53 -48
- package/dist/commands/common/sendMessageToClient.js +9 -4
- package/dist/commands/common/tsNodeImport.d.ts +1 -0
- package/dist/commands/common/tsNodeImport.js +18 -0
- package/dist/commands/common/utils/fileUtils.js +32 -22
- package/dist/commands/common/utils/settings.js +27 -19
- package/dist/commands/common/utils/unixSocket.js +43 -43
- package/dist/commands/common/utils/webTemplate.js +30 -28
- package/dist/commands/interface/run.js +162 -139
- package/dist/commands/ts-check.js +50 -50
- package/dist/common/Logger/Logger/index.js +55 -42
- package/dist/common/Logger/Logger/types.js +5 -1
- package/dist/common/Logger/index.js +55 -42
- package/dist/common/Logger/types.js +5 -1
- package/dist/common/asyncLocalStorage/index.js +16 -8
- package/dist/common/cleanEnvironmentVariables.js +16 -12
- package/dist/common/constants.js +7 -1
- package/dist/common/contextStorageStateHelpers.js +47 -38
- package/dist/common/getPlaywrightConstructs.js +178 -197
- package/dist/common/jwtTokenManager.js +76 -79
- package/dist/common/runApi/errors.js +159 -150
- package/dist/common/runApi/index.js +240 -232
- package/dist/common/runApi/types.d.ts +19 -5
- package/dist/common/runApi/types.js +53 -56
- package/dist/common/settingsSchema.js +15 -10
- package/dist/common/telemetry.js +28 -30
- package/dist/index.js +69 -4
- package/dist/runtime/RunError.js +18 -11
- package/dist/runtime/downloadDirectory.js +19 -13
- package/dist/runtime/enums.d.js +5 -0
- package/dist/runtime/enums.d.ts +11 -1
- package/dist/runtime/enums.js +18 -12
- package/dist/runtime/executionHelpers.test.js +53 -0
- package/dist/runtime/export.d.js +5 -0
- package/dist/runtime/export.d.ts +202 -1
- package/dist/runtime/extendPayload.js +21 -15
- package/dist/runtime/extendTimeout.js +28 -21
- package/dist/runtime/index.js +53 -6
- package/dist/runtime/requestMoreInfo.js +23 -16
- package/dist/runtime/runInfo.js +21 -14
- package/package.json +4 -7
- 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 -79
- package/dist/commands/common/browserUtils.ts +0 -45
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
- package/dist/commands/common/getDefaultExportFromFile.js +0 -12
- 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 -23
- package/dist/commands/interface/run.ts +0 -156
- package/dist/commands/ts-check.ts +0 -51
- package/dist/common/Logger/Logger/index.ts +0 -53
- package/dist/common/Logger/Logger/types.ts +0 -1
- package/dist/common/Logger/index.ts +0 -53
- package/dist/common/Logger/types.ts +0 -1
- 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 -182
- 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/executionHelpers.test.ts +0 -51
- 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/runtime/index.js
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "RunError", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _RunError.RunError;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "extendPayload", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _extendPayload.extendPayload;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "extendTimeout", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _extendTimeout.extendTimeout;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "getDownloadDirectoryPath", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _downloadDirectory.getDownloadDirectoryPath;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "requestMultipleChoice", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _requestMoreInfo.requestMultipleChoice;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "requestOTP", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _requestMoreInfo.requestOTP;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "runInfo", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _runInfo.runInfo;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
var _extendPayload = require("./extendPayload.js");
|
|
49
|
+
var _extendTimeout = require("./extendTimeout.js");
|
|
50
|
+
var _runInfo = require("./runInfo.js");
|
|
51
|
+
var _RunError = require("./RunError.js");
|
|
52
|
+
var _requestMoreInfo = require("./requestMoreInfo.js");
|
|
53
|
+
var _downloadDirectory = require("./downloadDirectory.js");
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.requestMultipleChoice = requestMultipleChoice;
|
|
7
|
+
exports.requestOTP = requestOTP;
|
|
1
8
|
const REQUEST_MORE_INFO_KEY = Symbol("REQUEST_MORE_INFO");
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
export function requestMultipleChoice(messageToUser, choices) {
|
|
11
|
-
return {
|
|
12
|
-
[REQUEST_MORE_INFO_KEY]: true,
|
|
13
|
-
action: "request_more_info",
|
|
14
|
-
messageToUser,
|
|
15
|
-
requestType: "multiple_choice",
|
|
16
|
-
choices,
|
|
17
|
-
};
|
|
9
|
+
function requestOTP(messageToUser) {
|
|
10
|
+
return {
|
|
11
|
+
[REQUEST_MORE_INFO_KEY]: true,
|
|
12
|
+
action: "request_more_info",
|
|
13
|
+
messageToUser,
|
|
14
|
+
requestType: "otp"
|
|
15
|
+
};
|
|
18
16
|
}
|
|
17
|
+
function requestMultipleChoice(messageToUser, choices) {
|
|
18
|
+
return {
|
|
19
|
+
[REQUEST_MORE_INFO_KEY]: true,
|
|
20
|
+
action: "request_more_info",
|
|
21
|
+
messageToUser,
|
|
22
|
+
requestType: "multiple_choice",
|
|
23
|
+
choices
|
|
24
|
+
};
|
|
25
|
+
}
|
package/dist/runtime/runInfo.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.runInfo = runInfo;
|
|
7
|
+
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
8
|
+
var _enums = require("./enums.js");
|
|
9
|
+
function runInfo() {
|
|
10
|
+
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
11
|
+
if (!context) {
|
|
12
|
+
return {
|
|
13
|
+
runEnvironment: _enums.RunEnvironment.IDE
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const {
|
|
17
|
+
extendedPayloads: _extendedPayloads,
|
|
18
|
+
...rest
|
|
19
|
+
} = context;
|
|
20
|
+
return rest;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.1.0-test.14",
|
|
3
|
+
"version": "0.1.0-test.16",
|
|
5
4
|
"description": "Intuned runtime",
|
|
6
5
|
"exports": {
|
|
7
6
|
".": "./dist/index.js",
|
|
8
|
-
"./
|
|
7
|
+
"./runtime": "./dist/runtime/index.js",
|
|
9
8
|
"./dist/common/runApi": "./dist/common/runApi/index.js",
|
|
10
9
|
"./dist/common/settingsSchema": "./dist/common/settingsSchema.js",
|
|
11
10
|
"./dist/common/contextStorageStateHelpers": "./dist/common/contextStorageStateHelpers.js",
|
|
@@ -13,8 +12,7 @@
|
|
|
13
12
|
"./dist/common/jwtTokenManager": "./dist/common/jwtTokenManager.js",
|
|
14
13
|
"./dist/common/asyncLocalStorage": "./dist/common/asyncLocalStorage/index.js",
|
|
15
14
|
"./dist/common/cleanEnvironmentVariables": "./dist/common/cleanEnvironmentVariables.js",
|
|
16
|
-
"./dist/common/constants": "./dist/common/constants.js"
|
|
17
|
-
"./dist/commands/interface/run": "./dist/commands/interface/run.js"
|
|
15
|
+
"./dist/common/constants": "./dist/common/constants.js"
|
|
18
16
|
},
|
|
19
17
|
"types": "./dist/index.d.ts",
|
|
20
18
|
"author": "Intuned Team",
|
|
@@ -29,7 +27,7 @@
|
|
|
29
27
|
"intuned-auth-session-refresh": "vite-node ./src/commands/auth/run-refresh.ts",
|
|
30
28
|
"intuned-auth-session-load": "vite-node ./src/commands/auth/load.ts",
|
|
31
29
|
"intuned-ts-check": "yarn prepublishOnly && vite-node ./src/commands/ts-check.ts",
|
|
32
|
-
"build": "rm -rf dist && tsc -p tsconfig.json && yarn copy-dts && babel src --out-dir dist --extensions '.ts'
|
|
30
|
+
"build": "rm -rf dist && tsc -p tsconfig.json && yarn copy-dts && babel src --out-dir dist --extensions '.ts' && cp -r ./src/common/assets dist/common/assets",
|
|
33
31
|
"test": "vitest run",
|
|
34
32
|
"test:watch": "vitest",
|
|
35
33
|
"e2e": "yarn playwright test --config ./playwright.config.ts",
|
|
@@ -92,7 +90,6 @@
|
|
|
92
90
|
"source-map": "^0.7.4",
|
|
93
91
|
"stack-utils": "^2.0.6",
|
|
94
92
|
"ts-morph": "^21.0.1",
|
|
95
|
-
"ts-node": "^10.9.1",
|
|
96
93
|
"tslib": "^2.6.0",
|
|
97
94
|
"typescript": "^5.1.6",
|
|
98
95
|
"wait-on": "^7.2.0",
|
package/dist/commands/api/run.ts
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program, Argument } from "commander";
|
|
3
|
-
import * as fs from "fs-extra";
|
|
4
|
-
import { getSettings } from "../common/utils/settings";
|
|
5
|
-
import dotenv from "dotenv";
|
|
6
|
-
import { runWithContext } from "../../common/asyncLocalStorage";
|
|
7
|
-
import { RunEnvironment } from "../../runtime/enums";
|
|
8
|
-
import { cleanEnvironmentVariables } from "../../common/cleanEnvironmentVariables";
|
|
9
|
-
import { logger } from "../../common/Logger";
|
|
10
|
-
import { nanoid } from "nanoid";
|
|
11
|
-
import chalk from "chalk";
|
|
12
|
-
import { runApi } from "../../common/runApi";
|
|
13
|
-
import { AutomationError } from "../../common/runApi";
|
|
14
|
-
dotenv.config({
|
|
15
|
-
path: `.env`
|
|
16
|
-
});
|
|
17
|
-
export async function executeCLI(apiName, mode, inputData, options) {
|
|
18
|
-
cleanEnvironmentVariables();
|
|
19
|
-
let authSessionPathToUse = null;
|
|
20
|
-
const settings = await getSettings();
|
|
21
|
-
if (settings.authSessions.enabled) {
|
|
22
|
-
if (!options.authSessionPath) {
|
|
23
|
-
throw new Error("Auth session is enabled but no auth session provided");
|
|
24
|
-
}
|
|
25
|
-
authSessionPathToUse = options.authSessionPath;
|
|
26
|
-
} else {
|
|
27
|
-
if (options.authSessionPath) {
|
|
28
|
-
throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const runApiResult = await runApi({
|
|
32
|
-
automationFunction: {
|
|
33
|
-
name: `api/${apiName}`,
|
|
34
|
-
params: inputData ?? {}
|
|
35
|
-
},
|
|
36
|
-
auth: authSessionPathToUse ? {
|
|
37
|
-
session: {
|
|
38
|
-
type: "file",
|
|
39
|
-
path: authSessionPathToUse
|
|
40
|
-
},
|
|
41
|
-
runCheck: false
|
|
42
|
-
} : undefined,
|
|
43
|
-
runOptions: {
|
|
44
|
-
environment: "ide",
|
|
45
|
-
cdpAddress: options.cdpAddress,
|
|
46
|
-
mode
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
if (runApiResult.isErr()) {
|
|
50
|
-
if (runApiResult.error instanceof AutomationError) {
|
|
51
|
-
throw runApiResult.error.error;
|
|
52
|
-
}
|
|
53
|
-
console.error("An error occurred while running the API", runApiResult.error);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const {
|
|
57
|
-
result,
|
|
58
|
-
extendedPayloads: payloadToAppend
|
|
59
|
-
} = runApiResult.value;
|
|
60
|
-
const isResponseObject = typeof result === "object" && result !== null;
|
|
61
|
-
const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
|
|
62
|
-
const hasNestedObjects = isResponseObject && Object.values(result).some(value => typeof value === "object");
|
|
63
|
-
const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
|
|
64
|
-
const resultsDir = "/tmp/run-results";
|
|
65
|
-
if (options.outputFileId && shouldWriteToFile) {
|
|
66
|
-
logger.info(chalk.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
|
|
67
|
-
fs.ensureDirSync(resultsDir);
|
|
68
|
-
const path = `${resultsDir}/${options.outputFileId}.json`;
|
|
69
|
-
await fs.writeJson(path, result, {
|
|
70
|
-
spaces: 2
|
|
71
|
-
});
|
|
72
|
-
} else {
|
|
73
|
-
console.log("result:", result);
|
|
74
|
-
}
|
|
75
|
-
const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
|
|
76
|
-
if (hasPayloadToAppend && options.outputFileId) {
|
|
77
|
-
logger.info(chalk.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
|
|
78
|
-
fs.ensureDirSync(resultsDir);
|
|
79
|
-
const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
|
|
80
|
-
await fs.writeJson(path, payloadToAppend, {
|
|
81
|
-
spaces: 2
|
|
82
|
-
});
|
|
83
|
-
} else if (hasPayloadToAppend) {
|
|
84
|
-
logger.info("payload to append:", payloadToAppend);
|
|
85
|
-
logger.info("This will only take an effect if this API run was part of a job.");
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
|
|
89
|
-
let inputData = null;
|
|
90
|
-
if (options.input) {
|
|
91
|
-
inputData = await fs.readJSON(options.input);
|
|
92
|
-
} else if (options.json) {
|
|
93
|
-
inputData = JSON.parse(options.json);
|
|
94
|
-
} else {
|
|
95
|
-
inputData = {};
|
|
96
|
-
}
|
|
97
|
-
await runWithContext({
|
|
98
|
-
runEnvironment: RunEnvironment.IDE,
|
|
99
|
-
extendedPayloads: [],
|
|
100
|
-
runId: nanoid(),
|
|
101
|
-
proxy: options.proxy
|
|
102
|
-
}, () => executeCLI(apiName, mode, inputData, options));
|
|
103
|
-
process.exit(0);
|
|
104
|
-
});
|
|
105
|
-
program.parse(process.argv);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program } from "commander";
|
|
3
|
-
import { getRemotePlaywrightContext } from "../../common/getPlaywrightConstructs";
|
|
4
|
-
import { getSettings } from "../common/utils/settings";
|
|
5
|
-
import dotenv from "dotenv";
|
|
6
|
-
import { loadSessionToContext } from "../../common/getPlaywrightConstructs";
|
|
7
|
-
dotenv.config({
|
|
8
|
-
path: `.env`
|
|
9
|
-
});
|
|
10
|
-
program.description("load auth session to browser").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").allowUnknownOption().action(async ({
|
|
11
|
-
cdpAddress,
|
|
12
|
-
authSessionPath
|
|
13
|
-
}) => {
|
|
14
|
-
const setting = await getSettings();
|
|
15
|
-
if (!setting.authSessions.enabled) {
|
|
16
|
-
throw new Error("Auth session is not enabled");
|
|
17
|
-
}
|
|
18
|
-
const {
|
|
19
|
-
context
|
|
20
|
-
} = await getRemotePlaywrightContext(cdpAddress);
|
|
21
|
-
await loadSessionToContext({
|
|
22
|
-
context,
|
|
23
|
-
session: {
|
|
24
|
-
type: "file",
|
|
25
|
-
path: authSessionPath
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
process.exit(0);
|
|
29
|
-
});
|
|
30
|
-
program.parse(process.argv);
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Argument, program } from "commander";
|
|
3
|
-
import * as fs from "fs-extra";
|
|
4
|
-
import { getFullPathInProject } from "../common/utils/fileUtils";
|
|
5
|
-
import { getSettings } from "../common/utils/settings";
|
|
6
|
-
import dotenv from "dotenv";
|
|
7
|
-
import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
|
|
8
|
-
import { runApi } from "../../common/runApi";
|
|
9
|
-
dotenv.config({
|
|
10
|
-
path: `.env`
|
|
11
|
-
});
|
|
12
|
-
program.description("run auth session check").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the check").allowUnknownOption().addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
|
|
13
|
-
cdpAddress,
|
|
14
|
-
authSessionPath
|
|
15
|
-
}) => {
|
|
16
|
-
const setting = await getSettings();
|
|
17
|
-
if (!setting.authSessions.enabled) {
|
|
18
|
-
throw new Error("auth session is not enabled");
|
|
19
|
-
}
|
|
20
|
-
const checkFilePath = getFullPathInProject(AUTH_SESSIONS_FOLDER_NAME, "check");
|
|
21
|
-
if (!fs.exists(checkFilePath)) {
|
|
22
|
-
throw new Error("auth session check file not found");
|
|
23
|
-
}
|
|
24
|
-
const runApiResult = await runApi({
|
|
25
|
-
automationFunction: {
|
|
26
|
-
name: `${AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
27
|
-
},
|
|
28
|
-
runOptions: {
|
|
29
|
-
environment: "ide",
|
|
30
|
-
mode,
|
|
31
|
-
cdpAddress
|
|
32
|
-
},
|
|
33
|
-
auth: {
|
|
34
|
-
session: {
|
|
35
|
-
type: "file",
|
|
36
|
-
path: authSessionPath
|
|
37
|
-
},
|
|
38
|
-
runCheck: false
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
if (runApiResult.isErr()) {
|
|
42
|
-
throw new Error(runApiResult.error);
|
|
43
|
-
}
|
|
44
|
-
const result = runApiResult.value.result;
|
|
45
|
-
console.log("check result", result);
|
|
46
|
-
if (!result) {
|
|
47
|
-
throw new Error("auth session check failed");
|
|
48
|
-
}
|
|
49
|
-
process.exit(0);
|
|
50
|
-
});
|
|
51
|
-
program.parse(process.argv);
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { Argument, program } from "commander";
|
|
3
|
-
import * as fs from "fs-extra";
|
|
4
|
-
import { prompt } from "promptly";
|
|
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 { runApiGenerator } from "../../common/runApi";
|
|
10
|
-
import { runWithContext } from "../../common/asyncLocalStorage";
|
|
11
|
-
import { nanoid } from "nanoid";
|
|
12
|
-
import { RunEnvironment } from "../../runtime/enums";
|
|
13
|
-
dotenv.config({
|
|
14
|
-
path: `.env`
|
|
15
|
-
});
|
|
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);
|
|
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
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
await runWithContext({
|
|
85
|
-
runEnvironment: RunEnvironment.IDE,
|
|
86
|
-
extendedPayloads: [],
|
|
87
|
-
runId: nanoid()
|
|
88
|
-
}, runCreate);
|
|
89
|
-
process.exit(0);
|
|
90
|
-
});
|
|
91
|
-
program.parse(process.argv);
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program } from "commander";
|
|
3
|
-
import { saveSessionFromOpenedBrowser } from "../common/browserUtils";
|
|
4
|
-
import dotenv from "dotenv";
|
|
5
|
-
dotenv.config({
|
|
6
|
-
path: `.env`
|
|
7
|
-
});
|
|
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);
|
|
13
|
-
});
|
|
14
|
-
program.parse(process.argv);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program } from "commander";
|
|
3
|
-
import { startOrRestartBrowser } from "../common/browserUtils";
|
|
4
|
-
import dotenv from "dotenv";
|
|
5
|
-
dotenv.config({
|
|
6
|
-
path: `.env`
|
|
7
|
-
});
|
|
8
|
-
program.description("start browser testing purposes").allowUnknownOption().action(async () => {
|
|
9
|
-
await startOrRestartBrowser();
|
|
10
|
-
});
|
|
11
|
-
program.parse(process.argv);
|
package/dist/commands/build.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { program, Argument } from "commander";
|
|
3
|
-
import { 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.js";
|
|
12
|
-
import { fileURLToPath } from "url";
|
|
13
|
-
function isThirdPartyWarning(warning) {
|
|
14
|
-
if (warning.id && /node_modules/.test(warning.id)) return true;
|
|
15
|
-
if (warning.ids && warning.ids.every(id => /node_modules/.test(id))) return true;
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
import dotenv from "dotenv";
|
|
19
|
-
dotenv.config();
|
|
20
|
-
program.description("build the intuned server").addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile) => {
|
|
21
|
-
await moveWebTemplateFiles();
|
|
22
|
-
const currentTemplateTsConfig = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "template.tsconfig.json");
|
|
23
|
-
await fs.copy(currentTemplateTsConfig, "./intuned/WebTemplate/tsconfig.json");
|
|
24
|
-
await build(outfile, mode);
|
|
25
|
-
});
|
|
26
|
-
async function build(outfile, mode) {
|
|
27
|
-
let bundle = null;
|
|
28
|
-
let buildFailed = false;
|
|
29
|
-
try {
|
|
30
|
-
bundle = await rollup({
|
|
31
|
-
input: `./intuned/WebTemplate/index.${mode}.ts`,
|
|
32
|
-
output: {
|
|
33
|
-
globals: {
|
|
34
|
-
crypto: "crypto"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
plugins: [json(), nodeResolve({
|
|
38
|
-
exportConditions: ["node"],
|
|
39
|
-
preferBuiltins: true
|
|
40
|
-
}), typescript({
|
|
41
|
-
tsconfig: "./intuned/WebTemplate/tsconfig.json"
|
|
42
|
-
}), commonjs({
|
|
43
|
-
include: ["node_modules/**", "intuned/WebTemplate/**", "dist", "../typescript-sdk/**", "../typescript-runtime/**"],
|
|
44
|
-
extensions: [".js"],
|
|
45
|
-
ignoreGlobal: false,
|
|
46
|
-
sourceMap: false,
|
|
47
|
-
dynamicRequireTargets: ["api/**/*.js", "auth-sessions/**/*.js"],
|
|
48
|
-
requireReturnsDefault: "auto",
|
|
49
|
-
transformMixedEsModules: true
|
|
50
|
-
}), dynamicImportVars({
|
|
51
|
-
include: ["**/*.js", "**/*.ts"],
|
|
52
|
-
exclude: ["**/*.d.ts", "**/*.js.map"]
|
|
53
|
-
})],
|
|
54
|
-
onwarn: (warning, warn) => {
|
|
55
|
-
if (isThirdPartyWarning(warning)) return;
|
|
56
|
-
warn(warning);
|
|
57
|
-
},
|
|
58
|
-
external: ["@intuned/playwright", "@intuned/playwright-core", "@intuned/runtime", "jsdom", "canvas", "pdfjs-dist", "pdf-to-png-converter", "crypto", "applicationinsights", "fingerprint-generator", "fingerprint-injector"]
|
|
59
|
-
});
|
|
60
|
-
console.log(`📦 Building ${outfile}`);
|
|
61
|
-
const outfileFolder = path.dirname(outfile);
|
|
62
|
-
const assetsDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "common", "assets");
|
|
63
|
-
await fs.copy(assetsDir, `${outfileFolder}/assets`);
|
|
64
|
-
await bundle.write({
|
|
65
|
-
format: "cjs",
|
|
66
|
-
file: outfile,
|
|
67
|
-
inlineDynamicImports: true
|
|
68
|
-
});
|
|
69
|
-
console.log(`✨ Build succeeded: ${outfile}`);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
buildFailed = true;
|
|
72
|
-
console.error("error", error);
|
|
73
|
-
}
|
|
74
|
-
if (buildFailed) {
|
|
75
|
-
console.error("build failed");
|
|
76
|
-
process.exit(1);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
program.parse(process.argv);
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { spawn } from "child_process";
|
|
2
|
-
import * as playwright from "@intuned/playwright-core";
|
|
3
|
-
import * as fs from "fs-extra";
|
|
4
|
-
import { getFullPathInProject } from "./utils/fileUtils.js";
|
|
5
|
-
import { getContextStorageState } from "../../common/contextStorageStateHelpers";
|
|
6
|
-
export const REMOTE_DEBUGGING_PORT = 9222;
|
|
7
|
-
export const getChromiumLaunchArgs = () => ["--no-sandbox", `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`, `--user-data-dir=/tmp/${Date.now()}`, "--new-window", "--start-maximized", "--disable-popup-blocking"];
|
|
8
|
-
async function getBrowser() {
|
|
9
|
-
let playwrightBrowser = null;
|
|
10
|
-
try {
|
|
11
|
-
playwrightBrowser = await playwright.chromium.connectOverCDP(`http://localhost:${REMOTE_DEBUGGING_PORT}`);
|
|
12
|
-
} catch (e) {
|
|
13
|
-
throw new Error("Browser is not running");
|
|
14
|
-
}
|
|
15
|
-
return playwrightBrowser;
|
|
16
|
-
}
|
|
17
|
-
export async function startOrRestartBrowser() {
|
|
18
|
-
const chromiumPath = await playwright.chromium.executablePath();
|
|
19
|
-
const chromeInstanceProcess = spawn(chromiumPath, getChromiumLaunchArgs());
|
|
20
|
-
chromeInstanceProcess.stdout.on("data", data => {
|
|
21
|
-
console.log(`Chrome stdout: ${data}`);
|
|
22
|
-
});
|
|
23
|
-
chromeInstanceProcess.stderr.on("data", data => {
|
|
24
|
-
console.error(`Chrome stderr: ${data}`);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
export async function saveSessionFromOpenedBrowser(path) {
|
|
28
|
-
const browser = await getBrowser();
|
|
29
|
-
const context = await browser.contexts()[0];
|
|
30
|
-
return saveSession(path, context);
|
|
31
|
-
}
|
|
32
|
-
export async function loadState(path, context) {
|
|
33
|
-
const fullPath = getFullPathInProject(path);
|
|
34
|
-
if (!(await fs.pathExists(fullPath))) {
|
|
35
|
-
throw new Error("session file does not exist");
|
|
36
|
-
}
|
|
37
|
-
const data = await fs.readJson(fullPath);
|
|
38
|
-
await context.addCookies(data.cookies);
|
|
39
|
-
}
|
|
40
|
-
export async function saveSession(path, context) {
|
|
41
|
-
const fullState = await getContextStorageState(context);
|
|
42
|
-
const fullPath = getFullPathInProject(path);
|
|
43
|
-
fs.ensureFileSync(fullPath);
|
|
44
|
-
await fs.writeJSON(fullPath, fullState);
|
|
45
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getDefaultExportFromFile(apiFilePath: string): Promise<any>;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export async function getDefaultExportFromFile(apiFilePath) {
|
|
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
|
-
const imported = await import(apiFilePath);
|
|
10
|
-
const defaultExport = imported.default;
|
|
11
|
-
return defaultExport;
|
|
12
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export async function getDefaultExportFromFile(apiFilePath) {
|
|
2
|
-
require("ts-node").register({
|
|
3
|
-
transpileOnly: true,
|
|
4
|
-
compilerOptions: {
|
|
5
|
-
lib: ["dom", "es2020"]
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
const imported = await import(apiFilePath);
|
|
9
|
-
const defaultExport = imported.default;
|
|
10
|
-
return defaultExport;
|
|
11
|
-
}
|