@intuned/runtime 1.3.17 → 1.3.18-interface.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/intuned +0 -0
- package/bin/intuned-interface +7 -0
- package/dist/chunk-6ZRJOUQS.mjs +16 -0
- package/dist/chunk-6ZRJOUQS.mjs.map +1 -0
- package/dist/chunk-7YL2JUTE.mjs +146 -0
- package/dist/chunk-7YL2JUTE.mjs.map +1 -0
- package/dist/chunk-B3T6RXPC.mjs +794 -0
- package/dist/chunk-B3T6RXPC.mjs.map +1 -0
- package/dist/chunk-FGV5T6SI.mjs +27 -0
- package/dist/chunk-FGV5T6SI.mjs.map +1 -0
- package/dist/chunk-G4PO5RIV.mjs +85 -0
- package/dist/chunk-G4PO5RIV.mjs.map +1 -0
- package/dist/chunk-LZOMFHX3.mjs +38 -0
- package/dist/chunk-LZOMFHX3.mjs.map +1 -0
- package/dist/{common/formatZodError.js → chunk-NDMVGENG.mjs} +9 -9
- package/dist/chunk-NDMVGENG.mjs.map +1 -0
- package/dist/chunk-W4UX6G4X.mjs +17 -0
- package/dist/chunk-W4UX6G4X.mjs.map +1 -0
- package/dist/chunk-XC75QGFG.mjs +1106 -0
- package/dist/chunk-XC75QGFG.mjs.map +1 -0
- package/dist/chunk-XOAZ2MGA.mjs +59 -0
- package/dist/chunk-XOAZ2MGA.mjs.map +1 -0
- package/dist/commands/interface/run.d.mts +3 -0
- package/dist/commands/interface/run.d.ts +3 -1
- package/dist/commands/interface/run.js +2060 -178
- package/dist/commands/interface/run.js.map +1 -0
- package/dist/commands/interface/run.mjs +255 -0
- package/dist/commands/interface/run.mjs.map +1 -0
- package/dist/common/asyncLocalStorage/index.d.mts +17 -0
- package/dist/common/asyncLocalStorage/index.d.ts +9 -8
- package/dist/common/asyncLocalStorage/index.js +34 -9
- package/dist/common/asyncLocalStorage/index.js.map +1 -0
- package/dist/common/asyncLocalStorage/index.mjs +12 -0
- package/dist/common/asyncLocalStorage/index.mjs.map +1 -0
- package/dist/common/binStartupScript.d.mts +2 -0
- package/dist/common/binStartupScript.d.ts +2 -1
- package/dist/common/binStartupScript.js +127 -11
- package/dist/common/binStartupScript.js.map +1 -0
- package/dist/common/binStartupScript.mjs +135 -0
- package/dist/common/binStartupScript.mjs.map +1 -0
- package/dist/common/cleanEnvironmentVariables.d.mts +3 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +3 -1
- package/dist/common/cleanEnvironmentVariables.js +30 -7
- package/dist/common/cleanEnvironmentVariables.js.map +1 -0
- package/dist/common/cleanEnvironmentVariables.mjs +8 -0
- package/dist/common/cleanEnvironmentVariables.mjs.map +1 -0
- package/dist/common/constants.d.mts +13 -0
- package/dist/common/constants.d.ts +13 -10
- package/dist/common/constants.js +58 -14
- package/dist/common/constants.js.map +1 -0
- package/dist/common/constants.mjs +28 -0
- package/dist/common/constants.mjs.map +1 -0
- package/dist/common/contextStorageStateHelpers.d.mts +24 -0
- package/dist/common/contextStorageStateHelpers.d.ts +8 -5
- package/dist/common/contextStorageStateHelpers.js +51 -23
- package/dist/common/contextStorageStateHelpers.js.map +1 -0
- package/dist/common/contextStorageStateHelpers.mjs +10 -0
- package/dist/common/contextStorageStateHelpers.mjs.map +1 -0
- package/dist/common/jwtTokenManager.d.mts +19 -0
- package/dist/common/jwtTokenManager.d.ts +6 -4
- package/dist/common/jwtTokenManager.js +112 -40
- package/dist/common/jwtTokenManager.js.map +1 -0
- package/dist/common/jwtTokenManager.mjs +11 -0
- package/dist/common/jwtTokenManager.mjs.map +1 -0
- package/dist/common/runApi/index.d.mts +11 -0
- package/dist/common/runApi/index.d.ts +10 -10
- package/dist/common/runApi/index.js +1776 -93
- package/dist/common/runApi/index.js.map +1 -0
- package/dist/common/runApi/index.mjs +18 -0
- package/dist/common/runApi/index.mjs.map +1 -0
- package/dist/common/settingsSchema.d.mts +536 -0
- package/dist/common/settingsSchema.d.ts +9 -6
- package/dist/common/settingsSchema.js +55 -20
- package/dist/common/settingsSchema.js.map +1 -0
- package/dist/common/settingsSchema.mjs +10 -0
- package/dist/common/settingsSchema.mjs.map +1 -0
- package/dist/common/telemetry.d.mts +6 -0
- package/dist/common/telemetry.d.ts +6 -3
- package/dist/common/telemetry.js +41 -9
- package/dist/common/telemetry.js.map +1 -0
- package/dist/common/telemetry.mjs +31 -0
- package/dist/common/telemetry.mjs.map +1 -0
- package/dist/export.d-BAUMB-lG.d.mts +140 -0
- package/dist/export.d-BAUMB-lG.d.ts +140 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +783 -98
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +47 -0
- package/dist/index.mjs.map +1 -0
- package/dist/runtime/index.d.mts +163 -0
- package/dist/runtime/index.d.ts +163 -10
- package/dist/runtime/index.js +779 -88
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/index.mjs +42 -0
- package/dist/runtime/index.mjs.map +1 -0
- package/package.json +78 -23
- package/.babelrc +0 -21
- package/.eslintignore +0 -10
- package/.eslintrc.js +0 -39
- package/InterfaceTemplate/__utils.ts +0 -61
- package/InterfaceTemplate/index.playwright.ts +0 -6
- package/WebTemplate.zip +0 -0
- package/dist/commands/api/run.d.ts +0 -6
- package/dist/commands/api/run.js +0 -119
- package/dist/commands/auth-sessions/load.d.ts +0 -2
- package/dist/commands/auth-sessions/load.js +0 -35
- package/dist/commands/auth-sessions/run-check.d.ts +0 -2
- package/dist/commands/auth-sessions/run-check.js +0 -74
- package/dist/commands/auth-sessions/run-create.d.ts +0 -2
- package/dist/commands/auth-sessions/run-create.js +0 -78
- 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 -1
- package/dist/commands/build.js +0 -84
- package/dist/commands/common/browserUtils.d.ts +0 -14
- package/dist/commands/common/browserUtils.js +0 -58
- package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
- package/dist/commands/common/getFirstLineNumber.js +0 -101
- package/dist/commands/common/getFirstLineNumber.test.js +0 -228
- package/dist/commands/common/projectExclusions.d.ts +0 -2
- package/dist/commands/common/projectExclusions.js +0 -8
- package/dist/commands/common/sendMessageToClient.d.ts +0 -1
- package/dist/commands/common/sendMessageToClient.js +0 -10
- package/dist/commands/common/tsNodeImport.d.ts +0 -2
- package/dist/commands/common/tsNodeImport.js +0 -43
- 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 -31
- package/dist/commands/common/utils/template.d.ts +0 -2
- package/dist/commands/common/utils/template.js +0 -31
- package/dist/commands/common/utils/unixSocket.d.ts +0 -23
- package/dist/commands/common/utils/unixSocket.js +0 -87
- package/dist/commands/get-headless-user-agent.d.ts +0 -1
- package/dist/commands/get-headless-user-agent.js +0 -18
- package/dist/commands/intuned-cli/commands/attempt.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt.command.js +0 -8
- package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +0 -30
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +0 -8
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +0 -19
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +0 -24
- package/dist/commands/intuned-cli/commands/authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession.command.js +0 -8
- package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession_record.command.js +0 -32
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +0 -16
- package/dist/commands/intuned-cli/commands/build.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/build.command.js +0 -12
- package/dist/commands/intuned-cli/commands/command.d.ts +0 -2
- package/dist/commands/intuned-cli/commands/command.js +0 -9
- package/dist/commands/intuned-cli/commands/deploy.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/deploy.command.js +0 -42
- package/dist/commands/intuned-cli/commands/index.d.ts +0 -18
- package/dist/commands/intuned-cli/commands/index.js +0 -203
- package/dist/commands/intuned-cli/commands/provision.command.d.ts +0 -13
- package/dist/commands/intuned-cli/commands/provision.command.js +0 -50
- package/dist/commands/intuned-cli/commands/run.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run.command.js +0 -8
- package/dist/commands/intuned-cli/commands/run_api.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_api.command.js +0 -46
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -31
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +0 -17
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +0 -35
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +0 -35
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +0 -33
- package/dist/commands/intuned-cli/commands/types.d.ts +0 -35
- package/dist/commands/intuned-cli/commands/types.js +0 -31
- package/dist/commands/intuned-cli/constants/index.d.ts +0 -17
- package/dist/commands/intuned-cli/constants/index.js +0 -25
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +0 -398
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +0 -1060
- package/dist/commands/intuned-cli/controller/api.d.ts +0 -42
- package/dist/commands/intuned-cli/controller/api.js +0 -194
- package/dist/commands/intuned-cli/controller/authSession.d.ts +0 -209
- package/dist/commands/intuned-cli/controller/authSession.js +0 -424
- package/dist/commands/intuned-cli/controller/build.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/build.js +0 -36
- package/dist/commands/intuned-cli/controller/deploy.d.ts +0 -5
- package/dist/commands/intuned-cli/controller/deploy.js +0 -318
- package/dist/commands/intuned-cli/controller/index.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/index.js +0 -46
- package/dist/commands/intuned-cli/controller/provision.d.ts +0 -21
- package/dist/commands/intuned-cli/controller/provision.js +0 -300
- package/dist/commands/intuned-cli/controller/scaffold.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/scaffold.js +0 -77
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +0 -115
- package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +0 -41
- package/dist/commands/intuned-cli/helpers/api.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/api.js +0 -16
- package/dist/commands/intuned-cli/helpers/auth.d.ts +0 -46
- package/dist/commands/intuned-cli/helpers/auth.js +0 -147
- package/dist/commands/intuned-cli/helpers/backend.d.ts +0 -8
- package/dist/commands/intuned-cli/helpers/backend.js +0 -35
- package/dist/commands/intuned-cli/helpers/browser.d.ts +0 -15
- package/dist/commands/intuned-cli/helpers/browser.js +0 -64
- package/dist/commands/intuned-cli/helpers/context.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/context.js +0 -33
- package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -16
- package/dist/commands/intuned-cli/helpers/errors.js +0 -44
- package/dist/commands/intuned-cli/helpers/index.d.ts +0 -12
- package/dist/commands/intuned-cli/helpers/index.js +0 -137
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +0 -39
- package/dist/commands/intuned-cli/helpers/intunedJson.js +0 -20
- package/dist/commands/intuned-cli/helpers/prompts.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/prompts.js +0 -71
- package/dist/commands/intuned-cli/helpers/proxy.d.ts +0 -5
- package/dist/commands/intuned-cli/helpers/proxy.js +0 -23
- package/dist/commands/intuned-cli/helpers/terminal.d.ts +0 -5
- package/dist/commands/intuned-cli/helpers/terminal.js +0 -13
- package/dist/commands/intuned-cli/helpers/timeout.d.ts +0 -1
- package/dist/commands/intuned-cli/helpers/timeout.js +0 -23
- package/dist/commands/intuned-cli/helpers/traces.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/traces.js +0 -32
- package/dist/commands/intuned-cli/helpers/validation.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/validation.js +0 -14
- package/dist/commands/intuned-cli/helpers/wrapper.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/wrapper.js +0 -76
- package/dist/commands/intuned-cli/index.d.ts +0 -1
- package/dist/commands/intuned-cli/index.js +0 -16
- package/dist/commands/intuned-cli/main.d.ts +0 -1
- package/dist/commands/intuned-cli/main.js +0 -36
- package/dist/commands/intuned-cli/types.d.ts +0 -70
- package/dist/commands/intuned-cli/types.js +0 -22
- package/dist/commands/ts-check.d.ts +0 -2
- package/dist/commands/ts-check.js +0 -56
- 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.d.ts +0 -8
- 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.d.ts +0 -8
- package/dist/common/Logger/types.js +0 -5
- package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +0 -1
- package/dist/common/backendFunctions/getAuthSessionParameters.js +0 -38
- package/dist/common/extension/extensionsHelpers.d.ts +0 -11
- package/dist/common/extension/extensionsHelpers.js +0 -147
- package/dist/common/extension/intunedExtensionServer.d.ts +0 -24
- package/dist/common/extension/intunedExtensionServer.js +0 -178
- package/dist/common/extension/types.d.ts +0 -212
- package/dist/common/extension/types.js +0 -51
- package/dist/common/formatZodError.d.ts +0 -2
- package/dist/common/intunedJson.d.ts +0 -229
- package/dist/common/intunedJson.js +0 -133
- package/dist/common/launchBrowser.d.ts +0 -33
- package/dist/common/launchBrowser.js +0 -235
- package/dist/common/playwrightContext.d.ts +0 -31
- package/dist/common/playwrightContext.js +0 -150
- package/dist/common/runApi/errors.d.ts +0 -72
- package/dist/common/runApi/errors.js +0 -169
- package/dist/common/runApi/importUsingImportFunction.d.ts +0 -9
- package/dist/common/runApi/importUsingImportFunction.js +0 -46
- package/dist/common/runApi/types.d.ts +0 -830
- package/dist/common/runApi/types.js +0 -73
- package/dist/common/setupContextHook.d.ts +0 -17
- package/dist/common/setupContextHook.js +0 -22
- package/dist/runtime/RunError.d.ts +0 -5
- package/dist/runtime/RunError.js +0 -19
- package/dist/runtime/attemptStore.d.ts +0 -2
- package/dist/runtime/attemptStore.js +0 -23
- package/dist/runtime/captcha.d.ts +0 -15
- package/dist/runtime/captcha.js +0 -191
- package/dist/runtime/captcha.test.js +0 -821
- 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.d.ts +0 -11
- package/dist/runtime/enums.js +0 -18
- package/dist/runtime/executionHelpers.test.js +0 -52
- package/dist/runtime/export.d.js +0 -5
- package/dist/runtime/export.d.ts +0 -284
- 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 -23
- package/dist/runtime/getAiGatewayConfig.d.ts +0 -10
- package/dist/runtime/getAiGatewayConfig.js +0 -16
- package/dist/runtime/getAuthSessionParameters.d.ts +0 -1
- package/dist/runtime/getAuthSessionParameters.js +0 -20
- package/dist/runtime/persistentStore.d.ts +0 -2
- package/dist/runtime/persistentStore.js +0 -37
- package/dist/runtime/persistentStore.test.js +0 -101
- package/dist/runtime/runInfo.d.ts +0 -2
- package/dist/runtime/runInfo.js +0 -21
- package/template.tsconfig.json +0 -11
- package/tsconfig.eslint.json +0 -5
- package/tsconfig.json +0 -25
- package/typedoc.json +0 -49
- /package/dist/common/assets/{browser_scripts.js → assets/browser_scripts.js} +0 -0
|
@@ -1,215 +1,2097 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
let timeoutTimestamp = Date.now();
|
|
67
|
-
const client = jsonl ? new _unixSocket.JSONLFileClient(socketPath) : new _unixSocket.SocketClient(socketPath);
|
|
68
|
-
const abortController = new AbortController();
|
|
69
|
-
const interruptSignalHandler = async () => {
|
|
70
|
-
abortController.abort();
|
|
71
|
-
await (0, _promises.setTimeout)(60_000);
|
|
72
|
-
await client.close();
|
|
73
|
-
process.exit(1);
|
|
74
|
-
};
|
|
75
|
-
process.on("SIGINT", interruptSignalHandler);
|
|
76
|
-
process.on("SIGTERM", interruptSignalHandler);
|
|
77
|
-
const messagesGenerator = client.receiveJSON();
|
|
78
|
-
async function receiveMessages() {
|
|
79
|
-
const data = await messagesGenerator.next();
|
|
80
|
-
if (data.done) {
|
|
81
|
-
return;
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// ../packages/runtime-interface/dist/errors.js
|
|
33
|
+
var require_errors = __commonJS({
|
|
34
|
+
"../packages/runtime-interface/dist/errors.js"(exports2) {
|
|
35
|
+
"use strict";
|
|
36
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
37
|
+
exports2.ResultTooBigError = exports2.InternalInvalidInputError = exports2.AutomationError = exports2.MaxLevelsExceededError = exports2.AuthCheckFailedError = exports2.AuthCheckNotFoundError = exports2.AuthRequiredError = exports2.AbortedError = exports2.InvalidCheckError = exports2.InvalidApiError = exports2.ApiNotFoundError = exports2.RunAutomationError = exports2.runAutomationErrorCodes = exports2.resultTooBigErrorCode = exports2.internalInvalidInputErrorCode = exports2.automationError = exports2.maxLevelsExceededErrorCode = exports2.authCheckFailedErrorCode = exports2.authCheckNotFoundErrorCode = exports2.authRequiredErrorCode = exports2.abortedErrorCode = exports2.invalidCheckErrorCode = exports2.invalidApiErrorCode = exports2.apiNotFoundErrorCode = void 0;
|
|
38
|
+
exports2.apiNotFoundErrorCode = "APINotFoundError";
|
|
39
|
+
exports2.invalidApiErrorCode = "InvalidAPIError";
|
|
40
|
+
exports2.invalidCheckErrorCode = "InvalidCheckError";
|
|
41
|
+
exports2.abortedErrorCode = "AbortedError";
|
|
42
|
+
exports2.authRequiredErrorCode = "AuthRequiredError";
|
|
43
|
+
exports2.authCheckNotFoundErrorCode = "AuthCheckNotFoundError";
|
|
44
|
+
exports2.authCheckFailedErrorCode = "AuthCheckFailedError";
|
|
45
|
+
exports2.maxLevelsExceededErrorCode = "MaxLevelsExceededError";
|
|
46
|
+
exports2.automationError = "AutomationError";
|
|
47
|
+
exports2.internalInvalidInputErrorCode = "InternalInvalidInputError";
|
|
48
|
+
exports2.resultTooBigErrorCode = "ResultTooBigError";
|
|
49
|
+
exports2.runAutomationErrorCodes = [
|
|
50
|
+
exports2.apiNotFoundErrorCode,
|
|
51
|
+
exports2.invalidApiErrorCode,
|
|
52
|
+
exports2.invalidCheckErrorCode,
|
|
53
|
+
exports2.abortedErrorCode,
|
|
54
|
+
exports2.authRequiredErrorCode,
|
|
55
|
+
exports2.authCheckNotFoundErrorCode,
|
|
56
|
+
exports2.authCheckFailedErrorCode,
|
|
57
|
+
exports2.maxLevelsExceededErrorCode,
|
|
58
|
+
exports2.automationError,
|
|
59
|
+
exports2.internalInvalidInputErrorCode,
|
|
60
|
+
exports2.resultTooBigErrorCode
|
|
61
|
+
];
|
|
62
|
+
var RunAutomationError4 = class {
|
|
63
|
+
constructor(code, message) {
|
|
64
|
+
this.code = code;
|
|
65
|
+
this.message = message;
|
|
82
66
|
}
|
|
83
|
-
|
|
84
|
-
if (!inputParseResult.success) {
|
|
85
|
-
console.error("Validation error:", (0, _formatZodError.formatZodError)(inputParseResult.error));
|
|
67
|
+
get json() {
|
|
86
68
|
return {
|
|
87
|
-
|
|
88
|
-
|
|
69
|
+
code: this.code,
|
|
70
|
+
details: this.details,
|
|
71
|
+
cause: this.cause?.json
|
|
89
72
|
};
|
|
90
73
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (message.type === "abort") {
|
|
97
|
-
abortController.abort();
|
|
98
|
-
return;
|
|
74
|
+
};
|
|
75
|
+
exports2.RunAutomationError = RunAutomationError4;
|
|
76
|
+
var ApiNotFoundError3 = class extends RunAutomationError4 {
|
|
77
|
+
constructor(apiName) {
|
|
78
|
+
super(exports2.apiNotFoundErrorCode, `API ${apiName} not found`);
|
|
99
79
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
80
|
+
};
|
|
81
|
+
exports2.ApiNotFoundError = ApiNotFoundError3;
|
|
82
|
+
var InvalidApiError2 = class extends RunAutomationError4 {
|
|
83
|
+
constructor(message) {
|
|
84
|
+
super(exports2.invalidApiErrorCode, `API is invalid: ${message}`);
|
|
85
|
+
this.details = {
|
|
86
|
+
message
|
|
87
|
+
};
|
|
103
88
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
89
|
+
};
|
|
90
|
+
exports2.InvalidApiError = InvalidApiError2;
|
|
91
|
+
var InvalidCheckError = class extends RunAutomationError4 {
|
|
92
|
+
constructor(message, cause) {
|
|
93
|
+
super(exports2.invalidCheckErrorCode, message);
|
|
94
|
+
this.cause = cause;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
exports2.InvalidCheckError = InvalidCheckError;
|
|
98
|
+
var AbortedError2 = class extends RunAutomationError4 {
|
|
99
|
+
constructor() {
|
|
100
|
+
super(exports2.abortedErrorCode, "Operation was aborted");
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
exports2.AbortedError = AbortedError2;
|
|
104
|
+
var AuthRequiredError2 = class extends RunAutomationError4 {
|
|
105
|
+
constructor() {
|
|
106
|
+
super(exports2.authRequiredErrorCode, "AuthSessions are required");
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
exports2.AuthRequiredError = AuthRequiredError2;
|
|
110
|
+
var AuthCheckNotFoundError = class extends RunAutomationError4 {
|
|
111
|
+
constructor() {
|
|
112
|
+
super(exports2.authCheckNotFoundErrorCode, "AuthSession check not found");
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports2.AuthCheckNotFoundError = AuthCheckNotFoundError;
|
|
116
|
+
var AuthCheckFailedError = class extends RunAutomationError4 {
|
|
117
|
+
constructor() {
|
|
118
|
+
super(exports2.authCheckFailedErrorCode, "AuthSession check failed");
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
exports2.AuthCheckFailedError = AuthCheckFailedError;
|
|
122
|
+
var MaxLevelsExceededError = class extends RunAutomationError4 {
|
|
123
|
+
constructor(levels) {
|
|
124
|
+
super(exports2.maxLevelsExceededErrorCode, `Max levels exceeded. Only ${levels} levels are supported`);
|
|
125
|
+
this.details = { levels };
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
exports2.MaxLevelsExceededError = MaxLevelsExceededError;
|
|
129
|
+
var AutomationError4 = class extends RunAutomationError4 {
|
|
130
|
+
constructor(error) {
|
|
131
|
+
super(exports2.automationError, `[${error?.name ?? error}] ${error?.message}`);
|
|
132
|
+
this.details = {
|
|
133
|
+
...error
|
|
120
134
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
exports2.AutomationError = AutomationError4;
|
|
138
|
+
var InternalInvalidInputError3 = class extends RunAutomationError4 {
|
|
139
|
+
constructor(message, details) {
|
|
140
|
+
super(exports2.internalInvalidInputErrorCode, message);
|
|
141
|
+
this.details = details;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
exports2.InternalInvalidInputError = InternalInvalidInputError3;
|
|
145
|
+
var ResultTooBigError2 = class extends RunAutomationError4 {
|
|
146
|
+
constructor(sizeInBytes, maxSizeInBytes) {
|
|
147
|
+
super(exports2.resultTooBigErrorCode, `Automation result is too big. Size: ${Math.round(sizeInBytes / 1024 / 1024 * 100) / 100}MB, Max allowed: ${Math.round(maxSizeInBytes / 1024 / 1024 * 100) / 100}MB`);
|
|
148
|
+
this.details = { sizeInBytes, maxSizeInBytes };
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
exports2.ResultTooBigError = ResultTooBigError2;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// ../packages/runtime-interface/dist/types.js
|
|
156
|
+
var require_types = __commonJS({
|
|
157
|
+
"../packages/runtime-interface/dist/types.js"(exports2) {
|
|
158
|
+
"use strict";
|
|
159
|
+
var __importDefault = exports2 && exports2.__importDefault || function(mod) {
|
|
160
|
+
return mod && mod.__esModule ? mod : { "default": mod };
|
|
161
|
+
};
|
|
162
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
163
|
+
exports2.outputRunApiSchema = exports2.pongMessageSchema = exports2.doneMessageSchema = exports2.extendMessageSchema = exports2.runApiInputSchema = exports2.pingSchema = exports2.tokenUpdateSchema = exports2.abortRunApiSchema = exports2.startRunApiSchema = exports2.startRunApiParametersSchema = exports2.runApiParametersSchema = exports2.runApiRunOptionsSchema = exports2.runApiCdpRunOptionsSchema = exports2.runApiStandaloneRunOptionsSchema = exports2.runApiAuthSchema = exports2.runApiTracingSchema = exports2.runApiAutomationFunctionSchema = exports2.runApiSessionSchema = exports2.runApiStorageStateSchema = void 0;
|
|
164
|
+
exports2.runApiResultOkSchema = runApiResultOkSchema;
|
|
165
|
+
exports2.runApiResultWithSessionOkSchema = runApiResultWithSessionOkSchema;
|
|
166
|
+
var zod_1 = __importDefault(require("zod"));
|
|
167
|
+
exports2.runApiStorageStateSchema = zod_1.default.object({
|
|
168
|
+
cookies: zod_1.default.array(zod_1.default.object({
|
|
169
|
+
name: zod_1.default.string(),
|
|
170
|
+
value: zod_1.default.string(),
|
|
171
|
+
domain: zod_1.default.string(),
|
|
172
|
+
path: zod_1.default.string(),
|
|
173
|
+
expires: zod_1.default.number(),
|
|
174
|
+
httpOnly: zod_1.default.boolean(),
|
|
175
|
+
secure: zod_1.default.boolean(),
|
|
176
|
+
sameSite: zod_1.default.enum(["Strict", "Lax", "None"])
|
|
177
|
+
})),
|
|
178
|
+
origins: zod_1.default.array(zod_1.default.object({
|
|
179
|
+
origin: zod_1.default.string(),
|
|
180
|
+
localStorage: zod_1.default.array(zod_1.default.object({
|
|
181
|
+
name: zod_1.default.string(),
|
|
182
|
+
value: zod_1.default.string()
|
|
183
|
+
}))
|
|
184
|
+
})),
|
|
185
|
+
sessionStorage: zod_1.default.array(zod_1.default.object({
|
|
186
|
+
origin: zod_1.default.string(),
|
|
187
|
+
sessionStorage: zod_1.default.array(zod_1.default.object({
|
|
188
|
+
name: zod_1.default.string(),
|
|
189
|
+
value: zod_1.default.string()
|
|
190
|
+
}))
|
|
191
|
+
})).optional()
|
|
192
|
+
});
|
|
193
|
+
exports2.runApiSessionSchema = zod_1.default.discriminatedUnion("type", [
|
|
194
|
+
zod_1.default.object({
|
|
195
|
+
type: zod_1.default.literal("file"),
|
|
196
|
+
path: zod_1.default.string()
|
|
197
|
+
}),
|
|
198
|
+
zod_1.default.object({
|
|
199
|
+
type: zod_1.default.literal("state"),
|
|
200
|
+
state: exports2.runApiStorageStateSchema.nullable().optional()
|
|
201
|
+
})
|
|
202
|
+
]);
|
|
203
|
+
exports2.runApiAutomationFunctionSchema = zod_1.default.object({
|
|
204
|
+
name: zod_1.default.string(),
|
|
205
|
+
params: zod_1.default.any().optional()
|
|
206
|
+
});
|
|
207
|
+
exports2.runApiTracingSchema = zod_1.default.discriminatedUnion("enabled", [
|
|
208
|
+
zod_1.default.object({ enabled: zod_1.default.literal(false) }),
|
|
209
|
+
zod_1.default.object({ enabled: zod_1.default.literal(true), filePath: zod_1.default.string() })
|
|
210
|
+
]).optional().default({ enabled: false });
|
|
211
|
+
exports2.runApiAuthSchema = zod_1.default.object({
|
|
212
|
+
session: exports2.runApiSessionSchema,
|
|
213
|
+
parameters: zod_1.default.record(zod_1.default.any()).optional()
|
|
214
|
+
}).optional();
|
|
215
|
+
exports2.runApiStandaloneRunOptionsSchema = zod_1.default.object({
|
|
216
|
+
environment: zod_1.default.literal("standalone"),
|
|
217
|
+
headless: zod_1.default.boolean().default(true),
|
|
218
|
+
proxy: zod_1.default.object({
|
|
219
|
+
server: zod_1.default.string(),
|
|
220
|
+
username: zod_1.default.string(),
|
|
221
|
+
password: zod_1.default.string()
|
|
222
|
+
}).optional()
|
|
223
|
+
});
|
|
224
|
+
exports2.runApiCdpRunOptionsSchema = zod_1.default.object({
|
|
225
|
+
environment: zod_1.default.literal("cdp"),
|
|
226
|
+
cdpAddress: zod_1.default.string(),
|
|
227
|
+
cdpTargetId: zod_1.default.string().optional()
|
|
228
|
+
});
|
|
229
|
+
exports2.runApiRunOptionsSchema = zod_1.default.discriminatedUnion("environment", [
|
|
230
|
+
exports2.runApiStandaloneRunOptionsSchema,
|
|
231
|
+
exports2.runApiCdpRunOptionsSchema
|
|
232
|
+
]).default({ environment: "standalone", headless: true });
|
|
233
|
+
exports2.runApiParametersSchema = zod_1.default.object({
|
|
234
|
+
automationFunction: exports2.runApiAutomationFunctionSchema,
|
|
235
|
+
tracing: exports2.runApiTracingSchema,
|
|
236
|
+
auth: exports2.runApiAuthSchema,
|
|
237
|
+
runOptions: exports2.runApiRunOptionsSchema,
|
|
238
|
+
retrieveSession: zod_1.default.boolean().default(false)
|
|
239
|
+
});
|
|
240
|
+
function runApiResultOkSchema(resultSchema) {
|
|
241
|
+
return zod_1.default.object({
|
|
242
|
+
result: resultSchema,
|
|
243
|
+
extendedPayloads: zod_1.default.array(zod_1.default.object({
|
|
244
|
+
api: zod_1.default.string(),
|
|
245
|
+
parameters: zod_1.default.record(zod_1.default.any())
|
|
246
|
+
})).optional()
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function runApiResultWithSessionOkSchema(resultSchema) {
|
|
250
|
+
return runApiResultOkSchema(resultSchema).extend({
|
|
251
|
+
session: exports2.runApiStorageStateSchema
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
exports2.startRunApiParametersSchema = exports2.runApiParametersSchema.extend({
|
|
255
|
+
retrieveSession: zod_1.default.boolean(),
|
|
256
|
+
functionsToken: zod_1.default.string().optional(),
|
|
257
|
+
context: zod_1.default.object({
|
|
258
|
+
jobId: zod_1.default.string().optional(),
|
|
259
|
+
jobRunId: zod_1.default.string().optional(),
|
|
260
|
+
runId: zod_1.default.string().optional(),
|
|
261
|
+
queueId: zod_1.default.string().optional(),
|
|
262
|
+
authSessionId: zod_1.default.string().optional()
|
|
263
|
+
}).optional()
|
|
264
|
+
});
|
|
265
|
+
exports2.startRunApiSchema = zod_1.default.object({
|
|
266
|
+
type: zod_1.default.literal("start"),
|
|
267
|
+
parameters: exports2.startRunApiParametersSchema
|
|
268
|
+
});
|
|
269
|
+
exports2.abortRunApiSchema = zod_1.default.object({
|
|
270
|
+
type: zod_1.default.literal("abort"),
|
|
271
|
+
parameters: zod_1.default.object({}).optional()
|
|
272
|
+
});
|
|
273
|
+
exports2.tokenUpdateSchema = zod_1.default.object({
|
|
274
|
+
type: zod_1.default.literal("tokenUpdate"),
|
|
275
|
+
parameters: zod_1.default.object({
|
|
276
|
+
functionsToken: zod_1.default.string()
|
|
277
|
+
})
|
|
278
|
+
});
|
|
279
|
+
exports2.pingSchema = zod_1.default.object({
|
|
280
|
+
type: zod_1.default.literal("ping"),
|
|
281
|
+
parameters: zod_1.default.object({}).optional()
|
|
282
|
+
});
|
|
283
|
+
exports2.runApiInputSchema = zod_1.default.union([
|
|
284
|
+
exports2.startRunApiSchema,
|
|
285
|
+
exports2.abortRunApiSchema,
|
|
286
|
+
exports2.tokenUpdateSchema,
|
|
287
|
+
exports2.pingSchema
|
|
288
|
+
]);
|
|
289
|
+
exports2.extendMessageSchema = zod_1.default.object({ type: zod_1.default.literal("extend") });
|
|
290
|
+
exports2.doneMessageSchema = zod_1.default.object({
|
|
291
|
+
type: zod_1.default.literal("done"),
|
|
292
|
+
result: zod_1.default.any(),
|
|
293
|
+
success: zod_1.default.boolean()
|
|
294
|
+
});
|
|
295
|
+
exports2.pongMessageSchema = zod_1.default.object({
|
|
296
|
+
type: zod_1.default.literal("pong")
|
|
297
|
+
});
|
|
298
|
+
exports2.outputRunApiSchema = zod_1.default.union([
|
|
299
|
+
exports2.extendMessageSchema,
|
|
300
|
+
exports2.doneMessageSchema,
|
|
301
|
+
exports2.pongMessageSchema
|
|
302
|
+
]);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
// ../packages/runtime-interface/dist/interfaceClient.js
|
|
307
|
+
var require_interfaceClient = __commonJS({
|
|
308
|
+
"../packages/runtime-interface/dist/interfaceClient.js"(exports2) {
|
|
309
|
+
"use strict";
|
|
310
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
311
|
+
if (k2 === void 0) k2 = k;
|
|
312
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
313
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
314
|
+
desc = { enumerable: true, get: function() {
|
|
315
|
+
return m[k];
|
|
316
|
+
} };
|
|
317
|
+
}
|
|
318
|
+
Object.defineProperty(o, k2, desc);
|
|
319
|
+
}) : (function(o, m, k, k2) {
|
|
320
|
+
if (k2 === void 0) k2 = k;
|
|
321
|
+
o[k2] = m[k];
|
|
322
|
+
}));
|
|
323
|
+
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
324
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
325
|
+
}) : function(o, v) {
|
|
326
|
+
o["default"] = v;
|
|
327
|
+
});
|
|
328
|
+
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
329
|
+
if (mod && mod.__esModule) return mod;
|
|
330
|
+
var result = {};
|
|
331
|
+
if (mod != null) {
|
|
332
|
+
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
333
|
+
}
|
|
334
|
+
__setModuleDefault(result, mod);
|
|
335
|
+
return result;
|
|
336
|
+
};
|
|
337
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
338
|
+
exports2.JSONLFileClient = exports2.TCPSocketClient = exports2.UnixSocketClient = exports2.SocketClient = void 0;
|
|
339
|
+
var net = __importStar(require("net"));
|
|
340
|
+
var fs5 = __importStar(require("fs-extra"));
|
|
341
|
+
var readline_1 = require("readline");
|
|
342
|
+
var promises_1 = require("timers/promises");
|
|
343
|
+
var SocketClient = class _SocketClient {
|
|
344
|
+
constructor(socket) {
|
|
345
|
+
this.socket = socket;
|
|
346
|
+
}
|
|
347
|
+
sendJSON(data) {
|
|
348
|
+
const dataToSend = JSON.stringify(data);
|
|
349
|
+
const length = Buffer.byteLength(dataToSend);
|
|
350
|
+
const buffer = Buffer.alloc(_SocketClient.LENGTH_HEADER_LENGTH + length);
|
|
351
|
+
buffer.writeUInt32BE(length, 0);
|
|
352
|
+
buffer.write(dataToSend, _SocketClient.LENGTH_HEADER_LENGTH);
|
|
353
|
+
this.socket.write(buffer);
|
|
354
|
+
}
|
|
355
|
+
async *receiveJSON() {
|
|
356
|
+
let buffer = Buffer.alloc(0);
|
|
357
|
+
const endPromise = new Promise((resolve2, reject) => {
|
|
358
|
+
this.socket.once("end", () => {
|
|
359
|
+
resolve2();
|
|
127
360
|
});
|
|
361
|
+
this.socket.once("error", reject);
|
|
128
362
|
});
|
|
363
|
+
while (true) {
|
|
364
|
+
const chunk = await Promise.race([
|
|
365
|
+
new Promise((resolve2) => this.socket.once("data", (data2) => {
|
|
366
|
+
if (typeof data2 === "string") {
|
|
367
|
+
return resolve2(Buffer.from(data2));
|
|
368
|
+
}
|
|
369
|
+
resolve2(data2);
|
|
370
|
+
})),
|
|
371
|
+
endPromise
|
|
372
|
+
]);
|
|
373
|
+
if (!(chunk instanceof Buffer)) {
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
377
|
+
const length = buffer.readUInt32BE(0);
|
|
378
|
+
if (buffer.length < length + _SocketClient.LENGTH_HEADER_LENGTH) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const data = buffer.subarray(_SocketClient.LENGTH_HEADER_LENGTH, length + _SocketClient.LENGTH_HEADER_LENGTH);
|
|
382
|
+
buffer = buffer.subarray(length + _SocketClient.LENGTH_HEADER_LENGTH);
|
|
383
|
+
yield JSON.parse(data.toString());
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
async close() {
|
|
387
|
+
this.socket.end();
|
|
388
|
+
await Promise.race([
|
|
389
|
+
new Promise((resolve2) => this.socket.once("close", resolve2)),
|
|
390
|
+
new Promise((resolve2) => this.socket.once("error", resolve2)),
|
|
391
|
+
(0, promises_1.setTimeout)(3e3)
|
|
392
|
+
]);
|
|
393
|
+
}
|
|
394
|
+
get closed() {
|
|
395
|
+
return this.socket.closed;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
exports2.SocketClient = SocketClient;
|
|
399
|
+
SocketClient.LENGTH_HEADER_LENGTH = 4;
|
|
400
|
+
var UnixSocketClient2 = class extends SocketClient {
|
|
401
|
+
constructor(path4) {
|
|
402
|
+
super(net.createConnection(path4));
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
exports2.UnixSocketClient = UnixSocketClient2;
|
|
406
|
+
var TCPSocketClient2 = class extends SocketClient {
|
|
407
|
+
constructor(host, port) {
|
|
408
|
+
super(net.createConnection(port, host));
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
exports2.TCPSocketClient = TCPSocketClient2;
|
|
412
|
+
var JSONLFileClient2 = class {
|
|
413
|
+
constructor(filePath) {
|
|
414
|
+
this.fileStream = fs5.createReadStream(filePath, { encoding: "utf-8" });
|
|
415
|
+
}
|
|
416
|
+
sendJSON(data) {
|
|
417
|
+
console.log("Sending message", data);
|
|
418
|
+
}
|
|
419
|
+
async *receiveJSON() {
|
|
420
|
+
const rl = (0, readline_1.createInterface)({
|
|
421
|
+
input: this.fileStream,
|
|
422
|
+
crlfDelay: Infinity
|
|
423
|
+
});
|
|
424
|
+
for await (const line of rl) {
|
|
425
|
+
if (line.trim() === "") {
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
yield JSON.parse(line);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
async close() {
|
|
432
|
+
this.fileStream.close();
|
|
433
|
+
await Promise.race([
|
|
434
|
+
new Promise((resolve2) => this.fileStream.once("close", resolve2)),
|
|
435
|
+
new Promise((resolve2) => this.fileStream.once("error", resolve2)),
|
|
436
|
+
(0, promises_1.setTimeout)(3e3)
|
|
437
|
+
]);
|
|
438
|
+
}
|
|
439
|
+
get closed() {
|
|
440
|
+
return this.fileStream.closed;
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
exports2.JSONLFileClient = JSONLFileClient2;
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
// ../packages/runtime-interface/dist/index.js
|
|
448
|
+
var require_dist = __commonJS({
|
|
449
|
+
"../packages/runtime-interface/dist/index.js"(exports2) {
|
|
450
|
+
"use strict";
|
|
451
|
+
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
452
|
+
if (k2 === void 0) k2 = k;
|
|
453
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
454
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
455
|
+
desc = { enumerable: true, get: function() {
|
|
456
|
+
return m[k];
|
|
457
|
+
} };
|
|
458
|
+
}
|
|
459
|
+
Object.defineProperty(o, k2, desc);
|
|
460
|
+
}) : (function(o, m, k, k2) {
|
|
461
|
+
if (k2 === void 0) k2 = k;
|
|
462
|
+
o[k2] = m[k];
|
|
463
|
+
}));
|
|
464
|
+
var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
|
|
465
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
|
|
466
|
+
};
|
|
467
|
+
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
468
|
+
__exportStar(require_errors(), exports2);
|
|
469
|
+
__exportStar(require_types(), exports2);
|
|
470
|
+
__exportStar(require_interfaceClient(), exports2);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
// src/commands/interface/run.ts
|
|
475
|
+
var run_exports = {};
|
|
476
|
+
__export(run_exports, {
|
|
477
|
+
runAutomationCLI: () => runAutomationCLI
|
|
478
|
+
});
|
|
479
|
+
module.exports = __toCommonJS(run_exports);
|
|
480
|
+
var import_commander = require("commander");
|
|
481
|
+
var import_dotenv2 = __toESM(require("dotenv"));
|
|
482
|
+
|
|
483
|
+
// src/common/asyncLocalStorage/index.ts
|
|
484
|
+
var import_node_async_hooks = require("async_hooks");
|
|
485
|
+
var asyncLocalStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
486
|
+
function runWithContext(contextData, callback, ...args) {
|
|
487
|
+
return asyncLocalStorage.run(contextData, callback, ...args);
|
|
488
|
+
}
|
|
489
|
+
function getExecutionContext() {
|
|
490
|
+
const contextData = asyncLocalStorage.getStore();
|
|
491
|
+
return contextData;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// src/runtime/attemptStore.ts
|
|
495
|
+
var attemptStore = Object.freeze({
|
|
496
|
+
get: (key) => {
|
|
497
|
+
const context = getExecutionContext();
|
|
498
|
+
return context?.store ? context.store[key] : void 0;
|
|
499
|
+
},
|
|
500
|
+
set: (key, value) => {
|
|
501
|
+
const context = getExecutionContext();
|
|
502
|
+
if (!context) {
|
|
503
|
+
throw new Error("store.set failed due to an internal error.");
|
|
504
|
+
}
|
|
505
|
+
if (!context.store) {
|
|
506
|
+
context.store = {};
|
|
507
|
+
}
|
|
508
|
+
context.store[key] = value;
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
|
|
512
|
+
// src/runtime/persistentStore.ts
|
|
513
|
+
var import_zod = require("zod");
|
|
514
|
+
|
|
515
|
+
// src/common/jwtTokenManager.ts
|
|
516
|
+
var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
517
|
+
var jwt = __toESM(require("jsonwebtoken"));
|
|
518
|
+
var import_neverthrow = require("neverthrow");
|
|
519
|
+
|
|
520
|
+
// src/common/constants.ts
|
|
521
|
+
var WORKSPACE_ID_ENV_VAR_KEY = "INTUNED_WORKSPACE_ID";
|
|
522
|
+
var PROJECT_ID_ENV_VAR_KEY = "INTUNED_PROJECT_ID";
|
|
523
|
+
var API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
|
|
524
|
+
var AUTH_TOKEN_ENV_VAR_KEY = "INTUNED_AUTH_TOKEN";
|
|
525
|
+
var API_KEY_HEADER_NAME = "x-api-key";
|
|
526
|
+
var CLI_ENV_VAR_KEY = "INTUNED_CLI";
|
|
527
|
+
|
|
528
|
+
// src/common/jwtTokenManager.ts
|
|
529
|
+
var JwtTokenManager = class {
|
|
530
|
+
constructor(refreshTokenPath) {
|
|
531
|
+
this.refreshTokenPath = refreshTokenPath;
|
|
532
|
+
this._token = void 0;
|
|
533
|
+
}
|
|
534
|
+
get token() {
|
|
535
|
+
return this._token;
|
|
536
|
+
}
|
|
537
|
+
// When the token is set, the schedule for renewal is issued automatically
|
|
538
|
+
// This is currently being set it two places:
|
|
539
|
+
// 1. Whenever the runner starts, initializes it from the environment variable (set whenever the api is run from the authoring IDE)
|
|
540
|
+
// 2. Whenever a published api is called to run (/api/run/*), it is set to the token received in the run request.
|
|
541
|
+
set token(newToken) {
|
|
542
|
+
if (this._token != newToken) {
|
|
543
|
+
this._token = newToken;
|
|
544
|
+
void this.scheduleTokenRefresh();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
get timeToRefresh() {
|
|
548
|
+
if (!this._token) return;
|
|
549
|
+
const payload = jwt.decode(this._token);
|
|
550
|
+
if (!payload || typeof payload == "string") return;
|
|
551
|
+
const expiry = payload.expiry;
|
|
552
|
+
if (!expiry || typeof expiry !== "number") return;
|
|
553
|
+
const timeWindow = 60 * 1e3;
|
|
554
|
+
const timeToRefresh = expiry - Date.now() - timeWindow;
|
|
555
|
+
return Math.max(timeToRefresh, timeWindow);
|
|
556
|
+
}
|
|
557
|
+
async scheduleTokenRefresh() {
|
|
558
|
+
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
|
|
559
|
+
const timeToRefresh = this.timeToRefresh;
|
|
560
|
+
if (timeToRefresh === void 0) return;
|
|
561
|
+
if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
|
|
562
|
+
this.tokenRefreshTimeout = setTimeout(async () => {
|
|
563
|
+
const result = await this.refreshToken();
|
|
564
|
+
if (result && result.isErr()) {
|
|
565
|
+
console.error(`[Internal Error] ${result.error}`);
|
|
129
566
|
return;
|
|
130
567
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
568
|
+
await this.scheduleTokenRefresh();
|
|
569
|
+
}, timeToRefresh);
|
|
570
|
+
}
|
|
571
|
+
async refreshToken() {
|
|
572
|
+
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
|
|
573
|
+
const res = await this.fetchWithToken(
|
|
574
|
+
`${this.backendFunctionsBaseUrl}/${this.refreshTokenPath}`,
|
|
575
|
+
{
|
|
576
|
+
method: "GET"
|
|
577
|
+
}
|
|
578
|
+
);
|
|
579
|
+
if (res.status === 401) {
|
|
580
|
+
return (0, import_neverthrow.err)("Unauthorized");
|
|
581
|
+
}
|
|
582
|
+
const jsonResult = await import_neverthrow.ResultAsync.fromPromise(
|
|
583
|
+
res.json(),
|
|
584
|
+
() => "not json"
|
|
585
|
+
);
|
|
586
|
+
if (jsonResult.isErr()) return;
|
|
587
|
+
const newToken = jsonResult.value.token;
|
|
588
|
+
if (newToken) this._token = newToken;
|
|
589
|
+
}
|
|
590
|
+
async fetchWithToken(...[input, init]) {
|
|
591
|
+
const headers = new Headers(init?.headers);
|
|
592
|
+
const apiKey = process.env[API_KEY_ENV_VAR_KEY];
|
|
593
|
+
if (apiKey) {
|
|
594
|
+
headers.set(API_KEY_HEADER_NAME, apiKey);
|
|
595
|
+
}
|
|
596
|
+
const token = process.env[AUTH_TOKEN_ENV_VAR_KEY];
|
|
597
|
+
if (token) {
|
|
598
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
599
|
+
}
|
|
600
|
+
if (this.token !== void 0) {
|
|
601
|
+
headers.set("Authorization", `Bearer ${this.token}`);
|
|
602
|
+
}
|
|
603
|
+
const result = await (0, import_cross_fetch.default)(input, {
|
|
604
|
+
...init,
|
|
605
|
+
headers
|
|
606
|
+
});
|
|
607
|
+
if (result.status === 401 && process.env[CLI_ENV_VAR_KEY] === "true") {
|
|
608
|
+
console.warn(
|
|
609
|
+
"Unauthorized backend function call - make sure to provision your project to Intuned to set up the correct API credentials.\nRun 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information."
|
|
610
|
+
);
|
|
611
|
+
}
|
|
612
|
+
return result;
|
|
613
|
+
}
|
|
614
|
+
get backendFunctionsBaseUrl() {
|
|
615
|
+
try {
|
|
616
|
+
if (!process.env.FUNCTIONS_DOMAIN) {
|
|
617
|
+
throw new Error(
|
|
618
|
+
`Cannot call backend function - FUNCTIONS_DOMAIN not set`
|
|
619
|
+
);
|
|
620
|
+
}
|
|
621
|
+
const domain = process.env.FUNCTIONS_DOMAIN;
|
|
622
|
+
if (!process.env[WORKSPACE_ID_ENV_VAR_KEY]) {
|
|
623
|
+
throw new Error(
|
|
624
|
+
`Cannot call backend function - ${WORKSPACE_ID_ENV_VAR_KEY} not set`
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
const workspaceId = process.env[WORKSPACE_ID_ENV_VAR_KEY];
|
|
628
|
+
if (!process.env[PROJECT_ID_ENV_VAR_KEY] && !process.env.INTUNED_INTEGRATION_ID) {
|
|
629
|
+
throw new Error(
|
|
630
|
+
`Cannot call backend function - ${PROJECT_ID_ENV_VAR_KEY} or INTUNED_INTEGRATION_ID not set`
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
const projectId = process.env.INTUNED_INTEGRATION_ID ?? process.env[PROJECT_ID_ENV_VAR_KEY];
|
|
634
|
+
return `${domain}/api/${workspaceId}/functions/${projectId}`;
|
|
635
|
+
} catch (e) {
|
|
636
|
+
if (process.env[CLI_ENV_VAR_KEY] === "true") {
|
|
637
|
+
throw new Error(
|
|
638
|
+
`API credentials not set - make sure to provision your project to Intuned to set up the correct API credentials.
|
|
639
|
+
Run 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information.
|
|
640
|
+
Original error: ${e.message}`
|
|
641
|
+
);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
var backendFunctionsTokenManager = new JwtTokenManager(
|
|
647
|
+
`refreshBackendFunctionsToken`
|
|
648
|
+
);
|
|
649
|
+
backendFunctionsTokenManager.token = process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;
|
|
650
|
+
function callBackendFunctionWithToken(path4, init) {
|
|
651
|
+
return backendFunctionsTokenManager.fetchWithToken(
|
|
652
|
+
`${backendFunctionsTokenManager.backendFunctionsBaseUrl}/${path4}`,
|
|
653
|
+
init
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
// src/runtime/persistentStore.ts
|
|
658
|
+
var forbiddenCharacters = /[:#]/g;
|
|
659
|
+
var keySchema = import_zod.z.string().min(1, "Key must be at least 1 character long").refine(
|
|
660
|
+
(key) => (key.match(forbiddenCharacters)?.length ?? 0) === 0,
|
|
661
|
+
'Key cannot contain the following characters: ":" or "#"'
|
|
662
|
+
);
|
|
663
|
+
var persistentStore = Object.freeze({
|
|
664
|
+
get: async (key) => {
|
|
665
|
+
const parsedKey = keySchema.parse(key);
|
|
666
|
+
const response = await callBackendFunctionWithToken(
|
|
667
|
+
`kv-store/${parsedKey}`,
|
|
668
|
+
{
|
|
669
|
+
method: "GET"
|
|
670
|
+
}
|
|
671
|
+
);
|
|
672
|
+
const json = await response.json();
|
|
673
|
+
if (!response.ok) {
|
|
674
|
+
throw new Error(json.message);
|
|
675
|
+
}
|
|
676
|
+
return json.value;
|
|
677
|
+
},
|
|
678
|
+
set: async (key, value) => {
|
|
679
|
+
const keyResult = keySchema.parse(key);
|
|
680
|
+
const response = await callBackendFunctionWithToken(
|
|
681
|
+
`kv-store/${keyResult}`,
|
|
682
|
+
{
|
|
683
|
+
method: "PUT",
|
|
684
|
+
body: JSON.stringify(value),
|
|
685
|
+
headers: {
|
|
686
|
+
"Content-Type": "application/json"
|
|
158
687
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
688
|
+
}
|
|
689
|
+
);
|
|
690
|
+
const json = await response.json();
|
|
691
|
+
if (!response.ok) {
|
|
692
|
+
throw new Error(json.message);
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
// src/runtime/RunError.ts
|
|
698
|
+
var RunError = class _RunError extends Error {
|
|
699
|
+
constructor(message, options) {
|
|
700
|
+
super(message);
|
|
701
|
+
this.message = message;
|
|
702
|
+
this.name = "USER_GENERATED_ERROR";
|
|
703
|
+
this.options = options ?? {
|
|
704
|
+
retryable: false
|
|
705
|
+
};
|
|
706
|
+
Object.setPrototypeOf(this, _RunError.prototype);
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
new RunError("", {});
|
|
710
|
+
|
|
711
|
+
// src/common/extension/intunedExtensionServer.ts
|
|
712
|
+
var import_fastify = __toESM(require("fastify"));
|
|
713
|
+
|
|
714
|
+
// src/common/extension/types.ts
|
|
715
|
+
var import_zod2 = require("zod");
|
|
716
|
+
var captchaTypeSchema = import_zod2.z.enum([
|
|
717
|
+
"aws",
|
|
718
|
+
"cloudflare",
|
|
719
|
+
"customcaptcha",
|
|
720
|
+
"funcaptcha",
|
|
721
|
+
"geetest",
|
|
722
|
+
"hcaptcha",
|
|
723
|
+
"lemincaptcha",
|
|
724
|
+
"recaptcha",
|
|
725
|
+
"textcaptcha"
|
|
726
|
+
]);
|
|
727
|
+
var captchaStatusSchema = import_zod2.z.enum([
|
|
728
|
+
"attached",
|
|
729
|
+
"solving",
|
|
730
|
+
"solved",
|
|
731
|
+
"error",
|
|
732
|
+
"detached"
|
|
733
|
+
]);
|
|
734
|
+
var captchaErrorCodeSchema = import_zod2.z.enum([
|
|
735
|
+
"HIT_LIMIT",
|
|
736
|
+
"MAX_RETRIES",
|
|
737
|
+
"UNEXPECTED_SERVER_RESPONSE",
|
|
738
|
+
"UNEXPECTED_ERROR"
|
|
739
|
+
]);
|
|
740
|
+
var captchaErrorSchema = import_zod2.z.object({
|
|
741
|
+
code: captchaErrorCodeSchema,
|
|
742
|
+
error: import_zod2.z.unknown().optional()
|
|
743
|
+
});
|
|
744
|
+
var captchaBaseSchema = import_zod2.z.object({
|
|
745
|
+
id: import_zod2.z.string().min(1),
|
|
746
|
+
tabId: import_zod2.z.number().int().positive(),
|
|
747
|
+
type: captchaTypeSchema,
|
|
748
|
+
retryCount: import_zod2.z.number().int().nonnegative().optional()
|
|
749
|
+
});
|
|
750
|
+
var captchaNonErrorSchema = captchaBaseSchema.extend({
|
|
751
|
+
status: captchaStatusSchema.exclude(["error"])
|
|
752
|
+
});
|
|
753
|
+
var captchaErrorStatusSchema = captchaBaseSchema.extend({
|
|
754
|
+
status: import_zod2.z.literal("error"),
|
|
755
|
+
error: captchaErrorSchema
|
|
756
|
+
});
|
|
757
|
+
var captchaSchema = import_zod2.z.discriminatedUnion("status", [
|
|
758
|
+
captchaBaseSchema.extend({
|
|
759
|
+
status: import_zod2.z.literal("attached")
|
|
760
|
+
}),
|
|
761
|
+
captchaBaseSchema.extend({
|
|
762
|
+
status: import_zod2.z.literal("solving")
|
|
763
|
+
}),
|
|
764
|
+
captchaBaseSchema.extend({
|
|
765
|
+
status: import_zod2.z.literal("solved")
|
|
766
|
+
}),
|
|
767
|
+
captchaBaseSchema.extend({
|
|
768
|
+
status: import_zod2.z.literal("detached")
|
|
769
|
+
}),
|
|
770
|
+
captchaErrorStatusSchema
|
|
771
|
+
]);
|
|
772
|
+
|
|
773
|
+
// src/commands/common/utils/fileUtils.ts
|
|
774
|
+
var path = __toESM(require("path"));
|
|
775
|
+
var fs = __toESM(require("fs-extra"));
|
|
776
|
+
var import_dotenv = __toESM(require("dotenv"));
|
|
777
|
+
import_dotenv.default.config();
|
|
778
|
+
function getFullPathInProject(...paths) {
|
|
779
|
+
return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// src/common/settingsSchema.ts
|
|
783
|
+
var z3 = __toESM(require("zod"));
|
|
784
|
+
var baseCaptchaSchema = z3.object({
|
|
785
|
+
enabled: z3.boolean()
|
|
786
|
+
});
|
|
787
|
+
var customCaptchaSchema = baseCaptchaSchema.extend({
|
|
788
|
+
imageLocators: z3.array(z3.string()).min(1, "At least one image locator is required"),
|
|
789
|
+
submitLocators: z3.array(z3.string()).min(1, "At least one submit locator is required"),
|
|
790
|
+
inputLocators: z3.array(z3.string()).min(1, "At least one input locator is required")
|
|
791
|
+
});
|
|
792
|
+
var textCaptchaSchema = baseCaptchaSchema.extend({
|
|
793
|
+
labelLocators: z3.array(z3.string()).min(1, "At least one image locator is required"),
|
|
794
|
+
submitLocators: z3.array(z3.string()).min(1, "At least one submit locator is required"),
|
|
795
|
+
inputLocators: z3.array(z3.string()).min(1, "At least one input locator is required")
|
|
796
|
+
});
|
|
797
|
+
var captchaSolverSolveSettingsSchema = z3.object({
|
|
798
|
+
autoSolve: z3.boolean().default(true),
|
|
799
|
+
solveDelay: z3.number().min(0).default(2e3),
|
|
800
|
+
maxRetries: z3.number().min(0).default(3),
|
|
801
|
+
timeout: z3.number().min(0).default(3e4)
|
|
802
|
+
});
|
|
803
|
+
var captchaSolverSettingsSchema = z3.object({
|
|
804
|
+
enabled: z3.boolean().default(false),
|
|
805
|
+
port: z3.number().int().min(1).max(65535).optional(),
|
|
806
|
+
cloudflare: baseCaptchaSchema.optional(),
|
|
807
|
+
googleRecaptchaV2: baseCaptchaSchema.optional(),
|
|
808
|
+
googleRecaptchaV3: baseCaptchaSchema.optional(),
|
|
809
|
+
awscaptcha: baseCaptchaSchema.optional(),
|
|
810
|
+
hcaptcha: baseCaptchaSchema.optional(),
|
|
811
|
+
funcaptcha: baseCaptchaSchema.optional(),
|
|
812
|
+
geetest: baseCaptchaSchema.optional(),
|
|
813
|
+
lemin: baseCaptchaSchema.optional(),
|
|
814
|
+
customCaptcha: customCaptchaSchema.optional(),
|
|
815
|
+
text: textCaptchaSchema.optional(),
|
|
816
|
+
settings: captchaSolverSolveSettingsSchema.default(
|
|
817
|
+
captchaSolverSolveSettingsSchema.parse({})
|
|
818
|
+
)
|
|
819
|
+
}).default({});
|
|
820
|
+
var authSessionsSchema = z3.object({
|
|
821
|
+
enabled: z3.boolean()
|
|
822
|
+
}).optional().default({
|
|
823
|
+
enabled: false
|
|
824
|
+
});
|
|
825
|
+
var stealthModeSchema = z3.object({
|
|
826
|
+
enabled: z3.boolean()
|
|
827
|
+
}).optional().default({
|
|
828
|
+
enabled: false
|
|
829
|
+
});
|
|
830
|
+
var settingsSchema = z3.object({
|
|
831
|
+
authSessions: authSessionsSchema,
|
|
832
|
+
stealthMode: stealthModeSchema,
|
|
833
|
+
captchaSolver: captchaSolverSettingsSchema.optional()
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
// src/commands/common/utils/settings.ts
|
|
837
|
+
var import_promises = require("fs/promises");
|
|
838
|
+
async function getSettings() {
|
|
839
|
+
const settingsFilePath = getFullPathInProject("Intuned.json");
|
|
840
|
+
const settings = await (0, import_promises.readFile)(settingsFilePath, { encoding: "utf-8" });
|
|
841
|
+
if (settings) {
|
|
842
|
+
const parsed = settingsSchema.safeParse(JSON.parse(settings));
|
|
843
|
+
if (parsed.success) {
|
|
844
|
+
return parsed.data;
|
|
845
|
+
} else {
|
|
846
|
+
throw new Error(parsed.error.message);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
return {
|
|
850
|
+
authSessions: { enabled: false },
|
|
851
|
+
stealthMode: { enabled: false }
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
// src/common/extension/extensionsHelpers.ts
|
|
856
|
+
var import_path = __toESM(require("path"));
|
|
857
|
+
var import_promises2 = require("fs/promises");
|
|
858
|
+
var import_portfinder = require("portfinder");
|
|
859
|
+
var INTUNED_WORKER = "intunedWorker.js";
|
|
860
|
+
var INTUNED_EXTENSION_SETTINGS_FILE_NAME = "intunedSettings.json";
|
|
861
|
+
var captchaSolverSettings = null;
|
|
862
|
+
async function getIntunedCaptchaExtensionPort() {
|
|
863
|
+
if (process.env.INTUNED_CAPTCHA_EXTENSION_PORT) {
|
|
864
|
+
return parseInt(process.env.INTUNED_CAPTCHA_EXTENSION_PORT, 10);
|
|
865
|
+
}
|
|
866
|
+
return await (0, import_portfinder.getPort)({});
|
|
867
|
+
}
|
|
868
|
+
async function resolveCaptchaSolverSettings(input) {
|
|
869
|
+
const parsed = captchaSolverSettingsSchema.parse(input || {});
|
|
870
|
+
if (!parsed.port) {
|
|
871
|
+
parsed.port = await getIntunedCaptchaExtensionPort();
|
|
872
|
+
}
|
|
873
|
+
return parsed;
|
|
874
|
+
}
|
|
875
|
+
function isIntunedExtensionLoaded() {
|
|
876
|
+
return !!getIntunedExtensionPath();
|
|
877
|
+
}
|
|
878
|
+
function buildExtensionsList() {
|
|
879
|
+
const extensionsList = [];
|
|
880
|
+
if (isIntunedExtensionLoaded()) {
|
|
881
|
+
const intunedExtensionPath = getIntunedExtensionPath();
|
|
882
|
+
extensionsList.push(intunedExtensionPath);
|
|
883
|
+
}
|
|
884
|
+
return extensionsList;
|
|
885
|
+
}
|
|
886
|
+
function getIntunedExtensionPath() {
|
|
887
|
+
return process.env.INTUNED_EXTENSION_PATH;
|
|
888
|
+
}
|
|
889
|
+
async function isIntunedExtensionEnabled() {
|
|
890
|
+
const path4 = getIntunedExtensionPath();
|
|
891
|
+
if (!path4) {
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
const captchaSolverSettings2 = await getIntunedCaptchaSolverSettings();
|
|
895
|
+
return captchaSolverSettings2.enabled;
|
|
896
|
+
}
|
|
897
|
+
async function getIntunedExtensionWorker(context) {
|
|
898
|
+
if (!await isIntunedExtensionEnabled()) {
|
|
899
|
+
return null;
|
|
900
|
+
}
|
|
901
|
+
let attemptCount = 0;
|
|
902
|
+
while (attemptCount < 4) {
|
|
903
|
+
const intunedServiceWorker = context.serviceWorkers().find((serviceWorker) => serviceWorker.url().includes(INTUNED_WORKER));
|
|
904
|
+
if (intunedServiceWorker) {
|
|
905
|
+
return intunedServiceWorker;
|
|
906
|
+
}
|
|
907
|
+
try {
|
|
908
|
+
await context.waitForEvent("serviceworker", { timeout: 3e3 });
|
|
909
|
+
} catch (err7) {
|
|
910
|
+
console.log(`Error accessing service workers (attempt ${attemptCount})`);
|
|
911
|
+
}
|
|
912
|
+
attemptCount++;
|
|
913
|
+
}
|
|
914
|
+
console.error("Failed to get intuned worker after 5 attmepts");
|
|
915
|
+
return null;
|
|
916
|
+
}
|
|
917
|
+
async function getIntunedExtensionSettings(captchaSolverSettings2) {
|
|
918
|
+
const [domain, workspaceId, projectId] = [
|
|
919
|
+
process.env.FUNCTIONS_DOMAIN,
|
|
920
|
+
process.env[WORKSPACE_ID_ENV_VAR_KEY],
|
|
921
|
+
process.env.INTUNED_INTEGRATION_ID ?? process.env[PROJECT_ID_ENV_VAR_KEY]
|
|
922
|
+
];
|
|
923
|
+
if (!domain || !workspaceId || !projectId) {
|
|
924
|
+
const missingEnvVars = [
|
|
925
|
+
domain && "FUNCTIONS_DOMAIN",
|
|
926
|
+
workspaceId && WORKSPACE_ID_ENV_VAR_KEY,
|
|
927
|
+
projectId && `INTUNED_INTEGRATION_ID OR ${PROJECT_ID_ENV_VAR_KEY}`
|
|
928
|
+
];
|
|
929
|
+
throw new Error(
|
|
930
|
+
`Missing required environment variables: ${missingEnvVars}`
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
const authentication = (() => {
|
|
934
|
+
if (process.env.INTUNED_API_KEY) {
|
|
935
|
+
return { type: "apiKey", apiKey: process.env.INTUNED_API_KEY };
|
|
936
|
+
}
|
|
937
|
+
if (process.env.INTUNED_BASIC_AUTH_USERNAME && process.env.INTUNED_BASIC_AUTH_PASSWORD) {
|
|
938
|
+
const credentials = `${process.env.INTUNED_BASIC_AUTH_USERNAME}:${process.env.INTUNED_BASIC_AUTH_PASSWORD}`;
|
|
939
|
+
const token = Buffer.from(credentials, "utf-8").toString("base64");
|
|
940
|
+
return { type: "basic", token };
|
|
941
|
+
}
|
|
942
|
+
return {
|
|
943
|
+
type: "bearer",
|
|
944
|
+
token: backendFunctionsTokenManager.token
|
|
945
|
+
};
|
|
946
|
+
})();
|
|
947
|
+
const baseUrl = process.env.INTUNED_API_BASE_URL ?? domain;
|
|
948
|
+
return {
|
|
949
|
+
...captchaSolverSettings2,
|
|
950
|
+
workspaceId,
|
|
951
|
+
projectId,
|
|
952
|
+
baseUrl,
|
|
953
|
+
authentication
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
async function getIntunedCaptchaSolverSettings() {
|
|
957
|
+
if (captchaSolverSettings) {
|
|
958
|
+
return captchaSolverSettings;
|
|
959
|
+
}
|
|
960
|
+
const settings = await getSettings();
|
|
961
|
+
captchaSolverSettings = await resolveCaptchaSolverSettings(
|
|
962
|
+
settings.captchaSolver
|
|
963
|
+
);
|
|
964
|
+
return captchaSolverSettings;
|
|
965
|
+
}
|
|
966
|
+
async function setupIntunedExtension() {
|
|
967
|
+
if (!await isIntunedExtensionEnabled()) {
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
const intunedExtensionPath = getIntunedExtensionPath();
|
|
971
|
+
const intunedExtensionSettingsPath = import_path.default.join(
|
|
972
|
+
intunedExtensionPath,
|
|
973
|
+
INTUNED_EXTENSION_SETTINGS_FILE_NAME
|
|
974
|
+
);
|
|
975
|
+
const captchaSolverSettings2 = await getIntunedCaptchaSolverSettings();
|
|
976
|
+
await setupIntunedExtensionServer(captchaSolverSettings2);
|
|
977
|
+
const captchaSolverSettingsWithRunContext = await getIntunedExtensionSettings(
|
|
978
|
+
captchaSolverSettings2
|
|
979
|
+
);
|
|
980
|
+
await (0, import_promises2.writeFile)(
|
|
981
|
+
intunedExtensionSettingsPath,
|
|
982
|
+
JSON.stringify(captchaSolverSettingsWithRunContext)
|
|
983
|
+
);
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
// src/common/extension/intunedExtensionServer.ts
|
|
987
|
+
var TabCaptchaState = class {
|
|
988
|
+
constructor(tabId) {
|
|
989
|
+
this.tabId = tabId;
|
|
990
|
+
this.captchasById = /* @__PURE__ */ new Map();
|
|
991
|
+
this.subscribers = new Array();
|
|
992
|
+
}
|
|
993
|
+
subscribe(handler) {
|
|
994
|
+
this.subscribers.push(handler);
|
|
995
|
+
}
|
|
996
|
+
unsubscribe(handler, status) {
|
|
997
|
+
const index = this.subscribers.findIndex(
|
|
998
|
+
(subscriber) => subscriber.handler === handler && (subscriber.status === status || !status)
|
|
999
|
+
);
|
|
1000
|
+
if (index !== -1) {
|
|
1001
|
+
this.subscribers.splice(index, 1);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
getCaptchas() {
|
|
1005
|
+
return [...this.captchasById.values()];
|
|
1006
|
+
}
|
|
1007
|
+
async upsertCaptcha(captcha) {
|
|
1008
|
+
this.captchasById.set(captcha.id, captcha);
|
|
1009
|
+
for (const subscriber of this.subscribers) {
|
|
1010
|
+
if (!subscriber.status || subscriber.status === captcha.status) {
|
|
1011
|
+
await subscriber.handler(captcha);
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
var ExtensionServer = class {
|
|
1017
|
+
constructor() {
|
|
1018
|
+
this.app = null;
|
|
1019
|
+
this.tabs = /* @__PURE__ */ new Map();
|
|
1020
|
+
}
|
|
1021
|
+
getOrCreateTab(tabId) {
|
|
1022
|
+
const existing = this.tabs.get(tabId);
|
|
1023
|
+
if (existing) return existing;
|
|
1024
|
+
const created = new TabCaptchaState(tabId);
|
|
1025
|
+
this.tabs.set(tabId, created);
|
|
1026
|
+
return created;
|
|
1027
|
+
}
|
|
1028
|
+
async handleUpsertCaptcha(captcha) {
|
|
1029
|
+
const tab = this.getOrCreateTab(captcha.tabId);
|
|
1030
|
+
await tab.upsertCaptcha(captcha);
|
|
1031
|
+
}
|
|
1032
|
+
async start({
|
|
1033
|
+
port,
|
|
1034
|
+
host = "0.0.0.0"
|
|
1035
|
+
}) {
|
|
1036
|
+
if (this.app) {
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
this.app = (0, import_fastify.default)({
|
|
1040
|
+
logger: false,
|
|
1041
|
+
bodyLimit: 1e6
|
|
1042
|
+
});
|
|
1043
|
+
this.app.post("/state", async (request, reply) => {
|
|
1044
|
+
try {
|
|
1045
|
+
const result = captchaSchema.safeParse(request.body);
|
|
1046
|
+
if (!result.success) {
|
|
1047
|
+
return reply.code(400).send({
|
|
1048
|
+
error: "Invalid captcha payload",
|
|
1049
|
+
details: result.error.flatten().fieldErrors
|
|
162
1050
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
1051
|
+
}
|
|
1052
|
+
await this.handleUpsertCaptcha(result.data);
|
|
1053
|
+
return reply.code(200).send({});
|
|
1054
|
+
} catch (error) {
|
|
1055
|
+
console.error("Error processing captcha state update:", error);
|
|
1056
|
+
return reply.code(500).send({
|
|
1057
|
+
error: "Internal server error",
|
|
1058
|
+
message: error?.message ?? String(error)
|
|
1059
|
+
});
|
|
1060
|
+
}
|
|
1061
|
+
});
|
|
1062
|
+
this.app.setNotFoundHandler((_request, reply) => {
|
|
1063
|
+
return reply.code(404).send({ error: "Not found" });
|
|
1064
|
+
});
|
|
1065
|
+
await this.app.listen({
|
|
1066
|
+
port,
|
|
1067
|
+
host
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
1070
|
+
async stop() {
|
|
1071
|
+
if (!this.app) return;
|
|
1072
|
+
const toClose = this.app;
|
|
1073
|
+
this.app = null;
|
|
1074
|
+
await toClose.close();
|
|
1075
|
+
}
|
|
1076
|
+
async getCaptchas(page, status) {
|
|
1077
|
+
const tabId = await getTabId(page);
|
|
1078
|
+
const tab = this.tabs.get(tabId);
|
|
1079
|
+
if (!tab) return [];
|
|
1080
|
+
const captchas = tab.getCaptchas();
|
|
1081
|
+
if (!status) return captchas;
|
|
1082
|
+
return captchas.filter((c) => c.status === status && c.tabId === tabId);
|
|
1083
|
+
}
|
|
1084
|
+
async subscribe(page, handler, status) {
|
|
1085
|
+
const tabId = await getTabId(page);
|
|
1086
|
+
const tab = this.getOrCreateTab(tabId);
|
|
1087
|
+
tab.subscribe({ handler, status });
|
|
1088
|
+
}
|
|
1089
|
+
async unsubscribe(page, handler, status) {
|
|
1090
|
+
const tabId = await getTabId(page);
|
|
1091
|
+
const tab = this.tabs.get(tabId);
|
|
1092
|
+
if (!tab) return;
|
|
1093
|
+
tab.unsubscribe(handler, status);
|
|
1094
|
+
}
|
|
1095
|
+
removeTab(tabId) {
|
|
1096
|
+
this.tabs.delete(tabId);
|
|
1097
|
+
}
|
|
1098
|
+
async getTabId(page) {
|
|
1099
|
+
return await getTabId(page);
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
var extensionServerSingleton = null;
|
|
1103
|
+
async function setupIntunedExtensionServer(captchaSolverSettings2) {
|
|
1104
|
+
if (!captchaSolverSettings2) {
|
|
1105
|
+
captchaSolverSettings2 = await resolveCaptchaSolverSettings();
|
|
1106
|
+
}
|
|
1107
|
+
if (!extensionServerSingleton) {
|
|
1108
|
+
extensionServerSingleton = new ExtensionServer();
|
|
1109
|
+
}
|
|
1110
|
+
await extensionServerSingleton.start({
|
|
1111
|
+
port: captchaSolverSettings2.port ?? 9e3
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
async function cleanIntunedExtensionServer() {
|
|
1115
|
+
if (extensionServerSingleton) {
|
|
1116
|
+
await extensionServerSingleton.stop();
|
|
1117
|
+
extensionServerSingleton = null;
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
var TAB_ID_CACHE_KEY = "__INTUNED_CACHED_TAB_ID__";
|
|
1121
|
+
async function getTabId(page) {
|
|
1122
|
+
const cached = page[TAB_ID_CACHE_KEY];
|
|
1123
|
+
if (cached !== void 0 && typeof cached === "number") {
|
|
1124
|
+
return cached;
|
|
1125
|
+
}
|
|
1126
|
+
let tabId;
|
|
1127
|
+
try {
|
|
1128
|
+
tabId = await page.evaluate("window.__INTUNED_TAB_ID__", { timeout: 100 });
|
|
1129
|
+
} catch {
|
|
1130
|
+
await page.waitForFunction("window.__INTUNED_TAB_ID__ !== undefined", {
|
|
1131
|
+
timeout: 15e3
|
|
1132
|
+
});
|
|
1133
|
+
tabId = await page.evaluate("window.__INTUNED_TAB_ID__");
|
|
1134
|
+
}
|
|
1135
|
+
const numericTabId = Number(tabId);
|
|
1136
|
+
page[TAB_ID_CACHE_KEY] = numericTabId;
|
|
1137
|
+
return numericTabId;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
// src/runtime/downloadDirectory.ts
|
|
1141
|
+
var import_fs_extra = require("fs-extra");
|
|
1142
|
+
function getDownloadDirectoryPath() {
|
|
1143
|
+
const context = getExecutionContext();
|
|
1144
|
+
if (!context) {
|
|
1145
|
+
throw new Error("ExecutionContext not found");
|
|
1146
|
+
}
|
|
1147
|
+
const path4 = `/tmp/downloads/${context.runId}`;
|
|
1148
|
+
(0, import_fs_extra.ensureDirSync)(path4, {
|
|
1149
|
+
mode: 1533
|
|
1150
|
+
});
|
|
1151
|
+
return path4;
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
// src/common/runApi/index.ts
|
|
1155
|
+
var fs4 = __toESM(require("fs-extra"));
|
|
1156
|
+
var import_fs_extra3 = require("fs-extra");
|
|
1157
|
+
var import_neverthrow6 = require("neverthrow");
|
|
1158
|
+
|
|
1159
|
+
// src/common/contextStorageStateHelpers.ts
|
|
1160
|
+
async function setStorageState(context, state) {
|
|
1161
|
+
if ("cookies" in state && state.cookies) {
|
|
1162
|
+
await context.addCookies(state.cookies);
|
|
1163
|
+
}
|
|
1164
|
+
const page = await context.newPage();
|
|
1165
|
+
if ("origins" in state && state.origins) {
|
|
1166
|
+
for (const originData of state.origins || []) {
|
|
1167
|
+
const origin = originData.origin;
|
|
1168
|
+
await page.route(
|
|
1169
|
+
`${origin}/*`,
|
|
1170
|
+
(route) => route.fulfill({
|
|
1171
|
+
body: "<html><head><title>Set Storage</title></head><body><h1>Set Storage</h1></body></html>",
|
|
1172
|
+
contentType: "text/html",
|
|
1173
|
+
status: 200
|
|
1174
|
+
})
|
|
1175
|
+
);
|
|
1176
|
+
try {
|
|
1177
|
+
await page.goto(origin);
|
|
1178
|
+
for (const item of originData.localStorage) {
|
|
1179
|
+
await page.evaluate(
|
|
1180
|
+
([key, value]) => {
|
|
1181
|
+
window.localStorage.setItem(key, value);
|
|
1182
|
+
},
|
|
1183
|
+
[item.name, item.value]
|
|
1184
|
+
);
|
|
1185
|
+
}
|
|
1186
|
+
} finally {
|
|
1187
|
+
await page.unroute(`${origin}/*`);
|
|
1188
|
+
}
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
if ("sessionStorage" in state && state.sessionStorage) {
|
|
1192
|
+
await context.addInitScript((storage) => {
|
|
1193
|
+
for (const { origin, sessionStorage } of storage) {
|
|
1194
|
+
if (window.location.origin === origin) {
|
|
1195
|
+
for (const item of sessionStorage) {
|
|
1196
|
+
const value = window.sessionStorage.getItem(item.name);
|
|
1197
|
+
if (!value) {
|
|
1198
|
+
window.sessionStorage.setItem(item.name, item.value);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
}, state.sessionStorage);
|
|
1204
|
+
}
|
|
1205
|
+
await page.close();
|
|
1206
|
+
}
|
|
1207
|
+
async function getStorageState(context) {
|
|
1208
|
+
const result = {
|
|
1209
|
+
cookies: [],
|
|
1210
|
+
origins: []
|
|
1211
|
+
};
|
|
1212
|
+
const storageState = await context.storageState();
|
|
1213
|
+
result.cookies = storageState.cookies;
|
|
1214
|
+
result.origins = storageState.origins;
|
|
1215
|
+
const sessionDataList = [];
|
|
1216
|
+
const pages = await context.pages();
|
|
1217
|
+
for (const page of pages) {
|
|
1218
|
+
if (page.isClosed()) continue;
|
|
1219
|
+
try {
|
|
1220
|
+
const sessionData = await page.evaluate(() => {
|
|
1221
|
+
const items = { ...window.sessionStorage };
|
|
1222
|
+
return {
|
|
1223
|
+
origin: window.location.origin,
|
|
1224
|
+
sessionStorage: Object.entries(items).map(([name, value]) => ({
|
|
1225
|
+
name,
|
|
1226
|
+
value
|
|
1227
|
+
}))
|
|
1228
|
+
};
|
|
1229
|
+
});
|
|
1230
|
+
sessionDataList.push(sessionData);
|
|
1231
|
+
} catch (error) {
|
|
1232
|
+
console.error("Error getting sessionStorage:", error);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
result["sessionStorage"] = sessionDataList;
|
|
1236
|
+
return result;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
// src/common/playwrightContext.ts
|
|
1240
|
+
var import_path3 = __toESM(require("path"));
|
|
1241
|
+
var fs3 = __toESM(require("fs-extra"));
|
|
1242
|
+
var import_neverthrow5 = require("neverthrow");
|
|
1243
|
+
|
|
1244
|
+
// src/common/setupContextHook.ts
|
|
1245
|
+
var import_neverthrow3 = require("neverthrow");
|
|
1246
|
+
|
|
1247
|
+
// src/common/runApi/importUsingImportFunction.ts
|
|
1248
|
+
var import_neverthrow2 = require("neverthrow");
|
|
1249
|
+
var import_runtime_interface = __toESM(require_dist());
|
|
1250
|
+
async function importUsingImportFunction({
|
|
1251
|
+
path: path4,
|
|
1252
|
+
allowGenerators = true,
|
|
1253
|
+
importFunction
|
|
1254
|
+
}) {
|
|
1255
|
+
try {
|
|
1256
|
+
const importedResult = await importFunction(path4);
|
|
1257
|
+
if (importedResult.isErr()) {
|
|
1258
|
+
if (importedResult.error.type === "not_found") {
|
|
1259
|
+
return (0, import_neverthrow2.err)(new import_runtime_interface.ApiNotFoundError(path4));
|
|
1260
|
+
}
|
|
1261
|
+
return (0, import_neverthrow2.err)(new import_runtime_interface.AutomationError(importedResult.error.error));
|
|
1262
|
+
}
|
|
1263
|
+
const imported = importedResult.value;
|
|
1264
|
+
if (!imported || !imported.default || !imported.default.constructor) {
|
|
1265
|
+
return (0, import_neverthrow2.err)(new import_runtime_interface.InvalidApiError(`${path4} does not have a default export`));
|
|
1266
|
+
}
|
|
1267
|
+
if (imported.default.constructor.name === "AsyncGeneratorFunction") {
|
|
1268
|
+
if (!allowGenerators) {
|
|
1269
|
+
return (0, import_neverthrow2.err)(
|
|
1270
|
+
new import_runtime_interface.InvalidApiError(
|
|
1271
|
+
`${path4} default export must be an async function`
|
|
1272
|
+
)
|
|
1273
|
+
);
|
|
1274
|
+
}
|
|
1275
|
+
return (0, import_neverthrow2.ok)(async (...args) => {
|
|
1276
|
+
const generator = imported.default(
|
|
1277
|
+
...args
|
|
1278
|
+
);
|
|
1279
|
+
const result = await generator.next();
|
|
1280
|
+
if (!result.done) {
|
|
1281
|
+
throw new Error("Yield is not supported");
|
|
1282
|
+
}
|
|
1283
|
+
return result.value;
|
|
178
1284
|
});
|
|
179
|
-
break;
|
|
180
1285
|
}
|
|
181
|
-
if (
|
|
182
|
-
|
|
1286
|
+
if (imported.default.constructor.name === "AsyncFunction") {
|
|
1287
|
+
return (0, import_neverthrow2.ok)(imported.default);
|
|
183
1288
|
}
|
|
184
|
-
|
|
1289
|
+
return (0, import_neverthrow2.err)(
|
|
1290
|
+
new import_runtime_interface.InvalidApiError(`${path4} default export must be an async function`)
|
|
1291
|
+
);
|
|
1292
|
+
} catch (error) {
|
|
1293
|
+
return (0, import_neverthrow2.err)(new import_runtime_interface.AutomationError(error));
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// src/common/setupContextHook.ts
|
|
1298
|
+
var import_runtime_interface2 = __toESM(require_dist());
|
|
1299
|
+
var setupContextHookPath = "hooks/setupContext";
|
|
1300
|
+
async function loadSetupContextHook({
|
|
1301
|
+
importFunction
|
|
1302
|
+
}) {
|
|
1303
|
+
const importedFunctionResult = await importUsingImportFunction({
|
|
1304
|
+
path: setupContextHookPath,
|
|
1305
|
+
importFunction
|
|
185
1306
|
});
|
|
186
|
-
|
|
1307
|
+
if (importedFunctionResult.isErr() && importedFunctionResult.error instanceof import_runtime_interface2.ApiNotFoundError) {
|
|
1308
|
+
return (0, import_neverthrow3.ok)(null);
|
|
1309
|
+
}
|
|
1310
|
+
return importedFunctionResult;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
// src/common/playwrightContext.ts
|
|
1314
|
+
var import_portfinder2 = require("portfinder");
|
|
1315
|
+
|
|
1316
|
+
// src/common/launchBrowser.ts
|
|
1317
|
+
var playwright = __toESM(require("playwright"));
|
|
1318
|
+
var import_fs_extra2 = require("fs-extra");
|
|
1319
|
+
var import_path2 = require("path");
|
|
1320
|
+
var fs2 = __toESM(require("fs-extra"));
|
|
1321
|
+
var import_wait_on = __toESM(require("wait-on"));
|
|
1322
|
+
var import_child_process = require("child_process");
|
|
1323
|
+
var import_util = require("util");
|
|
1324
|
+
var import_neverthrow4 = require("neverthrow");
|
|
1325
|
+
var import_zod3 = require("zod");
|
|
1326
|
+
var execAsync = (0, import_util.promisify)(import_child_process.exec);
|
|
1327
|
+
async function createUserDirWithPreferences() {
|
|
1328
|
+
const playwrightTempDir = await (0, import_fs_extra2.mkdtemp)("/tmp/pw-");
|
|
1329
|
+
const userDir = (0, import_path2.join)(playwrightTempDir, "userdir");
|
|
1330
|
+
const defaultDir = (0, import_path2.join)(userDir, "Default");
|
|
1331
|
+
await (0, import_fs_extra2.mkdir)(defaultDir, {
|
|
1332
|
+
recursive: true
|
|
1333
|
+
});
|
|
1334
|
+
const preferences = {
|
|
1335
|
+
plugins: {
|
|
1336
|
+
always_open_pdf_externally: true
|
|
1337
|
+
}
|
|
1338
|
+
};
|
|
1339
|
+
await (0, import_fs_extra2.writeFile)((0, import_path2.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
1340
|
+
return userDir;
|
|
1341
|
+
}
|
|
1342
|
+
async function launchChromium(options) {
|
|
1343
|
+
if ("cdpAddress" in options) {
|
|
1344
|
+
if (await isIntunedExtensionEnabled()) {
|
|
1345
|
+
await setupIntunedExtensionServer();
|
|
1346
|
+
}
|
|
1347
|
+
const browser = await playwright.chromium.connectOverCDP(
|
|
1348
|
+
options.cdpAddress
|
|
1349
|
+
);
|
|
1350
|
+
if (browser.contexts().length === 0) {
|
|
1351
|
+
throw new Error("No browser contexts found in the connected browser");
|
|
1352
|
+
}
|
|
1353
|
+
const context2 = browser.contexts()[0];
|
|
1354
|
+
let page2 = context2.pages().at(0) ?? await context2.newPage();
|
|
1355
|
+
const targetId = options.cdpTargetId;
|
|
1356
|
+
if (targetId) {
|
|
1357
|
+
for (const p of context2.pages()) {
|
|
1358
|
+
let cdp = null;
|
|
1359
|
+
try {
|
|
1360
|
+
cdp = await context2.newCDPSession(p);
|
|
1361
|
+
const result = await cdp.send("Target.getTargetInfo");
|
|
1362
|
+
if (result.targetInfo.targetId === targetId) {
|
|
1363
|
+
page2 = p;
|
|
1364
|
+
break;
|
|
1365
|
+
}
|
|
1366
|
+
} catch (error) {
|
|
1367
|
+
} finally {
|
|
1368
|
+
await cdp?.detach();
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
return { page: page2, context: context2 };
|
|
1373
|
+
}
|
|
1374
|
+
const { headless, appModeInitialUrl, cdpPort, proxy, downloadsPath } = options;
|
|
1375
|
+
let { executablePath } = options;
|
|
1376
|
+
const defaultArgsToIgnore = [
|
|
1377
|
+
"--disable-extensions",
|
|
1378
|
+
"--disable-component-extensions-with-background-pages",
|
|
1379
|
+
"--disable-background-networking",
|
|
1380
|
+
"--disable-backgrounding-occluded-windows",
|
|
1381
|
+
"--disable-background-timer-throttling"
|
|
1382
|
+
];
|
|
1383
|
+
const extraArgs = [];
|
|
1384
|
+
const userDataDir = await createUserDirWithPreferences();
|
|
1385
|
+
if (isIntunedExtensionLoaded()) {
|
|
1386
|
+
const extensionsList = buildExtensionsList();
|
|
1387
|
+
const extensions = extensionsList.join(",");
|
|
1388
|
+
extraArgs.push(`--disable-extensions-except=${extensions}`);
|
|
1389
|
+
extraArgs.push(`--load-extension=${extensions}`);
|
|
1390
|
+
}
|
|
1391
|
+
if (await isIntunedExtensionEnabled()) {
|
|
1392
|
+
await setupIntunedExtension();
|
|
1393
|
+
if (proxy) {
|
|
1394
|
+
extraArgs.push('--proxy-bypass-list="<-loopback>"');
|
|
1395
|
+
}
|
|
1396
|
+
}
|
|
1397
|
+
if (cdpPort) {
|
|
1398
|
+
extraArgs.push(`--remote-debugging-port=${cdpPort}`);
|
|
1399
|
+
}
|
|
1400
|
+
if (headless) {
|
|
1401
|
+
defaultArgsToIgnore.push("--headless=old");
|
|
1402
|
+
extraArgs.push("--headless=new");
|
|
1403
|
+
}
|
|
1404
|
+
if (appModeInitialUrl) {
|
|
1405
|
+
extraArgs.push(`--app=${appModeInitialUrl}`);
|
|
1406
|
+
}
|
|
1407
|
+
if (executablePath) {
|
|
1408
|
+
executablePath = await fs2.realpath(executablePath);
|
|
1409
|
+
if (!await fs2.exists(executablePath)) {
|
|
1410
|
+
console.log(
|
|
1411
|
+
`Warning: Executable path ${executablePath} does not exist. Falling back to default.`
|
|
1412
|
+
);
|
|
1413
|
+
executablePath = void 0;
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
const viewport = null;
|
|
1417
|
+
const userAgent = process.env.__PLAYWRIGHT_USER_AGENT_OVERRIDE ?? await getHeadlessUserAgent({
|
|
1418
|
+
executablePath
|
|
1419
|
+
});
|
|
1420
|
+
const context = await playwright.chromium.launchPersistentContext(
|
|
1421
|
+
userDataDir,
|
|
1422
|
+
{
|
|
1423
|
+
userAgent,
|
|
1424
|
+
executablePath,
|
|
1425
|
+
headless,
|
|
1426
|
+
viewport,
|
|
1427
|
+
proxy,
|
|
1428
|
+
downloadsPath,
|
|
1429
|
+
args: extraArgs,
|
|
1430
|
+
ignoreDefaultArgs: defaultArgsToIgnore
|
|
1431
|
+
}
|
|
1432
|
+
);
|
|
1433
|
+
context.once("close", async () => {
|
|
1434
|
+
try {
|
|
1435
|
+
await (0, import_fs_extra2.rm)(userDataDir, {
|
|
1436
|
+
recursive: true,
|
|
1437
|
+
force: true,
|
|
1438
|
+
retryDelay: 1e3,
|
|
1439
|
+
maxRetries: 5
|
|
1440
|
+
});
|
|
1441
|
+
if (await isIntunedExtensionEnabled()) {
|
|
1442
|
+
await cleanIntunedExtensionServer();
|
|
1443
|
+
}
|
|
1444
|
+
} catch (error) {
|
|
1445
|
+
console.error("Failed to remove user data dir", error);
|
|
1446
|
+
}
|
|
1447
|
+
});
|
|
1448
|
+
if (cdpPort) {
|
|
1449
|
+
const createdCdpAddress = getLocalCdpAddress(cdpPort);
|
|
1450
|
+
await waitOnCdpAddress(createdCdpAddress);
|
|
1451
|
+
}
|
|
1452
|
+
const page = context.pages().at(0) ?? await context.newPage();
|
|
1453
|
+
if (await isIntunedExtensionEnabled()) {
|
|
1454
|
+
await getIntunedExtensionWorker(context);
|
|
1455
|
+
}
|
|
1456
|
+
return {
|
|
1457
|
+
page,
|
|
1458
|
+
context
|
|
1459
|
+
};
|
|
1460
|
+
}
|
|
1461
|
+
async function getBrowserExecutablePath() {
|
|
1462
|
+
const browserType = getBrowserType();
|
|
1463
|
+
if (browserType === "brave") {
|
|
1464
|
+
return await getBraveExecutablePath();
|
|
1465
|
+
}
|
|
1466
|
+
}
|
|
1467
|
+
async function launchBrowser(options) {
|
|
1468
|
+
if ("cdpAddress" in options) {
|
|
1469
|
+
return launchChromium(options);
|
|
1470
|
+
}
|
|
1471
|
+
return launchChromium({
|
|
1472
|
+
...options,
|
|
1473
|
+
executablePath: await getBrowserExecutablePath()
|
|
1474
|
+
});
|
|
1475
|
+
}
|
|
1476
|
+
function getBrowserType() {
|
|
1477
|
+
if (process.env.BROWSER_TYPE === "brave") {
|
|
1478
|
+
return "brave";
|
|
1479
|
+
}
|
|
1480
|
+
return "chromium";
|
|
1481
|
+
}
|
|
1482
|
+
async function getBraveExecutablePath() {
|
|
1483
|
+
const { stdout } = await execAsync("which brave-browser-stable");
|
|
1484
|
+
const bravePath = stdout.trim();
|
|
1485
|
+
if (bravePath.length === 0) {
|
|
1486
|
+
throw new Error("Brave browser not found");
|
|
1487
|
+
}
|
|
1488
|
+
return bravePath;
|
|
1489
|
+
}
|
|
1490
|
+
function getLocalCdpAddress(port) {
|
|
1491
|
+
return `http://localhost:${port}`;
|
|
1492
|
+
}
|
|
1493
|
+
async function getCdpWebSocketUrl(cdpAddress) {
|
|
1494
|
+
let response;
|
|
1495
|
+
try {
|
|
1496
|
+
response = await fetch(`${cdpAddress}/json/version`);
|
|
1497
|
+
} catch (error) {
|
|
1498
|
+
return (0, import_neverthrow4.err)(
|
|
1499
|
+
`Failed to fetch CDP version from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`
|
|
1500
|
+
);
|
|
1501
|
+
}
|
|
1502
|
+
if (!response.ok) {
|
|
1503
|
+
return (0, import_neverthrow4.err)(
|
|
1504
|
+
`Failed to get CDP WebSocket URL from ${cdpAddress}: ${response.status} ${response.statusText}`
|
|
1505
|
+
);
|
|
1506
|
+
}
|
|
1507
|
+
let data;
|
|
1508
|
+
try {
|
|
1509
|
+
data = await response.json();
|
|
1510
|
+
} catch (error) {
|
|
1511
|
+
return (0, import_neverthrow4.err)(
|
|
1512
|
+
`Invalid CDP version response from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`
|
|
1513
|
+
);
|
|
1514
|
+
}
|
|
1515
|
+
const cdpJsonVersionResponseSchema = import_zod3.z.object({
|
|
1516
|
+
webSocketDebuggerUrl: import_zod3.z.string().url()
|
|
1517
|
+
});
|
|
1518
|
+
const parseResult = cdpJsonVersionResponseSchema.safeParse(data);
|
|
1519
|
+
if (!parseResult.success) {
|
|
1520
|
+
return (0, import_neverthrow4.err)(
|
|
1521
|
+
`Invalid CDP version response from ${cdpAddress}: ${JSON.stringify(
|
|
1522
|
+
parseResult.error.format()
|
|
1523
|
+
)}`
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
return (0, import_neverthrow4.ok)(parseResult.data.webSocketDebuggerUrl);
|
|
1527
|
+
}
|
|
1528
|
+
async function waitOnCdpAddress(cdpAddress) {
|
|
1529
|
+
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
1530
|
+
await (0, import_wait_on.default)({
|
|
1531
|
+
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
1532
|
+
delay: 100,
|
|
1533
|
+
interval: 100,
|
|
1534
|
+
timeout: 5e3,
|
|
1535
|
+
tcpTimeout: 1e3,
|
|
1536
|
+
window: 1e3
|
|
1537
|
+
});
|
|
1538
|
+
}
|
|
1539
|
+
async function getHeadlessUserAgent({
|
|
1540
|
+
executablePath,
|
|
1541
|
+
args,
|
|
1542
|
+
ignoreDefaultArgs
|
|
1543
|
+
}) {
|
|
1544
|
+
const browser = await playwright.chromium.launch({
|
|
1545
|
+
headless: true,
|
|
1546
|
+
executablePath,
|
|
1547
|
+
args,
|
|
1548
|
+
ignoreDefaultArgs
|
|
1549
|
+
});
|
|
1550
|
+
const context = await browser.newContext();
|
|
1551
|
+
const page = await context.newPage();
|
|
1552
|
+
let userAgent = await page.evaluate(() => navigator.userAgent);
|
|
1553
|
+
await browser.close();
|
|
1554
|
+
if (!userAgent || typeof userAgent !== "string") {
|
|
1555
|
+
return void 0;
|
|
1556
|
+
}
|
|
1557
|
+
userAgent = userAgent.replace("HeadlessChrome", "Chrome");
|
|
1558
|
+
return userAgent;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
// src/common/playwrightContext.ts
|
|
1562
|
+
var import_runtime_interface3 = __toESM(require_dist());
|
|
1563
|
+
var browserScriptsFile = import_path3.default.join(
|
|
1564
|
+
__dirname,
|
|
1565
|
+
"./assets/browser_scripts.js"
|
|
1566
|
+
);
|
|
1567
|
+
async function withPlaywrightContext({
|
|
1568
|
+
cdpAddress,
|
|
1569
|
+
cdpTargetId,
|
|
1570
|
+
proxy,
|
|
1571
|
+
headless = true,
|
|
1572
|
+
downloadsPath,
|
|
1573
|
+
importFunction,
|
|
1574
|
+
apiName,
|
|
1575
|
+
apiParameters
|
|
1576
|
+
}, fn) {
|
|
1577
|
+
let context;
|
|
1578
|
+
let page;
|
|
1579
|
+
try {
|
|
1580
|
+
const setupContextHookResult = importFunction ? await loadSetupContextHook({
|
|
1581
|
+
importFunction
|
|
1582
|
+
}) : (0, import_neverthrow5.ok)(null);
|
|
1583
|
+
if (setupContextHookResult.isErr()) {
|
|
1584
|
+
return setupContextHookResult;
|
|
1585
|
+
}
|
|
1586
|
+
const setupContextHook = setupContextHookResult.value;
|
|
1587
|
+
if (setupContextHook === null) {
|
|
1588
|
+
if (cdpAddress !== void 0) {
|
|
1589
|
+
({ page, context } = await launchBrowser({ cdpAddress, cdpTargetId }));
|
|
1590
|
+
} else {
|
|
1591
|
+
({ page, context } = await launchBrowser({
|
|
1592
|
+
proxy,
|
|
1593
|
+
headless,
|
|
1594
|
+
downloadsPath
|
|
1595
|
+
}));
|
|
1596
|
+
}
|
|
1597
|
+
return await fn(context, page);
|
|
1598
|
+
}
|
|
1599
|
+
let hookCdpUrl = null;
|
|
1600
|
+
if (cdpAddress) {
|
|
1601
|
+
hookCdpUrl = cdpAddress;
|
|
1602
|
+
({ context, page } = await launchBrowser({ cdpAddress, cdpTargetId }));
|
|
1603
|
+
} else {
|
|
1604
|
+
const port = await (0, import_portfinder2.getPort)({
|
|
1605
|
+
port: 9222
|
|
1606
|
+
});
|
|
1607
|
+
({ context, page } = await launchBrowser({
|
|
1608
|
+
proxy,
|
|
1609
|
+
headless,
|
|
1610
|
+
downloadsPath,
|
|
1611
|
+
cdpPort: port
|
|
1612
|
+
}));
|
|
1613
|
+
hookCdpUrl = getLocalCdpAddress(port);
|
|
1614
|
+
}
|
|
1615
|
+
let hookResult;
|
|
1616
|
+
try {
|
|
1617
|
+
const wsUrlResult = await getCdpWebSocketUrl(hookCdpUrl);
|
|
1618
|
+
if (wsUrlResult.isOk()) {
|
|
1619
|
+
hookCdpUrl = wsUrlResult.value;
|
|
1620
|
+
} else {
|
|
1621
|
+
throw new Error(wsUrlResult.error);
|
|
1622
|
+
}
|
|
1623
|
+
hookResult = await setupContextHook({
|
|
1624
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1625
|
+
apiName,
|
|
1626
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1627
|
+
apiParameters,
|
|
1628
|
+
cdpUrl: hookCdpUrl
|
|
1629
|
+
});
|
|
1630
|
+
} catch (error) {
|
|
1631
|
+
return (0, import_neverthrow5.err)(new import_runtime_interface3.AutomationError(error));
|
|
1632
|
+
}
|
|
1633
|
+
if (!hookResult) {
|
|
1634
|
+
return await fn(context, page);
|
|
1635
|
+
}
|
|
1636
|
+
const { page: newPage, context: newContext, cleanup } = hookResult;
|
|
1637
|
+
let result;
|
|
1638
|
+
try {
|
|
1639
|
+
result = { return: await fn(newContext, newPage ?? page) };
|
|
1640
|
+
} catch (e) {
|
|
1641
|
+
result = { throw: e };
|
|
1642
|
+
}
|
|
1643
|
+
try {
|
|
1644
|
+
await cleanup?.();
|
|
1645
|
+
} catch (e) {
|
|
1646
|
+
result = { return: (0, import_neverthrow5.err)(new import_runtime_interface3.AutomationError(e)) };
|
|
1647
|
+
}
|
|
1648
|
+
if ("throw" in result) {
|
|
1649
|
+
throw result.throw;
|
|
1650
|
+
}
|
|
1651
|
+
return result.return;
|
|
1652
|
+
} finally {
|
|
1653
|
+
await context?.close();
|
|
1654
|
+
}
|
|
1655
|
+
}
|
|
1656
|
+
async function loadSessionToContext({
|
|
1657
|
+
context,
|
|
1658
|
+
session
|
|
1659
|
+
}) {
|
|
1660
|
+
let sessionToLoad;
|
|
1661
|
+
if (session.type === "state") {
|
|
1662
|
+
const state = session.state;
|
|
1663
|
+
if (state === void 0 || state === null) {
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
sessionToLoad = state;
|
|
1667
|
+
} else {
|
|
1668
|
+
const fullPath = getFullPathInProject(session.path);
|
|
1669
|
+
sessionToLoad = await fs3.readJson(fullPath);
|
|
1670
|
+
}
|
|
1671
|
+
await setStorageState(context, sessionToLoad);
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
// src/common/formatZodError.ts
|
|
1675
|
+
function formatZodError(zodError) {
|
|
1676
|
+
const formattedErrors = zodError.errors.map((error) => {
|
|
1677
|
+
const path4 = error.path.map((segment) => {
|
|
1678
|
+
return typeof segment === "number" ? `[${segment}]` : segment;
|
|
1679
|
+
}).join(".");
|
|
1680
|
+
if (path4) {
|
|
1681
|
+
return `${path4} is invalid - ${error.message}`;
|
|
1682
|
+
}
|
|
1683
|
+
return error.message;
|
|
1684
|
+
});
|
|
1685
|
+
return formattedErrors;
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
// src/common/cleanEnvironmentVariables.ts
|
|
1689
|
+
function cleanEnvironmentVariables() {
|
|
1690
|
+
Object.keys(process.env).filter((i) => {
|
|
1691
|
+
if (i.toLocaleLowerCase().startsWith("npm")) {
|
|
1692
|
+
return true;
|
|
1693
|
+
}
|
|
1694
|
+
if (i.toLocaleLowerCase().startsWith("fly") && i !== "FLY_ALLOC_ID") {
|
|
1695
|
+
return true;
|
|
1696
|
+
}
|
|
1697
|
+
}).forEach((i) => delete process.env[i]);
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
// src/common/runApi/index.ts
|
|
1701
|
+
var import_runtime_interface4 = __toESM(require_dist());
|
|
1702
|
+
function getObjectSizeInBytes(obj) {
|
|
1703
|
+
try {
|
|
1704
|
+
return new TextEncoder().encode(JSON.stringify(obj)).length;
|
|
1705
|
+
} catch (error) {
|
|
1706
|
+
return new TextEncoder().encode(String(obj)).length;
|
|
1707
|
+
}
|
|
1708
|
+
}
|
|
1709
|
+
async function runApi({
|
|
1710
|
+
abortSignal,
|
|
1711
|
+
importFunction,
|
|
1712
|
+
retrieveSession = false,
|
|
1713
|
+
...input
|
|
1714
|
+
}) {
|
|
1715
|
+
let traceStarted = false;
|
|
1716
|
+
const inputParseResult = import_runtime_interface4.runApiParametersSchema.safeParse(input);
|
|
1717
|
+
if (!inputParseResult.success) {
|
|
1718
|
+
return (0, import_neverthrow6.err)(
|
|
1719
|
+
new import_runtime_interface4.InternalInvalidInputError(
|
|
1720
|
+
"Input validation failed",
|
|
1721
|
+
formatZodError(inputParseResult.error)
|
|
1722
|
+
)
|
|
1723
|
+
);
|
|
1724
|
+
}
|
|
1725
|
+
const {
|
|
1726
|
+
automationFunction: { name, params },
|
|
1727
|
+
runOptions,
|
|
1728
|
+
tracing,
|
|
1729
|
+
auth
|
|
1730
|
+
} = inputParseResult.data;
|
|
1731
|
+
const abortSymbol = /* @__PURE__ */ Symbol("abort");
|
|
1732
|
+
const abortPromise = new Promise((resolve2) => {
|
|
1733
|
+
if (!abortSignal) return;
|
|
1734
|
+
abortSignal.addEventListener("abort", () => {
|
|
1735
|
+
resolve2(abortSymbol);
|
|
1736
|
+
});
|
|
1737
|
+
});
|
|
1738
|
+
async function runAutomation() {
|
|
1739
|
+
const validatedModuleResult = await importUsingImportFunction({
|
|
1740
|
+
path: name,
|
|
1741
|
+
importFunction
|
|
1742
|
+
});
|
|
1743
|
+
if (validatedModuleResult.isErr()) {
|
|
1744
|
+
return (0, import_neverthrow6.err)(validatedModuleResult.error);
|
|
1745
|
+
}
|
|
1746
|
+
const automationFunction = validatedModuleResult.value;
|
|
1747
|
+
if (auth && auth.session.type === "state") {
|
|
1748
|
+
const state = auth.session.state;
|
|
1749
|
+
if (state === void 0 || state === null) {
|
|
1750
|
+
return (0, import_neverthrow6.err)(new import_runtime_interface4.AuthRequiredError());
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
const playwrightContextParameters = {
|
|
1754
|
+
apiName: name,
|
|
1755
|
+
apiParameters: params,
|
|
1756
|
+
importFunction
|
|
1757
|
+
};
|
|
1758
|
+
const intunedContext = getExecutionContext();
|
|
1759
|
+
const runAutomationWithContext = async (context, page) => {
|
|
1760
|
+
async function saveTraceIfNeeded({
|
|
1761
|
+
errorMessage
|
|
1762
|
+
}) {
|
|
1763
|
+
if (!tracing.enabled || !traceStarted) {
|
|
1764
|
+
return;
|
|
1765
|
+
}
|
|
1766
|
+
try {
|
|
1767
|
+
await context?.tracing.stop({ path: tracing.filePath });
|
|
1768
|
+
} catch (error) {
|
|
1769
|
+
console.log(errorMessage, error?.message);
|
|
1770
|
+
await (0, import_fs_extra3.remove)(tracing.filePath);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
if (auth) {
|
|
1774
|
+
await loadSessionToContext({
|
|
1775
|
+
context,
|
|
1776
|
+
session: auth.session
|
|
1777
|
+
});
|
|
1778
|
+
if (intunedContext && auth.parameters) {
|
|
1779
|
+
intunedContext.getAuthSessionParameters = async () => auth.parameters;
|
|
1780
|
+
}
|
|
1781
|
+
}
|
|
1782
|
+
const scriptContent = await fs4.readFile(browserScriptsFile, "utf-8");
|
|
1783
|
+
await context.addInitScript({
|
|
1784
|
+
content: scriptContent
|
|
1785
|
+
});
|
|
1786
|
+
for (const page2 of context.pages()) {
|
|
1787
|
+
await page2.evaluate(scriptContent);
|
|
1788
|
+
}
|
|
1789
|
+
if (tracing.enabled) {
|
|
1790
|
+
await context.tracing.start({
|
|
1791
|
+
screenshots: true,
|
|
1792
|
+
snapshots: true,
|
|
1793
|
+
sources: true
|
|
1794
|
+
});
|
|
1795
|
+
traceStarted = true;
|
|
1796
|
+
}
|
|
1797
|
+
cleanEnvironmentVariables();
|
|
1798
|
+
const automationFunctionParameters = [
|
|
1799
|
+
...params !== void 0 ? [params] : [],
|
|
1800
|
+
page,
|
|
1801
|
+
context
|
|
1802
|
+
];
|
|
1803
|
+
try {
|
|
1804
|
+
const [automationFunctionResult] = await Promise.all([
|
|
1805
|
+
automationFunction(...automationFunctionParameters)
|
|
1806
|
+
]);
|
|
1807
|
+
const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
|
|
1808
|
+
const resultSizeInBytes = getObjectSizeInBytes(
|
|
1809
|
+
automationFunctionResult
|
|
1810
|
+
);
|
|
1811
|
+
if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
|
|
1812
|
+
return (0, import_neverthrow6.err)(
|
|
1813
|
+
new import_runtime_interface4.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES)
|
|
1814
|
+
);
|
|
1815
|
+
}
|
|
1816
|
+
if (retrieveSession) {
|
|
1817
|
+
return (0, import_neverthrow6.ok)({
|
|
1818
|
+
result: automationFunctionResult,
|
|
1819
|
+
extendedPayloads: intunedContext?.extendedPayloads,
|
|
1820
|
+
session: await getStorageState(context)
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
return (0, import_neverthrow6.ok)({
|
|
1824
|
+
result: automationFunctionResult,
|
|
1825
|
+
extendedPayloads: intunedContext?.extendedPayloads
|
|
1826
|
+
});
|
|
1827
|
+
} catch (error) {
|
|
1828
|
+
return (0, import_neverthrow6.err)(new import_runtime_interface4.AutomationError(error));
|
|
1829
|
+
} finally {
|
|
1830
|
+
await saveTraceIfNeeded({ errorMessage: "failed to save trace" });
|
|
1831
|
+
}
|
|
1832
|
+
};
|
|
1833
|
+
if (intunedContext?.store) {
|
|
1834
|
+
intunedContext.store = {};
|
|
1835
|
+
}
|
|
1836
|
+
if (runOptions.environment === "standalone") {
|
|
1837
|
+
const downloadsPath = getDownloadDirectoryPath();
|
|
1838
|
+
try {
|
|
1839
|
+
return await withPlaywrightContext(
|
|
1840
|
+
{
|
|
1841
|
+
headless: runOptions.headless,
|
|
1842
|
+
proxy: runOptions.proxy,
|
|
1843
|
+
downloadsPath,
|
|
1844
|
+
...playwrightContextParameters
|
|
1845
|
+
},
|
|
1846
|
+
runAutomationWithContext
|
|
1847
|
+
);
|
|
1848
|
+
} finally {
|
|
1849
|
+
await fs4.remove(downloadsPath);
|
|
1850
|
+
}
|
|
1851
|
+
} else {
|
|
1852
|
+
return await withPlaywrightContext(
|
|
1853
|
+
{
|
|
1854
|
+
cdpAddress: runOptions.cdpAddress,
|
|
1855
|
+
cdpTargetId: runOptions.cdpTargetId,
|
|
1856
|
+
...playwrightContextParameters
|
|
1857
|
+
},
|
|
1858
|
+
runAutomationWithContext
|
|
1859
|
+
);
|
|
1860
|
+
}
|
|
1861
|
+
}
|
|
1862
|
+
const result = await Promise.race([await runAutomation(), abortPromise]);
|
|
1863
|
+
if (result === abortSymbol) {
|
|
1864
|
+
return (0, import_neverthrow6.err)(new import_runtime_interface4.AbortedError());
|
|
1865
|
+
}
|
|
1866
|
+
return result;
|
|
1867
|
+
}
|
|
1868
|
+
|
|
1869
|
+
// src/commands/interface/run.ts
|
|
1870
|
+
var import_promises3 = require("timers/promises");
|
|
1871
|
+
var import_neverthrow7 = require("neverthrow");
|
|
1872
|
+
|
|
1873
|
+
// src/common/backendFunctions/getAuthSessionParameters.ts
|
|
1874
|
+
var import_isNil = __toESM(require("lodash/isNil"));
|
|
1875
|
+
var import_zod4 = require("zod");
|
|
1876
|
+
var authSessionParametersResponseSchema = import_zod4.z.object({
|
|
1877
|
+
parameters: import_zod4.z.any().refine((v) => v !== void 0)
|
|
1878
|
+
});
|
|
1879
|
+
async function getAuthSessionParameters2() {
|
|
1880
|
+
const context = getExecutionContext();
|
|
1881
|
+
if (!context) {
|
|
1882
|
+
throw new Error(
|
|
1883
|
+
"getAuthSessionParameters failed due to an internal error (context was not found)."
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
const authSessionId = context.authSessionId;
|
|
1887
|
+
if ((0, import_isNil.default)(authSessionId)) {
|
|
1888
|
+
throw new Error("AuthSessions are not enabled");
|
|
1889
|
+
}
|
|
1890
|
+
const response = await callBackendFunctionWithToken(
|
|
1891
|
+
`auth-session/${authSessionId}/parameters`,
|
|
1892
|
+
{
|
|
1893
|
+
method: "GET"
|
|
1894
|
+
}
|
|
1895
|
+
);
|
|
1896
|
+
const body = await response.text();
|
|
1897
|
+
if (!response.ok) {
|
|
1898
|
+
throw new Error(
|
|
1899
|
+
`getAuthSessionParameters failed with status ${response.status}: ${body}`
|
|
1900
|
+
);
|
|
1901
|
+
}
|
|
1902
|
+
let json;
|
|
1903
|
+
try {
|
|
1904
|
+
json = JSON.parse(body);
|
|
1905
|
+
} catch (e) {
|
|
1906
|
+
throw new Error(`Expected JSON response, but got ${body}`);
|
|
1907
|
+
}
|
|
1908
|
+
return authSessionParametersResponseSchema.parse(json).parameters;
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
// src/commands/interface/run.ts
|
|
1912
|
+
var import_runtime_interface5 = __toESM(require_dist());
|
|
1913
|
+
import_dotenv2.default.config({
|
|
1914
|
+
path: `.env`
|
|
1915
|
+
});
|
|
1916
|
+
function runAutomationCLI(importFunction) {
|
|
1917
|
+
import_commander.program.description("run user automation and communicate using unix socket").argument(
|
|
1918
|
+
"<input>",
|
|
1919
|
+
"In unix socket mode: path to the unix socket. In jsonl mode: path to the jsonl file. In tcp socket mode: host:port"
|
|
1920
|
+
).option("--mode [mode]", "Communication mode: unix, jsonl, or tcp").action(
|
|
1921
|
+
async (input, {
|
|
1922
|
+
mode = "unix"
|
|
1923
|
+
}) => {
|
|
1924
|
+
let context;
|
|
1925
|
+
const throttleTime = 60 * 1e3;
|
|
1926
|
+
let timeoutTimestamp = Date.now();
|
|
1927
|
+
const client = createClient(mode, input);
|
|
1928
|
+
const abortController = new AbortController();
|
|
1929
|
+
const interruptSignalHandler = async () => {
|
|
1930
|
+
abortController.abort();
|
|
1931
|
+
await (0, import_promises3.setTimeout)(6e4);
|
|
1932
|
+
await client.close();
|
|
1933
|
+
process.exit(1);
|
|
1934
|
+
};
|
|
1935
|
+
process.on("SIGINT", interruptSignalHandler);
|
|
1936
|
+
process.on("SIGTERM", interruptSignalHandler);
|
|
1937
|
+
const messagesGenerator = client.receiveJSON();
|
|
1938
|
+
async function receiveMessages() {
|
|
1939
|
+
const data = await messagesGenerator.next();
|
|
1940
|
+
if (data.done) {
|
|
1941
|
+
return;
|
|
1942
|
+
}
|
|
1943
|
+
const inputParseResult = import_runtime_interface5.runApiInputSchema.safeParse(data.value);
|
|
1944
|
+
if (!inputParseResult.success) {
|
|
1945
|
+
console.error(
|
|
1946
|
+
"Validation error:",
|
|
1947
|
+
formatZodError(inputParseResult.error)
|
|
1948
|
+
);
|
|
1949
|
+
return {
|
|
1950
|
+
type: "error",
|
|
1951
|
+
error: new import_runtime_interface5.InternalInvalidInputError(
|
|
1952
|
+
"Invalid input",
|
|
1953
|
+
formatZodError(inputParseResult.error)
|
|
1954
|
+
)
|
|
1955
|
+
};
|
|
1956
|
+
}
|
|
1957
|
+
const input2 = inputParseResult.data;
|
|
1958
|
+
return input2;
|
|
1959
|
+
}
|
|
1960
|
+
let resultPromise = null;
|
|
1961
|
+
async function handleMessage(message) {
|
|
1962
|
+
if (message.type === "abort") {
|
|
1963
|
+
abortController.abort();
|
|
1964
|
+
return;
|
|
1965
|
+
}
|
|
1966
|
+
if (message.type === "tokenUpdate") {
|
|
1967
|
+
backendFunctionsTokenManager.token = message.parameters.functionsToken;
|
|
1968
|
+
return;
|
|
1969
|
+
}
|
|
1970
|
+
if (message.type === "start") {
|
|
1971
|
+
context = {
|
|
1972
|
+
extendedPayloads: [],
|
|
1973
|
+
runEnvironment: message.parameters.runOptions.environment === "standalone" ? "DEPLOYED" /* DEPLOYED */ : "IDE" /* IDE */,
|
|
1974
|
+
timeoutInfo: {
|
|
1975
|
+
extendTimeoutCallback: async () => {
|
|
1976
|
+
if (Date.now() - timeoutTimestamp < throttleTime) return;
|
|
1977
|
+
timeoutTimestamp = Date.now();
|
|
1978
|
+
client.sendJSON({ type: "extend" });
|
|
1979
|
+
}
|
|
1980
|
+
},
|
|
1981
|
+
getAuthSessionParameters: getAuthSessionParameters2,
|
|
1982
|
+
...message.parameters.context ?? {},
|
|
1983
|
+
proxy: getProxyUrlFromRunOptions(message.parameters.runOptions)
|
|
1984
|
+
};
|
|
1985
|
+
backendFunctionsTokenManager.token = message.parameters.functionsToken;
|
|
1986
|
+
resultPromise = runWithContext(context, async () => {
|
|
1987
|
+
return await runApi({
|
|
1988
|
+
...message.parameters,
|
|
1989
|
+
abortSignal: abortController.signal,
|
|
1990
|
+
importFunction: importFunction ?? _defaultImport
|
|
1991
|
+
});
|
|
1992
|
+
});
|
|
1993
|
+
return;
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
let receiveMessagesPromise = receiveMessages();
|
|
1997
|
+
while (true) {
|
|
1998
|
+
const messageOrResult = await Promise.race([
|
|
1999
|
+
receiveMessagesPromise.then((message) => ({
|
|
2000
|
+
type: "message",
|
|
2001
|
+
message
|
|
2002
|
+
})),
|
|
2003
|
+
...resultPromise ? [
|
|
2004
|
+
resultPromise.then((result2) => ({
|
|
2005
|
+
type: "result",
|
|
2006
|
+
result: result2
|
|
2007
|
+
}))
|
|
2008
|
+
] : []
|
|
2009
|
+
]);
|
|
2010
|
+
if (messageOrResult.type === "message") {
|
|
2011
|
+
const { message } = messageOrResult;
|
|
2012
|
+
if (message === void 0) {
|
|
2013
|
+
break;
|
|
2014
|
+
}
|
|
2015
|
+
if (message.type === "error") {
|
|
2016
|
+
client.sendJSON({
|
|
2017
|
+
type: "done",
|
|
2018
|
+
result: message.error.json,
|
|
2019
|
+
success: false
|
|
2020
|
+
});
|
|
2021
|
+
break;
|
|
2022
|
+
}
|
|
2023
|
+
if (message.type === "ping") {
|
|
2024
|
+
client.sendJSON({
|
|
2025
|
+
type: "pong"
|
|
2026
|
+
});
|
|
2027
|
+
break;
|
|
2028
|
+
}
|
|
2029
|
+
await handleMessage(message);
|
|
2030
|
+
receiveMessagesPromise = receiveMessages();
|
|
2031
|
+
continue;
|
|
2032
|
+
}
|
|
2033
|
+
const { result } = messageOrResult;
|
|
2034
|
+
const success = result.isOk();
|
|
2035
|
+
const resultToSend = success ? result.value : result.error.json;
|
|
2036
|
+
client.sendJSON({
|
|
2037
|
+
type: "done",
|
|
2038
|
+
result: resultToSend,
|
|
2039
|
+
success
|
|
2040
|
+
});
|
|
2041
|
+
break;
|
|
2042
|
+
}
|
|
2043
|
+
if (!client.closed) {
|
|
2044
|
+
await client.close();
|
|
2045
|
+
}
|
|
2046
|
+
process.exit(0);
|
|
2047
|
+
}
|
|
2048
|
+
);
|
|
2049
|
+
import_commander.program.parse(process.argv);
|
|
187
2050
|
}
|
|
188
2051
|
function getProxyUrlFromRunOptions(runOptions) {
|
|
189
|
-
if (runOptions?.environment !== "standalone") return
|
|
2052
|
+
if (runOptions?.environment !== "standalone") return void 0;
|
|
190
2053
|
const proxy = runOptions.proxy;
|
|
191
|
-
if (!proxy) return
|
|
2054
|
+
if (!proxy) return void 0;
|
|
192
2055
|
const url = new URL(proxy.server);
|
|
193
2056
|
url.username = proxy.username;
|
|
194
2057
|
url.password = proxy.password;
|
|
195
2058
|
return url.toString();
|
|
196
2059
|
}
|
|
197
|
-
|
|
2060
|
+
var _defaultImport = async (path4) => {
|
|
198
2061
|
try {
|
|
199
|
-
const imported = await (
|
|
200
|
-
return (0,
|
|
2062
|
+
const imported = await import(`${process.cwd()}/${path4}`);
|
|
2063
|
+
return (0, import_neverthrow7.ok)(imported);
|
|
201
2064
|
} catch (e) {
|
|
202
|
-
if ("code" in e && e.code === "MODULE_NOT_FOUND") {
|
|
203
|
-
return (0,
|
|
2065
|
+
if ("code" in e && e.code === "MODULE_NOT_FOUND" || e.code === "ERR_MODULE_NOT_FOUND") {
|
|
2066
|
+
return (0, import_neverthrow7.err)({
|
|
204
2067
|
type: "not_found"
|
|
205
2068
|
});
|
|
206
2069
|
}
|
|
207
|
-
return (0,
|
|
2070
|
+
return (0, import_neverthrow7.err)({
|
|
208
2071
|
type: "other",
|
|
209
2072
|
error: e
|
|
210
2073
|
});
|
|
211
2074
|
}
|
|
212
2075
|
};
|
|
2076
|
+
function createClient(mode, input) {
|
|
2077
|
+
if (mode === "jsonl") {
|
|
2078
|
+
return new import_runtime_interface5.JSONLFileClient(input);
|
|
2079
|
+
}
|
|
2080
|
+
if (mode === "tcp") {
|
|
2081
|
+
const [host, portString] = input.split(":");
|
|
2082
|
+
const port = Number(portString);
|
|
2083
|
+
if (!host || isNaN(port)) {
|
|
2084
|
+
throw new Error("Invalid tcp input, expected format host:port");
|
|
2085
|
+
}
|
|
2086
|
+
return new import_runtime_interface5.TCPSocketClient(host, port);
|
|
2087
|
+
}
|
|
2088
|
+
return new import_runtime_interface5.UnixSocketClient(input);
|
|
2089
|
+
}
|
|
213
2090
|
if (require.main === module) {
|
|
214
2091
|
runAutomationCLI();
|
|
215
|
-
}
|
|
2092
|
+
}
|
|
2093
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
2094
|
+
0 && (module.exports = {
|
|
2095
|
+
runAutomationCLI
|
|
2096
|
+
});
|
|
2097
|
+
//# sourceMappingURL=run.js.map
|