@intuned/runtime-dev 1.3.17-source.0 → 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/.babelrc +6 -0
- package/InterfaceTemplate/{utils.ts → __utils.ts} +3 -1
- package/InterfaceTemplate/index.playwright.ts +1 -1
- package/bin/intuned +0 -0
- package/bin/intuned-interface +7 -0
- package/dist/commands/api/run.js +3 -3
- package/dist/commands/auth-sessions/run-check.js +3 -3
- package/dist/commands/auth-sessions/run-create.js +3 -3
- package/dist/commands/build.js +1 -3
- package/dist/commands/common/browserUtils.d.ts +3 -3
- package/dist/commands/common/browserUtils.js +3 -4
- package/dist/commands/common/getFirstLineNumber.test.js +1 -2
- package/dist/commands/common/tsNodeImport.d.ts +1 -1
- package/dist/commands/common/tsNodeImport.js +1 -2
- package/dist/commands/common/utils/fileUtils.js +1 -2
- package/dist/commands/common/utils/{unixSocket.d.ts → interfaceClient.d.ts} +10 -2
- package/dist/commands/common/utils/{unixSocket.js → interfaceClient.js} +16 -5
- package/dist/commands/common/utils/template.js +1 -2
- package/dist/commands/interface/run.js +23 -49
- package/dist/commands/intuned-cli/commands/deploy.command.js +2 -2
- package/dist/commands/intuned-cli/commands/provision.command.d.ts +2 -2
- package/dist/commands/intuned-cli/commands/provision.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +5 -1
- package/dist/commands/intuned-cli/commands/types.d.ts +5 -1
- package/dist/commands/intuned-cli/commands/types.js +5 -3
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +6 -5
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +6 -5
- package/dist/commands/intuned-cli/controller/api.d.ts +2 -2
- package/dist/commands/intuned-cli/controller/api.js +3 -3
- package/dist/commands/intuned-cli/controller/authSession.d.ts +13 -13
- package/dist/commands/intuned-cli/controller/authSession.js +3 -2
- package/dist/commands/intuned-cli/controller/build.js +1 -2
- package/dist/commands/intuned-cli/controller/deploy.js +1 -2
- package/dist/commands/intuned-cli/controller/index.js +1 -2
- package/dist/commands/intuned-cli/controller/provision.js +1 -2
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +39 -2
- package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +3 -3
- package/dist/commands/intuned-cli/helpers/auth.d.ts +4 -4
- package/dist/commands/intuned-cli/helpers/auth.js +2 -2
- package/dist/commands/intuned-cli/helpers/browser.d.ts +3 -4
- package/dist/commands/intuned-cli/helpers/browser.js +31 -2
- package/dist/commands/intuned-cli/helpers/errors.d.ts +1 -1
- package/dist/commands/intuned-cli/helpers/errors.js +2 -2
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +6 -5
- package/dist/commands/intuned-cli/helpers/timeout.js +2 -2
- package/dist/commands/intuned-cli/helpers/traces.d.ts +1 -1
- package/dist/commands/intuned-cli/helpers/wrapper.js +2 -2
- package/dist/commands/intuned-cli/main.js +1 -2
- package/dist/commands/intuned-cli/types.d.ts +8 -8
- package/dist/commands/ts-check.js +1 -2
- package/dist/common/binStartupScript.js +16 -7
- package/dist/common/browserTabs.d.ts +72 -0
- package/dist/common/browserTabs.js +74 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +2 -1
- package/dist/common/contextStorageStateHelpers.d.ts +4 -3
- package/dist/common/contextStorageStateHelpers.js +4 -1
- package/dist/common/extension/extensionsHelpers.d.ts +1 -1
- package/dist/common/extension/types.d.ts +14 -7
- package/dist/common/formatZodError.d.ts +1 -1
- package/dist/common/intunedJson.d.ts +29 -14
- package/dist/common/intunedJson.js +24 -3
- package/dist/common/jwtTokenManager.js +10 -6
- package/dist/common/launchBrowser.d.ts +1 -0
- package/dist/common/launchBrowser.js +32 -5
- package/dist/common/playwrightContext.d.ts +3 -5
- package/dist/common/playwrightContext.js +9 -11
- package/dist/common/runApi/importUsingImportFunction.d.ts +1 -3
- package/dist/common/runApi/importUsingImportFunction.js +7 -7
- package/dist/common/runApi/index.d.ts +3 -6
- package/dist/common/runApi/index.js +25 -51
- package/dist/common/settingsSchema.d.ts +49 -45
- package/dist/common/settingsSchema.js +1 -2
- package/dist/common/setupContextHook.d.ts +1 -2
- package/dist/common/setupContextHook.js +2 -2
- package/dist/common/telemetry.js +1 -2
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -7
- package/dist/runtime/downloadDirectory.js +2 -2
- package/dist/vendor/runtime-interface.d.ts +1 -0
- package/dist/vendor/runtime-interface.js +491 -0
- package/package.json +17 -10
- package/tsup.config.ts +12 -0
- package/WebTemplate.zip +0 -0
- package/dist/common/runApi/errors.d.ts +0 -72
- package/dist/common/runApi/errors.js +0 -169
- package/dist/common/runApi/types.d.ts +0 -830
- package/dist/common/runApi/types.js +0 -73
|
@@ -9,8 +9,7 @@ var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
|
9
9
|
var jwt = _interopRequireWildcard(require("jsonwebtoken"));
|
|
10
10
|
var _neverthrow = require("neverthrow");
|
|
11
11
|
var _constants = require("./constants");
|
|
12
|
-
function
|
|
13
|
-
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; }
|
|
12
|
+
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); }
|
|
14
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
14
|
class JwtTokenManager {
|
|
16
15
|
constructor(refreshTokenPath) {
|
|
@@ -65,8 +64,13 @@ class JwtTokenManager {
|
|
|
65
64
|
}
|
|
66
65
|
async fetchWithToken(...[input, init]) {
|
|
67
66
|
const headers = new Headers(init?.headers);
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const apiKey = process.env[_constants.API_KEY_ENV_VAR_KEY];
|
|
68
|
+
if (apiKey) {
|
|
69
|
+
headers.set(_constants.API_KEY_HEADER_NAME, apiKey);
|
|
70
|
+
}
|
|
71
|
+
const token = process.env[_constants.AUTH_TOKEN_ENV_VAR_KEY];
|
|
72
|
+
if (token) {
|
|
73
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
70
74
|
}
|
|
71
75
|
if (this.token !== undefined) {
|
|
72
76
|
headers.set("Authorization", `Bearer ${this.token}`);
|
|
@@ -76,7 +80,7 @@ class JwtTokenManager {
|
|
|
76
80
|
headers
|
|
77
81
|
});
|
|
78
82
|
if (result.status === 401 && process.env[_constants.CLI_ENV_VAR_KEY] === "true") {
|
|
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#
|
|
83
|
+
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
84
|
}
|
|
81
85
|
return result;
|
|
82
86
|
}
|
|
@@ -97,7 +101,7 @@ class JwtTokenManager {
|
|
|
97
101
|
return `${domain}/api/${workspaceId}/functions/${projectId}`;
|
|
98
102
|
} catch (e) {
|
|
99
103
|
if (process.env[_constants.CLI_ENV_VAR_KEY] === "true") {
|
|
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#
|
|
104
|
+
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
105
|
}
|
|
102
106
|
}
|
|
103
107
|
}
|
|
@@ -19,6 +19,7 @@ export type LaunchChromiumStandaloneOptions = {
|
|
|
19
19
|
};
|
|
20
20
|
export type LaunchChromiumCdpOptions = {
|
|
21
21
|
cdpAddress: string;
|
|
22
|
+
cdpTargetId?: string;
|
|
22
23
|
};
|
|
23
24
|
export declare function launchChromium(options: LaunchChromiumStandaloneOptions): Promise<LaunchBrowserResult>;
|
|
24
25
|
export declare function launchChromium(options: LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
|
|
@@ -20,9 +20,9 @@ var _intunedExtensionServer = require("./extension/intunedExtensionServer");
|
|
|
20
20
|
var _util = require("util");
|
|
21
21
|
var _neverthrow = require("neverthrow");
|
|
22
22
|
var _zod = require("zod");
|
|
23
|
+
var _intunedJson = require("./intunedJson");
|
|
23
24
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
|
-
function
|
|
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; }
|
|
25
|
+
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); }
|
|
26
26
|
const execAsync = (0, _util.promisify)(_child_process.exec);
|
|
27
27
|
async function createUserDirWithPreferences() {
|
|
28
28
|
const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
|
|
@@ -49,9 +49,22 @@ async function launchChromium(options) {
|
|
|
49
49
|
throw new Error("No browser contexts found in the connected browser");
|
|
50
50
|
}
|
|
51
51
|
const context = browser.contexts()[0];
|
|
52
|
-
let page = context.pages().at(0);
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
let page = context.pages().at(0) ?? (await context.newPage());
|
|
53
|
+
const targetId = options.cdpTargetId;
|
|
54
|
+
if (targetId) {
|
|
55
|
+
for (const p of context.pages()) {
|
|
56
|
+
let cdp = null;
|
|
57
|
+
try {
|
|
58
|
+
cdp = await context.newCDPSession(p);
|
|
59
|
+
const result = await cdp.send("Target.getTargetInfo");
|
|
60
|
+
if (result.targetInfo.targetId === targetId) {
|
|
61
|
+
page = p;
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
} catch (error) {} finally {
|
|
65
|
+
await cdp?.detach();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
55
68
|
}
|
|
56
69
|
return {
|
|
57
70
|
page,
|
|
@@ -142,7 +155,21 @@ async function launchChromium(options) {
|
|
|
142
155
|
context
|
|
143
156
|
};
|
|
144
157
|
}
|
|
158
|
+
async function getIntunedBrowserExecutablePath() {
|
|
159
|
+
const intunedPath = process.env.INTUNED_BROWSER_PATH;
|
|
160
|
+
if (intunedPath && (await fs.exists(intunedPath))) {
|
|
161
|
+
return intunedPath;
|
|
162
|
+
}
|
|
163
|
+
return undefined;
|
|
164
|
+
}
|
|
145
165
|
async function getBrowserExecutablePath() {
|
|
166
|
+
const stealthConfig = await (0, _intunedJson.getStealthModeConfig)();
|
|
167
|
+
if (stealthConfig.enabled && stealthConfig.type === "intunedBrowser") {
|
|
168
|
+
const intunedPath = await getIntunedBrowserExecutablePath();
|
|
169
|
+
if (intunedPath) {
|
|
170
|
+
return intunedPath;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
146
173
|
const browserType = getBrowserType();
|
|
147
174
|
if (browserType === "brave") {
|
|
148
175
|
return await getBraveExecutablePath();
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import * as playwright from "playwright";
|
|
2
|
-
import { RunAutomationError } from "./runApi/errors";
|
|
3
|
-
import type { RunApiSession } from "./runApi/types";
|
|
1
|
+
import type * as playwright from "playwright";
|
|
4
2
|
import { Err, Ok } from "neverthrow";
|
|
5
|
-
import { type ImportFunction } from "./runApi/importUsingImportFunction";
|
|
6
3
|
import { type Proxy } from "./launchBrowser";
|
|
7
|
-
|
|
4
|
+
import { ImportFunction, RunAutomationError, RunApiSession } from "@intuned/runtime-interface";
|
|
8
5
|
type WithPlaywrightContextParameters = {
|
|
9
6
|
importFunction: ImportFunction;
|
|
10
7
|
apiName: string;
|
|
@@ -23,6 +20,7 @@ export declare function withPlaywrightContext<R>(options: {
|
|
|
23
20
|
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
24
21
|
export declare function withPlaywrightContext<R>(options: {
|
|
25
22
|
cdpAddress: string;
|
|
23
|
+
cdpTargetId?: string;
|
|
26
24
|
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
27
25
|
export declare function loadSessionToContext({ context, session, }: {
|
|
28
26
|
context: playwright.BrowserContext;
|
|
@@ -3,24 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.browserScriptsFile = void 0;
|
|
7
6
|
exports.loadSessionToContext = loadSessionToContext;
|
|
8
7
|
exports.withPlaywrightContext = withPlaywrightContext;
|
|
9
8
|
var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
9
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
12
10
|
var _fileUtils = require("../commands/common/utils/fileUtils");
|
|
13
|
-
var _errors = require("./runApi/errors");
|
|
14
11
|
var _neverthrow = require("neverthrow");
|
|
15
12
|
var _setupContextHook = require("./setupContextHook");
|
|
16
13
|
var _portfinder = require("portfinder");
|
|
17
14
|
var _launchBrowser = require("./launchBrowser");
|
|
18
|
-
|
|
19
|
-
function _interopRequireWildcard(e, r) { if (!
|
|
20
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
-
const browserScriptsFile = exports.browserScriptsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
15
|
+
var _runtimeInterface = require("../vendor/runtime-interface");
|
|
16
|
+
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); }
|
|
22
17
|
async function withPlaywrightContext({
|
|
23
18
|
cdpAddress,
|
|
19
|
+
cdpTargetId,
|
|
24
20
|
proxy,
|
|
25
21
|
headless = true,
|
|
26
22
|
downloadsPath,
|
|
@@ -44,7 +40,8 @@ async function withPlaywrightContext({
|
|
|
44
40
|
page,
|
|
45
41
|
context
|
|
46
42
|
} = await (0, _launchBrowser.launchBrowser)({
|
|
47
|
-
cdpAddress
|
|
43
|
+
cdpAddress,
|
|
44
|
+
cdpTargetId
|
|
48
45
|
}));
|
|
49
46
|
} else {
|
|
50
47
|
({
|
|
@@ -65,7 +62,8 @@ async function withPlaywrightContext({
|
|
|
65
62
|
context,
|
|
66
63
|
page
|
|
67
64
|
} = await (0, _launchBrowser.launchBrowser)({
|
|
68
|
-
cdpAddress
|
|
65
|
+
cdpAddress,
|
|
66
|
+
cdpTargetId
|
|
69
67
|
}));
|
|
70
68
|
} else {
|
|
71
69
|
const port = await (0, _portfinder.getPort)({
|
|
@@ -96,7 +94,7 @@ async function withPlaywrightContext({
|
|
|
96
94
|
cdpUrl: hookCdpUrl
|
|
97
95
|
});
|
|
98
96
|
} catch (error) {
|
|
99
|
-
return (0, _neverthrow.err)(new
|
|
97
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(error));
|
|
100
98
|
}
|
|
101
99
|
if (!hookResult) {
|
|
102
100
|
return await fn(context, page);
|
|
@@ -120,7 +118,7 @@ async function withPlaywrightContext({
|
|
|
120
118
|
await cleanup?.();
|
|
121
119
|
} catch (e) {
|
|
122
120
|
result = {
|
|
123
|
-
return: (0, _neverthrow.err)(new
|
|
121
|
+
return: (0, _neverthrow.err)(new _runtimeInterface.AutomationError(e))
|
|
124
122
|
};
|
|
125
123
|
}
|
|
126
124
|
if ("throw" in result) {
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Result } from "neverthrow";
|
|
2
|
-
import { RunAutomationError } from "
|
|
3
|
-
import { ExtendedRunApiParameters } from "./types";
|
|
4
|
-
export type ImportFunction = ExtendedRunApiParameters["importFunction"];
|
|
2
|
+
import { ImportFunction, RunAutomationError } from "@intuned/runtime-interface";
|
|
5
3
|
export declare function importUsingImportFunction<_ReturnType = any>({ path, allowGenerators, importFunction, }: {
|
|
6
4
|
path: string;
|
|
7
5
|
importFunction: ImportFunction;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.importUsingImportFunction = importUsingImportFunction;
|
|
7
7
|
var _neverthrow = require("neverthrow");
|
|
8
|
-
var
|
|
8
|
+
var _runtimeInterface = require("../../vendor/runtime-interface");
|
|
9
9
|
async function importUsingImportFunction({
|
|
10
10
|
path,
|
|
11
11
|
allowGenerators = true,
|
|
@@ -15,17 +15,17 @@ async function importUsingImportFunction({
|
|
|
15
15
|
const importedResult = await importFunction(path);
|
|
16
16
|
if (importedResult.isErr()) {
|
|
17
17
|
if (importedResult.error.type === "not_found") {
|
|
18
|
-
return (0, _neverthrow.err)(new
|
|
18
|
+
return (0, _neverthrow.err)(new _runtimeInterface.ApiNotFoundError(path));
|
|
19
19
|
}
|
|
20
|
-
return (0, _neverthrow.err)(new
|
|
20
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(importedResult.error.error));
|
|
21
21
|
}
|
|
22
22
|
const imported = importedResult.value;
|
|
23
23
|
if (!imported || !imported.default || !imported.default.constructor) {
|
|
24
|
-
return (0, _neverthrow.err)(new
|
|
24
|
+
return (0, _neverthrow.err)(new _runtimeInterface.InvalidApiError(`${path} does not have a default export`));
|
|
25
25
|
}
|
|
26
26
|
if (imported.default.constructor.name === "AsyncGeneratorFunction") {
|
|
27
27
|
if (!allowGenerators) {
|
|
28
|
-
return (0, _neverthrow.err)(new
|
|
28
|
+
return (0, _neverthrow.err)(new _runtimeInterface.InvalidApiError(`${path} default export must be an async function`));
|
|
29
29
|
}
|
|
30
30
|
return (0, _neverthrow.ok)(async (...args) => {
|
|
31
31
|
const generator = imported.default(...args);
|
|
@@ -39,8 +39,8 @@ async function importUsingImportFunction({
|
|
|
39
39
|
if (imported.default.constructor.name === "AsyncFunction") {
|
|
40
40
|
return (0, _neverthrow.ok)(imported.default);
|
|
41
41
|
}
|
|
42
|
-
return (0, _neverthrow.err)(new
|
|
42
|
+
return (0, _neverthrow.err)(new _runtimeInterface.InvalidApiError(`${path} default export must be an async function`));
|
|
43
43
|
} catch (error) {
|
|
44
|
-
return (0, _neverthrow.err)(new
|
|
44
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(error));
|
|
45
45
|
}
|
|
46
46
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { Result } from "neverthrow";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from "./types";
|
|
5
|
-
export * from "./types";
|
|
6
|
-
export * from "./errors";
|
|
2
|
+
import type { Page, BrowserContext } from "playwright";
|
|
3
|
+
import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk, RunAutomationError } from "@intuned/runtime-interface";
|
|
7
4
|
export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters & {
|
|
8
5
|
retrieveSession: true;
|
|
9
|
-
}): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk
|
|
6
|
+
}): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk<ResultType>>>;
|
|
10
7
|
export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
|
|
11
8
|
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
@@ -3,49 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
runApi: true,
|
|
8
|
-
checkAuthSessionWithRetries: true
|
|
9
|
-
};
|
|
10
6
|
exports.checkAuthSessionWithRetries = checkAuthSessionWithRetries;
|
|
11
7
|
exports.runApi = runApi;
|
|
12
8
|
var _downloadDirectory = require("../../runtime/downloadDirectory");
|
|
13
9
|
var _asyncLocalStorage = require("../asyncLocalStorage");
|
|
14
10
|
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
15
11
|
var fs = _fsExtra;
|
|
16
|
-
var _contextStorageStateHelpers = require("../contextStorageStateHelpers");
|
|
17
12
|
var _neverthrow = require("neverthrow");
|
|
18
|
-
var _errors = require("./errors");
|
|
19
|
-
Object.keys(_errors).forEach(function (key) {
|
|
20
|
-
if (key === "default" || key === "__esModule") return;
|
|
21
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
22
|
-
if (key in exports && exports[key] === _errors[key]) return;
|
|
23
|
-
Object.defineProperty(exports, key, {
|
|
24
|
-
enumerable: true,
|
|
25
|
-
get: function () {
|
|
26
|
-
return _errors[key];
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
13
|
var _constants = require("../constants");
|
|
31
14
|
var _playwrightContext = require("../playwrightContext");
|
|
32
|
-
var _types = require("./types");
|
|
33
|
-
Object.keys(_types).forEach(function (key) {
|
|
34
|
-
if (key === "default" || key === "__esModule") return;
|
|
35
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
36
|
-
if (key in exports && exports[key] === _types[key]) return;
|
|
37
|
-
Object.defineProperty(exports, key, {
|
|
38
|
-
enumerable: true,
|
|
39
|
-
get: function () {
|
|
40
|
-
return _types[key];
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
15
|
var _formatZodError = require("../formatZodError");
|
|
45
16
|
var _cleanEnvironmentVariables = require("../cleanEnvironmentVariables");
|
|
46
17
|
var _importUsingImportFunction = require("./importUsingImportFunction");
|
|
47
|
-
|
|
48
|
-
|
|
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); }
|
|
49
21
|
function getObjectSizeInBytes(obj) {
|
|
50
22
|
try {
|
|
51
23
|
return new TextEncoder().encode(JSON.stringify(obj)).length;
|
|
@@ -60,9 +32,9 @@ async function runApi({
|
|
|
60
32
|
...input
|
|
61
33
|
}) {
|
|
62
34
|
let traceStarted = false;
|
|
63
|
-
const inputParseResult =
|
|
35
|
+
const inputParseResult = _runtimeInterface.runApiParametersSchema.safeParse(input);
|
|
64
36
|
if (!inputParseResult.success) {
|
|
65
|
-
return (0, _neverthrow.err)(new
|
|
37
|
+
return (0, _neverthrow.err)(new _runtimeInterface.InternalInvalidInputError("Input validation failed", (0, _formatZodError.formatZodError)(inputParseResult.error)));
|
|
66
38
|
}
|
|
67
39
|
const {
|
|
68
40
|
automationFunction: {
|
|
@@ -92,7 +64,7 @@ async function runApi({
|
|
|
92
64
|
if (auth && auth.session.type === "state") {
|
|
93
65
|
const state = auth.session.state;
|
|
94
66
|
if (state === undefined || state === null) {
|
|
95
|
-
return (0, _neverthrow.err)(new
|
|
67
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AuthRequiredError());
|
|
96
68
|
}
|
|
97
69
|
}
|
|
98
70
|
const playwrightContextParameters = {
|
|
@@ -122,13 +94,9 @@ async function runApi({
|
|
|
122
94
|
context,
|
|
123
95
|
session: auth.session
|
|
124
96
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
content: scriptContent
|
|
129
|
-
});
|
|
130
|
-
for (const page of context.pages()) {
|
|
131
|
-
await page.evaluate(scriptContent);
|
|
97
|
+
if (intunedContext && auth.parameters) {
|
|
98
|
+
intunedContext.getAuthSessionParameters = async () => auth.parameters;
|
|
99
|
+
}
|
|
132
100
|
}
|
|
133
101
|
if (tracing.enabled) {
|
|
134
102
|
await context.tracing.start({
|
|
@@ -141,19 +109,28 @@ async function runApi({
|
|
|
141
109
|
(0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
|
|
142
110
|
const automationFunctionParameters = [...(params !== undefined ? [params] : []), page, context];
|
|
143
111
|
try {
|
|
144
|
-
const automationFunctionResult = await automationFunction(...automationFunctionParameters);
|
|
112
|
+
const automationFunctionResult = await Promise.race([automationFunction(...automationFunctionParameters), abortPromise]);
|
|
113
|
+
if (automationFunctionResult === abortSymbol) {
|
|
114
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AbortedError());
|
|
115
|
+
}
|
|
145
116
|
const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
|
|
146
117
|
const resultSizeInBytes = getObjectSizeInBytes(automationFunctionResult);
|
|
147
118
|
if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
|
|
148
|
-
return (0, _neverthrow.err)(new
|
|
119
|
+
return (0, _neverthrow.err)(new _runtimeInterface.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES));
|
|
120
|
+
}
|
|
121
|
+
if (retrieveSession) {
|
|
122
|
+
return (0, _neverthrow.ok)({
|
|
123
|
+
result: automationFunctionResult,
|
|
124
|
+
extendedPayloads: intunedContext?.extendedPayloads,
|
|
125
|
+
session: await (0, _contextStorageStateHelpers.getStorageState)(context)
|
|
126
|
+
});
|
|
149
127
|
}
|
|
150
128
|
return (0, _neverthrow.ok)({
|
|
151
129
|
result: automationFunctionResult,
|
|
152
|
-
extendedPayloads: intunedContext?.extendedPayloads
|
|
153
|
-
session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
|
|
130
|
+
extendedPayloads: intunedContext?.extendedPayloads
|
|
154
131
|
});
|
|
155
132
|
} catch (error) {
|
|
156
|
-
return (0, _neverthrow.err)(new
|
|
133
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(error));
|
|
157
134
|
} finally {
|
|
158
135
|
await saveTraceIfNeeded({
|
|
159
136
|
errorMessage: "failed to save trace"
|
|
@@ -178,15 +155,12 @@ async function runApi({
|
|
|
178
155
|
} else {
|
|
179
156
|
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
180
157
|
cdpAddress: runOptions.cdpAddress,
|
|
158
|
+
cdpTargetId: runOptions.cdpTargetId,
|
|
181
159
|
...playwrightContextParameters
|
|
182
160
|
}, runAutomationWithContext);
|
|
183
161
|
}
|
|
184
162
|
}
|
|
185
|
-
|
|
186
|
-
if (result === abortSymbol) {
|
|
187
|
-
return (0, _neverthrow.err)(new _errors.AbortedError());
|
|
188
|
-
}
|
|
189
|
-
return result;
|
|
163
|
+
return await runAutomation();
|
|
190
164
|
}
|
|
191
165
|
async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
|
|
192
166
|
if (retries === 0) {
|
|
@@ -60,6 +60,7 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
60
60
|
}>>;
|
|
61
61
|
customCaptcha: z.ZodOptional<z.ZodObject<{
|
|
62
62
|
enabled: z.ZodBoolean;
|
|
63
|
+
} & {
|
|
63
64
|
imageLocators: z.ZodArray<z.ZodString, "many">;
|
|
64
65
|
submitLocators: z.ZodArray<z.ZodString, "many">;
|
|
65
66
|
inputLocators: z.ZodArray<z.ZodString, "many">;
|
|
@@ -76,6 +77,7 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
76
77
|
}>>;
|
|
77
78
|
text: z.ZodOptional<z.ZodObject<{
|
|
78
79
|
enabled: z.ZodBoolean;
|
|
80
|
+
} & {
|
|
79
81
|
labelLocators: z.ZodArray<z.ZodString, "many">;
|
|
80
82
|
submitLocators: z.ZodArray<z.ZodString, "many">;
|
|
81
83
|
inputLocators: z.ZodArray<z.ZodString, "many">;
|
|
@@ -114,26 +116,26 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
114
116
|
maxRetries: number;
|
|
115
117
|
timeout: number;
|
|
116
118
|
};
|
|
117
|
-
port?: number | undefined;
|
|
118
119
|
cloudflare?: {
|
|
119
120
|
enabled: boolean;
|
|
120
121
|
} | undefined;
|
|
121
|
-
|
|
122
|
+
funcaptcha?: {
|
|
122
123
|
enabled: boolean;
|
|
123
124
|
} | undefined;
|
|
124
|
-
|
|
125
|
+
geetest?: {
|
|
125
126
|
enabled: boolean;
|
|
126
127
|
} | undefined;
|
|
127
|
-
|
|
128
|
+
hcaptcha?: {
|
|
128
129
|
enabled: boolean;
|
|
129
130
|
} | undefined;
|
|
130
|
-
|
|
131
|
+
port?: number | undefined;
|
|
132
|
+
googleRecaptchaV2?: {
|
|
131
133
|
enabled: boolean;
|
|
132
134
|
} | undefined;
|
|
133
|
-
|
|
135
|
+
googleRecaptchaV3?: {
|
|
134
136
|
enabled: boolean;
|
|
135
137
|
} | undefined;
|
|
136
|
-
|
|
138
|
+
awscaptcha?: {
|
|
137
139
|
enabled: boolean;
|
|
138
140
|
} | undefined;
|
|
139
141
|
lemin?: {
|
|
@@ -152,27 +154,27 @@ export declare const captchaSolverSettingsSchema: z.ZodDefault<z.ZodObject<{
|
|
|
152
154
|
labelLocators: string[];
|
|
153
155
|
} | undefined;
|
|
154
156
|
}, {
|
|
155
|
-
enabled?: boolean | undefined;
|
|
156
|
-
port?: number | undefined;
|
|
157
157
|
cloudflare?: {
|
|
158
158
|
enabled: boolean;
|
|
159
159
|
} | undefined;
|
|
160
|
-
|
|
160
|
+
funcaptcha?: {
|
|
161
161
|
enabled: boolean;
|
|
162
162
|
} | undefined;
|
|
163
|
-
|
|
163
|
+
geetest?: {
|
|
164
164
|
enabled: boolean;
|
|
165
165
|
} | undefined;
|
|
166
|
-
|
|
166
|
+
hcaptcha?: {
|
|
167
167
|
enabled: boolean;
|
|
168
168
|
} | undefined;
|
|
169
|
-
|
|
169
|
+
enabled?: boolean | undefined;
|
|
170
|
+
port?: number | undefined;
|
|
171
|
+
googleRecaptchaV2?: {
|
|
170
172
|
enabled: boolean;
|
|
171
173
|
} | undefined;
|
|
172
|
-
|
|
174
|
+
googleRecaptchaV3?: {
|
|
173
175
|
enabled: boolean;
|
|
174
176
|
} | undefined;
|
|
175
|
-
|
|
177
|
+
awscaptcha?: {
|
|
176
178
|
enabled: boolean;
|
|
177
179
|
} | undefined;
|
|
178
180
|
lemin?: {
|
|
@@ -286,6 +288,7 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
286
288
|
}>>;
|
|
287
289
|
customCaptcha: z.ZodOptional<z.ZodObject<{
|
|
288
290
|
enabled: z.ZodBoolean;
|
|
291
|
+
} & {
|
|
289
292
|
imageLocators: z.ZodArray<z.ZodString, "many">;
|
|
290
293
|
submitLocators: z.ZodArray<z.ZodString, "many">;
|
|
291
294
|
inputLocators: z.ZodArray<z.ZodString, "many">;
|
|
@@ -302,6 +305,7 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
302
305
|
}>>;
|
|
303
306
|
text: z.ZodOptional<z.ZodObject<{
|
|
304
307
|
enabled: z.ZodBoolean;
|
|
308
|
+
} & {
|
|
305
309
|
labelLocators: z.ZodArray<z.ZodString, "many">;
|
|
306
310
|
submitLocators: z.ZodArray<z.ZodString, "many">;
|
|
307
311
|
inputLocators: z.ZodArray<z.ZodString, "many">;
|
|
@@ -340,26 +344,26 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
340
344
|
maxRetries: number;
|
|
341
345
|
timeout: number;
|
|
342
346
|
};
|
|
343
|
-
port?: number | undefined;
|
|
344
347
|
cloudflare?: {
|
|
345
348
|
enabled: boolean;
|
|
346
349
|
} | undefined;
|
|
347
|
-
|
|
350
|
+
funcaptcha?: {
|
|
348
351
|
enabled: boolean;
|
|
349
352
|
} | undefined;
|
|
350
|
-
|
|
353
|
+
geetest?: {
|
|
351
354
|
enabled: boolean;
|
|
352
355
|
} | undefined;
|
|
353
|
-
|
|
356
|
+
hcaptcha?: {
|
|
354
357
|
enabled: boolean;
|
|
355
358
|
} | undefined;
|
|
356
|
-
|
|
359
|
+
port?: number | undefined;
|
|
360
|
+
googleRecaptchaV2?: {
|
|
357
361
|
enabled: boolean;
|
|
358
362
|
} | undefined;
|
|
359
|
-
|
|
363
|
+
googleRecaptchaV3?: {
|
|
360
364
|
enabled: boolean;
|
|
361
365
|
} | undefined;
|
|
362
|
-
|
|
366
|
+
awscaptcha?: {
|
|
363
367
|
enabled: boolean;
|
|
364
368
|
} | undefined;
|
|
365
369
|
lemin?: {
|
|
@@ -378,27 +382,27 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
378
382
|
labelLocators: string[];
|
|
379
383
|
} | undefined;
|
|
380
384
|
}, {
|
|
381
|
-
enabled?: boolean | undefined;
|
|
382
|
-
port?: number | undefined;
|
|
383
385
|
cloudflare?: {
|
|
384
386
|
enabled: boolean;
|
|
385
387
|
} | undefined;
|
|
386
|
-
|
|
388
|
+
funcaptcha?: {
|
|
387
389
|
enabled: boolean;
|
|
388
390
|
} | undefined;
|
|
389
|
-
|
|
391
|
+
geetest?: {
|
|
390
392
|
enabled: boolean;
|
|
391
393
|
} | undefined;
|
|
392
|
-
|
|
394
|
+
hcaptcha?: {
|
|
393
395
|
enabled: boolean;
|
|
394
396
|
} | undefined;
|
|
395
|
-
|
|
397
|
+
enabled?: boolean | undefined;
|
|
398
|
+
port?: number | undefined;
|
|
399
|
+
googleRecaptchaV2?: {
|
|
396
400
|
enabled: boolean;
|
|
397
401
|
} | undefined;
|
|
398
|
-
|
|
402
|
+
googleRecaptchaV3?: {
|
|
399
403
|
enabled: boolean;
|
|
400
404
|
} | undefined;
|
|
401
|
-
|
|
405
|
+
awscaptcha?: {
|
|
402
406
|
enabled: boolean;
|
|
403
407
|
} | undefined;
|
|
404
408
|
lemin?: {
|
|
@@ -438,26 +442,26 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
438
442
|
maxRetries: number;
|
|
439
443
|
timeout: number;
|
|
440
444
|
};
|
|
441
|
-
port?: number | undefined;
|
|
442
445
|
cloudflare?: {
|
|
443
446
|
enabled: boolean;
|
|
444
447
|
} | undefined;
|
|
445
|
-
|
|
448
|
+
funcaptcha?: {
|
|
446
449
|
enabled: boolean;
|
|
447
450
|
} | undefined;
|
|
448
|
-
|
|
451
|
+
geetest?: {
|
|
449
452
|
enabled: boolean;
|
|
450
453
|
} | undefined;
|
|
451
|
-
|
|
454
|
+
hcaptcha?: {
|
|
452
455
|
enabled: boolean;
|
|
453
456
|
} | undefined;
|
|
454
|
-
|
|
457
|
+
port?: number | undefined;
|
|
458
|
+
googleRecaptchaV2?: {
|
|
455
459
|
enabled: boolean;
|
|
456
460
|
} | undefined;
|
|
457
|
-
|
|
461
|
+
googleRecaptchaV3?: {
|
|
458
462
|
enabled: boolean;
|
|
459
463
|
} | undefined;
|
|
460
|
-
|
|
464
|
+
awscaptcha?: {
|
|
461
465
|
enabled: boolean;
|
|
462
466
|
} | undefined;
|
|
463
467
|
lemin?: {
|
|
@@ -484,27 +488,27 @@ export declare const settingsSchema: z.ZodObject<{
|
|
|
484
488
|
enabled: boolean;
|
|
485
489
|
} | undefined;
|
|
486
490
|
captchaSolver?: {
|
|
487
|
-
enabled?: boolean | undefined;
|
|
488
|
-
port?: number | undefined;
|
|
489
491
|
cloudflare?: {
|
|
490
492
|
enabled: boolean;
|
|
491
493
|
} | undefined;
|
|
492
|
-
|
|
494
|
+
funcaptcha?: {
|
|
493
495
|
enabled: boolean;
|
|
494
496
|
} | undefined;
|
|
495
|
-
|
|
497
|
+
geetest?: {
|
|
496
498
|
enabled: boolean;
|
|
497
499
|
} | undefined;
|
|
498
|
-
|
|
500
|
+
hcaptcha?: {
|
|
499
501
|
enabled: boolean;
|
|
500
502
|
} | undefined;
|
|
501
|
-
|
|
503
|
+
enabled?: boolean | undefined;
|
|
504
|
+
port?: number | undefined;
|
|
505
|
+
googleRecaptchaV2?: {
|
|
502
506
|
enabled: boolean;
|
|
503
507
|
} | undefined;
|
|
504
|
-
|
|
508
|
+
googleRecaptchaV3?: {
|
|
505
509
|
enabled: boolean;
|
|
506
510
|
} | undefined;
|
|
507
|
-
|
|
511
|
+
awscaptcha?: {
|
|
508
512
|
enabled: boolean;
|
|
509
513
|
} | undefined;
|
|
510
514
|
lemin?: {
|