@intuned/runtime-dev 1.3.18-interface.13 → 1.3.18-interface.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +27 -0
- package/.claude/settings.local.json +7 -0
- package/.eslintignore +10 -0
- package/.eslintrc.js +39 -0
- package/InterfaceTemplate/__utils.ts +3 -1
- package/WebTemplate.zip +0 -0
- package/dist/commands/api/run.d.ts +1 -3
- package/dist/commands/api/run.js +64 -2039
- package/dist/commands/auth-sessions/load.d.ts +1 -0
- package/dist/commands/auth-sessions/load.js +28 -1552
- package/dist/commands/auth-sessions/run-check.d.ts +1 -0
- package/dist/commands/auth-sessions/run-check.js +71 -1961
- package/dist/commands/auth-sessions/run-create.d.ts +1 -0
- package/dist/commands/auth-sessions/run-create.js +65 -1955
- package/dist/commands/browser/save-state.d.ts +1 -0
- package/dist/commands/browser/save-state.js +11 -102
- package/dist/commands/browser/start-browser.d.ts +1 -0
- package/dist/commands/browser/start-browser.js +9 -62
- package/dist/commands/build.d.ts +1 -2
- package/dist/commands/build.js +52 -172
- 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 -5
- package/dist/commands/common/tsNodeImport.js +15 -55
- 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 -2
- package/dist/commands/get-headless-user-agent.js +12 -348
- package/dist/commands/interface/pingPong.d.ts +2 -0
- package/dist/commands/interface/pingPong.js +11 -0
- package/dist/commands/interface/run.d.ts +1 -3
- package/dist/commands/interface/run.js +139 -2034
- package/dist/commands/interface/runApi.d.ts +1 -0
- package/dist/commands/interface/runApi.js +102 -0
- 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 +398 -0
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +1060 -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 -2
- package/dist/commands/intuned-cli/main.js +24 -5392
- 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 +1 -0
- package/dist/commands/ts-check.js +28 -131
- 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 -33
- 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 -126
- 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 -29
- package/dist/common/constants.d.ts +11 -13
- package/dist/common/constants.js +15 -57
- package/dist/common/contextStorageStateHelpers.d.ts +6 -8
- package/dist/common/contextStorageStateHelpers.js +22 -46
- 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/common/formatZodError.js +18 -0
- 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 -107
- 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 +70 -1765
- package/dist/common/settingsSchema.d.ts +6 -9
- package/dist/common/settingsSchema.js +18 -53
- 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 -40
- package/dist/index.d.ts +4 -6
- package/dist/index.js +92 -783
- 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 -778
- 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 +474 -0
- package/package.json +18 -72
- package/template.tsconfig.json +11 -0
- package/tsconfig.eslint.json +5 -0
- package/tsconfig.json +25 -0
- package/tsup.config.ts +11 -0
- package/typedoc.json +49 -0
- package/dist/export.d-BAUMB-lG.d.ts +0 -140
|
@@ -1,1696 +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(path3) {
|
|
402
|
-
super(net.createConnection(path3));
|
|
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(path3, init) {
|
|
648
|
-
return backendFunctionsTokenManager.fetchWithToken(
|
|
649
|
-
`${backendFunctionsTokenManager.backendFunctionsBaseUrl}/${path3}`,
|
|
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 path3 = getIntunedExtensionPath();
|
|
888
|
-
if (!path3) {
|
|
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 path3 = `/tmp/downloads/${context.runId}`;
|
|
1145
|
-
(0, import_fs_extra.ensureDirSync)(path3, {
|
|
1146
|
-
mode: 1533
|
|
1147
|
-
});
|
|
1148
|
-
return path3;
|
|
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 fs3 = __toESM(require("fs-extra"));
|
|
1238
|
-
var import_neverthrow5 = require("neverthrow");
|
|
1239
|
-
|
|
1240
|
-
// src/common/setupContextHook.ts
|
|
1241
|
-
var import_neverthrow3 = require("neverthrow");
|
|
1242
|
-
|
|
1243
|
-
// src/common/runApi/importUsingImportFunction.ts
|
|
1244
|
-
var import_neverthrow2 = require("neverthrow");
|
|
1245
|
-
var import_runtime_interface = __toESM(require_dist());
|
|
1246
|
-
async function importUsingImportFunction({
|
|
1247
|
-
path: path3,
|
|
1248
|
-
allowGenerators = true,
|
|
1249
|
-
importFunction
|
|
1250
|
-
}) {
|
|
1251
|
-
try {
|
|
1252
|
-
const importedResult = await importFunction(path3);
|
|
1253
|
-
if (importedResult.isErr()) {
|
|
1254
|
-
if (importedResult.error.type === "not_found") {
|
|
1255
|
-
return (0, import_neverthrow2.err)(new import_runtime_interface.ApiNotFoundError(path3));
|
|
1256
|
-
}
|
|
1257
|
-
return (0, import_neverthrow2.err)(new import_runtime_interface.AutomationError(importedResult.error.error));
|
|
1258
|
-
}
|
|
1259
|
-
const imported = importedResult.value;
|
|
1260
|
-
if (!imported || !imported.default || !imported.default.constructor) {
|
|
1261
|
-
return (0, import_neverthrow2.err)(new import_runtime_interface.InvalidApiError(`${path3} does not have a default export`));
|
|
1262
|
-
}
|
|
1263
|
-
if (imported.default.constructor.name === "AsyncGeneratorFunction") {
|
|
1264
|
-
if (!allowGenerators) {
|
|
1265
|
-
return (0, import_neverthrow2.err)(
|
|
1266
|
-
new import_runtime_interface.InvalidApiError(
|
|
1267
|
-
`${path3} default export must be an async function`
|
|
1268
|
-
)
|
|
1269
|
-
);
|
|
1270
|
-
}
|
|
1271
|
-
return (0, import_neverthrow2.ok)(async (...args) => {
|
|
1272
|
-
const generator = imported.default(
|
|
1273
|
-
...args
|
|
1274
|
-
);
|
|
1275
|
-
const result = await generator.next();
|
|
1276
|
-
if (!result.done) {
|
|
1277
|
-
throw new Error("Yield is not supported");
|
|
1278
|
-
}
|
|
1279
|
-
return result.value;
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
if (imported.default.constructor.name === "AsyncFunction") {
|
|
1283
|
-
return (0, import_neverthrow2.ok)(imported.default);
|
|
1284
|
-
}
|
|
1285
|
-
return (0, import_neverthrow2.err)(
|
|
1286
|
-
new import_runtime_interface.InvalidApiError(`${path3} default export must be an async function`)
|
|
1287
|
-
);
|
|
1288
|
-
} catch (error) {
|
|
1289
|
-
return (0, import_neverthrow2.err)(new import_runtime_interface.AutomationError(error));
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
// src/common/setupContextHook.ts
|
|
1294
|
-
var import_runtime_interface2 = __toESM(require_dist());
|
|
1295
|
-
var setupContextHookPath = "hooks/setupContext";
|
|
1296
|
-
async function loadSetupContextHook({
|
|
1297
|
-
importFunction
|
|
1298
|
-
}) {
|
|
1299
|
-
const importedFunctionResult = await importUsingImportFunction({
|
|
1300
|
-
path: setupContextHookPath,
|
|
1301
|
-
importFunction
|
|
1302
|
-
});
|
|
1303
|
-
if (importedFunctionResult.isErr() && importedFunctionResult.error instanceof import_runtime_interface2.ApiNotFoundError) {
|
|
1304
|
-
return (0, import_neverthrow3.ok)(null);
|
|
1305
|
-
}
|
|
1306
|
-
return importedFunctionResult;
|
|
1307
|
-
}
|
|
1308
|
-
|
|
1309
|
-
// src/common/playwrightContext.ts
|
|
1310
|
-
var import_portfinder2 = require("portfinder");
|
|
1311
|
-
|
|
1312
|
-
// src/common/launchBrowser.ts
|
|
1313
|
-
var playwright = __toESM(require("playwright"));
|
|
1314
|
-
var import_fs_extra2 = require("fs-extra");
|
|
1315
|
-
var import_path2 = require("path");
|
|
1316
|
-
var fs2 = __toESM(require("fs-extra"));
|
|
1317
|
-
var import_wait_on = __toESM(require("wait-on"));
|
|
1318
|
-
var import_child_process = require("child_process");
|
|
1319
|
-
var import_util = require("util");
|
|
1320
|
-
var import_neverthrow4 = require("neverthrow");
|
|
1321
|
-
var import_zod3 = require("zod");
|
|
1322
|
-
var execAsync = (0, import_util.promisify)(import_child_process.exec);
|
|
1323
|
-
async function createUserDirWithPreferences() {
|
|
1324
|
-
const playwrightTempDir = await (0, import_fs_extra2.mkdtemp)("/tmp/pw-");
|
|
1325
|
-
const userDir = (0, import_path2.join)(playwrightTempDir, "userdir");
|
|
1326
|
-
const defaultDir = (0, import_path2.join)(userDir, "Default");
|
|
1327
|
-
await (0, import_fs_extra2.mkdir)(defaultDir, {
|
|
1328
|
-
recursive: true
|
|
1329
|
-
});
|
|
1330
|
-
const preferences = {
|
|
1331
|
-
plugins: {
|
|
1332
|
-
always_open_pdf_externally: true
|
|
1333
|
-
}
|
|
1334
|
-
};
|
|
1335
|
-
await (0, import_fs_extra2.writeFile)((0, import_path2.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
1336
|
-
return userDir;
|
|
1337
|
-
}
|
|
1338
|
-
async function launchChromium(options) {
|
|
1339
|
-
if ("cdpAddress" in options) {
|
|
1340
|
-
if (await isIntunedExtensionEnabled()) {
|
|
1341
|
-
await setupIntunedExtensionServer();
|
|
1342
|
-
}
|
|
1343
|
-
const browser = await playwright.chromium.connectOverCDP(
|
|
1344
|
-
options.cdpAddress
|
|
1345
|
-
);
|
|
1346
|
-
if (browser.contexts().length === 0) {
|
|
1347
|
-
throw new Error("No browser contexts found in the connected browser");
|
|
1348
|
-
}
|
|
1349
|
-
const context2 = browser.contexts()[0];
|
|
1350
|
-
let page2 = context2.pages().at(0) ?? await context2.newPage();
|
|
1351
|
-
const targetId = options.cdpTargetId;
|
|
1352
|
-
if (targetId) {
|
|
1353
|
-
for (const p of context2.pages()) {
|
|
1354
|
-
let cdp = null;
|
|
1355
|
-
try {
|
|
1356
|
-
cdp = await context2.newCDPSession(p);
|
|
1357
|
-
const result = await cdp.send("Target.getTargetInfo");
|
|
1358
|
-
if (result.targetInfo.targetId === targetId) {
|
|
1359
|
-
page2 = p;
|
|
1360
|
-
break;
|
|
1361
|
-
}
|
|
1362
|
-
} catch (error) {
|
|
1363
|
-
} finally {
|
|
1364
|
-
await cdp?.detach();
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
return { page: page2, context: context2 };
|
|
1369
|
-
}
|
|
1370
|
-
const { headless, appModeInitialUrl, cdpPort, proxy, downloadsPath } = options;
|
|
1371
|
-
let { executablePath } = options;
|
|
1372
|
-
const defaultArgsToIgnore = [
|
|
1373
|
-
"--disable-extensions",
|
|
1374
|
-
"--disable-component-extensions-with-background-pages",
|
|
1375
|
-
"--disable-background-networking",
|
|
1376
|
-
"--disable-backgrounding-occluded-windows",
|
|
1377
|
-
"--disable-background-timer-throttling"
|
|
1378
|
-
];
|
|
1379
|
-
const extraArgs = [];
|
|
1380
|
-
const userDataDir = await createUserDirWithPreferences();
|
|
1381
|
-
if (isIntunedExtensionLoaded()) {
|
|
1382
|
-
const extensionsList = buildExtensionsList();
|
|
1383
|
-
const extensions = extensionsList.join(",");
|
|
1384
|
-
extraArgs.push(`--disable-extensions-except=${extensions}`);
|
|
1385
|
-
extraArgs.push(`--load-extension=${extensions}`);
|
|
1386
|
-
}
|
|
1387
|
-
if (await isIntunedExtensionEnabled()) {
|
|
1388
|
-
await setupIntunedExtension();
|
|
1389
|
-
if (proxy) {
|
|
1390
|
-
extraArgs.push('--proxy-bypass-list="<-loopback>"');
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
if (cdpPort) {
|
|
1394
|
-
extraArgs.push(`--remote-debugging-port=${cdpPort}`);
|
|
1395
|
-
}
|
|
1396
|
-
if (headless) {
|
|
1397
|
-
defaultArgsToIgnore.push("--headless=old");
|
|
1398
|
-
extraArgs.push("--headless=new");
|
|
1399
|
-
}
|
|
1400
|
-
if (appModeInitialUrl) {
|
|
1401
|
-
extraArgs.push(`--app=${appModeInitialUrl}`);
|
|
1402
|
-
}
|
|
1403
|
-
if (executablePath) {
|
|
1404
|
-
executablePath = await fs2.realpath(executablePath);
|
|
1405
|
-
if (!await fs2.exists(executablePath)) {
|
|
1406
|
-
console.log(
|
|
1407
|
-
`Warning: Executable path ${executablePath} does not exist. Falling back to default.`
|
|
1408
|
-
);
|
|
1409
|
-
executablePath = void 0;
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
const viewport = null;
|
|
1413
|
-
const userAgent = process.env.__PLAYWRIGHT_USER_AGENT_OVERRIDE ?? await getHeadlessUserAgent({
|
|
1414
|
-
executablePath
|
|
1415
|
-
});
|
|
1416
|
-
const context = await playwright.chromium.launchPersistentContext(
|
|
1417
|
-
userDataDir,
|
|
1418
|
-
{
|
|
1419
|
-
userAgent,
|
|
1420
|
-
executablePath,
|
|
1421
|
-
headless,
|
|
1422
|
-
viewport,
|
|
1423
|
-
proxy,
|
|
1424
|
-
downloadsPath,
|
|
1425
|
-
args: extraArgs,
|
|
1426
|
-
ignoreDefaultArgs: defaultArgsToIgnore
|
|
1427
|
-
}
|
|
1428
|
-
);
|
|
1429
|
-
context.once("close", async () => {
|
|
1430
|
-
try {
|
|
1431
|
-
await (0, import_fs_extra2.rm)(userDataDir, {
|
|
1432
|
-
recursive: true,
|
|
1433
|
-
force: true,
|
|
1434
|
-
retryDelay: 1e3,
|
|
1435
|
-
maxRetries: 5
|
|
1436
|
-
});
|
|
1437
|
-
if (await isIntunedExtensionEnabled()) {
|
|
1438
|
-
await cleanIntunedExtensionServer();
|
|
1439
|
-
}
|
|
1440
|
-
} catch (error) {
|
|
1441
|
-
console.error("Failed to remove user data dir", error);
|
|
1442
|
-
}
|
|
1443
|
-
});
|
|
1444
|
-
if (cdpPort) {
|
|
1445
|
-
const createdCdpAddress = getLocalCdpAddress(cdpPort);
|
|
1446
|
-
await waitOnCdpAddress(createdCdpAddress);
|
|
1447
|
-
}
|
|
1448
|
-
const page = context.pages().at(0) ?? await context.newPage();
|
|
1449
|
-
if (await isIntunedExtensionEnabled()) {
|
|
1450
|
-
await getIntunedExtensionWorker(context);
|
|
1451
|
-
}
|
|
1452
|
-
return {
|
|
1453
|
-
page,
|
|
1454
|
-
context
|
|
1455
|
-
};
|
|
1456
|
-
}
|
|
1457
|
-
async function getBrowserExecutablePath() {
|
|
1458
|
-
const browserType = getBrowserType();
|
|
1459
|
-
if (browserType === "brave") {
|
|
1460
|
-
return await getBraveExecutablePath();
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
async function launchBrowser(options) {
|
|
1464
|
-
if ("cdpAddress" in options) {
|
|
1465
|
-
return launchChromium(options);
|
|
1466
|
-
}
|
|
1467
|
-
return launchChromium({
|
|
1468
|
-
...options,
|
|
1469
|
-
executablePath: await getBrowserExecutablePath()
|
|
1470
|
-
});
|
|
1471
|
-
}
|
|
1472
|
-
function getBrowserType() {
|
|
1473
|
-
if (process.env.BROWSER_TYPE === "brave") {
|
|
1474
|
-
return "brave";
|
|
1475
|
-
}
|
|
1476
|
-
return "chromium";
|
|
1477
|
-
}
|
|
1478
|
-
async function getBraveExecutablePath() {
|
|
1479
|
-
const { stdout } = await execAsync("which brave-browser-stable");
|
|
1480
|
-
const bravePath = stdout.trim();
|
|
1481
|
-
if (bravePath.length === 0) {
|
|
1482
|
-
throw new Error("Brave browser not found");
|
|
1483
|
-
}
|
|
1484
|
-
return bravePath;
|
|
1485
|
-
}
|
|
1486
|
-
function getLocalCdpAddress(port) {
|
|
1487
|
-
return `http://localhost:${port}`;
|
|
1488
|
-
}
|
|
1489
|
-
async function getCdpWebSocketUrl(cdpAddress) {
|
|
1490
|
-
let response;
|
|
1491
|
-
try {
|
|
1492
|
-
response = await fetch(`${cdpAddress}/json/version`);
|
|
1493
|
-
} catch (error) {
|
|
1494
|
-
return (0, import_neverthrow4.err)(
|
|
1495
|
-
`Failed to fetch CDP version from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`
|
|
1496
|
-
);
|
|
1497
|
-
}
|
|
1498
|
-
if (!response.ok) {
|
|
1499
|
-
return (0, import_neverthrow4.err)(
|
|
1500
|
-
`Failed to get CDP WebSocket URL from ${cdpAddress}: ${response.status} ${response.statusText}`
|
|
1501
|
-
);
|
|
1502
|
-
}
|
|
1503
|
-
let data;
|
|
1504
|
-
try {
|
|
1505
|
-
data = await response.json();
|
|
1506
|
-
} catch (error) {
|
|
1507
|
-
return (0, import_neverthrow4.err)(
|
|
1508
|
-
`Invalid CDP version response from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`
|
|
1509
|
-
);
|
|
1510
|
-
}
|
|
1511
|
-
const cdpJsonVersionResponseSchema = import_zod3.z.object({
|
|
1512
|
-
webSocketDebuggerUrl: import_zod3.z.string().url()
|
|
1513
|
-
});
|
|
1514
|
-
const parseResult = cdpJsonVersionResponseSchema.safeParse(data);
|
|
1515
|
-
if (!parseResult.success) {
|
|
1516
|
-
return (0, import_neverthrow4.err)(
|
|
1517
|
-
`Invalid CDP version response from ${cdpAddress}: ${JSON.stringify(
|
|
1518
|
-
parseResult.error.format()
|
|
1519
|
-
)}`
|
|
1520
|
-
);
|
|
1521
|
-
}
|
|
1522
|
-
return (0, import_neverthrow4.ok)(parseResult.data.webSocketDebuggerUrl);
|
|
1523
|
-
}
|
|
1524
|
-
async function waitOnCdpAddress(cdpAddress) {
|
|
1525
|
-
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
1526
|
-
await (0, import_wait_on.default)({
|
|
1527
|
-
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
1528
|
-
delay: 100,
|
|
1529
|
-
interval: 100,
|
|
1530
|
-
timeout: 5e3,
|
|
1531
|
-
tcpTimeout: 1e3,
|
|
1532
|
-
window: 1e3
|
|
1533
|
-
});
|
|
1534
|
-
}
|
|
1535
|
-
async function getHeadlessUserAgent({
|
|
1536
|
-
executablePath,
|
|
1537
|
-
args,
|
|
1538
|
-
ignoreDefaultArgs
|
|
1539
|
-
}) {
|
|
1540
|
-
const browser = await playwright.chromium.launch({
|
|
1541
|
-
headless: true,
|
|
1542
|
-
executablePath,
|
|
1543
|
-
args,
|
|
1544
|
-
ignoreDefaultArgs
|
|
1545
|
-
});
|
|
1546
|
-
const context = await browser.newContext();
|
|
1547
|
-
const page = await context.newPage();
|
|
1548
|
-
let userAgent = await page.evaluate(() => navigator.userAgent);
|
|
1549
|
-
await browser.close();
|
|
1550
|
-
if (!userAgent || typeof userAgent !== "string") {
|
|
1551
|
-
return void 0;
|
|
1552
|
-
}
|
|
1553
|
-
userAgent = userAgent.replace("HeadlessChrome", "Chrome");
|
|
1554
|
-
return userAgent;
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
// src/common/playwrightContext.ts
|
|
1558
|
-
var import_runtime_interface3 = __toESM(require_dist());
|
|
1559
|
-
async function withPlaywrightContext({
|
|
1560
|
-
cdpAddress,
|
|
1561
|
-
cdpTargetId,
|
|
1562
|
-
proxy,
|
|
1563
|
-
headless = true,
|
|
1564
|
-
downloadsPath,
|
|
1565
|
-
importFunction,
|
|
1566
|
-
apiName,
|
|
1567
|
-
apiParameters
|
|
1568
|
-
}, fn) {
|
|
1569
|
-
let context;
|
|
1570
|
-
let page;
|
|
1571
|
-
try {
|
|
1572
|
-
const setupContextHookResult = importFunction ? await loadSetupContextHook({
|
|
1573
|
-
importFunction
|
|
1574
|
-
}) : (0, import_neverthrow5.ok)(null);
|
|
1575
|
-
if (setupContextHookResult.isErr()) {
|
|
1576
|
-
return setupContextHookResult;
|
|
1577
|
-
}
|
|
1578
|
-
const setupContextHook = setupContextHookResult.value;
|
|
1579
|
-
if (setupContextHook === null) {
|
|
1580
|
-
if (cdpAddress !== void 0) {
|
|
1581
|
-
({ page, context } = await launchBrowser({ cdpAddress, cdpTargetId }));
|
|
1582
|
-
} else {
|
|
1583
|
-
({ page, context } = await launchBrowser({
|
|
1584
|
-
proxy,
|
|
1585
|
-
headless,
|
|
1586
|
-
downloadsPath
|
|
1587
|
-
}));
|
|
1588
|
-
}
|
|
1589
|
-
return await fn(context, page);
|
|
1590
|
-
}
|
|
1591
|
-
let hookCdpUrl = null;
|
|
1592
|
-
if (cdpAddress) {
|
|
1593
|
-
hookCdpUrl = cdpAddress;
|
|
1594
|
-
({ context, page } = await launchBrowser({ cdpAddress, cdpTargetId }));
|
|
1595
|
-
} else {
|
|
1596
|
-
const port = await (0, import_portfinder2.getPort)({
|
|
1597
|
-
port: 9222
|
|
1598
|
-
});
|
|
1599
|
-
({ context, page } = await launchBrowser({
|
|
1600
|
-
proxy,
|
|
1601
|
-
headless,
|
|
1602
|
-
downloadsPath,
|
|
1603
|
-
cdpPort: port
|
|
1604
|
-
}));
|
|
1605
|
-
hookCdpUrl = getLocalCdpAddress(port);
|
|
1606
|
-
}
|
|
1607
|
-
let hookResult;
|
|
1608
|
-
try {
|
|
1609
|
-
const wsUrlResult = await getCdpWebSocketUrl(hookCdpUrl);
|
|
1610
|
-
if (wsUrlResult.isOk()) {
|
|
1611
|
-
hookCdpUrl = wsUrlResult.value;
|
|
1612
|
-
} else {
|
|
1613
|
-
throw new Error(wsUrlResult.error);
|
|
1614
|
-
}
|
|
1615
|
-
hookResult = await setupContextHook({
|
|
1616
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1617
|
-
apiName,
|
|
1618
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
1619
|
-
apiParameters,
|
|
1620
|
-
cdpUrl: hookCdpUrl
|
|
1621
|
-
});
|
|
1622
|
-
} catch (error) {
|
|
1623
|
-
return (0, import_neverthrow5.err)(new import_runtime_interface3.AutomationError(error));
|
|
1624
|
-
}
|
|
1625
|
-
if (!hookResult) {
|
|
1626
|
-
return await fn(context, page);
|
|
1627
|
-
}
|
|
1628
|
-
const { page: newPage, context: newContext, cleanup } = hookResult;
|
|
1629
|
-
let result;
|
|
1630
|
-
try {
|
|
1631
|
-
result = { return: await fn(newContext, newPage ?? page) };
|
|
1632
|
-
} catch (e) {
|
|
1633
|
-
result = { throw: e };
|
|
1634
|
-
}
|
|
1635
|
-
try {
|
|
1636
|
-
await cleanup?.();
|
|
1637
|
-
} catch (e) {
|
|
1638
|
-
result = { return: (0, import_neverthrow5.err)(new import_runtime_interface3.AutomationError(e)) };
|
|
1639
|
-
}
|
|
1640
|
-
if ("throw" in result) {
|
|
1641
|
-
throw result.throw;
|
|
1642
|
-
}
|
|
1643
|
-
return result.return;
|
|
1644
|
-
} finally {
|
|
1645
|
-
await context?.close();
|
|
1646
|
-
}
|
|
1647
|
-
}
|
|
1648
|
-
async function loadSessionToContext({
|
|
1649
|
-
context,
|
|
1650
|
-
session
|
|
1651
|
-
}) {
|
|
1652
|
-
let sessionToLoad;
|
|
1653
|
-
if (session.type === "state") {
|
|
1654
|
-
const state = session.state;
|
|
1655
|
-
if (state === void 0 || state === null) {
|
|
1656
|
-
return;
|
|
1657
|
-
}
|
|
1658
|
-
sessionToLoad = state;
|
|
1659
|
-
} else {
|
|
1660
|
-
const fullPath = getFullPathInProject(session.path);
|
|
1661
|
-
sessionToLoad = await fs3.readJson(fullPath);
|
|
1662
|
-
}
|
|
1663
|
-
await setStorageState(context, sessionToLoad);
|
|
1664
|
-
}
|
|
1665
|
-
|
|
1666
|
-
// src/common/formatZodError.ts
|
|
1667
|
-
function formatZodError(zodError) {
|
|
1668
|
-
const formattedErrors = zodError.errors.map((error) => {
|
|
1669
|
-
const path3 = error.path.map((segment) => {
|
|
1670
|
-
return typeof segment === "number" ? `[${segment}]` : segment;
|
|
1671
|
-
}).join(".");
|
|
1672
|
-
if (path3) {
|
|
1673
|
-
return `${path3} is invalid - ${error.message}`;
|
|
1674
|
-
}
|
|
1675
|
-
return error.message;
|
|
1676
|
-
});
|
|
1677
|
-
return formattedErrors;
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
// src/common/cleanEnvironmentVariables.ts
|
|
1681
|
-
function cleanEnvironmentVariables() {
|
|
1682
|
-
Object.keys(process.env).filter((i) => {
|
|
1683
|
-
if (i.toLocaleLowerCase().startsWith("npm")) {
|
|
1684
|
-
return true;
|
|
1685
|
-
}
|
|
1686
|
-
if (i.toLocaleLowerCase().startsWith("fly") && i !== "FLY_ALLOC_ID") {
|
|
1687
|
-
return true;
|
|
1688
|
-
}
|
|
1689
|
-
}).forEach((i) => delete process.env[i]);
|
|
1690
|
-
}
|
|
1691
|
-
|
|
1692
|
-
// src/common/runApi/index.ts
|
|
1693
|
-
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); }
|
|
1694
21
|
function getObjectSizeInBytes(obj) {
|
|
1695
22
|
try {
|
|
1696
23
|
return new TextEncoder().encode(JSON.stringify(obj)).length;
|
|
@@ -1705,41 +32,39 @@ async function runApi({
|
|
|
1705
32
|
...input
|
|
1706
33
|
}) {
|
|
1707
34
|
let traceStarted = false;
|
|
1708
|
-
const inputParseResult =
|
|
35
|
+
const inputParseResult = _runtimeInterface.runApiParametersSchema.safeParse(input);
|
|
1709
36
|
if (!inputParseResult.success) {
|
|
1710
|
-
return (0,
|
|
1711
|
-
new import_runtime_interface4.InternalInvalidInputError(
|
|
1712
|
-
"Input validation failed",
|
|
1713
|
-
formatZodError(inputParseResult.error)
|
|
1714
|
-
)
|
|
1715
|
-
);
|
|
37
|
+
return (0, _neverthrow.err)(new _runtimeInterface.InternalInvalidInputError("Input validation failed", (0, _formatZodError.formatZodError)(inputParseResult.error)));
|
|
1716
38
|
}
|
|
1717
39
|
const {
|
|
1718
|
-
automationFunction: {
|
|
40
|
+
automationFunction: {
|
|
41
|
+
name,
|
|
42
|
+
params
|
|
43
|
+
},
|
|
1719
44
|
runOptions,
|
|
1720
45
|
tracing,
|
|
1721
46
|
auth
|
|
1722
47
|
} = inputParseResult.data;
|
|
1723
|
-
const abortSymbol =
|
|
1724
|
-
const abortPromise = new Promise(
|
|
48
|
+
const abortSymbol = Symbol("abort");
|
|
49
|
+
const abortPromise = new Promise(resolve => {
|
|
1725
50
|
if (!abortSignal) return;
|
|
1726
51
|
abortSignal.addEventListener("abort", () => {
|
|
1727
|
-
|
|
52
|
+
resolve(abortSymbol);
|
|
1728
53
|
});
|
|
1729
54
|
});
|
|
1730
55
|
async function runAutomation() {
|
|
1731
|
-
const validatedModuleResult = await importUsingImportFunction({
|
|
56
|
+
const validatedModuleResult = await (0, _importUsingImportFunction.importUsingImportFunction)({
|
|
1732
57
|
path: name,
|
|
1733
58
|
importFunction
|
|
1734
59
|
});
|
|
1735
60
|
if (validatedModuleResult.isErr()) {
|
|
1736
|
-
return (0,
|
|
61
|
+
return (0, _neverthrow.err)(validatedModuleResult.error);
|
|
1737
62
|
}
|
|
1738
63
|
const automationFunction = validatedModuleResult.value;
|
|
1739
64
|
if (auth && auth.session.type === "state") {
|
|
1740
65
|
const state = auth.session.state;
|
|
1741
|
-
if (state ===
|
|
1742
|
-
return (0,
|
|
66
|
+
if (state === undefined || state === null) {
|
|
67
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AuthRequiredError());
|
|
1743
68
|
}
|
|
1744
69
|
}
|
|
1745
70
|
const playwrightContextParameters = {
|
|
@@ -1747,7 +72,7 @@ async function runApi({
|
|
|
1747
72
|
apiParameters: params,
|
|
1748
73
|
importFunction
|
|
1749
74
|
};
|
|
1750
|
-
const intunedContext = getExecutionContext();
|
|
75
|
+
const intunedContext = (0, _asyncLocalStorage.getExecutionContext)();
|
|
1751
76
|
const runAutomationWithContext = async (context, page) => {
|
|
1752
77
|
async function saveTraceIfNeeded({
|
|
1753
78
|
errorMessage
|
|
@@ -1756,14 +81,16 @@ async function runApi({
|
|
|
1756
81
|
return;
|
|
1757
82
|
}
|
|
1758
83
|
try {
|
|
1759
|
-
await context?.tracing.stop({
|
|
84
|
+
await context?.tracing.stop({
|
|
85
|
+
path: tracing.filePath
|
|
86
|
+
});
|
|
1760
87
|
} catch (error) {
|
|
1761
88
|
console.log(errorMessage, error?.message);
|
|
1762
|
-
await (0,
|
|
89
|
+
await (0, _fsExtra.remove)(tracing.filePath);
|
|
1763
90
|
}
|
|
1764
91
|
}
|
|
1765
92
|
if (auth) {
|
|
1766
|
-
await loadSessionToContext({
|
|
93
|
+
await (0, _playwrightContext.loadSessionToContext)({
|
|
1767
94
|
context,
|
|
1768
95
|
session: auth.session
|
|
1769
96
|
});
|
|
@@ -1779,95 +106,73 @@ async function runApi({
|
|
|
1779
106
|
});
|
|
1780
107
|
traceStarted = true;
|
|
1781
108
|
}
|
|
1782
|
-
cleanEnvironmentVariables();
|
|
1783
|
-
const automationFunctionParameters = [
|
|
1784
|
-
...params !== void 0 ? [params] : [],
|
|
1785
|
-
page,
|
|
1786
|
-
context
|
|
1787
|
-
];
|
|
109
|
+
(0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
|
|
110
|
+
const automationFunctionParameters = [...(params !== undefined ? [params] : []), page, context];
|
|
1788
111
|
try {
|
|
1789
|
-
const [automationFunctionResult] = await Promise.all([
|
|
1790
|
-
automationFunction(...automationFunctionParameters)
|
|
1791
|
-
]);
|
|
112
|
+
const [automationFunctionResult] = await Promise.all([automationFunction(...automationFunctionParameters)]);
|
|
1792
113
|
const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
|
|
1793
|
-
const resultSizeInBytes = getObjectSizeInBytes(
|
|
1794
|
-
automationFunctionResult
|
|
1795
|
-
);
|
|
114
|
+
const resultSizeInBytes = getObjectSizeInBytes(automationFunctionResult);
|
|
1796
115
|
if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
|
|
1797
|
-
return (0,
|
|
1798
|
-
new import_runtime_interface4.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES)
|
|
1799
|
-
);
|
|
116
|
+
return (0, _neverthrow.err)(new _runtimeInterface.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES));
|
|
1800
117
|
}
|
|
1801
118
|
if (retrieveSession) {
|
|
1802
|
-
return (0,
|
|
119
|
+
return (0, _neverthrow.ok)({
|
|
1803
120
|
result: automationFunctionResult,
|
|
1804
121
|
extendedPayloads: intunedContext?.extendedPayloads,
|
|
1805
|
-
session: await getStorageState(context)
|
|
122
|
+
session: await (0, _contextStorageStateHelpers.getStorageState)(context)
|
|
1806
123
|
});
|
|
1807
124
|
}
|
|
1808
|
-
return (0,
|
|
125
|
+
return (0, _neverthrow.ok)({
|
|
1809
126
|
result: automationFunctionResult,
|
|
1810
127
|
extendedPayloads: intunedContext?.extendedPayloads
|
|
1811
128
|
});
|
|
1812
129
|
} catch (error) {
|
|
1813
|
-
return (0,
|
|
130
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(error));
|
|
1814
131
|
} finally {
|
|
1815
|
-
await saveTraceIfNeeded({
|
|
132
|
+
await saveTraceIfNeeded({
|
|
133
|
+
errorMessage: "failed to save trace"
|
|
134
|
+
});
|
|
1816
135
|
}
|
|
1817
136
|
};
|
|
1818
137
|
if (intunedContext?.store) {
|
|
1819
138
|
intunedContext.store = {};
|
|
1820
139
|
}
|
|
1821
140
|
if (runOptions.environment === "standalone") {
|
|
1822
|
-
const downloadsPath = getDownloadDirectoryPath();
|
|
141
|
+
const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
|
|
1823
142
|
try {
|
|
1824
|
-
return await withPlaywrightContext(
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
},
|
|
1831
|
-
runAutomationWithContext
|
|
1832
|
-
);
|
|
143
|
+
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
144
|
+
headless: runOptions.headless,
|
|
145
|
+
proxy: runOptions.proxy,
|
|
146
|
+
downloadsPath,
|
|
147
|
+
...playwrightContextParameters
|
|
148
|
+
}, runAutomationWithContext);
|
|
1833
149
|
} finally {
|
|
1834
|
-
await
|
|
150
|
+
await fs.remove(downloadsPath);
|
|
1835
151
|
}
|
|
1836
152
|
} else {
|
|
1837
|
-
return await withPlaywrightContext(
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
},
|
|
1843
|
-
runAutomationWithContext
|
|
1844
|
-
);
|
|
153
|
+
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
154
|
+
cdpAddress: runOptions.cdpAddress,
|
|
155
|
+
cdpTargetId: runOptions.cdpTargetId,
|
|
156
|
+
...playwrightContextParameters
|
|
157
|
+
}, runAutomationWithContext);
|
|
1845
158
|
}
|
|
1846
159
|
}
|
|
1847
160
|
const result = await Promise.race([await runAutomation(), abortPromise]);
|
|
1848
161
|
if (result === abortSymbol) {
|
|
1849
|
-
return (0,
|
|
162
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AbortedError());
|
|
1850
163
|
}
|
|
1851
164
|
return result;
|
|
1852
165
|
}
|
|
1853
166
|
async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
|
|
1854
167
|
if (retries === 0) {
|
|
1855
|
-
return (0,
|
|
168
|
+
return (0, _neverthrow.ok)(false);
|
|
1856
169
|
}
|
|
1857
170
|
let tryNumber = 0;
|
|
1858
|
-
console.log(
|
|
1859
|
-
"Checking AuthSession with retries",
|
|
1860
|
-
`${AUTH_SESSIONS_FOLDER_NAME}/check`
|
|
1861
|
-
);
|
|
171
|
+
console.log("Checking AuthSession with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
1862
172
|
while (retries > tryNumber) {
|
|
1863
173
|
const result = await checkFn(page, context);
|
|
1864
|
-
if (result) return (0,
|
|
174
|
+
if (result) return (0, _neverthrow.ok)(true);
|
|
1865
175
|
tryNumber++;
|
|
1866
176
|
}
|
|
1867
|
-
return (0,
|
|
1868
|
-
}
|
|
1869
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1870
|
-
0 && (module.exports = {
|
|
1871
|
-
checkAuthSessionWithRetries,
|
|
1872
|
-
runApi
|
|
1873
|
-
});
|
|
177
|
+
return (0, _neverthrow.ok)(false);
|
|
178
|
+
}
|