@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,280 @@
1
+ import { DevtoolsApiError } from "../errors.mjs";
2
+ import { devtoolsRequestContext } from "./context.mjs";
3
+ import { readCookie, sessionCookie, sessionCookieName } from "./cookie.mjs";
4
+
5
+ //#region ../../packages/devtools/src/production/http/auth-routes.ts
6
+ const MAX_TEXT = 1024;
7
+ const MAX_EMAIL = 320;
8
+ const MAX_CODE = 128;
9
+ const MAX_TOKEN = 512;
10
+ const ROLES = ["admin", "viewer"];
11
+ /** A request body that is a plain JSON object, or `input.invalid`. */
12
+ function bodyOf(request) {
13
+ const body = request.body;
14
+ if (body === null || typeof body !== "object" || Array.isArray(body)) throw new DevtoolsApiError("input.invalid");
15
+ return body;
16
+ }
17
+ /** A non-empty string field no longer than `max`, or `input.invalid`. */
18
+ function text(body, key, max = MAX_TEXT) {
19
+ const value = body[key];
20
+ if (typeof value !== "string" || value === "" || value.length > max) throw new DevtoolsApiError("input.invalid");
21
+ return value;
22
+ }
23
+ /** An optional string field; `undefined` when absent, `input.invalid` when present but wrong. */
24
+ function optionalText(body, key, max = MAX_TEXT) {
25
+ return body[key] === void 0 ? void 0 : text(body, key, max);
26
+ }
27
+ function email(body) {
28
+ const value = text(body, "email", MAX_EMAIL).trim().toLowerCase();
29
+ if (!/^[^\s@]+@[^\s@]+$/.test(value)) throw new DevtoolsApiError("input.invalid");
30
+ return value;
31
+ }
32
+ function role(body) {
33
+ const value = body.role;
34
+ if (typeof value !== "string" || !ROLES.includes(value)) throw new DevtoolsApiError("input.invalid");
35
+ return value;
36
+ }
37
+ function purpose(body) {
38
+ const value = body.purpose;
39
+ if (value !== "register" && value !== "login") throw new DevtoolsApiError("input.invalid");
40
+ return value;
41
+ }
42
+ function idParam(request) {
43
+ const { id } = request.params ?? {};
44
+ if (typeof id !== "string" || id === "" || id.length > MAX_CODE) throw new DevtoolsApiError("input.invalid");
45
+ return id;
46
+ }
47
+ /** The `current` password of a request that may have no body (a DELETE). */
48
+ function currentOf(request) {
49
+ return request.body === void 0 || request.body === null ? void 0 : optionalText(bodyOf(request), "current");
50
+ }
51
+ /** What the gate stored, for a route that is never reached without it. */
52
+ function contextOf(request) {
53
+ const context = devtoolsRequestContext(request);
54
+ if (!context?.authenticated) throw new Error("A dashboard route ran without its session.");
55
+ return {
56
+ meta: context.meta,
57
+ auth: context.authenticated
58
+ };
59
+ }
60
+ function metaOf(request) {
61
+ const context = devtoolsRequestContext(request);
62
+ if (!context) throw new Error("A dashboard route ran without its request context.");
63
+ return context.meta;
64
+ }
65
+ /**
66
+ * Registers the sign-in, account and admin routes. All decisions live in the
67
+ * auth service; the handlers read the body, call it and answer. The gate
68
+ * (`mountProductionDevtools`) has already checked the session, role, origin
69
+ * and CSRF token by the time a handler runs.
70
+ */
71
+ function registerAuthRoutes(server, deps) {
72
+ const { auth, store, state, production } = deps;
73
+ const cookieOptions = {
74
+ path: production.path,
75
+ secure: production.requireHttps
76
+ };
77
+ /** Sets the new session cookie when the step minted one; answers the step. */
78
+ const answerStep = (reply, step, recoveryCodes) => {
79
+ if (step.token !== null) reply.header("set-cookie", sessionCookie(step.token, cookieOptions));
80
+ return {
81
+ stage: step.stage,
82
+ csrf: step.csrf,
83
+ ...recoveryCodes ? { recoveryCodes } : {}
84
+ };
85
+ };
86
+ /** The stage and CSRF token of the session in force, for answers that do not change it. */
87
+ const currentStep = (authenticated) => ({
88
+ stage: authenticated.stage,
89
+ csrf: auth.csrfToken(authenticated.session)
90
+ });
91
+ const clearCookie = (reply) => {
92
+ reply.header("set-cookie", sessionCookie(null, cookieOptions));
93
+ };
94
+ const requireAdmin = (authenticated) => {
95
+ if (authenticated.account.role !== "admin" || authenticated.stage !== "active") throw new DevtoolsApiError("role.forbidden");
96
+ };
97
+ server.get("/api/auth/session", async (request, reply) => {
98
+ const token = readCookie(request.headers.cookie, sessionCookieName(production.requireHttps));
99
+ const authenticated = token === void 0 ? null : await auth.authenticate(token);
100
+ if (token !== void 0 && authenticated === null) clearCookie(reply);
101
+ return auth.sessionView(authenticated);
102
+ });
103
+ server.post("/api/auth/login", async (request, reply) => {
104
+ const body = bodyOf(request);
105
+ const step = await auth.login({
106
+ email: email(body),
107
+ password: text(body, "password")
108
+ }, metaOf(request));
109
+ return answerStep(reply, step);
110
+ });
111
+ server.post("/api/auth/setup", async (request, reply) => {
112
+ const body = bodyOf(request);
113
+ const step = await auth.setup({
114
+ token: text(body, "token", MAX_TOKEN),
115
+ password: text(body, "password")
116
+ }, metaOf(request));
117
+ return answerStep(reply, step);
118
+ });
119
+ server.post("/api/auth/invite/inspect", async (request) => {
120
+ const body = bodyOf(request);
121
+ return auth.inspectInvite(text(body, "token", MAX_TOKEN));
122
+ });
123
+ server.post("/api/auth/invite/accept", async (request, reply) => {
124
+ const body = bodyOf(request);
125
+ const step = await auth.acceptInvite({
126
+ token: text(body, "token", MAX_TOKEN),
127
+ password: text(body, "password")
128
+ }, metaOf(request));
129
+ return answerStep(reply, step);
130
+ });
131
+ const changePassword = async (request, reply) => {
132
+ const { auth: authenticated, meta } = contextOf(request);
133
+ const body = bodyOf(request);
134
+ const current = optionalText(body, "current");
135
+ const step = await auth.changePassword(authenticated, {
136
+ ...current === void 0 ? {} : { current },
137
+ password: text(body, "password")
138
+ }, meta);
139
+ return answerStep(reply, step);
140
+ };
141
+ const startTotp = async (request) => {
142
+ const { auth: authenticated, meta } = contextOf(request);
143
+ return auth.startTotp(authenticated, meta);
144
+ };
145
+ const confirmTotp = async (request, reply) => {
146
+ const { auth: authenticated, meta } = contextOf(request);
147
+ const body = bodyOf(request);
148
+ const result = await auth.confirmTotp(authenticated, text(body, "code", MAX_CODE), meta, optionalText(body, "current"));
149
+ return answerStep(reply, result.step, result.recoveryCodes);
150
+ };
151
+ const passkeyOptions = async (request) => {
152
+ const { auth: authenticated, meta } = contextOf(request);
153
+ return auth.passkeyOptions(authenticated, purpose(bodyOf(request)), meta);
154
+ };
155
+ const passkeyVerify = async (request, reply) => {
156
+ const { auth: authenticated, meta } = contextOf(request);
157
+ const body = bodyOf(request);
158
+ if (body.response === null || typeof body.response !== "object") throw new DevtoolsApiError("input.invalid");
159
+ const result = await auth.verifyPasskey(authenticated, purpose(body), body.response, meta, optionalText(body, "current"));
160
+ if (result.step === null) return {
161
+ ...currentStep(authenticated),
162
+ ...result.recoveryCodes ? { recoveryCodes: result.recoveryCodes } : {}
163
+ };
164
+ return answerStep(reply, result.step, result.recoveryCodes);
165
+ };
166
+ server.post("/api/auth/password", changePassword);
167
+ server.post("/api/auth/totp/start", startTotp);
168
+ server.post("/api/auth/totp/confirm", confirmTotp);
169
+ server.post("/api/auth/passkey/options", passkeyOptions);
170
+ server.post("/api/auth/passkey/verify", passkeyVerify);
171
+ server.post("/api/auth/mfa", async (request, reply) => {
172
+ const { auth: authenticated, meta } = contextOf(request);
173
+ const body = bodyOf(request);
174
+ const code = optionalText(body, "code", MAX_CODE);
175
+ const recoveryCode = optionalText(body, "recoveryCode", MAX_CODE);
176
+ if (code === void 0 === (recoveryCode === void 0)) throw new DevtoolsApiError("input.invalid");
177
+ const step = await auth.verifySecondFactor(authenticated, code === void 0 ? { recoveryCode } : { code }, meta);
178
+ return answerStep(reply, step);
179
+ });
180
+ server.post("/api/auth/logout", async (request, reply) => {
181
+ const { auth: authenticated, meta } = contextOf(request);
182
+ await auth.logout(authenticated, meta);
183
+ clearCookie(reply);
184
+ return reply.code(204).send();
185
+ });
186
+ server.get("/api/account", async (request) => {
187
+ const { auth: authenticated } = contextOf(request);
188
+ return auth.accountView(authenticated.account);
189
+ });
190
+ server.get("/api/account/sessions", async (request) => {
191
+ const { auth: authenticated } = contextOf(request);
192
+ return auth.listSessions(authenticated);
193
+ });
194
+ server.delete("/api/account/sessions/:id", async (request, reply) => {
195
+ const { auth: authenticated, meta } = contextOf(request);
196
+ await auth.revokeSession(authenticated, idParam(request), meta);
197
+ return reply.code(204).send();
198
+ });
199
+ server.post("/api/account/password", changePassword);
200
+ server.post("/api/account/totp/start", startTotp);
201
+ server.post("/api/account/totp/confirm", confirmTotp);
202
+ server.delete("/api/account/totp", async (request, reply) => {
203
+ const { auth: authenticated, meta } = contextOf(request);
204
+ await auth.removeTotp(authenticated, meta, currentOf(request));
205
+ return reply.code(204).send();
206
+ });
207
+ server.post("/api/account/recovery-codes", async (request) => {
208
+ const { auth: authenticated, meta } = contextOf(request);
209
+ return { codes: await auth.regenerateRecoveryCodes(authenticated, optionalText(bodyOf(request), "code", MAX_CODE) ?? "", meta) };
210
+ });
211
+ server.post("/api/account/passkey/options", passkeyOptions);
212
+ server.post("/api/account/passkey/verify", passkeyVerify);
213
+ server.delete("/api/account/passkeys/:id", async (request, reply) => {
214
+ const { auth: authenticated, meta } = contextOf(request);
215
+ await auth.removePasskey(authenticated, idParam(request), meta, currentOf(request));
216
+ return reply.code(204).send();
217
+ });
218
+ server.get("/api/admin/users", async (request) => {
219
+ const { auth: authenticated } = contextOf(request);
220
+ return auth.listUsers(authenticated);
221
+ });
222
+ server.post("/api/admin/invites", async (request) => {
223
+ const { auth: authenticated, meta } = contextOf(request);
224
+ const body = bodyOf(request);
225
+ return auth.createInvite(authenticated, {
226
+ email: email(body),
227
+ role: role(body)
228
+ }, meta);
229
+ });
230
+ server.delete("/api/admin/invites/:id", async (request, reply) => {
231
+ const { auth: authenticated, meta } = contextOf(request);
232
+ await auth.revokeInvite(authenticated, idParam(request), meta);
233
+ return reply.code(204).send();
234
+ });
235
+ server.patch("/api/admin/users/:id", async (request) => {
236
+ const { auth: authenticated, meta } = contextOf(request);
237
+ return auth.setRole(authenticated, idParam(request), role(bodyOf(request)), meta);
238
+ });
239
+ server.delete("/api/admin/users/:id", async (request, reply) => {
240
+ const { auth: authenticated, meta } = contextOf(request);
241
+ await auth.removeAccount(authenticated, idParam(request), meta);
242
+ return reply.code(204).send();
243
+ });
244
+ server.post("/api/admin/users/:id/reset-mfa", async (request, reply) => {
245
+ const { auth: authenticated, meta } = contextOf(request);
246
+ await auth.resetSecondFactor(authenticated, idParam(request), meta);
247
+ return reply.code(204).send();
248
+ });
249
+ server.post("/api/admin/users/:id/sign-out", async (request, reply) => {
250
+ const { auth: authenticated, meta } = contextOf(request);
251
+ await auth.signOutAccount(authenticated, idParam(request), meta);
252
+ return reply.code(204).send();
253
+ });
254
+ server.get("/api/admin/audit", async (request) => {
255
+ const { auth: authenticated } = contextOf(request);
256
+ requireAdmin(authenticated);
257
+ const query = request.query;
258
+ const types = query.type?.split(",").map((type) => type.trim()).filter((type) => type !== "");
259
+ const before = query.before === void 0 ? void 0 : Number(query.before);
260
+ const limit = query.limit === void 0 ? 100 : Number(query.limit);
261
+ if (before !== void 0 && !Number.isFinite(before) || !Number.isInteger(limit) || limit < 1) throw new DevtoolsApiError("input.invalid");
262
+ return store.audit.list({
263
+ ...types && types.length > 0 ? { types } : {},
264
+ ...query.account ? { accountId: query.account } : {},
265
+ ...before === void 0 ? {} : { before },
266
+ limit: Math.min(limit, 500)
267
+ });
268
+ });
269
+ server.post("/api/admin/disable", async (request, reply) => {
270
+ const { auth: authenticated, meta } = contextOf(request);
271
+ if (bodyOf(request).confirm !== "disable") throw new DevtoolsApiError("input.invalid");
272
+ await auth.disableDashboard(authenticated, meta);
273
+ state.invalidate();
274
+ return reply.code(204).send();
275
+ });
276
+ }
277
+
278
+ //#endregion
279
+ export { registerAuthRoutes };
280
+ //# sourceMappingURL=auth-routes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-routes.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/auth-routes.ts"],"sourcesContent":["import type { FastifyInstance, FastifyReply, FastifyRequest } from \"fastify\";\nimport type { DevtoolsAuthenticated, DevtoolsAuthStep, DevtoolsRequestMeta } from \"../auth/types\";\nimport type { DevtoolsAuditType, DevtoolsAuthStepResult, DevtoolsRole } from \"../contracts\";\nimport { DevtoolsApiError } from \"../errors\";\nimport { readCookie, sessionCookie, sessionCookieName } from \"./cookie\";\nimport { devtoolsRequestContext } from \"./context\";\nimport type { MountProductionDevtoolsDeps } from \"./types\";\n\nconst MAX_TEXT = 1024;\nconst MAX_EMAIL = 320;\nconst MAX_CODE = 128;\nconst MAX_TOKEN = 512;\nconst ROLES: readonly DevtoolsRole[] = [\"admin\", \"viewer\"];\n\n/** A request body that is a plain JSON object, or `input.invalid`. */\nfunction bodyOf(request: FastifyRequest): Record<string, unknown> {\n const body: unknown = request.body;\n\n if (body === null || typeof body !== \"object\" || Array.isArray(body)) {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n return body as Record<string, unknown>;\n}\n\n/** A non-empty string field no longer than `max`, or `input.invalid`. */\nfunction text(body: Record<string, unknown>, key: string, max = MAX_TEXT): string {\n const value = body[key];\n\n if (typeof value !== \"string\" || value === \"\" || value.length > max) {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n return value;\n}\n\n/** An optional string field; `undefined` when absent, `input.invalid` when present but wrong. */\nfunction optionalText(\n body: Record<string, unknown>,\n key: string,\n max = MAX_TEXT,\n): string | undefined {\n return body[key] === undefined ? undefined : text(body, key, max);\n}\n\nfunction email(body: Record<string, unknown>): string {\n const value = text(body, \"email\", MAX_EMAIL).trim().toLowerCase();\n\n if (!/^[^\\s@]+@[^\\s@]+$/.test(value)) throw new DevtoolsApiError(\"input.invalid\");\n\n return value;\n}\n\nfunction role(body: Record<string, unknown>): DevtoolsRole {\n const value = body.role;\n\n if (typeof value !== \"string\" || !ROLES.includes(value as DevtoolsRole)) {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n return value as DevtoolsRole;\n}\n\nfunction purpose(body: Record<string, unknown>): \"register\" | \"login\" {\n const value = body.purpose;\n\n if (value !== \"register\" && value !== \"login\") throw new DevtoolsApiError(\"input.invalid\");\n\n return value;\n}\n\nfunction idParam(request: FastifyRequest): string {\n const { id } = (request.params ?? {}) as { id?: unknown };\n\n if (typeof id !== \"string\" || id === \"\" || id.length > MAX_CODE) {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n return id;\n}\n\n/** The `current` password of a request that may have no body (a DELETE). */\nfunction currentOf(request: FastifyRequest): string | undefined {\n return request.body === undefined || request.body === null\n ? undefined\n : optionalText(bodyOf(request), \"current\");\n}\n\n/** What the gate stored, for a route that is never reached without it. */\nfunction contextOf(request: FastifyRequest): {\n meta: DevtoolsRequestMeta;\n auth: DevtoolsAuthenticated;\n} {\n const context = devtoolsRequestContext(request);\n\n if (!context?.authenticated) throw new Error(\"A dashboard route ran without its session.\");\n\n return { meta: context.meta, auth: context.authenticated };\n}\n\nfunction metaOf(request: FastifyRequest): DevtoolsRequestMeta {\n const context = devtoolsRequestContext(request);\n\n if (!context) throw new Error(\"A dashboard route ran without its request context.\");\n\n return context.meta;\n}\n\n/**\n * Registers the sign-in, account and admin routes. All decisions live in the\n * auth service; the handlers read the body, call it and answer. The gate\n * (`mountProductionDevtools`) has already checked the session, role, origin\n * and CSRF token by the time a handler runs.\n */\nexport function registerAuthRoutes(\n server: FastifyInstance,\n deps: MountProductionDevtoolsDeps,\n): void {\n const { auth, store, state, production } = deps;\n const cookieOptions = { path: production.path, secure: production.requireHttps };\n\n /** Sets the new session cookie when the step minted one; answers the step. */\n const answerStep = (\n reply: FastifyReply,\n step: DevtoolsAuthStep,\n recoveryCodes?: string[] | null,\n ): DevtoolsAuthStepResult & { recoveryCodes?: string[] } => {\n if (step.token !== null) reply.header(\"set-cookie\", sessionCookie(step.token, cookieOptions));\n\n return {\n stage: step.stage,\n csrf: step.csrf,\n ...(recoveryCodes ? { recoveryCodes } : {}),\n };\n };\n\n /** The stage and CSRF token of the session in force, for answers that do not change it. */\n const currentStep = (authenticated: DevtoolsAuthenticated): DevtoolsAuthStepResult => ({\n stage: authenticated.stage,\n csrf: auth.csrfToken(authenticated.session),\n });\n\n const clearCookie = (reply: FastifyReply): void => {\n reply.header(\"set-cookie\", sessionCookie(null, cookieOptions));\n };\n\n const requireAdmin = (authenticated: DevtoolsAuthenticated): void => {\n if (authenticated.account.role !== \"admin\" || authenticated.stage !== \"active\") {\n throw new DevtoolsApiError(\"role.forbidden\");\n }\n };\n\n // ---- Public ------------------------------------------------------------\n\n server.get(\"/api/auth/session\", async (request, reply) => {\n const token = readCookie(request.headers.cookie, sessionCookieName(production.requireHttps));\n const authenticated = token === undefined ? null : await auth.authenticate(token);\n\n // A cookie that no longer matches a session is dead weight: clear it.\n if (token !== undefined && authenticated === null) clearCookie(reply);\n\n return auth.sessionView(authenticated);\n });\n\n server.post(\"/api/auth/login\", async (request, reply) => {\n const body = bodyOf(request);\n const step = await auth.login(\n { email: email(body), password: text(body, \"password\") },\n metaOf(request),\n );\n\n return answerStep(reply, step);\n });\n\n server.post(\"/api/auth/setup\", async (request, reply) => {\n const body = bodyOf(request);\n const step = await auth.setup(\n { token: text(body, \"token\", MAX_TOKEN), password: text(body, \"password\") },\n metaOf(request),\n );\n\n return answerStep(reply, step);\n });\n\n server.post(\"/api/auth/invite/inspect\", async (request) => {\n const body = bodyOf(request);\n\n return auth.inspectInvite(text(body, \"token\", MAX_TOKEN));\n });\n\n server.post(\"/api/auth/invite/accept\", async (request, reply) => {\n const body = bodyOf(request);\n const step = await auth.acceptInvite(\n { token: text(body, \"token\", MAX_TOKEN), password: text(body, \"password\") },\n metaOf(request),\n );\n\n return answerStep(reply, step);\n });\n\n // ---- Sign-in steps and the account (a session is required) --------------\n\n const changePassword = async (request: FastifyRequest, reply: FastifyReply) => {\n const { auth: authenticated, meta } = contextOf(request);\n const body = bodyOf(request);\n const current = optionalText(body, \"current\");\n const step = await auth.changePassword(\n authenticated,\n { ...(current === undefined ? {} : { current }), password: text(body, \"password\") },\n meta,\n );\n\n return answerStep(reply, step);\n };\n\n const startTotp = async (request: FastifyRequest) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n return auth.startTotp(authenticated, meta);\n };\n\n const confirmTotp = async (request: FastifyRequest, reply: FastifyReply) => {\n const { auth: authenticated, meta } = contextOf(request);\n const body = bodyOf(request);\n const result = await auth.confirmTotp(\n authenticated,\n text(body, \"code\", MAX_CODE),\n meta,\n optionalText(body, \"current\"),\n );\n\n return answerStep(reply, result.step, result.recoveryCodes);\n };\n\n const passkeyOptions = async (request: FastifyRequest) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n return auth.passkeyOptions(authenticated, purpose(bodyOf(request)), meta);\n };\n\n const passkeyVerify = async (request: FastifyRequest, reply: FastifyReply) => {\n const { auth: authenticated, meta } = contextOf(request);\n const body = bodyOf(request);\n\n if (body.response === null || typeof body.response !== \"object\") {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n const result = await auth.verifyPasskey(\n authenticated,\n purpose(body),\n body.response,\n meta,\n optionalText(body, \"current\"),\n );\n\n if (result.step === null) {\n return {\n ...currentStep(authenticated),\n ...(result.recoveryCodes ? { recoveryCodes: result.recoveryCodes } : {}),\n };\n }\n\n return answerStep(reply, result.step, result.recoveryCodes);\n };\n\n server.post(\"/api/auth/password\", changePassword);\n server.post(\"/api/auth/totp/start\", startTotp);\n server.post(\"/api/auth/totp/confirm\", confirmTotp);\n server.post(\"/api/auth/passkey/options\", passkeyOptions);\n server.post(\"/api/auth/passkey/verify\", passkeyVerify);\n\n server.post(\"/api/auth/mfa\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n const body = bodyOf(request);\n const code = optionalText(body, \"code\", MAX_CODE);\n const recoveryCode = optionalText(body, \"recoveryCode\", MAX_CODE);\n\n if ((code === undefined) === (recoveryCode === undefined)) {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n const step = await auth.verifySecondFactor(\n authenticated,\n code === undefined ? { recoveryCode: recoveryCode as string } : { code },\n meta,\n );\n\n return answerStep(reply, step);\n });\n\n server.post(\"/api/auth/logout\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n await auth.logout(authenticated, meta);\n clearCookie(reply);\n\n return reply.code(204).send();\n });\n\n server.get(\"/api/account\", async (request) => {\n const { auth: authenticated } = contextOf(request);\n\n return auth.accountView(authenticated.account);\n });\n\n server.get(\"/api/account/sessions\", async (request) => {\n const { auth: authenticated } = contextOf(request);\n\n return auth.listSessions(authenticated);\n });\n\n server.delete(\"/api/account/sessions/:id\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n await auth.revokeSession(authenticated, idParam(request), meta);\n\n return reply.code(204).send();\n });\n\n server.post(\"/api/account/password\", changePassword);\n server.post(\"/api/account/totp/start\", startTotp);\n server.post(\"/api/account/totp/confirm\", confirmTotp);\n\n server.delete(\"/api/account/totp\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n await auth.removeTotp(authenticated, meta, currentOf(request));\n\n return reply.code(204).send();\n });\n\n server.post(\"/api/account/recovery-codes\", async (request) => {\n const { auth: authenticated, meta } = contextOf(request);\n // No code: a passkey step-up in this session stands in for it.\n const codes = await auth.regenerateRecoveryCodes(\n authenticated,\n optionalText(bodyOf(request), \"code\", MAX_CODE) ?? \"\",\n meta,\n );\n\n return { codes };\n });\n\n server.post(\"/api/account/passkey/options\", passkeyOptions);\n server.post(\"/api/account/passkey/verify\", passkeyVerify);\n\n server.delete(\"/api/account/passkeys/:id\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n await auth.removePasskey(authenticated, idParam(request), meta, currentOf(request));\n\n return reply.code(204).send();\n });\n\n // ---- Admin ---------------------------------------------------------------\n\n server.get(\"/api/admin/users\", async (request) => {\n const { auth: authenticated } = contextOf(request);\n\n return auth.listUsers(authenticated);\n });\n\n server.post(\"/api/admin/invites\", async (request) => {\n const { auth: authenticated, meta } = contextOf(request);\n const body = bodyOf(request);\n\n return auth.createInvite(authenticated, { email: email(body), role: role(body) }, meta);\n });\n\n server.delete(\"/api/admin/invites/:id\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n await auth.revokeInvite(authenticated, idParam(request), meta);\n\n return reply.code(204).send();\n });\n\n server.patch(\"/api/admin/users/:id\", async (request) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n return auth.setRole(authenticated, idParam(request), role(bodyOf(request)), meta);\n });\n\n server.delete(\"/api/admin/users/:id\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n await auth.removeAccount(authenticated, idParam(request), meta);\n\n return reply.code(204).send();\n });\n\n server.post(\"/api/admin/users/:id/reset-mfa\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n await auth.resetSecondFactor(authenticated, idParam(request), meta);\n\n return reply.code(204).send();\n });\n\n server.post(\"/api/admin/users/:id/sign-out\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n await auth.signOutAccount(authenticated, idParam(request), meta);\n\n return reply.code(204).send();\n });\n\n server.get<{ Querystring: Record<string, string | undefined> }>(\n \"/api/admin/audit\",\n async (request) => {\n const { auth: authenticated } = contextOf(request);\n\n requireAdmin(authenticated);\n\n const query = request.query;\n const types = query.type\n ?.split(\",\")\n .map((type) => type.trim())\n .filter((type) => type !== \"\");\n const before = query.before === undefined ? undefined : Number(query.before);\n const limit = query.limit === undefined ? 100 : Number(query.limit);\n\n if (\n (before !== undefined && !Number.isFinite(before)) ||\n !Number.isInteger(limit) ||\n limit < 1\n ) {\n throw new DevtoolsApiError(\"input.invalid\");\n }\n\n return store.audit.list({\n ...(types && types.length > 0 ? { types: types as DevtoolsAuditType[] } : {}),\n ...(query.account ? { accountId: query.account } : {}),\n ...(before === undefined ? {} : { before }),\n limit: Math.min(limit, 500),\n });\n },\n );\n\n server.post(\"/api/admin/disable\", async (request, reply) => {\n const { auth: authenticated, meta } = contextOf(request);\n\n if (bodyOf(request).confirm !== \"disable\") throw new DevtoolsApiError(\"input.invalid\");\n\n await auth.disableDashboard(authenticated, meta);\n // This process closes at once; the others within the state cache time.\n state.invalidate();\n\n return reply.code(204).send();\n });\n}\n"],"mappings":";;;;;AAQA,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,WAAW;AACjB,MAAM,YAAY;AAClB,MAAM,QAAiC,CAAC,SAAS,QAAQ;;AAGzD,SAAS,OAAO,SAAkD;CAChE,MAAM,OAAgB,QAAQ;CAE9B,IAAI,SAAS,QAAQ,OAAO,SAAS,YAAY,MAAM,QAAQ,IAAI,GACjE,MAAM,IAAI,iBAAiB,eAAe;CAG5C,OAAO;AACT;;AAGA,SAAS,KAAK,MAA+B,KAAa,MAAM,UAAkB;CAChF,MAAM,QAAQ,KAAK;CAEnB,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,MAAM,SAAS,KAC9D,MAAM,IAAI,iBAAiB,eAAe;CAG5C,OAAO;AACT;;AAGA,SAAS,aACP,MACA,KACA,MAAM,UACc;CACpB,OAAO,KAAK,SAAS,SAAY,SAAY,KAAK,MAAM,KAAK,GAAG;AAClE;AAEA,SAAS,MAAM,MAAuC;CACpD,MAAM,QAAQ,KAAK,MAAM,SAAS,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC,YAAY;CAEhE,IAAI,CAAC,oBAAoB,KAAK,KAAK,GAAG,MAAM,IAAI,iBAAiB,eAAe;CAEhF,OAAO;AACT;AAEA,SAAS,KAAK,MAA6C;CACzD,MAAM,QAAQ,KAAK;CAEnB,IAAI,OAAO,UAAU,YAAY,CAAC,MAAM,SAAS,KAAqB,GACpE,MAAM,IAAI,iBAAiB,eAAe;CAG5C,OAAO;AACT;AAEA,SAAS,QAAQ,MAAqD;CACpE,MAAM,QAAQ,KAAK;CAEnB,IAAI,UAAU,cAAc,UAAU,SAAS,M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AAa;EAE1B,MAAM,QAAQ,QAAQ;EACtB,MAAM,QAAQ,MAAM,MAChB,MAAM,GAAG,CAAC,CACX,KAAK,SAAS,KAAK,KAAK,CAAC,CAAC,CAC1B,QAAQ,SAAS,SAAS,EAAE;EAC/B,MAAM,SAAS,MAAM,WAAW,SAAY,SAAY,OAAO,MAAM,MAAM;EAC3E,MAAM,QAAQ,MAAM,UAAU,SAAY,MAAM,OAAO,MAAM,KAAK;EAElE,IACG,WAAW,UAAa,CAAC,OAAO,SAAS,MAAM,KAChD,CAAC,OAAO,UAAU,KAAK,KACvB,QAAQ,GAER,MAAM,IAAI,iBAAiB,eAAe;EAG5C,OAAO,MAAM,MAAM,KAAK;GACtB,GAAI,SAAS,MAAM,SAAS,IAAI,EAAS,MAA6B,IAAI,CAAC;GAC3E,GAAI,MAAM,UAAU,EAAE,WAAW,MAAM,QAAQ,IAAI,CAAC;GACpD,GAAI,WAAW,SAAY,CAAC,IAAI,EAAE,OAAO;GACzC,OAAO,KAAK,IAAI,OAAO,GAAG;EAC5B,CAAC;CACH,CACF;CAEA,OAAO,KAAK,sBAAsB,OAAO,SAAS,UAAU;EAC1D,MAAM,EAAE,MAAM,eAAe,SAAS,UAAU,OAAO;EAEvD,IAAI,OAAO,OAAO,CAAC,CAAC,YAAY,WAAW,MAAM,IAAI,iBAAiB,eAAe;EAErF,MAAM,KAAK,iBAAiB,eAAe,IAAI;EAE/C,MAAM,WAAW;EAEjB,OAAO,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK;CAC9B,CAAC;AACH"}
@@ -0,0 +1,57 @@
1
+ import { ipMatches, normalizeIp } from "./ip.mjs";
2
+ import { isIP } from "node:net";
3
+
4
+ //#region ../../packages/devtools/src/production/http/client.ts
5
+ /** The first value of a header that may repeat or hold a comma list. */
6
+ function firstValue(value) {
7
+ const first = (Array.isArray(value) ? value[0] : value)?.split(",")[0]?.trim();
8
+ return first === void 0 || first === "" ? void 0 : first;
9
+ }
10
+ /** The host name of a `Host` value: no port, lower case, brackets of an IPv6 literal kept. */
11
+ function hostnameOf(host) {
12
+ const value = host.trim().toLowerCase();
13
+ if (value.startsWith("[")) {
14
+ const end = value.indexOf("]");
15
+ return end === -1 ? value : value.slice(0, end + 1);
16
+ }
17
+ const colon = value.indexOf(":");
18
+ return colon === -1 ? value : value.slice(0, colon);
19
+ }
20
+ /** The client address out of an `X-Forwarded-For` value, walking right to left past trusted hops. */
21
+ function forwardedClient(header, trusted) {
22
+ const hops = ((Array.isArray(header) ? header.join(",") : header) ?? "").split(",").map((hop) => normalizeIp(hop.trim().replace(/^\[|\]$/g, ""))).filter((hop) => isIP(hop) !== 0);
23
+ for (let index = hops.length - 1; index >= 0; index -= 1) {
24
+ const hop = hops[index];
25
+ if (hop !== void 0 && !ipMatches(hop, trusted)) return hop;
26
+ }
27
+ return hops[0];
28
+ }
29
+ /**
30
+ * The client IP, protocol and host. Forwarding headers are read only when the
31
+ * socket peer is a trusted proxy; `X-Forwarded-For` is walked right to left,
32
+ * skipping trusted addresses, and the first untrusted one is the client.
33
+ */
34
+ function resolveClient(request, trustedProxies) {
35
+ const peer = normalizeIp(request.socket.remoteAddress ?? "");
36
+ const headers = request.headers;
37
+ let ip = peer;
38
+ let proto = request.socket.encrypted === true ? "https" : "http";
39
+ let host = firstValue(headers.host) ?? "";
40
+ if (peer !== "" && ipMatches(peer, trustedProxies)) {
41
+ ip = forwardedClient(headers["x-forwarded-for"], trustedProxies) ?? peer;
42
+ const forwardedProto = firstValue(headers["x-forwarded-proto"])?.toLowerCase();
43
+ if (forwardedProto === "http" || forwardedProto === "https") proto = forwardedProto;
44
+ host = firstValue(headers["x-forwarded-host"]) ?? host;
45
+ }
46
+ host = host.toLowerCase();
47
+ return {
48
+ ip,
49
+ proto,
50
+ hostname: hostnameOf(host),
51
+ host
52
+ };
53
+ }
54
+
55
+ //#endregion
56
+ export { resolveClient };
57
+ //# sourceMappingURL=client.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/client.ts"],"sourcesContent":["import { isIP } from \"node:net\";\nimport type { DevtoolsClientInfo, DevtoolsProxyRequest } from \"./types\";\nimport { ipMatches, normalizeIp } from \"./ip\";\n\n/** The first value of a header that may repeat or hold a comma list. */\nfunction firstValue(value: string | string[] | undefined): string | undefined {\n const text = Array.isArray(value) ? value[0] : value;\n const first = text?.split(\",\")[0]?.trim();\n\n return first === undefined || first === \"\" ? undefined : first;\n}\n\n/** The host name of a `Host` value: no port, lower case, brackets of an IPv6 literal kept. */\nfunction hostnameOf(host: string): string {\n const value = host.trim().toLowerCase();\n\n if (value.startsWith(\"[\")) {\n const end = value.indexOf(\"]\");\n\n return end === -1 ? value : value.slice(0, end + 1);\n }\n\n const colon = value.indexOf(\":\");\n\n return colon === -1 ? value : value.slice(0, colon);\n}\n\n/** The client address out of an `X-Forwarded-For` value, walking right to left past trusted hops. */\nfunction forwardedClient(\n header: string | string[] | undefined,\n trusted: readonly string[],\n): string | undefined {\n const text = Array.isArray(header) ? header.join(\",\") : header;\n const hops = (text ?? \"\")\n .split(\",\")\n .map((hop) => normalizeIp(hop.trim().replace(/^\\[|\\]$/g, \"\")))\n .filter((hop) => isIP(hop) !== 0);\n\n for (let index = hops.length - 1; index >= 0; index -= 1) {\n const hop = hops[index];\n\n if (hop !== undefined && !ipMatches(hop, trusted)) return hop;\n }\n\n // Every hop is a trusted proxy: the leftmost is the origin of the chain.\n return hops[0];\n}\n\n/**\n * The client IP, protocol and host. Forwarding headers are read only when the\n * socket peer is a trusted proxy; `X-Forwarded-For` is walked right to left,\n * skipping trusted addresses, and the first untrusted one is the client.\n */\nexport function resolveClient(\n request: DevtoolsProxyRequest,\n trustedProxies: readonly string[],\n): DevtoolsClientInfo {\n const peer = normalizeIp(request.socket.remoteAddress ?? \"\");\n const headers = request.headers;\n let ip = peer;\n let proto = request.socket.encrypted === true ? \"https\" : \"http\";\n let host = firstValue(headers.host) ?? \"\";\n\n if (peer !== \"\" && ipMatches(peer, trustedProxies)) {\n ip = forwardedClient(headers[\"x-forwarded-for\"], trustedProxies) ?? peer;\n\n const forwardedProto = firstValue(headers[\"x-forwarded-proto\"])?.toLowerCase();\n\n if (forwardedProto === \"http\" || forwardedProto === \"https\") proto = forwardedProto;\n\n host = firstValue(headers[\"x-forwarded-host\"]) ?? host;\n }\n\n host = host.toLowerCase();\n\n return { ip, proto, hostname: hostnameOf(host), host };\n}\n"],"mappings":";;;;;AAKA,SAAS,WAAW,OAA0D;CAE5E,MAAM,SADO,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,MAC7B,EAAE,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,KAAK;CAExC,OAAO,UAAU,UAAa,UAAU,KAAK,SAAY;AAC3D;;AAGA,SAAS,WAAW,MAAsB;CACxC,MAAM,QAAQ,KAAK,KAAK,CAAC,CAAC,YAAY;CAEtC,IAAI,MAAM,WAAW,GAAG,GAAG;EACzB,MAAM,MAAM,MAAM,QAAQ,GAAG;EAE7B,OAAO,QAAQ,KAAK,QAAQ,MAAM,MAAM,GAAG,MAAM,CAAC;CACpD;CAEA,MAAM,QAAQ,MAAM,QAAQ,GAAG;CAE/B,OAAO,UAAU,KAAK,QAAQ,MAAM,MAAM,GAAG,KAAK;AACpD;;AAGA,SAAS,gBACP,QACA,SACoB;CAEpB,MAAM,SADO,MAAM,QAAQ,MAAM,IAAI,OAAO,KAAK,GAAG,IAAI,WAClC,GAAE,CACrB,MAAM,GAAG,CAAC,CACV,KAAK,QAAQ,YAAY,IAAI,KAAK,CAAC,CAAC,QAAQ,YAAY,EAAE,CAAC,CAAC,CAAC,CAC7D,QAAQ,QAAQ,KAAK,GAAG,MAAM,CAAC;CAElC,KAAK,IAAI,QAAQ,KAAK,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG;EACxD,MAAM,MAAM,KAAK;EAEjB,IAAI,QAAQ,UAAa,CAAC,UAAU,KAAK,OAAO,GAAG,OAAO;CAC5D;CAGA,OAAO,KAAK;AACd;;;;;;AAOA,SAAgB,cACd,SACA,gBACoB;CACpB,MAAM,OAAO,YAAY,QAAQ,OAAO,iBAAiB,EAAE;CAC3D,MAAM,UAAU,QAAQ;CACxB,IAAI,KAAK;CACT,IAAI,QAAQ,QAAQ,OAAO,cAAc,OAAO,UAAU;CAC1D,IAAI,OAAO,WAAW,QAAQ,IAAI,KAAK;CAEvC,IAAI,SAAS,MAAM,UAAU,MAAM,cAAc,GAAG;EAClD,KAAK,gBAAgB,QAAQ,oBAAoB,cAAc,KAAK;EAEpE,MAAM,iBAAiB,WAAW,QAAQ,oBAAoB,CAAC,EAAE,YAAY;EAE7E,IAAI,mBAAmB,UAAU,mBAAmB,SAAS,QAAQ;EAErE,OAAO,WAAW,QAAQ,mBAAmB,KAAK;CACpD;CAEA,OAAO,KAAK,YAAY;CAExB,OAAO;EAAE;EAAI;EAAO,UAAU,WAAW,IAAI;EAAG;CAAK;AACvD"}
@@ -0,0 +1,11 @@
1
+ //#region ../../packages/devtools/src/production/http/constants.ts
2
+ /** The header the dashboard sends the CSRF token in. */
3
+ const DEVTOOLS_CSRF_HEADER = "x-devtools-csrf";
4
+ /** The session cookie name over HTTPS (`__Secure-` makes browsers refuse it over plain HTTP). */
5
+ const DEVTOOLS_SESSION_COOKIE = "__Secure-warlock-devtools";
6
+ /** The session cookie name when `requireHttps` is off (local trials only). */
7
+ const DEVTOOLS_SESSION_COOKIE_INSECURE = "warlock-devtools";
8
+
9
+ //#endregion
10
+ export { DEVTOOLS_CSRF_HEADER, DEVTOOLS_SESSION_COOKIE, DEVTOOLS_SESSION_COOKIE_INSECURE };
11
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/constants.ts"],"sourcesContent":["/** The header the dashboard sends the CSRF token in. */\nexport const DEVTOOLS_CSRF_HEADER = \"x-devtools-csrf\";\n\n/** The session cookie name over HTTPS (`__Secure-` makes browsers refuse it over plain HTTP). */\nexport const DEVTOOLS_SESSION_COOKIE = \"__Secure-warlock-devtools\";\n\n/** The session cookie name when `requireHttps` is off (local trials only). */\nexport const DEVTOOLS_SESSION_COOKIE_INSECURE = \"warlock-devtools\";\n"],"mappings":";;AACA,MAAa,uBAAuB;;AAGpC,MAAa,0BAA0B;;AAGvC,MAAa,mCAAmC"}
@@ -0,0 +1,14 @@
1
+ //#region ../../packages/devtools/src/production/http/context.ts
2
+ const contexts = /* @__PURE__ */ new WeakMap();
3
+ /** Stores the context of `request` (the gate calls this). */
4
+ function setDevtoolsRequestContext(request, context) {
5
+ contexts.set(request, context);
6
+ }
7
+ /** The context the gate stored for `request`, or `undefined` outside the production dashboard. */
8
+ function devtoolsRequestContext(request) {
9
+ return contexts.get(request);
10
+ }
11
+
12
+ //#endregion
13
+ export { devtoolsRequestContext, setDevtoolsRequestContext };
14
+ //# sourceMappingURL=context.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/context.ts"],"sourcesContent":["import type { FastifyRequest } from \"fastify\";\nimport type { DevtoolsAuthenticated, DevtoolsRequestMeta } from \"../auth/types\";\nimport type { DevtoolsClientInfo, DevtoolsRouteAccessRule } from \"./types\";\n\n/** What the gate learned about a dashboard request, for the handlers that follow. */\nexport type DevtoolsRequestContext = {\n client: DevtoolsClientInfo;\n meta: DevtoolsRequestMeta;\n /** The access rule the route matched; `undefined` for a route with no entry (treated as admin). */\n rule: DevtoolsRouteAccessRule | undefined;\n /** The route pattern relative to the dashboard path (`/api/requests/:id`). */\n pattern: string;\n /** The session, for every route that is not public. */\n authenticated: DevtoolsAuthenticated | null;\n};\n\nconst contexts = new WeakMap<FastifyRequest, DevtoolsRequestContext>();\n\n/** Stores the context of `request` (the gate calls this). */\nexport function setDevtoolsRequestContext(\n request: FastifyRequest,\n context: DevtoolsRequestContext,\n): void {\n contexts.set(request, context);\n}\n\n/** The context the gate stored for `request`, or `undefined` outside the production dashboard. */\nexport function devtoolsRequestContext(\n request: FastifyRequest,\n): DevtoolsRequestContext | undefined {\n return contexts.get(request);\n}\n"],"mappings":";AAgBA,MAAM,2BAAW,IAAI,QAAgD;;AAGrE,SAAgB,0BACd,SACA,SACM;CACN,SAAS,IAAI,SAAS,OAAO;AAC/B;;AAGA,SAAgB,uBACd,SACoC;CACpC,OAAO,SAAS,IAAI,OAAO;AAC7B"}
@@ -0,0 +1,39 @@
1
+ import { DEVTOOLS_SESSION_COOKIE, DEVTOOLS_SESSION_COOKIE_INSECURE } from "./constants.mjs";
2
+
3
+ //#region ../../packages/devtools/src/production/http/cookie.ts
4
+ /** The cookie name for the HTTPS mode. */
5
+ function sessionCookieName(secure) {
6
+ return secure ? DEVTOOLS_SESSION_COOKIE : DEVTOOLS_SESSION_COOKIE_INSECURE;
7
+ }
8
+ /**
9
+ * `Set-Cookie` value for a session token (or a clearing cookie when `token`
10
+ * is `null`). The cookie is a browser-session cookie scoped to the dashboard
11
+ * path, `HttpOnly` and `SameSite=Strict`, with no `Domain`.
12
+ */
13
+ function sessionCookie(token, options) {
14
+ const parts = [
15
+ `${sessionCookieName(options.secure)}=${token ?? ""}`,
16
+ `Path=${options.path}`,
17
+ "HttpOnly",
18
+ "SameSite=Strict"
19
+ ];
20
+ if (options.secure) parts.push("Secure");
21
+ if (token === null) parts.push("Max-Age=0", "Expires=Thu, 01 Jan 1970 00:00:00 GMT");
22
+ return parts.join("; ");
23
+ }
24
+ /** The value of cookie `name` in a `Cookie` header, or `undefined`. */
25
+ function readCookie(header, name) {
26
+ if (!header) return void 0;
27
+ for (const pair of header.split(";")) {
28
+ const equals = pair.indexOf("=");
29
+ if (equals === -1) continue;
30
+ if (pair.slice(0, equals).trim() === name) {
31
+ const value = pair.slice(equals + 1).trim();
32
+ return value === "" ? void 0 : value;
33
+ }
34
+ }
35
+ }
36
+
37
+ //#endregion
38
+ export { readCookie, sessionCookie, sessionCookieName };
39
+ //# sourceMappingURL=cookie.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cookie.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/cookie.ts"],"sourcesContent":["import { DEVTOOLS_SESSION_COOKIE, DEVTOOLS_SESSION_COOKIE_INSECURE } from \"./constants\";\n\n/** The cookie name for the HTTPS mode. */\nexport function sessionCookieName(secure: boolean): string {\n return secure ? DEVTOOLS_SESSION_COOKIE : DEVTOOLS_SESSION_COOKIE_INSECURE;\n}\n\n/**\n * `Set-Cookie` value for a session token (or a clearing cookie when `token`\n * is `null`). The cookie is a browser-session cookie scoped to the dashboard\n * path, `HttpOnly` and `SameSite=Strict`, with no `Domain`.\n */\nexport function sessionCookie(\n token: string | null,\n options: { path: string; secure: boolean },\n): string {\n const parts = [\n `${sessionCookieName(options.secure)}=${token ?? \"\"}`,\n `Path=${options.path}`,\n \"HttpOnly\",\n \"SameSite=Strict\",\n ];\n\n if (options.secure) parts.push(\"Secure\");\n\n if (token === null) parts.push(\"Max-Age=0\", \"Expires=Thu, 01 Jan 1970 00:00:00 GMT\");\n\n return parts.join(\"; \");\n}\n\n/** The value of cookie `name` in a `Cookie` header, or `undefined`. */\nexport function readCookie(header: string | undefined, name: string): string | undefined {\n if (!header) return undefined;\n\n for (const pair of header.split(\";\")) {\n const equals = pair.indexOf(\"=\");\n\n if (equals === -1) continue;\n\n if (pair.slice(0, equals).trim() === name) {\n const value = pair.slice(equals + 1).trim();\n\n return value === \"\" ? undefined : value;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;AAGA,SAAgB,kBAAkB,QAAyB;CACzD,OAAO,SAAS,0BAA0B;AAC5C;;;;;;AAOA,SAAgB,cACd,OACA,SACQ;CACR,MAAM,QAAQ;EACZ,GAAG,kBAAkB,QAAQ,MAAM,EAAE,GAAG,SAAS;EACjD,QAAQ,QAAQ;EAChB;EACA;CACF;CAEA,IAAI,QAAQ,QAAQ,MAAM,KAAK,QAAQ;CAEvC,IAAI,UAAU,MAAM,MAAM,KAAK,aAAa,uCAAuC;CAEnF,OAAO,MAAM,KAAK,IAAI;AACxB;;AAGA,SAAgB,WAAW,QAA4B,MAAkC;CACvF,IAAI,CAAC,QAAQ,OAAO;CAEpB,KAAK,MAAM,QAAQ,OAAO,MAAM,GAAG,GAAG;EACpC,MAAM,SAAS,KAAK,QAAQ,GAAG;EAE/B,IAAI,WAAW,IAAI;EAEnB,IAAI,KAAK,MAAM,GAAG,MAAM,CAAC,CAAC,KAAK,MAAM,MAAM;GACzC,MAAM,QAAQ,KAAK,MAAM,SAAS,CAAC,CAAC,CAAC,KAAK;GAE1C,OAAO,UAAU,KAAK,SAAY;EACpC;CACF;AAGF"}
@@ -0,0 +1,25 @@
1
+ //#region ../../packages/devtools/src/production/http/headers.ts
2
+ /** Headers on every dashboard answer that is not the uniform 404. */
3
+ const DASHBOARD_HEADERS = {
4
+ "Cache-Control": "no-store",
5
+ "X-Robots-Tag": "noindex, nofollow, noarchive",
6
+ "Referrer-Policy": "no-referrer",
7
+ "X-Content-Type-Options": "nosniff",
8
+ "X-Frame-Options": "DENY",
9
+ "Cross-Origin-Opener-Policy": "same-origin",
10
+ "Cross-Origin-Resource-Policy": "same-origin",
11
+ "Permissions-Policy": "camera=(), microphone=(), geolocation=(), publickey-credentials-get=(self), publickey-credentials-create=(self)"
12
+ };
13
+ /** The policy of the dashboard's own HTML: scripts and styles from the bundle only. */
14
+ const DASHBOARD_CSP = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'; object-src 'none'";
15
+ /**
16
+ * The policy of the opt-in API documentation pages: scripts from the dashboard
17
+ * only (Scalar and Swagger UI probe `Function` in a try/catch and work without
18
+ * `'unsafe-eval'`), inline styles, and framing by the dashboard itself, whose
19
+ * API tab shows them in a frame.
20
+ */
21
+ const DOCS_CSP = "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'self'; base-uri 'none'; form-action 'self'; object-src 'none'";
22
+
23
+ //#endregion
24
+ export { DASHBOARD_CSP, DASHBOARD_HEADERS, DOCS_CSP };
25
+ //# sourceMappingURL=headers.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/http/headers.ts"],"sourcesContent":["/** Headers on every dashboard answer that is not the uniform 404. */\nexport const DASHBOARD_HEADERS: Readonly<Record<string, string>> = {\n \"Cache-Control\": \"no-store\",\n \"X-Robots-Tag\": \"noindex, nofollow, noarchive\",\n \"Referrer-Policy\": \"no-referrer\",\n \"X-Content-Type-Options\": \"nosniff\",\n \"X-Frame-Options\": \"DENY\",\n \"Cross-Origin-Opener-Policy\": \"same-origin\",\n \"Cross-Origin-Resource-Policy\": \"same-origin\",\n \"Permissions-Policy\":\n \"camera=(), microphone=(), geolocation=(), publickey-credentials-get=(self), publickey-credentials-create=(self)\",\n};\n\n/** The policy of the dashboard's own HTML: scripts and styles from the bundle only. */\nexport const DASHBOARD_CSP =\n \"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; frame-src 'self'; frame-ancestors 'none'; base-uri 'none'; form-action 'self'; object-src 'none'\";\n\n/**\n * The policy of the opt-in API documentation pages: scripts from the dashboard\n * only (Scalar and Swagger UI probe `Function` in a try/catch and work without\n * `'unsafe-eval'`), inline styles, and framing by the dashboard itself, whose\n * API tab shows them in a frame.\n */\nexport const DOCS_CSP =\n \"default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: blob:; font-src 'self' data:; connect-src 'self'; frame-ancestors 'self'; base-uri 'none'; form-action 'self'; object-src 'none'\";\n"],"mappings":";;AACA,MAAa,oBAAsD;CACjE,iBAAiB;CACjB,gBAAgB;CAChB,mBAAmB;CACnB,0BAA0B;CAC1B,mBAAmB;CACnB,8BAA8B;CAC9B,gCAAgC;CAChC,sBACE;AACJ;;AAGA,MAAa,gBACX;;;;;;;AAQF,MAAa,WACX"}
@@ -0,0 +1,10 @@
1
+ import { ipMatches } from "./ip.mjs";
2
+ import { productionRouteAccess } from "./access.mjs";
3
+ import { resolveClient } from "./client.mjs";
4
+ import { DEVTOOLS_CSRF_HEADER, DEVTOOLS_SESSION_COOKIE, DEVTOOLS_SESSION_COOKIE_INSECURE } from "./constants.mjs";
5
+ import { devtoolsRequestContext } from "./context.mjs";
6
+ import { sessionCookie } from "./cookie.mjs";
7
+ import { mountProductionDevtools } from "./mount.mjs";
8
+ import { createDashboardState } from "./state.mjs";
9
+
10
+ export { DEVTOOLS_CSRF_HEADER, DEVTOOLS_SESSION_COOKIE, DEVTOOLS_SESSION_COOKIE_INSECURE, createDashboardState, devtoolsRequestContext, ipMatches, mountProductionDevtools, productionRouteAccess, resolveClient, sessionCookie };