@intuned/runtime-dev 1.3.18-interface.2 → 1.3.18-interface.21

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 (225) hide show
  1. package/.babelrc +6 -0
  2. package/.claude/settings.local.json +7 -0
  3. package/InterfaceTemplate/__utils.ts +3 -1
  4. package/dist/commands/api/run.d.ts +6 -0
  5. package/dist/commands/api/run.js +119 -0
  6. package/dist/commands/auth-sessions/load.d.ts +2 -0
  7. package/dist/commands/auth-sessions/load.js +35 -0
  8. package/dist/commands/auth-sessions/run-check.d.ts +2 -0
  9. package/dist/commands/auth-sessions/run-check.js +74 -0
  10. package/dist/commands/auth-sessions/run-create.d.ts +2 -0
  11. package/dist/commands/auth-sessions/run-create.js +78 -0
  12. package/dist/commands/browser/save-state.d.ts +2 -0
  13. package/dist/commands/browser/save-state.js +17 -0
  14. package/dist/commands/browser/start-browser.d.ts +2 -0
  15. package/dist/commands/browser/start-browser.js +14 -0
  16. package/dist/commands/build.d.ts +1 -0
  17. package/dist/commands/build.js +83 -0
  18. package/dist/commands/common/browserUtils.d.ts +14 -0
  19. package/dist/commands/common/browserUtils.js +57 -0
  20. package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
  21. package/dist/commands/common/getFirstLineNumber.js +101 -0
  22. package/dist/commands/common/getFirstLineNumber.test.js +227 -0
  23. package/dist/commands/common/projectExclusions.d.ts +2 -0
  24. package/dist/commands/common/projectExclusions.js +8 -0
  25. package/dist/commands/common/sendMessageToClient.d.ts +1 -0
  26. package/dist/commands/common/sendMessageToClient.js +10 -0
  27. package/dist/commands/common/tsNodeImport.d.ts +2 -0
  28. package/dist/commands/common/tsNodeImport.js +42 -0
  29. package/dist/commands/common/utils/fileUtils.d.ts +6 -0
  30. package/dist/commands/common/utils/fileUtils.js +32 -0
  31. package/dist/commands/common/utils/interfaceClient.d.ts +31 -0
  32. package/dist/commands/common/utils/interfaceClient.js +98 -0
  33. package/dist/commands/common/utils/settings.d.ts +2 -0
  34. package/dist/commands/common/utils/settings.js +31 -0
  35. package/dist/commands/common/utils/template.d.ts +2 -0
  36. package/dist/commands/common/utils/template.js +30 -0
  37. package/dist/commands/get-headless-user-agent.d.ts +1 -0
  38. package/dist/commands/get-headless-user-agent.js +18 -0
  39. package/dist/commands/interface/run.d.ts +1 -0
  40. package/dist/commands/interface/run.js +189 -0
  41. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  42. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  43. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  44. package/dist/commands/intuned-cli/commands/attempt_api.command.js +30 -0
  45. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  46. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  47. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  48. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +19 -0
  49. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  50. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +24 -0
  51. package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
  52. package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
  53. package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
  54. package/dist/commands/intuned-cli/commands/authsession_record.command.js +32 -0
  55. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +1 -0
  56. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +16 -0
  57. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  58. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  59. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  60. package/dist/commands/intuned-cli/commands/command.js +9 -0
  61. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  62. package/dist/commands/intuned-cli/commands/deploy.command.js +42 -0
  63. package/dist/commands/intuned-cli/commands/index.d.ts +18 -0
  64. package/dist/commands/intuned-cli/commands/index.js +203 -0
  65. package/dist/commands/intuned-cli/commands/provision.command.d.ts +13 -0
  66. package/dist/commands/intuned-cli/commands/provision.command.js +50 -0
  67. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  68. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  69. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  70. package/dist/commands/intuned-cli/commands/run_api.command.js +46 -0
  71. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +35 -0
  72. package/dist/commands/intuned-cli/commands/run_authsession.command.js +17 -0
  73. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  74. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +35 -0
  75. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  76. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +35 -0
  77. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  78. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +33 -0
  79. package/dist/commands/intuned-cli/commands/types.d.ts +39 -0
  80. package/dist/commands/intuned-cli/commands/types.js +33 -0
  81. package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
  82. package/dist/commands/intuned-cli/constants/index.js +25 -0
  83. package/dist/commands/intuned-cli/controller/__test__/api.test.js +399 -0
  84. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +1061 -0
  85. package/dist/commands/intuned-cli/controller/api.d.ts +42 -0
  86. package/dist/commands/intuned-cli/controller/api.js +194 -0
  87. package/dist/commands/intuned-cli/controller/authSession.d.ts +209 -0
  88. package/dist/commands/intuned-cli/controller/authSession.js +425 -0
  89. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  90. package/dist/commands/intuned-cli/controller/build.js +35 -0
  91. package/dist/commands/intuned-cli/controller/deploy.d.ts +5 -0
  92. package/dist/commands/intuned-cli/controller/deploy.js +317 -0
  93. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  94. package/dist/commands/intuned-cli/controller/index.js +45 -0
  95. package/dist/commands/intuned-cli/controller/provision.d.ts +21 -0
  96. package/dist/commands/intuned-cli/controller/provision.js +299 -0
  97. package/dist/commands/intuned-cli/controller/scaffold.d.ts +1 -0
  98. package/dist/commands/intuned-cli/controller/scaffold.js +77 -0
  99. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +152 -0
  100. package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +41 -0
  101. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  102. package/dist/commands/intuned-cli/helpers/api.js +16 -0
  103. package/dist/commands/intuned-cli/helpers/auth.d.ts +46 -0
  104. package/dist/commands/intuned-cli/helpers/auth.js +147 -0
  105. package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  106. package/dist/commands/intuned-cli/helpers/backend.js +35 -0
  107. package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
  108. package/dist/commands/intuned-cli/helpers/browser.js +93 -0
  109. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  110. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  111. package/dist/commands/intuned-cli/helpers/errors.d.ts +16 -0
  112. package/dist/commands/intuned-cli/helpers/errors.js +44 -0
  113. package/dist/commands/intuned-cli/helpers/index.d.ts +12 -0
  114. package/dist/commands/intuned-cli/helpers/index.js +137 -0
  115. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +39 -0
  116. package/dist/commands/intuned-cli/helpers/intunedJson.js +20 -0
  117. package/dist/commands/intuned-cli/helpers/prompts.d.ts +3 -0
  118. package/dist/commands/intuned-cli/helpers/prompts.js +71 -0
  119. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  120. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  121. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  122. package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  123. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  124. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  125. package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
  126. package/dist/commands/intuned-cli/helpers/traces.js +32 -0
  127. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  128. package/dist/commands/intuned-cli/helpers/validation.js +14 -0
  129. package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
  130. package/dist/commands/intuned-cli/helpers/wrapper.js +76 -0
  131. package/dist/commands/intuned-cli/index.d.ts +1 -0
  132. package/dist/commands/intuned-cli/index.js +16 -0
  133. package/dist/commands/intuned-cli/main.d.ts +1 -0
  134. package/dist/commands/intuned-cli/main.js +35 -0
  135. package/dist/commands/intuned-cli/types.d.ts +70 -0
  136. package/dist/commands/intuned-cli/types.js +22 -0
  137. package/dist/commands/ts-check.d.ts +2 -0
  138. package/dist/commands/ts-check.js +55 -0
  139. package/dist/common/Logger/Logger/index.d.ts +12 -0
  140. package/dist/common/Logger/Logger/index.js +60 -0
  141. package/dist/common/Logger/Logger/types.d.ts +8 -0
  142. package/dist/common/Logger/Logger/types.js +5 -0
  143. package/dist/common/Logger/index.d.ts +12 -0
  144. package/dist/common/Logger/index.js +60 -0
  145. package/dist/common/Logger/types.d.ts +8 -0
  146. package/dist/common/Logger/types.js +5 -0
  147. package/dist/common/assets/browser_scripts.js +2580 -0
  148. package/dist/common/asyncLocalStorage/index.d.ts +16 -0
  149. package/dist/common/asyncLocalStorage/index.js +17 -0
  150. package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
  151. package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
  152. package/dist/common/binStartupScript.d.ts +1 -0
  153. package/dist/common/binStartupScript.js +36 -0
  154. package/dist/common/browserTabs.d.ts +72 -0
  155. package/dist/common/browserTabs.js +74 -0
  156. package/dist/common/cleanEnvironmentVariables.d.ts +1 -0
  157. package/dist/common/cleanEnvironmentVariables.js +16 -0
  158. package/dist/common/constants.d.ts +11 -0
  159. package/dist/common/constants.js +17 -0
  160. package/dist/common/contextStorageStateHelpers.d.ts +22 -0
  161. package/dist/common/contextStorageStateHelpers.js +84 -0
  162. package/dist/common/extension/extensionsHelpers.d.ts +11 -0
  163. package/dist/common/extension/extensionsHelpers.js +147 -0
  164. package/dist/common/extension/intunedExtensionServer.d.ts +24 -0
  165. package/dist/common/extension/intunedExtensionServer.js +178 -0
  166. package/dist/common/extension/types.d.ts +219 -0
  167. package/dist/common/extension/types.js +51 -0
  168. package/dist/common/formatZodError.d.ts +2 -0
  169. package/dist/common/formatZodError.js +18 -0
  170. package/dist/common/intunedJson.d.ts +229 -0
  171. package/dist/common/intunedJson.js +132 -0
  172. package/dist/common/jwtTokenManager.d.ts +17 -0
  173. package/dist/common/jwtTokenManager.js +113 -0
  174. package/dist/common/launchBrowser.d.ts +34 -0
  175. package/dist/common/launchBrowser.js +247 -0
  176. package/dist/common/playwrightContext.d.ts +29 -0
  177. package/dist/common/playwrightContext.js +148 -0
  178. package/dist/common/runApi/importUsingImportFunction.d.ts +7 -0
  179. package/dist/common/runApi/importUsingImportFunction.js +46 -0
  180. package/dist/common/runApi/index.d.ts +8 -0
  181. package/dist/common/runApi/index.js +177 -0
  182. package/dist/common/settingsSchema.d.ts +537 -0
  183. package/dist/common/settingsSchema.js +57 -0
  184. package/dist/common/setupContextHook.d.ts +16 -0
  185. package/dist/common/setupContextHook.js +22 -0
  186. package/dist/common/telemetry.d.ts +3 -0
  187. package/dist/common/telemetry.js +31 -0
  188. package/dist/index.d.ts +4 -0
  189. package/dist/index.js +117 -0
  190. package/dist/runtime/RunError.d.ts +5 -0
  191. package/dist/runtime/RunError.js +19 -0
  192. package/dist/runtime/attemptStore.d.ts +2 -0
  193. package/dist/runtime/attemptStore.js +23 -0
  194. package/dist/runtime/captcha.d.ts +15 -0
  195. package/dist/runtime/captcha.js +191 -0
  196. package/dist/runtime/captcha.test.js +821 -0
  197. package/dist/runtime/downloadDirectory.d.ts +1 -0
  198. package/dist/runtime/downloadDirectory.js +19 -0
  199. package/dist/runtime/enums.d.js +5 -0
  200. package/dist/runtime/enums.d.ts +11 -0
  201. package/dist/runtime/enums.js +18 -0
  202. package/dist/runtime/executionHelpers.test.js +52 -0
  203. package/dist/runtime/export.d.js +5 -0
  204. package/dist/runtime/export.d.ts +284 -0
  205. package/dist/runtime/extendPayload.d.ts +2 -0
  206. package/dist/runtime/extendPayload.js +21 -0
  207. package/dist/runtime/extendTimeout.d.ts +1 -0
  208. package/dist/runtime/extendTimeout.js +23 -0
  209. package/dist/runtime/getAiGatewayConfig.d.ts +10 -0
  210. package/dist/runtime/getAiGatewayConfig.js +16 -0
  211. package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
  212. package/dist/runtime/getAuthSessionParameters.js +20 -0
  213. package/dist/runtime/index.d.ts +10 -0
  214. package/dist/runtime/index.js +111 -0
  215. package/dist/runtime/persistentStore.d.ts +2 -0
  216. package/dist/runtime/persistentStore.js +37 -0
  217. package/dist/runtime/persistentStore.test.js +101 -0
  218. package/dist/runtime/runInfo.d.ts +2 -0
  219. package/dist/runtime/runInfo.js +21 -0
  220. package/dist/vendor/runtime-interface.d.ts +1 -0
  221. package/dist/vendor/runtime-interface.js +479 -0
  222. package/package.json +8 -3
  223. package/tsup.config.ts +12 -0
  224. package/WebTemplate.zip +0 -0
  225. package/api/sample.ts +0 -4
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.scaffoldAuthSessionFiles = scaffoldAuthSessionFiles;
7
+ var _zod = require("zod");
8
+ var _helpers = require("../helpers");
9
+ var _types = require("../types");
10
+ var _tsNodeImport = require("../../common/tsNodeImport");
11
+ var _constants = require("../../../common/constants");
12
+ var _fsExtra = require("fs-extra");
13
+ var _path = _interopRequireDefault(require("path"));
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ const authSessionTemplateResponseSchema = _zod.z.object({
16
+ "auth-sessions": _types.fileSystemTreeSchema
17
+ });
18
+ async function scaffoldAuthSessionFiles() {
19
+ const [createResult, checkResult] = await Promise.all([(0, _tsNodeImport.tsNodeImport)(`${_constants.AUTH_SESSIONS_FOLDER_NAME}/create`), (0, _tsNodeImport.tsNodeImport)(`${_constants.AUTH_SESSIONS_FOLDER_NAME}/check`)]);
20
+ const createExists = createResult.isOk() || createResult.error.type !== "not_found";
21
+ const checkExists = checkResult.isOk() || checkResult.error.type !== "not_found";
22
+ if (createExists && checkExists) {
23
+ (0, _helpers.terminal)("^g^+AuthSession files already exist^:\n");
24
+ return;
25
+ }
26
+ (0, _helpers.terminal)("^g^+Scaffolding...^:\n");
27
+ const authSessionTemplateUrl = new URL("/api/v1/templates/authsession", (0, _helpers.getBaseUrl)());
28
+ authSessionTemplateUrl.searchParams.append("language", "typescript");
29
+ const response = await fetch(authSessionTemplateUrl.toString(), {
30
+ method: "GET"
31
+ });
32
+ const text = await response.text();
33
+ if (!response.ok) {
34
+ throw new Error(`Failed to fetch AuthSession template
35
+ Got ${response.status} ${response.statusText}
36
+ ${text}`);
37
+ }
38
+ let json;
39
+ try {
40
+ json = JSON.parse(text);
41
+ } catch (e) {
42
+ throw new Error(`Failed to parse AuthSession template response as JSON
43
+ ${text}`);
44
+ }
45
+ const parseResult = authSessionTemplateResponseSchema.safeParse(json);
46
+ if (!parseResult.success) {
47
+ throw new Error(`AuthSession template response has invalid shape: ${JSON.stringify(parseResult.error.errors, null, 2)}`);
48
+ }
49
+ const authSessionsContent = parseResult.data["auth-sessions"];
50
+ const cwd = process.cwd();
51
+ const exists = {
52
+ create: createExists,
53
+ check: checkExists
54
+ };
55
+ await (0, _fsExtra.ensureDir)(_path.default.join(cwd, _constants.AUTH_SESSIONS_FOLDER_NAME));
56
+ for (const api in exists) {
57
+ if (exists[api]) {
58
+ continue;
59
+ }
60
+ const [name, node] = Object.entries(authSessionsContent).find(entry => "file" in entry[1] && entry[0].replace(/\.[^/.]+$/, "") === api) ?? [undefined, undefined];
61
+ if (!name || !node) {
62
+ continue;
63
+ }
64
+ const {
65
+ file: {
66
+ contents
67
+ }
68
+ } = node;
69
+ if (typeof contents !== "string") {
70
+ continue;
71
+ }
72
+ await (0, _fsExtra.writeFile)(_path.default.join(cwd, _constants.AUTH_SESSIONS_FOLDER_NAME, name), contents, {
73
+ encoding: "utf-8"
74
+ });
75
+ (0, _helpers.terminal)(`^g^+Written ^_${_path.default.join(_constants.AUTH_SESSIONS_FOLDER_NAME, name)}^:\n`);
76
+ }
77
+ }
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _browser = require("../browser");
5
+ var _launchBrowser = require("../../../../common/launchBrowser");
6
+ var _errors = require("../errors");
7
+ function getTerminal() {
8
+ return new Proxy(() => ({}), {
9
+ get: () => getTerminal(),
10
+ apply: () => ({})
11
+ });
12
+ }
13
+ _vitest.vi.mock("fs-extra", () => ({
14
+ ensureDir: _vitest.vi.fn(),
15
+ exists: _vitest.vi.fn().mockResolvedValue(true)
16
+ }));
17
+ _vitest.vi.mock("portfinder", () => ({
18
+ getPort: _vitest.vi.fn().mockResolvedValue(1234)
19
+ }));
20
+ _vitest.vi.mock("../../../../common/launchBrowser", () => ({
21
+ launchChromium: _vitest.vi.fn().mockImplementation(async () => ({
22
+ context: {
23
+ close: _vitest.vi.fn().mockResolvedValue(undefined)
24
+ },
25
+ page: {}
26
+ }))
27
+ }));
28
+ _vitest.vi.mock("../../helpers/terminal", () => ({
29
+ terminal: getTerminal()
30
+ }));
31
+ _vitest.vi.mock("../../helpers/proxy", () => {
32
+ return {
33
+ parseUrlProxy: _vitest.vi.fn(v => v)
34
+ };
35
+ });
36
+ _vitest.vi.mock("../../helpers", async importOriginal => {
37
+ const original = await importOriginal();
38
+ return {
39
+ ...original,
40
+ terminal: getTerminal()
41
+ };
42
+ });
43
+ _vitest.vi.mock("../../../../common/browserTabs", () => {
44
+ return {
45
+ getCDPTabs: _vitest.vi.fn().mockResolvedValue([{
46
+ id: "tab1",
47
+ title: "Tab 1",
48
+ url: "http://example.com/1"
49
+ }, {
50
+ id: "tab2",
51
+ title: "Tab 2",
52
+ url: "http://example.com/2"
53
+ }])
54
+ };
55
+ });
56
+ (0, _vitest.describe)("Browser CLI options", () => {
57
+ (0, _vitest.it)("returns cdp options with first tab if cdpUrl is set and no cdpTabId is not provided", async () => {
58
+ const options = await (0, _browser.getCLIRunOptions)({
59
+ keepBrowserOpen: true,
60
+ headless: true,
61
+ cdpUrl: "cdp_url"
62
+ });
63
+ (0, _vitest.expect)(options).toEqual(_vitest.expect.objectContaining({
64
+ environment: "cdp",
65
+ cdpAddress: "cdp_url",
66
+ cdpTargetId: "tab1"
67
+ }));
68
+ });
69
+ (0, _vitest.it)("returns cdp options with selected tab if cdpUrl and cdpTabId are provided", async () => {
70
+ const options = await (0, _browser.getCLIRunOptions)({
71
+ keepBrowserOpen: true,
72
+ headless: true,
73
+ cdpUrl: "cdp_url",
74
+ cdpTabId: "tab2"
75
+ });
76
+ (0, _vitest.expect)(options).toEqual(_vitest.expect.objectContaining({
77
+ environment: "cdp",
78
+ cdpAddress: "cdp_url",
79
+ cdpTargetId: "tab2"
80
+ }));
81
+ });
82
+ (0, _vitest.it)("fails in cdp options if cdp url is provided and invalid tab id is provided", async () => {
83
+ const optionsPromise = (0, _browser.getCLIRunOptions)({
84
+ keepBrowserOpen: true,
85
+ headless: true,
86
+ cdpUrl: "cdp_url",
87
+ cdpTabId: "tab3"
88
+ });
89
+ await (0, _vitest.expect)(optionsPromise).rejects.toThrowError(_errors.CLIError);
90
+ });
91
+ (0, _vitest.it)("returns standalone options if keepBrowserOpen is not set", async () => {
92
+ const options = await (0, _browser.getCLIRunOptions)({
93
+ keepBrowserOpen: false,
94
+ headless: false
95
+ });
96
+ (0, _vitest.expect)(options).toEqual(_vitest.expect.objectContaining({
97
+ environment: "standalone",
98
+ headless: false
99
+ }));
100
+ });
101
+ (0, _vitest.describe)("when keepBrowserOpen is set", () => {
102
+ beforeEach(async () => {
103
+ _vitest.vi.clearAllMocks();
104
+ await (0, _browser.closeCliBrowser)();
105
+ });
106
+ (0, _vitest.it)("launches a browser with correct parameters and returns cdp options", async () => {
107
+ const options = await (0, _browser.getCLIRunOptions)({
108
+ keepBrowserOpen: true,
109
+ headless: false,
110
+ proxy: "proxy"
111
+ });
112
+ (0, _vitest.expect)(_launchBrowser.launchChromium).toHaveBeenCalledWith({
113
+ headless: false,
114
+ cdpPort: 1234,
115
+ proxy: "proxy"
116
+ });
117
+ (0, _vitest.expect)(options).toEqual(_vitest.expect.objectContaining({
118
+ environment: "cdp",
119
+ cdpAddress: "http://localhost:1234"
120
+ }));
121
+ });
122
+ (0, _vitest.it)("keeps context open until new context", async () => {
123
+ await (0, _browser.getCLIRunOptions)({
124
+ keepBrowserOpen: true,
125
+ headless: false,
126
+ proxy: "proxy"
127
+ });
128
+ const firstContext = (0, _browser._getContextForTest)();
129
+ (0, _vitest.expect)(firstContext).not.toBeNull();
130
+ (0, _vitest.expect)(_launchBrowser.launchChromium).toHaveBeenCalledTimes(1);
131
+ await (0, _browser.getCLIRunOptions)({
132
+ keepBrowserOpen: true,
133
+ headless: false,
134
+ proxy: "proxy"
135
+ });
136
+ const secondContext = (0, _browser._getContextForTest)();
137
+ (0, _vitest.expect)(secondContext).not.toBeNull();
138
+ (0, _vitest.expect)(firstContext).not.toBe(secondContext);
139
+ (0, _vitest.expect)(_launchBrowser.launchChromium).toHaveBeenCalledTimes(2);
140
+ });
141
+ (0, _vitest.it)("keeps context open until explicitly closed", async () => {
142
+ await (0, _browser.getCLIRunOptions)({
143
+ keepBrowserOpen: true,
144
+ headless: false,
145
+ proxy: "proxy"
146
+ });
147
+ (0, _vitest.expect)((0, _browser._getContextForTest)()).not.toBeNull();
148
+ await (0, _browser.closeCliBrowser)();
149
+ (0, _vitest.expect)((0, _browser._getContextForTest)()).toBeNull();
150
+ });
151
+ });
152
+ });
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _dist = require("../../../../../dist");
5
+ function getTerminal() {
6
+ return new Proxy(() => ({}), {
7
+ get: () => getTerminal(),
8
+ apply: () => ({})
9
+ });
10
+ }
11
+ _vitest.vi.mock("fs-extra", () => ({
12
+ ensureDir: _vitest.vi.fn(),
13
+ exists: _vitest.vi.fn().mockResolvedValue(true)
14
+ }));
15
+ _vitest.vi.mock("../../helpers/terminal", () => ({
16
+ terminal: getTerminal()
17
+ }));
18
+ _vitest.vi.mock("../../helpers", async importOriginal => {
19
+ const original = await importOriginal();
20
+ return {
21
+ ...original,
22
+ terminal: getTerminal()
23
+ };
24
+ });
25
+ (0, _vitest.describe)("Tracing wrapper", () => {
26
+ (0, _vitest.it)("calls wrapped function with disabled tracing when id is undefined", async () => {
27
+ const fn = _vitest.vi.fn();
28
+ await (0, _dist.withCLITrace)(fn, undefined);
29
+ (0, _vitest.expect)(fn).toHaveBeenCalledWith({
30
+ enabled: false
31
+ });
32
+ });
33
+ (0, _vitest.it)("calls wrapped function with enabled tracing when id is defined", async () => {
34
+ const fn = _vitest.vi.fn();
35
+ await (0, _dist.withCLITrace)(fn, "trace-id");
36
+ (0, _vitest.expect)(fn).toHaveBeenCalledWith({
37
+ enabled: true,
38
+ filePath: _vitest.expect.stringContaining("trace-id")
39
+ });
40
+ });
41
+ });
@@ -0,0 +1,3 @@
1
+ import { API_FOLDER_NAME, AUTH_SESSIONS_FOLDER_NAME } from "../../../common/constants";
2
+ export declare function assertApiFileExists(dirname: typeof AUTH_SESSIONS_FOLDER_NAME, api: "create" | "check"): Promise<void>;
3
+ export declare function assertApiFileExists(dirname: typeof API_FOLDER_NAME, api: string): Promise<void>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assertApiFileExists = assertApiFileExists;
7
+ var _errors = require("./errors");
8
+ var _tsNodeImport = require("../../common/tsNodeImport");
9
+ async function assertApiFileExists(dirname, api) {
10
+ const result = await (0, _tsNodeImport.tsNodeImport)(`${dirname}/${api}`);
11
+ if (result.isErr() && result.error.type === "not_found") {
12
+ throw new _errors.CLIAssertionError(`^+^r API^ ^+${dirname}/${api}^ ^r^+does not exist. Make sure to use an existing API name.^:`, {
13
+ autoColor: false
14
+ });
15
+ }
16
+ }
@@ -0,0 +1,46 @@
1
+ import type { AuthSessionMetadata } from "../types";
2
+ import { RunApiStorageState } from "@intuned/runtime-interface";
3
+ export declare function isAuthEnabled(): Promise<boolean>;
4
+ export declare function assertAuthEnabled(): Promise<void>;
5
+ export declare function assertAuthConsistent(authSession: string | undefined): Promise<void>;
6
+ export declare function loadAuthSessionInstance(authSessionId: string): Promise<{
7
+ storageState: {
8
+ cookies: {
9
+ value: string;
10
+ path: string;
11
+ name: string;
12
+ domain: string;
13
+ expires: number;
14
+ httpOnly: boolean;
15
+ secure: boolean;
16
+ sameSite: "Strict" | "Lax" | "None";
17
+ }[];
18
+ origins: {
19
+ origin: string;
20
+ localStorage: {
21
+ value: string;
22
+ name: string;
23
+ }[];
24
+ }[];
25
+ sessionStorage?: {
26
+ origin: string;
27
+ sessionStorage: {
28
+ value: string;
29
+ name: string;
30
+ }[];
31
+ }[] | undefined;
32
+ };
33
+ metadata: AuthSessionMetadata;
34
+ }>;
35
+ export declare function storeAuthSessionInstance({ state, id, input, proxy, metadata, }: {
36
+ state: RunApiStorageState;
37
+ id: string;
38
+ input?: Record<string, any>;
39
+ proxy?: string;
40
+ metadata?: AuthSessionMetadata;
41
+ }): Promise<string>;
42
+ export declare function registerGetAuthSessionParameters(authSessionId?: string): void;
43
+ export declare function getAuthSessionRecorderParameters(): Promise<{
44
+ startUrl: string;
45
+ finishUrl: string;
46
+ }>;
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assertAuthConsistent = assertAuthConsistent;
7
+ exports.assertAuthEnabled = assertAuthEnabled;
8
+ exports.getAuthSessionRecorderParameters = getAuthSessionRecorderParameters;
9
+ exports.isAuthEnabled = isAuthEnabled;
10
+ exports.loadAuthSessionInstance = loadAuthSessionInstance;
11
+ exports.registerGetAuthSessionParameters = registerGetAuthSessionParameters;
12
+ exports.storeAuthSessionInstance = storeAuthSessionInstance;
13
+ var _constants = require("../../../common/constants");
14
+ var _path = _interopRequireDefault(require("path"));
15
+ var _fsExtra = require("fs-extra");
16
+ var _intunedJson = require("./intunedJson");
17
+ var _errors = require("./errors");
18
+ var _runtimeInterface = require("../../../vendor/runtime-interface");
19
+ var _formatZodError = require("../../../common/formatZodError");
20
+ var _asyncLocalStorage = require("../../../common/asyncLocalStorage");
21
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
+ async function isAuthEnabled() {
23
+ const intunedJson = await (0, _intunedJson.loadIntunedJson)();
24
+ return Boolean(intunedJson?.authSessions?.enabled);
25
+ }
26
+ async function assertAuthEnabled() {
27
+ if (!(await isAuthEnabled())) {
28
+ throw new _errors.CLIAssertionError(await getAuthNotEnabledErrorMessage());
29
+ }
30
+ }
31
+ async function assertAuthConsistent(authSession) {
32
+ const _isAuthEnabled = await isAuthEnabled();
33
+ if (_isAuthEnabled && !authSession) {
34
+ throw new _errors.CLIAssertionError("AuthSession is enabled, but no AuthSession is provided. Please provide an AuthSession using '--auth-session <id>' option.");
35
+ }
36
+ if (!_isAuthEnabled && authSession) {
37
+ throw new _errors.CLIAssertionError(await getAuthNotEnabledErrorMessage());
38
+ }
39
+ }
40
+ async function loadAuthSessionInstance(authSessionId) {
41
+ try {
42
+ const authSessionInstancePath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME, authSessionId);
43
+ const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
44
+ const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
45
+ if (!(await (0, _fsExtra.exists)(authSessionInstanceStoragePath))) {
46
+ throw new _errors.CLIError(`AuthSession instance with ID ${authSessionId} not found. Make sure the ID is correct.`);
47
+ }
48
+ const authSessionInstanceJson = await (0, _fsExtra.readJSON)(authSessionInstanceStoragePath);
49
+ const authSessionInstanceParseResult = _runtimeInterface.runApiStorageStateSchema.safeParse(authSessionInstanceJson);
50
+ if (!authSessionInstanceParseResult.success) {
51
+ throw new _errors.CLIError(`AuthSession instance with ID ${authSessionId} is not valid: ${(0, _formatZodError.formatZodError)(authSessionInstanceParseResult.error)}`);
52
+ }
53
+ const metadata = await (0, _fsExtra.readJSON)(authSessionInstanceMetadataPath);
54
+ return {
55
+ storageState: authSessionInstanceParseResult.data,
56
+ metadata
57
+ };
58
+ } catch (error) {
59
+ throw new _errors.CLIError(`Error loading AuthSession instance: ${error.message}`);
60
+ }
61
+ }
62
+ async function storeAuthSessionInstance({
63
+ state,
64
+ id,
65
+ input,
66
+ proxy,
67
+ metadata
68
+ }) {
69
+ try {
70
+ const authSessionsDirectoryPath = _path.default.join(process.cwd(), _constants.AUTH_SESSIONS_INSTANCES_FOLDER_NAME);
71
+ await (0, _fsExtra.ensureDir)(authSessionsDirectoryPath);
72
+ const authSessionInstancePath = _path.default.join(authSessionsDirectoryPath, id);
73
+ await (0, _fsExtra.ensureDir)(authSessionInstancePath);
74
+ const authSessionInstanceStoragePath = _path.default.join(authSessionInstancePath, `auth-session.json`);
75
+ await (0, _fsExtra.writeJSON)(authSessionInstanceStoragePath, state, {
76
+ spaces: 2
77
+ });
78
+ const projectAuthConfig = (await (0, _intunedJson.loadIntunedJson)()).authSessions;
79
+ if (!projectAuthConfig.enabled) {
80
+ throw new _errors.CLIError(`AuthSessions are not enabled in ${await (0, _intunedJson.getIntunedSettingsFileName)()}. Make sure they are enabled.`);
81
+ }
82
+ const authSessionInstanceMetadataPath = _path.default.join(authSessionInstancePath, `metadata.json`);
83
+ const authSessionMetadata = {
84
+ createdAt: metadata?.createdAt ?? new Date().toISOString(),
85
+ updatedAt: new Date().toISOString(),
86
+ ...(projectAuthConfig.type === "API" && {
87
+ authSessionInput: input || metadata?.authSessionInput || {}
88
+ }),
89
+ authSessionId: id,
90
+ authSessionType: projectAuthConfig.type ?? metadata?.authSessionType ?? "API",
91
+ ...(projectAuthConfig.type === "MANUAL" && {
92
+ recorderStartUrl: projectAuthConfig.startUrl,
93
+ recorderEndUrl: projectAuthConfig.finishUrl
94
+ }),
95
+ authSessionInput: input || metadata?.authSessionInput || {},
96
+ authSessionProxy: proxy || metadata?.authSessionProxy
97
+ };
98
+ await (0, _fsExtra.writeJSON)(authSessionInstanceMetadataPath, authSessionMetadata, {
99
+ spaces: 2
100
+ });
101
+ return authSessionInstancePath;
102
+ } catch (error) {
103
+ throw new _errors.CLIError(`Error storing AuthSession instance: ${error.message}`);
104
+ }
105
+ }
106
+ function registerGetAuthSessionParameters(authSessionId) {
107
+ async function getAuthSessionParameters() {
108
+ if (!authSessionId) {
109
+ throw new Error("getAuthSessionParameters cannot be called without using an AuthSession");
110
+ }
111
+ const {
112
+ metadata
113
+ } = await loadAuthSessionInstance(authSessionId);
114
+ if (metadata?.authSessionType === "MANUAL") {
115
+ throw new Error("AuthSession is recorder-based, it does not have parameters.");
116
+ }
117
+ return metadata?.authSessionInput ?? {};
118
+ }
119
+ (0, _asyncLocalStorage.getExecutionContext)().getAuthSessionParameters = getAuthSessionParameters;
120
+ }
121
+ async function getAuthSessionRecorderParameters() {
122
+ const intunedJson = await (0, _intunedJson.loadIntunedJson)();
123
+ if (!intunedJson.authSessions.enabled) {
124
+ throw new _errors.CLIError(`AuthSessions are not enabled in ${await (0, _intunedJson.getIntunedSettingsFileName)()}. Make sure they are enabled.`);
125
+ }
126
+ if (intunedJson.authSessions.type !== "MANUAL") {
127
+ throw new _errors.CLIError(`AuthSession type is not recorder-based in ${await (0, _intunedJson.getIntunedSettingsFileName)()}.
128
+ Make sure the AuthSession type is set to 'MANUAL'
129
+ For more details, check out https://docs.intunedhq.com/docs/05-references/intuned-json#configuration-properties.`);
130
+ }
131
+ const {
132
+ startUrl,
133
+ finishUrl
134
+ } = intunedJson.authSessions;
135
+ if (startUrl === undefined || finishUrl === undefined) {
136
+ throw new _errors.CLIError(`AuthSession type is recorder-based but start_url or finish_url is not set in ${await (0, _intunedJson.getIntunedSettingsFileName)()}.
137
+ Please set both values to use recorder-based AuthSessions.
138
+ For more details, check out https://docs.intunedhq.com/docs/05-references/intuned-json#configuration-properties`);
139
+ }
140
+ return {
141
+ startUrl,
142
+ finishUrl
143
+ };
144
+ }
145
+ async function getAuthNotEnabledErrorMessage() {
146
+ return "AuthSessions are not enabled.\n" + `Enable AuthSessions in ${await (0, _intunedJson.getIntunedSettingsFileName)()} to use this feature.\n` + "See https://docs.intunedhq.com/docs/02-features/auth-sessions#1-enable-authsessions-for-your-project for more information.";
147
+ }
@@ -0,0 +1,8 @@
1
+ export declare function getAuthCredentials(options: {
2
+ workspaceId?: string;
3
+ apiKey?: string;
4
+ }): Promise<{
5
+ workspaceId: string;
6
+ apiKey: string;
7
+ }>;
8
+ export declare function getBaseUrl(): string;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAuthCredentials = getAuthCredentials;
7
+ exports.getBaseUrl = getBaseUrl;
8
+ var _constants = require("../../../common/constants");
9
+ var _errors = require("./errors");
10
+ var _intunedJson = require("./intunedJson");
11
+ var _prompts = require("./prompts");
12
+ async function getAuthCredentials(options) {
13
+ const settings = await (0, _intunedJson.loadIntunedJson)();
14
+ let workspaceId = options.workspaceId || settings.workspaceId || process.env[_constants.WORKSPACE_ID_ENV_VAR_KEY];
15
+ let apiKey = options.apiKey || process.env[_constants.API_KEY_ENV_VAR_KEY];
16
+ if (!workspaceId) {
17
+ workspaceId = await (0, _prompts.promptForWorkspaceId)();
18
+ }
19
+ if (!workspaceId) {
20
+ throw new _errors.CLIError(`Workspace ID is required. Please provide it via command line options or ${await (0, _intunedJson.getIntunedSettingsFileName)()}.\n` + `Expected format: UUID (e.g., 123e4567-e89b-12d3-a456-426614174000)\n` + `Find your workspace ID at: https://app.intuned.io/settings/api-keys`);
21
+ }
22
+ if (!apiKey) {
23
+ apiKey = await (0, _prompts.promptForApiKey)();
24
+ }
25
+ if (!apiKey) {
26
+ throw new _errors.CLIError(`API key is required. Please provide it via command line options or ${_constants.API_KEY_ENV_VAR_KEY} environment variable.\n` + `Get your API key at: https://app.intuned.io/settings/api-keys`);
27
+ }
28
+ return {
29
+ workspaceId,
30
+ apiKey
31
+ };
32
+ }
33
+ function getBaseUrl() {
34
+ return new URL(process.env[_constants.API_BASE_URL_ENV_VAR_KEY] || process.env.INTUNED_API_DOMAIN || `https://app.intuned.io`).origin;
35
+ }
@@ -0,0 +1,14 @@
1
+ import type { BrowserContext } from "playwright";
2
+ import type { RunApiRunOptions } from "@intuned/runtime-interface";
3
+ declare let context: BrowserContext | null;
4
+ export declare function _getContextForTest(): typeof context;
5
+ export declare function getCLIRunOptions({ headless, proxy, keepBrowserOpen, cdpUrl, cdpTabId, }: {
6
+ headless: boolean;
7
+ proxy?: string;
8
+ keepBrowserOpen: boolean;
9
+ cdpUrl?: string;
10
+ cdpTabId?: string;
11
+ }): Promise<RunApiRunOptions>;
12
+ export declare function isCliBrowserLaunched(): boolean;
13
+ export declare function closeCliBrowser(): Promise<void>;
14
+ export {};
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports._getContextForTest = _getContextForTest;
7
+ exports.closeCliBrowser = closeCliBrowser;
8
+ exports.getCLIRunOptions = getCLIRunOptions;
9
+ exports.isCliBrowserLaunched = isCliBrowserLaunched;
10
+ var _launchBrowser = require("../../../common/launchBrowser");
11
+ var _portfinder = require("portfinder");
12
+ var _proxy = require("./proxy");
13
+ var _browserTabs = require("../../../common/browserTabs");
14
+ var _errors = require("./errors");
15
+ let context = null;
16
+ function _getContextForTest() {
17
+ if (process.env.NODE_ENV !== "test") {
18
+ throw new Error("_getContextForTest should only be used in tests");
19
+ }
20
+ return context;
21
+ }
22
+ async function getCLIRunOptions({
23
+ headless,
24
+ proxy,
25
+ keepBrowserOpen,
26
+ cdpUrl,
27
+ cdpTabId
28
+ }) {
29
+ if (context) {
30
+ await closeCliBrowser();
31
+ }
32
+ if (cdpUrl) {
33
+ return {
34
+ environment: "cdp",
35
+ cdpAddress: cdpUrl,
36
+ cdpTargetId: await resolveCdpTargetId({
37
+ cdpAddress: cdpUrl,
38
+ cdpTabId
39
+ })
40
+ };
41
+ }
42
+ if (!keepBrowserOpen) {
43
+ return {
44
+ environment: "standalone",
45
+ headless,
46
+ proxy: proxy ? (0, _proxy.parseUrlProxy)(proxy) : undefined
47
+ };
48
+ }
49
+ const port = await (0, _portfinder.getPort)({});
50
+ ({
51
+ context
52
+ } = await (0, _launchBrowser.launchChromium)({
53
+ headless,
54
+ proxy: proxy ? (0, _proxy.parseUrlProxy)(proxy) : undefined,
55
+ cdpPort: port
56
+ }));
57
+ return {
58
+ environment: "cdp",
59
+ cdpAddress: `http://localhost:${port}`
60
+ };
61
+ }
62
+ function isCliBrowserLaunched() {
63
+ return context !== null;
64
+ }
65
+ async function closeCliBrowser() {
66
+ if (!context) return;
67
+ try {
68
+ await context.close();
69
+ context = null;
70
+ } catch (e) {}
71
+ }
72
+ async function resolveCdpTargetId({
73
+ cdpAddress,
74
+ cdpTabId
75
+ }) {
76
+ let tabs = [];
77
+ try {
78
+ tabs = await (0, _browserTabs.getCDPTabs)(cdpAddress);
79
+ } catch (e) {
80
+ if (cdpTabId) {
81
+ throw new _errors.CLIError(`Failed to fetch tabs from browser: ${e}`);
82
+ }
83
+ }
84
+ if (!cdpTabId) {
85
+ return tabs[0]?.id;
86
+ }
87
+ for (const tab of tabs) {
88
+ if (tab.id.startsWith(cdpTabId)) {
89
+ return tab.id;
90
+ }
91
+ }
92
+ throw new _errors.CLIError(`Tab ${cdpTabId} not found at ${cdpAddress}`);
93
+ }
@@ -0,0 +1,3 @@
1
+ export declare function withCLIContext<R>(fn: () => Promise<R>, options?: {
2
+ authSessionId?: string;
3
+ }): Promise<R>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.withCLIContext = withCLIContext;
7
+ var _nanoid = require("nanoid");
8
+ var _asyncLocalStorage = require("../../../common/asyncLocalStorage");
9
+ var _enums = require("../../../runtime/enums");
10
+ var _auth = require("./auth");
11
+ async function withCLIContext(fn, options) {
12
+ const runId = (0, _nanoid.nanoid)();
13
+ async function getAuthSessionParameters() {
14
+ const id = options?.authSessionId;
15
+ if (!id) {
16
+ throw new Error("getAuthSessionParameters cannot be called without using an AuthSession");
17
+ }
18
+ const {
19
+ metadata
20
+ } = await (0, _auth.loadAuthSessionInstance)(id);
21
+ if (metadata?.authSessionType === "MANUAL") {
22
+ throw new Error("AuthSession is recorder-based, it does not have parameters.");
23
+ }
24
+ return metadata?.authSessionInput ?? {};
25
+ }
26
+ return await (0, _asyncLocalStorage.runWithContext)({
27
+ runEnvironment: _enums.RunEnvironment.IDE,
28
+ runId,
29
+ extendedPayloads: [],
30
+ timeoutInfo: {},
31
+ getAuthSessionParameters
32
+ }, fn);
33
+ }