@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.
Files changed (86) hide show
  1. package/Intuned.json +1 -1
  2. package/WebTemplate/api.ts +92 -90
  3. package/WebTemplate/controllers/authSessions/check.ts +4 -3
  4. package/WebTemplate/controllers/authSessions/create.ts +8 -10
  5. package/WebTemplate/controllers/authSessions/resumeOperation.ts +1 -1
  6. package/WebTemplate/controllers/runApi/helpers.ts +6 -11
  7. package/WebTemplate/index.playwright.ts +42 -32
  8. package/WebTemplate/jobs.ts +2 -13
  9. package/WebTemplate/utils.ts +1 -51
  10. package/api/test2.ts +5 -7
  11. package/auth-sessions/check.ts +1 -3
  12. package/auth-sessions/create.ts +10 -10
  13. package/bin/intuned-api-run +1 -1
  14. package/bin/intuned-auth-session-check +1 -1
  15. package/bin/intuned-auth-session-create +1 -1
  16. package/bin/intuned-auth-session-load +1 -1
  17. package/bin/intuned-auth-session-refresh +1 -1
  18. package/bin/intuned-browser-save-state +1 -1
  19. package/bin/intuned-browser-start +1 -1
  20. package/bin/intuned-build +1 -1
  21. package/bin/intuned-ts-check +1 -1
  22. package/dist/commands/api/run.js +2 -4
  23. package/dist/commands/auth-sessions/run-check.js +1 -3
  24. package/dist/commands/auth-sessions/run-create.js +3 -5
  25. package/dist/commands/build.js +4 -6
  26. package/dist/commands/common/browserUtils.js +1 -1
  27. package/dist/commands/common/getDefaultExportFromFile.d.ts +1 -0
  28. package/dist/commands/common/{tsNodeImport.js → getDefaultExportFromFile.js} +5 -6
  29. package/dist/commands/common/getFirstLineNumber.test.js +2 -2
  30. package/dist/commands/common/utils/settings.js +2 -1
  31. package/dist/commands/common/utils/webTemplate.js +2 -2
  32. package/dist/commands/interface/run.js +106 -122
  33. package/dist/commands/ts-check.js +2 -2
  34. package/dist/common/Logger/Logger/index.d.ts +1 -1
  35. package/dist/common/Logger/index.d.ts +1 -1
  36. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  37. package/dist/common/getPlaywrightConstructs.js +3 -3
  38. package/dist/common/runApi/errors.d.ts +1 -1
  39. package/dist/common/runApi/index.d.ts +5 -5
  40. package/dist/common/runApi/index.js +50 -21
  41. package/dist/common/runApi/types.d.ts +1 -2
  42. package/dist/index.d.ts +4 -4
  43. package/dist/index.js +12 -12
  44. package/dist/runtime/RunError.d.ts +1 -1
  45. package/dist/runtime/executionHelpers.test.js +2 -2
  46. package/dist/runtime/export.d.ts +1 -1
  47. package/dist/runtime/extendPayload.d.ts +1 -1
  48. package/dist/runtime/extendPayload.js +1 -1
  49. package/dist/runtime/index.d.ts +7 -7
  50. package/dist/runtime/index.js +6 -6
  51. package/dist/runtime/runInfo.d.ts +1 -1
  52. package/dist/runtime/runInfo.js +1 -1
  53. package/package.json +5 -6
  54. package/tsconfig.json +1 -1
  55. package/InterfaceTemplate/index.js +0 -1
  56. package/WebTemplate/accessKeyHelpers.js +0 -20
  57. package/WebTemplate/api.js +0 -48
  58. package/WebTemplate/app.js +0 -13
  59. package/WebTemplate/controllers/async.js +0 -78
  60. package/WebTemplate/controllers/authSessions/check.js +0 -44
  61. package/WebTemplate/controllers/authSessions/create.js +0 -69
  62. package/WebTemplate/controllers/authSessions/index.js +0 -25
  63. package/WebTemplate/controllers/authSessions/killOperation.js +0 -26
  64. package/WebTemplate/controllers/authSessions/resumeOperation.js +0 -42
  65. package/WebTemplate/controllers/authSessions/store.js +0 -1
  66. package/WebTemplate/controllers/controllers.js +0 -30
  67. package/WebTemplate/controllers/runApi/helpers.js +0 -90
  68. package/WebTemplate/controllers/runApi/index.js +0 -45
  69. package/WebTemplate/controllers/runApi/types.js +0 -1
  70. package/WebTemplate/controllers/traces.js +0 -108
  71. package/WebTemplate/features.js +0 -6
  72. package/WebTemplate/headers.js +0 -6
  73. package/WebTemplate/index.playwright.js +0 -37
  74. package/WebTemplate/index.vanilla.js +0 -19
  75. package/WebTemplate/jobs.js +0 -259
  76. package/WebTemplate/shutdown.js +0 -51
  77. package/WebTemplate/utils.js +0 -189
  78. package/api/authed.js +0 -6
  79. package/api/test.js +0 -3
  80. package/api/test2.js +0 -17
  81. package/auth-sessions/check.js +0 -6
  82. package/auth-sessions/create.js +0 -20
  83. package/dist/commands/common/tsNodeImport.d.ts +0 -1
  84. package/playwright.config.js +0 -43
  85. package/preserve-dynamic-imports.js +0 -16
  86. package/vite.config.js +0 -16
@@ -1,69 +0,0 @@
1
- import { authSessionsContextsStore } from "./store";
2
- import { getTraceFilePath, isHeadless, importModule } from "../../utils";
3
- import * as fs from "fs-extra";
4
- import { runApiGenerator, } from "@intuned/runtime/dist/common/runApi";
5
- export async function createAuthSession({ parameters, operationId, proxy, saveTrace, }) {
6
- const isAuthSessionEnabled = (await fs.readJSON("./Intuned.json"))
7
- .authSessions?.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
- if (authSessionsContextsStore.has(operationId)) {
18
- return {
19
- status: 400,
20
- body: {
21
- error: "Invalid Request",
22
- message: "operation id already exists, please use a different one, or kill the existing operation, and try again",
23
- },
24
- };
25
- }
26
- const headless = isHeadless();
27
- const abortController = new AbortController();
28
- const createGenerator = runApiGenerator({
29
- automationFunction: {
30
- name: "auth-sessions/create",
31
- params: parameters,
32
- },
33
- tracing: saveTrace
34
- ? {
35
- enabled: true,
36
- filePath: getTraceFilePath(operationId),
37
- }
38
- : { enabled: false },
39
- runOptions: {
40
- environment: "deployed",
41
- headless,
42
- proxy,
43
- },
44
- abortSignal: abortController.signal,
45
- retrieveSession: true,
46
- importFunction: importModule,
47
- });
48
- const result = await createGenerator.next();
49
- if (result.done === true) {
50
- const r = result.value;
51
- if (r.isErr()) {
52
- return r.error.apiResponse;
53
- }
54
- return {
55
- status: 200,
56
- body: { ...r.value.session, status: 200 },
57
- };
58
- }
59
- authSessionsContextsStore.set(operationId, {
60
- done: false,
61
- generator: createGenerator,
62
- requestInfo: result.value,
63
- abortController,
64
- });
65
- return {
66
- status: 200,
67
- body: result.value,
68
- };
69
- }
@@ -1,25 +0,0 @@
1
- import { createAuthSession } from "./create";
2
- import { makeEndpointControllers } from "../controllers";
3
- import { checkAuthSession } from "./check";
4
- import { killAuthSessionOperation } from "./killOperation";
5
- import { resumeAuthSessionOperation } from "./resumeOperation";
6
- export const { sync: createAuthSessionController, async: createAuthSessionAsyncController, } = makeEndpointControllers({
7
- requestId: (req) => `createAuthSession ${req.body.operationId}`,
8
- handler: createAuthSession,
9
- parameters: (req) => [req.body],
10
- });
11
- export const { sync: checkAuthSessionController, async: checkAuthSessionAsyncController, } = makeEndpointControllers({
12
- requestId: "checkAuthSession",
13
- handler: checkAuthSession,
14
- parameters: (req) => [req.body],
15
- });
16
- export const { sync: killAuthSessionOperationController, async: killAuthSessionOperationAsyncController, } = makeEndpointControllers({
17
- requestId: (req) => `killAuthSessionOperation ${req.body.operationId}`,
18
- handler: killAuthSessionOperation,
19
- parameters: (req) => [req.body],
20
- });
21
- export const { sync: resumeAuthSessionOperationController, async: resumeAuthSessionOperationAsyncController, } = makeEndpointControllers({
22
- requestId: (req) => `resumeAuthSessionOperation ${req.body.operationId}`,
23
- handler: resumeAuthSessionOperation,
24
- parameters: (req) => [req.body],
25
- });
@@ -1,26 +0,0 @@
1
- import { authSessionsContextsStore } from "./store";
2
- export async function killAuthSessionOperation({ operationId, }) {
3
- const operation = authSessionsContextsStore.get(operationId);
4
- if (!operation) {
5
- return {
6
- status: 200,
7
- body: {
8
- done: true,
9
- },
10
- };
11
- }
12
- try {
13
- operation.abortController.abort();
14
- authSessionsContextsStore.delete(operationId);
15
- return { status: 200, body: { done: true } };
16
- }
17
- catch (error) {
18
- return {
19
- status: 500,
20
- body: {
21
- error,
22
- message: "the server failed to kill the operation",
23
- },
24
- };
25
- }
26
- }
@@ -1,42 +0,0 @@
1
- import { authSessionsContextsStore } from "./store";
2
- export async function resumeAuthSessionOperation({ operationId, input, }) {
3
- const operation = authSessionsContextsStore.get(operationId);
4
- if (!operation) {
5
- return {
6
- status: 404,
7
- body: {
8
- error: "Invalid Request",
9
- message: "operation not found",
10
- },
11
- };
12
- }
13
- if (operation.requestInfo.requestType === "multiple_choice" &&
14
- !operation.requestInfo.choices.includes(input)) {
15
- return {
16
- status: 400,
17
- body: {
18
- error: "Invalid Request",
19
- message: "input does not match any of the choices",
20
- },
21
- };
22
- }
23
- const result = await operation.generator.next(input);
24
- if (result.done) {
25
- authSessionsContextsStore.delete(operationId);
26
- if (result.value.isErr()) {
27
- return result.value.error.apiResponse;
28
- }
29
- return {
30
- status: 200,
31
- body: result.value.value.session,
32
- };
33
- }
34
- authSessionsContextsStore.set(operationId, {
35
- ...operation,
36
- requestInfo: result.value,
37
- });
38
- return {
39
- status: 200,
40
- body: result.value,
41
- };
42
- }
@@ -1 +0,0 @@
1
- export const authSessionsContextsStore = new Map();
@@ -1,30 +0,0 @@
1
- import { AsyncRunEndpointController } from "../utils";
2
- import { runEndpointAsync } from "./async";
3
- export function makeSyncEndpointController({ handler, parameters, }) {
4
- return async (req, res) => {
5
- const { status, body } = await handler(...(typeof parameters === "function" ? parameters(req) : parameters));
6
- res.status(status).json(body);
7
- };
8
- }
9
- export function makeAsyncEndpointController({ requestId, handler, parameters, }) {
10
- return async (req, res) => {
11
- const { taskToken, startTime, functionsToken } = req.body;
12
- if (AsyncRunEndpointController.isRunning(taskToken)) {
13
- res.status(409).json({ error: "Already running" });
14
- return;
15
- }
16
- void runEndpointAsync(handler, typeof parameters === "function" ? parameters(req) : parameters, {
17
- taskToken,
18
- startTime,
19
- functionsToken,
20
- requestId: typeof requestId === "function" ? requestId(req) : requestId,
21
- });
22
- res.status(202).json({});
23
- };
24
- }
25
- export function makeEndpointControllers({ requestId, handler, parameters, }) {
26
- return {
27
- sync: makeSyncEndpointController({ handler, parameters }),
28
- async: makeAsyncEndpointController({ requestId, handler, parameters }),
29
- };
30
- }
@@ -1,90 +0,0 @@
1
- import { getTraceFilePath, importModule, waitWithExtendableTimeout, } from "../../utils";
2
- import * as fs from "fs-extra";
3
- import { getExecutionContext } from "@intuned/runtime";
4
- import { backendFunctionsTokenManager } from "@intuned/runtime/dist/common/jwtTokenManager";
5
- import { runApi as runApiInternal } from "@intuned/runtime/dist/common/runApi";
6
- export async function runApi({ session, params, proxy, functionsToken, runId, attemptNumber, functionName, shouldSaveTrace, headless = true, }) {
7
- const isAuthSessionEnabled = (await fs.readJSON("./Intuned.json"))
8
- .authSessions?.enabled;
9
- if (!runId) {
10
- return {
11
- status: 400,
12
- body: {
13
- error: "runId header not provided",
14
- message: "Please add provide run id to header",
15
- },
16
- };
17
- }
18
- backendFunctionsTokenManager.token = functionsToken;
19
- // handle timeout
20
- const requestTimeout = +(process.env.REQUEST_TIMEOUT ?? 600) * 1000;
21
- getExecutionContext().timeoutInfo = {
22
- ...(getExecutionContext()?.timeoutInfo ?? {}),
23
- timeoutDuration: requestTimeout,
24
- };
25
- async function handleTimeout() {
26
- console.log("timeout triggered");
27
- return {
28
- status: 508,
29
- body: {
30
- error: "TimeoutError",
31
- message: "The request timed out",
32
- },
33
- };
34
- }
35
- const abortController = new AbortController();
36
- const resultWithTimeout = await waitWithExtendableTimeout({
37
- promise: runApiInternal({
38
- automationFunction: {
39
- name: `api/${functionName}`,
40
- params,
41
- },
42
- auth: isAuthSessionEnabled
43
- ? {
44
- session: {
45
- type: "state",
46
- state: session,
47
- },
48
- runCheck: isAuthSessionEnabled,
49
- }
50
- : undefined,
51
- runOptions: {
52
- environment: "deployed",
53
- headless,
54
- proxy,
55
- },
56
- tracing: shouldSaveTrace
57
- ? {
58
- enabled: true,
59
- filePath: getTraceFilePath(runId, attemptNumber),
60
- }
61
- : { enabled: false },
62
- functionsToken,
63
- abortSignal: abortController.signal,
64
- importFunction: importModule,
65
- }),
66
- initialTimeout: requestTimeout,
67
- abortController,
68
- });
69
- if (resultWithTimeout.timedOut === true) {
70
- return await handleTimeout();
71
- }
72
- const { result } = resultWithTimeout;
73
- if (result.isErr()) {
74
- if (result.error.code === "AbortedError") {
75
- return await handleTimeout();
76
- }
77
- return result.error.apiResponse;
78
- }
79
- return {
80
- status: 200,
81
- body: {
82
- status: 200,
83
- result: result.value.result,
84
- payloadToAppend: result.value.extendedPayloads?.map(({ api, parameters }) => ({
85
- apiName: api,
86
- parameters,
87
- })),
88
- },
89
- };
90
- }
@@ -1,45 +0,0 @@
1
- import { RUN_ID_HEADER, ATTEMPT_NUMBER_HEADER } from "../../headers";
2
- import { runApi } from "./helpers";
3
- import { AsyncRunEndpointController, isHeadless } from "../../utils";
4
- import { makeEndpointControllers } from "../controllers";
5
- export { runApi } from "./helpers";
6
- export const { sync: runApiController, async: runApiAsyncController } = makeEndpointControllers({
7
- requestId: (req) => `runApi ${req.headers[RUN_ID_HEADER]} (${req.headers[ATTEMPT_NUMBER_HEADER]})`,
8
- parameters: (req) => {
9
- // e.g. /api/run/folder1/api should be folder1/api
10
- const functionName = req.params.wild
11
- .split("/")
12
- // filter(Boolean) should remove empty strings in case of a trailing slash
13
- .filter(Boolean)
14
- .join("/");
15
- const { session, params, proxy, executionContext, functionsToken } = req.body;
16
- const runId = req.headers[RUN_ID_HEADER];
17
- const attemptNumber = req.headers[ATTEMPT_NUMBER_HEADER];
18
- const shouldSaveTrace = req.query.saveTrace === "true";
19
- const headless = isHeadless();
20
- const result = [
21
- {
22
- session,
23
- params,
24
- proxy,
25
- executionContext,
26
- functionsToken,
27
- runId,
28
- attemptNumber,
29
- functionName,
30
- shouldSaveTrace,
31
- headless,
32
- },
33
- ];
34
- return result;
35
- },
36
- handler: async (parameters) => {
37
- const { status, body } = await runApi(parameters);
38
- return { status, body };
39
- },
40
- });
41
- export const getActiveAsyncEndpointController = async (req, res) => {
42
- res
43
- .status(200)
44
- .json({ count: AsyncRunEndpointController.activeRequestsCount });
45
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,108 +0,0 @@
1
- import { getTraceFilePath } from "../utils";
2
- import { pathExists, remove, createReadStream, stat } from "fs-extra";
3
- import fetch from "node-fetch";
4
- import { ok, err } from "neverthrow";
5
- export async function uploadTrace({ runId, attemptNumber, signedUrl, }) {
6
- const traceFilePath = getTraceFilePath(runId, attemptNumber);
7
- if (!(await pathExists(traceFilePath))) {
8
- return err({
9
- message: "Trace file not found",
10
- error: "Not found",
11
- errorCode: "trace_file_not_found",
12
- });
13
- }
14
- const fileSize = (await stat(traceFilePath)).size;
15
- const file = createReadStream(traceFilePath);
16
- const response = await fetch(signedUrl, {
17
- method: "PUT",
18
- headers: {
19
- "Content-Length": fileSize.toString(),
20
- },
21
- body: file,
22
- });
23
- if (!response.ok) {
24
- return err({
25
- message: `Upload trace failed with status code ${response.status}`,
26
- error: "Upload trace failed",
27
- errorCode: "upload_trace_failed",
28
- });
29
- }
30
- return ok({
31
- traceName: `${runId}.zip`,
32
- });
33
- }
34
- export async function deleteTrace({ runId, attemptNumber, }) {
35
- const traceFilePath = getTraceFilePath(runId, attemptNumber);
36
- if (!(await pathExists(traceFilePath))) {
37
- return err({
38
- message: "Trace file not found",
39
- error: "Not found",
40
- errorCode: "trace_file_not_found",
41
- });
42
- }
43
- try {
44
- await remove(traceFilePath);
45
- return ok(undefined);
46
- }
47
- catch (error) {
48
- return err({
49
- message: `Delete trace file failed ${runId}`,
50
- error: "Delete trace failed",
51
- errorCode: "delete_trace_failed",
52
- });
53
- }
54
- }
55
- export const uploadTraceController = async (req, res) => {
56
- const { runId } = req.params;
57
- const { attemptNumber } = req.query;
58
- const signedUrl = req.body.signedUrl;
59
- if (!runId) {
60
- return res.status(400).json({
61
- error: "runId not provided",
62
- message: "Please add provide run id",
63
- });
64
- }
65
- if (!signedUrl) {
66
- return res.status(400).json({
67
- error: "signedUrl not provided",
68
- message: "Please add provide signedUrl",
69
- });
70
- }
71
- const uploadTraceResult = await uploadTrace({
72
- runId,
73
- attemptNumber: attemptNumber,
74
- signedUrl,
75
- });
76
- if (uploadTraceResult.isOk()) {
77
- return res.status(200).json({
78
- result: uploadTraceResult.value,
79
- });
80
- }
81
- const error = uploadTraceResult.error;
82
- if (error.errorCode === "trace_file_not_found") {
83
- return res.status(404).json(error);
84
- }
85
- return res.status(500).json(error);
86
- };
87
- export const deleteTraceController = async (req, res) => {
88
- const { runId } = req.params;
89
- const { attemptNumber } = req.query;
90
- if (!runId) {
91
- return res.status(400).json({
92
- error: "runId not provided",
93
- message: "Please add provide run id",
94
- });
95
- }
96
- const deleteTraceResult = await deleteTrace({
97
- runId,
98
- attemptNumber: attemptNumber,
99
- });
100
- if (deleteTraceResult.isOk()) {
101
- return res.status(204).send("");
102
- }
103
- const error = deleteTraceResult.error;
104
- if (error.errorCode === "trace_file_not_found") {
105
- return res.status(404).json(error);
106
- }
107
- return res.status(500).json(error);
108
- };
@@ -1,6 +0,0 @@
1
- // sync with apps/web/lib/Services/IntegrationService/constants.ts
2
- export const FEATURES = [
3
- "JOBS-V3",
4
- "RUN-ASYNC-MODE",
5
- "AUTH-SESSION-ASYNC-MODE",
6
- ];
@@ -1,6 +0,0 @@
1
- export const RUN_ID_HEADER = "x-run-id";
2
- export const JOB_ID_HEADER = "x-job-id";
3
- export const JOB_RUN_ID_HEADER = "x-job-run-id";
4
- export const QUEUE_ID_HEADER = "x-queue-id";
5
- export const ATTEMPT_NUMBER_HEADER = "x-attempt-number";
6
- export const SHOULD_SHUTDOWN_HEADER = "x-should-shutdown";
@@ -1,37 +0,0 @@
1
- import { initializeAppInsights, getTelemetryClient, } from "@intuned/runtime/dist/common/telemetry";
2
- import { getExecutionContext } from "@intuned/runtime";
3
- import { app } from "./app";
4
- import { RUN_ID_HEADER } from "./headers";
5
- import { ShutdownController } from "./shutdown";
6
- const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
7
- initializeAppInsights();
8
- app.use((req, res, next) => {
9
- // Cleanup after the response is sent
10
- res.on("finish", () => {
11
- console.log("finished", req.headers[RUN_ID_HEADER]);
12
- void ShutdownController.instance.checkForShutdown();
13
- });
14
- next();
15
- });
16
- export * from "./api";
17
- export * from "./jobs";
18
- const server = app.listen(port, () => {
19
- // when deployed on flyio, the server will be turned on and
20
- // will shutdown after the specified time in TIME_TO_SHUTDOWN env variable
21
- ShutdownController.initialize(server);
22
- void ShutdownController.instance.checkForShutdown();
23
- console.log(`Server is running on port ${port}`);
24
- });
25
- process.on("unhandledRejection", (reason, promise) => {
26
- const telemetryClient = getTelemetryClient();
27
- console.error("Unhandled Rejection at:", promise, "reason:", reason);
28
- const context = getExecutionContext();
29
- telemetryClient?.trackEvent({
30
- name: "UNHANDLED_REJECTION",
31
- properties: {
32
- runId: context?.runId,
33
- promise,
34
- reason,
35
- },
36
- });
37
- });
@@ -1,19 +0,0 @@
1
- import { App } from "@tinyhttp/app";
2
- import { json as parser } from "milliparsec";
3
- import { accessKeyValidatorMiddleware } from "./accessKeyHelpers";
4
- const port = process.env.PORT ? parseInt(process.env.PORT) : 4000;
5
- const app = new App();
6
- app.use("/", parser());
7
- app.post("/api/run/*", async (req, res) => {
8
- return res.status(502).json({ message: "Not implemented" });
9
- });
10
- app.get("/api/health", async (req, res) => {
11
- res.status(200).json({ status: "ok" });
12
- });
13
- app.use(accessKeyValidatorMiddleware);
14
- app.get("/protected/health", async (req, res) => {
15
- res.status(200).json({ status: "ok" });
16
- });
17
- app.listen(port, () => {
18
- console.log(`Server is running on port ${port}`);
19
- });