@intuned/runtime-dev 1.3.9-dev8 → 1.3.11-deployment.0

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 (229) hide show
  1. package/InterfaceTemplate/index.playwright.ts +1 -1
  2. package/WebTemplate.zip +0 -0
  3. package/bin/intuned +1 -1
  4. package/bin/intuned-api-run +1 -1
  5. package/bin/intuned-auth-session-check +1 -1
  6. package/bin/intuned-auth-session-create +1 -1
  7. package/bin/intuned-auth-session-load +1 -1
  8. package/dist/commands/intuned-cli/commands/attempt_api.command.js +1 -1
  9. package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +1 -1
  10. package/dist/commands/intuned-cli/commands/run_api.command.js +1 -1
  11. package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +3 -0
  12. package/dist/commands/intuned-cli/commands/types.d.ts +4 -0
  13. package/dist/commands/intuned-cli/commands/types.js +5 -3
  14. package/dist/commands/intuned-cli/controller/api.d.ts +1 -1
  15. package/dist/commands/intuned-cli/controller/api.js +4 -2
  16. package/dist/commands/intuned-cli/controller/authSession.d.ts +2 -2
  17. package/dist/commands/intuned-cli/controller/authSession.js +8 -4
  18. package/dist/commands/intuned-cli/controller/deploy.d.ts +1 -0
  19. package/dist/commands/intuned-cli/controller/deploy.js +141 -6
  20. package/dist/commands/intuned-cli/controller/save.d.ts +4 -1
  21. package/dist/commands/intuned-cli/controller/save.js +8 -2
  22. package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +11 -0
  23. package/dist/commands/intuned-cli/helpers/backend.js +1 -1
  24. package/dist/commands/intuned-cli/helpers/browser.d.ts +2 -1
  25. package/dist/commands/intuned-cli/helpers/browser.js +8 -1
  26. package/dist/commands/intuned-cli/helpers/errors.d.ts +3 -0
  27. package/dist/commands/intuned-cli/helpers/errors.js +8 -1
  28. package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +113 -11
  29. package/dist/commands/intuned-cli/helpers/intunedJson.js +19 -3
  30. package/dist/commands/intuned-cli/helpers/wrapper.js +7 -1
  31. package/dist/commands/intuned-cli/main.js +1 -0
  32. package/{package/dist/commands/common/utils/fileUtils.js → dist/common/binStartupScript.js} +26 -25
  33. package/package.json +6 -2
  34. package/bin/common.js +0 -30
  35. package/package/dist/commands/api/run.d.ts +0 -6
  36. package/package/dist/commands/api/run.js +0 -123
  37. package/package/dist/commands/auth-sessions/load.d.ts +0 -2
  38. package/package/dist/commands/auth-sessions/load.js +0 -35
  39. package/package/dist/commands/auth-sessions/run-check.d.ts +0 -2
  40. package/package/dist/commands/auth-sessions/run-check.js +0 -74
  41. package/package/dist/commands/auth-sessions/run-create.d.ts +0 -2
  42. package/package/dist/commands/auth-sessions/run-create.js +0 -78
  43. package/package/dist/commands/browser/save-state.d.ts +0 -2
  44. package/package/dist/commands/browser/save-state.js +0 -17
  45. package/package/dist/commands/browser/start-browser.d.ts +0 -2
  46. package/package/dist/commands/browser/start-browser.js +0 -14
  47. package/package/dist/commands/build.js +0 -84
  48. package/package/dist/commands/common/browserUtils.d.ts +0 -14
  49. package/package/dist/commands/common/browserUtils.js +0 -58
  50. package/package/dist/commands/common/getFirstLineNumber.d.ts +0 -9
  51. package/package/dist/commands/common/getFirstLineNumber.js +0 -101
  52. package/package/dist/commands/common/getFirstLineNumber.test.js +0 -228
  53. package/package/dist/commands/common/projectExclusions.d.ts +0 -2
  54. package/package/dist/commands/common/projectExclusions.js +0 -8
  55. package/package/dist/commands/common/sendMessageToClient.d.ts +0 -1
  56. package/package/dist/commands/common/sendMessageToClient.js +0 -10
  57. package/package/dist/commands/common/tsNodeImport.d.ts +0 -2
  58. package/package/dist/commands/common/tsNodeImport.js +0 -34
  59. package/package/dist/commands/common/utils/fileUtils.d.ts +0 -6
  60. package/package/dist/commands/common/utils/settings.d.ts +0 -2
  61. package/package/dist/commands/common/utils/settings.js +0 -31
  62. package/package/dist/commands/common/utils/template.d.ts +0 -2
  63. package/package/dist/commands/common/utils/template.js +0 -31
  64. package/package/dist/commands/common/utils/unixSocket.d.ts +0 -9
  65. package/package/dist/commands/common/utils/unixSocket.js +0 -44
  66. package/package/dist/commands/interface/run.d.ts +0 -1
  67. package/package/dist/commands/interface/run.js +0 -216
  68. package/package/dist/commands/intuned-cli/commands/attempt.command.d.ts +0 -1
  69. package/package/dist/commands/intuned-cli/commands/attempt.command.js +0 -8
  70. package/package/dist/commands/intuned-cli/commands/attempt_api.command.d.ts +0 -1
  71. package/package/dist/commands/intuned-cli/commands/attempt_api.command.js +0 -30
  72. package/package/dist/commands/intuned-cli/commands/attempt_authsession.command.d.ts +0 -1
  73. package/package/dist/commands/intuned-cli/commands/attempt_authsession.command.js +0 -8
  74. package/package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.d.ts +0 -1
  75. package/package/dist/commands/intuned-cli/commands/attempt_authsession_check.command.js +0 -19
  76. package/package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.d.ts +0 -1
  77. package/package/dist/commands/intuned-cli/commands/attempt_authsession_create.command.js +0 -24
  78. package/package/dist/commands/intuned-cli/commands/authsession.command.d.ts +0 -1
  79. package/package/dist/commands/intuned-cli/commands/authsession.command.js +0 -8
  80. package/package/dist/commands/intuned-cli/commands/authsession_record.command.d.ts +0 -1
  81. package/package/dist/commands/intuned-cli/commands/authsession_record.command.js +0 -31
  82. package/package/dist/commands/intuned-cli/commands/build.command.d.ts +0 -1
  83. package/package/dist/commands/intuned-cli/commands/build.command.js +0 -12
  84. package/package/dist/commands/intuned-cli/commands/command.d.ts +0 -2
  85. package/package/dist/commands/intuned-cli/commands/command.js +0 -9
  86. package/package/dist/commands/intuned-cli/commands/deploy.command.d.ts +0 -1
  87. package/package/dist/commands/intuned-cli/commands/deploy.command.js +0 -38
  88. package/package/dist/commands/intuned-cli/commands/index.d.ts +0 -18
  89. package/package/dist/commands/intuned-cli/commands/index.js +0 -203
  90. package/package/dist/commands/intuned-cli/commands/init.command.d.ts +0 -1
  91. package/package/dist/commands/intuned-cli/commands/init.command.js +0 -13
  92. package/package/dist/commands/intuned-cli/commands/run.command.d.ts +0 -1
  93. package/package/dist/commands/intuned-cli/commands/run.command.js +0 -8
  94. package/package/dist/commands/intuned-cli/commands/run_api.command.d.ts +0 -1
  95. package/package/dist/commands/intuned-cli/commands/run_api.command.js +0 -46
  96. package/package/dist/commands/intuned-cli/commands/run_authsession.command.d.ts +0 -28
  97. package/package/dist/commands/intuned-cli/commands/run_authsession.command.js +0 -17
  98. package/package/dist/commands/intuned-cli/commands/run_authsession_create.command.d.ts +0 -1
  99. package/package/dist/commands/intuned-cli/commands/run_authsession_create.command.js +0 -35
  100. package/package/dist/commands/intuned-cli/commands/run_authsession_update.command.d.ts +0 -1
  101. package/package/dist/commands/intuned-cli/commands/run_authsession_update.command.js +0 -35
  102. package/package/dist/commands/intuned-cli/commands/run_authsession_validate.command.d.ts +0 -1
  103. package/package/dist/commands/intuned-cli/commands/run_authsession_validate.command.js +0 -33
  104. package/package/dist/commands/intuned-cli/commands/save.command.d.ts +0 -13
  105. package/package/dist/commands/intuned-cli/commands/save.command.js +0 -42
  106. package/package/dist/commands/intuned-cli/commands/types.d.ts +0 -31
  107. package/package/dist/commands/intuned-cli/commands/types.js +0 -29
  108. package/package/dist/commands/intuned-cli/constants/index.d.ts +0 -17
  109. package/package/dist/commands/intuned-cli/constants/index.js +0 -25
  110. package/package/dist/commands/intuned-cli/controller/__test__/api.test.js +0 -397
  111. package/package/dist/commands/intuned-cli/controller/__test__/authSession.test.js +0 -1059
  112. package/package/dist/commands/intuned-cli/controller/api.d.ts +0 -42
  113. package/package/dist/commands/intuned-cli/controller/api.js +0 -189
  114. package/package/dist/commands/intuned-cli/controller/authSession.d.ts +0 -209
  115. package/package/dist/commands/intuned-cli/controller/authSession.js +0 -420
  116. package/package/dist/commands/intuned-cli/controller/build.d.ts +0 -1
  117. package/package/dist/commands/intuned-cli/controller/build.js +0 -36
  118. package/package/dist/commands/intuned-cli/controller/deploy.d.ts +0 -4
  119. package/package/dist/commands/intuned-cli/controller/deploy.js +0 -139
  120. package/package/dist/commands/intuned-cli/controller/index.d.ts +0 -1
  121. package/package/dist/commands/intuned-cli/controller/index.js +0 -46
  122. package/package/dist/commands/intuned-cli/controller/save.d.ts +0 -14
  123. package/package/dist/commands/intuned-cli/controller/save.js +0 -345
  124. package/package/dist/commands/intuned-cli/helpers/__test__/browser.test.js +0 -103
  125. package/package/dist/commands/intuned-cli/helpers/__test__/tracing.test.js +0 -40
  126. package/package/dist/commands/intuned-cli/helpers/api.d.ts +0 -3
  127. package/package/dist/commands/intuned-cli/helpers/api.js +0 -19
  128. package/package/dist/commands/intuned-cli/helpers/auth.d.ts +0 -46
  129. package/package/dist/commands/intuned-cli/helpers/auth.js +0 -144
  130. package/package/dist/commands/intuned-cli/helpers/backend.d.ts +0 -8
  131. package/package/dist/commands/intuned-cli/helpers/backend.js +0 -27
  132. package/package/dist/commands/intuned-cli/helpers/browser.d.ts +0 -14
  133. package/package/dist/commands/intuned-cli/helpers/browser.js +0 -57
  134. package/package/dist/commands/intuned-cli/helpers/context.d.ts +0 -3
  135. package/package/dist/commands/intuned-cli/helpers/context.js +0 -33
  136. package/package/dist/commands/intuned-cli/helpers/errors.d.ts +0 -13
  137. package/package/dist/commands/intuned-cli/helpers/errors.js +0 -37
  138. package/package/dist/commands/intuned-cli/helpers/index.d.ts +0 -12
  139. package/package/dist/commands/intuned-cli/helpers/index.js +0 -137
  140. package/package/dist/commands/intuned-cli/helpers/intunedJson.d.ts +0 -69
  141. package/package/dist/commands/intuned-cli/helpers/intunedJson.js +0 -71
  142. package/package/dist/commands/intuned-cli/helpers/proxy.d.ts +0 -5
  143. package/package/dist/commands/intuned-cli/helpers/proxy.js +0 -23
  144. package/package/dist/commands/intuned-cli/helpers/terminal.d.ts +0 -5
  145. package/package/dist/commands/intuned-cli/helpers/terminal.js +0 -13
  146. package/package/dist/commands/intuned-cli/helpers/timeout.d.ts +0 -1
  147. package/package/dist/commands/intuned-cli/helpers/timeout.js +0 -23
  148. package/package/dist/commands/intuned-cli/helpers/traces.d.ts +0 -2
  149. package/package/dist/commands/intuned-cli/helpers/traces.js +0 -32
  150. package/package/dist/commands/intuned-cli/helpers/validation.d.ts +0 -2
  151. package/package/dist/commands/intuned-cli/helpers/validation.js +0 -14
  152. package/package/dist/commands/intuned-cli/helpers/wrapper.d.ts +0 -2
  153. package/package/dist/commands/intuned-cli/helpers/wrapper.js +0 -60
  154. package/package/dist/commands/intuned-cli/index.d.ts +0 -1
  155. package/package/dist/commands/intuned-cli/index.js +0 -16
  156. package/package/dist/commands/intuned-cli/main.d.ts +0 -1
  157. package/package/dist/commands/intuned-cli/main.js +0 -22
  158. package/package/dist/commands/intuned-cli/types.d.ts +0 -41
  159. package/package/dist/commands/intuned-cli/types.js +0 -12
  160. package/package/dist/commands/ts-check.d.ts +0 -2
  161. package/package/dist/commands/ts-check.js +0 -56
  162. package/package/dist/common/Logger/Logger/index.d.ts +0 -12
  163. package/package/dist/common/Logger/Logger/index.js +0 -60
  164. package/package/dist/common/Logger/Logger/types.d.ts +0 -8
  165. package/package/dist/common/Logger/Logger/types.js +0 -5
  166. package/package/dist/common/Logger/index.d.ts +0 -12
  167. package/package/dist/common/Logger/index.js +0 -60
  168. package/package/dist/common/Logger/types.d.ts +0 -8
  169. package/package/dist/common/Logger/types.js +0 -5
  170. package/package/dist/common/assets/browser_scripts.js +0 -2580
  171. package/package/dist/common/asyncLocalStorage/index.d.ts +0 -16
  172. package/package/dist/common/asyncLocalStorage/index.js +0 -17
  173. package/package/dist/common/backendFunctions/getAuthSessionParameters.d.ts +0 -1
  174. package/package/dist/common/backendFunctions/getAuthSessionParameters.js +0 -38
  175. package/package/dist/common/cleanEnvironmentVariables.d.ts +0 -1
  176. package/package/dist/common/cleanEnvironmentVariables.js +0 -16
  177. package/package/dist/common/constants.d.ts +0 -10
  178. package/package/dist/common/constants.js +0 -16
  179. package/package/dist/common/contextStorageStateHelpers.d.ts +0 -21
  180. package/package/dist/common/contextStorageStateHelpers.js +0 -81
  181. package/package/dist/common/extensionsHelpers.d.ts +0 -8
  182. package/package/dist/common/extensionsHelpers.js +0 -80
  183. package/package/dist/common/formatZodError.d.ts +0 -2
  184. package/package/dist/common/formatZodError.js +0 -18
  185. package/package/dist/common/jwtTokenManager.d.ts +0 -17
  186. package/package/dist/common/jwtTokenManager.js +0 -109
  187. package/package/dist/common/launchBrowser.d.ts +0 -25
  188. package/package/dist/common/launchBrowser.js +0 -172
  189. package/package/dist/common/playwrightContext.d.ts +0 -31
  190. package/package/dist/common/playwrightContext.js +0 -144
  191. package/package/dist/common/runApi/errors.d.ts +0 -72
  192. package/package/dist/common/runApi/errors.js +0 -169
  193. package/package/dist/common/runApi/importUsingImportFunction.d.ts +0 -9
  194. package/package/dist/common/runApi/importUsingImportFunction.js +0 -46
  195. package/package/dist/common/runApi/index.d.ts +0 -11
  196. package/package/dist/common/runApi/index.js +0 -199
  197. package/package/dist/common/runApi/types.d.ts +0 -830
  198. package/package/dist/common/runApi/types.js +0 -73
  199. package/package/dist/common/settingsSchema.d.ts +0 -518
  200. package/package/dist/common/settingsSchema.js +0 -57
  201. package/package/dist/common/setupContextHook.d.ts +0 -17
  202. package/package/dist/common/setupContextHook.js +0 -22
  203. package/package/dist/common/telemetry.d.ts +0 -3
  204. package/package/dist/common/telemetry.js +0 -32
  205. package/package/dist/index.d.ts +0 -4
  206. package/package/dist/index.js +0 -69
  207. package/package/dist/runtime/RunError.d.ts +0 -5
  208. package/package/dist/runtime/RunError.js +0 -19
  209. package/package/dist/runtime/attemptStore.d.ts +0 -2
  210. package/package/dist/runtime/attemptStore.js +0 -23
  211. package/package/dist/runtime/downloadDirectory.d.ts +0 -1
  212. package/package/dist/runtime/downloadDirectory.js +0 -19
  213. package/package/dist/runtime/enums.d.js +0 -5
  214. package/package/dist/runtime/enums.d.ts +0 -11
  215. package/package/dist/runtime/enums.js +0 -18
  216. package/package/dist/runtime/executionHelpers.test.js +0 -52
  217. package/package/dist/runtime/export.d.js +0 -5
  218. package/package/dist/runtime/export.d.ts +0 -228
  219. package/package/dist/runtime/extendPayload.d.ts +0 -2
  220. package/package/dist/runtime/extendPayload.js +0 -21
  221. package/package/dist/runtime/extendTimeout.d.ts +0 -1
  222. package/package/dist/runtime/extendTimeout.js +0 -23
  223. package/package/dist/runtime/getAuthSessionParameters.d.ts +0 -1
  224. package/package/dist/runtime/getAuthSessionParameters.js +0 -20
  225. package/package/dist/runtime/index.d.ts +0 -7
  226. package/package/dist/runtime/index.js +0 -54
  227. package/package/dist/runtime/runInfo.d.ts +0 -2
  228. package/package/dist/runtime/runInfo.js +0 -21
  229. /package/{package/dist/commands/build.d.ts → dist/common/binStartupScript.d.ts} +0 -0
@@ -1,1059 +0,0 @@
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
- });