@intuned/runtime-dev 0.1.0-test.11 → 0.1.0-test.13

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 (100) hide show
  1. package/.babelrc +0 -1
  2. package/dist/commands/api/run.js +156 -83
  3. package/dist/commands/api/run.ts +105 -0
  4. package/dist/commands/auth-sessions/load.js +20 -20
  5. package/dist/commands/auth-sessions/load.ts +30 -0
  6. package/dist/commands/auth-sessions/run-check.js +45 -39
  7. package/dist/commands/auth-sessions/run-check.ts +51 -0
  8. package/dist/commands/auth-sessions/run-create.js +84 -74
  9. package/dist/commands/auth-sessions/run-create.ts +91 -0
  10. package/dist/commands/browser/save-state.js +12 -7
  11. package/dist/commands/browser/save-state.ts +14 -0
  12. package/dist/commands/browser/start-browser.js +7 -4
  13. package/dist/commands/browser/start-browser.ts +11 -0
  14. package/dist/commands/build.js +97 -61
  15. package/dist/commands/build.ts +78 -0
  16. package/dist/commands/common/browserUtils.js +42 -31
  17. package/dist/commands/common/browserUtils.ts +45 -0
  18. package/dist/commands/common/getDefaultExportFromFile.js +11 -10
  19. package/dist/commands/common/getDefaultExportFromFile.ts +11 -0
  20. package/dist/commands/common/getFirstLineNumber.js +90 -83
  21. package/dist/commands/common/{getFirstLineNumber.test.js → getFirstLineNumber.test.ts} +2 -2
  22. package/dist/commands/common/getFirstLineNumber.ts +96 -0
  23. package/dist/commands/common/sendMessageToClient.js +4 -2
  24. package/dist/commands/common/sendMessageToClient.ts +3 -0
  25. package/dist/commands/common/utils/fileUtils.js +16 -16
  26. package/dist/commands/common/utils/fileUtils.ts +23 -0
  27. package/dist/commands/common/utils/settings.js +17 -19
  28. package/dist/commands/common/utils/settings.ts +22 -0
  29. package/dist/commands/common/utils/unixSocket.js +43 -36
  30. package/dist/commands/common/utils/unixSocket.ts +38 -0
  31. package/dist/commands/common/utils/webTemplate.js +25 -18
  32. package/dist/commands/common/utils/webTemplate.ts +22 -0
  33. package/dist/commands/interface/run.js +139 -133
  34. package/dist/commands/interface/run.ts +156 -0
  35. package/dist/commands/ts-check.js +45 -41
  36. package/dist/commands/ts-check.ts +50 -0
  37. package/dist/common/Logger/Logger/index.d.ts +1 -1
  38. package/dist/common/Logger/Logger/index.js +40 -46
  39. package/dist/common/Logger/Logger/index.ts +53 -0
  40. package/dist/common/Logger/Logger/types.js +1 -1
  41. package/dist/common/Logger/index.d.ts +1 -1
  42. package/dist/common/Logger/index.js +40 -46
  43. package/dist/common/Logger/index.ts +53 -0
  44. package/dist/common/Logger/types.js +1 -1
  45. package/dist/common/asyncLocalStorage/index.js +4 -4
  46. package/dist/common/asyncLocalStorage/index.ts +9 -0
  47. package/dist/common/cleanEnvironmentVariables.js +11 -9
  48. package/dist/common/cleanEnvironmentVariables.ts +10 -0
  49. package/dist/common/constants.js +1 -1
  50. package/dist/common/constants.ts +1 -0
  51. package/dist/common/contextStorageStateHelpers.js +36 -38
  52. package/dist/common/contextStorageStateHelpers.ts +43 -0
  53. package/dist/common/getPlaywrightConstructs.d.ts +1 -1
  54. package/dist/common/getPlaywrightConstructs.js +187 -157
  55. package/dist/common/getPlaywrightConstructs.ts +181 -0
  56. package/dist/common/jwtTokenManager.js +74 -61
  57. package/dist/common/jwtTokenManager.ts +71 -0
  58. package/dist/common/runApi/errors.d.ts +1 -1
  59. package/dist/common/runApi/errors.js +130 -121
  60. package/dist/common/runApi/errors.ts +154 -0
  61. package/dist/common/runApi/index.d.ts +4 -4
  62. package/dist/common/runApi/index.js +219 -233
  63. package/dist/common/runApi/index.ts +253 -0
  64. package/dist/common/runApi/types.d.ts +1 -1
  65. package/dist/common/runApi/types.js +55 -41
  66. package/dist/common/runApi/types.ts +43 -0
  67. package/dist/common/settingsSchema.js +9 -6
  68. package/dist/common/settingsSchema.ts +9 -0
  69. package/dist/common/telemetry.js +27 -16
  70. package/dist/common/telemetry.ts +23 -0
  71. package/dist/index.d.ts +4 -4
  72. package/dist/index.js +4 -4
  73. package/dist/index.ts +4 -0
  74. package/dist/runtime/RunError.d.ts +1 -1
  75. package/dist/runtime/RunError.js +10 -10
  76. package/dist/runtime/RunError.ts +12 -0
  77. package/dist/runtime/downloadDirectory.js +10 -10
  78. package/dist/runtime/downloadDirectory.ts +13 -0
  79. package/dist/runtime/enums.d.ts +1 -11
  80. package/dist/runtime/enums.js +12 -12
  81. package/dist/runtime/enums.ts +12 -0
  82. package/dist/runtime/{executionHelpers.test.js → executionHelpers.test.ts} +2 -2
  83. package/dist/runtime/export.d.ts +1 -202
  84. package/dist/runtime/extendPayload.d.ts +1 -1
  85. package/dist/runtime/extendPayload.js +13 -13
  86. package/dist/runtime/extendPayload.ts +15 -0
  87. package/dist/runtime/extendTimeout.js +19 -20
  88. package/dist/runtime/extendTimeout.ts +24 -0
  89. package/dist/runtime/index.d.ts +7 -7
  90. package/dist/runtime/index.js +6 -6
  91. package/dist/runtime/index.ts +6 -0
  92. package/dist/runtime/requestMoreInfo.js +14 -14
  93. package/dist/runtime/requestMoreInfo.ts +18 -0
  94. package/dist/runtime/runInfo.d.ts +1 -1
  95. package/dist/runtime/runInfo.js +12 -13
  96. package/dist/runtime/runInfo.ts +15 -0
  97. package/package.json +3 -2
  98. package/tsconfig.json +1 -1
  99. /package/dist/{runtime/enums.d.js → common/Logger/Logger/types.ts} +0 -0
  100. /package/dist/{runtime/export.d.js → common/Logger/types.ts} +0 -0
@@ -11,81 +11,91 @@ import { runWithContext } from "../../common/asyncLocalStorage";
11
11
  import { nanoid } from "nanoid";
12
12
  import { RunEnvironment } from "../../runtime/enums";
13
13
  dotenv.config({
14
- path: `.env`
14
+ path: `.env`,
15
15
  });
16
- 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 Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
17
- cdpAddress,
18
- pathToSave,
19
- input,
20
- json
21
- }) => {
22
- let inputData = null;
23
- if (input) {
24
- inputData = await fs.readJSON(input);
25
- } else if (json) {
26
- inputData = JSON.parse(json);
27
- } else {
28
- inputData = {};
29
- }
30
- const setting = await getSettings();
31
- if (!setting.authSessions.enabled) {
32
- throw new Error("auth sessions feature is not enabled");
33
- }
34
- const createFilePath = getFullPathInProject(AUTH_SESSIONS_FOLDER_NAME, "create.ts");
35
- if (!fs.exists(createFilePath)) {
36
- throw new Error("auth session create file not found");
37
- }
38
- async function runCreate() {
39
- const generator = runApiGenerator({
40
- automationFunction: {
41
- name: "auth-sessions/create",
42
- params: inputData ?? {}
43
- },
44
- runOptions: {
45
- environment: "ide",
46
- mode,
47
- cdpAddress
48
- },
49
- retrieveSession: true
50
- });
51
- let nextGeneratorParam = undefined;
52
- while (true) {
53
- const {
54
- value,
55
- done
56
- } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
57
- if (done) {
58
- if (value.isErr()) {
59
- console.log(value.error);
60
- throw new Error(value.error);
61
- }
62
- const fullState = value.value.session;
63
- if (pathToSave) {
64
- const fullPath = getFullPathInProject(pathToSave);
65
- fs.ensureFileSync(fullPath);
66
- await fs.writeJSON(fullPath, fullState);
67
- }
68
- break;
69
- }
70
- if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
71
- nextGeneratorParam = await prompt(value.messageToUser + `, choices: ${value.choices}`, {
72
- validator: input => {
73
- if (!value.choices.includes(input)) {
74
- throw new Error("Please type on of the allowed choices");
75
- }
76
- return input;
77
- }
16
+ program
17
+ .description("run auth session create")
18
+ .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
19
+ .option("-i, --input [file]", "input json file")
20
+ .option("-j, --json [json]", "input json string")
21
+ .option("--authSessionPath <authSession>", "auth session to use when executing the api")
22
+ .option("--pathToSave <pathToSave>", "path to save the auth session, if not provided, will discard the auth session")
23
+ .allowUnknownOption()
24
+ .addArgument(new Argument("<mode>", "mode of execution")
25
+ .choices(["vanilla", "playwright", "playwright-standalone"])
26
+ .default("playwright-standalone")
27
+ .argOptional())
28
+ .action(async (mode, { cdpAddress, pathToSave, input, json, }) => {
29
+ let inputData = null;
30
+ if (input) {
31
+ inputData = await fs.readJSON(input);
32
+ }
33
+ else if (json) {
34
+ inputData = JSON.parse(json);
35
+ }
36
+ else {
37
+ inputData = {};
38
+ }
39
+ const setting = await getSettings();
40
+ if (!setting.authSessions.enabled) {
41
+ throw new Error("auth sessions feature is not enabled");
42
+ }
43
+ const createFilePath = getFullPathInProject(AUTH_SESSIONS_FOLDER_NAME, "create.ts");
44
+ if (!fs.exists(createFilePath)) {
45
+ throw new Error("auth session create file not found");
46
+ }
47
+ async function runCreate() {
48
+ const generator = runApiGenerator({
49
+ automationFunction: {
50
+ name: "auth-sessions/create",
51
+ params: inputData ?? {},
52
+ },
53
+ runOptions: {
54
+ environment: "ide",
55
+ mode,
56
+ cdpAddress,
57
+ },
58
+ retrieveSession: true,
78
59
  });
79
- } else if (value.action === "request_more_info" && value.requestType == "otp") {
80
- nextGeneratorParam = await prompt(value.messageToUser, {});
81
- }
60
+ let nextGeneratorParam = undefined;
61
+ // eslint-disable-next-line no-constant-condition
62
+ while (true) {
63
+ const { value, done } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
64
+ if (done) {
65
+ if (value.isErr()) {
66
+ console.log(value.error);
67
+ throw new Error(value.error);
68
+ }
69
+ const fullState = value.value.session;
70
+ if (pathToSave) {
71
+ const fullPath = getFullPathInProject(pathToSave);
72
+ fs.ensureFileSync(fullPath);
73
+ await fs.writeJSON(fullPath, fullState);
74
+ }
75
+ break;
76
+ }
77
+ if (value.action === "request_more_info" &&
78
+ value.requestType == "multiple_choice") {
79
+ nextGeneratorParam = await prompt(value.messageToUser + `, choices: ${value.choices}`, {
80
+ validator: (input) => {
81
+ if (!value.choices.includes(input)) {
82
+ throw new Error("Please type on of the allowed choices");
83
+ }
84
+ return input;
85
+ },
86
+ });
87
+ }
88
+ else if (value.action === "request_more_info" &&
89
+ value.requestType == "otp") {
90
+ nextGeneratorParam = await prompt(value.messageToUser, {});
91
+ }
92
+ }
82
93
  }
83
- }
84
- await runWithContext({
85
- runEnvironment: RunEnvironment.IDE,
86
- extendedPayloads: [],
87
- runId: nanoid()
88
- }, runCreate);
89
- process.exit(0);
94
+ await runWithContext({
95
+ runEnvironment: RunEnvironment.IDE,
96
+ extendedPayloads: [],
97
+ runId: nanoid(),
98
+ }, runCreate);
99
+ process.exit(0);
90
100
  });
91
- program.parse(process.argv);
101
+ program.parse(process.argv);
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env node
2
+ import { Argument, program } from "commander";
3
+ import * as fs from "fs-extra";
4
+ import { prompt } from "promptly";
5
+ import { getFullPathInProject } from "../common/utils/fileUtils";
6
+ import { getSettings } from "../common/utils/settings";
7
+ import dotenv from "dotenv";
8
+ import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
9
+ import { runApiGenerator } from "../../common/runApi";
10
+ import { runWithContext } from "../../common/asyncLocalStorage";
11
+ import { nanoid } from "nanoid";
12
+ import { RunEnvironment } from "../../runtime/enums";
13
+ dotenv.config({
14
+ path: `.env`
15
+ });
16
+ 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 Argument("<mode>", "mode of execution").choices(["vanilla", "playwright", "playwright-standalone"]).default("playwright-standalone").argOptional()).action(async (mode, {
17
+ cdpAddress,
18
+ pathToSave,
19
+ input,
20
+ json
21
+ }) => {
22
+ let inputData = null;
23
+ if (input) {
24
+ inputData = await fs.readJSON(input);
25
+ } else if (json) {
26
+ inputData = JSON.parse(json);
27
+ } else {
28
+ inputData = {};
29
+ }
30
+ const setting = await getSettings();
31
+ if (!setting.authSessions.enabled) {
32
+ throw new Error("auth sessions feature is not enabled");
33
+ }
34
+ const createFilePath = getFullPathInProject(AUTH_SESSIONS_FOLDER_NAME, "create.ts");
35
+ if (!fs.exists(createFilePath)) {
36
+ throw new Error("auth session create file not found");
37
+ }
38
+ async function runCreate() {
39
+ const generator = runApiGenerator({
40
+ automationFunction: {
41
+ name: "auth-sessions/create",
42
+ params: inputData ?? {}
43
+ },
44
+ runOptions: {
45
+ environment: "ide",
46
+ mode,
47
+ cdpAddress
48
+ },
49
+ retrieveSession: true
50
+ });
51
+ let nextGeneratorParam = undefined;
52
+ while (true) {
53
+ const {
54
+ value,
55
+ done
56
+ } = await generator.next(...(nextGeneratorParam ? [nextGeneratorParam] : []));
57
+ if (done) {
58
+ if (value.isErr()) {
59
+ console.log(value.error);
60
+ throw new Error(value.error);
61
+ }
62
+ const fullState = value.value.session;
63
+ if (pathToSave) {
64
+ const fullPath = getFullPathInProject(pathToSave);
65
+ fs.ensureFileSync(fullPath);
66
+ await fs.writeJSON(fullPath, fullState);
67
+ }
68
+ break;
69
+ }
70
+ if (value.action === "request_more_info" && value.requestType == "multiple_choice") {
71
+ nextGeneratorParam = await prompt(value.messageToUser + `, choices: ${value.choices}`, {
72
+ validator: input => {
73
+ if (!value.choices.includes(input)) {
74
+ throw new Error("Please type on of the allowed choices");
75
+ }
76
+ return input;
77
+ }
78
+ });
79
+ } else if (value.action === "request_more_info" && value.requestType == "otp") {
80
+ nextGeneratorParam = await prompt(value.messageToUser, {});
81
+ }
82
+ }
83
+ }
84
+ await runWithContext({
85
+ runEnvironment: RunEnvironment.IDE,
86
+ extendedPayloads: [],
87
+ runId: nanoid()
88
+ }, runCreate);
89
+ process.exit(0);
90
+ });
91
+ program.parse(process.argv);
@@ -3,12 +3,17 @@ import { program } from "commander";
3
3
  import { saveSessionFromOpenedBrowser } from "../common/browserUtils";
4
4
  import dotenv from "dotenv";
5
5
  dotenv.config({
6
- path: `.env`
6
+ path: `.env`,
7
7
  });
8
- program.description("save browser state to file storage.json").option("-p, --path [file]", "path for file", "./localSessions/default.json").allowUnknownOption().action(async ({
9
- path
10
- }) => {
11
- await saveSessionFromOpenedBrowser(path);
12
- process.exit(0);
8
+ program
9
+ .description("save browser state to file storage.json")
10
+ .option("-p, --path [file]", "path for file", "./localSessions/default.json")
11
+ .allowUnknownOption()
12
+ .action(async ({ path }) => {
13
+ await saveSessionFromOpenedBrowser(path);
14
+ // playwright keeps an open handle to the connected browser and it stops the process from exiting
15
+ // there is no way to close the connection gracefully without destroying the context/browser
16
+ // https://github.com/microsoft/playwright/issues/4956
17
+ process.exit(0);
13
18
  });
14
- program.parse(process.argv);
19
+ program.parse(process.argv);
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import { saveSessionFromOpenedBrowser } from "../common/browserUtils";
4
+ import dotenv from "dotenv";
5
+ dotenv.config({
6
+ path: `.env`
7
+ });
8
+ program.description("save browser state to file storage.json").option("-p, --path [file]", "path for file", "./localSessions/default.json").allowUnknownOption().action(async ({
9
+ path
10
+ }) => {
11
+ await saveSessionFromOpenedBrowser(path);
12
+ process.exit(0);
13
+ });
14
+ program.parse(process.argv);
@@ -3,9 +3,12 @@ import { program } from "commander";
3
3
  import { startOrRestartBrowser } from "../common/browserUtils";
4
4
  import dotenv from "dotenv";
5
5
  dotenv.config({
6
- path: `.env`
6
+ path: `.env`,
7
7
  });
8
- program.description("start browser testing purposes").allowUnknownOption().action(async () => {
9
- await startOrRestartBrowser();
8
+ program
9
+ .description("start browser testing purposes")
10
+ .allowUnknownOption()
11
+ .action(async () => {
12
+ await startOrRestartBrowser();
10
13
  });
11
- program.parse(process.argv);
14
+ program.parse(process.argv);
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env node
2
+ import { program } from "commander";
3
+ import { startOrRestartBrowser } from "../common/browserUtils";
4
+ import dotenv from "dotenv";
5
+ dotenv.config({
6
+ path: `.env`
7
+ });
8
+ program.description("start browser testing purposes").allowUnknownOption().action(async () => {
9
+ await startOrRestartBrowser();
10
+ });
11
+ program.parse(process.argv);
@@ -8,71 +8,107 @@ import dynamicImportVars from "@rollup/plugin-dynamic-import-vars";
8
8
  import json from "@rollup/plugin-json";
9
9
  import * as fs from "fs-extra";
10
10
  import * as path from "path";
11
- import { moveWebTemplateFiles } from "./common/utils/webTemplate";
11
+ import { moveWebTemplateFiles } from "./common/utils/webTemplate.js";
12
12
  function isThirdPartyWarning(warning) {
13
- if (warning.id && /node_modules/.test(warning.id)) return true;
14
- if (warning.ids && warning.ids.every(id => /node_modules/.test(id))) return true;
15
- return false;
13
+ if (warning.id && /node_modules/.test(warning.id))
14
+ return true;
15
+ if (warning.ids && warning.ids.every((id) => /node_modules/.test(id)))
16
+ return true;
17
+ return false;
16
18
  }
17
19
  import dotenv from "dotenv";
18
20
  dotenv.config();
19
- program.description("build the intuned server").addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile) => {
20
- await moveWebTemplateFiles();
21
- const currentTemplateTsConfig = path.resolve(__dirname, "..", "..", "template.tsconfig.json");
22
- await fs.copy(currentTemplateTsConfig, "./intuned/WebTemplate/tsconfig.json");
23
- await build(outfile, mode);
21
+ program
22
+ .description("build the intuned server")
23
+ .addArgument(new Argument("<mode>", "mode of execution")
24
+ .choices(["vanilla", "playwright"])
25
+ .default("playwright")
26
+ .argOptional())
27
+ .argument("[outfile]", "output bundle", "./output/bundle_v2.js")
28
+ .allowUnknownOption()
29
+ .action(async (mode, outfile) => {
30
+ await moveWebTemplateFiles();
31
+ const currentTemplateTsConfig = path.resolve(path.dirname(import.meta.url), "..", "..", "template.tsconfig.json");
32
+ await fs.copy(currentTemplateTsConfig, "./intuned/WebTemplate/tsconfig.json");
33
+ await build(outfile, mode);
24
34
  });
25
35
  async function build(outfile, mode) {
26
- let bundle = null;
27
- let buildFailed = false;
28
- try {
29
- bundle = await rollup({
30
- input: `./intuned/WebTemplate/index.${mode}.ts`,
31
- output: {
32
- globals: {
33
- crypto: "crypto"
34
- }
35
- },
36
- plugins: [json(), nodeResolve({
37
- exportConditions: ["node"],
38
- preferBuiltins: true
39
- }), typescript({
40
- tsconfig: "./intuned/WebTemplate/tsconfig.json"
41
- }), commonjs({
42
- include: ["node_modules/**", "intuned/WebTemplate/**", "dist", "../typescript-sdk/**", "../typescript-runtime/**"],
43
- extensions: [".js"],
44
- ignoreGlobal: false,
45
- sourceMap: false,
46
- dynamicRequireTargets: ["api/**/*.js", "auth-sessions/**/*.js"],
47
- requireReturnsDefault: "auto",
48
- transformMixedEsModules: true
49
- }), dynamicImportVars({
50
- include: ["**/*.js", "**/*.ts"],
51
- exclude: ["**/*.d.ts", "**/*.js.map"]
52
- })],
53
- onwarn: (warning, warn) => {
54
- if (isThirdPartyWarning(warning)) return;
55
- warn(warning);
56
- },
57
- external: ["@intuned/playwright", "@intuned/playwright-core", "@intuned/runtime", "jsdom", "canvas", "pdfjs-dist", "pdf-to-png-converter", "crypto", "applicationinsights", "fingerprint-generator", "fingerprint-injector"]
58
- });
59
- console.log(`📦 Building ${outfile}`);
60
- const outfileFolder = path.dirname(outfile);
61
- const assetsDir = path.resolve(__dirname, "..", "common", "assets");
62
- await fs.copy(assetsDir, `${outfileFolder}/assets`);
63
- await bundle.write({
64
- format: "cjs",
65
- file: outfile,
66
- inlineDynamicImports: true
67
- });
68
- console.log(`✨ Build succeeded: ${outfile}`);
69
- } catch (error) {
70
- buildFailed = true;
71
- console.error("error", error);
72
- }
73
- if (buildFailed) {
74
- console.error("build failed");
75
- process.exit(1);
76
- }
36
+ let bundle = null;
37
+ let buildFailed = false;
38
+ try {
39
+ // create a bundle
40
+ bundle = await rollup({
41
+ input: `./intuned/WebTemplate/index.${mode}.ts`,
42
+ output: {
43
+ globals: { crypto: "crypto" },
44
+ },
45
+ plugins: [
46
+ json(),
47
+ nodeResolve({ exportConditions: ["node"], preferBuiltins: true }),
48
+ typescript({ tsconfig: "./intuned/WebTemplate/tsconfig.json" }),
49
+ commonjs({
50
+ include: [
51
+ "node_modules/**",
52
+ "intuned/WebTemplate/**",
53
+ "dist",
54
+ "../typescript-sdk/**",
55
+ "../typescript-runtime/**",
56
+ ],
57
+ extensions: [".js"],
58
+ ignoreGlobal: false,
59
+ sourceMap: false,
60
+ dynamicRequireTargets: [
61
+ // "api/**/*.ts",
62
+ // "auth-sessions/**/*.ts",
63
+ "api/**/*.js",
64
+ "auth-sessions/**/*.js",
65
+ ],
66
+ requireReturnsDefault: "auto",
67
+ transformMixedEsModules: true,
68
+ }),
69
+ dynamicImportVars({
70
+ include: ["**/*.js", "**/*.ts"],
71
+ exclude: ["**/*.d.ts", "**/*.js.map"],
72
+ }),
73
+ ],
74
+ onwarn: (warning, warn) => {
75
+ if (isThirdPartyWarning(warning))
76
+ return;
77
+ warn(warning);
78
+ },
79
+ external: [
80
+ "@intuned/playwright",
81
+ "@intuned/playwright-core",
82
+ "@intuned/runtime",
83
+ "jsdom",
84
+ "canvas",
85
+ "pdfjs-dist",
86
+ "pdf-to-png-converter",
87
+ "crypto",
88
+ "applicationinsights",
89
+ "fingerprint-generator",
90
+ "fingerprint-injector",
91
+ ],
92
+ });
93
+ console.log(`📦 Building ${outfile}`);
94
+ const outfileFolder = path.dirname(outfile);
95
+ // copy assets to outfile folder
96
+ const assetsDir = path.resolve(path.dirname(import.meta.url), "..", "common", "assets");
97
+ await fs.copy(assetsDir, `${outfileFolder}/assets`);
98
+ await bundle.write({
99
+ format: "cjs",
100
+ file: outfile,
101
+ inlineDynamicImports: true,
102
+ });
103
+ console.log(`✨ Build succeeded: ${outfile}`);
104
+ }
105
+ catch (error) {
106
+ buildFailed = true;
107
+ console.error("error", error);
108
+ }
109
+ if (buildFailed) {
110
+ console.error("build failed");
111
+ process.exit(1);
112
+ }
77
113
  }
78
- program.parse(process.argv);
114
+ program.parse(process.argv);
@@ -0,0 +1,78 @@
1
+ #!/usr/bin/env node
2
+ import { program, Argument } from "commander";
3
+ import { rollup } from "rollup";
4
+ import typescript from "@rollup/plugin-typescript";
5
+ import commonjs from "@rollup/plugin-commonjs";
6
+ import { nodeResolve } from "@rollup/plugin-node-resolve";
7
+ import dynamicImportVars from "@rollup/plugin-dynamic-import-vars";
8
+ import json from "@rollup/plugin-json";
9
+ import * as fs from "fs-extra";
10
+ import * as path from "path";
11
+ import { moveWebTemplateFiles } from "./common/utils/webTemplate.js";
12
+ function isThirdPartyWarning(warning) {
13
+ if (warning.id && /node_modules/.test(warning.id)) return true;
14
+ if (warning.ids && warning.ids.every(id => /node_modules/.test(id))) return true;
15
+ return false;
16
+ }
17
+ import dotenv from "dotenv";
18
+ dotenv.config();
19
+ program.description("build the intuned server").addArgument(new Argument("<mode>", "mode of execution").choices(["vanilla", "playwright"]).default("playwright").argOptional()).argument("[outfile]", "output bundle", "./output/bundle_v2.js").allowUnknownOption().action(async (mode, outfile) => {
20
+ await moveWebTemplateFiles();
21
+ const currentTemplateTsConfig = path.resolve(path.dirname(import.meta.url), "..", "..", "template.tsconfig.json");
22
+ await fs.copy(currentTemplateTsConfig, "./intuned/WebTemplate/tsconfig.json");
23
+ await build(outfile, mode);
24
+ });
25
+ async function build(outfile, mode) {
26
+ let bundle = null;
27
+ let buildFailed = false;
28
+ try {
29
+ bundle = await rollup({
30
+ input: `./intuned/WebTemplate/index.${mode}.ts`,
31
+ output: {
32
+ globals: {
33
+ crypto: "crypto"
34
+ }
35
+ },
36
+ plugins: [json(), nodeResolve({
37
+ exportConditions: ["node"],
38
+ preferBuiltins: true
39
+ }), typescript({
40
+ tsconfig: "./intuned/WebTemplate/tsconfig.json"
41
+ }), commonjs({
42
+ include: ["node_modules/**", "intuned/WebTemplate/**", "dist", "../typescript-sdk/**", "../typescript-runtime/**"],
43
+ extensions: [".js"],
44
+ ignoreGlobal: false,
45
+ sourceMap: false,
46
+ dynamicRequireTargets: ["api/**/*.js", "auth-sessions/**/*.js"],
47
+ requireReturnsDefault: "auto",
48
+ transformMixedEsModules: true
49
+ }), dynamicImportVars({
50
+ include: ["**/*.js", "**/*.ts"],
51
+ exclude: ["**/*.d.ts", "**/*.js.map"]
52
+ })],
53
+ onwarn: (warning, warn) => {
54
+ if (isThirdPartyWarning(warning)) return;
55
+ warn(warning);
56
+ },
57
+ external: ["@intuned/playwright", "@intuned/playwright-core", "@intuned/runtime", "jsdom", "canvas", "pdfjs-dist", "pdf-to-png-converter", "crypto", "applicationinsights", "fingerprint-generator", "fingerprint-injector"]
58
+ });
59
+ console.log(`📦 Building ${outfile}`);
60
+ const outfileFolder = path.dirname(outfile);
61
+ const assetsDir = path.resolve(path.dirname(import.meta.url), "..", "common", "assets");
62
+ await fs.copy(assetsDir, `${outfileFolder}/assets`);
63
+ await bundle.write({
64
+ format: "cjs",
65
+ file: outfile,
66
+ inlineDynamicImports: true
67
+ });
68
+ console.log(`✨ Build succeeded: ${outfile}`);
69
+ } catch (error) {
70
+ buildFailed = true;
71
+ console.error("error", error);
72
+ }
73
+ if (buildFailed) {
74
+ console.error("build failed");
75
+ process.exit(1);
76
+ }
77
+ }
78
+ program.parse(process.argv);