@intuned/runtime-dev 0.1.0-test.14 → 0.1.0-test.16

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 (114) hide show
  1. package/.babelrc +1 -2
  2. package/WebTemplate/api.ts +90 -92
  3. package/WebTemplate/controllers/authSessions/create.ts +2 -2
  4. package/WebTemplate/controllers/authSessions/store.ts +1 -1
  5. package/WebTemplate/controllers/runApi/helpers.ts +14 -12
  6. package/WebTemplate/index.playwright.ts +32 -42
  7. package/WebTemplate/jobs.ts +13 -2
  8. package/WebTemplate/utils.ts +53 -1
  9. package/api/test2.ts +6 -1
  10. package/auth-sessions/check.ts +3 -1
  11. package/auth-sessions/create.ts +10 -10
  12. package/bin/intuned-api-run +1 -1
  13. package/bin/intuned-auth-session-check +1 -1
  14. package/bin/intuned-auth-session-create +1 -1
  15. package/bin/intuned-auth-session-load +1 -1
  16. package/bin/intuned-auth-session-refresh +1 -1
  17. package/bin/intuned-browser-save-state +1 -1
  18. package/bin/intuned-browser-start +1 -1
  19. package/bin/intuned-build +1 -1
  20. package/bin/intuned-ts-check +1 -1
  21. package/dist/commands/api/run.js +109 -170
  22. package/dist/commands/auth-sessions/load.js +28 -26
  23. package/dist/commands/auth-sessions/run-check.js +54 -53
  24. package/dist/commands/auth-sessions/run-create.js +93 -96
  25. package/dist/commands/browser/save-state.js +14 -16
  26. package/dist/commands/browser/start-browser.js +11 -11
  27. package/dist/commands/build.js +79 -109
  28. package/dist/commands/common/browserUtils.js +53 -51
  29. package/dist/commands/common/getFirstLineNumber.js +93 -93
  30. package/dist/commands/common/{getFirstLineNumber.test.ts → getFirstLineNumber.test.js} +53 -48
  31. package/dist/commands/common/sendMessageToClient.js +9 -4
  32. package/dist/commands/common/tsNodeImport.d.ts +1 -0
  33. package/dist/commands/common/tsNodeImport.js +18 -0
  34. package/dist/commands/common/utils/fileUtils.js +32 -22
  35. package/dist/commands/common/utils/settings.js +27 -19
  36. package/dist/commands/common/utils/unixSocket.js +43 -43
  37. package/dist/commands/common/utils/webTemplate.js +30 -28
  38. package/dist/commands/interface/run.js +162 -139
  39. package/dist/commands/ts-check.js +50 -50
  40. package/dist/common/Logger/Logger/index.js +55 -42
  41. package/dist/common/Logger/Logger/types.js +5 -1
  42. package/dist/common/Logger/index.js +55 -42
  43. package/dist/common/Logger/types.js +5 -1
  44. package/dist/common/asyncLocalStorage/index.js +16 -8
  45. package/dist/common/cleanEnvironmentVariables.js +16 -12
  46. package/dist/common/constants.js +7 -1
  47. package/dist/common/contextStorageStateHelpers.js +47 -38
  48. package/dist/common/getPlaywrightConstructs.js +178 -197
  49. package/dist/common/jwtTokenManager.js +76 -79
  50. package/dist/common/runApi/errors.js +159 -150
  51. package/dist/common/runApi/index.js +240 -232
  52. package/dist/common/runApi/types.d.ts +19 -5
  53. package/dist/common/runApi/types.js +53 -56
  54. package/dist/common/settingsSchema.js +15 -10
  55. package/dist/common/telemetry.js +28 -30
  56. package/dist/index.js +69 -4
  57. package/dist/runtime/RunError.js +18 -11
  58. package/dist/runtime/downloadDirectory.js +19 -13
  59. package/dist/runtime/enums.d.js +5 -0
  60. package/dist/runtime/enums.d.ts +11 -1
  61. package/dist/runtime/enums.js +18 -12
  62. package/dist/runtime/executionHelpers.test.js +53 -0
  63. package/dist/runtime/export.d.js +5 -0
  64. package/dist/runtime/export.d.ts +202 -1
  65. package/dist/runtime/extendPayload.js +21 -15
  66. package/dist/runtime/extendTimeout.js +28 -21
  67. package/dist/runtime/index.js +53 -6
  68. package/dist/runtime/requestMoreInfo.js +23 -16
  69. package/dist/runtime/runInfo.js +21 -14
  70. package/package.json +4 -7
  71. package/dist/commands/api/run.ts +0 -105
  72. package/dist/commands/auth-sessions/load.ts +0 -30
  73. package/dist/commands/auth-sessions/run-check.ts +0 -51
  74. package/dist/commands/auth-sessions/run-create.ts +0 -91
  75. package/dist/commands/browser/save-state.ts +0 -14
  76. package/dist/commands/browser/start-browser.ts +0 -11
  77. package/dist/commands/build.ts +0 -79
  78. package/dist/commands/common/browserUtils.ts +0 -45
  79. package/dist/commands/common/getDefaultExportFromFile.d.ts +0 -1
  80. package/dist/commands/common/getDefaultExportFromFile.js +0 -12
  81. package/dist/commands/common/getDefaultExportFromFile.ts +0 -11
  82. package/dist/commands/common/getFirstLineNumber.ts +0 -96
  83. package/dist/commands/common/sendMessageToClient.ts +0 -3
  84. package/dist/commands/common/utils/fileUtils.ts +0 -23
  85. package/dist/commands/common/utils/settings.ts +0 -22
  86. package/dist/commands/common/utils/unixSocket.ts +0 -38
  87. package/dist/commands/common/utils/webTemplate.ts +0 -23
  88. package/dist/commands/interface/run.ts +0 -156
  89. package/dist/commands/ts-check.ts +0 -51
  90. package/dist/common/Logger/Logger/index.ts +0 -53
  91. package/dist/common/Logger/Logger/types.ts +0 -1
  92. package/dist/common/Logger/index.ts +0 -53
  93. package/dist/common/Logger/types.ts +0 -1
  94. package/dist/common/asyncLocalStorage/index.ts +0 -9
  95. package/dist/common/cleanEnvironmentVariables.ts +0 -10
  96. package/dist/common/constants.ts +0 -1
  97. package/dist/common/contextStorageStateHelpers.ts +0 -43
  98. package/dist/common/getPlaywrightConstructs.ts +0 -182
  99. package/dist/common/jwtTokenManager.ts +0 -71
  100. package/dist/common/runApi/errors.ts +0 -154
  101. package/dist/common/runApi/index.ts +0 -253
  102. package/dist/common/runApi/types.ts +0 -43
  103. package/dist/common/settingsSchema.ts +0 -9
  104. package/dist/common/telemetry.ts +0 -23
  105. package/dist/index.ts +0 -4
  106. package/dist/runtime/RunError.ts +0 -12
  107. package/dist/runtime/downloadDirectory.ts +0 -13
  108. package/dist/runtime/enums.ts +0 -12
  109. package/dist/runtime/executionHelpers.test.ts +0 -51
  110. package/dist/runtime/extendPayload.ts +0 -15
  111. package/dist/runtime/extendTimeout.ts +0 -24
  112. package/dist/runtime/index.ts +0 -6
  113. package/dist/runtime/requestMoreInfo.ts +0 -18
  114. package/dist/runtime/runInfo.ts +0 -15
@@ -1,178 +1,117 @@
1
1
  #!/usr/bin/env node
2
- import { program, Argument } from "commander";
3
- import * as fs from "fs-extra";
4
- import { getSettings } from "../common/utils/settings";
5
- import dotenv from "dotenv";
6
- import { runWithContext } from "../../common/asyncLocalStorage";
7
- import { RunEnvironment } from "../../runtime/enums";
8
- import { cleanEnvironmentVariables } from "../../common/cleanEnvironmentVariables";
9
- import { logger } from "../../common/Logger";
10
- import { nanoid } from "nanoid";
11
- import chalk from "chalk";
12
- import { runApi } from "../../common/runApi";
13
- import { AutomationError } from "../../common/runApi";
14
- dotenv.config({
15
- path: `.env`,
2
+ "use strict";
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
16
6
  });
17
- export async function executeCLI(apiName, mode, inputData, options) {
18
- // cleanup environment variables before running the user code
19
- cleanEnvironmentVariables();
20
- let authSessionPathToUse = null;
21
- // check auth session
22
- const settings = await getSettings();
23
- if (settings.authSessions.enabled) {
24
- // if auth session enabled, check if the auth session is provided
25
- if (!options.authSessionPath) {
26
- throw new Error("Auth session is enabled but no auth session provided");
27
- }
28
- authSessionPathToUse = options.authSessionPath;
29
- }
30
- else {
31
- // if auth session is not enabled, check if the auth session is provided
32
- if (options.authSessionPath) {
33
- throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
34
- }
35
- }
36
- // Dynamically import the TypeScript file
37
- // const defaultExport = await getDefaultExportFromFile(apiFilePath);
38
- // const isDebug = process.execArgv.some((arg) => arg.includes("--inspect"));
39
- // if (isDebug) {
40
- // const { sourceFileName, lineNumber } = await getFirstLineNumber(
41
- // apiFilePath
42
- // );
43
- // sendBreakPointOnToClient(sourceFileName, lineNumber);
44
- // }
45
- // if (mode === "vanilla") {
46
- // Execute the function with the input data
47
- // const result = await defaultExport(inputData);
48
- // return result;
49
- // }
50
- // const { page, context } = await getPlaywrightConstructsForMode(
51
- // mode,
52
- // options.cdpAddress,
53
- // authSessionPathToUse ? authSessionPathToUse : undefined
54
- // );
55
- // // wait for the page to get stable, this is a workaround for a bug in playwright when you try to do something
56
- // // on a page after connecting to it immediately, the page needs some time to get stable.
57
- // let isPageStable = false;
58
- // let retry = 0;
59
- // // will wait maximum 2 seconds before failing.
60
- // while (!isPageStable && retry < 10) {
61
- // try {
62
- // await page.locator("html").all();
63
- // isPageStable = true;
64
- // break;
65
- // } catch (error) {
66
- // if (error?.message?.includes("Execution context was destroyed")) {
67
- // await new Promise((resolve) => setTimeout(resolve, 200));
68
- // } else {
69
- // // throwing to make sure we do not hide any other unexpected issues.
70
- // throw error;
71
- // }
72
- // }
73
- // retry++;
74
- // }
75
- // if (!isPageStable) {
76
- // throw new Error("The page is not stable, try to run again.");
77
- // }
78
- const runApiResult = await runApi({
79
- automationFunction: {
80
- name: `api/${apiName}`,
81
- params: inputData ?? {},
82
- },
83
- auth: authSessionPathToUse
84
- ? {
85
- session: {
86
- type: "file",
87
- path: authSessionPathToUse,
88
- },
89
- runCheck: false,
90
- }
91
- : undefined,
92
- runOptions: {
93
- environment: "ide",
94
- cdpAddress: options.cdpAddress,
95
- mode,
96
- },
97
- });
98
- if (runApiResult.isErr()) {
99
- if (runApiResult.error instanceof AutomationError) {
100
- throw runApiResult.error.error;
101
- }
102
- console.error("An error occurred while running the API", runApiResult.error);
103
- return;
104
- }
105
- const { result, extendedPayloads: payloadToAppend } = runApiResult.value;
106
- const isResponseObject = typeof result === "object" && result !== null;
107
- const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
108
- const hasNestedObjects = isResponseObject &&
109
- Object.values(result).some((value) => typeof value === "object");
110
- const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
111
- const resultsDir = "/tmp/run-results";
112
- if (options.outputFileId && shouldWriteToFile) {
113
- logger.info(chalk.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
114
- fs.ensureDirSync(resultsDir);
115
- const path = `${resultsDir}/${options.outputFileId}.json`;
116
- await fs.writeJson(path, result, {
117
- spaces: 2,
118
- });
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
+ var _fileUtils = require("../common/utils/fileUtils");
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ 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); }
23
+ 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; }
24
+ _dotenv.default.config({
25
+ path: `.env`
26
+ });
27
+ async function executeCLI(apiName, mode, inputData, options) {
28
+ (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
29
+ let authSessionPathToUse = null;
30
+ const settings = await (0, _settings.getSettings)();
31
+ if (settings.authSessions.enabled) {
32
+ if (!options.authSessionPath) {
33
+ throw new Error("Auth session is enabled but no auth session provided");
119
34
  }
120
- else {
121
- console.log("result:", result);
35
+ authSessionPathToUse = options.authSessionPath;
36
+ } else {
37
+ if (options.authSessionPath) {
38
+ throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
122
39
  }
123
- const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
124
- if (hasPayloadToAppend && options.outputFileId) {
125
- logger.info(chalk.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
126
- fs.ensureDirSync(resultsDir);
127
- const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
128
- await fs.writeJson(path, payloadToAppend, {
129
- spaces: 2,
130
- });
40
+ }
41
+ const apiFilePath = (0, _fileUtils.getFullPathInProject)("api", `${apiName}.ts`);
42
+ const runApiModule = await (0, _tsNodeImport.tsNodeImport)(apiFilePath);
43
+ const runApiResult = await (0, _runApi.runApi)({
44
+ automationFunction: {
45
+ module: runApiModule,
46
+ params: inputData
47
+ },
48
+ auth: authSessionPathToUse ? {
49
+ session: {
50
+ type: "file",
51
+ path: authSessionPathToUse
52
+ },
53
+ runCheck: false
54
+ } : undefined,
55
+ runOptions: {
56
+ environment: "ide",
57
+ cdpAddress: options.cdpAddress,
58
+ mode
131
59
  }
132
- else if (hasPayloadToAppend) {
133
- logger.info("payload to append:", payloadToAppend);
134
- logger.info("This will only take an effect if this API run was part of a job.");
60
+ });
61
+ if (runApiResult.isErr()) {
62
+ if (runApiResult.error instanceof _runApi.AutomationError) {
63
+ throw runApiResult.error.error;
135
64
  }
65
+ console.error("An error occurred while running the API", runApiResult.error);
66
+ return;
67
+ }
68
+ const {
69
+ result,
70
+ extendedPayloads: payloadToAppend
71
+ } = runApiResult.value;
72
+ const isResponseObject = typeof result === "object" && result !== null;
73
+ const hasMoreThank5Keys = isResponseObject && Object.keys(result).length > 5;
74
+ const hasNestedObjects = isResponseObject && Object.values(result).some(value => typeof value === "object");
75
+ const shouldWriteToFile = isResponseObject && (hasMoreThank5Keys || hasNestedObjects);
76
+ const resultsDir = "/tmp/run-results";
77
+ if (options.outputFileId && shouldWriteToFile) {
78
+ _Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: Results saved (Run: ${options.outputFileId})`));
79
+ fs.ensureDirSync(resultsDir);
80
+ const path = `${resultsDir}/${options.outputFileId}.json`;
81
+ await fs.writeJson(path, result, {
82
+ spaces: 2
83
+ });
84
+ } else {
85
+ console.log("result:", result);
86
+ }
87
+ const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
88
+ if (hasPayloadToAppend && options.outputFileId) {
89
+ _Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
90
+ fs.ensureDirSync(resultsDir);
91
+ const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
92
+ await fs.writeJson(path, payloadToAppend, {
93
+ spaces: 2
94
+ });
95
+ } else if (hasPayloadToAppend) {
96
+ _Logger.logger.info("payload to append:", payloadToAppend);
97
+ _Logger.logger.info("This will only take an effect if this API run was part of a job.");
98
+ }
136
99
  }
137
- program
138
- .description("run the user function in the cli for testing purposes")
139
- .option("-i, --input [file]", "input json file")
140
- .option("-j, --json [json]", "input json string")
141
- .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
142
- .option("--authSessionPath <authSession>", "auth session to use when executing the api")
143
- .option("--outputFileId <outputFileId>", "the output file id to save the result in")
144
- .option("--proxy <proxy>", "proxy to use")
145
- .argument("[apiName]", "name of the api", "default")
146
- .allowUnknownOption()
147
- .addArgument(new Argument("<mode>", "mode of execution")
148
- .choices([
149
- "vanilla",
150
- "playwright",
151
- "playwright-standalone",
152
- "playwright-headless",
153
- ])
154
- .default("playwright-standalone")
155
- .argOptional())
156
- .action(async (apiName, mode, options) => {
157
- let inputData = null;
158
- if (options.input) {
159
- inputData = await fs.readJSON(options.input);
160
- }
161
- else if (options.json) {
162
- inputData = JSON.parse(options.json);
163
- }
164
- else {
165
- inputData = {};
166
- }
167
- await runWithContext({
168
- runEnvironment: RunEnvironment.IDE,
169
- extendedPayloads: [],
170
- runId: nanoid(),
171
- proxy: options.proxy,
172
- }, () => executeCLI(apiName, mode, inputData, options));
173
- // playwright keeps an open handle to the connected browser and it stops the process from exiting
174
- // there is no way to close the connection gracefully without destroying the context/browser
175
- // https://github.com/microsoft/playwright/issues/4956
176
- process.exit(0);
100
+ _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) => {
101
+ let inputData = null;
102
+ if (options.input) {
103
+ inputData = await fs.readJSON(options.input);
104
+ } else if (options.json) {
105
+ inputData = JSON.parse(options.json);
106
+ } else {
107
+ inputData = {};
108
+ }
109
+ await (0, _asyncLocalStorage.runWithContext)({
110
+ runEnvironment: _enums.RunEnvironment.IDE,
111
+ extendedPayloads: [],
112
+ runId: (0, _nanoid.nanoid)(),
113
+ proxy: options.proxy
114
+ }, () => executeCLI(apiName, mode, inputData, options));
115
+ process.exit(0);
177
116
  });
178
- program.parse(process.argv);
117
+ _commander.program.parse(process.argv);
@@ -1,30 +1,32 @@
1
1
  #!/usr/bin/env node
2
- import { program } from "commander";
3
- import { getRemotePlaywrightContext } from "../../common/getPlaywrightConstructs";
4
- import { getSettings } from "../common/utils/settings";
5
- import dotenv from "dotenv";
6
- import { loadSessionToContext } from "../../common/getPlaywrightConstructs";
7
- dotenv.config({
8
- path: `.env`,
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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ _dotenv.default.config({
10
+ path: `.env`
9
11
  });
10
- program
11
- .description("load auth session to browser")
12
- .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
13
- .option("--authSessionPath <authSession>", "auth session to use when executing the api")
14
- .allowUnknownOption()
15
- .action(async ({ cdpAddress, authSessionPath, }) => {
16
- const setting = await getSettings();
17
- if (!setting.authSessions.enabled) {
18
- throw new Error("Auth session is not enabled");
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
19
28
  }
20
- const { context } = await getRemotePlaywrightContext(cdpAddress);
21
- await loadSessionToContext({
22
- context,
23
- session: {
24
- type: "file",
25
- path: authSessionPath,
26
- },
27
- });
28
- process.exit(0);
29
+ });
30
+ process.exit(0);
29
31
  });
30
- program.parse(process.argv);
32
+ _commander.program.parse(process.argv);
@@ -1,57 +1,58 @@
1
1
  #!/usr/bin/env node
2
- import { Argument, program } from "commander";
3
- import * as fs from "fs-extra";
4
- import { getFullPathInProject } from "../common/utils/fileUtils";
5
- import { getSettings } from "../common/utils/settings";
6
- import dotenv from "dotenv";
7
- import { AUTH_SESSIONS_FOLDER_NAME } from "../../common/constants";
8
- import { runApi } from "../../common/runApi";
9
- dotenv.config({
10
- path: `.env`,
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(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 && 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; }
15
+ _dotenv.default.config({
16
+ path: `.env`
11
17
  });
12
- program
13
- .description("run auth session check")
14
- .option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222")
15
- .option("--authSessionPath <authSession>", "auth session to use when executing the check")
16
- .allowUnknownOption()
17
- .addArgument(new Argument("<mode>", "mode of execution")
18
- .choices(["vanilla", "playwright", "playwright-standalone"])
19
- .default("playwright-standalone")
20
- .argOptional())
21
- .action(async (mode, { cdpAddress, authSessionPath, }) => {
22
- const setting = await getSettings();
23
- if (!setting.authSessions.enabled) {
24
- throw new Error("auth session is not enabled");
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 checkModule = await (0, _tsNodeImport.tsNodeImport)(checkFilePath);
31
+ const runApiResult = await (0, _runApi.runApi)({
32
+ automationFunction: {
33
+ module: checkModule
34
+ },
35
+ runOptions: {
36
+ environment: "ide",
37
+ mode,
38
+ cdpAddress
39
+ },
40
+ auth: {
41
+ session: {
42
+ type: "file",
43
+ path: authSessionPath
44
+ },
45
+ runCheck: false
25
46
  }
26
- const checkFilePath = getFullPathInProject(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 runApi({
31
- automationFunction: {
32
- name: `${AUTH_SESSIONS_FOLDER_NAME}/check`,
33
- },
34
- runOptions: {
35
- environment: "ide",
36
- mode,
37
- cdpAddress,
38
- },
39
- auth: {
40
- session: {
41
- type: "file",
42
- path: authSessionPath,
43
- },
44
- runCheck: false,
45
- },
46
- });
47
- if (runApiResult.isErr()) {
48
- throw new Error(runApiResult.error);
49
- }
50
- const result = runApiResult.value.result;
51
- console.log("check result", result);
52
- if (!result) {
53
- throw new Error("auth session check failed");
54
- }
55
- process.exit(0);
47
+ });
48
+ if (runApiResult.isErr()) {
49
+ throw new Error(runApiResult.error);
50
+ }
51
+ const result = runApiResult.value.result;
52
+ console.log("check result", result);
53
+ if (!result) {
54
+ throw new Error("auth session check failed");
55
+ }
56
+ process.exit(0);
56
57
  });
57
- program.parse(process.argv);
58
+ _commander.program.parse(process.argv);