nish-ui 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/README.md +6 -3
  2. package/dist/chart.js +2 -2
  3. package/dist/elements-all.js +28 -28
  4. package/dist/elements-charts.d.ts +1 -1
  5. package/dist/elements-charts.js +22 -22
  6. package/dist/elements-data.js +2 -2
  7. package/dist/elements-forms.js +8 -8
  8. package/dist/elements.js +3 -3
  9. package/dist/esm/chart-values.js +2 -1
  10. package/dist/esm/combobox-filter.js +6 -5
  11. package/dist/esm/command-filter.js +32 -0
  12. package/dist/esm/components/accordion.js +2 -1
  13. package/dist/esm/components/app-shell.js +1 -1
  14. package/dist/esm/components/breadcrumbs.js +1 -1
  15. package/dist/esm/components/calendar-base.js +1 -1
  16. package/dist/esm/components/combobox.js +2 -2
  17. package/dist/esm/components/command.js +5 -5
  18. package/dist/esm/components/data-classes.js +18 -4
  19. package/dist/esm/components/display.js +4 -4
  20. package/dist/esm/components/feedback.js +1 -1
  21. package/dist/esm/components/file-dropzone.js +23 -1
  22. package/dist/esm/components/flow.js +4 -4
  23. package/dist/esm/components/forms-classes.js +1 -1
  24. package/dist/esm/components/forms.js +6 -4
  25. package/dist/esm/components/inbox.js +4 -1
  26. package/dist/esm/components/menu.js +4 -0
  27. package/dist/esm/components/multi-select.js +2 -2
  28. package/dist/esm/components/nav-classes.js +9 -0
  29. package/dist/esm/components/nav.js +2 -1
  30. package/dist/esm/components/primitives-classes.js +4 -4
  31. package/dist/esm/components/primitives.js +1 -1
  32. package/dist/esm/components/radio-group.js +1 -1
  33. package/dist/esm/components/resource-classes.js +7 -3
  34. package/dist/esm/components/resource.js +3 -2
  35. package/dist/esm/components/settings.js +5 -1
  36. package/dist/esm/components/tabs.js +3 -2
  37. package/dist/esm/components/toast-store.js +16 -4
  38. package/dist/esm/components/url-state.js +2 -1
  39. package/dist/esm/format.js +24 -2
  40. package/dist/esm/runtime.js +9 -2
  41. package/dist/esm/split-layout.js +2 -1
  42. package/dist/format.js +33 -5
  43. package/dist/inbox-client.d.ts +5 -1
  44. package/dist/inbox-client.js +0 -1
  45. package/dist/index.d.ts +7 -4
  46. package/dist/nish-components.css +11 -2
  47. package/dist/nish-components.min.css +1 -1
  48. package/dist/server/hono.d.ts +1 -1
  49. package/dist/server/hono.js +91 -7
  50. package/dist/server/index.d.ts +20 -12
  51. package/dist/server/index.js +117 -27
  52. package/dist/{spa-7myD4xvA.d.ts → spa-BfRDo38r.d.ts} +32 -4
  53. package/dist/split-layout.js +2 -2
  54. package/dist/theme.global.js +9 -4
  55. package/dist/theme.js +9 -3
  56. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
- import { c as InboxEventInput, d as InboxIngestAction, e as InboxEvent, f as InboxAction, I as InboxActionCall, a as InboxData } from '../spa-7myD4xvA.js';
2
- export { g as ClientIpOptions, C as CrossSiteOptions, h as INBOX_ACTION_HEADER, i as INBOX_ACTION_TIMEOUT_MS, j as INBOX_DEFAULT_SETTINGS, k as INBOX_SOURCE_LABELS, l as InboxActionResult, m as InboxItem, n as InboxListResponse, o as InboxSettings, p as InboxSeverity, q as InboxView, L as Limiter, r as MIN_SECRET_BYTES, M as ManagedServiceTokens, R as RevocationStore, s as RevokedToken, t as SESSION_DAYS, u as ServiceTokenEntry, v as ServiceTokenView, w as ServiceTokens, S as SessionAuth, b as SpaOptions, T as TrustProxy, V as VerifyOptions, x as VerifyResult, y as checkServiceRequest, z as clientIp, A as createLimiter, B as createServiceTokens, D as createSessionAuth, E as createSessionToken, F as createSpaHandler, G as hashServiceToken, H as isCrossSiteWrite, J as isDirectLoopback, K as isLoopback, N as jsonRevocationStore, O as loadManagedServiceTokens, P as loadServiceTokens, Q as mintServiceToken, U as passwordMatches, W as readCookie, X as verifySessionToken } from '../spa-7myD4xvA.js';
1
+ import { c as InboxEventInput, d as InboxIngestAction, e as InboxEvent, f as InboxAction, I as InboxActionCall, a as InboxData } from '../spa-BfRDo38r.js';
2
+ export { g as ClientIpOptions, C as CrossSiteOptions, h as INBOX_ACTION_HEADER, i as INBOX_ACTION_TIMEOUT_MS, j as INBOX_DEFAULT_SETTINGS, k as INBOX_SOURCE_LABELS, l as InboxActionResult, m as InboxItem, n as InboxListResponse, o as InboxSettings, p as InboxSeverity, q as InboxView, L as Limiter, r as MIN_SECRET_BYTES, M as ManagedServiceTokens, R as RevocationStore, s as RevokedToken, t as SESSION_DAYS, u as ServiceTokenEntry, v as ServiceTokenView, w as ServiceTokens, S as SessionAuth, b as SpaOptions, T as TrustProxy, V as VerifyOptions, x as VerifyResult, y as checkServiceRequest, z as clientIp, A as createLimiter, B as createServiceTokens, D as createSessionAuth, E as createSessionToken, F as createSpaHandler, G as hashServiceToken, H as isCrossSiteWrite, J as isDirectLoopback, K as isLoopback, N as jsonRevocationStore, O as loadManagedServiceTokens, P as loadServiceTokens, Q as mintServiceToken, U as passwordMatches, W as readCookie, X as verifySessionToken } from '../spa-BfRDo38r.js';
3
3
 
4
4
  /** Folder `up` levels above the directory of `importMetaUrl` (dist/server/env.js, up 2 = repo root). */
5
5
  declare function appRoot(importMetaUrl: string, up?: number): string;
@@ -50,6 +50,19 @@ declare function errorResponse(err: unknown, req: {
50
50
  };
51
51
  };
52
52
 
53
+ type HeaderBag = Headers | Record<string, string | string[] | undefined>;
54
+ /** The one shared "direct call to this app on this PC" check. True only when every rule holds:
55
+ * remoteAddress is 127.0.0.1, ::1 or ::ffff:127.0.0.1; header host === `127.0.0.1:${port}`;
56
+ * none of these headers is present: forwarded, via, x-real-ip, true-client-ip, cdn-loop, origin, and any name
57
+ * starting with x-forwarded- or cf-; no sec-fetch-* header (site, dest, user: browsers only) except
58
+ * sec-fetch-mode with the exact value 'cors', which Node's own fetch (undici) always sends.
59
+ * Header names compared lowercase; Headers and Node IncomingHttpHeaders both accepted. */
60
+ declare function isDirectCall(req: {
61
+ headers: HeaderBag;
62
+ remoteAddress: string | null | undefined;
63
+ port: number;
64
+ }): boolean;
65
+
53
66
  /** Whether `target` is an allowed action target: http://127.0.0.1 with an explicit port, no credentials,
54
67
  * no #hash, at most 2000 characters. The inbox service re-checks this before every call. */
55
68
  declare function isInboxActionTarget(target: unknown): target is string;
@@ -103,21 +116,16 @@ declare function createInboxClient(options: InboxClientOptions): InboxClient;
103
116
  declare const INBOX_ACTION_PATH = "/api/inbox/action";
104
117
  declare const ACTION_TOKEN_FIELD = "actionToken";
105
118
  declare const inboxActionTarget: (port: number, path?: string) => string;
106
- type HeaderBag = Headers | Record<string, string | string[] | undefined>;
107
- /** True only when every rule holds:
108
- * remoteAddress is 127.0.0.1, ::1 or ::ffff:127.0.0.1; header host === `127.0.0.1:${port}`;
109
- * none of these headers is present: forwarded, via, x-real-ip, true-client-ip, cdn-loop, origin, and any name
110
- * starting with x-forwarded- or cf-; no sec-fetch-* header (site, dest, user: browsers only) except
111
- * sec-fetch-mode with the exact value 'cors', which Node's own fetch (undici) always sends;
112
- * header x-inbox-action === '1'.
113
- * Header names compared lowercase; Headers and Node IncomingHttpHeaders both accepted. */
119
+
120
+ /** True only when isDirectCall holds (loopback peer, Host 127.0.0.1:port, no proxy/Origin/browser fetch-metadata
121
+ * headers; see isDirectCall for the full rules) and header x-inbox-action === '1'. */
114
122
  declare function isInboxCall(req: {
115
123
  headers: HeaderBag;
116
124
  remoteAddress: string | null | undefined;
117
125
  port: number;
118
126
  }): boolean;
119
127
  /** The body as an InboxActionCall for `source`, or null: itemId a positive safe integer, actionId
120
- * matching /^[a-z0-9][a-z0-9-]{0,31}$/, source === `source`, kind a string, dedupeKey string or null,
128
+ * matching /^[a-z0-9][a-z0-9-]{0,31}$/, source === `source`, kind a string, dedupeKey null or a string of 1..200 chars with no control characters (below 0x20 or 0x7f),
121
129
  * data a plain object. */
122
130
  declare function parseInboxActionCall(body: unknown, source: string): (InboxActionCall & {
123
131
  data: InboxData;
@@ -131,5 +139,5 @@ declare function actionTokenMatches(token: unknown, storedHash: string | null |
131
139
  /** An action button; throws Error(`not an inbox action target: ${target}`) when isInboxActionTarget fails. */
132
140
  declare function inboxAction(id: string, label: string, target: string): InboxAction;
133
141
 
134
- export { ACTION_TOKEN_FIELD, INBOX_ACTION_PATH, InboxAction, InboxActionCall, InboxData, InboxEvent, InboxEventInput, InboxIngestAction, actionTokenMatches, appRoot, createInboxClient, envNumber, errorResponse, hashActionToken, inboxAction, inboxActionTarget, installProcessHandlers, isInboxActionTarget, isInboxCall, loadAppEnv, newActionToken, parseInboxActionCall, parseInboxEvent };
142
+ export { ACTION_TOKEN_FIELD, INBOX_ACTION_PATH, InboxAction, InboxActionCall, InboxData, InboxEvent, InboxEventInput, InboxIngestAction, actionTokenMatches, appRoot, createInboxClient, envNumber, errorResponse, hashActionToken, inboxAction, inboxActionTarget, installProcessHandlers, isDirectCall, isInboxActionTarget, isInboxCall, loadAppEnv, newActionToken, parseInboxActionCall, parseInboxEvent };
135
143
  export type { HeaderBag, InboxClient, InboxClientOptions, InboxSendResult, ProcessHandlerOptions };
@@ -120,12 +120,17 @@ function createLimiter(o = {}) {
120
120
  const cap = o.cap ?? 1e4;
121
121
  const entries = /* @__PURE__ */ new Map();
122
122
  const makeRoom = (now) => {
123
+ if (cap <= 0) return false;
123
124
  if (entries.size < cap) return true;
124
125
  for (const [k, v] of entries) if (v.reset <= now) entries.delete(k);
125
126
  for (const [k, v] of entries) {
126
127
  if (entries.size < cap) break;
127
128
  if (v.count < max) entries.delete(k);
128
129
  }
130
+ for (const k of entries.keys()) {
131
+ if (entries.size < cap) break;
132
+ entries.delete(k);
133
+ }
129
134
  return entries.size < cap;
130
135
  };
131
136
  const touch = (key, now) => {
@@ -246,6 +251,7 @@ function errorResponse(err, req, log = (line) => console.error(line)) {
246
251
  }
247
252
 
248
253
  // src/server/spa.ts
254
+ import { createHash as createHash2 } from "crypto";
249
255
  import { readFile, stat } from "fs/promises";
250
256
  import { resolve as resolve2, sep } from "path";
251
257
  var SECURITY_HEADERS = {
@@ -283,6 +289,35 @@ async function isFile(path) {
283
289
  return false;
284
290
  }
285
291
  }
292
+ function checkSources(list) {
293
+ const out = list ?? [];
294
+ for (const v of out) {
295
+ if (/[;,\r\n]/.test(v)) throw new Error(`@nish/ui/server: bad csp source: ${v}`);
296
+ }
297
+ return out;
298
+ }
299
+ function inlineScriptHashes(html) {
300
+ const lower = html.toLowerCase();
301
+ const hashes = /* @__PURE__ */ new Set();
302
+ let i = lower.indexOf("<script");
303
+ while (i >= 0) {
304
+ const tagEnd = lower.indexOf(">", i);
305
+ if (tagEnd < 0) break;
306
+ const next = lower.charAt(i + 7);
307
+ const isTag = next === ">" || next === "/" || /\s/.test(next);
308
+ const close = lower.indexOf("</script", tagEnd + 1);
309
+ if (isTag) {
310
+ const attrs = lower.slice(i + 7, tagEnd);
311
+ if (!/(?:^|[\s"'/])src\s*=/.test(attrs) && close >= 0) {
312
+ const content = html.slice(tagEnd + 1, close);
313
+ if (content.length > 0) hashes.add(`'sha256-${createHash2("sha256").update(content, "utf8").digest("base64")}'`);
314
+ }
315
+ }
316
+ if (close < 0) break;
317
+ i = lower.indexOf("<script", close);
318
+ }
319
+ return [...hashes];
320
+ }
286
321
  function createSpaHandler(o) {
287
322
  const dir = resolve2(o.dir);
288
323
  const indexName = o.index ?? "index.html";
@@ -292,10 +327,42 @@ function createSpaHandler(o) {
292
327
  const indexPath = resolve2(dir, indexName);
293
328
  const safety = { ...SECURITY_HEADERS };
294
329
  if (o.frameOptions !== false) safety["X-Frame-Options"] = "SAMEORIGIN";
330
+ const cspOpt = o.csp === "strict" ? {} : o.csp;
331
+ const cspConnect = checkSources(cspOpt?.connect);
332
+ const cspImg = checkSources(cspOpt?.img);
333
+ const cspScript = checkSources(cspOpt?.script);
334
+ const cspFrame = checkSources(cspOpt?.frameAncestors);
335
+ const cspHeader = cspOpt?.reportOnly ? "Content-Security-Policy-Report-Only" : "Content-Security-Policy";
336
+ const policies = /* @__PURE__ */ new Map();
337
+ const buildPolicy = (html) => [
338
+ "default-src 'self'",
339
+ ["script-src", "'self'", ...inlineScriptHashes(html), ...cspScript].join(" "),
340
+ "style-src 'self' 'unsafe-inline'",
341
+ ["img-src", "'self'", "data:", ...cspImg].join(" "),
342
+ ["connect-src", "'self'", ...cspConnect].join(" "),
343
+ "font-src 'self'",
344
+ "object-src 'none'",
345
+ "base-uri 'none'",
346
+ "form-action 'self'",
347
+ ["frame-ancestors", ...cspFrame.length ? cspFrame : ["'self'"]].join(" ")
348
+ ].join("; ");
295
349
  const text = (body, status) => new Response(body, { status, headers: { "Content-Type": "text/plain; charset=utf-8", ...safety } });
296
350
  const send = async (file, cache, head) => {
351
+ const type = contentType(file);
352
+ const headers = { "Content-Type": type, "Cache-Control": cache, ...safety };
353
+ if (cspOpt && type.startsWith("text/html")) {
354
+ const mtimeMs = (await stat(file)).mtimeMs;
355
+ const html = await readFile(file);
356
+ let hit = policies.get(file);
357
+ if (!hit || hit.mtimeMs !== mtimeMs) {
358
+ hit = { mtimeMs, policy: buildPolicy(html.toString("utf8")) };
359
+ policies.set(file, hit);
360
+ }
361
+ headers[cspHeader] = hit.policy;
362
+ return new Response(head ? null : html, { status: 200, headers });
363
+ }
297
364
  const body = head ? null : await readFile(file);
298
- return new Response(body, { status: 200, headers: { "Content-Type": contentType(file), "Cache-Control": cache, ...safety } });
365
+ return new Response(body, { status: 200, headers });
299
366
  };
300
367
  return async (req) => {
301
368
  const head = req.method === "HEAD";
@@ -324,6 +391,36 @@ function createSpaHandler(o) {
324
391
  };
325
392
  }
326
393
 
394
+ // src/server/direct-call.ts
395
+ var LOOPBACK_PEERS = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
396
+ var FORBIDDEN_HEADERS = ["forwarded", "via", "x-real-ip", "true-client-ip", "cdn-loop", "origin"];
397
+ var FORBIDDEN_PREFIXES = ["x-forwarded-", "cf-"];
398
+ function headerNames(headers) {
399
+ if (typeof headers.forEach === "function" && typeof headers.get === "function") {
400
+ const names = [];
401
+ headers.forEach((_v, k) => names.push(k.toLowerCase()));
402
+ return names;
403
+ }
404
+ return Object.entries(headers).filter(([, v]) => v !== void 0).map(([k]) => k.toLowerCase());
405
+ }
406
+ function headerValue(headers, name) {
407
+ if (typeof headers.get === "function") return headers.get(name) ?? void 0;
408
+ for (const [k, v] of Object.entries(headers)) {
409
+ if (k.toLowerCase() === name) return Array.isArray(v) ? v[0] : v;
410
+ }
411
+ return void 0;
412
+ }
413
+ function isDirectCall(req) {
414
+ if (!req.remoteAddress || !LOOPBACK_PEERS.has(req.remoteAddress)) return false;
415
+ if (headerValue(req.headers, "host") !== `127.0.0.1:${req.port}`) return false;
416
+ for (const name of headerNames(req.headers)) {
417
+ if (FORBIDDEN_HEADERS.includes(name)) return false;
418
+ if (FORBIDDEN_PREFIXES.some((p) => name.startsWith(p))) return false;
419
+ if (name.startsWith("sec-fetch-") && !(name === "sec-fetch-mode" && headerValue(req.headers, name) === "cors")) return false;
420
+ }
421
+ return true;
422
+ }
423
+
327
424
  // src/server/inbox/types.ts
328
425
  var INBOX_ACTION_HEADER = "X-Inbox-Action";
329
426
  var INBOX_ACTION_TIMEOUT_MS = 8e3;
@@ -636,39 +733,29 @@ function createInboxClient(options) {
636
733
  }
637
734
 
638
735
  // src/server/inbox/action.ts
639
- import { createHash as createHash2, randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual2 } from "crypto";
736
+ import { createHash as createHash3, randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual2 } from "crypto";
640
737
  var INBOX_ACTION_PATH = "/api/inbox/action";
641
738
  var ACTION_TOKEN_FIELD = "actionToken";
642
739
  var inboxActionTarget = (port, path) => `http://127.0.0.1:${port}${path ?? INBOX_ACTION_PATH}`;
643
- var LOOPBACK_PEERS = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
644
- var FORBIDDEN_HEADERS = ["forwarded", "via", "x-real-ip", "true-client-ip", "cdn-loop", "origin"];
645
- var FORBIDDEN_PREFIXES = ["x-forwarded-", "cf-"];
646
740
  var ACTION_ID_RE2 = /^[a-z0-9][a-z0-9-]{0,31}$/;
647
741
  var HASH_RE = /^[0-9a-f]{64}$/;
648
- function headerNames(headers) {
649
- if (typeof headers.forEach === "function" && typeof headers.get === "function") {
650
- const names = [];
651
- headers.forEach((_v, k) => names.push(k.toLowerCase()));
652
- return names;
653
- }
654
- return Object.entries(headers).filter(([, v]) => v !== void 0).map(([k]) => k.toLowerCase());
655
- }
656
- function headerValue(headers, name) {
657
- if (typeof headers.get === "function") return headers.get(name) ?? void 0;
742
+ function inboxHeader(headers) {
743
+ if (typeof headers.get === "function") return headers.get("x-inbox-action") ?? void 0;
658
744
  for (const [k, v] of Object.entries(headers)) {
659
- if (k.toLowerCase() === name) return Array.isArray(v) ? v[0] : v;
745
+ if (k.toLowerCase() === "x-inbox-action") return Array.isArray(v) ? v[0] : v;
660
746
  }
661
747
  return void 0;
662
748
  }
663
749
  function isInboxCall(req) {
664
- if (!req.remoteAddress || !LOOPBACK_PEERS.has(req.remoteAddress)) return false;
665
- if (headerValue(req.headers, "host") !== `127.0.0.1:${req.port}`) return false;
666
- for (const name of headerNames(req.headers)) {
667
- if (FORBIDDEN_HEADERS.includes(name)) return false;
668
- if (FORBIDDEN_PREFIXES.some((p) => name.startsWith(p))) return false;
669
- if (name.startsWith("sec-fetch-") && !(name === "sec-fetch-mode" && headerValue(req.headers, name) === "cors")) return false;
750
+ return isDirectCall(req) && inboxHeader(req.headers) === "1";
751
+ }
752
+ function validDedupeKey(k) {
753
+ if (typeof k !== "string" || k.length < 1 || k.length > 200) return false;
754
+ for (let i = 0; i < k.length; i++) {
755
+ const c = k.charCodeAt(i);
756
+ if (c < 32 || c === 127) return false;
670
757
  }
671
- return headerValue(req.headers, "x-inbox-action") === "1";
758
+ return true;
672
759
  }
673
760
  function parseInboxActionCall(body, source) {
674
761
  if (typeof body !== "object" || body === null || Array.isArray(body)) return null;
@@ -677,7 +764,7 @@ function parseInboxActionCall(body, source) {
677
764
  if (typeof b.actionId !== "string" || !ACTION_ID_RE2.test(b.actionId)) return null;
678
765
  if (b.source !== source) return null;
679
766
  if (typeof b.kind !== "string") return null;
680
- if (b.dedupeKey !== null && typeof b.dedupeKey !== "string") return null;
767
+ if (b.dedupeKey !== null && !validDedupeKey(b.dedupeKey)) return null;
681
768
  const data = b.data;
682
769
  if (typeof data !== "object" || data === null || Array.isArray(data)) return null;
683
770
  return {
@@ -693,7 +780,7 @@ function newActionToken() {
693
780
  return randomBytes2(32).toString("base64url");
694
781
  }
695
782
  function hashActionToken(token) {
696
- return createHash2("sha256").update(token, "utf8").digest("hex");
783
+ return createHash3("sha256").update(token, "utf8").digest("hex");
697
784
  }
698
785
  function actionTokenMatches(token, storedHash) {
699
786
  if (typeof token !== "string" || token.length < 1 || token.length > 128) return false;
@@ -706,12 +793,12 @@ function inboxAction(id, label, target) {
706
793
  }
707
794
 
708
795
  // src/server/service-tokens.ts
709
- import { createHash as createHash3, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual3 } from "crypto";
796
+ import { createHash as createHash4, randomBytes as randomBytes3, timingSafeEqual as timingSafeEqual3 } from "crypto";
710
797
  import { mkdirSync, readFileSync as readFileSync2, renameSync, writeFileSync } from "fs";
711
798
  import { dirname as dirname2 } from "path";
712
799
  var TOKEN_RE = /^nish_[a-z][a-z0-9-]*_[A-Za-z0-9_-]{43}$/;
713
800
  var HEX_RE2 = /^[0-9a-f]{64}$/;
714
- var hashServiceToken = (token) => createHash3("sha256").update(token, "utf8").digest("hex");
801
+ var hashServiceToken = (token) => createHash4("sha256").update(token, "utf8").digest("hex");
715
802
  function mintServiceToken(app) {
716
803
  if (!/^[a-z][a-z0-9-]*$/.test(app)) throw new Error(`bad app name: ${app}`);
717
804
  const token = `nish_${app}_${randomBytes3(32).toString("base64url")}`;
@@ -888,8 +975,10 @@ function isDirectLoopback(get, port) {
888
975
  if (get("origin") !== void 0) return false;
889
976
  return PROXY_HEADERS.every((h) => get(h) === void 0);
890
977
  }
978
+ var LOOPBACK_PEERS2 = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "::ffff:127.0.0.1"]);
891
979
  function checkServiceRequest(get, o) {
892
980
  if (!isDirectLoopback(get, o.port)) return { status: 403, error: "Forbidden" };
981
+ if ("remoteAddress" in o && (!o.remoteAddress || !LOOPBACK_PEERS2.has(o.remoteAddress))) return { status: 403, error: "Forbidden" };
893
982
  const r = o.tokens.verify(get("authorization"), o.scope);
894
983
  if (!r.ok) return { status: r.status, error: r.status === 401 ? "Unauthorized" : "Forbidden" };
895
984
  return null;
@@ -947,6 +1036,7 @@ export {
947
1036
  inboxActionTarget,
948
1037
  installProcessHandlers,
949
1038
  isCrossSiteWrite,
1039
+ isDirectCall,
950
1040
  isDirectLoopback,
951
1041
  isInboxActionTarget,
952
1042
  isInboxCall,
@@ -103,7 +103,11 @@ interface InboxEventInput {
103
103
  resolve?: boolean;
104
104
  /** ISO 8601 time the event happened. Defaults to now; future times are clamped to now. */
105
105
  occurredAt?: string;
106
- /** Flat extra data, JSON-encoded at most 4096 bytes. */
106
+ /**
107
+ * Flat extra data, JSON-encoded at most 4096 bytes. Only data.actionToken (ACTION_TOKEN_FIELD) is private
108
+ * (stripped before the browser and /api/v1 see the item); every other key is visible in the inbox UI and API.
109
+ * /ingest trusts every local caller, so action routes must verify actionToken (actionTokenMatches) on every call.
110
+ */
107
111
  data?: InboxData;
108
112
  /** Up to 3 buttons shown on the item, ids unique. A repeat with the same dedupeKey replaces them. */
109
113
  actions?: Array<Omit<InboxAction, 'method'> & {
@@ -209,8 +213,9 @@ interface InboxListResponse {
209
213
  interface Limiter {
210
214
  /** Counts one attempt for key and says whether it may go ahead: true for the first `max`
211
215
  * attempts inside the current window, false after. Synchronous, so check it before any
212
- * `await` and parallel requests cannot all pass. A new key when the limiter is full of locked
213
- * keys gets false. */
216
+ * `await` and parallel requests cannot all pass. When the table is full, expired keys go first,
217
+ * then the oldest unlocked keys, then the oldest locked keys, so a flood of locked keys can
218
+ * never lock out a new client. */
214
219
  hit(key: string, now?: number): boolean;
215
220
  /** False once `max` failures happened inside the current window for key. */
216
221
  allowed(key: string, now?: number): boolean;
@@ -303,13 +308,18 @@ declare function createServiceTokens(entries: ServiceTokenEntry[]): ServiceToken
303
308
  /**
304
309
  * True only for a request made straight to the app on loopback: Host is 127.0.0.1, localhost or
305
310
  * [::1] with the app's port, there are no proxy headers and no Origin (browsers never get in).
311
+ * @deprecated Checks only headers; prefer isDirectCall, which also checks the socket peer.
306
312
  */
307
313
  declare function isDirectLoopback(get: (name: string) => string | undefined, port: number): boolean;
308
- /** Framework-free check: the status and body a guard should answer with, or null to continue. */
314
+ /** Framework-free check: the status and body a guard should answer with, or null to continue.
315
+ * Apps should pass `remoteAddress`, the socket peer (hono: `remoteAddressOf(c)`): when the property is present
316
+ * the request is also refused with 403 unless the peer is 127.0.0.1, ::1 or ::ffff:127.0.0.1 (null or empty is
317
+ * refused). Omitting it keeps the old header-only check. */
309
318
  declare function checkServiceRequest(get: (name: string) => string | undefined, o: {
310
319
  tokens: ServiceTokens;
311
320
  scope: string;
312
321
  port: number;
322
+ remoteAddress?: string | null;
313
323
  }): {
314
324
  status: 401 | 403;
315
325
  error: string;
@@ -368,7 +378,25 @@ interface SpaOptions {
368
378
  notBuilt?: string;
369
379
  /** Sends `X-Frame-Options: SAMEORIGIN` unless false (for an app that is meant to be framed). */
370
380
  frameOptions?: false;
381
+ /** Sends a Content-Security-Policy on HTML answers. Off by default. 'strict' or an object builds
382
+ * default-src 'self'; script-src 'self' <sha256 of every inline <script> in the HTML>; style-src 'self' 'unsafe-inline'; img-src 'self' data: <img>; connect-src 'self' <connect>; font-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'self' (or <frameAncestors>).
383
+ * reportOnly sends Content-Security-Policy-Report-Only instead, to try a policy first. */
384
+ csp?: 'strict' | {
385
+ connect?: string[];
386
+ img?: string[];
387
+ script?: string[];
388
+ frameAncestors?: string[];
389
+ reportOnly?: boolean;
390
+ };
371
391
  }
392
+ /**
393
+ * Serves a built single-page app: files under `dir`, the index for any other extensionless path.
394
+ *
395
+ * `csp` adds a Content-Security-Policy to HTML answers only. Every inline script in the HTML being
396
+ * served is hashed automatically, so the theme-init script that nishThemeInit() injects into the
397
+ * built index.html is allowed without copying its hash. An app that uses the nonce placeholder
398
+ * setup (`__NISH_CSP_NONCE__`) should leave `csp` off and send its own header.
399
+ */
372
400
  declare function createSpaHandler(o: SpaOptions): (req: Request) => Promise<Response>;
373
401
 
374
402
  export { createLimiter as A, createServiceTokens as B, createSessionAuth as D, createSessionToken as E, createSpaHandler as F, hashServiceToken as G, isCrossSiteWrite as H, isDirectLoopback as J, isLoopback as K, jsonRevocationStore as N, loadManagedServiceTokens as O, loadServiceTokens as P, mintServiceToken as Q, passwordMatches as U, readCookie as W, verifySessionToken as X, INBOX_ACTION_HEADER as h, INBOX_ACTION_TIMEOUT_MS as i, INBOX_DEFAULT_SETTINGS as j, INBOX_SOURCE_LABELS as k, MIN_SECRET_BYTES as r, SESSION_DAYS as t, checkServiceRequest as y, clientIp as z };
@@ -361,7 +361,8 @@ function swapSlots(slots, a, b) {
361
361
  function narrowLayout(count, n, aspect) {
362
362
  if (count === 1) return leaf(0);
363
363
  const dir = n.dir === "auto" ? aspect >= 1.2 ? "row" : "col" : n.dir;
364
- const split = Math.min(0.8, Math.max(0.2, n.split));
364
+ const s = Number.isFinite(n.split) ? n.split : 0.5;
365
+ const split = Math.min(0.8, Math.max(0.2, s));
365
366
  return {
366
367
  type: "split",
367
368
  dir,
@@ -417,4 +418,3 @@ export {
417
418
  resizeAt,
418
419
  swapSlots
419
420
  };
420
- //# sourceMappingURL=split-layout.js.map
@@ -314,17 +314,23 @@ var nishTheme = (() => {
314
314
  var DEFAULT_THEME = "dark";
315
315
 
316
316
  // src/runtime.ts
317
- var version = true ? "3.1.0" : "dev";
317
+ var version = true ? "3.2.0" : "dev";
318
318
  var KEY = /* @__PURE__ */ Symbol.for("nish-ui.runtime.v1");
319
319
  function runtime() {
320
320
  var _a;
321
321
  const g = globalThis;
322
322
  return (_a = g[KEY]) != null ? _a : g[KEY] = { versions: /* @__PURE__ */ new Set(), slots: {} };
323
323
  }
324
+ function isDevelopment() {
325
+ try {
326
+ return process.env.NODE_ENV !== "production";
327
+ } catch (e) {
328
+ return false;
329
+ }
330
+ }
324
331
  function register(rt) {
325
- var _a, _b;
326
332
  rt.versions.add(version);
327
- if (rt.versions.size > 1 && !rt.warned && ((_b = (_a = globalThis.process) == null ? void 0 : _a.env) == null ? void 0 : _b.NODE_ENV) !== "production") {
333
+ if (rt.versions.size > 1 && !rt.warned && isDevelopment()) {
328
334
  rt.warned = true;
329
335
  console.warn(
330
336
  `nish-ui: two versions are loaded on this page (${[...rt.versions].join(", ")}). Overlays, toasts and theme state are shared, but mixing versions is unsupported.`
@@ -1230,4 +1236,3 @@ var nishTheme = (() => {
1230
1236
  }
1231
1237
  return __toCommonJS(theme_global_exports);
1232
1238
  })();
1233
- //# sourceMappingURL=theme.global.js.map
package/dist/theme.js CHANGED
@@ -264,15 +264,22 @@ var THEMES = /* @__PURE__ */ Object.fromEntries(
264
264
  var DEFAULT_THEME = "dark";
265
265
 
266
266
  // src/runtime.ts
267
- var version = true ? "3.1.0" : "dev";
267
+ var version = true ? "3.2.0" : "dev";
268
268
  var KEY = /* @__PURE__ */ Symbol.for("nish-ui.runtime.v1");
269
269
  function runtime() {
270
270
  const g = globalThis;
271
271
  return g[KEY] ??= { versions: /* @__PURE__ */ new Set(), slots: {} };
272
272
  }
273
+ function isDevelopment() {
274
+ try {
275
+ return process.env.NODE_ENV !== "production";
276
+ } catch {
277
+ return false;
278
+ }
279
+ }
273
280
  function register(rt) {
274
281
  rt.versions.add(version);
275
- if (rt.versions.size > 1 && !rt.warned && globalThis.process?.env?.NODE_ENV !== "production") {
282
+ if (rt.versions.size > 1 && !rt.warned && isDevelopment()) {
276
283
  rt.warned = true;
277
284
  console.warn(
278
285
  `nish-ui: two versions are loaded on this page (${[...rt.versions].join(", ")}). Overlays, toasts and theme state are shared, but mixing versions is unsupported.`
@@ -1195,4 +1202,3 @@ export {
1195
1202
  setThemeChoice,
1196
1203
  showToast
1197
1204
  };
1198
- //# sourceMappingURL=theme.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nish-ui",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "Design tokens, seven themes, flash-free theme switching and accessible React 19 components for Tailwind 4, plain CSS and static HTML. Live docs: https://design.nish.software",
5
5
  "license": "MIT",
6
6
  "author": "Nishant Arora",