@intuned/runtime-dev 1.0.6-playwright-1.46.0 → 1.0.6-test-ping.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/InterfaceTemplate/utils.ts +53 -31
- package/WebTemplate.zip +0 -0
- package/dist/commands/common/tsNodeImport.d.ts +2 -1
- package/dist/commands/common/tsNodeImport.js +19 -5
- package/dist/commands/common/utils/unixSocket.d.ts +1 -0
- package/dist/commands/interface/run.js +30 -3
- package/dist/common/asyncLocalStorage/index.d.ts +1 -0
- package/dist/common/runApi/index.d.ts +1 -0
- package/dist/common/runApi/index.js +9 -2
- package/dist/common/runApi/types.d.ts +9 -3
- package/package.json +2 -2
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ImportFunction } from "@intuned/runtime/dist/common/runApi";
|
|
2
|
+
import { err, ok } from "neverthrow";
|
|
3
|
+
|
|
4
|
+
export const importModule: ImportFunction = async (path: string) => {
|
|
2
5
|
const [folderName, ...functionNameParts] = path.split("/");
|
|
3
6
|
const functionNameDepth = functionNameParts.length;
|
|
4
7
|
|
|
@@ -6,34 +9,53 @@ export async function importModule(path: string) {
|
|
|
6
9
|
// currently we support only 5 levels of depth
|
|
7
10
|
// rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
|
|
8
11
|
let imported: any = undefined;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
try {
|
|
13
|
+
switch (functionNameDepth) {
|
|
14
|
+
case 1:
|
|
15
|
+
imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
|
|
16
|
+
break;
|
|
17
|
+
case 2:
|
|
18
|
+
imported = await import(
|
|
19
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
|
|
20
|
+
);
|
|
21
|
+
break;
|
|
22
|
+
case 3:
|
|
23
|
+
imported = await import(
|
|
24
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
|
|
25
|
+
);
|
|
26
|
+
break;
|
|
27
|
+
case 4:
|
|
28
|
+
imported = await import(
|
|
29
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
|
|
30
|
+
);
|
|
31
|
+
break;
|
|
32
|
+
case 5:
|
|
33
|
+
imported = await import(
|
|
34
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
|
|
35
|
+
);
|
|
36
|
+
break;
|
|
37
|
+
default:
|
|
38
|
+
return err({
|
|
39
|
+
type: "other",
|
|
40
|
+
error: new Error(
|
|
41
|
+
`intuned supports maximum 5 levels of depth in the api folder`
|
|
42
|
+
),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
return ok(imported);
|
|
46
|
+
} catch (e: any) {
|
|
47
|
+
if (
|
|
48
|
+
"message" in e &&
|
|
49
|
+
typeof e.message === "string" &&
|
|
50
|
+
e.message.includes("Unknown variable dynamic import")
|
|
51
|
+
) {
|
|
52
|
+
return err({
|
|
53
|
+
type: "not_found",
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return err({
|
|
57
|
+
type: "other",
|
|
58
|
+
error: e,
|
|
59
|
+
});
|
|
37
60
|
}
|
|
38
|
-
|
|
39
|
-
}
|
|
61
|
+
};
|
package/WebTemplate.zip
ADDED
|
Binary file
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { ExtendedRunApiParameters } from "../../common/runApi/types";
|
|
2
|
+
export declare const tsNodeImport: ExtendedRunApiParameters["importFunction"];
|
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.tsNodeImport =
|
|
6
|
+
exports.tsNodeImport = void 0;
|
|
7
|
+
var _neverthrow = require("neverthrow");
|
|
7
8
|
var _fileUtils = require("./utils/fileUtils");
|
|
8
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); }
|
|
9
10
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
-
async
|
|
11
|
+
const tsNodeImport = async apiName => {
|
|
11
12
|
require("ts-node").register({
|
|
12
13
|
transpileOnly: true,
|
|
13
14
|
compilerOptions: {
|
|
@@ -15,6 +16,19 @@ async function tsNodeImport(apiName) {
|
|
|
15
16
|
}
|
|
16
17
|
});
|
|
17
18
|
const path = (0, _fileUtils.getFullPathInProject)(...apiName.split("/"));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
try {
|
|
20
|
+
const imported = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(path);
|
|
21
|
+
return (0, _neverthrow.ok)(imported);
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if ("code" in e && e.code === "MODULE_NOT_FOUND") {
|
|
24
|
+
return (0, _neverthrow.err)({
|
|
25
|
+
type: "not_found"
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return (0, _neverthrow.err)({
|
|
29
|
+
type: "other",
|
|
30
|
+
error: e
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.tsNodeImport = tsNodeImport;
|
|
@@ -15,9 +15,10 @@ var _unixSocket = require("../common/utils/unixSocket");
|
|
|
15
15
|
var _promises = require("timers/promises");
|
|
16
16
|
var _jwtTokenManager = require("../../common/jwtTokenManager");
|
|
17
17
|
var _formatZodError = require("../../common/formatZodError");
|
|
18
|
+
var _neverthrow = require("neverthrow");
|
|
19
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
20
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
21
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
20
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
21
22
|
const startRunApiSchema = _zod.default.object({
|
|
22
23
|
type: _zod.default.literal("start"),
|
|
23
24
|
parameters: _runApi.runApiParametersSchema.extend({
|
|
@@ -47,7 +48,11 @@ const tokenUpdateSchema = _zod.default.object({
|
|
|
47
48
|
functionsToken: _zod.default.string()
|
|
48
49
|
})
|
|
49
50
|
});
|
|
50
|
-
const
|
|
51
|
+
const pingSchema = _zod.default.object({
|
|
52
|
+
type: _zod.default.literal("ping"),
|
|
53
|
+
parameters: _zod.default.object({}).optional()
|
|
54
|
+
});
|
|
55
|
+
const inputSchema = _zod.default.union([startRunApiSchema, nextRunApiSchema, abortRunApiSchema, tokenUpdateSchema, pingSchema]);
|
|
51
56
|
_dotenv.default.config({
|
|
52
57
|
path: `.env`
|
|
53
58
|
});
|
|
@@ -105,7 +110,7 @@ function runAutomationCLI(importFunction) {
|
|
|
105
110
|
generator = (0, _runApi.runApiGenerator)({
|
|
106
111
|
...message.parameters,
|
|
107
112
|
abortSignal: abortController.signal,
|
|
108
|
-
importFunction
|
|
113
|
+
importFunction: importFunction ?? _defaultImport
|
|
109
114
|
});
|
|
110
115
|
context = {
|
|
111
116
|
extendedPayloads: [],
|
|
@@ -180,6 +185,12 @@ function runAutomationCLI(importFunction) {
|
|
|
180
185
|
});
|
|
181
186
|
break;
|
|
182
187
|
}
|
|
188
|
+
if (message.type === "ping") {
|
|
189
|
+
jsonUnixSocket.sendJSON({
|
|
190
|
+
type: "pong"
|
|
191
|
+
});
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
183
194
|
await handleMessage(message);
|
|
184
195
|
receiveMessagesPromise = receiveMessages();
|
|
185
196
|
continue;
|
|
@@ -209,6 +220,22 @@ function getProxyUrlFromRunOptions(runOptions) {
|
|
|
209
220
|
url.password = proxy.password;
|
|
210
221
|
return url.toString();
|
|
211
222
|
}
|
|
223
|
+
const _defaultImport = async path => {
|
|
224
|
+
try {
|
|
225
|
+
const imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`../../../${path}.ts`);
|
|
226
|
+
return (0, _neverthrow.ok)(imported);
|
|
227
|
+
} catch (e) {
|
|
228
|
+
if ("code" in e && e.code === "MODULE_NOT_FOUND") {
|
|
229
|
+
return (0, _neverthrow.err)({
|
|
230
|
+
type: "not_found"
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
return (0, _neverthrow.err)({
|
|
234
|
+
type: "other",
|
|
235
|
+
error: e
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
};
|
|
212
239
|
if (require.main === module) {
|
|
213
240
|
runAutomationCLI();
|
|
214
241
|
}
|
|
@@ -10,3 +10,4 @@ export declare function runApiGenerator<ResultType = any, _YieldType = any, _Nex
|
|
|
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
12
|
export declare function checkAuthSessionWithRetries(page: Page, context: BrowserContext, checkFn: (..._: any) => Promise<boolean>, retries?: number): Promise<Result<boolean, RunAutomationError>>;
|
|
13
|
+
export type ImportFunction = ExtendedRunApiParameters["importFunction"];
|
|
@@ -242,7 +242,14 @@ async function checkAuthSessionWithRetries(page, context, checkFn, retries = 3)
|
|
|
242
242
|
}
|
|
243
243
|
async function importUsingImportFunction(path, importFunction) {
|
|
244
244
|
try {
|
|
245
|
-
const
|
|
245
|
+
const importedResult = await importFunction(path);
|
|
246
|
+
if (importedResult.isErr()) {
|
|
247
|
+
if (importedResult.error.type === "not_found") {
|
|
248
|
+
return (0, _neverthrow.err)(new _errors.ApiNotFoundError(path));
|
|
249
|
+
}
|
|
250
|
+
return (0, _neverthrow.err)(new _errors.AutomationError(importedResult.error.error));
|
|
251
|
+
}
|
|
252
|
+
const imported = importedResult.value;
|
|
246
253
|
if (!imported || !imported.default || !imported.default.constructor) {
|
|
247
254
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
|
|
248
255
|
}
|
|
@@ -260,6 +267,6 @@ async function importUsingImportFunction(path, importFunction) {
|
|
|
260
267
|
}
|
|
261
268
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default async function/generator export"));
|
|
262
269
|
} catch (error) {
|
|
263
|
-
return (0, _neverthrow.err)(new _errors.
|
|
270
|
+
return (0, _neverthrow.err)(new _errors.AutomationError(error));
|
|
264
271
|
}
|
|
265
272
|
}
|
|
@@ -545,12 +545,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
545
545
|
} | undefined;
|
|
546
546
|
}, {
|
|
547
547
|
environment: "standalone";
|
|
548
|
+
headless?: boolean | undefined;
|
|
548
549
|
proxy?: {
|
|
549
550
|
server: string;
|
|
550
551
|
username: string;
|
|
551
552
|
password: string;
|
|
552
553
|
} | undefined;
|
|
553
|
-
headless?: boolean | undefined;
|
|
554
554
|
}>, z.ZodObject<{
|
|
555
555
|
environment: z.ZodLiteral<"cdp">;
|
|
556
556
|
cdpAddress: z.ZodString;
|
|
@@ -673,12 +673,12 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
673
673
|
} | undefined;
|
|
674
674
|
runOptions?: {
|
|
675
675
|
environment: "standalone";
|
|
676
|
+
headless?: boolean | undefined;
|
|
676
677
|
proxy?: {
|
|
677
678
|
server: string;
|
|
678
679
|
username: string;
|
|
679
680
|
password: string;
|
|
680
681
|
} | undefined;
|
|
681
|
-
headless?: boolean | undefined;
|
|
682
682
|
} | {
|
|
683
683
|
mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless";
|
|
684
684
|
environment: "cdp";
|
|
@@ -688,9 +688,15 @@ export declare const runApiParametersSchema: z.ZodObject<{
|
|
|
688
688
|
}>;
|
|
689
689
|
export type RunApiSession = z.infer<typeof runApiSessionSchema>;
|
|
690
690
|
export type RunApiParameters = z.input<typeof runApiParametersSchema>;
|
|
691
|
+
export type ImportFunctionError = {
|
|
692
|
+
type: "not_found";
|
|
693
|
+
} | {
|
|
694
|
+
type: "other";
|
|
695
|
+
error: any;
|
|
696
|
+
};
|
|
691
697
|
export type ExtendedRunApiParameters = RunApiParameters & {
|
|
692
698
|
abortSignal?: AbortSignal;
|
|
693
|
-
importFunction
|
|
699
|
+
importFunction: (name: string) => Promise<Result<any, ImportFunctionError>>;
|
|
694
700
|
};
|
|
695
701
|
export type RunApiResultOk<R = any> = {
|
|
696
702
|
result: R;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"version": "1.0.6-
|
|
3
|
+
"version": "1.0.6-test-ping.0",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"ms": "^2.1.3",
|
|
82
82
|
"nanoid": "3",
|
|
83
83
|
"neverthrow": "^6.1.0",
|
|
84
|
-
"playwright": "1.
|
|
84
|
+
"playwright": "1.44.1",
|
|
85
85
|
"playwright-extra": "^4.3.6",
|
|
86
86
|
"prettier": "^2.8.0",
|
|
87
87
|
"promptly": "^3.2.0",
|