@intuned/runtime-dev 0.1.0-test.14 → 0.1.0-test.15

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.
Files changed (97) hide show
  1. package/bin/intuned-api-run +1 -1
  2. package/bin/intuned-auth-session-check +1 -1
  3. package/bin/intuned-auth-session-create +1 -1
  4. package/bin/intuned-auth-session-load +1 -1
  5. package/bin/intuned-auth-session-refresh +1 -1
  6. package/bin/intuned-browser-save-state +1 -1
  7. package/bin/intuned-browser-start +1 -1
  8. package/bin/intuned-build +1 -1
  9. package/bin/intuned-ts-check +1 -1
  10. package/dist/commands/api/run.js +83 -156
  11. package/dist/commands/auth-sessions/load.js +20 -20
  12. package/dist/commands/auth-sessions/run-check.js +39 -45
  13. package/dist/commands/auth-sessions/run-create.js +74 -84
  14. package/dist/commands/browser/save-state.js +7 -12
  15. package/dist/commands/browser/start-browser.js +4 -7
  16. package/dist/commands/build.js +61 -96
  17. package/dist/commands/common/browserUtils.js +30 -41
  18. package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
  19. package/dist/commands/common/getDefaultExportFromFile.js +0 -12
  20. package/dist/commands/common/getFirstLineNumber.js +83 -90
  21. package/dist/commands/common/sendMessageToClient.js +2 -4
  22. package/dist/commands/common/utils/fileUtils.js +16 -16
  23. package/dist/commands/common/utils/settings.js +18 -16
  24. package/dist/commands/common/utils/unixSocket.js +36 -43
  25. package/dist/commands/common/utils/webTemplate.js +18 -25
  26. package/dist/commands/interface/run.js +133 -139
  27. package/dist/commands/ts-check.js +40 -44
  28. package/dist/common/Logger/Logger/index.js +46 -40
  29. package/dist/common/Logger/Logger/types.js +1 -1
  30. package/dist/common/Logger/index.js +46 -40
  31. package/dist/common/Logger/types.js +1 -1
  32. package/dist/common/asyncLocalStorage/index.js +4 -4
  33. package/dist/common/cleanEnvironmentVariables.js +9 -11
  34. package/dist/common/constants.js +1 -1
  35. package/dist/common/contextStorageStateHelpers.js +38 -36
  36. package/dist/common/getPlaywrightConstructs.js +156 -186
  37. package/dist/common/jwtTokenManager.js +61 -74
  38. package/dist/common/runApi/errors.js +121 -130
  39. package/dist/common/runApi/index.js +231 -217
  40. package/dist/common/runApi/types.js +41 -55
  41. package/dist/common/settingsSchema.js +6 -9
  42. package/dist/common/telemetry.js +16 -27
  43. package/dist/index.js +3 -3
  44. package/dist/runtime/RunError.js +10 -10
  45. package/dist/runtime/downloadDirectory.js +10 -10
  46. package/dist/runtime/enums.d.ts +11 -1
  47. package/dist/runtime/enums.js +12 -12
  48. package/dist/runtime/export.d.ts +202 -1
  49. package/dist/runtime/extendPayload.js +12 -12
  50. package/dist/runtime/extendTimeout.js +20 -19
  51. package/dist/runtime/index.js +1 -1
  52. package/dist/runtime/requestMoreInfo.js +14 -14
  53. package/dist/runtime/runInfo.js +12 -11
  54. package/package.json +2 -3
  55. package/dist/commands/api/run.ts +0 -105
  56. package/dist/commands/auth-sessions/load.ts +0 -30
  57. package/dist/commands/auth-sessions/run-check.ts +0 -51
  58. package/dist/commands/auth-sessions/run-create.ts +0 -91
  59. package/dist/commands/browser/save-state.ts +0 -14
  60. package/dist/commands/browser/start-browser.ts +0 -11
  61. package/dist/commands/build.ts +0 -79
  62. package/dist/commands/common/browserUtils.ts +0 -45
  63. package/dist/commands/common/getDefaultExportFromFile.ts +0 -11
  64. package/dist/commands/common/getFirstLineNumber.ts +0 -96
  65. package/dist/commands/common/sendMessageToClient.ts +0 -3
  66. package/dist/commands/common/utils/fileUtils.ts +0 -23
  67. package/dist/commands/common/utils/settings.ts +0 -22
  68. package/dist/commands/common/utils/unixSocket.ts +0 -38
  69. package/dist/commands/common/utils/webTemplate.ts +0 -23
  70. package/dist/commands/interface/run.ts +0 -156
  71. package/dist/commands/ts-check.ts +0 -51
  72. package/dist/common/Logger/Logger/index.ts +0 -53
  73. package/dist/common/Logger/index.ts +0 -53
  74. package/dist/common/asyncLocalStorage/index.ts +0 -9
  75. package/dist/common/cleanEnvironmentVariables.ts +0 -10
  76. package/dist/common/constants.ts +0 -1
  77. package/dist/common/contextStorageStateHelpers.ts +0 -43
  78. package/dist/common/getPlaywrightConstructs.ts +0 -182
  79. package/dist/common/jwtTokenManager.ts +0 -71
  80. package/dist/common/runApi/errors.ts +0 -154
  81. package/dist/common/runApi/index.ts +0 -253
  82. package/dist/common/runApi/types.ts +0 -43
  83. package/dist/common/settingsSchema.ts +0 -9
  84. package/dist/common/telemetry.ts +0 -23
  85. package/dist/index.ts +0 -4
  86. package/dist/runtime/RunError.ts +0 -12
  87. package/dist/runtime/downloadDirectory.ts +0 -13
  88. package/dist/runtime/enums.ts +0 -12
  89. package/dist/runtime/extendPayload.ts +0 -15
  90. package/dist/runtime/extendTimeout.ts +0 -24
  91. package/dist/runtime/index.ts +0 -6
  92. package/dist/runtime/requestMoreInfo.ts +0 -18
  93. package/dist/runtime/runInfo.ts +0 -15
  94. /package/dist/commands/common/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +0 -0
  95. /package/dist/{common/Logger/Logger/types.ts → runtime/enums.d.js} +0 -0
  96. /package/dist/runtime/{executionHelpers.test.ts → executionHelpers.test.js} +0 -0
  97. /package/dist/{common/Logger/types.ts → runtime/export.d.js} +0 -0
@@ -1,53 +0,0 @@
1
- import { formatWithOptions } from "node:util";
2
- import chalk from "chalk";
3
- const format = formatWithOptions.bind(undefined, {
4
- colors: true
5
- });
6
- const LOG_LEVEL_COLORS = {
7
- TRACE: chalk.gray,
8
- DEBUG: chalk.blue,
9
- INFO: chalk.green,
10
- WARN: chalk.yellow,
11
- ERROR: chalk.red
12
- };
13
- class Logger {
14
- logFunction(entry) {
15
- const {
16
- level,
17
- timestamp,
18
- message,
19
- meta
20
- } = entry;
21
- const date = new Date(timestamp);
22
- const levelColor = LOG_LEVEL_COLORS[level];
23
- if (meta === undefined) {
24
- process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
25
- } else {
26
- process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
27
- }
28
- }
29
- log(level, message, meta) {
30
- this.logFunction({
31
- level,
32
- message,
33
- meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
34
- timestamp: Date.now()
35
- });
36
- }
37
- trace(message, meta) {
38
- this.log("TRACE", message, meta);
39
- }
40
- debug(message, meta) {
41
- this.log("DEBUG", message, meta);
42
- }
43
- info(message, meta) {
44
- this.log("INFO", message, meta);
45
- }
46
- warn(message, meta) {
47
- this.log("WARN", message, meta);
48
- }
49
- error(message, meta) {
50
- this.log("ERROR", message, meta);
51
- }
52
- }
53
- export const logger = new Logger();
@@ -1,53 +0,0 @@
1
- import { formatWithOptions } from "node:util";
2
- import chalk from "chalk";
3
- const format = formatWithOptions.bind(undefined, {
4
- colors: true
5
- });
6
- const LOG_LEVEL_COLORS = {
7
- TRACE: chalk.gray,
8
- DEBUG: chalk.blue,
9
- INFO: chalk.green,
10
- WARN: chalk.yellow,
11
- ERROR: chalk.red
12
- };
13
- class Logger {
14
- logFunction(entry) {
15
- const {
16
- level,
17
- timestamp,
18
- message,
19
- meta
20
- } = entry;
21
- const date = new Date(timestamp);
22
- const levelColor = LOG_LEVEL_COLORS[level];
23
- if (meta === undefined) {
24
- process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
25
- } else {
26
- process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
27
- }
28
- }
29
- log(level, message, meta) {
30
- this.logFunction({
31
- level,
32
- message,
33
- meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
34
- timestamp: Date.now()
35
- });
36
- }
37
- trace(message, meta) {
38
- this.log("TRACE", message, meta);
39
- }
40
- debug(message, meta) {
41
- this.log("DEBUG", message, meta);
42
- }
43
- info(message, meta) {
44
- this.log("INFO", message, meta);
45
- }
46
- warn(message, meta) {
47
- this.log("WARN", message, meta);
48
- }
49
- error(message, meta) {
50
- this.log("ERROR", message, meta);
51
- }
52
- }
53
- export const logger = new Logger();
@@ -1,9 +0,0 @@
1
- import { AsyncLocalStorage } from "async_hooks";
2
- export const asyncLocalStorage = new AsyncLocalStorage();
3
- export function runWithContext(contextData, callback, ...args) {
4
- return asyncLocalStorage.run(contextData, callback, ...args);
5
- }
6
- export function getExecutionContext() {
7
- const contextData = asyncLocalStorage.getStore();
8
- return contextData;
9
- }
@@ -1,10 +0,0 @@
1
- export function cleanEnvironmentVariables() {
2
- Object.keys(process.env).filter(i => {
3
- if (i.toLocaleLowerCase().startsWith("npm")) {
4
- return true;
5
- }
6
- if (i.toLocaleLowerCase().startsWith("fly") && i !== "FLY_ALLOC_ID") {
7
- return true;
8
- }
9
- }).forEach(i => delete process.env[i]);
10
- }
@@ -1 +0,0 @@
1
- export const AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
@@ -1,43 +0,0 @@
1
- function sessionStorageToArray(storage) {
2
- const result = [];
3
- for (const key in storage) {
4
- result.push({
5
- name: key,
6
- value: storage[key]
7
- });
8
- }
9
- return result;
10
- }
11
- export async function getContextStorageState(context) {
12
- const cookiesAndLocalStorage = await context.storageState();
13
- const pages = context.pages();
14
- const pagesSessions = [];
15
- for (const page of pages) {
16
- try {
17
- const [origin, session] = await page.evaluate(() => [location.origin, sessionStorage]);
18
- const transformed = sessionStorageToArray(session);
19
- pagesSessions.push({
20
- origin,
21
- sessionStorage: transformed
22
- });
23
- } catch (e) {}
24
- }
25
- return {
26
- ...cookiesAndLocalStorage,
27
- sessionStorage: pagesSessions
28
- };
29
- }
30
- export async function setContextStorageState(context, storage) {
31
- await context.intunedSetStorageState(storage);
32
- const sessionStorage = storage.sessionStorage;
33
- await context.addInitScript(storage => {
34
- for (const {
35
- origin,
36
- sessionStorage
37
- } of storage) {
38
- if (window.location.origin === origin) {
39
- for (const item of sessionStorage) window.sessionStorage.setItem(item.name, item.value);
40
- }
41
- }
42
- }, sessionStorage);
43
- }
@@ -1,182 +0,0 @@
1
- import * as playwright from "@intuned/playwright-core";
2
- import { existsSync, mkdir, mkdtemp, rm, writeFile, readFile } from "fs-extra";
3
- import { setContextStorageState } from "./contextStorageStateHelpers.js";
4
- import { join } from "path";
5
- import path from "path";
6
- import * as fs from "fs-extra";
7
- import { getFullPathInProject } from "../commands/common/utils/fileUtils";
8
- import waitOn from "wait-on";
9
- import { getDownloadDirectoryPath } from "../runtime";
10
- import { fileURLToPath } from "url";
11
- async function createUserDirWithPreferences() {
12
- const playwrightTempDir = await mkdtemp("/tmp/pw-");
13
- const userDir = join(playwrightTempDir, "userdir");
14
- const defaultDir = join(userDir, "Default");
15
- await mkdir(defaultDir, {
16
- recursive: true
17
- });
18
- const preferences = {
19
- plugins: {
20
- always_open_pdf_externally: true
21
- }
22
- };
23
- await writeFile(join(defaultDir, "Preferences"), JSON.stringify(preferences));
24
- return userDir;
25
- }
26
- export async function getProductionPlaywrightConstructs({
27
- proxy,
28
- headless = true,
29
- storageState,
30
- downloadsPath
31
- }) {
32
- const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
33
- if (headless) {
34
- extraArgs.push("--headless=new");
35
- }
36
- const executablePath = playwright.chromium.executablePath();
37
- const chromium127Path = executablePath.replace("chromium-1117", "chromium-1124");
38
- const isChrome127There = existsSync(chromium127Path);
39
- const userAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${isChrome127There ? 127 : 125}.0.0.0 Safari/537.36`;
40
- const userDataDir = await createUserDirWithPreferences();
41
- const context = await playwright.chromium.launchPersistentContext(userDataDir, {
42
- headless,
43
- ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
44
- proxy,
45
- executablePath: isChrome127There ? chromium127Path : executablePath,
46
- args: extraArgs,
47
- downloadsPath,
48
- userAgent
49
- });
50
- context.once("close", async () => {
51
- try {
52
- await rm(userDataDir, {
53
- recursive: true,
54
- force: true,
55
- retryDelay: 1000,
56
- maxRetries: 5
57
- });
58
- } catch (error) {
59
- console.error("Failed to remove user data dir", error);
60
- }
61
- });
62
- if (storageState) {
63
- await loadSessionToContext({
64
- context,
65
- session: storageState
66
- });
67
- }
68
- const assetsFile = path.join(path.dirname(fileURLToPath(import.meta.url)), "./assets/browser_scripts.js");
69
- await context.addInitScript({
70
- path: assetsFile
71
- });
72
- let page = context.pages().at(0);
73
- if (page) {
74
- const scriptString = await readFile(assetsFile, "utf8");
75
- await page.evaluate(scriptString);
76
- } else {
77
- page = await context.newPage();
78
- }
79
- return {
80
- page,
81
- context
82
- };
83
- }
84
- const getChromiumLaunchArgsToIgnore = () => ["--disable-field-trial-config", "--disable-background-networking", "--enable-features=NetworkService,NetworkServiceInProcess", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-back-forward-cache", "--disable-breakpad", "--disable-client-side-phishing-detection", "--disable-component-extensions-with-background-pages", "--disable-component-update", "--no-default-browser-check", "--disable-default-apps", "--disable-dev-shm-usage", "--disable-extensions", "--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,TranslateUI", "--allow-pre-commit-input", "--disable-hang-monitor", "--disable-ipc-flooding-protection", "--disable-prompt-on-repost", "--disable-renderer-backgrounding", "--force-color-profile=srgb", "--metrics-recording-only", "--no-first-run", "--enable-automation", "--password-store=basic", "--use-mock-keychain", "--no-service-autorun", "--export-tagged-pdf", "--enable-use-zoom-for-dsf=false"];
85
- export async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
86
- if (mode == "playwright-standalone") {
87
- if (!cdpAddress) {
88
- throw new Error("cdpAddress is required");
89
- }
90
- const {
91
- context
92
- } = await getRemotePlaywrightContext(cdpAddress);
93
- if (!context) {
94
- throw new Error("no context found");
95
- }
96
- const assetsFile = path.join(path.dirname(fileURLToPath(import.meta.url)), "./assets/browser_scripts.js");
97
- await context.addInitScript({
98
- path: assetsFile
99
- });
100
- const pages = await context.pages();
101
- let page = null;
102
- if (pages.length > 0) {
103
- page = pages[0];
104
- const scriptString = await fs.readFile(assetsFile, "utf8");
105
- await page.evaluate(scriptString);
106
- } else {
107
- page = await context.newPage();
108
- }
109
- if (authSession) {
110
- await loadSessionToContext({
111
- context,
112
- session: authSession
113
- });
114
- }
115
- return {
116
- page,
117
- context
118
- };
119
- }
120
- const downloadsPath = getDownloadDirectoryPath();
121
- if (mode === "playwright" || mode === "playwright-headless") {
122
- const productionConstructs = await getProductionPlaywrightConstructs({
123
- headless: mode === "playwright-headless",
124
- downloadsPath
125
- });
126
- if (authSession) {
127
- await loadSessionToContext({
128
- context: productionConstructs.context,
129
- session: authSession
130
- });
131
- }
132
- return {
133
- ...productionConstructs
134
- };
135
- }
136
- throw "invalid mode";
137
- }
138
- export async function loadSessionToContext({
139
- context,
140
- session
141
- }) {
142
- let sessionToLoad;
143
- if (session.type === "state") {
144
- sessionToLoad = session.state;
145
- } else {
146
- const fullPath = getFullPathInProject(session.path);
147
- sessionToLoad = await fs.readJson(fullPath);
148
- }
149
- await setContextStorageState(context, sessionToLoad);
150
- }
151
- export async function getRemotePlaywrightContext(cdpAddress) {
152
- const playwright = await import("@intuned/playwright-core");
153
- let browser = null;
154
- if (!cdpAddress) {
155
- throw new Error("cdpAddress is required");
156
- }
157
- const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
158
- try {
159
- await waitOn({
160
- resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
161
- delay: 100,
162
- interval: 100,
163
- timeout: 5000,
164
- tcpTimeout: 1000,
165
- window: 1000
166
- });
167
- } catch (error) {
168
- console.error("Failed to connect to the browser");
169
- process.exit(128 + 9);
170
- }
171
- try {
172
- browser = await playwright.chromium.connectOverCDP(cdpAddress);
173
- } catch (e) {
174
- console.log(e);
175
- throw new Error("failed to connect to the browser");
176
- }
177
- const context = browser.contexts()[0];
178
- return {
179
- browser,
180
- context
181
- };
182
- }
@@ -1,71 +0,0 @@
1
- import fetch from "cross-fetch";
2
- import * as jwt from "jsonwebtoken";
3
- import { err, ResultAsync } from "neverthrow";
4
- class JwtTokenManager {
5
- constructor(refreshTokenPath) {
6
- this.refreshTokenPath = refreshTokenPath;
7
- this._token = undefined;
8
- }
9
- get token() {
10
- return this._token;
11
- }
12
- set token(newToken) {
13
- if (this._token != newToken) {
14
- this._token = newToken;
15
- void this.scheduleTokenRefresh();
16
- }
17
- }
18
- get timeToRefresh() {
19
- if (!this._token) return;
20
- const payload = jwt.decode(this._token);
21
- if (!payload || typeof payload == "string") return;
22
- const expiry = payload.expiry;
23
- if (!expiry || typeof expiry !== "number") return;
24
- const timeWindow = 60 * 1000;
25
- const timeToRefresh = expiry - Date.now() - timeWindow;
26
- return Math.max(timeToRefresh, timeWindow);
27
- }
28
- async scheduleTokenRefresh() {
29
- var _process$env$RUN_ENVI;
30
- if (((_process$env$RUN_ENVI = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI === void 0 ? void 0 : _process$env$RUN_ENVI.toLowerCase()) !== "authoring") return;
31
- const timeToRefresh = this.timeToRefresh;
32
- if (timeToRefresh === undefined) return;
33
- if (this.tokenRefreshTimeout) clearTimeout(this.tokenRefreshTimeout);
34
- this.tokenRefreshTimeout = setTimeout(async () => {
35
- const result = await this.refreshToken();
36
- if (result && result.isErr()) {
37
- console.error(`[Internal Error] ${result.error}`);
38
- return;
39
- }
40
- await this.scheduleTokenRefresh();
41
- }, timeToRefresh);
42
- }
43
- async refreshToken() {
44
- var _process$env$RUN_ENVI2;
45
- if (((_process$env$RUN_ENVI2 = process.env.RUN_ENVIRONMENT) === null || _process$env$RUN_ENVI2 === void 0 ? void 0 : _process$env$RUN_ENVI2.toLowerCase()) !== "authoring") return;
46
- const res = await this.fetchWithToken(this.refreshTokenPath, {
47
- method: "GET"
48
- });
49
- if (res.status === 401) {
50
- return err("Unauthorized");
51
- }
52
- const jsonResult = await ResultAsync.fromPromise(res.json(), () => "not json");
53
- if (jsonResult.isErr()) return;
54
- const newToken = jsonResult.value.token;
55
- if (newToken) this._token = newToken;
56
- }
57
- fetchWithToken(...[input, init]) {
58
- const headers = new Headers(init === null || init === void 0 ? void 0 : init.headers);
59
- headers.set("Authorization", `Bearer ${this.token}`);
60
- return fetch(input, {
61
- ...init,
62
- headers
63
- });
64
- }
65
- }
66
- const backendFunctionsPath = `${process.env.FUNCTIONS_DOMAIN}/api/${process.env.INTUNED_WORKSPACE_ID}/functions/${process.env.INTUNED_INTEGRATION_ID}`;
67
- export const backendFunctionsTokenManager = new JwtTokenManager(`${backendFunctionsPath}/refreshBackendFunctionsToken`);
68
- backendFunctionsTokenManager.token = process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;
69
- export function callBackendFunctionWithToken(path, init) {
70
- return backendFunctionsTokenManager.fetchWithToken(`${backendFunctionsPath}/${path}`, init);
71
- }
@@ -1,154 +0,0 @@
1
- import { RunError } from "../../runtime";
2
- import * as playwright from "@intuned/playwright-core";
3
- export const apiNotFoundErrorCode = "APINotFoundError";
4
- export const invalidApiErrorCode = "InvalidAPIError";
5
- export const invalidCheckErrorCode = "InvalidCheckError";
6
- export const abortedErrorCode = "AbortedError";
7
- export const authRequiredErrorCode = "AuthRequiredError";
8
- export const authCheckNotFoundErrorCode = "AuthCheckNotFoundError";
9
- export const authCheckFailedErrorCode = "AuthCheckFailedError";
10
- export const maxLevelsExceededErrorCode = "MaxLevelsExceededError";
11
- export const automationError = "AutomationError";
12
- export const runAutomationErrorCodes = [apiNotFoundErrorCode, invalidApiErrorCode, invalidCheckErrorCode, abortedErrorCode, authRequiredErrorCode, authCheckNotFoundErrorCode, authCheckFailedErrorCode, maxLevelsExceededErrorCode, automationError];
13
- export class RunAutomationError {
14
- wrapped = false;
15
- get apiResponse() {
16
- if (this.wrapped) {
17
- return {
18
- status: 200,
19
- body: {
20
- status: this.statusCode,
21
- error: this.code,
22
- message: this.message
23
- }
24
- };
25
- }
26
- return {
27
- status: this.statusCode,
28
- body: {
29
- error: this.code,
30
- message: this.message
31
- }
32
- };
33
- }
34
- get json() {
35
- var _this$cause;
36
- return {
37
- code: this.code,
38
- details: this.details,
39
- cause: (_this$cause = this.cause) === null || _this$cause === void 0 ? void 0 : _this$cause.json
40
- };
41
- }
42
- }
43
- export class ApiNotFoundError extends RunAutomationError {
44
- constructor(apiName) {
45
- super();
46
- this.code = apiNotFoundErrorCode;
47
- this.statusCode = 404;
48
- this.message = `API ${apiName} not found`;
49
- }
50
- }
51
- export class InvalidApiError extends RunAutomationError {
52
- constructor(message) {
53
- super();
54
- this.code = invalidApiErrorCode;
55
- this.statusCode = 400;
56
- this.message = `API is invalid: ${message}`;
57
- }
58
- }
59
- export class InvalidCheckError extends RunAutomationError {
60
- constructor(message, cause) {
61
- super();
62
- this.code = invalidCheckErrorCode;
63
- this.statusCode = 400;
64
- this.message = message;
65
- this.cause = cause;
66
- }
67
- }
68
- export class AbortedError extends RunAutomationError {
69
- constructor() {
70
- super();
71
- this.code = abortedErrorCode;
72
- this.statusCode = 200;
73
- this.message = "Operation was aborted";
74
- }
75
- }
76
- export class AuthRequiredError extends RunAutomationError {
77
- constructor() {
78
- super();
79
- this.code = authRequiredErrorCode;
80
- this.statusCode = 401;
81
- this.message = "Authentication is required";
82
- }
83
- }
84
- export class AuthCheckNotFoundError extends RunAutomationError {
85
- constructor() {
86
- super();
87
- this.code = authCheckNotFoundErrorCode;
88
- this.statusCode = 404;
89
- this.message = "Auth check not found";
90
- }
91
- }
92
- export class AuthCheckFailedError extends RunAutomationError {
93
- constructor() {
94
- super();
95
- this.code = authCheckFailedErrorCode;
96
- this.statusCode = 401;
97
- this.message = "auth session check failed";
98
- }
99
- get apiResponse() {
100
- return {
101
- status: 200,
102
- body: {
103
- status: this.statusCode,
104
- error: "AUTH_SESSION_CHECK_FAILED",
105
- message: this.message
106
- }
107
- };
108
- }
109
- }
110
- export class MaxLevelsExceededError extends RunAutomationError {
111
- constructor(levels) {
112
- super();
113
- this.code = maxLevelsExceededErrorCode;
114
- this.statusCode = 400;
115
- this.message = `Max levels exceeded. Only ${levels} levels are supported`;
116
- this.details = {
117
- levels
118
- };
119
- }
120
- }
121
- export class AutomationError extends RunAutomationError {
122
- constructor(error) {
123
- super();
124
- this.error = error;
125
- this.code = automationError;
126
- if (error instanceof playwright.errors.TimeoutError) {
127
- this.statusCode = 500;
128
- this.message = `[${error.name}] ${error.message}`;
129
- this.details = {
130
- name: error.name,
131
- message: error.message
132
- };
133
- return;
134
- }
135
- if (error instanceof RunError) {
136
- this.wrapped = true;
137
- this.statusCode = error.options.status_code ?? 500;
138
- this.message = `[${error.options.error_code ?? error.name}] ${error.message}`;
139
- this.details = {
140
- name: error.name,
141
- statusCode: error.options.status_code,
142
- errorCode: error.options.error_code,
143
- message: error.message,
144
- options: error.options
145
- };
146
- }
147
- this.statusCode = 500;
148
- this.message = `[${(error === null || error === void 0 ? void 0 : error.name) ?? error}] ${error === null || error === void 0 ? void 0 : error.message}`;
149
- this.details = {
150
- name: error === null || error === void 0 ? void 0 : error.name,
151
- message: error === null || error === void 0 ? void 0 : error.message
152
- };
153
- }
154
- }