@antelopejs/dms-api 0.1.7 → 0.2.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 (347) hide show
  1. package/README.md +99 -8
  2. package/dist/automation/get-api-health.js +4 -3
  3. package/dist/automation/get-api-health.js.map +1 -1
  4. package/dist/automation/route-unhealthy.js +2 -2
  5. package/dist/automation/route-unhealthy.js.map +1 -1
  6. package/dist/automation/scope.d.ts +0 -1
  7. package/dist/automation/scope.js +0 -7
  8. package/dist/automation/scope.js.map +1 -1
  9. package/dist/config.d.ts +4 -0
  10. package/dist/config.js +15 -9
  11. package/dist/config.js.map +1 -1
  12. package/dist/db/models/request_log.model.d.ts +37 -2
  13. package/dist/db/models/request_log.model.js +130 -35
  14. package/dist/db/models/request_log.model.js.map +1 -1
  15. package/dist/db/models/request_log.search.d.ts +5 -0
  16. package/dist/db/models/request_log.search.js +35 -0
  17. package/dist/db/models/request_log.search.js.map +1 -0
  18. package/dist/db/models/request_log.status.d.ts +5 -0
  19. package/dist/db/models/request_log.status.js +9 -0
  20. package/dist/db/models/request_log.status.js.map +1 -0
  21. package/dist/db/models/routes.model.d.ts +1 -0
  22. package/dist/db/models/routes.model.js +5 -1
  23. package/dist/db/models/routes.model.js.map +1 -1
  24. package/dist/db/models/routes_statistics.model.js +1 -1
  25. package/dist/db/models/routes_statistics.model.js.map +1 -1
  26. package/dist/db/tables/api_settings.table.d.ts +1 -0
  27. package/dist/db/tables/api_settings.table.js +4 -0
  28. package/dist/db/tables/api_settings.table.js.map +1 -1
  29. package/dist/db/tables/request_log.table.d.ts +18 -3
  30. package/dist/db/tables/request_log.table.js +34 -1
  31. package/dist/db/tables/request_log.table.js.map +1 -1
  32. package/dist/db/tables/routes.table.d.ts +1 -2
  33. package/dist/db/tables/routes.table.js.map +1 -1
  34. package/dist/db/tables/routes_statistics.table.d.ts +4 -3
  35. package/dist/db/tables/routes_statistics.table.js +5 -1
  36. package/dist/db/tables/routes_statistics.table.js.map +1 -1
  37. package/dist/index.d.ts +1 -1
  38. package/dist/index.js +9 -1
  39. package/dist/index.js.map +1 -1
  40. package/dist/memo.d.ts +5 -0
  41. package/dist/memo.js +36 -0
  42. package/dist/memo.js.map +1 -0
  43. package/dist/pages/blocks.d.ts +3 -0
  44. package/dist/pages/blocks.js +31 -0
  45. package/dist/pages/blocks.js.map +1 -0
  46. package/dist/pages/displays.d.ts +7 -0
  47. package/dist/pages/displays.js +23 -0
  48. package/dist/pages/displays.js.map +1 -0
  49. package/dist/pages/index.d.ts +5 -2
  50. package/dist/pages/index.js +5 -2
  51. package/dist/pages/index.js.map +1 -1
  52. package/dist/pages/logs.d.ts +18 -0
  53. package/dist/pages/logs.js +112 -0
  54. package/dist/pages/logs.js.map +1 -0
  55. package/dist/pages/module.d.ts +3 -0
  56. package/dist/pages/module.js +102 -6
  57. package/dist/pages/module.js.map +1 -1
  58. package/dist/pages/overview.d.ts +14 -0
  59. package/dist/pages/overview.js +215 -0
  60. package/dist/pages/overview.js.map +1 -0
  61. package/dist/pages/period.d.ts +9 -0
  62. package/dist/pages/period.js +24 -0
  63. package/dist/pages/period.js.map +1 -0
  64. package/dist/pages/request-table.d.ts +11 -0
  65. package/dist/pages/request-table.js +187 -0
  66. package/dist/pages/request-table.js.map +1 -0
  67. package/dist/pages/routes.d.ts +15 -0
  68. package/dist/pages/routes.js +269 -0
  69. package/dist/pages/routes.js.map +1 -0
  70. package/dist/pages/scope-chip.d.ts +9 -0
  71. package/dist/pages/scope-chip.js +28 -0
  72. package/dist/pages/scope-chip.js.map +1 -0
  73. package/dist/pages/{logs/page.d.ts → settings.d.ts} +3 -3
  74. package/dist/pages/settings.js +218 -0
  75. package/dist/pages/settings.js.map +1 -0
  76. package/dist/pages/toolbar.d.ts +9 -0
  77. package/dist/pages/toolbar.js +33 -0
  78. package/dist/pages/toolbar.js.map +1 -0
  79. package/dist/realtime.d.ts +2 -0
  80. package/dist/realtime.js +21 -0
  81. package/dist/realtime.js.map +1 -0
  82. package/dist/routes/index.d.ts +2 -2
  83. package/dist/routes/index.js +2 -2
  84. package/dist/routes/index.js.map +1 -1
  85. package/dist/routes/logs.d.ts +173 -2
  86. package/dist/routes/logs.js +177 -86
  87. package/dist/routes/logs.js.map +1 -1
  88. package/dist/routes/overview.d.ts +27 -0
  89. package/dist/routes/overview.js +131 -0
  90. package/dist/routes/overview.js.map +1 -0
  91. package/dist/routes/routes.d.ts +92 -28
  92. package/dist/routes/routes.js +165 -97
  93. package/dist/routes/routes.js.map +1 -1
  94. package/dist/routes/settings.d.ts +16 -11
  95. package/dist/routes/settings.js +62 -54
  96. package/dist/routes/settings.js.map +1 -1
  97. package/dist/routes/tester.d.ts +7 -0
  98. package/dist/routes/tester.js +34 -0
  99. package/dist/routes/tester.js.map +1 -0
  100. package/dist/services/activity.d.ts +49 -0
  101. package/dist/services/activity.js +207 -0
  102. package/dist/services/activity.js.map +1 -0
  103. package/dist/services/aggregate-cache.d.ts +3 -0
  104. package/dist/services/aggregate-cache.js +16 -0
  105. package/dist/services/aggregate-cache.js.map +1 -0
  106. package/dist/services/api-origin.d.ts +1 -0
  107. package/dist/services/api-origin.js +9 -0
  108. package/dist/services/api-origin.js.map +1 -0
  109. package/dist/services/attention.d.ts +45 -0
  110. package/dist/services/attention.js +203 -0
  111. package/dist/services/attention.js.map +1 -0
  112. package/dist/services/composed-text.d.ts +6 -0
  113. package/dist/services/composed-text.js +23 -0
  114. package/dist/services/composed-text.js.map +1 -0
  115. package/dist/services/health-rules.d.ts +49 -0
  116. package/dist/services/health-rules.js +233 -0
  117. package/dist/services/health-rules.js.map +1 -0
  118. package/dist/services/index.d.ts +1 -3
  119. package/dist/services/index.js +3 -3
  120. package/dist/services/index.js.map +1 -1
  121. package/dist/services/introspection/decorators.d.ts +14 -0
  122. package/dist/services/introspection/decorators.js +192 -0
  123. package/dist/services/introspection/decorators.js.map +1 -0
  124. package/dist/services/introspection/errors.js +4 -4
  125. package/dist/services/introspection/errors.js.map +1 -1
  126. package/dist/services/introspection/index.d.ts +6 -8
  127. package/dist/services/introspection/index.js +96 -32
  128. package/dist/services/introspection/index.js.map +1 -1
  129. package/dist/services/introspection/probe.d.ts +2 -1
  130. package/dist/services/introspection/probe.js +11 -0
  131. package/dist/services/introspection/probe.js.map +1 -1
  132. package/dist/services/links.d.ts +25 -0
  133. package/dist/services/links.js +72 -0
  134. package/dist/services/links.js.map +1 -0
  135. package/dist/services/live-feed.d.ts +6 -0
  136. package/dist/services/live-feed.js +18 -0
  137. package/dist/services/live-feed.js.map +1 -0
  138. package/dist/services/live.d.ts +16 -0
  139. package/dist/services/live.js +32 -0
  140. package/dist/services/live.js.map +1 -0
  141. package/dist/services/overview.d.ts +122 -0
  142. package/dist/services/overview.js +324 -0
  143. package/dist/services/overview.js.map +1 -0
  144. package/dist/services/period.d.ts +0 -9
  145. package/dist/services/period.js +5 -52
  146. package/dist/services/period.js.map +1 -1
  147. package/dist/services/request-log/access.d.ts +5 -0
  148. package/dist/services/request-log/access.js +21 -0
  149. package/dist/services/request-log/access.js.map +1 -0
  150. package/dist/services/request-log/capture.d.ts +30 -0
  151. package/dist/services/request-log/capture.js +216 -39
  152. package/dist/services/request-log/capture.js.map +1 -1
  153. package/dist/services/request-log/list.d.ts +36 -0
  154. package/dist/services/request-log/list.js +201 -0
  155. package/dist/services/request-log/list.js.map +1 -0
  156. package/dist/services/request-log/read.d.ts +15 -2
  157. package/dist/services/request-log/read.js +47 -4
  158. package/dist/services/request-log/read.js.map +1 -1
  159. package/dist/services/request-log/redaction.d.ts +16 -3
  160. package/dist/services/request-log/redaction.js +149 -27
  161. package/dist/services/request-log/redaction.js.map +1 -1
  162. package/dist/services/request-log/util.d.ts +10 -3
  163. package/dist/services/request-log/util.js +39 -22
  164. package/dist/services/request-log/util.js.map +1 -1
  165. package/dist/services/route-catalog.d.ts +62 -0
  166. package/dist/services/route-catalog.js +163 -0
  167. package/dist/services/route-catalog.js.map +1 -0
  168. package/dist/services/route-contract.d.ts +66 -0
  169. package/dist/services/route-contract.js +266 -0
  170. package/dist/services/route-contract.js.map +1 -0
  171. package/dist/services/route-health.d.ts +35 -0
  172. package/dist/services/route-health.js +179 -0
  173. package/dist/services/route-health.js.map +1 -0
  174. package/dist/services/route-statistics.d.ts +68 -0
  175. package/dist/services/route-statistics.js +277 -0
  176. package/dist/services/route-statistics.js.map +1 -0
  177. package/dist/services/routes-sync.d.ts +7 -3
  178. package/dist/services/routes-sync.js +96 -20
  179. package/dist/services/routes-sync.js.map +1 -1
  180. package/dist/services/scope.d.ts +0 -1
  181. package/dist/services/scope.js +4 -17
  182. package/dist/services/scope.js.map +1 -1
  183. package/dist/services/settings-form.d.ts +131 -0
  184. package/dist/services/settings-form.js +210 -0
  185. package/dist/services/settings-form.js.map +1 -0
  186. package/dist/services/settings.d.ts +2 -0
  187. package/dist/services/settings.js +5 -0
  188. package/dist/services/settings.js.map +1 -1
  189. package/dist/services/statistics-aggregate.d.ts +6 -41
  190. package/dist/services/statistics-aggregate.js +55 -280
  191. package/dist/services/statistics-aggregate.js.map +1 -1
  192. package/dist/services/statistics-utils.d.ts +7 -12
  193. package/dist/services/statistics-utils.js +36 -51
  194. package/dist/services/statistics-utils.js.map +1 -1
  195. package/dist/services/statistics-write.js +64 -22
  196. package/dist/services/statistics-write.js.map +1 -1
  197. package/dist/services/tester-source.d.ts +11 -0
  198. package/dist/services/tester-source.js +48 -0
  199. package/dist/services/tester-source.js.map +1 -0
  200. package/dist/services/traffic-samples.d.ts +18 -0
  201. package/dist/services/traffic-samples.js +134 -0
  202. package/dist/services/traffic-samples.js.map +1 -0
  203. package/dist/services/traffic.d.ts +43 -0
  204. package/dist/services/traffic.js +270 -0
  205. package/dist/services/traffic.js.map +1 -0
  206. package/dist/services/window.d.ts +48 -0
  207. package/dist/services/window.js +179 -0
  208. package/dist/services/window.js.map +1 -0
  209. package/dist/types/constants.d.ts +11 -20
  210. package/dist/types/constants.js +15 -25
  211. package/dist/types/constants.js.map +1 -1
  212. package/dist/types/index.d.ts +0 -1
  213. package/dist/types/index.js +0 -1
  214. package/dist/types/index.js.map +1 -1
  215. package/dist/types/statistics.d.ts +5 -3
  216. package/dist/types/statistics.js +5 -0
  217. package/dist/types/statistics.js.map +1 -1
  218. package/frontend-vue/app/components/blocks/BetaBadge.vue +20 -0
  219. package/frontend-vue/app/components/blocks/HealthHero.vue +708 -0
  220. package/frontend-vue/app/components/blocks/LiveTraffic.vue +356 -0
  221. package/frontend-vue/app/components/blocks/LogsEmptyState.vue +228 -0
  222. package/frontend-vue/app/components/blocks/LogsFilters.vue +279 -0
  223. package/frontend-vue/app/components/blocks/RequestDetail.vue +722 -0
  224. package/frontend-vue/app/components/blocks/RetentionInput.vue +227 -0
  225. package/frontend-vue/app/components/blocks/RouteDocumentation.vue +611 -0
  226. package/frontend-vue/app/components/blocks/RouteHeader.vue +320 -0
  227. package/frontend-vue/app/components/blocks/RouteTester.vue +1879 -0
  228. package/frontend-vue/app/components/blocks/RouteTree.vue +676 -0
  229. package/frontend-vue/app/components/blocks/ScopeChip.vue +89 -0
  230. package/frontend-vue/app/components/blocks/SettingNumberInput.vue +65 -0
  231. package/frontend-vue/app/components/blocks/SplitLayout.vue +41 -0
  232. package/frontend-vue/app/components/internal/ApiBody.vue +129 -0
  233. package/frontend-vue/app/components/internal/ApiJsonTree.vue +82 -0
  234. package/frontend-vue/app/components/internal/ApiKeyValues.vue +41 -0
  235. package/frontend-vue/app/components/internal/ApiMethodBadge.vue +19 -19
  236. package/frontend-vue/app/components/internal/ApiPath.vue +33 -0
  237. package/frontend-vue/app/components/internal/ApiStatusBadge.vue +20 -15
  238. package/frontend-vue/app/components/internal/ApiTesterBadge.vue +17 -0
  239. package/frontend-vue/app/composables/useApiOrigin.ts +19 -0
  240. package/frontend-vue/app/composables/useApiPeriod.ts +19 -0
  241. package/frontend-vue/app/composables/useApiResource.ts +92 -0
  242. package/frontend-vue/app/composables/useDateFormat.ts +23 -0
  243. package/frontend-vue/app/composables/useLiveMissedErrors.ts +33 -0
  244. package/frontend-vue/app/composables/useRouteDetail.ts +253 -0
  245. package/frontend-vue/app/composables/useRouteSelection.ts +43 -0
  246. package/frontend-vue/app/config/shortcuts-registry.ts +30 -0
  247. package/frontend-vue/app/plugins/displays.ts +92 -0
  248. package/frontend-vue/app/utils/format.ts +281 -0
  249. package/frontend-vue/app/utils/http.ts +127 -0
  250. package/frontend-vue/app/utils/logsQuery.ts +261 -0
  251. package/frontend-vue/app/utils/minuteHistogram.ts +116 -0
  252. package/frontend-vue/app/utils/requestDrawer.ts +257 -0
  253. package/frontend-vue/app/utils/routeExplorer.ts +206 -0
  254. package/frontend-vue/app/utils/search.ts +45 -0
  255. package/frontend-vue/app/utils/settingsForm.ts +119 -0
  256. package/frontend-vue/app/utils/snippets.ts +501 -0
  257. package/frontend-vue/app/utils/testerHistory.ts +354 -0
  258. package/frontend-vue/app/utils/testerRequest.ts +632 -11
  259. package/frontend-vue/dms.frontend.build.ts +7 -0
  260. package/frontend-vue/dms.frontend.ts +10 -3
  261. package/frontend-vue/i18n/locales/api-en-GB.json +866 -0
  262. package/frontend-vue/i18n/locales/api-fr-FR.json +866 -0
  263. package/frontend-vue/package.json +2 -6
  264. package/frontend-vue/pnpm-lock.yaml +97 -3375
  265. package/frontend-vue/tests/format.test.ts +180 -0
  266. package/frontend-vue/tests/http.test.ts +61 -0
  267. package/frontend-vue/tests/logsQuery.test.ts +255 -0
  268. package/frontend-vue/tests/minuteHistogram.test.ts +94 -0
  269. package/frontend-vue/tests/registration.test.ts +24 -7
  270. package/frontend-vue/tests/requestDrawer.test.ts +179 -0
  271. package/frontend-vue/tests/routeExplorer.test.ts +206 -0
  272. package/frontend-vue/tests/settingsForm.test.ts +155 -0
  273. package/frontend-vue/tests/snippets.test.ts +285 -0
  274. package/frontend-vue/tests/testerHistory.test.ts +295 -0
  275. package/frontend-vue/tests/testerRequest.test.ts +471 -76
  276. package/frontend-vue/tests/tooltipTriggers.test.ts +51 -0
  277. package/package.json +8 -8
  278. package/dist/middlewares/index.d.ts +0 -1
  279. package/dist/middlewares/index.js +0 -18
  280. package/dist/middlewares/index.js.map +0 -1
  281. package/dist/middlewares/request-log-capture.d.ts +0 -1
  282. package/dist/middlewares/request-log-capture.js +0 -6
  283. package/dist/middlewares/request-log-capture.js.map +0 -1
  284. package/dist/pages/all.d.ts +0 -4
  285. package/dist/pages/all.js +0 -21
  286. package/dist/pages/all.js.map +0 -1
  287. package/dist/pages/logs/page.js +0 -29
  288. package/dist/pages/logs/page.js.map +0 -1
  289. package/dist/pages/routes/page.d.ts +0 -9
  290. package/dist/pages/routes/page.js +0 -29
  291. package/dist/pages/routes/page.js.map +0 -1
  292. package/dist/pages/settings/form.d.ts +0 -3
  293. package/dist/pages/settings/form.js +0 -80
  294. package/dist/pages/settings/form.js.map +0 -1
  295. package/dist/pages/settings/page.d.ts +0 -9
  296. package/dist/pages/settings/page.js +0 -26
  297. package/dist/pages/settings/page.js.map +0 -1
  298. package/dist/pages/summary/page.d.ts +0 -9
  299. package/dist/pages/summary/page.js +0 -29
  300. package/dist/pages/summary/page.js.map +0 -1
  301. package/dist/routes/monitoring.d.ts +0 -17
  302. package/dist/routes/monitoring.js +0 -101
  303. package/dist/routes/monitoring.js.map +0 -1
  304. package/dist/routes/summary.d.ts +0 -32
  305. package/dist/routes/summary.js +0 -181
  306. package/dist/routes/summary.js.map +0 -1
  307. package/dist/services/request-log/index.d.ts +0 -3
  308. package/dist/services/request-log/index.js +0 -12
  309. package/dist/services/request-log/index.js.map +0 -1
  310. package/dist/services/statistics-read.d.ts +0 -4
  311. package/dist/services/statistics-read.js +0 -48
  312. package/dist/services/statistics-read.js.map +0 -1
  313. package/dist/services/tree.d.ts +0 -10
  314. package/dist/services/tree.js +0 -128
  315. package/dist/services/tree.js.map +0 -1
  316. package/dist/types/charts.d.ts +0 -9
  317. package/dist/types/charts.js +0 -3
  318. package/dist/types/charts.js.map +0 -1
  319. package/frontend-vue/app/components/ConfigurationView.vue +0 -187
  320. package/frontend-vue/app/components/DocumentationView.vue +0 -224
  321. package/frontend-vue/app/components/LogDetailDrawer.vue +0 -178
  322. package/frontend-vue/app/components/LogsView.vue +0 -347
  323. package/frontend-vue/app/components/RouteDetailTabs.vue +0 -179
  324. package/frontend-vue/app/components/RouteTree.vue +0 -196
  325. package/frontend-vue/app/components/RoutesView.vue +0 -79
  326. package/frontend-vue/app/components/StatsView.vue +0 -268
  327. package/frontend-vue/app/components/SummaryView.vue +0 -657
  328. package/frontend-vue/app/components/TesterPanel.vue +0 -499
  329. package/frontend-vue/app/components/internal/PeriodSelect.vue +0 -58
  330. package/frontend-vue/app/components/internal/RouteTreeNode.vue +0 -168
  331. package/frontend-vue/app/components/internal/StatusBreakdownBars.vue +0 -162
  332. package/frontend-vue/app/components/internal/StatusDonut.vue +0 -84
  333. package/frontend-vue/app/components/internal/UnitAreaChart.vue +0 -73
  334. package/frontend-vue/app/composables/useApiIntrospection.ts +0 -350
  335. package/frontend-vue/app/composables/useLogDetailDrawer.ts +0 -50
  336. package/frontend-vue/app/composables/useSelectedPeriod.ts +0 -107
  337. package/frontend-vue/app/composables/useStatsPeriods.ts +0 -139
  338. package/frontend-vue/app/custom-layouts/.gitkeep +0 -0
  339. package/frontend-vue/app/custom-pages/.gitkeep +0 -0
  340. package/frontend-vue/app/utils/httpMethod.ts +0 -49
  341. package/frontend-vue/app/utils/statusClass.ts +0 -49
  342. package/frontend-vue/i18n/locales/en-GB.json +0 -240
  343. package/frontend-vue/i18n/locales/fr-FR.json +0 -240
  344. package/frontend-vue/public/.gitkeep +0 -0
  345. package/frontend-vue/server/.gitkeep +0 -0
  346. package/frontend-vue/tests/periods.test.ts +0 -145
  347. package/frontend-vue/tests/persistence.test.ts +0 -45
@@ -1,3 +1,7 @@
1
+ import { prettyBody } from './format'
2
+ import { acceptsRequestBody } from './http'
3
+ import { REDACTED } from './snippets'
4
+
1
5
  /** Editable request data; stored session credentials stay on the server. */
2
6
  export interface TesterRequest {
3
7
  method: string
@@ -13,6 +17,390 @@ export interface TesterResponse {
13
17
  body: string
14
18
  }
15
19
 
20
+ /** One header, query parameter or form field of the tester, in order. */
21
+ export interface KeyValue {
22
+ name: string
23
+ value: string
24
+ }
25
+
26
+ /** How the body is written, and the content type it implies. */
27
+ export type BodyMode = 'json' | 'text' | 'form' | 'none'
28
+
29
+ /** Who the call is authenticated as, as the DMS proxy sends it. */
30
+ export type AuthMode = 'session' | 'manual' | 'none'
31
+
32
+ // --- The DMS proxy (`/api/_dms/tester`) ---
33
+ // dms-frontend `templates/vue/server/tester.mjs`: the limits it applies, and
34
+ // what it answers when it does not forward a call. Its error bodies hold one
35
+ // generic text per status, so the status, the elapsed time and the checks
36
+ // below are what tell the causes apart.
37
+
38
+ /** The proxy reads at most this much of the request (the JSON envelope). */
39
+ export const PROXY_BODY_LIMIT = 64 * 1024
40
+ /**
41
+ * The proxy fails (502) when the API answers more than this, and returns
42
+ * neither the status nor the start of the body: `limitedText()` throws
43
+ * "Backend response too large" past `RESPONSE_LIMIT` (tester.mjs, lines 5
44
+ * and 131-141), and `handleTester()` turns every error into the same 502
45
+ * "DMS tester request failed" (lines 220-226), as for an API down. Only the
46
+ * capture of the call tells the two apart. For the DMS: return the status,
47
+ * the headers and the first 64 KiB with a `truncated: true` flag instead of
48
+ * throwing, and give the 502 a `reason` (`too_large`, `timeout`,
49
+ * `unreachable`).
50
+ */
51
+ export const PROXY_RESPONSE_LIMIT = 64 * 1024
52
+ /** The proxy gives up on the API after this long, with a 502 as well. */
53
+ export const PROXY_TIMEOUT_MS = 30_000
54
+ /** Our own limit, should the proxy never answer. */
55
+ const CLIENT_TIMEOUT_MS = PROXY_TIMEOUT_MS + 5_000
56
+ /** A 502 this late is the proxy's timeout. */
57
+ const TIMEOUT_MARGIN_MS = 1_000
58
+
59
+ /**
60
+ * Marks of a call sent by the tester, which the module reads to keep it out
61
+ * of the statistics and to find it in the logs: its own request id, and a
62
+ * token the server signs (`GET /api/monitoring/tester/source`), so no client
63
+ * can declare its calls the Tester's. Not `x-dms-*`: the proxy drops those.
64
+ */
65
+ export const SOURCE_HEADER = 'x-antelopejs-api-source'
66
+ export const REQUEST_ID_HEADER = 'x-request-id'
67
+
68
+ /** Where the Tester asks for the token its next calls carry. */
69
+ export const TESTER_SOURCE_URL = '/api/monitoring/tester/source'
70
+
71
+ /** A token as the server signs it: `{ header, value, expiresAt }`. */
72
+ export interface TesterSourceToken {
73
+ header: string
74
+ value: string
75
+ expiresAt: string
76
+ }
77
+
78
+ /**
79
+ * A stand-in as long as a real token (`tester.<ms>.<base64url SHA-256>`), to
80
+ * size a request before one is asked for.
81
+ */
82
+ export const SIZE_PROBE_SOURCE = `tester.${'0'.repeat(13)}.${'0'.repeat(43)}`
83
+
84
+ /** A token is asked again this long before it expires. */
85
+ const SOURCE_RENEW_MARGIN_MS = 60_000
86
+
87
+ /**
88
+ * The tokens of the Tester's calls: one asked for, then reused until a
89
+ * minute before it expires.
90
+ */
91
+ export function createSourceTokens(
92
+ ask: () => Promise<TesterSourceToken>,
93
+ now: () => number = Date.now,
94
+ ): { get: () => Promise<TesterSourceToken> } {
95
+ let current: TesterSourceToken | null = null
96
+ return {
97
+ async get() {
98
+ if (
99
+ current &&
100
+ Date.parse(current.expiresAt) - SOURCE_RENEW_MARGIN_MS > now()
101
+ )
102
+ return current
103
+ current = await ask()
104
+ return current
105
+ },
106
+ }
107
+ }
108
+
109
+ const CONTENT_TYPES: Record<BodyMode, string | undefined> = {
110
+ json: 'application/json',
111
+ text: 'text/plain',
112
+ form: 'application/x-www-form-urlencoded',
113
+ none: undefined,
114
+ }
115
+
116
+ /** Why the tester could not get an answer from the API. */
117
+ export type TesterErrorCode =
118
+ /** The proxy refused the path, a header or the body (400). */
119
+ | 'invalid_input'
120
+ /** The request is over the proxy's 64 KiB (413). */
121
+ | 'body_too_large'
122
+ /** The console session is gone (401 from the proxy). */
123
+ | 'not_authenticated'
124
+ /** The tester is for owners only (403). */
125
+ | 'not_owner'
126
+ /** The call did not come from the console's origin (403). */
127
+ | 'cross_origin'
128
+ /** The proxy got nothing it could return (502): API down, or an answer over 64 KiB. */
129
+ | 'proxy_failed'
130
+ /** Seen in the logs after a 502: the API answered more than 64 KiB. */
131
+ | 'response_too_large'
132
+ /** No answer within 30 s. */
133
+ | 'timeout'
134
+ /** Cancelled before the answer. */
135
+ | 'aborted'
136
+ /** The console's server could not be reached. */
137
+ | 'network'
138
+ /** Any other answer of the proxy. */
139
+ | 'unexpected'
140
+
141
+ /** Codes after which the API was never called: nothing to find in the logs. */
142
+ const NOT_SENT: ReadonlySet<TesterErrorCode> = new Set([
143
+ 'invalid_input',
144
+ 'body_too_large',
145
+ 'not_authenticated',
146
+ 'not_owner',
147
+ 'cross_origin',
148
+ ])
149
+
150
+ export function neverSent(code: TesterErrorCode | undefined): boolean {
151
+ return code !== undefined && NOT_SENT.has(code)
152
+ }
153
+
154
+ export class TesterError extends Error {
155
+ readonly code: TesterErrorCode
156
+ readonly status?: number
157
+
158
+ constructor(code: TesterErrorCode, message: string, status?: number) {
159
+ super(message)
160
+ this.code = code
161
+ this.status = status
162
+ }
163
+ }
164
+
165
+ /** What the tester shows of one call, and keeps in its draft and history. */
166
+ export interface TesterResult {
167
+ status: number
168
+ /** Measured in the browser, through the proxy. */
169
+ durationMs: number
170
+ headers: Record<string, string>
171
+ body: string
172
+ /** Size of the whole answer, when `body` was cut to be stored. */
173
+ bodySize?: number
174
+ bodyTruncated?: boolean
175
+ error?: TesterErrorCode
176
+ message?: string
177
+ auth: AuthMode
178
+ /** Credential headers it was sent with, by name: their values are never kept. */
179
+ secrets?: string[]
180
+ /** The `x-request-id` it was sent with: its captured request. */
181
+ requestId?: string
182
+ /** What the module captured of it, once found: kept with the answer. */
183
+ captured?: CapturedSummary
184
+ /** Cancelled because the tester left its route: the API may have it. */
185
+ abandoned?: boolean
186
+ at: number
187
+ }
188
+
189
+ /** The capture of a call, as far as its answer line goes. */
190
+ export interface CapturedSummary {
191
+ id: string
192
+ status: number
193
+ responseTimeMs: number | null
194
+ /** Over the slow threshold of the module. */
195
+ slow: boolean
196
+ }
197
+
198
+ export function capturedSummary(log: CapturedRequest): CapturedSummary {
199
+ return {
200
+ id: log._id,
201
+ status: log.statusCode,
202
+ responseTimeMs: log.responseTimeMs,
203
+ slow:
204
+ log.responseTimeMs !== null &&
205
+ log.slowThresholdMs !== undefined &&
206
+ log.responseTimeMs >= log.slowThresholdMs,
207
+ }
208
+ }
209
+
210
+ // --- Building the request ---
211
+
212
+ /** The query of `rows`, every value kept: repeated names, empty values. */
213
+ export function queryString(rows: KeyValue[]): string {
214
+ const params = new URLSearchParams()
215
+ for (const { name, value } of rows) if (name) params.append(name, value)
216
+ return params.toString()
217
+ }
218
+
219
+ export function withQueryRows(path: string, rows: KeyValue[]): string {
220
+ const search = queryString(rows)
221
+ return search ? `${path}?${search}` : path
222
+ }
223
+
224
+ export function contentTypeFor(mode: BodyMode): string | undefined {
225
+ return CONTENT_TYPES[mode]
226
+ }
227
+
228
+ /** The mode a captured or typed content type is edited in. */
229
+ export function bodyModeFor(contentType: string | undefined): BodyMode {
230
+ const type = (contentType ?? '').toLowerCase()
231
+ if (type.includes('json')) return 'json'
232
+ if (type.includes('x-www-form-urlencoded')) return 'form'
233
+ return 'text'
234
+ }
235
+
236
+ /** The body as sent: nothing for `none` or an empty text. */
237
+ export function serializeBody(
238
+ mode: BodyMode,
239
+ text: string,
240
+ form: KeyValue[],
241
+ ): string | undefined {
242
+ if (mode === 'none') return undefined
243
+ if (mode === 'form') return queryString(form) || undefined
244
+ return text.trim() ? text : undefined
245
+ }
246
+
247
+ /** Why `text` is not JSON, or null. The tester warns, it never blocks. */
248
+ export function jsonProblem(text: string): string | null {
249
+ if (!text.trim()) return null
250
+ try {
251
+ JSON.parse(text)
252
+ return null
253
+ } catch (cause) {
254
+ return (cause as Error).message
255
+ }
256
+ }
257
+
258
+ /** `text` indented, or null when it is not JSON. */
259
+ export function formatJson(text: string): string | null {
260
+ try {
261
+ return JSON.stringify(JSON.parse(text), null, 2)
262
+ } catch {
263
+ return null
264
+ }
265
+ }
266
+
267
+ function headerKey(record: Record<string, string>, name: string) {
268
+ const lower = name.toLowerCase()
269
+ return Object.keys(record).find((key) => key.toLowerCase() === lower)
270
+ }
271
+
272
+ export function headerValue(
273
+ record: Record<string, string>,
274
+ name: string,
275
+ ): string | undefined {
276
+ const key = headerKey(record, name)
277
+ return key === undefined ? undefined : record[key]
278
+ }
279
+
280
+ /** Header layers merged in order, a later name replacing an earlier one whatever its case. */
281
+ export function mergeHeaders(
282
+ ...layers: Array<Record<string, string> | KeyValue[]>
283
+ ): Record<string, string> {
284
+ const merged: Record<string, string> = {}
285
+ for (const layer of layers) {
286
+ const entries = Array.isArray(layer)
287
+ ? layer.map((entry) => [entry.name, entry.value] as const)
288
+ : Object.entries(layer)
289
+ for (const [name, value] of entries) {
290
+ if (!name) continue
291
+ const existing = headerKey(merged, name)
292
+ if (existing !== undefined) delete merged[existing]
293
+ merged[name] = value
294
+ }
295
+ }
296
+ return merged
297
+ }
298
+
299
+ /**
300
+ * The credentials the proxy sends: a typed Authorization header wins over
301
+ * the session, which it then leaves out.
302
+ */
303
+ export function authModeOf(
304
+ headers: Record<string, string>,
305
+ useSession: boolean,
306
+ ): AuthMode {
307
+ if (headerValue(headers, 'authorization') !== undefined) return 'manual'
308
+ return useSession ? 'session' : 'none'
309
+ }
310
+
311
+ /** A version 4 UUID, outside secure contexts too. */
312
+ export function newRequestId(): string {
313
+ if (typeof crypto.randomUUID === 'function') return crypto.randomUUID()
314
+ const bytes = crypto.getRandomValues(new Uint8Array(16))
315
+ bytes[6] = (bytes[6] & 0x0f) | 0x40
316
+ bytes[8] = (bytes[8] & 0x3f) | 0x80
317
+ const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, '0'))
318
+ return [
319
+ hex.slice(0, 4),
320
+ hex.slice(4, 6),
321
+ hex.slice(6, 8),
322
+ hex.slice(8, 10),
323
+ hex.slice(10),
324
+ ]
325
+ .map((part) => part.join(''))
326
+ .join('-')
327
+ }
328
+
329
+ /**
330
+ * `headers` with the marks that tell the module this call is the tester's:
331
+ * its request id, and the signed token (`source`).
332
+ */
333
+ export function markedHeaders(
334
+ headers: Record<string, string>,
335
+ requestId: string,
336
+ source: string,
337
+ ): Record<string, string> {
338
+ return mergeHeaders(headers, {
339
+ [REQUEST_ID_HEADER]: requestId,
340
+ [SOURCE_HEADER]: source,
341
+ })
342
+ }
343
+
344
+ // --- What the proxy would refuse, said before sending ---
345
+
346
+ /** Characters a decoded path segment may not hold, as the proxy checks it. */
347
+ const UNSAFE_SEGMENT = /[\\/#\u0000-\u0020\u007f]/
348
+
349
+ export type TesterInputProblem =
350
+ | { code: 'path_value'; name: string }
351
+ | { code: 'header'; name: string }
352
+ | { code: 'body_too_large'; size: number }
353
+
354
+ function decodedFully(value: string): string | null {
355
+ let decoded = value
356
+ for (;;) {
357
+ let next: string
358
+ try {
359
+ next = decodeURIComponent(decoded)
360
+ } catch {
361
+ return null
362
+ }
363
+ if (next === decoded) return decoded
364
+ decoded = next
365
+ }
366
+ }
367
+
368
+ /** Size of what the proxy reads: the request and its path, as JSON. */
369
+ export function envelopeSize(path: string, request: TesterRequest): number {
370
+ return new TextEncoder().encode(JSON.stringify({ ...request, path })).length
371
+ }
372
+
373
+ /**
374
+ * The first thing the proxy would refuse in this request: a path value it
375
+ * reads as a separator (`/`, a space…), a header the platform rejects, or a
376
+ * request over 64 KiB. Null when it would forward it.
377
+ */
378
+ export function inputProblem(
379
+ pathValues: Record<string, string>,
380
+ path: string,
381
+ request: TesterRequest,
382
+ ): TesterInputProblem | null {
383
+ for (const [name, value] of Object.entries(pathValues)) {
384
+ if (!value) continue
385
+ const decoded = decodedFully(value)
386
+ if (decoded === null || ['.', '..'].includes(decoded))
387
+ return { code: 'path_value', name }
388
+ if (UNSAFE_SEGMENT.test(decoded)) return { code: 'path_value', name }
389
+ }
390
+ for (const [name, value] of Object.entries(request.headers)) {
391
+ try {
392
+ new Headers([[name, value]])
393
+ } catch {
394
+ return { code: 'header', name }
395
+ }
396
+ }
397
+ const size = envelopeSize(path, request)
398
+ if (size > PROXY_BODY_LIMIT) return { code: 'body_too_large', size }
399
+ return null
400
+ }
401
+
402
+ // --- Sending ---
403
+
16
404
  function resolvePath(target: string, origin: string): string {
17
405
  const url = new URL(target, origin)
18
406
  if (
@@ -24,27 +412,260 @@ function resolvePath(target: string, origin: string): string {
24
412
  url.password ||
25
413
  url.hash
26
414
  ) {
27
- throw new Error(
415
+ throw new TesterError(
416
+ 'invalid_input',
28
417
  'API Tester requires a same-origin URL without credentials or fragments',
29
418
  )
30
419
  }
31
420
  return `${url.pathname}${url.search}`
32
421
  }
33
422
 
34
- /** Sends a same-origin request through the authenticated owner-only Tester BFF. */
423
+ /** The cause of an answer of the proxy that is not the API's. */
424
+ export function proxyFailure(
425
+ status: number,
426
+ payload: unknown,
427
+ elapsedMs: number,
428
+ ): TesterErrorCode {
429
+ const reason =
430
+ payload && typeof payload === 'object' && 'reason' in payload
431
+ ? (payload as { reason?: unknown }).reason
432
+ : undefined
433
+ switch (status) {
434
+ case 400:
435
+ return 'invalid_input'
436
+ case 401:
437
+ return 'not_authenticated'
438
+ case 403:
439
+ return reason ? 'cross_origin' : 'not_owner'
440
+ case 413:
441
+ return 'body_too_large'
442
+ case 502:
443
+ return elapsedMs >= PROXY_TIMEOUT_MS - TIMEOUT_MARGIN_MS
444
+ ? 'timeout'
445
+ : 'proxy_failed'
446
+ default:
447
+ return 'unexpected'
448
+ }
449
+ }
450
+
451
+ async function readPayload(response: Response): Promise<unknown> {
452
+ try {
453
+ return await response.json()
454
+ } catch {
455
+ return null
456
+ }
457
+ }
458
+
459
+ /**
460
+ * Sends a same-origin request through the authenticated owner-only Tester
461
+ * BFF. Fails with a {@link TesterError} naming the cause when the API's
462
+ * answer does not come back: refused by the proxy, cancelled through
463
+ * `signal`, timed out, or unreachable.
464
+ */
35
465
  export async function sendTesterRequest(
36
466
  target: string,
37
467
  origin: string,
38
468
  request: TesterRequest,
469
+ signal?: AbortSignal,
39
470
  ): Promise<TesterResponse> {
40
471
  const path = resolvePath(target, origin)
41
- const response = await fetch('/api/_dms/tester', {
42
- method: 'POST',
43
- headers: { 'content-type': 'application/json' },
44
- credentials: 'same-origin',
45
- body: JSON.stringify({ ...request, path }),
46
- })
47
- if (!response.ok)
48
- throw new Error(`API Tester request failed (${response.status})`)
49
- return response.json()
472
+ const controller = new AbortController()
473
+ let timedOut = false
474
+ const timer = setTimeout(() => {
475
+ timedOut = true
476
+ controller.abort()
477
+ }, CLIENT_TIMEOUT_MS)
478
+ const cancel = () => controller.abort()
479
+ signal?.addEventListener('abort', cancel)
480
+ const started = Date.now()
481
+ try {
482
+ let response: Response
483
+ try {
484
+ response = await fetch('/api/_dms/tester', {
485
+ method: 'POST',
486
+ headers: { 'content-type': 'application/json' },
487
+ credentials: 'same-origin',
488
+ body: JSON.stringify({ ...request, path }),
489
+ signal: controller.signal,
490
+ })
491
+ } catch (cause) {
492
+ if (timedOut) throw new TesterError('timeout', 'Timed out')
493
+ if (signal?.aborted) throw new TesterError('aborted', 'Cancelled')
494
+ throw new TesterError(
495
+ 'network',
496
+ cause instanceof Error ? cause.message : String(cause),
497
+ )
498
+ }
499
+ if (!response.ok) {
500
+ const payload = await readPayload(response)
501
+ const code = proxyFailure(response.status, payload, Date.now() - started)
502
+ throw new TesterError(
503
+ code,
504
+ `API Tester request failed (${response.status})`,
505
+ response.status,
506
+ )
507
+ }
508
+ return (await response.json()) as TesterResponse
509
+ } finally {
510
+ clearTimeout(timer)
511
+ signal?.removeEventListener('abort', cancel)
512
+ }
513
+ }
514
+
515
+ /**
516
+ * `text` with its bidirectional controls shown as `⟨U+202E⟩`: invisible, they
517
+ * would turn the text around on screen without saying so.
518
+ */
519
+ export function revealBidi(text: string): string {
520
+ return text.replace(
521
+ /[‎‏‪-‮⁦-⁩]/g,
522
+ (char) =>
523
+ `⟨U+${char.charCodeAt(0).toString(16).toUpperCase().padStart(4, '0')}⟩`,
524
+ )
525
+ }
526
+
527
+ // --- Masked values ---
528
+
529
+ const literal = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
530
+ /** A masked value as the capture writes it, raw or URL-encoded. */
531
+ const MASK = `${literal(REDACTED)}|${literal(encodeURIComponent(REDACTED))}`
532
+ const REDACTED_PATTERN = new RegExp(MASK, 'gi')
533
+ const JSON_FIELD = new RegExp(
534
+ `"([^"\\\\]+)"\\s*:\\s*"${literal(REDACTED)}"`,
535
+ 'g',
536
+ )
537
+ const FORM_FIELD = new RegExp(`(?:^|&)([^&=\\s]+)=(?:${MASK})`, 'gi')
538
+
539
+ /** How many masked values `text` still holds, raw or URL-encoded. */
540
+ export function countRedacted(text: string | undefined): number {
541
+ return text ? (text.match(REDACTED_PATTERN) ?? []).length : 0
542
+ }
543
+
544
+ export function hasRedacted(text: string | undefined): boolean {
545
+ return countRedacted(text) > 0
546
+ }
547
+
548
+ /** Names of the masked fields of a JSON or form body, for the warning. */
549
+ export function redactedFields(text: string): string[] {
550
+ const names = new Set<string>()
551
+ for (const match of text.matchAll(JSON_FIELD)) names.add(match[1])
552
+ for (const match of text.matchAll(FORM_FIELD)) {
553
+ try {
554
+ names.add(decodeURIComponent(match[1].replace(/\+/g, ' ')))
555
+ } catch {
556
+ names.add(match[1])
557
+ }
558
+ }
559
+ return [...names]
560
+ }
561
+
562
+ // --- Replaying a captured request ---
563
+
564
+ /** A request as the logs' detail route returns it. */
565
+ export interface CapturedRequest {
566
+ _id: string
567
+ timestamp: string
568
+ method: string
569
+ uri: string
570
+ route: string
571
+ statusCode: number
572
+ responseTimeMs: number | null
573
+ pathParams?: Record<string, string>
574
+ query?: Record<string, string | string[]>
575
+ requestHeaders?: Record<string, string>
576
+ requestBody?: string
577
+ requestBodyTruncated?: boolean
578
+ requestBodyOmitted?: string | null
579
+ error?: { message: string; stack?: string } | null
580
+ slowThresholdMs?: number
581
+ source?: string
582
+ }
583
+
584
+ /** Captured headers a replay leaves to the browser and the proxy. */
585
+ const SKIPPED_REPLAY_HEADERS = new Set([
586
+ 'host',
587
+ 'content-length',
588
+ 'user-agent',
589
+ 'accept-encoding',
590
+ 'origin',
591
+ 'referer',
592
+ REQUEST_ID_HEADER,
593
+ SOURCE_HEADER,
594
+ ])
595
+
596
+ /** What a replay puts in the tester, and what it could not. */
597
+ export interface ReplayedRequest {
598
+ headers: KeyValue[]
599
+ /** Captured headers left out, by name. */
600
+ skippedHeaders: string[]
601
+ query: KeyValue[]
602
+ pathValues: Record<string, string>
603
+ bodyMode: BodyMode
604
+ body: string
605
+ /** No body was stored; `bodyOmitted` says why when the capture told. */
606
+ bodyMissing: boolean
607
+ bodyOmitted: string | null
608
+ bodyTruncated: boolean
609
+ }
610
+
611
+ /** `value` decoded once, or as it is when it does not decode. */
612
+ export function decodedValue(value: string): string {
613
+ try {
614
+ return decodeURIComponent(value)
615
+ } catch {
616
+ return value
617
+ }
618
+ }
619
+
620
+ /**
621
+ * The tester's fields for a captured request: every query value (repeated
622
+ * names, empty values), path values decoded (they are encoded again on
623
+ * sending), and its own body or none. A form or a cut body is replayed as
624
+ * text, as it was received.
625
+ */
626
+ export function replayFrom(captured: CapturedRequest): ReplayedRequest {
627
+ const headers: KeyValue[] = []
628
+ const skippedHeaders: string[] = []
629
+ for (const [name, value] of Object.entries(captured.requestHeaders ?? {})) {
630
+ if (SKIPPED_REPLAY_HEADERS.has(name.toLowerCase()))
631
+ skippedHeaders.push(name)
632
+ else headers.push({ name, value })
633
+ }
634
+ const query = Object.entries(captured.query ?? {}).flatMap(([name, value]) =>
635
+ (Array.isArray(value) ? value : [value]).map((item) => ({
636
+ name,
637
+ value: String(item ?? ''),
638
+ })),
639
+ )
640
+ const pathValues = Object.fromEntries(
641
+ Object.entries(captured.pathParams ?? {}).map(([name, value]) => [
642
+ name,
643
+ decodedValue(String(value)),
644
+ ]),
645
+ )
646
+ const stored = captured.requestBody
647
+ const bodyMissing = stored === undefined || stored === null || stored === ''
648
+ const truncated = !bodyMissing && captured.requestBodyTruncated === true
649
+ const contentType = headerValue(captured.requestHeaders ?? {}, 'content-type')
650
+ let bodyMode: BodyMode = 'none'
651
+ if (acceptsRequestBody(captured.method)) {
652
+ const mode = bodyMissing && !contentType ? 'json' : bodyModeFor(contentType)
653
+ bodyMode = truncated || mode === 'form' ? 'text' : mode
654
+ }
655
+ return {
656
+ headers,
657
+ skippedHeaders,
658
+ query,
659
+ pathValues,
660
+ bodyMode,
661
+ body:
662
+ bodyMissing || bodyMode === 'none'
663
+ ? ''
664
+ : bodyMode === 'json'
665
+ ? prettyBody(stored).text
666
+ : (stored ?? ''),
667
+ bodyMissing: bodyMissing && bodyMode !== 'none',
668
+ bodyOmitted: bodyMissing ? (captured.requestBodyOmitted ?? null) : null,
669
+ bodyTruncated: truncated,
670
+ }
50
671
  }
@@ -0,0 +1,7 @@
1
+ import { defineDmsFrontendBuild } from '#dms/frontend-build'
2
+
3
+ // The composables are shared by the blocks; the utils are imported by path,
4
+ // so their names never compete with the DMS's own auto-imported helpers.
5
+ export default defineDmsFrontendBuild((build) => {
6
+ build.registerAutoImports(['app/composables'])
7
+ })