@intuned/runtime-dev 0.1.0-test.13 → 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 +62 -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/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +2 -1
  22. package/dist/commands/common/sendMessageToClient.js +2 -4
  23. package/dist/commands/common/utils/fileUtils.js +16 -16
  24. package/dist/commands/common/utils/settings.js +18 -16
  25. package/dist/commands/common/utils/unixSocket.js +36 -43
  26. package/dist/commands/common/utils/webTemplate.js +19 -25
  27. package/dist/commands/interface/run.js +133 -139
  28. package/dist/commands/ts-check.js +41 -44
  29. package/dist/common/Logger/Logger/index.js +46 -40
  30. package/dist/common/Logger/Logger/types.js +1 -1
  31. package/dist/common/Logger/index.js +46 -40
  32. package/dist/common/Logger/types.js +1 -1
  33. package/dist/common/asyncLocalStorage/index.js +4 -4
  34. package/dist/common/cleanEnvironmentVariables.js +9 -11
  35. package/dist/common/constants.js +1 -1
  36. package/dist/common/contextStorageStateHelpers.js +38 -36
  37. package/dist/common/getPlaywrightConstructs.js +158 -187
  38. package/dist/common/jwtTokenManager.js +61 -74
  39. package/dist/common/runApi/errors.js +121 -130
  40. package/dist/common/runApi/index.js +231 -217
  41. package/dist/common/runApi/types.js +41 -55
  42. package/dist/common/settingsSchema.js +6 -9
  43. package/dist/common/telemetry.js +16 -27
  44. package/dist/index.js +3 -3
  45. package/dist/runtime/RunError.js +10 -10
  46. package/dist/runtime/downloadDirectory.js +10 -10
  47. package/dist/runtime/enums.d.ts +11 -1
  48. package/dist/runtime/enums.js +12 -12
  49. package/dist/runtime/export.d.ts +202 -1
  50. package/dist/runtime/extendPayload.js +12 -12
  51. package/dist/runtime/extendTimeout.js +20 -19
  52. package/dist/runtime/index.js +1 -1
  53. package/dist/runtime/requestMoreInfo.js +14 -14
  54. package/dist/runtime/runInfo.js +12 -11
  55. package/package.json +2 -3
  56. package/dist/commands/api/run.ts +0 -105
  57. package/dist/commands/auth-sessions/load.ts +0 -30
  58. package/dist/commands/auth-sessions/run-check.ts +0 -51
  59. package/dist/commands/auth-sessions/run-create.ts +0 -91
  60. package/dist/commands/browser/save-state.ts +0 -14
  61. package/dist/commands/browser/start-browser.ts +0 -11
  62. package/dist/commands/build.ts +0 -78
  63. package/dist/commands/common/browserUtils.ts +0 -45
  64. package/dist/commands/common/getDefaultExportFromFile.ts +0 -11
  65. package/dist/commands/common/getFirstLineNumber.ts +0 -96
  66. package/dist/commands/common/sendMessageToClient.ts +0 -3
  67. package/dist/commands/common/utils/fileUtils.ts +0 -23
  68. package/dist/commands/common/utils/settings.ts +0 -22
  69. package/dist/commands/common/utils/unixSocket.ts +0 -38
  70. package/dist/commands/common/utils/webTemplate.ts +0 -22
  71. package/dist/commands/interface/run.ts +0 -156
  72. package/dist/commands/ts-check.ts +0 -50
  73. package/dist/common/Logger/Logger/index.ts +0 -53
  74. package/dist/common/Logger/index.ts +0 -53
  75. package/dist/common/asyncLocalStorage/index.ts +0 -9
  76. package/dist/common/cleanEnvironmentVariables.ts +0 -10
  77. package/dist/common/constants.ts +0 -1
  78. package/dist/common/contextStorageStateHelpers.ts +0 -43
  79. package/dist/common/getPlaywrightConstructs.ts +0 -181
  80. package/dist/common/jwtTokenManager.ts +0 -71
  81. package/dist/common/runApi/errors.ts +0 -154
  82. package/dist/common/runApi/index.ts +0 -253
  83. package/dist/common/runApi/types.ts +0 -43
  84. package/dist/common/settingsSchema.ts +0 -9
  85. package/dist/common/telemetry.ts +0 -23
  86. package/dist/index.ts +0 -4
  87. package/dist/runtime/RunError.ts +0 -12
  88. package/dist/runtime/downloadDirectory.ts +0 -13
  89. package/dist/runtime/enums.ts +0 -12
  90. package/dist/runtime/extendPayload.ts +0 -15
  91. package/dist/runtime/extendTimeout.ts +0 -24
  92. package/dist/runtime/index.ts +0 -6
  93. package/dist/runtime/requestMoreInfo.ts +0 -18
  94. package/dist/runtime/runInfo.ts +0 -15
  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,181 +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
- async function createUserDirWithPreferences() {
11
- const playwrightTempDir = await mkdtemp("/tmp/pw-");
12
- const userDir = join(playwrightTempDir, "userdir");
13
- const defaultDir = join(userDir, "Default");
14
- await mkdir(defaultDir, {
15
- recursive: true
16
- });
17
- const preferences = {
18
- plugins: {
19
- always_open_pdf_externally: true
20
- }
21
- };
22
- await writeFile(join(defaultDir, "Preferences"), JSON.stringify(preferences));
23
- return userDir;
24
- }
25
- export async function getProductionPlaywrightConstructs({
26
- proxy,
27
- headless = true,
28
- storageState,
29
- downloadsPath
30
- }) {
31
- const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
32
- if (headless) {
33
- extraArgs.push("--headless=new");
34
- }
35
- const executablePath = playwright.chromium.executablePath();
36
- const chromium127Path = executablePath.replace("chromium-1117", "chromium-1124");
37
- const isChrome127There = existsSync(chromium127Path);
38
- 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`;
39
- const userDataDir = await createUserDirWithPreferences();
40
- const context = await playwright.chromium.launchPersistentContext(userDataDir, {
41
- headless,
42
- ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
43
- proxy,
44
- executablePath: isChrome127There ? chromium127Path : executablePath,
45
- args: extraArgs,
46
- downloadsPath,
47
- userAgent
48
- });
49
- context.once("close", async () => {
50
- try {
51
- await rm(userDataDir, {
52
- recursive: true,
53
- force: true,
54
- retryDelay: 1000,
55
- maxRetries: 5
56
- });
57
- } catch (error) {
58
- console.error("Failed to remove user data dir", error);
59
- }
60
- });
61
- if (storageState) {
62
- await loadSessionToContext({
63
- context,
64
- session: storageState
65
- });
66
- }
67
- const assetsFile = path.join(path.dirname(import.meta.url), "./assets/browser_scripts.js");
68
- await context.addInitScript({
69
- path: assetsFile
70
- });
71
- let page = context.pages().at(0);
72
- if (page) {
73
- const scriptString = await readFile(assetsFile, "utf8");
74
- await page.evaluate(scriptString);
75
- } else {
76
- page = await context.newPage();
77
- }
78
- return {
79
- page,
80
- context
81
- };
82
- }
83
- 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"];
84
- export async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
85
- if (mode == "playwright-standalone") {
86
- if (!cdpAddress) {
87
- throw new Error("cdpAddress is required");
88
- }
89
- const {
90
- context
91
- } = await getRemotePlaywrightContext(cdpAddress);
92
- if (!context) {
93
- throw new Error("no context found");
94
- }
95
- const assetsFile = path.join(path.dirname(import.meta.url), "./assets/browser_scripts.js");
96
- await context.addInitScript({
97
- path: assetsFile
98
- });
99
- const pages = await context.pages();
100
- let page = null;
101
- if (pages.length > 0) {
102
- page = pages[0];
103
- const scriptString = await fs.readFile(assetsFile, "utf8");
104
- await page.evaluate(scriptString);
105
- } else {
106
- page = await context.newPage();
107
- }
108
- if (authSession) {
109
- await loadSessionToContext({
110
- context,
111
- session: authSession
112
- });
113
- }
114
- return {
115
- page,
116
- context
117
- };
118
- }
119
- const downloadsPath = getDownloadDirectoryPath();
120
- if (mode === "playwright" || mode === "playwright-headless") {
121
- const productionConstructs = await getProductionPlaywrightConstructs({
122
- headless: mode === "playwright-headless",
123
- downloadsPath
124
- });
125
- if (authSession) {
126
- await loadSessionToContext({
127
- context: productionConstructs.context,
128
- session: authSession
129
- });
130
- }
131
- return {
132
- ...productionConstructs
133
- };
134
- }
135
- throw "invalid mode";
136
- }
137
- export async function loadSessionToContext({
138
- context,
139
- session
140
- }) {
141
- let sessionToLoad;
142
- if (session.type === "state") {
143
- sessionToLoad = session.state;
144
- } else {
145
- const fullPath = getFullPathInProject(session.path);
146
- sessionToLoad = await fs.readJson(fullPath);
147
- }
148
- await setContextStorageState(context, sessionToLoad);
149
- }
150
- export async function getRemotePlaywrightContext(cdpAddress) {
151
- const playwright = await import("@intuned/playwright-core");
152
- let browser = null;
153
- if (!cdpAddress) {
154
- throw new Error("cdpAddress is required");
155
- }
156
- const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
157
- try {
158
- await waitOn({
159
- resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
160
- delay: 100,
161
- interval: 100,
162
- timeout: 5000,
163
- tcpTimeout: 1000,
164
- window: 1000
165
- });
166
- } catch (error) {
167
- console.error("Failed to connect to the browser");
168
- process.exit(128 + 9);
169
- }
170
- try {
171
- browser = await playwright.chromium.connectOverCDP(cdpAddress);
172
- } catch (e) {
173
- console.log(e);
174
- throw new Error("failed to connect to the browser");
175
- }
176
- const context = browser.contexts()[0];
177
- return {
178
- browser,
179
- context
180
- };
181
- }
@@ -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
- }