@speedkit/cli 4.50.5 → 4.51.0-run-control.1

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 (406) hide show
  1. package/README.md +1369 -10
  2. package/dist/base/run-control-command.d.ts +15 -0
  3. package/dist/base/run-control-command.js +20 -0
  4. package/dist/build-info.json +6 -0
  5. package/dist/commands/diff.d.ts +6 -1
  6. package/dist/commands/diff.js +9 -3
  7. package/dist/commands/onboarding/browser/click.d.ts +75 -0
  8. package/dist/commands/onboarding/browser/click.js +19 -0
  9. package/dist/commands/onboarding/browser/emulate.d.ts +93 -0
  10. package/dist/commands/onboarding/browser/emulate.js +23 -0
  11. package/dist/commands/onboarding/browser/navigate.d.ts +67 -0
  12. package/dist/commands/onboarding/browser/navigate.js +18 -0
  13. package/dist/commands/onboarding/browser/panel.d.ts +63 -0
  14. package/dist/commands/onboarding/browser/panel.js +12 -0
  15. package/dist/commands/onboarding/browser/reinstall-sw.d.ts +63 -0
  16. package/dist/commands/onboarding/browser/reinstall-sw.js +14 -0
  17. package/dist/commands/onboarding/browser/reset.d.ts +71 -0
  18. package/dist/commands/onboarding/browser/reset.js +18 -0
  19. package/dist/commands/onboarding/browser/screenshot.d.ts +77 -0
  20. package/dist/commands/onboarding/browser/screenshot.js +19 -0
  21. package/dist/commands/onboarding/browser/state.d.ts +63 -0
  22. package/dist/commands/onboarding/browser/state.js +12 -0
  23. package/dist/commands/onboarding/browser/tabs.d.ts +58 -0
  24. package/dist/commands/onboarding/browser/tabs.js +16 -0
  25. package/dist/commands/onboarding/cache/clear.d.ts +58 -0
  26. package/dist/commands/onboarding/cache/clear.js +12 -0
  27. package/dist/commands/onboarding/cache/errors.d.ts +58 -0
  28. package/dist/commands/onboarding/cache/errors.js +12 -0
  29. package/dist/commands/onboarding/cache/evict.d.ts +62 -0
  30. package/dist/commands/onboarding/cache/evict.js +15 -0
  31. package/dist/commands/onboarding/cache/get.d.ts +85 -0
  32. package/dist/commands/onboarding/cache/get.js +17 -0
  33. package/dist/commands/onboarding/cache/list.d.ts +58 -0
  34. package/dist/commands/onboarding/cache/list.js +15 -0
  35. package/dist/commands/onboarding/cache/prewarm.d.ts +73 -0
  36. package/dist/commands/onboarding/cache/prewarm.js +20 -0
  37. package/dist/commands/onboarding/cache/refresh.d.ts +62 -0
  38. package/dist/commands/onboarding/cache/refresh.js +18 -0
  39. package/dist/commands/onboarding/cdp.d.ts +81 -0
  40. package/dist/commands/onboarding/cdp.js +18 -0
  41. package/dist/commands/onboarding/debug/arm.d.ts +77 -0
  42. package/dist/commands/onboarding/debug/arm.js +18 -0
  43. package/dist/commands/onboarding/debug/await.d.ts +71 -0
  44. package/dist/commands/onboarding/debug/await.js +18 -0
  45. package/dist/commands/onboarding/debug/disarm.d.ts +63 -0
  46. package/dist/commands/onboarding/debug/disarm.js +12 -0
  47. package/dist/commands/onboarding/debug/eval.d.ts +75 -0
  48. package/dist/commands/onboarding/debug/eval.js +16 -0
  49. package/dist/commands/onboarding/debug/release.d.ts +63 -0
  50. package/dist/commands/onboarding/debug/release.js +12 -0
  51. package/dist/commands/onboarding/debug/resume.d.ts +63 -0
  52. package/dist/commands/onboarding/debug/resume.js +12 -0
  53. package/dist/commands/onboarding/debug/status.d.ts +63 -0
  54. package/dist/commands/onboarding/debug/status.js +12 -0
  55. package/dist/commands/onboarding/debug/step.d.ts +67 -0
  56. package/dist/commands/onboarding/debug/step.js +15 -0
  57. package/dist/commands/onboarding/files/list.d.ts +58 -0
  58. package/dist/commands/onboarding/files/list.js +12 -0
  59. package/dist/commands/onboarding/files/read.d.ts +73 -0
  60. package/dist/commands/onboarding/files/read.js +16 -0
  61. package/dist/commands/onboarding/files/rebuild.d.ts +63 -0
  62. package/dist/commands/onboarding/files/rebuild.js +18 -0
  63. package/dist/commands/onboarding/files/validate.d.ts +58 -0
  64. package/dist/commands/onboarding/files/validate.js +12 -0
  65. package/dist/commands/onboarding/fouc.d.ts +77 -0
  66. package/dist/commands/onboarding/fouc.js +16 -0
  67. package/dist/commands/onboarding/inject/add.d.ts +89 -0
  68. package/dist/commands/onboarding/inject/add.js +17 -0
  69. package/dist/commands/onboarding/inject/clear.d.ts +63 -0
  70. package/dist/commands/onboarding/inject/clear.js +12 -0
  71. package/dist/commands/onboarding/inject/list.d.ts +63 -0
  72. package/dist/commands/onboarding/inject/list.js +12 -0
  73. package/dist/commands/onboarding/inject/read.d.ts +75 -0
  74. package/dist/commands/onboarding/inject/read.js +18 -0
  75. package/dist/commands/onboarding/inject/recipes.d.ts +63 -0
  76. package/dist/commands/onboarding/inject/recipes.js +12 -0
  77. package/dist/commands/onboarding/inject/remove.d.ts +67 -0
  78. package/dist/commands/onboarding/inject/remove.js +15 -0
  79. package/dist/commands/onboarding/list.d.ts +13 -0
  80. package/dist/commands/onboarding/list.js +12 -0
  81. package/dist/commands/onboarding/logs.d.ts +41 -0
  82. package/dist/commands/onboarding/logs.js +256 -0
  83. package/dist/commands/onboarding/navwalk.d.ts +95 -0
  84. package/dist/commands/onboarding/navwalk.js +19 -0
  85. package/dist/commands/onboarding/response.d.ts +67 -0
  86. package/dist/commands/onboarding/response.js +18 -0
  87. package/dist/commands/onboarding/rum/beacons.d.ts +75 -0
  88. package/dist/commands/onboarding/rum/beacons.js +16 -0
  89. package/dist/commands/onboarding/rum/get.d.ts +77 -0
  90. package/dist/commands/onboarding/rum/get.js +18 -0
  91. package/dist/commands/onboarding/rum/key.d.ts +67 -0
  92. package/dist/commands/onboarding/rum/key.js +13 -0
  93. package/dist/commands/onboarding/rum/previous.d.ts +63 -0
  94. package/dist/commands/onboarding/rum/previous.js +12 -0
  95. package/dist/commands/onboarding/status.d.ts +13 -0
  96. package/dist/commands/onboarding/status.js +17 -0
  97. package/dist/commands/onboarding/todo.d.ts +58 -0
  98. package/dist/commands/onboarding/todo.js +12 -0
  99. package/dist/commands/onboarding/viewport.d.ts +101 -0
  100. package/dist/commands/onboarding/viewport.js +18 -0
  101. package/dist/commands/onboarding/watch.d.ts +93 -0
  102. package/dist/commands/onboarding/watch.js +16 -0
  103. package/dist/commands/onboarding.d.ts +26 -0
  104. package/dist/commands/onboarding.js +220 -3
  105. package/dist/commands/origin-request.d.ts +4 -0
  106. package/dist/commands/origin-request.js +4 -0
  107. package/dist/commands/spec/onboarding.spec.d.ts +1 -0
  108. package/dist/commands/spec/onboarding.spec.js +127 -0
  109. package/dist/services/cli/build-info.d.ts +33 -0
  110. package/dist/services/cli/build-info.js +63 -0
  111. package/dist/services/cli/cli-environment-factory.d.ts +3 -0
  112. package/dist/services/cli/cli-environment-factory.js +1 -0
  113. package/dist/services/cli/cli-service-build-context.d.ts +3 -0
  114. package/dist/services/cli/cli-service-factory.js +1 -1
  115. package/dist/services/cli/cli-service-model.d.ts +29 -10
  116. package/dist/services/cli/cli-service.d.ts +60 -11
  117. package/dist/services/cli/cli-service.js +196 -32
  118. package/dist/services/cli/index.d.ts +2 -0
  119. package/dist/services/cli/index.js +2 -0
  120. package/dist/services/cli/sink.d.ts +47 -0
  121. package/dist/services/cli/sink.js +31 -0
  122. package/dist/services/cli/spec/build-identity.spec.d.ts +1 -0
  123. package/dist/services/cli/spec/build-identity.spec.js +85 -0
  124. package/dist/services/cli/spec/build-info.spec.d.ts +1 -0
  125. package/dist/services/cli/spec/build-info.spec.js +10 -0
  126. package/dist/services/cli/spec/cli-service-log.spec.d.ts +1 -0
  127. package/dist/services/cli/spec/cli-service-log.spec.js +133 -0
  128. package/dist/services/cli/spec/cli-service.spec.js +113 -50
  129. package/dist/services/cli/spec/memory-cli.d.ts +9 -0
  130. package/dist/services/cli/spec/memory-cli.js +9 -0
  131. package/dist/services/diff/config-at-ref.d.ts +20 -0
  132. package/dist/services/diff/config-at-ref.js +33 -0
  133. package/dist/services/diff/diff-service-build-context.d.ts +8 -0
  134. package/dist/services/diff/diff-service-build-context.js +40 -1
  135. package/dist/services/diff/diff-service-factory.d.ts +2 -0
  136. package/dist/services/diff/diff-service-factory.js +48 -20
  137. package/dist/services/diff/diff-service.d.ts +11 -0
  138. package/dist/services/diff/diff-service.js +37 -11
  139. package/dist/services/diff/page-source.d.ts +12 -0
  140. package/dist/services/diff/page-source.js +16 -11
  141. package/dist/services/diff/sinks/tool-diff-sink.d.ts +3 -2
  142. package/dist/services/diff/sinks/tool-diff-sink.js +3 -2
  143. package/dist/services/diff/spec/config-at-ref.spec.d.ts +1 -0
  144. package/dist/services/diff/spec/config-at-ref.spec.js +46 -0
  145. package/dist/services/diff/spec/diff-service-build-context.spec.js +19 -0
  146. package/dist/services/diff/spec/diff-service.spec.js +95 -0
  147. package/dist/services/git/git-repository.d.ts +2 -0
  148. package/dist/services/git/git-repository.js +6 -0
  149. package/dist/services/integration-api/customer-config-flags.js +1 -0
  150. package/dist/services/onboarding/browser/baqend-response.d.ts +17 -1
  151. package/dist/services/onboarding/browser/baqend-response.js +23 -0
  152. package/dist/services/onboarding/browser/console-log.d.ts +9 -0
  153. package/dist/services/onboarding/browser/console-log.js +27 -0
  154. package/dist/services/onboarding/browser/executable/executable-validator.js +4 -2
  155. package/dist/services/onboarding/browser/extension/extension-bridge.js +5 -3
  156. package/dist/services/onboarding/browser/extension/extension-downloader.js +17 -8
  157. package/dist/services/onboarding/browser/extension/extension-validator.js +9 -4
  158. package/dist/services/onboarding/control/body-inspect.d.ts +24 -0
  159. package/dist/services/onboarding/control/body-inspect.js +106 -0
  160. package/dist/services/onboarding/control/browser-session.d.ts +521 -0
  161. package/dist/services/onboarding/control/browser-session.js +1273 -0
  162. package/dist/services/onboarding/control/config-validation.d.ts +17 -0
  163. package/dist/services/onboarding/control/config-validation.js +46 -0
  164. package/dist/services/onboarding/control/control-protocol.d.ts +1390 -0
  165. package/dist/services/onboarding/control/control-protocol.js +69 -0
  166. package/dist/services/onboarding/control/control-server.d.ts +284 -0
  167. package/dist/services/onboarding/control/control-server.js +1609 -0
  168. package/dist/services/onboarding/control/debug-session.d.ts +190 -0
  169. package/dist/services/onboarding/control/debug-session.js +801 -0
  170. package/dist/services/onboarding/control/fouc.d.ts +23 -0
  171. package/dist/services/onboarding/control/fouc.js +151 -0
  172. package/dist/services/onboarding/control/index.d.ts +4 -0
  173. package/dist/services/onboarding/control/index.js +4 -0
  174. package/dist/services/onboarding/control/navwalk.d.ts +65 -0
  175. package/dist/services/onboarding/control/navwalk.js +248 -0
  176. package/dist/services/onboarding/control/preload-registry.d.ts +150 -0
  177. package/dist/services/onboarding/control/preload-registry.js +829 -0
  178. package/dist/services/onboarding/control/response-explainer.d.ts +24 -0
  179. package/dist/services/onboarding/control/response-explainer.js +257 -0
  180. package/dist/services/onboarding/control/rum.d.ts +8 -0
  181. package/dist/services/onboarding/control/rum.js +220 -0
  182. package/dist/services/onboarding/control/service-worker-tracker.d.ts +68 -0
  183. package/dist/services/onboarding/control/service-worker-tracker.js +119 -0
  184. package/dist/services/onboarding/control/viewport.d.ts +45 -0
  185. package/dist/services/onboarding/control/viewport.js +344 -0
  186. package/dist/services/onboarding/control/watch.d.ts +26 -0
  187. package/dist/services/onboarding/control/watch.js +149 -0
  188. package/dist/services/onboarding/dashboard/diff-against-current-page.js +3 -1
  189. package/dist/services/onboarding/dashboard/index.js +7 -2
  190. package/dist/services/onboarding/fetch-event-handler.d.ts +24 -5
  191. package/dist/services/onboarding/fetch-event-handler.js +94 -32
  192. package/dist/services/onboarding/fetch-events/speed-kit-install-js.js +11 -2
  193. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.d.ts +14 -0
  194. package/dist/services/onboarding/fetch-events/speed-kit-rum-pi-request.js +30 -0
  195. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.d.ts +13 -0
  196. package/dist/services/onboarding/fetch-events/speed-kit-service-worker-js.js +28 -1
  197. package/dist/services/onboarding/file-events/file-watcher.d.ts +42 -1
  198. package/dist/services/onboarding/file-events/file-watcher.js +117 -12
  199. package/dist/services/onboarding/onboarding-model.d.ts +30 -0
  200. package/dist/services/onboarding/onboarding-model.js +10 -0
  201. package/dist/services/onboarding/onboarding-service-build-context.d.ts +4 -0
  202. package/dist/services/onboarding/onboarding-service-build-context.js +6 -0
  203. package/dist/services/onboarding/onboarding-service-factory.d.ts +17 -1
  204. package/dist/services/onboarding/onboarding-service-factory.js +131 -17
  205. package/dist/services/onboarding/onboarding-service.d.ts +40 -1
  206. package/dist/services/onboarding/onboarding-service.js +135 -22
  207. package/dist/services/onboarding/request-cache/asset-key.d.ts +61 -0
  208. package/dist/services/onboarding/request-cache/asset-key.js +115 -0
  209. package/dist/services/onboarding/request-cache/cache.d.ts +62 -5
  210. package/dist/services/onboarding/request-cache/cache.js +128 -17
  211. package/dist/services/onboarding/spec/browser/console-log.spec.d.ts +1 -0
  212. package/dist/services/onboarding/spec/browser/console-log.spec.js +42 -0
  213. package/dist/services/onboarding/spec/control/browser-session.spec.d.ts +1 -0
  214. package/dist/services/onboarding/spec/control/browser-session.spec.js +526 -0
  215. package/dist/services/onboarding/spec/control/control-server.spec.d.ts +1 -0
  216. package/dist/services/onboarding/spec/control/control-server.spec.js +338 -0
  217. package/dist/services/onboarding/spec/control/debug-session.spec.d.ts +1 -0
  218. package/dist/services/onboarding/spec/control/debug-session.spec.js +693 -0
  219. package/dist/services/onboarding/spec/control/fakes.d.ts +31 -0
  220. package/dist/services/onboarding/spec/control/fakes.js +66 -0
  221. package/dist/services/onboarding/spec/control/fouc.spec.d.ts +1 -0
  222. package/dist/services/onboarding/spec/control/fouc.spec.js +167 -0
  223. package/dist/services/onboarding/spec/control/navwalk.spec.d.ts +1 -0
  224. package/dist/services/onboarding/spec/control/navwalk.spec.js +222 -0
  225. package/dist/services/onboarding/spec/control/preload-registry.spec.d.ts +1 -0
  226. package/dist/services/onboarding/spec/control/preload-registry.spec.js +432 -0
  227. package/dist/services/onboarding/spec/control/response-explainer.spec.d.ts +1 -0
  228. package/dist/services/onboarding/spec/control/response-explainer.spec.js +324 -0
  229. package/dist/services/onboarding/spec/control/rum.spec.d.ts +1 -0
  230. package/dist/services/onboarding/spec/control/rum.spec.js +222 -0
  231. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.d.ts +1 -0
  232. package/dist/services/onboarding/spec/control/service-worker-tracker.spec.js +193 -0
  233. package/dist/services/onboarding/spec/control/viewport.spec.d.ts +1 -0
  234. package/dist/services/onboarding/spec/control/viewport.spec.js +200 -0
  235. package/dist/services/onboarding/spec/control/watch.spec.d.ts +1 -0
  236. package/dist/services/onboarding/spec/control/watch.spec.js +172 -0
  237. package/dist/services/onboarding/spec/fetch-event-handler.spec.d.ts +1 -0
  238. package/dist/services/onboarding/spec/fetch-event-handler.spec.js +202 -0
  239. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.d.ts +1 -0
  240. package/dist/services/onboarding/spec/fetch-events/speed-kit-service-worker-js.spec.js +41 -0
  241. package/dist/services/onboarding/spec/onboarding-model.spec.js +37 -0
  242. package/dist/services/onboarding/spec/onboarding-service-factory.spec.js +1 -0
  243. package/dist/services/onboarding/spec/request-cache/cache.spec.d.ts +1 -0
  244. package/dist/services/onboarding/spec/request-cache/cache.spec.js +107 -0
  245. package/dist/services/onboarding/spec/todo-collector.spec.d.ts +1 -0
  246. package/dist/services/onboarding/spec/todo-collector.spec.js +136 -0
  247. package/dist/services/onboarding/todo-collector.d.ts +7 -2
  248. package/dist/services/onboarding/todo-collector.js +49 -12
  249. package/dist/services/onboarding/virtual-orestes-app/index.d.ts +34 -0
  250. package/dist/services/onboarding/virtual-orestes-app/index.js +82 -27
  251. package/dist/services/origin-request/asset-variations.d.ts +14 -0
  252. package/dist/services/origin-request/asset-variations.js +11 -4
  253. package/dist/services/origin-request/origin-fetcher.d.ts +7 -0
  254. package/dist/services/origin-request/origin-fetcher.js +43 -5
  255. package/dist/services/origin-request/origin-request-service-build-context.d.ts +17 -0
  256. package/dist/services/origin-request/origin-request-service-build-context.js +8 -0
  257. package/dist/services/origin-request/origin-request-service-factory.d.ts +0 -5
  258. package/dist/services/origin-request/origin-request-service-factory.js +2 -30
  259. package/dist/services/origin-request/origin-request-service.d.ts +121 -6
  260. package/dist/services/origin-request/origin-request-service.js +273 -49
  261. package/dist/services/origin-request/runtime-config-source.js +9 -4
  262. package/dist/services/origin-request/spec/asset-variations.spec.js +20 -0
  263. package/dist/services/origin-request/spec/origin-request-service.spec.js +329 -6
  264. package/dist/services/query-builder/rules/rule-match.d.ts +35 -0
  265. package/dist/services/query-builder/rules/rule-match.js +70 -0
  266. package/dist/services/query-builder/spec/rules/rule-match.spec.d.ts +1 -0
  267. package/dist/services/query-builder/spec/rules/rule-match.spec.js +121 -0
  268. package/dist/services/run-control/browser/run-browser-contexts.d.ts +541 -0
  269. package/dist/services/run-control/browser/run-browser-contexts.js +78 -0
  270. package/dist/services/run-control/browser/run-browser-service-factory.d.ts +5 -0
  271. package/dist/services/run-control/browser/run-browser-service-factory.js +7 -0
  272. package/dist/services/run-control/browser/run-browser-service.d.ts +64 -0
  273. package/dist/services/run-control/browser/run-browser-service.js +199 -0
  274. package/dist/services/run-control/cache/run-cache-contexts.d.ts +349 -0
  275. package/dist/services/run-control/cache/run-cache-contexts.js +51 -0
  276. package/dist/services/run-control/cache/run-cache-service-factory.d.ts +6 -0
  277. package/dist/services/run-control/cache/run-cache-service-factory.js +12 -0
  278. package/dist/services/run-control/cache/run-cache-service.d.ts +35 -0
  279. package/dist/services/run-control/cache/run-cache-service.js +151 -0
  280. package/dist/services/run-control/control-client.d.ts +36 -0
  281. package/dist/services/run-control/control-client.js +147 -0
  282. package/dist/services/run-control/debug/run-debug-contexts.d.ts +411 -0
  283. package/dist/services/run-control/debug/run-debug-contexts.js +44 -0
  284. package/dist/services/run-control/debug/run-debug-service-factory.d.ts +5 -0
  285. package/dist/services/run-control/debug/run-debug-service-factory.js +7 -0
  286. package/dist/services/run-control/debug/run-debug-service.d.ts +38 -0
  287. package/dist/services/run-control/debug/run-debug-service.js +161 -0
  288. package/dist/services/run-control/files/run-files-contexts.d.ts +238 -0
  289. package/dist/services/run-control/files/run-files-contexts.js +26 -0
  290. package/dist/services/run-control/files/run-files-service-factory.d.ts +5 -0
  291. package/dist/services/run-control/files/run-files-service-factory.js +7 -0
  292. package/dist/services/run-control/files/run-files-service.d.ts +29 -0
  293. package/dist/services/run-control/files/run-files-service.js +120 -0
  294. package/dist/services/run-control/index.d.ts +32 -0
  295. package/dist/services/run-control/index.js +31 -0
  296. package/dist/services/run-control/inject/run-inject-contexts.d.ts +319 -0
  297. package/dist/services/run-control/inject/run-inject-contexts.js +32 -0
  298. package/dist/services/run-control/inject/run-inject-service-factory.d.ts +5 -0
  299. package/dist/services/run-control/inject/run-inject-service-factory.js +7 -0
  300. package/dist/services/run-control/inject/run-inject-service.d.ts +31 -0
  301. package/dist/services/run-control/inject/run-inject-service.js +203 -0
  302. package/dist/services/run-control/live-run.d.ts +37 -0
  303. package/dist/services/run-control/live-run.js +56 -0
  304. package/dist/services/run-control/probe/run-probe-contexts.d.ts +333 -0
  305. package/dist/services/run-control/probe/run-probe-contexts.js +73 -0
  306. package/dist/services/run-control/probe/run-probe-service-factory.d.ts +5 -0
  307. package/dist/services/run-control/probe/run-probe-service-factory.js +7 -0
  308. package/dist/services/run-control/probe/run-probe-service.d.ts +54 -0
  309. package/dist/services/run-control/probe/run-probe-service.js +193 -0
  310. package/dist/services/run-control/rum/run-rum-contexts.d.ts +216 -0
  311. package/dist/services/run-control/rum/run-rum-contexts.js +34 -0
  312. package/dist/services/run-control/rum/run-rum-service-factory.d.ts +5 -0
  313. package/dist/services/run-control/rum/run-rum-service-factory.js +7 -0
  314. package/dist/services/run-control/rum/run-rum-service.d.ts +36 -0
  315. package/dist/services/run-control/rum/run-rum-service.js +122 -0
  316. package/dist/services/run-control/run-answer.d.ts +28 -0
  317. package/dist/services/run-control/run-answer.js +58 -0
  318. package/dist/services/run-control/run-control-context.d.ts +102 -0
  319. package/dist/services/run-control/run-control-context.js +36 -0
  320. package/dist/services/run-control/run-control-flags.d.ts +12 -0
  321. package/dist/services/run-control/run-control-flags.js +22 -0
  322. package/dist/services/run-control/run-control-model.d.ts +9 -0
  323. package/dist/services/run-control/run-control-model.js +1 -0
  324. package/dist/services/run-control/run-control-service-factory.d.ts +14 -0
  325. package/dist/services/run-control/run-control-service-factory.js +26 -0
  326. package/dist/services/run-control/session/run-session-contexts.d.ts +25 -0
  327. package/dist/services/run-control/session/run-session-contexts.js +20 -0
  328. package/dist/services/run-control/session/run-session-service-factory.d.ts +8 -0
  329. package/dist/services/run-control/session/run-session-service-factory.js +18 -0
  330. package/dist/services/run-control/session/run-session-service.d.ts +25 -0
  331. package/dist/services/run-control/session/run-session-service.js +95 -0
  332. package/dist/services/run-control/spec/browser/run-browser-service.spec.d.ts +1 -0
  333. package/dist/services/run-control/spec/browser/run-browser-service.spec.js +327 -0
  334. package/dist/services/run-control/spec/cache/run-cache-service.spec.d.ts +1 -0
  335. package/dist/services/run-control/spec/cache/run-cache-service.spec.js +454 -0
  336. package/dist/services/run-control/spec/debug/run-debug-service.spec.d.ts +1 -0
  337. package/dist/services/run-control/spec/debug/run-debug-service.spec.js +113 -0
  338. package/dist/services/run-control/spec/files/run-files-service.spec.d.ts +1 -0
  339. package/dist/services/run-control/spec/files/run-files-service.spec.js +234 -0
  340. package/dist/services/run-control/spec/inject/run-inject-service.spec.d.ts +1 -0
  341. package/dist/services/run-control/spec/inject/run-inject-service.spec.js +224 -0
  342. package/dist/services/run-control/spec/live-run-fixture.d.ts +32 -0
  343. package/dist/services/run-control/spec/live-run-fixture.js +109 -0
  344. package/dist/services/run-control/spec/probe/run-probe-service.spec.d.ts +1 -0
  345. package/dist/services/run-control/spec/probe/run-probe-service.spec.js +108 -0
  346. package/dist/services/run-control/spec/rum/run-rum-service.spec.d.ts +1 -0
  347. package/dist/services/run-control/spec/rum/run-rum-service.spec.js +47 -0
  348. package/dist/services/run-control/spec/run-answer.spec.d.ts +1 -0
  349. package/dist/services/run-control/spec/run-answer.spec.js +57 -0
  350. package/dist/services/run-control/spec/session/run-session-service.spec.d.ts +1 -0
  351. package/dist/services/run-control/spec/session/run-session-service.spec.js +101 -0
  352. package/dist/services/run-log/crash-mirror.d.ts +31 -0
  353. package/dist/services/run-log/crash-mirror.js +69 -0
  354. package/dist/services/run-log/index.d.ts +11 -0
  355. package/dist/services/run-log/index.js +11 -0
  356. package/dist/services/run-log/jsonl-appender.d.ts +46 -0
  357. package/dist/services/run-log/jsonl-appender.js +91 -0
  358. package/dist/services/run-log/log-event-model.d.ts +104 -0
  359. package/dist/services/run-log/log-event-model.js +56 -0
  360. package/dist/services/run-log/log-query-service-factory.d.ts +11 -0
  361. package/dist/services/run-log/log-query-service-factory.js +14 -0
  362. package/dist/services/run-log/log-query-service.d.ts +59 -0
  363. package/dist/services/run-log/log-query-service.js +111 -0
  364. package/dist/services/run-log/log-reader.d.ts +84 -0
  365. package/dist/services/run-log/log-reader.js +180 -0
  366. package/dist/services/run-log/log-summary.d.ts +72 -0
  367. package/dist/services/run-log/log-summary.js +208 -0
  368. package/dist/services/run-log/redaction.d.ts +34 -0
  369. package/dist/services/run-log/redaction.js +124 -0
  370. package/dist/services/run-log/request-log.d.ts +80 -0
  371. package/dist/services/run-log/request-log.js +69 -0
  372. package/dist/services/run-log/request-summary.d.ts +76 -0
  373. package/dist/services/run-log/request-summary.js +0 -0
  374. package/dist/services/run-log/run-log.d.ts +61 -0
  375. package/dist/services/run-log/run-log.js +102 -0
  376. package/dist/services/run-log/spec/log-query-service.spec.d.ts +1 -0
  377. package/dist/services/run-log/spec/log-query-service.spec.js +197 -0
  378. package/dist/services/run-log/spec/log-reader.spec.d.ts +1 -0
  379. package/dist/services/run-log/spec/log-reader.spec.js +109 -0
  380. package/dist/services/run-log/spec/log-summary.spec.d.ts +1 -0
  381. package/dist/services/run-log/spec/log-summary.spec.js +153 -0
  382. package/dist/services/run-log/spec/redaction.spec.d.ts +1 -0
  383. package/dist/services/run-log/spec/redaction.spec.js +61 -0
  384. package/dist/services/run-log/spec/request-log.spec.d.ts +1 -0
  385. package/dist/services/run-log/spec/request-log.spec.js +101 -0
  386. package/dist/services/run-log/spec/request-summary.spec.d.ts +1 -0
  387. package/dist/services/run-log/spec/request-summary.spec.js +171 -0
  388. package/dist/services/run-log/spec/run-log.spec.d.ts +1 -0
  389. package/dist/services/run-log/spec/run-log.spec.js +122 -0
  390. package/dist/services/run-registry/exit-classification.d.ts +39 -0
  391. package/dist/services/run-registry/exit-classification.js +42 -0
  392. package/dist/services/run-registry/index.d.ts +3 -0
  393. package/dist/services/run-registry/index.js +3 -0
  394. package/dist/services/run-registry/process-identity.d.ts +28 -0
  395. package/dist/services/run-registry/process-identity.js +80 -0
  396. package/dist/services/run-registry/run-registry-model.d.ts +128 -0
  397. package/dist/services/run-registry/run-registry-model.js +16 -0
  398. package/dist/services/run-registry/run-registry.d.ts +150 -0
  399. package/dist/services/run-registry/run-registry.js +409 -0
  400. package/dist/services/run-registry/spec/exit-classification.spec.d.ts +1 -0
  401. package/dist/services/run-registry/spec/exit-classification.spec.js +82 -0
  402. package/dist/services/run-registry/spec/run-registry.spec.d.ts +1 -0
  403. package/dist/services/run-registry/spec/run-registry.spec.js +509 -0
  404. package/dist/services/setup/os/tool-registry.js +2 -2
  405. package/oclif.manifest.json +3293 -272
  406. package/package.json +20 -2
@@ -1,12 +1,70 @@
1
1
  import { CliServiceInterface } from "../cli/index.js";
2
+ import { ConfigApiService } from "../config-api/index.js";
3
+ import { CustomerConfig } from "../integration-api/index.js";
2
4
  import { OriginRequestOptions } from "./origin-request-service-build-context.js";
3
- import { OriginFetcher } from "./origin-fetcher.js";
4
5
  import { ResolvedRequest } from "./asset-variations.js";
5
6
  /**
6
7
  * The headers as reported. Origin basic auth and the origin map's headers are sent, but their
7
8
  * values are not printed: the runtime config stores credentials there, such as a bypass token.
8
9
  */
9
10
  export declare function printable(headers: Record<string, string>, { originMapHeaders }: ResolvedRequest): Record<string, string>;
11
+ /** What the origin answered, and the request that was sent to get it. */
12
+ export interface OriginRequestResult {
13
+ outcome: "fetched";
14
+ variation: string;
15
+ /** Every variation the config defines, so a wrong guess is one call from right. */
16
+ variations: string[];
17
+ /** And the ones the server resolves regardless — a config often defines none. */
18
+ deviceDefaults: string[];
19
+ resolutionPath: "named" | "template";
20
+ appliedKeys: string[];
21
+ /** The `speedKit.originMap` entry the request was rewritten by, if any. */
22
+ originMapKey?: string;
23
+ requestUrl: string;
24
+ requestHeaders: Record<string, string>;
25
+ curl: string;
26
+ status: number;
27
+ statusText: string;
28
+ responseHeaders: Record<string, string>;
29
+ setCookie: string[];
30
+ body: string;
31
+ }
32
+ /**
33
+ * A reason no request was sent, as data rather than a printed line.
34
+ *
35
+ * Every one of these is a thing the caller can act on — log in, pass a file,
36
+ * pick a variation that exists — so each carries what the next attempt needs.
37
+ * Discriminated by a string: `strict` is off in this project, and a boolean
38
+ * discriminant does not narrow under it.
39
+ */
40
+ export type OriginRequestFailure = {
41
+ outcome: "config-unavailable";
42
+ message: string;
43
+ cause: string;
44
+ } | {
45
+ outcome: "unreadable-variations";
46
+ message: string;
47
+ file: string;
48
+ } | {
49
+ outcome: "unknown-variation";
50
+ message: string;
51
+ requested: string;
52
+ /** What the config defines. `*` is the wildcard and a template key is a regex. */
53
+ available: string[];
54
+ deviceDefaults: string[];
55
+ } | {
56
+ outcome: "bad-url";
57
+ message: string;
58
+ url: string;
59
+ base: string | null;
60
+ };
61
+ export type OriginRequestOutcome = OriginRequestResult | OriginRequestFailure;
62
+ /** The variations a customer's deployed config defines. */
63
+ export type VariationListOutcome = {
64
+ outcome: "variations";
65
+ variations: string[];
66
+ deviceDefaults: string[];
67
+ } | OriginRequestFailure;
10
68
  /**
11
69
  * Fetches a page from origin with exactly the headers Speed Kit's server would send for a cache
12
70
  * variation, then reports what the origin answered.
@@ -15,6 +73,10 @@ export declare function printable(headers: Record<string, string>, { originMapHe
15
73
  * — without waiting for a render or reading backend logs. The variations come from the app's
16
74
  * deployed runtime config, so the simulation follows production rather than a local file.
17
75
  *
76
+ * {@link run} renders for a terminal; {@link execute} returns the same work as data. The split
77
+ * keeps the failures typed: a failure a human reads as one line is an outcome a caller can branch
78
+ * on, and the tests read it that way.
79
+ *
18
80
  * Known deviations from the server, all deliberate:
19
81
  * - Revalidation headers (If-None-Match, If-Modified-Since) apply only when refreshing a cached
20
82
  * entry, so they are out of scope.
@@ -23,12 +85,65 @@ export declare function printable(headers: Record<string, string>, { originMapHe
23
85
  export declare class OriginRequestService {
24
86
  private readonly context;
25
87
  private readonly cli;
26
- /** Absent when the runtime config could not be used; the reason is reported. */
27
- private readonly fetcher;
88
+ /** Absent without a customer: there is no app to load a runtime config from. */
89
+ private readonly configApi;
90
+ private readonly customer?;
28
91
  constructor(context: OriginRequestOptions, cli: CliServiceInterface,
29
- /** Absent when the runtime config could not be used; the reason is reported. */
30
- fetcher: OriginFetcher | undefined);
31
- /** False when the request was not sent, because the runtime config could not be used. */
92
+ /** Absent without a customer: there is no app to load a runtime config from. */
93
+ configApi: ConfigApiService | undefined, customer?: CustomerConfig);
94
+ /** False when no request was sent, so the command can exit 2 like `sk diff`. */
32
95
  run(): Promise<boolean>;
96
+ /**
97
+ * The request, as data.
98
+ *
99
+ * A failure comes back as an outcome rather than a thrown error, because
100
+ * every one of them is an ordinary answer to "can this be simulated" — not
101
+ * logged in, no variations configured, a variation that does not exist. Only
102
+ * a genuinely unexpected error still throws.
103
+ */
104
+ execute(): Promise<OriginRequestOutcome>;
105
+ /**
106
+ * Which variations exist, without sending anything to the origin.
107
+ *
108
+ * The answer to "what do I pass as `variation`", which otherwise costs a
109
+ * request that is known in advance to be refused.
110
+ */
111
+ listVariations(): Promise<VariationListOutcome>;
112
+ /**
113
+ * Resolves the requested page against the customer's own origin, so a path is enough.
114
+ *
115
+ * Normalised the way the control socket does, and for the same reason: `new URL(input, base)`
116
+ * parses the base first and throws when it is not absolute — even when the input is — and
117
+ * `domain` is a bare host in every `config_customer` that has one. Blaming the input for a base
118
+ * that was wrong already cost one testing session.
119
+ *
120
+ * `domain` is optional, and plenty of configs carry only `origins` — so a single origin serves as
121
+ * the base too. Several origins and no `domain` used to be refused outright: picking the first
122
+ * would be a guess, and a page fetched from the wrong one of a customer's origins answers like a
123
+ * real result.
124
+ *
125
+ * {@link OriginRequestOptions.base} is the way out of that, and it wins over both — a caller that
126
+ * supplies one knows something the config does not. For a run that is the origin it is actually
127
+ * driving, which is why `sk onboarding response` accepted `/sale` on a twelve-origin customer while this
128
+ * refused it: the same question, two answers, for no reason the caller could see.
129
+ */
130
+ private absoluteUrl;
131
+ /**
132
+ * Reads `speedKit.variations` from the app's deployed runtime config, or from a local file when
133
+ * `--variations` is given.
134
+ */
135
+ private loadVariations;
136
+ /**
137
+ * `--raw` without a customer: no app, so no runtime config. An empty set is the point here —
138
+ * only Speed Kit's device defaults resolve, and no origin basic auth is sent — which is the
139
+ * request `sk diff --raw` makes for a site that has no config yet.
140
+ */
141
+ private noApp;
142
+ private fetchRuntimeConfig;
143
+ private readVariationsFile;
33
144
  private report;
145
+ /** `--select`, counted and sampled: "did the origin send it" in one number. */
146
+ private selected;
147
+ /** `--grep`, case-insensitive as its flag says, each line windowed. */
148
+ private grepped;
34
149
  }
@@ -1,6 +1,10 @@
1
- import { writeFile } from "node:fs/promises";
1
+ import { readFile, writeFile } from "node:fs/promises";
2
+ import { safe } from "../../helpers/safe.js";
2
3
  import { originFetch } from "../../helpers/origin-proxy.js";
3
- import { DEFAULT_TYPE, toCurl } from "./asset-variations.js";
4
+ import { grepText, selectInHtml } from "../onboarding/control/body-inspect.js";
5
+ import ApplicationError from "../error-handling/error/application-error.js";
6
+ import { OriginFetcher } from "./origin-fetcher.js";
7
+ import { DEFAULT_TYPE, DEVICE_DEFAULT_TYPES, toCurl, } from "./asset-variations.js";
4
8
  /** Standard request headers that carry no credentials, so an origin map value stays visible. */
5
9
  const PLAIN_HEADERS = new Set([
6
10
  "accept",
@@ -38,6 +42,10 @@ export function printable(headers, { originMapHeaders = [] }) {
38
42
  * — without waiting for a render or reading backend logs. The variations come from the app's
39
43
  * deployed runtime config, so the simulation follows production rather than a local file.
40
44
  *
45
+ * {@link run} renders for a terminal; {@link execute} returns the same work as data. The split
46
+ * keeps the failures typed: a failure a human reads as one line is an outcome a caller can branch
47
+ * on, and the tests read it that way.
48
+ *
41
49
  * Known deviations from the server, all deliberate:
42
50
  * - Revalidation headers (If-None-Match, If-Modified-Since) apply only when refreshing a cached
43
51
  * entry, so they are out of scope.
@@ -46,72 +54,288 @@ export function printable(headers, { originMapHeaders = [] }) {
46
54
  export class OriginRequestService {
47
55
  context;
48
56
  cli;
49
- fetcher;
57
+ configApi;
58
+ customer;
50
59
  constructor(context, cli,
51
- /** Absent when the runtime config could not be used; the reason is reported. */
52
- fetcher) {
60
+ /** Absent without a customer: there is no app to load a runtime config from. */
61
+ configApi, customer) {
53
62
  this.context = context;
54
63
  this.cli = cli;
55
- this.fetcher = fetcher;
64
+ this.configApi = configApi;
65
+ this.customer = customer;
56
66
  }
57
- /** False when the request was not sent, because the runtime config could not be used. */
67
+ /** False when no request was sent, so the command can exit 2 like `sk diff`. */
58
68
  async run() {
59
- // Without a runtime config every request would resolve to the bare defaults, so the report
60
- // would describe a request the server never sends. Stop instead of simulating something wrong.
61
- if (!this.fetcher)
69
+ const result = await this.execute();
70
+ if (result.outcome !== "fetched") {
71
+ // `--variations` is this command's flag, so the hint is added here rather
72
+ // than carried in the outcome, which names what happened and not what to
73
+ // type.
74
+ this.cli.writeError(result.outcome === "config-unavailable"
75
+ ? `${result.message} Or pass --variations <file> to simulate against a config you already have.`
76
+ : result.message);
62
77
  return false;
63
- const variation = this.context.variation ?? DEFAULT_TYPE;
64
- const { url, init, resolved } = this.fetcher.prepare(this.context.pageUrl, this.context.variation);
65
- const headers = printable(init.headers, resolved);
66
- const response = await originFetch(url, { ...init, redirect: "manual" });
67
- const body = await response.text();
68
- const setCookies = response.headers.getSetCookie?.() ?? [];
78
+ }
69
79
  if (this.context.bodyFile)
70
- await writeFile(this.context.bodyFile, body);
80
+ await writeFile(this.context.bodyFile, result.body);
71
81
  if (this.context.json) {
72
- this.cli.write(JSON.stringify({
73
- variation,
74
- resolutionPath: resolved.resolutionPath,
75
- appliedConfigs: resolved.appliedKeys,
76
- originMapKey: resolved.originMapKey ?? null,
77
- requestUrl: url,
78
- requestHeaders: headers,
79
- status: response.status,
80
- responseHeaders: Object.fromEntries(response.headers),
81
- setCookie: setCookies,
82
- bodyLength: body.length,
83
- }, null, 2));
82
+ // The payload channel, so `--json > file` gets the document and nothing
83
+ // the CLI had to say about it.
84
+ this.cli.pipe(`${JSON.stringify({
85
+ variation: result.variation,
86
+ resolutionPath: result.resolutionPath,
87
+ appliedConfigs: result.appliedKeys,
88
+ originMapKey: result.originMapKey ?? null,
89
+ requestUrl: result.requestUrl,
90
+ requestHeaders: result.requestHeaders,
91
+ status: result.status,
92
+ responseHeaders: result.responseHeaders,
93
+ setCookie: result.setCookie,
94
+ bodyLength: result.body.length,
95
+ bodyFile: this.context.bodyFile,
96
+ curl: result.curl,
97
+ select: this.selected(result.body),
98
+ grep: this.grepped(result.body),
99
+ }, null, 2)}\n`);
84
100
  return true;
85
101
  }
86
- this.report(variation, resolved, headers, response, setCookies, body);
102
+ this.report(result);
87
103
  return true;
88
104
  }
89
- report(variation, resolved, headers, response, setCookies, body) {
90
- this.cli.write(`variation ${variation}`);
91
- this.cli.write(`resolution ${resolved.resolutionPath} → applied: ${resolved.appliedKeys.join(" then ")}`);
92
- if (resolved.originMapKey)
93
- this.cli.write(`origin map ${resolved.originMapKey}`);
94
- this.cli.write(`request url ${resolved.url}`);
105
+ /**
106
+ * The request, as data.
107
+ *
108
+ * A failure comes back as an outcome rather than a thrown error, because
109
+ * every one of them is an ordinary answer to "can this be simulated" — not
110
+ * logged in, no variations configured, a variation that does not exist. Only
111
+ * a genuinely unexpected error still throws.
112
+ */
113
+ async execute() {
114
+ const loaded = await this.loadVariations();
115
+ // Without variations every request would resolve to the bare defaults, so the report would
116
+ // describe a request the server never sends. Stop instead of simulating something wrong.
117
+ if (loaded.outcome !== "loaded")
118
+ return loaded;
119
+ const variations = loaded.variations;
120
+ const variation = this.context.variation ?? DEFAULT_TYPE;
121
+ const pageUrl = this.absoluteUrl();
122
+ if (typeof pageUrl !== "string")
123
+ return pageUrl;
124
+ const fetcher = new OriginFetcher({
125
+ cli: this.cli,
126
+ config: {
127
+ variations,
128
+ authentications: loaded.authentications,
129
+ originMap: loaded.originMap,
130
+ },
131
+ host: this.context.host,
132
+ strict: true,
133
+ });
134
+ let prepared;
135
+ try {
136
+ prepared = fetcher.prepare(pageUrl, this.context.variation);
137
+ }
138
+ catch (error) {
139
+ // Strict, the fetcher throws only for a variation the config does not define.
140
+ if (error instanceof ApplicationError) {
141
+ return {
142
+ outcome: "unknown-variation",
143
+ message: error.message,
144
+ requested: variation,
145
+ available: Object.keys(variations),
146
+ deviceDefaults: DEVICE_DEFAULT_TYPES,
147
+ };
148
+ }
149
+ throw error;
150
+ }
151
+ const { url, init, resolved } = prepared;
152
+ const headers = printable(init.headers, resolved);
153
+ const response = await originFetch(url, { ...init, redirect: "manual" });
154
+ const body = await response.text();
155
+ return {
156
+ outcome: "fetched",
157
+ variation,
158
+ variations: Object.keys(variations),
159
+ deviceDefaults: DEVICE_DEFAULT_TYPES,
160
+ resolutionPath: resolved.resolutionPath,
161
+ appliedKeys: resolved.appliedKeys,
162
+ originMapKey: resolved.originMapKey,
163
+ requestUrl: url,
164
+ requestHeaders: headers,
165
+ curl: toCurl(url, headers),
166
+ status: response.status,
167
+ statusText: response.statusText,
168
+ responseHeaders: Object.fromEntries(response.headers),
169
+ setCookie: response.headers.getSetCookie?.() ?? [],
170
+ body,
171
+ };
172
+ }
173
+ /**
174
+ * Which variations exist, without sending anything to the origin.
175
+ *
176
+ * The answer to "what do I pass as `variation`", which otherwise costs a
177
+ * request that is known in advance to be refused.
178
+ */
179
+ async listVariations() {
180
+ const loaded = await this.loadVariations();
181
+ if (loaded.outcome !== "loaded")
182
+ return loaded;
183
+ return {
184
+ outcome: "variations",
185
+ variations: Object.keys(loaded.variations),
186
+ deviceDefaults: DEVICE_DEFAULT_TYPES,
187
+ };
188
+ }
189
+ /**
190
+ * Resolves the requested page against the customer's own origin, so a path is enough.
191
+ *
192
+ * Normalised the way the control socket does, and for the same reason: `new URL(input, base)`
193
+ * parses the base first and throws when it is not absolute — even when the input is — and
194
+ * `domain` is a bare host in every `config_customer` that has one. Blaming the input for a base
195
+ * that was wrong already cost one testing session.
196
+ *
197
+ * `domain` is optional, and plenty of configs carry only `origins` — so a single origin serves as
198
+ * the base too. Several origins and no `domain` used to be refused outright: picking the first
199
+ * would be a guess, and a page fetched from the wrong one of a customer's origins answers like a
200
+ * real result.
201
+ *
202
+ * {@link OriginRequestOptions.base} is the way out of that, and it wins over both — a caller that
203
+ * supplies one knows something the config does not. For a run that is the origin it is actually
204
+ * driving, which is why `sk onboarding response` accepted `/sale` on a twelve-origin customer while this
205
+ * refused it: the same question, two answers, for no reason the caller could see.
206
+ */
207
+ absoluteUrl() {
208
+ const origins = this.customer?.origins ?? [];
209
+ const named = this.context.base ||
210
+ this.customer?.domain ||
211
+ (origins.length === 1 && origins[0]);
212
+ const base = named && !/^https?:\/\//.test(named) ? `https://${named}` : named;
213
+ try {
214
+ return new URL(this.context.pageUrl, base || undefined).toString();
215
+ }
216
+ catch {
217
+ return {
218
+ outcome: "bad-url",
219
+ message: base
220
+ ? `"${this.context.pageUrl}" is not a url, absolute or relative to ${base}`
221
+ : origins.length > 1
222
+ ? `"${this.context.pageUrl}" is not an absolute url, and this config names no domain and ${origins.length} origins — say which: ${origins.join(", ")}`
223
+ : `"${this.context.pageUrl}" is not an absolute url, and no customer config was available to resolve it against`,
224
+ url: this.context.pageUrl,
225
+ base: base || null,
226
+ };
227
+ }
228
+ }
229
+ /**
230
+ * Reads `speedKit.variations` from the app's deployed runtime config, or from a local file when
231
+ * `--variations` is given.
232
+ */
233
+ async loadVariations() {
234
+ if (!this.configApi && !this.context.variationsFile)
235
+ return this.noApp();
236
+ const raw = this.context.variationsFile
237
+ ? await this.readVariationsFile(this.context.variationsFile)
238
+ : await this.fetchRuntimeConfig();
239
+ if (typeof raw !== "string")
240
+ return raw;
241
+ const parsed = JSON.parse(raw);
242
+ // An empty variation set still runs: device defaults resolve, originMap and authentications apply.
243
+ const variations = parsed.speedKit?.variations ?? parsed.variations ?? {};
244
+ const authentications = (parsed.speedKit ?? parsed).authentications ?? [];
245
+ const originMap = (parsed.speedKit ?? parsed).originMap ?? {};
246
+ // Narration, so never under --json: stdout is the document there.
247
+ if (!this.context.json && Object.keys(variations).length > 0) {
248
+ this.cli.writeSuccess(`variations: ${Object.keys(variations).join(", ")}`);
249
+ }
250
+ return { outcome: "loaded", variations, authentications, originMap };
251
+ }
252
+ /**
253
+ * `--raw` without a customer: no app, so no runtime config. An empty set is the point here —
254
+ * only Speed Kit's device defaults resolve, and no origin basic auth is sent — which is the
255
+ * request `sk diff --raw` makes for a site that has no config yet.
256
+ */
257
+ noApp() {
258
+ if (!this.context.json) {
259
+ this.cli.writeWarning("no customer: the request carries Speed Kit's device defaults only, no variation of an app");
260
+ }
261
+ return {
262
+ outcome: "loaded",
263
+ variations: {},
264
+ authentications: [],
265
+ originMap: {},
266
+ };
267
+ }
268
+ async fetchRuntimeConfig() {
269
+ this.cli.startAction("ORIGIN_REQUEST:FETCH:RUNTIME_CONFIG", "load variations from the app");
270
+ const serverConfig = await safe(this.configApi.getServerConfig());
271
+ if (serverConfig.success === false) {
272
+ this.cli.failAction("ORIGIN_REQUEST:FETCH:RUNTIME_CONFIG");
273
+ return {
274
+ outcome: "config-unavailable",
275
+ message: `unable to load the runtime config: ${serverConfig.error}. Run "sk login" and try again.`,
276
+ cause: String(serverConfig.error),
277
+ };
278
+ }
279
+ this.cli.successAction("ORIGIN_REQUEST:FETCH:RUNTIME_CONFIG");
280
+ return serverConfig.data;
281
+ }
282
+ async readVariationsFile(file) {
283
+ const content = await safe(readFile(file, "utf8"));
284
+ if (content.success === false) {
285
+ return {
286
+ outcome: "unreadable-variations",
287
+ message: `unable to read ${file}: ${content.error}`,
288
+ file,
289
+ };
290
+ }
291
+ this.cli.writeSuccess(`variations from ${file}`);
292
+ return content.data;
293
+ }
294
+ report(result) {
295
+ this.cli.write(`variation ${result.variation}`);
296
+ this.cli.write(`resolution ${result.resolutionPath} → applied: ${result.appliedKeys.join(" then ")}`);
297
+ if (result.originMapKey)
298
+ this.cli.write(`origin map ${result.originMapKey}`);
299
+ this.cli.write(`request url ${result.requestUrl}`);
95
300
  this.cli.write("request headers");
96
- for (const [key, value] of Object.entries(headers))
301
+ for (const [key, value] of Object.entries(result.requestHeaders))
97
302
  this.cli.write(` ${key}: ${value}`);
98
- this.cli.write(`\nstatus ${response.status} ${response.statusText}`);
99
- const location = response.headers.get("location");
303
+ this.cli.write(`\nstatus ${result.status} ${result.statusText}`);
304
+ const location = result.responseHeaders.location;
100
305
  if (location)
101
306
  this.cli.write(`location ${location}`);
102
- if (setCookies.length) {
307
+ if (result.setCookie.length) {
103
308
  this.cli.write("set-cookie");
104
- for (const cookie of setCookies)
309
+ for (const cookie of result.setCookie)
105
310
  this.cli.write(` ${cookie}`);
106
311
  }
107
- this.cli.write(`body ${body.length} bytes${this.context.bodyFile ? ` → ${this.context.bodyFile}` : ""}`);
108
- this.cli.write(`\nequivalent curl:\n${toCurl(resolved.url, headers)}`);
109
- if (this.context.grep) {
110
- const pattern = new RegExp(this.context.grep, "i");
111
- const hits = body.split("\n").filter((line) => pattern.test(line));
112
- this.cli.write(`\ngrep "${this.context.grep}" → ${hits.length} line(s)`);
113
- for (const line of hits.slice(0, 10))
114
- this.cli.write(` ${line.trim().slice(0, 300)}`);
312
+ this.cli.write(`body ${result.body.length} bytes${this.context.bodyFile ? ` → ${this.context.bodyFile}` : ""}`);
313
+ this.cli.write(`\nequivalent curl:\n${result.curl}`);
314
+ const selected = this.selected(result.body);
315
+ if (selected) {
316
+ this.cli.write(selected.error
317
+ ? `\nselect "${selected.selector}" → rejected: ${selected.error}`
318
+ : `\nselect "${selected.selector}" → ${selected.count} match(es)`);
319
+ for (const match of selected.matches)
320
+ this.cli.write(` ${match}`);
115
321
  }
322
+ const grepped = this.grepped(result.body);
323
+ if (grepped) {
324
+ this.cli.write(`\ngrep "${grepped.pattern}" → ${grepped.count} line(s)`);
325
+ for (const match of grepped.matches)
326
+ this.cli.write(` ${match.line}: ${match.text}`);
327
+ }
328
+ }
329
+ /** `--select`, counted and sampled: "did the origin send it" in one number. */
330
+ selected(body) {
331
+ return this.context.select
332
+ ? selectInHtml(body, this.context.select, this.context.maxMatches)
333
+ : undefined;
334
+ }
335
+ /** `--grep`, case-insensitive as its flag says, each line windowed. */
336
+ grepped(body) {
337
+ return this.context.grep
338
+ ? grepText(body, this.context.grep, this.context.maxMatches, "i")
339
+ : undefined;
116
340
  }
117
341
  }
@@ -35,17 +35,22 @@ export class RuntimeConfigSource {
35
35
  cli.writeError(`there is no app to load the runtime config from${fileFlag ? `; pass ${fileFlag} <file>` : ""}.`);
36
36
  return undefined;
37
37
  }
38
- cli.startAction("RUNTIME_CONFIG:FETCH", "get server config from app");
38
+ cli.startAction("RUNTIME_CONFIG:FETCH", "get server config from app", {
39
+ scope: "config",
40
+ });
39
41
  const serverConfig = await safe(configApi.getServerConfig());
40
42
  if (serverConfig.success === false) {
41
- cli.failAction("RUNTIME_CONFIG:FETCH");
43
+ cli.failAction("RUNTIME_CONFIG:FETCH", undefined, {
44
+ scope: "config",
45
+ data: { error: serverConfig.error },
46
+ });
42
47
  const alternative = fileFlag
43
48
  ? `, or pass ${fileFlag} <file> to use a config you already have`
44
49
  : "";
45
- cli.writeError(`unable to load the runtime config: ${serverConfig.error}. Run "sk login"${alternative}.`);
50
+ cli.writeError(`unable to load the runtime config: ${serverConfig.error}. Run "sk login"${alternative}.`, false, { scope: "config" });
46
51
  return undefined;
47
52
  }
48
- cli.successAction("RUNTIME_CONFIG:FETCH");
53
+ cli.successAction("RUNTIME_CONFIG:FETCH", undefined, { scope: "config" });
49
54
  return serverConfig.data;
50
55
  }
51
56
  async readFile(file) {
@@ -78,6 +78,26 @@ describe("asset variations", () => {
78
78
  }, "https://www.example.com/plp?page=2");
79
79
  expect(url).to.equal("https://proxy.example.com/?target=https%3A%2F%2Fwww.example.com%2Fplp%3Fpage%3D2&bq=1");
80
80
  });
81
+ it("calls a plain named key named, whatever it is called", () => {
82
+ // The path used to be inferred from the finished chain, where the only
83
+ // usable signal was whether a device default had been applied — so every
84
+ // key that was not `default`, `mobile` or `tablet` was announced as a
85
+ // regex match, for entries that carry no regex at all.
86
+ const custom = {
87
+ default: { headers: {} },
88
+ abtest_a: { headers: { cookie: "abtest=_a" } },
89
+ };
90
+ const named = resolveRequest(custom, "https://www.example.com/", "abtest_a");
91
+ expect(named.resolutionPath).to.equal("named");
92
+ expect(named.appliedKeys).to.deep.equal(["abtest_a"]);
93
+ expect(resolveRequest(custom, "https://www.example.com/", "default")
94
+ .resolutionPath).to.equal("named");
95
+ });
96
+ it("calls a device default named, since no template matched it", () => {
97
+ const { resolutionPath, appliedKeys } = resolveRequest({}, "https://www.example.com/", "mobile");
98
+ expect(resolutionPath).to.equal("named");
99
+ expect(appliedKeys).to.deep.equal(["device-default:mobile"]);
100
+ });
81
101
  it("resolves desktop as the default variation, with its configured entry", () => {
82
102
  const custom = { default: { headers: { "x-variant": "default" } } };
83
103
  expect(getVariations(custom, "desktop")).to.deep.equal(getVariations(custom, "default"));