@intuned/runtime 1.3.17 → 1.3.18-interface.7
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 +540 -0
- package/dist/common/settingsSchema.d.ts +58 -51
- 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 +168 -0
- package/dist/runtime/index.d.ts +168 -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,51 +1,1701 @@
|
|
|
1
|
-
|
|
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;
|
|
66
|
+
}
|
|
67
|
+
get json() {
|
|
68
|
+
return {
|
|
69
|
+
code: this.code,
|
|
70
|
+
details: this.details,
|
|
71
|
+
cause: this.cause?.json
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports2.RunAutomationError = RunAutomationError4;
|
|
76
|
+
var ApiNotFoundError3 = class extends RunAutomationError4 {
|
|
77
|
+
constructor(apiName) {
|
|
78
|
+
super(exports2.apiNotFoundErrorCode, `API ${apiName} not found`);
|
|
79
|
+
}
|
|
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
|
+
};
|
|
88
|
+
}
|
|
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
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
exports2.AutomationError = AutomationError4;
|
|
138
|
+
var InternalInvalidInputError2 = class extends RunAutomationError4 {
|
|
139
|
+
constructor(message, details) {
|
|
140
|
+
super(exports2.internalInvalidInputErrorCode, message);
|
|
141
|
+
this.details = details;
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
exports2.InternalInvalidInputError = InternalInvalidInputError2;
|
|
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
|
+
});
|
|
2
305
|
|
|
3
|
-
|
|
4
|
-
|
|
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();
|
|
360
|
+
});
|
|
361
|
+
this.socket.once("error", reject);
|
|
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 UnixSocketClient = class extends SocketClient {
|
|
401
|
+
constructor(path4) {
|
|
402
|
+
super(net.createConnection(path4));
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
exports2.UnixSocketClient = UnixSocketClient;
|
|
406
|
+
var TCPSocketClient = class extends SocketClient {
|
|
407
|
+
constructor(host, port) {
|
|
408
|
+
super(net.createConnection(port, host));
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
exports2.TCPSocketClient = TCPSocketClient;
|
|
412
|
+
var JSONLFileClient = 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 = JSONLFileClient;
|
|
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/common/runApi/index.ts
|
|
475
|
+
var runApi_exports = {};
|
|
476
|
+
__export(runApi_exports, {
|
|
477
|
+
checkAuthSessionWithRetries: () => checkAuthSessionWithRetries,
|
|
478
|
+
runApi: () => runApi
|
|
5
479
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
480
|
+
module.exports = __toCommonJS(runApi_exports);
|
|
481
|
+
|
|
482
|
+
// src/common/asyncLocalStorage/index.ts
|
|
483
|
+
var import_node_async_hooks = require("async_hooks");
|
|
484
|
+
var asyncLocalStorage = new import_node_async_hooks.AsyncLocalStorage();
|
|
485
|
+
function getExecutionContext() {
|
|
486
|
+
const contextData = asyncLocalStorage.getStore();
|
|
487
|
+
return contextData;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
// src/runtime/attemptStore.ts
|
|
491
|
+
var attemptStore = Object.freeze({
|
|
492
|
+
get: (key) => {
|
|
493
|
+
const context = getExecutionContext();
|
|
494
|
+
return context?.store ? context.store[key] : void 0;
|
|
495
|
+
},
|
|
496
|
+
set: (key, value) => {
|
|
497
|
+
const context = getExecutionContext();
|
|
498
|
+
if (!context) {
|
|
499
|
+
throw new Error("store.set failed due to an internal error.");
|
|
500
|
+
}
|
|
501
|
+
if (!context.store) {
|
|
502
|
+
context.store = {};
|
|
503
|
+
}
|
|
504
|
+
context.store[key] = value;
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// src/runtime/persistentStore.ts
|
|
509
|
+
var import_zod = require("zod");
|
|
510
|
+
|
|
511
|
+
// src/common/jwtTokenManager.ts
|
|
512
|
+
var import_cross_fetch = __toESM(require("cross-fetch"));
|
|
513
|
+
var jwt = __toESM(require("jsonwebtoken"));
|
|
514
|
+
var import_neverthrow = require("neverthrow");
|
|
515
|
+
|
|
516
|
+
// src/common/constants.ts
|
|
517
|
+
var AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
|
|
518
|
+
var WORKSPACE_ID_ENV_VAR_KEY = "INTUNED_WORKSPACE_ID";
|
|
519
|
+
var PROJECT_ID_ENV_VAR_KEY = "INTUNED_PROJECT_ID";
|
|
520
|
+
var API_KEY_ENV_VAR_KEY = "INTUNED_API_KEY";
|
|
521
|
+
var AUTH_TOKEN_ENV_VAR_KEY = "INTUNED_AUTH_TOKEN";
|
|
522
|
+
var API_KEY_HEADER_NAME = "x-api-key";
|
|
523
|
+
var CLI_ENV_VAR_KEY = "INTUNED_CLI";
|
|
524
|
+
|
|
525
|
+
// src/common/jwtTokenManager.ts
|
|
526
|
+
var JwtTokenManager = class {
|
|
527
|
+
constructor(refreshTokenPath) {
|
|
528
|
+
this.refreshTokenPath = refreshTokenPath;
|
|
529
|
+
this._token = void 0;
|
|
530
|
+
}
|
|
531
|
+
get token() {
|
|
532
|
+
return this._token;
|
|
533
|
+
}
|
|
534
|
+
// When the token is set, the schedule for renewal is issued automatically
|
|
535
|
+
// This is currently being set it two places:
|
|
536
|
+
// 1. Whenever the runner starts, initializes it from the environment variable (set whenever the api is run from the authoring IDE)
|
|
537
|
+
// 2. Whenever a published api is called to run (/api/run/*), it is set to the token received in the run request.
|
|
538
|
+
set token(newToken) {
|
|
539
|
+
if (this._token != newToken) {
|
|
540
|
+
this._token = newToken;
|
|
541
|
+
void this.scheduleTokenRefresh();
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
get timeToRefresh() {
|
|
545
|
+
if (!this._token) return;
|
|
546
|
+
const payload = jwt.decode(this._token);
|
|
547
|
+
if (!payload || typeof payload == "string") return;
|
|
548
|
+
const expiry = payload.expiry;
|
|
549
|
+
if (!expiry || typeof expiry !== "number") return;
|
|
550
|
+
const timeWindow = 60 * 1e3;
|
|
551
|
+
const timeToRefresh = expiry - Date.now() - timeWindow;
|
|
552
|
+
return Math.max(timeToRefresh, timeWindow);
|
|
553
|
+
}
|
|
554
|
+
async scheduleTokenRefresh() {
|
|
555
|
+
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
|
|
556
|
+
const timeToRefresh = this.timeToRefresh;
|
|
557
|
+
if (timeToRefresh === void 0) return;
|
|
558
|
+
if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
|
|
559
|
+
this.tokenRefreshTimeout = setTimeout(async () => {
|
|
560
|
+
const result = await this.refreshToken();
|
|
561
|
+
if (result && result.isErr()) {
|
|
562
|
+
console.error(`[Internal Error] ${result.error}`);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
await this.scheduleTokenRefresh();
|
|
566
|
+
}, timeToRefresh);
|
|
567
|
+
}
|
|
568
|
+
async refreshToken() {
|
|
569
|
+
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
|
|
570
|
+
const res = await this.fetchWithToken(
|
|
571
|
+
`${this.backendFunctionsBaseUrl}/${this.refreshTokenPath}`,
|
|
572
|
+
{
|
|
573
|
+
method: "GET"
|
|
574
|
+
}
|
|
575
|
+
);
|
|
576
|
+
if (res.status === 401) {
|
|
577
|
+
return (0, import_neverthrow.err)("Unauthorized");
|
|
578
|
+
}
|
|
579
|
+
const jsonResult = await import_neverthrow.ResultAsync.fromPromise(
|
|
580
|
+
res.json(),
|
|
581
|
+
() => "not json"
|
|
582
|
+
);
|
|
583
|
+
if (jsonResult.isErr()) return;
|
|
584
|
+
const newToken = jsonResult.value.token;
|
|
585
|
+
if (newToken) this._token = newToken;
|
|
586
|
+
}
|
|
587
|
+
async fetchWithToken(...[input, init]) {
|
|
588
|
+
const headers = new Headers(init?.headers);
|
|
589
|
+
const apiKey = process.env[API_KEY_ENV_VAR_KEY];
|
|
590
|
+
if (apiKey) {
|
|
591
|
+
headers.set(API_KEY_HEADER_NAME, apiKey);
|
|
592
|
+
}
|
|
593
|
+
const token = process.env[AUTH_TOKEN_ENV_VAR_KEY];
|
|
594
|
+
if (token) {
|
|
595
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
596
|
+
}
|
|
597
|
+
if (this.token !== void 0) {
|
|
598
|
+
headers.set("Authorization", `Bearer ${this.token}`);
|
|
599
|
+
}
|
|
600
|
+
const result = await (0, import_cross_fetch.default)(input, {
|
|
601
|
+
...init,
|
|
602
|
+
headers
|
|
603
|
+
});
|
|
604
|
+
if (result.status === 401 && process.env[CLI_ENV_VAR_KEY] === "true") {
|
|
605
|
+
console.warn(
|
|
606
|
+
"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."
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
return result;
|
|
610
|
+
}
|
|
611
|
+
get backendFunctionsBaseUrl() {
|
|
612
|
+
try {
|
|
613
|
+
if (!process.env.FUNCTIONS_DOMAIN) {
|
|
614
|
+
throw new Error(
|
|
615
|
+
`Cannot call backend function - FUNCTIONS_DOMAIN not set`
|
|
616
|
+
);
|
|
617
|
+
}
|
|
618
|
+
const domain = process.env.FUNCTIONS_DOMAIN;
|
|
619
|
+
if (!process.env[WORKSPACE_ID_ENV_VAR_KEY]) {
|
|
620
|
+
throw new Error(
|
|
621
|
+
`Cannot call backend function - ${WORKSPACE_ID_ENV_VAR_KEY} not set`
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
const workspaceId = process.env[WORKSPACE_ID_ENV_VAR_KEY];
|
|
625
|
+
if (!process.env[PROJECT_ID_ENV_VAR_KEY] && !process.env.INTUNED_INTEGRATION_ID) {
|
|
626
|
+
throw new Error(
|
|
627
|
+
`Cannot call backend function - ${PROJECT_ID_ENV_VAR_KEY} or INTUNED_INTEGRATION_ID not set`
|
|
628
|
+
);
|
|
629
|
+
}
|
|
630
|
+
const projectId = process.env.INTUNED_INTEGRATION_ID ?? process.env[PROJECT_ID_ENV_VAR_KEY];
|
|
631
|
+
return `${domain}/api/${workspaceId}/functions/${projectId}`;
|
|
632
|
+
} catch (e) {
|
|
633
|
+
if (process.env[CLI_ENV_VAR_KEY] === "true") {
|
|
634
|
+
throw new Error(
|
|
635
|
+
`API credentials not set - make sure to provision your project to Intuned to set up the correct API credentials.
|
|
636
|
+
Run 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information.
|
|
637
|
+
Original error: ${e.message}`
|
|
638
|
+
);
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
}
|
|
9
642
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
643
|
+
var backendFunctionsTokenManager = new JwtTokenManager(
|
|
644
|
+
`refreshBackendFunctionsToken`
|
|
645
|
+
);
|
|
646
|
+
backendFunctionsTokenManager.token = process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;
|
|
647
|
+
function callBackendFunctionWithToken(path4, init) {
|
|
648
|
+
return backendFunctionsTokenManager.fetchWithToken(
|
|
649
|
+
`${backendFunctionsTokenManager.backendFunctionsBaseUrl}/${path4}`,
|
|
650
|
+
init
|
|
651
|
+
);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// src/runtime/persistentStore.ts
|
|
655
|
+
var forbiddenCharacters = /[:#]/g;
|
|
656
|
+
var keySchema = import_zod.z.string().min(1, "Key must be at least 1 character long").refine(
|
|
657
|
+
(key) => (key.match(forbiddenCharacters)?.length ?? 0) === 0,
|
|
658
|
+
'Key cannot contain the following characters: ":" or "#"'
|
|
659
|
+
);
|
|
660
|
+
var persistentStore = Object.freeze({
|
|
661
|
+
get: async (key) => {
|
|
662
|
+
const parsedKey = keySchema.parse(key);
|
|
663
|
+
const response = await callBackendFunctionWithToken(
|
|
664
|
+
`kv-store/${parsedKey}`,
|
|
665
|
+
{
|
|
666
|
+
method: "GET"
|
|
667
|
+
}
|
|
668
|
+
);
|
|
669
|
+
const json = await response.json();
|
|
670
|
+
if (!response.ok) {
|
|
671
|
+
throw new Error(json.message);
|
|
27
672
|
}
|
|
28
|
-
|
|
673
|
+
return json.value;
|
|
674
|
+
},
|
|
675
|
+
set: async (key, value) => {
|
|
676
|
+
const keyResult = keySchema.parse(key);
|
|
677
|
+
const response = await callBackendFunctionWithToken(
|
|
678
|
+
`kv-store/${keyResult}`,
|
|
679
|
+
{
|
|
680
|
+
method: "PUT",
|
|
681
|
+
body: JSON.stringify(value),
|
|
682
|
+
headers: {
|
|
683
|
+
"Content-Type": "application/json"
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
);
|
|
687
|
+
const json = await response.json();
|
|
688
|
+
if (!response.ok) {
|
|
689
|
+
throw new Error(json.message);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
});
|
|
693
|
+
|
|
694
|
+
// src/runtime/RunError.ts
|
|
695
|
+
var RunError = class _RunError extends Error {
|
|
696
|
+
constructor(message, options) {
|
|
697
|
+
super(message);
|
|
698
|
+
this.message = message;
|
|
699
|
+
this.name = "USER_GENERATED_ERROR";
|
|
700
|
+
this.options = options ?? {
|
|
701
|
+
retryable: false
|
|
702
|
+
};
|
|
703
|
+
Object.setPrototypeOf(this, _RunError.prototype);
|
|
704
|
+
}
|
|
705
|
+
};
|
|
706
|
+
new RunError("", {});
|
|
707
|
+
|
|
708
|
+
// src/common/extension/intunedExtensionServer.ts
|
|
709
|
+
var import_fastify = __toESM(require("fastify"));
|
|
710
|
+
|
|
711
|
+
// src/common/extension/types.ts
|
|
712
|
+
var import_zod2 = require("zod");
|
|
713
|
+
var captchaTypeSchema = import_zod2.z.enum([
|
|
714
|
+
"aws",
|
|
715
|
+
"cloudflare",
|
|
716
|
+
"customcaptcha",
|
|
717
|
+
"funcaptcha",
|
|
718
|
+
"geetest",
|
|
719
|
+
"hcaptcha",
|
|
720
|
+
"lemincaptcha",
|
|
721
|
+
"recaptcha",
|
|
722
|
+
"textcaptcha"
|
|
723
|
+
]);
|
|
724
|
+
var captchaStatusSchema = import_zod2.z.enum([
|
|
725
|
+
"attached",
|
|
726
|
+
"solving",
|
|
727
|
+
"solved",
|
|
728
|
+
"error",
|
|
729
|
+
"detached"
|
|
730
|
+
]);
|
|
731
|
+
var captchaErrorCodeSchema = import_zod2.z.enum([
|
|
732
|
+
"HIT_LIMIT",
|
|
733
|
+
"MAX_RETRIES",
|
|
734
|
+
"UNEXPECTED_SERVER_RESPONSE",
|
|
735
|
+
"UNEXPECTED_ERROR"
|
|
736
|
+
]);
|
|
737
|
+
var captchaErrorSchema = import_zod2.z.object({
|
|
738
|
+
code: captchaErrorCodeSchema,
|
|
739
|
+
error: import_zod2.z.unknown().optional()
|
|
740
|
+
});
|
|
741
|
+
var captchaBaseSchema = import_zod2.z.object({
|
|
742
|
+
id: import_zod2.z.string().min(1),
|
|
743
|
+
tabId: import_zod2.z.number().int().positive(),
|
|
744
|
+
type: captchaTypeSchema,
|
|
745
|
+
retryCount: import_zod2.z.number().int().nonnegative().optional()
|
|
746
|
+
});
|
|
747
|
+
var captchaNonErrorSchema = captchaBaseSchema.extend({
|
|
748
|
+
status: captchaStatusSchema.exclude(["error"])
|
|
29
749
|
});
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
750
|
+
var captchaErrorStatusSchema = captchaBaseSchema.extend({
|
|
751
|
+
status: import_zod2.z.literal("error"),
|
|
752
|
+
error: captchaErrorSchema
|
|
753
|
+
});
|
|
754
|
+
var captchaSchema = import_zod2.z.discriminatedUnion("status", [
|
|
755
|
+
captchaBaseSchema.extend({
|
|
756
|
+
status: import_zod2.z.literal("attached")
|
|
757
|
+
}),
|
|
758
|
+
captchaBaseSchema.extend({
|
|
759
|
+
status: import_zod2.z.literal("solving")
|
|
760
|
+
}),
|
|
761
|
+
captchaBaseSchema.extend({
|
|
762
|
+
status: import_zod2.z.literal("solved")
|
|
763
|
+
}),
|
|
764
|
+
captchaBaseSchema.extend({
|
|
765
|
+
status: import_zod2.z.literal("detached")
|
|
766
|
+
}),
|
|
767
|
+
captchaErrorStatusSchema
|
|
768
|
+
]);
|
|
769
|
+
|
|
770
|
+
// src/commands/common/utils/fileUtils.ts
|
|
771
|
+
var path = __toESM(require("path"));
|
|
772
|
+
var fs = __toESM(require("fs-extra"));
|
|
773
|
+
var import_dotenv = __toESM(require("dotenv"));
|
|
774
|
+
import_dotenv.default.config();
|
|
775
|
+
function getFullPathInProject(...paths) {
|
|
776
|
+
return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// src/common/settingsSchema.ts
|
|
780
|
+
var z3 = __toESM(require("zod"));
|
|
781
|
+
var baseCaptchaSchema = z3.object({
|
|
782
|
+
enabled: z3.boolean()
|
|
783
|
+
});
|
|
784
|
+
var customCaptchaSchema = baseCaptchaSchema.extend({
|
|
785
|
+
imageLocators: z3.array(z3.string()).min(1, "At least one image locator is required"),
|
|
786
|
+
submitLocators: z3.array(z3.string()).min(1, "At least one submit locator is required"),
|
|
787
|
+
inputLocators: z3.array(z3.string()).min(1, "At least one input locator is required")
|
|
788
|
+
});
|
|
789
|
+
var textCaptchaSchema = baseCaptchaSchema.extend({
|
|
790
|
+
labelLocators: z3.array(z3.string()).min(1, "At least one image locator is required"),
|
|
791
|
+
submitLocators: z3.array(z3.string()).min(1, "At least one submit locator is required"),
|
|
792
|
+
inputLocators: z3.array(z3.string()).min(1, "At least one input locator is required")
|
|
793
|
+
});
|
|
794
|
+
var captchaSolverSolveSettingsSchema = z3.object({
|
|
795
|
+
autoSolve: z3.boolean().default(true),
|
|
796
|
+
solveDelay: z3.number().min(0).default(2e3),
|
|
797
|
+
maxRetries: z3.number().min(0).default(3),
|
|
798
|
+
timeout: z3.number().min(0).default(3e4)
|
|
799
|
+
});
|
|
800
|
+
var captchaSolverSettingsSchema = z3.object({
|
|
801
|
+
enabled: z3.boolean().default(false),
|
|
802
|
+
port: z3.number().int().min(1).max(65535).optional(),
|
|
803
|
+
cloudflare: baseCaptchaSchema.optional(),
|
|
804
|
+
googleRecaptchaV2: baseCaptchaSchema.optional(),
|
|
805
|
+
googleRecaptchaV3: baseCaptchaSchema.optional(),
|
|
806
|
+
awscaptcha: baseCaptchaSchema.optional(),
|
|
807
|
+
hcaptcha: baseCaptchaSchema.optional(),
|
|
808
|
+
funcaptcha: baseCaptchaSchema.optional(),
|
|
809
|
+
geetest: baseCaptchaSchema.optional(),
|
|
810
|
+
lemin: baseCaptchaSchema.optional(),
|
|
811
|
+
customCaptcha: customCaptchaSchema.optional(),
|
|
812
|
+
text: textCaptchaSchema.optional(),
|
|
813
|
+
settings: captchaSolverSolveSettingsSchema.default(
|
|
814
|
+
captchaSolverSolveSettingsSchema.parse({})
|
|
815
|
+
)
|
|
816
|
+
}).default({});
|
|
817
|
+
var authSessionsSchema = z3.object({
|
|
818
|
+
enabled: z3.boolean()
|
|
819
|
+
}).optional().default({
|
|
820
|
+
enabled: false
|
|
821
|
+
});
|
|
822
|
+
var stealthModeSchema = z3.object({
|
|
823
|
+
enabled: z3.boolean()
|
|
824
|
+
}).optional().default({
|
|
825
|
+
enabled: false
|
|
826
|
+
});
|
|
827
|
+
var settingsSchema = z3.object({
|
|
828
|
+
authSessions: authSessionsSchema,
|
|
829
|
+
stealthMode: stealthModeSchema,
|
|
830
|
+
captchaSolver: captchaSolverSettingsSchema.optional()
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// src/commands/common/utils/settings.ts
|
|
834
|
+
var import_promises = require("fs/promises");
|
|
835
|
+
async function getSettings() {
|
|
836
|
+
const settingsFilePath = getFullPathInProject("Intuned.json");
|
|
837
|
+
const settings = await (0, import_promises.readFile)(settingsFilePath, { encoding: "utf-8" });
|
|
838
|
+
if (settings) {
|
|
839
|
+
const parsed = settingsSchema.safeParse(JSON.parse(settings));
|
|
840
|
+
if (parsed.success) {
|
|
841
|
+
return parsed.data;
|
|
842
|
+
} else {
|
|
843
|
+
throw new Error(parsed.error.message);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return {
|
|
847
|
+
authSessions: { enabled: false },
|
|
848
|
+
stealthMode: { enabled: false }
|
|
849
|
+
};
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
// src/common/extension/extensionsHelpers.ts
|
|
853
|
+
var import_path = __toESM(require("path"));
|
|
854
|
+
var import_promises2 = require("fs/promises");
|
|
855
|
+
var import_portfinder = require("portfinder");
|
|
856
|
+
var INTUNED_WORKER = "intunedWorker.js";
|
|
857
|
+
var INTUNED_EXTENSION_SETTINGS_FILE_NAME = "intunedSettings.json";
|
|
858
|
+
var captchaSolverSettings = null;
|
|
859
|
+
async function getIntunedCaptchaExtensionPort() {
|
|
860
|
+
if (process.env.INTUNED_CAPTCHA_EXTENSION_PORT) {
|
|
861
|
+
return parseInt(process.env.INTUNED_CAPTCHA_EXTENSION_PORT, 10);
|
|
862
|
+
}
|
|
863
|
+
return await (0, import_portfinder.getPort)({});
|
|
864
|
+
}
|
|
865
|
+
async function resolveCaptchaSolverSettings(input) {
|
|
866
|
+
const parsed = captchaSolverSettingsSchema.parse(input || {});
|
|
867
|
+
if (!parsed.port) {
|
|
868
|
+
parsed.port = await getIntunedCaptchaExtensionPort();
|
|
869
|
+
}
|
|
870
|
+
return parsed;
|
|
871
|
+
}
|
|
872
|
+
function isIntunedExtensionLoaded() {
|
|
873
|
+
return !!getIntunedExtensionPath();
|
|
874
|
+
}
|
|
875
|
+
function buildExtensionsList() {
|
|
876
|
+
const extensionsList = [];
|
|
877
|
+
if (isIntunedExtensionLoaded()) {
|
|
878
|
+
const intunedExtensionPath = getIntunedExtensionPath();
|
|
879
|
+
extensionsList.push(intunedExtensionPath);
|
|
880
|
+
}
|
|
881
|
+
return extensionsList;
|
|
882
|
+
}
|
|
883
|
+
function getIntunedExtensionPath() {
|
|
884
|
+
return process.env.INTUNED_EXTENSION_PATH;
|
|
885
|
+
}
|
|
886
|
+
async function isIntunedExtensionEnabled() {
|
|
887
|
+
const path4 = getIntunedExtensionPath();
|
|
888
|
+
if (!path4) {
|
|
889
|
+
return false;
|
|
890
|
+
}
|
|
891
|
+
const captchaSolverSettings2 = await getIntunedCaptchaSolverSettings();
|
|
892
|
+
return captchaSolverSettings2.enabled;
|
|
893
|
+
}
|
|
894
|
+
async function getIntunedExtensionWorker(context) {
|
|
895
|
+
if (!await isIntunedExtensionEnabled()) {
|
|
896
|
+
return null;
|
|
897
|
+
}
|
|
898
|
+
let attemptCount = 0;
|
|
899
|
+
while (attemptCount < 4) {
|
|
900
|
+
const intunedServiceWorker = context.serviceWorkers().find((serviceWorker) => serviceWorker.url().includes(INTUNED_WORKER));
|
|
901
|
+
if (intunedServiceWorker) {
|
|
902
|
+
return intunedServiceWorker;
|
|
903
|
+
}
|
|
904
|
+
try {
|
|
905
|
+
await context.waitForEvent("serviceworker", { timeout: 3e3 });
|
|
906
|
+
} catch (err6) {
|
|
907
|
+
console.log(`Error accessing service workers (attempt ${attemptCount})`);
|
|
908
|
+
}
|
|
909
|
+
attemptCount++;
|
|
910
|
+
}
|
|
911
|
+
console.error("Failed to get intuned worker after 5 attmepts");
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
async function getIntunedExtensionSettings(captchaSolverSettings2) {
|
|
915
|
+
const [domain, workspaceId, projectId] = [
|
|
916
|
+
process.env.FUNCTIONS_DOMAIN,
|
|
917
|
+
process.env[WORKSPACE_ID_ENV_VAR_KEY],
|
|
918
|
+
process.env.INTUNED_INTEGRATION_ID ?? process.env[PROJECT_ID_ENV_VAR_KEY]
|
|
919
|
+
];
|
|
920
|
+
if (!domain || !workspaceId || !projectId) {
|
|
921
|
+
const missingEnvVars = [
|
|
922
|
+
domain && "FUNCTIONS_DOMAIN",
|
|
923
|
+
workspaceId && WORKSPACE_ID_ENV_VAR_KEY,
|
|
924
|
+
projectId && `INTUNED_INTEGRATION_ID OR ${PROJECT_ID_ENV_VAR_KEY}`
|
|
925
|
+
];
|
|
926
|
+
throw new Error(
|
|
927
|
+
`Missing required environment variables: ${missingEnvVars}`
|
|
928
|
+
);
|
|
929
|
+
}
|
|
930
|
+
const authentication = (() => {
|
|
931
|
+
if (process.env.INTUNED_API_KEY) {
|
|
932
|
+
return { type: "apiKey", apiKey: process.env.INTUNED_API_KEY };
|
|
933
|
+
}
|
|
934
|
+
if (process.env.INTUNED_BASIC_AUTH_USERNAME && process.env.INTUNED_BASIC_AUTH_PASSWORD) {
|
|
935
|
+
const credentials = `${process.env.INTUNED_BASIC_AUTH_USERNAME}:${process.env.INTUNED_BASIC_AUTH_PASSWORD}`;
|
|
936
|
+
const token = Buffer.from(credentials, "utf-8").toString("base64");
|
|
937
|
+
return { type: "basic", token };
|
|
938
|
+
}
|
|
939
|
+
return {
|
|
940
|
+
type: "bearer",
|
|
941
|
+
token: backendFunctionsTokenManager.token
|
|
942
|
+
};
|
|
943
|
+
})();
|
|
944
|
+
const baseUrl = process.env.INTUNED_API_BASE_URL ?? domain;
|
|
945
|
+
return {
|
|
946
|
+
...captchaSolverSettings2,
|
|
947
|
+
workspaceId,
|
|
948
|
+
projectId,
|
|
949
|
+
baseUrl,
|
|
950
|
+
authentication
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
async function getIntunedCaptchaSolverSettings() {
|
|
954
|
+
if (captchaSolverSettings) {
|
|
955
|
+
return captchaSolverSettings;
|
|
956
|
+
}
|
|
957
|
+
const settings = await getSettings();
|
|
958
|
+
captchaSolverSettings = await resolveCaptchaSolverSettings(
|
|
959
|
+
settings.captchaSolver
|
|
960
|
+
);
|
|
961
|
+
return captchaSolverSettings;
|
|
962
|
+
}
|
|
963
|
+
async function setupIntunedExtension() {
|
|
964
|
+
if (!await isIntunedExtensionEnabled()) {
|
|
965
|
+
return;
|
|
966
|
+
}
|
|
967
|
+
const intunedExtensionPath = getIntunedExtensionPath();
|
|
968
|
+
const intunedExtensionSettingsPath = import_path.default.join(
|
|
969
|
+
intunedExtensionPath,
|
|
970
|
+
INTUNED_EXTENSION_SETTINGS_FILE_NAME
|
|
971
|
+
);
|
|
972
|
+
const captchaSolverSettings2 = await getIntunedCaptchaSolverSettings();
|
|
973
|
+
await setupIntunedExtensionServer(captchaSolverSettings2);
|
|
974
|
+
const captchaSolverSettingsWithRunContext = await getIntunedExtensionSettings(
|
|
975
|
+
captchaSolverSettings2
|
|
976
|
+
);
|
|
977
|
+
await (0, import_promises2.writeFile)(
|
|
978
|
+
intunedExtensionSettingsPath,
|
|
979
|
+
JSON.stringify(captchaSolverSettingsWithRunContext)
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
// src/common/extension/intunedExtensionServer.ts
|
|
984
|
+
var TabCaptchaState = class {
|
|
985
|
+
constructor(tabId) {
|
|
986
|
+
this.tabId = tabId;
|
|
987
|
+
this.captchasById = /* @__PURE__ */ new Map();
|
|
988
|
+
this.subscribers = new Array();
|
|
989
|
+
}
|
|
990
|
+
subscribe(handler) {
|
|
991
|
+
this.subscribers.push(handler);
|
|
992
|
+
}
|
|
993
|
+
unsubscribe(handler, status) {
|
|
994
|
+
const index = this.subscribers.findIndex(
|
|
995
|
+
(subscriber) => subscriber.handler === handler && (subscriber.status === status || !status)
|
|
996
|
+
);
|
|
997
|
+
if (index !== -1) {
|
|
998
|
+
this.subscribers.splice(index, 1);
|
|
41
999
|
}
|
|
1000
|
+
}
|
|
1001
|
+
getCaptchas() {
|
|
1002
|
+
return [...this.captchasById.values()];
|
|
1003
|
+
}
|
|
1004
|
+
async upsertCaptcha(captcha) {
|
|
1005
|
+
this.captchasById.set(captcha.id, captcha);
|
|
1006
|
+
for (const subscriber of this.subscribers) {
|
|
1007
|
+
if (!subscriber.status || subscriber.status === captcha.status) {
|
|
1008
|
+
await subscriber.handler(captcha);
|
|
1009
|
+
}
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
var ExtensionServer = class {
|
|
1014
|
+
constructor() {
|
|
1015
|
+
this.app = null;
|
|
1016
|
+
this.tabs = /* @__PURE__ */ new Map();
|
|
1017
|
+
}
|
|
1018
|
+
getOrCreateTab(tabId) {
|
|
1019
|
+
const existing = this.tabs.get(tabId);
|
|
1020
|
+
if (existing) return existing;
|
|
1021
|
+
const created = new TabCaptchaState(tabId);
|
|
1022
|
+
this.tabs.set(tabId, created);
|
|
1023
|
+
return created;
|
|
1024
|
+
}
|
|
1025
|
+
async handleUpsertCaptcha(captcha) {
|
|
1026
|
+
const tab = this.getOrCreateTab(captcha.tabId);
|
|
1027
|
+
await tab.upsertCaptcha(captcha);
|
|
1028
|
+
}
|
|
1029
|
+
async start({
|
|
1030
|
+
port,
|
|
1031
|
+
host = "0.0.0.0"
|
|
1032
|
+
}) {
|
|
1033
|
+
if (this.app) {
|
|
1034
|
+
return;
|
|
1035
|
+
}
|
|
1036
|
+
this.app = (0, import_fastify.default)({
|
|
1037
|
+
logger: false,
|
|
1038
|
+
bodyLimit: 1e6
|
|
1039
|
+
});
|
|
1040
|
+
this.app.post("/state", async (request, reply) => {
|
|
1041
|
+
try {
|
|
1042
|
+
const result = captchaSchema.safeParse(request.body);
|
|
1043
|
+
if (!result.success) {
|
|
1044
|
+
return reply.code(400).send({
|
|
1045
|
+
error: "Invalid captcha payload",
|
|
1046
|
+
details: result.error.flatten().fieldErrors
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
await this.handleUpsertCaptcha(result.data);
|
|
1050
|
+
return reply.code(200).send({});
|
|
1051
|
+
} catch (error) {
|
|
1052
|
+
console.error("Error processing captcha state update:", error);
|
|
1053
|
+
return reply.code(500).send({
|
|
1054
|
+
error: "Internal server error",
|
|
1055
|
+
message: error?.message ?? String(error)
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
});
|
|
1059
|
+
this.app.setNotFoundHandler((_request, reply) => {
|
|
1060
|
+
return reply.code(404).send({ error: "Not found" });
|
|
1061
|
+
});
|
|
1062
|
+
await this.app.listen({
|
|
1063
|
+
port,
|
|
1064
|
+
host
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
async stop() {
|
|
1068
|
+
if (!this.app) return;
|
|
1069
|
+
const toClose = this.app;
|
|
1070
|
+
this.app = null;
|
|
1071
|
+
await toClose.close();
|
|
1072
|
+
}
|
|
1073
|
+
async getCaptchas(page, status) {
|
|
1074
|
+
const tabId = await getTabId(page);
|
|
1075
|
+
const tab = this.tabs.get(tabId);
|
|
1076
|
+
if (!tab) return [];
|
|
1077
|
+
const captchas = tab.getCaptchas();
|
|
1078
|
+
if (!status) return captchas;
|
|
1079
|
+
return captchas.filter((c) => c.status === status && c.tabId === tabId);
|
|
1080
|
+
}
|
|
1081
|
+
async subscribe(page, handler, status) {
|
|
1082
|
+
const tabId = await getTabId(page);
|
|
1083
|
+
const tab = this.getOrCreateTab(tabId);
|
|
1084
|
+
tab.subscribe({ handler, status });
|
|
1085
|
+
}
|
|
1086
|
+
async unsubscribe(page, handler, status) {
|
|
1087
|
+
const tabId = await getTabId(page);
|
|
1088
|
+
const tab = this.tabs.get(tabId);
|
|
1089
|
+
if (!tab) return;
|
|
1090
|
+
tab.unsubscribe(handler, status);
|
|
1091
|
+
}
|
|
1092
|
+
removeTab(tabId) {
|
|
1093
|
+
this.tabs.delete(tabId);
|
|
1094
|
+
}
|
|
1095
|
+
async getTabId(page) {
|
|
1096
|
+
return await getTabId(page);
|
|
1097
|
+
}
|
|
1098
|
+
};
|
|
1099
|
+
var extensionServerSingleton = null;
|
|
1100
|
+
async function setupIntunedExtensionServer(captchaSolverSettings2) {
|
|
1101
|
+
if (!captchaSolverSettings2) {
|
|
1102
|
+
captchaSolverSettings2 = await resolveCaptchaSolverSettings();
|
|
1103
|
+
}
|
|
1104
|
+
if (!extensionServerSingleton) {
|
|
1105
|
+
extensionServerSingleton = new ExtensionServer();
|
|
1106
|
+
}
|
|
1107
|
+
await extensionServerSingleton.start({
|
|
1108
|
+
port: captchaSolverSettings2.port ?? 9e3
|
|
42
1109
|
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
1110
|
+
}
|
|
1111
|
+
async function cleanIntunedExtensionServer() {
|
|
1112
|
+
if (extensionServerSingleton) {
|
|
1113
|
+
await extensionServerSingleton.stop();
|
|
1114
|
+
extensionServerSingleton = null;
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
var TAB_ID_CACHE_KEY = "__INTUNED_CACHED_TAB_ID__";
|
|
1118
|
+
async function getTabId(page) {
|
|
1119
|
+
const cached = page[TAB_ID_CACHE_KEY];
|
|
1120
|
+
if (cached !== void 0 && typeof cached === "number") {
|
|
1121
|
+
return cached;
|
|
1122
|
+
}
|
|
1123
|
+
let tabId;
|
|
1124
|
+
try {
|
|
1125
|
+
tabId = await page.evaluate("window.__INTUNED_TAB_ID__", { timeout: 100 });
|
|
1126
|
+
} catch {
|
|
1127
|
+
await page.waitForFunction("window.__INTUNED_TAB_ID__ !== undefined", {
|
|
1128
|
+
timeout: 15e3
|
|
1129
|
+
});
|
|
1130
|
+
tabId = await page.evaluate("window.__INTUNED_TAB_ID__");
|
|
1131
|
+
}
|
|
1132
|
+
const numericTabId = Number(tabId);
|
|
1133
|
+
page[TAB_ID_CACHE_KEY] = numericTabId;
|
|
1134
|
+
return numericTabId;
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
// src/runtime/downloadDirectory.ts
|
|
1138
|
+
var import_fs_extra = require("fs-extra");
|
|
1139
|
+
function getDownloadDirectoryPath() {
|
|
1140
|
+
const context = getExecutionContext();
|
|
1141
|
+
if (!context) {
|
|
1142
|
+
throw new Error("ExecutionContext not found");
|
|
1143
|
+
}
|
|
1144
|
+
const path4 = `/tmp/downloads/${context.runId}`;
|
|
1145
|
+
(0, import_fs_extra.ensureDirSync)(path4, {
|
|
1146
|
+
mode: 1533
|
|
1147
|
+
});
|
|
1148
|
+
return path4;
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
// src/common/runApi/index.ts
|
|
1152
|
+
var fs4 = __toESM(require("fs-extra"));
|
|
1153
|
+
var import_fs_extra3 = require("fs-extra");
|
|
1154
|
+
var import_neverthrow6 = require("neverthrow");
|
|
1155
|
+
|
|
1156
|
+
// src/common/contextStorageStateHelpers.ts
|
|
1157
|
+
async function setStorageState(context, state) {
|
|
1158
|
+
if ("cookies" in state && state.cookies) {
|
|
1159
|
+
await context.addCookies(state.cookies);
|
|
1160
|
+
}
|
|
1161
|
+
const page = await context.newPage();
|
|
1162
|
+
if ("origins" in state && state.origins) {
|
|
1163
|
+
for (const originData of state.origins || []) {
|
|
1164
|
+
const origin = originData.origin;
|
|
1165
|
+
await page.route(
|
|
1166
|
+
`${origin}/*`,
|
|
1167
|
+
(route) => route.fulfill({
|
|
1168
|
+
body: "<html><head><title>Set Storage</title></head><body><h1>Set Storage</h1></body></html>",
|
|
1169
|
+
contentType: "text/html",
|
|
1170
|
+
status: 200
|
|
1171
|
+
})
|
|
1172
|
+
);
|
|
1173
|
+
try {
|
|
1174
|
+
await page.goto(origin);
|
|
1175
|
+
for (const item of originData.localStorage) {
|
|
1176
|
+
await page.evaluate(
|
|
1177
|
+
([key, value]) => {
|
|
1178
|
+
window.localStorage.setItem(key, value);
|
|
1179
|
+
},
|
|
1180
|
+
[item.name, item.value]
|
|
1181
|
+
);
|
|
1182
|
+
}
|
|
1183
|
+
} finally {
|
|
1184
|
+
await page.unroute(`${origin}/*`);
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
if ("sessionStorage" in state && state.sessionStorage) {
|
|
1189
|
+
await context.addInitScript((storage) => {
|
|
1190
|
+
for (const { origin, sessionStorage } of storage) {
|
|
1191
|
+
if (window.location.origin === origin) {
|
|
1192
|
+
for (const item of sessionStorage) {
|
|
1193
|
+
const value = window.sessionStorage.getItem(item.name);
|
|
1194
|
+
if (!value) {
|
|
1195
|
+
window.sessionStorage.setItem(item.name, item.value);
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}, state.sessionStorage);
|
|
1201
|
+
}
|
|
1202
|
+
await page.close();
|
|
1203
|
+
}
|
|
1204
|
+
async function getStorageState(context) {
|
|
1205
|
+
const result = {
|
|
1206
|
+
cookies: [],
|
|
1207
|
+
origins: []
|
|
1208
|
+
};
|
|
1209
|
+
const storageState = await context.storageState();
|
|
1210
|
+
result.cookies = storageState.cookies;
|
|
1211
|
+
result.origins = storageState.origins;
|
|
1212
|
+
const sessionDataList = [];
|
|
1213
|
+
const pages = await context.pages();
|
|
1214
|
+
for (const page of pages) {
|
|
1215
|
+
if (page.isClosed()) continue;
|
|
1216
|
+
try {
|
|
1217
|
+
const sessionData = await page.evaluate(() => {
|
|
1218
|
+
const items = { ...window.sessionStorage };
|
|
1219
|
+
return {
|
|
1220
|
+
origin: window.location.origin,
|
|
1221
|
+
sessionStorage: Object.entries(items).map(([name, value]) => ({
|
|
1222
|
+
name,
|
|
1223
|
+
value
|
|
1224
|
+
}))
|
|
1225
|
+
};
|
|
1226
|
+
});
|
|
1227
|
+
sessionDataList.push(sessionData);
|
|
1228
|
+
} catch (error) {
|
|
1229
|
+
console.error("Error getting sessionStorage:", error);
|
|
1230
|
+
}
|
|
1231
|
+
}
|
|
1232
|
+
result["sessionStorage"] = sessionDataList;
|
|
1233
|
+
return result;
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
// src/common/playwrightContext.ts
|
|
1237
|
+
var import_path3 = __toESM(require("path"));
|
|
1238
|
+
var fs3 = __toESM(require("fs-extra"));
|
|
1239
|
+
var import_neverthrow5 = require("neverthrow");
|
|
1240
|
+
|
|
1241
|
+
// src/common/setupContextHook.ts
|
|
1242
|
+
var import_neverthrow3 = require("neverthrow");
|
|
1243
|
+
|
|
1244
|
+
// src/common/runApi/importUsingImportFunction.ts
|
|
1245
|
+
var import_neverthrow2 = require("neverthrow");
|
|
1246
|
+
var import_runtime_interface = __toESM(require_dist());
|
|
1247
|
+
async function importUsingImportFunction({
|
|
1248
|
+
path: path4,
|
|
1249
|
+
allowGenerators = true,
|
|
1250
|
+
importFunction
|
|
1251
|
+
}) {
|
|
1252
|
+
try {
|
|
1253
|
+
const importedResult = await importFunction(path4);
|
|
1254
|
+
if (importedResult.isErr()) {
|
|
1255
|
+
if (importedResult.error.type === "not_found") {
|
|
1256
|
+
return (0, import_neverthrow2.err)(new import_runtime_interface.ApiNotFoundError(path4));
|
|
1257
|
+
}
|
|
1258
|
+
return (0, import_neverthrow2.err)(new import_runtime_interface.AutomationError(importedResult.error.error));
|
|
1259
|
+
}
|
|
1260
|
+
const imported = importedResult.value;
|
|
1261
|
+
if (!imported || !imported.default || !imported.default.constructor) {
|
|
1262
|
+
return (0, import_neverthrow2.err)(new import_runtime_interface.InvalidApiError(`${path4} does not have a default export`));
|
|
1263
|
+
}
|
|
1264
|
+
if (imported.default.constructor.name === "AsyncGeneratorFunction") {
|
|
1265
|
+
if (!allowGenerators) {
|
|
1266
|
+
return (0, import_neverthrow2.err)(
|
|
1267
|
+
new import_runtime_interface.InvalidApiError(
|
|
1268
|
+
`${path4} default export must be an async function`
|
|
1269
|
+
)
|
|
1270
|
+
);
|
|
1271
|
+
}
|
|
1272
|
+
return (0, import_neverthrow2.ok)(async (...args) => {
|
|
1273
|
+
const generator = imported.default(
|
|
1274
|
+
...args
|
|
1275
|
+
);
|
|
1276
|
+
const result = await generator.next();
|
|
1277
|
+
if (!result.done) {
|
|
1278
|
+
throw new Error("Yield is not supported");
|
|
1279
|
+
}
|
|
1280
|
+
return result.value;
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
if (imported.default.constructor.name === "AsyncFunction") {
|
|
1284
|
+
return (0, import_neverthrow2.ok)(imported.default);
|
|
1285
|
+
}
|
|
1286
|
+
return (0, import_neverthrow2.err)(
|
|
1287
|
+
new import_runtime_interface.InvalidApiError(`${path4} default export must be an async function`)
|
|
1288
|
+
);
|
|
1289
|
+
} catch (error) {
|
|
1290
|
+
return (0, import_neverthrow2.err)(new import_runtime_interface.AutomationError(error));
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
// src/common/setupContextHook.ts
|
|
1295
|
+
var import_runtime_interface2 = __toESM(require_dist());
|
|
1296
|
+
var setupContextHookPath = "hooks/setupContext";
|
|
1297
|
+
async function loadSetupContextHook({
|
|
1298
|
+
importFunction
|
|
1299
|
+
}) {
|
|
1300
|
+
const importedFunctionResult = await importUsingImportFunction({
|
|
1301
|
+
path: setupContextHookPath,
|
|
1302
|
+
importFunction
|
|
1303
|
+
});
|
|
1304
|
+
if (importedFunctionResult.isErr() && importedFunctionResult.error instanceof import_runtime_interface2.ApiNotFoundError) {
|
|
1305
|
+
return (0, import_neverthrow3.ok)(null);
|
|
1306
|
+
}
|
|
1307
|
+
return importedFunctionResult;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
// src/common/playwrightContext.ts
|
|
1311
|
+
var import_portfinder2 = require("portfinder");
|
|
1312
|
+
|
|
1313
|
+
// src/common/launchBrowser.ts
|
|
1314
|
+
var playwright = __toESM(require("playwright"));
|
|
1315
|
+
var import_fs_extra2 = require("fs-extra");
|
|
1316
|
+
var import_path2 = require("path");
|
|
1317
|
+
var fs2 = __toESM(require("fs-extra"));
|
|
1318
|
+
var import_wait_on = __toESM(require("wait-on"));
|
|
1319
|
+
var import_child_process = require("child_process");
|
|
1320
|
+
var import_util = require("util");
|
|
1321
|
+
var import_neverthrow4 = require("neverthrow");
|
|
1322
|
+
var import_zod3 = require("zod");
|
|
1323
|
+
var execAsync = (0, import_util.promisify)(import_child_process.exec);
|
|
1324
|
+
async function createUserDirWithPreferences() {
|
|
1325
|
+
const playwrightTempDir = await (0, import_fs_extra2.mkdtemp)("/tmp/pw-");
|
|
1326
|
+
const userDir = (0, import_path2.join)(playwrightTempDir, "userdir");
|
|
1327
|
+
const defaultDir = (0, import_path2.join)(userDir, "Default");
|
|
1328
|
+
await (0, import_fs_extra2.mkdir)(defaultDir, {
|
|
1329
|
+
recursive: true
|
|
1330
|
+
});
|
|
1331
|
+
const preferences = {
|
|
1332
|
+
plugins: {
|
|
1333
|
+
always_open_pdf_externally: true
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
await (0, import_fs_extra2.writeFile)((0, import_path2.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
1337
|
+
return userDir;
|
|
1338
|
+
}
|
|
1339
|
+
async function launchChromium(options) {
|
|
1340
|
+
if ("cdpAddress" in options) {
|
|
1341
|
+
if (await isIntunedExtensionEnabled()) {
|
|
1342
|
+
await setupIntunedExtensionServer();
|
|
1343
|
+
}
|
|
1344
|
+
const browser = await playwright.chromium.connectOverCDP(
|
|
1345
|
+
options.cdpAddress
|
|
1346
|
+
);
|
|
1347
|
+
if (browser.contexts().length === 0) {
|
|
1348
|
+
throw new Error("No browser contexts found in the connected browser");
|
|
1349
|
+
}
|
|
1350
|
+
const context2 = browser.contexts()[0];
|
|
1351
|
+
let page2 = context2.pages().at(0) ?? await context2.newPage();
|
|
1352
|
+
const targetId = options.cdpTargetId;
|
|
1353
|
+
if (targetId) {
|
|
1354
|
+
for (const p of context2.pages()) {
|
|
1355
|
+
let cdp = null;
|
|
1356
|
+
try {
|
|
1357
|
+
cdp = await context2.newCDPSession(p);
|
|
1358
|
+
const result = await cdp.send("Target.getTargetInfo");
|
|
1359
|
+
if (result.targetInfo.targetId === targetId) {
|
|
1360
|
+
page2 = p;
|
|
1361
|
+
break;
|
|
1362
|
+
}
|
|
1363
|
+
} catch (error) {
|
|
1364
|
+
} finally {
|
|
1365
|
+
await cdp?.detach();
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
return { page: page2, context: context2 };
|
|
1370
|
+
}
|
|
1371
|
+
const { headless, appModeInitialUrl, cdpPort, proxy, downloadsPath } = options;
|
|
1372
|
+
let { executablePath } = options;
|
|
1373
|
+
const defaultArgsToIgnore = [
|
|
1374
|
+
"--disable-extensions",
|
|
1375
|
+
"--disable-component-extensions-with-background-pages",
|
|
1376
|
+
"--disable-background-networking",
|
|
1377
|
+
"--disable-backgrounding-occluded-windows",
|
|
1378
|
+
"--disable-background-timer-throttling"
|
|
1379
|
+
];
|
|
1380
|
+
const extraArgs = [];
|
|
1381
|
+
const userDataDir = await createUserDirWithPreferences();
|
|
1382
|
+
if (isIntunedExtensionLoaded()) {
|
|
1383
|
+
const extensionsList = buildExtensionsList();
|
|
1384
|
+
const extensions = extensionsList.join(",");
|
|
1385
|
+
extraArgs.push(`--disable-extensions-except=${extensions}`);
|
|
1386
|
+
extraArgs.push(`--load-extension=${extensions}`);
|
|
1387
|
+
}
|
|
1388
|
+
if (await isIntunedExtensionEnabled()) {
|
|
1389
|
+
await setupIntunedExtension();
|
|
1390
|
+
if (proxy) {
|
|
1391
|
+
extraArgs.push('--proxy-bypass-list="<-loopback>"');
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
if (cdpPort) {
|
|
1395
|
+
extraArgs.push(`--remote-debugging-port=${cdpPort}`);
|
|
1396
|
+
}
|
|
1397
|
+
if (headless) {
|
|
1398
|
+
defaultArgsToIgnore.push("--headless=old");
|
|
1399
|
+
extraArgs.push("--headless=new");
|
|
1400
|
+
}
|
|
1401
|
+
if (appModeInitialUrl) {
|
|
1402
|
+
extraArgs.push(`--app=${appModeInitialUrl}`);
|
|
1403
|
+
}
|
|
1404
|
+
if (executablePath) {
|
|
1405
|
+
executablePath = await fs2.realpath(executablePath);
|
|
1406
|
+
if (!await fs2.exists(executablePath)) {
|
|
1407
|
+
console.log(
|
|
1408
|
+
`Warning: Executable path ${executablePath} does not exist. Falling back to default.`
|
|
1409
|
+
);
|
|
1410
|
+
executablePath = void 0;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
const viewport = null;
|
|
1414
|
+
const userAgent = process.env.__PLAYWRIGHT_USER_AGENT_OVERRIDE ?? await getHeadlessUserAgent({
|
|
1415
|
+
executablePath
|
|
1416
|
+
});
|
|
1417
|
+
const context = await playwright.chromium.launchPersistentContext(
|
|
1418
|
+
userDataDir,
|
|
1419
|
+
{
|
|
1420
|
+
userAgent,
|
|
1421
|
+
executablePath,
|
|
1422
|
+
headless,
|
|
1423
|
+
viewport,
|
|
1424
|
+
proxy,
|
|
1425
|
+
downloadsPath,
|
|
1426
|
+
args: extraArgs,
|
|
1427
|
+
ignoreDefaultArgs: defaultArgsToIgnore
|
|
1428
|
+
}
|
|
1429
|
+
);
|
|
1430
|
+
context.once("close", async () => {
|
|
1431
|
+
try {
|
|
1432
|
+
await (0, import_fs_extra2.rm)(userDataDir, {
|
|
1433
|
+
recursive: true,
|
|
1434
|
+
force: true,
|
|
1435
|
+
retryDelay: 1e3,
|
|
1436
|
+
maxRetries: 5
|
|
1437
|
+
});
|
|
1438
|
+
if (await isIntunedExtensionEnabled()) {
|
|
1439
|
+
await cleanIntunedExtensionServer();
|
|
1440
|
+
}
|
|
1441
|
+
} catch (error) {
|
|
1442
|
+
console.error("Failed to remove user data dir", error);
|
|
1443
|
+
}
|
|
1444
|
+
});
|
|
1445
|
+
if (cdpPort) {
|
|
1446
|
+
const createdCdpAddress = getLocalCdpAddress(cdpPort);
|
|
1447
|
+
await waitOnCdpAddress(createdCdpAddress);
|
|
1448
|
+
}
|
|
1449
|
+
const page = context.pages().at(0) ?? await context.newPage();
|
|
1450
|
+
if (await isIntunedExtensionEnabled()) {
|
|
1451
|
+
await getIntunedExtensionWorker(context);
|
|
1452
|
+
}
|
|
1453
|
+
return {
|
|
1454
|
+
page,
|
|
1455
|
+
context
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
async function getBrowserExecutablePath() {
|
|
1459
|
+
const browserType = getBrowserType();
|
|
1460
|
+
if (browserType === "brave") {
|
|
1461
|
+
return await getBraveExecutablePath();
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
async function launchBrowser(options) {
|
|
1465
|
+
if ("cdpAddress" in options) {
|
|
1466
|
+
return launchChromium(options);
|
|
1467
|
+
}
|
|
1468
|
+
return launchChromium({
|
|
1469
|
+
...options,
|
|
1470
|
+
executablePath: await getBrowserExecutablePath()
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
function getBrowserType() {
|
|
1474
|
+
if (process.env.BROWSER_TYPE === "brave") {
|
|
1475
|
+
return "brave";
|
|
1476
|
+
}
|
|
1477
|
+
return "chromium";
|
|
1478
|
+
}
|
|
1479
|
+
async function getBraveExecutablePath() {
|
|
1480
|
+
const { stdout } = await execAsync("which brave-browser-stable");
|
|
1481
|
+
const bravePath = stdout.trim();
|
|
1482
|
+
if (bravePath.length === 0) {
|
|
1483
|
+
throw new Error("Brave browser not found");
|
|
1484
|
+
}
|
|
1485
|
+
return bravePath;
|
|
1486
|
+
}
|
|
1487
|
+
function getLocalCdpAddress(port) {
|
|
1488
|
+
return `http://localhost:${port}`;
|
|
1489
|
+
}
|
|
1490
|
+
async function getCdpWebSocketUrl(cdpAddress) {
|
|
1491
|
+
let response;
|
|
1492
|
+
try {
|
|
1493
|
+
response = await fetch(`${cdpAddress}/json/version`);
|
|
1494
|
+
} catch (error) {
|
|
1495
|
+
return (0, import_neverthrow4.err)(
|
|
1496
|
+
`Failed to fetch CDP version from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`
|
|
1497
|
+
);
|
|
1498
|
+
}
|
|
1499
|
+
if (!response.ok) {
|
|
1500
|
+
return (0, import_neverthrow4.err)(
|
|
1501
|
+
`Failed to get CDP WebSocket URL from ${cdpAddress}: ${response.status} ${response.statusText}`
|
|
1502
|
+
);
|
|
1503
|
+
}
|
|
1504
|
+
let data;
|
|
1505
|
+
try {
|
|
1506
|
+
data = await response.json();
|
|
1507
|
+
} catch (error) {
|
|
1508
|
+
return (0, import_neverthrow4.err)(
|
|
1509
|
+
`Invalid CDP version response from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
const cdpJsonVersionResponseSchema = import_zod3.z.object({
|
|
1513
|
+
webSocketDebuggerUrl: import_zod3.z.string().url()
|
|
1514
|
+
});
|
|
1515
|
+
const parseResult = cdpJsonVersionResponseSchema.safeParse(data);
|
|
1516
|
+
if (!parseResult.success) {
|
|
1517
|
+
return (0, import_neverthrow4.err)(
|
|
1518
|
+
`Invalid CDP version response from ${cdpAddress}: ${JSON.stringify(
|
|
1519
|
+
parseResult.error.format()
|
|
1520
|
+
)}`
|
|
1521
|
+
);
|
|
1522
|
+
}
|
|
1523
|
+
return (0, import_neverthrow4.ok)(parseResult.data.webSocketDebuggerUrl);
|
|
1524
|
+
}
|
|
1525
|
+
async function waitOnCdpAddress(cdpAddress) {
|
|
1526
|
+
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
1527
|
+
await (0, import_wait_on.default)({
|
|
1528
|
+
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
1529
|
+
delay: 100,
|
|
1530
|
+
interval: 100,
|
|
1531
|
+
timeout: 5e3,
|
|
1532
|
+
tcpTimeout: 1e3,
|
|
1533
|
+
window: 1e3
|
|
1534
|
+
});
|
|
1535
|
+
}
|
|
1536
|
+
async function getHeadlessUserAgent({
|
|
1537
|
+
executablePath,
|
|
1538
|
+
args,
|
|
1539
|
+
ignoreDefaultArgs
|
|
1540
|
+
}) {
|
|
1541
|
+
const browser = await playwright.chromium.launch({
|
|
1542
|
+
headless: true,
|
|
1543
|
+
executablePath,
|
|
1544
|
+
args,
|
|
1545
|
+
ignoreDefaultArgs
|
|
1546
|
+
});
|
|
1547
|
+
const context = await browser.newContext();
|
|
1548
|
+
const page = await context.newPage();
|
|
1549
|
+
let userAgent = await page.evaluate(() => navigator.userAgent);
|
|
1550
|
+
await browser.close();
|
|
1551
|
+
if (!userAgent || typeof userAgent !== "string") {
|
|
1552
|
+
return void 0;
|
|
1553
|
+
}
|
|
1554
|
+
userAgent = userAgent.replace("HeadlessChrome", "Chrome");
|
|
1555
|
+
return userAgent;
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// src/common/playwrightContext.ts
|
|
1559
|
+
var import_runtime_interface3 = __toESM(require_dist());
|
|
1560
|
+
var browserScriptsFile = import_path3.default.join(
|
|
1561
|
+
__dirname,
|
|
1562
|
+
"./assets/browser_scripts.js"
|
|
1563
|
+
);
|
|
1564
|
+
async function withPlaywrightContext({
|
|
1565
|
+
cdpAddress,
|
|
1566
|
+
cdpTargetId,
|
|
1567
|
+
proxy,
|
|
1568
|
+
headless = true,
|
|
1569
|
+
downloadsPath,
|
|
1570
|
+
importFunction,
|
|
1571
|
+
apiName,
|
|
1572
|
+
apiParameters
|
|
1573
|
+
}, fn) {
|
|
1574
|
+
let context;
|
|
1575
|
+
let page;
|
|
1576
|
+
try {
|
|
1577
|
+
const setupContextHookResult = importFunction ? await loadSetupContextHook({
|
|
1578
|
+
importFunction
|
|
1579
|
+
}) : (0, import_neverthrow5.ok)(null);
|
|
1580
|
+
if (setupContextHookResult.isErr()) {
|
|
1581
|
+
return setupContextHookResult;
|
|
1582
|
+
}
|
|
1583
|
+
const setupContextHook = setupContextHookResult.value;
|
|
1584
|
+
if (setupContextHook === null) {
|
|
1585
|
+
if (cdpAddress !== void 0) {
|
|
1586
|
+
({ page, context } = await launchBrowser({ cdpAddress, cdpTargetId }));
|
|
1587
|
+
} else {
|
|
1588
|
+
({ page, context } = await launchBrowser({
|
|
1589
|
+
proxy,
|
|
1590
|
+
headless,
|
|
1591
|
+
downloadsPath
|
|
1592
|
+
}));
|
|
1593
|
+
}
|
|
1594
|
+
return await fn(context, page);
|
|
1595
|
+
}
|
|
1596
|
+
let hookCdpUrl = null;
|
|
1597
|
+
if (cdpAddress) {
|
|
1598
|
+
hookCdpUrl = cdpAddress;
|
|
1599
|
+
({ context, page } = await launchBrowser({ cdpAddress, cdpTargetId }));
|
|
1600
|
+
} else {
|
|
1601
|
+
const port = await (0, import_portfinder2.getPort)({
|
|
1602
|
+
port: 9222
|
|
1603
|
+
});
|
|
1604
|
+
({ context, page } = await launchBrowser({
|
|
1605
|
+
proxy,
|
|
1606
|
+
headless,
|
|
1607
|
+
downloadsPath,
|
|
1608
|
+
cdpPort: port
|
|
1609
|
+
}));
|
|
1610
|
+
hookCdpUrl = getLocalCdpAddress(port);
|
|
1611
|
+
}
|
|
1612
|
+
let hookResult;
|
|
1613
|
+
try {
|
|
1614
|
+
const wsUrlResult = await getCdpWebSocketUrl(hookCdpUrl);
|
|
1615
|
+
if (wsUrlResult.isOk()) {
|
|
1616
|
+
hookCdpUrl = wsUrlResult.value;
|
|
1617
|
+
} else {
|
|
1618
|
+
throw new Error(wsUrlResult.error);
|
|
1619
|
+
}
|
|
1620
|
+
hookResult = await setupContextHook({
|
|
1621
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1622
|
+
apiName,
|
|
1623
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1624
|
+
apiParameters,
|
|
1625
|
+
cdpUrl: hookCdpUrl
|
|
1626
|
+
});
|
|
1627
|
+
} catch (error) {
|
|
1628
|
+
return (0, import_neverthrow5.err)(new import_runtime_interface3.AutomationError(error));
|
|
1629
|
+
}
|
|
1630
|
+
if (!hookResult) {
|
|
1631
|
+
return await fn(context, page);
|
|
1632
|
+
}
|
|
1633
|
+
const { page: newPage, context: newContext, cleanup } = hookResult;
|
|
1634
|
+
let result;
|
|
1635
|
+
try {
|
|
1636
|
+
result = { return: await fn(newContext, newPage ?? page) };
|
|
1637
|
+
} catch (e) {
|
|
1638
|
+
result = { throw: e };
|
|
1639
|
+
}
|
|
1640
|
+
try {
|
|
1641
|
+
await cleanup?.();
|
|
1642
|
+
} catch (e) {
|
|
1643
|
+
result = { return: (0, import_neverthrow5.err)(new import_runtime_interface3.AutomationError(e)) };
|
|
1644
|
+
}
|
|
1645
|
+
if ("throw" in result) {
|
|
1646
|
+
throw result.throw;
|
|
1647
|
+
}
|
|
1648
|
+
return result.return;
|
|
1649
|
+
} finally {
|
|
1650
|
+
await context?.close();
|
|
1651
|
+
}
|
|
1652
|
+
}
|
|
1653
|
+
async function loadSessionToContext({
|
|
1654
|
+
context,
|
|
1655
|
+
session
|
|
1656
|
+
}) {
|
|
1657
|
+
let sessionToLoad;
|
|
1658
|
+
if (session.type === "state") {
|
|
1659
|
+
const state = session.state;
|
|
1660
|
+
if (state === void 0 || state === null) {
|
|
1661
|
+
return;
|
|
1662
|
+
}
|
|
1663
|
+
sessionToLoad = state;
|
|
1664
|
+
} else {
|
|
1665
|
+
const fullPath = getFullPathInProject(session.path);
|
|
1666
|
+
sessionToLoad = await fs3.readJson(fullPath);
|
|
1667
|
+
}
|
|
1668
|
+
await setStorageState(context, sessionToLoad);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
// src/common/formatZodError.ts
|
|
1672
|
+
function formatZodError(zodError) {
|
|
1673
|
+
const formattedErrors = zodError.errors.map((error) => {
|
|
1674
|
+
const path4 = error.path.map((segment) => {
|
|
1675
|
+
return typeof segment === "number" ? `[${segment}]` : segment;
|
|
1676
|
+
}).join(".");
|
|
1677
|
+
if (path4) {
|
|
1678
|
+
return `${path4} is invalid - ${error.message}`;
|
|
1679
|
+
}
|
|
1680
|
+
return error.message;
|
|
1681
|
+
});
|
|
1682
|
+
return formattedErrors;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
// src/common/cleanEnvironmentVariables.ts
|
|
1686
|
+
function cleanEnvironmentVariables() {
|
|
1687
|
+
Object.keys(process.env).filter((i) => {
|
|
1688
|
+
if (i.toLocaleLowerCase().startsWith("npm")) {
|
|
1689
|
+
return true;
|
|
1690
|
+
}
|
|
1691
|
+
if (i.toLocaleLowerCase().startsWith("fly") && i !== "FLY_ALLOC_ID") {
|
|
1692
|
+
return true;
|
|
1693
|
+
}
|
|
1694
|
+
}).forEach((i) => delete process.env[i]);
|
|
1695
|
+
}
|
|
1696
|
+
|
|
1697
|
+
// src/common/runApi/index.ts
|
|
1698
|
+
var import_runtime_interface4 = __toESM(require_dist());
|
|
49
1699
|
function getObjectSizeInBytes(obj) {
|
|
50
1700
|
try {
|
|
51
1701
|
return new TextEncoder().encode(JSON.stringify(obj)).length;
|
|
@@ -60,39 +1710,41 @@ async function runApi({
|
|
|
60
1710
|
...input
|
|
61
1711
|
}) {
|
|
62
1712
|
let traceStarted = false;
|
|
63
|
-
const inputParseResult =
|
|
1713
|
+
const inputParseResult = import_runtime_interface4.runApiParametersSchema.safeParse(input);
|
|
64
1714
|
if (!inputParseResult.success) {
|
|
65
|
-
return (0,
|
|
1715
|
+
return (0, import_neverthrow6.err)(
|
|
1716
|
+
new import_runtime_interface4.InternalInvalidInputError(
|
|
1717
|
+
"Input validation failed",
|
|
1718
|
+
formatZodError(inputParseResult.error)
|
|
1719
|
+
)
|
|
1720
|
+
);
|
|
66
1721
|
}
|
|
67
1722
|
const {
|
|
68
|
-
automationFunction: {
|
|
69
|
-
name,
|
|
70
|
-
params
|
|
71
|
-
},
|
|
1723
|
+
automationFunction: { name, params },
|
|
72
1724
|
runOptions,
|
|
73
1725
|
tracing,
|
|
74
1726
|
auth
|
|
75
1727
|
} = inputParseResult.data;
|
|
76
|
-
const abortSymbol = Symbol("abort");
|
|
77
|
-
const abortPromise = new Promise(
|
|
1728
|
+
const abortSymbol = /* @__PURE__ */ Symbol("abort");
|
|
1729
|
+
const abortPromise = new Promise((resolve2) => {
|
|
78
1730
|
if (!abortSignal) return;
|
|
79
1731
|
abortSignal.addEventListener("abort", () => {
|
|
80
|
-
|
|
1732
|
+
resolve2(abortSymbol);
|
|
81
1733
|
});
|
|
82
1734
|
});
|
|
83
1735
|
async function runAutomation() {
|
|
84
|
-
const validatedModuleResult = await
|
|
1736
|
+
const validatedModuleResult = await importUsingImportFunction({
|
|
85
1737
|
path: name,
|
|
86
1738
|
importFunction
|
|
87
1739
|
});
|
|
88
1740
|
if (validatedModuleResult.isErr()) {
|
|
89
|
-
return (0,
|
|
1741
|
+
return (0, import_neverthrow6.err)(validatedModuleResult.error);
|
|
90
1742
|
}
|
|
91
1743
|
const automationFunction = validatedModuleResult.value;
|
|
92
1744
|
if (auth && auth.session.type === "state") {
|
|
93
1745
|
const state = auth.session.state;
|
|
94
|
-
if (state ===
|
|
95
|
-
return (0,
|
|
1746
|
+
if (state === void 0 || state === null) {
|
|
1747
|
+
return (0, import_neverthrow6.err)(new import_runtime_interface4.AuthRequiredError());
|
|
96
1748
|
}
|
|
97
1749
|
}
|
|
98
1750
|
const playwrightContextParameters = {
|
|
@@ -100,7 +1752,7 @@ async function runApi({
|
|
|
100
1752
|
apiParameters: params,
|
|
101
1753
|
importFunction
|
|
102
1754
|
};
|
|
103
|
-
const intunedContext =
|
|
1755
|
+
const intunedContext = getExecutionContext();
|
|
104
1756
|
const runAutomationWithContext = async (context, page) => {
|
|
105
1757
|
async function saveTraceIfNeeded({
|
|
106
1758
|
errorMessage
|
|
@@ -109,26 +1761,27 @@ async function runApi({
|
|
|
109
1761
|
return;
|
|
110
1762
|
}
|
|
111
1763
|
try {
|
|
112
|
-
await context?.tracing.stop({
|
|
113
|
-
path: tracing.filePath
|
|
114
|
-
});
|
|
1764
|
+
await context?.tracing.stop({ path: tracing.filePath });
|
|
115
1765
|
} catch (error) {
|
|
116
1766
|
console.log(errorMessage, error?.message);
|
|
117
|
-
await (0,
|
|
1767
|
+
await (0, import_fs_extra3.remove)(tracing.filePath);
|
|
118
1768
|
}
|
|
119
1769
|
}
|
|
120
1770
|
if (auth) {
|
|
121
|
-
await
|
|
1771
|
+
await loadSessionToContext({
|
|
122
1772
|
context,
|
|
123
1773
|
session: auth.session
|
|
124
1774
|
});
|
|
1775
|
+
if (intunedContext && auth.parameters) {
|
|
1776
|
+
intunedContext.getAuthSessionParameters = async () => auth.parameters;
|
|
1777
|
+
}
|
|
125
1778
|
}
|
|
126
|
-
const scriptContent = await
|
|
1779
|
+
const scriptContent = await fs4.readFile(browserScriptsFile, "utf-8");
|
|
127
1780
|
await context.addInitScript({
|
|
128
1781
|
content: scriptContent
|
|
129
1782
|
});
|
|
130
|
-
for (const
|
|
131
|
-
await
|
|
1783
|
+
for (const page2 of context.pages()) {
|
|
1784
|
+
await page2.evaluate(scriptContent);
|
|
132
1785
|
}
|
|
133
1786
|
if (tracing.enabled) {
|
|
134
1787
|
await context.tracing.start({
|
|
@@ -138,66 +1791,96 @@ async function runApi({
|
|
|
138
1791
|
});
|
|
139
1792
|
traceStarted = true;
|
|
140
1793
|
}
|
|
141
|
-
|
|
142
|
-
const automationFunctionParameters = [
|
|
1794
|
+
cleanEnvironmentVariables();
|
|
1795
|
+
const automationFunctionParameters = [
|
|
1796
|
+
...params !== void 0 ? [params] : [],
|
|
1797
|
+
page,
|
|
1798
|
+
context
|
|
1799
|
+
];
|
|
143
1800
|
try {
|
|
144
|
-
const [automationFunctionResult] = await Promise.all([
|
|
1801
|
+
const [automationFunctionResult] = await Promise.all([
|
|
1802
|
+
automationFunction(...automationFunctionParameters)
|
|
1803
|
+
]);
|
|
145
1804
|
const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
|
|
146
|
-
const resultSizeInBytes = getObjectSizeInBytes(
|
|
1805
|
+
const resultSizeInBytes = getObjectSizeInBytes(
|
|
1806
|
+
automationFunctionResult
|
|
1807
|
+
);
|
|
147
1808
|
if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
|
|
148
|
-
return (0,
|
|
1809
|
+
return (0, import_neverthrow6.err)(
|
|
1810
|
+
new import_runtime_interface4.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES)
|
|
1811
|
+
);
|
|
1812
|
+
}
|
|
1813
|
+
if (retrieveSession) {
|
|
1814
|
+
return (0, import_neverthrow6.ok)({
|
|
1815
|
+
result: automationFunctionResult,
|
|
1816
|
+
extendedPayloads: intunedContext?.extendedPayloads,
|
|
1817
|
+
session: await getStorageState(context)
|
|
1818
|
+
});
|
|
149
1819
|
}
|
|
150
|
-
return (0,
|
|
1820
|
+
return (0, import_neverthrow6.ok)({
|
|
151
1821
|
result: automationFunctionResult,
|
|
152
|
-
extendedPayloads: intunedContext?.extendedPayloads
|
|
153
|
-
session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
|
|
1822
|
+
extendedPayloads: intunedContext?.extendedPayloads
|
|
154
1823
|
});
|
|
155
1824
|
} catch (error) {
|
|
156
|
-
return (0,
|
|
1825
|
+
return (0, import_neverthrow6.err)(new import_runtime_interface4.AutomationError(error));
|
|
157
1826
|
} finally {
|
|
158
|
-
await saveTraceIfNeeded({
|
|
159
|
-
errorMessage: "failed to save trace"
|
|
160
|
-
});
|
|
1827
|
+
await saveTraceIfNeeded({ errorMessage: "failed to save trace" });
|
|
161
1828
|
}
|
|
162
1829
|
};
|
|
163
1830
|
if (intunedContext?.store) {
|
|
164
1831
|
intunedContext.store = {};
|
|
165
1832
|
}
|
|
166
1833
|
if (runOptions.environment === "standalone") {
|
|
167
|
-
const downloadsPath =
|
|
1834
|
+
const downloadsPath = getDownloadDirectoryPath();
|
|
168
1835
|
try {
|
|
169
|
-
return await
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
1836
|
+
return await withPlaywrightContext(
|
|
1837
|
+
{
|
|
1838
|
+
headless: runOptions.headless,
|
|
1839
|
+
proxy: runOptions.proxy,
|
|
1840
|
+
downloadsPath,
|
|
1841
|
+
...playwrightContextParameters
|
|
1842
|
+
},
|
|
1843
|
+
runAutomationWithContext
|
|
1844
|
+
);
|
|
175
1845
|
} finally {
|
|
176
|
-
await
|
|
1846
|
+
await fs4.remove(downloadsPath);
|
|
177
1847
|
}
|
|
178
1848
|
} else {
|
|
179
|
-
return await
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
1849
|
+
return await withPlaywrightContext(
|
|
1850
|
+
{
|
|
1851
|
+
cdpAddress: runOptions.cdpAddress,
|
|
1852
|
+
cdpTargetId: runOptions.cdpTargetId,
|
|
1853
|
+
...playwrightContextParameters
|
|
1854
|
+
},
|
|
1855
|
+
runAutomationWithContext
|
|
1856
|
+
);
|
|
183
1857
|
}
|
|
184
1858
|
}
|
|
185
1859
|
const result = await Promise.race([await runAutomation(), abortPromise]);
|
|
186
1860
|
if (result === abortSymbol) {
|
|
187
|
-
return (0,
|
|
1861
|
+
return (0, import_neverthrow6.err)(new import_runtime_interface4.AbortedError());
|
|
188
1862
|
}
|
|
189
1863
|
return result;
|
|
190
1864
|
}
|
|
191
1865
|
async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
|
|
192
1866
|
if (retries === 0) {
|
|
193
|
-
return (0,
|
|
1867
|
+
return (0, import_neverthrow6.ok)(false);
|
|
194
1868
|
}
|
|
195
1869
|
let tryNumber = 0;
|
|
196
|
-
console.log(
|
|
1870
|
+
console.log(
|
|
1871
|
+
"Checking AuthSession with retries",
|
|
1872
|
+
`${AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
1873
|
+
);
|
|
197
1874
|
while (retries > tryNumber) {
|
|
198
1875
|
const result = await checkFn(page, context);
|
|
199
|
-
if (result) return (0,
|
|
1876
|
+
if (result) return (0, import_neverthrow6.ok)(true);
|
|
200
1877
|
tryNumber++;
|
|
201
1878
|
}
|
|
202
|
-
return (0,
|
|
203
|
-
}
|
|
1879
|
+
return (0, import_neverthrow6.ok)(false);
|
|
1880
|
+
}
|
|
1881
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1882
|
+
0 && (module.exports = {
|
|
1883
|
+
checkAuthSessionWithRetries,
|
|
1884
|
+
runApi
|
|
1885
|
+
});
|
|
1886
|
+
//# sourceMappingURL=index.js.map
|