@warlock.js/devtools 5.55.0 → 5.57.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 (240) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +26 -13
  3. package/cjs/ai-source-DTpxumMA.cjs +381 -0
  4. package/cjs/ai-source-DTpxumMA.cjs.map +1 -0
  5. package/cjs/auth-DzU0gHDG.cjs +1655 -0
  6. package/cjs/auth-DzU0gHDG.cjs.map +1 -0
  7. package/cjs/boot-Dy5OqgTM.cjs +138 -0
  8. package/cjs/boot-Dy5OqgTM.cjs.map +1 -0
  9. package/cjs/capture-CqIiaznN.cjs +1342 -0
  10. package/cjs/capture-CqIiaznN.cjs.map +1 -0
  11. package/cjs/cascade-store-pHjKeSFm.cjs +863 -0
  12. package/cjs/cascade-store-pHjKeSFm.cjs.map +1 -0
  13. package/cjs/collector-CJbQbzzK.cjs +271 -0
  14. package/cjs/collector-CJbQbzzK.cjs.map +1 -0
  15. package/cjs/contracts-CVmplkNb.cjs +112 -0
  16. package/cjs/contracts-CVmplkNb.cjs.map +1 -0
  17. package/cjs/current-request-id-BoJJb3y7.cjs +37 -0
  18. package/cjs/current-request-id-BoJJb3y7.cjs.map +1 -0
  19. package/cjs/errors-CyZp5yS-.cjs +177 -0
  20. package/cjs/errors-CyZp5yS-.cjs.map +1 -0
  21. package/cjs/histogram-BaI-PnCv.cjs +102 -0
  22. package/cjs/histogram-BaI-PnCv.cjs.map +1 -0
  23. package/cjs/http-DCfXQvw-.cjs +870 -0
  24. package/cjs/http-DCfXQvw-.cjs.map +1 -0
  25. package/cjs/index.cjs +2 -1
  26. package/cjs/insights-BKtqxdnP.cjs +811 -0
  27. package/cjs/insights-BKtqxdnP.cjs.map +1 -0
  28. package/cjs/ip-DbNhPOzi.cjs +153 -0
  29. package/cjs/ip-DbNhPOzi.cjs.map +1 -0
  30. package/cjs/migrations-w7GMsrQw.cjs +297 -0
  31. package/cjs/migrations-w7GMsrQw.cjs.map +1 -0
  32. package/cjs/openapi-CC7OAUc6.cjs +52 -0
  33. package/cjs/openapi-CC7OAUc6.cjs.map +1 -0
  34. package/cjs/options-CWqFC5__.cjs +181 -0
  35. package/cjs/options-CWqFC5__.cjs.map +1 -0
  36. package/cjs/panels-Rcmeitu3.cjs +318 -0
  37. package/cjs/panels-Rcmeitu3.cjs.map +1 -0
  38. package/cjs/process-panel-DEOnLxoT.cjs +48 -0
  39. package/cjs/process-panel-DEOnLxoT.cjs.map +1 -0
  40. package/cjs/production/index.cjs +238 -0
  41. package/cjs/production/index.cjs.map +1 -0
  42. package/cjs/rolldown-runtime-Zuuoy_Rh.cjs +52 -0
  43. package/cjs/server-ykxsOwob.cjs +184 -0
  44. package/cjs/server-ykxsOwob.cjs.map +1 -0
  45. package/cjs/{src-Xwm3Eel9.cjs → src-UPtTCI2j.cjs} +210 -293
  46. package/cjs/src-UPtTCI2j.cjs.map +1 -0
  47. package/cjs/store-aq207T8v.cjs +9 -0
  48. package/cjs/stream-route-CJTABkUy.cjs +875 -0
  49. package/cjs/stream-route-CJTABkUy.cjs.map +1 -0
  50. package/esm/devtools-connector.d.mts +16 -13
  51. package/esm/devtools-connector.d.mts.map +1 -1
  52. package/esm/devtools-connector.mjs +127 -18
  53. package/esm/devtools-connector.mjs.map +1 -1
  54. package/esm/index.d.mts +4 -2
  55. package/esm/index.mjs +2 -1
  56. package/esm/options.mjs +2 -1
  57. package/esm/options.mjs.map +1 -1
  58. package/esm/panel-tokens.d.mts +13 -0
  59. package/esm/panel-tokens.d.mts.map +1 -0
  60. package/esm/panel-tokens.mjs +45 -0
  61. package/esm/panel-tokens.mjs.map +1 -0
  62. package/esm/panels.mjs +73 -8
  63. package/esm/panels.mjs.map +1 -1
  64. package/esm/production/auth/common-passwords.mjs +303 -0
  65. package/esm/production/auth/common-passwords.mjs.map +1 -0
  66. package/esm/production/auth/default-crypto.mjs +19 -0
  67. package/esm/production/auth/default-crypto.mjs.map +1 -0
  68. package/esm/production/auth/helpers.mjs +77 -0
  69. package/esm/production/auth/helpers.mjs.map +1 -0
  70. package/esm/production/auth/index.mjs +6 -0
  71. package/esm/production/auth/passkeys.mjs +96 -0
  72. package/esm/production/auth/passkeys.mjs.map +1 -0
  73. package/esm/production/auth/service.mjs +1166 -0
  74. package/esm/production/auth/service.mjs.map +1 -0
  75. package/esm/production/boot.mjs +138 -0
  76. package/esm/production/boot.mjs.map +1 -0
  77. package/esm/production/capture/dev-stats.mjs +83 -0
  78. package/esm/production/capture/dev-stats.mjs.map +1 -0
  79. package/esm/production/capture/engine.mjs +442 -0
  80. package/esm/production/capture/engine.mjs.map +1 -0
  81. package/esm/production/capture/explain.mjs +271 -0
  82. package/esm/production/capture/explain.mjs.map +1 -0
  83. package/esm/production/capture/filter.mjs +24 -0
  84. package/esm/production/capture/filter.mjs.map +1 -0
  85. package/esm/production/capture/index.mjs +7 -0
  86. package/esm/production/capture/production-capture.mjs +134 -0
  87. package/esm/production/capture/production-capture.mjs.map +1 -0
  88. package/esm/production/capture/redact.mjs +109 -0
  89. package/esm/production/capture/redact.mjs.map +1 -0
  90. package/esm/production/capture/stats-stores.mjs +300 -0
  91. package/esm/production/capture/stats-stores.mjs.map +1 -0
  92. package/esm/production/cli/actions.mjs +151 -0
  93. package/esm/production/cli/actions.mjs.map +1 -0
  94. package/esm/production/cli/index.d.mts +17 -0
  95. package/esm/production/cli/index.d.mts.map +1 -0
  96. package/esm/production/cli/index.mjs +86 -0
  97. package/esm/production/cli/index.mjs.map +1 -0
  98. package/esm/production/contracts.d.mts +592 -0
  99. package/esm/production/contracts.d.mts.map +1 -0
  100. package/esm/production/contracts.mjs +95 -0
  101. package/esm/production/contracts.mjs.map +1 -0
  102. package/esm/production/errors.d.mts +31 -0
  103. package/esm/production/errors.d.mts.map +1 -0
  104. package/esm/production/errors.mjs +142 -0
  105. package/esm/production/errors.mjs.map +1 -0
  106. package/esm/production/http/access.mjs +124 -0
  107. package/esm/production/http/access.mjs.map +1 -0
  108. package/esm/production/http/auth-routes.mjs +280 -0
  109. package/esm/production/http/auth-routes.mjs.map +1 -0
  110. package/esm/production/http/client.mjs +57 -0
  111. package/esm/production/http/client.mjs.map +1 -0
  112. package/esm/production/http/constants.mjs +11 -0
  113. package/esm/production/http/constants.mjs.map +1 -0
  114. package/esm/production/http/context.mjs +14 -0
  115. package/esm/production/http/context.mjs.map +1 -0
  116. package/esm/production/http/cookie.mjs +39 -0
  117. package/esm/production/http/cookie.mjs.map +1 -0
  118. package/esm/production/http/headers.mjs +25 -0
  119. package/esm/production/http/headers.mjs.map +1 -0
  120. package/esm/production/http/index.mjs +10 -0
  121. package/esm/production/http/ip.mjs +130 -0
  122. package/esm/production/http/ip.mjs.map +1 -0
  123. package/esm/production/http/mount.mjs +300 -0
  124. package/esm/production/http/mount.mjs.map +1 -0
  125. package/esm/production/http/state.mjs +54 -0
  126. package/esm/production/http/state.mjs.map +1 -0
  127. package/esm/production/index.d.mts +6 -0
  128. package/esm/production/index.mjs +5 -0
  129. package/esm/production/insights/cap-report.mjs +67 -0
  130. package/esm/production/insights/cap-report.mjs.map +1 -0
  131. package/esm/production/insights/health.mjs +88 -0
  132. package/esm/production/insights/health.mjs.map +1 -0
  133. package/esm/production/insights/index.mjs +10 -0
  134. package/esm/production/insights/insights.mjs +167 -0
  135. package/esm/production/insights/insights.mjs.map +1 -0
  136. package/esm/production/insights/instance.mjs +24 -0
  137. package/esm/production/insights/instance.mjs.map +1 -0
  138. package/esm/production/insights/jobs.mjs +100 -0
  139. package/esm/production/insights/jobs.mjs.map +1 -0
  140. package/esm/production/insights/reporter.mjs +59 -0
  141. package/esm/production/insights/reporter.mjs.map +1 -0
  142. package/esm/production/insights/resources.mjs +139 -0
  143. package/esm/production/insights/resources.mjs.map +1 -0
  144. package/esm/production/insights/writer.mjs +72 -0
  145. package/esm/production/insights/writer.mjs.map +1 -0
  146. package/esm/production/openapi.mjs +52 -0
  147. package/esm/production/openapi.mjs.map +1 -0
  148. package/esm/production/options.d.mts +60 -0
  149. package/esm/production/options.d.mts.map +1 -0
  150. package/esm/production/options.mjs +170 -0
  151. package/esm/production/options.mjs.map +1 -0
  152. package/esm/production/stats/histogram.mjs +67 -0
  153. package/esm/production/stats/histogram.mjs.map +1 -0
  154. package/esm/production/stats/merge.mjs +106 -0
  155. package/esm/production/stats/merge.mjs.map +1 -0
  156. package/esm/production/store/cascade-store.mjs +322 -0
  157. package/esm/production/store/cascade-store.mjs.map +1 -0
  158. package/esm/production/store/index.mjs +5 -0
  159. package/esm/production/store/mapping.mjs +258 -0
  160. package/esm/production/store/mapping.mjs.map +1 -0
  161. package/esm/production/store/memory-store.mjs +291 -0
  162. package/esm/production/store/memory-store.mjs.map +1 -0
  163. package/esm/production/store/migrations.d.mts +11 -0
  164. package/esm/production/store/migrations.d.mts.map +1 -0
  165. package/esm/production/store/migrations.mjs +29 -0
  166. package/esm/production/store/migrations.mjs.map +1 -0
  167. package/esm/production/store/models/account.migration.mjs +34 -0
  168. package/esm/production/store/models/account.migration.mjs.map +1 -0
  169. package/esm/production/store/models/account.model.mjs +13 -0
  170. package/esm/production/store/models/account.model.mjs.map +1 -0
  171. package/esm/production/store/models/audit.migration.mjs +30 -0
  172. package/esm/production/store/models/audit.migration.mjs.map +1 -0
  173. package/esm/production/store/models/audit.model.mjs +13 -0
  174. package/esm/production/store/models/audit.model.mjs.map +1 -0
  175. package/esm/production/store/models/base.mjs +27 -0
  176. package/esm/production/store/models/base.mjs.map +1 -0
  177. package/esm/production/store/models/index.mjs +17 -0
  178. package/esm/production/store/models/invite.migration.mjs +26 -0
  179. package/esm/production/store/models/invite.migration.mjs.map +1 -0
  180. package/esm/production/store/models/invite.model.mjs +13 -0
  181. package/esm/production/store/models/invite.model.mjs.map +1 -0
  182. package/esm/production/store/models/report.migration.mjs +20 -0
  183. package/esm/production/store/models/report.migration.mjs.map +1 -0
  184. package/esm/production/store/models/report.model.mjs +13 -0
  185. package/esm/production/store/models/report.model.mjs.map +1 -0
  186. package/esm/production/store/models/sample.migration.mjs +25 -0
  187. package/esm/production/store/models/sample.migration.mjs.map +1 -0
  188. package/esm/production/store/models/sample.model.mjs +13 -0
  189. package/esm/production/store/models/sample.model.mjs.map +1 -0
  190. package/esm/production/store/models/session.migration.mjs +31 -0
  191. package/esm/production/store/models/session.migration.mjs.map +1 -0
  192. package/esm/production/store/models/session.model.mjs +13 -0
  193. package/esm/production/store/models/session.model.mjs.map +1 -0
  194. package/esm/production/store/models/state.migration.mjs +26 -0
  195. package/esm/production/store/models/state.migration.mjs.map +1 -0
  196. package/esm/production/store/models/state.model.mjs +13 -0
  197. package/esm/production/store/models/state.model.mjs.map +1 -0
  198. package/esm/query-shape.mjs +14 -1
  199. package/esm/query-shape.mjs.map +1 -1
  200. package/esm/server/explain-route.mjs +26 -1
  201. package/esm/server/explain-route.mjs.map +1 -1
  202. package/esm/server/index.mjs +9 -4
  203. package/esm/server/index.mjs.map +1 -1
  204. package/esm/server/insights-routes.mjs +62 -0
  205. package/esm/server/insights-routes.mjs.map +1 -0
  206. package/esm/server/log-routes.mjs +32 -5
  207. package/esm/server/log-routes.mjs.map +1 -1
  208. package/esm/server/openapi-routes.mjs +3 -2
  209. package/esm/server/openapi-routes.mjs.map +1 -1
  210. package/esm/server/requests-routes.mjs +125 -0
  211. package/esm/server/requests-routes.mjs.map +1 -1
  212. package/esm/server/session-routes.mjs +42 -0
  213. package/esm/server/session-routes.mjs.map +1 -0
  214. package/esm/server/stream-route.mjs +81 -11
  215. package/esm/server/stream-route.mjs.map +1 -1
  216. package/esm/server/ui-assets.mjs +34 -25
  217. package/esm/server/ui-assets.mjs.map +1 -1
  218. package/esm/sources/log-source.mjs +14 -1
  219. package/esm/sources/log-source.mjs.map +1 -1
  220. package/esm/types.d.mts +208 -3
  221. package/esm/types.d.mts.map +1 -1
  222. package/esm/ui-root.mjs +9 -4
  223. package/esm/ui-root.mjs.map +1 -1
  224. package/llms-full.txt +166 -21
  225. package/llms.txt +2 -2
  226. package/package.json +32 -8
  227. package/skills/SKILL.md +166 -21
  228. package/ui/dashboard/assets/app.css +3 -0
  229. package/ui/dashboard/assets/app.js +50 -0
  230. package/ui/dashboard/build-info.json +21 -0
  231. package/ui/dashboard/index.html +16 -0
  232. package/ui/panels/processes.js +12 -3
  233. package/cjs/ai-source-Dz_3tlZ5.cjs +0 -703
  234. package/cjs/ai-source-Dz_3tlZ5.cjs.map +0 -1
  235. package/cjs/server-B11ShQYE.cjs +0 -628
  236. package/cjs/server-B11ShQYE.cjs.map +0 -1
  237. package/cjs/src-Xwm3Eel9.cjs.map +0 -1
  238. package/ui/app.css +0 -376
  239. package/ui/app.js +0 -1158
  240. package/ui/index.html +0 -28
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/production/contracts.ts"],"sourcesContent":["/**\n * The contracts of the devtools production monitor: the shapes the server\n * stores, the JSON its API returns, and the few constants both sides share.\n *\n * This file has NO imports, so the dashboard (`ui-src/`) can import its types\n * too. Every timestamp is epoch milliseconds, every duration milliseconds,\n * every size bytes. Absent values are `null`, never missing.\n */\n\n// ---------------------------------------------------------------------------\n// Modes, roles and stages\n// ---------------------------------------------------------------------------\n\n/** Where the dashboard runs: the loopback development dashboard or the signed-in production monitor. */\nexport type DevtoolsMode = \"development\" | \"production\";\n\n/** What an account may do: `admin` manages users and the dashboard, `viewer` reads. */\nexport type DevtoolsRole = \"admin\" | \"viewer\";\n\n/**\n * Where a browser session stands. Only `active` reaches the data routes;\n * every other stage reaches only the sign-in steps it needs next.\n */\nexport type DevtoolsSessionStage =\n | \"signed-out\"\n | \"password-change\"\n | \"mfa-enrol\"\n | \"mfa-verify\"\n | \"active\";\n\n/** How an account's current password was set. `env` and `reset` passwords must be changed at the next sign-in. */\nexport type DevtoolsPasswordSource = \"env\" | \"setup\" | \"invite\" | \"user\" | \"reset\";\n\n// ---------------------------------------------------------------------------\n// Instances\n// ---------------------------------------------------------------------------\n\n/** One process that runs the monitor (a pm2 or cluster worker, a container). */\nexport type DevtoolsInstanceInfo = {\n /** Stable for the life of the process: `<host>:<pid>:<start time base36>`. */\n id: string;\n /** What the dashboard shows: `<host> #<worker>` or `<host> pid <pid>`. */\n label: string;\n host: string;\n pid: number;\n /** pm2's `NODE_APP_INSTANCE` / `pm_id`, or the cluster worker id; `null` when neither is set. */\n worker: string | null;\n startedAt: number;\n /** When the instance last wrote its report (the current time for the instance answering). */\n seenAt: number;\n nodeVersion: string;\n};\n\n// ---------------------------------------------------------------------------\n// Histograms (mergeable across instances)\n// ---------------------------------------------------------------------------\n\n/**\n * Upper bounds (inclusive, ms) of the latency buckets every histogram uses.\n * A histogram's `counts` has one more entry than this list: the last entry\n * counts everything above the highest bound. Fixed bounds make histograms\n * from several instances merge exactly.\n */\nexport const DEVTOOLS_LATENCY_BUCKETS_MS = [\n 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 30000,\n] as const;\n\n/** A latency histogram over `DEVTOOLS_LATENCY_BUCKETS_MS`. */\nexport type DevtoolsHistogram = {\n /** `DEVTOOLS_LATENCY_BUCKETS_MS.length + 1` entries. */\n counts: number[];\n count: number;\n sumMs: number;\n maxMs: number;\n};\n\n// ---------------------------------------------------------------------------\n// Query, route and error statistics\n// ---------------------------------------------------------------------------\n\n/** Statistics for one normalized query shape (literals and bindings replaced by `?`). */\nexport type DevtoolsQueryShapeStats = {\n /** First 16 hex characters of the SHA-256 of `shape`; the id the API and EXPLAIN use. */\n id: string;\n /** The normalized query, at most 2000 characters. Never holds a value. */\n shape: string;\n driver: \"postgres\" | \"mongodb\";\n connection: string;\n count: number;\n errors: number;\n histogram: DevtoolsHistogram;\n /** Sampled requests in which this shape reached the N+1 threshold, and the highest count in one request. */\n nPlusOne: { requests: number; maxPerRequest: number };\n /** The slowest run seen; its values stay in the process that ran it (see EXPLAIN). */\n slowest: {\n durationMs: number;\n at: number;\n route: string | null;\n requestId: string | null;\n instance: string;\n } | null;\n firstSeen: number;\n lastSeen: number;\n /** Whether EXPLAIN can run for this shape (a Postgres `SELECT`/`WITH`, or a MongoDB `find`/`aggregate`/`count`). */\n explainable: boolean;\n};\n\n/** Time spent in one named request phase (middleware, validation, handler, …) on one route. */\nexport type DevtoolsRoutePhaseStats = {\n name: string;\n count: number;\n sumMs: number;\n maxMs: number;\n};\n\n/** Statistics for one route pattern and method. */\nexport type DevtoolsRouteStats = {\n /** `\"<METHOD> <route pattern>\"`, e.g. `\"GET /posts/:slug\"`. */\n key: string;\n method: string;\n route: string;\n count: number;\n /** Responses with a 5xx status or a thrown error. */\n errors: number;\n histogram: DevtoolsHistogram;\n /** At most 30 phases, slowest total first. */\n phases: DevtoolsRoutePhaseStats[];\n slowest: { durationMs: number; at: number; requestId: string | null; instance: string } | null;\n};\n\n/** Errors grouped by fingerprint (normalized message + route + source). */\nexport type DevtoolsErrorGroup = {\n /** First 16 hex characters of the SHA-256 of the fingerprint. */\n id: string;\n /** The latest message as raised, at most 500 characters. */\n message: string;\n /** The error class name when known (`TypeError`). */\n name: string | null;\n source: \"request\" | \"log\";\n route: string | null;\n status: number | null;\n count: number;\n firstSeen: number;\n lastSeen: number;\n lastRequestId: string | null;\n /** The latest stack, at most 4000 characters; `null` when none was available. */\n stack: string | null;\n};\n\n/** A warn/error log entry kept for the Logs panel in production (no context: it may hold values). */\nexport type DevtoolsReportLogEntry = {\n level: \"debug\" | \"info\" | \"warn\" | \"error\" | \"success\";\n module: string;\n action: string;\n /** At most 1000 characters. */\n message: string;\n at: number;\n requestId: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Resources, health, jobs\n// ---------------------------------------------------------------------------\n\n/** One resource reading of a process. */\nexport type DevtoolsResourcePoint = {\n at: number;\n rssBytes: number;\n heapUsedBytes: number;\n heapTotalBytes: number;\n externalBytes: number;\n /** Process CPU time over wall time since the previous point, 0–100 per core (can exceed 100). */\n cpuPercent: number;\n eventLoopDelayP50Ms: number;\n eventLoopDelayP99Ms: number;\n eventLoopDelayMaxMs: number;\n /** `performance.eventLoopUtilization()` since the previous point, 0–1. */\n eventLoopUtilization: number;\n /** Garbage collections since the previous point. */\n gcCount: number;\n /** Total GC pause since the previous point. */\n gcPauseMs: number;\n};\n\n/** The latest resource reading plus values that change rarely. */\nexport type DevtoolsResourceSnapshot = DevtoolsResourcePoint & {\n heapLimitBytes: number;\n uptimeSeconds: number;\n /** Totals since the monitor started, by GC kind. */\n gcByKind: Record<\n \"minor\" | \"major\" | \"incremental\" | \"weakcb\",\n { count: number; pauseMs: number }\n >;\n};\n\n/** Readiness checks (core's `health` registry) of one process, with a short history. */\nexport type DevtoolsHealthReport = {\n status: \"ok\" | \"error\" | \"unknown\";\n checkedAt: number | null;\n checks: Record<string, boolean>;\n /** Newest last, at most 60 entries. */\n history: { at: number; status: \"ok\" | \"error\"; failed: string[] }[];\n};\n\n/** One scheduled job (`@warlock.js/scheduler`). */\nexport type DevtoolsScheduleInfo = {\n name: string;\n /** The cron expression, or `null` for an interval schedule. */\n cron: string | null;\n /** A readable interval such as `\"every 5 minutes\"`, or `null`. */\n interval: string | null;\n isRunning: boolean;\n lastRunAt: number | null;\n nextRunAt: number | null;\n lastDurationMs: number | null;\n lastError: string | null;\n runs: number;\n failures: number;\n};\n\n/** Background work of one process: schedules and queue counts, each `available: false` when its package is not installed. */\nexport type DevtoolsJobsReport = {\n available: { scheduler: boolean; queue: boolean };\n schedules: DevtoolsScheduleInfo[];\n /** Job counts per queue and state (`waiting`, `active`, `delayed`, `failed`, `completed`). */\n queues: { name: string; counts: Record<string, number> }[];\n};\n\n/** What the capture did since the process started. */\nexport type DevtoolsCaptureCounters = {\n sampleRate: number;\n requests: number;\n sampled: number;\n /** Unsampled requests kept as a summary because they were slow or failed. */\n keptUnsampled: number;\n /** Samples written to the database. */\n stored: number;\n /** Samples not written because the per-minute budget was spent. */\n droppedStored: number;\n /** Query shapes, routes and error groups evicted to keep memory bounded. */\n evictedShapes: number;\n evictedRoutes: number;\n evictedErrors: number;\n /** Queries not kept inside a sampled request because it reached its per-request limit. */\n droppedQueries: number;\n};\n\n/**\n * Everything one process reports, written to the database every\n * `reportIntervalMs` (one row per instance) and merged by the dashboard.\n * Serialized it stays under 256 KB: lists are trimmed from the end.\n */\nexport type DevtoolsInstanceReport = {\n instance: DevtoolsInstanceInfo;\n at: number;\n resources: { snapshot: DevtoolsResourceSnapshot; history: DevtoolsResourcePoint[] };\n /** At most 200, highest total time first. */\n queries: DevtoolsQueryShapeStats[];\n /** At most 200, highest total time first. */\n routes: DevtoolsRouteStats[];\n /** At most 50, newest first. */\n errors: DevtoolsErrorGroup[];\n /** At most 50, newest first. */\n logs: DevtoolsReportLogEntry[];\n health: DevtoolsHealthReport;\n jobs: DevtoolsJobsReport;\n capture: DevtoolsCaptureCounters;\n};\n\n// ---------------------------------------------------------------------------\n// Requests (stored samples)\n// ---------------------------------------------------------------------------\n\n/**\n * A request row. Matches the development `DevtoolsRequestSummary` field for\n * field, plus where it was captured.\n */\nexport type DevtoolsSampleSummary = {\n id: string;\n method: string;\n path: string;\n route?: string;\n status?: number;\n startedAt: number;\n durationMs?: number;\n queryCount: number;\n warningCount: number;\n /** Read from the persisted request log only. */\n persisted?: true;\n /** The instance that served the request. */\n instance?: string;\n /** Kept because it was slow or failed, without a timeline (the request was not sampled). */\n partial?: true;\n};\n\n/** A query inside a stored sample: the shape only, never the SQL text with values or the bindings. */\nexport type DevtoolsSampleQuery = {\n id: string;\n connection: string;\n driver: \"postgres\" | \"mongodb\";\n /** Same as `shape`: kept under this name so the request view renders it like a development query. */\n sql?: string;\n collection?: string;\n command?: string;\n shape: string;\n shapeId: string;\n startedAt: number;\n durationMs: number;\n rowCount?: number;\n error?: string;\n};\n\n/** The timeline of a sampled request, with every value removed (see the redaction rules). */\nexport type DevtoolsSampleDetail = DevtoolsSampleSummary & {\n error?: string;\n phases: { name: string; startedAt: number; durationMs: number }[];\n queries: DevtoolsSampleQuery[];\n /** Cache operation counts only; keys are not kept. */\n cache: { hits: number; misses: number; writes: number };\n /** Log entries without context. */\n logs: { level: string; module: string; action: string; message: string; at: number }[];\n warnings: { type: \"n+1\"; message: string; shape: string; count: number }[];\n /** Queries left out because the request reached `maxQueriesPerRequest`. */\n droppedQueries: number;\n};\n\n// ---------------------------------------------------------------------------\n// API views (what the dashboard reads)\n// ---------------------------------------------------------------------------\n\n/** `GET api/instances`. */\nexport type DevtoolsInstancesView = {\n /** The instance that answered this request. */\n current: string;\n /** Instances seen in the last 5 minutes (the answering one included), newest first. */\n instances: DevtoolsInstanceInfo[];\n};\n\n/** `GET api/resources?instance=<id|all>`. */\nexport type DevtoolsResourcesView = {\n instances: {\n instance: DevtoolsInstanceInfo;\n snapshot: DevtoolsResourceSnapshot;\n history: DevtoolsResourcePoint[];\n }[];\n};\n\n/** A shape row with figures computed from its histogram. */\nexport type DevtoolsQueryShapeRow = DevtoolsQueryShapeStats & {\n p50Ms: number;\n p95Ms: number;\n meanMs: number;\n /** Ids of the instances that reported this shape. */\n instances: string[];\n};\n\n/** `GET api/queries/stats?instance=&sort=total|p95|count|n+1&limit=`. */\nexport type DevtoolsQueryStatsView = {\n shapes: DevtoolsQueryShapeRow[];\n /** The sample rate the counts come from; counts are of sampled requests only. */\n sampleRate: number;\n instanceCount: number;\n evicted: number;\n};\n\n/** A route row with figures computed from its histogram. */\nexport type DevtoolsRouteStatsRow = DevtoolsRouteStats & {\n p50Ms: number;\n p95Ms: number;\n meanMs: number;\n instances: string[];\n};\n\n/** `GET api/routes/stats?instance=&sort=total|p95|count|errors&limit=`. */\nexport type DevtoolsRouteStatsView = {\n routes: DevtoolsRouteStatsRow[];\n sampleRate: number;\n instanceCount: number;\n};\n\n/** `GET api/health?instance=`. */\nexport type DevtoolsHealthView = {\n instances: { instance: DevtoolsInstanceInfo; report: DevtoolsHealthReport }[];\n};\n\n/** `GET api/errors?instance=&limit=`. */\nexport type DevtoolsErrorsView = {\n groups: (DevtoolsErrorGroup & { instances: string[] })[];\n};\n\n/**\n * One row of `GET api/logs?level=&module=&instance=` (newest first), in both\n * modes. Development rows carry `context` and no `instance`; production rows\n * carry `instance` and never `context`.\n */\nexport type DevtoolsLogRow = DevtoolsReportLogEntry & {\n instance: string | null;\n context?: unknown;\n};\n\n/** `GET api/logs`: the rows, newest first (a plain array, as in 5.55). */\nexport type DevtoolsLogsView = DevtoolsLogRow[];\n\n/** `GET api/jobs?instance=`. */\nexport type DevtoolsJobsView = {\n instances: { instance: DevtoolsInstanceInfo; report: DevtoolsJobsReport }[];\n};\n\n/** `POST api/queries/:shapeId/explain`. */\nexport type DevtoolsExplainResult = {\n shapeId: string;\n driver: \"postgres\" | \"mongodb\";\n /** `true` only when the project allows executing plans (`explain.executing`). */\n executing: boolean;\n plan: unknown;\n /** The instance whose example ran the EXPLAIN. */\n instance: string;\n};\n\n/** One dashboard tab, as `GET api/panels` lists it (enabled tabs only, in display order). */\nexport type DevtoolsPanelInfo = {\n id: string;\n title: string;\n /** `built-in` tabs are React views in the bundle; `package` tabs load `panels/<id>/view.js`. */\n type: \"built-in\" | \"package\";\n};\n\n/**\n * The built-in tabs, in display order, with whether production shows them\n * when the project says nothing (`production.panels` overrides per id).\n */\nexport const DEVTOOLS_BUILT_IN_PANELS = [\n { id: \"requests\", title: \"Requests\", production: true },\n { id: \"queries\", title: \"Queries\", production: true },\n { id: \"routes\", title: \"Routes\", production: true },\n { id: \"resources\", title: \"Resources\", production: true },\n { id: \"health\", title: \"Health\", production: true },\n { id: \"errors\", title: \"Errors\", production: true },\n { id: \"logs\", title: \"Logs\", production: true },\n { id: \"jobs\", title: \"Jobs\", production: true },\n { id: \"mail\", title: \"Mail\", production: false },\n { id: \"ai\", title: \"AI\", production: false },\n { id: \"agents\", title: \"Agents\", production: false },\n { id: \"api\", title: \"API\", production: false },\n] as const;\n\n/** The id of a built-in tab. */\nexport type DevtoolsBuiltInPanelId = (typeof DEVTOOLS_BUILT_IN_PANELS)[number][\"id\"];\n\n// ---------------------------------------------------------------------------\n// Accounts, sessions, invites\n// ---------------------------------------------------------------------------\n\n/** An account as the API shows it (never a hash or a secret). */\nexport type DevtoolsAccountView = {\n id: string;\n email: string;\n role: DevtoolsRole;\n twoFactor: {\n totp: boolean;\n passkeys: { id: string; name: string; createdAt: number; lastUsedAt: number | null }[];\n recoveryCodesLeft: number;\n };\n mustChangePassword: boolean;\n createdAt: number;\n lastLoginAt: number | null;\n};\n\n/** `GET api/auth/session`: who is signed in and what comes next. */\nexport type DevtoolsSessionView = {\n mode: DevtoolsMode;\n stage: DevtoolsSessionStage;\n /** `null` when signed out, and in development (no accounts there). */\n account: DevtoolsAccountView | null;\n /** `admin` in development; `null` when signed out. */\n role: DevtoolsRole | null;\n /** The token to send as `X-Devtools-Csrf` on every POST/PUT/PATCH/DELETE; `null` when signed out and in development. */\n csrf: string | null;\n /** When the session ends at the latest; `null` when signed out and in development. */\n expiresAt: number | null;\n /** The instance that answered; `null` when signed out. */\n instance: DevtoolsInstanceInfo | null;\n /** Sign-in methods the server offers; `null` when signed out. */\n methods: { totp: true; passkeys: boolean } | null;\n};\n\n/** `POST api/auth/login` body. */\nexport type DevtoolsLoginInput = { email: string; password: string };\n\n/** Answer of every sign-in step: the next stage, and the new CSRF token when the session changed. */\nexport type DevtoolsAuthStepResult = { stage: DevtoolsSessionStage; csrf: string | null };\n\n/** `POST api/auth/totp/start` (and `api/account/totp/start`). */\nexport type DevtoolsTotpEnrolment = {\n /** Base32, for manual entry. */\n secret: string;\n /** `otpauth://totp/...`, rendered as a QR code by the dashboard. */\n uri: string;\n issuer: string;\n account: string;\n};\n\n/** Recovery codes, shown once. */\nexport type DevtoolsRecoveryCodes = { codes: string[] };\n\n/** A pending or used invite. */\nexport type DevtoolsInviteView = {\n id: string;\n email: string;\n role: DevtoolsRole;\n createdAt: number;\n expiresAt: number;\n createdBy: string | null;\n usedAt: number | null;\n};\n\n/** `POST api/admin/invites`: the token appears only in this answer. */\nexport type DevtoolsCreatedInvite = { invite: DevtoolsInviteView; token: string };\n\n/** `GET api/admin/users`. */\nexport type DevtoolsUserListView = {\n accounts: DevtoolsAccountView[];\n invites: DevtoolsInviteView[];\n};\n\n/** A session as its owner sees it (`GET api/account/sessions`). */\nexport type DevtoolsSessionInfo = {\n id: string;\n current: boolean;\n createdAt: number;\n lastSeenAt: number;\n expiresAt: number;\n ip: string | null;\n userAgent: string | null;\n};\n\n// ---------------------------------------------------------------------------\n// Audit log\n// ---------------------------------------------------------------------------\n\n/** Every audited event. `login.failed` and `mfa.failed` are the ones rate limits count. */\nexport type DevtoolsAuditType =\n | \"admin.seeded\"\n | \"admin.reset\"\n | \"setup.completed\"\n | \"login.succeeded\"\n | \"login.failed\"\n | \"login.blocked\"\n | \"mfa.succeeded\"\n | \"mfa.failed\"\n | \"mfa.enrolled\"\n | \"mfa.removed\"\n | \"recovery-code.used\"\n | \"recovery-codes.regenerated\"\n | \"passkey.added\"\n | \"passkey.removed\"\n | \"password.changed\"\n | \"logout\"\n | \"session.revoked\"\n | \"invite.created\"\n | \"invite.revoked\"\n | \"invite.accepted\"\n | \"account.role-changed\"\n | \"account.removed\"\n | \"account.mfa-reset\"\n | \"account.signed-out\"\n | \"dashboard.disabled\"\n | \"dashboard.enabled\"\n | \"dashboard.locked\"\n | \"explain.run\"\n | \"requests.cleared\"\n | \"panel.action\";\n\n/** The audit types that count toward the account, IP and global failure limits. */\nexport const DEVTOOLS_FAILURE_AUDIT_TYPES: readonly DevtoolsAuditType[] = [\n \"login.failed\",\n \"mfa.failed\",\n];\n\n/** One audit log entry. */\nexport type DevtoolsAuditEntry = {\n id: string;\n at: number;\n type: DevtoolsAuditType;\n /** The account acting or targeted; `null` for an unknown email or the CLI. */\n accountId: string | null;\n /** The email as typed or as stored, lower-cased; `null` when there was none. */\n email: string | null;\n /** `\"cli\"` for a command, else the client IP after trusted-proxy resolution. */\n ip: string | null;\n /** At most 200 characters. */\n userAgent: string | null;\n /** Small flat facts: target account, role, shape id, panel route. Never a secret. */\n detail: Record<string, string | number | boolean | null>;\n /** Short reference shown to users in error messages (8 characters). */\n ref: string;\n};\n\n// ---------------------------------------------------------------------------\n// Errors the API returns\n// ---------------------------------------------------------------------------\n\n/**\n * Error codes in API answers. Each has a fixed message (see\n * `DEVTOOLS_ERROR_MESSAGES` in `errors.ts`) that says what failed and what to\n * do next.\n */\nexport type DevtoolsErrorCode =\n | \"auth.invalid-credentials\"\n | \"auth.invalid-code\"\n | \"auth.invalid-setup-token\"\n | \"auth.password-too-short\"\n | \"auth.password-too-long\"\n | \"auth.password-common\"\n | \"auth.password-same-as-email\"\n | \"auth.password-unchanged\"\n | \"auth.wrong-current-password\"\n | \"auth.busy\"\n | \"invite.invalid\"\n | \"invite.email-taken\"\n | \"account.not-found\"\n | \"account.last-admin\"\n | \"account.self\"\n | \"account.last-factor\"\n | \"role.forbidden\"\n | \"csrf.invalid\"\n | \"passkey.unavailable\"\n | \"passkey.failed\"\n | \"explain.not-allowed\"\n | \"explain.unsupported\"\n | \"explain.elsewhere\"\n | \"explain.failed\"\n | \"request.not-found\"\n | \"request.invalid-filter\"\n | \"stream.too-many\"\n | \"input.invalid\"\n | \"server.error\";\n\n/** The JSON body of every failed API call. */\nexport type DevtoolsApiErrorBody = {\n /** What failed and what to do next. */\n error: string;\n code: DevtoolsErrorCode;\n /** Short reference to quote to an admin; also written to the audit log or server log. */\n ref?: string;\n /** The instance that answered, when it matters (`explain.elsewhere`). */\n instance?: string;\n};\n"],"mappings":";;;;;;;AA+DA,MAAa,8BAA8B;CACzC;CAAG;CAAG;CAAG;CAAI;CAAI;CAAI;CAAK;CAAK;CAAK;CAAM;CAAM;CAAM;CAAO;AAC/D;;;;;AA8WA,MAAa,2BAA2B;CACtC;EAAE,IAAI;EAAY,OAAO;EAAY,YAAY;CAAK;CACtD;EAAE,IAAI;EAAW,OAAO;EAAW,YAAY;CAAK;CACpD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAa,OAAO;EAAa,YAAY;CAAK;CACxD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAK;CAClD;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAK;CAC9C;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAK;CAC9C;EAAE,IAAI;EAAQ,OAAO;EAAQ,YAAY;CAAM;CAC/C;EAAE,IAAI;EAAM,OAAO;EAAM,YAAY;CAAM;CAC3C;EAAE,IAAI;EAAU,OAAO;EAAU,YAAY;CAAM;CACnD;EAAE,IAAI;EAAO,OAAO;EAAO,YAAY;CAAM;AAC/C;;AAkIA,MAAa,+BAA6D,CACxE,gBACA,YACF"}
@@ -0,0 +1,31 @@
1
+ //#region ../../packages/devtools/src/production/errors.d.ts
2
+ /**
3
+ * Why production mode refused to start. Each code names one missing or
4
+ * invalid setting; the message says which and how to fix it.
5
+ */
6
+ export declare const DEVTOOLS_CONFIG_CODES: {
7
+ readonly DT001: "Devtools production mode needs a dashboard path. Set DEVTOOLS_PATH (for example /ops-7f3k2q) or devtools.production.path.";
8
+ readonly DT002: 'The devtools dashboard path must start with "/", be at least 8 characters, use only letters, digits, "-", "_", ".", "~" and "/", and not be "/__warlock".';
9
+ readonly DT003: "Devtools production mode has no admin yet. Set DEVTOOLS_ADMIN_EMAIL with DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin --email <email>`.";
10
+ readonly DT004: "DEVTOOLS_ADMIN_PASSWORD does not meet the password rules (at least 8 characters, at most 72 bytes, not a common password, not the email). Choose another one.";
11
+ readonly DT005: "Devtools production mode stores its accounts in the database. Install @warlock.js/cascade and configure a database connection.";
12
+ readonly DT006: "Devtools production mode encrypts two-factor secrets with the app key. Set encryption.key (64 hex characters) in src/config/encryption.ts.";
13
+ readonly DT007: "A devtools production option has an invalid value. The message names the option and the accepted values.";
14
+ readonly DT008: "The devtools tables are missing. Add devtoolsMigrations from @warlock.js/devtools/production to database.migrations in warlock.config.ts and run `warlock migrate`.";
15
+ readonly DT009: "Set either DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, not both.";
16
+ readonly DT010: "DEVTOOLS_SETUP_TOKEN must be at least 32 characters. Generate one with: openssl rand -base64 32";
17
+ };
18
+ /** A production configuration error code (`DT001`–`DT010`). */
19
+ export type DevtoolsConfigCode = keyof typeof DEVTOOLS_CONFIG_CODES;
20
+ /**
21
+ * Thrown while the devtools connector boots in production when the monitor is
22
+ * enabled but cannot start safely. It stops the app from booting, so a
23
+ * misconfigured deploy fails at once instead of serving an unprotected
24
+ * dashboard.
25
+ */
26
+ export declare class DevtoolsProductionConfigError extends Error {
27
+ readonly code: DevtoolsConfigCode;
28
+ constructor(code: DevtoolsConfigCode, detail?: string);
29
+ }
30
+ //#endregion
31
+ //# sourceMappingURL=errors.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.mts","names":[],"sources":["../../../../../../../../packages/devtools/src/production/errors.ts"],"mappings":";;;;;qBAOa;WACX;WAEA;WAEA;WAEA;WAEA;WAEA;WAEA;WAEA;WAEA;WACA;;;YAKU,kCAAkC;;;;;;;qBAQjC,sCAAsC;WACjC,MAAM;EAEtB,YAAmB,MAAM,oBAAoB"}
@@ -0,0 +1,142 @@
1
+ import { randomBytes } from "node:crypto";
2
+
3
+ //#region ../../packages/devtools/src/production/errors.ts
4
+ /**
5
+ * Why production mode refused to start. Each code names one missing or
6
+ * invalid setting; the message says which and how to fix it.
7
+ */
8
+ const DEVTOOLS_CONFIG_CODES = {
9
+ DT001: "Devtools production mode needs a dashboard path. Set DEVTOOLS_PATH (for example /ops-7f3k2q) or devtools.production.path.",
10
+ DT002: "The devtools dashboard path must start with \"/\", be at least 8 characters, use only letters, digits, \"-\", \"_\", \".\", \"~\" and \"/\", and not be \"/__warlock\".",
11
+ DT003: "Devtools production mode has no admin yet. Set DEVTOOLS_ADMIN_EMAIL with DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin --email <email>`.",
12
+ DT004: "DEVTOOLS_ADMIN_PASSWORD does not meet the password rules (at least 8 characters, at most 72 bytes, not a common password, not the email). Choose another one.",
13
+ DT005: "Devtools production mode stores its accounts in the database. Install @warlock.js/cascade and configure a database connection.",
14
+ DT006: "Devtools production mode encrypts two-factor secrets with the app key. Set encryption.key (64 hex characters) in src/config/encryption.ts.",
15
+ DT007: "A devtools production option has an invalid value. The message names the option and the accepted values.",
16
+ DT008: "The devtools tables are missing. Add devtoolsMigrations from @warlock.js/devtools/production to database.migrations in warlock.config.ts and run `warlock migrate`.",
17
+ DT009: "Set either DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, not both.",
18
+ DT010: "DEVTOOLS_SETUP_TOKEN must be at least 32 characters. Generate one with: openssl rand -base64 32"
19
+ };
20
+ /**
21
+ * Thrown while the devtools connector boots in production when the monitor is
22
+ * enabled but cannot start safely. It stops the app from booting, so a
23
+ * misconfigured deploy fails at once instead of serving an unprotected
24
+ * dashboard.
25
+ */
26
+ var DevtoolsProductionConfigError = class extends Error {
27
+ constructor(code, detail) {
28
+ super(`[${code}] ${detail ? `${detail} ` : ""}${DEVTOOLS_CONFIG_CODES[code]}`);
29
+ this.name = "DevtoolsProductionConfigError";
30
+ this.code = code;
31
+ }
32
+ };
33
+ /** The message every API error code answers with: what failed and what to do next. */
34
+ const DEVTOOLS_ERROR_MESSAGES = {
35
+ "auth.invalid-credentials": "The email or password is not correct. Check both and try again; after several failed tries, wait 15 minutes.",
36
+ "auth.invalid-code": "The code is not correct or has expired. Enter the current 6-digit code from your authenticator app, or a recovery code.",
37
+ "auth.invalid-setup-token": "This setup link is not valid. Use the link built from DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin`.",
38
+ "auth.password-too-short": "Use a password of at least 8 characters.",
39
+ "auth.password-too-long": "Use a password of at most 72 bytes (about 72 letters).",
40
+ "auth.password-common": "This password is too common. Choose one that is harder to guess.",
41
+ "auth.password-same-as-email": "The password must not be your email address. Choose another one.",
42
+ "auth.password-unchanged": "Choose a new password that differs from the current one.",
43
+ "auth.wrong-current-password": "The current password is not correct. Enter it again.",
44
+ "auth.busy": "The server is busy checking other sign-ins. Wait a few seconds and try again.",
45
+ "invite.invalid": "This invite link is not valid, was already used, or has expired. Ask an admin for a new one.",
46
+ "invite.email-taken": "An account with this email already exists. Sign in instead.",
47
+ "account.not-found": "This account no longer exists. Reload the list.",
48
+ "account.last-admin": "This is the last admin. Make another account an admin first.",
49
+ "account.self": "You cannot do this to your own account. Ask another admin.",
50
+ "account.last-factor": "This is your only second factor. Add another one (an authenticator app or a passkey) before removing it.",
51
+ "role.forbidden": "Only admins can do this. Ask an admin.",
52
+ "csrf.invalid": "This page is out of date. Reload the dashboard and try again.",
53
+ "passkey.unavailable": "Passkeys are not available on this server (the @simplewebauthn/server package is not installed). Use an authenticator app instead.",
54
+ "passkey.failed": "The passkey could not be verified. Try again, or use your authenticator app.",
55
+ "explain.not-allowed": "Only admins can run EXPLAIN. Ask an admin.",
56
+ "explain.unsupported": "This query cannot be explained: only PostgreSQL SELECT/WITH queries and MongoDB find, aggregate and count commands can.",
57
+ "explain.elsewhere": "Only the instance that ran this query can explain it, and this request reached another one. Try again later or from that instance.",
58
+ "explain.failed": "The database could not explain this query. The reference is in the server log.",
59
+ "request.not-found": "This request is no longer stored. Requests are kept for a limited time (24 hours by default).",
60
+ "request.invalid-filter": "A filter value is not valid. Check the status, method and dates.",
61
+ "stream.too-many": "Too many live views are open for this session. Close another dashboard tab and reload.",
62
+ "input.invalid": "Some fields are missing or not valid. Check the form and try again.",
63
+ "server.error": "The dashboard could not complete this action. Try again; if it keeps failing, give your admin the reference shown."
64
+ };
65
+ /** The HTTP status each code answers with. */
66
+ const DEVTOOLS_ERROR_STATUS = {
67
+ "auth.invalid-credentials": 401,
68
+ "auth.invalid-code": 401,
69
+ "auth.invalid-setup-token": 401,
70
+ "auth.password-too-short": 422,
71
+ "auth.password-too-long": 422,
72
+ "auth.password-common": 422,
73
+ "auth.password-same-as-email": 422,
74
+ "auth.password-unchanged": 422,
75
+ "auth.wrong-current-password": 401,
76
+ "auth.busy": 503,
77
+ "invite.invalid": 410,
78
+ "invite.email-taken": 409,
79
+ "account.not-found": 404,
80
+ "account.last-admin": 409,
81
+ "account.self": 409,
82
+ "account.last-factor": 409,
83
+ "role.forbidden": 403,
84
+ "csrf.invalid": 403,
85
+ "passkey.unavailable": 501,
86
+ "passkey.failed": 401,
87
+ "explain.not-allowed": 403,
88
+ "explain.unsupported": 400,
89
+ "explain.elsewhere": 409,
90
+ "explain.failed": 502,
91
+ "request.not-found": 404,
92
+ "request.invalid-filter": 400,
93
+ "stream.too-many": 429,
94
+ "input.invalid": 422,
95
+ "server.error": 500
96
+ };
97
+ /** A short reference id (8 characters, base32 alphabet) to quote to support. */
98
+ function createErrorRef() {
99
+ const alphabet = "ABCDEFGHJKMNPQRSTUVWXYZ23456789";
100
+ const bytes = randomBytes(8);
101
+ let ref = "";
102
+ for (const byte of bytes) ref += alphabet[byte % 31];
103
+ return ref;
104
+ }
105
+ /**
106
+ * An error a dashboard route answers with. The production error handler turns
107
+ * it into `{ error, code, ref?, instance? }` with `statusCode`.
108
+ */
109
+ var DevtoolsApiError = class extends Error {
110
+ constructor(code, options = {}) {
111
+ super(DEVTOOLS_ERROR_MESSAGES[code], options.cause === void 0 ? {} : { cause: options.cause });
112
+ this.name = "DevtoolsApiError";
113
+ this.code = code;
114
+ this.statusCode = DEVTOOLS_ERROR_STATUS[code];
115
+ this.ref = options.ref;
116
+ this.instance = options.instance;
117
+ }
118
+ /** The JSON body this error answers with. */
119
+ toBody() {
120
+ return {
121
+ error: this.message,
122
+ code: this.code,
123
+ ...this.ref === void 0 ? {} : { ref: this.ref },
124
+ ...this.instance === void 0 ? {} : { instance: this.instance }
125
+ };
126
+ }
127
+ };
128
+ /**
129
+ * Raised by a store when a unique value is taken (an email) so callers can
130
+ * answer with their own error code.
131
+ */
132
+ var DevtoolsStoreConflictError = class extends Error {
133
+ constructor(field) {
134
+ super(`A devtools record with this ${field} already exists.`);
135
+ this.field = field;
136
+ this.name = "DevtoolsStoreConflictError";
137
+ }
138
+ };
139
+
140
+ //#endregion
141
+ export { DEVTOOLS_CONFIG_CODES, DEVTOOLS_ERROR_MESSAGES, DEVTOOLS_ERROR_STATUS, DevtoolsApiError, DevtoolsProductionConfigError, DevtoolsStoreConflictError, createErrorRef };
142
+ //# sourceMappingURL=errors.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.mjs","names":[],"sources":["../../../../../../../../packages/devtools/src/production/errors.ts"],"sourcesContent":["import { randomBytes } from \"node:crypto\";\nimport type { DevtoolsApiErrorBody, DevtoolsErrorCode } from \"./contracts\";\n\n/**\n * Why production mode refused to start. Each code names one missing or\n * invalid setting; the message says which and how to fix it.\n */\nexport const DEVTOOLS_CONFIG_CODES = {\n DT001:\n \"Devtools production mode needs a dashboard path. Set DEVTOOLS_PATH (for example /ops-7f3k2q) or devtools.production.path.\",\n DT002:\n 'The devtools dashboard path must start with \"/\", be at least 8 characters, use only letters, digits, \"-\", \"_\", \".\", \"~\" and \"/\", and not be \"/__warlock\".',\n DT003:\n \"Devtools production mode has no admin yet. Set DEVTOOLS_ADMIN_EMAIL with DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin --email <email>`.\",\n DT004:\n \"DEVTOOLS_ADMIN_PASSWORD does not meet the password rules (at least 8 characters, at most 72 bytes, not a common password, not the email). Choose another one.\",\n DT005:\n \"Devtools production mode stores its accounts in the database. Install @warlock.js/cascade and configure a database connection.\",\n DT006:\n \"Devtools production mode encrypts two-factor secrets with the app key. Set encryption.key (64 hex characters) in src/config/encryption.ts.\",\n DT007:\n \"A devtools production option has an invalid value. The message names the option and the accepted values.\",\n DT008:\n \"The devtools tables are missing. Add devtoolsMigrations from @warlock.js/devtools/production to database.migrations in warlock.config.ts and run `warlock migrate`.\",\n DT009: \"Set either DEVTOOLS_ADMIN_PASSWORD or DEVTOOLS_SETUP_TOKEN, not both.\",\n DT010:\n \"DEVTOOLS_SETUP_TOKEN must be at least 32 characters. Generate one with: openssl rand -base64 32\",\n} as const;\n\n/** A production configuration error code (`DT001`–`DT010`). */\nexport type DevtoolsConfigCode = keyof typeof DEVTOOLS_CONFIG_CODES;\n\n/**\n * Thrown while the devtools connector boots in production when the monitor is\n * enabled but cannot start safely. It stops the app from booting, so a\n * misconfigured deploy fails at once instead of serving an unprotected\n * dashboard.\n */\nexport class DevtoolsProductionConfigError extends Error {\n public readonly code: DevtoolsConfigCode;\n\n public constructor(code: DevtoolsConfigCode, detail?: string) {\n super(`[${code}] ${detail ? `${detail} ` : \"\"}${DEVTOOLS_CONFIG_CODES[code]}`);\n this.name = \"DevtoolsProductionConfigError\";\n this.code = code;\n }\n}\n\n/** The message every API error code answers with: what failed and what to do next. */\nexport const DEVTOOLS_ERROR_MESSAGES: Record<DevtoolsErrorCode, string> = {\n \"auth.invalid-credentials\":\n \"The email or password is not correct. Check both and try again; after several failed tries, wait 15 minutes.\",\n \"auth.invalid-code\":\n \"The code is not correct or has expired. Enter the current 6-digit code from your authenticator app, or a recovery code.\",\n \"auth.invalid-setup-token\":\n \"This setup link is not valid. Use the link built from DEVTOOLS_SETUP_TOKEN, or run `warlock devtools:reset-admin`.\",\n \"auth.password-too-short\": \"Use a password of at least 8 characters.\",\n \"auth.password-too-long\": \"Use a password of at most 72 bytes (about 72 letters).\",\n \"auth.password-common\": \"This password is too common. Choose one that is harder to guess.\",\n \"auth.password-same-as-email\": \"The password must not be your email address. Choose another one.\",\n \"auth.password-unchanged\": \"Choose a new password that differs from the current one.\",\n \"auth.wrong-current-password\": \"The current password is not correct. Enter it again.\",\n \"auth.busy\": \"The server is busy checking other sign-ins. Wait a few seconds and try again.\",\n \"invite.invalid\":\n \"This invite link is not valid, was already used, or has expired. Ask an admin for a new one.\",\n \"invite.email-taken\": \"An account with this email already exists. Sign in instead.\",\n \"account.not-found\": \"This account no longer exists. Reload the list.\",\n \"account.last-admin\": \"This is the last admin. Make another account an admin first.\",\n \"account.self\": \"You cannot do this to your own account. Ask another admin.\",\n \"account.last-factor\":\n \"This is your only second factor. Add another one (an authenticator app or a passkey) before removing it.\",\n \"role.forbidden\": \"Only admins can do this. Ask an admin.\",\n \"csrf.invalid\": \"This page is out of date. Reload the dashboard and try again.\",\n \"passkey.unavailable\":\n \"Passkeys are not available on this server (the @simplewebauthn/server package is not installed). Use an authenticator app instead.\",\n \"passkey.failed\": \"The passkey could not be verified. Try again, or use your authenticator app.\",\n \"explain.not-allowed\": \"Only admins can run EXPLAIN. Ask an admin.\",\n \"explain.unsupported\":\n \"This query cannot be explained: only PostgreSQL SELECT/WITH queries and MongoDB find, aggregate and count commands can.\",\n \"explain.elsewhere\":\n \"Only the instance that ran this query can explain it, and this request reached another one. Try again later or from that instance.\",\n \"explain.failed\":\n \"The database could not explain this query. The reference is in the server log.\",\n \"request.not-found\":\n \"This request is no longer stored. Requests are kept for a limited time (24 hours by default).\",\n \"request.invalid-filter\": \"A filter value is not valid. Check the status, method and dates.\",\n \"stream.too-many\":\n \"Too many live views are open for this session. Close another dashboard tab and reload.\",\n \"input.invalid\": \"Some fields are missing or not valid. Check the form and try again.\",\n \"server.error\":\n \"The dashboard could not complete this action. Try again; if it keeps failing, give your admin the reference shown.\",\n};\n\n/** The HTTP status each code answers with. */\nexport const DEVTOOLS_ERROR_STATUS: Record<DevtoolsErrorCode, number> = {\n \"auth.invalid-credentials\": 401,\n \"auth.invalid-code\": 401,\n \"auth.invalid-setup-token\": 401,\n \"auth.password-too-short\": 422,\n \"auth.password-too-long\": 422,\n \"auth.password-common\": 422,\n \"auth.password-same-as-email\": 422,\n \"auth.password-unchanged\": 422,\n \"auth.wrong-current-password\": 401,\n \"auth.busy\": 503,\n \"invite.invalid\": 410,\n \"invite.email-taken\": 409,\n \"account.not-found\": 404,\n \"account.last-admin\": 409,\n \"account.self\": 409,\n \"account.last-factor\": 409,\n \"role.forbidden\": 403,\n \"csrf.invalid\": 403,\n \"passkey.unavailable\": 501,\n \"passkey.failed\": 401,\n \"explain.not-allowed\": 403,\n \"explain.unsupported\": 400,\n \"explain.elsewhere\": 409,\n \"explain.failed\": 502,\n \"request.not-found\": 404,\n \"request.invalid-filter\": 400,\n \"stream.too-many\": 429,\n \"input.invalid\": 422,\n \"server.error\": 500,\n};\n\n/** A short reference id (8 characters, base32 alphabet) to quote to support. */\nexport function createErrorRef(): string {\n const alphabet = \"ABCDEFGHJKMNPQRSTUVWXYZ23456789\";\n const bytes = randomBytes(8);\n let ref = \"\";\n\n for (const byte of bytes) ref += alphabet[byte % alphabet.length];\n\n return ref;\n}\n\n/**\n * An error a dashboard route answers with. The production error handler turns\n * it into `{ error, code, ref?, instance? }` with `statusCode`.\n */\nexport class DevtoolsApiError extends Error {\n public readonly code: DevtoolsErrorCode;\n public readonly statusCode: number;\n public readonly ref: string | undefined;\n public readonly instance: string | undefined;\n\n public constructor(\n code: DevtoolsErrorCode,\n options: { ref?: string; instance?: string; cause?: unknown } = {},\n ) {\n super(\n DEVTOOLS_ERROR_MESSAGES[code],\n options.cause === undefined ? {} : { cause: options.cause },\n );\n this.name = \"DevtoolsApiError\";\n this.code = code;\n this.statusCode = DEVTOOLS_ERROR_STATUS[code];\n this.ref = options.ref;\n this.instance = options.instance;\n }\n\n /** The JSON body this error answers with. */\n public toBody(): DevtoolsApiErrorBody {\n return {\n error: this.message,\n code: this.code,\n ...(this.ref === undefined ? {} : { ref: this.ref }),\n ...(this.instance === undefined ? {} : { instance: this.instance }),\n };\n }\n}\n\n/**\n * Raised by a store when a unique value is taken (an email) so callers can\n * answer with their own error code.\n */\nexport class DevtoolsStoreConflictError extends Error {\n public constructor(public readonly field: string) {\n super(`A devtools record with this ${field} already exists.`);\n this.name = \"DevtoolsStoreConflictError\";\n }\n}\n"],"mappings":";;;;;;;AAOA,MAAa,wBAAwB;CACnC,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OACE;CACF,OAAO;CACP,OACE;AACJ;;;;;;;AAWA,IAAa,gCAAb,cAAmD,MAAM;CAGvD,AAAO,YAAY,MAA0B,QAAiB;EAC5D,MAAM,IAAI,KAAK,IAAI,SAAS,GAAG,OAAO,KAAK,KAAK,sBAAsB,OAAO;EAC7E,KAAK,OAAO;EACZ,KAAK,OAAO;CACd;AACF;;AAGA,MAAa,0BAA6D;CACxE,4BACE;CACF,qBACE;CACF,4BACE;CACF,2BAA2B;CAC3B,0BAA0B;CAC1B,wBAAwB;CACxB,+BAA+B;CAC/B,2BAA2B;CAC3B,+BAA+B;CAC/B,aAAa;CACb,kBACE;CACF,sBAAsB;CACtB,qBAAqB;CACrB,sBAAsB;CACtB,gBAAgB;CAChB,uBACE;CACF,kBAAkB;CAClB,gBAAgB;CAChB,uBACE;CACF,kBAAkB;CAClB,uBAAuB;CACvB,uBACE;CACF,qBACE;CACF,kBACE;CACF,qBACE;CACF,0BAA0B;CAC1B,mBACE;CACF,iBAAiB;CACjB,gBACE;AACJ;;AAGA,MAAa,wBAA2D;CACtE,4BAA4B;CAC5B,qBAAqB;CACrB,4BAA4B;CAC5B,2BAA2B;CAC3B,0BAA0B;CAC1B,wBAAwB;CACxB,+BAA+B;CAC/B,2BAA2B;CAC3B,+BAA+B;CAC/B,aAAa;CACb,kBAAkB;CAClB,sBAAsB;CACtB,qBAAqB;CACrB,sBAAsB;CACtB,gBAAgB;CAChB,uBAAuB;CACvB,kBAAkB;CAClB,gBAAgB;CAChB,uBAAuB;CACvB,kBAAkB;CAClB,uBAAuB;CACvB,uBAAuB;CACvB,qBAAqB;CACrB,kBAAkB;CAClB,qBAAqB;CACrB,0BAA0B;CAC1B,mBAAmB;CACnB,iBAAiB;CACjB,gBAAgB;AAClB;;AAGA,SAAgB,iBAAyB;CACvC,MAAM,WAAW;CACjB,MAAM,QAAQ,YAAY,CAAC;CAC3B,IAAI,MAAM;CAEV,KAAK,MAAM,QAAQ,OAAO,OAAO,SAAS,OAAO;CAEjD,OAAO;AACT;;;;;AAMA,IAAa,mBAAb,cAAsC,MAAM;CAM1C,AAAO,YACL,MACA,UAAgE,CAAC,GACjE;EACA,MACE,wBAAwB,OACxB,QAAQ,UAAU,SAAY,CAAC,IAAI,EAAE,OAAO,QAAQ,MAAM,CAC5D;EACA,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,aAAa,sBAAsB;EACxC,KAAK,MAAM,QAAQ;EACnB,KAAK,WAAW,QAAQ;CAC1B;;CAGA,AAAO,SAA+B;EACpC,OAAO;GACL,OAAO,KAAK;GACZ,MAAM,KAAK;GACX,GAAI,KAAK,QAAQ,SAAY,CAAC,IAAI,EAAE,KAAK,KAAK,IAAI;GAClD,GAAI,KAAK,aAAa,SAAY,CAAC,IAAI,EAAE,UAAU,KAAK,SAAS;EACnE;CACF;AACF;;;;;AAMA,IAAa,6BAAb,cAAgD,MAAM;CACpD,AAAO,YAAY,AAAgB,OAAe;EAChD,MAAM,+BAA+B,MAAM,iBAAiB;EAD3B;EAEjC,KAAK,OAAO;CACd;AACF"}
@@ -0,0 +1,124 @@
1
+ //#region ../../packages/devtools/src/production/http/access.ts
2
+ const PUBLIC = { type: "public" };
3
+ const VIEWER = { type: "viewer" };
4
+ const ADMIN = { type: "admin" };
5
+ const pending = (...stages) => ({
6
+ type: "pending",
7
+ stages
8
+ });
9
+ const ALL_STEPS = [
10
+ "password-change",
11
+ "mfa-enrol",
12
+ "mfa-verify"
13
+ ];
14
+ /**
15
+ * The access table: every production route, its method and who may call it.
16
+ * A route with no entry is `admin` (fail closed). A package panel `<id>`
17
+ * gets `GET /api/<id>` and `GET /api/<id>/*` for viewers and every other
18
+ * method there for admins, audited as `panel.action`; a url ending in `/*`
19
+ * matches every pattern below it.
20
+ */
21
+ function productionRouteAccess(panelIds) {
22
+ const rule = (method, url, access, audit) => ({
23
+ method,
24
+ url,
25
+ access,
26
+ ...audit ? { audit } : {}
27
+ });
28
+ const rules = [
29
+ rule("GET", "/", PUBLIC),
30
+ rule("GET", "/assets/:name", PUBLIC),
31
+ rule("GET", "/api/auth/session", PUBLIC),
32
+ rule("POST", "/api/auth/login", PUBLIC),
33
+ rule("POST", "/api/auth/setup", PUBLIC),
34
+ rule("POST", "/api/auth/invite/inspect", PUBLIC),
35
+ rule("POST", "/api/auth/invite/accept", PUBLIC),
36
+ rule("POST", "/api/auth/password", pending("password-change")),
37
+ rule("POST", "/api/auth/totp/start", pending("mfa-enrol")),
38
+ rule("POST", "/api/auth/totp/confirm", pending("mfa-enrol")),
39
+ rule("POST", "/api/auth/passkey/options", pending("mfa-enrol", "mfa-verify")),
40
+ rule("POST", "/api/auth/passkey/verify", pending("mfa-enrol", "mfa-verify")),
41
+ rule("POST", "/api/auth/mfa", pending("mfa-verify")),
42
+ rule("POST", "/api/auth/logout", pending(...ALL_STEPS)),
43
+ rule("GET", "/api/panels", VIEWER),
44
+ rule("GET", "/api/account", VIEWER),
45
+ rule("GET", "/api/account/sessions", VIEWER),
46
+ rule("DELETE", "/api/account/sessions/:id", VIEWER),
47
+ rule("POST", "/api/account/password", VIEWER),
48
+ rule("POST", "/api/account/totp/start", VIEWER),
49
+ rule("POST", "/api/account/totp/confirm", VIEWER),
50
+ rule("DELETE", "/api/account/totp", VIEWER),
51
+ rule("POST", "/api/account/recovery-codes", VIEWER),
52
+ rule("POST", "/api/account/passkey/options", VIEWER),
53
+ rule("POST", "/api/account/passkey/verify", VIEWER),
54
+ rule("DELETE", "/api/account/passkeys/:id", VIEWER),
55
+ rule("GET", "/api/admin/users", ADMIN),
56
+ rule("POST", "/api/admin/invites", ADMIN),
57
+ rule("DELETE", "/api/admin/invites/:id", ADMIN),
58
+ rule("PATCH", "/api/admin/users/:id", ADMIN),
59
+ rule("DELETE", "/api/admin/users/:id", ADMIN),
60
+ rule("POST", "/api/admin/users/:id/reset-mfa", ADMIN),
61
+ rule("POST", "/api/admin/users/:id/sign-out", ADMIN),
62
+ rule("GET", "/api/admin/audit", ADMIN),
63
+ rule("POST", "/api/admin/disable", ADMIN),
64
+ rule("GET", "/api/stream", VIEWER),
65
+ rule("GET", "/api/instances", VIEWER),
66
+ rule("GET", "/api/resources", VIEWER),
67
+ rule("GET", "/api/queries/stats", VIEWER),
68
+ rule("GET", "/api/routes/stats", VIEWER),
69
+ rule("GET", "/api/health", VIEWER),
70
+ rule("GET", "/api/errors", VIEWER),
71
+ rule("GET", "/api/jobs", VIEWER),
72
+ rule("GET", "/api/logs", VIEWER),
73
+ rule("GET", "/api/requests", VIEWER),
74
+ rule("GET", "/api/requests/:id", VIEWER),
75
+ rule("GET", "/api/requests/:id/curl", VIEWER),
76
+ rule("DELETE", "/api/requests", ADMIN, "requests.cleared"),
77
+ rule("POST", "/api/queries/:shapeId/explain", ADMIN, "explain.run"),
78
+ rule("GET", "/api/routes", VIEWER),
79
+ rule("GET", "/panels/:id/:name", VIEWER),
80
+ rule("GET", "/api/mails", VIEWER),
81
+ rule("GET", "/api/mails/:id", VIEWER),
82
+ rule("GET", "/api/mails/:id/html", VIEWER),
83
+ rule("GET", "/api/ai", VIEWER),
84
+ rule("GET", "/api/ai/agent-runs", VIEWER),
85
+ rule("GET", "/api/ai/agent-runs/:id", VIEWER),
86
+ rule("GET", "/api/ai/runs/:id", VIEWER),
87
+ rule("GET", "/api/openapi.json", VIEWER),
88
+ rule("GET", "/api/postman.json", VIEWER),
89
+ rule("GET", "/docs", VIEWER),
90
+ rule("GET", "/docs/swagger", VIEWER)
91
+ ];
92
+ for (const id of panelIds) {
93
+ rules.push(rule("GET", `/api/${id}`, VIEWER), rule("GET", `/api/${id}/*`, VIEWER));
94
+ for (const method of [
95
+ "POST",
96
+ "PUT",
97
+ "PATCH",
98
+ "DELETE"
99
+ ]) rules.push(rule(method, `/api/${id}`, ADMIN, "panel.action"), rule(method, `/api/${id}/*`, ADMIN, "panel.action"));
100
+ }
101
+ return rules;
102
+ }
103
+ /** Looks routes up by method and URL pattern: exact first, then the longest `/*` prefix. */
104
+ function createAccessLookup(rules) {
105
+ const exact = /* @__PURE__ */ new Map();
106
+ const wildcards = [];
107
+ for (const rule of rules) if (rule.url.endsWith("/*")) wildcards.push({
108
+ method: rule.method,
109
+ prefix: rule.url.slice(0, -1),
110
+ rule
111
+ });
112
+ else exact.set(`${rule.method} ${rule.url}`, rule);
113
+ wildcards.sort((a, b) => b.prefix.length - a.prefix.length);
114
+ return (method, pattern) => {
115
+ const verb = method === "HEAD" ? "GET" : method;
116
+ const found = exact.get(`${verb} ${pattern}`);
117
+ if (found) return found;
118
+ return wildcards.find((item) => item.method === verb && pattern.startsWith(item.prefix))?.rule;
119
+ };
120
+ }
121
+
122
+ //#endregion
123
+ export { createAccessLookup, productionRouteAccess };
124
+ //# sourceMappingURL=access.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/access.ts"],"sourcesContent":["import type { DevtoolsRouteAccess, DevtoolsRouteAccessRule } from \"./types\";\n\ntype Method = DevtoolsRouteAccessRule[\"method\"];\n\nconst PUBLIC: DevtoolsRouteAccess = { type: \"public\" };\nconst VIEWER: DevtoolsRouteAccess = { type: \"viewer\" };\nconst ADMIN: DevtoolsRouteAccess = { type: \"admin\" };\n\nconst pending = (...stages: Extract<DevtoolsRouteAccess, { type: \"pending\" }>[\"stages\"]) =>\n ({ type: \"pending\", stages }) satisfies DevtoolsRouteAccess;\n\nconst ALL_STEPS = [\"password-change\", \"mfa-enrol\", \"mfa-verify\"] as const;\n\n/**\n * The access table: every production route, its method and who may call it.\n * A route with no entry is `admin` (fail closed). A package panel `<id>`\n * gets `GET /api/<id>` and `GET /api/<id>/*` for viewers and every other\n * method there for admins, audited as `panel.action`; a url ending in `/*`\n * matches every pattern below it.\n */\nexport function productionRouteAccess(panelIds: readonly string[]): DevtoolsRouteAccessRule[] {\n const rule = (\n method: Method,\n url: string,\n access: DevtoolsRouteAccess,\n audit?: DevtoolsRouteAccessRule[\"audit\"],\n ): DevtoolsRouteAccessRule => ({ method, url, access, ...(audit ? { audit } : {}) });\n\n const rules: DevtoolsRouteAccessRule[] = [\n // The shell and its sign-in steps.\n rule(\"GET\", \"/\", PUBLIC),\n rule(\"GET\", \"/assets/:name\", PUBLIC),\n rule(\"GET\", \"/api/auth/session\", PUBLIC),\n rule(\"POST\", \"/api/auth/login\", PUBLIC),\n rule(\"POST\", \"/api/auth/setup\", PUBLIC),\n rule(\"POST\", \"/api/auth/invite/inspect\", PUBLIC),\n rule(\"POST\", \"/api/auth/invite/accept\", PUBLIC),\n rule(\"POST\", \"/api/auth/password\", pending(\"password-change\")),\n rule(\"POST\", \"/api/auth/totp/start\", pending(\"mfa-enrol\")),\n rule(\"POST\", \"/api/auth/totp/confirm\", pending(\"mfa-enrol\")),\n rule(\"POST\", \"/api/auth/passkey/options\", pending(\"mfa-enrol\", \"mfa-verify\")),\n rule(\"POST\", \"/api/auth/passkey/verify\", pending(\"mfa-enrol\", \"mfa-verify\")),\n rule(\"POST\", \"/api/auth/mfa\", pending(\"mfa-verify\")),\n rule(\"POST\", \"/api/auth/logout\", pending(...ALL_STEPS)),\n\n // The signed-in account.\n rule(\"GET\", \"/api/panels\", VIEWER),\n rule(\"GET\", \"/api/account\", VIEWER),\n rule(\"GET\", \"/api/account/sessions\", VIEWER),\n rule(\"DELETE\", \"/api/account/sessions/:id\", VIEWER),\n rule(\"POST\", \"/api/account/password\", VIEWER),\n rule(\"POST\", \"/api/account/totp/start\", VIEWER),\n rule(\"POST\", \"/api/account/totp/confirm\", VIEWER),\n rule(\"DELETE\", \"/api/account/totp\", VIEWER),\n rule(\"POST\", \"/api/account/recovery-codes\", VIEWER),\n rule(\"POST\", \"/api/account/passkey/options\", VIEWER),\n rule(\"POST\", \"/api/account/passkey/verify\", VIEWER),\n rule(\"DELETE\", \"/api/account/passkeys/:id\", VIEWER),\n\n // Administration.\n rule(\"GET\", \"/api/admin/users\", ADMIN),\n rule(\"POST\", \"/api/admin/invites\", ADMIN),\n rule(\"DELETE\", \"/api/admin/invites/:id\", ADMIN),\n rule(\"PATCH\", \"/api/admin/users/:id\", ADMIN),\n rule(\"DELETE\", \"/api/admin/users/:id\", ADMIN),\n rule(\"POST\", \"/api/admin/users/:id/reset-mfa\", ADMIN),\n rule(\"POST\", \"/api/admin/users/:id/sign-out\", ADMIN),\n rule(\"GET\", \"/api/admin/audit\", ADMIN),\n rule(\"POST\", \"/api/admin/disable\", ADMIN),\n\n // Data.\n rule(\"GET\", \"/api/stream\", VIEWER),\n rule(\"GET\", \"/api/instances\", VIEWER),\n rule(\"GET\", \"/api/resources\", VIEWER),\n rule(\"GET\", \"/api/queries/stats\", VIEWER),\n rule(\"GET\", \"/api/routes/stats\", VIEWER),\n rule(\"GET\", \"/api/health\", VIEWER),\n rule(\"GET\", \"/api/errors\", VIEWER),\n rule(\"GET\", \"/api/jobs\", VIEWER),\n rule(\"GET\", \"/api/logs\", VIEWER),\n rule(\"GET\", \"/api/requests\", VIEWER),\n rule(\"GET\", \"/api/requests/:id\", VIEWER),\n rule(\"GET\", \"/api/requests/:id/curl\", VIEWER),\n rule(\"DELETE\", \"/api/requests\", ADMIN, \"requests.cleared\"),\n rule(\"POST\", \"/api/queries/:shapeId/explain\", ADMIN, \"explain.run\"),\n rule(\"GET\", \"/api/routes\", VIEWER),\n rule(\"GET\", \"/panels/:id/:name\", VIEWER),\n\n // Tabs that are off unless the project turns them on.\n rule(\"GET\", \"/api/mails\", VIEWER),\n rule(\"GET\", \"/api/mails/:id\", VIEWER),\n rule(\"GET\", \"/api/mails/:id/html\", VIEWER),\n rule(\"GET\", \"/api/ai\", VIEWER),\n rule(\"GET\", \"/api/ai/agent-runs\", VIEWER),\n rule(\"GET\", \"/api/ai/agent-runs/:id\", VIEWER),\n rule(\"GET\", \"/api/ai/runs/:id\", VIEWER),\n rule(\"GET\", \"/api/openapi.json\", VIEWER),\n rule(\"GET\", \"/api/postman.json\", VIEWER),\n rule(\"GET\", \"/docs\", VIEWER),\n rule(\"GET\", \"/docs/swagger\", VIEWER),\n ];\n\n for (const id of panelIds) {\n rules.push(rule(\"GET\", `/api/${id}`, VIEWER), rule(\"GET\", `/api/${id}/*`, VIEWER));\n\n for (const method of [\"POST\", \"PUT\", \"PATCH\", \"DELETE\"] as const) {\n rules.push(\n rule(method, `/api/${id}`, ADMIN, \"panel.action\"),\n rule(method, `/api/${id}/*`, ADMIN, \"panel.action\"),\n );\n }\n }\n\n return rules;\n}\n\n/** Looks routes up by method and URL pattern: exact first, then the longest `/*` prefix. */\nexport function createAccessLookup(\n rules: readonly DevtoolsRouteAccessRule[],\n): (method: string, pattern: string) => DevtoolsRouteAccessRule | undefined {\n const exact = new Map<string, DevtoolsRouteAccessRule>();\n const wildcards: { method: Method; prefix: string; rule: DevtoolsRouteAccessRule }[] = [];\n\n for (const rule of rules) {\n if (rule.url.endsWith(\"/*\")) {\n wildcards.push({ method: rule.method, prefix: rule.url.slice(0, -1), rule });\n } else {\n exact.set(`${rule.method} ${rule.url}`, rule);\n }\n }\n\n wildcards.sort((a, b) => b.prefix.length - a.prefix.length);\n\n return (method, pattern) => {\n // A HEAD request is answered by the GET route.\n const verb = method === \"HEAD\" ? \"GET\" : method;\n const found = exact.get(`${verb} ${pattern}`);\n\n if (found) return found;\n\n return wildcards.find((item) => item.method === verb && pattern.startsWith(item.prefix))?.rule;\n };\n}\n"],"mappings":";AAIA,MAAM,SAA8B,EAAE,MAAM,SAAS;AACrD,MAAM,SAA8B,EAAE,MAAM,SAAS;AACrD,MAAM,QAA6B,EAAE,MAAM,QAAQ;AAEnD,MAAM,WAAW,GAAG,YACjB;CAAE,MAAM;CAAW;AAAO;AAE7B,MAAM,YAAY;CAAC;CAAmB;CAAa;AAAY;;;;;;;;AAS/D,SAAgB,sBAAsB,UAAwD;CAC5F,MAAM,QACJ,QACA,KACA,QACA,WAC6B;EAAE;EAAQ;EAAK;EAAQ,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;CAAG;CAElF,MAAM,QAAmC;EAEvC,KAAK,OAAO,KAAK,MAAM;EACvB,KAAK,OAAO,iBAAiB,MAAM;EACnC,KAAK,OAAO,qBAAqB,MAAM;EACvC,KAAK,QAAQ,mBAAmB,MAAM;EACtC,KAAK,QAAQ,mBAAmB,MAAM;EACtC,KAAK,QAAQ,4BAA4B,MAAM;EAC/C,KAAK,QAAQ,2BAA2B,MAAM;EAC9C,KAAK,QAAQ,sBAAsB,QAAQ,iBAAiB,CAAC;EAC7D,KAAK,QAAQ,wBAAwB,QAAQ,WAAW,CAAC;EACzD,KAAK,QAAQ,0BAA0B,QAAQ,WAAW,CAAC;EAC3D,KAAK,QAAQ,6BAA6B,QAAQ,aAAa,YAAY,CAAC;EAC5E,KAAK,QAAQ,4BAA4B,QAAQ,aAAa,YAAY,CAAC;EAC3E,KAAK,QAAQ,iBAAiB,QAAQ,YAAY,CAAC;EACnD,KAAK,QAAQ,oBAAoB,QAAQ,GAAG,SAAS,CAAC;EAGtD,KAAK,OAAO,eAAe,MAAM;EACjC,KAAK,OAAO,gBAAgB,MAAM;EAClC,KAAK,OAAO,yBAAyB,MAAM;EAC3C,KAAK,UAAU,6BAA6B,MAAM;EAClD,KAAK,QAAQ,yBAAyB,MAAM;EAC5C,KAAK,QAAQ,2BAA2B,MAAM;EAC9C,KAAK,QAAQ,6BAA6B,MAAM;EAChD,KAAK,UAAU,qBAAqB,MAAM;EAC1C,KAAK,QAAQ,+BAA+B,MAAM;EAClD,KAAK,QAAQ,gCAAgC,MAAM;EACnD,KAAK,QAAQ,+BAA+B,MAAM;EAClD,KAAK,UAAU,6BAA6B,MAAM;EAGlD,KAAK,OAAO,oBAAoB,KAAK;EACrC,KAAK,QAAQ,sBAAsB,KAAK;EACxC,KAAK,UAAU,0BAA0B,KAAK;EAC9C,KAAK,SAAS,wBAAwB,KAAK;EAC3C,KAAK,UAAU,wBAAwB,KAAK;EAC5C,KAAK,QAAQ,kCAAkC,KAAK;EACpD,KAAK,QAAQ,iCAAiC,KAAK;EACnD,KAAK,OAAO,oBAAoB,KAAK;EACrC,KAAK,QAAQ,sBAAsB,KAAK;EAGxC,KAAK,OAAO,eAAe,MAAM;EACjC,KAAK,OAAO,kBAAkB,MAAM;EACpC,KAAK,OAAO,kBAAkB,MAAM;EACpC,KAAK,OAAO,sBAAsB,MAAM;EACxC,KAAK,OAAO,qBAAqB,MAAM;EACvC,KAAK,OAAO,eAAe,MAAM;EACjC,KAAK,OAAO,eAAe,MAAM;EACjC,KAAK,OAAO,aAAa,MAAM;EAC/B,KAAK,OAAO,aAAa,MAAM;EAC/B,KAAK,OAAO,iBAAiB,MAAM;EACnC,KAAK,OAAO,qBAAqB,MAAM;EACvC,KAAK,OAAO,0BAA0B,MAAM;EAC5C,KAAK,UAAU,iBAAiB,OAAO,kBAAkB;EACzD,KAAK,QAAQ,iCAAiC,OAAO,aAAa;EAClE,KAAK,OAAO,eAAe,MAAM;EACjC,KAAK,OAAO,qBAAqB,MAAM;EAGvC,KAAK,OAAO,cAAc,MAAM;EAChC,KAAK,OAAO,kBAAkB,MAAM;EACpC,KAAK,OAAO,uBAAuB,MAAM;EACzC,KAAK,OAAO,WAAW,MAAM;EAC7B,KAAK,OAAO,sBAAsB,MAAM;EACxC,KAAK,OAAO,0BAA0B,MAAM;EAC5C,KAAK,OAAO,oBAAoB,MAAM;EACtC,KAAK,OAAO,qBAAqB,MAAM;EACvC,KAAK,OAAO,qBAAqB,MAAM;EACvC,KAAK,OAAO,SAAS,MAAM;EAC3B,KAAK,OAAO,iBAAiB,MAAM;CACrC;CAEA,KAAK,MAAM,MAAM,UAAU;EACzB,MAAM,KAAK,KAAK,OAAO,QAAQ,MAAM,MAAM,GAAG,KAAK,OAAO,QAAQ,GAAG,KAAK,MAAM,CAAC;EAEjF,KAAK,MAAM,UAAU;GAAC;GAAQ;GAAO;GAAS;EAAQ,GACpD,MAAM,KACJ,KAAK,QAAQ,QAAQ,MAAM,OAAO,cAAc,GAChD,KAAK,QAAQ,QAAQ,GAAG,KAAK,OAAO,cAAc,CACpD;CAEJ;CAEA,OAAO;AACT;;AAGA,SAAgB,mBACd,OAC0E;CAC1E,MAAM,wBAAQ,IAAI,IAAqC;CACvD,MAAM,YAAiF,CAAC;CAExF,KAAK,MAAM,QAAQ,OACjB,IAAI,KAAK,IAAI,SAAS,IAAI,GACxB,UAAU,KAAK;EAAE,QAAQ,KAAK;EAAQ,QAAQ,KAAK,IAAI,MAAM,GAAG,EAAE;EAAG;CAAK,CAAC;MAE3E,MAAM,IAAI,GAAG,KAAK,OAAO,GAAG,KAAK,OAAO,IAAI;CAIhD,UAAU,MAAM,GAAG,MAAM,EAAE,OAAO,SAAS,EAAE,OAAO,MAAM;CAE1D,QAAQ,QAAQ,YAAY;EAE1B,MAAM,OAAO,WAAW,SAAS,QAAQ;EACzC,MAAM,QAAQ,MAAM,IAAI,GAAG,KAAK,GAAG,SAAS;EAE5C,IAAI,OAAO,OAAO;EAElB,OAAO,UAAU,MAAM,SAAS,KAAK,WAAW,QAAQ,QAAQ,WAAW,KAAK,MAAM,CAAC,CAAC,EAAE;CAC5F;AACF"}