@intuned/runtime-dev 1.3.9-dev9 → 1.3.11-deployment.0
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/intuned-cli/commands/attempt_api.command.js +1 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +3 -0
- package/dist/commands/intuned-cli/commands/types.d.ts +4 -0
- package/dist/commands/intuned-cli/commands/types.js +5 -3
- package/dist/commands/intuned-cli/controller/api.d.ts +1 -1
- package/dist/commands/intuned-cli/controller/api.js +4 -2
- package/dist/commands/intuned-cli/controller/authSession.d.ts +2 -2
- package/dist/commands/intuned-cli/controller/authSession.js +8 -4
- package/dist/commands/intuned-cli/controller/deploy.d.ts +1 -0
- package/dist/commands/intuned-cli/controller/deploy.js +141 -6
- package/dist/commands/intuned-cli/controller/save.d.ts +4 -1
- package/dist/commands/intuned-cli/controller/save.js +8 -2
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +11 -0
- package/dist/commands/intuned-cli/helpers/backend.js +1 -1
- package/dist/commands/intuned-cli/helpers/browser.d.ts +2 -1
- package/dist/commands/intuned-cli/helpers/browser.js +8 -1
- package/dist/commands/intuned-cli/helpers/errors.d.ts +3 -0
- package/dist/commands/intuned-cli/helpers/errors.js +8 -1
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +113 -11
- package/dist/commands/intuned-cli/helpers/intunedJson.js +19 -3
- package/dist/commands/intuned-cli/helpers/wrapper.js +7 -1
- package/dist/commands/intuned-cli/main.js +1 -0
- package/package.json +6 -2
- package/package/dist/commands/api/run.d.ts +0 -6
- package/package/dist/commands/api/run.js +0 -123
- package/package/dist/commands/auth-sessions/load.d.ts +0 -2
- package/package/dist/commands/auth-sessions/load.js +0 -35
- package/package/dist/commands/auth-sessions/run-check.d.ts +0 -2
- package/package/dist/commands/auth-sessions/run-check.js +0 -74
- package/package/dist/commands/auth-sessions/run-create.d.ts +0 -2
- package/package/dist/commands/auth-sessions/run-create.js +0 -78
- package/package/dist/commands/browser/save-state.d.ts +0 -2
- package/package/dist/commands/browser/save-state.js +0 -17
- package/package/dist/commands/browser/start-browser.d.ts +0 -2
- package/package/dist/commands/browser/start-browser.js +0 -14
- package/package/dist/commands/build.d.ts +0 -1
- package/package/dist/commands/build.js +0 -84
- package/package/dist/commands/common/browserUtils.d.ts +0 -14
- package/package/dist/commands/common/browserUtils.js +0 -58
- package/package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
- package/package/dist/commands/common/getFirstLineNumber.js +0 -101
- package/package/dist/commands/common/getFirstLineNumber.test.js +0 -228
- package/package/dist/commands/common/projectExclusions.d.ts +0 -2
- package/package/dist/commands/common/projectExclusions.js +0 -8
- package/package/dist/commands/common/sendMessageToClient.d.ts +0 -1
- package/package/dist/commands/common/sendMessageToClient.js +0 -10
- package/package/dist/commands/common/tsNodeImport.d.ts +0 -2
- package/package/dist/commands/common/tsNodeImport.js +0 -34
- package/package/dist/commands/common/utils/fileUtils.d.ts +0 -6
- package/package/dist/commands/common/utils/fileUtils.js +0 -33
- package/package/dist/commands/common/utils/settings.d.ts +0 -2
- package/package/dist/commands/common/utils/settings.js +0 -31
- package/package/dist/commands/common/utils/template.d.ts +0 -2
- package/package/dist/commands/common/utils/template.js +0 -31
- package/package/dist/commands/common/utils/unixSocket.d.ts +0 -9
- package/package/dist/commands/common/utils/unixSocket.js +0 -44
- package/package/dist/commands/interface/run.d.ts +0 -1
- package/package/dist/commands/interface/run.js +0 -216
- package/package/dist/commands/intuned-cli/commands/attempt.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/attempt.command.js +0 -8
- package/package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/attempt_api.command.js +0 -30
- package/package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +0 -8
- package/package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +0 -19
- package/package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +0 -24
- package/package/dist/commands/intuned-cli/commands/authsession.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/authsession.command.js +0 -8
- package/package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/authsession_record.command.js +0 -31
- package/package/dist/commands/intuned-cli/commands/build.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/build.command.js +0 -12
- package/package/dist/commands/intuned-cli/commands/command.d.ts +0 -2
- package/package/dist/commands/intuned-cli/commands/command.js +0 -9
- package/package/dist/commands/intuned-cli/commands/deploy.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/deploy.command.js +0 -38
- package/package/dist/commands/intuned-cli/commands/index.d.ts +0 -18
- package/package/dist/commands/intuned-cli/commands/index.js +0 -203
- package/package/dist/commands/intuned-cli/commands/init.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/init.command.js +0 -13
- package/package/dist/commands/intuned-cli/commands/run.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/run.command.js +0 -8
- package/package/dist/commands/intuned-cli/commands/run_api.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/run_api.command.js +0 -46
- package/package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -28
- package/package/dist/commands/intuned-cli/commands/run_authsession.command.js +0 -17
- package/package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +0 -35
- package/package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +0 -35
- package/package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +0 -1
- package/package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +0 -33
- package/package/dist/commands/intuned-cli/commands/save.command.d.ts +0 -13
- package/package/dist/commands/intuned-cli/commands/save.command.js +0 -42
- package/package/dist/commands/intuned-cli/commands/types.d.ts +0 -31
- package/package/dist/commands/intuned-cli/commands/types.js +0 -29
- package/package/dist/commands/intuned-cli/constants/index.d.ts +0 -17
- package/package/dist/commands/intuned-cli/constants/index.js +0 -25
- package/package/dist/commands/intuned-cli/controller/__test__/api.test.js +0 -397
- package/package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +0 -1059
- package/package/dist/commands/intuned-cli/controller/api.d.ts +0 -42
- package/package/dist/commands/intuned-cli/controller/api.js +0 -189
- package/package/dist/commands/intuned-cli/controller/authSession.d.ts +0 -209
- package/package/dist/commands/intuned-cli/controller/authSession.js +0 -420
- package/package/dist/commands/intuned-cli/controller/build.d.ts +0 -1
- package/package/dist/commands/intuned-cli/controller/build.js +0 -36
- package/package/dist/commands/intuned-cli/controller/deploy.d.ts +0 -4
- package/package/dist/commands/intuned-cli/controller/deploy.js +0 -139
- package/package/dist/commands/intuned-cli/controller/index.d.ts +0 -1
- package/package/dist/commands/intuned-cli/controller/index.js +0 -46
- package/package/dist/commands/intuned-cli/controller/save.d.ts +0 -14
- package/package/dist/commands/intuned-cli/controller/save.js +0 -345
- package/package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +0 -103
- package/package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +0 -40
- package/package/dist/commands/intuned-cli/helpers/api.d.ts +0 -3
- package/package/dist/commands/intuned-cli/helpers/api.js +0 -19
- package/package/dist/commands/intuned-cli/helpers/auth.d.ts +0 -46
- package/package/dist/commands/intuned-cli/helpers/auth.js +0 -144
- package/package/dist/commands/intuned-cli/helpers/backend.d.ts +0 -8
- package/package/dist/commands/intuned-cli/helpers/backend.js +0 -27
- package/package/dist/commands/intuned-cli/helpers/browser.d.ts +0 -14
- package/package/dist/commands/intuned-cli/helpers/browser.js +0 -57
- package/package/dist/commands/intuned-cli/helpers/context.d.ts +0 -3
- package/package/dist/commands/intuned-cli/helpers/context.js +0 -33
- package/package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -13
- package/package/dist/commands/intuned-cli/helpers/errors.js +0 -37
- package/package/dist/commands/intuned-cli/helpers/index.d.ts +0 -12
- package/package/dist/commands/intuned-cli/helpers/index.js +0 -137
- package/package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +0 -69
- package/package/dist/commands/intuned-cli/helpers/intunedJson.js +0 -71
- package/package/dist/commands/intuned-cli/helpers/proxy.d.ts +0 -5
- package/package/dist/commands/intuned-cli/helpers/proxy.js +0 -23
- package/package/dist/commands/intuned-cli/helpers/terminal.d.ts +0 -5
- package/package/dist/commands/intuned-cli/helpers/terminal.js +0 -13
- package/package/dist/commands/intuned-cli/helpers/timeout.d.ts +0 -1
- package/package/dist/commands/intuned-cli/helpers/timeout.js +0 -23
- package/package/dist/commands/intuned-cli/helpers/traces.d.ts +0 -2
- package/package/dist/commands/intuned-cli/helpers/traces.js +0 -32
- package/package/dist/commands/intuned-cli/helpers/validation.d.ts +0 -2
- package/package/dist/commands/intuned-cli/helpers/validation.js +0 -14
- package/package/dist/commands/intuned-cli/helpers/wrapper.d.ts +0 -2
- package/package/dist/commands/intuned-cli/helpers/wrapper.js +0 -60
- package/package/dist/commands/intuned-cli/index.d.ts +0 -1
- package/package/dist/commands/intuned-cli/index.js +0 -16
- package/package/dist/commands/intuned-cli/main.d.ts +0 -1
- package/package/dist/commands/intuned-cli/main.js +0 -22
- package/package/dist/commands/intuned-cli/types.d.ts +0 -41
- package/package/dist/commands/intuned-cli/types.js +0 -12
- package/package/dist/commands/ts-check.d.ts +0 -2
- package/package/dist/commands/ts-check.js +0 -56
- package/package/dist/common/Logger/Logger/index.d.ts +0 -12
- package/package/dist/common/Logger/Logger/index.js +0 -60
- package/package/dist/common/Logger/Logger/types.d.ts +0 -8
- package/package/dist/common/Logger/Logger/types.js +0 -5
- package/package/dist/common/Logger/index.d.ts +0 -12
- package/package/dist/common/Logger/index.js +0 -60
- package/package/dist/common/Logger/types.d.ts +0 -8
- package/package/dist/common/Logger/types.js +0 -5
- package/package/dist/common/assets/browser_scripts.js +0 -2580
- package/package/dist/common/asyncLocalStorage/index.d.ts +0 -16
- package/package/dist/common/asyncLocalStorage/index.js +0 -17
- package/package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +0 -1
- package/package/dist/common/backendFunctions/getAuthSessionParameters.js +0 -38
- package/package/dist/common/cleanEnvironmentVariables.d.ts +0 -1
- package/package/dist/common/cleanEnvironmentVariables.js +0 -16
- package/package/dist/common/constants.d.ts +0 -10
- package/package/dist/common/constants.js +0 -16
- package/package/dist/common/contextStorageStateHelpers.d.ts +0 -21
- package/package/dist/common/contextStorageStateHelpers.js +0 -81
- package/package/dist/common/extensionsHelpers.d.ts +0 -8
- package/package/dist/common/extensionsHelpers.js +0 -80
- package/package/dist/common/formatZodError.d.ts +0 -2
- package/package/dist/common/formatZodError.js +0 -18
- package/package/dist/common/jwtTokenManager.d.ts +0 -17
- package/package/dist/common/jwtTokenManager.js +0 -109
- package/package/dist/common/launchBrowser.d.ts +0 -25
- package/package/dist/common/launchBrowser.js +0 -172
- package/package/dist/common/playwrightContext.d.ts +0 -31
- package/package/dist/common/playwrightContext.js +0 -144
- package/package/dist/common/runApi/errors.d.ts +0 -72
- package/package/dist/common/runApi/errors.js +0 -169
- package/package/dist/common/runApi/importUsingImportFunction.d.ts +0 -9
- package/package/dist/common/runApi/importUsingImportFunction.js +0 -46
- package/package/dist/common/runApi/index.d.ts +0 -11
- package/package/dist/common/runApi/index.js +0 -199
- package/package/dist/common/runApi/types.d.ts +0 -830
- package/package/dist/common/runApi/types.js +0 -73
- package/package/dist/common/settingsSchema.d.ts +0 -518
- package/package/dist/common/settingsSchema.js +0 -57
- package/package/dist/common/setupContextHook.d.ts +0 -17
- package/package/dist/common/setupContextHook.js +0 -22
- package/package/dist/common/telemetry.d.ts +0 -3
- package/package/dist/common/telemetry.js +0 -32
- package/package/dist/index.d.ts +0 -4
- package/package/dist/index.js +0 -69
- package/package/dist/runtime/RunError.d.ts +0 -5
- package/package/dist/runtime/RunError.js +0 -19
- package/package/dist/runtime/attemptStore.d.ts +0 -2
- package/package/dist/runtime/attemptStore.js +0 -23
- package/package/dist/runtime/downloadDirectory.d.ts +0 -1
- package/package/dist/runtime/downloadDirectory.js +0 -19
- package/package/dist/runtime/enums.d.js +0 -5
- package/package/dist/runtime/enums.d.ts +0 -11
- package/package/dist/runtime/enums.js +0 -18
- package/package/dist/runtime/executionHelpers.test.js +0 -52
- package/package/dist/runtime/export.d.js +0 -5
- package/package/dist/runtime/export.d.ts +0 -228
- package/package/dist/runtime/extendPayload.d.ts +0 -2
- package/package/dist/runtime/extendPayload.js +0 -21
- package/package/dist/runtime/extendTimeout.d.ts +0 -1
- package/package/dist/runtime/extendTimeout.js +0 -23
- package/package/dist/runtime/getAuthSessionParameters.d.ts +0 -1
- package/package/dist/runtime/getAuthSessionParameters.js +0 -20
- package/package/dist/runtime/index.d.ts +0 -7
- package/package/dist/runtime/index.js +0 -54
- package/package/dist/runtime/runInfo.d.ts +0 -2
- package/package/dist/runtime/runInfo.js +0 -21
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import * as playwright from "playwright";
|
|
2
|
-
import { RunAutomationError } from "./runApi/errors";
|
|
3
|
-
import type { RunApiSession } from "./runApi/types";
|
|
4
|
-
import { Err, Ok } from "neverthrow";
|
|
5
|
-
import { type ImportFunction } from "./runApi/importUsingImportFunction";
|
|
6
|
-
import { type Proxy } from "./launchBrowser";
|
|
7
|
-
export declare const browserScriptsFile: string;
|
|
8
|
-
type WithPlaywrightContextParameters = {
|
|
9
|
-
importFunction: ImportFunction;
|
|
10
|
-
apiName: string;
|
|
11
|
-
apiParameters: any;
|
|
12
|
-
} | {
|
|
13
|
-
importFunction?: undefined;
|
|
14
|
-
apiName?: undefined;
|
|
15
|
-
apiParameters?: undefined;
|
|
16
|
-
};
|
|
17
|
-
type WithPlaywrightContextWrappedFunctionReturn<R> = Ok<R, any> | Err<any, RunAutomationError>;
|
|
18
|
-
export type WithPlaywrightContextWrappedFunction<R> = (context: playwright.BrowserContext, page: playwright.Page) => Promise<WithPlaywrightContextWrappedFunctionReturn<R>>;
|
|
19
|
-
export declare function withPlaywrightContext<R>(options: {
|
|
20
|
-
proxy?: Proxy;
|
|
21
|
-
headless: boolean;
|
|
22
|
-
downloadsPath: string;
|
|
23
|
-
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
24
|
-
export declare function withPlaywrightContext<R>(options: {
|
|
25
|
-
cdpAddress: string;
|
|
26
|
-
} & WithPlaywrightContextParameters, fn: WithPlaywrightContextWrappedFunction<R>): Promise<Ok<R, any> | Err<any, RunAutomationError>>;
|
|
27
|
-
export declare function loadSessionToContext({ context, session, }: {
|
|
28
|
-
context: playwright.BrowserContext;
|
|
29
|
-
session: RunApiSession;
|
|
30
|
-
}): Promise<void>;
|
|
31
|
-
export {};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.browserScriptsFile = void 0;
|
|
7
|
-
exports.loadSessionToContext = loadSessionToContext;
|
|
8
|
-
exports.withPlaywrightContext = withPlaywrightContext;
|
|
9
|
-
var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
|
|
10
|
-
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
12
|
-
var _fileUtils = require("../commands/common/utils/fileUtils");
|
|
13
|
-
var _errors = require("./runApi/errors");
|
|
14
|
-
var _neverthrow = require("neverthrow");
|
|
15
|
-
var _setupContextHook = require("./setupContextHook");
|
|
16
|
-
var _portfinder = require("portfinder");
|
|
17
|
-
var _launchBrowser = require("./launchBrowser");
|
|
18
|
-
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
|
-
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
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
|
-
const browserScriptsFile = exports.browserScriptsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
|
|
22
|
-
async function withPlaywrightContext({
|
|
23
|
-
cdpAddress,
|
|
24
|
-
proxy,
|
|
25
|
-
headless = true,
|
|
26
|
-
downloadsPath,
|
|
27
|
-
importFunction,
|
|
28
|
-
apiName,
|
|
29
|
-
apiParameters
|
|
30
|
-
}, fn) {
|
|
31
|
-
let context;
|
|
32
|
-
let page;
|
|
33
|
-
try {
|
|
34
|
-
const setupContextHookResult = importFunction ? await (0, _setupContextHook.loadSetupContextHook)({
|
|
35
|
-
importFunction
|
|
36
|
-
}) : (0, _neverthrow.ok)(null);
|
|
37
|
-
if (setupContextHookResult.isErr()) {
|
|
38
|
-
return setupContextHookResult;
|
|
39
|
-
}
|
|
40
|
-
const setupContextHook = setupContextHookResult.value;
|
|
41
|
-
if (setupContextHook === null) {
|
|
42
|
-
if (cdpAddress !== undefined) {
|
|
43
|
-
({
|
|
44
|
-
page,
|
|
45
|
-
context
|
|
46
|
-
} = await (0, _launchBrowser.launchBrowser)({
|
|
47
|
-
cdpAddress
|
|
48
|
-
}));
|
|
49
|
-
} else {
|
|
50
|
-
({
|
|
51
|
-
page,
|
|
52
|
-
context
|
|
53
|
-
} = await (0, _launchBrowser.launchBrowser)({
|
|
54
|
-
proxy,
|
|
55
|
-
headless,
|
|
56
|
-
downloadsPath
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
return await fn(context, page);
|
|
60
|
-
}
|
|
61
|
-
let hookCdpUrl = null;
|
|
62
|
-
if (cdpAddress) {
|
|
63
|
-
hookCdpUrl = cdpAddress;
|
|
64
|
-
({
|
|
65
|
-
context,
|
|
66
|
-
page
|
|
67
|
-
} = await (0, _launchBrowser.launchBrowser)({
|
|
68
|
-
cdpAddress
|
|
69
|
-
}));
|
|
70
|
-
} else {
|
|
71
|
-
const port = await (0, _portfinder.getPort)({
|
|
72
|
-
port: 9222
|
|
73
|
-
});
|
|
74
|
-
hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
|
|
75
|
-
({
|
|
76
|
-
context,
|
|
77
|
-
page
|
|
78
|
-
} = await (0, _launchBrowser.launchBrowser)({
|
|
79
|
-
proxy,
|
|
80
|
-
headless,
|
|
81
|
-
downloadsPath,
|
|
82
|
-
cdpPort: port
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
let hookResult;
|
|
86
|
-
try {
|
|
87
|
-
hookResult = await setupContextHook({
|
|
88
|
-
apiName: apiName,
|
|
89
|
-
apiParameters: apiParameters,
|
|
90
|
-
cdpUrl: hookCdpUrl
|
|
91
|
-
});
|
|
92
|
-
} catch (error) {
|
|
93
|
-
return (0, _neverthrow.err)(new _errors.AutomationError(error));
|
|
94
|
-
}
|
|
95
|
-
if (!hookResult) {
|
|
96
|
-
return await fn(context, page);
|
|
97
|
-
}
|
|
98
|
-
const {
|
|
99
|
-
page: newPage,
|
|
100
|
-
context: newContext,
|
|
101
|
-
cleanup
|
|
102
|
-
} = hookResult;
|
|
103
|
-
let result;
|
|
104
|
-
try {
|
|
105
|
-
result = {
|
|
106
|
-
return: await fn(newContext, newPage ?? page)
|
|
107
|
-
};
|
|
108
|
-
} catch (e) {
|
|
109
|
-
result = {
|
|
110
|
-
throw: e
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
await cleanup?.();
|
|
115
|
-
} catch (e) {
|
|
116
|
-
result = {
|
|
117
|
-
return: (0, _neverthrow.err)(new _errors.AutomationError(e))
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
if ("throw" in result) {
|
|
121
|
-
throw result.throw;
|
|
122
|
-
}
|
|
123
|
-
return result.return;
|
|
124
|
-
} finally {
|
|
125
|
-
await context?.close();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async function loadSessionToContext({
|
|
129
|
-
context,
|
|
130
|
-
session
|
|
131
|
-
}) {
|
|
132
|
-
let sessionToLoad;
|
|
133
|
-
if (session.type === "state") {
|
|
134
|
-
const state = session.state;
|
|
135
|
-
if (state === undefined || state === null) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
sessionToLoad = state;
|
|
139
|
-
} else {
|
|
140
|
-
const fullPath = (0, _fileUtils.getFullPathInProject)(session.path);
|
|
141
|
-
sessionToLoad = await fs.readJson(fullPath);
|
|
142
|
-
}
|
|
143
|
-
await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
|
|
144
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { RunErrorOptions } from "../../runtime/export";
|
|
2
|
-
export declare const apiNotFoundErrorCode = "APINotFoundError";
|
|
3
|
-
export declare const invalidApiErrorCode = "InvalidAPIError";
|
|
4
|
-
export declare const invalidCheckErrorCode = "InvalidCheckError";
|
|
5
|
-
export declare const abortedErrorCode = "AbortedError";
|
|
6
|
-
export declare const authRequiredErrorCode = "AuthRequiredError";
|
|
7
|
-
export declare const authCheckNotFoundErrorCode = "AuthCheckNotFoundError";
|
|
8
|
-
export declare const authCheckFailedErrorCode = "AuthCheckFailedError";
|
|
9
|
-
export declare const maxLevelsExceededErrorCode = "MaxLevelsExceededError";
|
|
10
|
-
export declare const automationError = "AutomationError";
|
|
11
|
-
export declare const internalInvalidInputErrorCode = "InternalInvalidInputError";
|
|
12
|
-
export declare const resultTooBigErrorCode = "ResultTooBigError";
|
|
13
|
-
export declare const runAutomationErrorCodes: readonly ["APINotFoundError", "InvalidAPIError", "InvalidCheckError", "AbortedError", "AuthRequiredError", "AuthCheckNotFoundError", "AuthCheckFailedError", "MaxLevelsExceededError", "AutomationError", "InternalInvalidInputError", "ResultTooBigError"];
|
|
14
|
-
export type RunAutomationErrorCode = typeof runAutomationErrorCodes[number];
|
|
15
|
-
export declare abstract class RunAutomationError<T = any> {
|
|
16
|
-
code: RunAutomationErrorCode;
|
|
17
|
-
statusCode: number;
|
|
18
|
-
wrapped: boolean;
|
|
19
|
-
message: string;
|
|
20
|
-
cause?: RunAutomationError;
|
|
21
|
-
details?: T;
|
|
22
|
-
get json(): {
|
|
23
|
-
code: "APINotFoundError" | "InvalidAPIError" | "InvalidCheckError" | "AbortedError" | "AuthRequiredError" | "AuthCheckNotFoundError" | "AuthCheckFailedError" | "MaxLevelsExceededError" | "AutomationError" | "InternalInvalidInputError" | "ResultTooBigError";
|
|
24
|
-
details: T | undefined;
|
|
25
|
-
cause: any;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
export declare class ApiNotFoundError extends RunAutomationError {
|
|
29
|
-
constructor(apiName: string);
|
|
30
|
-
}
|
|
31
|
-
export declare class InvalidApiError extends RunAutomationError {
|
|
32
|
-
constructor(message: string);
|
|
33
|
-
}
|
|
34
|
-
export declare class InvalidCheckError extends RunAutomationError {
|
|
35
|
-
constructor(message: string, cause?: RunAutomationError);
|
|
36
|
-
}
|
|
37
|
-
export declare class AbortedError extends RunAutomationError {
|
|
38
|
-
constructor();
|
|
39
|
-
}
|
|
40
|
-
export declare class AuthRequiredError extends RunAutomationError {
|
|
41
|
-
constructor();
|
|
42
|
-
}
|
|
43
|
-
export declare class AuthCheckNotFoundError extends RunAutomationError {
|
|
44
|
-
constructor();
|
|
45
|
-
}
|
|
46
|
-
export declare class AuthCheckFailedError extends RunAutomationError {
|
|
47
|
-
constructor();
|
|
48
|
-
}
|
|
49
|
-
export declare class MaxLevelsExceededError extends RunAutomationError<{
|
|
50
|
-
levels: number;
|
|
51
|
-
}> {
|
|
52
|
-
constructor(levels: number);
|
|
53
|
-
}
|
|
54
|
-
export declare class AutomationError extends RunAutomationError<{
|
|
55
|
-
name?: string;
|
|
56
|
-
message?: string;
|
|
57
|
-
statusCode?: number;
|
|
58
|
-
errorCode?: string;
|
|
59
|
-
options?: RunErrorOptions;
|
|
60
|
-
}> {
|
|
61
|
-
error: any;
|
|
62
|
-
constructor(error: any);
|
|
63
|
-
}
|
|
64
|
-
export declare class InternalInvalidInputError extends RunAutomationError {
|
|
65
|
-
constructor(message: string, details?: any);
|
|
66
|
-
}
|
|
67
|
-
export declare class ResultTooBigError extends RunAutomationError<{
|
|
68
|
-
sizeInBytes: number;
|
|
69
|
-
maxSizeInBytes: number;
|
|
70
|
-
}> {
|
|
71
|
-
constructor(sizeInBytes: number, maxSizeInBytes: number);
|
|
72
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.runAutomationErrorCodes = exports.resultTooBigErrorCode = exports.maxLevelsExceededErrorCode = exports.invalidCheckErrorCode = exports.invalidApiErrorCode = exports.internalInvalidInputErrorCode = exports.automationError = exports.authRequiredErrorCode = exports.authCheckNotFoundErrorCode = exports.authCheckFailedErrorCode = exports.apiNotFoundErrorCode = exports.abortedErrorCode = exports.RunAutomationError = exports.ResultTooBigError = exports.MaxLevelsExceededError = exports.InvalidCheckError = exports.InvalidApiError = exports.InternalInvalidInputError = exports.AutomationError = exports.AuthRequiredError = exports.AuthCheckNotFoundError = exports.AuthCheckFailedError = exports.ApiNotFoundError = exports.AbortedError = void 0;
|
|
7
|
-
var _runtime = require("../../runtime");
|
|
8
|
-
var playwright = _interopRequireWildcard(require("playwright-core"));
|
|
9
|
-
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); }
|
|
10
|
-
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; }
|
|
11
|
-
const apiNotFoundErrorCode = exports.apiNotFoundErrorCode = "APINotFoundError";
|
|
12
|
-
const invalidApiErrorCode = exports.invalidApiErrorCode = "InvalidAPIError";
|
|
13
|
-
const invalidCheckErrorCode = exports.invalidCheckErrorCode = "InvalidCheckError";
|
|
14
|
-
const abortedErrorCode = exports.abortedErrorCode = "AbortedError";
|
|
15
|
-
const authRequiredErrorCode = exports.authRequiredErrorCode = "AuthRequiredError";
|
|
16
|
-
const authCheckNotFoundErrorCode = exports.authCheckNotFoundErrorCode = "AuthCheckNotFoundError";
|
|
17
|
-
const authCheckFailedErrorCode = exports.authCheckFailedErrorCode = "AuthCheckFailedError";
|
|
18
|
-
const maxLevelsExceededErrorCode = exports.maxLevelsExceededErrorCode = "MaxLevelsExceededError";
|
|
19
|
-
const automationError = exports.automationError = "AutomationError";
|
|
20
|
-
const internalInvalidInputErrorCode = exports.internalInvalidInputErrorCode = "InternalInvalidInputError";
|
|
21
|
-
const resultTooBigErrorCode = exports.resultTooBigErrorCode = "ResultTooBigError";
|
|
22
|
-
const runAutomationErrorCodes = exports.runAutomationErrorCodes = [apiNotFoundErrorCode, invalidApiErrorCode, invalidCheckErrorCode, abortedErrorCode, authRequiredErrorCode, authCheckNotFoundErrorCode, authCheckFailedErrorCode, maxLevelsExceededErrorCode, automationError, internalInvalidInputErrorCode, resultTooBigErrorCode];
|
|
23
|
-
class RunAutomationError {
|
|
24
|
-
wrapped = false;
|
|
25
|
-
get json() {
|
|
26
|
-
return {
|
|
27
|
-
code: this.code,
|
|
28
|
-
details: this.details,
|
|
29
|
-
cause: this.cause?.json
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.RunAutomationError = RunAutomationError;
|
|
34
|
-
class ApiNotFoundError extends RunAutomationError {
|
|
35
|
-
constructor(apiName) {
|
|
36
|
-
super();
|
|
37
|
-
this.code = apiNotFoundErrorCode;
|
|
38
|
-
this.statusCode = 404;
|
|
39
|
-
this.message = `API ${apiName} not found`;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.ApiNotFoundError = ApiNotFoundError;
|
|
43
|
-
class InvalidApiError extends RunAutomationError {
|
|
44
|
-
constructor(message) {
|
|
45
|
-
super();
|
|
46
|
-
this.code = invalidApiErrorCode;
|
|
47
|
-
this.statusCode = 400;
|
|
48
|
-
this.message = `API is invalid: ${message}`;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.InvalidApiError = InvalidApiError;
|
|
52
|
-
class InvalidCheckError extends RunAutomationError {
|
|
53
|
-
constructor(message, cause) {
|
|
54
|
-
super();
|
|
55
|
-
this.code = invalidCheckErrorCode;
|
|
56
|
-
this.statusCode = 400;
|
|
57
|
-
this.message = message;
|
|
58
|
-
this.cause = cause;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
exports.InvalidCheckError = InvalidCheckError;
|
|
62
|
-
class AbortedError extends RunAutomationError {
|
|
63
|
-
constructor() {
|
|
64
|
-
super();
|
|
65
|
-
this.code = abortedErrorCode;
|
|
66
|
-
this.statusCode = 200;
|
|
67
|
-
this.message = "Operation was aborted";
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.AbortedError = AbortedError;
|
|
71
|
-
class AuthRequiredError extends RunAutomationError {
|
|
72
|
-
constructor() {
|
|
73
|
-
super();
|
|
74
|
-
this.code = authRequiredErrorCode;
|
|
75
|
-
this.statusCode = 401;
|
|
76
|
-
this.message = "Authentication is required";
|
|
77
|
-
this.wrapped = true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
exports.AuthRequiredError = AuthRequiredError;
|
|
81
|
-
class AuthCheckNotFoundError extends RunAutomationError {
|
|
82
|
-
constructor() {
|
|
83
|
-
super();
|
|
84
|
-
this.code = authCheckNotFoundErrorCode;
|
|
85
|
-
this.statusCode = 404;
|
|
86
|
-
this.message = "Auth check not found";
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
exports.AuthCheckNotFoundError = AuthCheckNotFoundError;
|
|
90
|
-
class AuthCheckFailedError extends RunAutomationError {
|
|
91
|
-
constructor() {
|
|
92
|
-
super();
|
|
93
|
-
this.code = authCheckFailedErrorCode;
|
|
94
|
-
this.statusCode = 401;
|
|
95
|
-
this.message = "auth session check failed";
|
|
96
|
-
this.wrapped = true;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
exports.AuthCheckFailedError = AuthCheckFailedError;
|
|
100
|
-
class MaxLevelsExceededError extends RunAutomationError {
|
|
101
|
-
constructor(levels) {
|
|
102
|
-
super();
|
|
103
|
-
this.code = maxLevelsExceededErrorCode;
|
|
104
|
-
this.statusCode = 400;
|
|
105
|
-
this.message = `Max levels exceeded. Only ${levels} levels are supported`;
|
|
106
|
-
this.details = {
|
|
107
|
-
levels
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
exports.MaxLevelsExceededError = MaxLevelsExceededError;
|
|
112
|
-
class AutomationError extends RunAutomationError {
|
|
113
|
-
constructor(error) {
|
|
114
|
-
super();
|
|
115
|
-
this.error = error;
|
|
116
|
-
this.code = automationError;
|
|
117
|
-
if (error instanceof playwright.errors.TimeoutError) {
|
|
118
|
-
this.statusCode = 500;
|
|
119
|
-
this.message = `[${error.name}] ${error.message}`;
|
|
120
|
-
this.details = {
|
|
121
|
-
name: error.name,
|
|
122
|
-
message: error.message
|
|
123
|
-
};
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (error instanceof _runtime.RunError) {
|
|
127
|
-
this.wrapped = true;
|
|
128
|
-
this.statusCode = error.options.status_code ?? 500;
|
|
129
|
-
this.message = `[${error.options.error_code ?? error.name}] ${error.message}`;
|
|
130
|
-
this.details = {
|
|
131
|
-
name: error.name,
|
|
132
|
-
statusCode: error.options.status_code,
|
|
133
|
-
errorCode: error.options.error_code,
|
|
134
|
-
message: error.message,
|
|
135
|
-
options: error.options
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
this.statusCode = 500;
|
|
139
|
-
this.message = `[${error?.name ?? error}] ${error?.message}`;
|
|
140
|
-
this.details = {
|
|
141
|
-
name: error?.name,
|
|
142
|
-
message: error?.message
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
exports.AutomationError = AutomationError;
|
|
147
|
-
class InternalInvalidInputError extends RunAutomationError {
|
|
148
|
-
constructor(message, details) {
|
|
149
|
-
super();
|
|
150
|
-
this.code = internalInvalidInputErrorCode;
|
|
151
|
-
this.statusCode = 500;
|
|
152
|
-
this.message = message;
|
|
153
|
-
this.details = details;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
exports.InternalInvalidInputError = InternalInvalidInputError;
|
|
157
|
-
class ResultTooBigError extends RunAutomationError {
|
|
158
|
-
constructor(sizeInBytes, maxSizeInBytes) {
|
|
159
|
-
super();
|
|
160
|
-
this.code = resultTooBigErrorCode;
|
|
161
|
-
this.statusCode = 413;
|
|
162
|
-
this.message = `Automation result is too big. Size: ${Math.round(sizeInBytes / 1024 / 1024 * 100) / 100}MB, Max allowed: ${Math.round(maxSizeInBytes / 1024 / 1024 * 100) / 100}MB`;
|
|
163
|
-
this.details = {
|
|
164
|
-
sizeInBytes,
|
|
165
|
-
maxSizeInBytes
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
exports.ResultTooBigError = ResultTooBigError;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Result } from "neverthrow";
|
|
2
|
-
import { RunAutomationError } from "./errors";
|
|
3
|
-
import { ExtendedRunApiParameters } from "./types";
|
|
4
|
-
export type ImportFunction = ExtendedRunApiParameters["importFunction"];
|
|
5
|
-
export declare function importUsingImportFunction<_ReturnType = any>({ path, allowGenerators, importFunction, }: {
|
|
6
|
-
path: string;
|
|
7
|
-
importFunction: ImportFunction;
|
|
8
|
-
allowGenerators?: boolean;
|
|
9
|
-
}): Promise<Result<(..._: any) => Promise<_ReturnType>, RunAutomationError>>;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.importUsingImportFunction = importUsingImportFunction;
|
|
7
|
-
var _neverthrow = require("neverthrow");
|
|
8
|
-
var _errors = require("./errors");
|
|
9
|
-
async function importUsingImportFunction({
|
|
10
|
-
path,
|
|
11
|
-
allowGenerators = true,
|
|
12
|
-
importFunction
|
|
13
|
-
}) {
|
|
14
|
-
try {
|
|
15
|
-
const importedResult = await importFunction(path);
|
|
16
|
-
if (importedResult.isErr()) {
|
|
17
|
-
if (importedResult.error.type === "not_found") {
|
|
18
|
-
return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
|
|
19
|
-
}
|
|
20
|
-
return (0, _neverthrow.err)(new _errors.AutomationError(importedResult.error.error));
|
|
21
|
-
}
|
|
22
|
-
const imported = importedResult.value;
|
|
23
|
-
if (!imported || !imported.default || !imported.default.constructor) {
|
|
24
|
-
return (0, _neverthrow.err)(new _errors.InvalidApiError(`${path} does not have a default export`));
|
|
25
|
-
}
|
|
26
|
-
if (imported.default.constructor.name === "AsyncGeneratorFunction") {
|
|
27
|
-
if (!allowGenerators) {
|
|
28
|
-
return (0, _neverthrow.err)(new _errors.InvalidApiError(`${path} default export must be an async function`));
|
|
29
|
-
}
|
|
30
|
-
return (0, _neverthrow.ok)(async (...args) => {
|
|
31
|
-
const generator = imported.default(...args);
|
|
32
|
-
const result = await generator.next();
|
|
33
|
-
if (!result.done) {
|
|
34
|
-
throw new Error("Yield is not supported");
|
|
35
|
-
}
|
|
36
|
-
return result.value;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (imported.default.constructor.name === "AsyncFunction") {
|
|
40
|
-
return (0, _neverthrow.ok)(imported.default);
|
|
41
|
-
}
|
|
42
|
-
return (0, _neverthrow.err)(new _errors.InvalidApiError(`${path} default export must be an async function`));
|
|
43
|
-
} catch (error) {
|
|
44
|
-
return (0, _neverthrow.err)(new _errors.AutomationError(error));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Result } from "neverthrow";
|
|
2
|
-
import { RunAutomationError } from "./errors";
|
|
3
|
-
import { Page, BrowserContext } from "playwright";
|
|
4
|
-
import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from "./types";
|
|
5
|
-
export * from "./types";
|
|
6
|
-
export * from "./errors";
|
|
7
|
-
export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters & {
|
|
8
|
-
retrieveSession: true;
|
|
9
|
-
}): Promise<RunApiResult<ResultType, RunApiResultWithSessionOk>>;
|
|
10
|
-
export declare function runApi<ResultType = any>(input: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
|
|
11
|
-
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var _exportNames = {
|
|
7
|
-
runApi: true,
|
|
8
|
-
checkAuthSessionWithRetries: true
|
|
9
|
-
};
|
|
10
|
-
exports.checkAuthSessionWithRetries = checkAuthSessionWithRetries;
|
|
11
|
-
exports.runApi = runApi;
|
|
12
|
-
var _downloadDirectory = require("../../runtime/downloadDirectory");
|
|
13
|
-
var _asyncLocalStorage = require("../asyncLocalStorage");
|
|
14
|
-
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
15
|
-
var fs = _fsExtra;
|
|
16
|
-
var _contextStorageStateHelpers = require("../contextStorageStateHelpers");
|
|
17
|
-
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
|
-
var _constants = require("../constants");
|
|
31
|
-
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
|
-
var _formatZodError = require("../formatZodError");
|
|
45
|
-
var _cleanEnvironmentVariables = require("../cleanEnvironmentVariables");
|
|
46
|
-
var _importUsingImportFunction = require("./importUsingImportFunction");
|
|
47
|
-
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); }
|
|
48
|
-
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; }
|
|
49
|
-
function getObjectSizeInBytes(obj) {
|
|
50
|
-
try {
|
|
51
|
-
return new TextEncoder().encode(JSON.stringify(obj)).length;
|
|
52
|
-
} catch (error) {
|
|
53
|
-
return new TextEncoder().encode(String(obj)).length;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
async function runApi({
|
|
57
|
-
abortSignal,
|
|
58
|
-
importFunction,
|
|
59
|
-
retrieveSession = false,
|
|
60
|
-
...input
|
|
61
|
-
}) {
|
|
62
|
-
let traceStarted = false;
|
|
63
|
-
const inputParseResult = _types.runApiParametersSchema.safeParse(input);
|
|
64
|
-
if (!inputParseResult.success) {
|
|
65
|
-
return (0, _neverthrow.err)(new _errors.InternalInvalidInputError("Input validation failed", (0, _formatZodError.formatZodError)(inputParseResult.error)));
|
|
66
|
-
}
|
|
67
|
-
const {
|
|
68
|
-
automationFunction: {
|
|
69
|
-
name,
|
|
70
|
-
params
|
|
71
|
-
},
|
|
72
|
-
runOptions,
|
|
73
|
-
tracing,
|
|
74
|
-
auth
|
|
75
|
-
} = inputParseResult.data;
|
|
76
|
-
const abortSymbol = Symbol("abort");
|
|
77
|
-
const abortPromise = new Promise(resolve => {
|
|
78
|
-
if (!abortSignal) return;
|
|
79
|
-
abortSignal.addEventListener("abort", () => {
|
|
80
|
-
resolve(abortSymbol);
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
async function runAutomation() {
|
|
84
|
-
const validatedModuleResult = await (0, _importUsingImportFunction.importUsingImportFunction)({
|
|
85
|
-
path: name,
|
|
86
|
-
importFunction
|
|
87
|
-
});
|
|
88
|
-
if (validatedModuleResult.isErr()) {
|
|
89
|
-
return (0, _neverthrow.err)(validatedModuleResult.error);
|
|
90
|
-
}
|
|
91
|
-
const automationFunction = validatedModuleResult.value;
|
|
92
|
-
if (auth && auth.session.type === "state") {
|
|
93
|
-
const state = auth.session.state;
|
|
94
|
-
if (state === undefined || state === null) {
|
|
95
|
-
return (0, _neverthrow.err)(new _errors.AuthRequiredError());
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
const playwrightContextParameters = {
|
|
99
|
-
apiName: name,
|
|
100
|
-
apiParameters: params,
|
|
101
|
-
importFunction
|
|
102
|
-
};
|
|
103
|
-
const runAutomationWithContext = async (context, page) => {
|
|
104
|
-
async function saveTraceIfNeeded({
|
|
105
|
-
errorMessage
|
|
106
|
-
}) {
|
|
107
|
-
if (!tracing.enabled || !traceStarted) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
try {
|
|
111
|
-
await context?.tracing.stop({
|
|
112
|
-
path: tracing.filePath
|
|
113
|
-
});
|
|
114
|
-
} catch (error) {
|
|
115
|
-
console.log(errorMessage, error?.message);
|
|
116
|
-
await (0, _fsExtra.remove)(tracing.filePath);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (auth) {
|
|
120
|
-
await (0, _playwrightContext.loadSessionToContext)({
|
|
121
|
-
context,
|
|
122
|
-
session: auth.session
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
const scriptContent = await fs.readFile(_playwrightContext.browserScriptsFile, "utf-8");
|
|
126
|
-
await context.addInitScript({
|
|
127
|
-
content: scriptContent
|
|
128
|
-
});
|
|
129
|
-
for (const page of context.pages()) {
|
|
130
|
-
await page.evaluate(scriptContent);
|
|
131
|
-
}
|
|
132
|
-
if (tracing.enabled) {
|
|
133
|
-
await context.tracing.start({
|
|
134
|
-
screenshots: true,
|
|
135
|
-
snapshots: true,
|
|
136
|
-
sources: true
|
|
137
|
-
});
|
|
138
|
-
traceStarted = true;
|
|
139
|
-
}
|
|
140
|
-
(0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
|
|
141
|
-
const automationFunctionParameters = [...(params !== undefined ? [params] : []), page, context];
|
|
142
|
-
try {
|
|
143
|
-
const automationFunctionResult = await automationFunction(...automationFunctionParameters);
|
|
144
|
-
const MAX_RESULT_SIZE_BYTES = 2 * 1024 * 1024;
|
|
145
|
-
const resultSizeInBytes = getObjectSizeInBytes(automationFunctionResult);
|
|
146
|
-
if (resultSizeInBytes > MAX_RESULT_SIZE_BYTES) {
|
|
147
|
-
return (0, _neverthrow.err)(new _errors.ResultTooBigError(resultSizeInBytes, MAX_RESULT_SIZE_BYTES));
|
|
148
|
-
}
|
|
149
|
-
return (0, _neverthrow.ok)({
|
|
150
|
-
result: automationFunctionResult,
|
|
151
|
-
extendedPayloads: (0, _asyncLocalStorage.getExecutionContext)()?.extendedPayloads,
|
|
152
|
-
session: retrieveSession ? await (0, _contextStorageStateHelpers.getStorageState)(context) : undefined
|
|
153
|
-
});
|
|
154
|
-
} catch (error) {
|
|
155
|
-
return (0, _neverthrow.err)(new _errors.AutomationError(error));
|
|
156
|
-
} finally {
|
|
157
|
-
await saveTraceIfNeeded({
|
|
158
|
-
errorMessage: "failed to save trace"
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
if (runOptions.environment === "standalone") {
|
|
163
|
-
const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
|
|
164
|
-
try {
|
|
165
|
-
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
166
|
-
headless: runOptions.headless,
|
|
167
|
-
proxy: runOptions.proxy,
|
|
168
|
-
downloadsPath,
|
|
169
|
-
...playwrightContextParameters
|
|
170
|
-
}, runAutomationWithContext);
|
|
171
|
-
} finally {
|
|
172
|
-
await fs.remove(downloadsPath);
|
|
173
|
-
}
|
|
174
|
-
} else {
|
|
175
|
-
return await (0, _playwrightContext.withPlaywrightContext)({
|
|
176
|
-
cdpAddress: runOptions.cdpAddress,
|
|
177
|
-
...playwrightContextParameters
|
|
178
|
-
}, runAutomationWithContext);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const result = await Promise.race([await runAutomation(), abortPromise]);
|
|
182
|
-
if (result === abortSymbol) {
|
|
183
|
-
return (0, _neverthrow.err)(new _errors.AbortedError());
|
|
184
|
-
}
|
|
185
|
-
return result;
|
|
186
|
-
}
|
|
187
|
-
async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3) {
|
|
188
|
-
if (retries === 0) {
|
|
189
|
-
return (0, _neverthrow.ok)(false);
|
|
190
|
-
}
|
|
191
|
-
let tryNumber = 0;
|
|
192
|
-
console.log("Checking auth session with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
193
|
-
while (retries > tryNumber) {
|
|
194
|
-
const result = await checkFn(page, context);
|
|
195
|
-
if (result) return (0, _neverthrow.ok)(true);
|
|
196
|
-
tryNumber++;
|
|
197
|
-
}
|
|
198
|
-
return (0, _neverthrow.ok)(false);
|
|
199
|
-
}
|