@intuned/runtime 1.0.5

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 (110) hide show
  1. package/.babelrc +21 -0
  2. package/.eslintignore +10 -0
  3. package/.eslintrc.js +39 -0
  4. package/CHANGELOG.md +7 -0
  5. package/InterfaceTemplate/index.playwright.ts +5 -0
  6. package/InterfaceTemplate/utils.ts +39 -0
  7. package/bin/intuned-api-run +2 -0
  8. package/bin/intuned-auth-session-check +2 -0
  9. package/bin/intuned-auth-session-create +2 -0
  10. package/bin/intuned-auth-session-load +2 -0
  11. package/bin/intuned-auth-session-refresh +2 -0
  12. package/bin/intuned-browser-save-state +2 -0
  13. package/bin/intuned-browser-start +2 -0
  14. package/bin/intuned-build +2 -0
  15. package/bin/intuned-ts-check +2 -0
  16. package/dist/commands/api/run.d.ts +6 -0
  17. package/dist/commands/api/run.js +115 -0
  18. package/dist/commands/auth-sessions/load.d.ts +2 -0
  19. package/dist/commands/auth-sessions/load.js +32 -0
  20. package/dist/commands/auth-sessions/run-check.d.ts +2 -0
  21. package/dist/commands/auth-sessions/run-check.js +62 -0
  22. package/dist/commands/auth-sessions/run-create.d.ts +2 -0
  23. package/dist/commands/auth-sessions/run-create.js +101 -0
  24. package/dist/commands/browser/save-state.d.ts +2 -0
  25. package/dist/commands/browser/save-state.js +17 -0
  26. package/dist/commands/browser/start-browser.d.ts +2 -0
  27. package/dist/commands/browser/start-browser.js +14 -0
  28. package/dist/commands/build.d.ts +1 -0
  29. package/dist/commands/build.js +84 -0
  30. package/dist/commands/common/browserUtils.d.ts +14 -0
  31. package/dist/commands/common/browserUtils.js +58 -0
  32. package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
  33. package/dist/commands/common/getFirstLineNumber.js +103 -0
  34. package/dist/commands/common/getFirstLineNumber.test.js +228 -0
  35. package/dist/commands/common/sendMessageToClient.d.ts +1 -0
  36. package/dist/commands/common/sendMessageToClient.js +10 -0
  37. package/dist/commands/common/tsNodeImport.d.ts +1 -0
  38. package/dist/commands/common/tsNodeImport.js +20 -0
  39. package/dist/commands/common/utils/fileUtils.d.ts +6 -0
  40. package/dist/commands/common/utils/fileUtils.js +33 -0
  41. package/dist/commands/common/utils/settings.d.ts +2 -0
  42. package/dist/commands/common/utils/settings.js +28 -0
  43. package/dist/commands/common/utils/template.d.ts +2 -0
  44. package/dist/commands/common/utils/template.js +31 -0
  45. package/dist/commands/common/utils/unixSocket.d.ts +9 -0
  46. package/dist/commands/common/utils/unixSocket.js +44 -0
  47. package/dist/commands/interface/run.d.ts +1 -0
  48. package/dist/commands/interface/run.js +214 -0
  49. package/dist/commands/ts-check.d.ts +2 -0
  50. package/dist/commands/ts-check.js +56 -0
  51. package/dist/common/Logger/Logger/index.d.ts +12 -0
  52. package/dist/common/Logger/Logger/index.js +60 -0
  53. package/dist/common/Logger/Logger/types.d.ts +8 -0
  54. package/dist/common/Logger/Logger/types.js +5 -0
  55. package/dist/common/Logger/index.d.ts +12 -0
  56. package/dist/common/Logger/index.js +60 -0
  57. package/dist/common/Logger/types.d.ts +8 -0
  58. package/dist/common/Logger/types.js +5 -0
  59. package/dist/common/assets/browser_scripts.js +2214 -0
  60. package/dist/common/asyncLocalStorage/index.d.ts +16 -0
  61. package/dist/common/asyncLocalStorage/index.js +17 -0
  62. package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
  63. package/dist/common/cleanEnvironmentVariables.js +16 -0
  64. package/dist/common/constants.d.ts +1 -0
  65. package/dist/common/constants.js +7 -0
  66. package/dist/common/contextStorageStateHelpers.d.ts +21 -0
  67. package/dist/common/contextStorageStateHelpers.js +81 -0
  68. package/dist/common/formatZodError.d.ts +2 -0
  69. package/dist/common/formatZodError.js +18 -0
  70. package/dist/common/getPlaywrightConstructs.d.ts +30 -0
  71. package/dist/common/getPlaywrightConstructs.js +196 -0
  72. package/dist/common/jwtTokenManager.d.ts +16 -0
  73. package/dist/common/jwtTokenManager.js +81 -0
  74. package/dist/common/runApi/errors.d.ts +65 -0
  75. package/dist/common/runApi/errors.js +156 -0
  76. package/dist/common/runApi/index.d.ts +12 -0
  77. package/dist/common/runApi/index.js +265 -0
  78. package/dist/common/runApi/types.d.ts +702 -0
  79. package/dist/common/runApi/types.js +74 -0
  80. package/dist/common/settingsSchema.d.ts +19 -0
  81. package/dist/common/settingsSchema.js +17 -0
  82. package/dist/common/telemetry.d.ts +3 -0
  83. package/dist/common/telemetry.js +32 -0
  84. package/dist/index.d.ts +4 -0
  85. package/dist/index.js +69 -0
  86. package/dist/runtime/RunError.d.ts +5 -0
  87. package/dist/runtime/RunError.js +19 -0
  88. package/dist/runtime/downloadDirectory.d.ts +1 -0
  89. package/dist/runtime/downloadDirectory.js +19 -0
  90. package/dist/runtime/enums.d.js +5 -0
  91. package/dist/runtime/enums.d.ts +11 -0
  92. package/dist/runtime/enums.js +18 -0
  93. package/dist/runtime/executionHelpers.test.js +53 -0
  94. package/dist/runtime/export.d.js +5 -0
  95. package/dist/runtime/export.d.ts +202 -0
  96. package/dist/runtime/extendPayload.d.ts +2 -0
  97. package/dist/runtime/extendPayload.js +21 -0
  98. package/dist/runtime/extendTimeout.d.ts +1 -0
  99. package/dist/runtime/extendTimeout.js +30 -0
  100. package/dist/runtime/index.d.ts +7 -0
  101. package/dist/runtime/index.js +53 -0
  102. package/dist/runtime/requestMoreInfo.d.ts +18 -0
  103. package/dist/runtime/requestMoreInfo.js +25 -0
  104. package/dist/runtime/runInfo.d.ts +2 -0
  105. package/dist/runtime/runInfo.js +21 -0
  106. package/package.json +136 -0
  107. package/template.tsconfig.json +14 -0
  108. package/tsconfig.eslint.json +5 -0
  109. package/tsconfig.json +24 -0
  110. package/typedoc.json +49 -0
package/.babelrc ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "presets": [
3
+ [
4
+ "@babel/preset-env",
5
+ {
6
+ "targets": {
7
+ "chrome": 115,
8
+ "node": "16"
9
+ },
10
+ "modules": "commonjs"
11
+ }
12
+ ],
13
+ "@babel/preset-typescript"
14
+ ],
15
+ "plugins": [
16
+ "babel-plugin-macros",
17
+ "@babel/plugin-transform-export-namespace-from"
18
+ ],
19
+ "sourceMaps": false,
20
+ "comments": false
21
+ }
package/.eslintignore ADDED
@@ -0,0 +1,10 @@
1
+ node_modules
2
+ dist
3
+ .eslintrc.js
4
+ *.test.ts
5
+ *.js
6
+ types-package
7
+ vite.config.ts
8
+ reports
9
+ intuned
10
+ **/*.d.ts
package/.eslintrc.js ADDED
@@ -0,0 +1,39 @@
1
+ module.exports = {
2
+ root: true,
3
+ parser: "@typescript-eslint/parser",
4
+ parserOptions: {
5
+ project: "./tsconfig.eslint.json",
6
+ tsconfigRootDir: __dirname,
7
+ },
8
+ plugins: ["@typescript-eslint", "deprecation", "prettier"],
9
+ ignorePatterns: ["src/common/browserScripts/rollup.config.mjs"],
10
+ extends: [
11
+ "eslint:recommended",
12
+ "plugin:@typescript-eslint/eslint-recommended",
13
+ "plugin:@typescript-eslint/recommended",
14
+ ],
15
+ rules: {
16
+ "@next/next/no-html-link-for-pages": 0,
17
+ "prettier/prettier": "error",
18
+
19
+ // recommended for safety
20
+ "@typescript-eslint/no-floating-promises": "error", // forgetting to await Activities and Workflow APIs is bad
21
+ "deprecation/deprecation": "warn",
22
+
23
+ // code style preference
24
+ "object-shorthand": ["warn", "always"],
25
+
26
+ // relaxed rules, for convenience
27
+ "@typescript-eslint/no-unused-vars": [
28
+ "warn",
29
+ {
30
+ argsIgnorePattern: "^_",
31
+ varsIgnorePattern: "^_",
32
+ },
33
+ ],
34
+ "@typescript-eslint/no-explicit-any": "off",
35
+ "@typescript-eslint/no-empty-interface": "off",
36
+ "@typescript-eslint/ban-ts-comment": "warn",
37
+ "no-empty": "warn",
38
+ },
39
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # UNRELEASED
2
+
3
+ -
4
+
5
+ # 1.0.3
6
+
7
+ - Fix node-fetch builds (used in deprecated `downloadFile` SDK functions).
@@ -0,0 +1,5 @@
1
+ import { runAutomationCLI } from "@intuned/runtime/dist/commands/interface/run";
2
+
3
+ import { importModule } from "./utils";
4
+
5
+ runAutomationCLI(importModule);
@@ -0,0 +1,39 @@
1
+ export async function importModule(path: string) {
2
+ const [folderName, ...functionNameParts] = path.split("/");
3
+ const functionNameDepth = functionNameParts.length;
4
+
5
+ // string literals should be inline
6
+ // currently we support only 5 levels of depth
7
+ // rollup dynamic import does not support multiple levels of dynamic imports so we need to specify the possible paths explicitly
8
+ let imported: any = undefined;
9
+ switch (functionNameDepth) {
10
+ case 1:
11
+ imported = await import(`./${folderName}/${functionNameParts[0]}.ts`);
12
+ break;
13
+ case 2:
14
+ imported = await import(
15
+ `./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}.ts`
16
+ );
17
+ break;
18
+ case 3:
19
+ imported = await import(
20
+ `./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}.ts`
21
+ );
22
+ break;
23
+ case 4:
24
+ imported = await import(
25
+ `./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}.ts`
26
+ );
27
+ break;
28
+ case 5:
29
+ imported = await import(
30
+ `./${folderName}/${functionNameParts[0]}/${functionNameParts[1]}/${functionNameParts[2]}/${functionNameParts[3]}/${functionNameParts[4]}.ts`
31
+ );
32
+ break;
33
+ default:
34
+ throw new Error(
35
+ "intuned supports maximum 5 levels of depth in the api folder"
36
+ );
37
+ }
38
+ return imported;
39
+ }
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/api/run.js");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/auth-sessions/run-check.js");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/auth-sessions/run-create.js");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/auth-sessions/load.js");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/auth-sessions/run-refresh.js");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/browser/save-state.js");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/browser/start-browser.js");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/build.js");
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ require("../dist/commands/ts-check.js");
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ export declare function executeCLI(apiName: string, mode: "vanilla" | "playwright" | "playwright-standalone" | "playwright-headless", inputData: object | null | undefined, options: {
3
+ cdpAddress: string;
4
+ authSessionPath: undefined | string;
5
+ outputFileId: string | undefined;
6
+ }): Promise<void>;
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.executeCLI = executeCLI;
8
+ var _commander = require("commander");
9
+ var fs = _interopRequireWildcard(require("fs-extra"));
10
+ var _settings = require("../common/utils/settings");
11
+ var _dotenv = _interopRequireDefault(require("dotenv"));
12
+ var _asyncLocalStorage = require("../../common/asyncLocalStorage");
13
+ var _enums = require("../../runtime/enums");
14
+ var _cleanEnvironmentVariables = require("../../common/cleanEnvironmentVariables");
15
+ var _Logger = require("../../common/Logger");
16
+ var _nanoid = require("nanoid");
17
+ var _chalk = _interopRequireDefault(require("chalk"));
18
+ var _runApi = require("../../common/runApi");
19
+ var _tsNodeImport = require("../common/tsNodeImport");
20
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
21
+ 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); }
22
+ 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 && {}.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; }
23
+ _dotenv.default.config({
24
+ path: `.env`
25
+ });
26
+ async function executeCLI(apiName, mode, inputData, options) {
27
+ (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
28
+ let authSessionPathToUse = null;
29
+ const settings = await (0, _settings.getSettings)();
30
+ if (settings.authSessions.enabled) {
31
+ if (!options.authSessionPath) {
32
+ throw new Error("Auth session is enabled but no auth session provided");
33
+ }
34
+ authSessionPathToUse = options.authSessionPath;
35
+ } else {
36
+ if (options.authSessionPath) {
37
+ throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
38
+ }
39
+ }
40
+ const runApiResult = await (0, _runApi.runApi)({
41
+ automationFunction: {
42
+ name: `api/${apiName}`,
43
+ params: inputData
44
+ },
45
+ auth: authSessionPathToUse ? {
46
+ session: {
47
+ type: "file",
48
+ path: authSessionPathToUse
49
+ },
50
+ runCheck: false
51
+ } : undefined,
52
+ runOptions: {
53
+ environment: "cdp",
54
+ cdpAddress: options.cdpAddress,
55
+ mode
56
+ },
57
+ importFunction: _tsNodeImport.tsNodeImport
58
+ });
59
+ if (runApiResult.isErr()) {
60
+ if (runApiResult.error instanceof _runApi.AutomationError) {
61
+ throw runApiResult.error.error;
62
+ }
63
+ console.error(runApiResult.error);
64
+ throw new Error("An error occurred while running the API");
65
+ }
66
+ const {
67
+ result,
68
+ extendedPayloads: payloadToAppend
69
+ } = runApiResult.value;
70
+ const isResponseObject = typeof result === "object" && result !== null;
71
+ const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
72
+ const hasNestedObjects = isResponseObject && Object.values(result).some(value => typeof value === "object");
73
+ const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
74
+ const resultsDir = "/tmp/run-results";
75
+ if (options.outputFileId && shouldWriteToFile) {
76
+ _Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
77
+ fs.ensureDirSync(resultsDir);
78
+ const path = `${resultsDir}/${options.outputFileId}.json`;
79
+ await fs.writeJson(path, result, {
80
+ spaces: 2
81
+ });
82
+ } else {
83
+ console.log("result:", result);
84
+ }
85
+ const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
86
+ if (hasPayloadToAppend && options.outputFileId) {
87
+ _Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
88
+ fs.ensureDirSync(resultsDir);
89
+ const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
90
+ await fs.writeJson(path, payloadToAppend, {
91
+ spaces: 2
92
+ });
93
+ } else if (hasPayloadToAppend) {
94
+ _Logger.logger.info("payload to append:", payloadToAppend);
95
+ _Logger.logger.info("This will only take an effect if this API run was part of a job.");
96
+ }
97
+ }
98
+ _commander.program.description("run the user function in the cli for testing purposes").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--outputFileId <outputFileId>", "the output file id to save the result in").option("--proxy <proxy>", "proxy to use").argument("[apiName]", "name of the api", "default").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone", "playwright-headless"]).default("playwright-standalone").argOptional()).action(async (apiName, mode, options) => {
99
+ let inputData = null;
100
+ if (options.input) {
101
+ inputData = await fs.readJSON(options.input);
102
+ } else if (options.json) {
103
+ inputData = JSON.parse(options.json);
104
+ } else {
105
+ inputData = {};
106
+ }
107
+ await (0, _asyncLocalStorage.runWithContext)({
108
+ runEnvironment: _enums.RunEnvironment.IDE,
109
+ extendedPayloads: [],
110
+ runId: (0, _nanoid.nanoid)(),
111
+ proxy: options.proxy
112
+ }, () => executeCLI(apiName, mode, inputData, options));
113
+ process.exit(0);
114
+ });
115
+ _commander.program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _commander = require("commander");
5
+ var _getPlaywrightConstructs = require("../../common/getPlaywrightConstructs");
6
+ var _settings = require("../common/utils/settings");
7
+ var _dotenv = _interopRequireDefault(require("dotenv"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ _dotenv.default.config({
10
+ path: `.env`
11
+ });
12
+ _commander.program.description("load auth session to browser").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the api").allowUnknownOption().action(async ({
13
+ cdpAddress,
14
+ authSessionPath
15
+ }) => {
16
+ const setting = await (0, _settings.getSettings)();
17
+ if (!setting.authSessions.enabled) {
18
+ throw new Error("Auth session is not enabled");
19
+ }
20
+ const {
21
+ context
22
+ } = await (0, _getPlaywrightConstructs.getRemotePlaywrightContext)(cdpAddress);
23
+ await (0, _getPlaywrightConstructs.loadSessionToContext)({
24
+ context,
25
+ session: {
26
+ type: "file",
27
+ path: authSessionPath
28
+ }
29
+ });
30
+ process.exit(0);
31
+ });
32
+ _commander.program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _commander = require("commander");
5
+ var fs = _interopRequireWildcard(require("fs-extra"));
6
+ var _fileUtils = require("../common/utils/fileUtils");
7
+ var _settings = require("../common/utils/settings");
8
+ var _dotenv = _interopRequireDefault(require("dotenv"));
9
+ var _constants = require("../../common/constants");
10
+ var _runApi = require("../../common/runApi");
11
+ var _tsNodeImport = require("../common/tsNodeImport");
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ 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); }
14
+ 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 && {}.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; }
15
+ _dotenv.default.config({
16
+ path: `.env`
17
+ });
18
+ _commander.program.description("run auth session check").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the check").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
19
+ cdpAddress,
20
+ authSessionPath
21
+ }) => {
22
+ const setting = await (0, _settings.getSettings)();
23
+ if (!setting.authSessions.enabled) {
24
+ throw new Error("auth session is not enabled");
25
+ }
26
+ const checkFilePath = (0, _fileUtils.getFullPathInProject)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
27
+ if (!fs.exists(checkFilePath)) {
28
+ throw new Error("auth session check file not found");
29
+ }
30
+ const runApiResult = await (0, _runApi.runApi)({
31
+ automationFunction: {
32
+ name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
33
+ },
34
+ runOptions: {
35
+ environment: "cdp",
36
+ mode,
37
+ cdpAddress
38
+ },
39
+ auth: {
40
+ session: {
41
+ type: "file",
42
+ path: authSessionPath
43
+ },
44
+ runCheck: false
45
+ },
46
+ importFunction: _tsNodeImport.tsNodeImport
47
+ });
48
+ if (runApiResult.isErr()) {
49
+ if (runApiResult.error instanceof _runApi.AutomationError) {
50
+ throw runApiResult.error.error;
51
+ }
52
+ console.error(runApiResult.error);
53
+ throw new Error("Error running auth session check");
54
+ }
55
+ const result = runApiResult.value.result;
56
+ console.log("check result", result);
57
+ if (!result) {
58
+ throw new Error("auth session check failed");
59
+ }
60
+ process.exit(0);
61
+ });
62
+ _commander.program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,101 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _commander = require("commander");
5
+ var fs = _interopRequireWildcard(require("fs-extra"));
6
+ var _promptly = require("promptly");
7
+ var _fileUtils = require("../common/utils/fileUtils");
8
+ var _settings = require("../common/utils/settings");
9
+ var _dotenv = _interopRequireDefault(require("dotenv"));
10
+ var _constants = require("../../common/constants");
11
+ var _runApi = require("../../common/runApi");
12
+ var _asyncLocalStorage = require("../../common/asyncLocalStorage");
13
+ var _nanoid = require("nanoid");
14
+ var _enums = require("../../runtime/enums");
15
+ var _tsNodeImport = require("../common/tsNodeImport");
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ 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); }
18
+ 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 && {}.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; }
19
+ _dotenv.default.config({
20
+ path: `.env`
21
+ });
22
+ _commander.program.description("run auth session create").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("-i, --input [file]", "input json file").option("-j, --json [json]", "input json string").option("--authSessionPath <authSession>", "auth session to use when executing the api").option("--pathToSave <pathToSave>", "path to save the auth session, if not provided, will discard the auth session").allowUnknownOption().addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
23
+ cdpAddress,
24
+ pathToSave,
25
+ input,
26
+ json
27
+ }) => {
28
+ let inputData = null;
29
+ if (input) {
30
+ inputData = await fs.readJSON(input);
31
+ } else if (json) {
32
+ inputData = JSON.parse(json);
33
+ } else {
34
+ inputData = {};
35
+ }
36
+ const setting = await (0, _settings.getSettings)();
37
+ if (!setting.authSessions.enabled) {
38
+ throw new Error("auth sessions feature is not enabled");
39
+ }
40
+ const createFilePath = (0, _fileUtils.getFullPathInProject)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create.ts");
41
+ if (!fs.exists(createFilePath)) {
42
+ throw new Error("auth session create file not found");
43
+ }
44
+ async function runCreate() {
45
+ const generator = (0, _runApi.runApiGenerator)({
46
+ automationFunction: {
47
+ name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
48
+ params: inputData
49
+ },
50
+ runOptions: {
51
+ environment: "cdp",
52
+ mode,
53
+ cdpAddress
54
+ },
55
+ retrieveSession: true,
56
+ importFunction: _tsNodeImport.tsNodeImport
57
+ });
58
+ let nextGeneratorParam = undefined;
59
+ while (true) {
60
+ const {
61
+ value,
62
+ done
63
+ } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
64
+ if (done) {
65
+ if (value.isErr()) {
66
+ if (value.error instanceof _runApi.AutomationError) {
67
+ throw value.error.error;
68
+ }
69
+ console.error(value.error);
70
+ throw new Error("Error while running create");
71
+ }
72
+ const fullState = value.value.session;
73
+ if (pathToSave) {
74
+ const fullPath = (0, _fileUtils.getFullPathInProject)(pathToSave);
75
+ fs.ensureFileSync(fullPath);
76
+ await fs.writeJSON(fullPath, fullState);
77
+ }
78
+ break;
79
+ }
80
+ if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
81
+ nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser + `, choices: ${value.choices}`, {
82
+ validator: input => {
83
+ if (!value.choices.includes(input)) {
84
+ throw new Error("Please type on of the allowed choices");
85
+ }
86
+ return input;
87
+ }
88
+ });
89
+ } else if (value.action === "request_more_info" && value.requestType == "otp") {
90
+ nextGeneratorParam = await (0, _promptly.prompt)(value.messageToUser, {});
91
+ }
92
+ }
93
+ }
94
+ await (0, _asyncLocalStorage.runWithContext)({
95
+ runEnvironment: _enums.RunEnvironment.IDE,
96
+ extendedPayloads: [],
97
+ runId: (0, _nanoid.nanoid)()
98
+ }, runCreate);
99
+ process.exit(0);
100
+ });
101
+ _commander.program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _commander = require("commander");
5
+ var _browserUtils = require("../common/browserUtils");
6
+ var _dotenv = _interopRequireDefault(require("dotenv"));
7
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
+ _dotenv.default.config({
9
+ path: `.env`
10
+ });
11
+ _commander.program.description("save browser state to file storage.json").option("-p, --path [file]", "path for file", "./localSessions/default.json").allowUnknownOption().action(async ({
12
+ path
13
+ }) => {
14
+ await (0, _browserUtils.saveSessionFromOpenedBrowser)(path);
15
+ process.exit(0);
16
+ });
17
+ _commander.program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _commander = require("commander");
5
+ var _browserUtils = require("../common/browserUtils");
6
+ var _dotenv = _interopRequireDefault(require("dotenv"));
7
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
+ _dotenv.default.config({
9
+ path: `.env`
10
+ });
11
+ _commander.program.description("start browser testing purposes").allowUnknownOption().action(async () => {
12
+ await (0, _browserUtils.startOrRestartBrowser)();
13
+ });
14
+ _commander.program.parse(process.argv);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+
3
+ var _commander = require("commander");
4
+ var _rollup = require("rollup");
5
+ var _pluginTypescript = _interopRequireDefault(require("@rollup/plugin-typescript"));
6
+ var _pluginCommonjs = _interopRequireDefault(require("@rollup/plugin-commonjs"));
7
+ var _pluginNodeResolve = require("@rollup/plugin-node-resolve");
8
+ var _pluginDynamicImportVars = _interopRequireDefault(require("@rollup/plugin-dynamic-import-vars"));
9
+ var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
10
+ var fs = _interopRequireWildcard(require("fs-extra"));
11
+ var path = _interopRequireWildcard(require("path"));
12
+ var _template = require("./common/utils/template");
13
+ var _dotenv = _interopRequireDefault(require("dotenv"));
14
+ 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); }
15
+ 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 && {}.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; }
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ function isThirdPartyWarning(warning) {
18
+ if (warning.id && /node_modules/.test(warning.id)) return true;
19
+ if (warning.ids && warning.ids.every(id => /node_modules/.test(id))) return true;
20
+ return false;
21
+ }
22
+ _dotenv.default.config();
23
+ _commander.program.description("build the intuned server").option("-t, --template <type>", "template to use", "InterfaceTemplate").addArgument(new _commander.Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile, {
24
+ template
25
+ }) => {
26
+ await (0, _template.moveTemplateFiles)(template);
27
+ const currentTemplateTsConfig = path.resolve(path.dirname(__filename), "..", "..", "template.tsconfig.json");
28
+ await fs.copy(currentTemplateTsConfig, `./intuned/${template}/tsconfig.json`);
29
+ await build(outfile, mode, template);
30
+ });
31
+ async function build(outfile, mode, template) {
32
+ let bundle = null;
33
+ let buildFailed = false;
34
+ try {
35
+ bundle = await (0, _rollup.rollup)({
36
+ input: `./intuned/${template}/index.${mode}.ts`,
37
+ output: {
38
+ globals: {
39
+ crypto: "crypto"
40
+ }
41
+ },
42
+ plugins: [(0, _pluginJson.default)(), (0, _pluginNodeResolve.nodeResolve)({
43
+ exportConditions: ["node"],
44
+ preferBuiltins: true
45
+ }), (0, _pluginTypescript.default)({
46
+ tsconfig: `./intuned/${template}/tsconfig.json`
47
+ }), (0, _pluginCommonjs.default)({
48
+ include: ["node_modules/**", `intuned/${template}/**`, "dist", "../typescript-sdk/**", "../typescript-runtime/**"],
49
+ extensions: [".js"],
50
+ ignoreGlobal: false,
51
+ sourceMap: false,
52
+ dynamicRequireTargets: ["api/**/*.js", "auth-sessions/**/*.js"],
53
+ requireReturnsDefault: "auto",
54
+ transformMixedEsModules: true
55
+ }), (0, _pluginDynamicImportVars.default)({
56
+ include: ["**/*.js", "**/*.ts"],
57
+ exclude: ["**/*.d.ts", "**/*.js.map"]
58
+ })],
59
+ onwarn: (warning, warn) => {
60
+ if (isThirdPartyWarning(warning)) return;
61
+ warn(warning);
62
+ },
63
+ external: ["playwright", "playwright-core", "jsdom", "canvas", "pdfjs-dist", "pdf-to-png-converter", "crypto", "applicationinsights", "fingerprint-generator", "fingerprint-injector", "node-fetch"]
64
+ });
65
+ console.log(`📦 Building ${outfile}`);
66
+ const outfileFolder = path.dirname(outfile);
67
+ const assetsDir = path.resolve(path.dirname(__filename), "..", "common", "assets");
68
+ await fs.copy(assetsDir, `${outfileFolder}/assets`);
69
+ await bundle.write({
70
+ format: "cjs",
71
+ file: outfile,
72
+ inlineDynamicImports: true
73
+ });
74
+ console.log(`✨ Build succeeded: ${outfile}`);
75
+ } catch (error) {
76
+ buildFailed = true;
77
+ console.error("error", error);
78
+ }
79
+ if (buildFailed) {
80
+ console.error("build failed");
81
+ process.exit(1);
82
+ }
83
+ }
84
+ _commander.program.parse(process.argv);
@@ -0,0 +1,14 @@
1
+ import { BrowserContext } from "playwright-core";
2
+ export declare const REMOTE_DEBUGGING_PORT = 9222;
3
+ export declare const getChromiumLaunchArgs: () => string[];
4
+ export declare function startOrRestartBrowser(): Promise<void>;
5
+ export interface SessionState {
6
+ cookies: any[];
7
+ storage: Record<string, {
8
+ localStorage: any;
9
+ sessionStorage: any;
10
+ }>;
11
+ }
12
+ export declare function saveSessionFromOpenedBrowser(path: string): Promise<void>;
13
+ export declare function loadState(path: string, context: BrowserContext): Promise<void>;
14
+ export declare function saveSession(path: string, context: BrowserContext): Promise<void>;