@intuned/runtime-dev 0.1.0-test.37 → 0.1.0-test.4
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.ts +1 -5
- package/Intuned.json +1 -1
- package/WebTemplate/api.ts +92 -90
- package/WebTemplate/controllers/async.ts +48 -52
- package/WebTemplate/controllers/authSessions/check.ts +4 -3
- package/WebTemplate/controllers/authSessions/create.ts +7 -5
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +7 -12
- package/WebTemplate/index.playwright.ts +42 -32
- package/WebTemplate/jobs.ts +2 -13
- package/WebTemplate/utils.ts +1 -48
- package/api/test2.ts +5 -7
- package/auth-sessions/check.ts +1 -3
- package/auth-sessions/create.ts +10 -10
- package/bin/intuned-ts-check +1 -1
- package/dist/commands/api/run.js +4 -6
- package/dist/commands/auth-sessions/run-check.js +2 -8
- package/dist/commands/auth-sessions/run-create.js +5 -10
- package/dist/commands/build.js +13 -16
- package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
- package/dist/commands/common/{tsNodeImport.js → getDefaultExportFromFile.js} +5 -6
- package/dist/commands/common/utils/settings.js +5 -5
- package/dist/commands/common/utils/webTemplate.d.ts +1 -0
- package/dist/commands/common/utils/{template.js → webTemplate.js} +7 -7
- package/dist/commands/interface/run.d.ts +1 -1
- package/dist/commands/interface/run.js +106 -131
- package/dist/commands/ts-check.js +7 -9
- package/dist/common/getPlaywrightConstructs.js +1 -5
- package/dist/common/runApi/errors.d.ts +3 -8
- package/dist/common/runApi/errors.js +3 -26
- package/dist/common/runApi/index.d.ts +1 -1
- package/dist/common/runApi/index.js +55 -33
- package/dist/common/runApi/types.d.ts +61 -277
- package/dist/common/runApi/types.js +2 -26
- package/dist/runtime/executionHelpers.test.js +6 -6
- package/package.json +3 -5
- package/testing +0 -0
- package/tsconfig.json +2 -1
- package/InterfaceTemplate/utils.ts +0 -257
- package/dist/commands/common/tsNodeImport.d.ts +0 -1
- package/dist/commands/common/utils/template.d.ts +0 -2
- package/dist/common/formatZodError.d.ts +0 -2
- package/dist/common/formatZodError.js +0 -18
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RunAutomationResponse } from "./types";
|
|
2
|
-
import { RunErrorOptions } from "
|
|
2
|
+
import { RunErrorOptions } from "src/runtime/export";
|
|
3
3
|
export declare const apiNotFoundErrorCode = "APINotFoundError";
|
|
4
4
|
export declare const invalidApiErrorCode = "InvalidAPIError";
|
|
5
5
|
export declare const invalidCheckErrorCode = "InvalidCheckError";
|
|
@@ -9,8 +9,7 @@ export declare const authCheckNotFoundErrorCode = "AuthCheckNotFoundError";
|
|
|
9
9
|
export declare const authCheckFailedErrorCode = "AuthCheckFailedError";
|
|
10
10
|
export declare const maxLevelsExceededErrorCode = "MaxLevelsExceededError";
|
|
11
11
|
export declare const automationError = "AutomationError";
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const runAutomationErrorCodes: readonly ["APINotFoundError", "InvalidAPIError", "InvalidCheckError", "AbortedError", "AuthRequiredError", "AuthCheckNotFoundError", "AuthCheckFailedError", "MaxLevelsExceededError", "AutomationError", "InternalInvalidInputError"];
|
|
12
|
+
export declare const runAutomationErrorCodes: readonly ["APINotFoundError", "InvalidAPIError", "InvalidCheckError", "AbortedError", "AuthRequiredError", "AuthCheckNotFoundError", "AuthCheckFailedError", "MaxLevelsExceededError", "AutomationError"];
|
|
14
13
|
export type RunAutomationErrorCode = (typeof runAutomationErrorCodes)[number];
|
|
15
14
|
export declare abstract class RunAutomationError<T = any> {
|
|
16
15
|
code: RunAutomationErrorCode;
|
|
@@ -21,7 +20,7 @@ export declare abstract class RunAutomationError<T = any> {
|
|
|
21
20
|
details?: T;
|
|
22
21
|
get apiResponse(): RunAutomationResponse;
|
|
23
22
|
get json(): {
|
|
24
|
-
code: "APINotFoundError" | "InvalidAPIError" | "InvalidCheckError" | "AbortedError" | "AuthRequiredError" | "AuthCheckNotFoundError" | "AuthCheckFailedError" | "MaxLevelsExceededError" | "AutomationError"
|
|
23
|
+
code: "APINotFoundError" | "InvalidAPIError" | "InvalidCheckError" | "AbortedError" | "AuthRequiredError" | "AuthCheckNotFoundError" | "AuthCheckFailedError" | "MaxLevelsExceededError" | "AutomationError";
|
|
25
24
|
details: T | undefined;
|
|
26
25
|
cause: any;
|
|
27
26
|
};
|
|
@@ -70,7 +69,3 @@ export declare class AutomationError extends RunAutomationError<{
|
|
|
70
69
|
error: any;
|
|
71
70
|
constructor(error: any);
|
|
72
71
|
}
|
|
73
|
-
export declare class InternalInvalidInputError extends RunAutomationError {
|
|
74
|
-
constructor(message: string, details?: any);
|
|
75
|
-
get apiResponse(): RunAutomationResponse;
|
|
76
|
-
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.runAutomationErrorCodes = exports.maxLevelsExceededErrorCode = exports.invalidCheckErrorCode = exports.invalidApiErrorCode = exports.
|
|
6
|
+
exports.runAutomationErrorCodes = exports.maxLevelsExceededErrorCode = exports.invalidCheckErrorCode = exports.invalidApiErrorCode = exports.automationError = exports.authRequiredErrorCode = exports.authCheckNotFoundErrorCode = exports.authCheckFailedErrorCode = exports.apiNotFoundErrorCode = exports.abortedErrorCode = exports.RunAutomationError = exports.MaxLevelsExceededError = exports.InvalidCheckError = exports.InvalidApiError = exports.AutomationError = exports.AuthRequiredError = exports.AuthCheckNotFoundError = exports.AuthCheckFailedError = exports.ApiNotFoundError = exports.AbortedError = void 0;
|
|
7
7
|
var _runtime = require("../../runtime");
|
|
8
8
|
var playwright = _interopRequireWildcard(require("@intuned/playwright-core"));
|
|
9
9
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -17,8 +17,7 @@ const authCheckNotFoundErrorCode = exports.authCheckNotFoundErrorCode = "AuthChe
|
|
|
17
17
|
const authCheckFailedErrorCode = exports.authCheckFailedErrorCode = "AuthCheckFailedError";
|
|
18
18
|
const maxLevelsExceededErrorCode = exports.maxLevelsExceededErrorCode = "MaxLevelsExceededError";
|
|
19
19
|
const automationError = exports.automationError = "AutomationError";
|
|
20
|
-
const
|
|
21
|
-
const runAutomationErrorCodes = exports.runAutomationErrorCodes = [apiNotFoundErrorCode, invalidApiErrorCode, invalidCheckErrorCode, abortedErrorCode, authRequiredErrorCode, authCheckNotFoundErrorCode, authCheckFailedErrorCode, maxLevelsExceededErrorCode, automationError, internalInvalidInputErrorCode];
|
|
20
|
+
const runAutomationErrorCodes = exports.runAutomationErrorCodes = [apiNotFoundErrorCode, invalidApiErrorCode, invalidCheckErrorCode, abortedErrorCode, authRequiredErrorCode, authCheckNotFoundErrorCode, authCheckFailedErrorCode, maxLevelsExceededErrorCode, automationError];
|
|
22
21
|
class RunAutomationError {
|
|
23
22
|
wrapped = false;
|
|
24
23
|
get apiResponse() {
|
|
@@ -93,7 +92,6 @@ class AuthRequiredError extends RunAutomationError {
|
|
|
93
92
|
this.code = authRequiredErrorCode;
|
|
94
93
|
this.statusCode = 401;
|
|
95
94
|
this.message = "Authentication is required";
|
|
96
|
-
this.wrapped = true;
|
|
97
95
|
}
|
|
98
96
|
}
|
|
99
97
|
exports.AuthRequiredError = AuthRequiredError;
|
|
@@ -112,7 +110,6 @@ class AuthCheckFailedError extends RunAutomationError {
|
|
|
112
110
|
this.code = authCheckFailedErrorCode;
|
|
113
111
|
this.statusCode = 401;
|
|
114
112
|
this.message = "auth session check failed";
|
|
115
|
-
this.wrapped = true;
|
|
116
113
|
}
|
|
117
114
|
get apiResponse() {
|
|
118
115
|
return {
|
|
@@ -172,24 +169,4 @@ class AutomationError extends RunAutomationError {
|
|
|
172
169
|
};
|
|
173
170
|
}
|
|
174
171
|
}
|
|
175
|
-
exports.AutomationError = AutomationError;
|
|
176
|
-
class InternalInvalidInputError extends RunAutomationError {
|
|
177
|
-
constructor(message, details) {
|
|
178
|
-
super();
|
|
179
|
-
this.code = internalInvalidInputErrorCode;
|
|
180
|
-
this.statusCode = 500;
|
|
181
|
-
this.message = message;
|
|
182
|
-
this.details = details;
|
|
183
|
-
}
|
|
184
|
-
get apiResponse() {
|
|
185
|
-
return {
|
|
186
|
-
status: 500,
|
|
187
|
-
body: {
|
|
188
|
-
error: "InternalServerError",
|
|
189
|
-
message: `Internal error: ${this.message}. Please report this issue to the Intuned team.`,
|
|
190
|
-
details: this.details
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
exports.InternalInvalidInputError = InternalInvalidInputError;
|
|
172
|
+
exports.AutomationError = AutomationError;
|
|
@@ -9,4 +9,4 @@ export declare function runApiGenerator<ResultType = any, _YieldType = any, _Nex
|
|
|
9
9
|
}): AsyncGenerator<_YieldType, RunApiResult<ResultType, RunApiResultWithSessionOk>, _NextType>;
|
|
10
10
|
export declare function runApiGenerator<ResultType = any, _YieldType = any, _NextType = any>(params: ExtendedRunApiParameters): AsyncGenerator<_YieldType, RunApiResult<ResultType>, _NextType>;
|
|
11
11
|
export declare function runApi<ResultType = any>(params: ExtendedRunApiParameters): Promise<RunApiResult<ResultType>>;
|
|
12
|
-
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext,
|
|
12
|
+
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
@@ -15,6 +15,7 @@ var _downloadDirectory = require("../../runtime/downloadDirectory");
|
|
|
15
15
|
var _asyncLocalStorage = require("../asyncLocalStorage");
|
|
16
16
|
var _fsExtra = _interopRequireWildcard(require("fs-extra"));
|
|
17
17
|
var fs = _fsExtra;
|
|
18
|
+
var _jwtTokenManager = require("../jwtTokenManager");
|
|
18
19
|
var _contextStorageStateHelpers = require("../contextStorageStateHelpers");
|
|
19
20
|
var _neverthrow = require("neverthrow");
|
|
20
21
|
var _errors = require("./errors");
|
|
@@ -43,32 +44,26 @@ Object.keys(_types).forEach(function (key) {
|
|
|
43
44
|
}
|
|
44
45
|
});
|
|
45
46
|
});
|
|
46
|
-
var _formatZodError = require("../formatZodError");
|
|
47
|
-
var _cleanEnvironmentVariables = require("../cleanEnvironmentVariables");
|
|
48
47
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
49
48
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.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; }
|
|
50
49
|
async function* runApiGenerator({
|
|
51
50
|
retrieveSession = false,
|
|
52
51
|
abortSignal,
|
|
53
|
-
importFunction,
|
|
54
52
|
...input
|
|
55
53
|
}) {
|
|
56
54
|
let traceStarted = false;
|
|
57
|
-
const inputParseResult = _types.runApiParametersSchema.safeParse(input);
|
|
58
|
-
if (!inputParseResult.success) {
|
|
59
|
-
return (0, _neverthrow.err)(new _errors.InternalInvalidInputError("Input validation failed", (0, _formatZodError.formatZodError)(inputParseResult.error)));
|
|
60
|
-
}
|
|
61
55
|
const {
|
|
62
56
|
automationFunction,
|
|
63
57
|
runOptions,
|
|
64
58
|
tracing,
|
|
65
|
-
auth
|
|
59
|
+
auth,
|
|
60
|
+
functionsToken
|
|
66
61
|
} = _types.runApiParametersSchema.parse(input);
|
|
62
|
+
_jwtTokenManager.backendFunctionsTokenManager.token = functionsToken;
|
|
63
|
+
const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
|
|
67
64
|
let page;
|
|
68
65
|
let context;
|
|
69
|
-
let downloadsPath;
|
|
70
66
|
if (runOptions.environment === "deployed") {
|
|
71
|
-
downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
|
|
72
67
|
const {
|
|
73
68
|
headless,
|
|
74
69
|
proxy
|
|
@@ -92,6 +87,10 @@ async function* runApiGenerator({
|
|
|
92
87
|
context
|
|
93
88
|
} = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
|
|
94
89
|
}
|
|
90
|
+
const executionContext = (0, _asyncLocalStorage.getExecutionContext)();
|
|
91
|
+
if (!executionContext) {
|
|
92
|
+
throw "";
|
|
93
|
+
}
|
|
95
94
|
async function saveTraceIfNeeded({
|
|
96
95
|
errorMessage
|
|
97
96
|
}) {
|
|
@@ -123,20 +122,18 @@ async function* runApiGenerator({
|
|
|
123
122
|
});
|
|
124
123
|
});
|
|
125
124
|
if (auth && auth.session.type === "state") {
|
|
126
|
-
|
|
127
|
-
if (state === undefined || state === null) {
|
|
128
|
-
return (0, _neverthrow.err)(new _errors.AuthRequiredError());
|
|
129
|
-
}
|
|
130
|
-
await (0, _contextStorageStateHelpers.setContextStorageState)(context, state);
|
|
125
|
+
await (0, _contextStorageStateHelpers.setContextStorageState)(context, auth.session.state);
|
|
131
126
|
}
|
|
132
127
|
async function* runAutomation() {
|
|
133
128
|
var _getExecutionContext;
|
|
134
129
|
if (auth !== null && auth !== void 0 && auth.runCheck) {
|
|
135
130
|
if (!auth.session) {
|
|
136
|
-
return (0, _neverthrow.err)(
|
|
131
|
+
return (0, _neverthrow.err)({
|
|
132
|
+
code: "AuthRequiredError"
|
|
133
|
+
});
|
|
137
134
|
}
|
|
138
135
|
console.log("Running auth check");
|
|
139
|
-
const authCheckResult = await checkAuthSessionWithRetries(page, context,
|
|
136
|
+
const authCheckResult = await checkAuthSessionWithRetries(page, context, 2);
|
|
140
137
|
if (authCheckResult.isErr()) {
|
|
141
138
|
const error = authCheckResult.error;
|
|
142
139
|
if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
|
|
@@ -145,18 +142,20 @@ async function* runApiGenerator({
|
|
|
145
142
|
return authCheckResult;
|
|
146
143
|
}
|
|
147
144
|
if (!authCheckResult.value) {
|
|
148
|
-
return (0, _neverthrow.err)(
|
|
145
|
+
return (0, _neverthrow.err)({
|
|
146
|
+
code: "AuthCheckFailedError"
|
|
147
|
+
});
|
|
149
148
|
}
|
|
150
149
|
}
|
|
151
|
-
(
|
|
152
|
-
const args = [...(automationFunction.params
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
155
|
-
return
|
|
150
|
+
console.log("Running function", automationFunction.name);
|
|
151
|
+
const args = [...(automationFunction.params ? [automationFunction.params] : []), page, context];
|
|
152
|
+
const importResult = await importFunction(automationFunction.name);
|
|
153
|
+
if (importResult.isErr()) {
|
|
154
|
+
return importResult;
|
|
156
155
|
}
|
|
157
156
|
let result;
|
|
158
|
-
if (
|
|
159
|
-
const generator =
|
|
157
|
+
if (importResult.value.type === "async-generator") {
|
|
158
|
+
const generator = importResult.value.generator(...args);
|
|
160
159
|
let next = undefined;
|
|
161
160
|
while (true) {
|
|
162
161
|
const generatorResult = await generator.next(...(next ? [next] : []));
|
|
@@ -168,7 +167,7 @@ async function* runApiGenerator({
|
|
|
168
167
|
break;
|
|
169
168
|
}
|
|
170
169
|
} else {
|
|
171
|
-
result = await
|
|
170
|
+
result = await importResult.value.func(...args);
|
|
172
171
|
}
|
|
173
172
|
return (0, _neverthrow.ok)({
|
|
174
173
|
result,
|
|
@@ -191,15 +190,14 @@ async function* runApiGenerator({
|
|
|
191
190
|
return result.value;
|
|
192
191
|
}
|
|
193
192
|
} catch (error) {
|
|
193
|
+
console.log("run errored", error);
|
|
194
194
|
return (0, _neverthrow.err)(new _errors.AutomationError(error));
|
|
195
195
|
} finally {
|
|
196
196
|
await saveTraceIfNeeded({
|
|
197
197
|
errorMessage: "failed to save trace"
|
|
198
198
|
});
|
|
199
199
|
await context.close();
|
|
200
|
-
|
|
201
|
-
await fs.remove(downloadsPath);
|
|
202
|
-
}
|
|
200
|
+
await fs.remove(downloadsPath);
|
|
203
201
|
}
|
|
204
202
|
}
|
|
205
203
|
async function runApi(params) {
|
|
@@ -213,13 +211,13 @@ async function runApi(params) {
|
|
|
213
211
|
}
|
|
214
212
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("Expected API to be async function, got async generator"));
|
|
215
213
|
}
|
|
216
|
-
async function checkAuthSessionWithRetries(page, context,
|
|
214
|
+
async function checkAuthSessionWithRetries(page, context, retries = 3) {
|
|
217
215
|
if (retries === 0) {
|
|
218
216
|
return (0, _neverthrow.ok)(false);
|
|
219
217
|
}
|
|
220
218
|
let tryNumber = 0;
|
|
221
219
|
console.log("Checking auth session with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
222
|
-
const importResult = await
|
|
220
|
+
const importResult = await importFunction(`${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
223
221
|
if (importResult.isErr()) {
|
|
224
222
|
return (0, _neverthrow.err)(importResult.error);
|
|
225
223
|
}
|
|
@@ -234,9 +232,33 @@ async function checkAuthSessionWithRetries(page, context, importFunction, retrie
|
|
|
234
232
|
}
|
|
235
233
|
return (0, _neverthrow.ok)(false);
|
|
236
234
|
}
|
|
237
|
-
async function
|
|
235
|
+
async function importFunction(path) {
|
|
236
|
+
const functionNameParts = path.split("/");
|
|
237
|
+
const functionNameDepth = functionNameParts.length;
|
|
238
238
|
try {
|
|
239
|
-
|
|
239
|
+
let imported = undefined;
|
|
240
|
+
switch (functionNameDepth) {
|
|
241
|
+
case 1:
|
|
242
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}.ts`);
|
|
243
|
+
break;
|
|
244
|
+
case 2:
|
|
245
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}.ts`);
|
|
246
|
+
break;
|
|
247
|
+
case 3:
|
|
248
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`);
|
|
249
|
+
break;
|
|
250
|
+
case 4:
|
|
251
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`);
|
|
252
|
+
break;
|
|
253
|
+
case 5:
|
|
254
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`);
|
|
255
|
+
break;
|
|
256
|
+
case 6:
|
|
257
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}/${functionNameParts[5]}.ts`);
|
|
258
|
+
break;
|
|
259
|
+
default:
|
|
260
|
+
return (0, _neverthrow.err)(new _errors.MaxLevelsExceededError(5));
|
|
261
|
+
}
|
|
240
262
|
if (!imported || !imported.default || !imported.default.constructor) {
|
|
241
263
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
|
|
242
264
|
}
|