@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
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var ts = _interopRequireWildcard(require("typescript"));
5
+ var _commander = require("commander");
6
+ var fs = _interopRequireWildcard(require("fs-extra"));
7
+ var path = _interopRequireWildcard(require("path"));
8
+ var _webTemplate = require("./common/utils/webTemplate");
9
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
10
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
11
+ _commander.program.description("Check TypeScript types in the project").allowUnknownOption().action(async () => {
12
+ await (0, _webTemplate.moveWebTemplateFiles)();
13
+ const templateTsConfig = path.resolve(__dirname, "..", "..", "template.tsconfig.json");
14
+ await fs.copy(templateTsConfig, "./intuned/WebTemplate/tsconfig.json");
15
+ checkTypes();
16
+ });
17
+ function checkTypes() {
18
+ const configPath = ts.findConfigFile("./intuned/WebTemplate", ts.sys.fileExists, "tsconfig.json");
19
+ if (!configPath) {
20
+ console.error("Could not find a valid 'tsconfig.json'.");
21
+ process.exit(1);
22
+ }
23
+ const readConfigResult = ts.readConfigFile(configPath, ts.sys.readFile);
24
+ const config = readConfigResult.config;
25
+ const parseConfigHost = {
26
+ useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
27
+ readDirectory: ts.sys.readDirectory,
28
+ fileExists: ts.sys.fileExists,
29
+ readFile: ts.sys.readFile
30
+ };
31
+ const parsed = ts.parseJsonConfigFileContent(config, parseConfigHost, "./intuned");
32
+ const program = ts.createProgram(parsed.fileNames, parsed.options);
33
+ const emitResult = program.emit();
34
+ const allDiagnostics = ts.getPreEmitDiagnostics(program).concat(emitResult.diagnostics);
35
+ allDiagnostics.forEach(diagnostic => {
36
+ if (diagnostic.file) {
37
+ const {
38
+ line,
39
+ character
40
+ } = ts.getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
41
+ const message = ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n");
42
+ console.log(`${diagnostic.file.fileName} (${line + 1},${character + 1}): ${message}`);
43
+ } else {
44
+ console.log(ts.flattenDiagnosticMessageText(diagnostic.messageText, "\n"));
45
+ }
46
+ });
47
+ if (allDiagnostics.length === 0) {
48
+ console.log("✨ TypeScript type checking passed without errors.");
49
+ } else {
50
+ console.error("Errors found during TypeScript type checking.");
51
+ process.exit(1);
52
+ }
53
+ }
54
+ _commander.program.parse(process.argv);
@@ -0,0 +1,12 @@
1
+ import { LogEntry, LogMetadata } from "./types";
2
+ declare class Logger {
3
+ logFunction(entry: LogEntry): void;
4
+ private log;
5
+ trace(message: string, meta?: LogMetadata): void;
6
+ debug(message: string, meta?: LogMetadata): void;
7
+ info(message: string, meta?: LogMetadata): void;
8
+ warn(message: string, meta?: LogMetadata): void;
9
+ error(message: string, meta?: LogMetadata): void;
10
+ }
11
+ export declare const logger: Logger;
12
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.logger = void 0;
7
+ var _nodeUtil = require("node:util");
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const format = _nodeUtil.formatWithOptions.bind(undefined, {
11
+ colors: true
12
+ });
13
+ const LOG_LEVEL_COLORS = {
14
+ TRACE: _chalk.default.gray,
15
+ DEBUG: _chalk.default.blue,
16
+ INFO: _chalk.default.green,
17
+ WARN: _chalk.default.yellow,
18
+ ERROR: _chalk.default.red
19
+ };
20
+ class Logger {
21
+ logFunction(entry) {
22
+ const {
23
+ level,
24
+ timestamp,
25
+ message,
26
+ meta
27
+ } = entry;
28
+ const date = new Date(timestamp);
29
+ const levelColor = LOG_LEVEL_COLORS[level];
30
+ if (meta === undefined) {
31
+ process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
32
+ } else {
33
+ process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
34
+ }
35
+ }
36
+ log(level, message, meta) {
37
+ this.logFunction({
38
+ level,
39
+ message,
40
+ meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
41
+ timestamp: Date.now()
42
+ });
43
+ }
44
+ trace(message, meta) {
45
+ this.log("TRACE", message, meta);
46
+ }
47
+ debug(message, meta) {
48
+ this.log("DEBUG", message, meta);
49
+ }
50
+ info(message, meta) {
51
+ this.log("INFO", message, meta);
52
+ }
53
+ warn(message, meta) {
54
+ this.log("WARN", message, meta);
55
+ }
56
+ error(message, meta) {
57
+ this.log("ERROR", message, meta);
58
+ }
59
+ }
60
+ const logger = exports.logger = new Logger();
@@ -1,9 +1,8 @@
1
1
  export type LogLevel = "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR";
2
2
  export type LogMetadata = Record<string | symbol, any>;
3
-
4
3
  export interface LogEntry {
5
- level: LogLevel;
6
- message: string;
7
- timestamp: number;
8
- meta?: LogMetadata;
4
+ level: LogLevel;
5
+ message: string;
6
+ timestamp: number;
7
+ meta?: LogMetadata;
9
8
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,12 @@
1
+ import { LogEntry, LogMetadata } from "./types";
2
+ declare class Logger {
3
+ logFunction(entry: LogEntry): void;
4
+ private log;
5
+ trace(message: string, meta?: LogMetadata): void;
6
+ debug(message: string, meta?: LogMetadata): void;
7
+ info(message: string, meta?: LogMetadata): void;
8
+ warn(message: string, meta?: LogMetadata): void;
9
+ error(message: string, meta?: LogMetadata): void;
10
+ }
11
+ export declare const logger: Logger;
12
+ export {};
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.logger = void 0;
7
+ var _nodeUtil = require("node:util");
8
+ var _chalk = _interopRequireDefault(require("chalk"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ const format = _nodeUtil.formatWithOptions.bind(undefined, {
11
+ colors: true
12
+ });
13
+ const LOG_LEVEL_COLORS = {
14
+ TRACE: _chalk.default.gray,
15
+ DEBUG: _chalk.default.blue,
16
+ INFO: _chalk.default.green,
17
+ WARN: _chalk.default.yellow,
18
+ ERROR: _chalk.default.red
19
+ };
20
+ class Logger {
21
+ logFunction(entry) {
22
+ const {
23
+ level,
24
+ timestamp,
25
+ message,
26
+ meta
27
+ } = entry;
28
+ const date = new Date(timestamp);
29
+ const levelColor = LOG_LEVEL_COLORS[level];
30
+ if (meta === undefined) {
31
+ process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message}\n`);
32
+ } else {
33
+ process.stderr.write(`${format(date)} [@intuned/sdk][${levelColor(level)}] ${message} ${format(meta)}\n`);
34
+ }
35
+ }
36
+ log(level, message, meta) {
37
+ this.logFunction({
38
+ level,
39
+ message,
40
+ meta: meta && Object.keys(meta).length === 0 ? undefined : meta,
41
+ timestamp: Date.now()
42
+ });
43
+ }
44
+ trace(message, meta) {
45
+ this.log("TRACE", message, meta);
46
+ }
47
+ debug(message, meta) {
48
+ this.log("DEBUG", message, meta);
49
+ }
50
+ info(message, meta) {
51
+ this.log("INFO", message, meta);
52
+ }
53
+ warn(message, meta) {
54
+ this.log("WARN", message, meta);
55
+ }
56
+ error(message, meta) {
57
+ this.log("ERROR", message, meta);
58
+ }
59
+ }
60
+ const logger = exports.logger = new Logger();
@@ -1,9 +1,8 @@
1
1
  export type LogLevel = "TRACE" | "DEBUG" | "INFO" | "WARN" | "ERROR";
2
2
  export type LogMetadata = Record<string | symbol, any>;
3
-
4
3
  export interface LogEntry {
5
- level: LogLevel;
6
- message: string;
7
- timestamp: number;
8
- meta?: LogMetadata;
4
+ level: LogLevel;
5
+ message: string;
6
+ timestamp: number;
7
+ meta?: LogMetadata;
9
8
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,16 @@
1
+ /// <reference types="node" />
2
+ import { AsyncLocalStorage } from "async_hooks";
3
+ import { Payload, RunInfo } from "../../runtime/export";
4
+ export declare const asyncLocalStorage: AsyncLocalStorage<InternalRunInfo>;
5
+ export declare function runWithContext<R, TArgs extends any[]>(contextData: InternalRunInfo, callback: (...args: TArgs) => R, ...args: TArgs): R;
6
+ interface TimeoutInfo {
7
+ extendTimeoutCallback?: () => Promise<void>;
8
+ timeoutDuration?: number;
9
+ timeoutTimestamp?: number;
10
+ }
11
+ export interface InternalRunInfo extends RunInfo {
12
+ extendedPayloads: Payload[];
13
+ timeoutInfo?: TimeoutInfo;
14
+ }
15
+ export declare function getExecutionContext(): InternalRunInfo | undefined;
16
+ export {};
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.asyncLocalStorage = void 0;
7
+ exports.getExecutionContext = getExecutionContext;
8
+ exports.runWithContext = runWithContext;
9
+ var _async_hooks = require("async_hooks");
10
+ const asyncLocalStorage = exports.asyncLocalStorage = new _async_hooks.AsyncLocalStorage();
11
+ function runWithContext(contextData, callback, ...args) {
12
+ return asyncLocalStorage.run(contextData, callback, ...args);
13
+ }
14
+ function getExecutionContext() {
15
+ const contextData = asyncLocalStorage.getStore();
16
+ return contextData;
17
+ }
@@ -0,0 +1 @@
1
+ export declare function cleanEnvironmentVariables(): void;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cleanEnvironmentVariables = cleanEnvironmentVariables;
7
+ function cleanEnvironmentVariables() {
8
+ Object.keys(process.env).filter(i => {
9
+ if (i.toLocaleLowerCase().startsWith("npm")) {
10
+ return true;
11
+ }
12
+ if (i.toLocaleLowerCase().startsWith("fly") && i !== "FLY_ALLOC_ID") {
13
+ return true;
14
+ }
15
+ }).forEach(i => delete process.env[i]);
16
+ }
@@ -0,0 +1 @@
1
+ export declare const AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AUTH_SESSIONS_FOLDER_NAME = void 0;
7
+ const AUTH_SESSIONS_FOLDER_NAME = exports.AUTH_SESSIONS_FOLDER_NAME = "auth-sessions";
@@ -0,0 +1,14 @@
1
+ import { BrowserContext } from "@intuned/playwright";
2
+ import * as playwright from "@intuned/playwright-core";
3
+ export interface OriginSessionStorage {
4
+ origin: string;
5
+ sessionStorage: Array<{
6
+ name: string;
7
+ value: string;
8
+ }>;
9
+ }
10
+ export type IntunedStorageState = Exclude<playwright.BrowserContextOptions["storageState"], string> & {
11
+ sessionStorage?: OriginSessionStorage[];
12
+ };
13
+ export declare function getContextStorageState(context: BrowserContext): Promise<IntunedStorageState>;
14
+ export declare function setContextStorageState(context: BrowserContext, storage: IntunedStorageState): Promise<void>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getContextStorageState = getContextStorageState;
7
+ exports.setContextStorageState = setContextStorageState;
8
+ function sessionStorageToArray(storage) {
9
+ const result = [];
10
+ for (const key in storage) {
11
+ result.push({
12
+ name: key,
13
+ value: storage[key]
14
+ });
15
+ }
16
+ return result;
17
+ }
18
+ async function getContextStorageState(context) {
19
+ const cookiesAndLocalStorage = await context.storageState();
20
+ const pages = context.pages();
21
+ const pagesSessions = [];
22
+ for (const page of pages) {
23
+ try {
24
+ const [origin, session] = await page.evaluate(() => [location.origin, sessionStorage]);
25
+ const transformed = sessionStorageToArray(session);
26
+ pagesSessions.push({
27
+ origin,
28
+ sessionStorage: transformed
29
+ });
30
+ } catch (e) {}
31
+ }
32
+ return {
33
+ ...cookiesAndLocalStorage,
34
+ sessionStorage: pagesSessions
35
+ };
36
+ }
37
+ async function setContextStorageState(context, storage) {
38
+ await context.intunedSetStorageState(storage);
39
+ const sessionStorage = storage.sessionStorage;
40
+ await context.addInitScript(storage => {
41
+ for (const {
42
+ origin,
43
+ sessionStorage
44
+ } of storage) {
45
+ if (window.location.origin === origin) {
46
+ for (const item of sessionStorage) window.sessionStorage.setItem(item.name, item.value);
47
+ }
48
+ }
49
+ }, sessionStorage);
50
+ }
@@ -0,0 +1,30 @@
1
+ import * as playwright from "@intuned/playwright-core";
2
+ import type { RunApiSession } from "./runApi";
3
+ interface Proxy {
4
+ server: string;
5
+ username: string;
6
+ password: string;
7
+ }
8
+ interface GetPlaywrightConstructsOptions {
9
+ proxy?: Proxy;
10
+ headless?: boolean;
11
+ storageState?: RunApiSession;
12
+ downloadsPath: string;
13
+ }
14
+ export declare function getProductionPlaywrightConstructs({ proxy, headless, storageState, downloadsPath, }: GetPlaywrightConstructsOptions): Promise<{
15
+ page: playwright.Page;
16
+ context: playwright.BrowserContext;
17
+ }>;
18
+ export declare function getPlaywrightConstructsForMode(mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless", cdpAddress: string | undefined, authSession?: RunApiSession): Promise<{
19
+ page: playwright.Page;
20
+ context: playwright.BrowserContext;
21
+ }>;
22
+ export declare function loadSessionToContext({ context, session, }: {
23
+ context: playwright.BrowserContext;
24
+ session: RunApiSession;
25
+ }): Promise<void>;
26
+ export declare function getRemotePlaywrightContext(cdpAddress: string): Promise<{
27
+ browser: playwright.Browser;
28
+ context: playwright.BrowserContext;
29
+ }>;
30
+ export {};
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPlaywrightConstructsForMode = getPlaywrightConstructsForMode;
7
+ exports.getProductionPlaywrightConstructs = getProductionPlaywrightConstructs;
8
+ exports.getRemotePlaywrightContext = getRemotePlaywrightContext;
9
+ exports.loadSessionToContext = loadSessionToContext;
10
+ var playwright = _interopRequireWildcard(require("@intuned/playwright-core"));
11
+ var _fsExtra = _interopRequireWildcard(require("fs-extra"));
12
+ var fs = _fsExtra;
13
+ var _contextStorageStateHelpers = require("./contextStorageStateHelpers");
14
+ var _path = _interopRequireWildcard(require("path"));
15
+ var _fileUtils = require("../commands/common/utils/fileUtils");
16
+ var _waitOn = _interopRequireDefault(require("wait-on"));
17
+ var _runtime = require("../runtime");
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
20
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
21
+ async function createUserDirWithPreferences() {
22
+ const playwrightTempDir = await (0, _fsExtra.mkdtemp)("/tmp/pw-");
23
+ const userDir = (0, _path.join)(playwrightTempDir, "userdir");
24
+ const defaultDir = (0, _path.join)(userDir, "Default");
25
+ await (0, _fsExtra.mkdir)(defaultDir, {
26
+ recursive: true
27
+ });
28
+ const preferences = {
29
+ plugins: {
30
+ always_open_pdf_externally: true
31
+ }
32
+ };
33
+ await (0, _fsExtra.writeFile)((0, _path.join)(defaultDir, "Preferences"), JSON.stringify(preferences));
34
+ return userDir;
35
+ }
36
+ async function getProductionPlaywrightConstructs({
37
+ proxy,
38
+ headless = true,
39
+ storageState,
40
+ downloadsPath
41
+ }) {
42
+ const extraArgs = ["--no-first-run", "--disable-sync", "--disable-translate", "--disable-features=TranslateUI", "--disable-features=NetworkService", "--lang=en"];
43
+ if (headless) {
44
+ extraArgs.push("--headless=new");
45
+ }
46
+ const executablePath = playwright.chromium.executablePath();
47
+ const chromium127Path = executablePath.replace("chromium-1117", "chromium-1124");
48
+ const isChrome127There = (0, _fsExtra.existsSync)(chromium127Path);
49
+ const userAgent = `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/${isChrome127There ? 127 : 125}.0.0.0 Safari/537.36`;
50
+ const userDataDir = await createUserDirWithPreferences();
51
+ const context = await playwright.chromium.launchPersistentContext(userDataDir, {
52
+ headless,
53
+ ignoreDefaultArgs: [...getChromiumLaunchArgsToIgnore(), "--headless"],
54
+ proxy,
55
+ executablePath: isChrome127There ? chromium127Path : executablePath,
56
+ args: extraArgs,
57
+ downloadsPath,
58
+ userAgent
59
+ });
60
+ context.once("close", async () => {
61
+ try {
62
+ await (0, _fsExtra.rm)(userDataDir, {
63
+ recursive: true,
64
+ force: true,
65
+ retryDelay: 1000,
66
+ maxRetries: 5
67
+ });
68
+ } catch (error) {
69
+ console.error("Failed to remove user data dir", error);
70
+ }
71
+ });
72
+ if (storageState) {
73
+ await loadSessionToContext({
74
+ context,
75
+ session: storageState
76
+ });
77
+ }
78
+ const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
79
+ await context.addInitScript({
80
+ path: assetsFile
81
+ });
82
+ let page = context.pages().at(0);
83
+ if (page) {
84
+ const scriptString = await (0, _fsExtra.readFile)(assetsFile, "utf8");
85
+ await page.evaluate(scriptString);
86
+ } else {
87
+ page = await context.newPage();
88
+ }
89
+ return {
90
+ page,
91
+ context
92
+ };
93
+ }
94
+ const getChromiumLaunchArgsToIgnore = () => ["--disable-field-trial-config", "--disable-background-networking", "--enable-features=NetworkService,NetworkServiceInProcess", "--disable-background-timer-throttling", "--disable-backgrounding-occluded-windows", "--disable-back-forward-cache", "--disable-breakpad", "--disable-client-side-phishing-detection", "--disable-component-extensions-with-background-pages", "--disable-component-update", "--no-default-browser-check", "--disable-default-apps", "--disable-dev-shm-usage", "--disable-extensions", "--disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate,TranslateUI", "--allow-pre-commit-input", "--disable-hang-monitor", "--disable-ipc-flooding-protection", "--disable-prompt-on-repost", "--disable-renderer-backgrounding", "--force-color-profile=srgb", "--metrics-recording-only", "--no-first-run", "--enable-automation", "--password-store=basic", "--use-mock-keychain", "--no-service-autorun", "--export-tagged-pdf", "--enable-use-zoom-for-dsf=false"];
95
+ async function getPlaywrightConstructsForMode(mode, cdpAddress, authSession) {
96
+ if (mode == "playwright-standalone") {
97
+ if (!cdpAddress) {
98
+ throw new Error("cdpAddress is required");
99
+ }
100
+ const {
101
+ context
102
+ } = await getRemotePlaywrightContext(cdpAddress);
103
+ if (!context) {
104
+ throw new Error("no context found");
105
+ }
106
+ const assetsFile = _path.default.join(__dirname, "./assets/browser_scripts.js");
107
+ await context.addInitScript({
108
+ path: assetsFile
109
+ });
110
+ const pages = await context.pages();
111
+ let page = null;
112
+ if (pages.length > 0) {
113
+ page = pages[0];
114
+ const scriptString = await fs.readFile(assetsFile, "utf8");
115
+ await page.evaluate(scriptString);
116
+ } else {
117
+ page = await context.newPage();
118
+ }
119
+ if (authSession) {
120
+ await loadSessionToContext({
121
+ context,
122
+ session: authSession
123
+ });
124
+ }
125
+ return {
126
+ page,
127
+ context
128
+ };
129
+ }
130
+ const downloadsPath = (0, _runtime.getDownloadDirectoryPath)();
131
+ if (mode === "playwright" || mode === "playwright-headless") {
132
+ const productionConstructs = await getProductionPlaywrightConstructs({
133
+ headless: mode === "playwright-headless",
134
+ downloadsPath
135
+ });
136
+ if (authSession) {
137
+ await loadSessionToContext({
138
+ context: productionConstructs.context,
139
+ session: authSession
140
+ });
141
+ }
142
+ return {
143
+ ...productionConstructs
144
+ };
145
+ }
146
+ throw "invalid mode";
147
+ }
148
+ async function loadSessionToContext({
149
+ context,
150
+ session
151
+ }) {
152
+ let sessionToLoad;
153
+ if (session.type === "state") {
154
+ sessionToLoad = session.state;
155
+ } else {
156
+ const fullPath = (0, _fileUtils.getFullPathInProject)(session.path);
157
+ sessionToLoad = await fs.readJson(fullPath);
158
+ }
159
+ await (0, _contextStorageStateHelpers.setContextStorageState)(context, sessionToLoad);
160
+ }
161
+ async function getRemotePlaywrightContext(cdpAddress) {
162
+ const playwright = await Promise.resolve().then(() => _interopRequireWildcard(require("@intuned/playwright-core")));
163
+ let browser = null;
164
+ if (!cdpAddress) {
165
+ throw new Error("cdpAddress is required");
166
+ }
167
+ const cdpAddressWithoutProtocol = cdpAddress.replace("http://", "").replace("https://", "").replace("localhost", "127.0.0.1");
168
+ try {
169
+ await (0, _waitOn.default)({
170
+ resources: [`http-get://${cdpAddressWithoutProtocol}/json/version`],
171
+ delay: 100,
172
+ interval: 100,
173
+ timeout: 5000,
174
+ tcpTimeout: 1000,
175
+ window: 1000
176
+ });
177
+ } catch (error) {
178
+ console.error("Failed to connect to the browser");
179
+ process.exit(128 + 9);
180
+ }
181
+ try {
182
+ browser = await playwright.chromium.connectOverCDP(cdpAddress);
183
+ } catch (e) {
184
+ console.log(e);
185
+ throw new Error("failed to connect to the browser");
186
+ }
187
+ const context = browser.contexts()[0];
188
+ return {
189
+ browser,
190
+ context
191
+ };
192
+ }
@@ -0,0 +1,16 @@
1
+ import fetch from "cross-fetch";
2
+ declare class JwtTokenManager {
3
+ private _token;
4
+ private tokenRefreshTimeout;
5
+ private refreshTokenPath;
6
+ constructor(refreshTokenPath: string);
7
+ get token(): string | undefined;
8
+ set token(newToken: string | undefined);
9
+ private get timeToRefresh();
10
+ private scheduleTokenRefresh;
11
+ private refreshToken;
12
+ fetchWithToken(...[input, init]: Parameters<typeof fetch>): Promise<Response>;
13
+ }
14
+ export declare const backendFunctionsTokenManager: JwtTokenManager;
15
+ export declare function callBackendFunctionWithToken(path: string, init?: Parameters<typeof fetch>[1]): Promise<Response>;
16
+ export {};