@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.
- package/InterfaceTemplate/index.ts +1 -0
- package/Intuned.json +5 -0
- package/WebTemplate/api.ts +92 -90
- package/WebTemplate/controllers/authSessions/check.ts +23 -29
- package/WebTemplate/controllers/authSessions/create.ts +46 -71
- package/WebTemplate/controllers/authSessions/index.ts +4 -4
- package/WebTemplate/controllers/authSessions/killOperation.ts +1 -1
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +28 -52
- package/WebTemplate/controllers/authSessions/store.ts +11 -6
- package/WebTemplate/controllers/runApi/helpers.ts +47 -146
- package/WebTemplate/index.playwright.ts +42 -32
- package/WebTemplate/index.vanilla.ts +2 -20
- package/WebTemplate/jobs.ts +2 -13
- package/WebTemplate/utils.ts +1 -85
- package/WebTemplate.zip +0 -0
- package/api/authed.ts +12 -0
- package/api/test.ts +3 -0
- package/api/test2.ts +25 -0
- package/auth-sessions/check.ts +9 -0
- package/auth-sessions/create.ts +32 -0
- package/authSessions +1 -0
- package/bin/intuned-api-run +2 -0
- package/bin/intuned-auth-session-check +2 -0
- package/bin/intuned-auth-session-create +2 -0
- package/bin/intuned-auth-session-load +2 -0
- package/bin/intuned-auth-session-refresh +2 -0
- package/bin/intuned-browser-save-state +2 -0
- package/bin/intuned-browser-start +2 -0
- package/bin/intuned-build +2 -0
- package/bin/intuned-ts-check +2 -0
- package/dist/commands/api/run.d.ts +6 -0
- package/dist/commands/api/run.js +113 -0
- package/dist/commands/auth-sessions/load.d.ts +2 -0
- package/dist/commands/auth-sessions/load.js +32 -0
- package/dist/commands/auth-sessions/run-check.d.ts +2 -0
- package/dist/commands/auth-sessions/run-check.js +56 -0
- package/dist/commands/auth-sessions/run-create.d.ts +2 -0
- package/dist/commands/auth-sessions/run-create.js +96 -0
- package/dist/commands/browser/save-state.d.ts +2 -0
- package/dist/commands/browser/save-state.js +17 -0
- package/dist/commands/browser/start-browser.d.ts +2 -0
- package/dist/commands/browser/start-browser.js +14 -0
- package/dist/commands/build.d.ts +2 -0
- package/dist/commands/build.js +83 -0
- package/dist/commands/common/browserUtils.d.ts +14 -0
- package/dist/commands/common/browserUtils.js +58 -0
- package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
- package/dist/commands/common/getDefaultExportFromFile.js +19 -0
- package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
- package/dist/commands/common/getFirstLineNumber.js +103 -0
- package/{src/commands/common/getFirstLineNumber.test.ts → dist/commands/common/getFirstLineNumber.test.js} +75 -121
- package/dist/commands/common/sendMessageToClient.d.ts +1 -0
- package/dist/commands/common/sendMessageToClient.js +10 -0
- package/dist/commands/common/utils/fileUtils.d.ts +6 -0
- package/dist/commands/common/utils/fileUtils.js +33 -0
- package/dist/commands/common/utils/settings.d.ts +2 -0
- package/dist/commands/common/utils/settings.js +28 -0
- package/dist/commands/common/utils/unixSocket.d.ts +9 -0
- package/dist/commands/common/utils/unixSocket.js +45 -0
- package/dist/commands/common/utils/webTemplate.d.ts +1 -0
- package/dist/commands/common/utils/webTemplate.js +31 -0
- package/dist/commands/interface/run.d.ts +2 -0
- package/dist/commands/interface/run.js +161 -0
- package/dist/commands/ts-check.d.ts +2 -0
- package/dist/commands/ts-check.js +54 -0
- package/dist/common/Logger/Logger/index.d.ts +12 -0
- package/dist/common/Logger/Logger/index.js +60 -0
- package/{src/common/Logger/Logger/types.ts → dist/common/Logger/Logger/types.d.ts} +4 -5
- package/dist/common/Logger/Logger/types.js +5 -0
- package/dist/common/Logger/index.d.ts +12 -0
- package/dist/common/Logger/index.js +60 -0
- package/{src/common/Logger/types.ts → dist/common/Logger/types.d.ts} +4 -5
- package/dist/common/Logger/types.js +5 -0
- package/dist/common/asyncLocalStorage/index.d.ts +16 -0
- package/dist/common/asyncLocalStorage/index.js +17 -0
- package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
- package/dist/common/cleanEnvironmentVariables.js +16 -0
- package/dist/common/constants.d.ts +1 -0
- package/dist/common/constants.js +7 -0
- package/dist/common/contextStorageStateHelpers.d.ts +14 -0
- package/dist/common/contextStorageStateHelpers.js +50 -0
- package/dist/common/getPlaywrightConstructs.d.ts +30 -0
- package/dist/common/getPlaywrightConstructs.js +192 -0
- package/dist/common/jwtTokenManager.d.ts +16 -0
- package/dist/common/jwtTokenManager.js +81 -0
- package/dist/common/runApi/errors.d.ts +71 -0
- package/dist/common/runApi/errors.js +172 -0
- package/dist/common/runApi/index.d.ts +12 -0
- package/dist/common/runApi/index.js +288 -0
- package/dist/common/runApi/types.d.ts +486 -0
- package/dist/common/runApi/types.js +50 -0
- package/dist/common/settingsSchema.d.ts +19 -0
- package/dist/common/settingsSchema.js +17 -0
- package/dist/common/telemetry.d.ts +3 -0
- package/dist/common/telemetry.js +32 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +69 -0
- package/dist/runtime/RunError.d.ts +5 -0
- package/dist/runtime/RunError.js +19 -0
- package/dist/runtime/downloadDirectory.d.ts +1 -0
- package/dist/runtime/downloadDirectory.js +19 -0
- package/dist/runtime/enums.d.js +5 -0
- package/dist/runtime/enums.js +18 -0
- package/dist/runtime/executionHelpers.test.js +53 -0
- package/dist/runtime/export.d.js +5 -0
- package/dist/runtime/extendPayload.d.ts +2 -0
- package/dist/runtime/extendPayload.js +21 -0
- package/dist/runtime/extendTimeout.d.ts +1 -0
- package/dist/runtime/extendTimeout.js +30 -0
- package/{src/runtime/index.ts → dist/runtime/index.d.ts} +2 -3
- package/dist/runtime/index.js +53 -0
- package/dist/runtime/requestMoreInfo.d.ts +18 -0
- package/dist/runtime/requestMoreInfo.js +25 -0
- package/dist/runtime/runInfo.d.ts +2 -0
- package/dist/runtime/runInfo.js +21 -0
- package/output.txt +39 -0
- package/package.json +9 -7
- package/testing +0 -0
- package/tsconfig.json +2 -1
- package/.vite/deps_temp_01af7156/package.json +0 -3
- package/.vscode/extensions.json +0 -3
- package/.vscode/launch.json +0 -102
- package/.vscode/settings.json +0 -12
- package/playwright.config.ts +0 -48
- package/src/commands/api/run.ts +0 -225
- package/src/commands/auth-sessions/load.ts +0 -42
- package/src/commands/auth-sessions/run-check.ts +0 -70
- package/src/commands/auth-sessions/run-create.ts +0 -124
- package/src/commands/browser/save-state.ts +0 -22
- package/src/commands/browser/start-browser.ts +0 -17
- package/src/commands/build.ts +0 -125
- package/src/commands/common/browserUtils.ts +0 -80
- package/src/commands/common/getDefaultExportFromFile.ts +0 -13
- package/src/commands/common/getFirstLineNumber.ts +0 -146
- package/src/commands/common/sendMessageToClient.ts +0 -8
- package/src/commands/common/utils/fileUtils.ts +0 -25
- package/src/commands/common/utils/settings.ts +0 -23
- package/src/commands/common/utils/webTemplate.ts +0 -46
- package/src/commands/testing/saveVisibleHtml.ts +0 -29
- package/src/commands/ts-check.ts +0 -88
- package/src/common/Logger/Logger/index.ts +0 -64
- package/src/common/Logger/index.ts +0 -64
- package/src/common/asyncLocalStorage/index.ts +0 -29
- package/src/common/cleanEnvironmentVariables.ts +0 -13
- package/src/common/constants.ts +0 -1
- package/src/common/contextStorageStateHelpers.ts +0 -71
- package/src/common/getPlaywrightConstructs.ts +0 -283
- package/src/common/jwtTokenManager.ts +0 -111
- package/src/common/settingsSchema.ts +0 -16
- package/src/common/telemetry.ts +0 -49
- package/src/index.ts +0 -14
- package/src/runtime/RunError.ts +0 -16
- package/src/runtime/downloadDirectory.ts +0 -14
- package/src/runtime/enums.ts +0 -11
- package/src/runtime/executionHelpers.test.ts +0 -70
- package/src/runtime/extendPayload.ts +0 -22
- package/src/runtime/extendTimeout.ts +0 -32
- package/src/runtime/requestMoreInfo.ts +0 -40
- package/src/runtime/runInfo.ts +0 -19
- package/vite.config.ts +0 -17
- /package/{src → dist}/common/assets/browser_scripts.js +0 -0
- /package/{src → dist}/runtime/enums.d.ts +0 -0
- /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
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,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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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:
|
|
59
|
+
result: result.value.result,
|
|
66
60
|
},
|
|
67
61
|
};
|
|
68
62
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { authSessionsContextsStore } from "./store";
|
|
2
|
-
import {
|
|
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 {
|
|
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
|
-
|
|
77
|
-
AUTH_SESSIONS_FOLDER_NAME,
|
|
78
|
-
"create",
|
|
79
|
-
[parameters ?? {}, page, context]
|
|
80
|
-
);
|
|
48
|
+
const abortController = new AbortController();
|
|
81
49
|
|
|
82
|
-
|
|
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
|
-
|
|
74
|
+
const result = await createGenerator.next();
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
|
|
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:
|
|
100
|
-
body:
|
|
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:
|
|
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
|
});
|
|
@@ -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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
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<
|
|
10
|
-
|
|
11
|
+
generator: AsyncGenerator<
|
|
12
|
+
RequestMoreInfoDetails,
|
|
13
|
+
RunApiResult<void, RunApiResultWithSessionOk>,
|
|
14
|
+
string
|
|
15
|
+
>;
|
|
11
16
|
requestInfo: RequestMoreInfoDetails;
|
|
12
|
-
|
|
17
|
+
abortController: AbortController;
|
|
13
18
|
}
|
|
14
19
|
>();
|