@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
package/package.json CHANGED
@@ -1,18 +1,21 @@
1
1
  {
2
2
  "name": "@intuned/runtime-dev",
3
- "version": "0.0.1",
3
+ "version": "0.1.0-test.0",
4
4
  "description": "Intuned runtime",
5
5
  "exports": {
6
6
  ".": "./dist/index.js",
7
- "./runtime": "./dist/runtime/index.js",
7
+ "./dist/runtime": "./dist/runtime/index.js",
8
+ "./dist/common/runApi": "./dist/common/runApi/index.js",
8
9
  "./dist/common/settingsSchema": "./dist/common/settingsSchema.js",
9
10
  "./dist/common/contextStorageStateHelpers": "./dist/common/contextStorageStateHelpers.js",
10
11
  "./dist/common/telemetry": "./dist/common/telemetry.js",
11
12
  "./dist/common/jwtTokenManager": "./dist/common/jwtTokenManager.js",
12
13
  "./dist/common/asyncLocalStorage": "./dist/common/asyncLocalStorage/index.js",
13
14
  "./dist/common/cleanEnvironmentVariables": "./dist/common/cleanEnvironmentVariables.js",
14
- "./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"
15
17
  },
18
+ "types": "./dist/index.d.ts",
16
19
  "author": "Intuned Team",
17
20
  "license": "MIT",
18
21
  "scripts": {
@@ -25,7 +28,6 @@
25
28
  "intuned-auth-session-refresh": "vite-node ./src/commands/auth/run-refresh.ts",
26
29
  "intuned-auth-session-load": "vite-node ./src/commands/auth/load.ts",
27
30
  "intuned-ts-check": "yarn prepublishOnly && vite-node ./src/commands/ts-check.ts",
28
- "save-html": "vite-node ./src/commands/testing/saveVisibleHtml.ts",
29
31
  "build": "rm -rf dist && tsc -p tsconfig.json && yarn copy-dts && babel src --out-dir dist --extensions '.ts' && cp -r ./src/common/assets dist/common/assets",
30
32
  "test": "vitest run",
31
33
  "test:watch": "vitest",
@@ -122,12 +124,12 @@
122
124
  "typedoc-plugin-frontmatter": "^1.0.0",
123
125
  "typedoc-plugin-markdown": "^4.0.2",
124
126
  "typedoc-plugin-remove-references": "^0.0.6",
125
- "vite": "^5.2.14",
127
+ "vite": "^5.4.12",
126
128
  "vite-node": "^1.1.3",
127
129
  "vite-plugin-babel-macros": "^1.0.6",
128
130
  "vitest": "^1.1.3"
129
131
  },
130
132
  "peerDependencies": {
131
- "@intuned/runtime": "0.0.1"
133
+ "@intuned/runtime": "*"
132
134
  }
133
- }
135
+ }
package/testing ADDED
Binary file
package/tsconfig.json CHANGED
@@ -12,7 +12,8 @@
12
12
  "sourceMap": false,
13
13
  "declaration": true,
14
14
  "emitDeclarationOnly": false,
15
- "skipLibCheck": true
15
+ "skipLibCheck": true,
16
+ "baseUrl": "./"
16
17
  },
17
18
  "include": [
18
19
  "src/**/*.ts",
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "recommendations": ["zixuanchen.vitest-explorer"]
3
- }
@@ -1,102 +0,0 @@
1
- {
2
- // Use IntelliSense to learn about possible attributes.
3
- // Hover to view descriptions of existing attributes.
4
- // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
- "version": "0.2.0",
6
- "configurations": [
7
- {
8
- "name": "Hiltion api",
9
- "type": "node",
10
- "request": "launch",
11
- "runtimeExecutable": "node",
12
- "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
13
-
14
- "args": ["src/commands/api/run.ts", "hilton", "-j", "{}", "playwright"],
15
-
16
- "cwd": "${workspaceRoot}",
17
- "internalConsoleOptions": "openOnSessionStart",
18
- "skipFiles": ["<node_internals>/**", "node_modules/**"]
19
- },
20
- {
21
- "name": "Books Extractor",
22
- "type": "node",
23
- "request": "launch",
24
- "runtimeExecutable": "node",
25
- "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
26
-
27
- "args": [
28
- "src/commands/api/run.ts",
29
- "books-array",
30
- "-j",
31
- "{}",
32
- "playwright"
33
- ],
34
-
35
- "cwd": "${workspaceRoot}",
36
- "internalConsoleOptions": "openOnSessionStart",
37
- "skipFiles": ["<node_internals>/**", "node_modules/**"]
38
- },
39
- {
40
- "name": "Run execution-info",
41
- "type": "node",
42
- "request": "launch",
43
- "runtimeExecutable": "node",
44
- "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
45
-
46
- "args": [
47
- "src/commands/api/run.ts",
48
- "execution-info",
49
- "-j",
50
- "{}",
51
- "playwright"
52
- ],
53
-
54
- "cwd": "${workspaceRoot}",
55
- "internalConsoleOptions": "openOnSessionStart",
56
- "skipFiles": ["<node_internals>/**", "node_modules/**"]
57
- },
58
- {
59
- "name": "Run progressive",
60
- "type": "node",
61
- "request": "launch",
62
- "runtimeExecutable": "node",
63
- "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
64
-
65
- "args": [
66
- "src/commands/api/run.ts",
67
- "progressive",
68
- "-j",
69
- "{}",
70
- "playwright"
71
- ],
72
-
73
- "cwd": "${workspaceRoot}",
74
- "internalConsoleOptions": "openOnSessionStart",
75
- "skipFiles": ["<node_internals>/**", "node_modules/**"]
76
- },
77
- {
78
- "name": "Run progressive - standalone",
79
- "type": "node",
80
- "request": "launch",
81
- "runtimeExecutable": "node",
82
- "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
83
-
84
- "args": ["src/commands/api/run.ts", "progressive", "-j", "{}"],
85
- "cwd": "${workspaceRoot}",
86
- "internalConsoleOptions": "openOnSessionStart",
87
- "skipFiles": ["<node_internals>/**", "node_modules/**"]
88
- },
89
- {
90
- "name": "Run progressive extract - standalone",
91
- "type": "node",
92
- "request": "launch",
93
- "runtimeExecutable": "node",
94
- "runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
95
-
96
- "args": ["src/commands/api/run.ts", "progressive-extract", "-j", "{}"],
97
- "cwd": "${workspaceRoot}",
98
- "internalConsoleOptions": "openOnSessionStart",
99
- "skipFiles": ["<node_internals>/**", "node_modules/**"]
100
- }
101
- ]
102
- }
@@ -1,12 +0,0 @@
1
- {
2
- "editor.formatOnSave": true,
3
- "cSpell.words": ["backcompat", "ـget", "INFINITI", "neverthrow"],
4
- "editor.detectIndentation": true,
5
- "files.exclude": {
6
- "dist": false,
7
- "node_modules": false,
8
- "output": false,
9
- "intuned": false,
10
- "htmlFiles": true
11
- }
12
- }
@@ -1,48 +0,0 @@
1
- import { defineConfig, devices } from "@intuned/playwright-test";
2
-
3
- /**
4
- * Read environment variables from file.
5
- * https://github.com/motdotla/dotenv
6
- */
7
- // require('dotenv').config();
8
-
9
- /**
10
- * See https://playwright.dev/docs/test-configuration.
11
- */
12
- export default defineConfig({
13
- testDir: "./e2e-tests",
14
- /* Run tests in files in parallel */
15
- fullyParallel: true,
16
- /* Fail the build on CI if you accidentally left test.only in the source code. */
17
- forbidOnly: !!process.env.CI,
18
- /* Retry on CI only */
19
- retries: process.env.CI ? 2 : 0,
20
- /* Opt out of parallel tests on CI. */
21
- workers: process.env.CI ? 1 : undefined,
22
- /* Reporter to use. See https://playwright.dev/docs/test-reporters */
23
- reporter: "html",
24
- /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
25
- use: {
26
- /* Base URL to use in actions like `await page.goto('/')`. */
27
- // baseURL: 'http://127.0.0.1:3000',
28
-
29
- /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
30
- trace: "on-first-retry",
31
- // headless: false,
32
- },
33
-
34
- /* Configure projects for major browsers */
35
- projects: [
36
- {
37
- name: "chromium",
38
- use: { ...devices["Desktop Chrome"] },
39
- },
40
- ],
41
-
42
- /* Run your local dev server before starting the tests */
43
- // webServer: {
44
- // command: 'npm run start',
45
- // url: 'http://127.0.0.1:3000',
46
- // reuseExistingServer: !process.env.CI,
47
- // },
48
- });
@@ -1,225 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program, Argument } from "commander";
3
- import * as fs from "fs-extra";
4
- import { getDefaultExportFromFile } from "../common/getDefaultExportFromFile";
5
- import { getFullPathInProject } from "../common/utils/fileUtils";
6
- import { getSettings } from "../common/utils/settings";
7
- import getFirstLineNumber from "../common/getFirstLineNumber";
8
- import { sendBreakPointOnToClient } from "../common/sendMessageToClient";
9
- import dotenv from "dotenv";
10
- import {
11
- getExecutionContext,
12
- runWithContext,
13
- } from "../../common/asyncLocalStorage";
14
- import { RunEnvironment } from "../../runtime/enums";
15
- import { cleanEnvironmentVariables } from "../../common/cleanEnvironmentVariables";
16
- import { logger } from "../../common/Logger";
17
- import { nanoid } from "nanoid";
18
- import chalk from "chalk";
19
- import { getDownloadDirectoryPath } from "../../runtime";
20
- import { getPlaywrightConstructsForMode } from "../../common/getPlaywrightConstructs";
21
-
22
- dotenv.config({
23
- path: `.env`,
24
- });
25
-
26
- export async function executeCLI(
27
- apiName: string,
28
- mode:
29
- | "vanilla"
30
- | "playwright"
31
- | "playwright-standalone"
32
- | "playwright-headless",
33
- inputData: object | null | undefined,
34
- options: {
35
- cdpAddress: string;
36
- authSessionPath: undefined | string;
37
- outputFileId: string | undefined;
38
- }
39
- ) {
40
- // cleanup environment variables before running the user code
41
- cleanEnvironmentVariables();
42
- // Path to the TypeScript file
43
- const apiFilePath = getFullPathInProject("api", `${apiName}.ts`);
44
-
45
- let authSessionPathToUse: string | null = null;
46
-
47
- // check auth session
48
- const settings = await getSettings();
49
-
50
- if (settings.authSessions.enabled) {
51
- // if auth session enabled, check if the auth session is provided
52
- if (!options.authSessionPath) {
53
- throw new Error("Auth session is enabled but no auth session provided");
54
- }
55
-
56
- authSessionPathToUse = options.authSessionPath as string;
57
- } else {
58
- // if auth session is not enabled, check if the auth session is provided
59
- if (options.authSessionPath) {
60
- throw new Error(
61
- "Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json"
62
- );
63
- }
64
- }
65
-
66
- // Dynamically import the TypeScript file
67
- const defaultExport = await getDefaultExportFromFile(apiFilePath);
68
- const isDebug = process.execArgv.some((arg) => arg.includes("--inspect"));
69
- if (isDebug) {
70
- const { sourceFileName, lineNumber } = await getFirstLineNumber(
71
- apiFilePath
72
- );
73
- sendBreakPointOnToClient(sourceFileName, lineNumber);
74
- }
75
-
76
- if (mode === "vanilla") {
77
- // Execute the function with the input data
78
- const result = await defaultExport(inputData);
79
- return result;
80
- }
81
-
82
- const { page, context } = await getPlaywrightConstructsForMode(
83
- mode,
84
- options.cdpAddress,
85
- authSessionPathToUse ? authSessionPathToUse : undefined
86
- );
87
-
88
- // wait for the page to get stable, this is a workaround for a bug in playwright when you try to do something
89
- // on a page after connecting to it immediately, the page needs some time to get stable.
90
- let isPageStable = false;
91
- let retry = 0;
92
- // will wait maximum 2 seconds before failing.
93
- while (!isPageStable && retry < 10) {
94
- try {
95
- await page.locator("html").all();
96
- isPageStable = true;
97
- break;
98
- } catch (error) {
99
- if (error?.message?.includes("Execution context was destroyed")) {
100
- await new Promise((resolve) => setTimeout(resolve, 200));
101
- } else {
102
- // throwing to make sure we do not hide any other unexpected issues.
103
- throw error;
104
- }
105
- }
106
- retry++;
107
- }
108
-
109
- if (!isPageStable) {
110
- throw new Error("The page is not stable, try to run again.");
111
- }
112
-
113
- const result = await defaultExport(inputData, page, context);
114
- const downloadsPath = getDownloadDirectoryPath();
115
- await fs.remove(downloadsPath);
116
- if (mode == "playwright") {
117
- await context.close();
118
- }
119
- const isResponseObject = typeof result === "object" && result !== null;
120
-
121
- const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
122
- const hasNestedObjects =
123
- isResponseObject &&
124
- Object.values(result).some((value) => typeof value === "object");
125
-
126
- const shouldWriteToFile =
127
- isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
128
-
129
- const resultsDir = "/tmp/run-results";
130
-
131
- if (options.outputFileId && shouldWriteToFile) {
132
- logger.info(
133
- chalk.underline.bgBlue.white(
134
- `Click to Open: Results saved (Run: ${options.outputFileId})`
135
- )
136
- );
137
-
138
- fs.ensureDirSync(resultsDir);
139
- const path = `${resultsDir}/${options.outputFileId}.json`;
140
- await fs.writeJson(path, result, {
141
- spaces: 2,
142
- });
143
- } else {
144
- console.log("result:", result);
145
- }
146
-
147
- const payloadToAppend = getExecutionContext()?.extendedPayloads;
148
- const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
149
-
150
- if (hasPayloadToAppend && options.outputFileId) {
151
- logger.info(
152
- chalk.underline.bgBlue.white(
153
- `Click to Open: payloads to append (Run: ${options.outputFileId})`
154
- )
155
- );
156
-
157
- fs.ensureDirSync(resultsDir);
158
-
159
- const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
160
- await fs.writeJson(path, payloadToAppend, {
161
- spaces: 2,
162
- });
163
- } else if (hasPayloadToAppend) {
164
- logger.info("payload to append:", payloadToAppend);
165
- logger.info(
166
- "This will only take an effect if this API run was part of a job."
167
- );
168
- }
169
- }
170
-
171
- program
172
- .description("run the user function in the cli for testing purposes")
173
- .option("-i, --input [file]", "input json file")
174
- .option("-j, --json [json]", "input json string")
175
- .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
176
- .option(
177
- "--authSessionPath <authSession>",
178
- "auth session to use when executing the api"
179
- )
180
- .option(
181
- "--outputFileId <outputFileId>",
182
- "the output file id to save the result in"
183
- )
184
- .option("--proxy <proxy>", "proxy to use")
185
- .argument("[apiName]", "name of the api", "default")
186
- .allowUnknownOption()
187
- .addArgument(
188
- new Argument("<mode>", "mode of execution")
189
- .choices([
190
- "vanilla",
191
- "playwright",
192
- "playwright-standalone",
193
- "playwright-headless",
194
- ])
195
- .default("playwright-standalone")
196
- .argOptional()
197
- )
198
- .action(async (apiName, mode, options) => {
199
- let inputData: null | object = null;
200
-
201
- if (options.input) {
202
- inputData = await fs.readJSON(options.input);
203
- } else if (options.json) {
204
- inputData = JSON.parse(options.json);
205
- } else {
206
- inputData = {};
207
- }
208
-
209
- await runWithContext(
210
- {
211
- runEnvironment: RunEnvironment.IDE,
212
- extendedPayloads: [],
213
- runId: nanoid(),
214
- proxy: options.proxy,
215
- },
216
- () => executeCLI(apiName, mode, inputData as object, options)
217
- );
218
-
219
- // playwright keeps an open handle to the connected browser and it stops the process from exiting
220
- // there is no way to close the connection gracefully without destroying the context/browser
221
- // https://github.com/microsoft/playwright/issues/4956
222
- process.exit(0);
223
- });
224
-
225
- program.parse(process.argv);
@@ -1,42 +0,0 @@
1
- #!/usr/bin/env node
2
- import { program } from "commander";
3
- import { getRemotePlaywrightContext } from "../../common/getPlaywrightConstructs";
4
- import { getSettings } from "../common/utils/settings";
5
-
6
- import dotenv from "dotenv";
7
- import { loadAuthSessionToContext } from "../../common/getPlaywrightConstructs";
8
-
9
- dotenv.config({
10
- path: `.env`,
11
- });
12
-
13
- program
14
- .description("load auth session to browser")
15
- .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
16
- .option(
17
- "--authSessionPath <authSession>",
18
- "auth session to use when executing the api"
19
- )
20
- .allowUnknownOption()
21
- .action(
22
- async ({
23
- cdpAddress,
24
- authSessionPath,
25
- }: {
26
- cdpAddress: string;
27
- authSessionPath: string;
28
- }) => {
29
- const setting = await getSettings();
30
-
31
- if (!setting.authSessions.enabled) {
32
- throw new Error("Auth session is not enabled");
33
- }
34
-
35
- const { context } = await getRemotePlaywrightContext(cdpAddress);
36
- await loadAuthSessionToContext(context, authSessionPath);
37
-
38
- process.exit(0);
39
- }
40
- );
41
-
42
- program.parse(process.argv);
@@ -1,70 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Argument, program } from "commander";
3
- import { getDefaultExportFromFile } from "../common/getDefaultExportFromFile";
4
- import * as fs from "fs-extra";
5
- import { getFullPathInProject } from "../common/utils/fileUtils";
6
- import { getSettings } from "../common/utils/settings";
7
- import dotenv from "dotenv";
8
- import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
9
- import { getPlaywrightConstructsForMode } from "../../common/getPlaywrightConstructs";
10
-
11
- dotenv.config({
12
- path: `.env`,
13
- });
14
-
15
- program
16
- .description("run auth session check")
17
- .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
18
- .option(
19
- "--authSessionPath <authSession>",
20
- "auth session to use when executing the check"
21
- )
22
- .allowUnknownOption()
23
- .addArgument(
24
- new Argument("<mode>", "mode of execution")
25
- .choices(["vanilla", "playwright", "playwright-standalone"])
26
- .default("playwright-standalone")
27
- .argOptional()
28
- )
29
- .action(
30
- async (
31
- mode: "vanilla" | "playwright" | "playwright-standalone",
32
- {
33
- cdpAddress,
34
- authSessionPath,
35
- }: { cdpAddress: string; authSessionPath?: string }
36
- ) => {
37
- const setting = await getSettings();
38
- if (!setting.authSessions.enabled) {
39
- throw new Error("auth session is not enabled");
40
- }
41
-
42
- const checkFilePath = getFullPathInProject(
43
- AUTH_SESSIONS_FOLDER_NAME,
44
- "check.ts"
45
- );
46
-
47
- if (!fs.exists(checkFilePath)) {
48
- throw new Error("auth session check file not found");
49
- }
50
-
51
- // Dynamically import the TypeScript file
52
- const defaultExport = await getDefaultExportFromFile(checkFilePath);
53
- const { page, context } = await getPlaywrightConstructsForMode(
54
- mode,
55
- cdpAddress,
56
- authSessionPath
57
- );
58
-
59
- const result: boolean = await defaultExport(page, context);
60
- console.log("check result", result);
61
-
62
- if (!result) {
63
- throw new Error("auth session check failed");
64
- }
65
-
66
- process.exit(0);
67
- }
68
- );
69
-
70
- program.parse(process.argv);