@intuned/runtime-dev 1.3.17-source.0 → 1.3.18-dev.2
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/CHANGELOG.md +1 -1
- 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 +8 -1
- package/dist/commands/intuned-cli/commands/types.d.ts +9 -1
- package/dist/commands/intuned-cli/commands/types.js +7 -3
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +24 -14
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +128 -66
- 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 +16 -16
- package/dist/commands/intuned-cli/controller/authSession.js +22 -11
- 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 +44 -5
- 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 +4 -4
- package/dist/commands/intuned-cli/helpers/browser.js +40 -5
- 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 +1 -2
- 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 +19 -14
- package/dist/common/intunedJson.js +2 -2
- package/dist/common/jwtTokenManager.js +10 -6
- package/dist/common/launchBrowser.d.ts +8 -0
- package/dist/common/launchBrowser.js +39 -7
- package/dist/common/playwrightContext.d.ts +5 -5
- package/dist/common/playwrightContext.js +17 -13
- 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 +27 -51
- package/dist/common/settingsSchema.d.ts +52 -45
- package/dist/common/settingsSchema.js +3 -3
- 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 +493 -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
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getBrowserExecutablePath = getBrowserExecutablePath;
|
|
7
7
|
exports.getCdpWebSocketUrl = getCdpWebSocketUrl;
|
|
8
8
|
exports.getHeadlessUserAgent = getHeadlessUserAgent;
|
|
9
|
+
exports.getIgnoreHttpErrorsFromConfig = getIgnoreHttpErrorsFromConfig;
|
|
9
10
|
exports.getLocalCdpAddress = getLocalCdpAddress;
|
|
10
11
|
exports.launchBrowser = launchBrowser;
|
|
11
12
|
exports.launchChromium = launchChromium;
|
|
@@ -20,9 +21,9 @@ var _intunedExtensionServer = require("./extension/intunedExtensionServer");
|
|
|
20
21
|
var _util = require("util");
|
|
21
22
|
var _neverthrow = require("neverthrow");
|
|
22
23
|
var _zod = require("zod");
|
|
24
|
+
var _intunedJson = require("./intunedJson");
|
|
23
25
|
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; }
|
|
26
|
+
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
27
|
const execAsync = (0, _util.promisify)(_child_process.exec);
|
|
27
28
|
async function createUserDirWithPreferences() {
|
|
28
29
|
const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
|
|
@@ -39,6 +40,22 @@ async function createUserDirWithPreferences() {
|
|
|
39
40
|
await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
40
41
|
return userDir;
|
|
41
42
|
}
|
|
43
|
+
async function getIgnoreHttpErrorsFromConfig(cliOption) {
|
|
44
|
+
if (cliOption !== undefined) {
|
|
45
|
+
return cliOption;
|
|
46
|
+
}
|
|
47
|
+
const envValue = process.env.IGNORE_HTTP_ERRORS;
|
|
48
|
+
if (envValue !== undefined) {
|
|
49
|
+
return envValue.toLowerCase() === "true" || envValue === "1" || envValue.toLowerCase() === "yes";
|
|
50
|
+
}
|
|
51
|
+
try {
|
|
52
|
+
const intunedJsonResult = await (0, _intunedJson.loadIntunedJson)();
|
|
53
|
+
if (intunedJsonResult.isOk() && intunedJsonResult.value.ignoreHttpErrors !== undefined) {
|
|
54
|
+
return intunedJsonResult.value.ignoreHttpErrors;
|
|
55
|
+
}
|
|
56
|
+
} catch (error) {}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
42
59
|
async function launchChromium(options) {
|
|
43
60
|
if ("cdpAddress" in options) {
|
|
44
61
|
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
@@ -49,9 +66,22 @@ async function launchChromium(options) {
|
|
|
49
66
|
throw new Error("No browser contexts found in the connected browser");
|
|
50
67
|
}
|
|
51
68
|
const context = browser.contexts()[0];
|
|
52
|
-
let page = context.pages().at(0);
|
|
53
|
-
|
|
54
|
-
|
|
69
|
+
let page = context.pages().at(0) ?? (await context.newPage());
|
|
70
|
+
const targetId = options.cdpTargetId;
|
|
71
|
+
if (targetId) {
|
|
72
|
+
for (const p of context.pages()) {
|
|
73
|
+
let cdp = null;
|
|
74
|
+
try {
|
|
75
|
+
cdp = await context.newCDPSession(p);
|
|
76
|
+
const result = await cdp.send("Target.getTargetInfo");
|
|
77
|
+
if (result.targetInfo.targetId === targetId) {
|
|
78
|
+
page = p;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
} catch (error) {} finally {
|
|
82
|
+
await cdp?.detach();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
55
85
|
}
|
|
56
86
|
return {
|
|
57
87
|
page,
|
|
@@ -63,7 +93,8 @@ async function launchChromium(options) {
|
|
|
63
93
|
appModeInitialUrl,
|
|
64
94
|
cdpPort,
|
|
65
95
|
proxy,
|
|
66
|
-
downloadsPath
|
|
96
|
+
downloadsPath,
|
|
97
|
+
ignoreHttpErrors
|
|
67
98
|
} = options;
|
|
68
99
|
let {
|
|
69
100
|
executablePath
|
|
@@ -112,7 +143,8 @@ async function launchChromium(options) {
|
|
|
112
143
|
proxy,
|
|
113
144
|
downloadsPath,
|
|
114
145
|
args: extraArgs,
|
|
115
|
-
ignoreDefaultArgs: defaultArgsToIgnore
|
|
146
|
+
ignoreDefaultArgs: defaultArgsToIgnore,
|
|
147
|
+
ignoreHTTPSErrors: ignoreHttpErrors
|
|
116
148
|
});
|
|
117
149
|
context.once("close", async () => {
|
|
118
150
|
try {
|
|
@@ -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;
|
|
@@ -20,9 +17,12 @@ export declare function withPlaywrightContext<R>(options: {
|
|
|
20
17
|
proxy?: Proxy;
|
|
21
18
|
headless: boolean;
|
|
22
19
|
downloadsPath: string;
|
|
20
|
+
ignoreHttpErrors?: boolean;
|
|
23
21
|
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
24
22
|
export declare function withPlaywrightContext<R>(options: {
|
|
25
23
|
cdpAddress: string;
|
|
24
|
+
cdpTargetId?: string;
|
|
25
|
+
ignoreHttpErrors?: boolean;
|
|
26
26
|
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
27
27
|
export declare function loadSessionToContext({ context, session, }: {
|
|
28
28
|
context: playwright.BrowserContext;
|
|
@@ -3,27 +3,24 @@
|
|
|
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,
|
|
23
|
+
ignoreHttpErrors: cliIgnoreHttpErrors,
|
|
27
24
|
importFunction,
|
|
28
25
|
apiName,
|
|
29
26
|
apiParameters
|
|
@@ -31,6 +28,7 @@ async function withPlaywrightContext({
|
|
|
31
28
|
let context;
|
|
32
29
|
let page;
|
|
33
30
|
try {
|
|
31
|
+
const ignoreHttpErrors = await (0, _launchBrowser.getIgnoreHttpErrorsFromConfig)(cliIgnoreHttpErrors);
|
|
34
32
|
const setupContextHookResult = importFunction ? await (0, _setupContextHook.loadSetupContextHook)({
|
|
35
33
|
importFunction
|
|
36
34
|
}) : (0, _neverthrow.ok)(null);
|
|
@@ -44,7 +42,9 @@ async function withPlaywrightContext({
|
|
|
44
42
|
page,
|
|
45
43
|
context
|
|
46
44
|
} = await (0, _launchBrowser.launchBrowser)({
|
|
47
|
-
cdpAddress
|
|
45
|
+
cdpAddress,
|
|
46
|
+
cdpTargetId,
|
|
47
|
+
ignoreHttpErrors
|
|
48
48
|
}));
|
|
49
49
|
} else {
|
|
50
50
|
({
|
|
@@ -53,7 +53,8 @@ async function withPlaywrightContext({
|
|
|
53
53
|
} = await (0, _launchBrowser.launchBrowser)({
|
|
54
54
|
proxy,
|
|
55
55
|
headless,
|
|
56
|
-
downloadsPath
|
|
56
|
+
downloadsPath,
|
|
57
|
+
ignoreHttpErrors
|
|
57
58
|
}));
|
|
58
59
|
}
|
|
59
60
|
return await fn(context, page);
|
|
@@ -65,7 +66,9 @@ async function withPlaywrightContext({
|
|
|
65
66
|
context,
|
|
66
67
|
page
|
|
67
68
|
} = await (0, _launchBrowser.launchBrowser)({
|
|
68
|
-
cdpAddress
|
|
69
|
+
cdpAddress,
|
|
70
|
+
cdpTargetId,
|
|
71
|
+
ignoreHttpErrors
|
|
69
72
|
}));
|
|
70
73
|
} else {
|
|
71
74
|
const port = await (0, _portfinder.getPort)({
|
|
@@ -78,7 +81,8 @@ async function withPlaywrightContext({
|
|
|
78
81
|
proxy,
|
|
79
82
|
headless,
|
|
80
83
|
downloadsPath,
|
|
81
|
-
cdpPort: port
|
|
84
|
+
cdpPort: port,
|
|
85
|
+
ignoreHttpErrors
|
|
82
86
|
}));
|
|
83
87
|
hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
|
|
84
88
|
}
|
|
@@ -96,7 +100,7 @@ async function withPlaywrightContext({
|
|
|
96
100
|
cdpUrl: hookCdpUrl
|
|
97
101
|
});
|
|
98
102
|
} catch (error) {
|
|
99
|
-
return (0, _neverthrow.err)(new
|
|
103
|
+
return (0, _neverthrow.err)(new _runtimeInterface.AutomationError(error));
|
|
100
104
|
}
|
|
101
105
|
if (!hookResult) {
|
|
102
106
|
return await fn(context, page);
|
|
@@ -120,7 +124,7 @@ async function withPlaywrightContext({
|
|
|
120
124
|
await cleanup?.();
|
|
121
125
|
} catch (e) {
|
|
122
126
|
result = {
|
|
123
|
-
return: (0, _neverthrow.err)(new
|
|
127
|
+
return: (0, _neverthrow.err)(new _runtimeInterface.AutomationError(e))
|
|
124
128
|
};
|
|
125
129
|
}
|
|
126
130
|
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"
|
|
@@ -170,6 +147,7 @@ async function runApi({
|
|
|
170
147
|
headless: runOptions.headless,
|
|
171
148
|
proxy: runOptions.proxy,
|
|
172
149
|
downloadsPath,
|
|
150
|
+
ignoreHttpErrors: runOptions.ignoreHttpErrors,
|
|
173
151
|
...playwrightContextParameters
|
|
174
152
|
}, runAutomationWithContext);
|
|
175
153
|
} finally {
|
|
@@ -178,15 +156,13 @@ async function runApi({
|
|
|
178
156
|
} else {
|
|
179
157
|
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
180
158
|
cdpAddress: runOptions.cdpAddress,
|
|
159
|
+
cdpTargetId: runOptions.cdpTargetId,
|
|
160
|
+
ignoreHttpErrors: runOptions.ignoreHttpErrors,
|
|
181
161
|
...playwrightContextParameters
|
|
182
162
|
}, runAutomationWithContext);
|
|
183
163
|
}
|
|
184
164
|
}
|
|
185
|
-
|
|
186
|
-
if (result === abortSymbol) {
|
|
187
|
-
return (0, _neverthrow.err)(new _errors.AbortedError());
|
|
188
|
-
}
|
|
189
|
-
return result;
|
|
165
|
+
return await runAutomation();
|
|
190
166
|
}
|
|
191
167
|
async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
|
|
192
168
|
if (retries === 0) {
|