@intuned/runtime-dev 1.3.18-interface.15 → 1.3.18-interface.18

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