@intuned/runtime-dev 0.1.0-test.4 → 0.1.0-test.41
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.playwright.ts +5 -0
- package/InterfaceTemplate/utils.ts +257 -0
- package/Intuned.json +1 -1
- package/WebTemplate/api.ts +90 -92
- package/WebTemplate/controllers/async.ts +52 -48
- package/WebTemplate/controllers/authSessions/check.ts +3 -4
- package/WebTemplate/controllers/authSessions/create.ts +5 -7
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +12 -7
- package/WebTemplate/index.playwright.ts +32 -42
- package/WebTemplate/jobs.ts +13 -2
- package/WebTemplate/utils.ts +48 -1
- package/api/test2.ts +7 -5
- package/auth-sessions/check.ts +3 -1
- package/auth-sessions/create.ts +10 -10
- package/bin/intuned-ts-check +1 -1
- package/dist/commands/api/run.js +6 -4
- package/dist/commands/auth-sessions/run-check.js +8 -2
- package/dist/commands/auth-sessions/run-create.js +10 -5
- package/dist/commands/build.js +16 -13
- package/dist/commands/common/tsNodeImport.d.ts +1 -0
- package/dist/commands/common/{getDefaultExportFromFile.js → tsNodeImport.js} +6 -5
- package/dist/commands/common/utils/settings.js +5 -5
- package/dist/commands/common/utils/template.d.ts +2 -0
- package/dist/commands/common/utils/{webTemplate.js → template.js} +7 -7
- package/dist/commands/interface/run.d.ts +1 -1
- package/dist/commands/interface/run.js +131 -106
- package/dist/commands/ts-check.js +9 -7
- package/dist/common/formatZodError.d.ts +2 -0
- package/dist/common/formatZodError.js +18 -0
- package/dist/common/getPlaywrightConstructs.js +5 -1
- package/dist/common/runApi/errors.d.ts +8 -3
- package/dist/common/runApi/errors.js +26 -3
- package/dist/common/runApi/index.d.ts +1 -1
- package/dist/common/runApi/index.js +33 -55
- package/dist/common/runApi/types.d.ts +277 -61
- package/dist/common/runApi/types.js +26 -2
- package/dist/runtime/executionHelpers.test.js +6 -6
- package/package.json +5 -3
- package/tsconfig.json +1 -2
- package/InterfaceTemplate/index.ts +0 -1
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
- package/dist/commands/common/utils/webTemplate.d.ts +0 -1
- package/testing +0 -0
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
getTraceFilePath,
|
|
3
|
+
importModule,
|
|
4
|
+
waitWithExtendableTimeout,
|
|
5
|
+
} from "../../utils";
|
|
2
6
|
import * as fs from "fs-extra";
|
|
3
7
|
import { getExecutionContext } from "@intuned/runtime";
|
|
4
8
|
import { backendFunctionsTokenManager } from "@intuned/runtime/dist/common/jwtTokenManager";
|
|
@@ -61,21 +65,22 @@ export async function runApi({
|
|
|
61
65
|
|
|
62
66
|
const abortController = new AbortController();
|
|
63
67
|
|
|
68
|
+
backendFunctionsTokenManager.token = functionsToken;
|
|
64
69
|
const resultWithTimeout = await waitWithExtendableTimeout({
|
|
65
70
|
promise: runApiInternal({
|
|
66
71
|
automationFunction: {
|
|
67
72
|
name: `api/${functionName}`,
|
|
68
|
-
params
|
|
73
|
+
params,
|
|
69
74
|
},
|
|
70
|
-
auth:
|
|
71
|
-
?
|
|
72
|
-
: {
|
|
75
|
+
auth: isAuthSessionEnabled
|
|
76
|
+
? {
|
|
73
77
|
session: {
|
|
74
78
|
type: "state",
|
|
75
79
|
state: session,
|
|
76
80
|
},
|
|
77
81
|
runCheck: isAuthSessionEnabled,
|
|
78
|
-
}
|
|
82
|
+
}
|
|
83
|
+
: undefined,
|
|
79
84
|
runOptions: {
|
|
80
85
|
environment: "deployed",
|
|
81
86
|
headless,
|
|
@@ -87,8 +92,8 @@ export async function runApi({
|
|
|
87
92
|
filePath: getTraceFilePath(runId, attemptNumber),
|
|
88
93
|
}
|
|
89
94
|
: { enabled: false },
|
|
90
|
-
functionsToken,
|
|
91
95
|
abortSignal: abortController.signal,
|
|
96
|
+
importFunction: importModule,
|
|
92
97
|
}),
|
|
93
98
|
initialTimeout: requestTimeout,
|
|
94
99
|
abortController,
|
|
@@ -6,52 +6,42 @@ import { getExecutionContext } from "@intuned/runtime";
|
|
|
6
6
|
import { app } from "./app";
|
|
7
7
|
import { RUN_ID_HEADER } from "./headers";
|
|
8
8
|
import { ShutdownController } from "./shutdown";
|
|
9
|
-
import { registerApiEndpoints } from "./api";
|
|
10
|
-
import { runJobsLoop } from "./jobs";
|
|
11
|
-
import { isJobRunMachine } from "./utils";
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
|
14
11
|
|
|
15
|
-
|
|
16
|
-
const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
|
12
|
+
initializeAppInsights();
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
res.on("finish", () => {
|
|
23
|
-
console.log("finished", req.headers[RUN_ID_HEADER]);
|
|
24
|
-
void ShutdownController.instance.checkForShutdown();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
next();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
registerApiEndpoints();
|
|
31
|
-
if (isJobRunMachine()) {
|
|
32
|
-
console.log("Running in job v3 mode");
|
|
33
|
-
void runJobsLoop();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const server = app.listen(port, () => {
|
|
37
|
-
// when deployed on flyio, the server will be turned on and
|
|
38
|
-
// will shutdown after the specified time in TIME_TO_SHUTDOWN env variable
|
|
39
|
-
ShutdownController.initialize(server);
|
|
14
|
+
app.use((req, res, next) => {
|
|
15
|
+
// Cleanup after the response is sent
|
|
16
|
+
res.on("finish", () => {
|
|
17
|
+
console.log("finished", req.headers[RUN_ID_HEADER]);
|
|
40
18
|
void ShutdownController.instance.checkForShutdown();
|
|
41
|
-
console.log(`Server is running on port ${port}`);
|
|
42
19
|
});
|
|
43
20
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
21
|
+
next();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export * from "./api";
|
|
25
|
+
export * from "./jobs";
|
|
26
|
+
|
|
27
|
+
const server = app.listen(port, () => {
|
|
28
|
+
// when deployed on flyio, the server will be turned on and
|
|
29
|
+
// will shutdown after the specified time in TIME_TO_SHUTDOWN env variable
|
|
30
|
+
ShutdownController.initialize(server);
|
|
31
|
+
void ShutdownController.instance.checkForShutdown();
|
|
32
|
+
console.log(`Server is running on port ${port}`);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
36
|
+
const telemetryClient = getTelemetryClient();
|
|
37
|
+
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
38
|
+
const context = getExecutionContext();
|
|
39
|
+
telemetryClient?.trackEvent({
|
|
40
|
+
name: "UNHANDLED_REJECTION",
|
|
41
|
+
properties: {
|
|
42
|
+
runId: context?.runId,
|
|
43
|
+
promise,
|
|
44
|
+
reason,
|
|
45
|
+
},
|
|
56
46
|
});
|
|
57
|
-
}
|
|
47
|
+
});
|
package/WebTemplate/jobs.ts
CHANGED
|
@@ -6,7 +6,13 @@ import {
|
|
|
6
6
|
RUN_ID_HEADER,
|
|
7
7
|
SHOULD_SHUTDOWN_HEADER,
|
|
8
8
|
} from "./headers";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getErrorResponse,
|
|
11
|
+
isHeadless,
|
|
12
|
+
isJobRunMachine,
|
|
13
|
+
ProxyConfig,
|
|
14
|
+
proxyToUrl,
|
|
15
|
+
} from "./utils";
|
|
10
16
|
import {
|
|
11
17
|
callBackendFunctionWithToken,
|
|
12
18
|
backendFunctionsTokenManager,
|
|
@@ -26,6 +32,11 @@ type JobPayload = {
|
|
|
26
32
|
traceSignedUrl?: string;
|
|
27
33
|
};
|
|
28
34
|
|
|
35
|
+
if (isJobRunMachine()) {
|
|
36
|
+
console.log("Running in job v3 mode");
|
|
37
|
+
void jobsV3();
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
async function runApiInContext(
|
|
30
41
|
jobPayload: JobPayload
|
|
31
42
|
): Promise<Awaited<ReturnType<typeof runApi>>> {
|
|
@@ -72,7 +83,7 @@ async function runApiInContext(
|
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
85
|
|
|
75
|
-
|
|
86
|
+
async function jobsV3() {
|
|
76
87
|
await reportReady();
|
|
77
88
|
const initialDelay = 1000;
|
|
78
89
|
let delay = initialDelay;
|
package/WebTemplate/utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as playwright from "@intuned/playwright-core";
|
|
2
2
|
import { Handler, Response } from "@tinyhttp/app";
|
|
3
3
|
import * as path from "path";
|
|
4
|
-
import { getExecutionContext } from "@intuned/runtime
|
|
4
|
+
import { getExecutionContext } from "@intuned/runtime";
|
|
5
5
|
import { setTimeout } from "timers/promises";
|
|
6
6
|
|
|
7
7
|
export class FunctionNotFoundError extends Error {
|
|
@@ -208,3 +208,50 @@ export async function waitWithExtendableTimeout<T>({
|
|
|
208
208
|
result: await promise,
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
+
|
|
212
|
+
export async function importModule(path: string) {
|
|
213
|
+
const [folderName, ...functionNameParts] = path.split("/");
|
|
214
|
+
const functionNameDepth = functionNameParts.length;
|
|
215
|
+
|
|
216
|
+
// string literals should be inline
|
|
217
|
+
// currently we support only 5 levels of depth
|
|
218
|
+
// rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
|
|
219
|
+
try {
|
|
220
|
+
let imported: any = undefined;
|
|
221
|
+
switch (functionNameDepth) {
|
|
222
|
+
case 1:
|
|
223
|
+
imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
|
|
224
|
+
break;
|
|
225
|
+
case 2:
|
|
226
|
+
imported = await import(
|
|
227
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
|
|
228
|
+
);
|
|
229
|
+
break;
|
|
230
|
+
case 3:
|
|
231
|
+
imported = await import(
|
|
232
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
|
|
233
|
+
);
|
|
234
|
+
break;
|
|
235
|
+
case 4:
|
|
236
|
+
imported = await import(
|
|
237
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
|
|
238
|
+
);
|
|
239
|
+
break;
|
|
240
|
+
case 5:
|
|
241
|
+
imported = await import(
|
|
242
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
|
|
243
|
+
);
|
|
244
|
+
break;
|
|
245
|
+
default:
|
|
246
|
+
throw new Error(
|
|
247
|
+
"intuned supports maximum 5 levels of depth in the api folder"
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return imported;
|
|
251
|
+
} catch (error: any) {
|
|
252
|
+
if (error.message.includes("Unknown variable dynamic import")) {
|
|
253
|
+
throw new FunctionNotFoundError("", path);
|
|
254
|
+
}
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
package/api/test2.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Page, BrowserContext } from "@intuned/playwright-core";
|
|
2
|
-
import { extendTimeout } from "../src/runtime
|
|
3
|
-
import { requestOTP } from "../src/runtime/requestMoreInfo";
|
|
2
|
+
import { extendTimeout, extendPayload } from "../src/runtime";
|
|
4
3
|
|
|
5
|
-
export default async function
|
|
4
|
+
export default async function test2(
|
|
6
5
|
{ n }: { n?: number },
|
|
7
6
|
page: Page,
|
|
8
7
|
context: BrowserContext
|
|
@@ -10,8 +9,6 @@ export default async function* test2(
|
|
|
10
9
|
await page.goto("https://wikipedia.org/");
|
|
11
10
|
await page.waitForTimeout(1000);
|
|
12
11
|
|
|
13
|
-
yield requestOTP("Please enter the OTP");
|
|
14
|
-
|
|
15
12
|
const titles: string[] = [];
|
|
16
13
|
|
|
17
14
|
for (let i = 0; i < (n ?? 2); i++) {
|
|
@@ -21,5 +18,10 @@ export default async function* test2(
|
|
|
21
18
|
extendTimeout();
|
|
22
19
|
}
|
|
23
20
|
|
|
21
|
+
extendPayload({
|
|
22
|
+
api: "test",
|
|
23
|
+
parameters: {},
|
|
24
|
+
});
|
|
25
|
+
|
|
24
26
|
return { titles };
|
|
25
27
|
}
|
package/auth-sessions/check.ts
CHANGED
|
@@ -5,5 +5,7 @@ export default async function check(
|
|
|
5
5
|
_context: BrowserContext
|
|
6
6
|
): Promise<boolean> {
|
|
7
7
|
await page.goto("https://setcookie.net");
|
|
8
|
-
|
|
8
|
+
const result = (await page.locator("ul li code").all()).length > 0;
|
|
9
|
+
console.log("Check result", result);
|
|
10
|
+
return result;
|
|
9
11
|
}
|
package/auth-sessions/create.ts
CHANGED
|
@@ -15,16 +15,16 @@ export default async function* create(
|
|
|
15
15
|
await page.locator("#value").fill("password");
|
|
16
16
|
await page.locator("input[type=submit]").click();
|
|
17
17
|
|
|
18
|
-
console.log("Received", yield requestOTP("Enter useless otp"));
|
|
19
|
-
console.log(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
);
|
|
18
|
+
// console.log("Received", yield requestOTP("Enter useless otp"));
|
|
19
|
+
// console.log(
|
|
20
|
+
// "Received",
|
|
21
|
+
// yield requestMultipleChoice("Choose the correct answer", [
|
|
22
|
+
// "A",
|
|
23
|
+
// "B",
|
|
24
|
+
// "C",
|
|
25
|
+
// "D",
|
|
26
|
+
// ])
|
|
27
|
+
// );
|
|
28
28
|
|
|
29
29
|
await page.goto("http://www.sharonminsuk.com/code/storage-test.html");
|
|
30
30
|
await page.locator("#local").fill("intuned");
|
package/bin/intuned-ts-check
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
require("../dist/commands/ts-check.js");
|
|
2
|
+
require("../dist/commands/ts-check.js");
|
package/dist/commands/api/run.js
CHANGED
|
@@ -16,6 +16,7 @@ var _Logger = require("../../common/Logger");
|
|
|
16
16
|
var _nanoid = require("nanoid");
|
|
17
17
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
18
18
|
var _runApi = require("../../common/runApi");
|
|
19
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
19
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
21
|
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); }
|
|
21
22
|
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; }
|
|
@@ -39,7 +40,7 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
39
40
|
const runApiResult = await (0, _runApi.runApi)({
|
|
40
41
|
automationFunction: {
|
|
41
42
|
name: `api/${apiName}`,
|
|
42
|
-
params: inputData
|
|
43
|
+
params: inputData
|
|
43
44
|
},
|
|
44
45
|
auth: authSessionPathToUse ? {
|
|
45
46
|
session: {
|
|
@@ -52,14 +53,15 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
52
53
|
environment: "ide",
|
|
53
54
|
cdpAddress: options.cdpAddress,
|
|
54
55
|
mode
|
|
55
|
-
}
|
|
56
|
+
},
|
|
57
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
56
58
|
});
|
|
57
59
|
if (runApiResult.isErr()) {
|
|
58
60
|
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
59
61
|
throw runApiResult.error.error;
|
|
60
62
|
}
|
|
61
|
-
console.error(
|
|
62
|
-
|
|
63
|
+
console.error(runApiResult.error);
|
|
64
|
+
throw new Error("An error occurred while running the API");
|
|
63
65
|
}
|
|
64
66
|
const {
|
|
65
67
|
result,
|
|
@@ -8,6 +8,7 @@ var _settings = require("../common/utils/settings");
|
|
|
8
8
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
9
9
|
var _constants = require("../../common/constants");
|
|
10
10
|
var _runApi = require("../../common/runApi");
|
|
11
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
11
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
13
|
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); }
|
|
13
14
|
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; }
|
|
@@ -41,10 +42,15 @@ _commander.program.description("run auth session check").option("--cdpAddress <c
|
|
|
41
42
|
path: authSessionPath
|
|
42
43
|
},
|
|
43
44
|
runCheck: false
|
|
44
|
-
}
|
|
45
|
+
},
|
|
46
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
45
47
|
});
|
|
46
48
|
if (runApiResult.isErr()) {
|
|
47
|
-
|
|
49
|
+
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
50
|
+
throw runApiResult.error.error;
|
|
51
|
+
}
|
|
52
|
+
console.error(runApiResult.error);
|
|
53
|
+
throw new Error("Error running auth session check");
|
|
48
54
|
}
|
|
49
55
|
const result = runApiResult.value.result;
|
|
50
56
|
console.log("check result", result);
|
|
@@ -12,6 +12,7 @@ var _runApi = require("../../common/runApi");
|
|
|
12
12
|
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
13
13
|
var _nanoid = require("nanoid");
|
|
14
14
|
var _enums = require("../../runtime/enums");
|
|
15
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
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
18
|
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; }
|
|
@@ -43,15 +44,16 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
43
44
|
async function runCreate() {
|
|
44
45
|
const generator = (0, _runApi.runApiGenerator)({
|
|
45
46
|
automationFunction: {
|
|
46
|
-
name:
|
|
47
|
-
params: inputData
|
|
47
|
+
name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
|
|
48
|
+
params: inputData
|
|
48
49
|
},
|
|
49
50
|
runOptions: {
|
|
50
51
|
environment: "ide",
|
|
51
52
|
mode,
|
|
52
53
|
cdpAddress
|
|
53
54
|
},
|
|
54
|
-
retrieveSession: true
|
|
55
|
+
retrieveSession: true,
|
|
56
|
+
importFunction: _tsNodeImport.tsNodeImport
|
|
55
57
|
});
|
|
56
58
|
let nextGeneratorParam = undefined;
|
|
57
59
|
while (true) {
|
|
@@ -61,8 +63,11 @@ _commander.program.description("run auth session create").option("--cdpAddress <
|
|
|
61
63
|
} = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
|
|
62
64
|
if (done) {
|
|
63
65
|
if (value.isErr()) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
if (value.error instanceof _runApi.AutomationError) {
|
|
67
|
+
throw value.error.error;
|
|
68
|
+
}
|
|
69
|
+
console.error(value.error);
|
|
70
|
+
throw new Error("Error while running create");
|
|
66
71
|
}
|
|
67
72
|
const fullState = value.value.session;
|
|
68
73
|
if (pathToSave) {
|
package/dist/commands/build.js
CHANGED
|
@@ -10,7 +10,7 @@ var _pluginDynamicImportVars = _interopRequireDefault(require("@rollup/plugin-dy
|
|
|
10
10
|
var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
|
|
11
11
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
12
12
|
var path = _interopRequireWildcard(require("path"));
|
|
13
|
-
var
|
|
13
|
+
var _template = require("./common/utils/template");
|
|
14
14
|
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
15
15
|
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); }
|
|
16
16
|
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; }
|
|
@@ -21,18 +21,20 @@ function isThirdPartyWarning(warning) {
|
|
|
21
21
|
return false;
|
|
22
22
|
}
|
|
23
23
|
_dotenv.default.config();
|
|
24
|
-
_commander.program.description("build the intuned server").addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
await
|
|
28
|
-
|
|
24
|
+
_commander.program.description("build the intuned server").option("-t, --template <type>", "template to use", "WebTemplate").addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile, {
|
|
25
|
+
template
|
|
26
|
+
}) => {
|
|
27
|
+
await (0, _template.moveTemplateFiles)(template);
|
|
28
|
+
const currentTemplateTsConfig = path.resolve(path.dirname(__filename), "..", "..", "template.tsconfig.json");
|
|
29
|
+
await fs.copy(currentTemplateTsConfig, `./intuned/${template}/tsconfig.json`);
|
|
30
|
+
await build(outfile, mode, template);
|
|
29
31
|
});
|
|
30
|
-
async function build(outfile, mode) {
|
|
32
|
+
async function build(outfile, mode, template) {
|
|
31
33
|
let bundle = null;
|
|
32
34
|
let buildFailed = false;
|
|
33
35
|
try {
|
|
34
36
|
bundle = await (0, _rollup.rollup)({
|
|
35
|
-
input: `./intuned/
|
|
37
|
+
input: `./intuned/${template}/index.${mode}.ts`,
|
|
36
38
|
output: {
|
|
37
39
|
globals: {
|
|
38
40
|
crypto: "crypto"
|
|
@@ -42,14 +44,15 @@ async function build(outfile, mode) {
|
|
|
42
44
|
exportConditions: ["node"],
|
|
43
45
|
preferBuiltins: true
|
|
44
46
|
}), (0, _pluginTypescript.default)({
|
|
45
|
-
tsconfig:
|
|
47
|
+
tsconfig: `./intuned/${template}/tsconfig.json`
|
|
46
48
|
}), (0, _pluginCommonjs.default)({
|
|
47
|
-
include: ["node_modules/**",
|
|
49
|
+
include: ["node_modules/**", `intuned/${template}/**`, "dist", "../typescript-sdk/**", "../typescript-runtime/**"],
|
|
48
50
|
extensions: [".js"],
|
|
49
51
|
ignoreGlobal: false,
|
|
50
52
|
sourceMap: false,
|
|
51
|
-
dynamicRequireTargets: ["
|
|
52
|
-
requireReturnsDefault: "
|
|
53
|
+
dynamicRequireTargets: ["api/**/*.js", "auth-sessions/**/*.js"],
|
|
54
|
+
requireReturnsDefault: "auto",
|
|
55
|
+
transformMixedEsModules: true
|
|
53
56
|
}), (0, _pluginDynamicImportVars.default)({
|
|
54
57
|
include: ["**/*.js", "**/*.ts"],
|
|
55
58
|
exclude: ["**/*.d.ts", "**/*.js.map"]
|
|
@@ -62,7 +65,7 @@ async function build(outfile, mode) {
|
|
|
62
65
|
});
|
|
63
66
|
console.log(`📦 Building ${outfile}`);
|
|
64
67
|
const outfileFolder = path.dirname(outfile);
|
|
65
|
-
const assetsDir = path.resolve(
|
|
68
|
+
const assetsDir = path.resolve(path.dirname(__filename), "..", "common", "assets");
|
|
66
69
|
await fs.copy(assetsDir, `${outfileFolder}/assets`);
|
|
67
70
|
await bundle.write({
|
|
68
71
|
format: "cjs",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function tsNodeImport(apiName: string): Promise<any>;
|
|
@@ -3,17 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.tsNodeImport = tsNodeImport;
|
|
7
|
+
var _fileUtils = require("./utils/fileUtils");
|
|
7
8
|
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); }
|
|
8
9
|
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; }
|
|
9
|
-
async function
|
|
10
|
+
async function tsNodeImport(apiName) {
|
|
10
11
|
require("ts-node").register({
|
|
11
12
|
transpileOnly: true,
|
|
12
13
|
compilerOptions: {
|
|
13
14
|
lib: ["dom", "es2020"]
|
|
14
15
|
}
|
|
15
16
|
});
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
return
|
|
17
|
+
const path = (0, _fileUtils.getFullPathInProject)(...apiName.split("/"));
|
|
18
|
+
const imported = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(path);
|
|
19
|
+
return imported;
|
|
19
20
|
}
|
|
@@ -6,14 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getSettings = getSettings;
|
|
7
7
|
var _fileUtils = require("./fileUtils");
|
|
8
8
|
var _settingsSchema = require("../../../common/settingsSchema");
|
|
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); }
|
|
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 && 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; }
|
|
10
11
|
async function getSettings() {
|
|
11
12
|
const settingsFilePath = (0, _fileUtils.getFullPathInProject)("Intuned.json");
|
|
12
13
|
console.log("loading settings");
|
|
13
|
-
const settings = await (
|
|
14
|
-
if (settings) {
|
|
15
|
-
const parsed = _settingsSchema.settingsSchema.safeParse(settings);
|
|
16
|
-
console.log(parsed);
|
|
14
|
+
const settings = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(settingsFilePath);
|
|
15
|
+
if (settings.default) {
|
|
16
|
+
const parsed = _settingsSchema.settingsSchema.safeParse(settings.default);
|
|
17
17
|
if (parsed.success) {
|
|
18
18
|
return parsed.data;
|
|
19
19
|
} else {
|
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.moveTemplateFiles = void 0;
|
|
7
7
|
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
8
8
|
var path = _interopRequireWildcard(require("path"));
|
|
9
9
|
var _fileUtils = require("./fileUtils");
|
|
10
10
|
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); }
|
|
11
11
|
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; }
|
|
12
|
-
const
|
|
12
|
+
const moveTemplateFiles = async templateName => {
|
|
13
13
|
await fs.remove("./intuned");
|
|
14
14
|
await fs.ensureDir("./intuned");
|
|
15
|
-
const currentFileLocation = path.resolve(__dirname, "..", "..", "..", "..",
|
|
16
|
-
await fs.copy(`${currentFileLocation}`,
|
|
17
|
-
filter: (src,
|
|
15
|
+
const currentFileLocation = path.resolve(__dirname, "..", "..", "..", "..", templateName);
|
|
16
|
+
await fs.copy(`${currentFileLocation}`, `./intuned/${templateName}`, {
|
|
17
|
+
filter: (src, _) => {
|
|
18
18
|
if (src.includes(".d.ts")) {
|
|
19
19
|
return false;
|
|
20
20
|
}
|
|
@@ -25,7 +25,7 @@ const moveWebTemplateFiles = async () => {
|
|
|
25
25
|
const pathsIgnoreList = [(0, _fileUtils.getFullPathInProject)("intuned"), (0, _fileUtils.getFullPathInProject)("node_modules"), (0, _fileUtils.getFullPathInProject)("package.json"), (0, _fileUtils.getFullPathInProject)("yarn.lock"), (0, _fileUtils.getFullPathInProject)(".env")];
|
|
26
26
|
const filesToCopy = filesAndFolders.filter(file => !pathsIgnoreList.includes(file.fullPath));
|
|
27
27
|
for (const file of filesToCopy) {
|
|
28
|
-
await fs.copy(file.fullPath, `./intuned
|
|
28
|
+
await fs.copy(file.fullPath, `./intuned/${templateName}/${file.name}`);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
|
-
exports.
|
|
31
|
+
exports.moveTemplateFiles = moveTemplateFiles;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export
|
|
2
|
+
export declare function runAutomationCLI(importFunction?: (path: string) => Promise<any>): void;
|