@intuned/runtime-dev 0.0.1-split.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 (87) hide show
  1. package/.babelrc +21 -0
  2. package/.eslintignore +10 -0
  3. package/.eslintrc.js +39 -0
  4. package/.vite/deps_temp_01af7156/package.json +3 -0
  5. package/.vscode/extensions.json +3 -0
  6. package/.vscode/launch.json +102 -0
  7. package/.vscode/settings.json +12 -0
  8. package/WebTemplate/accessKeyHelpers.ts +28 -0
  9. package/WebTemplate/api.ts +139 -0
  10. package/WebTemplate/app.ts +18 -0
  11. package/WebTemplate/controllers/async.ts +138 -0
  12. package/WebTemplate/controllers/authSessions/check.ts +68 -0
  13. package/WebTemplate/controllers/authSessions/create.ts +128 -0
  14. package/WebTemplate/controllers/authSessions/index.ts +41 -0
  15. package/WebTemplate/controllers/authSessions/killOperation.ts +35 -0
  16. package/WebTemplate/controllers/authSessions/resumeOperation.ts +80 -0
  17. package/WebTemplate/controllers/authSessions/store.ts +14 -0
  18. package/WebTemplate/controllers/controllers.ts +73 -0
  19. package/WebTemplate/controllers/runApi/helpers.ts +220 -0
  20. package/WebTemplate/controllers/runApi/index.ts +68 -0
  21. package/WebTemplate/controllers/runApi/types.ts +13 -0
  22. package/WebTemplate/controllers/traces.ts +151 -0
  23. package/WebTemplate/features.ts +8 -0
  24. package/WebTemplate/headers.ts +6 -0
  25. package/WebTemplate/index.playwright.ts +47 -0
  26. package/WebTemplate/index.vanilla.ts +44 -0
  27. package/WebTemplate/jobs.ts +356 -0
  28. package/WebTemplate/shutdown.ts +64 -0
  29. package/WebTemplate/utils.ts +294 -0
  30. package/bin/intuned-api-run +2 -0
  31. package/bin/intuned-auth-session-check +2 -0
  32. package/bin/intuned-auth-session-create +2 -0
  33. package/bin/intuned-auth-session-load +2 -0
  34. package/bin/intuned-auth-session-refresh +2 -0
  35. package/bin/intuned-browser-save-state +2 -0
  36. package/bin/intuned-browser-start +2 -0
  37. package/bin/intuned-build +2 -0
  38. package/bin/intuned-ts-check +2 -0
  39. package/package.json +133 -0
  40. package/playwright.config.ts +48 -0
  41. package/src/commands/api/run.ts +225 -0
  42. package/src/commands/auth-sessions/load.ts +42 -0
  43. package/src/commands/auth-sessions/run-check.ts +70 -0
  44. package/src/commands/auth-sessions/run-create.ts +124 -0
  45. package/src/commands/browser/save-state.ts +22 -0
  46. package/src/commands/browser/start-browser.ts +17 -0
  47. package/src/commands/build.ts +125 -0
  48. package/src/commands/common/browserUtils.ts +80 -0
  49. package/src/commands/common/getDefaultExportFromFile.ts +13 -0
  50. package/src/commands/common/getFirstLineNumber.test.ts +274 -0
  51. package/src/commands/common/getFirstLineNumber.ts +146 -0
  52. package/src/commands/common/sendMessageToClient.ts +8 -0
  53. package/src/commands/common/utils/fileUtils.ts +25 -0
  54. package/src/commands/common/utils/settings.ts +23 -0
  55. package/src/commands/common/utils/webTemplate.ts +46 -0
  56. package/src/commands/testing/saveVisibleHtml.ts +29 -0
  57. package/src/commands/ts-check.ts +88 -0
  58. package/src/common/Logger/Logger/index.ts +64 -0
  59. package/src/common/Logger/Logger/types.ts +9 -0
  60. package/src/common/Logger/index.ts +64 -0
  61. package/src/common/Logger/types.ts +9 -0
  62. package/src/common/assets/browser_scripts.js +2214 -0
  63. package/src/common/asyncLocalStorage/index.ts +29 -0
  64. package/src/common/cleanEnvironmentVariables.ts +13 -0
  65. package/src/common/constants.ts +1 -0
  66. package/src/common/contextStorageStateHelpers.ts +71 -0
  67. package/src/common/getPlaywrightConstructs.ts +283 -0
  68. package/src/common/jwtTokenManager.ts +111 -0
  69. package/src/common/settingsSchema.ts +16 -0
  70. package/src/common/telemetry.ts +49 -0
  71. package/src/index.ts +14 -0
  72. package/src/runtime/RunError.ts +16 -0
  73. package/src/runtime/downloadDirectory.ts +14 -0
  74. package/src/runtime/enums.d.ts +11 -0
  75. package/src/runtime/enums.ts +11 -0
  76. package/src/runtime/executionHelpers.test.ts +70 -0
  77. package/src/runtime/export.d.ts +202 -0
  78. package/src/runtime/extendPayload.ts +22 -0
  79. package/src/runtime/extendTimeout.ts +32 -0
  80. package/src/runtime/index.ts +8 -0
  81. package/src/runtime/requestMoreInfo.ts +40 -0
  82. package/src/runtime/runInfo.ts +19 -0
  83. package/template.tsconfig.json +14 -0
  84. package/tsconfig.eslint.json +5 -0
  85. package/tsconfig.json +24 -0
  86. package/typedoc.json +49 -0
  87. package/vite.config.ts +17 -0
@@ -0,0 +1,80 @@
1
+ // this file is to make testing easier only.
2
+
3
+ import { spawn } from "child_process";
4
+ import * as playwright from "@intuned/playwright-core";
5
+ import * as fs from "fs-extra";
6
+ import { BrowserContext } from "@intuned/playwright-core";
7
+ import { getFullPathInProject } from "./utils/fileUtils";
8
+ import { getContextStorageState } from "../../common/contextStorageStateHelpers";
9
+
10
+ export const REMOTE_DEBUGGING_PORT = 9222;
11
+
12
+ export const getChromiumLaunchArgs = () => [
13
+ "--no-sandbox",
14
+ `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`,
15
+ `--user-data-dir=/tmp/${Date.now()}`,
16
+ "--new-window",
17
+ "--start-maximized",
18
+ "--disable-popup-blocking",
19
+ ];
20
+
21
+ // this is needed cause we need to keep the same browser instance alive between start recording and stop recording calls.
22
+ async function getBrowser() {
23
+ let playwrightBrowser: playwright.Browser | null = null;
24
+
25
+ try {
26
+ playwrightBrowser = await playwright.chromium.connectOverCDP(
27
+ `http://localhost:${REMOTE_DEBUGGING_PORT}`
28
+ );
29
+ } catch (e) {
30
+ throw new Error("Browser is not running");
31
+ }
32
+
33
+ return playwrightBrowser;
34
+ }
35
+
36
+ export async function startOrRestartBrowser() {
37
+ const chromiumPath = await playwright.chromium.executablePath();
38
+
39
+ const chromeInstanceProcess = spawn(chromiumPath, getChromiumLaunchArgs());
40
+
41
+ chromeInstanceProcess.stdout.on("data", (data) => {
42
+ console.log(`Chrome stdout: ${data}`);
43
+ });
44
+
45
+ chromeInstanceProcess.stderr.on("data", (data) => {
46
+ console.error(`Chrome stderr: ${data}`);
47
+ });
48
+ }
49
+
50
+ export interface SessionState {
51
+ cookies: any[];
52
+ storage: Record<string, { localStorage: any; sessionStorage: any }>;
53
+ }
54
+
55
+ export async function saveSessionFromOpenedBrowser(path: string) {
56
+ const browser = await getBrowser();
57
+ const context = await browser.contexts()[0];
58
+
59
+ return saveSession(path, context);
60
+ }
61
+
62
+ export async function loadState(path: string, context: BrowserContext) {
63
+ const fullPath = getFullPathInProject(path);
64
+ if (!(await fs.pathExists(fullPath))) {
65
+ throw new Error("session file does not exist");
66
+ }
67
+
68
+ const data: SessionState = await fs.readJson(fullPath);
69
+
70
+ await context.addCookies(data.cookies);
71
+
72
+ // ToDo: logic to load storage without using the page.
73
+ }
74
+
75
+ export async function saveSession(path: string, context: BrowserContext) {
76
+ const fullState = await getContextStorageState(context);
77
+ const fullPath = getFullPathInProject(path);
78
+ fs.ensureFileSync(fullPath);
79
+ await fs.writeJSON(fullPath, fullState);
80
+ }
@@ -0,0 +1,13 @@
1
+ export async function getDefaultExportFromFile(apiFilePath: string) {
2
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
3
+ require("ts-node").register({
4
+ transpileOnly: true,
5
+ compilerOptions: {
6
+ lib: ["dom", "es2020"],
7
+ },
8
+ });
9
+
10
+ const imported = await import(apiFilePath);
11
+ const defaultExport = imported.default;
12
+ return defaultExport;
13
+ }
@@ -0,0 +1,274 @@
1
+ import { expect, describe, it, beforeAll, afterAll } from "vitest";
2
+ import getFirstLineNumber from "./getFirstLineNumber";
3
+ import * as fs from "fs";
4
+ import * as path from "path";
5
+
6
+ describe("getFirstLineNumber", () => {
7
+ const testFilesDir = path.join(__dirname, "testFiles");
8
+ const createTestFile = (fileName: string, content: string) => {
9
+ const filePath = path.join(testFilesDir, fileName);
10
+ fs.writeFileSync(filePath, content);
11
+ return filePath;
12
+ };
13
+
14
+ beforeAll(() => {
15
+ if (!fs.existsSync(testFilesDir)) {
16
+ fs.mkdirSync(testFilesDir);
17
+ }
18
+ });
19
+
20
+ afterAll(() => {
21
+ fs.readdirSync(testFilesDir).forEach((file) =>
22
+ fs.unlinkSync(path.join(testFilesDir, file))
23
+ );
24
+ fs.rmdirSync(testFilesDir);
25
+ });
26
+
27
+ it("correctly identifies first line in a default exported named function", async () => {
28
+ const filePath = createTestFile(
29
+ "defaultFunction.ts",
30
+ `import {
31
+ EnhancedPlaywrightPage,
32
+ EnhancedPlaywrightBrowserContext,
33
+ ExecutionHelpers,
34
+ } from "@intuned/runner";
35
+ interface Params {
36
+ name: string;
37
+ [key: string]: string | number | undefined;
38
+ }
39
+ export default async function runApi(
40
+ params: Params,
41
+ page: EnhancedPlaywrightPage,
42
+ context: EnhancedPlaywrightBrowserContext,
43
+ executionHelpers: ExecutionHelpers
44
+ ) {
45
+ await page.goto("https://www.wikipedia.org/");
46
+ await page.getByLabel("Search Wikipedia").click();
47
+ await page.getByLabel("Search Wikipedia").type(params.name);
48
+ await page.getByLabel("Search Wikipedia").press("Enter");
49
+ return { done: "true", name: "custom name from api1" };
50
+ }
51
+ `
52
+ );
53
+ const result = await getFirstLineNumber(filePath);
54
+ expect(result.lineNumber).toBe(4); // 4 is the index after it's compiled to commonjs
55
+ });
56
+
57
+ it("correctly identifies first line in a default exported anonymous function", async () => {
58
+ const filePath = createTestFile(
59
+ "defaultFunction.ts",
60
+ `import {
61
+ EnhancedPlaywrightPage,
62
+ EnhancedPlaywrightBrowserContext,
63
+ ExecutionHelpers,
64
+ } from "@intuned/runner";
65
+ interface Params {
66
+ name: string;
67
+ [key: string]: string | number | undefined;
68
+ }
69
+ export default async function(
70
+ params: Params,
71
+ page: EnhancedPlaywrightPage,
72
+ context: EnhancedPlaywrightBrowserContext,
73
+ executionHelpers: ExecutionHelpers
74
+ ) {
75
+ await page.goto("https://www.wikipedia.org/");
76
+ await page.getByLabel("Search Wikipedia").click();
77
+ await page.getByLabel("Search Wikipedia").type(params.name);
78
+ await page.getByLabel("Search Wikipedia").press("Enter");
79
+ return { done: "true", name: "custom name from api1" };
80
+ }
81
+ `
82
+ );
83
+ const result = await getFirstLineNumber(filePath);
84
+ expect(result.lineNumber).toBe(4);
85
+ });
86
+
87
+ it("correctly identifies first line in a default exported function identifier", async () => {
88
+ const filePath = createTestFile(
89
+ "defaultFunction.ts",
90
+ `import {
91
+ EnhancedPlaywrightPage,
92
+ EnhancedPlaywrightBrowserContext,
93
+ ExecutionHelpers,
94
+ } from "@intuned/runner";
95
+ interface Params {
96
+ name: string;
97
+ [key: string]: string | number | undefined;
98
+ }
99
+ async function runApi(
100
+ params: Params,
101
+ page: EnhancedPlaywrightPage,
102
+ context: EnhancedPlaywrightBrowserContext,
103
+ executionHelpers: ExecutionHelpers
104
+ ) {
105
+ await page.goto("https://www.wikipedia.org/");
106
+ await page.getByLabel("Search Wikipedia").click();
107
+ await page.getByLabel("Search Wikipedia").type(params.name);
108
+ await page.getByLabel("Search Wikipedia").press("Enter");
109
+ return { done: "true", name: "custom name from api1" };
110
+ }
111
+ export default runApi;
112
+ `
113
+ );
114
+ const result = await getFirstLineNumber(filePath);
115
+ expect(result.lineNumber).toBe(4);
116
+ });
117
+
118
+ it("correctly identifies first line in a file with multiple exports including a default function", async () => {
119
+ const filePath = createTestFile(
120
+ "multipleExports.ts",
121
+ `import {
122
+ EnhancedPlaywrightPage,
123
+ EnhancedPlaywrightBrowserContext,
124
+ ExecutionHelpers,
125
+ } from "@intuned/runner";
126
+ interface Params {
127
+ name: string;
128
+ [key: string]: string | number | undefined;
129
+ }
130
+ export const foo = () => {};
131
+ async function runApi(
132
+ params: Params,
133
+ page: EnhancedPlaywrightPage,
134
+ context: EnhancedPlaywrightBrowserContext,
135
+ executionHelpers: ExecutionHelpers
136
+ ) {
137
+ await page.goto("https://www.wikipedia.org/");
138
+ await page.getByLabel("Search Wikipedia").click();
139
+ await page.getByLabel("Search Wikipedia").type(params.name);
140
+ await page.getByLabel("Search Wikipedia").press("Enter");
141
+ return { done: "true", name: "custom name from api1" };
142
+ }
143
+ export default runApi;`
144
+ );
145
+ const result = await getFirstLineNumber(filePath);
146
+ expect(result.lineNumber).toBe(7);
147
+ });
148
+
149
+ it("correctly identifies first line in a default exported arrow function identifier", async () => {
150
+ const filePath = createTestFile(
151
+ "multipleExports.ts",
152
+ `import {
153
+ EnhancedPlaywrightPage,
154
+ EnhancedPlaywrightBrowserContext,
155
+ ExecutionHelpers,
156
+ } from "@intuned/runner";
157
+ interface Params {
158
+ name: string;
159
+ [key: string]: string | number | undefined;
160
+ }
161
+ const runApi = async (
162
+ params: Params,
163
+ page: EnhancedPlaywrightPage,
164
+ context: EnhancedPlaywrightBrowserContext,
165
+ executionHelpers: ExecutionHelpers
166
+ ) => {
167
+ await page.goto("https://www.wikipedia.org/");
168
+ await page.getByLabel("Search Wikipedia").click();
169
+ await page.getByLabel("Search Wikipedia").type(params.name);
170
+ await page.getByLabel("Search Wikipedia").press("Enter");
171
+ return { done: "true", name: "custom name from api1" };
172
+ }
173
+ export default runApi;`
174
+ );
175
+ const result = await getFirstLineNumber(filePath);
176
+ expect(result.lineNumber).toBe(4);
177
+ });
178
+
179
+ it("correctly identifies first line in a default exported anonymous arrow function", async () => {
180
+ const filePath = createTestFile(
181
+ "multipleExports.ts",
182
+ `import {
183
+ EnhancedPlaywrightPage,
184
+ EnhancedPlaywrightBrowserContext,
185
+ ExecutionHelpers,
186
+ } from "@intuned/runner";
187
+ interface Params {
188
+ name: string;
189
+ [key: string]: string | number | undefined;
190
+ }
191
+ export default async (
192
+ params: Params,
193
+ page: EnhancedPlaywrightPage,
194
+ context: EnhancedPlaywrightBrowserContext,
195
+ executionHelpers: ExecutionHelpers
196
+ ) => {
197
+ await page.goto("https://www.wikipedia.org/");
198
+ await page.getByLabel("Search Wikipedia").click();
199
+ await page.getByLabel("Search Wikipedia").type(params.name);
200
+ await page.getByLabel("Search Wikipedia").press("Enter");
201
+ return { done: "true", name: "custom name from api1" };
202
+ };`
203
+ );
204
+ const result = await getFirstLineNumber(filePath);
205
+ expect(result.lineNumber).toBe(4);
206
+ });
207
+
208
+ it("identifies first executable line in a default exported arrow function", async () => {
209
+ const filePath = createTestFile(
210
+ "defaultArrowFunction.ts",
211
+ `export default () => {
212
+ console.log("Hello, Arrow World!");
213
+ };`
214
+ );
215
+ const result = await getFirstLineNumber(filePath);
216
+ expect(result.lineNumber).toBe(4);
217
+ });
218
+
219
+ it("identifies first executable line within nested functions of a default export", async () => {
220
+ const filePath = createTestFile(
221
+ "nestedFunctions.ts",
222
+ `const x = 4;
223
+ export default function() {
224
+ const nested = (x) => console.log("Nested function call");
225
+ nested(x);
226
+ }`
227
+ );
228
+ const result = await getFirstLineNumber(filePath);
229
+ expect(result.lineNumber).toBe(5);
230
+ });
231
+
232
+ it("handles async default exported function correctly", async () => {
233
+ const filePath = createTestFile(
234
+ "asyncDefaultFunction.ts",
235
+ `export default async function() {
236
+ await Promise.resolve(console.log("Async Hello, World!"));
237
+ }`
238
+ );
239
+ const result = await getFirstLineNumber(filePath);
240
+ expect(result.lineNumber).toBe(4);
241
+ });
242
+
243
+ it("returns -1 for a default exported class", async () => {
244
+ const filePath = createTestFile(
245
+ "defaultClass.ts",
246
+ `export default class MyClass {
247
+ constructor() {}
248
+ }`
249
+ );
250
+ const result = await getFirstLineNumber(filePath);
251
+ expect(result.lineNumber).toBe(-1);
252
+ });
253
+
254
+ it("returns -1 for a default exported variable", async () => {
255
+ const filePath = createTestFile("defaultVariable.ts", `export default 42;`);
256
+ const result = await getFirstLineNumber(filePath);
257
+ expect(result.lineNumber).toBe(-1);
258
+ });
259
+
260
+ it("returns -1 when there is no default export", async () => {
261
+ const filePath = createTestFile(
262
+ "noDefaultExport.ts",
263
+ `export const foo = () => console.log("bar");`
264
+ );
265
+ const result = await getFirstLineNumber(filePath);
266
+ expect(result.lineNumber).toBe(-1);
267
+ });
268
+
269
+ it("returns -1 for an empty file", async () => {
270
+ const filePath = createTestFile("emptyFile.ts", ``);
271
+ const result = await getFirstLineNumber(filePath);
272
+ expect(result.lineNumber).toBe(-1);
273
+ });
274
+ });
@@ -0,0 +1,146 @@
1
+ import {
2
+ ts,
3
+ Project,
4
+ CompilerOptions,
5
+ ModuleKind,
6
+ ScriptTarget,
7
+ FunctionDeclaration,
8
+ SourceFile,
9
+ Node,
10
+ } from "ts-morph";
11
+ import { SourceMapConsumer } from "source-map";
12
+
13
+ function compileTypeScript(apiFilePath: string) {
14
+ const compilerOptions: CompilerOptions = {
15
+ lib: ["dom", "es2020"],
16
+ sourceMap: true,
17
+ inlineSourceMap: true,
18
+ inlineSources: true,
19
+ declaration: false,
20
+ noEmit: false,
21
+ module: ModuleKind.CommonJS,
22
+ target: ScriptTarget.ES2020,
23
+ };
24
+ const project = new Project({
25
+ compilerOptions,
26
+ });
27
+ const sourceFile = project.addSourceFileAtPath(apiFilePath);
28
+ const outputJS = project.emitToMemory({ targetSourceFile: sourceFile });
29
+ const outputJSText = outputJS.getFiles()[0].text;
30
+ return { sourceFile, outputJSText };
31
+ }
32
+
33
+ export function findFirstExecutableLine(sourceFile: SourceFile) {
34
+ let functionBody: ReturnType<FunctionDeclaration["getBody"]>;
35
+
36
+ // Directly find the default exported function's body
37
+ const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
38
+ const defaultExportDeclaration = defaultExportSymbol?.getDeclarations()?.[0];
39
+ if (defaultExportDeclaration) {
40
+ // Check if the default export is a function
41
+ if (
42
+ defaultExportDeclaration.getKind() === ts.SyntaxKind.FunctionDeclaration
43
+ ) {
44
+ functionBody = (
45
+ defaultExportDeclaration as FunctionDeclaration
46
+ ).getBody();
47
+ } else {
48
+ // Handle ExportAssignment specifically for cases like `export default identifier;`
49
+ const exportAssignments = sourceFile.getExportAssignments();
50
+ for (const exportAssignment of exportAssignments) {
51
+ const expression = exportAssignment.getExpression();
52
+ if (!expression) continue;
53
+
54
+ if (
55
+ expression.getKind() === ts.SyntaxKind.Identifier ||
56
+ expression.getKind() === ts.SyntaxKind.FunctionExpression ||
57
+ expression.getKind() === ts.SyntaxKind.ArrowFunction
58
+ ) {
59
+ const identifier = expression.getText();
60
+ const possiblyExportedFunction =
61
+ sourceFile.getFunction(identifier) ||
62
+ (sourceFile
63
+ .getVariableStatement(identifier)
64
+ ?.getDescendants()
65
+ .find(
66
+ (node) =>
67
+ node.getKind() === ts.SyntaxKind.FunctionExpression ||
68
+ node.getKind() === ts.SyntaxKind.ArrowFunction
69
+ ) as FunctionDeclaration);
70
+ if (possiblyExportedFunction) {
71
+ functionBody = possiblyExportedFunction.getBody();
72
+ break;
73
+ }
74
+ }
75
+ if (
76
+ Node.hasBody(expression) &&
77
+ (expression.getKind() === ts.SyntaxKind.FunctionExpression ||
78
+ expression.getKind() === ts.SyntaxKind.ArrowFunction)
79
+ ) {
80
+ // As these are anonymous, we directly access their body
81
+ functionBody = expression.getBody() as ReturnType<
82
+ FunctionDeclaration["getBody"]
83
+ >;
84
+ break;
85
+ }
86
+ }
87
+ }
88
+ }
89
+ if (!functionBody || !Node.isStatemented(functionBody)) {
90
+ return -1;
91
+ }
92
+ if (functionBody.getStatements().length === 0) {
93
+ return -1;
94
+ }
95
+ const position = functionBody.getStatements()[0].getStart();
96
+ return sourceFile.getLineAndColumnAtPos(position);
97
+ }
98
+
99
+ async function getSourceMap(jsCode: string) {
100
+ const sourceMapBase64 = jsCode.substring(
101
+ jsCode.lastIndexOf("//# sourceMappingURL=data:application/json;base64,") +
102
+ "//# sourceMappingURL=data:application/json;base64,".length
103
+ );
104
+ const sourceMapText = Buffer.from(sourceMapBase64, "base64").toString(
105
+ "utf-8"
106
+ );
107
+ const sourceMap = JSON.parse(sourceMapText);
108
+ return new SourceMapConsumer(sourceMap);
109
+ }
110
+
111
+ async function mapFirstLineNumberBySourceMap(
112
+ sourceFileName: string,
113
+ jsCode: string,
114
+ line: number,
115
+ column: number
116
+ ) {
117
+ const sourceMap = await getSourceMap(jsCode);
118
+ const generatedLineNumber = sourceMap.generatedPositionFor({
119
+ source: sourceFileName,
120
+ line,
121
+ column,
122
+ }).line;
123
+ if (!generatedLineNumber) return -1;
124
+ return generatedLineNumber;
125
+ }
126
+
127
+ export default async function getFirstLineNumber(apiFilePath: string) {
128
+ const sourceFileName = apiFilePath.split("/").pop() ?? apiFilePath;
129
+
130
+ // Compile TypeScript to JavaScript and get the Typescript AST
131
+ const { sourceFile, outputJSText } = compileTypeScript(apiFilePath);
132
+
133
+ // Find the first line of code in the default export ts code
134
+ const result = findFirstExecutableLine(sourceFile);
135
+ if (result === -1) return { sourceFileName, lineNumber: -1 };
136
+
137
+ return {
138
+ sourceFileName,
139
+ lineNumber: await mapFirstLineNumberBySourceMap(
140
+ sourceFileName,
141
+ outputJSText,
142
+ result.line,
143
+ result.column
144
+ ),
145
+ };
146
+ }
@@ -0,0 +1,8 @@
1
+ // Send information to the parent process where it should continue the debugger
2
+ // This is handled by DebuggingProcessManager
3
+ export const sendBreakPointOnToClient = (
4
+ sourceFileName: string,
5
+ lineNumber: number
6
+ ) => {
7
+ console.log(`breakpoint on ${sourceFileName}:${lineNumber}`);
8
+ };
@@ -0,0 +1,25 @@
1
+ import * as path from "path";
2
+ import * as fs from "fs-extra";
3
+ import dotenv from "dotenv";
4
+
5
+ dotenv.config();
6
+
7
+ // TODO: todo-identity handle identity instances
8
+ export function getFullPathInProject(...paths: string[]) {
9
+ return path.resolve(process.cwd(), process.env.ROOT || "./", ...paths);
10
+ }
11
+
12
+ export async function listProjectFilesAndFolders() {
13
+ const projectPath = path.resolve(process.cwd(), process.env.ROOT || "./");
14
+ try {
15
+ const files = await fs.readdir(projectPath, { withFileTypes: true });
16
+ return files.map((file) => ({
17
+ type: file.isDirectory() ? ("Folder" as const) : ("File" as const),
18
+ fullPath: path.join(projectPath, file.name),
19
+ name: file.name,
20
+ }));
21
+ } catch (err) {
22
+ console.error("Error reading the directory:", err);
23
+ throw err;
24
+ }
25
+ }
@@ -0,0 +1,23 @@
1
+ import { getFullPathInProject } from "./fileUtils";
2
+ import {
3
+ IntunedSettings,
4
+ settingsSchema,
5
+ } from "../../../common/settingsSchema";
6
+
7
+ export async function getSettings(): Promise<IntunedSettings> {
8
+ const settingsFilePath = getFullPathInProject("Intuned.json");
9
+ console.log("loading settings");
10
+
11
+ const settings = await import(settingsFilePath);
12
+ if (settings.default) {
13
+ const parsed = settingsSchema.safeParse(settings.default);
14
+ if (parsed.success) {
15
+ return parsed.data;
16
+ } else {
17
+ // ToDo: why does the type not work here?
18
+ throw new Error((parsed as any).error.message);
19
+ }
20
+ }
21
+
22
+ return { authSessions: { enabled: false } };
23
+ }
@@ -0,0 +1,46 @@
1
+ import * as fs from "fs-extra";
2
+ import * as path from "path";
3
+
4
+ import { getFullPathInProject, listProjectFilesAndFolders } from "./fileUtils";
5
+
6
+ export const moveWebTemplateFiles = async () => {
7
+ await fs.remove("./intuned");
8
+ await fs.ensureDir("./intuned");
9
+
10
+ const currentFileLocation = path.resolve(
11
+ __dirname,
12
+ "..",
13
+ "..",
14
+ "..",
15
+ "..",
16
+ "WebTemplate"
17
+ );
18
+
19
+ // copy WebTemplate to ./intuned
20
+ await fs.copy(`${currentFileLocation}`, "./intuned/WebTemplate", {
21
+ filter: (src, dest) => {
22
+ if (src.includes(".d.ts")) {
23
+ return false;
24
+ }
25
+
26
+ return true;
27
+ },
28
+ });
29
+
30
+ const filesAndFolders = await listProjectFilesAndFolders();
31
+ const pathsIgnoreList = [
32
+ getFullPathInProject("intuned"),
33
+ getFullPathInProject("node_modules"),
34
+ getFullPathInProject("package.json"),
35
+ getFullPathInProject("yarn.lock"),
36
+ getFullPathInProject(".env"),
37
+ ];
38
+
39
+ const filesToCopy = filesAndFolders.filter(
40
+ (file) => !pathsIgnoreList.includes(file.fullPath)
41
+ );
42
+
43
+ for (const file of filesToCopy) {
44
+ await fs.copy(file.fullPath, `./intuned/WebTemplate/${file.name}`);
45
+ }
46
+ };
@@ -0,0 +1,29 @@
1
+ import * as fs from "fs-extra";
2
+ import dotenv from "dotenv";
3
+ // import { getPageVisiblePageHtml } from "../../common/playwrightPageHelpers";
4
+ import { getPlaywrightConstructsForMode } from "../../common/getPlaywrightConstructs";
5
+
6
+ dotenv.config({
7
+ path: `.env`,
8
+ });
9
+
10
+ async function main() {
11
+ const { page } = await getPlaywrightConstructsForMode(
12
+ "playwright",
13
+ undefined
14
+ );
15
+
16
+ await page.goto(
17
+ "https://www.marriott.com/search/findHotels.mi?roomTypeCode=&recordsPerPage=20&autoSuggestItemType=&destinationAddress.types=locality,political&destinationAddress.latitude=47.6061389&propertyCode=&destinationAddress.stateProvinceShort=&isInternalSearch=true&destinationAddress.cityPopulation=&vsInitialRequest=false&searchType=InCity&destinationAddress.locality=&showAddressPin=&miniStoreFormSubmit=&destinationAddress.stateProvinceDisplayName=&destinationAddress.destinationPageDestinationAddress=&countryName=&destinationAddress.stateProvince=WA&searchRadius=50.0&singleSearchAutoSuggest=Unmatched&missingcheckInDateMsg=Please+enter+a+check-in+date.&destinationAddress.placeId=ChIJVTPokywQkFQRmtVEaUZlJRA&is-hotelsnearme-clicked=false&destinationAddress.addressline1=&airportName=&for-hotels-nearme=Near&missingcheckOutDateMsg=Please+enter+a+check-out+date.&suggestionsPropertyCode=&pageType=advanced&destinationAddress.country=US&destinationAddress.name=&poiCity=&destinationAddress.countryShort=&marriottBrands=&poiName=&destinationAddress.address=Seattle,+WA,+USA&search-countryRegion=&collapseAccordian=is-hidden&singleSearch=true&destinationAddress.cityPopulationDensity=&destinationAddress.secondaryText=WA,+USA&destinationAddress.postalCode=&destinationAddress.city=Seattle&destinationAddress.mainText=Seattle&airportCode=&isTransient=true&destinationAddress.longitude=-122.3328481&initialRequest=false&destinationAddress.website=https://maps.google.com/?q=Seattle,+WA,+USA&ftid=0x5490102c93e83355:0x102565466944d59a&search-locality=&dimensions=0&roomTypeCode=&propertyCode=&flexibleDateSearchRateDisplay=false&propertyName=&isSearch=true&marriottRewardsNumber=&isRateCalendar=false&incentiveType_Number=&incentiveType=&flexibleDateLowestRateMonth=&flexibleDateLowestRateDate=&marrOfferId=&isMultiRateSearch=&multiRateMaxCount=&multiRateCorpCodes=&useMultiRateRewardsPoints=&multiRateClusterCodes=&multiRateCorpCodesEntered=&lowestRegularRate=&js-location-nearme-values=&destinationAddress.destination=Seattle,+WA,+USA&fromToDate=10/07/2023&fromToDate_submit=10/08/2023&fromDate=10/07/2023&toDate=10/08/2023&toDateDefaultFormat=10/08/2023&fromDateDefaultFormat=10/07/2023&flexibleDateSearch=false&isHideFlexibleDateCalendar=false&t-start=2023-10-07&t-end=2023-10-08&lengthOfStay=1&roomCountBox=1+Room&roomCount=1&guestCountBox=1+Adult+Per+Room&numAdultsPerRoom=1&childrenCountBox=0+Children+Per+Room&childrenCount=0&childrenAges=&clusterCode=none&corporateCode=&useRewardsPoints=true&view=list#/0/",
18
+ { waitUntil: "load" }
19
+ );
20
+ await page.waitForTimeout(10000);
21
+
22
+ const html = ""; // await getPageVisiblePageHtml(page);
23
+
24
+ await fs.writeFile("./htmlFiles/marriott.html", html);
25
+
26
+ process.exit();
27
+ }
28
+
29
+ void main();