@intuned/runtime-dev 1.3.9-deploy.0 → 1.3.9-dev10

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 (223) hide show
  1. package/InterfaceTemplate/index.playwright.ts +1 -0
  2. package/bin/intuned +2 -0
  3. package/bin/intuned-api-run +2 -0
  4. package/bin/intuned-auth-session-check +2 -0
  5. package/bin/intuned-auth-session-create +2 -0
  6. package/bin/intuned-auth-session-load +2 -0
  7. package/dist/commands/common/utils/settings.js +3 -0
  8. package/dist/commands/intuned-cli/commands/attempt_api.command.js +1 -1
  9. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
  10. package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
  11. package/dist/commands/intuned-cli/controller/deploy.d.ts +0 -1
  12. package/dist/commands/intuned-cli/controller/deploy.js +6 -143
  13. package/dist/commands/intuned-cli/controller/save.d.ts +1 -4
  14. package/dist/commands/intuned-cli/controller/save.js +2 -8
  15. package/dist/commands/intuned-cli/helpers/backend.js +1 -1
  16. package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -3
  17. package/dist/commands/intuned-cli/helpers/errors.js +1 -8
  18. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +11 -113
  19. package/dist/commands/intuned-cli/helpers/intunedJson.js +3 -19
  20. package/dist/commands/intuned-cli/helpers/wrapper.js +0 -5
  21. package/dist/common/binStartupScript.d.ts +1 -0
  22. package/dist/common/binStartupScript.js +34 -0
  23. package/dist/common/settingsSchema.d.ts +13 -0
  24. package/dist/common/settingsSchema.js +6 -0
  25. package/package/dist/commands/api/run.d.ts +6 -0
  26. package/package/dist/commands/api/run.js +123 -0
  27. package/package/dist/commands/auth-sessions/load.d.ts +2 -0
  28. package/package/dist/commands/auth-sessions/load.js +35 -0
  29. package/package/dist/commands/auth-sessions/run-check.d.ts +2 -0
  30. package/package/dist/commands/auth-sessions/run-check.js +74 -0
  31. package/package/dist/commands/auth-sessions/run-create.d.ts +2 -0
  32. package/package/dist/commands/auth-sessions/run-create.js +78 -0
  33. package/package/dist/commands/browser/save-state.d.ts +2 -0
  34. package/package/dist/commands/browser/save-state.js +17 -0
  35. package/package/dist/commands/browser/start-browser.d.ts +2 -0
  36. package/package/dist/commands/browser/start-browser.js +14 -0
  37. package/package/dist/commands/build.d.ts +1 -0
  38. package/package/dist/commands/build.js +84 -0
  39. package/package/dist/commands/common/browserUtils.d.ts +14 -0
  40. package/package/dist/commands/common/browserUtils.js +58 -0
  41. package/package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
  42. package/package/dist/commands/common/getFirstLineNumber.js +101 -0
  43. package/package/dist/commands/common/getFirstLineNumber.test.js +228 -0
  44. package/package/dist/commands/common/projectExclusions.d.ts +2 -0
  45. package/package/dist/commands/common/projectExclusions.js +8 -0
  46. package/package/dist/commands/common/sendMessageToClient.d.ts +1 -0
  47. package/package/dist/commands/common/sendMessageToClient.js +10 -0
  48. package/package/dist/commands/common/tsNodeImport.d.ts +2 -0
  49. package/package/dist/commands/common/tsNodeImport.js +34 -0
  50. package/package/dist/commands/common/utils/fileUtils.d.ts +6 -0
  51. package/package/dist/commands/common/utils/fileUtils.js +33 -0
  52. package/package/dist/commands/common/utils/settings.d.ts +2 -0
  53. package/package/dist/commands/common/utils/settings.js +31 -0
  54. package/package/dist/commands/common/utils/template.d.ts +2 -0
  55. package/package/dist/commands/common/utils/template.js +31 -0
  56. package/package/dist/commands/common/utils/unixSocket.d.ts +9 -0
  57. package/package/dist/commands/common/utils/unixSocket.js +44 -0
  58. package/package/dist/commands/interface/run.d.ts +1 -0
  59. package/package/dist/commands/interface/run.js +216 -0
  60. package/package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  61. package/package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  62. package/package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  63. package/package/dist/commands/intuned-cli/commands/attempt_api.command.js +30 -0
  64. package/package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  65. package/package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  66. package/package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  67. package/package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +19 -0
  68. package/package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  69. package/package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +24 -0
  70. package/package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
  71. package/package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
  72. package/package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
  73. package/package/dist/commands/intuned-cli/commands/authsession_record.command.js +31 -0
  74. package/package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  75. package/package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  76. package/package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  77. package/package/dist/commands/intuned-cli/commands/command.js +9 -0
  78. package/package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  79. package/package/dist/commands/intuned-cli/commands/deploy.command.js +38 -0
  80. package/package/dist/commands/intuned-cli/commands/index.d.ts +18 -0
  81. package/package/dist/commands/intuned-cli/commands/index.js +203 -0
  82. package/package/dist/commands/intuned-cli/commands/init.command.d.ts +1 -0
  83. package/package/dist/commands/intuned-cli/commands/init.command.js +13 -0
  84. package/package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  85. package/package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  86. package/package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  87. package/package/dist/commands/intuned-cli/commands/run_api.command.js +46 -0
  88. package/package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +28 -0
  89. package/package/dist/commands/intuned-cli/commands/run_authsession.command.js +17 -0
  90. package/package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  91. package/package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +35 -0
  92. package/package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  93. package/package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +35 -0
  94. package/package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  95. package/package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +33 -0
  96. package/package/dist/commands/intuned-cli/commands/save.command.d.ts +13 -0
  97. package/package/dist/commands/intuned-cli/commands/save.command.js +42 -0
  98. package/package/dist/commands/intuned-cli/commands/types.d.ts +31 -0
  99. package/package/dist/commands/intuned-cli/commands/types.js +29 -0
  100. package/package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
  101. package/package/dist/commands/intuned-cli/constants/index.js +25 -0
  102. package/package/dist/commands/intuned-cli/controller/__test__/api.test.js +397 -0
  103. package/package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +1059 -0
  104. package/package/dist/commands/intuned-cli/controller/api.d.ts +42 -0
  105. package/package/dist/commands/intuned-cli/controller/api.js +189 -0
  106. package/package/dist/commands/intuned-cli/controller/authSession.d.ts +209 -0
  107. package/package/dist/commands/intuned-cli/controller/authSession.js +420 -0
  108. package/package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  109. package/package/dist/commands/intuned-cli/controller/build.js +36 -0
  110. package/package/dist/commands/intuned-cli/controller/deploy.d.ts +4 -0
  111. package/package/dist/commands/intuned-cli/controller/deploy.js +139 -0
  112. package/package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  113. package/package/dist/commands/intuned-cli/controller/index.js +46 -0
  114. package/package/dist/commands/intuned-cli/controller/save.d.ts +14 -0
  115. package/package/dist/commands/intuned-cli/controller/save.js +345 -0
  116. package/package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +103 -0
  117. package/package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +40 -0
  118. package/package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  119. package/package/dist/commands/intuned-cli/helpers/api.js +19 -0
  120. package/package/dist/commands/intuned-cli/helpers/auth.d.ts +46 -0
  121. package/package/dist/commands/intuned-cli/helpers/auth.js +144 -0
  122. package/package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  123. package/package/dist/commands/intuned-cli/helpers/backend.js +27 -0
  124. package/package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
  125. package/package/dist/commands/intuned-cli/helpers/browser.js +57 -0
  126. package/package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  127. package/package/dist/commands/intuned-cli/helpers/context.js +33 -0
  128. package/package/dist/commands/intuned-cli/helpers/errors.d.ts +13 -0
  129. package/package/dist/commands/intuned-cli/helpers/errors.js +37 -0
  130. package/package/dist/commands/intuned-cli/helpers/index.d.ts +12 -0
  131. package/package/dist/commands/intuned-cli/helpers/index.js +137 -0
  132. package/package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +69 -0
  133. package/package/dist/commands/intuned-cli/helpers/intunedJson.js +71 -0
  134. package/package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  135. package/package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  136. package/package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  137. package/package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  138. package/package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  139. package/package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  140. package/package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
  141. package/package/dist/commands/intuned-cli/helpers/traces.js +32 -0
  142. package/package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  143. package/package/dist/commands/intuned-cli/helpers/validation.js +14 -0
  144. package/package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
  145. package/package/dist/commands/intuned-cli/helpers/wrapper.js +60 -0
  146. package/package/dist/commands/intuned-cli/index.d.ts +1 -0
  147. package/package/dist/commands/intuned-cli/index.js +16 -0
  148. package/package/dist/commands/intuned-cli/main.d.ts +1 -0
  149. package/package/dist/commands/intuned-cli/main.js +22 -0
  150. package/package/dist/commands/intuned-cli/types.d.ts +41 -0
  151. package/package/dist/commands/intuned-cli/types.js +12 -0
  152. package/package/dist/commands/ts-check.d.ts +2 -0
  153. package/package/dist/commands/ts-check.js +56 -0
  154. package/package/dist/common/Logger/Logger/index.d.ts +12 -0
  155. package/package/dist/common/Logger/Logger/index.js +60 -0
  156. package/package/dist/common/Logger/Logger/types.d.ts +8 -0
  157. package/package/dist/common/Logger/Logger/types.js +5 -0
  158. package/package/dist/common/Logger/index.d.ts +12 -0
  159. package/package/dist/common/Logger/index.js +60 -0
  160. package/package/dist/common/Logger/types.d.ts +8 -0
  161. package/package/dist/common/Logger/types.js +5 -0
  162. package/package/dist/common/assets/browser_scripts.js +2580 -0
  163. package/package/dist/common/asyncLocalStorage/index.d.ts +16 -0
  164. package/package/dist/common/asyncLocalStorage/index.js +17 -0
  165. package/package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
  166. package/package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
  167. package/package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
  168. package/package/dist/common/cleanEnvironmentVariables.js +16 -0
  169. package/package/dist/common/constants.d.ts +10 -0
  170. package/package/dist/common/constants.js +16 -0
  171. package/package/dist/common/contextStorageStateHelpers.d.ts +21 -0
  172. package/package/dist/common/contextStorageStateHelpers.js +81 -0
  173. package/package/dist/common/extensionsHelpers.d.ts +8 -0
  174. package/package/dist/common/extensionsHelpers.js +80 -0
  175. package/package/dist/common/formatZodError.d.ts +2 -0
  176. package/package/dist/common/formatZodError.js +18 -0
  177. package/package/dist/common/jwtTokenManager.d.ts +17 -0
  178. package/package/dist/common/jwtTokenManager.js +109 -0
  179. package/package/dist/common/launchBrowser.d.ts +25 -0
  180. package/package/dist/common/launchBrowser.js +172 -0
  181. package/package/dist/common/playwrightContext.d.ts +31 -0
  182. package/package/dist/common/playwrightContext.js +144 -0
  183. package/package/dist/common/runApi/errors.d.ts +72 -0
  184. package/package/dist/common/runApi/errors.js +169 -0
  185. package/package/dist/common/runApi/importUsingImportFunction.d.ts +9 -0
  186. package/package/dist/common/runApi/importUsingImportFunction.js +46 -0
  187. package/package/dist/common/runApi/index.d.ts +11 -0
  188. package/package/dist/common/runApi/index.js +199 -0
  189. package/package/dist/common/runApi/types.d.ts +830 -0
  190. package/package/dist/common/runApi/types.js +73 -0
  191. package/package/dist/common/settingsSchema.d.ts +518 -0
  192. package/package/dist/common/settingsSchema.js +57 -0
  193. package/package/dist/common/setupContextHook.d.ts +17 -0
  194. package/package/dist/common/setupContextHook.js +22 -0
  195. package/package/dist/common/telemetry.d.ts +3 -0
  196. package/package/dist/common/telemetry.js +32 -0
  197. package/package/dist/index.d.ts +4 -0
  198. package/package/dist/index.js +69 -0
  199. package/package/dist/runtime/RunError.d.ts +5 -0
  200. package/package/dist/runtime/RunError.js +19 -0
  201. package/package/dist/runtime/attemptStore.d.ts +2 -0
  202. package/package/dist/runtime/attemptStore.js +23 -0
  203. package/package/dist/runtime/downloadDirectory.d.ts +1 -0
  204. package/package/dist/runtime/downloadDirectory.js +19 -0
  205. package/package/dist/runtime/enums.d.js +5 -0
  206. package/package/dist/runtime/enums.d.ts +11 -0
  207. package/package/dist/runtime/enums.js +18 -0
  208. package/package/dist/runtime/executionHelpers.test.js +52 -0
  209. package/package/dist/runtime/export.d.js +5 -0
  210. package/package/dist/runtime/export.d.ts +228 -0
  211. package/package/dist/runtime/extendPayload.d.ts +2 -0
  212. package/package/dist/runtime/extendPayload.js +21 -0
  213. package/package/dist/runtime/extendTimeout.d.ts +1 -0
  214. package/package/dist/runtime/extendTimeout.js +23 -0
  215. package/package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
  216. package/package/dist/runtime/getAuthSessionParameters.js +20 -0
  217. package/package/dist/runtime/index.d.ts +7 -0
  218. package/package/dist/runtime/index.js +54 -0
  219. package/package/dist/runtime/runInfo.d.ts +2 -0
  220. package/package/dist/runtime/runInfo.js +21 -0
  221. package/package.json +3 -5
  222. package/WebTemplate.zip +0 -0
  223. package/bin/intuned-auth-session-refresh +0 -2
@@ -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,123 @@
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
+ var _isNil = _interopRequireDefault(require("lodash/isNil"));
21
+ var _constants = require("../../common/constants");
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
+ 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); }
24
+ 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; }
25
+ _dotenv.default.config({
26
+ path: `.env`
27
+ });
28
+ async function executeCLI(apiName, mode, inputData, options) {
29
+ (0, _cleanEnvironmentVariables.cleanEnvironmentVariables)();
30
+ let authSessionPathToUse = null;
31
+ const settings = await (0, _settings.getSettings)();
32
+ if (settings.authSessions.enabled) {
33
+ if (!options.authSessionPath) {
34
+ throw new Error("Auth session is enabled but no auth session provided");
35
+ }
36
+ authSessionPathToUse = options.authSessionPath;
37
+ } else {
38
+ if (options.authSessionPath) {
39
+ throw new Error("Auth session is not enabled but auth session provided. To use auth session please enable it in Intuned.json");
40
+ }
41
+ }
42
+ const runApiResult = await (0, _runApi.runApi)({
43
+ automationFunction: {
44
+ name: `${_constants.API_FOLDER_NAME}/${apiName}`,
45
+ params: inputData
46
+ },
47
+ auth: authSessionPathToUse ? {
48
+ session: {
49
+ type: "file",
50
+ path: authSessionPathToUse
51
+ }
52
+ } : undefined,
53
+ runOptions: {
54
+ environment: "cdp",
55
+ cdpAddress: options.cdpAddress
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, {
80
+ input: inputData,
81
+ output: result
82
+ }, {
83
+ spaces: 2
84
+ });
85
+ } else {
86
+ console.log("result:", result);
87
+ }
88
+ const hasPayloadToAppend = payloadToAppend && payloadToAppend.length > 0;
89
+ if (hasPayloadToAppend && options.outputFileId) {
90
+ _Logger.logger.info(_chalk.default.underline.bgBlue.white(`Click to Open: payloads to append (Run: ${options.outputFileId})`));
91
+ fs.ensureDirSync(resultsDir);
92
+ const path = `${resultsDir}/${options.outputFileId}-payloads-to-append.json`;
93
+ await fs.writeJson(path, payloadToAppend, {
94
+ spaces: 2
95
+ });
96
+ } else if (hasPayloadToAppend) {
97
+ _Logger.logger.info("payload to append:", payloadToAppend);
98
+ _Logger.logger.info("This will only take an effect if this API run was part of a job.");
99
+ }
100
+ }
101
+ _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").option("--authSessionParameters <authSessionParameters>", "parameters used to create the used auth session").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) => {
102
+ let inputData = null;
103
+ if (options.input) {
104
+ inputData = await fs.readJSON(options.input);
105
+ } else if (options.json) {
106
+ inputData = JSON.parse(options.json);
107
+ } else {
108
+ inputData = {};
109
+ }
110
+ let authSessionParametersJson = undefined;
111
+ if (!(0, _isNil.default)(options?.authSessionParameters)) {
112
+ authSessionParametersJson = JSON.parse(options.authSessionParameters);
113
+ }
114
+ await (0, _asyncLocalStorage.runWithContext)({
115
+ runEnvironment: _enums.RunEnvironment.IDE,
116
+ extendedPayloads: [],
117
+ runId: (0, _nanoid.nanoid)(),
118
+ proxy: options.proxy,
119
+ getAuthSessionParameters: authSessionParametersJson !== undefined ? async () => authSessionParametersJson : undefined
120
+ }, () => executeCLI(apiName, mode, inputData, options));
121
+ process.exit(0);
122
+ });
123
+ _commander.program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ var _commander = require("commander");
5
+ var _playwrightContext = require("../../common/playwrightContext");
6
+ var _settings = require("../common/utils/settings");
7
+ var _dotenv = _interopRequireDefault(require("dotenv"));
8
+ var _neverthrow = require("neverthrow");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ _dotenv.default.config({
11
+ path: `.env`
12
+ });
13
+ _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 ({
14
+ cdpAddress,
15
+ authSessionPath
16
+ }) => {
17
+ const setting = await (0, _settings.getSettings)();
18
+ if (!setting.authSessions.enabled) {
19
+ throw new Error("Auth session is not enabled");
20
+ }
21
+ await (0, _playwrightContext.withPlaywrightContext)({
22
+ cdpAddress
23
+ }, async context => {
24
+ await (0, _playwrightContext.loadSessionToContext)({
25
+ context,
26
+ session: {
27
+ type: "file",
28
+ path: authSessionPath
29
+ }
30
+ });
31
+ return (0, _neverthrow.ok)({});
32
+ });
33
+ process.exit(0);
34
+ });
35
+ _commander.program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,74 @@
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
+ var _enums = require("../../runtime/enums");
13
+ var _nanoid = require("nanoid");
14
+ var _asyncLocalStorage = require("../../common/asyncLocalStorage");
15
+ var _isNil = _interopRequireDefault(require("lodash/isNil"));
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 check").option("--cdpAddress <cdpAddress>", "CDP address", "http://localhost:9222").option("--authSessionPath <authSession>", "auth session to use when executing the check").option("--authSessionParameters <authSessionParameters>", "parameters used to create the used 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
+ authSessionPath,
25
+ authSessionParameters
26
+ }) => {
27
+ const setting = await (0, _settings.getSettings)();
28
+ if (!setting.authSessions.enabled) {
29
+ throw new Error("auth session is not enabled");
30
+ }
31
+ const checkFilePath = (0, _fileUtils.getFullPathInProject)(_constants.AUTH_SESSIONS_FOLDER_NAME, "check");
32
+ if (!fs.exists(checkFilePath)) {
33
+ throw new Error("auth session check file not found");
34
+ }
35
+ let authSessionParametersJson = undefined;
36
+ if (!(0, _isNil.default)(authSessionParameters)) {
37
+ authSessionParametersJson = JSON.parse(authSessionParameters);
38
+ }
39
+ const runApiResult = await (0, _asyncLocalStorage.runWithContext)({
40
+ runEnvironment: _enums.RunEnvironment.IDE,
41
+ extendedPayloads: [],
42
+ runId: (0, _nanoid.nanoid)(),
43
+ getAuthSessionParameters: authSessionParametersJson !== undefined ? async () => authSessionParametersJson : undefined
44
+ }, async () => await (0, _runApi.runApi)({
45
+ automationFunction: {
46
+ name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`
47
+ },
48
+ runOptions: {
49
+ environment: "cdp",
50
+ cdpAddress
51
+ },
52
+ auth: {
53
+ session: {
54
+ type: "file",
55
+ path: authSessionPath
56
+ }
57
+ },
58
+ importFunction: _tsNodeImport.tsNodeImport
59
+ }));
60
+ if (runApiResult.isErr()) {
61
+ if (runApiResult.error instanceof _runApi.AutomationError) {
62
+ throw runApiResult.error.error;
63
+ }
64
+ console.error(runApiResult.error);
65
+ throw new Error("Error running auth session check");
66
+ }
67
+ const result = runApiResult.value.result;
68
+ console.log("check result", result);
69
+ if (!result) {
70
+ throw new Error("auth session check failed");
71
+ }
72
+ process.exit(0);
73
+ });
74
+ _commander.program.parse(process.argv);
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,78 @@
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 _asyncLocalStorage = require("../../common/asyncLocalStorage");
12
+ var _nanoid = require("nanoid");
13
+ var _enums = require("../../runtime/enums");
14
+ var _tsNodeImport = require("../common/tsNodeImport");
15
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ 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); }
17
+ 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; }
18
+ _dotenv.default.config({
19
+ path: `.env`
20
+ });
21
+ _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, {
22
+ cdpAddress,
23
+ pathToSave,
24
+ input,
25
+ json
26
+ }) => {
27
+ let inputData = null;
28
+ if (input) {
29
+ inputData = await fs.readJSON(input);
30
+ } else if (json) {
31
+ inputData = JSON.parse(json);
32
+ } else {
33
+ inputData = {};
34
+ }
35
+ const setting = await (0, _settings.getSettings)();
36
+ if (!setting.authSessions.enabled) {
37
+ throw new Error("auth sessions feature is not enabled");
38
+ }
39
+ const createFilePath = (0, _fileUtils.getFullPathInProject)(_constants.AUTH_SESSIONS_FOLDER_NAME, "create.ts");
40
+ if (!fs.exists(createFilePath)) {
41
+ throw new Error("auth session create file not found");
42
+ }
43
+ async function runCreate() {
44
+ const result = await (0, _runApi.runApi)({
45
+ automationFunction: {
46
+ name: `${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`,
47
+ params: inputData
48
+ },
49
+ runOptions: {
50
+ environment: "cdp",
51
+ cdpAddress
52
+ },
53
+ retrieveSession: true,
54
+ importFunction: _tsNodeImport.tsNodeImport
55
+ });
56
+ if (result.isErr()) {
57
+ if (result.error instanceof _runApi.AutomationError) {
58
+ throw result.error.error;
59
+ }
60
+ console.error(result.error);
61
+ throw new Error("Error while running create");
62
+ }
63
+ const fullState = result.value.session;
64
+ if (pathToSave) {
65
+ const fullPath = (0, _fileUtils.getFullPathInProject)(pathToSave);
66
+ fs.ensureFileSync(fullPath);
67
+ await fs.writeJSON(fullPath, fullState);
68
+ }
69
+ }
70
+ await (0, _asyncLocalStorage.runWithContext)({
71
+ runEnvironment: _enums.RunEnvironment.IDE,
72
+ extendedPayloads: [],
73
+ runId: (0, _nanoid.nanoid)(),
74
+ getAuthSessionParameters: async () => inputData
75
+ }, runCreate);
76
+ process.exit(0);
77
+ });
78
+ _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";
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>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getChromiumLaunchArgs = exports.REMOTE_DEBUGGING_PORT = void 0;
7
+ exports.loadState = loadState;
8
+ exports.saveSession = saveSession;
9
+ exports.saveSessionFromOpenedBrowser = saveSessionFromOpenedBrowser;
10
+ exports.startOrRestartBrowser = startOrRestartBrowser;
11
+ var _child_process = require("child_process");
12
+ var playwright = _interopRequireWildcard(require("playwright"));
13
+ var fs = _interopRequireWildcard(require("fs-extra"));
14
+ var _fileUtils = require("./utils/fileUtils");
15
+ var _contextStorageStateHelpers = require("../../common/contextStorageStateHelpers");
16
+ 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); }
17
+ 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; }
18
+ const REMOTE_DEBUGGING_PORT = exports.REMOTE_DEBUGGING_PORT = 9222;
19
+ const getChromiumLaunchArgs = () => ["--no-sandbox", `--remote-debugging-port=${REMOTE_DEBUGGING_PORT}`, `--user-data-dir=/tmp/${Date.now()}`, "--new-window", "--start-maximized", "--disable-popup-blocking"];
20
+ exports.getChromiumLaunchArgs = getChromiumLaunchArgs;
21
+ async function getBrowser() {
22
+ let playwrightBrowser = null;
23
+ try {
24
+ playwrightBrowser = await playwright.chromium.connectOverCDP(`http://localhost:${REMOTE_DEBUGGING_PORT}`);
25
+ } catch (e) {
26
+ throw new Error("Browser is not running");
27
+ }
28
+ return playwrightBrowser;
29
+ }
30
+ async function startOrRestartBrowser() {
31
+ const chromiumPath = await playwright.chromium.executablePath();
32
+ const chromeInstanceProcess = (0, _child_process.spawn)(chromiumPath, getChromiumLaunchArgs());
33
+ chromeInstanceProcess.stdout.on("data", data => {
34
+ console.log(`Chrome stdout: ${data}`);
35
+ });
36
+ chromeInstanceProcess.stderr.on("data", data => {
37
+ console.error(`Chrome stderr: ${data}`);
38
+ });
39
+ }
40
+ async function saveSessionFromOpenedBrowser(path) {
41
+ const browser = await getBrowser();
42
+ const context = await browser.contexts()[0];
43
+ return saveSession(path, context);
44
+ }
45
+ async function loadState(path, context) {
46
+ const fullPath = (0, _fileUtils.getFullPathInProject)(path);
47
+ if (!(await fs.pathExists(fullPath))) {
48
+ throw new Error("session file does not exist");
49
+ }
50
+ const data = await fs.readJson(fullPath);
51
+ await context.addCookies(data.cookies);
52
+ }
53
+ async function saveSession(path, context) {
54
+ const fullState = await (0, _contextStorageStateHelpers.getStorageState)(context);
55
+ const fullPath = (0, _fileUtils.getFullPathInProject)(path);
56
+ fs.ensureFileSync(fullPath);
57
+ await fs.writeJSON(fullPath, fullState);
58
+ }
@@ -0,0 +1,9 @@
1
+ import { SourceFile } from "ts-morph";
2
+ export declare function findFirstExecutableLine(sourceFile: SourceFile): -1 | {
3
+ line: number;
4
+ column: number;
5
+ };
6
+ export default function getFirstLineNumber(apiFilePath: string): Promise<{
7
+ sourceFileName: string;
8
+ lineNumber: number;
9
+ }>;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = getFirstLineNumber;
7
+ exports.findFirstExecutableLine = findFirstExecutableLine;
8
+ var _tsMorph = require("ts-morph");
9
+ var _sourceMap = require("source-map");
10
+ function compileTypeScript(apiFilePath) {
11
+ const compilerOptions = {
12
+ lib: ["dom", "es2020"],
13
+ sourceMap: true,
14
+ inlineSourceMap: true,
15
+ inlineSources: true,
16
+ declaration: false,
17
+ noEmit: false,
18
+ module: _tsMorph.ModuleKind.CommonJS,
19
+ target: _tsMorph.ScriptTarget.ES2020
20
+ };
21
+ const project = new _tsMorph.Project({
22
+ compilerOptions
23
+ });
24
+ const sourceFile = project.addSourceFileAtPath(apiFilePath);
25
+ const outputJS = project.emitToMemory({
26
+ targetSourceFile: sourceFile
27
+ });
28
+ const outputJSText = outputJS.getFiles()[0].text;
29
+ return {
30
+ sourceFile,
31
+ outputJSText
32
+ };
33
+ }
34
+ function findFirstExecutableLine(sourceFile) {
35
+ let functionBody;
36
+ const defaultExportSymbol = sourceFile.getDefaultExportSymbol();
37
+ const defaultExportDeclaration = defaultExportSymbol?.getDeclarations()?.[0];
38
+ if (defaultExportDeclaration) {
39
+ if (defaultExportDeclaration.getKind() === _tsMorph.ts.SyntaxKind.FunctionDeclaration) {
40
+ functionBody = defaultExportDeclaration.getBody();
41
+ } else {
42
+ const exportAssignments = sourceFile.getExportAssignments();
43
+ for (const exportAssignment of exportAssignments) {
44
+ const expression = exportAssignment.getExpression();
45
+ if (!expression) continue;
46
+ if (expression.getKind() === _tsMorph.ts.SyntaxKind.Identifier || expression.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || expression.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction) {
47
+ const identifier = expression.getText();
48
+ const possiblyExportedFunction = sourceFile.getFunction(identifier) || sourceFile.getVariableStatement(identifier)?.getDescendants().find(node => node.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || node.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction);
49
+ if (possiblyExportedFunction) {
50
+ functionBody = possiblyExportedFunction.getBody();
51
+ break;
52
+ }
53
+ }
54
+ if (_tsMorph.Node.hasBody(expression) && (expression.getKind() === _tsMorph.ts.SyntaxKind.FunctionExpression || expression.getKind() === _tsMorph.ts.SyntaxKind.ArrowFunction)) {
55
+ functionBody = expression.getBody();
56
+ break;
57
+ }
58
+ }
59
+ }
60
+ }
61
+ if (!functionBody || !_tsMorph.Node.isStatemented(functionBody)) {
62
+ return -1;
63
+ }
64
+ if (functionBody.getStatements().length === 0) {
65
+ return -1;
66
+ }
67
+ const position = functionBody.getStatements()[0].getStart();
68
+ return sourceFile.getLineAndColumnAtPos(position);
69
+ }
70
+ async function getSourceMap(jsCode) {
71
+ const sourceMapBase64 = jsCode.substring(jsCode.lastIndexOf("//# sourceMappingURL=data:application/json;base64,") + "//# sourceMappingURL=data:application/json;base64,".length);
72
+ const sourceMapText = Buffer.from(sourceMapBase64, "base64").toString("utf-8");
73
+ const sourceMap = JSON.parse(sourceMapText);
74
+ return new _sourceMap.SourceMapConsumer(sourceMap);
75
+ }
76
+ async function mapFirstLineNumberBySourceMap(sourceFileName, jsCode, line, column) {
77
+ const sourceMap = await getSourceMap(jsCode);
78
+ const generatedLineNumber = sourceMap.generatedPositionFor({
79
+ source: sourceFileName,
80
+ line,
81
+ column
82
+ }).line;
83
+ if (!generatedLineNumber) return -1;
84
+ return generatedLineNumber;
85
+ }
86
+ async function getFirstLineNumber(apiFilePath) {
87
+ const sourceFileName = apiFilePath.split("/").pop() ?? apiFilePath;
88
+ const {
89
+ sourceFile,
90
+ outputJSText
91
+ } = compileTypeScript(apiFilePath);
92
+ const result = findFirstExecutableLine(sourceFile);
93
+ if (result === -1) return {
94
+ sourceFileName,
95
+ lineNumber: -1
96
+ };
97
+ return {
98
+ sourceFileName,
99
+ lineNumber: await mapFirstLineNumberBySourceMap(sourceFileName, outputJSText, result.line, result.column)
100
+ };
101
+ }