@intuned/runtime-dev 0.1.0-test.11 → 0.1.0-test.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +0 -1
- package/dist/commands/api/run.js +156 -83
- package/dist/commands/api/run.ts +105 -0
- package/dist/commands/auth-sessions/load.js +20 -20
- package/dist/commands/auth-sessions/load.ts +30 -0
- package/dist/commands/auth-sessions/run-check.js +45 -39
- package/dist/commands/auth-sessions/run-check.ts +51 -0
- package/dist/commands/auth-sessions/run-create.js +84 -74
- package/dist/commands/auth-sessions/run-create.ts +91 -0
- package/dist/commands/browser/save-state.js +12 -7
- package/dist/commands/browser/save-state.ts +14 -0
- package/dist/commands/browser/start-browser.js +7 -4
- package/dist/commands/browser/start-browser.ts +11 -0
- package/dist/commands/build.js +97 -61
- package/dist/commands/build.ts +78 -0
- package/dist/commands/common/browserUtils.js +42 -31
- package/dist/commands/common/browserUtils.ts +45 -0
- package/dist/commands/common/getDefaultExportFromFile.js +11 -10
- package/dist/commands/common/getDefaultExportFromFile.ts +11 -0
- package/dist/commands/common/getFirstLineNumber.js +90 -83
- package/dist/commands/common/{getFirstLineNumber.test.js → getFirstLineNumber.test.ts} +2 -2
- package/dist/commands/common/getFirstLineNumber.ts +96 -0
- package/dist/commands/common/sendMessageToClient.js +4 -2
- package/dist/commands/common/sendMessageToClient.ts +3 -0
- package/dist/commands/common/utils/fileUtils.js +16 -16
- package/dist/commands/common/utils/fileUtils.ts +23 -0
- package/dist/commands/common/utils/settings.js +17 -19
- package/dist/commands/common/utils/settings.ts +22 -0
- package/dist/commands/common/utils/unixSocket.js +43 -36
- package/dist/commands/common/utils/unixSocket.ts +38 -0
- package/dist/commands/common/utils/webTemplate.js +25 -18
- package/dist/commands/common/utils/webTemplate.ts +22 -0
- package/dist/commands/interface/run.js +139 -133
- package/dist/commands/interface/run.ts +156 -0
- package/dist/commands/ts-check.js +45 -41
- package/dist/commands/ts-check.ts +50 -0
- package/dist/common/Logger/Logger/index.d.ts +1 -1
- package/dist/common/Logger/Logger/index.js +40 -46
- package/dist/common/Logger/Logger/index.ts +53 -0
- package/dist/common/Logger/Logger/types.js +1 -1
- package/dist/common/Logger/index.d.ts +1 -1
- package/dist/common/Logger/index.js +40 -46
- package/dist/common/Logger/index.ts +53 -0
- package/dist/common/Logger/types.js +1 -1
- package/dist/common/asyncLocalStorage/index.js +4 -4
- package/dist/common/asyncLocalStorage/index.ts +9 -0
- package/dist/common/cleanEnvironmentVariables.js +11 -9
- package/dist/common/cleanEnvironmentVariables.ts +10 -0
- package/dist/common/constants.js +1 -1
- package/dist/common/constants.ts +1 -0
- package/dist/common/contextStorageStateHelpers.js +36 -38
- package/dist/common/contextStorageStateHelpers.ts +43 -0
- package/dist/common/getPlaywrightConstructs.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.js +187 -157
- package/dist/common/getPlaywrightConstructs.ts +181 -0
- package/dist/common/jwtTokenManager.js +74 -61
- package/dist/common/jwtTokenManager.ts +71 -0
- package/dist/common/runApi/errors.d.ts +1 -1
- package/dist/common/runApi/errors.js +130 -121
- package/dist/common/runApi/errors.ts +154 -0
- package/dist/common/runApi/index.d.ts +4 -4
- package/dist/common/runApi/index.js +219 -233
- package/dist/common/runApi/index.ts +253 -0
- package/dist/common/runApi/types.d.ts +1 -1
- package/dist/common/runApi/types.js +55 -41
- package/dist/common/runApi/types.ts +43 -0
- package/dist/common/settingsSchema.js +9 -6
- package/dist/common/settingsSchema.ts +9 -0
- package/dist/common/telemetry.js +27 -16
- package/dist/common/telemetry.ts +23 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +4 -4
- package/dist/index.ts +4 -0
- package/dist/runtime/RunError.d.ts +1 -1
- package/dist/runtime/RunError.js +10 -10
- package/dist/runtime/RunError.ts +12 -0
- package/dist/runtime/downloadDirectory.js +10 -10
- package/dist/runtime/downloadDirectory.ts +13 -0
- package/dist/runtime/enums.d.ts +1 -11
- package/dist/runtime/enums.js +12 -12
- package/dist/runtime/enums.ts +12 -0
- package/dist/runtime/{executionHelpers.test.js → executionHelpers.test.ts} +2 -2
- package/dist/runtime/export.d.ts +1 -202
- package/dist/runtime/extendPayload.d.ts +1 -1
- package/dist/runtime/extendPayload.js +13 -13
- package/dist/runtime/extendPayload.ts +15 -0
- package/dist/runtime/extendTimeout.js +19 -20
- package/dist/runtime/extendTimeout.ts +24 -0
- package/dist/runtime/index.d.ts +7 -7
- package/dist/runtime/index.js +6 -6
- package/dist/runtime/index.ts +6 -0
- package/dist/runtime/requestMoreInfo.js +14 -14
- package/dist/runtime/requestMoreInfo.ts +18 -0
- package/dist/runtime/runInfo.d.ts +1 -1
- package/dist/runtime/runInfo.js +12 -13
- package/dist/runtime/runInfo.ts +15 -0
- package/package.json +3 -2
- package/tsconfig.json +1 -1
- /package/dist/{runtime/enums.d.js → common/Logger/Logger/types.ts} +0 -0
- /package/dist/{runtime/export.d.js → common/Logger/types.ts} +0 -0
|
@@ -1,71 +1,84 @@
|
|
|
1
1
|
import fetch from "cross-fetch";
|
|
2
2
|
import * as jwt from "jsonwebtoken";
|
|
3
3
|
import { err, ResultAsync } from "neverthrow";
|
|
4
|
+
// Manages JWT token with renewal
|
|
4
5
|
class JwtTokenManager {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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();
|
|
6
|
+
constructor(refreshTokenPath) {
|
|
7
|
+
this.refreshTokenPath = refreshTokenPath;
|
|
8
|
+
this._token = undefined;
|
|
16
9
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
10
|
+
get token() {
|
|
11
|
+
return this._token;
|
|
12
|
+
}
|
|
13
|
+
// When the token is set, the schedule for renewal is issued automatically
|
|
14
|
+
// This is currently being set it two places:
|
|
15
|
+
// 1. Whenever the runner starts, initializes it from the environment variable (set whenever the api is run from the authoring IDE)
|
|
16
|
+
// 2. Whenever a published api is called to run (/api/run/*), it is set to the token received in the run request.
|
|
17
|
+
set token(newToken) {
|
|
18
|
+
if (this._token != newToken) {
|
|
19
|
+
this._token = newToken;
|
|
20
|
+
void this.scheduleTokenRefresh();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
get timeToRefresh() {
|
|
24
|
+
if (!this._token)
|
|
25
|
+
return;
|
|
26
|
+
const payload = jwt.decode(this._token);
|
|
27
|
+
if (!payload || typeof payload == "string")
|
|
28
|
+
return;
|
|
29
|
+
const expiry = payload.expiry;
|
|
30
|
+
if (!expiry || typeof expiry !== "number")
|
|
31
|
+
return;
|
|
32
|
+
const timeWindow = 60 * 1000; // 1 minute
|
|
33
|
+
const timeToRefresh = expiry - Date.now() - timeWindow;
|
|
34
|
+
return Math.max(timeToRefresh, timeWindow);
|
|
35
|
+
}
|
|
36
|
+
async scheduleTokenRefresh() {
|
|
37
|
+
if (process.env.RUN_ENVIRONMENT?.toLowerCase() !== "authoring")
|
|
38
|
+
return;
|
|
39
|
+
const timeToRefresh = this.timeToRefresh;
|
|
40
|
+
if (timeToRefresh === undefined)
|
|
41
|
+
return;
|
|
42
|
+
if (this.tokenRefreshTimeout)
|
|
43
|
+
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")
|
|
55
|
+
return;
|
|
56
|
+
const res = await this.fetchWithToken(this.refreshTokenPath, {
|
|
57
|
+
method: "GET",
|
|
58
|
+
});
|
|
59
|
+
if (res.status === 401) {
|
|
60
|
+
return err("Unauthorized");
|
|
61
|
+
}
|
|
62
|
+
const jsonResult = await ResultAsync.fromPromise(res.json(), () => "not json");
|
|
63
|
+
if (jsonResult.isErr())
|
|
64
|
+
return;
|
|
65
|
+
const newToken = jsonResult.value.token;
|
|
66
|
+
if (newToken)
|
|
67
|
+
this._token = newToken;
|
|
68
|
+
}
|
|
69
|
+
fetchWithToken(...[input, init]) {
|
|
70
|
+
const headers = new Headers(init?.headers);
|
|
71
|
+
headers.set("Authorization", `Bearer ${this.token}`);
|
|
72
|
+
return fetch(input, {
|
|
73
|
+
...init,
|
|
74
|
+
headers,
|
|
75
|
+
});
|
|
51
76
|
}
|
|
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
77
|
}
|
|
66
78
|
const backendFunctionsPath = `${process.env.FUNCTIONS_DOMAIN}/api/${process.env.INTUNED_WORKSPACE_ID}/functions/${process.env.INTUNED_INTEGRATION_ID}`;
|
|
67
79
|
export const backendFunctionsTokenManager = new JwtTokenManager(`${backendFunctionsPath}/refreshBackendFunctionsToken`);
|
|
68
|
-
backendFunctionsTokenManager.token =
|
|
80
|
+
backendFunctionsTokenManager.token =
|
|
81
|
+
process.env.INTUNED_AUTHORING_SESSION_BACKEND_FUNCTIONS_TOKEN;
|
|
69
82
|
export function callBackendFunctionWithToken(path, init) {
|
|
70
|
-
|
|
71
|
-
}
|
|
83
|
+
return backendFunctionsTokenManager.fetchWithToken(`${backendFunctionsPath}/${path}`, init);
|
|
84
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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,4 +1,4 @@
|
|
|
1
|
-
import { RunAutomationResponse } from "./types";
|
|
1
|
+
import { RunAutomationResponse } from "./types.js";
|
|
2
2
|
import { RunErrorOptions } from "src/runtime/export";
|
|
3
3
|
export declare const apiNotFoundErrorCode = "APINotFoundError";
|
|
4
4
|
export declare const invalidApiErrorCode = "InvalidAPIError";
|
|
@@ -9,146 +9,155 @@ export const authCheckNotFoundErrorCode = "AuthCheckNotFoundError";
|
|
|
9
9
|
export const authCheckFailedErrorCode = "AuthCheckFailedError";
|
|
10
10
|
export const maxLevelsExceededErrorCode = "MaxLevelsExceededError";
|
|
11
11
|
export const automationError = "AutomationError";
|
|
12
|
-
export const runAutomationErrorCodes = [
|
|
12
|
+
export const runAutomationErrorCodes = [
|
|
13
|
+
apiNotFoundErrorCode,
|
|
14
|
+
invalidApiErrorCode,
|
|
15
|
+
invalidCheckErrorCode,
|
|
16
|
+
abortedErrorCode,
|
|
17
|
+
authRequiredErrorCode,
|
|
18
|
+
authCheckNotFoundErrorCode,
|
|
19
|
+
authCheckFailedErrorCode,
|
|
20
|
+
maxLevelsExceededErrorCode,
|
|
21
|
+
automationError,
|
|
22
|
+
];
|
|
13
23
|
export class RunAutomationError {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
24
|
+
constructor() {
|
|
25
|
+
this.wrapped = false;
|
|
26
|
+
}
|
|
27
|
+
get apiResponse() {
|
|
28
|
+
if (this.wrapped) {
|
|
29
|
+
return {
|
|
30
|
+
status: 200,
|
|
31
|
+
body: {
|
|
32
|
+
status: this.statusCode,
|
|
33
|
+
error: this.code,
|
|
34
|
+
message: this.message,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
23
37
|
}
|
|
24
|
-
|
|
38
|
+
return {
|
|
39
|
+
status: this.statusCode,
|
|
40
|
+
body: {
|
|
41
|
+
error: this.code,
|
|
42
|
+
message: this.message,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
get json() {
|
|
47
|
+
return {
|
|
48
|
+
code: this.code,
|
|
49
|
+
details: this.details,
|
|
50
|
+
cause: this.cause?.json,
|
|
51
|
+
};
|
|
25
52
|
}
|
|
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
53
|
}
|
|
43
54
|
export class ApiNotFoundError extends RunAutomationError {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
55
|
+
constructor(apiName) {
|
|
56
|
+
super();
|
|
57
|
+
this.code = apiNotFoundErrorCode;
|
|
58
|
+
this.statusCode = 404;
|
|
59
|
+
this.message = `API ${apiName} not found`;
|
|
60
|
+
}
|
|
50
61
|
}
|
|
51
62
|
export class InvalidApiError extends RunAutomationError {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
63
|
+
constructor(message) {
|
|
64
|
+
super();
|
|
65
|
+
this.code = invalidApiErrorCode;
|
|
66
|
+
this.statusCode = 400;
|
|
67
|
+
this.message = `API is invalid: ${message}`;
|
|
68
|
+
}
|
|
58
69
|
}
|
|
59
70
|
export class InvalidCheckError extends RunAutomationError {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
constructor(message, cause) {
|
|
72
|
+
super();
|
|
73
|
+
this.code = invalidCheckErrorCode;
|
|
74
|
+
this.statusCode = 400;
|
|
75
|
+
this.message = message;
|
|
76
|
+
this.cause = cause;
|
|
77
|
+
}
|
|
67
78
|
}
|
|
68
79
|
export class AbortedError extends RunAutomationError {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
constructor() {
|
|
81
|
+
super();
|
|
82
|
+
this.code = abortedErrorCode;
|
|
83
|
+
this.statusCode = 200;
|
|
84
|
+
this.message = "Operation was aborted";
|
|
85
|
+
}
|
|
75
86
|
}
|
|
76
87
|
export class AuthRequiredError extends RunAutomationError {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
88
|
+
constructor() {
|
|
89
|
+
super();
|
|
90
|
+
this.code = authRequiredErrorCode;
|
|
91
|
+
this.statusCode = 401;
|
|
92
|
+
this.message = "Authentication is required";
|
|
93
|
+
}
|
|
83
94
|
}
|
|
84
95
|
export class AuthCheckNotFoundError extends RunAutomationError {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
constructor() {
|
|
97
|
+
super();
|
|
98
|
+
this.code = authCheckNotFoundErrorCode;
|
|
99
|
+
this.statusCode = 404;
|
|
100
|
+
this.message = "Auth check not found";
|
|
101
|
+
}
|
|
91
102
|
}
|
|
92
103
|
export class AuthCheckFailedError extends RunAutomationError {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
104
|
+
constructor() {
|
|
105
|
+
super();
|
|
106
|
+
this.code = authCheckFailedErrorCode;
|
|
107
|
+
this.statusCode = 401;
|
|
108
|
+
this.message = "auth session check failed";
|
|
109
|
+
}
|
|
110
|
+
get apiResponse() {
|
|
111
|
+
return {
|
|
112
|
+
status: 200,
|
|
113
|
+
body: {
|
|
114
|
+
status: this.statusCode,
|
|
115
|
+
error: "AUTH_SESSION_CHECK_FAILED",
|
|
116
|
+
message: this.message,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
109
120
|
}
|
|
110
121
|
export class MaxLevelsExceededError extends RunAutomationError {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
119
|
-
}
|
|
122
|
+
constructor(levels) {
|
|
123
|
+
super();
|
|
124
|
+
this.code = maxLevelsExceededErrorCode;
|
|
125
|
+
this.statusCode = 400;
|
|
126
|
+
this.message = `Max levels exceeded. Only ${levels} levels are supported`;
|
|
127
|
+
this.details = { levels };
|
|
128
|
+
}
|
|
120
129
|
}
|
|
121
130
|
export class AutomationError extends RunAutomationError {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
131
|
+
constructor(error) {
|
|
132
|
+
super();
|
|
133
|
+
this.error = error;
|
|
134
|
+
this.code = automationError;
|
|
135
|
+
if (error instanceof playwright.errors.TimeoutError) {
|
|
136
|
+
this.statusCode = 500;
|
|
137
|
+
this.message = `[${error.name}] ${error.message}`;
|
|
138
|
+
this.details = {
|
|
139
|
+
name: error.name,
|
|
140
|
+
message: error.message,
|
|
141
|
+
};
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (error instanceof RunError) {
|
|
145
|
+
this.wrapped = true;
|
|
146
|
+
this.statusCode = error.options.status_code ?? 500;
|
|
147
|
+
this.message = `[${error.options.error_code ?? error.name}] ${error.message}`;
|
|
148
|
+
this.details = {
|
|
149
|
+
name: error.name,
|
|
150
|
+
statusCode: error.options.status_code,
|
|
151
|
+
errorCode: error.options.error_code,
|
|
152
|
+
message: error.message,
|
|
153
|
+
options: error.options,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
this.statusCode = 500;
|
|
157
|
+
this.message = `[${error?.name ?? error}] ${error?.message}`;
|
|
158
|
+
this.details = {
|
|
159
|
+
name: error?.name,
|
|
160
|
+
message: error?.message,
|
|
161
|
+
};
|
|
146
162
|
}
|
|
147
|
-
|
|
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
|
-
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
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
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Result } from "neverthrow";
|
|
2
|
-
import { RunAutomationError } from "./errors";
|
|
2
|
+
import { RunAutomationError } from "./errors.js";
|
|
3
3
|
import { Page, BrowserContext } from "@intuned/playwright-core";
|
|
4
|
-
import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from "./types";
|
|
5
|
-
export * from "./types";
|
|
6
|
-
export * from "./errors";
|
|
4
|
+
import { ExtendedRunApiParameters, RunApiResult, RunApiResultWithSessionOk } from "./types.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export * from "./errors.js";
|
|
7
7
|
export declare function runApiGenerator<ResultType = any, _YieldType = any, _NextType = any>(params: ExtendedRunApiParameters & {
|
|
8
8
|
retrieveSession: true;
|
|
9
9
|
}): AsyncGenerator<_YieldType, RunApiResult<ResultType, RunApiResultWithSessionOk>, _NextType>;
|