@intuned/runtime-dev 1.3.8-jsonl.0 → 1.3.9-dev1

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