@intuned/runtime-dev 1.3.18-interface.13 → 1.3.18-interface.4

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 (230) hide show
  1. package/.babelrc +21 -0
  2. package/.eslintignore +10 -0
  3. package/.eslintrc.js +39 -0
  4. package/.turbo/turbo-build.log +2 -0
  5. package/WebTemplate.zip +0 -0
  6. package/dist/commands/api/run.d.ts +1 -3
  7. package/dist/commands/api/run.js +65 -2039
  8. package/dist/commands/auth-sessions/load.d.ts +1 -0
  9. package/dist/commands/auth-sessions/load.js +28 -1552
  10. package/dist/commands/auth-sessions/run-check.d.ts +1 -0
  11. package/dist/commands/auth-sessions/run-check.js +72 -1961
  12. package/dist/commands/auth-sessions/run-create.d.ts +1 -0
  13. package/dist/commands/auth-sessions/run-create.js +66 -1955
  14. package/dist/commands/browser/save-state.d.ts +1 -0
  15. package/dist/commands/browser/save-state.js +11 -102
  16. package/dist/commands/browser/start-browser.d.ts +1 -0
  17. package/dist/commands/browser/start-browser.js +9 -62
  18. package/dist/commands/build.d.ts +1 -2
  19. package/dist/commands/build.js +53 -172
  20. package/dist/commands/common/browserUtils.d.ts +14 -0
  21. package/dist/commands/common/browserUtils.js +58 -0
  22. package/dist/commands/common/getFirstLineNumber.d.ts +9 -0
  23. package/dist/commands/common/getFirstLineNumber.js +101 -0
  24. package/dist/commands/common/getFirstLineNumber.test.js +228 -0
  25. package/dist/commands/common/projectExclusions.d.ts +2 -0
  26. package/dist/commands/common/projectExclusions.js +8 -0
  27. package/dist/commands/common/sendMessageToClient.d.ts +1 -0
  28. package/dist/commands/common/sendMessageToClient.js +10 -0
  29. package/dist/commands/common/tsNodeImport.d.ts +2 -5
  30. package/dist/commands/common/tsNodeImport.js +16 -55
  31. package/dist/commands/common/utils/fileUtils.d.ts +6 -0
  32. package/dist/commands/common/utils/fileUtils.js +33 -0
  33. package/dist/commands/common/utils/interfaceClient.d.ts +31 -0
  34. package/dist/commands/common/utils/interfaceClient.js +99 -0
  35. package/dist/commands/common/utils/settings.d.ts +2 -0
  36. package/dist/commands/common/utils/settings.js +31 -0
  37. package/dist/commands/common/utils/template.d.ts +2 -0
  38. package/dist/commands/common/utils/template.js +31 -0
  39. package/dist/commands/get-headless-user-agent.d.ts +1 -2
  40. package/dist/commands/get-headless-user-agent.js +12 -348
  41. package/dist/commands/interface/pingPong.d.ts +2 -0
  42. package/dist/commands/interface/pingPong.js +11 -0
  43. package/dist/commands/interface/run.d.ts +1 -3
  44. package/dist/commands/interface/run.js +140 -2034
  45. package/dist/commands/interface/runApi.d.ts +1 -0
  46. package/dist/commands/interface/runApi.js +102 -0
  47. package/dist/commands/intuned-cli/commands/attempt.command.d.ts +1 -0
  48. package/dist/commands/intuned-cli/commands/attempt.command.js +8 -0
  49. package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +1 -0
  50. package/dist/commands/intuned-cli/commands/attempt_api.command.js +30 -0
  51. package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +1 -0
  52. package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +8 -0
  53. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +1 -0
  54. package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +19 -0
  55. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +1 -0
  56. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +24 -0
  57. package/dist/commands/intuned-cli/commands/authsession.command.d.ts +1 -0
  58. package/dist/commands/intuned-cli/commands/authsession.command.js +8 -0
  59. package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +1 -0
  60. package/dist/commands/intuned-cli/commands/authsession_record.command.js +32 -0
  61. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.d.ts +1 -0
  62. package/dist/commands/intuned-cli/commands/authsession_scaffold.command.js +16 -0
  63. package/dist/commands/intuned-cli/commands/build.command.d.ts +1 -0
  64. package/dist/commands/intuned-cli/commands/build.command.js +12 -0
  65. package/dist/commands/intuned-cli/commands/command.d.ts +2 -0
  66. package/dist/commands/intuned-cli/commands/command.js +9 -0
  67. package/dist/commands/intuned-cli/commands/deploy.command.d.ts +1 -0
  68. package/dist/commands/intuned-cli/commands/deploy.command.js +42 -0
  69. package/dist/commands/intuned-cli/commands/index.d.ts +18 -0
  70. package/dist/commands/intuned-cli/commands/index.js +203 -0
  71. package/dist/commands/intuned-cli/commands/provision.command.d.ts +13 -0
  72. package/dist/commands/intuned-cli/commands/provision.command.js +50 -0
  73. package/dist/commands/intuned-cli/commands/run.command.d.ts +1 -0
  74. package/dist/commands/intuned-cli/commands/run.command.js +8 -0
  75. package/dist/commands/intuned-cli/commands/run_api.command.d.ts +1 -0
  76. package/dist/commands/intuned-cli/commands/run_api.command.js +46 -0
  77. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +34 -0
  78. package/dist/commands/intuned-cli/commands/run_authsession.command.js +17 -0
  79. package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +1 -0
  80. package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +35 -0
  81. package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +1 -0
  82. package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +35 -0
  83. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +1 -0
  84. package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +33 -0
  85. package/dist/commands/intuned-cli/commands/types.d.ts +39 -0
  86. package/dist/commands/intuned-cli/commands/types.js +33 -0
  87. package/dist/commands/intuned-cli/constants/index.d.ts +17 -0
  88. package/dist/commands/intuned-cli/constants/index.js +25 -0
  89. package/dist/commands/intuned-cli/controller/__test__/api.test.js +398 -0
  90. package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +1060 -0
  91. package/dist/commands/intuned-cli/controller/api.d.ts +42 -0
  92. package/dist/commands/intuned-cli/controller/api.js +195 -0
  93. package/dist/commands/intuned-cli/controller/authSession.d.ts +209 -0
  94. package/dist/commands/intuned-cli/controller/authSession.js +425 -0
  95. package/dist/commands/intuned-cli/controller/build.d.ts +1 -0
  96. package/dist/commands/intuned-cli/controller/build.js +36 -0
  97. package/dist/commands/intuned-cli/controller/deploy.d.ts +5 -0
  98. package/dist/commands/intuned-cli/controller/deploy.js +318 -0
  99. package/dist/commands/intuned-cli/controller/index.d.ts +1 -0
  100. package/dist/commands/intuned-cli/controller/index.js +46 -0
  101. package/dist/commands/intuned-cli/controller/provision.d.ts +21 -0
  102. package/dist/commands/intuned-cli/controller/provision.js +300 -0
  103. package/dist/commands/intuned-cli/controller/scaffold.d.ts +1 -0
  104. package/dist/commands/intuned-cli/controller/scaffold.js +77 -0
  105. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +152 -0
  106. package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +41 -0
  107. package/dist/commands/intuned-cli/helpers/api.d.ts +3 -0
  108. package/dist/commands/intuned-cli/helpers/api.js +16 -0
  109. package/dist/commands/intuned-cli/helpers/auth.d.ts +46 -0
  110. package/dist/commands/intuned-cli/helpers/auth.js +147 -0
  111. package/dist/commands/intuned-cli/helpers/backend.d.ts +8 -0
  112. package/dist/commands/intuned-cli/helpers/backend.js +35 -0
  113. package/dist/commands/intuned-cli/helpers/browser.d.ts +14 -0
  114. package/dist/commands/intuned-cli/helpers/browser.js +93 -0
  115. package/dist/commands/intuned-cli/helpers/context.d.ts +3 -0
  116. package/dist/commands/intuned-cli/helpers/context.js +33 -0
  117. package/dist/commands/intuned-cli/helpers/errors.d.ts +16 -0
  118. package/dist/commands/intuned-cli/helpers/errors.js +44 -0
  119. package/dist/commands/intuned-cli/helpers/index.d.ts +12 -0
  120. package/dist/commands/intuned-cli/helpers/index.js +137 -0
  121. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +39 -0
  122. package/dist/commands/intuned-cli/helpers/intunedJson.js +20 -0
  123. package/dist/commands/intuned-cli/helpers/prompts.d.ts +3 -0
  124. package/dist/commands/intuned-cli/helpers/prompts.js +71 -0
  125. package/dist/commands/intuned-cli/helpers/proxy.d.ts +5 -0
  126. package/dist/commands/intuned-cli/helpers/proxy.js +23 -0
  127. package/dist/commands/intuned-cli/helpers/terminal.d.ts +5 -0
  128. package/dist/commands/intuned-cli/helpers/terminal.js +13 -0
  129. package/dist/commands/intuned-cli/helpers/timeout.d.ts +1 -0
  130. package/dist/commands/intuned-cli/helpers/timeout.js +23 -0
  131. package/dist/commands/intuned-cli/helpers/traces.d.ts +2 -0
  132. package/dist/commands/intuned-cli/helpers/traces.js +32 -0
  133. package/dist/commands/intuned-cli/helpers/validation.d.ts +2 -0
  134. package/dist/commands/intuned-cli/helpers/validation.js +14 -0
  135. package/dist/commands/intuned-cli/helpers/wrapper.d.ts +2 -0
  136. package/dist/commands/intuned-cli/helpers/wrapper.js +76 -0
  137. package/dist/commands/intuned-cli/index.d.ts +1 -0
  138. package/dist/commands/intuned-cli/index.js +16 -0
  139. package/dist/commands/intuned-cli/main.d.ts +1 -2
  140. package/dist/commands/intuned-cli/main.js +25 -5392
  141. package/dist/commands/intuned-cli/types.d.ts +70 -0
  142. package/dist/commands/intuned-cli/types.js +22 -0
  143. package/dist/commands/ts-check.d.ts +1 -0
  144. package/dist/commands/ts-check.js +29 -131
  145. package/dist/common/Logger/Logger/index.d.ts +12 -0
  146. package/dist/common/Logger/Logger/index.js +60 -0
  147. package/dist/common/Logger/Logger/types.d.ts +8 -0
  148. package/dist/common/Logger/Logger/types.js +5 -0
  149. package/dist/common/Logger/index.d.ts +12 -0
  150. package/dist/common/Logger/index.js +60 -0
  151. package/dist/common/Logger/types.d.ts +8 -0
  152. package/dist/common/Logger/types.js +5 -0
  153. package/dist/common/asyncLocalStorage/index.d.ts +8 -9
  154. package/dist/common/asyncLocalStorage/index.js +9 -33
  155. package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +1 -0
  156. package/dist/common/backendFunctions/getAuthSessionParameters.js +38 -0
  157. package/dist/common/binStartupScript.d.ts +1 -2
  158. package/dist/common/binStartupScript.js +11 -126
  159. package/dist/common/browserTabs.d.ts +72 -0
  160. package/dist/common/browserTabs.js +74 -0
  161. package/dist/common/cleanEnvironmentVariables.d.ts +1 -3
  162. package/dist/common/cleanEnvironmentVariables.js +7 -29
  163. package/dist/common/constants.d.ts +11 -13
  164. package/dist/common/constants.js +15 -57
  165. package/dist/common/contextStorageStateHelpers.d.ts +6 -8
  166. package/dist/common/contextStorageStateHelpers.js +22 -46
  167. package/dist/common/extension/extensionsHelpers.d.ts +11 -0
  168. package/dist/common/extension/extensionsHelpers.js +147 -0
  169. package/dist/common/extension/intunedExtensionServer.d.ts +24 -0
  170. package/dist/common/extension/intunedExtensionServer.js +178 -0
  171. package/dist/common/extension/types.d.ts +212 -0
  172. package/dist/common/extension/types.js +51 -0
  173. package/dist/common/formatZodError.d.ts +2 -0
  174. package/dist/common/formatZodError.js +18 -0
  175. package/dist/common/intunedJson.d.ts +229 -0
  176. package/dist/common/intunedJson.js +133 -0
  177. package/dist/common/jwtTokenManager.d.ts +4 -6
  178. package/dist/common/jwtTokenManager.js +41 -107
  179. package/dist/common/launchBrowser.d.ts +34 -0
  180. package/dist/common/launchBrowser.js +248 -0
  181. package/dist/common/playwrightContext.d.ts +30 -0
  182. package/dist/common/playwrightContext.js +153 -0
  183. package/dist/common/runApi/importUsingImportFunction.d.ts +7 -0
  184. package/dist/common/runApi/importUsingImportFunction.js +46 -0
  185. package/dist/common/runApi/index.d.ts +6 -9
  186. package/dist/common/runApi/index.js +78 -1765
  187. package/dist/common/settingsSchema.d.ts +51 -58
  188. package/dist/common/settingsSchema.js +20 -54
  189. package/dist/common/setupContextHook.d.ts +16 -0
  190. package/dist/common/setupContextHook.js +22 -0
  191. package/dist/common/telemetry.d.ts +3 -6
  192. package/dist/common/telemetry.js +9 -40
  193. package/dist/index.d.ts +4 -6
  194. package/dist/index.js +92 -783
  195. package/dist/runtime/RunError.d.ts +5 -0
  196. package/dist/runtime/RunError.js +19 -0
  197. package/dist/runtime/attemptStore.d.ts +2 -0
  198. package/dist/runtime/attemptStore.js +23 -0
  199. package/dist/runtime/captcha.d.ts +15 -0
  200. package/dist/runtime/captcha.js +191 -0
  201. package/dist/runtime/captcha.test.js +821 -0
  202. package/dist/runtime/downloadDirectory.d.ts +1 -0
  203. package/dist/runtime/downloadDirectory.js +19 -0
  204. package/dist/runtime/enums.d.js +5 -0
  205. package/dist/runtime/enums.d.ts +11 -0
  206. package/dist/runtime/enums.js +18 -0
  207. package/dist/runtime/executionHelpers.test.js +52 -0
  208. package/dist/runtime/export.d.js +5 -0
  209. package/dist/runtime/export.d.ts +284 -0
  210. package/dist/runtime/extendPayload.d.ts +2 -0
  211. package/dist/runtime/extendPayload.js +21 -0
  212. package/dist/runtime/extendTimeout.d.ts +1 -0
  213. package/dist/runtime/extendTimeout.js +23 -0
  214. package/dist/runtime/getAiGatewayConfig.d.ts +10 -0
  215. package/dist/runtime/getAiGatewayConfig.js +16 -0
  216. package/dist/runtime/getAuthSessionParameters.d.ts +1 -0
  217. package/dist/runtime/getAuthSessionParameters.js +20 -0
  218. package/dist/runtime/index.d.ts +10 -168
  219. package/dist/runtime/index.js +88 -778
  220. package/dist/runtime/persistentStore.d.ts +2 -0
  221. package/dist/runtime/persistentStore.js +37 -0
  222. package/dist/runtime/persistentStore.test.js +101 -0
  223. package/dist/runtime/runInfo.d.ts +2 -0
  224. package/dist/runtime/runInfo.js +21 -0
  225. package/package.json +16 -77
  226. package/template.tsconfig.json +11 -0
  227. package/tsconfig.eslint.json +5 -0
  228. package/tsconfig.json +25 -0
  229. package/typedoc.json +49 -0
  230. package/dist/export.d-BAUMB-lG.d.ts +0 -140
@@ -0,0 +1,1060 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _authSession = require("../authSession");
5
+ var _helpers = require("../../helpers");
6
+ var _neverthrow = require("neverthrow");
7
+ var _runApi = require("../../../../common/runApi");
8
+ var _browser = require("../../helpers/browser");
9
+ var _launchBrowser = require("../../../../common/launchBrowser");
10
+ var _promises = require("timers/promises");
11
+ const _checkPassedResult = (0, _neverthrow.ok)({
12
+ result: true
13
+ });
14
+ const _checkFailedResult = (0, _neverthrow.ok)({
15
+ result: false
16
+ });
17
+ const _errorResult = (0, _neverthrow.err)(new _runApi.AutomationError("failed"));
18
+ function _createSuccessResult(session) {
19
+ return (0, _neverthrow.ok)({
20
+ session
21
+ });
22
+ }
23
+ function getTerminal() {
24
+ return new Proxy(() => ({}), {
25
+ get: () => getTerminal(),
26
+ apply: () => ({})
27
+ });
28
+ }
29
+ function getMockTimeout() {
30
+ let resolveTimeout = () => undefined;
31
+ _vitest.vi.mocked(_promises.setTimeout).mockImplementation(() => new Promise(r => {
32
+ resolveTimeout = r;
33
+ }));
34
+ return {
35
+ async resolve() {
36
+ await Promise.resolve();
37
+ resolveTimeout();
38
+ }
39
+ };
40
+ }
41
+ _vitest.vi.mock("fs-extra", () => ({
42
+ ensureDir: _vitest.vi.fn(),
43
+ writeJSON: _vitest.vi.fn(),
44
+ exists: _vitest.vi.fn().mockResolvedValue(true)
45
+ }));
46
+ _vitest.vi.mock("timers/promises", () => ({
47
+ setTimeout: _vitest.vi.fn().mockResolvedValue(undefined)
48
+ }));
49
+ _vitest.vi.mock("../../../../common/contextStorageStateHelpers", () => ({
50
+ getStorageState: _vitest.vi.fn()
51
+ }));
52
+ _vitest.vi.mock("../../../../common/launchBrowser", () => ({
53
+ launchChromium: _vitest.vi.fn()
54
+ }));
55
+ _vitest.vi.mock("../../../../common/runApi", async importOriginal => {
56
+ const original = await importOriginal();
57
+ return {
58
+ ...original,
59
+ runApi: _vitest.vi.fn().mockImplementation(() => (0, _neverthrow.ok)({}))
60
+ };
61
+ });
62
+ _vitest.vi.mock("../../helpers/terminal", () => ({
63
+ terminal: getTerminal()
64
+ }));
65
+ _vitest.vi.mock("../../helpers/proxy", () => {
66
+ return {
67
+ parseUrlProxy: _vitest.vi.fn(v => v)
68
+ };
69
+ });
70
+ _vitest.vi.mock("../../helpers/browser", async importOriginal => {
71
+ const original = await importOriginal();
72
+ return {
73
+ getCLIRunOptions: _vitest.vi.fn(({
74
+ keepBrowserOpen: _,
75
+ ...rest
76
+ }) => original.getCLIRunOptions({
77
+ keepBrowserOpen: false,
78
+ ...rest
79
+ }))
80
+ };
81
+ });
82
+ _vitest.vi.mock("../../helpers", async importOriginal => {
83
+ const original = await importOriginal();
84
+ return {
85
+ ...original,
86
+ terminal: getTerminal(),
87
+ assertApiFileExists: _vitest.vi.fn(),
88
+ withTimeout: _vitest.vi.fn(fn => fn()),
89
+ keepBrowserOpen: false,
90
+ withCLITrace: _vitest.vi.fn(original.withCLITrace),
91
+ loadAuthSessionInstance: _vitest.vi.fn(),
92
+ storeAuthSessionInstance: _vitest.vi.fn().mockResolvedValue("authSessionInstancePath"),
93
+ registerGetAuthSessionParameters: _vitest.vi.fn()
94
+ };
95
+ });
96
+ (0, _vitest.describe)("AuthSession controller", () => {
97
+ (0, _vitest.beforeEach)(() => {
98
+ _vitest.vi.clearAllMocks();
99
+ });
100
+ (0, _vitest.describe)("runCheck", () => {
101
+ (0, _vitest.it)("calls timeout middleware with timeout", async () => {
102
+ await (0, _authSession._runCheck)({
103
+ auth: "session",
104
+ headless: false,
105
+ timeout: 6000,
106
+ keepBrowserOpen: false
107
+ });
108
+ (0, _vitest.expect)(_helpers.withTimeout).toHaveBeenCalledWith(_vitest.expect.any(Function), 6000);
109
+ });
110
+ (0, _vitest.it)("uses tracing wrapper and calls with correct parameters", async () => {
111
+ await (0, _authSession._runCheck)({
112
+ auth: "session",
113
+ headless: false,
114
+ timeout: 6000,
115
+ keepBrowserOpen: false
116
+ });
117
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), undefined);
118
+ _vitest.vi.mocked(_helpers.withCLITrace).mockClear();
119
+ _vitest.vi.mocked(_runApi.runApi).mockClear();
120
+ await (0, _authSession._runCheck)({
121
+ auth: "session",
122
+ headless: false,
123
+ timeout: 6000,
124
+ keepBrowserOpen: false,
125
+ traceId: "trace-id"
126
+ });
127
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), "trace-id");
128
+ });
129
+ (0, _vitest.it)("uses cli browser helper", async () => {
130
+ await (0, _authSession._runCheck)({
131
+ auth: "session",
132
+ headless: false,
133
+ timeout: 6000,
134
+ keepBrowserOpen: false
135
+ });
136
+ (0, _vitest.expect)(_browser.getCLIRunOptions).toHaveBeenCalledWith(_vitest.expect.objectContaining({
137
+ headless: false,
138
+ keepBrowserOpen: false
139
+ }));
140
+ _vitest.vi.mocked(_helpers.withCLITrace).mockClear();
141
+ _vitest.vi.mocked(_runApi.runApi).mockClear();
142
+ await (0, _authSession._runCheck)({
143
+ auth: "session",
144
+ headless: true,
145
+ timeout: 6000,
146
+ keepBrowserOpen: true
147
+ });
148
+ (0, _vitest.expect)(_browser.getCLIRunOptions).toHaveBeenCalledWith(_vitest.expect.objectContaining({
149
+ headless: true,
150
+ keepBrowserOpen: true
151
+ }));
152
+ });
153
+ (0, _vitest.it)("calls runApi with correct parameters and parses proxy", async () => {
154
+ _vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
155
+ await (0, _authSession._runCheck)({
156
+ auth: "session",
157
+ headless: "headless",
158
+ timeout: 999999999,
159
+ keepBrowserOpen: false,
160
+ proxy: "proxy"
161
+ });
162
+ (0, _vitest.expect)(_helpers.parseUrlProxy).toHaveBeenCalledWith("proxy");
163
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
164
+ automationFunction: {
165
+ name: "auth-sessions/check"
166
+ },
167
+ runOptions: {
168
+ headless: "headless",
169
+ environment: "standalone",
170
+ proxy: "parsed-proxy"
171
+ },
172
+ auth: _vitest.expect.objectContaining({
173
+ session: {
174
+ type: "state",
175
+ state: "session"
176
+ }
177
+ })
178
+ }));
179
+ });
180
+ (0, _vitest.it)("returns if check returns", async () => {
181
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkPassedResult);
182
+ const resultTrue = await (0, _authSession._runCheck)({
183
+ auth: "session",
184
+ headless: "headless",
185
+ timeout: 999999999,
186
+ keepBrowserOpen: false
187
+ });
188
+ (0, _vitest.expect)(resultTrue).toEqual(true);
189
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkFailedResult);
190
+ const resultFalse = await (0, _authSession._runCheck)({
191
+ auth: "session",
192
+ headless: "headless",
193
+ timeout: 999999999,
194
+ keepBrowserOpen: false
195
+ });
196
+ (0, _vitest.expect)(resultFalse).toEqual(false);
197
+ });
198
+ (0, _vitest.it)("throws the error check fails with an error", async () => {
199
+ const error = new Error("runApi failed");
200
+ _vitest.vi.mocked(_runApi.runApi).mockRejectedValueOnce(error);
201
+ await (0, _vitest.expect)((0, _authSession._runCheck)({
202
+ auth: "session",
203
+ headless: "headless",
204
+ timeout: 999999999,
205
+ keepBrowserOpen: false
206
+ })).rejects.toThrow(error);
207
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_errorResult);
208
+ await (0, _vitest.expect)((0, _authSession._runCheck)({
209
+ auth: "session",
210
+ headless: "headless",
211
+ timeout: 999999999,
212
+ keepBrowserOpen: false
213
+ })).rejects.toThrow("failed");
214
+ });
215
+ });
216
+ (0, _vitest.describe)("runCheckWithRetries", () => {
217
+ (0, _vitest.it)("enables tracing on runCheck if trace is true", async () => {
218
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkPassedResult);
219
+ await (0, _authSession._runCheckWithRetries)({
220
+ auth: "session",
221
+ retries: 1,
222
+ headless: "headless",
223
+ timeout: 999999999,
224
+ keepBrowserOpen: false,
225
+ trace: false
226
+ });
227
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), undefined);
228
+ _vitest.vi.mocked(_helpers.withCLITrace).mockClear();
229
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkPassedResult);
230
+ await (0, _authSession._runCheckWithRetries)({
231
+ auth: "session",
232
+ retries: 1,
233
+ headless: "headless",
234
+ timeout: 999999999,
235
+ keepBrowserOpen: false,
236
+ trace: true
237
+ });
238
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), _vitest.expect.any(String));
239
+ });
240
+ (0, _vitest.it)("retries the check if it fails", async () => {
241
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkFailedResult).mockResolvedValueOnce(_checkPassedResult);
242
+ const result = await (0, _authSession._runCheckWithRetries)({
243
+ auth: "session",
244
+ retries: 10,
245
+ headless: "headless",
246
+ timeout: 999999999,
247
+ keepBrowserOpen: false,
248
+ trace: false
249
+ });
250
+ (0, _vitest.expect)(result).toEqual(true);
251
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(2);
252
+ });
253
+ (0, _vitest.it)("returns false if all retries fail", async () => {
254
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
255
+ result: false
256
+ }));
257
+ const result = await (0, _authSession._runCheckWithRetries)({
258
+ auth: "session",
259
+ retries: 10,
260
+ headless: "headless",
261
+ timeout: 999999999,
262
+ keepBrowserOpen: false,
263
+ trace: false
264
+ });
265
+ (0, _vitest.expect)(result).toEqual(false);
266
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(10);
267
+ });
268
+ (0, _vitest.it)("continues retrying if check fails due to an automation error", async () => {
269
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_errorResult).mockResolvedValueOnce(_checkPassedResult);
270
+ const result = await (0, _authSession._runCheckWithRetries)({
271
+ auth: "session",
272
+ retries: 10,
273
+ headless: "headless",
274
+ timeout: 999999999,
275
+ keepBrowserOpen: false,
276
+ trace: false
277
+ });
278
+ (0, _vitest.expect)(result).toEqual(true);
279
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(2);
280
+ });
281
+ (0, _vitest.it)("throws the error if check fails with a non-automation error", async () => {
282
+ const error = new Error("runCheck failed");
283
+ _vitest.vi.mocked(_runApi.runApi).mockRejectedValueOnce(error);
284
+ await (0, _vitest.expect)((0, _authSession._runCheckWithRetries)({
285
+ auth: "session",
286
+ retries: 10,
287
+ headless: "headless",
288
+ timeout: 999999999,
289
+ keepBrowserOpen: false,
290
+ trace: false
291
+ })).rejects.toThrow(error);
292
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
293
+ });
294
+ });
295
+ (0, _vitest.describe)("runCreate", () => {
296
+ (0, _vitest.it)("calls timeout middleware with timeout", async () => {
297
+ await (0, _authSession._runCreate)({
298
+ authSessionInput: {},
299
+ headless: false,
300
+ timeout: 6000,
301
+ keepBrowserOpen: false
302
+ });
303
+ (0, _vitest.expect)(_helpers.withTimeout).toHaveBeenCalledWith(_vitest.expect.any(Function), 6000);
304
+ });
305
+ (0, _vitest.it)("uses tracing wrapper and calls with correct parameters", async () => {
306
+ await (0, _authSession._runCreate)({
307
+ authSessionInput: {},
308
+ headless: false,
309
+ timeout: 6000,
310
+ keepBrowserOpen: false
311
+ });
312
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), undefined);
313
+ _vitest.vi.mocked(_helpers.withCLITrace).mockClear();
314
+ _vitest.vi.mocked(_runApi.runApi).mockClear();
315
+ await (0, _authSession._runCreate)({
316
+ authSessionInput: {},
317
+ headless: false,
318
+ timeout: 6000,
319
+ keepBrowserOpen: false,
320
+ traceId: "trace-id"
321
+ });
322
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), "trace-id");
323
+ });
324
+ (0, _vitest.it)("uses cli browser helper", async () => {
325
+ await (0, _authSession._runCreate)({
326
+ authSessionInput: {},
327
+ headless: false,
328
+ timeout: 6000,
329
+ keepBrowserOpen: false
330
+ });
331
+ (0, _vitest.expect)(_browser.getCLIRunOptions).toHaveBeenCalledWith(_vitest.expect.objectContaining({
332
+ headless: false,
333
+ keepBrowserOpen: false
334
+ }));
335
+ _vitest.vi.mocked(_helpers.withCLITrace).mockClear();
336
+ _vitest.vi.mocked(_runApi.runApi).mockClear();
337
+ await (0, _authSession._runCreate)({
338
+ authSessionInput: {},
339
+ headless: true,
340
+ timeout: 6000,
341
+ keepBrowserOpen: true
342
+ });
343
+ (0, _vitest.expect)(_browser.getCLIRunOptions).toHaveBeenCalledWith(_vitest.expect.objectContaining({
344
+ headless: true,
345
+ keepBrowserOpen: true
346
+ }));
347
+ });
348
+ (0, _vitest.it)("calls runApi with correct parameters and parses proxy", async () => {
349
+ _vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
350
+ await (0, _authSession._runCreate)({
351
+ authSessionInput: "authSessionInput",
352
+ headless: "headless",
353
+ timeout: 999999999,
354
+ keepBrowserOpen: false,
355
+ proxy: "proxy"
356
+ });
357
+ (0, _vitest.expect)(_helpers.parseUrlProxy).toHaveBeenCalledWith("proxy");
358
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
359
+ automationFunction: {
360
+ name: "auth-sessions/create",
361
+ params: "authSessionInput"
362
+ },
363
+ runOptions: {
364
+ headless: "headless",
365
+ environment: "standalone",
366
+ proxy: "parsed-proxy"
367
+ },
368
+ retrieveSession: true
369
+ }));
370
+ });
371
+ (0, _vitest.it)("returns if create returns", async () => {
372
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session"));
373
+ const storageState = await (0, _authSession._runCreate)({
374
+ authSessionInput: {},
375
+ headless: "headless",
376
+ timeout: 999999999,
377
+ keepBrowserOpen: false
378
+ });
379
+ (0, _vitest.expect)(storageState).toEqual("session");
380
+ });
381
+ (0, _vitest.it)("throws the error create fails with an error", async () => {
382
+ const error = new Error("runApi failed");
383
+ _vitest.vi.mocked(_runApi.runApi).mockRejectedValueOnce(error);
384
+ await (0, _vitest.expect)((0, _authSession._runCreate)({
385
+ authSessionInput: {},
386
+ headless: "headless",
387
+ timeout: 999999999,
388
+ keepBrowserOpen: false
389
+ })).rejects.toThrow(error);
390
+ });
391
+ });
392
+ (0, _vitest.describe)("runCreateWithRetries", () => {
393
+ (0, _vitest.it)("enables tracing on runCreate if trace is true", async () => {
394
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session"));
395
+ _vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
396
+ await (0, _authSession._runCreateWithRetries)({
397
+ authSessionId: "authSessionId",
398
+ authSessionInput: "authSessionInput",
399
+ retries: 10,
400
+ headless: "headless",
401
+ proxy: "proxy",
402
+ timeout: 999999999,
403
+ keepBrowserOpen: false,
404
+ trace: false
405
+ });
406
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), undefined);
407
+ _vitest.vi.mocked(_helpers.withCLITrace).mockClear();
408
+ _vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
409
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session"));
410
+ await (0, _authSession._runCreateWithRetries)({
411
+ authSessionId: "authSessionId",
412
+ authSessionInput: "authSessionInput",
413
+ retries: 10,
414
+ headless: "headless",
415
+ proxy: "proxy",
416
+ timeout: 999999999,
417
+ keepBrowserOpen: false,
418
+ trace: true
419
+ });
420
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), _vitest.expect.any(String));
421
+ });
422
+ (0, _vitest.it)("saves the AuthSession instance", async () => {
423
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session"));
424
+ _vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
425
+ await (0, _authSession._runCreateWithRetries)({
426
+ authSessionId: "authSessionId",
427
+ authSessionInput: "authSessionInput",
428
+ retries: 10,
429
+ headless: "headless",
430
+ proxy: "proxy",
431
+ timeout: 999999999,
432
+ keepBrowserOpen: false,
433
+ trace: false
434
+ });
435
+ (0, _vitest.expect)(_helpers.storeAuthSessionInstance).toHaveBeenCalledWith({
436
+ state: "session",
437
+ id: "authSessionId",
438
+ input: "authSessionInput",
439
+ proxy: "proxy"
440
+ });
441
+ });
442
+ (0, _vitest.it)("retries the create if it fails with automation error", async () => {
443
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_errorResult).mockResolvedValueOnce(_createSuccessResult("session"));
444
+ await (0, _authSession._runCreateWithRetries)({
445
+ authSessionId: "authSessionId",
446
+ authSessionInput: "authSessionInput",
447
+ retries: 10,
448
+ headless: "headless",
449
+ timeout: 999999999,
450
+ keepBrowserOpen: false,
451
+ trace: false
452
+ });
453
+ });
454
+ (0, _vitest.it)("throws if all retries fail", async () => {
455
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValue(_errorResult);
456
+ await (0, _vitest.expect)((0, _authSession._runCreateWithRetries)({
457
+ authSessionId: "authSessionId",
458
+ authSessionInput: {},
459
+ retries: 10,
460
+ headless: "headless",
461
+ timeout: 999999999,
462
+ keepBrowserOpen: false,
463
+ trace: false
464
+ })).rejects.toThrow(_helpers.CLIError);
465
+ });
466
+ (0, _vitest.it)("continues retrying if create fails due to an automation error", async () => {
467
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_errorResult).mockResolvedValueOnce(_createSuccessResult("session"));
468
+ const result = await (0, _authSession._runCreateWithRetries)({
469
+ authSessionId: "authSessionId",
470
+ authSessionInput: {},
471
+ retries: 10,
472
+ headless: "headless",
473
+ timeout: 999999999,
474
+ keepBrowserOpen: false,
475
+ trace: false
476
+ });
477
+ (0, _vitest.expect)(result).toEqual("session");
478
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(2);
479
+ });
480
+ (0, _vitest.it)("throws the error if create fails with a non-automation error", async () => {
481
+ const error = new Error("runCheck failed");
482
+ _vitest.vi.mocked(_runApi.runApi).mockRejectedValueOnce(error);
483
+ await (0, _vitest.expect)((0, _authSession._runCreateWithRetries)({
484
+ authSessionId: "authSessionId",
485
+ authSessionInput: {},
486
+ retries: 10,
487
+ headless: "headless",
488
+ timeout: 999999999,
489
+ keepBrowserOpen: false,
490
+ trace: false
491
+ })).rejects.toThrow(error);
492
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
493
+ });
494
+ });
495
+ (0, _vitest.describe)("executeRunValidateAuthSessionCLI", () => {
496
+ (0, _vitest.beforeEach)(() => {
497
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
498
+ storageState: {},
499
+ metadata: {
500
+ authSessionId: "authSessionId",
501
+ authSessionType: "API",
502
+ authSessionInput: {},
503
+ createdAt: "",
504
+ updatedAt: ""
505
+ }
506
+ });
507
+ });
508
+ (0, _vitest.it)("asserts check API file exists", async () => {
509
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkPassedResult);
510
+ await (0, _authSession.executeRunValidateAuthSessionCLI)({
511
+ id: "authSessionId",
512
+ checkRetries: 1,
513
+ createRetries: 1,
514
+ autoRecreate: false,
515
+ headless: false,
516
+ timeout: 999999999,
517
+ keepBrowserOpen: false,
518
+ trace: false
519
+ });
520
+ (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("auth-sessions", "check");
521
+ });
522
+ (0, _vitest.it)("succeeds if check succeeds", async () => {
523
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkPassedResult);
524
+ await (0, _authSession.executeRunValidateAuthSessionCLI)({
525
+ id: "authSessionId",
526
+ checkRetries: 1,
527
+ createRetries: 1,
528
+ autoRecreate: false,
529
+ headless: false,
530
+ timeout: 999999999,
531
+ keepBrowserOpen: false,
532
+ trace: false
533
+ });
534
+ });
535
+ (0, _vitest.it)("throws if check fails with auto recreate disabled", async () => {
536
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkFailedResult);
537
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
538
+ storageState: {},
539
+ metadata: {
540
+ authSessionId: "authSessionId",
541
+ authSessionType: "API",
542
+ authSessionInput: {},
543
+ createdAt: "1970-01-01T00:00:00Z",
544
+ updatedAt: "1970-01-01T00:00:00Z"
545
+ }
546
+ });
547
+ await (0, _vitest.expect)((0, _authSession.executeRunValidateAuthSessionCLI)({
548
+ id: "authSessionId",
549
+ checkRetries: 1,
550
+ createRetries: 1,
551
+ autoRecreate: false,
552
+ headless: false,
553
+ timeout: 999999999,
554
+ keepBrowserOpen: false,
555
+ trace: false
556
+ })).rejects.toThrow(_helpers.CLIError);
557
+ });
558
+ (0, _vitest.describe)("check failed with auto recreate enabled", () => {
559
+ (0, _vitest.beforeEach)(() => {
560
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkFailedResult);
561
+ });
562
+ afterEach(() => {
563
+ _vitest.vi.mocked(_runApi.runApi).mockReset();
564
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockReset();
565
+ });
566
+ (0, _vitest.it)("asserts create API file exists", async () => {
567
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session")).mockResolvedValueOnce(_checkPassedResult);
568
+ await (0, _authSession.executeRunValidateAuthSessionCLI)({
569
+ id: "authSessionId",
570
+ checkRetries: 1,
571
+ createRetries: 1,
572
+ autoRecreate: true,
573
+ headless: false,
574
+ timeout: 999999999,
575
+ keepBrowserOpen: false,
576
+ trace: false
577
+ });
578
+ (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("auth-sessions", "create");
579
+ });
580
+ (0, _vitest.it)("throws if AuthSession is manual", async () => {
581
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
582
+ storageState: {},
583
+ metadata: {
584
+ authSessionId: "authSessionId",
585
+ authSessionType: "MANUAL",
586
+ authSessionInput: {},
587
+ createdAt: "",
588
+ updatedAt: ""
589
+ }
590
+ });
591
+ await (0, _vitest.expect)((0, _authSession.executeRunValidateAuthSessionCLI)({
592
+ id: "authSessionId",
593
+ checkRetries: 1,
594
+ createRetries: 1,
595
+ autoRecreate: true,
596
+ headless: false,
597
+ timeout: 999999999,
598
+ keepBrowserOpen: false,
599
+ trace: false
600
+ })).rejects.toThrow(_helpers.CLIError);
601
+ });
602
+ (0, _vitest.it)("throws if create fails", async () => {
603
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_errorResult);
604
+ await (0, _vitest.expect)((0, _authSession.executeRunValidateAuthSessionCLI)({
605
+ id: "authSessionId",
606
+ checkRetries: 1,
607
+ createRetries: 1,
608
+ autoRecreate: true,
609
+ headless: false,
610
+ timeout: 999999999,
611
+ keepBrowserOpen: false,
612
+ trace: false
613
+ })).rejects.toThrow(_helpers.CLIError);
614
+ });
615
+ (0, _vitest.it)("throws if create succeeds then check fails", async () => {
616
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session")).mockResolvedValueOnce(_checkFailedResult);
617
+ await (0, _vitest.expect)((0, _authSession.executeRunValidateAuthSessionCLI)({
618
+ id: "authSessionId",
619
+ checkRetries: 1,
620
+ createRetries: 1,
621
+ autoRecreate: true,
622
+ headless: false,
623
+ timeout: 999999999,
624
+ keepBrowserOpen: false,
625
+ trace: false
626
+ })).rejects.toThrow(_helpers.CLIError);
627
+ });
628
+ (0, _vitest.it)("succeeds if create succeeds then check succeeds", async () => {
629
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session")).mockResolvedValueOnce(_checkPassedResult);
630
+ await (0, _authSession.executeRunValidateAuthSessionCLI)({
631
+ id: "authSessionId",
632
+ checkRetries: 1,
633
+ createRetries: 1,
634
+ autoRecreate: true,
635
+ headless: false,
636
+ timeout: 999999999,
637
+ keepBrowserOpen: false,
638
+ trace: false
639
+ });
640
+ });
641
+ });
642
+ });
643
+ (0, _vitest.describe)("executeRunCreateAuthSessionCLI", () => {
644
+ (0, _vitest.beforeEach)(() => {
645
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session")).mockResolvedValueOnce(_checkPassedResult);
646
+ });
647
+ (0, _vitest.it)("asserts create check API file exists", async () => {
648
+ await (0, _authSession.executeRunCreateAuthSessionCLI)({
649
+ input: {},
650
+ checkRetries: 1,
651
+ createRetries: 1,
652
+ headless: false,
653
+ timeout: 999999999,
654
+ keepBrowserOpen: false,
655
+ trace: false
656
+ });
657
+ (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("auth-sessions", "check");
658
+ (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("auth-sessions", "create");
659
+ });
660
+ (0, _vitest.it)("throws if create fails", async () => {
661
+ _vitest.vi.mocked(_runApi.runApi).mockReset().mockResolvedValueOnce(_errorResult);
662
+ await (0, _vitest.expect)((0, _authSession.executeRunCreateAuthSessionCLI)({
663
+ input: {},
664
+ checkRetries: 1,
665
+ createRetries: 1,
666
+ headless: false,
667
+ timeout: 999999999,
668
+ keepBrowserOpen: false,
669
+ trace: false
670
+ })).rejects.toThrow(_helpers.CLIError);
671
+ });
672
+ (0, _vitest.it)("throws if check fails after create succeeds", async () => {
673
+ _vitest.vi.mocked(_runApi.runApi).mockReset().mockResolvedValueOnce(_createSuccessResult("session")).mockResolvedValueOnce(_checkFailedResult);
674
+ await (0, _vitest.expect)((0, _authSession.executeRunCreateAuthSessionCLI)({
675
+ input: {},
676
+ checkRetries: 1,
677
+ createRetries: 1,
678
+ headless: false,
679
+ timeout: 999999999,
680
+ keepBrowserOpen: false,
681
+ trace: false
682
+ })).rejects.toThrow(_helpers.CLIError);
683
+ });
684
+ (0, _vitest.it)("saves to AuthSession instance path if create and check succeed", async () => {
685
+ await (0, _authSession.executeRunCreateAuthSessionCLI)({
686
+ input: "authSessionInput",
687
+ checkRetries: 1,
688
+ createRetries: 1,
689
+ headless: false,
690
+ timeout: 999999999,
691
+ keepBrowserOpen: false,
692
+ trace: false
693
+ });
694
+ (0, _vitest.expect)(_helpers.storeAuthSessionInstance).toHaveBeenCalledWith(_vitest.expect.objectContaining({
695
+ id: _vitest.expect.any(String)
696
+ }));
697
+ });
698
+ (0, _vitest.it)("uses AuthSession id to save if provided", async () => {
699
+ const result = await (0, _authSession.executeRunCreateAuthSessionCLI)({
700
+ id: "authSessionId",
701
+ input: "authSessionInput",
702
+ checkRetries: 1,
703
+ createRetries: 1,
704
+ headless: false,
705
+ timeout: 999999999,
706
+ keepBrowserOpen: false,
707
+ trace: false
708
+ });
709
+ (0, _vitest.expect)(_helpers.storeAuthSessionInstance).toHaveBeenCalledWith(_vitest.expect.objectContaining({
710
+ id: "authSessionId"
711
+ }));
712
+ });
713
+ });
714
+ (0, _vitest.describe)("executeRunUpdateAuthSessionCLI", () => {
715
+ (0, _vitest.beforeEach)(() => {
716
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session")).mockResolvedValueOnce(_checkPassedResult);
717
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
718
+ storageState: {},
719
+ metadata: {
720
+ authSessionId: "authSessionId",
721
+ authSessionType: "API",
722
+ authSessionInput: {},
723
+ createdAt: "",
724
+ updatedAt: ""
725
+ }
726
+ });
727
+ });
728
+ afterEach(() => {
729
+ _vitest.vi.mocked(_runApi.runApi).mockReset();
730
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockReset();
731
+ });
732
+ (0, _vitest.it)("throws if AuthSession is manual", async () => {
733
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
734
+ storageState: {},
735
+ metadata: {
736
+ authSessionId: "authSessionId",
737
+ authSessionType: "MANUAL",
738
+ authSessionInput: {},
739
+ createdAt: "",
740
+ updatedAt: ""
741
+ }
742
+ });
743
+ await (0, _vitest.expect)((0, _authSession.executeRunUpdateAuthSessionCLI)({
744
+ id: "authSessionId",
745
+ checkRetries: 1,
746
+ createRetries: 1,
747
+ headless: false,
748
+ timeout: 999999999,
749
+ keepBrowserOpen: false,
750
+ trace: false
751
+ })).rejects.toThrow(_helpers.CLIError);
752
+ });
753
+ (0, _vitest.it)("calls create with existing input if no input provided", async () => {
754
+ await (0, _authSession.executeRunUpdateAuthSessionCLI)({
755
+ id: "authSessionId",
756
+ checkRetries: 1,
757
+ createRetries: 1,
758
+ headless: false,
759
+ timeout: 999999999,
760
+ keepBrowserOpen: false,
761
+ trace: false
762
+ });
763
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
764
+ automationFunction: {
765
+ name: "auth-sessions/create",
766
+ params: {}
767
+ },
768
+ runOptions: {
769
+ headless: false,
770
+ environment: "standalone",
771
+ proxy: undefined
772
+ },
773
+ retrieveSession: true
774
+ }));
775
+ });
776
+ (0, _vitest.it)("calls create with new input if provided", async () => {
777
+ _vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("newProxy");
778
+ await (0, _authSession.executeRunUpdateAuthSessionCLI)({
779
+ id: "authSessionId",
780
+ input: "newAuthSessionInput",
781
+ proxy: "newProxyUrl",
782
+ checkRetries: 1,
783
+ createRetries: 1,
784
+ headless: false,
785
+ timeout: 999999999,
786
+ keepBrowserOpen: false,
787
+ trace: false
788
+ });
789
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
790
+ automationFunction: {
791
+ name: "auth-sessions/create",
792
+ params: "newAuthSessionInput"
793
+ },
794
+ runOptions: {
795
+ headless: false,
796
+ environment: "standalone",
797
+ proxy: "newProxy"
798
+ },
799
+ retrieveSession: true
800
+ }));
801
+ });
802
+ (0, _vitest.it)("saves the AuthSession with existing input if create and check succeed without providing input", async () => {
803
+ const result = await (0, _authSession.executeRunUpdateAuthSessionCLI)({
804
+ id: "authSessionId",
805
+ checkRetries: 1,
806
+ createRetries: 1,
807
+ headless: false,
808
+ timeout: 999999999,
809
+ keepBrowserOpen: false,
810
+ trace: false
811
+ });
812
+ (0, _vitest.expect)(_helpers.storeAuthSessionInstance).toHaveBeenCalledWith(_vitest.expect.objectContaining({
813
+ id: "authSessionId",
814
+ input: {},
815
+ proxy: undefined
816
+ }));
817
+ });
818
+ (0, _vitest.it)("saves the AuthSession with new input if create and check succeed with new input", async () => {
819
+ const result = await (0, _authSession.executeRunUpdateAuthSessionCLI)({
820
+ id: "authSessionId",
821
+ input: "newAuthSessionInput",
822
+ proxy: "newProxyUrl",
823
+ checkRetries: 1,
824
+ createRetries: 1,
825
+ headless: false,
826
+ timeout: 999999999,
827
+ keepBrowserOpen: false,
828
+ trace: false
829
+ });
830
+ (0, _vitest.expect)(_helpers.storeAuthSessionInstance).toHaveBeenCalledWith(_vitest.expect.objectContaining({
831
+ id: "authSessionId",
832
+ input: "newAuthSessionInput",
833
+ proxy: "newProxyUrl"
834
+ }));
835
+ });
836
+ });
837
+ (0, _vitest.describe)("executeAttemptCheckAuthSessionCLI", () => {
838
+ (0, _vitest.beforeEach)(() => {
839
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
840
+ storageState: {},
841
+ metadata: {
842
+ authSessionId: "authSessionId",
843
+ authSessionType: "API",
844
+ authSessionInput: {},
845
+ createdAt: "",
846
+ updatedAt: ""
847
+ }
848
+ });
849
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkPassedResult);
850
+ });
851
+ afterEach(() => {
852
+ _vitest.vi.mocked(_runApi.runApi).mockReset();
853
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockReset();
854
+ });
855
+ (0, _vitest.it)("asserts check API file exists", async () => {
856
+ await (0, _authSession.executeAttemptCheckAuthSessionCLI)({
857
+ id: "authSessionId",
858
+ headless: false,
859
+ timeout: 999999999,
860
+ keepBrowserOpen: false,
861
+ trace: false
862
+ });
863
+ (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("auth-sessions", "check");
864
+ });
865
+ (0, _vitest.it)("succeeds if check succeeds", async () => {
866
+ await (0, _authSession.executeAttemptCheckAuthSessionCLI)({
867
+ id: "authSessionId",
868
+ headless: false,
869
+ timeout: 999999999,
870
+ keepBrowserOpen: false,
871
+ trace: false
872
+ });
873
+ });
874
+ (0, _vitest.it)("throws if check fails", async () => {
875
+ _vitest.vi.mocked(_runApi.runApi).mockReset().mockResolvedValueOnce(_checkFailedResult);
876
+ await (0, _vitest.expect)((0, _authSession.executeAttemptCheckAuthSessionCLI)({
877
+ id: "authSessionId",
878
+ headless: false,
879
+ timeout: 999999999,
880
+ keepBrowserOpen: false,
881
+ trace: false
882
+ })).rejects.toThrow(_helpers.CLIError);
883
+ });
884
+ });
885
+ (0, _vitest.describe)("executeAttemptCreateAuthSessionCLI", () => {
886
+ (0, _vitest.beforeEach)(() => {
887
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_createSuccessResult("session"));
888
+ });
889
+ (0, _vitest.it)("asserts create API file exists", async () => {
890
+ await (0, _authSession.executeAttemptCreateAuthSessionCLI)({
891
+ input: {},
892
+ headless: false,
893
+ timeout: 999999999,
894
+ keepBrowserOpen: false,
895
+ trace: false
896
+ });
897
+ (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("auth-sessions", "create");
898
+ });
899
+ (0, _vitest.it)("throws if create fails", async () => {
900
+ _vitest.vi.mocked(_runApi.runApi).mockReset().mockResolvedValueOnce(_errorResult);
901
+ await (0, _vitest.expect)((0, _authSession.executeAttemptCreateAuthSessionCLI)({
902
+ input: {},
903
+ headless: false,
904
+ timeout: 999999999,
905
+ keepBrowserOpen: false,
906
+ trace: false
907
+ })).rejects.toThrow(_helpers.CLIError);
908
+ });
909
+ (0, _vitest.it)("saves to AuthSession instance path if create and check succeed", async () => {
910
+ await (0, _authSession.executeAttemptCreateAuthSessionCLI)({
911
+ input: "authSessionInput",
912
+ headless: false,
913
+ timeout: 999999999,
914
+ keepBrowserOpen: false,
915
+ trace: false
916
+ });
917
+ (0, _vitest.expect)(_helpers.storeAuthSessionInstance).toHaveBeenCalledWith(_vitest.expect.objectContaining({
918
+ id: _vitest.expect.any(String)
919
+ }));
920
+ });
921
+ (0, _vitest.it)("uses AuthSession id to save if provided", async () => {
922
+ await (0, _authSession.executeAttemptCreateAuthSessionCLI)({
923
+ id: "authSessionId",
924
+ input: "authSessionInput",
925
+ headless: false,
926
+ timeout: 999999999,
927
+ keepBrowserOpen: false,
928
+ trace: false
929
+ });
930
+ (0, _vitest.expect)(_helpers.storeAuthSessionInstance).toHaveBeenCalledWith(_vitest.expect.objectContaining({
931
+ id: "authSessionId"
932
+ }));
933
+ });
934
+ });
935
+ (0, _vitest.describe)("executeRecordAuthSessionCLI", () => {
936
+ let mockPage;
937
+ let mockContext;
938
+ (0, _vitest.beforeEach)(() => {
939
+ _vitest.vi.useFakeTimers();
940
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce(_checkPassedResult);
941
+ mockPage = {
942
+ url: _vitest.vi.fn().mockReturnValue(""),
943
+ close: _vitest.vi.fn(),
944
+ goto: _vitest.vi.fn(),
945
+ waitForLoadState: _vitest.vi.fn()
946
+ };
947
+ mockContext = {
948
+ pages: _vitest.vi.fn().mockReturnValue([mockPage]),
949
+ close: _vitest.vi.fn()
950
+ };
951
+ _vitest.vi.mocked(_launchBrowser.launchChromium).mockResolvedValue({
952
+ context: mockContext,
953
+ page: mockPage
954
+ });
955
+ _vitest.vi.mocked(_helpers.loadAuthSessionInstance).mockResolvedValue({
956
+ storageState: {},
957
+ metadata: {
958
+ authSessionId: "authSessionId",
959
+ authSessionType: "MANUAL",
960
+ authSessionInput: {},
961
+ createdAt: "",
962
+ updatedAt: ""
963
+ }
964
+ });
965
+ });
966
+ afterEach(() => {
967
+ _vitest.vi.mocked(_runApi.runApi).mockReset();
968
+ _vitest.vi.mocked(_launchBrowser.launchChromium).mockReset();
969
+ _vitest.vi.useRealTimers();
970
+ });
971
+ (0, _vitest.it)("launches browser with app mode", async () => {
972
+ mockPage.url.mockReturnValue("finishUrl");
973
+ await (0, _authSession.executeRecordAuthSessionCLI)({
974
+ checkRetries: 1,
975
+ startUrl: "startUrl",
976
+ finishUrl: "finishUrl",
977
+ headless: false,
978
+ keepBrowserOpen: false
979
+ });
980
+ (0, _vitest.expect)(_launchBrowser.launchChromium).toHaveBeenCalledWith(_vitest.expect.objectContaining({
981
+ appModeInitialUrl: "startUrl"
982
+ }));
983
+ });
984
+ (0, _vitest.it)("navigates to the start url if the page doesn't load with it", async () => {
985
+ mockPage.url.mockReturnValue("finishUrl");
986
+ await (0, _authSession.executeRecordAuthSessionCLI)({
987
+ checkRetries: 1,
988
+ startUrl: "startUrl",
989
+ finishUrl: "finishUrl",
990
+ headless: false,
991
+ keepBrowserOpen: false
992
+ });
993
+ (0, _vitest.expect)(mockPage.goto).toHaveBeenCalledWith("startUrl");
994
+ });
995
+ (0, _vitest.it)("waits for the finish url", async () => {
996
+ mockPage.url.mockReturnValueOnce("startUrl");
997
+ const mockTimeout = getMockTimeout();
998
+ let pending = true;
999
+ const p = (0, _authSession.executeRecordAuthSessionCLI)({
1000
+ checkRetries: 1,
1001
+ startUrl: "startUrl",
1002
+ finishUrl: "finishUrl",
1003
+ headless: false,
1004
+ keepBrowserOpen: false
1005
+ }).finally(() => pending = false);
1006
+ await mockTimeout.resolve();
1007
+ await mockTimeout.resolve();
1008
+ await mockTimeout.resolve();
1009
+ (0, _vitest.expect)(pending).toEqual(true);
1010
+ mockPage.url.mockClear();
1011
+ mockPage.url.mockReturnValueOnce("finishUrl");
1012
+ await mockTimeout.resolve();
1013
+ await p;
1014
+ });
1015
+ (0, _vitest.it)("throws if timeout is reached", async () => {
1016
+ mockPage.url.mockReturnValueOnce("startUrl");
1017
+ const mockTimeout = getMockTimeout();
1018
+ _vitest.vi.setSystemTime(new Date(0));
1019
+ let pending = true;
1020
+ const p = (0, _authSession.executeRecordAuthSessionCLI)({
1021
+ checkRetries: 1,
1022
+ startUrl: "startUrl",
1023
+ finishUrl: "finishUrl",
1024
+ headless: false,
1025
+ keepBrowserOpen: false,
1026
+ timeout: 1000
1027
+ }).finally(() => pending = false);
1028
+ await mockTimeout.resolve();
1029
+ await mockTimeout.resolve();
1030
+ await mockTimeout.resolve();
1031
+ (0, _vitest.expect)(pending).toEqual(true);
1032
+ _vitest.vi.setSystemTime(new Date(2000));
1033
+ await mockTimeout.resolve();
1034
+ await (0, _vitest.expect)(p).rejects.toThrow(_helpers.CLIError);
1035
+ });
1036
+ (0, _vitest.it)("stores AuthSession and validates it if successful", async () => {
1037
+ mockPage.url.mockReturnValue("finishUrl");
1038
+ await (0, _authSession.executeRecordAuthSessionCLI)({
1039
+ checkRetries: 1,
1040
+ startUrl: "startUrl",
1041
+ finishUrl: "finishUrl",
1042
+ headless: false,
1043
+ keepBrowserOpen: false
1044
+ });
1045
+ (0, _vitest.expect)(_helpers.storeAuthSessionInstance).toHaveBeenCalledWith(_vitest.expect.objectContaining({
1046
+ id: _vitest.expect.any(String),
1047
+ metadata: _vitest.expect.objectContaining({
1048
+ authSessionType: "MANUAL",
1049
+ recorderStartUrl: "startUrl",
1050
+ recorderEndUrl: "finishUrl"
1051
+ })
1052
+ }));
1053
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
1054
+ automationFunction: _vitest.expect.objectContaining({
1055
+ name: "auth-sessions/check"
1056
+ })
1057
+ }));
1058
+ });
1059
+ });
1060
+ });