@intuned/runtime-dev 0.1.0-test.28 → 0.1.0-test.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Intuned.json +1 -1
- package/WebTemplate/api.ts +92 -90
- package/WebTemplate/controllers/authSessions/check.ts +4 -3
- package/WebTemplate/controllers/authSessions/create.ts +8 -10
- package/WebTemplate/controllers/authSessions/resumeOperation.ts +1 -1
- package/WebTemplate/controllers/runApi/helpers.ts +6 -11
- package/WebTemplate/index.playwright.ts +42 -32
- package/WebTemplate/jobs.ts +2 -13
- package/WebTemplate/utils.ts +1 -51
- package/api/test2.ts +5 -7
- package/auth-sessions/check.ts +1 -3
- package/auth-sessions/create.ts +10 -10
- package/bin/intuned-api-run +1 -1
- package/bin/intuned-auth-session-check +1 -1
- package/bin/intuned-auth-session-create +1 -1
- package/bin/intuned-auth-session-load +1 -1
- package/bin/intuned-auth-session-refresh +1 -1
- package/bin/intuned-browser-save-state +1 -1
- package/bin/intuned-browser-start +1 -1
- package/bin/intuned-build +1 -1
- package/bin/intuned-ts-check +1 -1
- package/dist/commands/api/run.js +2 -4
- package/dist/commands/auth-sessions/run-check.js +1 -3
- package/dist/commands/auth-sessions/run-create.js +3 -5
- package/dist/commands/build.js +4 -6
- package/dist/commands/common/browserUtils.js +1 -1
- package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
- package/dist/commands/common/{tsNodeImport.js → getDefaultExportFromFile.js} +5 -6
- package/dist/commands/common/getFirstLineNumber.test.js +2 -2
- package/dist/commands/common/utils/settings.js +2 -1
- package/dist/commands/common/utils/webTemplate.js +2 -2
- package/dist/commands/interface/run.js +106 -122
- package/dist/commands/ts-check.js +2 -2
- package/dist/common/Logger/Logger/index.d.ts +1 -1
- package/dist/common/Logger/index.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.d.ts +1 -1
- package/dist/common/getPlaywrightConstructs.js +3 -3
- package/dist/common/runApi/errors.d.ts +1 -1
- package/dist/common/runApi/index.d.ts +5 -5
- package/dist/common/runApi/index.js +50 -21
- package/dist/common/runApi/types.d.ts +1 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/runtime/RunError.d.ts +1 -1
- package/dist/runtime/executionHelpers.test.js +2 -2
- package/dist/runtime/export.d.ts +1 -1
- package/dist/runtime/extendPayload.d.ts +1 -1
- package/dist/runtime/extendPayload.js +1 -1
- package/dist/runtime/index.d.ts +7 -7
- package/dist/runtime/index.js +6 -6
- package/dist/runtime/runInfo.d.ts +1 -1
- package/dist/runtime/runInfo.js +1 -1
- package/package.json +5 -6
- package/tsconfig.json +1 -1
- package/InterfaceTemplate/index.js +0 -1
- package/WebTemplate/accessKeyHelpers.js +0 -20
- package/WebTemplate/api.js +0 -48
- package/WebTemplate/app.js +0 -13
- package/WebTemplate/controllers/async.js +0 -78
- package/WebTemplate/controllers/authSessions/check.js +0 -44
- package/WebTemplate/controllers/authSessions/create.js +0 -69
- package/WebTemplate/controllers/authSessions/index.js +0 -25
- package/WebTemplate/controllers/authSessions/killOperation.js +0 -26
- package/WebTemplate/controllers/authSessions/resumeOperation.js +0 -42
- package/WebTemplate/controllers/authSessions/store.js +0 -1
- package/WebTemplate/controllers/controllers.js +0 -30
- package/WebTemplate/controllers/runApi/helpers.js +0 -90
- package/WebTemplate/controllers/runApi/index.js +0 -45
- package/WebTemplate/controllers/runApi/types.js +0 -1
- package/WebTemplate/controllers/traces.js +0 -108
- package/WebTemplate/features.js +0 -6
- package/WebTemplate/headers.js +0 -6
- package/WebTemplate/index.playwright.js +0 -37
- package/WebTemplate/index.vanilla.js +0 -19
- package/WebTemplate/jobs.js +0 -259
- package/WebTemplate/shutdown.js +0 -51
- package/WebTemplate/utils.js +0 -189
- package/api/authed.js +0 -6
- package/api/test.js +0 -3
- package/api/test2.js +0 -17
- package/auth-sessions/check.js +0 -6
- package/auth-sessions/create.js +0 -20
- package/dist/commands/common/tsNodeImport.d.ts +0 -1
- package/playwright.config.js +0 -43
- package/preserve-dynamic-imports.js +0 -16
- package/vite.config.js +0 -16
|
@@ -18,7 +18,7 @@ var fs = _fsExtra;
|
|
|
18
18
|
var _jwtTokenManager = require("../jwtTokenManager");
|
|
19
19
|
var _contextStorageStateHelpers = require("../contextStorageStateHelpers");
|
|
20
20
|
var _neverthrow = require("neverthrow");
|
|
21
|
-
var _errors = require("./errors
|
|
21
|
+
var _errors = require("./errors");
|
|
22
22
|
Object.keys(_errors).forEach(function (key) {
|
|
23
23
|
if (key === "default" || key === "__esModule") return;
|
|
24
24
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -32,7 +32,7 @@ Object.keys(_errors).forEach(function (key) {
|
|
|
32
32
|
});
|
|
33
33
|
var _constants = require("../constants");
|
|
34
34
|
var _getPlaywrightConstructs = require("../getPlaywrightConstructs");
|
|
35
|
-
var _types = require("./types
|
|
35
|
+
var _types = require("./types");
|
|
36
36
|
Object.keys(_types).forEach(function (key) {
|
|
37
37
|
if (key === "default" || key === "__esModule") return;
|
|
38
38
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -49,7 +49,6 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
49
49
|
async function* runApiGenerator({
|
|
50
50
|
retrieveSession = false,
|
|
51
51
|
abortSignal,
|
|
52
|
-
importFunction,
|
|
53
52
|
...input
|
|
54
53
|
}) {
|
|
55
54
|
let traceStarted = false;
|
|
@@ -61,11 +60,10 @@ async function* runApiGenerator({
|
|
|
61
60
|
functionsToken
|
|
62
61
|
} = _types.runApiParametersSchema.parse(input);
|
|
63
62
|
_jwtTokenManager.backendFunctionsTokenManager.token = functionsToken;
|
|
63
|
+
const downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
|
|
64
64
|
let page;
|
|
65
65
|
let context;
|
|
66
|
-
let downloadsPath;
|
|
67
66
|
if (runOptions.environment === "deployed") {
|
|
68
|
-
downloadsPath = (0, _downloadDirectory.getDownloadDirectoryPath)();
|
|
69
67
|
const {
|
|
70
68
|
headless,
|
|
71
69
|
proxy
|
|
@@ -89,6 +87,10 @@ async function* runApiGenerator({
|
|
|
89
87
|
context
|
|
90
88
|
} = await (0, _getPlaywrightConstructs.getPlaywrightConstructsForMode)(mode, cdpAddress, auth === null || auth === void 0 ? void 0 : auth.session));
|
|
91
89
|
}
|
|
90
|
+
const executionContext = (0, _asyncLocalStorage.getExecutionContext)();
|
|
91
|
+
if (!executionContext) {
|
|
92
|
+
throw "";
|
|
93
|
+
}
|
|
92
94
|
async function saveTraceIfNeeded({
|
|
93
95
|
errorMessage
|
|
94
96
|
}) {
|
|
@@ -126,10 +128,12 @@ async function* runApiGenerator({
|
|
|
126
128
|
var _getExecutionContext;
|
|
127
129
|
if (auth !== null && auth !== void 0 && auth.runCheck) {
|
|
128
130
|
if (!auth.session) {
|
|
129
|
-
return (0, _neverthrow.err)(
|
|
131
|
+
return (0, _neverthrow.err)({
|
|
132
|
+
code: "AuthRequiredError"
|
|
133
|
+
});
|
|
130
134
|
}
|
|
131
135
|
console.log("Running auth check");
|
|
132
|
-
const authCheckResult = await checkAuthSessionWithRetries(page, context,
|
|
136
|
+
const authCheckResult = await checkAuthSessionWithRetries(page, context, 2);
|
|
133
137
|
if (authCheckResult.isErr()) {
|
|
134
138
|
const error = authCheckResult.error;
|
|
135
139
|
if (["APINotFoundError", "InvalidAPIError"].includes(error.code)) {
|
|
@@ -138,17 +142,20 @@ async function* runApiGenerator({
|
|
|
138
142
|
return authCheckResult;
|
|
139
143
|
}
|
|
140
144
|
if (!authCheckResult.value) {
|
|
141
|
-
return (0, _neverthrow.err)(
|
|
145
|
+
return (0, _neverthrow.err)({
|
|
146
|
+
code: "AuthCheckFailedError"
|
|
147
|
+
});
|
|
142
148
|
}
|
|
143
149
|
}
|
|
150
|
+
console.log("Running function", automationFunction.name);
|
|
144
151
|
const args = [...(automationFunction.params ? [automationFunction.params] : []), page, context];
|
|
145
|
-
const
|
|
146
|
-
if (
|
|
147
|
-
return
|
|
152
|
+
const importResult = await importFunction(automationFunction.name);
|
|
153
|
+
if (importResult.isErr()) {
|
|
154
|
+
return importResult;
|
|
148
155
|
}
|
|
149
156
|
let result;
|
|
150
|
-
if (
|
|
151
|
-
const generator =
|
|
157
|
+
if (importResult.value.type === "async-generator") {
|
|
158
|
+
const generator = importResult.value.generator(...args);
|
|
152
159
|
let next = undefined;
|
|
153
160
|
while (true) {
|
|
154
161
|
const generatorResult = await generator.next(...(next ? [next] : []));
|
|
@@ -160,7 +167,7 @@ async function* runApiGenerator({
|
|
|
160
167
|
break;
|
|
161
168
|
}
|
|
162
169
|
} else {
|
|
163
|
-
result = await
|
|
170
|
+
result = await importResult.value.func(...args);
|
|
164
171
|
}
|
|
165
172
|
return (0, _neverthrow.ok)({
|
|
166
173
|
result,
|
|
@@ -190,9 +197,7 @@ async function* runApiGenerator({
|
|
|
190
197
|
errorMessage: "failed to save trace"
|
|
191
198
|
});
|
|
192
199
|
await context.close();
|
|
193
|
-
|
|
194
|
-
await fs.remove(downloadsPath);
|
|
195
|
-
}
|
|
200
|
+
await fs.remove(downloadsPath);
|
|
196
201
|
}
|
|
197
202
|
}
|
|
198
203
|
async function runApi(params) {
|
|
@@ -206,13 +211,13 @@ async function runApi(params) {
|
|
|
206
211
|
}
|
|
207
212
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("Expected API to be async function, got async generator"));
|
|
208
213
|
}
|
|
209
|
-
async function checkAuthSessionWithRetries(page, context,
|
|
214
|
+
async function checkAuthSessionWithRetries(page, context, retries = 3) {
|
|
210
215
|
if (retries === 0) {
|
|
211
216
|
return (0, _neverthrow.ok)(false);
|
|
212
217
|
}
|
|
213
218
|
let tryNumber = 0;
|
|
214
219
|
console.log("Checking auth session with retries", `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
215
|
-
const importResult = await
|
|
220
|
+
const importResult = await importFunction(`${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`);
|
|
216
221
|
if (importResult.isErr()) {
|
|
217
222
|
return (0, _neverthrow.err)(importResult.error);
|
|
218
223
|
}
|
|
@@ -227,9 +232,33 @@ async function checkAuthSessionWithRetries(page, context, importFunction, retrie
|
|
|
227
232
|
}
|
|
228
233
|
return (0, _neverthrow.ok)(false);
|
|
229
234
|
}
|
|
230
|
-
async function
|
|
235
|
+
async function importFunction(path) {
|
|
236
|
+
const functionNameParts = path.split("/");
|
|
237
|
+
const functionNameDepth = functionNameParts.length;
|
|
231
238
|
try {
|
|
232
|
-
|
|
239
|
+
let imported = undefined;
|
|
240
|
+
switch (functionNameDepth) {
|
|
241
|
+
case 1:
|
|
242
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}.ts`);
|
|
243
|
+
break;
|
|
244
|
+
case 2:
|
|
245
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}.ts`);
|
|
246
|
+
break;
|
|
247
|
+
case 3:
|
|
248
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`);
|
|
249
|
+
break;
|
|
250
|
+
case 4:
|
|
251
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`);
|
|
252
|
+
break;
|
|
253
|
+
case 5:
|
|
254
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`);
|
|
255
|
+
break;
|
|
256
|
+
case 6:
|
|
257
|
+
imported = await (specifier => new Promise(r => r(specifier)).then(s => _interopRequireWildcard(require(s))))(`${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}/${functionNameParts[5]}.ts`);
|
|
258
|
+
break;
|
|
259
|
+
default:
|
|
260
|
+
return (0, _neverthrow.err)(new _errors.MaxLevelsExceededError(5));
|
|
261
|
+
}
|
|
233
262
|
if (!imported || !imported.default || !imported.default.constructor) {
|
|
234
263
|
return (0, _neverthrow.err)(new _errors.InvalidApiError("API file path does not have a default export"));
|
|
235
264
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IntunedStorageState } from "../contextStorageStateHelpers";
|
|
2
2
|
import type { Payload } from "../../runtime/export";
|
|
3
3
|
import type { Result } from "neverthrow";
|
|
4
|
-
import type { RunAutomationError } from "./errors
|
|
4
|
+
import type { RunAutomationError } from "./errors";
|
|
5
5
|
import z from "zod";
|
|
6
6
|
export interface PayloadToAppend {
|
|
7
7
|
apiName: string;
|
|
@@ -475,7 +475,6 @@ export type RunApiSession = z.infer<typeof runApiSessionSchema>;
|
|
|
475
475
|
export type RunApiParameters = z.input<typeof runApiParametersSchema>;
|
|
476
476
|
export type ExtendedRunApiParameters = RunApiParameters & {
|
|
477
477
|
abortSignal?: AbortSignal;
|
|
478
|
-
importFunction?: (name: string) => Promise<any> | undefined;
|
|
479
478
|
};
|
|
480
479
|
export type RunApiResultOk<R = any> = {
|
|
481
480
|
result: R;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP, } from "./runtime
|
|
2
|
-
export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage
|
|
3
|
-
export { getDownloadDirectoryPath } from "./runtime/downloadDirectory
|
|
4
|
-
export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs
|
|
1
|
+
export { extendPayload, extendTimeout, runInfo, RunError, requestMultipleChoice, requestOTP, } from "./runtime";
|
|
2
|
+
export { runWithContext, getExecutionContext, } from "./common/asyncLocalStorage";
|
|
3
|
+
export { getDownloadDirectoryPath } from "./runtime/downloadDirectory";
|
|
4
|
+
export { getProductionPlaywrightConstructs } from "./common/getPlaywrightConstructs";
|
package/dist/index.js
CHANGED
|
@@ -6,19 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
Object.defineProperty(exports, "RunError", {
|
|
7
7
|
enumerable: true,
|
|
8
8
|
get: function () {
|
|
9
|
-
return
|
|
9
|
+
return _runtime.RunError;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "extendPayload", {
|
|
13
13
|
enumerable: true,
|
|
14
14
|
get: function () {
|
|
15
|
-
return
|
|
15
|
+
return _runtime.extendPayload;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "extendTimeout", {
|
|
19
19
|
enumerable: true,
|
|
20
20
|
get: function () {
|
|
21
|
-
return
|
|
21
|
+
return _runtime.extendTimeout;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "getDownloadDirectoryPath", {
|
|
@@ -30,7 +30,7 @@ Object.defineProperty(exports, "getDownloadDirectoryPath", {
|
|
|
30
30
|
Object.defineProperty(exports, "getExecutionContext", {
|
|
31
31
|
enumerable: true,
|
|
32
32
|
get: function () {
|
|
33
|
-
return
|
|
33
|
+
return _asyncLocalStorage.getExecutionContext;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "getProductionPlaywrightConstructs", {
|
|
@@ -42,28 +42,28 @@ Object.defineProperty(exports, "getProductionPlaywrightConstructs", {
|
|
|
42
42
|
Object.defineProperty(exports, "requestMultipleChoice", {
|
|
43
43
|
enumerable: true,
|
|
44
44
|
get: function () {
|
|
45
|
-
return
|
|
45
|
+
return _runtime.requestMultipleChoice;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
Object.defineProperty(exports, "requestOTP", {
|
|
49
49
|
enumerable: true,
|
|
50
50
|
get: function () {
|
|
51
|
-
return
|
|
51
|
+
return _runtime.requestOTP;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
54
|
Object.defineProperty(exports, "runInfo", {
|
|
55
55
|
enumerable: true,
|
|
56
56
|
get: function () {
|
|
57
|
-
return
|
|
57
|
+
return _runtime.runInfo;
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
Object.defineProperty(exports, "runWithContext", {
|
|
61
61
|
enumerable: true,
|
|
62
62
|
get: function () {
|
|
63
|
-
return
|
|
63
|
+
return _asyncLocalStorage.runWithContext;
|
|
64
64
|
}
|
|
65
65
|
});
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var _downloadDirectory = require("./runtime/downloadDirectory
|
|
69
|
-
var _getPlaywrightConstructs = require("./common/getPlaywrightConstructs
|
|
66
|
+
var _runtime = require("./runtime");
|
|
67
|
+
var _asyncLocalStorage = require("./common/asyncLocalStorage");
|
|
68
|
+
var _downloadDirectory = require("./runtime/downloadDirectory");
|
|
69
|
+
var _getPlaywrightConstructs = require("./common/getPlaywrightConstructs");
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var _vitest = require("vitest");
|
|
4
4
|
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
5
|
-
var _index = require("./index
|
|
6
|
-
var _enums = require("./enums
|
|
5
|
+
var _index = require("./index");
|
|
6
|
+
var _enums = require("./enums");
|
|
7
7
|
(0, _vitest.describe)("Execution Helpers", () => {
|
|
8
8
|
(0, _vitest.it)("should be able to get execution info", () => {
|
|
9
9
|
(0, _asyncLocalStorage.runWithContext)({
|
package/dist/runtime/export.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Payload } from "./export
|
|
1
|
+
import { Payload } from "./export";
|
|
2
2
|
export declare function extendPayload(payload: Payload | Payload[]): void;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.extendPayload = extendPayload;
|
|
7
7
|
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
8
|
-
var _extendTimeout = require("./extendTimeout
|
|
8
|
+
var _extendTimeout = require("./extendTimeout");
|
|
9
9
|
function extendPayload(payload) {
|
|
10
10
|
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
11
11
|
if (!context) {
|
package/dist/runtime/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { extendPayload } from "./extendPayload
|
|
2
|
-
export { extendTimeout } from "./extendTimeout
|
|
3
|
-
export { runInfo } from "./runInfo
|
|
4
|
-
export { RunError } from "./RunError
|
|
5
|
-
export { requestMultipleChoice, requestOTP } from "./requestMoreInfo
|
|
6
|
-
export type { RequestMoreInfoDetails } from "./requestMoreInfo
|
|
7
|
-
export { getDownloadDirectoryPath } from "./downloadDirectory
|
|
1
|
+
export { extendPayload } from "./extendPayload";
|
|
2
|
+
export { extendTimeout } from "./extendTimeout";
|
|
3
|
+
export { runInfo } from "./runInfo";
|
|
4
|
+
export { RunError } from "./RunError";
|
|
5
|
+
export { requestMultipleChoice, requestOTP } from "./requestMoreInfo";
|
|
6
|
+
export type { RequestMoreInfoDetails } from "./requestMoreInfo";
|
|
7
|
+
export { getDownloadDirectoryPath } from "./downloadDirectory";
|
package/dist/runtime/index.js
CHANGED
|
@@ -45,9 +45,9 @@ Object.defineProperty(exports, "runInfo", {
|
|
|
45
45
|
return _runInfo.runInfo;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
-
var _extendPayload = require("./extendPayload
|
|
49
|
-
var _extendTimeout = require("./extendTimeout
|
|
50
|
-
var _runInfo = require("./runInfo
|
|
51
|
-
var _RunError = require("./RunError
|
|
52
|
-
var _requestMoreInfo = require("./requestMoreInfo
|
|
53
|
-
var _downloadDirectory = require("./downloadDirectory
|
|
48
|
+
var _extendPayload = require("./extendPayload");
|
|
49
|
+
var _extendTimeout = require("./extendTimeout");
|
|
50
|
+
var _runInfo = require("./runInfo");
|
|
51
|
+
var _RunError = require("./RunError");
|
|
52
|
+
var _requestMoreInfo = require("./requestMoreInfo");
|
|
53
|
+
var _downloadDirectory = require("./downloadDirectory");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RunInfo } from "./export
|
|
1
|
+
import { RunInfo } from "./export";
|
|
2
2
|
export declare function runInfo(): RunInfo;
|
package/dist/runtime/runInfo.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.runInfo = runInfo;
|
|
7
7
|
var _asyncLocalStorage = require("../common/asyncLocalStorage");
|
|
8
|
-
var _enums = require("./enums
|
|
8
|
+
var _enums = require("./enums");
|
|
9
9
|
function runInfo() {
|
|
10
10
|
const context = (0, _asyncLocalStorage.getExecutionContext)();
|
|
11
11
|
if (!context) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intuned/runtime-dev",
|
|
3
|
-
"version": "0.1.0-test.
|
|
3
|
+
"version": "0.1.0-test.3",
|
|
4
4
|
"description": "Intuned runtime",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./dist/index.js",
|
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
"./dist/common/jwtTokenManager": "./dist/common/jwtTokenManager.js",
|
|
13
13
|
"./dist/common/asyncLocalStorage": "./dist/common/asyncLocalStorage/index.js",
|
|
14
14
|
"./dist/common/cleanEnvironmentVariables": "./dist/common/cleanEnvironmentVariables.js",
|
|
15
|
-
"./dist/common/constants": "./dist/common/constants.js"
|
|
15
|
+
"./dist/common/constants": "./dist/common/constants.js",
|
|
16
|
+
"./dist/commands/interface/run": "./dist/commands/interface/run.js"
|
|
16
17
|
},
|
|
17
18
|
"types": "./dist/index.d.ts",
|
|
18
19
|
"author": "Intuned Team",
|
|
@@ -50,7 +51,6 @@
|
|
|
50
51
|
"intuned-ts-check": "./bin/intuned-ts-check"
|
|
51
52
|
},
|
|
52
53
|
"dependencies": {
|
|
53
|
-
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
54
54
|
"@intuned/playwright": "^1.44.1-4",
|
|
55
55
|
"@intuned/playwright-core": "^1.44.1-4",
|
|
56
56
|
"@rollup/plugin-commonjs": "^25.0.2",
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
"@types/node": "^20.4.1",
|
|
66
66
|
"applicationinsights": "^2.9.2",
|
|
67
67
|
"async-retry": "^1.3.3",
|
|
68
|
-
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
69
68
|
"chalk": "^4.1.2",
|
|
70
69
|
"commander": "^11.0.0",
|
|
71
70
|
"cross-fetch": "^4.0.0",
|
|
@@ -90,12 +89,12 @@
|
|
|
90
89
|
"source-map": "^0.7.4",
|
|
91
90
|
"stack-utils": "^2.0.6",
|
|
92
91
|
"ts-morph": "^21.0.1",
|
|
92
|
+
"ts-node": "^10.9.1",
|
|
93
93
|
"tslib": "^2.6.0",
|
|
94
94
|
"typescript": "^5.1.6",
|
|
95
95
|
"wait-on": "^7.2.0",
|
|
96
96
|
"zod": "^3.21.4",
|
|
97
|
-
"zod-validation-error": "^3.0.3"
|
|
98
|
-
"ts-node": "^10.9.1"
|
|
97
|
+
"zod-validation-error": "^3.0.3"
|
|
99
98
|
},
|
|
100
99
|
"devDependencies": {
|
|
101
100
|
"@babel/cli": "^7.23.4",
|
package/tsconfig.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { createHash } from "crypto";
|
|
2
|
-
function hashToken(token) {
|
|
3
|
-
// This has to match the logic from the workflow that saves adds the token to fly io App.
|
|
4
|
-
return createHash("sha256").update(token).digest("hex");
|
|
5
|
-
}
|
|
6
|
-
export const accessKeyValidatorMiddleware = (req, res, next) => {
|
|
7
|
-
const authHeader = req.headers.authorization;
|
|
8
|
-
if (!authHeader || !authHeader.startsWith("Bearer ")) {
|
|
9
|
-
return res.status(401).send("Unauthorized");
|
|
10
|
-
}
|
|
11
|
-
const token = authHeader.split(" ")[1];
|
|
12
|
-
// Create a hash of the provided token
|
|
13
|
-
const hashedToken = hashToken(token);
|
|
14
|
-
const hashedTokenFromEnv = process.env.HASHED_ACCESS_KEY;
|
|
15
|
-
if (hashedToken !== hashedTokenFromEnv) {
|
|
16
|
-
console.log("Token mismatch", hashedToken, hashedTokenFromEnv);
|
|
17
|
-
return res.status(401).send("Unauthorized");
|
|
18
|
-
}
|
|
19
|
-
next();
|
|
20
|
-
};
|
package/WebTemplate/api.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { errorRetryMiddleware, proxyToUrl, isJobRunMachine, } from "./utils";
|
|
2
|
-
import { accessKeyValidatorMiddleware } from "./accessKeyHelpers";
|
|
3
|
-
import { runWithContext } from "@intuned/runtime";
|
|
4
|
-
import { createAuthSessionController, createAuthSessionAsyncController, resumeAuthSessionOperationController, resumeAuthSessionOperationAsyncController, killAuthSessionOperationController, checkAuthSessionController, checkAuthSessionAsyncController, } from "./controllers/authSessions";
|
|
5
|
-
import { app } from "./app";
|
|
6
|
-
import { getActiveAsyncEndpointController, runApiAsyncController, runApiController, } from "./controllers/runApi";
|
|
7
|
-
import { uploadTraceController, deleteTraceController, } from "./controllers/traces";
|
|
8
|
-
import { RUN_ID_HEADER, JOB_ID_HEADER, JOB_RUN_ID_HEADER, QUEUE_ID_HEADER, } from "./headers";
|
|
9
|
-
import { FEATURES } from "./features";
|
|
10
|
-
if (!isJobRunMachine()) {
|
|
11
|
-
app.use((req, _, next) => {
|
|
12
|
-
const runId = req.headers[RUN_ID_HEADER];
|
|
13
|
-
const jobId = req.headers[JOB_ID_HEADER];
|
|
14
|
-
const jobRunId = req.headers[JOB_RUN_ID_HEADER];
|
|
15
|
-
const queueId = req.headers[QUEUE_ID_HEADER];
|
|
16
|
-
const proxy = req?.body?.proxy
|
|
17
|
-
? proxyToUrl(req.body.proxy)
|
|
18
|
-
: undefined;
|
|
19
|
-
const contextData = {
|
|
20
|
-
runId: runId ?? "",
|
|
21
|
-
jobId,
|
|
22
|
-
jobRunId,
|
|
23
|
-
queueId,
|
|
24
|
-
proxy,
|
|
25
|
-
...(req?.body?.executionContext ?? {}),
|
|
26
|
-
};
|
|
27
|
-
runWithContext(contextData, next);
|
|
28
|
-
});
|
|
29
|
-
app.get("/api/protected/health", accessKeyValidatorMiddleware, async (req, res) => {
|
|
30
|
-
res.status(200).json({ status: "ok" });
|
|
31
|
-
});
|
|
32
|
-
app.post("/api/auth-session/create", accessKeyValidatorMiddleware, errorRetryMiddleware(createAuthSessionController));
|
|
33
|
-
app.post("/api/auth-session-async/create", accessKeyValidatorMiddleware, errorRetryMiddleware(createAuthSessionAsyncController));
|
|
34
|
-
app.post("/api/auth-session/check", accessKeyValidatorMiddleware, errorRetryMiddleware(checkAuthSessionController));
|
|
35
|
-
app.post("/api/auth-session-async/check", accessKeyValidatorMiddleware, errorRetryMiddleware(checkAuthSessionAsyncController));
|
|
36
|
-
app.post("/api/auth-session/kill", accessKeyValidatorMiddleware, errorRetryMiddleware(killAuthSessionOperationController));
|
|
37
|
-
app.post("/api/auth-session/resume", accessKeyValidatorMiddleware, errorRetryMiddleware(resumeAuthSessionOperationController));
|
|
38
|
-
app.post("/api/auth-session-async/resume", accessKeyValidatorMiddleware, errorRetryMiddleware(resumeAuthSessionOperationAsyncController));
|
|
39
|
-
app.post("/api/run/*", accessKeyValidatorMiddleware, errorRetryMiddleware(runApiController));
|
|
40
|
-
app.post("/api/run-async/start/*", accessKeyValidatorMiddleware, errorRetryMiddleware(runApiAsyncController) // todo: this probably needs changing
|
|
41
|
-
);
|
|
42
|
-
app.get("/api/run-async/count", accessKeyValidatorMiddleware, getActiveAsyncEndpointController);
|
|
43
|
-
app.post("/api/trace/upload/:runId", accessKeyValidatorMiddleware, uploadTraceController);
|
|
44
|
-
app.post("/api/trace/delete/:runId", accessKeyValidatorMiddleware, deleteTraceController);
|
|
45
|
-
}
|
|
46
|
-
app.get("/api/features", accessKeyValidatorMiddleware, async (_, res) => {
|
|
47
|
-
res.status(200).json({ features: FEATURES });
|
|
48
|
-
});
|
package/WebTemplate/app.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { App } from "@tinyhttp/app";
|
|
2
|
-
import { json as parser } from "milliparsec";
|
|
3
|
-
export const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
|
|
4
|
-
export const app = new App();
|
|
5
|
-
app.use("/", parser());
|
|
6
|
-
// add header with flyio instance id where the request is served from
|
|
7
|
-
app.use((_, res, next) => {
|
|
8
|
-
res.setHeader("fly-instance-id", process.env.FLY_ALLOC_ID ?? "");
|
|
9
|
-
next();
|
|
10
|
-
});
|
|
11
|
-
app.get("/api/health", async (req, res) => {
|
|
12
|
-
res.status(200).json({ status: "ok" });
|
|
13
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { AsyncRunEndpointController, getErrorResponse } from "../utils";
|
|
2
|
-
import { backendFunctionsTokenManager, callBackendFunctionWithToken, } from "@intuned/runtime/dist/common/jwtTokenManager";
|
|
3
|
-
import retry from "async-retry";
|
|
4
|
-
import { ShutdownController } from "../shutdown";
|
|
5
|
-
export async function runEndpointAsync(handler, parameters, endpointParameters) {
|
|
6
|
-
const { functionsToken, taskToken, startTime, requestId = "endpoint", } = endpointParameters;
|
|
7
|
-
AsyncRunEndpointController.addRequest(taskToken);
|
|
8
|
-
backendFunctionsTokenManager.token = functionsToken;
|
|
9
|
-
let status, body;
|
|
10
|
-
try {
|
|
11
|
-
console.log("Running", requestId, "in async mode");
|
|
12
|
-
({ status, body } = await handler(...parameters));
|
|
13
|
-
console.log("Finished running", requestId, "in async mode");
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
console.error(`Error running ${requestId} in async mode:`, e);
|
|
17
|
-
({ status, body } = getErrorResponse(e));
|
|
18
|
-
}
|
|
19
|
-
finally {
|
|
20
|
-
AsyncRunEndpointController.removeRequest(taskToken);
|
|
21
|
-
}
|
|
22
|
-
// report result
|
|
23
|
-
console.log("Reporting result for", requestId);
|
|
24
|
-
try {
|
|
25
|
-
// `retry` will keep retrying any errors unless they are thrown through calling `bail`
|
|
26
|
-
await retry(async (bail) => {
|
|
27
|
-
const response = await callBackendFunctionWithToken("run/reportResult", {
|
|
28
|
-
method: "POST",
|
|
29
|
-
headers: {
|
|
30
|
-
"Content-Type": "application/json",
|
|
31
|
-
"fly-instance-id": process.env.FLY_ALLOC_ID ?? "",
|
|
32
|
-
},
|
|
33
|
-
body: JSON.stringify({
|
|
34
|
-
status,
|
|
35
|
-
body,
|
|
36
|
-
startTime,
|
|
37
|
-
taskToken,
|
|
38
|
-
}),
|
|
39
|
-
});
|
|
40
|
-
if (!response.ok) {
|
|
41
|
-
// Do not retry unauthenticated, forbidden, not found or too large responses
|
|
42
|
-
if ([401, 403, 404, 413].includes(response.status)) {
|
|
43
|
-
bail(new Error(`Reporting result failed for ${requestId} (non-retryable), status ${response.status}`));
|
|
44
|
-
}
|
|
45
|
-
// retry other errors (such as 502)
|
|
46
|
-
throw new Error(`Reporting result failed for ${requestId}, status ${response.status}`);
|
|
47
|
-
}
|
|
48
|
-
return response;
|
|
49
|
-
}, {
|
|
50
|
-
retries: 5,
|
|
51
|
-
factor: 2,
|
|
52
|
-
maxTimeout: 1000 * 60, // 1 minute
|
|
53
|
-
minTimeout: 1000 * 5, // 5 seconds
|
|
54
|
-
});
|
|
55
|
-
console.log("Reported result for", requestId);
|
|
56
|
-
}
|
|
57
|
-
catch (e) {
|
|
58
|
-
console.log(e?.message ?? `Reporting result failed for ${requestId}`);
|
|
59
|
-
}
|
|
60
|
-
await ShutdownController.instance.checkForShutdown();
|
|
61
|
-
return { status, body };
|
|
62
|
-
}
|
|
63
|
-
export function makeAsyncEndpointController({ requestId, handler, parameters, }) {
|
|
64
|
-
return async (req, res) => {
|
|
65
|
-
const { taskToken, startTime, functionsToken } = req.body;
|
|
66
|
-
if (AsyncRunEndpointController.isRunning(taskToken)) {
|
|
67
|
-
res.status(409).json({ error: "Already running" });
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
void runEndpointAsync(handler, typeof parameters === "function" ? parameters(req) : parameters, {
|
|
71
|
-
taskToken,
|
|
72
|
-
startTime,
|
|
73
|
-
functionsToken,
|
|
74
|
-
requestId: typeof requestId === "function" ? requestId(req) : requestId,
|
|
75
|
-
});
|
|
76
|
-
res.status(202).json({});
|
|
77
|
-
};
|
|
78
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { readJSON } from "fs-extra";
|
|
2
|
-
import { isHeadless } from "../../utils";
|
|
3
|
-
import { runApi } from "@intuned/runtime/dist/common/runApi";
|
|
4
|
-
import { importModule } from "../../utils";
|
|
5
|
-
export async function checkAuthSession({ proxy, session, }) {
|
|
6
|
-
const isAuthSessionEnabled = (await readJSON("./Intuned.json")).authSessions
|
|
7
|
-
?.enabled;
|
|
8
|
-
if (!isAuthSessionEnabled) {
|
|
9
|
-
return {
|
|
10
|
-
status: 400,
|
|
11
|
-
body: {
|
|
12
|
-
error: "Invalid Request",
|
|
13
|
-
message: "auth sessions are not enabled",
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
const result = await runApi({
|
|
18
|
-
automationFunction: {
|
|
19
|
-
name: "auth-sessions/check",
|
|
20
|
-
},
|
|
21
|
-
runOptions: {
|
|
22
|
-
environment: "deployed",
|
|
23
|
-
headless: isHeadless(),
|
|
24
|
-
proxy,
|
|
25
|
-
},
|
|
26
|
-
auth: {
|
|
27
|
-
session: {
|
|
28
|
-
type: "state",
|
|
29
|
-
state: session,
|
|
30
|
-
},
|
|
31
|
-
runCheck: false,
|
|
32
|
-
},
|
|
33
|
-
importFunction: importModule,
|
|
34
|
-
});
|
|
35
|
-
if (result.isErr()) {
|
|
36
|
-
return result.error.apiResponse;
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
status: 200,
|
|
40
|
-
body: {
|
|
41
|
-
result: result.value.result,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|