@intuned/runtime-dev 0.1.0-test.45 → 0.1.0-test.6

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.
Files changed (46) hide show
  1. package/InterfaceTemplate/index.ts +1 -0
  2. package/Intuned.json +1 -1
  3. package/WebTemplate/api.ts +92 -90
  4. package/WebTemplate/controllers/async.ts +48 -52
  5. package/WebTemplate/controllers/authSessions/check.ts +5 -4
  6. package/WebTemplate/controllers/authSessions/create.ts +8 -6
  7. package/WebTemplate/controllers/authSessions/resumeOperation.ts +1 -1
  8. package/WebTemplate/controllers/runApi/helpers.ts +8 -13
  9. package/WebTemplate/index.playwright.ts +42 -32
  10. package/WebTemplate/jobs.ts +2 -13
  11. package/WebTemplate/utils.ts +1 -48
  12. package/api/test2.ts +5 -7
  13. package/auth-sessions/check.ts +1 -3
  14. package/auth-sessions/create.ts +10 -10
  15. package/bin/intuned-ts-check +1 -1
  16. package/dist/commands/api/run.js +5 -7
  17. package/dist/commands/auth-sessions/run-check.js +3 -9
  18. package/dist/commands/auth-sessions/run-create.js +6 -11
  19. package/dist/commands/build.js +12 -16
  20. package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
  21. package/dist/commands/common/{tsNodeImport.js → getDefaultExportFromFile.js} +5 -6
  22. package/dist/commands/common/utils/settings.js +5 -5
  23. package/dist/commands/common/utils/webTemplate.d.ts +1 -0
  24. package/dist/commands/common/utils/{template.js → webTemplate.js} +7 -7
  25. package/dist/commands/interface/run.d.ts +2 -1
  26. package/dist/commands/interface/run.js +108 -132
  27. package/dist/commands/ts-check.js +7 -9
  28. package/dist/common/getPlaywrightConstructs.js +1 -5
  29. package/dist/common/runApi/errors.d.ts +3 -8
  30. package/dist/common/runApi/errors.js +3 -26
  31. package/dist/common/runApi/index.d.ts +1 -1
  32. package/dist/common/runApi/index.js +65 -37
  33. package/dist/common/runApi/types.d.ts +71 -287
  34. package/dist/common/runApi/types.js +5 -29
  35. package/dist/runtime/executionHelpers.test.js +6 -6
  36. package/package.json +3 -5
  37. package/testing +0 -0
  38. package/tsconfig.json +2 -1
  39. package/11_1.zip +0 -0
  40. package/2_1.zip +0 -0
  41. package/InterfaceTemplate/index.playwright.ts +0 -5
  42. package/InterfaceTemplate/utils.ts +0 -39
  43. package/dist/commands/common/tsNodeImport.d.ts +0 -1
  44. package/dist/commands/common/utils/template.d.ts +0 -2
  45. package/dist/common/formatZodError.d.ts +0 -2
  46. package/dist/common/formatZodError.js +0 -18
@@ -0,0 +1 @@
1
+ import * as _ from "@intuned/runtime/dist/commands/interface/run";
package/Intuned.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "authSessions": {
3
- "enabled": false
3
+ "enabled": true
4
4
  }
5
5
  }
@@ -33,107 +33,109 @@ import {
33
33
  } from "./headers";
34
34
  import { FEATURES } from "./features";
35
35
 
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
- });
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
- app.get(
57
- "/api/protected/health",
58
- accessKeyValidatorMiddleware,
59
- async (req, res) => {
60
- res.status(200).json({ status: "ok" });
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
- app.post(
65
- "/api/auth-session/create",
66
- accessKeyValidatorMiddleware,
67
- errorRetryMiddleware(createAuthSessionController)
68
- );
65
+ app.post(
66
+ "/api/auth-session/create",
67
+ accessKeyValidatorMiddleware,
68
+ errorRetryMiddleware(createAuthSessionController)
69
+ );
69
70
 
70
- app.post(
71
- "/api/auth-session-async/create",
72
- accessKeyValidatorMiddleware,
73
- errorRetryMiddleware(createAuthSessionAsyncController)
74
- );
71
+ app.post(
72
+ "/api/auth-session-async/create",
73
+ accessKeyValidatorMiddleware,
74
+ errorRetryMiddleware(createAuthSessionAsyncController)
75
+ );
75
76
 
76
- app.post(
77
- "/api/auth-session/check",
78
- accessKeyValidatorMiddleware,
79
- errorRetryMiddleware(checkAuthSessionController)
80
- );
77
+ app.post(
78
+ "/api/auth-session/check",
79
+ accessKeyValidatorMiddleware,
80
+ errorRetryMiddleware(checkAuthSessionController)
81
+ );
81
82
 
82
- app.post(
83
- "/api/auth-session-async/check",
84
- accessKeyValidatorMiddleware,
85
- errorRetryMiddleware(checkAuthSessionAsyncController)
86
- );
83
+ app.post(
84
+ "/api/auth-session-async/check",
85
+ accessKeyValidatorMiddleware,
86
+ errorRetryMiddleware(checkAuthSessionAsyncController)
87
+ );
87
88
 
88
- app.post(
89
- "/api/auth-session/kill",
90
- accessKeyValidatorMiddleware,
91
- errorRetryMiddleware(killAuthSessionOperationController)
92
- );
89
+ app.post(
90
+ "/api/auth-session/kill",
91
+ accessKeyValidatorMiddleware,
92
+ errorRetryMiddleware(killAuthSessionOperationController)
93
+ );
93
94
 
94
- app.post(
95
- "/api/auth-session/resume",
96
- accessKeyValidatorMiddleware,
97
- errorRetryMiddleware(resumeAuthSessionOperationController)
98
- );
95
+ app.post(
96
+ "/api/auth-session/resume",
97
+ accessKeyValidatorMiddleware,
98
+ errorRetryMiddleware(resumeAuthSessionOperationController)
99
+ );
99
100
 
100
- app.post(
101
- "/api/auth-session-async/resume",
102
- accessKeyValidatorMiddleware,
103
- errorRetryMiddleware(resumeAuthSessionOperationAsyncController)
104
- );
101
+ app.post(
102
+ "/api/auth-session-async/resume",
103
+ accessKeyValidatorMiddleware,
104
+ errorRetryMiddleware(resumeAuthSessionOperationAsyncController)
105
+ );
105
106
 
106
- app.post(
107
- "/api/run/*",
108
- accessKeyValidatorMiddleware,
109
- errorRetryMiddleware(runApiController)
110
- );
107
+ app.post(
108
+ "/api/run/*",
109
+ accessKeyValidatorMiddleware,
110
+ errorRetryMiddleware(runApiController)
111
+ );
111
112
 
112
- app.post(
113
- "/api/run-async/start/*",
114
- accessKeyValidatorMiddleware,
115
- errorRetryMiddleware(runApiAsyncController) // todo: this probably needs changing
116
- );
113
+ app.post(
114
+ "/api/run-async/start/*",
115
+ accessKeyValidatorMiddleware,
116
+ errorRetryMiddleware(runApiAsyncController) // todo: this probably needs changing
117
+ );
117
118
 
118
- app.get(
119
- "/api/run-async/count",
120
- accessKeyValidatorMiddleware,
121
- getActiveAsyncEndpointController
122
- );
119
+ app.get(
120
+ "/api/run-async/count",
121
+ accessKeyValidatorMiddleware,
122
+ getActiveAsyncEndpointController
123
+ );
123
124
 
124
- app.post(
125
- "/api/trace/upload/:runId",
126
- accessKeyValidatorMiddleware,
127
- uploadTraceController
128
- );
125
+ app.post(
126
+ "/api/trace/upload/:runId",
127
+ accessKeyValidatorMiddleware,
128
+ uploadTraceController
129
+ );
129
130
 
130
- app.post(
131
- "/api/trace/delete/:runId",
132
- accessKeyValidatorMiddleware,
133
- deleteTraceController
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
- res.status(200).json({ features: FEATURES });
139
- });
138
+ app.get("/api/features", accessKeyValidatorMiddleware, async (_, res) => {
139
+ res.status(200).json({ features: FEATURES });
140
+ });
141
+ }
@@ -40,63 +40,59 @@ export async function runEndpointAsync<_Parameters extends any[], _Result>(
40
40
  } catch (e: any) {
41
41
  console.error(`Error running ${requestId} in async mode:`, e);
42
42
  ({ status, body } = getErrorResponse(e));
43
+ } finally {
44
+ AsyncRunEndpointController.removeRequest(taskToken);
43
45
  }
44
46
 
47
+ // report result
48
+ console.log("Reporting result for", requestId);
45
49
  try {
46
- // report result
47
- console.log("Reporting result for", requestId);
48
- try {
49
- // `retry` will keep retrying any errors unless they are thrown through calling `bail`
50
- await retry(
51
- async (bail: (e: Error) => void) => {
52
- const response = await callBackendFunctionWithToken(
53
- "run/reportResult",
54
- {
55
- method: "POST",
56
- headers: {
57
- "Content-Type": "application/json",
58
- "fly-instance-id": process.env.FLY_ALLOC_ID ?? "",
59
- },
60
- body: JSON.stringify({
61
- status,
62
- body,
63
- startTime,
64
- taskToken,
65
- }),
66
- }
67
- ).catch((e) => {
68
- const message = `Reporting result failed for ${requestId}, error: ${e.message}`;
69
- console.error(message);
70
- throw e;
71
- });
72
- if (!response.ok) {
73
- // Do not retry unauthenticated, forbidden, not found or too large responses
74
- if ([401, 403, 404, 413].includes(response.status)) {
75
- const message = `Reporting result failed for ${requestId} (non-retryable), status ${response.status}`;
76
- console.error(message);
77
- bail(new Error(message));
78
- }
79
- // retry other errors (such as 502)
80
- const message = `Reporting result failed for ${requestId}, status ${response.status}`;
81
- console.error(message);
82
- throw new Error(message);
50
+ // `retry` will keep retrying any errors unless they are thrown through calling `bail`
51
+ await retry(
52
+ async (bail: (e: Error) => void) => {
53
+ const response = await callBackendFunctionWithToken(
54
+ "run/reportResult",
55
+ {
56
+ method: "POST",
57
+ headers: {
58
+ "Content-Type": "application/json",
59
+ "fly-instance-id": process.env.FLY_ALLOC_ID ?? "",
60
+ },
61
+ body: JSON.stringify({
62
+ status,
63
+ body,
64
+ startTime,
65
+ taskToken,
66
+ }),
83
67
  }
84
-
85
- return response;
86
- },
87
- {
88
- retries: 5,
89
- factor: 2,
90
- maxTimeout: 1000 * 60, // 1 minute
91
- minTimeout: 1000 * 5, // 5 seconds
68
+ );
69
+ if (!response.ok) {
70
+ // Do not retry unauthenticated, forbidden, not found or too large responses
71
+ if ([401, 403, 404, 413].includes(response.status)) {
72
+ bail(
73
+ new Error(
74
+ `Reporting result failed for ${requestId} (non-retryable), status ${response.status}`
75
+ )
76
+ );
77
+ }
78
+ // retry other errors (such as 502)
79
+ throw new Error(
80
+ `Reporting result failed for ${requestId}, status ${response.status}`
81
+ );
92
82
  }
93
- );
94
- console.log("Reported result for", requestId);
95
- } catch (e: any) {
96
- // ignore
97
- }
98
- } finally {
99
- AsyncRunEndpointController.removeRequest(taskToken);
83
+
84
+ return response;
85
+ },
86
+ {
87
+ retries: 5,
88
+ factor: 2,
89
+ maxTimeout: 1000 * 60, // 1 minute
90
+ minTimeout: 1000 * 5, // 5 seconds
91
+ }
92
+ );
93
+ console.log("Reported result for", requestId);
94
+ } catch (e: any) {
95
+ console.log(e?.message ?? `Reporting result failed for ${requestId}`);
100
96
  }
101
97
 
102
98
  await ShutdownController.instance.checkForShutdown();
@@ -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,
@@ -36,7 +35,7 @@ export async function checkAuthSession({
36
35
  name: "auth-sessions/check",
37
36
  },
38
37
  runOptions: {
39
- environment: "standalone",
38
+ environment: "deployed",
40
39
  headless: isHeadless(),
41
40
  proxy,
42
41
  },
@@ -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 result.error.apiResponse;
51
+ return {
52
+ status: 500,
53
+ body: result.error,
54
+ };
54
55
  }
55
56
  return {
56
57
  status: 200,
@@ -1,5 +1,5 @@
1
1
  import { authSessionsContextsStore } from "./store";
2
- import { getTraceFilePath, isHeadless, importModule } from "../../utils";
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
5
  import type { RequestMoreInfoDetails } from "@intuned/runtime/dist/runtime";
@@ -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
  ? {
@@ -63,22 +63,24 @@ export async function createAuthSession({
63
63
  }
64
64
  : { enabled: false },
65
65
  runOptions: {
66
- environment: "standalone",
66
+ environment: "deployed",
67
67
  headless,
68
68
  proxy,
69
69
  },
70
70
  abortSignal: abortController.signal,
71
71
  retrieveSession: true,
72
- importFunction: importModule,
73
72
  });
74
73
 
75
74
  const result = await createGenerator.next();
76
75
 
77
- if (result.done === true) {
76
+ if (result.done) {
78
77
  const r = result.value;
79
78
 
80
79
  if (r.isErr()) {
81
- return r.error.apiResponse;
80
+ return {
81
+ status: 500,
82
+ body: r.error,
83
+ };
82
84
  }
83
85
 
84
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 === true) {
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";
@@ -65,24 +61,23 @@ export async function runApi({
65
61
 
66
62
  const abortController = new AbortController();
67
63
 
68
- backendFunctionsTokenManager.token = functionsToken;
69
64
  const resultWithTimeout = await waitWithExtendableTimeout({
70
65
  promise: runApiInternal({
71
66
  automationFunction: {
72
67
  name: `api/${functionName}`,
73
- params,
68
+ params: params ?? {},
74
69
  },
75
- auth: isAuthSessionEnabled
76
- ? {
70
+ auth: !isAuthSessionEnabled
71
+ ? undefined
72
+ : {
77
73
  session: {
78
74
  type: "state",
79
75
  state: session,
80
76
  },
81
77
  runCheck: isAuthSessionEnabled,
82
- }
83
- : undefined,
78
+ },
84
79
  runOptions: {
85
- environment: "standalone",
80
+ environment: "deployed",
86
81
  headless,
87
82
  proxy,
88
83
  },
@@ -92,8 +87,8 @@ export async function runApi({
92
87
  filePath: getTraceFilePath(runId, attemptNumber),
93
88
  }
94
89
  : { enabled: false },
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
- const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
13
+ void main();
11
14
 
12
- initializeAppInsights();
15
+ async function main() {
16
+ const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
13
17
 
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]);
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
- 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
- },
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
+ }
@@ -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 jobsV3() {
75
+ export async function runJobsLoop() {
87
76
  await reportReady();
88
77
  const initialDelay = 1000;
89
78
  let delay = initialDelay;
@@ -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,50 +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
- 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,7 +1,8 @@
1
1
  import { Page, BrowserContext } from "@intuned/playwright-core";
2
- import { extendTimeout, extendPayload } from "../src/runtime";
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
  }