@intuned/runtime-dev 1.3.17-source.0 → 1.3.18-interface.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/api/sample.ts +4 -0
- package/bin/intuned +0 -0
- package/bin/intuned-interface +7 -0
- package/package.json +10 -8
- package/dist/commands/api/run.d.ts +0 -6
- package/dist/commands/api/run.js +0 -119
- package/dist/commands/auth-sessions/load.d.ts +0 -2
- package/dist/commands/auth-sessions/load.js +0 -35
- package/dist/commands/auth-sessions/run-check.d.ts +0 -2
- package/dist/commands/auth-sessions/run-check.js +0 -74
- package/dist/commands/auth-sessions/run-create.d.ts +0 -2
- package/dist/commands/auth-sessions/run-create.js +0 -78
- package/dist/commands/browser/save-state.d.ts +0 -2
- package/dist/commands/browser/save-state.js +0 -17
- package/dist/commands/browser/start-browser.d.ts +0 -2
- package/dist/commands/browser/start-browser.js +0 -14
- package/dist/commands/build.d.ts +0 -1
- package/dist/commands/build.js +0 -85
- package/dist/commands/common/browserUtils.d.ts +0 -14
- package/dist/commands/common/browserUtils.js +0 -58
- package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
- package/dist/commands/common/getFirstLineNumber.js +0 -101
- package/dist/commands/common/getFirstLineNumber.test.js +0 -228
- package/dist/commands/common/projectExclusions.d.ts +0 -2
- package/dist/commands/common/projectExclusions.js +0 -8
- package/dist/commands/common/sendMessageToClient.d.ts +0 -1
- package/dist/commands/common/sendMessageToClient.js +0 -10
- package/dist/commands/common/tsNodeImport.d.ts +0 -2
- package/dist/commands/common/tsNodeImport.js +0 -43
- package/dist/commands/common/utils/fileUtils.d.ts +0 -6
- package/dist/commands/common/utils/fileUtils.js +0 -33
- package/dist/commands/common/utils/settings.d.ts +0 -2
- package/dist/commands/common/utils/settings.js +0 -31
- package/dist/commands/common/utils/template.d.ts +0 -2
- package/dist/commands/common/utils/template.js +0 -31
- package/dist/commands/common/utils/unixSocket.d.ts +0 -23
- package/dist/commands/common/utils/unixSocket.js +0 -87
- package/dist/commands/get-headless-user-agent.d.ts +0 -1
- package/dist/commands/get-headless-user-agent.js +0 -18
- package/dist/commands/interface/run.d.ts +0 -1
- package/dist/commands/interface/run.js +0 -215
- package/dist/commands/intuned-cli/commands/attempt.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt.command.js +0 -8
- package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_api.command.js +0 -30
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +0 -8
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +0 -19
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +0 -24
- package/dist/commands/intuned-cli/commands/authsession.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession.command.js +0 -8
- package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession_record.command.js +0 -32
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +0 -16
- package/dist/commands/intuned-cli/commands/build.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/build.command.js +0 -12
- package/dist/commands/intuned-cli/commands/command.d.ts +0 -2
- package/dist/commands/intuned-cli/commands/command.js +0 -9
- package/dist/commands/intuned-cli/commands/deploy.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/deploy.command.js +0 -42
- package/dist/commands/intuned-cli/commands/index.d.ts +0 -18
- package/dist/commands/intuned-cli/commands/index.js +0 -203
- package/dist/commands/intuned-cli/commands/provision.command.d.ts +0 -13
- package/dist/commands/intuned-cli/commands/provision.command.js +0 -50
- package/dist/commands/intuned-cli/commands/run.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run.command.js +0 -8
- package/dist/commands/intuned-cli/commands/run_api.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_api.command.js +0 -46
- package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -31
- package/dist/commands/intuned-cli/commands/run_authsession.command.js +0 -17
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +0 -35
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +0 -35
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +0 -1
- package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +0 -33
- package/dist/commands/intuned-cli/commands/types.d.ts +0 -35
- package/dist/commands/intuned-cli/commands/types.js +0 -31
- package/dist/commands/intuned-cli/constants/index.d.ts +0 -17
- package/dist/commands/intuned-cli/constants/index.js +0 -25
- package/dist/commands/intuned-cli/controller/__test__/api.test.js +0 -398
- package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +0 -1060
- package/dist/commands/intuned-cli/controller/api.d.ts +0 -42
- package/dist/commands/intuned-cli/controller/api.js +0 -194
- package/dist/commands/intuned-cli/controller/authSession.d.ts +0 -209
- package/dist/commands/intuned-cli/controller/authSession.js +0 -424
- package/dist/commands/intuned-cli/controller/build.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/build.js +0 -36
- package/dist/commands/intuned-cli/controller/deploy.d.ts +0 -5
- package/dist/commands/intuned-cli/controller/deploy.js +0 -318
- package/dist/commands/intuned-cli/controller/index.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/index.js +0 -46
- package/dist/commands/intuned-cli/controller/provision.d.ts +0 -21
- package/dist/commands/intuned-cli/controller/provision.js +0 -300
- package/dist/commands/intuned-cli/controller/scaffold.d.ts +0 -1
- package/dist/commands/intuned-cli/controller/scaffold.js +0 -77
- package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +0 -115
- package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +0 -41
- package/dist/commands/intuned-cli/helpers/api.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/api.js +0 -16
- package/dist/commands/intuned-cli/helpers/auth.d.ts +0 -46
- package/dist/commands/intuned-cli/helpers/auth.js +0 -147
- package/dist/commands/intuned-cli/helpers/backend.d.ts +0 -8
- package/dist/commands/intuned-cli/helpers/backend.js +0 -35
- package/dist/commands/intuned-cli/helpers/browser.d.ts +0 -15
- package/dist/commands/intuned-cli/helpers/browser.js +0 -64
- package/dist/commands/intuned-cli/helpers/context.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/context.js +0 -33
- package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -16
- package/dist/commands/intuned-cli/helpers/errors.js +0 -44
- package/dist/commands/intuned-cli/helpers/index.d.ts +0 -12
- package/dist/commands/intuned-cli/helpers/index.js +0 -137
- package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +0 -39
- package/dist/commands/intuned-cli/helpers/intunedJson.js +0 -20
- package/dist/commands/intuned-cli/helpers/prompts.d.ts +0 -3
- package/dist/commands/intuned-cli/helpers/prompts.js +0 -71
- package/dist/commands/intuned-cli/helpers/proxy.d.ts +0 -5
- package/dist/commands/intuned-cli/helpers/proxy.js +0 -23
- package/dist/commands/intuned-cli/helpers/terminal.d.ts +0 -5
- package/dist/commands/intuned-cli/helpers/terminal.js +0 -13
- package/dist/commands/intuned-cli/helpers/timeout.d.ts +0 -1
- package/dist/commands/intuned-cli/helpers/timeout.js +0 -23
- package/dist/commands/intuned-cli/helpers/traces.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/traces.js +0 -32
- package/dist/commands/intuned-cli/helpers/validation.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/validation.js +0 -14
- package/dist/commands/intuned-cli/helpers/wrapper.d.ts +0 -2
- package/dist/commands/intuned-cli/helpers/wrapper.js +0 -76
- package/dist/commands/intuned-cli/index.d.ts +0 -1
- package/dist/commands/intuned-cli/index.js +0 -16
- package/dist/commands/intuned-cli/main.d.ts +0 -1
- package/dist/commands/intuned-cli/main.js +0 -36
- package/dist/commands/intuned-cli/types.d.ts +0 -70
- package/dist/commands/intuned-cli/types.js +0 -22
- package/dist/commands/ts-check.d.ts +0 -2
- package/dist/commands/ts-check.js +0 -56
- package/dist/common/Logger/Logger/index.d.ts +0 -12
- package/dist/common/Logger/Logger/index.js +0 -60
- package/dist/common/Logger/Logger/types.d.ts +0 -8
- package/dist/common/Logger/Logger/types.js +0 -5
- package/dist/common/Logger/index.d.ts +0 -12
- package/dist/common/Logger/index.js +0 -60
- package/dist/common/Logger/types.d.ts +0 -8
- package/dist/common/Logger/types.js +0 -5
- package/dist/common/assets/browser_scripts.js +0 -2580
- package/dist/common/asyncLocalStorage/index.d.ts +0 -16
- package/dist/common/asyncLocalStorage/index.js +0 -17
- package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +0 -1
- package/dist/common/backendFunctions/getAuthSessionParameters.js +0 -38
- package/dist/common/binStartupScript.d.ts +0 -1
- package/dist/common/binStartupScript.js +0 -37
- package/dist/common/cleanEnvironmentVariables.d.ts +0 -1
- package/dist/common/cleanEnvironmentVariables.js +0 -16
- package/dist/common/constants.d.ts +0 -10
- package/dist/common/constants.js +0 -16
- package/dist/common/contextStorageStateHelpers.d.ts +0 -21
- package/dist/common/contextStorageStateHelpers.js +0 -81
- package/dist/common/extension/extensionsHelpers.d.ts +0 -11
- package/dist/common/extension/extensionsHelpers.js +0 -147
- package/dist/common/extension/intunedExtensionServer.d.ts +0 -24
- package/dist/common/extension/intunedExtensionServer.js +0 -178
- package/dist/common/extension/types.d.ts +0 -212
- package/dist/common/extension/types.js +0 -51
- package/dist/common/formatZodError.d.ts +0 -2
- package/dist/common/formatZodError.js +0 -18
- package/dist/common/intunedJson.d.ts +0 -229
- package/dist/common/intunedJson.js +0 -133
- package/dist/common/jwtTokenManager.d.ts +0 -17
- package/dist/common/jwtTokenManager.js +0 -109
- package/dist/common/launchBrowser.d.ts +0 -33
- package/dist/common/launchBrowser.js +0 -235
- package/dist/common/playwrightContext.d.ts +0 -31
- package/dist/common/playwrightContext.js +0 -150
- package/dist/common/runApi/errors.d.ts +0 -72
- package/dist/common/runApi/errors.js +0 -169
- package/dist/common/runApi/importUsingImportFunction.d.ts +0 -9
- package/dist/common/runApi/importUsingImportFunction.js +0 -46
- package/dist/common/runApi/index.d.ts +0 -11
- package/dist/common/runApi/index.js +0 -203
- package/dist/common/runApi/types.d.ts +0 -830
- package/dist/common/runApi/types.js +0 -73
- package/dist/common/settingsSchema.d.ts +0 -533
- package/dist/common/settingsSchema.js +0 -58
- package/dist/common/setupContextHook.d.ts +0 -17
- package/dist/common/setupContextHook.js +0 -22
- package/dist/common/telemetry.d.ts +0 -3
- package/dist/common/telemetry.js +0 -32
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -124
- package/dist/runtime/RunError.d.ts +0 -5
- package/dist/runtime/RunError.js +0 -19
- package/dist/runtime/attemptStore.d.ts +0 -2
- package/dist/runtime/attemptStore.js +0 -23
- package/dist/runtime/captcha.d.ts +0 -15
- package/dist/runtime/captcha.js +0 -191
- package/dist/runtime/captcha.test.js +0 -821
- package/dist/runtime/downloadDirectory.d.ts +0 -1
- package/dist/runtime/downloadDirectory.js +0 -19
- package/dist/runtime/enums.d.js +0 -5
- package/dist/runtime/enums.d.ts +0 -11
- package/dist/runtime/enums.js +0 -18
- package/dist/runtime/executionHelpers.test.js +0 -52
- package/dist/runtime/export.d.js +0 -5
- package/dist/runtime/export.d.ts +0 -284
- package/dist/runtime/extendPayload.d.ts +0 -2
- package/dist/runtime/extendPayload.js +0 -21
- package/dist/runtime/extendTimeout.d.ts +0 -1
- package/dist/runtime/extendTimeout.js +0 -23
- package/dist/runtime/getAiGatewayConfig.d.ts +0 -10
- package/dist/runtime/getAiGatewayConfig.js +0 -16
- package/dist/runtime/getAuthSessionParameters.d.ts +0 -1
- package/dist/runtime/getAuthSessionParameters.js +0 -20
- package/dist/runtime/index.d.ts +0 -10
- package/dist/runtime/index.js +0 -111
- package/dist/runtime/persistentStore.d.ts +0 -2
- package/dist/runtime/persistentStore.js +0 -37
- package/dist/runtime/persistentStore.test.js +0 -101
- package/dist/runtime/runInfo.d.ts +0 -2
- package/dist/runtime/runInfo.js +0 -21
- /package/InterfaceTemplate/{utils.ts → __utils.ts} +0 -0
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.backendFunctionsTokenManager = void 0;
|
|
7
|
-
exports.callBackendFunctionWithToken = callBackendFunctionWithToken;
|
|
8
|
-
var _crossFetch = _interopRequireDefault(require("cross-fetch"));
|
|
9
|
-
var jwt = _interopRequireWildcard(require("jsonwebtoken"));
|
|
10
|
-
var _neverthrow = require("neverthrow");
|
|
11
|
-
var _constants = require("./constants");
|
|
12
|
-
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); }
|
|
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; }
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
class JwtTokenManager {
|
|
16
|
-
constructor(refreshTokenPath) {
|
|
17
|
-
this.refreshTokenPath = refreshTokenPath;
|
|
18
|
-
this._token = undefined;
|
|
19
|
-
}
|
|
20
|
-
get token() {
|
|
21
|
-
return this._token;
|
|
22
|
-
}
|
|
23
|
-
set token(newToken) {
|
|
24
|
-
if (this._token != newToken) {
|
|
25
|
-
this._token = newToken;
|
|
26
|
-
void this.scheduleTokenRefresh();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
get timeToRefresh() {
|
|
30
|
-
if (!this._token) return;
|
|
31
|
-
const payload = jwt.decode(this._token);
|
|
32
|
-
if (!payload || typeof payload == "string") return;
|
|
33
|
-
const expiry = payload.expiry;
|
|
34
|
-
if (!expiry || typeof expiry !== "number") return;
|
|
35
|
-
const timeWindow = 60 * 1000;
|
|
36
|
-
const timeToRefresh = expiry - Date.now() - timeWindow;
|
|
37
|
-
return Math.max(timeToRefresh, timeWindow);
|
|
38
|
-
}
|
|
39
|
-
async scheduleTokenRefresh() {
|
|
40
|
-
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
|
|
41
|
-
const timeToRefresh = this.timeToRefresh;
|
|
42
|
-
if (timeToRefresh === undefined) return;
|
|
43
|
-
if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
|
|
44
|
-
this.tokenRefreshTimeout = setTimeout(async () => {
|
|
45
|
-
const result = await this.refreshToken();
|
|
46
|
-
if (result && result.isErr()) {
|
|
47
|
-
console.error(`[Internal Error] ${result.error}`);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
await this.scheduleTokenRefresh();
|
|
51
|
-
}, timeToRefresh);
|
|
52
|
-
}
|
|
53
|
-
async refreshToken() {
|
|
54
|
-
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring") return;
|
|
55
|
-
const res = await this.fetchWithToken(`${this.backendFunctionsBaseUrl}/${this.refreshTokenPath}`, {
|
|
56
|
-
method: "GET"
|
|
57
|
-
});
|
|
58
|
-
if (res.status === 401) {
|
|
59
|
-
return (0, _neverthrow.err)("Unauthorized");
|
|
60
|
-
}
|
|
61
|
-
const jsonResult = await _neverthrow.ResultAsync.fromPromise(res.json(), () => "not json");
|
|
62
|
-
if (jsonResult.isErr()) return;
|
|
63
|
-
const newToken = jsonResult.value.token;
|
|
64
|
-
if (newToken) this._token = newToken;
|
|
65
|
-
}
|
|
66
|
-
async fetchWithToken(...[input, init]) {
|
|
67
|
-
const headers = new Headers(init?.headers);
|
|
68
|
-
if (process.env[_constants.API_KEY_ENV_VAR_KEY]) {
|
|
69
|
-
headers.set(_constants.API_KEY_HEADER_NAME, process.env[_constants.API_KEY_ENV_VAR_KEY]);
|
|
70
|
-
}
|
|
71
|
-
if (this.token !== undefined) {
|
|
72
|
-
headers.set("Authorization", `Bearer ${this.token}`);
|
|
73
|
-
}
|
|
74
|
-
const result = await (0, _crossFetch.default)(input, {
|
|
75
|
-
...init,
|
|
76
|
-
headers
|
|
77
|
-
});
|
|
78
|
-
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#save-project for more information.");
|
|
80
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
get backendFunctionsBaseUrl() {
|
|
84
|
-
try {
|
|
85
|
-
if (!process.env.FUNCTIONS_DOMAIN) {
|
|
86
|
-
throw new Error(`Cannot call backend function - FUNCTIONS_DOMAIN not set`);
|
|
87
|
-
}
|
|
88
|
-
const domain = process.env.FUNCTIONS_DOMAIN;
|
|
89
|
-
if (!process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY]) {
|
|
90
|
-
throw new Error(`Cannot call backend function - ${_constants.WORKSPACE_ID_ENV_VAR_KEY} not set`);
|
|
91
|
-
}
|
|
92
|
-
const workspaceId = process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY];
|
|
93
|
-
if (!process.env[_constants.PROJECT_ID_ENV_VAR_KEY] && !process.env.INTUNED_INTEGRATION_ID) {
|
|
94
|
-
throw new Error(`Cannot call backend function - ${_constants.PROJECT_ID_ENV_VAR_KEY} or INTUNED_INTEGRATION_ID not set`);
|
|
95
|
-
}
|
|
96
|
-
const projectId = process.env.INTUNED_INTEGRATION_ID ?? process.env[_constants.PROJECT_ID_ENV_VAR_KEY];
|
|
97
|
-
return `${domain}/api/${workspaceId}/functions/${projectId}`;
|
|
98
|
-
} catch (e) {
|
|
99
|
-
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#save-project for more information.\n` + `Original error: ${e.message}`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
const backendFunctionsTokenManager = exports.backendFunctionsTokenManager = new JwtTokenManager(`refreshBackendFunctionsToken`);
|
|
106
|
-
backendFunctionsTokenManager.token = process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;
|
|
107
|
-
function callBackendFunctionWithToken(path, init) {
|
|
108
|
-
return backendFunctionsTokenManager.fetchWithToken(`${backendFunctionsTokenManager.backendFunctionsBaseUrl}/${path}`, init);
|
|
109
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import * as playwright from "playwright";
|
|
2
|
-
import { Result } from "neverthrow";
|
|
3
|
-
export interface Proxy {
|
|
4
|
-
server: string;
|
|
5
|
-
username: string;
|
|
6
|
-
password: string;
|
|
7
|
-
}
|
|
8
|
-
export type LaunchBrowserResult = {
|
|
9
|
-
page: playwright.Page;
|
|
10
|
-
context: playwright.BrowserContext;
|
|
11
|
-
};
|
|
12
|
-
export type LaunchChromiumStandaloneOptions = {
|
|
13
|
-
proxy?: Proxy;
|
|
14
|
-
headless: boolean;
|
|
15
|
-
downloadsPath?: string;
|
|
16
|
-
cdpPort?: number;
|
|
17
|
-
appModeInitialUrl?: string;
|
|
18
|
-
executablePath?: string;
|
|
19
|
-
};
|
|
20
|
-
export type LaunchChromiumCdpOptions = {
|
|
21
|
-
cdpAddress: string;
|
|
22
|
-
};
|
|
23
|
-
export declare function launchChromium(options: LaunchChromiumStandaloneOptions): Promise<LaunchBrowserResult>;
|
|
24
|
-
export declare function launchChromium(options: LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
|
|
25
|
-
export declare function getBrowserExecutablePath(): Promise<string | undefined>;
|
|
26
|
-
export declare function launchBrowser(options: Omit<LaunchChromiumStandaloneOptions, "executablePath"> | LaunchChromiumCdpOptions): Promise<LaunchBrowserResult>;
|
|
27
|
-
export declare function getLocalCdpAddress(port: number): string;
|
|
28
|
-
export declare function getCdpWebSocketUrl(cdpAddress: string): Promise<Result<string, string>>;
|
|
29
|
-
export declare function getHeadlessUserAgent({ executablePath, args, ignoreDefaultArgs, }: {
|
|
30
|
-
executablePath?: string;
|
|
31
|
-
args?: string[];
|
|
32
|
-
ignoreDefaultArgs?: string[];
|
|
33
|
-
}): Promise<string | undefined>;
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getBrowserExecutablePath = getBrowserExecutablePath;
|
|
7
|
-
exports.getCdpWebSocketUrl = getCdpWebSocketUrl;
|
|
8
|
-
exports.getHeadlessUserAgent = getHeadlessUserAgent;
|
|
9
|
-
exports.getLocalCdpAddress = getLocalCdpAddress;
|
|
10
|
-
exports.launchBrowser = launchBrowser;
|
|
11
|
-
exports.launchChromium = launchChromium;
|
|
12
|
-
var playwright = _interopRequireWildcard(require("playwright"));
|
|
13
|
-
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
14
|
-
var fs = _fsExtra;
|
|
15
|
-
var _path = require("path");
|
|
16
|
-
var _waitOn = _interopRequireDefault(require("wait-on"));
|
|
17
|
-
var _child_process = require("child_process");
|
|
18
|
-
var _extensionsHelpers = require("./extension/extensionsHelpers");
|
|
19
|
-
var _intunedExtensionServer = require("./extension/intunedExtensionServer");
|
|
20
|
-
var _util = require("util");
|
|
21
|
-
var _neverthrow = require("neverthrow");
|
|
22
|
-
var _zod = require("zod");
|
|
23
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
24
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
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
|
-
const execAsync = (0, _util.promisify)(_child_process.exec);
|
|
27
|
-
async function createUserDirWithPreferences() {
|
|
28
|
-
const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
|
|
29
|
-
const userDir = (0, _path.join)(playwrightTempDir, "userdir");
|
|
30
|
-
const defaultDir = (0, _path.join)(userDir, "Default");
|
|
31
|
-
await (0, _fsExtra.mkdir)(defaultDir, {
|
|
32
|
-
recursive: true
|
|
33
|
-
});
|
|
34
|
-
const preferences = {
|
|
35
|
-
plugins: {
|
|
36
|
-
always_open_pdf_externally: true
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
|
|
40
|
-
return userDir;
|
|
41
|
-
}
|
|
42
|
-
async function launchChromium(options) {
|
|
43
|
-
if ("cdpAddress" in options) {
|
|
44
|
-
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
45
|
-
await (0, _intunedExtensionServer.setupIntunedExtensionServer)();
|
|
46
|
-
}
|
|
47
|
-
const browser = await playwright.chromium.connectOverCDP(options.cdpAddress);
|
|
48
|
-
if (browser.contexts().length === 0) {
|
|
49
|
-
throw new Error("No browser contexts found in the connected browser");
|
|
50
|
-
}
|
|
51
|
-
const context = browser.contexts()[0];
|
|
52
|
-
let page = context.pages().at(0);
|
|
53
|
-
if (!page) {
|
|
54
|
-
page = await context.newPage();
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
page,
|
|
58
|
-
context
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const {
|
|
62
|
-
headless,
|
|
63
|
-
appModeInitialUrl,
|
|
64
|
-
cdpPort,
|
|
65
|
-
proxy,
|
|
66
|
-
downloadsPath
|
|
67
|
-
} = options;
|
|
68
|
-
let {
|
|
69
|
-
executablePath
|
|
70
|
-
} = options;
|
|
71
|
-
const defaultArgsToIgnore = ["--disable-extensions", "--disable-component-extensions-with-background-pages", "--disable-background-networking", "--disable-backgrounding-occluded-windows", "--disable-background-timer-throttling"];
|
|
72
|
-
const extraArgs = [];
|
|
73
|
-
const userDataDir = await createUserDirWithPreferences();
|
|
74
|
-
if ((0, _extensionsHelpers.isIntunedExtensionLoaded)()) {
|
|
75
|
-
const extensionsList = (0, _extensionsHelpers.buildExtensionsList)();
|
|
76
|
-
const extensions = extensionsList.join(",");
|
|
77
|
-
extraArgs.push(`--disable-extensions-except=${extensions}`);
|
|
78
|
-
extraArgs.push(`--load-extension=${extensions}`);
|
|
79
|
-
}
|
|
80
|
-
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
81
|
-
await (0, _extensionsHelpers.setupIntunedExtension)();
|
|
82
|
-
if (proxy) {
|
|
83
|
-
extraArgs.push('--proxy-bypass-list="<-loopback>"');
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (cdpPort) {
|
|
87
|
-
extraArgs.push(`--remote-debugging-port=${cdpPort}`);
|
|
88
|
-
}
|
|
89
|
-
if (headless) {
|
|
90
|
-
defaultArgsToIgnore.push("--headless=old");
|
|
91
|
-
extraArgs.push("--headless=new");
|
|
92
|
-
}
|
|
93
|
-
if (appModeInitialUrl) {
|
|
94
|
-
extraArgs.push(`--app=${appModeInitialUrl}`);
|
|
95
|
-
}
|
|
96
|
-
if (executablePath) {
|
|
97
|
-
executablePath = await fs.realpath(executablePath);
|
|
98
|
-
if (!(await fs.exists(executablePath))) {
|
|
99
|
-
console.log(`Warning: Executable path ${executablePath} does not exist. Falling back to default.`);
|
|
100
|
-
executablePath = undefined;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const viewport = null;
|
|
104
|
-
const userAgent = process.env.__PLAYWRIGHT_USER_AGENT_OVERRIDE ?? (await getHeadlessUserAgent({
|
|
105
|
-
executablePath
|
|
106
|
-
}));
|
|
107
|
-
const context = await playwright.chromium.launchPersistentContext(userDataDir, {
|
|
108
|
-
userAgent,
|
|
109
|
-
executablePath,
|
|
110
|
-
headless,
|
|
111
|
-
viewport,
|
|
112
|
-
proxy,
|
|
113
|
-
downloadsPath,
|
|
114
|
-
args: extraArgs,
|
|
115
|
-
ignoreDefaultArgs: defaultArgsToIgnore
|
|
116
|
-
});
|
|
117
|
-
context.once("close", async () => {
|
|
118
|
-
try {
|
|
119
|
-
await (0, _fsExtra.rm)(userDataDir, {
|
|
120
|
-
recursive: true,
|
|
121
|
-
force: true,
|
|
122
|
-
retryDelay: 1000,
|
|
123
|
-
maxRetries: 5
|
|
124
|
-
});
|
|
125
|
-
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
126
|
-
await (0, _intunedExtensionServer.cleanIntunedExtensionServer)();
|
|
127
|
-
}
|
|
128
|
-
} catch (error) {
|
|
129
|
-
console.error("Failed to remove user data dir", error);
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
if (cdpPort) {
|
|
133
|
-
const createdCdpAddress = getLocalCdpAddress(cdpPort);
|
|
134
|
-
await waitOnCdpAddress(createdCdpAddress);
|
|
135
|
-
}
|
|
136
|
-
const page = context.pages().at(0) ?? (await context.newPage());
|
|
137
|
-
if (await (0, _extensionsHelpers.isIntunedExtensionEnabled)()) {
|
|
138
|
-
await (0, _extensionsHelpers.getIntunedExtensionWorker)(context);
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
page,
|
|
142
|
-
context
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
async function getBrowserExecutablePath() {
|
|
146
|
-
const browserType = getBrowserType();
|
|
147
|
-
if (browserType === "brave") {
|
|
148
|
-
return await getBraveExecutablePath();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
async function launchBrowser(options) {
|
|
152
|
-
if ("cdpAddress" in options) {
|
|
153
|
-
return launchChromium(options);
|
|
154
|
-
}
|
|
155
|
-
return launchChromium({
|
|
156
|
-
...options,
|
|
157
|
-
executablePath: await getBrowserExecutablePath()
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
function getBrowserType() {
|
|
161
|
-
if (process.env.BROWSER_TYPE === "brave") {
|
|
162
|
-
return "brave";
|
|
163
|
-
}
|
|
164
|
-
return "chromium";
|
|
165
|
-
}
|
|
166
|
-
async function getBraveExecutablePath() {
|
|
167
|
-
const {
|
|
168
|
-
stdout
|
|
169
|
-
} = await execAsync("which brave-browser-stable");
|
|
170
|
-
const bravePath = stdout.trim();
|
|
171
|
-
if (bravePath.length === 0) {
|
|
172
|
-
throw new Error("Brave browser not found");
|
|
173
|
-
}
|
|
174
|
-
return bravePath;
|
|
175
|
-
}
|
|
176
|
-
function getLocalCdpAddress(port) {
|
|
177
|
-
return `http://localhost:${port}`;
|
|
178
|
-
}
|
|
179
|
-
async function getCdpWebSocketUrl(cdpAddress) {
|
|
180
|
-
let response;
|
|
181
|
-
try {
|
|
182
|
-
response = await fetch(`${cdpAddress}/json/version`);
|
|
183
|
-
} catch (error) {
|
|
184
|
-
return (0, _neverthrow.err)(`Failed to fetch CDP version from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`);
|
|
185
|
-
}
|
|
186
|
-
if (!response.ok) {
|
|
187
|
-
return (0, _neverthrow.err)(`Failed to get CDP WebSocket URL from ${cdpAddress}: ${response.status} ${response.statusText}`);
|
|
188
|
-
}
|
|
189
|
-
let data;
|
|
190
|
-
try {
|
|
191
|
-
data = await response.json();
|
|
192
|
-
} catch (error) {
|
|
193
|
-
return (0, _neverthrow.err)(`Invalid CDP version response from ${cdpAddress}: ${error instanceof Error ? error.message : String(error)}`);
|
|
194
|
-
}
|
|
195
|
-
const cdpJsonVersionResponseSchema = _zod.z.object({
|
|
196
|
-
webSocketDebuggerUrl: _zod.z.string().url()
|
|
197
|
-
});
|
|
198
|
-
const parseResult = cdpJsonVersionResponseSchema.safeParse(data);
|
|
199
|
-
if (!parseResult.success) {
|
|
200
|
-
return (0, _neverthrow.err)(`Invalid CDP version response from ${cdpAddress}: ${JSON.stringify(parseResult.error.format())}`);
|
|
201
|
-
}
|
|
202
|
-
return (0, _neverthrow.ok)(parseResult.data.webSocketDebuggerUrl);
|
|
203
|
-
}
|
|
204
|
-
async function waitOnCdpAddress(cdpAddress) {
|
|
205
|
-
const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
|
|
206
|
-
await (0, _waitOn.default)({
|
|
207
|
-
resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
|
|
208
|
-
delay: 100,
|
|
209
|
-
interval: 100,
|
|
210
|
-
timeout: 5000,
|
|
211
|
-
tcpTimeout: 1000,
|
|
212
|
-
window: 1000
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
async function getHeadlessUserAgent({
|
|
216
|
-
executablePath,
|
|
217
|
-
args,
|
|
218
|
-
ignoreDefaultArgs
|
|
219
|
-
}) {
|
|
220
|
-
const browser = await playwright.chromium.launch({
|
|
221
|
-
headless: true,
|
|
222
|
-
executablePath,
|
|
223
|
-
args,
|
|
224
|
-
ignoreDefaultArgs
|
|
225
|
-
});
|
|
226
|
-
const context = await browser.newContext();
|
|
227
|
-
const page = await context.newPage();
|
|
228
|
-
let userAgent = await page.evaluate(() => navigator.userAgent);
|
|
229
|
-
await browser.close();
|
|
230
|
-
if (!userAgent || typeof userAgent !== "string") {
|
|
231
|
-
return undefined;
|
|
232
|
-
}
|
|
233
|
-
userAgent = userAgent.replace("HeadlessChrome", "Chrome");
|
|
234
|
-
return userAgent;
|
|
235
|
-
}
|
|
@@ -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,150 +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
|
-
({
|
|
75
|
-
context,
|
|
76
|
-
page
|
|
77
|
-
} = await (0, _launchBrowser.launchBrowser)({
|
|
78
|
-
proxy,
|
|
79
|
-
headless,
|
|
80
|
-
downloadsPath,
|
|
81
|
-
cdpPort: port
|
|
82
|
-
}));
|
|
83
|
-
hookCdpUrl = (0, _launchBrowser.getLocalCdpAddress)(port);
|
|
84
|
-
}
|
|
85
|
-
let hookResult;
|
|
86
|
-
try {
|
|
87
|
-
const wsUrlResult = await (0, _launchBrowser.getCdpWebSocketUrl)(hookCdpUrl);
|
|
88
|
-
if (wsUrlResult.isOk()) {
|
|
89
|
-
hookCdpUrl = wsUrlResult.value;
|
|
90
|
-
} else {
|
|
91
|
-
throw new Error(wsUrlResult.error);
|
|
92
|
-
}
|
|
93
|
-
hookResult = await setupContextHook({
|
|
94
|
-
apiName: apiName,
|
|
95
|
-
apiParameters: apiParameters,
|
|
96
|
-
cdpUrl: hookCdpUrl
|
|
97
|
-
});
|
|
98
|
-
} catch (error) {
|
|
99
|
-
return (0, _neverthrow.err)(new _errors.AutomationError(error));
|
|
100
|
-
}
|
|
101
|
-
if (!hookResult) {
|
|
102
|
-
return await fn(context, page);
|
|
103
|
-
}
|
|
104
|
-
const {
|
|
105
|
-
page: newPage,
|
|
106
|
-
context: newContext,
|
|
107
|
-
cleanup
|
|
108
|
-
} = hookResult;
|
|
109
|
-
let result;
|
|
110
|
-
try {
|
|
111
|
-
result = {
|
|
112
|
-
return: await fn(newContext, newPage ?? page)
|
|
113
|
-
};
|
|
114
|
-
} catch (e) {
|
|
115
|
-
result = {
|
|
116
|
-
throw: e
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
await cleanup?.();
|
|
121
|
-
} catch (e) {
|
|
122
|
-
result = {
|
|
123
|
-
return: (0, _neverthrow.err)(new _errors.AutomationError(e))
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
if ("throw" in result) {
|
|
127
|
-
throw result.throw;
|
|
128
|
-
}
|
|
129
|
-
return result.return;
|
|
130
|
-
} finally {
|
|
131
|
-
await context?.close();
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async function loadSessionToContext({
|
|
135
|
-
context,
|
|
136
|
-
session
|
|
137
|
-
}) {
|
|
138
|
-
let sessionToLoad;
|
|
139
|
-
if (session.type === "state") {
|
|
140
|
-
const state = session.state;
|
|
141
|
-
if (state === undefined || state === null) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
sessionToLoad = state;
|
|
145
|
-
} else {
|
|
146
|
-
const fullPath = (0, _fileUtils.getFullPathInProject)(session.path);
|
|
147
|
-
sessionToLoad = await fs.readJson(fullPath);
|
|
148
|
-
}
|
|
149
|
-
await (0, _contextStorageStateHelpers.setStorageState)(context, sessionToLoad);
|
|
150
|
-
}
|
|
@@ -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
|
-
}
|