@warlock.js/devtools 5.56.0 → 5.58.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 (121) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +3 -0
  3. package/cjs/{auth-DzU0gHDG.cjs → auth-DV2GA1A9.cjs} +33 -403
  4. package/cjs/auth-DV2GA1A9.cjs.map +1 -0
  5. package/cjs/{boot-BQi0Etor.cjs → boot-CyeHPFtk.cjs} +14 -12
  6. package/cjs/boot-CyeHPFtk.cjs.map +1 -0
  7. package/cjs/{capture-CqIiaznN.cjs → capture-DcyBhdqw.cjs} +3 -3
  8. package/cjs/{capture-CqIiaznN.cjs.map → capture-DcyBhdqw.cjs.map} +1 -1
  9. package/cjs/{cascade-store-pHjKeSFm.cjs → cascade-store-DEGxAFDI.cjs} +141 -4
  10. package/cjs/cascade-store-DEGxAFDI.cjs.map +1 -0
  11. package/cjs/{contracts-CVmplkNb.cjs → contracts-CDuY-ahl.cjs} +6 -2
  12. package/cjs/{contracts-CVmplkNb.cjs.map → contracts-CDuY-ahl.cjs.map} +1 -1
  13. package/cjs/{errors-CyZp5yS-.cjs → errors-DEqdWaqm.cjs} +3 -1
  14. package/cjs/{errors-CyZp5yS-.cjs.map → errors-DEqdWaqm.cjs.map} +1 -1
  15. package/cjs/helpers-7k_Q-abk.cjs +436 -0
  16. package/cjs/helpers-7k_Q-abk.cjs.map +1 -0
  17. package/cjs/{histogram-BaI-PnCv.cjs → histogram-BRV5eHcp.cjs} +2 -2
  18. package/cjs/{histogram-BaI-PnCv.cjs.map → histogram-BRV5eHcp.cjs.map} +1 -1
  19. package/cjs/{http-CabcUwBx.cjs → http-XNLYU2vS.cjs} +517 -28
  20. package/cjs/http-XNLYU2vS.cjs.map +1 -0
  21. package/cjs/index.cjs +2 -1
  22. package/cjs/{insights-BKtqxdnP.cjs → insights-BBZnUpWO.cjs} +4 -3
  23. package/cjs/{insights-BKtqxdnP.cjs.map → insights-BBZnUpWO.cjs.map} +1 -1
  24. package/cjs/{migrations-w7GMsrQw.cjs → migrations-DTTzCNpR.cjs} +38 -3
  25. package/cjs/migrations-DTTzCNpR.cjs.map +1 -0
  26. package/cjs/{options-CWqFC5__.cjs → options-CHhmQJic.cjs} +16 -4
  27. package/cjs/options-CHhmQJic.cjs.map +1 -0
  28. package/cjs/{panels-B0dAfGbJ.cjs → panels-CHd20RK5.cjs} +97 -10
  29. package/cjs/panels-CHd20RK5.cjs.map +1 -0
  30. package/cjs/production/index.cjs +4 -4
  31. package/cjs/{server-B6xdeKS8.cjs → server-C8JfggQU.cjs} +5 -4
  32. package/cjs/server-C8JfggQU.cjs.map +1 -0
  33. package/cjs/{src-Ce-3Lniv.cjs → src-DjOUdhKc.cjs} +96 -10
  34. package/cjs/src-DjOUdhKc.cjs.map +1 -0
  35. package/cjs/{store-aq207T8v.cjs → store-C06KO_A1.cjs} +2 -2
  36. package/cjs/{stream-route-BGJa-zQu.cjs → stream-route-D4k-sJvW.cjs} +70 -9
  37. package/cjs/stream-route-D4k-sJvW.cjs.map +1 -0
  38. package/esm/devtools-connector.d.mts.map +1 -1
  39. package/esm/devtools-connector.mjs +10 -3
  40. package/esm/devtools-connector.mjs.map +1 -1
  41. package/esm/index.d.mts +4 -3
  42. package/esm/index.mjs +2 -1
  43. package/esm/panel-errors.mjs +33 -0
  44. package/esm/panel-errors.mjs.map +1 -0
  45. package/esm/panel-tokens.d.mts +13 -0
  46. package/esm/panel-tokens.d.mts.map +1 -0
  47. package/esm/panel-tokens.mjs +45 -0
  48. package/esm/panel-tokens.mjs.map +1 -0
  49. package/esm/panels.mjs +96 -9
  50. package/esm/panels.mjs.map +1 -1
  51. package/esm/production/auth/service.mjs +4 -2
  52. package/esm/production/auth/service.mjs.map +1 -1
  53. package/esm/production/boot.mjs +4 -2
  54. package/esm/production/boot.mjs.map +1 -1
  55. package/esm/production/contracts.d.mts +68 -2
  56. package/esm/production/contracts.d.mts.map +1 -1
  57. package/esm/production/contracts.mjs +5 -1
  58. package/esm/production/contracts.mjs.map +1 -1
  59. package/esm/production/errors.mjs +2 -0
  60. package/esm/production/errors.mjs.map +1 -1
  61. package/esm/production/http/access.mjs +6 -2
  62. package/esm/production/http/access.mjs.map +1 -1
  63. package/esm/production/http/constants.mjs +7 -1
  64. package/esm/production/http/constants.mjs.map +1 -1
  65. package/esm/production/http/context.mjs.map +1 -1
  66. package/esm/production/http/cookie.mjs +23 -2
  67. package/esm/production/http/cookie.mjs.map +1 -1
  68. package/esm/production/http/mount.mjs +25 -3
  69. package/esm/production/http/mount.mjs.map +1 -1
  70. package/esm/production/http/share-session.mjs +114 -0
  71. package/esm/production/http/share-session.mjs.map +1 -0
  72. package/esm/production/http/share.mjs +339 -0
  73. package/esm/production/http/share.mjs.map +1 -0
  74. package/esm/production/index.d.mts +2 -2
  75. package/esm/production/insights/writer.mjs +2 -1
  76. package/esm/production/insights/writer.mjs.map +1 -1
  77. package/esm/production/options.d.mts +5 -0
  78. package/esm/production/options.d.mts.map +1 -1
  79. package/esm/production/options.mjs +14 -2
  80. package/esm/production/options.mjs.map +1 -1
  81. package/esm/production/store/cascade-store.mjs +49 -2
  82. package/esm/production/store/cascade-store.mjs.map +1 -1
  83. package/esm/production/store/mapping.mjs +29 -1
  84. package/esm/production/store/mapping.mjs.map +1 -1
  85. package/esm/production/store/memory-store.mjs +62 -0
  86. package/esm/production/store/memory-store.mjs.map +1 -1
  87. package/esm/production/store/migrations.d.mts +2 -1
  88. package/esm/production/store/migrations.d.mts.map +1 -1
  89. package/esm/production/store/migrations.mjs +5 -2
  90. package/esm/production/store/migrations.mjs.map +1 -1
  91. package/esm/production/store/models/index.mjs +3 -1
  92. package/esm/production/store/models/share.migration.mjs +27 -0
  93. package/esm/production/store/models/share.migration.mjs.map +1 -0
  94. package/esm/production/store/models/share.model.mjs +13 -0
  95. package/esm/production/store/models/share.model.mjs.map +1 -0
  96. package/esm/server/panel-files.mjs +35 -0
  97. package/esm/server/panel-files.mjs.map +1 -0
  98. package/esm/server/panel-routes.mjs +27 -7
  99. package/esm/server/panel-routes.mjs.map +1 -1
  100. package/esm/server/session-routes.mjs +2 -1
  101. package/esm/server/session-routes.mjs.map +1 -1
  102. package/esm/types.d.mts +87 -4
  103. package/esm/types.d.mts.map +1 -1
  104. package/llms-full.txt +41 -4
  105. package/package.json +8 -8
  106. package/skills/SKILL.md +41 -4
  107. package/ui/dashboard/assets/app.css +1 -1
  108. package/ui/dashboard/assets/app.js +16 -16
  109. package/ui/dashboard/build-info.json +10 -10
  110. package/ui/dashboard/index.html +1 -0
  111. package/ui/panels/processes.js +12 -3
  112. package/cjs/auth-DzU0gHDG.cjs.map +0 -1
  113. package/cjs/boot-BQi0Etor.cjs.map +0 -1
  114. package/cjs/cascade-store-pHjKeSFm.cjs.map +0 -1
  115. package/cjs/http-CabcUwBx.cjs.map +0 -1
  116. package/cjs/migrations-w7GMsrQw.cjs.map +0 -1
  117. package/cjs/options-CWqFC5__.cjs.map +0 -1
  118. package/cjs/panels-B0dAfGbJ.cjs.map +0 -1
  119. package/cjs/server-B6xdeKS8.cjs.map +0 -1
  120. package/cjs/src-Ce-3Lniv.cjs.map +0 -1
  121. package/cjs/stream-route-BGJa-zQu.cjs.map +0 -1
@@ -1,7 +1,9 @@
1
- const require_panels = require("./panels-B0dAfGbJ.cjs");
2
- const require_errors = require("./errors-CyZp5yS-.cjs");
1
+ const require_contracts = require("./contracts-CDuY-ahl.cjs");
2
+ const require_panels = require("./panels-CHd20RK5.cjs");
3
+ const require_errors = require("./errors-DEqdWaqm.cjs");
3
4
  const require_ip = require("./ip-DbNhPOzi.cjs");
4
- const require_stream_route = require("./stream-route-BGJa-zQu.cjs");
5
+ const require_helpers = require("./helpers-7k_Q-abk.cjs");
6
+ const require_stream_route = require("./stream-route-D4k-sJvW.cjs");
5
7
  let node_crypto = require("node:crypto");
6
8
  let node_net = require("node:net");
7
9
 
@@ -9,6 +11,7 @@ let node_net = require("node:net");
9
11
  const PUBLIC = { type: "public" };
10
12
  const VIEWER = { type: "viewer" };
11
13
  const ADMIN = { type: "admin" };
14
+ const SHARE = { type: "share" };
12
15
  const pending = (...stages) => ({
13
16
  type: "pending",
14
17
  stages
@@ -23,9 +26,10 @@ const ALL_STEPS = [
23
26
  * A route with no entry is `admin` (fail closed). A package panel `<id>`
24
27
  * gets `GET /api/<id>` and `GET /api/<id>/*` for viewers and every other
25
28
  * method there for admins, audited as `panel.action`; a url ending in `/*`
26
- * matches every pattern below it.
29
+ * matches every pattern below it. The share routes exist only when
30
+ * `options.share` is `true` (`production.share.enabled`).
27
31
  */
28
- function productionRouteAccess(panelIds) {
32
+ function productionRouteAccess(panelIds, options = {}) {
29
33
  const rule = (method, url, access, audit) => ({
30
34
  method,
31
35
  url,
@@ -84,6 +88,7 @@ function productionRouteAccess(panelIds) {
84
88
  rule("POST", "/api/queries/:shapeId/explain", ADMIN, "explain.run"),
85
89
  rule("GET", "/api/routes", VIEWER),
86
90
  rule("GET", "/panels/:id/:name", VIEWER),
91
+ rule("GET", "/panels/:id/files/*", VIEWER),
87
92
  rule("GET", "/api/mails", VIEWER),
88
93
  rule("GET", "/api/mails/:id", VIEWER),
89
94
  rule("GET", "/api/mails/:id/html", VIEWER),
@@ -96,6 +101,7 @@ function productionRouteAccess(panelIds) {
96
101
  rule("GET", "/docs", VIEWER),
97
102
  rule("GET", "/docs/swagger", VIEWER)
98
103
  ];
104
+ if (options.share === true) rules.push(rule("POST", "/api/share/open", PUBLIC), rule("GET", "/api/share/info", SHARE), rule("GET", "/api/share/view.js", SHARE), rule("GET", "/api/share/assets/:name", SHARE), rule("GET", "/api/share/files/*", SHARE), rule("GET", "/api/share/panel", SHARE), rule("GET", "/api/share/panel/*", SHARE), rule("GET", "/api/admin/shares", ADMIN), rule("POST", "/api/admin/shares", ADMIN), rule("DELETE", "/api/admin/shares/:id", ADMIN), rule("POST", "/api/admin/shares/revoke-all", ADMIN));
99
105
  for (const id of panelIds) {
100
106
  rules.push(rule("GET", `/api/${id}`, VIEWER), rule("GET", `/api/${id}/*`, VIEWER));
101
107
  for (const method of [
@@ -186,6 +192,12 @@ const DEVTOOLS_CSRF_HEADER = "x-devtools-csrf";
186
192
  const DEVTOOLS_SESSION_COOKIE = "__Secure-warlock-devtools";
187
193
  /** The session cookie name when `requireHttps` is off (local trials only). */
188
194
  const DEVTOOLS_SESSION_COOKIE_INSECURE = "warlock-devtools";
195
+ /** The share cookie name over HTTPS. */
196
+ const DEVTOOLS_SHARE_COOKIE = "__Secure-warlock-devtools-share";
197
+ /** The share cookie name when `requireHttps` is off (local trials only). */
198
+ const DEVTOOLS_SHARE_COOKIE_INSECURE = "warlock-devtools-share";
199
+ /** The longest a share cookie lives, whatever the link's expiry: 12 hours. */
200
+ const DEVTOOLS_SHARE_COOKIE_MAX_SECONDS = 43200;
189
201
 
190
202
  //#endregion
191
203
  //#region ../../packages/devtools/src/production/http/context.ts
@@ -233,16 +245,37 @@ function readCookie(header, name) {
233
245
  }
234
246
  }
235
247
  }
248
+ /** The share cookie name for the HTTPS mode. */
249
+ function shareCookieName(secure) {
250
+ return secure ? DEVTOOLS_SHARE_COOKIE : DEVTOOLS_SHARE_COOKIE_INSECURE;
251
+ }
252
+ /**
253
+ * `Set-Cookie` value for a share grant (or a clearing cookie when `value` is
254
+ * `null`). Scoped to the dashboard path, `HttpOnly`, `SameSite=Strict`, no
255
+ * `Domain`, and it ends after `maxAgeSeconds`.
256
+ */
257
+ function shareCookie(value, options) {
258
+ const parts = [
259
+ `${shareCookieName(options.secure)}=${value ?? ""}`,
260
+ `Path=${options.path}`,
261
+ "HttpOnly",
262
+ "SameSite=Strict"
263
+ ];
264
+ if (options.secure) parts.push("Secure");
265
+ if (value === null) parts.push("Max-Age=0", "Expires=Thu, 01 Jan 1970 00:00:00 GMT");
266
+ else parts.push(`Max-Age=${Math.max(1, Math.floor(options.maxAgeSeconds ?? 0))}`);
267
+ return parts.join("; ");
268
+ }
236
269
 
237
270
  //#endregion
238
271
  //#region ../../packages/devtools/src/production/http/auth-routes.ts
239
272
  const MAX_TEXT = 1024;
240
273
  const MAX_EMAIL = 320;
241
274
  const MAX_CODE = 128;
242
- const MAX_TOKEN = 512;
275
+ const MAX_TOKEN$1 = 512;
243
276
  const ROLES = ["admin", "viewer"];
244
277
  /** A request body that is a plain JSON object, or `input.invalid`. */
245
- function bodyOf(request) {
278
+ function bodyOf$1(request) {
246
279
  const body = request.body;
247
280
  if (body === null || typeof body !== "object" || Array.isArray(body)) throw new require_errors.DevtoolsApiError("input.invalid");
248
281
  return body;
@@ -279,7 +312,7 @@ function idParam(request) {
279
312
  }
280
313
  /** The `current` password of a request that may have no body (a DELETE). */
281
314
  function currentOf(request) {
282
- return request.body === void 0 || request.body === null ? void 0 : optionalText(bodyOf(request), "current");
315
+ return request.body === void 0 || request.body === null ? void 0 : optionalText(bodyOf$1(request), "current");
283
316
  }
284
317
  /** What the gate stored, for a route that is never reached without it. */
285
318
  function contextOf(request) {
@@ -334,7 +367,7 @@ function registerAuthRoutes(server, deps) {
334
367
  return auth.sessionView(authenticated);
335
368
  });
336
369
  server.post("/api/auth/login", async (request, reply) => {
337
- const body = bodyOf(request);
370
+ const body = bodyOf$1(request);
338
371
  const step = await auth.login({
339
372
  email: email(body),
340
373
  password: text(body, "password")
@@ -342,28 +375,28 @@ function registerAuthRoutes(server, deps) {
342
375
  return answerStep(reply, step);
343
376
  });
344
377
  server.post("/api/auth/setup", async (request, reply) => {
345
- const body = bodyOf(request);
378
+ const body = bodyOf$1(request);
346
379
  const step = await auth.setup({
347
- token: text(body, "token", MAX_TOKEN),
380
+ token: text(body, "token", MAX_TOKEN$1),
348
381
  password: text(body, "password")
349
382
  }, metaOf(request));
350
383
  return answerStep(reply, step);
351
384
  });
352
385
  server.post("/api/auth/invite/inspect", async (request) => {
353
- const body = bodyOf(request);
354
- return auth.inspectInvite(text(body, "token", MAX_TOKEN));
386
+ const body = bodyOf$1(request);
387
+ return auth.inspectInvite(text(body, "token", MAX_TOKEN$1));
355
388
  });
356
389
  server.post("/api/auth/invite/accept", async (request, reply) => {
357
- const body = bodyOf(request);
390
+ const body = bodyOf$1(request);
358
391
  const step = await auth.acceptInvite({
359
- token: text(body, "token", MAX_TOKEN),
392
+ token: text(body, "token", MAX_TOKEN$1),
360
393
  password: text(body, "password")
361
394
  }, metaOf(request));
362
395
  return answerStep(reply, step);
363
396
  });
364
397
  const changePassword = async (request, reply) => {
365
398
  const { auth: authenticated, meta } = contextOf(request);
366
- const body = bodyOf(request);
399
+ const body = bodyOf$1(request);
367
400
  const current = optionalText(body, "current");
368
401
  const step = await auth.changePassword(authenticated, {
369
402
  ...current === void 0 ? {} : { current },
@@ -377,17 +410,17 @@ function registerAuthRoutes(server, deps) {
377
410
  };
378
411
  const confirmTotp = async (request, reply) => {
379
412
  const { auth: authenticated, meta } = contextOf(request);
380
- const body = bodyOf(request);
413
+ const body = bodyOf$1(request);
381
414
  const result = await auth.confirmTotp(authenticated, text(body, "code", MAX_CODE), meta, optionalText(body, "current"));
382
415
  return answerStep(reply, result.step, result.recoveryCodes);
383
416
  };
384
417
  const passkeyOptions = async (request) => {
385
418
  const { auth: authenticated, meta } = contextOf(request);
386
- return auth.passkeyOptions(authenticated, purpose(bodyOf(request)), meta);
419
+ return auth.passkeyOptions(authenticated, purpose(bodyOf$1(request)), meta);
387
420
  };
388
421
  const passkeyVerify = async (request, reply) => {
389
422
  const { auth: authenticated, meta } = contextOf(request);
390
- const body = bodyOf(request);
423
+ const body = bodyOf$1(request);
391
424
  if (body.response === null || typeof body.response !== "object") throw new require_errors.DevtoolsApiError("input.invalid");
392
425
  const result = await auth.verifyPasskey(authenticated, purpose(body), body.response, meta, optionalText(body, "current"));
393
426
  if (result.step === null) return {
@@ -403,7 +436,7 @@ function registerAuthRoutes(server, deps) {
403
436
  server.post("/api/auth/passkey/verify", passkeyVerify);
404
437
  server.post("/api/auth/mfa", async (request, reply) => {
405
438
  const { auth: authenticated, meta } = contextOf(request);
406
- const body = bodyOf(request);
439
+ const body = bodyOf$1(request);
407
440
  const code = optionalText(body, "code", MAX_CODE);
408
441
  const recoveryCode = optionalText(body, "recoveryCode", MAX_CODE);
409
442
  if (code === void 0 === (recoveryCode === void 0)) throw new require_errors.DevtoolsApiError("input.invalid");
@@ -439,7 +472,7 @@ function registerAuthRoutes(server, deps) {
439
472
  });
440
473
  server.post("/api/account/recovery-codes", async (request) => {
441
474
  const { auth: authenticated, meta } = contextOf(request);
442
- return { codes: await auth.regenerateRecoveryCodes(authenticated, optionalText(bodyOf(request), "code", MAX_CODE) ?? "", meta) };
475
+ return { codes: await auth.regenerateRecoveryCodes(authenticated, optionalText(bodyOf$1(request), "code", MAX_CODE) ?? "", meta) };
443
476
  });
444
477
  server.post("/api/account/passkey/options", passkeyOptions);
445
478
  server.post("/api/account/passkey/verify", passkeyVerify);
@@ -454,7 +487,7 @@ function registerAuthRoutes(server, deps) {
454
487
  });
455
488
  server.post("/api/admin/invites", async (request) => {
456
489
  const { auth: authenticated, meta } = contextOf(request);
457
- const body = bodyOf(request);
490
+ const body = bodyOf$1(request);
458
491
  return auth.createInvite(authenticated, {
459
492
  email: email(body),
460
493
  role: role(body)
@@ -467,7 +500,7 @@ function registerAuthRoutes(server, deps) {
467
500
  });
468
501
  server.patch("/api/admin/users/:id", async (request) => {
469
502
  const { auth: authenticated, meta } = contextOf(request);
470
- return auth.setRole(authenticated, idParam(request), role(bodyOf(request)), meta);
503
+ return auth.setRole(authenticated, idParam(request), role(bodyOf$1(request)), meta);
471
504
  });
472
505
  server.delete("/api/admin/users/:id", async (request, reply) => {
473
506
  const { auth: authenticated, meta } = contextOf(request);
@@ -501,7 +534,7 @@ function registerAuthRoutes(server, deps) {
501
534
  });
502
535
  server.post("/api/admin/disable", async (request, reply) => {
503
536
  const { auth: authenticated, meta } = contextOf(request);
504
- if (bodyOf(request).confirm !== "disable") throw new require_errors.DevtoolsApiError("input.invalid");
537
+ if (bodyOf$1(request).confirm !== "disable") throw new require_errors.DevtoolsApiError("input.invalid");
505
538
  await auth.disableDashboard(authenticated, meta);
506
539
  state.invalidate();
507
540
  return reply.code(204).send();
@@ -531,6 +564,441 @@ const DASHBOARD_CSP = "default-src 'self'; script-src 'self'; style-src 'self' '
531
564
  */
532
565
  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'";
533
566
 
567
+ //#endregion
568
+ //#region ../../packages/devtools/src/production/http/share-session.ts
569
+ /** How long a read of a share record is reused. A revoke reaches every instance within this time. */
570
+ const SHARE_CACHE_MS = 5e3;
571
+ /** Records kept in the cache of one process (oldest evicted). */
572
+ const SHARE_CACHE_SIZE = 500;
573
+ /** A link's use is written at most this often per link and process. */
574
+ const TOUCH_INTERVAL_MS = 6e4;
575
+ /**
576
+ * The share grant: a cookie carrying `<shareId>.<exp>.<HMAC-SHA256(key,
577
+ * "share:<id>:<exp>")>`. The signature proves this server issued it; the
578
+ * link's record, read through a 5-second cache, proves it is still alive, so
579
+ * a revoke takes effect everywhere within that time without a session table.
580
+ */
581
+ function createShareSessions(input) {
582
+ const { store, hmac } = input;
583
+ const now = input.now ?? (() => Date.now());
584
+ const panels = new Map(input.panels.filter((panel) => panel.share !== null).map((panel) => [panel.id, panel]));
585
+ const cache = /* @__PURE__ */ new Map();
586
+ const touched = /* @__PURE__ */ new Map();
587
+ const sign = (id, exp) => hmac(`share:${id}:${exp}`);
588
+ async function record(id) {
589
+ const cached = cache.get(id);
590
+ if (cached && now() - cached.at < 5e3) return cached.record;
591
+ const found = await store.shares.get(id);
592
+ cache.delete(id);
593
+ if (cache.size >= SHARE_CACHE_SIZE) {
594
+ const oldest = cache.keys().next();
595
+ if (!oldest.done) cache.delete(oldest.value);
596
+ }
597
+ cache.set(id, {
598
+ record: found,
599
+ at: now()
600
+ });
601
+ return found;
602
+ }
603
+ function grantFor(share) {
604
+ if (share.revokedAt !== null) return {
605
+ refused: "revoked",
606
+ shareId: share.id
607
+ };
608
+ if (share.expiresAt <= now()) return {
609
+ refused: "expired",
610
+ shareId: share.id
611
+ };
612
+ const panel = panels.get(share.panel);
613
+ return panel ? { grant: {
614
+ share,
615
+ panel
616
+ } } : {
617
+ refused: "panel",
618
+ shareId: share.id
619
+ };
620
+ }
621
+ return {
622
+ issue(share) {
623
+ const remaining = Math.floor((share.expiresAt - now()) / 1e3);
624
+ const maxAgeSeconds = Math.max(1, Math.min(remaining, DEVTOOLS_SHARE_COOKIE_MAX_SECONDS));
625
+ const exp = now() + maxAgeSeconds * 1e3;
626
+ return {
627
+ value: `${share.id}.${exp}.${sign(share.id, exp)}`,
628
+ maxAgeSeconds
629
+ };
630
+ },
631
+ async verify(value) {
632
+ const parts = (value ?? "").split(".");
633
+ const [id, expText, signature] = parts;
634
+ if (parts.length !== 3 || !id || !expText || !signature || !/^\d{1,16}$/.test(expText)) return {
635
+ refused: "cookie",
636
+ shareId: null
637
+ };
638
+ const exp = Number(expText);
639
+ if (!require_helpers.safeEqual(signature, sign(id, exp)) || exp <= now()) return {
640
+ refused: "cookie",
641
+ shareId: null
642
+ };
643
+ const share = await record(id);
644
+ return share ? grantFor(share) : {
645
+ refused: "unknown",
646
+ shareId: id
647
+ };
648
+ },
649
+ async open(tokenHash) {
650
+ const share = await store.shares.findByTokenHash(tokenHash);
651
+ return share ? grantFor(share) : {
652
+ refused: "unknown",
653
+ shareId: null
654
+ };
655
+ },
656
+ touch(shareId) {
657
+ const at = now();
658
+ const last = touched.get(shareId);
659
+ if (last !== void 0 && at - last < TOUCH_INTERVAL_MS) return;
660
+ touched.delete(shareId);
661
+ if (touched.size >= SHARE_CACHE_SIZE) {
662
+ const oldest = touched.keys().next();
663
+ if (!oldest.done) touched.delete(oldest.value);
664
+ }
665
+ touched.set(shareId, at);
666
+ store.shares.touch(shareId, at).catch((error) => {
667
+ input.warn?.(`devtools could not record a share link use: ${error instanceof Error ? error.message : String(error)}`);
668
+ });
669
+ },
670
+ invalidate() {
671
+ cache.clear();
672
+ }
673
+ };
674
+ }
675
+
676
+ //#endregion
677
+ //#region ../../packages/devtools/src/production/http/share.ts
678
+ const DAY_MS = 864e5;
679
+ const MAX_TOKEN = 512;
680
+ const MAX_PANEL_ID = 64;
681
+ /** A failed token is not looked up again for this long once its client is over the limit. */
682
+ const BLOCK_CACHE_MS = 3e4;
683
+ const BLOCK_CACHE_SIZE = 1e3;
684
+ /** A cookie failure is audited at most this often per client (a revoked link in use must not flood the log). */
685
+ const COOKIE_AUDIT_INTERVAL_MS = 6e4;
686
+ /** The path pattern `pattern` (`/flows/:feature`) matched against `path`, as its params; `null` for no match. */
687
+ function matchSharePath(pattern, path) {
688
+ if (/[\0\\]/.test(path)) return null;
689
+ const wanted = pattern.split("/");
690
+ const given = path.split("/");
691
+ if (wanted.length !== given.length) return null;
692
+ const params = {};
693
+ for (const [index, part] of wanted.entries()) {
694
+ const actual = given[index];
695
+ if (actual === void 0) return null;
696
+ if (part.startsWith(":")) {
697
+ if (actual === "") return null;
698
+ params[part.slice(1)] = actual;
699
+ } else if (part !== actual) return null;
700
+ }
701
+ return params;
702
+ }
703
+ function bodyOf(request) {
704
+ const body = request.body;
705
+ if (body === null || typeof body !== "object" || Array.isArray(body)) throw new require_errors.DevtoolsApiError("input.invalid");
706
+ return body;
707
+ }
708
+ function viewOf(record, createdBy, at) {
709
+ return {
710
+ id: record.id,
711
+ panel: record.panel,
712
+ label: record.label,
713
+ createdBy,
714
+ createdAt: record.createdAt,
715
+ expiresAt: record.expiresAt,
716
+ revokedAt: record.revokedAt,
717
+ lastUsedAt: record.lastUsedAt,
718
+ uses: record.uses,
719
+ status: record.revokedAt !== null ? "revoked" : record.expiresAt <= at ? "expired" : "active"
720
+ };
721
+ }
722
+ function openAnswer(grant) {
723
+ const { panel, share } = grant;
724
+ return {
725
+ panel: panel.id,
726
+ title: panel.title,
727
+ label: share.label,
728
+ expiresAt: share.expiresAt,
729
+ assets: [...panel.share?.assets ?? []],
730
+ files: panel.share?.files === true
731
+ };
732
+ }
733
+ /**
734
+ * Read-only share links of the production monitor. An admin creates a link
735
+ * for a panel that declares `share`; the token is shown once and only its
736
+ * SHA-256 is stored. Opening a link exchanges the token for a scoped cookie
737
+ * (`__Secure-warlock-devtools-share`) that reaches only that panel's shared
738
+ * view. Every refusal answers the dashboard's uniform 404, is audited as
739
+ * `share.failed` (which counts toward the per-IP failure limit) and never
740
+ * records the token.
741
+ */
742
+ function createDevtoolsShare(deps) {
743
+ const { production, store, auth } = deps;
744
+ const now = deps.now ?? (() => Date.now());
745
+ if (typeof deps.hmac !== "function") throw new Error("Share links need deps.hmac (HMAC-SHA256 keyed with encryption.key).");
746
+ const sessions = createShareSessions({
747
+ store,
748
+ panels: deps.panels,
749
+ hmac: deps.hmac,
750
+ now,
751
+ ...deps.warn ? { warn: deps.warn } : {}
752
+ });
753
+ const cookieOptions = {
754
+ path: production.path,
755
+ secure: production.requireHttps
756
+ };
757
+ const cookieName = shareCookieName(production.requireHttps);
758
+ const sharePanels = deps.panels.filter((panel) => panel.share !== null);
759
+ const blocked = /* @__PURE__ */ new Map();
760
+ const cookieAudited = /* @__PURE__ */ new Map();
761
+ const limits = production.rateLimits;
762
+ const windowMs = limits.windowMinutes * 6e4;
763
+ async function overLimit(ip) {
764
+ const client = require_ip.rateLimitClient(ip);
765
+ const at = now();
766
+ const until = blocked.get(client);
767
+ if (until !== void 0 && at < until) return true;
768
+ const state = await store.state.read();
769
+ const since = Math.max(at - windowMs, state.failuresResetAt ?? 0);
770
+ const count = await store.audit.count({
771
+ types: require_contracts.DEVTOOLS_FAILURE_AUDIT_TYPES,
772
+ since,
773
+ ip
774
+ });
775
+ blocked.delete(client);
776
+ if (count < limits.ip) return false;
777
+ if (blocked.size >= BLOCK_CACHE_SIZE) {
778
+ const oldest = blocked.keys().next();
779
+ if (!oldest.done) blocked.delete(oldest.value);
780
+ }
781
+ blocked.set(client, at + BLOCK_CACHE_MS);
782
+ return true;
783
+ }
784
+ /** Writes one `share.failed` entry (never the token). Never throws. */
785
+ async function failed(meta, reason, shareId) {
786
+ await auth.audit("share.failed", {
787
+ meta,
788
+ detail: {
789
+ reason,
790
+ share: shareId
791
+ }
792
+ });
793
+ }
794
+ /** The cookie check for a share request. */
795
+ async function authorize(request, meta) {
796
+ const value = readCookie(request.headers.cookie, cookieName);
797
+ if (value === void 0) return null;
798
+ let result;
799
+ try {
800
+ result = await sessions.verify(value);
801
+ } catch (error) {
802
+ deps.warn?.(`A devtools share link could not be checked and the request was refused: ${error instanceof Error ? error.message : String(error)}`);
803
+ return null;
804
+ }
805
+ if ("grant" in result) {
806
+ sessions.touch(result.grant.share.id);
807
+ return result.grant;
808
+ }
809
+ const client = require_ip.rateLimitClient(meta.ip);
810
+ const last = cookieAudited.get(client);
811
+ if (last === void 0 || now() - last >= COOKIE_AUDIT_INTERVAL_MS) {
812
+ cookieAudited.delete(client);
813
+ if (cookieAudited.size >= BLOCK_CACHE_SIZE) {
814
+ const oldest = cookieAudited.keys().next();
815
+ if (!oldest.done) cookieAudited.delete(oldest.value);
816
+ }
817
+ cookieAudited.set(client, now());
818
+ try {
819
+ if (!await overLimit(meta.ip)) await failed(meta, result.refused, result.shareId);
820
+ } catch {}
821
+ }
822
+ return null;
823
+ }
824
+ function grantOf(request) {
825
+ const grant = devtoolsRequestContext(request)?.share;
826
+ if (!grant) throw new Error("A share route ran without its grant.");
827
+ return grant;
828
+ }
829
+ function createdByOf(accounts, id) {
830
+ return accounts.find((account) => account.id === id)?.email ?? null;
831
+ }
832
+ async function list() {
833
+ const [records, accounts] = await Promise.all([store.shares.list(), store.accounts.list()]);
834
+ const at = now();
835
+ return {
836
+ enabled: true,
837
+ maxDays: production.share.maxDays,
838
+ panels: sharePanels.map((panel) => ({
839
+ id: panel.id,
840
+ title: panel.title
841
+ })),
842
+ shares: records.map((record) => viewOf(record, createdByOf(accounts, record.createdBy), at))
843
+ };
844
+ }
845
+ async function create(authenticated, meta, body) {
846
+ const panel = body.panel;
847
+ const label = typeof body.label === "string" ? body.label.trim() : "";
848
+ const days = body.days;
849
+ if (typeof panel !== "string" || panel.length > MAX_PANEL_ID || !sharePanels.some((item) => item.id === panel) || label === "" || label.length > 80 || /[\u0000-\u001f\u007f]/.test(label) || typeof days !== "number" || !Number.isInteger(days) || days < 1 || days > production.share.maxDays) throw new require_errors.DevtoolsApiError("input.invalid");
850
+ const token = require_helpers.generateToken();
851
+ const at = now();
852
+ const record = await store.shares.create({
853
+ tokenHash: require_helpers.hashToken(token),
854
+ panel,
855
+ label,
856
+ createdBy: authenticated.account.id,
857
+ createdAt: at,
858
+ expiresAt: at + days * DAY_MS
859
+ });
860
+ sessions.invalidate();
861
+ await auth.audit("share.created", {
862
+ auth: authenticated,
863
+ meta,
864
+ detail: {
865
+ share: record.id,
866
+ panel,
867
+ days
868
+ }
869
+ });
870
+ return {
871
+ share: viewOf(record, authenticated.account.email, at),
872
+ url: `${meta.origin}${production.path}/#/share/${token}`
873
+ };
874
+ }
875
+ function register(server, notFound) {
876
+ const requireAuth = (request) => {
877
+ const context = devtoolsRequestContext(request);
878
+ if (!context?.authenticated) throw new Error("A dashboard route ran without its session.");
879
+ return {
880
+ auth: context.authenticated,
881
+ meta: context.meta
882
+ };
883
+ };
884
+ server.post("/api/share/open", async (request, reply) => {
885
+ const context = devtoolsRequestContext(request);
886
+ if (!context) return notFound(request, reply);
887
+ const { meta } = context;
888
+ const token = request.body?.token;
889
+ if (typeof token !== "string" || token === "" || token.length > MAX_TOKEN) return notFound(request, reply);
890
+ try {
891
+ if (await overLimit(meta.ip)) return notFound(request, reply);
892
+ const result = await sessions.open(require_helpers.hashToken(token));
893
+ if (!("grant" in result)) {
894
+ await failed(meta, result.refused, result.shareId);
895
+ return notFound(request, reply);
896
+ }
897
+ const { value, maxAgeSeconds } = sessions.issue(result.grant.share);
898
+ sessions.touch(result.grant.share.id);
899
+ reply.header("set-cookie", shareCookie(value, {
900
+ ...cookieOptions,
901
+ maxAgeSeconds
902
+ }));
903
+ return openAnswer(result.grant);
904
+ } catch (error) {
905
+ deps.warn?.(`A devtools share link could not be opened: ${error instanceof Error ? error.message : String(error)}`);
906
+ return notFound(request, reply);
907
+ }
908
+ });
909
+ server.get("/api/share/info", async (request) => openAnswer(grantOf(request)));
910
+ server.get("/api/share/view.js", async (request, reply) => {
911
+ const view = grantOf(request).panel.share?.view;
912
+ if (view === void 0) return notFound(request, reply);
913
+ require_stream_route.sendFile(reply, view, "text/javascript; charset=utf-8");
914
+ return reply;
915
+ });
916
+ server.get("/api/share/assets/:name", async (request, reply) => {
917
+ const { panel } = grantOf(request);
918
+ const name = request.params.name;
919
+ const file = panel.share?.assets.includes(name) === true && Object.hasOwn(panel.assets, name) ? panel.assets[name] : void 0;
920
+ if (file === void 0) return notFound(request, reply);
921
+ require_stream_route.sendFile(reply, file, require_panels.panelContentType(name));
922
+ return reply;
923
+ });
924
+ server.get("/api/share/files/*", async (request, reply) => {
925
+ const { panel } = grantOf(request);
926
+ return require_stream_route.sendPanelFile({ files: panel.share?.files === true ? panel.files : null }, request.params["*"], request, reply, notFound);
927
+ });
928
+ const panelRoute = async (request, reply) => {
929
+ const { panel } = grantOf(request);
930
+ const sub = request.params["*"];
931
+ const path = sub === void 0 || sub === "" ? "" : `/${sub}`;
932
+ let matched = null;
933
+ for (const pattern of panel.share?.routes ?? []) {
934
+ const params = matchSharePath(pattern, path);
935
+ const route = panel.routes.find((candidate) => candidate.method === "GET" && candidate.path === pattern);
936
+ if (params !== null && route !== void 0) {
937
+ matched = {
938
+ route,
939
+ params
940
+ };
941
+ break;
942
+ }
943
+ }
944
+ if (matched === null) return notFound(request, reply);
945
+ const input = {
946
+ params: matched.params,
947
+ query: request.query ?? {},
948
+ body: void 0,
949
+ shared: true
950
+ };
951
+ const result = await matched.route.handler(input);
952
+ reply.header("cache-control", "no-store");
953
+ if (result === void 0) return reply.code(204).send();
954
+ return result;
955
+ };
956
+ server.get("/api/share/panel", panelRoute);
957
+ server.get("/api/share/panel/*", panelRoute);
958
+ server.get("/api/admin/shares", async () => list());
959
+ server.post("/api/admin/shares", async (request, reply) => {
960
+ const { auth: authenticated, meta } = requireAuth(request);
961
+ const created = await create(authenticated, meta, bodyOf(request));
962
+ return reply.code(201).send(created);
963
+ });
964
+ server.delete("/api/admin/shares/:id", async (request, reply) => {
965
+ const { auth: authenticated, meta } = requireAuth(request);
966
+ const id = request.params.id;
967
+ if (typeof id !== "string" || id === "" || id.length > 64) throw new require_errors.DevtoolsApiError("input.invalid");
968
+ const record = await store.shares.get(id);
969
+ if (!record || !await store.shares.revoke(id, now())) throw new require_errors.DevtoolsApiError("share.not-found");
970
+ sessions.invalidate();
971
+ await auth.audit("share.revoked", {
972
+ auth: authenticated,
973
+ meta,
974
+ detail: {
975
+ share: id,
976
+ panel: record.panel
977
+ }
978
+ });
979
+ return reply.code(204).send();
980
+ });
981
+ server.post("/api/admin/shares/revoke-all", async (request) => {
982
+ const { auth: authenticated, meta } = requireAuth(request);
983
+ const revoked = await store.shares.revokeAll(now());
984
+ sessions.invalidate();
985
+ await auth.audit("share.revoked", {
986
+ auth: authenticated,
987
+ meta,
988
+ detail: {
989
+ all: true,
990
+ count: revoked
991
+ }
992
+ });
993
+ return { revoked };
994
+ });
995
+ }
996
+ return {
997
+ authorize,
998
+ register
999
+ };
1000
+ }
1001
+
534
1002
  //#endregion
535
1003
  //#region ../../packages/devtools/src/production/http/mount.ts
536
1004
  /** Open live streams a session may hold, and an instance may serve. */
@@ -545,6 +1013,8 @@ const SAFE_METHODS = /* @__PURE__ */ new Set([
545
1013
  ]);
546
1014
  /** The routes of the opt-in API documentation pages (they keep a CSP of their own). */
547
1015
  const DOCS_PATTERNS = /* @__PURE__ */ new Set(["/docs", "/docs/swagger"]);
1016
+ /** The grant exchange of a share link: every failure of it answers the uniform 404. */
1017
+ const SHARE_OPEN_PATTERN = "/api/share/open";
548
1018
  /** The mail preview's HTML: framed by the dashboard, with a policy of its own. */
549
1019
  const MAIL_HTML_PATTERN = "/api/mails/:id/html";
550
1020
  /** Which tab a route belongs to: a route of a tab that is off answers the uniform 404. */
@@ -607,7 +1077,8 @@ function mountProductionDevtools(server, deps) {
607
1077
  const prefix = production.path;
608
1078
  const cookieName = sessionCookieName(production.requireHttps);
609
1079
  const enabledTabs = new Set(deps.builtInPanels);
610
- const lookup = createAccessLookup(productionRouteAccess(deps.panels.map((panel) => panel.id)));
1080
+ const share = production.share.enabled ? createDevtoolsShare(deps) : null;
1081
+ const lookup = createAccessLookup(productionRouteAccess(deps.panels.map((panel) => panel.id), { share: share !== null }));
611
1082
  const streamsPerSession = /* @__PURE__ */ new Map();
612
1083
  let streamsInstance = 0;
613
1084
  let lastWarningAt = 0;
@@ -708,6 +1179,19 @@ function mountProductionDevtools(server, deps) {
708
1179
  const rule = lookup(method, pattern);
709
1180
  const access = rule?.access ?? { type: "admin" };
710
1181
  let authenticated = null;
1182
+ if (access.type === "share") {
1183
+ const grant = share ? await share.authorize(request, meta) : null;
1184
+ if (grant === null) return notFound(request, reply);
1185
+ setDevtoolsRequestContext(request, {
1186
+ client,
1187
+ meta,
1188
+ rule,
1189
+ pattern,
1190
+ authenticated: null,
1191
+ share: grant
1192
+ });
1193
+ return;
1194
+ }
711
1195
  if (access.type !== "public") {
712
1196
  try {
713
1197
  authenticated = await auth.authenticate(readCookie(request.headers.cookie, cookieName));
@@ -739,7 +1223,10 @@ function mountProductionDevtools(server, deps) {
739
1223
  if (authenticated === null) return notFound(request, reply);
740
1224
  throw new require_errors.DevtoolsApiError("csrf.invalid");
741
1225
  }
742
- if (hasBody(request) && !isJson(request)) throw new require_errors.DevtoolsApiError("input.invalid");
1226
+ if (hasBody(request) && !isJson(request)) {
1227
+ if (pattern === SHARE_OPEN_PATTERN) return notFound(request, reply);
1228
+ throw new require_errors.DevtoolsApiError("input.invalid");
1229
+ }
743
1230
  if (authenticated !== null) {
744
1231
  const header = request.headers[DEVTOOLS_CSRF_HEADER];
745
1232
  if (!auth.verifyCsrf(authenticated, Array.isArray(header) ? header[0] : header)) throw new require_errors.DevtoolsApiError("csrf.invalid");
@@ -775,6 +1262,7 @@ function mountProductionDevtools(server, deps) {
775
1262
  });
776
1263
  });
777
1264
  instance.setErrorHandler((error, request, reply) => {
1265
+ if (devtoolsRequestContext(request)?.pattern === SHARE_OPEN_PATTERN) return notFound(request, reply);
778
1266
  if (error instanceof require_errors.DevtoolsApiError) return reply.code(error.statusCode).send(error.toBody());
779
1267
  const status = error.statusCode;
780
1268
  if (status !== void 0 && status >= 400 && status < 500) return reply.code(status).send(error.code?.startsWith("FST_ERR_") ? new require_errors.DevtoolsApiError("input.invalid").toBody() : { error: error.message });
@@ -798,7 +1286,8 @@ function mountProductionDevtools(server, deps) {
798
1286
  require_stream_route.registerInsightsRoutes(instance, routes);
799
1287
  require_stream_route.registerLogRoutes(instance, routes);
800
1288
  require_stream_route.registerShapeExplainRoute(instance, routes);
801
- require_stream_route.registerPanelRoutes(instance, deps.panels);
1289
+ require_stream_route.registerPanelRoutes(instance, deps.panels, { notFound });
1290
+ share?.register(instance, notFound);
802
1291
  if (enabledTabs.has("mail")) require_stream_route.registerMailRoutes(instance, routes);
803
1292
  if (enabledTabs.has("ai") || enabledTabs.has("agents")) require_stream_route.registerAiRoutes(instance, routes);
804
1293
  if (enabledTabs.has("api")) require_stream_route.registerOpenApiRoutes(instance, routes);
@@ -867,4 +1356,4 @@ exports.mountProductionDevtools = mountProductionDevtools;
867
1356
  exports.productionRouteAccess = productionRouteAccess;
868
1357
  exports.resolveClient = resolveClient;
869
1358
  exports.sessionCookie = sessionCookie;
870
- //# sourceMappingURL=http-CabcUwBx.cjs.map
1359
+ //# sourceMappingURL=http-XNLYU2vS.cjs.map