@intuned/runtime 1.3.17 → 1.3.18-interface.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/intuned +0 -0
- package/bin/intuned-interface +7 -0
- package/dist/chunk-6ZRJOUQS.mjs +16 -0
- package/dist/chunk-6ZRJOUQS.mjs.map +1 -0
- package/dist/chunk-7YL2JUTE.mjs +146 -0
- package/dist/chunk-7YL2JUTE.mjs.map +1 -0
- package/dist/chunk-B3T6RXPC.mjs +794 -0
- package/dist/chunk-B3T6RXPC.mjs.map +1 -0
- package/dist/chunk-FGV5T6SI.mjs +27 -0
- package/dist/chunk-FGV5T6SI.mjs.map +1 -0
- package/dist/chunk-G4PO5RIV.mjs +85 -0
- package/dist/chunk-G4PO5RIV.mjs.map +1 -0
- package/dist/chunk-LZOMFHX3.mjs +38 -0
- package/dist/chunk-LZOMFHX3.mjs.map +1 -0
- package/dist/{common/formatZodError.js → chunk-NDMVGENG.mjs} +9 -9
- package/dist/chunk-NDMVGENG.mjs.map +1 -0
- package/dist/chunk-W4UX6G4X.mjs +17 -0
- package/dist/chunk-W4UX6G4X.mjs.map +1 -0
- package/dist/chunk-XC75QGFG.mjs +1106 -0
- package/dist/chunk-XC75QGFG.mjs.map +1 -0
- package/dist/chunk-XOAZ2MGA.mjs +59 -0
- package/dist/chunk-XOAZ2MGA.mjs.map +1 -0
- package/dist/commands/interface/run.d.mts +3 -0
- package/dist/commands/interface/run.d.ts +3 -1
- package/dist/commands/interface/run.js +2060 -178
- package/dist/commands/interface/run.js.map +1 -0
- package/dist/commands/interface/run.mjs +255 -0
- package/dist/commands/interface/run.mjs.map +1 -0
- package/dist/common/asyncLocalStorage/index.d.mts +17 -0
- package/dist/common/asyncLocalStorage/index.d.ts +9 -8
- package/dist/common/asyncLocalStorage/index.js +34 -9
- package/dist/common/asyncLocalStorage/index.js.map +1 -0
- package/dist/common/asyncLocalStorage/index.mjs +12 -0
- package/dist/common/asyncLocalStorage/index.mjs.map +1 -0
- package/dist/common/binStartupScript.d.mts +2 -0
- package/dist/common/binStartupScript.d.ts +2 -1
- package/dist/common/binStartupScript.js +127 -11
- package/dist/common/binStartupScript.js.map +1 -0
- package/dist/common/binStartupScript.mjs +135 -0
- package/dist/common/binStartupScript.mjs.map +1 -0
- package/dist/common/cleanEnvironmentVariables.d.mts +3 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +3 -1
- package/dist/common/cleanEnvironmentVariables.js +30 -7
- package/dist/common/cleanEnvironmentVariables.js.map +1 -0
- package/dist/common/cleanEnvironmentVariables.mjs +8 -0
- package/dist/common/cleanEnvironmentVariables.mjs.map +1 -0
- package/dist/common/constants.d.mts +13 -0
- package/dist/common/constants.d.ts +13 -10
- package/dist/common/constants.js +58 -14
- package/dist/common/constants.js.map +1 -0
- package/dist/common/constants.mjs +28 -0
- package/dist/common/constants.mjs.map +1 -0
- package/dist/common/contextStorageStateHelpers.d.mts +24 -0
- package/dist/common/contextStorageStateHelpers.d.ts +8 -5
- package/dist/common/contextStorageStateHelpers.js +51 -23
- package/dist/common/contextStorageStateHelpers.js.map +1 -0
- package/dist/common/contextStorageStateHelpers.mjs +10 -0
- package/dist/common/contextStorageStateHelpers.mjs.map +1 -0
- package/dist/common/jwtTokenManager.d.mts +19 -0
- package/dist/common/jwtTokenManager.d.ts +6 -4
- package/dist/common/jwtTokenManager.js +112 -40
- package/dist/common/jwtTokenManager.js.map +1 -0
- package/dist/common/jwtTokenManager.mjs +11 -0
- package/dist/common/jwtTokenManager.mjs.map +1 -0
- package/dist/common/runApi/index.d.mts +11 -0
- package/dist/common/runApi/index.d.ts +10 -10
- package/dist/common/runApi/index.js +1776 -93
- package/dist/common/runApi/index.js.map +1 -0
- package/dist/common/runApi/index.mjs +18 -0
- package/dist/common/runApi/index.mjs.map +1 -0
- package/dist/common/settingsSchema.d.mts +536 -0
- package/dist/common/settingsSchema.d.ts +9 -6
- package/dist/common/settingsSchema.js +55 -20
- package/dist/common/settingsSchema.js.map +1 -0
- package/dist/common/settingsSchema.mjs +10 -0
- package/dist/common/settingsSchema.mjs.map +1 -0
- package/dist/common/telemetry.d.mts +6 -0
- package/dist/common/telemetry.d.ts +6 -3
- package/dist/common/telemetry.js +41 -9
- package/dist/common/telemetry.js.map +1 -0
- package/dist/common/telemetry.mjs +31 -0
- package/dist/common/telemetry.mjs.map +1 -0
- package/dist/export.d-BAUMB-lG.d.mts +140 -0
- package/dist/export.d-BAUMB-lG.d.ts +140 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +783 -98
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +47 -0
- package/dist/index.mjs.map +1 -0
- package/dist/runtime/index.d.mts +163 -0
- package/dist/runtime/index.d.ts +163 -10
- package/dist/runtime/index.js +779 -88
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/index.mjs +42 -0
- package/dist/runtime/index.mjs.map +1 -0
- package/package.json +78 -23
- package/.babelrc +0 -21
- package/.eslintignore +0 -10
- package/.eslintrc.js +0 -39
- package/InterfaceTemplate/__utils.ts +0 -61
- package/InterfaceTemplate/index.playwright.ts +0 -6
- package/WebTemplate.zip +0 -0
- package/dist/commands/api/run.d.ts +0 -6
- package/dist/commands/api/run.js +0 -119
- package/dist/commands/auth-sessions/load.d.ts +0 -2
- package/dist/commands/auth-sessions/load.js +0 -35
- package/dist/commands/auth-sessions/run-check.d.ts +0 -2
- package/dist/commands/auth-sessions/run-check.js +0 -74
- package/dist/commands/auth-sessions/run-create.d.ts +0 -2
- package/dist/commands/auth-sessions/run-create.js +0 -78
- package/dist/commands/browser/save-state.d.ts +0 -2
- package/dist/commands/browser/save-state.js +0 -17
- package/dist/commands/browser/start-browser.d.ts +0 -2
- package/dist/commands/browser/start-browser.js +0 -14
- package/dist/commands/build.d.ts +0 -1
- package/dist/commands/build.js +0 -84
- package/dist/commands/common/browserUtils.d.ts +0 -14
- package/dist/commands/common/browserUtils.js +0 -58
- package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
- package/dist/commands/common/getFirstLineNumber.js +0 -101
- package/dist/commands/common/getFirstLineNumber.test.js +0 -228
- package/dist/commands/common/projectExclusions.d.ts +0 -2
- package/dist/commands/common/projectExclusions.js +0 -8
- package/dist/commands/common/sendMessageToClient.d.ts +0 -1
- package/dist/commands/common/sendMessageToClient.js +0 -10
- package/dist/commands/common/tsNodeImport.d.ts +0 -2
- package/dist/commands/common/tsNodeImport.js +0 -43
- package/dist/commands/common/utils/fileUtils.d.ts +0 -6
- package/dist/commands/common/utils/fileUtils.js +0 -33
- package/dist/commands/common/utils/settings.d.ts +0 -2
- package/dist/commands/common/utils/settings.js +0 -31
- package/dist/commands/common/utils/template.d.ts +0 -2
- package/dist/commands/common/utils/template.js +0 -31
- package/dist/commands/common/utils/unixSocket.d.ts +0 -23
- package/dist/commands/common/utils/unixSocket.js +0 -87
- package/dist/commands/get-headless-user-agent.d.ts +0 -1
- package/dist/commands/get-headless-user-agent.js +0 -18
- package/dist/commands/intuned-cli/commands/attempt.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt.command.js +0 -8
- package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +0 -30
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +0 -8
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +0 -19
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +0 -24
- package/dist/commands/intuned-cli/commands/authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession.command.js +0 -8
- package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession_record.command.js +0 -32
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +0 -16
- package/dist/commands/intuned-cli/commands/build.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/build.command.js +0 -12
- package/dist/commands/intuned-cli/commands/command.d.ts +0 -2
- package/dist/commands/intuned-cli/commands/command.js +0 -9
- package/dist/commands/intuned-cli/commands/deploy.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/deploy.command.js +0 -42
- package/dist/commands/intuned-cli/commands/index.d.ts +0 -18
- package/dist/commands/intuned-cli/commands/index.js +0 -203
- package/dist/commands/intuned-cli/commands/provision.command.d.ts +0 -13
- package/dist/commands/intuned-cli/commands/provision.command.js +0 -50
- package/dist/commands/intuned-cli/commands/run.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run.command.js +0 -8
- package/dist/commands/intuned-cli/commands/run_api.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_api.command.js +0 -46
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -31
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +0 -17
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +0 -35
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +0 -35
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +0 -33
- package/dist/commands/intuned-cli/commands/types.d.ts +0 -35
- package/dist/commands/intuned-cli/commands/types.js +0 -31
- package/dist/commands/intuned-cli/constants/index.d.ts +0 -17
- package/dist/commands/intuned-cli/constants/index.js +0 -25
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +0 -398
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +0 -1060
- package/dist/commands/intuned-cli/controller/api.d.ts +0 -42
- package/dist/commands/intuned-cli/controller/api.js +0 -194
- package/dist/commands/intuned-cli/controller/authSession.d.ts +0 -209
- package/dist/commands/intuned-cli/controller/authSession.js +0 -424
- package/dist/commands/intuned-cli/controller/build.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/build.js +0 -36
- package/dist/commands/intuned-cli/controller/deploy.d.ts +0 -5
- package/dist/commands/intuned-cli/controller/deploy.js +0 -318
- package/dist/commands/intuned-cli/controller/index.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/index.js +0 -46
- package/dist/commands/intuned-cli/controller/provision.d.ts +0 -21
- package/dist/commands/intuned-cli/controller/provision.js +0 -300
- package/dist/commands/intuned-cli/controller/scaffold.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/scaffold.js +0 -77
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +0 -115
- package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +0 -41
- package/dist/commands/intuned-cli/helpers/api.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/api.js +0 -16
- package/dist/commands/intuned-cli/helpers/auth.d.ts +0 -46
- package/dist/commands/intuned-cli/helpers/auth.js +0 -147
- package/dist/commands/intuned-cli/helpers/backend.d.ts +0 -8
- package/dist/commands/intuned-cli/helpers/backend.js +0 -35
- package/dist/commands/intuned-cli/helpers/browser.d.ts +0 -15
- package/dist/commands/intuned-cli/helpers/browser.js +0 -64
- package/dist/commands/intuned-cli/helpers/context.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/context.js +0 -33
- package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -16
- package/dist/commands/intuned-cli/helpers/errors.js +0 -44
- package/dist/commands/intuned-cli/helpers/index.d.ts +0 -12
- package/dist/commands/intuned-cli/helpers/index.js +0 -137
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +0 -39
- package/dist/commands/intuned-cli/helpers/intunedJson.js +0 -20
- package/dist/commands/intuned-cli/helpers/prompts.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/prompts.js +0 -71
- package/dist/commands/intuned-cli/helpers/proxy.d.ts +0 -5
- package/dist/commands/intuned-cli/helpers/proxy.js +0 -23
- package/dist/commands/intuned-cli/helpers/terminal.d.ts +0 -5
- package/dist/commands/intuned-cli/helpers/terminal.js +0 -13
- package/dist/commands/intuned-cli/helpers/timeout.d.ts +0 -1
- package/dist/commands/intuned-cli/helpers/timeout.js +0 -23
- package/dist/commands/intuned-cli/helpers/traces.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/traces.js +0 -32
- package/dist/commands/intuned-cli/helpers/validation.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/validation.js +0 -14
- package/dist/commands/intuned-cli/helpers/wrapper.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/wrapper.js +0 -76
- package/dist/commands/intuned-cli/index.d.ts +0 -1
- package/dist/commands/intuned-cli/index.js +0 -16
- package/dist/commands/intuned-cli/main.d.ts +0 -1
- package/dist/commands/intuned-cli/main.js +0 -36
- package/dist/commands/intuned-cli/types.d.ts +0 -70
- package/dist/commands/intuned-cli/types.js +0 -22
- package/dist/commands/ts-check.d.ts +0 -2
- package/dist/commands/ts-check.js +0 -56
- package/dist/common/Logger/Logger/index.d.ts +0 -12
- package/dist/common/Logger/Logger/index.js +0 -60
- package/dist/common/Logger/Logger/types.d.ts +0 -8
- package/dist/common/Logger/Logger/types.js +0 -5
- package/dist/common/Logger/index.d.ts +0 -12
- package/dist/common/Logger/index.js +0 -60
- package/dist/common/Logger/types.d.ts +0 -8
- package/dist/common/Logger/types.js +0 -5
- package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +0 -1
- package/dist/common/backendFunctions/getAuthSessionParameters.js +0 -38
- package/dist/common/extension/extensionsHelpers.d.ts +0 -11
- package/dist/common/extension/extensionsHelpers.js +0 -147
- package/dist/common/extension/intunedExtensionServer.d.ts +0 -24
- package/dist/common/extension/intunedExtensionServer.js +0 -178
- package/dist/common/extension/types.d.ts +0 -212
- package/dist/common/extension/types.js +0 -51
- package/dist/common/formatZodError.d.ts +0 -2
- package/dist/common/intunedJson.d.ts +0 -229
- package/dist/common/intunedJson.js +0 -133
- package/dist/common/launchBrowser.d.ts +0 -33
- package/dist/common/launchBrowser.js +0 -235
- package/dist/common/playwrightContext.d.ts +0 -31
- package/dist/common/playwrightContext.js +0 -150
- package/dist/common/runApi/errors.d.ts +0 -72
- package/dist/common/runApi/errors.js +0 -169
- package/dist/common/runApi/importUsingImportFunction.d.ts +0 -9
- package/dist/common/runApi/importUsingImportFunction.js +0 -46
- package/dist/common/runApi/types.d.ts +0 -830
- package/dist/common/runApi/types.js +0 -73
- package/dist/common/setupContextHook.d.ts +0 -17
- package/dist/common/setupContextHook.js +0 -22
- package/dist/runtime/RunError.d.ts +0 -5
- package/dist/runtime/RunError.js +0 -19
- package/dist/runtime/attemptStore.d.ts +0 -2
- package/dist/runtime/attemptStore.js +0 -23
- package/dist/runtime/captcha.d.ts +0 -15
- package/dist/runtime/captcha.js +0 -191
- package/dist/runtime/captcha.test.js +0 -821
- package/dist/runtime/downloadDirectory.d.ts +0 -1
- package/dist/runtime/downloadDirectory.js +0 -19
- package/dist/runtime/enums.d.js +0 -5
- package/dist/runtime/enums.d.ts +0 -11
- package/dist/runtime/enums.js +0 -18
- package/dist/runtime/executionHelpers.test.js +0 -52
- package/dist/runtime/export.d.js +0 -5
- package/dist/runtime/export.d.ts +0 -284
- package/dist/runtime/extendPayload.d.ts +0 -2
- package/dist/runtime/extendPayload.js +0 -21
- package/dist/runtime/extendTimeout.d.ts +0 -1
- package/dist/runtime/extendTimeout.js +0 -23
- package/dist/runtime/getAiGatewayConfig.d.ts +0 -10
- package/dist/runtime/getAiGatewayConfig.js +0 -16
- package/dist/runtime/getAuthSessionParameters.d.ts +0 -1
- package/dist/runtime/getAuthSessionParameters.js +0 -20
- package/dist/runtime/persistentStore.d.ts +0 -2
- package/dist/runtime/persistentStore.js +0 -37
- package/dist/runtime/persistentStore.test.js +0 -101
- package/dist/runtime/runInfo.d.ts +0 -2
- package/dist/runtime/runInfo.js +0 -21
- package/template.tsconfig.json +0 -11
- package/tsconfig.eslint.json +0 -5
- package/tsconfig.json +0 -25
- package/typedoc.json +0 -49
- /package/dist/common/assets/{browser_scripts.js → assets/browser_scripts.js} +0 -0
|
@@ -0,0 +1,794 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getExecutionContext
|
|
3
|
+
} from "./chunk-W4UX6G4X.mjs";
|
|
4
|
+
import {
|
|
5
|
+
backendFunctionsTokenManager,
|
|
6
|
+
callBackendFunctionWithToken
|
|
7
|
+
} from "./chunk-7YL2JUTE.mjs";
|
|
8
|
+
import {
|
|
9
|
+
API_KEY_ENV_VAR_KEY,
|
|
10
|
+
PROJECT_ID_ENV_VAR_KEY,
|
|
11
|
+
WORKSPACE_ID_ENV_VAR_KEY
|
|
12
|
+
} from "./chunk-FGV5T6SI.mjs";
|
|
13
|
+
import {
|
|
14
|
+
captchaSolverSettingsSchema,
|
|
15
|
+
settingsSchema
|
|
16
|
+
} from "./chunk-XOAZ2MGA.mjs";
|
|
17
|
+
|
|
18
|
+
// src/runtime/extendTimeout.ts
|
|
19
|
+
function extendTimeout() {
|
|
20
|
+
const context = getExecutionContext();
|
|
21
|
+
if (!context) {
|
|
22
|
+
throw new Error("extendTimeout failed due to an internal error.");
|
|
23
|
+
}
|
|
24
|
+
const { timeoutInfo } = context;
|
|
25
|
+
if (!timeoutInfo) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (timeoutInfo.extendTimeoutCallback !== void 0) {
|
|
29
|
+
void timeoutInfo.extendTimeoutCallback().catch(() => void 0);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// src/runtime/extendPayload.ts
|
|
34
|
+
function extendPayload(payload) {
|
|
35
|
+
const context = getExecutionContext();
|
|
36
|
+
if (!context) {
|
|
37
|
+
throw new Error("extendPayload failed due to an internal error.");
|
|
38
|
+
}
|
|
39
|
+
const items = Array.isArray(payload) ? payload : [payload];
|
|
40
|
+
if (!context.extendedPayloads) {
|
|
41
|
+
context.extendedPayloads = [...items];
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
context?.extendedPayloads.push(...items);
|
|
45
|
+
extendTimeout();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/runtime/attemptStore.ts
|
|
49
|
+
var attemptStore = Object.freeze({
|
|
50
|
+
get: (key) => {
|
|
51
|
+
const context = getExecutionContext();
|
|
52
|
+
return context?.store ? context.store[key] : void 0;
|
|
53
|
+
},
|
|
54
|
+
set: (key, value) => {
|
|
55
|
+
const context = getExecutionContext();
|
|
56
|
+
if (!context) {
|
|
57
|
+
throw new Error("store.set failed due to an internal error.");
|
|
58
|
+
}
|
|
59
|
+
if (!context.store) {
|
|
60
|
+
context.store = {};
|
|
61
|
+
}
|
|
62
|
+
context.store[key] = value;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// src/runtime/persistentStore.ts
|
|
67
|
+
import { z } from "zod";
|
|
68
|
+
var forbiddenCharacters = /[:#]/g;
|
|
69
|
+
var keySchema = z.string().min(1, "Key must be at least 1 character long").refine(
|
|
70
|
+
(key) => (key.match(forbiddenCharacters)?.length ?? 0) === 0,
|
|
71
|
+
'Key cannot contain the following characters: ":" or "#"'
|
|
72
|
+
);
|
|
73
|
+
var persistentStore = Object.freeze({
|
|
74
|
+
get: async (key) => {
|
|
75
|
+
const parsedKey = keySchema.parse(key);
|
|
76
|
+
const response = await callBackendFunctionWithToken(
|
|
77
|
+
`kv-store/${parsedKey}`,
|
|
78
|
+
{
|
|
79
|
+
method: "GET"
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
const json = await response.json();
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
throw new Error(json.message);
|
|
85
|
+
}
|
|
86
|
+
return json.value;
|
|
87
|
+
},
|
|
88
|
+
set: async (key, value) => {
|
|
89
|
+
const keyResult = keySchema.parse(key);
|
|
90
|
+
const response = await callBackendFunctionWithToken(
|
|
91
|
+
`kv-store/${keyResult}`,
|
|
92
|
+
{
|
|
93
|
+
method: "PUT",
|
|
94
|
+
body: JSON.stringify(value),
|
|
95
|
+
headers: {
|
|
96
|
+
"Content-Type": "application/json"
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
const json = await response.json();
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
throw new Error(json.message);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// src/runtime/getAuthSessionParameters.ts
|
|
108
|
+
async function getAuthSessionParameters() {
|
|
109
|
+
const context = getExecutionContext();
|
|
110
|
+
if (!context) {
|
|
111
|
+
throw new Error(
|
|
112
|
+
"getAuthSessionParameters failed due to an internal error (context was not found)."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const { getAuthSessionParameters: getAuthSessionParameters2 } = context;
|
|
116
|
+
if (!getAuthSessionParameters2) {
|
|
117
|
+
throw new Error(
|
|
118
|
+
"getAuthSessionParameters failed due to an internal error (helper was not found on context)."
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return await getAuthSessionParameters2();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/runtime/runInfo.ts
|
|
125
|
+
function runInfo() {
|
|
126
|
+
const context = getExecutionContext();
|
|
127
|
+
if (!context) {
|
|
128
|
+
return {
|
|
129
|
+
runEnvironment: "IDE" /* IDE */
|
|
130
|
+
// runType: RunType.SYNC,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
const { extendedPayloads: _extendedPayloads, ...rest } = context;
|
|
134
|
+
return rest;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// src/runtime/RunError.ts
|
|
138
|
+
var RunError = class _RunError extends Error {
|
|
139
|
+
constructor(message, options) {
|
|
140
|
+
super(message);
|
|
141
|
+
this.message = message;
|
|
142
|
+
this.name = "USER_GENERATED_ERROR";
|
|
143
|
+
this.options = options ?? {
|
|
144
|
+
retryable: false
|
|
145
|
+
};
|
|
146
|
+
Object.setPrototypeOf(this, _RunError.prototype);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
new RunError("", {});
|
|
150
|
+
|
|
151
|
+
// src/common/extension/intunedExtensionServer.ts
|
|
152
|
+
import fastify from "fastify";
|
|
153
|
+
|
|
154
|
+
// src/common/extension/types.ts
|
|
155
|
+
import { z as z2 } from "zod";
|
|
156
|
+
var captchaTypeSchema = z2.enum([
|
|
157
|
+
"aws",
|
|
158
|
+
"cloudflare",
|
|
159
|
+
"customcaptcha",
|
|
160
|
+
"funcaptcha",
|
|
161
|
+
"geetest",
|
|
162
|
+
"hcaptcha",
|
|
163
|
+
"lemincaptcha",
|
|
164
|
+
"recaptcha",
|
|
165
|
+
"textcaptcha"
|
|
166
|
+
]);
|
|
167
|
+
var captchaStatusSchema = z2.enum([
|
|
168
|
+
"attached",
|
|
169
|
+
"solving",
|
|
170
|
+
"solved",
|
|
171
|
+
"error",
|
|
172
|
+
"detached"
|
|
173
|
+
]);
|
|
174
|
+
var captchaErrorCodeSchema = z2.enum([
|
|
175
|
+
"HIT_LIMIT",
|
|
176
|
+
"MAX_RETRIES",
|
|
177
|
+
"UNEXPECTED_SERVER_RESPONSE",
|
|
178
|
+
"UNEXPECTED_ERROR"
|
|
179
|
+
]);
|
|
180
|
+
var captchaErrorSchema = z2.object({
|
|
181
|
+
code: captchaErrorCodeSchema,
|
|
182
|
+
error: z2.unknown().optional()
|
|
183
|
+
});
|
|
184
|
+
var captchaBaseSchema = z2.object({
|
|
185
|
+
id: z2.string().min(1),
|
|
186
|
+
tabId: z2.number().int().positive(),
|
|
187
|
+
type: captchaTypeSchema,
|
|
188
|
+
retryCount: z2.number().int().nonnegative().optional()
|
|
189
|
+
});
|
|
190
|
+
var captchaNonErrorSchema = captchaBaseSchema.extend({
|
|
191
|
+
status: captchaStatusSchema.exclude(["error"])
|
|
192
|
+
});
|
|
193
|
+
var captchaErrorStatusSchema = captchaBaseSchema.extend({
|
|
194
|
+
status: z2.literal("error"),
|
|
195
|
+
error: captchaErrorSchema
|
|
196
|
+
});
|
|
197
|
+
var captchaSchema = z2.discriminatedUnion("status", [
|
|
198
|
+
captchaBaseSchema.extend({
|
|
199
|
+
status: z2.literal("attached")
|
|
200
|
+
}),
|
|
201
|
+
captchaBaseSchema.extend({
|
|
202
|
+
status: z2.literal("solving")
|
|
203
|
+
}),
|
|
204
|
+
captchaBaseSchema.extend({
|
|
205
|
+
status: z2.literal("solved")
|
|
206
|
+
}),
|
|
207
|
+
captchaBaseSchema.extend({
|
|
208
|
+
status: z2.literal("detached")
|
|
209
|
+
}),
|
|
210
|
+
captchaErrorStatusSchema
|
|
211
|
+
]);
|
|
212
|
+
var CaptchaSolveError = class extends Error {
|
|
213
|
+
constructor(message, error) {
|
|
214
|
+
super(message);
|
|
215
|
+
this.error = error;
|
|
216
|
+
this.name = "CaptchaSolveError";
|
|
217
|
+
}
|
|
218
|
+
};
|
|
219
|
+
var TimeoutError = class extends Error {
|
|
220
|
+
constructor(message) {
|
|
221
|
+
super(message);
|
|
222
|
+
this.name = "TimeoutError";
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/commands/common/utils/fileUtils.ts
|
|
227
|
+
import * as path from "path";
|
|
228
|
+
import * as fs from "fs-extra";
|
|
229
|
+
import dotenv from "dotenv";
|
|
230
|
+
dotenv.config();
|
|
231
|
+
function getFullPathInProject(...paths) {
|
|
232
|
+
return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// src/commands/common/utils/settings.ts
|
|
236
|
+
import { readFile } from "fs/promises";
|
|
237
|
+
async function getSettings() {
|
|
238
|
+
const settingsFilePath = getFullPathInProject("Intuned.json");
|
|
239
|
+
const settings = await readFile(settingsFilePath, { encoding: "utf-8" });
|
|
240
|
+
if (settings) {
|
|
241
|
+
const parsed = settingsSchema.safeParse(JSON.parse(settings));
|
|
242
|
+
if (parsed.success) {
|
|
243
|
+
return parsed.data;
|
|
244
|
+
} else {
|
|
245
|
+
throw new Error(parsed.error.message);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
authSessions: { enabled: false },
|
|
250
|
+
stealthMode: { enabled: false }
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/common/extension/extensionsHelpers.ts
|
|
255
|
+
import path2 from "path";
|
|
256
|
+
import { writeFile } from "fs/promises";
|
|
257
|
+
import { getPort } from "portfinder";
|
|
258
|
+
var INTUNED_WORKER = "intunedWorker.js";
|
|
259
|
+
var INTUNED_EXTENSION_SETTINGS_FILE_NAME = "intunedSettings.json";
|
|
260
|
+
var captchaSolverSettings = null;
|
|
261
|
+
async function getIntunedCaptchaExtensionPort() {
|
|
262
|
+
if (process.env.INTUNED_CAPTCHA_EXTENSION_PORT) {
|
|
263
|
+
return parseInt(process.env.INTUNED_CAPTCHA_EXTENSION_PORT, 10);
|
|
264
|
+
}
|
|
265
|
+
return await getPort({});
|
|
266
|
+
}
|
|
267
|
+
async function resolveCaptchaSolverSettings(input) {
|
|
268
|
+
const parsed = captchaSolverSettingsSchema.parse(input || {});
|
|
269
|
+
if (!parsed.port) {
|
|
270
|
+
parsed.port = await getIntunedCaptchaExtensionPort();
|
|
271
|
+
}
|
|
272
|
+
return parsed;
|
|
273
|
+
}
|
|
274
|
+
function isIntunedExtensionLoaded() {
|
|
275
|
+
return !!getIntunedExtensionPath();
|
|
276
|
+
}
|
|
277
|
+
function buildExtensionsList() {
|
|
278
|
+
const extensionsList = [];
|
|
279
|
+
if (isIntunedExtensionLoaded()) {
|
|
280
|
+
const intunedExtensionPath = getIntunedExtensionPath();
|
|
281
|
+
extensionsList.push(intunedExtensionPath);
|
|
282
|
+
}
|
|
283
|
+
return extensionsList;
|
|
284
|
+
}
|
|
285
|
+
function getIntunedExtensionPath() {
|
|
286
|
+
return process.env.INTUNED_EXTENSION_PATH;
|
|
287
|
+
}
|
|
288
|
+
async function isIntunedExtensionEnabled() {
|
|
289
|
+
const path3 = getIntunedExtensionPath();
|
|
290
|
+
if (!path3) {
|
|
291
|
+
return false;
|
|
292
|
+
}
|
|
293
|
+
const captchaSolverSettings2 = await getIntunedCaptchaSolverSettings();
|
|
294
|
+
return captchaSolverSettings2.enabled;
|
|
295
|
+
}
|
|
296
|
+
async function getIntunedExtensionWorker(context) {
|
|
297
|
+
if (!await isIntunedExtensionEnabled()) {
|
|
298
|
+
return null;
|
|
299
|
+
}
|
|
300
|
+
let attemptCount = 0;
|
|
301
|
+
while (attemptCount < 4) {
|
|
302
|
+
const intunedServiceWorker = context.serviceWorkers().find((serviceWorker) => serviceWorker.url().includes(INTUNED_WORKER));
|
|
303
|
+
if (intunedServiceWorker) {
|
|
304
|
+
return intunedServiceWorker;
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
await context.waitForEvent("serviceworker", { timeout: 3e3 });
|
|
308
|
+
} catch (err) {
|
|
309
|
+
console.log(`Error accessing service workers (attempt ${attemptCount})`);
|
|
310
|
+
}
|
|
311
|
+
attemptCount++;
|
|
312
|
+
}
|
|
313
|
+
console.error("Failed to get intuned worker after 5 attmepts");
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
async function getIntunedExtensionSettings(captchaSolverSettings2) {
|
|
317
|
+
const [domain, workspaceId, projectId] = [
|
|
318
|
+
process.env.FUNCTIONS_DOMAIN,
|
|
319
|
+
process.env[WORKSPACE_ID_ENV_VAR_KEY],
|
|
320
|
+
process.env.INTUNED_INTEGRATION_ID ?? process.env[PROJECT_ID_ENV_VAR_KEY]
|
|
321
|
+
];
|
|
322
|
+
if (!domain || !workspaceId || !projectId) {
|
|
323
|
+
const missingEnvVars = [
|
|
324
|
+
domain && "FUNCTIONS_DOMAIN",
|
|
325
|
+
workspaceId && WORKSPACE_ID_ENV_VAR_KEY,
|
|
326
|
+
projectId && `INTUNED_INTEGRATION_ID OR ${PROJECT_ID_ENV_VAR_KEY}`
|
|
327
|
+
];
|
|
328
|
+
throw new Error(
|
|
329
|
+
`Missing required environment variables: ${missingEnvVars}`
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
const authentication = (() => {
|
|
333
|
+
if (process.env.INTUNED_API_KEY) {
|
|
334
|
+
return { type: "apiKey", apiKey: process.env.INTUNED_API_KEY };
|
|
335
|
+
}
|
|
336
|
+
if (process.env.INTUNED_BASIC_AUTH_USERNAME && process.env.INTUNED_BASIC_AUTH_PASSWORD) {
|
|
337
|
+
const credentials = `${process.env.INTUNED_BASIC_AUTH_USERNAME}:${process.env.INTUNED_BASIC_AUTH_PASSWORD}`;
|
|
338
|
+
const token = Buffer.from(credentials, "utf-8").toString("base64");
|
|
339
|
+
return { type: "basic", token };
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
type: "bearer",
|
|
343
|
+
token: backendFunctionsTokenManager.token
|
|
344
|
+
};
|
|
345
|
+
})();
|
|
346
|
+
const baseUrl = process.env.INTUNED_API_BASE_URL ?? domain;
|
|
347
|
+
return {
|
|
348
|
+
...captchaSolverSettings2,
|
|
349
|
+
workspaceId,
|
|
350
|
+
projectId,
|
|
351
|
+
baseUrl,
|
|
352
|
+
authentication
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
async function getIntunedCaptchaSolverSettings() {
|
|
356
|
+
if (captchaSolverSettings) {
|
|
357
|
+
return captchaSolverSettings;
|
|
358
|
+
}
|
|
359
|
+
const settings = await getSettings();
|
|
360
|
+
captchaSolverSettings = await resolveCaptchaSolverSettings(
|
|
361
|
+
settings.captchaSolver
|
|
362
|
+
);
|
|
363
|
+
return captchaSolverSettings;
|
|
364
|
+
}
|
|
365
|
+
async function setupIntunedExtension() {
|
|
366
|
+
if (!await isIntunedExtensionEnabled()) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const intunedExtensionPath = getIntunedExtensionPath();
|
|
370
|
+
const intunedExtensionSettingsPath = path2.join(
|
|
371
|
+
intunedExtensionPath,
|
|
372
|
+
INTUNED_EXTENSION_SETTINGS_FILE_NAME
|
|
373
|
+
);
|
|
374
|
+
const captchaSolverSettings2 = await getIntunedCaptchaSolverSettings();
|
|
375
|
+
await setupIntunedExtensionServer(captchaSolverSettings2);
|
|
376
|
+
const captchaSolverSettingsWithRunContext = await getIntunedExtensionSettings(
|
|
377
|
+
captchaSolverSettings2
|
|
378
|
+
);
|
|
379
|
+
await writeFile(
|
|
380
|
+
intunedExtensionSettingsPath,
|
|
381
|
+
JSON.stringify(captchaSolverSettingsWithRunContext)
|
|
382
|
+
);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// src/common/extension/intunedExtensionServer.ts
|
|
386
|
+
var TabCaptchaState = class {
|
|
387
|
+
constructor(tabId) {
|
|
388
|
+
this.tabId = tabId;
|
|
389
|
+
this.captchasById = /* @__PURE__ */ new Map();
|
|
390
|
+
this.subscribers = new Array();
|
|
391
|
+
}
|
|
392
|
+
subscribe(handler) {
|
|
393
|
+
this.subscribers.push(handler);
|
|
394
|
+
}
|
|
395
|
+
unsubscribe(handler, status) {
|
|
396
|
+
const index = this.subscribers.findIndex(
|
|
397
|
+
(subscriber) => subscriber.handler === handler && (subscriber.status === status || !status)
|
|
398
|
+
);
|
|
399
|
+
if (index !== -1) {
|
|
400
|
+
this.subscribers.splice(index, 1);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
getCaptchas() {
|
|
404
|
+
return [...this.captchasById.values()];
|
|
405
|
+
}
|
|
406
|
+
async upsertCaptcha(captcha) {
|
|
407
|
+
this.captchasById.set(captcha.id, captcha);
|
|
408
|
+
for (const subscriber of this.subscribers) {
|
|
409
|
+
if (!subscriber.status || subscriber.status === captcha.status) {
|
|
410
|
+
await subscriber.handler(captcha);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
var ExtensionServer = class {
|
|
416
|
+
constructor() {
|
|
417
|
+
this.app = null;
|
|
418
|
+
this.tabs = /* @__PURE__ */ new Map();
|
|
419
|
+
}
|
|
420
|
+
getOrCreateTab(tabId) {
|
|
421
|
+
const existing = this.tabs.get(tabId);
|
|
422
|
+
if (existing) return existing;
|
|
423
|
+
const created = new TabCaptchaState(tabId);
|
|
424
|
+
this.tabs.set(tabId, created);
|
|
425
|
+
return created;
|
|
426
|
+
}
|
|
427
|
+
async handleUpsertCaptcha(captcha) {
|
|
428
|
+
const tab = this.getOrCreateTab(captcha.tabId);
|
|
429
|
+
await tab.upsertCaptcha(captcha);
|
|
430
|
+
}
|
|
431
|
+
async start({
|
|
432
|
+
port,
|
|
433
|
+
host = "0.0.0.0"
|
|
434
|
+
}) {
|
|
435
|
+
if (this.app) {
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
this.app = fastify({
|
|
439
|
+
logger: false,
|
|
440
|
+
bodyLimit: 1e6
|
|
441
|
+
});
|
|
442
|
+
this.app.post("/state", async (request, reply) => {
|
|
443
|
+
try {
|
|
444
|
+
const result = captchaSchema.safeParse(request.body);
|
|
445
|
+
if (!result.success) {
|
|
446
|
+
return reply.code(400).send({
|
|
447
|
+
error: "Invalid captcha payload",
|
|
448
|
+
details: result.error.flatten().fieldErrors
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
await this.handleUpsertCaptcha(result.data);
|
|
452
|
+
return reply.code(200).send({});
|
|
453
|
+
} catch (error) {
|
|
454
|
+
console.error("Error processing captcha state update:", error);
|
|
455
|
+
return reply.code(500).send({
|
|
456
|
+
error: "Internal server error",
|
|
457
|
+
message: error?.message ?? String(error)
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
this.app.setNotFoundHandler((_request, reply) => {
|
|
462
|
+
return reply.code(404).send({ error: "Not found" });
|
|
463
|
+
});
|
|
464
|
+
await this.app.listen({
|
|
465
|
+
port,
|
|
466
|
+
host
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
async stop() {
|
|
470
|
+
if (!this.app) return;
|
|
471
|
+
const toClose = this.app;
|
|
472
|
+
this.app = null;
|
|
473
|
+
await toClose.close();
|
|
474
|
+
}
|
|
475
|
+
async getCaptchas(page, status) {
|
|
476
|
+
const tabId = await getTabId(page);
|
|
477
|
+
const tab = this.tabs.get(tabId);
|
|
478
|
+
if (!tab) return [];
|
|
479
|
+
const captchas = tab.getCaptchas();
|
|
480
|
+
if (!status) return captchas;
|
|
481
|
+
return captchas.filter((c) => c.status === status && c.tabId === tabId);
|
|
482
|
+
}
|
|
483
|
+
async subscribe(page, handler, status) {
|
|
484
|
+
const tabId = await getTabId(page);
|
|
485
|
+
const tab = this.getOrCreateTab(tabId);
|
|
486
|
+
tab.subscribe({ handler, status });
|
|
487
|
+
}
|
|
488
|
+
async unsubscribe(page, handler, status) {
|
|
489
|
+
const tabId = await getTabId(page);
|
|
490
|
+
const tab = this.tabs.get(tabId);
|
|
491
|
+
if (!tab) return;
|
|
492
|
+
tab.unsubscribe(handler, status);
|
|
493
|
+
}
|
|
494
|
+
removeTab(tabId) {
|
|
495
|
+
this.tabs.delete(tabId);
|
|
496
|
+
}
|
|
497
|
+
async getTabId(page) {
|
|
498
|
+
return await getTabId(page);
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
var extensionServerSingleton = null;
|
|
502
|
+
function getIntunedExtensionServer() {
|
|
503
|
+
if (!extensionServerSingleton) {
|
|
504
|
+
throw new Error("Intuned Extension Server is not initialized.");
|
|
505
|
+
}
|
|
506
|
+
return extensionServerSingleton;
|
|
507
|
+
}
|
|
508
|
+
async function setupIntunedExtensionServer(captchaSolverSettings2) {
|
|
509
|
+
if (!captchaSolverSettings2) {
|
|
510
|
+
captchaSolverSettings2 = await resolveCaptchaSolverSettings();
|
|
511
|
+
}
|
|
512
|
+
if (!extensionServerSingleton) {
|
|
513
|
+
extensionServerSingleton = new ExtensionServer();
|
|
514
|
+
}
|
|
515
|
+
await extensionServerSingleton.start({
|
|
516
|
+
port: captchaSolverSettings2.port ?? 9e3
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
async function cleanIntunedExtensionServer() {
|
|
520
|
+
if (extensionServerSingleton) {
|
|
521
|
+
await extensionServerSingleton.stop();
|
|
522
|
+
extensionServerSingleton = null;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
var TAB_ID_CACHE_KEY = "__INTUNED_CACHED_TAB_ID__";
|
|
526
|
+
async function getTabId(page) {
|
|
527
|
+
const cached = page[TAB_ID_CACHE_KEY];
|
|
528
|
+
if (cached !== void 0 && typeof cached === "number") {
|
|
529
|
+
return cached;
|
|
530
|
+
}
|
|
531
|
+
let tabId;
|
|
532
|
+
try {
|
|
533
|
+
tabId = await page.evaluate("window.__INTUNED_TAB_ID__", { timeout: 100 });
|
|
534
|
+
} catch {
|
|
535
|
+
await page.waitForFunction("window.__INTUNED_TAB_ID__ !== undefined", {
|
|
536
|
+
timeout: 15e3
|
|
537
|
+
});
|
|
538
|
+
tabId = await page.evaluate("window.__INTUNED_TAB_ID__");
|
|
539
|
+
}
|
|
540
|
+
const numericTabId = Number(tabId);
|
|
541
|
+
page[TAB_ID_CACHE_KEY] = numericTabId;
|
|
542
|
+
return numericTabId;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// src/runtime/captcha.ts
|
|
546
|
+
async function withWaitForCaptchaSolve(callback, options) {
|
|
547
|
+
const {
|
|
548
|
+
page,
|
|
549
|
+
timeoutInMs = 1e4,
|
|
550
|
+
settleDurationMs = 5e3,
|
|
551
|
+
waitForNetworkSettled = true
|
|
552
|
+
} = options;
|
|
553
|
+
console.error(
|
|
554
|
+
`Starting captcha solve wait (timeout=${timeoutInMs}ms, settleDuration=${settleDurationMs}ms, waitForNetworkSettled=${waitForNetworkSettled})`
|
|
555
|
+
);
|
|
556
|
+
const extensionServer = getIntunedExtensionServer();
|
|
557
|
+
let settledResolve = null;
|
|
558
|
+
let settledPromise = new Promise((resolve2) => {
|
|
559
|
+
settledResolve = resolve2;
|
|
560
|
+
});
|
|
561
|
+
let isTimeout = false;
|
|
562
|
+
let captchasAppeared = false;
|
|
563
|
+
let error = void 0;
|
|
564
|
+
let actionDone = false;
|
|
565
|
+
const getPendingCaptchas = async () => await extensionServer.getCaptchas(page, "solving");
|
|
566
|
+
const hasNoPendingCaptchas = async () => !captchasAppeared || (await getPendingCaptchas()).length === 0;
|
|
567
|
+
const maybeSettle = async () => {
|
|
568
|
+
if (await hasNoPendingCaptchas()) {
|
|
569
|
+
settledResolve?.();
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
const onCaptchaUpdate = async (_captcha) => {
|
|
573
|
+
const solvingCaptchas = await extensionServer.getCaptchas(page, "solving");
|
|
574
|
+
const errorCaptchas = await extensionServer.getCaptchas(page, "error");
|
|
575
|
+
console.error(
|
|
576
|
+
`Captcha update received: solving=${solvingCaptchas.length}, errors=${errorCaptchas.length}`
|
|
577
|
+
);
|
|
578
|
+
if (solvingCaptchas.length > 0) {
|
|
579
|
+
captchasAppeared = true;
|
|
580
|
+
console.error(
|
|
581
|
+
`Captchas detected: ${solvingCaptchas.map((c) => c.id).join(", ")}`
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
if (errorCaptchas.length > 0) {
|
|
585
|
+
error = errorCaptchas[0].error;
|
|
586
|
+
console.error(`Captcha error detected: ${error?.code}`);
|
|
587
|
+
await maybeSettle();
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
if (solvingCaptchas.length === 0) {
|
|
591
|
+
console.error("No pending captchas, settling");
|
|
592
|
+
await maybeSettle();
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
const result = await callback(page);
|
|
596
|
+
actionDone = true;
|
|
597
|
+
if (waitForNetworkSettled) {
|
|
598
|
+
try {
|
|
599
|
+
await page.waitForLoadState("networkidle");
|
|
600
|
+
} catch (err) {
|
|
601
|
+
console.error(`Failed to wait for networkidle. Error: ${err}`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const timeoutPromise = new Promise((resolve2) => {
|
|
605
|
+
setTimeout(() => {
|
|
606
|
+
isTimeout = true;
|
|
607
|
+
console.error("Captcha solve timeout reached");
|
|
608
|
+
settledResolve?.();
|
|
609
|
+
resolve2();
|
|
610
|
+
}, timeoutInMs);
|
|
611
|
+
});
|
|
612
|
+
await extensionServer.subscribe(page, onCaptchaUpdate);
|
|
613
|
+
try {
|
|
614
|
+
const initialPending = await getPendingCaptchas();
|
|
615
|
+
console.error(`Found ${initialPending.length} ongoing captchas`);
|
|
616
|
+
if (initialPending.length > 0) {
|
|
617
|
+
captchasAppeared = true;
|
|
618
|
+
}
|
|
619
|
+
await maybeSettle();
|
|
620
|
+
let shouldContinue = true;
|
|
621
|
+
while (shouldContinue) {
|
|
622
|
+
await Promise.race([settledPromise, timeoutPromise]);
|
|
623
|
+
console.error(
|
|
624
|
+
`Settled event received, waiting ${settleDurationMs}ms before checking`
|
|
625
|
+
);
|
|
626
|
+
await new Promise((r) => setTimeout(r, settleDurationMs));
|
|
627
|
+
if (error) {
|
|
628
|
+
console.error(`Raising captcha error: ${error.code}`);
|
|
629
|
+
throw new CaptchaSolveError(
|
|
630
|
+
`CAPTCHA Solve Error: ${error.code}`,
|
|
631
|
+
error
|
|
632
|
+
);
|
|
633
|
+
}
|
|
634
|
+
const noPendingCaptchas = await hasNoPendingCaptchas();
|
|
635
|
+
const pending = await getPendingCaptchas();
|
|
636
|
+
console.error(
|
|
637
|
+
`Check point: actionDone=${actionDone}, noPendingCaptchas=${noPendingCaptchas}, isTimeout=${isTimeout}, pendingCount=${pending.length}`
|
|
638
|
+
);
|
|
639
|
+
if (actionDone && noPendingCaptchas || isTimeout) {
|
|
640
|
+
if (isTimeout && !noPendingCaptchas) {
|
|
641
|
+
console.error(`Timeout with ${pending.length} pending captchas`);
|
|
642
|
+
throw new TimeoutError(
|
|
643
|
+
"CAPTCHA Solve timed out with pending captchas."
|
|
644
|
+
);
|
|
645
|
+
}
|
|
646
|
+
console.error("Captcha solve completed successfully");
|
|
647
|
+
shouldContinue = false;
|
|
648
|
+
} else {
|
|
649
|
+
console.error(
|
|
650
|
+
`Still have ${pending.length} pending captchas, waiting for more updates`
|
|
651
|
+
);
|
|
652
|
+
settledPromise = new Promise((resolve2) => {
|
|
653
|
+
settledResolve = resolve2;
|
|
654
|
+
});
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return result;
|
|
658
|
+
} finally {
|
|
659
|
+
await extensionServer.unsubscribe(page, onCaptchaUpdate);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
async function waitForCaptchaSolve(page, {
|
|
663
|
+
timeoutInMs = 1e4,
|
|
664
|
+
settleDurationMs = 5e3
|
|
665
|
+
} = {}) {
|
|
666
|
+
await withWaitForCaptchaSolve(async () => void 0, {
|
|
667
|
+
page,
|
|
668
|
+
timeoutInMs,
|
|
669
|
+
settleDurationMs,
|
|
670
|
+
waitForNetworkSettled: false
|
|
671
|
+
});
|
|
672
|
+
}
|
|
673
|
+
async function removeCaptchaEventListener(page, status, f) {
|
|
674
|
+
const extensionServer = getIntunedExtensionServer();
|
|
675
|
+
await extensionServer.unsubscribe(page, f, status);
|
|
676
|
+
}
|
|
677
|
+
async function onCaptchaEvent(page, status, f) {
|
|
678
|
+
const extensionServer = getIntunedExtensionServer();
|
|
679
|
+
await extensionServer.subscribe(page, f, status);
|
|
680
|
+
}
|
|
681
|
+
async function onceCaptchaEvent(page, status, f) {
|
|
682
|
+
const extensionServer = getIntunedExtensionServer();
|
|
683
|
+
const oneTimeHandler = async (captcha) => {
|
|
684
|
+
await extensionServer.unsubscribe(page, oneTimeHandler, status);
|
|
685
|
+
await f(captcha);
|
|
686
|
+
};
|
|
687
|
+
await extensionServer.subscribe(page, oneTimeHandler, status);
|
|
688
|
+
}
|
|
689
|
+
async function setAutoSolve(context, enabled) {
|
|
690
|
+
const worker = await getIntunedExtensionWorker(context);
|
|
691
|
+
if (!worker) {
|
|
692
|
+
if (!enabled) {
|
|
693
|
+
return;
|
|
694
|
+
}
|
|
695
|
+
throw new Error("Intuned service worker not found");
|
|
696
|
+
}
|
|
697
|
+
await worker.evaluate(
|
|
698
|
+
`
|
|
699
|
+
(enabled) => new Promise((resolve, reject) => {
|
|
700
|
+
const updateSettings = () => {
|
|
701
|
+
if (chrome?.storage?.local) {
|
|
702
|
+
chrome.storage.local.get('settings', (result) => {
|
|
703
|
+
if (chrome.runtime.lastError) {
|
|
704
|
+
reject(new Error(chrome.runtime.lastError.message));
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
const settings = result.settings || {};
|
|
708
|
+
if (!settings.settings) {
|
|
709
|
+
settings.settings = {};
|
|
710
|
+
}
|
|
711
|
+
settings.settings.autoSolve = enabled;
|
|
712
|
+
chrome.storage.local.set({ settings }, () => {
|
|
713
|
+
if (chrome.runtime.lastError) {
|
|
714
|
+
reject(new Error(chrome.runtime.lastError.message));
|
|
715
|
+
} else {
|
|
716
|
+
resolve(true);
|
|
717
|
+
}
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
} else {
|
|
721
|
+
setTimeout(updateSettings, 50);
|
|
722
|
+
}
|
|
723
|
+
};
|
|
724
|
+
updateSettings();
|
|
725
|
+
})
|
|
726
|
+
`,
|
|
727
|
+
enabled
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
async function pauseCaptchaSolver(context) {
|
|
731
|
+
if (!await isIntunedExtensionEnabled()) {
|
|
732
|
+
throw new Error(
|
|
733
|
+
"Intuned extension is not enabled. Cannot pause captcha solver."
|
|
734
|
+
);
|
|
735
|
+
}
|
|
736
|
+
await setAutoSolve(context, false);
|
|
737
|
+
}
|
|
738
|
+
async function resumeCaptchaSolver(context) {
|
|
739
|
+
if (!await isIntunedExtensionEnabled()) {
|
|
740
|
+
throw new Error(
|
|
741
|
+
"Intuned extension is not enabled. Cannot resume captcha solver."
|
|
742
|
+
);
|
|
743
|
+
}
|
|
744
|
+
await setAutoSolve(context, true);
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// src/runtime/getAiGatewayConfig.ts
|
|
748
|
+
function getAiGatewayConfig() {
|
|
749
|
+
const baseUrl = `${backendFunctionsTokenManager.backendFunctionsBaseUrl}/intuned-ai-gateway`;
|
|
750
|
+
const apiKey = backendFunctionsTokenManager.token ?? process.env[API_KEY_ENV_VAR_KEY] ?? "";
|
|
751
|
+
return { baseUrl, apiKey };
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// src/runtime/downloadDirectory.ts
|
|
755
|
+
import { ensureDirSync } from "fs-extra";
|
|
756
|
+
function getDownloadDirectoryPath() {
|
|
757
|
+
const context = getExecutionContext();
|
|
758
|
+
if (!context) {
|
|
759
|
+
throw new Error("ExecutionContext not found");
|
|
760
|
+
}
|
|
761
|
+
const path3 = `/tmp/downloads/${context.runId}`;
|
|
762
|
+
ensureDirSync(path3, {
|
|
763
|
+
mode: 1533
|
|
764
|
+
});
|
|
765
|
+
return path3;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
export {
|
|
769
|
+
extendTimeout,
|
|
770
|
+
extendPayload,
|
|
771
|
+
attemptStore,
|
|
772
|
+
persistentStore,
|
|
773
|
+
getAuthSessionParameters,
|
|
774
|
+
runInfo,
|
|
775
|
+
RunError,
|
|
776
|
+
getFullPathInProject,
|
|
777
|
+
isIntunedExtensionLoaded,
|
|
778
|
+
buildExtensionsList,
|
|
779
|
+
isIntunedExtensionEnabled,
|
|
780
|
+
getIntunedExtensionWorker,
|
|
781
|
+
setupIntunedExtension,
|
|
782
|
+
setupIntunedExtensionServer,
|
|
783
|
+
cleanIntunedExtensionServer,
|
|
784
|
+
withWaitForCaptchaSolve,
|
|
785
|
+
waitForCaptchaSolve,
|
|
786
|
+
removeCaptchaEventListener,
|
|
787
|
+
onCaptchaEvent,
|
|
788
|
+
onceCaptchaEvent,
|
|
789
|
+
pauseCaptchaSolver,
|
|
790
|
+
resumeCaptchaSolver,
|
|
791
|
+
getAiGatewayConfig,
|
|
792
|
+
getDownloadDirectoryPath
|
|
793
|
+
};
|
|
794
|
+
//# sourceMappingURL=chunk-B3T6RXPC.mjs.map
|