@intuned/runtime-dev 0.1.0-test.28 → 0.1.0-test.3
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/Intuned.json +1 -1
- package/WebTemplate/api.ts +92 -90
- package/WebTemplate/controllers/authSessions/check.ts +4 -3
- package/WebTemplate/controllers/authSessions/create.ts +8 -10
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +6 -11
- package/WebTemplate/index.playwright.ts +42 -32
- package/WebTemplate/jobs.ts +2 -13
- package/WebTemplate/utils.ts +1 -51
- package/api/test2.ts +5 -7
- package/auth-sessions/check.ts +1 -3
- package/auth-sessions/create.ts +10 -10
- package/bin/intuned-api-run +1 -1
- package/bin/intuned-auth-session-check +1 -1
- package/bin/intuned-auth-session-create +1 -1
- package/bin/intuned-auth-session-load +1 -1
- package/bin/intuned-auth-session-refresh +1 -1
- package/bin/intuned-browser-save-state +1 -1
- package/bin/intuned-browser-start +1 -1
- package/bin/intuned-build +1 -1
- package/bin/intuned-ts-check +1 -1
- package/dist/commands/api/run.js +2 -4
- package/dist/commands/auth-sessions/run-check.js +1 -3
- package/dist/commands/auth-sessions/run-create.js +3 -5
- package/dist/commands/build.js +4 -6
- package/dist/commands/common/browserUtils.js +1 -1
- package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
- package/dist/commands/common/{tsNodeImport.js → getDefaultExportFromFile.js} +5 -6
- package/dist/commands/common/getFirstLineNumber.test.js +2 -2
- package/dist/commands/common/utils/settings.js +2 -1
- package/dist/commands/common/utils/webTemplate.js +2 -2
- package/dist/commands/interface/run.js +106 -122
- package/dist/commands/ts-check.js +2 -2
- package/dist/common/Logger/Logger/index.d.ts +1 -1
- package/dist/common/Logger/index.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.js +3 -3
- package/dist/common/runApi/errors.d.ts +1 -1
- package/dist/common/runApi/index.d.ts +5 -5
- package/dist/common/runApi/index.js +50 -21
- package/dist/common/runApi/types.d.ts +1 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/runtime/RunError.d.ts +1 -1
- package/dist/runtime/executionHelpers.test.js +2 -2
- package/dist/runtime/export.d.ts +1 -1
- package/dist/runtime/extendPayload.d.ts +1 -1
- package/dist/runtime/extendPayload.js +1 -1
- package/dist/runtime/index.d.ts +7 -7
- package/dist/runtime/index.js +6 -6
- package/dist/runtime/runInfo.d.ts +1 -1
- package/dist/runtime/runInfo.js +1 -1
- package/package.json +5 -6
- package/tsconfig.json +1 -1
- package/InterfaceTemplate/index.js +0 -1
- package/WebTemplate/accessKeyHelpers.js +0 -20
- package/WebTemplate/api.js +0 -48
- package/WebTemplate/app.js +0 -13
- package/WebTemplate/controllers/async.js +0 -78
- package/WebTemplate/controllers/authSessions/check.js +0 -44
- package/WebTemplate/controllers/authSessions/create.js +0 -69
- package/WebTemplate/controllers/authSessions/index.js +0 -25
- package/WebTemplate/controllers/authSessions/killOperation.js +0 -26
- package/WebTemplate/controllers/authSessions/resumeOperation.js +0 -42
- package/WebTemplate/controllers/authSessions/store.js +0 -1
- package/WebTemplate/controllers/controllers.js +0 -30
- package/WebTemplate/controllers/runApi/helpers.js +0 -90
- package/WebTemplate/controllers/runApi/index.js +0 -45
- package/WebTemplate/controllers/runApi/types.js +0 -1
- package/WebTemplate/controllers/traces.js +0 -108
- package/WebTemplate/features.js +0 -6
- package/WebTemplate/headers.js +0 -6
- package/WebTemplate/index.playwright.js +0 -37
- package/WebTemplate/index.vanilla.js +0 -19
- package/WebTemplate/jobs.js +0 -259
- package/WebTemplate/shutdown.js +0 -51
- package/WebTemplate/utils.js +0 -189
- package/api/authed.js +0 -6
- package/api/test.js +0 -3
- package/api/test2.js +0 -17
- package/auth-sessions/check.js +0 -6
- package/auth-sessions/create.js +0 -20
- package/dist/commands/common/tsNodeImport.d.ts +0 -1
- package/playwright.config.js +0 -43
- package/preserve-dynamic-imports.js +0 -16
- package/vite.config.js +0 -16
package/Intuned.json
CHANGED
package/WebTemplate/api.ts
CHANGED
|
@@ -33,107 +33,109 @@ import {
|
|
|
33
33
|
} from "./headers";
|
|
34
34
|
import { FEATURES } from "./features";
|
|
35
35
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
export function registerApiEndpoints() {
|
|
37
|
+
if (!isJobRunMachine()) {
|
|
38
|
+
app.use((req, _, next) => {
|
|
39
|
+
const runId = req.headers[RUN_ID_HEADER] as string;
|
|
40
|
+
const jobId = req.headers[JOB_ID_HEADER] as string;
|
|
41
|
+
const jobRunId = req.headers[JOB_RUN_ID_HEADER] as string;
|
|
42
|
+
const queueId = req.headers[QUEUE_ID_HEADER] as string;
|
|
43
|
+
const proxy = req?.body?.proxy
|
|
44
|
+
? (proxyToUrl(req.body.proxy as ProxyConfig) as string)
|
|
45
|
+
: undefined;
|
|
46
|
+
const contextData = {
|
|
47
|
+
runId: runId ?? "",
|
|
48
|
+
jobId,
|
|
49
|
+
jobRunId,
|
|
50
|
+
queueId,
|
|
51
|
+
proxy,
|
|
52
|
+
...(req?.body?.executionContext ?? {}),
|
|
53
|
+
};
|
|
54
|
+
runWithContext(contextData, next);
|
|
55
|
+
});
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
app.get(
|
|
58
|
+
"/api/protected/health",
|
|
59
|
+
accessKeyValidatorMiddleware,
|
|
60
|
+
async (req, res) => {
|
|
61
|
+
res.status(200).json({ status: "ok" });
|
|
62
|
+
}
|
|
63
|
+
);
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
app.post(
|
|
66
|
+
"/api/auth-session/create",
|
|
67
|
+
accessKeyValidatorMiddleware,
|
|
68
|
+
errorRetryMiddleware(createAuthSessionController)
|
|
69
|
+
);
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
app.post(
|
|
72
|
+
"/api/auth-session-async/create",
|
|
73
|
+
accessKeyValidatorMiddleware,
|
|
74
|
+
errorRetryMiddleware(createAuthSessionAsyncController)
|
|
75
|
+
);
|
|
75
76
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
app.post(
|
|
78
|
+
"/api/auth-session/check",
|
|
79
|
+
accessKeyValidatorMiddleware,
|
|
80
|
+
errorRetryMiddleware(checkAuthSessionController)
|
|
81
|
+
);
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
app.post(
|
|
84
|
+
"/api/auth-session-async/check",
|
|
85
|
+
accessKeyValidatorMiddleware,
|
|
86
|
+
errorRetryMiddleware(checkAuthSessionAsyncController)
|
|
87
|
+
);
|
|
87
88
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
app.post(
|
|
90
|
+
"/api/auth-session/kill",
|
|
91
|
+
accessKeyValidatorMiddleware,
|
|
92
|
+
errorRetryMiddleware(killAuthSessionOperationController)
|
|
93
|
+
);
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
app.post(
|
|
96
|
+
"/api/auth-session/resume",
|
|
97
|
+
accessKeyValidatorMiddleware,
|
|
98
|
+
errorRetryMiddleware(resumeAuthSessionOperationController)
|
|
99
|
+
);
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
app.post(
|
|
102
|
+
"/api/auth-session-async/resume",
|
|
103
|
+
accessKeyValidatorMiddleware,
|
|
104
|
+
errorRetryMiddleware(resumeAuthSessionOperationAsyncController)
|
|
105
|
+
);
|
|
105
106
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
107
|
+
app.post(
|
|
108
|
+
"/api/run/*",
|
|
109
|
+
accessKeyValidatorMiddleware,
|
|
110
|
+
errorRetryMiddleware(runApiController)
|
|
111
|
+
);
|
|
111
112
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
113
|
+
app.post(
|
|
114
|
+
"/api/run-async/start/*",
|
|
115
|
+
accessKeyValidatorMiddleware,
|
|
116
|
+
errorRetryMiddleware(runApiAsyncController) // todo: this probably needs changing
|
|
117
|
+
);
|
|
117
118
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
app.get(
|
|
120
|
+
"/api/run-async/count",
|
|
121
|
+
accessKeyValidatorMiddleware,
|
|
122
|
+
getActiveAsyncEndpointController
|
|
123
|
+
);
|
|
123
124
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
app.post(
|
|
126
|
+
"/api/trace/upload/:runId",
|
|
127
|
+
accessKeyValidatorMiddleware,
|
|
128
|
+
uploadTraceController
|
|
129
|
+
);
|
|
129
130
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
131
|
+
app.post(
|
|
132
|
+
"/api/trace/delete/:runId",
|
|
133
|
+
accessKeyValidatorMiddleware,
|
|
134
|
+
deleteTraceController
|
|
135
|
+
);
|
|
136
|
+
}
|
|
136
137
|
|
|
137
|
-
app.get("/api/features", accessKeyValidatorMiddleware, async (_, res) => {
|
|
138
|
-
|
|
139
|
-
});
|
|
138
|
+
app.get("/api/features", accessKeyValidatorMiddleware, async (_, res) => {
|
|
139
|
+
res.status(200).json({ features: FEATURES });
|
|
140
|
+
});
|
|
141
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { readJSON } from "fs-extra";
|
|
2
2
|
import { isHeadless } from "../../utils";
|
|
3
3
|
import { runApi } from "@intuned/runtime/dist/common/runApi";
|
|
4
|
-
import { importModule } from "../../utils";
|
|
5
4
|
|
|
6
5
|
export async function checkAuthSession({
|
|
7
6
|
proxy,
|
|
@@ -47,10 +46,12 @@ export async function checkAuthSession({
|
|
|
47
46
|
},
|
|
48
47
|
runCheck: false,
|
|
49
48
|
},
|
|
50
|
-
importFunction: importModule,
|
|
51
49
|
});
|
|
52
50
|
if (result.isErr()) {
|
|
53
|
-
return
|
|
51
|
+
return {
|
|
52
|
+
status: 500,
|
|
53
|
+
body: result.error,
|
|
54
|
+
};
|
|
54
55
|
}
|
|
55
56
|
return {
|
|
56
57
|
status: 200,
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { authSessionsContextsStore } from "./store";
|
|
2
|
-
import { getTraceFilePath, isHeadless
|
|
2
|
+
import { getTraceFilePath, isHeadless } from "../../utils";
|
|
3
3
|
import * as fs from "fs-extra";
|
|
4
|
-
import {
|
|
5
|
-
runApiGenerator,
|
|
6
|
-
type RunApiResult,
|
|
7
|
-
type RunApiResultWithSessionOk,
|
|
8
|
-
} from "@intuned/runtime/dist/common/runApi";
|
|
4
|
+
import { runApiGenerator } from "@intuned/runtime/dist/common/runApi";
|
|
9
5
|
import type { RequestMoreInfoDetails } from "@intuned/runtime/dist/runtime";
|
|
10
6
|
|
|
11
7
|
export async function createAuthSession({
|
|
@@ -58,7 +54,7 @@ export async function createAuthSession({
|
|
|
58
54
|
>({
|
|
59
55
|
automationFunction: {
|
|
60
56
|
name: "auth-sessions/create",
|
|
61
|
-
params: parameters,
|
|
57
|
+
params: parameters ?? {},
|
|
62
58
|
},
|
|
63
59
|
tracing: saveTrace
|
|
64
60
|
? {
|
|
@@ -73,16 +69,18 @@ export async function createAuthSession({
|
|
|
73
69
|
},
|
|
74
70
|
abortSignal: abortController.signal,
|
|
75
71
|
retrieveSession: true,
|
|
76
|
-
importFunction: importModule,
|
|
77
72
|
});
|
|
78
73
|
|
|
79
74
|
const result = await createGenerator.next();
|
|
80
75
|
|
|
81
|
-
if (result.done
|
|
76
|
+
if (result.done) {
|
|
82
77
|
const r = result.value;
|
|
83
78
|
|
|
84
79
|
if (r.isErr()) {
|
|
85
|
-
return
|
|
80
|
+
return {
|
|
81
|
+
status: 500,
|
|
82
|
+
body: r.error,
|
|
83
|
+
};
|
|
86
84
|
}
|
|
87
85
|
|
|
88
86
|
return {
|
|
@@ -33,7 +33,7 @@ export async function resumeAuthSessionOperation({
|
|
|
33
33
|
|
|
34
34
|
const result = await operation.generator.next(input);
|
|
35
35
|
|
|
36
|
-
if (result.done
|
|
36
|
+
if (result.done) {
|
|
37
37
|
authSessionsContextsStore.delete(operationId);
|
|
38
38
|
if (result.value.isErr()) {
|
|
39
39
|
return result.value.error.apiResponse;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getTraceFilePath,
|
|
3
|
-
importModule,
|
|
4
|
-
waitWithExtendableTimeout,
|
|
5
|
-
} from "../../utils";
|
|
1
|
+
import { getTraceFilePath, waitWithExtendableTimeout } from "../../utils";
|
|
6
2
|
import * as fs from "fs-extra";
|
|
7
3
|
import { getExecutionContext } from "@intuned/runtime";
|
|
8
4
|
import { backendFunctionsTokenManager } from "@intuned/runtime/dist/common/jwtTokenManager";
|
|
@@ -69,17 +65,17 @@ export async function runApi({
|
|
|
69
65
|
promise: runApiInternal({
|
|
70
66
|
automationFunction: {
|
|
71
67
|
name: `api/${functionName}`,
|
|
72
|
-
params,
|
|
68
|
+
params: params ?? {},
|
|
73
69
|
},
|
|
74
|
-
auth: isAuthSessionEnabled
|
|
75
|
-
?
|
|
70
|
+
auth: !isAuthSessionEnabled
|
|
71
|
+
? undefined
|
|
72
|
+
: {
|
|
76
73
|
session: {
|
|
77
74
|
type: "state",
|
|
78
75
|
state: session,
|
|
79
76
|
},
|
|
80
77
|
runCheck: isAuthSessionEnabled,
|
|
81
|
-
}
|
|
82
|
-
: undefined,
|
|
78
|
+
},
|
|
83
79
|
runOptions: {
|
|
84
80
|
environment: "deployed",
|
|
85
81
|
headless,
|
|
@@ -93,7 +89,6 @@ export async function runApi({
|
|
|
93
89
|
: { enabled: false },
|
|
94
90
|
functionsToken,
|
|
95
91
|
abortSignal: abortController.signal,
|
|
96
|
-
importFunction: importModule,
|
|
97
92
|
}),
|
|
98
93
|
initialTimeout: requestTimeout,
|
|
99
94
|
abortController,
|
|
@@ -6,42 +6,52 @@ 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";
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
void main();
|
|
11
14
|
|
|
12
|
-
|
|
15
|
+
async function main() {
|
|
16
|
+
const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
initializeAppInsights();
|
|
19
|
+
|
|
20
|
+
app.use((req, res, next) => {
|
|
21
|
+
// Cleanup after the response is sent
|
|
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);
|
|
18
40
|
void ShutdownController.instance.checkForShutdown();
|
|
41
|
+
console.log(`Server is running on port ${port}`);
|
|
19
42
|
});
|
|
20
43
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
},
|
|
44
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
45
|
+
const telemetryClient = getTelemetryClient();
|
|
46
|
+
console.error("Unhandled Rejection at:", promise, "reason:", reason);
|
|
47
|
+
const context = getExecutionContext();
|
|
48
|
+
telemetryClient?.trackEvent({
|
|
49
|
+
name: "UNHANDLED_REJECTION",
|
|
50
|
+
properties: {
|
|
51
|
+
runId: context?.runId,
|
|
52
|
+
promise,
|
|
53
|
+
reason,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
46
56
|
});
|
|
47
|
-
}
|
|
57
|
+
}
|
package/WebTemplate/jobs.ts
CHANGED
|
@@ -6,13 +6,7 @@ import {
|
|
|
6
6
|
RUN_ID_HEADER,
|
|
7
7
|
SHOULD_SHUTDOWN_HEADER,
|
|
8
8
|
} from "./headers";
|
|
9
|
-
import {
|
|
10
|
-
getErrorResponse,
|
|
11
|
-
isHeadless,
|
|
12
|
-
isJobRunMachine,
|
|
13
|
-
ProxyConfig,
|
|
14
|
-
proxyToUrl,
|
|
15
|
-
} from "./utils";
|
|
9
|
+
import { getErrorResponse, isHeadless, ProxyConfig, proxyToUrl } from "./utils";
|
|
16
10
|
import {
|
|
17
11
|
callBackendFunctionWithToken,
|
|
18
12
|
backendFunctionsTokenManager,
|
|
@@ -32,11 +26,6 @@ type JobPayload = {
|
|
|
32
26
|
traceSignedUrl?: string;
|
|
33
27
|
};
|
|
34
28
|
|
|
35
|
-
if (isJobRunMachine()) {
|
|
36
|
-
console.log("Running in job v3 mode");
|
|
37
|
-
void jobsV3();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
29
|
async function runApiInContext(
|
|
41
30
|
jobPayload: JobPayload
|
|
42
31
|
): Promise<Awaited<ReturnType<typeof runApi>>> {
|
|
@@ -83,7 +72,7 @@ async function runApiInContext(
|
|
|
83
72
|
}
|
|
84
73
|
}
|
|
85
74
|
|
|
86
|
-
async function
|
|
75
|
+
export async function runJobsLoop() {
|
|
87
76
|
await reportReady();
|
|
88
77
|
const initialDelay = 1000;
|
|
89
78
|
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/dist/common/asyncLocalStorage";
|
|
5
5
|
import { setTimeout } from "timers/promises";
|
|
6
6
|
|
|
7
7
|
export class FunctionNotFoundError extends Error {
|
|
@@ -208,53 +208,3 @@ export async function waitWithExtendableTimeout<T>({
|
|
|
208
208
|
result: await promise,
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
-
|
|
212
|
-
export async function importModule(path: string) {
|
|
213
|
-
// cleanup environment variables before running the user code
|
|
214
|
-
// cleanEnvironmentVariables();
|
|
215
|
-
|
|
216
|
-
const [folderName, ...functionNameParts] = path.split("/");
|
|
217
|
-
const functionNameDepth = functionNameParts.length;
|
|
218
|
-
|
|
219
|
-
// string literals should be inline
|
|
220
|
-
// currently we support only 5 levels of depth
|
|
221
|
-
// rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
|
|
222
|
-
try {
|
|
223
|
-
let imported: any = undefined;
|
|
224
|
-
switch (functionNameDepth) {
|
|
225
|
-
case 1:
|
|
226
|
-
imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
|
|
227
|
-
break;
|
|
228
|
-
case 2:
|
|
229
|
-
imported = await import(
|
|
230
|
-
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
|
|
231
|
-
);
|
|
232
|
-
break;
|
|
233
|
-
case 3:
|
|
234
|
-
imported = await import(
|
|
235
|
-
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
|
|
236
|
-
);
|
|
237
|
-
break;
|
|
238
|
-
case 4:
|
|
239
|
-
imported = await import(
|
|
240
|
-
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
|
|
241
|
-
);
|
|
242
|
-
break;
|
|
243
|
-
case 5:
|
|
244
|
-
imported = await import(
|
|
245
|
-
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
|
|
246
|
-
);
|
|
247
|
-
break;
|
|
248
|
-
default:
|
|
249
|
-
throw new Error(
|
|
250
|
-
"intuned supports maximum 5 levels of depth in the api folder"
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
return imported;
|
|
254
|
-
} catch (error: any) {
|
|
255
|
-
if (error.message.includes("Unknown variable dynamic import")) {
|
|
256
|
-
throw new FunctionNotFoundError("", path);
|
|
257
|
-
}
|
|
258
|
-
throw error;
|
|
259
|
-
}
|
|
260
|
-
}
|
package/api/test2.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Page, BrowserContext } from "@intuned/playwright-core";
|
|
2
|
-
import { extendTimeout
|
|
2
|
+
import { extendTimeout } from "../src/runtime/extendTimeout";
|
|
3
|
+
import { requestOTP } from "../src/runtime/requestMoreInfo";
|
|
3
4
|
|
|
4
|
-
export default async function test2(
|
|
5
|
+
export default async function* test2(
|
|
5
6
|
{ n }: { n?: number },
|
|
6
7
|
page: Page,
|
|
7
8
|
context: BrowserContext
|
|
@@ -9,6 +10,8 @@ export default async function test2(
|
|
|
9
10
|
await page.goto("https://wikipedia.org/");
|
|
10
11
|
await page.waitForTimeout(1000);
|
|
11
12
|
|
|
13
|
+
yield requestOTP("Please enter the OTP");
|
|
14
|
+
|
|
12
15
|
const titles: string[] = [];
|
|
13
16
|
|
|
14
17
|
for (let i = 0; i < (n ?? 2); i++) {
|
|
@@ -18,10 +21,5 @@ export default async function test2(
|
|
|
18
21
|
extendTimeout();
|
|
19
22
|
}
|
|
20
23
|
|
|
21
|
-
extendPayload({
|
|
22
|
-
api: "test",
|
|
23
|
-
parameters: {},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
24
|
return { titles };
|
|
27
25
|
}
|
package/auth-sessions/check.ts
CHANGED
|
@@ -5,7 +5,5 @@ export default async function check(
|
|
|
5
5
|
_context: BrowserContext
|
|
6
6
|
): Promise<boolean> {
|
|
7
7
|
await page.goto("https://setcookie.net");
|
|
8
|
-
|
|
9
|
-
console.log("Check result", result);
|
|
10
|
-
return result;
|
|
8
|
+
return (await page.locator("ul li code").all()).length > 0;
|
|
11
9
|
}
|
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
|
-
|
|
19
|
-
|
|
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-api-run
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/api/run.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/auth-sessions/run-check.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/auth-sessions/run-create.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/auth-sessions/load.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/auth-sessions/run-refresh.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/browser/save-state.js");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/browser/start-browser.js");
|
package/bin/intuned-build
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/build.js");
|
package/bin/intuned-ts-check
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
require("../dist/commands/ts-check.js");
|
package/dist/commands/api/run.js
CHANGED
|
@@ -16,7 +16,6 @@ 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");
|
|
20
19
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
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); }
|
|
22
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 && 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; }
|
|
@@ -40,7 +39,7 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
40
39
|
const runApiResult = await (0, _runApi.runApi)({
|
|
41
40
|
automationFunction: {
|
|
42
41
|
name: `api/${apiName}`,
|
|
43
|
-
params: inputData
|
|
42
|
+
params: inputData ?? {}
|
|
44
43
|
},
|
|
45
44
|
auth: authSessionPathToUse ? {
|
|
46
45
|
session: {
|
|
@@ -53,8 +52,7 @@ async function executeCLI(apiName, mode, inputData, options) {
|
|
|
53
52
|
environment: "ide",
|
|
54
53
|
cdpAddress: options.cdpAddress,
|
|
55
54
|
mode
|
|
56
|
-
}
|
|
57
|
-
importFunction: _tsNodeImport.tsNodeImport
|
|
55
|
+
}
|
|
58
56
|
});
|
|
59
57
|
if (runApiResult.isErr()) {
|
|
60
58
|
if (runApiResult.error instanceof _runApi.AutomationError) {
|