@intuned/runtime 1.3.18-interface.7 → 1.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +27 -0
- package/.claude/settings.local.json +7 -0
- package/.eslintignore +10 -0
- package/.eslintrc.js +39 -0
- package/InterfaceTemplate/__utils.ts +63 -0
- package/InterfaceTemplate/index.playwright.ts +6 -0
- package/dist/commands/api/run.d.ts +6 -0
- package/dist/commands/api/run.js +119 -0
- package/dist/commands/auth-sessions/load.d.ts +2 -0
- package/dist/commands/auth-sessions/load.js +35 -0
- package/dist/commands/auth-sessions/run-check.d.ts +2 -0
- package/dist/commands/auth-sessions/run-check.js +74 -0
- package/dist/commands/auth-sessions/run-create.d.ts +2 -0
- package/dist/commands/auth-sessions/run-create.js +78 -0
- package/dist/commands/browser/save-state.d.ts +2 -0
- package/dist/commands/browser/save-state.js +17 -0
- package/dist/commands/browser/start-browser.d.ts +2 -0
- package/dist/commands/browser/start-browser.js +14 -0
- package/dist/commands/build.d.ts +1 -0
- package/dist/commands/build.js +83 -0
- package/dist/commands/common/browserUtils.d.ts +14 -0
- package/dist/commands/common/browserUtils.js +57 -0
- package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
- package/dist/commands/common/getFirstLineNumber.js +101 -0
- package/dist/commands/common/getFirstLineNumber.test.js +227 -0
- package/dist/commands/common/projectExclusions.d.ts +2 -0
- package/dist/commands/common/projectExclusions.js +8 -0
- package/dist/commands/common/sendMessageToClient.d.ts +1 -0
- package/dist/commands/common/sendMessageToClient.js +10 -0
- package/dist/commands/common/tsNodeImport.d.ts +2 -0
- package/dist/commands/common/tsNodeImport.js +42 -0
- package/dist/commands/common/utils/fileUtils.d.ts +6 -0
- package/dist/commands/common/utils/fileUtils.js +32 -0
- package/dist/commands/common/utils/interfaceClient.d.ts +31 -0
- package/dist/commands/common/utils/interfaceClient.js +98 -0
- package/dist/commands/common/utils/settings.d.ts +2 -0
- package/dist/commands/common/utils/settings.js +31 -0
- package/dist/commands/common/utils/template.d.ts +2 -0
- package/dist/commands/common/utils/template.js +30 -0
- package/dist/commands/get-headless-user-agent.d.ts +1 -0
- package/dist/commands/get-headless-user-agent.js +18 -0
- package/dist/commands/interface/run.d.ts +1 -3
- package/dist/commands/interface/run.js +139 -2047
- package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
- package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +30 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +19 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +24 -0
- package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
- package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/authsession_record.command.js +32 -0
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +16 -0
- package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/build.command.js +12 -0
- package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
- package/dist/commands/intuned-cli/commands/command.js +9 -0
- package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/deploy.command.js +42 -0
- package/dist/commands/intuned-cli/commands/index.d.ts +18 -0
- package/dist/commands/intuned-cli/commands/index.js +203 -0
- package/dist/commands/intuned-cli/commands/provision.command.d.ts +13 -0
- package/dist/commands/intuned-cli/commands/provision.command.js +50 -0
- package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run.command.js +8 -0
- package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_api.command.js +46 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +35 -0
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +17 -0
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +35 -0
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +35 -0
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +33 -0
- package/dist/commands/intuned-cli/commands/types.d.ts +39 -0
- package/dist/commands/intuned-cli/commands/types.js +33 -0
- package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
- package/dist/commands/intuned-cli/constants/index.js +25 -0
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +399 -0
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +1061 -0
- package/dist/commands/intuned-cli/controller/api.d.ts +42 -0
- package/dist/commands/intuned-cli/controller/api.js +194 -0
- package/dist/commands/intuned-cli/controller/authSession.d.ts +209 -0
- package/dist/commands/intuned-cli/controller/authSession.js +425 -0
- package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/build.js +35 -0
- package/dist/commands/intuned-cli/controller/deploy.d.ts +5 -0
- package/dist/commands/intuned-cli/controller/deploy.js +317 -0
- package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/index.js +45 -0
- package/dist/commands/intuned-cli/controller/provision.d.ts +21 -0
- package/dist/commands/intuned-cli/controller/provision.js +299 -0
- package/dist/commands/intuned-cli/controller/scaffold.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/scaffold.js +77 -0
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +152 -0
- package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +41 -0
- package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/api.js +16 -0
- package/dist/commands/intuned-cli/helpers/auth.d.ts +46 -0
- package/dist/commands/intuned-cli/helpers/auth.js +147 -0
- package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
- package/dist/commands/intuned-cli/helpers/backend.js +35 -0
- package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
- package/dist/commands/intuned-cli/helpers/browser.js +93 -0
- package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/context.js +33 -0
- package/dist/commands/intuned-cli/helpers/errors.d.ts +16 -0
- package/dist/commands/intuned-cli/helpers/errors.js +44 -0
- package/dist/commands/intuned-cli/helpers/index.d.ts +12 -0
- package/dist/commands/intuned-cli/helpers/index.js +137 -0
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +39 -0
- package/dist/commands/intuned-cli/helpers/intunedJson.js +20 -0
- package/dist/commands/intuned-cli/helpers/prompts.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/prompts.js +71 -0
- package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
- package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
- package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
- package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
- package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
- package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
- package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
- package/dist/commands/intuned-cli/helpers/traces.js +32 -0
- package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
- package/dist/commands/intuned-cli/helpers/validation.js +14 -0
- package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
- package/dist/commands/intuned-cli/helpers/wrapper.js +76 -0
- package/dist/commands/intuned-cli/index.d.ts +1 -0
- package/dist/commands/intuned-cli/index.js +16 -0
- package/dist/commands/intuned-cli/main.d.ts +1 -0
- package/dist/commands/intuned-cli/main.js +35 -0
- package/dist/commands/intuned-cli/types.d.ts +70 -0
- package/dist/commands/intuned-cli/types.js +22 -0
- package/dist/commands/ts-check.d.ts +2 -0
- package/dist/commands/ts-check.js +55 -0
- package/dist/common/Logger/Logger/index.d.ts +12 -0
- package/dist/common/Logger/Logger/index.js +60 -0
- package/dist/common/Logger/Logger/types.d.ts +8 -0
- package/dist/common/Logger/Logger/types.js +5 -0
- package/dist/common/Logger/index.d.ts +12 -0
- package/dist/common/Logger/index.js +60 -0
- package/dist/common/Logger/types.d.ts +8 -0
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/asyncLocalStorage/index.d.ts +8 -9
- package/dist/common/asyncLocalStorage/index.js +9 -34
- package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
- package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
- package/dist/common/binStartupScript.d.ts +1 -2
- package/dist/common/binStartupScript.js +10 -127
- package/dist/common/browserTabs.d.ts +72 -0
- package/dist/common/browserTabs.js +74 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +1 -3
- package/dist/common/cleanEnvironmentVariables.js +7 -30
- package/dist/common/constants.d.ts +11 -13
- package/dist/common/constants.js +15 -58
- package/dist/common/contextStorageStateHelpers.d.ts +6 -8
- package/dist/common/contextStorageStateHelpers.js +22 -47
- package/dist/common/extension/extensionsHelpers.d.ts +11 -0
- package/dist/common/extension/extensionsHelpers.js +147 -0
- package/dist/common/extension/intunedExtensionServer.d.ts +24 -0
- package/dist/common/extension/intunedExtensionServer.js +178 -0
- package/dist/common/extension/types.d.ts +219 -0
- package/dist/common/extension/types.js +51 -0
- package/dist/common/formatZodError.d.ts +2 -0
- package/dist/{chunk-NDMVGENG.mjs → common/formatZodError.js} +9 -9
- package/dist/common/intunedJson.d.ts +229 -0
- package/dist/common/intunedJson.js +132 -0
- package/dist/common/jwtTokenManager.d.ts +4 -6
- package/dist/common/jwtTokenManager.js +40 -108
- package/dist/common/launchBrowser.d.ts +34 -0
- package/dist/common/launchBrowser.js +247 -0
- package/dist/common/playwrightContext.d.ts +29 -0
- package/dist/common/playwrightContext.js +148 -0
- package/dist/common/runApi/importUsingImportFunction.d.ts +7 -0
- package/dist/common/runApi/importUsingImportFunction.js +46 -0
- package/dist/common/runApi/index.d.ts +6 -9
- package/dist/common/runApi/index.js +73 -1782
- package/dist/common/settingsSchema.d.ts +6 -9
- package/dist/common/settingsSchema.js +18 -54
- package/dist/common/setupContextHook.d.ts +16 -0
- package/dist/common/setupContextHook.js +22 -0
- package/dist/common/telemetry.d.ts +3 -6
- package/dist/common/telemetry.js +8 -41
- package/dist/index.d.ts +4 -6
- package/dist/index.js +92 -784
- package/dist/runtime/RunError.d.ts +5 -0
- package/dist/runtime/RunError.js +19 -0
- package/dist/runtime/attemptStore.d.ts +2 -0
- package/dist/runtime/attemptStore.js +23 -0
- package/dist/runtime/captcha.d.ts +15 -0
- package/dist/runtime/captcha.js +191 -0
- package/dist/runtime/captcha.test.js +821 -0
- package/dist/runtime/downloadDirectory.d.ts +1 -0
- package/dist/runtime/downloadDirectory.js +19 -0
- package/dist/runtime/enums.d.js +5 -0
- package/dist/runtime/enums.d.ts +11 -0
- package/dist/runtime/enums.js +18 -0
- package/dist/runtime/executionHelpers.test.js +52 -0
- package/dist/runtime/export.d.js +5 -0
- package/dist/runtime/export.d.ts +284 -0
- package/dist/runtime/extendPayload.d.ts +2 -0
- package/dist/runtime/extendPayload.js +21 -0
- package/dist/runtime/extendTimeout.d.ts +1 -0
- package/dist/runtime/extendTimeout.js +23 -0
- package/dist/runtime/getAiGatewayConfig.d.ts +10 -0
- package/dist/runtime/getAiGatewayConfig.js +16 -0
- package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
- package/dist/runtime/getAuthSessionParameters.js +20 -0
- package/dist/runtime/index.d.ts +10 -168
- package/dist/runtime/index.js +88 -779
- package/dist/runtime/persistentStore.d.ts +2 -0
- package/dist/runtime/persistentStore.js +37 -0
- package/dist/runtime/persistentStore.test.js +101 -0
- package/dist/runtime/runInfo.d.ts +2 -0
- package/dist/runtime/runInfo.js +21 -0
- package/dist/vendor/runtime-interface.d.ts +1 -0
- package/dist/vendor/runtime-interface.js +479 -0
- package/package.json +20 -68
- package/template.tsconfig.json +11 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +25 -0
- package/tsup.config.ts +12 -0
- package/typedoc.json +49 -0
- package/dist/chunk-6ZRJOUQS.mjs +0 -16
- package/dist/chunk-6ZRJOUQS.mjs.map +0 -1
- package/dist/chunk-7YL2JUTE.mjs +0 -146
- package/dist/chunk-7YL2JUTE.mjs.map +0 -1
- package/dist/chunk-B3T6RXPC.mjs +0 -794
- package/dist/chunk-B3T6RXPC.mjs.map +0 -1
- package/dist/chunk-FGV5T6SI.mjs +0 -27
- package/dist/chunk-FGV5T6SI.mjs.map +0 -1
- package/dist/chunk-G4PO5RIV.mjs +0 -85
- package/dist/chunk-G4PO5RIV.mjs.map +0 -1
- package/dist/chunk-LZOMFHX3.mjs +0 -38
- package/dist/chunk-LZOMFHX3.mjs.map +0 -1
- package/dist/chunk-NDMVGENG.mjs.map +0 -1
- package/dist/chunk-W4UX6G4X.mjs +0 -17
- package/dist/chunk-W4UX6G4X.mjs.map +0 -1
- package/dist/chunk-XC75QGFG.mjs +0 -1106
- package/dist/chunk-XC75QGFG.mjs.map +0 -1
- package/dist/chunk-XOAZ2MGA.mjs +0 -59
- package/dist/chunk-XOAZ2MGA.mjs.map +0 -1
- package/dist/commands/interface/run.d.mts +0 -3
- package/dist/commands/interface/run.js.map +0 -1
- package/dist/commands/interface/run.mjs +0 -255
- package/dist/commands/interface/run.mjs.map +0 -1
- package/dist/common/asyncLocalStorage/index.d.mts +0 -17
- package/dist/common/asyncLocalStorage/index.js.map +0 -1
- package/dist/common/asyncLocalStorage/index.mjs +0 -12
- package/dist/common/asyncLocalStorage/index.mjs.map +0 -1
- package/dist/common/binStartupScript.d.mts +0 -2
- package/dist/common/binStartupScript.js.map +0 -1
- package/dist/common/binStartupScript.mjs +0 -135
- package/dist/common/binStartupScript.mjs.map +0 -1
- package/dist/common/cleanEnvironmentVariables.d.mts +0 -3
- package/dist/common/cleanEnvironmentVariables.js.map +0 -1
- package/dist/common/cleanEnvironmentVariables.mjs +0 -8
- package/dist/common/cleanEnvironmentVariables.mjs.map +0 -1
- package/dist/common/constants.d.mts +0 -13
- package/dist/common/constants.js.map +0 -1
- package/dist/common/constants.mjs +0 -28
- package/dist/common/constants.mjs.map +0 -1
- package/dist/common/contextStorageStateHelpers.d.mts +0 -24
- package/dist/common/contextStorageStateHelpers.js.map +0 -1
- package/dist/common/contextStorageStateHelpers.mjs +0 -10
- package/dist/common/contextStorageStateHelpers.mjs.map +0 -1
- package/dist/common/jwtTokenManager.d.mts +0 -19
- package/dist/common/jwtTokenManager.js.map +0 -1
- package/dist/common/jwtTokenManager.mjs +0 -11
- package/dist/common/jwtTokenManager.mjs.map +0 -1
- package/dist/common/runApi/index.d.mts +0 -11
- package/dist/common/runApi/index.js.map +0 -1
- package/dist/common/runApi/index.mjs +0 -18
- package/dist/common/runApi/index.mjs.map +0 -1
- package/dist/common/settingsSchema.d.mts +0 -540
- package/dist/common/settingsSchema.js.map +0 -1
- package/dist/common/settingsSchema.mjs +0 -10
- package/dist/common/settingsSchema.mjs.map +0 -1
- package/dist/common/telemetry.d.mts +0 -6
- package/dist/common/telemetry.js.map +0 -1
- package/dist/common/telemetry.mjs +0 -31
- package/dist/common/telemetry.mjs.map +0 -1
- package/dist/export.d-BAUMB-lG.d.mts +0 -140
- package/dist/export.d-BAUMB-lG.d.ts +0 -140
- package/dist/index.d.mts +0 -6
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -47
- package/dist/index.mjs.map +0 -1
- package/dist/runtime/index.d.mts +0 -168
- package/dist/runtime/index.js.map +0 -1
- package/dist/runtime/index.mjs +0 -42
- package/dist/runtime/index.mjs.map +0 -1
- /package/dist/common/assets/{assets/browser_scripts.js → browser_scripts.js} +0 -0
|
@@ -1,1701 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
});
|
|
305
|
-
|
|
306
|
-
// ../packages/runtime-interface/dist/interfaceClient.js
|
|
307
|
-
var require_interfaceClient = __commonJS({
|
|
308
|
-
"../packages/runtime-interface/dist/interfaceClient.js"(exports2) {
|
|
309
|
-
"use strict";
|
|
310
|
-
var __createBinding = exports2 && exports2.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
311
|
-
if (k2 === void 0) k2 = k;
|
|
312
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
313
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
314
|
-
desc = { enumerable: true, get: function() {
|
|
315
|
-
return m[k];
|
|
316
|
-
} };
|
|
317
|
-
}
|
|
318
|
-
Object.defineProperty(o, k2, desc);
|
|
319
|
-
}) : (function(o, m, k, k2) {
|
|
320
|
-
if (k2 === void 0) k2 = k;
|
|
321
|
-
o[k2] = m[k];
|
|
322
|
-
}));
|
|
323
|
-
var __setModuleDefault = exports2 && exports2.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
324
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
325
|
-
}) : function(o, v) {
|
|
326
|
-
o["default"] = v;
|
|
327
|
-
});
|
|
328
|
-
var __importStar = exports2 && exports2.__importStar || function(mod) {
|
|
329
|
-
if (mod && mod.__esModule) return mod;
|
|
330
|
-
var result = {};
|
|
331
|
-
if (mod != null) {
|
|
332
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
333
|
-
}
|
|
334
|
-
__setModuleDefault(result, mod);
|
|
335
|
-
return result;
|
|
336
|
-
};
|
|
337
|
-
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
338
|
-
exports2.JSONLFileClient = exports2.TCPSocketClient = exports2.UnixSocketClient = exports2.SocketClient = void 0;
|
|
339
|
-
var net = __importStar(require("net"));
|
|
340
|
-
var fs5 = __importStar(require("fs-extra"));
|
|
341
|
-
var readline_1 = require("readline");
|
|
342
|
-
var promises_1 = require("timers/promises");
|
|
343
|
-
var SocketClient = class _SocketClient {
|
|
344
|
-
constructor(socket) {
|
|
345
|
-
this.socket = socket;
|
|
346
|
-
}
|
|
347
|
-
sendJSON(data) {
|
|
348
|
-
const dataToSend = JSON.stringify(data);
|
|
349
|
-
const length = Buffer.byteLength(dataToSend);
|
|
350
|
-
const buffer = Buffer.alloc(_SocketClient.LENGTH_HEADER_LENGTH + length);
|
|
351
|
-
buffer.writeUInt32BE(length, 0);
|
|
352
|
-
buffer.write(dataToSend, _SocketClient.LENGTH_HEADER_LENGTH);
|
|
353
|
-
this.socket.write(buffer);
|
|
354
|
-
}
|
|
355
|
-
async *receiveJSON() {
|
|
356
|
-
let buffer = Buffer.alloc(0);
|
|
357
|
-
const endPromise = new Promise((resolve2, reject) => {
|
|
358
|
-
this.socket.once("end", () => {
|
|
359
|
-
resolve2();
|
|
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
|
|
479
|
-
});
|
|
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
|
-
}
|
|
642
|
-
};
|
|
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);
|
|
672
|
-
}
|
|
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"])
|
|
749
|
-
});
|
|
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);
|
|
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
|
|
1109
|
-
});
|
|
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());
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.checkAuthSessionWithRetries = checkAuthSessionWithRetries;
|
|
7
|
+
exports.runApi = runApi;
|
|
8
|
+
var _downloadDirectory = require("../../runtime/downloadDirectory");
|
|
9
|
+
var _asyncLocalStorage = require("../asyncLocalStorage");
|
|
10
|
+
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
11
|
+
var fs = _fsExtra;
|
|
12
|
+
var _neverthrow = require("neverthrow");
|
|
13
|
+
var _constants = require("../constants");
|
|
14
|
+
var _playwrightContext = require("../playwrightContext");
|
|
15
|
+
var _formatZodError = require("../formatZodError");
|
|
16
|
+
var _cleanEnvironmentVariables = require("../cleanEnvironmentVariables");
|
|
17
|
+
var _importUsingImportFunction = require("./importUsingImportFunction");
|
|
18
|
+
var _runtimeInterface = require("../../vendor/runtime-interface");
|
|
19
|
+
var _contextStorageStateHelpers = require("../contextStorageStateHelpers");
|
|
20
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
1699
21
|
function getObjectSizeInBytes(obj) {
|
|
1700
22
|
try {
|
|
1701
23
|
return new TextEncoder().encode(JSON.stringify(obj)).length;
|
|
@@ -1710,41 +32,39 @@ async function runApi({
|
|
|
1710
32
|
...input
|
|
1711
33
|
}) {
|
|
1712
34
|
let traceStarted = false;
|
|
1713
|
-
const inputParseResult =
|
|
35
|
+
const inputParseResult = _runtimeInterface.runApiParametersSchema.safeParse(input);
|
|
1714
36
|
if (!inputParseResult.success) {
|
|
1715
|
-
return (0,
|
|
1716
|
-
new import_runtime_interface4.InternalInvalidInputError(
|
|
1717
|
-
"Input validation failed",
|
|
1718
|
-
formatZodError(inputParseResult.error)
|
|
1719
|
-
)
|
|
1720
|
-
);
|
|
37
|
+
return (0, _neverthrow.err)(new _runtimeInterface.InternalInvalidInputError("Input validation failed", (0, _formatZodError.formatZodError)(inputParseResult.error)));
|
|
1721
38
|
}
|
|
1722
39
|
const {
|
|
1723
|
-
automationFunction: {
|
|
40
|
+
automationFunction: {
|
|
41
|
+
name,
|
|
42
|
+
params
|
|
43
|
+
},
|
|
1724
44
|
runOptions,
|
|
1725
45
|
tracing,
|
|
1726
46
|
auth
|
|
1727
47
|
} = inputParseResult.data;
|
|
1728
|
-
const abortSymbol =
|
|
1729
|
-
const abortPromise = new Promise(
|
|
48
|
+
const abortSymbol = Symbol("abort");
|
|
49
|
+
const abortPromise = new Promise(resolve => {
|
|
1730
50
|
if (!abortSignal) return;
|
|
1731
51
|
abortSignal.addEventListener("abort", () => {
|
|
1732
|
-
|
|
52
|
+
resolve(abortSymbol);
|
|
1733
53
|
});
|
|
1734
54
|
});
|
|
1735
55
|
async function runAutomation() {
|
|
1736
|
-
const validatedModuleResult = await importUsingImportFunction({
|
|
56
|
+
const validatedModuleResult = await (0, _importUsingImportFunction.importUsingImportFunction)({
|
|
1737
57
|
path: name,
|
|
1738
58
|
importFunction
|
|
1739
59
|
});
|
|
1740
60
|
if (validatedModuleResult.isErr()) {
|
|
1741
|
-
return (0,
|
|
61
|
+
return (0, _neverthrow.err)(validatedModuleResult.error);
|
|
1742
62
|
}
|
|
1743
63
|
const automationFunction = validatedModuleResult.value;
|
|
1744
64
|
if (auth && auth.session.type === "state") {
|
|
1745
65
|
const state = auth.session.state;
|
|
1746
|
-
if (state ===
|
|
1747
|
-
return (0,
|
|
66
|
+
if (state === undefined || state === null) {
|
|
67
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AuthRequiredError());
|
|
1748
68
|
}
|
|
1749
69
|
}
|
|
1750
70
|
const playwrightContextParameters = {
|
|
@@ -1752,7 +72,7 @@ async function runApi({
|
|
|
1752
72
|
apiParameters: params,
|
|
1753
73
|
importFunction
|
|
1754
74
|
};
|
|
1755
|
-
const intunedContext = getExecutionContext();
|
|
75
|
+
const intunedContext = (0, _asyncLocalStorage.getExecutionContext)();
|
|
1756
76
|
const runAutomationWithContext = async (context, page) => {
|
|
1757
77
|
async function saveTraceIfNeeded({
|
|
1758
78
|
errorMessage
|
|
@@ -1761,14 +81,16 @@ async function runApi({
|
|
|
1761
81
|
return;
|
|
1762
82
|
}
|
|
1763
83
|
try {
|
|
1764
|
-
await context?.tracing.stop({
|
|
84
|
+
await context?.tracing.stop({
|
|
85
|
+
path: tracing.filePath
|
|
86
|
+
});
|
|
1765
87
|
} catch (error) {
|
|
1766
88
|
console.log(errorMessage, error?.message);
|
|
1767
|
-
await (0,
|
|
89
|
+
await (0, _fsExtra.remove)(tracing.filePath);
|
|
1768
90
|
}
|
|
1769
91
|
}
|
|
1770
92
|
if (auth) {
|
|
1771
|
-
await loadSessionToContext({
|
|
93
|
+
await (0, _playwrightContext.loadSessionToContext)({
|
|
1772
94
|
context,
|
|
1773
95
|
session: auth.session
|
|
1774
96
|
});
|
|
@@ -1776,13 +98,6 @@ async function runApi({
|
|
|
1776
98
|
intunedContext.getAuthSessionParameters = async () => auth.parameters;
|
|
1777
99
|
}
|
|
1778
100
|
}
|
|
1779
|
-
const scriptContent = await fs4.readFile(browserScriptsFile, "utf-8");
|
|
1780
|
-
await context.addInitScript({
|
|
1781
|
-
content: scriptContent
|
|
1782
|
-
});
|
|
1783
|
-
for (const page2 of context.pages()) {
|
|
1784
|
-
await page2.evaluate(scriptContent);
|
|
1785
|
-
}
|
|
1786
101
|
if (tracing.enabled) {
|
|
1787
102
|
await context.tracing.start({
|
|
1788
103
|
screenshots: true,
|
|
@@ -1791,96 +106,72 @@ async function runApi({
|
|
|
1791
106
|
});
|
|
1792
107
|
traceStarted = true;
|
|
1793
108
|
}
|
|
1794
|
-
cleanEnvironmentVariables();
|
|
1795
|
-
const automationFunctionParameters = [
|
|
1796
|
-
...params !== void 0 ? [params] : [],
|
|
1797
|
-
page,
|
|
1798
|
-
context
|
|
1799
|
-
];
|
|
109
|
+
(0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
|
|
110
|
+
const automationFunctionParameters = [...(params !== undefined ? [params] : []), page, context];
|
|
1800
111
|
try {
|
|
1801
|
-
const
|
|
1802
|
-
|
|
1803
|
-
|
|
112
|
+
const automationFunctionResult = await Promise.race([automationFunction(...automationFunctionParameters), abortPromise]);
|
|
113
|
+
if (automationFunctionResult === abortSymbol) {
|
|
114
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AbortedError());
|
|
115
|
+
}
|
|
1804
116
|
const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
|
|
1805
|
-
const resultSizeInBytes = getObjectSizeInBytes(
|
|
1806
|
-
automationFunctionResult
|
|
1807
|
-
);
|
|
117
|
+
const resultSizeInBytes = getObjectSizeInBytes(automationFunctionResult);
|
|
1808
118
|
if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
|
|
1809
|
-
return (0,
|
|
1810
|
-
new import_runtime_interface4.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES)
|
|
1811
|
-
);
|
|
119
|
+
return (0, _neverthrow.err)(new _runtimeInterface.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES));
|
|
1812
120
|
}
|
|
1813
121
|
if (retrieveSession) {
|
|
1814
|
-
return (0,
|
|
122
|
+
return (0, _neverthrow.ok)({
|
|
1815
123
|
result: automationFunctionResult,
|
|
1816
124
|
extendedPayloads: intunedContext?.extendedPayloads,
|
|
1817
|
-
session: await getStorageState(context)
|
|
125
|
+
session: await (0, _contextStorageStateHelpers.getStorageState)(context)
|
|
1818
126
|
});
|
|
1819
127
|
}
|
|
1820
|
-
return (0,
|
|
128
|
+
return (0, _neverthrow.ok)({
|
|
1821
129
|
result: automationFunctionResult,
|
|
1822
130
|
extendedPayloads: intunedContext?.extendedPayloads
|
|
1823
131
|
});
|
|
1824
132
|
} catch (error) {
|
|
1825
|
-
return (0,
|
|
133
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(error));
|
|
1826
134
|
} finally {
|
|
1827
|
-
await saveTraceIfNeeded({
|
|
135
|
+
await saveTraceIfNeeded({
|
|
136
|
+
errorMessage: "failed to save trace"
|
|
137
|
+
});
|
|
1828
138
|
}
|
|
1829
139
|
};
|
|
1830
140
|
if (intunedContext?.store) {
|
|
1831
141
|
intunedContext.store = {};
|
|
1832
142
|
}
|
|
1833
143
|
if (runOptions.environment === "standalone") {
|
|
1834
|
-
const downloadsPath = getDownloadDirectoryPath();
|
|
144
|
+
const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
|
|
1835
145
|
try {
|
|
1836
|
-
return await withPlaywrightContext(
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
},
|
|
1843
|
-
runAutomationWithContext
|
|
1844
|
-
);
|
|
146
|
+
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
147
|
+
headless: runOptions.headless,
|
|
148
|
+
proxy: runOptions.proxy,
|
|
149
|
+
downloadsPath,
|
|
150
|
+
...playwrightContextParameters
|
|
151
|
+
}, runAutomationWithContext);
|
|
1845
152
|
} finally {
|
|
1846
|
-
await
|
|
153
|
+
await fs.remove(downloadsPath);
|
|
1847
154
|
}
|
|
1848
155
|
} else {
|
|
1849
|
-
return await withPlaywrightContext(
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
},
|
|
1855
|
-
runAutomationWithContext
|
|
1856
|
-
);
|
|
156
|
+
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
157
|
+
cdpAddress: runOptions.cdpAddress,
|
|
158
|
+
cdpTargetId: runOptions.cdpTargetId,
|
|
159
|
+
...playwrightContextParameters
|
|
160
|
+
}, runAutomationWithContext);
|
|
1857
161
|
}
|
|
1858
162
|
}
|
|
1859
|
-
|
|
1860
|
-
if (result === abortSymbol) {
|
|
1861
|
-
return (0, import_neverthrow6.err)(new import_runtime_interface4.AbortedError());
|
|
1862
|
-
}
|
|
1863
|
-
return result;
|
|
163
|
+
return await runAutomation();
|
|
1864
164
|
}
|
|
1865
165
|
async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
|
|
1866
166
|
if (retries === 0) {
|
|
1867
|
-
return (0,
|
|
167
|
+
return (0, _neverthrow.ok)(false);
|
|
1868
168
|
}
|
|
1869
169
|
let tryNumber = 0;
|
|
1870
|
-
console.log(
|
|
1871
|
-
"Checking AuthSession with retries",
|
|
1872
|
-
`${AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
1873
|
-
);
|
|
170
|
+
console.log("Checking AuthSession with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
1874
171
|
while (retries > tryNumber) {
|
|
1875
172
|
const result = await checkFn(page, context);
|
|
1876
|
-
if (result) return (0,
|
|
173
|
+
if (result) return (0, _neverthrow.ok)(true);
|
|
1877
174
|
tryNumber++;
|
|
1878
175
|
}
|
|
1879
|
-
return (0,
|
|
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
|
|
176
|
+
return (0, _neverthrow.ok)(false);
|
|
177
|
+
}
|