@intuned/runtime-dev 0.0.1 → 0.1.0-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/InterfaceTemplate/index.ts +1 -0
  2. package/Intuned.json +5 -0
  3. package/WebTemplate/api.ts +92 -90
  4. package/WebTemplate/controllers/authSessions/check.ts +23 -29
  5. package/WebTemplate/controllers/authSessions/create.ts +46 -71
  6. package/WebTemplate/controllers/authSessions/index.ts +4 -4
  7. package/WebTemplate/controllers/authSessions/killOperation.ts +1 -1
  8. package/WebTemplate/controllers/authSessions/resumeOperation.ts +28 -52
  9. package/WebTemplate/controllers/authSessions/store.ts +11 -6
  10. package/WebTemplate/controllers/runApi/helpers.ts +47 -146
  11. package/WebTemplate/index.playwright.ts +42 -32
  12. package/WebTemplate/index.vanilla.ts +2 -20
  13. package/WebTemplate/jobs.ts +2 -13
  14. package/WebTemplate/utils.ts +1 -85
  15. package/WebTemplate.zip +0 -0
  16. package/api/authed.ts +12 -0
  17. package/api/test.ts +3 -0
  18. package/api/test2.ts +25 -0
  19. package/auth-sessions/check.ts +9 -0
  20. package/auth-sessions/create.ts +32 -0
  21. package/authSessions +1 -0
  22. package/bin/intuned-api-run +2 -0
  23. package/bin/intuned-auth-session-check +2 -0
  24. package/bin/intuned-auth-session-create +2 -0
  25. package/bin/intuned-auth-session-load +2 -0
  26. package/bin/intuned-auth-session-refresh +2 -0
  27. package/bin/intuned-browser-save-state +2 -0
  28. package/bin/intuned-browser-start +2 -0
  29. package/bin/intuned-build +2 -0
  30. package/bin/intuned-ts-check +2 -0
  31. package/dist/commands/api/run.d.ts +6 -0
  32. package/dist/commands/api/run.js +113 -0
  33. package/dist/commands/auth-sessions/load.d.ts +2 -0
  34. package/dist/commands/auth-sessions/load.js +32 -0
  35. package/dist/commands/auth-sessions/run-check.d.ts +2 -0
  36. package/dist/commands/auth-sessions/run-check.js +56 -0
  37. package/dist/commands/auth-sessions/run-create.d.ts +2 -0
  38. package/dist/commands/auth-sessions/run-create.js +96 -0
  39. package/dist/commands/browser/save-state.d.ts +2 -0
  40. package/dist/commands/browser/save-state.js +17 -0
  41. package/dist/commands/browser/start-browser.d.ts +2 -0
  42. package/dist/commands/browser/start-browser.js +14 -0
  43. package/dist/commands/build.d.ts +2 -0
  44. package/dist/commands/build.js +83 -0
  45. package/dist/commands/common/browserUtils.d.ts +14 -0
  46. package/dist/commands/common/browserUtils.js +58 -0
  47. package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
  48. package/dist/commands/common/getDefaultExportFromFile.js +19 -0
  49. package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
  50. package/dist/commands/common/getFirstLineNumber.js +103 -0
  51. package/{src/commands/common/getFirstLineNumber.test.ts → dist/commands/common/getFirstLineNumber.test.js} +75 -121
  52. package/dist/commands/common/sendMessageToClient.d.ts +1 -0
  53. package/dist/commands/common/sendMessageToClient.js +10 -0
  54. package/dist/commands/common/utils/fileUtils.d.ts +6 -0
  55. package/dist/commands/common/utils/fileUtils.js +33 -0
  56. package/dist/commands/common/utils/settings.d.ts +2 -0
  57. package/dist/commands/common/utils/settings.js +28 -0
  58. package/dist/commands/common/utils/unixSocket.d.ts +9 -0
  59. package/dist/commands/common/utils/unixSocket.js +45 -0
  60. package/dist/commands/common/utils/webTemplate.d.ts +1 -0
  61. package/dist/commands/common/utils/webTemplate.js +31 -0
  62. package/dist/commands/interface/run.d.ts +2 -0
  63. package/dist/commands/interface/run.js +161 -0
  64. package/dist/commands/ts-check.d.ts +2 -0
  65. package/dist/commands/ts-check.js +54 -0
  66. package/dist/common/Logger/Logger/index.d.ts +12 -0
  67. package/dist/common/Logger/Logger/index.js +60 -0
  68. package/{src/common/Logger/Logger/types.ts → dist/common/Logger/Logger/types.d.ts} +4 -5
  69. package/dist/common/Logger/Logger/types.js +5 -0
  70. package/dist/common/Logger/index.d.ts +12 -0
  71. package/dist/common/Logger/index.js +60 -0
  72. package/{src/common/Logger/types.ts → dist/common/Logger/types.d.ts} +4 -5
  73. package/dist/common/Logger/types.js +5 -0
  74. package/dist/common/asyncLocalStorage/index.d.ts +16 -0
  75. package/dist/common/asyncLocalStorage/index.js +17 -0
  76. package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
  77. package/dist/common/cleanEnvironmentVariables.js +16 -0
  78. package/dist/common/constants.d.ts +1 -0
  79. package/dist/common/constants.js +7 -0
  80. package/dist/common/contextStorageStateHelpers.d.ts +14 -0
  81. package/dist/common/contextStorageStateHelpers.js +50 -0
  82. package/dist/common/getPlaywrightConstructs.d.ts +30 -0
  83. package/dist/common/getPlaywrightConstructs.js +192 -0
  84. package/dist/common/jwtTokenManager.d.ts +16 -0
  85. package/dist/common/jwtTokenManager.js +81 -0
  86. package/dist/common/runApi/errors.d.ts +71 -0
  87. package/dist/common/runApi/errors.js +172 -0
  88. package/dist/common/runApi/index.d.ts +12 -0
  89. package/dist/common/runApi/index.js +288 -0
  90. package/dist/common/runApi/types.d.ts +486 -0
  91. package/dist/common/runApi/types.js +50 -0
  92. package/dist/common/settingsSchema.d.ts +19 -0
  93. package/dist/common/settingsSchema.js +17 -0
  94. package/dist/common/telemetry.d.ts +3 -0
  95. package/dist/common/telemetry.js +32 -0
  96. package/dist/index.d.ts +4 -0
  97. package/dist/index.js +69 -0
  98. package/dist/runtime/RunError.d.ts +5 -0
  99. package/dist/runtime/RunError.js +19 -0
  100. package/dist/runtime/downloadDirectory.d.ts +1 -0
  101. package/dist/runtime/downloadDirectory.js +19 -0
  102. package/dist/runtime/enums.d.js +5 -0
  103. package/dist/runtime/enums.js +18 -0
  104. package/dist/runtime/executionHelpers.test.js +53 -0
  105. package/dist/runtime/export.d.js +5 -0
  106. package/dist/runtime/extendPayload.d.ts +2 -0
  107. package/dist/runtime/extendPayload.js +21 -0
  108. package/dist/runtime/extendTimeout.d.ts +1 -0
  109. package/dist/runtime/extendTimeout.js +30 -0
  110. package/{src/runtime/index.ts → dist/runtime/index.d.ts} +2 -3
  111. package/dist/runtime/index.js +53 -0
  112. package/dist/runtime/requestMoreInfo.d.ts +18 -0
  113. package/dist/runtime/requestMoreInfo.js +25 -0
  114. package/dist/runtime/runInfo.d.ts +2 -0
  115. package/dist/runtime/runInfo.js +21 -0
  116. package/output.txt +39 -0
  117. package/package.json +9 -7
  118. package/testing +0 -0
  119. package/tsconfig.json +2 -1
  120. package/.vite/deps_temp_01af7156/package.json +0 -3
  121. package/.vscode/extensions.json +0 -3
  122. package/.vscode/launch.json +0 -102
  123. package/.vscode/settings.json +0 -12
  124. package/playwright.config.ts +0 -48
  125. package/src/commands/api/run.ts +0 -225
  126. package/src/commands/auth-sessions/load.ts +0 -42
  127. package/src/commands/auth-sessions/run-check.ts +0 -70
  128. package/src/commands/auth-sessions/run-create.ts +0 -124
  129. package/src/commands/browser/save-state.ts +0 -22
  130. package/src/commands/browser/start-browser.ts +0 -17
  131. package/src/commands/build.ts +0 -125
  132. package/src/commands/common/browserUtils.ts +0 -80
  133. package/src/commands/common/getDefaultExportFromFile.ts +0 -13
  134. package/src/commands/common/getFirstLineNumber.ts +0 -146
  135. package/src/commands/common/sendMessageToClient.ts +0 -8
  136. package/src/commands/common/utils/fileUtils.ts +0 -25
  137. package/src/commands/common/utils/settings.ts +0 -23
  138. package/src/commands/common/utils/webTemplate.ts +0 -46
  139. package/src/commands/testing/saveVisibleHtml.ts +0 -29
  140. package/src/commands/ts-check.ts +0 -88
  141. package/src/common/Logger/Logger/index.ts +0 -64
  142. package/src/common/Logger/index.ts +0 -64
  143. package/src/common/asyncLocalStorage/index.ts +0 -29
  144. package/src/common/cleanEnvironmentVariables.ts +0 -13
  145. package/src/common/constants.ts +0 -1
  146. package/src/common/contextStorageStateHelpers.ts +0 -71
  147. package/src/common/getPlaywrightConstructs.ts +0 -283
  148. package/src/common/jwtTokenManager.ts +0 -111
  149. package/src/common/settingsSchema.ts +0 -16
  150. package/src/common/telemetry.ts +0 -49
  151. package/src/index.ts +0 -14
  152. package/src/runtime/RunError.ts +0 -16
  153. package/src/runtime/downloadDirectory.ts +0 -14
  154. package/src/runtime/enums.ts +0 -11
  155. package/src/runtime/executionHelpers.test.ts +0 -70
  156. package/src/runtime/extendPayload.ts +0 -22
  157. package/src/runtime/extendTimeout.ts +0 -32
  158. package/src/runtime/requestMoreInfo.ts +0 -40
  159. package/src/runtime/runInfo.ts +0 -19
  160. package/vite.config.ts +0 -17
  161. /package/{src → dist}/common/assets/browser_scripts.js +0 -0
  162. /package/{src → dist}/runtime/enums.d.ts +0 -0
  163. /package/{src → dist}/runtime/export.d.ts +0 -0
@@ -0,0 +1 @@
1
+ import * as _ from "@intuned/runtime/dist/commands/interface/run";
package/Intuned.json ADDED
@@ -0,0 +1,5 @@
1
+ {
2
+ "authSessions": {
3
+ "enabled": true
4
+ }
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
+ }
@@ -1,11 +1,8 @@
1
- import { getDownloadDirectoryPath } from "@intuned/runtime";
2
- import { getProductionPlaywrightConstructs } from "@intuned/runtime";
3
- import { checkAuthSessionWithRetries, isHeadless } from "../../utils";
4
- import * as fs from "fs-extra";
5
1
  import { readJSON } from "fs-extra";
2
+ import { isHeadless } from "../../utils";
3
+ import { runApi } from "@intuned/runtime/dist/common/runApi";
6
4
 
7
5
  export async function checkAuthSession({
8
- mode,
9
6
  proxy,
10
7
  session,
11
8
  }: {
@@ -33,36 +30,33 @@ export async function checkAuthSession({
33
30
  };
34
31
  }
35
32
 
36
- if (mode !== "async") {
37
- return {
38
- status: 400,
39
- body: {
40
- error: "Invalid Request",
41
- message: "only async mode is supported",
33
+ const result = await runApi<boolean>({
34
+ automationFunction: {
35
+ name: "auth-sessions/check",
36
+ },
37
+ runOptions: {
38
+ environment: "deployed",
39
+ headless: isHeadless(),
40
+ proxy,
41
+ },
42
+ auth: {
43
+ session: {
44
+ type: "state",
45
+ state: session,
42
46
  },
47
+ runCheck: false,
48
+ },
49
+ });
50
+ if (result.isErr()) {
51
+ return {
52
+ status: 500,
53
+ body: result.error,
43
54
  };
44
55
  }
45
-
46
- const downloadsPath = getDownloadDirectoryPath();
47
- const headless = isHeadless();
48
- const { page, context } = await getProductionPlaywrightConstructs({
49
- headless,
50
- proxy,
51
- downloadsPath,
52
- storageState: session,
53
- });
54
-
55
- const authSessionCheckResult = await checkAuthSessionWithRetries(
56
- page,
57
- context,
58
- 2
59
- );
60
-
61
- await fs.remove(downloadsPath);
62
56
  return {
63
57
  status: 200,
64
58
  body: {
65
- result: authSessionCheckResult,
59
+ result: result.value.result,
66
60
  },
67
61
  };
68
62
  }
@@ -1,15 +1,12 @@
1
1
  import { authSessionsContextsStore } from "./store";
2
- import { AUTH_SESSIONS_FOLDER_NAME } from "@intuned/runtime/dist/common/constants";
3
- import { getDownloadDirectoryPath } from "@intuned/runtime";
4
- import { getProductionPlaywrightConstructs } from "../../../src/common/getPlaywrightConstructs";
5
- import { callFunction, getTraceFilePath, isHeadless } from "../../utils";
2
+ import { getTraceFilePath, isHeadless } from "../../utils";
6
3
  import * as fs from "fs-extra";
7
- import { getContextStorageState } from "@intuned/runtime/dist/common/contextStorageStateHelpers";
4
+ import { runApiGenerator } from "@intuned/runtime/dist/common/runApi";
5
+ import type { RequestMoreInfoDetails } from "@intuned/runtime/dist/runtime";
8
6
 
9
7
  export async function createAuthSession({
10
8
  parameters,
11
9
  operationId,
12
- mode,
13
10
  proxy,
14
11
  saveTrace,
15
12
  }: {
@@ -36,16 +33,6 @@ export async function createAuthSession({
36
33
  };
37
34
  }
38
35
 
39
- if (mode !== "async") {
40
- return {
41
- status: 400,
42
- body: {
43
- error: "Invalid Request",
44
- message: "only async mode is supported",
45
- },
46
- };
47
- }
48
-
49
36
  if (authSessionsContextsStore.has(operationId)) {
50
37
  return {
51
38
  status: 400,
@@ -56,73 +43,61 @@ export async function createAuthSession({
56
43
  },
57
44
  };
58
45
  }
59
- const downloadsPath = getDownloadDirectoryPath();
60
46
  const headless = isHeadless();
61
- const { page, context } = await getProductionPlaywrightConstructs({
62
- headless,
63
- proxy,
64
- downloadsPath,
65
- });
66
-
67
- try {
68
- if (saveTrace) {
69
- try {
70
- await context.tracing.start({ screenshots: true, snapshots: true });
71
- } catch (error) {
72
- console.error("Error starting trace", error);
73
- }
74
- }
75
47
 
76
- const operationGenerator = await callFunction(
77
- AUTH_SESSIONS_FOLDER_NAME,
78
- "create",
79
- [parameters ?? {}, page, context]
80
- );
48
+ const abortController = new AbortController();
81
49
 
82
- await fs.remove(downloadsPath);
50
+ const createGenerator = runApiGenerator<
51
+ void,
52
+ RequestMoreInfoDetails,
53
+ unknown
54
+ >({
55
+ automationFunction: {
56
+ name: "auth-sessions/create",
57
+ params: parameters ?? {},
58
+ },
59
+ tracing: saveTrace
60
+ ? {
61
+ enabled: true,
62
+ filePath: getTraceFilePath(operationId),
63
+ }
64
+ : { enabled: false },
65
+ runOptions: {
66
+ environment: "deployed",
67
+ headless,
68
+ proxy,
69
+ },
70
+ abortSignal: abortController.signal,
71
+ retrieveSession: true,
72
+ });
83
73
 
84
- const result = await operationGenerator.next();
74
+ const result = await createGenerator.next();
85
75
 
86
- if (result.done) {
87
- if (saveTrace) {
88
- try {
89
- const traceFilePath = getTraceFilePath(operationId);
90
- await context.tracing.stop({ path: traceFilePath });
91
- } catch (error) {
92
- console.error("Error stopping trace", error);
93
- }
94
- }
95
- const fullSessionState = await getContextStorageState(context);
96
- await context.close();
76
+ if (result.done) {
77
+ const r = result.value;
97
78
 
79
+ if (r.isErr()) {
98
80
  return {
99
- status: 200,
100
- body: { ...fullSessionState, status: 200 },
81
+ status: 500,
82
+ body: r.error,
101
83
  };
102
84
  }
103
85
 
104
- authSessionsContextsStore.set(operationId, {
105
- done: false,
106
- generator: operationGenerator,
107
- context,
108
- requestInfo: result.value,
109
- saveTrace,
110
- });
111
-
112
86
  return {
113
87
  status: 200,
114
- body: result.value,
88
+ body: { ...r.value.session, status: 200 },
115
89
  };
116
- } catch (e) {
117
- if (saveTrace) {
118
- try {
119
- const traceFilePath = getTraceFilePath(operationId);
120
- await context.tracing.stop({ path: traceFilePath });
121
- } catch (error) {
122
- console.error("Error stopping trace", error);
123
- }
124
- }
125
-
126
- throw e;
127
90
  }
91
+
92
+ authSessionsContextsStore.set(operationId, {
93
+ done: false,
94
+ generator: createGenerator,
95
+ requestInfo: result.value,
96
+ abortController,
97
+ });
98
+
99
+ return {
100
+ status: 200,
101
+ body: result.value,
102
+ };
128
103
  }
@@ -10,7 +10,7 @@ export const {
10
10
  } = makeEndpointControllers({
11
11
  requestId: (req) => `createAuthSession ${req.body.operationId}`,
12
12
  handler: createAuthSession,
13
- parameters: (req) => [req.body],
13
+ parameters: (req): [any] => [req.body],
14
14
  });
15
15
 
16
16
  export const {
@@ -19,7 +19,7 @@ export const {
19
19
  } = makeEndpointControllers({
20
20
  requestId: "checkAuthSession",
21
21
  handler: checkAuthSession,
22
- parameters: (req) => [req.body],
22
+ parameters: (req): [any] => [req.body],
23
23
  });
24
24
 
25
25
  export const {
@@ -28,7 +28,7 @@ export const {
28
28
  } = makeEndpointControllers({
29
29
  requestId: (req) => `killAuthSessionOperation ${req.body.operationId}`,
30
30
  handler: killAuthSessionOperation,
31
- parameters: (req) => [req.body],
31
+ parameters: (req): [any] => [req.body],
32
32
  });
33
33
 
34
34
  export const {
@@ -37,5 +37,5 @@ export const {
37
37
  } = makeEndpointControllers({
38
38
  requestId: (req) => `resumeAuthSessionOperation ${req.body.operationId}`,
39
39
  handler: resumeAuthSessionOperation,
40
- parameters: (req) => [req.body],
40
+ parameters: (req): [any] => [req.body],
41
41
  });
@@ -19,7 +19,7 @@ export async function killAuthSessionOperation({
19
19
  }
20
20
 
21
21
  try {
22
- await operation.context.browser()?.close();
22
+ operation.abortController.abort();
23
23
  authSessionsContextsStore.delete(operationId);
24
24
 
25
25
  return { status: 200, body: { done: true } };
@@ -1,6 +1,4 @@
1
1
  import { authSessionsContextsStore } from "./store";
2
- import { getContextStorageState } from "@intuned/runtime/dist/common/contextStorageStateHelpers";
3
- import { getTraceFilePath } from "../../utils";
4
2
 
5
3
  export async function resumeAuthSessionOperation({
6
4
  operationId,
@@ -20,61 +18,39 @@ export async function resumeAuthSessionOperation({
20
18
  };
21
19
  }
22
20
 
23
- try {
24
- if (
25
- operation.requestInfo.requestType === "multiple_choice" &&
26
- !operation.requestInfo.choices.includes(input)
27
- ) {
28
- return {
29
- status: 400,
30
- body: {
31
- error: "Invalid Request",
32
- message: "input does not match any of the choices",
33
- },
34
- };
35
- }
36
-
37
- const result = await operation.generator.next(input);
21
+ if (
22
+ operation.requestInfo.requestType === "multiple_choice" &&
23
+ !operation.requestInfo.choices.includes(input)
24
+ ) {
25
+ return {
26
+ status: 400,
27
+ body: {
28
+ error: "Invalid Request",
29
+ message: "input does not match any of the choices",
30
+ },
31
+ };
32
+ }
38
33
 
39
- authSessionsContextsStore.set(operationId, {
40
- done: result.done,
41
- generator: operation.generator,
42
- context: operation.context,
43
- requestInfo: result.value,
44
- saveTrace: operation.saveTrace,
45
- });
34
+ const result = await operation.generator.next(input);
46
35
 
47
- if (result.done) {
48
- if (operation.saveTrace) {
49
- try {
50
- const traceFilePath = getTraceFilePath(operationId);
51
- await operation.context.tracing.stop({ path: traceFilePath });
52
- } catch (error) {
53
- console.error("Error stopping trace", error);
54
- }
55
- }
56
- const storageState = await getContextStorageState(operation.context);
57
- await operation.context.browser()?.close();
58
- authSessionsContextsStore.delete(operationId);
59
- return {
60
- status: 200,
61
- body: storageState,
62
- };
36
+ if (result.done) {
37
+ authSessionsContextsStore.delete(operationId);
38
+ if (result.value.isErr()) {
39
+ return result.value.error.apiResponse;
63
40
  }
64
-
65
41
  return {
66
42
  status: 200,
67
- body: result.value,
43
+ body: result.value.value.session,
68
44
  };
69
- } catch (e) {
70
- if (operation.saveTrace) {
71
- try {
72
- const traceFilePath = getTraceFilePath(operationId);
73
- await operation.context.tracing.stop({ path: traceFilePath });
74
- } catch (error) {
75
- console.error("Error stopping trace", error);
76
- }
77
- }
78
- throw e;
79
45
  }
46
+
47
+ authSessionsContextsStore.set(operationId, {
48
+ ...operation,
49
+ requestInfo: result.value,
50
+ });
51
+
52
+ return {
53
+ status: 200,
54
+ body: result.value,
55
+ };
80
56
  }
@@ -1,14 +1,19 @@
1
- //@ts-ignore
2
- import { RequestMoreInfoDetails } from "@intuned/sdk/dist/common/requestMoreInfo";
3
- import { BrowserContext } from "@intuned/playwright-core";
1
+ import type { RequestMoreInfoDetails } from "@intuned/runtime/dist/runtime";
2
+ import type {
3
+ RunApiResult,
4
+ RunApiResultWithSessionOk,
5
+ } from "@intuned/runtime/dist/common/runApi";
4
6
 
5
7
  export const authSessionsContextsStore = new Map<
6
8
  string,
7
9
  {
8
10
  done: boolean | undefined;
9
- generator: AsyncGenerator<any, void, unknown>;
10
- context: BrowserContext;
11
+ generator: AsyncGenerator<
12
+ RequestMoreInfoDetails,
13
+ RunApiResult<void, RunApiResultWithSessionOk>,
14
+ string
15
+ >;
11
16
  requestInfo: RequestMoreInfoDetails;
12
- saveTrace: boolean;
17
+ abortController: AbortController;
13
18
  }
14
19
  >();