@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,397 @@
1
+ "use strict";
2
+
3
+ var _vitest = require("vitest");
4
+ var _api = require("../api");
5
+ var _authSession = require("../authSession");
6
+ var _helpers = require("../../helpers");
7
+ var _neverthrow = require("neverthrow");
8
+ var _runApi = require("../../../../common/runApi");
9
+ var _fsExtra = require("fs-extra");
10
+ var _browser = require("../../helpers/browser");
11
+ function getTerminal() {
12
+ return new Proxy(() => ({}), {
13
+ get: () => getTerminal(),
14
+ apply: () => ({})
15
+ });
16
+ }
17
+ _vitest.vi.mock("fs-extra", () => ({
18
+ writeJSON: _vitest.vi.fn(),
19
+ exists: _vitest.vi.fn().mockResolvedValue(true)
20
+ }));
21
+ _vitest.vi.mock("../authSession", async importOriginal => {
22
+ const original = await importOriginal();
23
+ return {
24
+ ...original,
25
+ executeRunValidateAuthSessionCLI: _vitest.vi.fn()
26
+ };
27
+ });
28
+ _vitest.vi.mock("../../../../common/runApi", async importOriginal => {
29
+ const original = await importOriginal();
30
+ return {
31
+ ...original,
32
+ runApi: _vitest.vi.fn().mockImplementation(() => (0, _neverthrow.ok)({}))
33
+ };
34
+ });
35
+ _vitest.vi.mock("../../helpers/terminal", () => ({
36
+ terminal: getTerminal()
37
+ }));
38
+ _vitest.vi.mock("../../helpers/proxy", async () => {
39
+ return {
40
+ parseUrlProxy: _vitest.vi.fn()
41
+ };
42
+ });
43
+ _vitest.vi.mock("../../helpers/browser", async importOriginal => {
44
+ const original = await importOriginal();
45
+ return {
46
+ getCLIRunOptions: _vitest.vi.fn(({
47
+ keepBrowserOpen: _,
48
+ ...rest
49
+ }) => original.getCLIRunOptions({
50
+ keepBrowserOpen: false,
51
+ ...rest
52
+ }))
53
+ };
54
+ });
55
+ _vitest.vi.mock("../../helpers", async importOriginal => {
56
+ const original = await importOriginal();
57
+ return {
58
+ ...original,
59
+ terminal: getTerminal(),
60
+ assertApiFileExists: _vitest.vi.fn(),
61
+ withCLIContext: _vitest.vi.fn(fn => fn()),
62
+ withTimeout: _vitest.vi.fn(fn => fn()),
63
+ withCLITrace: _vitest.vi.fn(original.withCLITrace),
64
+ registerGetAuthSessionParameters: _vitest.vi.fn()
65
+ };
66
+ });
67
+ (0, _vitest.describe)("API controller", () => {
68
+ (0, _vitest.beforeEach)(() => {
69
+ _vitest.vi.clearAllMocks();
70
+ });
71
+ (0, _vitest.describe)("attemptApi", () => {
72
+ (0, _vitest.it)("calls timeout middleware with timeout", async () => {
73
+ await (0, _api._attemptApi)({
74
+ apiName: "testApi",
75
+ inputData: {},
76
+ headless: false,
77
+ timeout: 6000,
78
+ keepBrowserOpen: false
79
+ });
80
+ (0, _vitest.expect)(_helpers.withTimeout).toHaveBeenCalledWith(_vitest.expect.any(Function), 6000);
81
+ });
82
+ (0, _vitest.it)("uses tracing wrapper with trace id", async () => {
83
+ await (0, _api._attemptApi)({
84
+ apiName: "testApi",
85
+ inputData: {},
86
+ headless: false,
87
+ timeout: 6000,
88
+ keepBrowserOpen: false
89
+ });
90
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), undefined);
91
+ _vitest.vi.mocked(_helpers.withCLITrace).mockClear();
92
+ _vitest.vi.mocked(_runApi.runApi).mockClear();
93
+ await (0, _api._attemptApi)({
94
+ apiName: "testApi",
95
+ inputData: {},
96
+ headless: false,
97
+ timeout: 6000,
98
+ keepBrowserOpen: false,
99
+ traceId: "trace-id"
100
+ });
101
+ (0, _vitest.expect)(_helpers.withCLITrace).toHaveBeenCalledWith(_vitest.expect.any(Function), "trace-id");
102
+ });
103
+ (0, _vitest.it)("uses cli browser helper", async () => {
104
+ await (0, _api._attemptApi)({
105
+ apiName: "testApi",
106
+ inputData: {},
107
+ headless: false,
108
+ timeout: 6000,
109
+ keepBrowserOpen: false
110
+ });
111
+ (0, _vitest.expect)(_browser.getCLIRunOptions).toHaveBeenCalledWith(_vitest.expect.objectContaining({
112
+ headless: false,
113
+ keepBrowserOpen: false
114
+ }));
115
+ _vitest.vi.mocked(_helpers.withCLITrace).mockClear();
116
+ _vitest.vi.mocked(_runApi.runApi).mockClear();
117
+ await (0, _api._attemptApi)({
118
+ apiName: "testApi",
119
+ inputData: {},
120
+ headless: true,
121
+ timeout: 6000,
122
+ keepBrowserOpen: true
123
+ });
124
+ (0, _vitest.expect)(_browser.getCLIRunOptions).toHaveBeenCalledWith(_vitest.expect.objectContaining({
125
+ headless: true,
126
+ keepBrowserOpen: true
127
+ }));
128
+ });
129
+ (0, _vitest.it)("calls runApi with correct parameters and parses proxy", async () => {
130
+ _vitest.vi.mocked(_helpers.parseUrlProxy).mockReturnValueOnce("parsed-proxy");
131
+ await (0, _api._attemptApi)({
132
+ apiName: "testApi",
133
+ inputData: "inputData",
134
+ headless: "headless",
135
+ auth: "auth",
136
+ proxy: "proxy",
137
+ timeout: 999999999,
138
+ keepBrowserOpen: false
139
+ });
140
+ (0, _vitest.expect)(_helpers.parseUrlProxy).toHaveBeenCalledWith("proxy");
141
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
142
+ automationFunction: {
143
+ name: "api/testApi",
144
+ params: "inputData"
145
+ },
146
+ runOptions: {
147
+ headless: "headless",
148
+ environment: "standalone",
149
+ proxy: "parsed-proxy"
150
+ },
151
+ auth: {
152
+ session: {
153
+ type: "state",
154
+ state: "auth"
155
+ }
156
+ },
157
+ importFunction: _vitest.expect.anything()
158
+ }));
159
+ });
160
+ (0, _vitest.it)("returns the result and extended payloads if runApi succeeds", async () => {
161
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.ok)({
162
+ result: "result",
163
+ extendedPayloads: "extendedPayloads"
164
+ }));
165
+ const result = await (0, _api._attemptApi)({
166
+ apiName: "testApi",
167
+ inputData: "inputData",
168
+ headless: "headless",
169
+ auth: "auth",
170
+ timeout: 999999999,
171
+ keepBrowserOpen: false
172
+ });
173
+ (0, _vitest.expect)(result).toEqual({
174
+ result: "result",
175
+ payloadToAppend: "extendedPayloads"
176
+ });
177
+ });
178
+ (0, _vitest.it)("throws the error runApi fails with an error", async () => {
179
+ const error = new Error("runApi failed");
180
+ _vitest.vi.mocked(_runApi.runApi).mockRejectedValueOnce(error);
181
+ await (0, _vitest.expect)((0, _api._attemptApi)({
182
+ apiName: "testApi",
183
+ inputData: "inputData",
184
+ headless: "headless",
185
+ auth: "auth",
186
+ timeout: 999999999,
187
+ keepBrowserOpen: false
188
+ })).rejects.toThrow(error);
189
+ });
190
+ });
191
+ (0, _vitest.describe)("executeRunApiCLI", () => {
192
+ (0, _vitest.it)("enables tracing correctly", async () => {
193
+ await (0, _api.executeRunApiCLI)({
194
+ apiName: "testApi",
195
+ inputData: {},
196
+ retries: 1,
197
+ trace: false
198
+ });
199
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
200
+ tracing: {
201
+ enabled: false
202
+ }
203
+ }));
204
+ _vitest.vi.mocked(_runApi.runApi).mockClear();
205
+ await (0, _api.executeRunApiCLI)({
206
+ apiName: "testApi",
207
+ inputData: {},
208
+ retries: 1,
209
+ trace: true
210
+ });
211
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
212
+ tracing: _vitest.expect.objectContaining({
213
+ enabled: true
214
+ })
215
+ }));
216
+ });
217
+ (0, _vitest.it)("calls attemptApi once if success", async () => {
218
+ await (0, _api.executeRunApiCLI)({
219
+ apiName: "testApi",
220
+ inputData: {},
221
+ retries: 3
222
+ });
223
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
224
+ });
225
+ (0, _vitest.it)("stops retrying after max retries", async () => {
226
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed")));
227
+ await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
228
+ apiName: "testApi",
229
+ inputData: {},
230
+ retries: 10
231
+ })).rejects.toThrow(_helpers.CLIError);
232
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(10);
233
+ });
234
+ (0, _vitest.it)("stops retrying on non-automation errors", async () => {
235
+ _vitest.vi.mocked(_runApi.runApi).mockRejectedValue(new Error("runApi failed"));
236
+ await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
237
+ apiName: "testApi",
238
+ inputData: {},
239
+ retries: 3
240
+ })).rejects.toThrow("runApi failed");
241
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
242
+ });
243
+ (0, _vitest.it)("stops retrying on success", async () => {
244
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed"))).mockResolvedValue((0, _neverthrow.ok)({
245
+ result: "success"
246
+ }));
247
+ await (0, _api.executeRunApiCLI)({
248
+ apiName: "testApi",
249
+ inputData: {},
250
+ retries: 10
251
+ });
252
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(2);
253
+ });
254
+ (0, _vitest.it)("validates auth session before each attempt if provided", async () => {
255
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValueOnce((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed"))).mockResolvedValue((0, _neverthrow.ok)({
256
+ result: "success"
257
+ }));
258
+ await (0, _api.executeRunApiCLI)({
259
+ apiName: "testApi",
260
+ inputData: {},
261
+ authSession: {
262
+ id: "authSessionId",
263
+ autoRecreate: false,
264
+ checkRetries: 1,
265
+ createRetries: 2
266
+ },
267
+ retries: 10
268
+ });
269
+ (0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toBeCalledTimes(2);
270
+ (0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toHaveBeenCalledWith(_vitest.expect.objectContaining({
271
+ id: "authSessionId",
272
+ autoRecreate: false,
273
+ checkRetries: 1,
274
+ createRetries: 2
275
+ }));
276
+ });
277
+ (0, _vitest.it)("doesn't validate auth session if not provided", async () => {
278
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
279
+ result: "success"
280
+ }));
281
+ await (0, _api.executeRunApiCLI)({
282
+ apiName: "testApi",
283
+ inputData: {},
284
+ retries: 1
285
+ });
286
+ (0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).not.toHaveBeenCalled();
287
+ });
288
+ (0, _vitest.it)("fails if auth session is provided but not valid", async () => {
289
+ _vitest.vi.mocked(_authSession.executeRunValidateAuthSessionCLI).mockRejectedValue(new _helpers.CLIError("Auth session validation failed"));
290
+ await (0, _vitest.expect)((0, _api.executeRunApiCLI)({
291
+ apiName: "testApi",
292
+ inputData: {},
293
+ authSession: {
294
+ id: "authSessionId",
295
+ autoRecreate: false,
296
+ checkRetries: 1,
297
+ createRetries: 2
298
+ },
299
+ retries: 10
300
+ })).rejects.toThrow("Auth session validation failed");
301
+ (0, _vitest.expect)(_authSession.executeRunValidateAuthSessionCLI).toHaveBeenCalledWith(_vitest.expect.objectContaining({
302
+ id: "authSessionId",
303
+ autoRecreate: false,
304
+ checkRetries: 1,
305
+ createRetries: 2
306
+ }));
307
+ (0, _vitest.expect)(_runApi.runApi).not.toHaveBeenCalled();
308
+ });
309
+ (0, _vitest.it)("writes result to file if outputFile is provided", async () => {
310
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
311
+ result: "result",
312
+ extendedPayloads: "extendedPayloads"
313
+ }));
314
+ await (0, _api.executeRunApiCLI)({
315
+ apiName: "testApi",
316
+ inputData: {},
317
+ outputFile: "output.json",
318
+ retries: 1
319
+ });
320
+ (0, _vitest.expect)(_fsExtra.writeJSON).toHaveBeenCalledWith("output.json", {
321
+ result: "result",
322
+ extendedPayloads: "extendedPayloads"
323
+ }, _vitest.expect.anything());
324
+ });
325
+ (0, _vitest.it)("asserts API file exists", async () => {
326
+ await (0, _api.executeRunApiCLI)({
327
+ apiName: "testApi",
328
+ inputData: {},
329
+ retries: 1
330
+ });
331
+ (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("api", "testApi");
332
+ });
333
+ });
334
+ (0, _vitest.describe)("executeAttemptApiCLI", () => {
335
+ (0, _vitest.it)("enables tracing correctly", async () => {
336
+ await (0, _api.executeAttemptApiCLI)({
337
+ apiName: "testApi",
338
+ inputData: {},
339
+ trace: false
340
+ });
341
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
342
+ tracing: {
343
+ enabled: false
344
+ }
345
+ }));
346
+ _vitest.vi.mocked(_runApi.runApi).mockClear();
347
+ await (0, _api.executeAttemptApiCLI)({
348
+ apiName: "testApi",
349
+ inputData: {},
350
+ trace: true
351
+ });
352
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledWith(_vitest.expect.objectContaining({
353
+ tracing: _vitest.expect.objectContaining({
354
+ enabled: true
355
+ })
356
+ }));
357
+ });
358
+ (0, _vitest.it)("calls attemptApi once", async () => {
359
+ await (0, _api.executeAttemptApiCLI)({
360
+ apiName: "testApi",
361
+ inputData: {},
362
+ retries: 3
363
+ });
364
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
365
+ _vitest.vi.mocked(_runApi.runApi).mockReset();
366
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.err)(new _runApi.AutomationError("runApi failed")));
367
+ await (0, _vitest.expect)((0, _api.executeAttemptApiCLI)({
368
+ apiName: "testApi",
369
+ inputData: {}
370
+ })).rejects.toThrow(_runApi.AutomationError);
371
+ (0, _vitest.expect)(_runApi.runApi).toHaveBeenCalledTimes(1);
372
+ });
373
+ (0, _vitest.it)("writes result to file if outputFile is provided", async () => {
374
+ _vitest.vi.mocked(_runApi.runApi).mockResolvedValue((0, _neverthrow.ok)({
375
+ result: "result",
376
+ extendedPayloads: "extendedPayloads"
377
+ }));
378
+ await (0, _api.executeAttemptApiCLI)({
379
+ apiName: "testApi",
380
+ inputData: {},
381
+ outputFile: "output.json"
382
+ });
383
+ (0, _vitest.expect)(_fsExtra.writeJSON).toHaveBeenCalledWith("output.json", {
384
+ result: "result",
385
+ extendedPayloads: "extendedPayloads"
386
+ }, _vitest.expect.anything());
387
+ });
388
+ (0, _vitest.it)("asserts API file exists", async () => {
389
+ await (0, _api.executeRunApiCLI)({
390
+ apiName: "testApi",
391
+ inputData: {},
392
+ retries: 1
393
+ });
394
+ (0, _vitest.expect)(_helpers.assertApiFileExists).toHaveBeenCalledWith("api", "testApi");
395
+ });
396
+ });
397
+ });