@intuned/runtime 1.3.15 → 1.3.17
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/InterfaceTemplate/index.playwright.ts +1 -1
- package/WebTemplate.zip +0 -0
- package/dist/commands/api/run.js +4 -8
- package/dist/commands/auth-sessions/load.js +2 -2
- package/dist/commands/auth-sessions/run-check.js +5 -5
- package/dist/commands/auth-sessions/run-create.js +3 -3
- package/dist/commands/build.js +1 -1
- package/dist/commands/common/projectExclusions.js +1 -1
- package/dist/commands/common/tsNodeImport.js +9 -0
- package/dist/commands/interface/run.js +1 -1
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +1 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +1 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +2 -2
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
- package/dist/commands/intuned-cli/commands/authsession.command.js +1 -1
- package/dist/commands/intuned-cli/commands/authsession_record.command.js +1 -1
- 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/deploy.command.js +13 -9
- package/dist/commands/intuned-cli/commands/index.d.ts +2 -2
- package/dist/commands/intuned-cli/commands/index.js +15 -15
- package/dist/commands/intuned-cli/commands/{save.command.d.ts → provision.command.d.ts} +1 -1
- package/dist/commands/intuned-cli/commands/provision.command.js +50 -0
- package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +3 -3
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +2 -2
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +2 -2
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +2 -2
- package/dist/commands/intuned-cli/commands/types.d.ts +1 -1
- package/dist/commands/intuned-cli/commands/types.js +2 -2
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +6 -5
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +12 -11
- package/dist/commands/intuned-cli/controller/api.js +4 -1
- package/dist/commands/intuned-cli/controller/authSession.js +28 -28
- package/dist/commands/intuned-cli/controller/deploy.js +52 -10
- package/dist/commands/intuned-cli/controller/index.js +1 -1
- package/dist/commands/intuned-cli/controller/{save.d.ts → provision.d.ts} +5 -1
- package/dist/commands/intuned-cli/controller/provision.js +300 -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 +1 -0
- package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +1 -0
- package/dist/commands/intuned-cli/helpers/api.js +4 -7
- package/dist/commands/intuned-cli/helpers/auth.js +22 -19
- package/dist/commands/intuned-cli/helpers/backend.js +12 -4
- package/dist/commands/intuned-cli/helpers/context.js +2 -2
- 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/wrapper.js +12 -2
- package/dist/commands/intuned-cli/main.js +21 -8
- package/dist/commands/intuned-cli/types.d.ts +42 -13
- package/dist/commands/intuned-cli/types.js +12 -2
- package/dist/common/backendFunctions/getAuthSessionParameters.js +1 -1
- package/dist/common/extension/extensionsHelpers.d.ts +6 -3
- package/dist/common/extension/extensionsHelpers.js +45 -19
- package/dist/common/extension/intunedExtensionServer.d.ts +2 -5
- package/dist/common/extension/intunedExtensionServer.js +6 -9
- package/dist/common/intunedJson.js +2 -2
- package/dist/common/jwtTokenManager.js +2 -2
- package/dist/common/launchBrowser.d.ts +2 -0
- package/dist/common/launchBrowser.js +41 -3
- package/dist/common/playwrightContext.js +7 -1
- package/dist/common/runApi/errors.js +1 -1
- package/dist/common/runApi/index.js +2 -2
- package/dist/common/settingsSchema.d.ts +2 -1
- package/dist/runtime/captcha.js +25 -11
- package/package.json +5 -3
- package/dist/commands/intuned-cli/commands/init.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/init.command.js +0 -13
- package/dist/commands/intuned-cli/commands/save.command.js +0 -42
- package/dist/commands/intuned-cli/controller/save.js +0 -351
- /package/InterfaceTemplate/{utils.ts → __utils.ts} +0 -0
|
@@ -10,6 +10,8 @@ var _browser = require("./browser");
|
|
|
10
10
|
var _errors = require("./errors");
|
|
11
11
|
var _zod = require("zod");
|
|
12
12
|
var _validation = require("./validation");
|
|
13
|
+
var _pressAnyKey = _interopRequireDefault(require("press-any-key"));
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
15
|
function cliCommandWrapper(argsSchema, optionsSchema, fn) {
|
|
14
16
|
return async (...input) => {
|
|
15
17
|
let keepBrowserOpen = false;
|
|
@@ -61,6 +63,14 @@ function cliCommandWrapper(argsSchema, optionsSchema, fn) {
|
|
|
61
63
|
async function waitForUserInput() {
|
|
62
64
|
if (!(0, _browser.isCliBrowserLaunched)()) return;
|
|
63
65
|
if (!_terminal.terminalStdout.isTTY) return;
|
|
64
|
-
(0, _terminal.terminal)("Press
|
|
65
|
-
|
|
66
|
+
(0, _terminal.terminal)("Press any key to continue...");
|
|
67
|
+
try {
|
|
68
|
+
await (0, _pressAnyKey.default)("", {
|
|
69
|
+
ctrlC: "reject",
|
|
70
|
+
hideMessage: true
|
|
71
|
+
});
|
|
72
|
+
} catch {
|
|
73
|
+
throw new _errors.AbortedCLIError();
|
|
74
|
+
}
|
|
75
|
+
(0, _terminal.terminal)("\n");
|
|
66
76
|
}
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
4
4
|
var _constants = require("../../common/constants");
|
|
5
5
|
var _backend = require("./helpers/backend");
|
|
6
|
-
var
|
|
7
|
-
var _helpers = require("./helpers");
|
|
6
|
+
var _intunedJson = require("../../common/intunedJson");
|
|
8
7
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
9
10
|
require("../../common/binStartupScript");
|
|
10
11
|
_dotenv.default.config({
|
|
11
12
|
path: `.env`
|
|
@@ -15,9 +16,21 @@ process.env.RUN_ENVIRONMENT = "AUTHORING";
|
|
|
15
16
|
if (!process.env.FUNCTIONS_DOMAIN) {
|
|
16
17
|
process.env.FUNCTIONS_DOMAIN = (0, _backend.getBaseUrl)().replace(/\/$/, "");
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
void (async () => {
|
|
20
|
+
const intunedJson = await (0, _intunedJson.loadIntunedJson)();
|
|
21
|
+
if (intunedJson.isOk() && intunedJson.value.workspaceId) {
|
|
22
|
+
process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY] = intunedJson.value.workspaceId;
|
|
23
|
+
}
|
|
24
|
+
const {
|
|
25
|
+
program
|
|
26
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands")));
|
|
27
|
+
const {
|
|
28
|
+
withCLIContext
|
|
29
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require("./helpers/context")));
|
|
30
|
+
await withCLIContext(async () => {
|
|
31
|
+
program.configureHelp({
|
|
32
|
+
sortSubcommands: true
|
|
33
|
+
});
|
|
34
|
+
program.parse(process.argv);
|
|
35
|
+
});
|
|
36
|
+
})();
|
|
@@ -1,17 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const fileNodeSchema: z.ZodObject<{
|
|
3
|
+
file: z.ZodObject<{
|
|
4
|
+
contents: z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
|
|
5
|
+
}, "strip", z.ZodTypeAny, {
|
|
6
|
+
contents: (string | Uint8Array) & (string | Uint8Array | undefined);
|
|
7
|
+
}, {
|
|
8
|
+
contents: (string | Uint8Array) & (string | Uint8Array | undefined);
|
|
9
|
+
}>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
11
|
file: {
|
|
9
|
-
|
|
10
|
-
* The contents of the file, either as a UTF-8 string or as raw binary.
|
|
11
|
-
*/
|
|
12
|
-
contents: string | Uint8Array;
|
|
12
|
+
contents: (string | Uint8Array) & (string | Uint8Array | undefined);
|
|
13
13
|
};
|
|
14
|
-
}
|
|
14
|
+
}, {
|
|
15
|
+
file: {
|
|
16
|
+
contents: (string | Uint8Array) & (string | Uint8Array | undefined);
|
|
17
|
+
};
|
|
18
|
+
}>;
|
|
19
|
+
export type FileNode = z.infer<typeof fileNodeSchema>;
|
|
20
|
+
export type DirectoryNode = {
|
|
21
|
+
directory: {
|
|
22
|
+
[key: string]: FileNode | DirectoryNode;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const fileSystemTreeSchema: z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodType<DirectoryNode, z.ZodTypeDef, DirectoryNode>, z.ZodObject<{
|
|
26
|
+
file: z.ZodObject<{
|
|
27
|
+
contents: z.ZodUnion<[z.ZodString, z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>]>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
contents: (string | Uint8Array) & (string | Uint8Array | undefined);
|
|
30
|
+
}, {
|
|
31
|
+
contents: (string | Uint8Array) & (string | Uint8Array | undefined);
|
|
32
|
+
}>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
file: {
|
|
35
|
+
contents: (string | Uint8Array) & (string | Uint8Array | undefined);
|
|
36
|
+
};
|
|
37
|
+
}, {
|
|
38
|
+
file: {
|
|
39
|
+
contents: (string | Uint8Array) & (string | Uint8Array | undefined);
|
|
40
|
+
};
|
|
41
|
+
}>]>>;
|
|
42
|
+
export type FileSystemTree = z.infer<typeof fileSystemTreeSchema>;
|
|
15
43
|
export interface AuthCredentials {
|
|
16
44
|
workspaceId: string;
|
|
17
45
|
apiKey: string;
|
|
@@ -20,7 +48,7 @@ export declare enum ApiAuthSessionBehavior {
|
|
|
20
48
|
PERFORM_CHECK_AND_REFRESH = "PERFORM_CHECK_AND_REFRESH",
|
|
21
49
|
SKIP_CHECK_AND_REFRESH = "SKIP_CHECK_AND_REFRESH"
|
|
22
50
|
}
|
|
23
|
-
export declare const CHECK_FAILED_ERROR_MESSAGE = "
|
|
51
|
+
export declare const CHECK_FAILED_ERROR_MESSAGE = "AuthSession check failed";
|
|
24
52
|
export type AuthSessionType = "API" | "MANUAL";
|
|
25
53
|
export type AuthSessionMetadata = {
|
|
26
54
|
createdAt: string;
|
|
@@ -39,3 +67,4 @@ export interface SessionStorageState {
|
|
|
39
67
|
value: string;
|
|
40
68
|
}[];
|
|
41
69
|
}
|
|
70
|
+
export {};
|
|
@@ -3,10 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.CHECK_FAILED_ERROR_MESSAGE = exports.ApiAuthSessionBehavior = void 0;
|
|
6
|
+
exports.fileSystemTreeSchema = exports.CHECK_FAILED_ERROR_MESSAGE = exports.ApiAuthSessionBehavior = void 0;
|
|
7
|
+
var _zod = require("zod");
|
|
8
|
+
const fileNodeSchema = _zod.z.object({
|
|
9
|
+
file: _zod.z.object({
|
|
10
|
+
contents: _zod.z.union([_zod.z.string(), _zod.z.instanceof(Uint8Array)])
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
const directoryNodeSchema = _zod.z.lazy(() => _zod.z.object({
|
|
14
|
+
directory: fileSystemTreeSchema
|
|
15
|
+
}));
|
|
16
|
+
const fileSystemTreeSchema = exports.fileSystemTreeSchema = _zod.z.record(_zod.z.union([directoryNodeSchema, fileNodeSchema]));
|
|
7
17
|
let ApiAuthSessionBehavior = exports.ApiAuthSessionBehavior = function (ApiAuthSessionBehavior) {
|
|
8
18
|
ApiAuthSessionBehavior["PERFORM_CHECK_AND_REFRESH"] = "PERFORM_CHECK_AND_REFRESH";
|
|
9
19
|
ApiAuthSessionBehavior["SKIP_CHECK_AND_REFRESH"] = "SKIP_CHECK_AND_REFRESH";
|
|
10
20
|
return ApiAuthSessionBehavior;
|
|
11
21
|
}({});
|
|
12
|
-
const CHECK_FAILED_ERROR_MESSAGE = exports.CHECK_FAILED_ERROR_MESSAGE = "
|
|
22
|
+
const CHECK_FAILED_ERROR_MESSAGE = exports.CHECK_FAILED_ERROR_MESSAGE = "AuthSession check failed";
|
|
@@ -19,7 +19,7 @@ async function getAuthSessionParameters() {
|
|
|
19
19
|
}
|
|
20
20
|
const authSessionId = context.authSessionId;
|
|
21
21
|
if ((0, _isNil.default)(authSessionId)) {
|
|
22
|
-
throw new Error("
|
|
22
|
+
throw new Error("AuthSessions are not enabled");
|
|
23
23
|
}
|
|
24
24
|
const response = await (0, _jwtTokenManager.callBackendFunctionWithToken)(`auth-session/${authSessionId}/parameters`, {
|
|
25
25
|
method: "GET"
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as playwright from "playwright";
|
|
2
|
-
import { CaptchaSolverSettingsWithRunContext } from "../settingsSchema";
|
|
2
|
+
import { CaptchaSolverSettings, CaptchaSolverSettingsWithRunContext } from "../settingsSchema";
|
|
3
|
+
export declare function resolveCaptchaSolverSettings(input?: unknown): Promise<CaptchaSolverSettings>;
|
|
4
|
+
export declare function isIntunedExtensionLoaded(): boolean;
|
|
3
5
|
export declare function buildExtensionsList(): string[];
|
|
4
6
|
export declare function getIntunedExtensionPath(): string;
|
|
5
|
-
export declare function isIntunedExtensionEnabled(): boolean
|
|
7
|
+
export declare function isIntunedExtensionEnabled(): Promise<boolean>;
|
|
6
8
|
export declare function getIntunedExtensionWorker(context: playwright.BrowserContext): Promise<playwright.Worker | null>;
|
|
7
|
-
export declare function getIntunedExtensionSettings(): Promise<CaptchaSolverSettingsWithRunContext>;
|
|
9
|
+
export declare function getIntunedExtensionSettings(captchaSolverSettings: CaptchaSolverSettings): Promise<CaptchaSolverSettingsWithRunContext>;
|
|
10
|
+
export declare function getIntunedCaptchaSolverSettings(): Promise<CaptchaSolverSettings>;
|
|
8
11
|
export declare function setupIntunedExtension(): Promise<void>;
|
|
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.buildExtensionsList = buildExtensionsList;
|
|
7
|
+
exports.getIntunedCaptchaSolverSettings = getIntunedCaptchaSolverSettings;
|
|
7
8
|
exports.getIntunedExtensionPath = getIntunedExtensionPath;
|
|
8
9
|
exports.getIntunedExtensionSettings = getIntunedExtensionSettings;
|
|
9
10
|
exports.getIntunedExtensionWorker = getIntunedExtensionWorker;
|
|
10
11
|
exports.isIntunedExtensionEnabled = isIntunedExtensionEnabled;
|
|
12
|
+
exports.isIntunedExtensionLoaded = isIntunedExtensionLoaded;
|
|
13
|
+
exports.resolveCaptchaSolverSettings = resolveCaptchaSolverSettings;
|
|
11
14
|
exports.setupIntunedExtension = setupIntunedExtension;
|
|
12
15
|
var _settings = require("../../commands/common/utils/settings");
|
|
13
16
|
var _settingsSchema = require("../settingsSchema");
|
|
@@ -21,6 +24,20 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
|
|
|
21
24
|
const INTUNED_WORKER = "intunedWorker.js";
|
|
22
25
|
const INTUNED_EXTENSION_SETTINGS_FILE_NAME = "intunedSettings.json";
|
|
23
26
|
const INTUNED_CAPTCHA_EXTENSION_PORT_ENV_VAR = "INTUNED_CAPTCHA_EXTENSION_PORT";
|
|
27
|
+
let captchaSolverSettings = null;
|
|
28
|
+
async function getIntunedCaptchaExtensionPort() {
|
|
29
|
+
if (process.env.INTUNED_CAPTCHA_EXTENSION_PORT) {
|
|
30
|
+
return parseInt(process.env.INTUNED_CAPTCHA_EXTENSION_PORT, 10);
|
|
31
|
+
}
|
|
32
|
+
return await (0, _portfinder.getPort)({});
|
|
33
|
+
}
|
|
34
|
+
async function resolveCaptchaSolverSettings(input) {
|
|
35
|
+
const parsed = _settingsSchema.captchaSolverSettingsSchema.parse(input || {});
|
|
36
|
+
if (!parsed.port) {
|
|
37
|
+
parsed.port = await getIntunedCaptchaExtensionPort();
|
|
38
|
+
}
|
|
39
|
+
return parsed;
|
|
40
|
+
}
|
|
24
41
|
function getIntunedCaptchaExtensionPortFromEnv() {
|
|
25
42
|
const raw = process.env[INTUNED_CAPTCHA_EXTENSION_PORT_ENV_VAR];
|
|
26
43
|
if (!raw) return null;
|
|
@@ -30,9 +47,12 @@ function getIntunedCaptchaExtensionPortFromEnv() {
|
|
|
30
47
|
}
|
|
31
48
|
return parsed;
|
|
32
49
|
}
|
|
50
|
+
function isIntunedExtensionLoaded() {
|
|
51
|
+
return !!getIntunedExtensionPath();
|
|
52
|
+
}
|
|
33
53
|
function buildExtensionsList() {
|
|
34
54
|
const extensionsList = [];
|
|
35
|
-
if (
|
|
55
|
+
if (isIntunedExtensionLoaded()) {
|
|
36
56
|
const intunedExtensionPath = getIntunedExtensionPath();
|
|
37
57
|
extensionsList.push(intunedExtensionPath);
|
|
38
58
|
}
|
|
@@ -41,11 +61,16 @@ function buildExtensionsList() {
|
|
|
41
61
|
function getIntunedExtensionPath() {
|
|
42
62
|
return process.env.INTUNED_EXTENSION_PATH;
|
|
43
63
|
}
|
|
44
|
-
function isIntunedExtensionEnabled() {
|
|
45
|
-
|
|
64
|
+
async function isIntunedExtensionEnabled() {
|
|
65
|
+
const path = getIntunedExtensionPath();
|
|
66
|
+
if (!path) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
const captchaSolverSettings = await getIntunedCaptchaSolverSettings();
|
|
70
|
+
return captchaSolverSettings.enabled;
|
|
46
71
|
}
|
|
47
72
|
async function getIntunedExtensionWorker(context) {
|
|
48
|
-
if (!isIntunedExtensionEnabled()) {
|
|
73
|
+
if (!(await isIntunedExtensionEnabled())) {
|
|
49
74
|
return null;
|
|
50
75
|
}
|
|
51
76
|
let attemptCount = 0;
|
|
@@ -66,8 +91,7 @@ async function getIntunedExtensionWorker(context) {
|
|
|
66
91
|
console.error("Failed to get intuned worker after 5 attmepts");
|
|
67
92
|
return null;
|
|
68
93
|
}
|
|
69
|
-
async function getIntunedExtensionSettings() {
|
|
70
|
-
const settings = await (0, _settings.getSettings)();
|
|
94
|
+
async function getIntunedExtensionSettings(captchaSolverSettings) {
|
|
71
95
|
const [domain, workspaceId, projectId] = [process.env.FUNCTIONS_DOMAIN, process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY], process.env.INTUNED_INTEGRATION_ID ?? process.env[_constants.PROJECT_ID_ENV_VAR_KEY]];
|
|
72
96
|
if (!domain || !workspaceId || !projectId) {
|
|
73
97
|
const missingEnvVars = [domain && "FUNCTIONS_DOMAIN", workspaceId && _constants.WORKSPACE_ID_ENV_VAR_KEY, projectId && `INTUNED_INTEGRATION_ID OR ${_constants.PROJECT_ID_ENV_VAR_KEY}`];
|
|
@@ -94,28 +118,30 @@ async function getIntunedExtensionSettings() {
|
|
|
94
118
|
};
|
|
95
119
|
})();
|
|
96
120
|
const baseUrl = process.env.INTUNED_API_BASE_URL ?? domain;
|
|
97
|
-
const port = getIntunedCaptchaExtensionPortFromEnv() ?? (await (0, _portfinder.getPort)({}));
|
|
98
121
|
return {
|
|
99
|
-
...
|
|
122
|
+
...captchaSolverSettings,
|
|
100
123
|
workspaceId,
|
|
101
124
|
projectId,
|
|
102
125
|
baseUrl,
|
|
103
|
-
authentication
|
|
104
|
-
port
|
|
126
|
+
authentication
|
|
105
127
|
};
|
|
106
128
|
}
|
|
129
|
+
async function getIntunedCaptchaSolverSettings() {
|
|
130
|
+
if (captchaSolverSettings) {
|
|
131
|
+
return captchaSolverSettings;
|
|
132
|
+
}
|
|
133
|
+
const settings = await (0, _settings.getSettings)();
|
|
134
|
+
captchaSolverSettings = await resolveCaptchaSolverSettings(settings.captchaSolver);
|
|
135
|
+
return captchaSolverSettings;
|
|
136
|
+
}
|
|
107
137
|
async function setupIntunedExtension() {
|
|
108
|
-
if (!isIntunedExtensionEnabled()) {
|
|
138
|
+
if (!(await isIntunedExtensionEnabled())) {
|
|
109
139
|
return;
|
|
110
140
|
}
|
|
111
141
|
const intunedExtensionPath = getIntunedExtensionPath();
|
|
112
142
|
const intunedExtensionSettingsPath = _path.default.join(intunedExtensionPath, INTUNED_EXTENSION_SETTINGS_FILE_NAME);
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
await (0, _intunedExtensionServer.setupIntunedExtensionServer)({
|
|
118
|
-
port: settings.port ?? 9000
|
|
119
|
-
});
|
|
120
|
-
await (0, _promises.writeFile)(intunedExtensionSettingsPath, JSON.stringify(settings));
|
|
143
|
+
const captchaSolverSettings = await getIntunedCaptchaSolverSettings();
|
|
144
|
+
await (0, _intunedExtensionServer.setupIntunedExtensionServer)(captchaSolverSettings);
|
|
145
|
+
const captchaSolverSettingsWithRunContext = await getIntunedExtensionSettings(captchaSolverSettings);
|
|
146
|
+
await (0, _promises.writeFile)(intunedExtensionSettingsPath, JSON.stringify(captchaSolverSettingsWithRunContext));
|
|
121
147
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as playwright from "playwright";
|
|
2
2
|
import { Captcha, CaptchaCallback, CaptchaStatus } from "./types";
|
|
3
|
+
import { CaptchaSolverSettings } from "../settingsSchema";
|
|
3
4
|
export declare class ExtensionServer {
|
|
4
5
|
private tabs;
|
|
5
6
|
private app;
|
|
6
|
-
isHealthy: boolean;
|
|
7
7
|
constructor();
|
|
8
8
|
private getOrCreateTab;
|
|
9
9
|
handleUpsertCaptcha(captcha: Captcha): Promise<void>;
|
|
@@ -19,9 +19,6 @@ export declare class ExtensionServer {
|
|
|
19
19
|
getTabId(page: playwright.Page): Promise<number>;
|
|
20
20
|
}
|
|
21
21
|
export declare function getIntunedExtensionServer(): ExtensionServer;
|
|
22
|
-
export declare function setupIntunedExtensionServer(
|
|
23
|
-
port: number;
|
|
24
|
-
host?: string;
|
|
25
|
-
}): Promise<void>;
|
|
22
|
+
export declare function setupIntunedExtensionServer(captchaSolverSettings?: CaptchaSolverSettings): Promise<void>;
|
|
26
23
|
export declare function cleanIntunedExtensionServer(): Promise<void>;
|
|
27
24
|
export declare function getTabId(page: playwright.Page): Promise<number>;
|
|
@@ -10,6 +10,7 @@ exports.getTabId = getTabId;
|
|
|
10
10
|
exports.setupIntunedExtensionServer = setupIntunedExtensionServer;
|
|
11
11
|
var _fastify = _interopRequireDefault(require("fastify"));
|
|
12
12
|
var _types = require("./types");
|
|
13
|
+
var _extensionsHelpers = require("./extensionsHelpers");
|
|
13
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
15
|
class TabCaptchaState {
|
|
15
16
|
constructor(tabId) {
|
|
@@ -40,7 +41,6 @@ class TabCaptchaState {
|
|
|
40
41
|
}
|
|
41
42
|
class ExtensionServer {
|
|
42
43
|
app = null;
|
|
43
|
-
isHealthy = false;
|
|
44
44
|
constructor() {
|
|
45
45
|
this.tabs = new Map();
|
|
46
46
|
}
|
|
@@ -94,13 +94,11 @@ class ExtensionServer {
|
|
|
94
94
|
port,
|
|
95
95
|
host
|
|
96
96
|
});
|
|
97
|
-
this.isHealthy = true;
|
|
98
97
|
}
|
|
99
98
|
async stop() {
|
|
100
99
|
if (!this.app) return;
|
|
101
100
|
const toClose = this.app;
|
|
102
101
|
this.app = null;
|
|
103
|
-
this.isHealthy = false;
|
|
104
102
|
await toClose.close();
|
|
105
103
|
}
|
|
106
104
|
async getCaptchas(page, status) {
|
|
@@ -140,16 +138,15 @@ function getIntunedExtensionServer() {
|
|
|
140
138
|
}
|
|
141
139
|
return extensionServerSingleton;
|
|
142
140
|
}
|
|
143
|
-
async function setupIntunedExtensionServer({
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
141
|
+
async function setupIntunedExtensionServer(captchaSolverSettings) {
|
|
142
|
+
if (!captchaSolverSettings) {
|
|
143
|
+
captchaSolverSettings = await (0, _extensionsHelpers.resolveCaptchaSolverSettings)();
|
|
144
|
+
}
|
|
147
145
|
if (!extensionServerSingleton) {
|
|
148
146
|
extensionServerSingleton = new ExtensionServer();
|
|
149
147
|
}
|
|
150
148
|
await extensionServerSingleton.start({
|
|
151
|
-
port
|
|
152
|
-
host
|
|
149
|
+
port: captchaSolverSettings.port ?? 9000
|
|
153
150
|
});
|
|
154
151
|
}
|
|
155
152
|
async function cleanIntunedExtensionServer() {
|
|
@@ -15,6 +15,7 @@ var JSONC = _interopRequireWildcard(require("jsonc-parser"));
|
|
|
15
15
|
var YAML = _interopRequireWildcard(require("yaml"));
|
|
16
16
|
var TOML = _interopRequireWildcard(require("smol-toml"));
|
|
17
17
|
var _neverthrow = require("neverthrow");
|
|
18
|
+
var _formatZodError = require("./formatZodError");
|
|
18
19
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
20
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
21
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -66,8 +67,7 @@ async function loadIntunedJson() {
|
|
|
66
67
|
}
|
|
67
68
|
const parseResult = intunedJsonSchema.safeParse(intunedJson);
|
|
68
69
|
if (!parseResult.success) {
|
|
69
|
-
|
|
70
|
-
return (0, _neverthrow.err)(`${settingsFile.name} is not valid:\n${formattedError}\nPlease fix the errors and try again.`);
|
|
70
|
+
return (0, _neverthrow.err)(`${settingsFile.name} is not valid:\n${(0, _formatZodError.formatZodError)(parseResult.error)}\nPlease fix the errors and try again.`);
|
|
71
71
|
}
|
|
72
72
|
return (0, _neverthrow.ok)(parseResult.data);
|
|
73
73
|
}
|
|
@@ -76,7 +76,7 @@ class JwtTokenManager {
|
|
|
76
76
|
headers
|
|
77
77
|
});
|
|
78
78
|
if (result.status === 401 && process.env[_constants.CLI_ENV_VAR_KEY] === "true") {
|
|
79
|
-
console.warn("Unauthorized backend function call - make sure to
|
|
79
|
+
console.warn("Unauthorized backend function call - make sure to provision your project to Intuned to set up the correct API credentials.\n" + "Run 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information.");
|
|
80
80
|
}
|
|
81
81
|
return result;
|
|
82
82
|
}
|
|
@@ -97,7 +97,7 @@ class JwtTokenManager {
|
|
|
97
97
|
return `${domain}/api/${workspaceId}/functions/${projectId}`;
|
|
98
98
|
} catch (e) {
|
|
99
99
|
if (process.env[_constants.CLI_ENV_VAR_KEY] === "true") {
|
|
100
|
-
throw new Error(`API credentials not set - make sure to
|
|
100
|
+
throw new Error(`API credentials not set - make sure to provision your project to Intuned to set up the correct API credentials.\n` + `Run 'intuned provision' or see https://docs.intunedhq.com/docs/05-references/cli#provision-project for more information.\n` + `Original error: ${e.message}`);
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as playwright from "playwright";
|
|
2
|
+
import { Result } from "neverthrow";
|
|
2
3
|
export interface Proxy {
|
|
3
4
|
server: string;
|
|
4
5
|
username: string;
|
|
@@ -24,6 +25,7 @@ export declare function launchChromium(options: LaunchChromiumCdpOptions): Promi
|
|
|
24
25
|
export declare function getBrowserExecutablePath(): Promise<string | undefined>;
|
|
25
26
|
export declare function launchBrowser(options: Omit<LaunchChromiumStandaloneOptions, "executablePath"> | LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
|
|
26
27
|
export declare function getLocalCdpAddress(port: number): string;
|
|
28
|
+
export declare function getCdpWebSocketUrl(cdpAddress: string): Promise<Result<string, string>>;
|
|
27
29
|
export declare function getHeadlessUserAgent({ executablePath, args, ignoreDefaultArgs, }: {
|
|
28
30
|
executablePath?: string;
|
|
29
31
|
args?: string[];
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getBrowserExecutablePath = getBrowserExecutablePath;
|
|
7
|
+
exports.getCdpWebSocketUrl = getCdpWebSocketUrl;
|
|
7
8
|
exports.getHeadlessUserAgent = getHeadlessUserAgent;
|
|
8
9
|
exports.getLocalCdpAddress = getLocalCdpAddress;
|
|
9
10
|
exports.launchBrowser = launchBrowser;
|
|
@@ -17,6 +18,8 @@ var _child_process = require("child_process");
|
|
|
17
18
|
var _extensionsHelpers = require("./extension/extensionsHelpers");
|
|
18
19
|
var _intunedExtensionServer = require("./extension/intunedExtensionServer");
|
|
19
20
|
var _util = require("util");
|
|
21
|
+
var _neverthrow = require("neverthrow");
|
|
22
|
+
var _zod = require("zod");
|
|
20
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
24
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
22
25
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -38,6 +41,9 @@ async function createUserDirWithPreferences() {
|
|
|
38
41
|
}
|
|
39
42
|
async function launchChromium(options) {
|
|
40
43
|
if ("cdpAddress" in options) {
|
|
44
|
+
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
45
|
+
await (0, _intunedExtensionServer.setupIntunedExtensionServer)();
|
|
46
|
+
}
|
|
41
47
|
const browser = await playwright.chromium.connectOverCDP(options.cdpAddress);
|
|
42
48
|
if (browser.contexts().length === 0) {
|
|
43
49
|
throw new Error("No browser contexts found in the connected browser");
|
|
@@ -65,12 +71,17 @@ async function launchChromium(options) {
|
|
|
65
71
|
const defaultArgsToIgnore = ["--disable-extensions", "--disable-component-extensions-with-background-pages", "--disable-background-networking", "--disable-backgrounding-occluded-windows", "--disable-background-timer-throttling"];
|
|
66
72
|
const extraArgs = [];
|
|
67
73
|
const userDataDir = await createUserDirWithPreferences();
|
|
68
|
-
if ((0, _extensionsHelpers.
|
|
74
|
+
if ((0, _extensionsHelpers.isIntunedExtensionLoaded)()) {
|
|
69
75
|
const extensionsList = (0, _extensionsHelpers.buildExtensionsList)();
|
|
70
76
|
const extensions = extensionsList.join(",");
|
|
71
77
|
extraArgs.push(`--disable-extensions-except=${extensions}`);
|
|
72
78
|
extraArgs.push(`--load-extension=${extensions}`);
|
|
79
|
+
}
|
|
80
|
+
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
73
81
|
await (0, _extensionsHelpers.setupIntunedExtension)();
|
|
82
|
+
if (proxy) {
|
|
83
|
+
extraArgs.push('--proxy-bypass-list="<-loopback>"');
|
|
84
|
+
}
|
|
74
85
|
}
|
|
75
86
|
if (cdpPort) {
|
|
76
87
|
extraArgs.push(`--remote-debugging-port=${cdpPort}`);
|
|
@@ -105,13 +116,15 @@ async function launchChromium(options) {
|
|
|
105
116
|
});
|
|
106
117
|
context.once("close", async () => {
|
|
107
118
|
try {
|
|
108
|
-
await (0, _intunedExtensionServer.cleanIntunedExtensionServer)();
|
|
109
119
|
await (0, _fsExtra.rm)(userDataDir, {
|
|
110
120
|
recursive: true,
|
|
111
121
|
force: true,
|
|
112
122
|
retryDelay: 1000,
|
|
113
123
|
maxRetries: 5
|
|
114
124
|
});
|
|
125
|
+
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
126
|
+
await (0, _intunedExtensionServer.cleanIntunedExtensionServer)();
|
|
127
|
+
}
|
|
115
128
|
} catch (error) {
|
|
116
129
|
console.error("Failed to remove user data dir", error);
|
|
117
130
|
}
|
|
@@ -121,7 +134,7 @@ async function launchChromium(options) {
|
|
|
121
134
|
await waitOnCdpAddress(createdCdpAddress);
|
|
122
135
|
}
|
|
123
136
|
const page = context.pages().at(0) ?? (await context.newPage());
|
|
124
|
-
if ((0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
137
|
+
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
125
138
|
await (0, _extensionsHelpers.getIntunedExtensionWorker)(context);
|
|
126
139
|
}
|
|
127
140
|
return {
|
|
@@ -163,6 +176,31 @@ async function getBraveExecutablePath() {
|
|
|
163
176
|
function getLocalCdpAddress(port) {
|
|
164
177
|
return `http://localhost:${port}`;
|
|
165
178
|
}
|
|
179
|
+
async function getCdpWebSocketUrl(cdpAddress) {
|
|
180
|
+
let response;
|
|
181
|
+
try {
|
|
182
|
+
response = await fetch(`${cdpAddress}/json/version`);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
return (0, _neverthrow.err)(`Failed to fetch CDP version from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`);
|
|
185
|
+
}
|
|
186
|
+
if (!response.ok) {
|
|
187
|
+
return (0, _neverthrow.err)(`Failed to get CDP WebSocket URL from ${cdpAddress}: ${response.status} ${response.statusText}`);
|
|
188
|
+
}
|
|
189
|
+
let data;
|
|
190
|
+
try {
|
|
191
|
+
data = await response.json();
|
|
192
|
+
} catch (error) {
|
|
193
|
+
return (0, _neverthrow.err)(`Invalid CDP version response from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`);
|
|
194
|
+
}
|
|
195
|
+
const cdpJsonVersionResponseSchema = _zod.z.object({
|
|
196
|
+
webSocketDebuggerUrl: _zod.z.string().url()
|
|
197
|
+
});
|
|
198
|
+
const parseResult = cdpJsonVersionResponseSchema.safeParse(data);
|
|
199
|
+
if (!parseResult.success) {
|
|
200
|
+
return (0, _neverthrow.err)(`Invalid CDP version response from ${cdpAddress}: ${JSON.stringify(parseResult.error.format())}`);
|
|
201
|
+
}
|
|
202
|
+
return (0, _neverthrow.ok)(parseResult.data.webSocketDebuggerUrl);
|
|
203
|
+
}
|
|
166
204
|
async function waitOnCdpAddress(cdpAddress) {
|
|
167
205
|
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
168
206
|
await (0, _waitOn.default)({
|
|
@@ -71,7 +71,6 @@ async function withPlaywrightContext({
|
|
|
71
71
|
const port = await (0, _portfinder.getPort)({
|
|
72
72
|
port: 9222
|
|
73
73
|
});
|
|
74
|
-
hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
|
|
75
74
|
({
|
|
76
75
|
context,
|
|
77
76
|
page
|
|
@@ -81,9 +80,16 @@ async function withPlaywrightContext({
|
|
|
81
80
|
downloadsPath,
|
|
82
81
|
cdpPort: port
|
|
83
82
|
}));
|
|
83
|
+
hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
|
|
84
84
|
}
|
|
85
85
|
let hookResult;
|
|
86
86
|
try {
|
|
87
|
+
const wsUrlResult = await (0, _launchBrowser.getCdpWebSocketUrl)(hookCdpUrl);
|
|
88
|
+
if (wsUrlResult.isOk()) {
|
|
89
|
+
hookCdpUrl = wsUrlResult.value;
|
|
90
|
+
} else {
|
|
91
|
+
throw new Error(wsUrlResult.error);
|
|
92
|
+
}
|
|
87
93
|
hookResult = await setupContextHook({
|
|
88
94
|
apiName: apiName,
|
|
89
95
|
apiParameters: apiParameters,
|
|
@@ -92,7 +92,7 @@ class AuthCheckFailedError extends RunAutomationError {
|
|
|
92
92
|
super();
|
|
93
93
|
this.code = authCheckFailedErrorCode;
|
|
94
94
|
this.statusCode = 401;
|
|
95
|
-
this.message = "
|
|
95
|
+
this.message = "AuthSession check failed";
|
|
96
96
|
this.wrapped = true;
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -141,7 +141,7 @@ async function runApi({
|
|
|
141
141
|
(0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
|
|
142
142
|
const automationFunctionParameters = [...(params !== undefined ? [params] : []), page, context];
|
|
143
143
|
try {
|
|
144
|
-
const automationFunctionResult = await automationFunction(...automationFunctionParameters);
|
|
144
|
+
const [automationFunctionResult] = await Promise.all([automationFunction(...automationFunctionParameters)]);
|
|
145
145
|
const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
|
|
146
146
|
const resultSizeInBytes = getObjectSizeInBytes(automationFunctionResult);
|
|
147
147
|
if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
|
|
@@ -193,7 +193,7 @@ async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3)
|
|
|
193
193
|
return (0, _neverthrow.ok)(false);
|
|
194
194
|
}
|
|
195
195
|
let tryNumber = 0;
|
|
196
|
-
console.log("Checking
|
|
196
|
+
console.log("Checking AuthSession with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
197
197
|
while (retries > tryNumber) {
|
|
198
198
|
const result = await checkFn(page, context);
|
|
199
199
|
if (result) return (0, _neverthrow.ok)(true);
|
|
@@ -197,7 +197,8 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
197
197
|
timeout?: number | undefined;
|
|
198
198
|
} | undefined;
|
|
199
199
|
}>>;
|
|
200
|
-
export type
|
|
200
|
+
export type CaptchaSolverSettings = z.infer<typeof captchaSolverSettingsSchema>;
|
|
201
|
+
export type CaptchaSolverSettingsWithRunContext = CaptchaSolverSettings & {
|
|
201
202
|
workspaceId: string;
|
|
202
203
|
projectId: string;
|
|
203
204
|
baseUrl: string;
|