@intuned/runtime-dev 0.1.0-test.15 → 0.1.0-test.17
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 +1 -2
- package/WebTemplate/api.ts +90 -92
- package/WebTemplate/controllers/authSessions/create.ts +2 -2
- package/WebTemplate/controllers/authSessions/store.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +14 -12
- package/WebTemplate/index.playwright.ts +32 -42
- package/WebTemplate/jobs.ts +13 -2
- package/WebTemplate/utils.ts +53 -1
- package/api/test2.ts +6 -1
- package/auth-sessions/check.ts +3 -1
- package/auth-sessions/create.ts +10 -10
- package/dist/commands/api/run.js +41 -29
- package/dist/commands/auth-sessions/load.js +13 -11
- package/dist/commands/auth-sessions/run-check.js +21 -14
- package/dist/commands/auth-sessions/run-create.js +32 -25
- package/dist/commands/browser/save-state.js +10 -7
- package/dist/commands/browser/start-browser.js +10 -7
- package/dist/commands/build.js +30 -27
- package/dist/commands/common/browserUtils.js +28 -15
- package/dist/commands/common/getFirstLineNumber.js +20 -13
- package/dist/commands/common/getFirstLineNumber.test.js +52 -48
- package/dist/commands/common/sendMessageToClient.js +9 -2
- package/dist/commands/common/tsNodeImport.d.ts +1 -0
- package/dist/commands/common/tsNodeImport.js +18 -0
- package/dist/commands/common/utils/fileUtils.js +16 -6
- package/dist/commands/common/utils/settings.js +13 -7
- package/dist/commands/common/utils/unixSocket.js +9 -2
- package/dist/commands/common/utils/webTemplate.js +17 -9
- package/dist/commands/interface/run.js +163 -134
- package/dist/commands/ts-check.js +13 -10
- package/dist/common/Logger/Logger/index.js +16 -9
- package/dist/common/Logger/Logger/types.js +5 -1
- package/dist/common/Logger/index.js +16 -9
- package/dist/common/Logger/types.js +5 -1
- package/dist/common/asyncLocalStorage/index.js +12 -4
- package/dist/common/cleanEnvironmentVariables.js +7 -1
- package/dist/common/constants.js +7 -1
- package/dist/common/contextStorageStateHelpers.js +9 -2
- package/dist/common/getPlaywrightConstructs.js +39 -29
- package/dist/common/jwtTokenManager.js +18 -8
- package/dist/common/runApi/errors.js +42 -24
- package/dist/common/runApi/index.js +97 -103
- package/dist/common/runApi/types.d.ts +19 -5
- package/dist/common/runApi/types.js +42 -31
- package/dist/common/settingsSchema.js +10 -2
- package/dist/common/telemetry.js +12 -3
- package/dist/index.js +69 -4
- package/dist/runtime/RunError.js +8 -1
- package/dist/runtime/downloadDirectory.js +11 -5
- package/dist/runtime/enums.d.js +5 -1
- package/dist/runtime/enums.js +8 -2
- package/dist/runtime/executionHelpers.test.js +22 -20
- package/dist/runtime/export.d.js +5 -1
- package/dist/runtime/extendPayload.js +11 -5
- package/dist/runtime/extendTimeout.js +9 -3
- package/dist/runtime/index.js +53 -6
- package/dist/runtime/requestMoreInfo.js +9 -2
- package/dist/runtime/runInfo.js +11 -5
- package/package.json +3 -5
- package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -0
- package/dist/commands/common/getDefaultExportFromFile.js +0 -0
package/.babelrc
CHANGED
|
@@ -7,14 +7,13 @@
|
|
|
7
7
|
"chrome": 115,
|
|
8
8
|
"node": "16"
|
|
9
9
|
},
|
|
10
|
-
"modules":
|
|
10
|
+
"modules": "commonjs"
|
|
11
11
|
}
|
|
12
12
|
],
|
|
13
13
|
"@babel/preset-typescript"
|
|
14
14
|
],
|
|
15
15
|
"plugins": [
|
|
16
16
|
"babel-plugin-macros",
|
|
17
|
-
"@babel/plugin-syntax-dynamic-import",
|
|
18
17
|
"@babel/plugin-transform-export-namespace-from"
|
|
19
18
|
],
|
|
20
19
|
"sourceMaps": false,
|
package/WebTemplate/api.ts
CHANGED
|
@@ -33,109 +33,107 @@ 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
|
-
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
app.get(
|
|
58
|
-
"/api/protected/health",
|
|
59
|
-
accessKeyValidatorMiddleware,
|
|
60
|
-
async (req, res) => {
|
|
61
|
-
res.status(200).json({ status: "ok" });
|
|
62
|
-
}
|
|
63
|
-
);
|
|
36
|
+
if (!isJobRunMachine()) {
|
|
37
|
+
app.use((req, _, next) => {
|
|
38
|
+
const runId = req.headers[RUN_ID_HEADER] as string;
|
|
39
|
+
const jobId = req.headers[JOB_ID_HEADER] as string;
|
|
40
|
+
const jobRunId = req.headers[JOB_RUN_ID_HEADER] as string;
|
|
41
|
+
const queueId = req.headers[QUEUE_ID_HEADER] as string;
|
|
42
|
+
const proxy = req?.body?.proxy
|
|
43
|
+
? (proxyToUrl(req.body.proxy as ProxyConfig) as string)
|
|
44
|
+
: undefined;
|
|
45
|
+
const contextData = {
|
|
46
|
+
runId: runId ?? "",
|
|
47
|
+
jobId,
|
|
48
|
+
jobRunId,
|
|
49
|
+
queueId,
|
|
50
|
+
proxy,
|
|
51
|
+
...(req?.body?.executionContext ?? {}),
|
|
52
|
+
};
|
|
53
|
+
runWithContext(contextData, next);
|
|
54
|
+
});
|
|
64
55
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
56
|
+
app.get(
|
|
57
|
+
"/api/protected/health",
|
|
58
|
+
accessKeyValidatorMiddleware,
|
|
59
|
+
async (req, res) => {
|
|
60
|
+
res.status(200).json({ status: "ok" });
|
|
61
|
+
}
|
|
62
|
+
);
|
|
70
63
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
64
|
+
app.post(
|
|
65
|
+
"/api/auth-session/create",
|
|
66
|
+
accessKeyValidatorMiddleware,
|
|
67
|
+
errorRetryMiddleware(createAuthSessionController)
|
|
68
|
+
);
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
70
|
+
app.post(
|
|
71
|
+
"/api/auth-session-async/create",
|
|
72
|
+
accessKeyValidatorMiddleware,
|
|
73
|
+
errorRetryMiddleware(createAuthSessionAsyncController)
|
|
74
|
+
);
|
|
82
75
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
76
|
+
app.post(
|
|
77
|
+
"/api/auth-session/check",
|
|
78
|
+
accessKeyValidatorMiddleware,
|
|
79
|
+
errorRetryMiddleware(checkAuthSessionController)
|
|
80
|
+
);
|
|
88
81
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
82
|
+
app.post(
|
|
83
|
+
"/api/auth-session-async/check",
|
|
84
|
+
accessKeyValidatorMiddleware,
|
|
85
|
+
errorRetryMiddleware(checkAuthSessionAsyncController)
|
|
86
|
+
);
|
|
94
87
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
88
|
+
app.post(
|
|
89
|
+
"/api/auth-session/kill",
|
|
90
|
+
accessKeyValidatorMiddleware,
|
|
91
|
+
errorRetryMiddleware(killAuthSessionOperationController)
|
|
92
|
+
);
|
|
100
93
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
94
|
+
app.post(
|
|
95
|
+
"/api/auth-session/resume",
|
|
96
|
+
accessKeyValidatorMiddleware,
|
|
97
|
+
errorRetryMiddleware(resumeAuthSessionOperationController)
|
|
98
|
+
);
|
|
106
99
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
app.post(
|
|
101
|
+
"/api/auth-session-async/resume",
|
|
102
|
+
accessKeyValidatorMiddleware,
|
|
103
|
+
errorRetryMiddleware(resumeAuthSessionOperationAsyncController)
|
|
104
|
+
);
|
|
112
105
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
106
|
+
app.post(
|
|
107
|
+
"/api/run/*",
|
|
108
|
+
accessKeyValidatorMiddleware,
|
|
109
|
+
errorRetryMiddleware(runApiController)
|
|
110
|
+
);
|
|
118
111
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
app.post(
|
|
113
|
+
"/api/run-async/start/*",
|
|
114
|
+
accessKeyValidatorMiddleware,
|
|
115
|
+
errorRetryMiddleware(runApiAsyncController) // todo: this probably needs changing
|
|
116
|
+
);
|
|
124
117
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
app.get(
|
|
119
|
+
"/api/run-async/count",
|
|
120
|
+
accessKeyValidatorMiddleware,
|
|
121
|
+
getActiveAsyncEndpointController
|
|
122
|
+
);
|
|
130
123
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
124
|
+
app.post(
|
|
125
|
+
"/api/trace/upload/:runId",
|
|
126
|
+
accessKeyValidatorMiddleware,
|
|
127
|
+
uploadTraceController
|
|
128
|
+
);
|
|
137
129
|
|
|
138
|
-
app.
|
|
139
|
-
|
|
140
|
-
|
|
130
|
+
app.post(
|
|
131
|
+
"/api/trace/delete/:runId",
|
|
132
|
+
accessKeyValidatorMiddleware,
|
|
133
|
+
deleteTraceController
|
|
134
|
+
);
|
|
141
135
|
}
|
|
136
|
+
|
|
137
|
+
app.get("/api/features", accessKeyValidatorMiddleware, async (_, res) => {
|
|
138
|
+
res.status(200).json({ features: FEATURES });
|
|
139
|
+
});
|
|
@@ -2,7 +2,7 @@ import { authSessionsContextsStore } from "./store";
|
|
|
2
2
|
import { getTraceFilePath, isHeadless } from "../../utils";
|
|
3
3
|
import * as fs from "fs-extra";
|
|
4
4
|
import { runApiGenerator } from "@intuned/runtime/dist/common/runApi";
|
|
5
|
-
import type { RequestMoreInfoDetails } from "@intuned/runtime/
|
|
5
|
+
import type { RequestMoreInfoDetails } from "@intuned/runtime/runtime";
|
|
6
6
|
|
|
7
7
|
export async function createAuthSession({
|
|
8
8
|
parameters,
|
|
@@ -54,7 +54,7 @@ export async function createAuthSession({
|
|
|
54
54
|
>({
|
|
55
55
|
automationFunction: {
|
|
56
56
|
name: "auth-sessions/create",
|
|
57
|
-
params: parameters
|
|
57
|
+
params: parameters,
|
|
58
58
|
},
|
|
59
59
|
tracing: saveTrace
|
|
60
60
|
? {
|
|
@@ -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";
|
|
@@ -64,18 +68,16 @@ export async function runApi({
|
|
|
64
68
|
const resultWithTimeout = await waitWithExtendableTimeout({
|
|
65
69
|
promise: runApiInternal({
|
|
66
70
|
automationFunction: {
|
|
67
|
-
|
|
68
|
-
params
|
|
71
|
+
module: await importModule(`api/${functionName}`),
|
|
72
|
+
params,
|
|
73
|
+
},
|
|
74
|
+
auth: {
|
|
75
|
+
session: {
|
|
76
|
+
type: "state",
|
|
77
|
+
state: session,
|
|
78
|
+
},
|
|
79
|
+
runCheck: isAuthSessionEnabled,
|
|
69
80
|
},
|
|
70
|
-
auth: !isAuthSessionEnabled
|
|
71
|
-
? undefined
|
|
72
|
-
: {
|
|
73
|
-
session: {
|
|
74
|
-
type: "state",
|
|
75
|
-
state: session,
|
|
76
|
-
},
|
|
77
|
-
runCheck: isAuthSessionEnabled,
|
|
78
|
-
},
|
|
79
81
|
runOptions: {
|
|
80
82
|
environment: "deployed",
|
|
81
83
|
headless,
|
|
@@ -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,55 @@ 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 fullPath = `./${path}.ts`;
|
|
217
|
+
|
|
218
|
+
const [folderName, ...functionNameParts] = fullPath.split("/");
|
|
219
|
+
const functionNameDepth = functionNameParts.length;
|
|
220
|
+
|
|
221
|
+
// string literals should be inline
|
|
222
|
+
// currently we support only 5 levels of depth
|
|
223
|
+
// rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
|
|
224
|
+
try {
|
|
225
|
+
let imported: any = undefined;
|
|
226
|
+
switch (functionNameDepth) {
|
|
227
|
+
case 1:
|
|
228
|
+
imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
|
|
229
|
+
break;
|
|
230
|
+
case 2:
|
|
231
|
+
imported = await import(
|
|
232
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
|
|
233
|
+
);
|
|
234
|
+
break;
|
|
235
|
+
case 3:
|
|
236
|
+
imported = await import(
|
|
237
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
|
|
238
|
+
);
|
|
239
|
+
break;
|
|
240
|
+
case 4:
|
|
241
|
+
imported = await import(
|
|
242
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
|
|
243
|
+
);
|
|
244
|
+
break;
|
|
245
|
+
case 5:
|
|
246
|
+
imported = await import(
|
|
247
|
+
`./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
|
|
248
|
+
);
|
|
249
|
+
break;
|
|
250
|
+
default:
|
|
251
|
+
throw new Error(
|
|
252
|
+
"intuned supports maximum 5 levels of depth in the api folder"
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
return imported;
|
|
256
|
+
} catch (error: any) {
|
|
257
|
+
if (error.message.includes("Unknown variable dynamic import")) {
|
|
258
|
+
throw new FunctionNotFoundError("", path);
|
|
259
|
+
}
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
package/api/test2.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Page, BrowserContext } from "@intuned/playwright-core";
|
|
2
|
-
import { extendTimeout } from "../src/runtime
|
|
2
|
+
import { extendTimeout, extendPayload } from "../src/runtime";
|
|
3
3
|
|
|
4
4
|
export default async function test2(
|
|
5
5
|
{ n }: { n?: number },
|
|
@@ -18,5 +18,10 @@ export default async function test2(
|
|
|
18
18
|
extendTimeout();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
extendPayload({
|
|
22
|
+
api: "test",
|
|
23
|
+
parameters: {},
|
|
24
|
+
});
|
|
25
|
+
|
|
21
26
|
return { titles };
|
|
22
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/dist/commands/api/run.js
CHANGED
|
@@ -1,23 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.executeCLI = executeCLI;
|
|
8
|
+
var _commander = require("commander");
|
|
9
|
+
var fs = _interopRequireWildcard(require("fs-extra"));
|
|
10
|
+
var _settings = require("../common/utils/settings");
|
|
11
|
+
var _dotenv = _interopRequireDefault(require("dotenv"));
|
|
12
|
+
var _asyncLocalStorage = require("../../common/asyncLocalStorage");
|
|
13
|
+
var _enums = require("../../runtime/enums");
|
|
14
|
+
var _cleanEnvironmentVariables = require("../../common/cleanEnvironmentVariables");
|
|
15
|
+
var _Logger = require("../../common/Logger");
|
|
16
|
+
var _nanoid = require("nanoid");
|
|
17
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
18
|
+
var _runApi = require("../../common/runApi");
|
|
19
|
+
var _tsNodeImport = require("../common/tsNodeImport");
|
|
20
|
+
var _fileUtils = require("../common/utils/fileUtils");
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
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); }
|
|
23
|
+
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; }
|
|
24
|
+
_dotenv.default.config({
|
|
15
25
|
path: `.env`
|
|
16
26
|
});
|
|
17
|
-
|
|
18
|
-
cleanEnvironmentVariables();
|
|
27
|
+
async function executeCLI(apiName, mode, inputData, options) {
|
|
28
|
+
(0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
|
|
19
29
|
let authSessionPathToUse = null;
|
|
20
|
-
const settings = await getSettings();
|
|
30
|
+
const settings = await (0, _settings.getSettings)();
|
|
21
31
|
if (settings.authSessions.enabled) {
|
|
22
32
|
if (!options.authSessionPath) {
|
|
23
33
|
throw new Error("Auth session is enabled but no auth session provided");
|
|
@@ -28,10 +38,12 @@ export async function executeCLI(apiName, mode, inputData, options) {
|
|
|
28
38
|
throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
|
-
const
|
|
41
|
+
const apiFilePath = (0, _fileUtils.getFullPathInProject)("api", `${apiName}.ts`);
|
|
42
|
+
const runApiModule = await (0, _tsNodeImport.tsNodeImport)(apiFilePath);
|
|
43
|
+
const runApiResult = await (0, _runApi.runApi)({
|
|
32
44
|
automationFunction: {
|
|
33
|
-
|
|
34
|
-
params: inputData
|
|
45
|
+
module: runApiModule,
|
|
46
|
+
params: inputData
|
|
35
47
|
},
|
|
36
48
|
auth: authSessionPathToUse ? {
|
|
37
49
|
session: {
|
|
@@ -47,7 +59,7 @@ export async function executeCLI(apiName, mode, inputData, options) {
|
|
|
47
59
|
}
|
|
48
60
|
});
|
|
49
61
|
if (runApiResult.isErr()) {
|
|
50
|
-
if (runApiResult.error instanceof AutomationError) {
|
|
62
|
+
if (runApiResult.error instanceof _runApi.AutomationError) {
|
|
51
63
|
throw runApiResult.error.error;
|
|
52
64
|
}
|
|
53
65
|
console.error("An error occurred while running the API", runApiResult.error);
|
|
@@ -63,7 +75,7 @@ export async function executeCLI(apiName, mode, inputData, options) {
|
|
|
63
75
|
const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
|
|
64
76
|
const resultsDir = "/tmp/run-results";
|
|
65
77
|
if (options.outputFileId && shouldWriteToFile) {
|
|
66
|
-
logger.info(
|
|
78
|
+
_Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
|
|
67
79
|
fs.ensureDirSync(resultsDir);
|
|
68
80
|
const path = `${resultsDir}/${options.outputFileId}.json`;
|
|
69
81
|
await fs.writeJson(path, result, {
|
|
@@ -74,18 +86,18 @@ export async function executeCLI(apiName, mode, inputData, options) {
|
|
|
74
86
|
}
|
|
75
87
|
const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
|
|
76
88
|
if (hasPayloadToAppend && options.outputFileId) {
|
|
77
|
-
logger.info(
|
|
89
|
+
_Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
|
|
78
90
|
fs.ensureDirSync(resultsDir);
|
|
79
91
|
const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
|
|
80
92
|
await fs.writeJson(path, payloadToAppend, {
|
|
81
93
|
spaces: 2
|
|
82
94
|
});
|
|
83
95
|
} else if (hasPayloadToAppend) {
|
|
84
|
-
logger.info("payload to append:", payloadToAppend);
|
|
85
|
-
logger.info("This will only take an effect if this API run was part of a job.");
|
|
96
|
+
_Logger.logger.info("payload to append:", payloadToAppend);
|
|
97
|
+
_Logger.logger.info("This will only take an effect if this API run was part of a job.");
|
|
86
98
|
}
|
|
87
99
|
}
|
|
88
|
-
program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
|
|
100
|
+
_commander.program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
|
|
89
101
|
let inputData = null;
|
|
90
102
|
if (options.input) {
|
|
91
103
|
inputData = await fs.readJSON(options.input);
|
|
@@ -94,12 +106,12 @@ program.description("run the user function in the cli for testing purposes").opt
|
|
|
94
106
|
} else {
|
|
95
107
|
inputData = {};
|
|
96
108
|
}
|
|
97
|
-
await runWithContext({
|
|
98
|
-
runEnvironment: RunEnvironment.IDE,
|
|
109
|
+
await (0, _asyncLocalStorage.runWithContext)({
|
|
110
|
+
runEnvironment: _enums.RunEnvironment.IDE,
|
|
99
111
|
extendedPayloads: [],
|
|
100
|
-
runId: nanoid(),
|
|
112
|
+
runId: (0, _nanoid.nanoid)(),
|
|
101
113
|
proxy: options.proxy
|
|
102
114
|
}, () => executeCLI(apiName, mode, inputData, options));
|
|
103
115
|
process.exit(0);
|
|
104
116
|
});
|
|
105
|
-
program.parse(process.argv);
|
|
117
|
+
_commander.program.parse(process.argv);
|