@tdacorp/hyle-sdk 0.2.1 → 0.5.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 (37) hide show
  1. package/README.md +105 -4
  2. package/bin/hyle-sdk-check-routes.mjs +3 -0
  3. package/dist/check-routes-bin.js +389 -0
  4. package/dist/chunk-4OB77ZOD.js +455 -0
  5. package/dist/chunk-BUJFMR3M.js +38 -0
  6. package/dist/{chunk-7VCMJUPC.js → chunk-OW6S7IZX.js} +1 -1
  7. package/dist/{chunk-MHVWHSKC.js → chunk-SO6H2UGL.js} +124 -6
  8. package/dist/diagram-viewer-DYX6R63Y.js +1132 -0
  9. package/dist/index.cjs +191 -20
  10. package/dist/index.d.cts +95 -3
  11. package/dist/index.d.ts +95 -3
  12. package/dist/index.js +13 -1
  13. package/dist/mermaid-diagram.cjs +1395 -0
  14. package/dist/mermaid-diagram.d.cts +55 -0
  15. package/dist/mermaid-diagram.d.ts +55 -0
  16. package/dist/mermaid-diagram.js +140 -0
  17. package/dist/next.cjs +286 -27
  18. package/dist/next.d.cts +51 -5
  19. package/dist/next.d.ts +51 -5
  20. package/dist/next.js +131 -5
  21. package/dist/react.cjs +124 -5
  22. package/dist/react.d.cts +60 -4
  23. package/dist/react.d.ts +60 -4
  24. package/dist/react.js +3 -1
  25. package/dist/{resolve-fMx2W8RR.d.ts → resolve-1rQntRBh.d.ts} +1 -1
  26. package/dist/{resolve-B_p0p4Zn.d.cts → resolve-36-Ng1H0.d.cts} +1 -1
  27. package/dist/styles.css +82 -1
  28. package/dist/{types-BNaGecO7.d.ts → types-BoyBWF2F.d.ts} +3 -1
  29. package/dist/{types-DjXf6iPo.d.cts → types-CwBCPh6K.d.cts} +20 -1
  30. package/dist/{types-DjXf6iPo.d.ts → types-CwBCPh6K.d.ts} +20 -1
  31. package/dist/{types-DLWvqanV.d.cts → types-DnPzhrFx.d.cts} +3 -1
  32. package/dist/use-cache.cjs +34 -20
  33. package/dist/use-cache.d.cts +2 -2
  34. package/dist/use-cache.d.ts +2 -2
  35. package/dist/use-cache.js +2 -2
  36. package/package.json +8 -3
  37. package/dist/chunk-HFUJRNFP.js +0 -290
package/dist/styles.css CHANGED
@@ -355,7 +355,7 @@
355
355
  .hyle-callout .bd{font-size:.9375em;line-height:1.6}
356
356
 
357
357
  /* mermaid placeholder frame */
358
- .hyle-mermaid{margin-inline:0;border:var(--h-border-width) dashed var(--h-border);border-radius:var(--h-radius);background:var(--h-surface);overflow:hidden}
358
+ .hyle-mermaid{margin-inline:0;border:var(--h-border-width) dashed var(--h-border);border-radius:var(--h-radius);background:var(--h-surface);overflow-x:auto}
359
359
  .hyle-mermaid .hyle-stage{display:flex;align-items:center;justify-content:center;gap:0;padding:32px 16px;flex-wrap:wrap;row-gap:12px}
360
360
  .hyle-mermaid .node{display:grid;place-items:center;min-width:104px;height:40px;padding:0 12px;border:var(--h-border-width) solid var(--h-border);border-radius:min(var(--h-radius),8px);background:var(--h-surface-2);font:500 13px/1 var(--h-font-mono);color:var(--h-text-muted)}
361
361
  .hyle-mermaid .edge{width:32px;height:1px;background:var(--h-border);position:relative}
@@ -401,3 +401,84 @@
401
401
  /* ---- additions not in the design kit (the kit mocks these; the real hast needs them) ---- */
402
402
  .hyle .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
403
403
  .hyle-mermaid iframe{display:block;width:100%;min-height:240px;border:0;background:transparent}
404
+ .hyle-mermaid>pre{padding:16px}
405
+ /* contain:paint clips the SVG and makes it the containing block of any absolute or fixed descendant, so diagram CSS cannot overlay the host page */
406
+ .hyle-mermaid-svg{display:flex;justify-content:center;padding:16px;contain:paint}
407
+ .hyle-mermaid-svg svg{position:static!important;max-width:100%;height:auto}
408
+ .hyle-mermaid-note{margin:0;padding:8px 16px;border-top:1px dashed var(--h-border);font-size:13px;color:var(--h-warn)}
409
+
410
+ /* ---- diagram viewer (the click-to-expand trigger and its dialog, loaded on first click) ----
411
+ Public variables: --hyle-viewer-bg, --hyle-viewer-accent, --hyle-viewer-up, --hyle-viewer-down, --hyle-viewer-dim (opacity of dimmed
412
+ parts), --hyle-viewer-backdrop. All fall back to the --hyle-* surface, accent, warn and ok tokens above. */
413
+ .hyle-mermaid-open{position:relative;display:block;width:100%;margin:0;padding:0;border:0;border-radius:inherit;background:none;color:inherit;font:inherit;text-align:inherit;cursor:zoom-in}
414
+ .hyle-mermaid-open:focus-visible{outline-offset:-2px}
415
+ .hyle-mermaid-hint{position:absolute;top:8px;right:8px;padding:2px 10px;border:var(--h-border-width,1px) solid var(--h-border,GrayText);border-radius:var(--h-radius,6px);background:var(--h-surface-2,Canvas);font:500 12px/1.6 var(--h-font-sans,system-ui,sans-serif);color:var(--h-text-muted,CanvasText);opacity:0;transition:opacity .15s;pointer-events:none}
416
+ .hyle-mermaid-open:hover .hyle-mermaid-hint,.hyle-mermaid-open:focus-visible .hyle-mermaid-hint{opacity:1}
417
+ @media (hover:none){.hyle-mermaid-hint{opacity:1}}
418
+ @media (prefers-reduced-motion:reduce){.hyle-mermaid-hint{transition:none}}
419
+ html.hyle-viewer-lock{overflow:hidden;scrollbar-gutter:stable}
420
+ html.hyle-viewer-lock:has(.hv-shell:fullscreen){scrollbar-gutter:auto}
421
+
422
+ .hyle-viewer{--hv-bg:var(--hyle-viewer-bg,var(--h-surface,Canvas));--hv-accent:var(--hyle-viewer-accent,var(--h-accent,#6f9bff));--hv-up:var(--hyle-viewer-up,var(--h-warn,#e0a030));--hv-down:var(--hyle-viewer-down,var(--h-ok,#3fb27f));--hv-dim:var(--hyle-viewer-dim,.16);
423
+ --hv-text:var(--h-text,CanvasText);--hv-muted:var(--h-text-muted,color-mix(in srgb,var(--hv-text) 65%,transparent));--hv-border:var(--h-border,color-mix(in srgb,var(--hv-text) 28%,transparent));--hv-raise:var(--h-surface-2,color-mix(in srgb,var(--hv-text) 8%,var(--hv-bg)));--hv-hairline:var(--h-hairline,color-mix(in srgb,var(--hv-text) 14%,transparent));--hv-focus:var(--h-focus,var(--hv-accent));
424
+
425
+ width:min(96vw,1680px);height:min(92vh,1100px);height:min(92dvh,1100px);max-width:none;max-height:none;margin:auto;padding:0;overflow:hidden;overscroll-behavior:contain;border:var(--h-border-width,1px) solid var(--hv-border);border-radius:var(--h-radius-lg,8px);background:var(--hv-bg);color:var(--hv-text);box-shadow:var(--h-shadow,0 12px 48px rgb(0 0 0/.4));font:400 14px/1.4 var(--h-font-sans,system-ui,sans-serif)}
426
+ .hv-shell{display:flex;flex-direction:column;width:100%;height:100%;background:var(--hv-bg);color:var(--hv-text)}
427
+ .hyle-viewer::backdrop{background:var(--hyle-viewer-backdrop,rgb(0 0 0/.6))}
428
+ @media (prefers-reduced-motion:no-preference){.hyle-viewer[open]{animation:hv-in .18s ease-out}@keyframes hv-in{from{opacity:0;transform:scale(.98)}}}
429
+ @media (max-width:640px){.hyle-viewer{width:100vw;width:100dvw;height:100vh;height:100dvh;border:0;border-radius:0}}
430
+ .hyle-viewer *{box-sizing:border-box}
431
+ .hv-bar{display:flex;flex:none;flex-wrap:wrap;align-items:center;gap:6px 12px;padding:8px 12px;border-bottom:1px solid var(--hv-border);font-weight:500;font-size:13px}
432
+ .hv-title{max-width:22ch;overflow:hidden;font-weight:600;text-overflow:ellipsis;white-space:nowrap}
433
+ .hv-zoom{min-width:5ch;font:400 13px/1 var(--h-font-mono,ui-monospace,monospace);font-variant-numeric:tabular-nums;color:var(--hv-muted)}
434
+ .hv-group{display:inline-flex;align-items:center;gap:4px}
435
+ .hv-end{margin-inline-start:auto}
436
+ .hv-btn,.hv-select,.hv-input{min-width:32px;min-height:32px;padding:0 8px;border:1px solid var(--hv-border);border-radius:var(--h-radius,6px);background:var(--hv-raise);color:var(--hv-text);font:inherit;line-height:1}
437
+ .hv-btn{display:inline-grid;place-items:center;cursor:pointer}
438
+ .hv-btn:hover,.hv-select:hover{border-color:var(--hv-accent)}
439
+ .hv-btn[aria-pressed=true]{border-color:var(--hv-accent);color:var(--hv-accent)}
440
+ .hv-txt{font:500 12px/1 var(--h-font-mono,ui-monospace,monospace)}
441
+ .hv-ic{width:16px;height:16px;fill:none;stroke:currentColor;stroke-width:1.4;stroke-linecap:round;stroke-linejoin:round}
442
+ .hv-input{width:14ch;cursor:text}
443
+ .hv-count{min-width:6ch;color:var(--hv-muted);font-size:12px}
444
+ @media (pointer:coarse){.hv-btn,.hv-select,.hv-input{min-width:44px;min-height:44px}}
445
+
446
+ .hv-view{position:relative;flex:1;min-height:0;overflow:hidden;contain:paint;touch-action:none;cursor:grab;outline:none;user-select:none;-webkit-user-select:none;background-image:radial-gradient(circle,var(--hv-hairline) 1px,transparent 1.5px);background-size:24px 24px}
447
+ .hv-view.hv-grabbing{cursor:grabbing}
448
+ /* --hv-k is the current zoom, written by the viewer while something is highlighted: strokes of highlights are divided by it so they keep their on-screen width. */
449
+ .hv-stage{--hv-k:1;position:absolute;top:0;left:0;transform-origin:0 0}
450
+ .hv-stage svg{display:block;position:static!important;width:100%;height:100%;max-width:none!important}
451
+ .hv-stage .hv-n{cursor:pointer;outline:none}
452
+ .hv-stage .hv-n,.hv-stage .hv-e{transition:opacity .15s}
453
+ @media (prefers-reduced-motion:reduce){.hv-stage .hv-n,.hv-stage .hv-e{transition:none}}
454
+ .hv-stage.hv-plain .hv-n,.hv-stage.hv-plain .hv-e{transition:none}
455
+ .hv-stage.hv-active .hv-n:not(.hv-on),.hv-stage.hv-active .hv-e:not(.hv-on){opacity:var(--hv-dim)}
456
+ .hv-stage .hv-n:focus-visible :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-focus)!important;stroke-width:calc(3px / var(--hv-k,1))!important}
457
+ .hv-stage .hv-n.hv-nb :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(2px / var(--hv-k,1))!important}
458
+ .hv-stage .hv-n.hv-up :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-up)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
459
+ .hv-stage .hv-n.hv-down :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-down)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
460
+ .hv-stage .hv-n.hv-sel :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(3.5px / var(--hv-k,1))!important}
461
+ .hv-stage .hv-n.hv-hit :is(rect,polygon,circle,ellipse,path){stroke:var(--hv-accent)!important;stroke-width:calc(3px / var(--hv-k,1))!important}
462
+ .hv-stage .hv-n.hv-cur :is(rect,polygon,circle,ellipse,path){stroke-width:calc(5px / var(--hv-k,1))!important}
463
+ .hv-stage text.hv-hit,.hv-stage text.hv-hit tspan{fill:var(--hv-accent)!important;font-weight:700}
464
+ .hv-stage text.hv-cur{text-decoration:underline}
465
+ .hv-stage path.hv-nb{stroke:var(--hv-accent)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
466
+ .hv-stage path.hv-up{stroke:var(--hv-up)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
467
+ .hv-stage path.hv-down{stroke:var(--hv-down)!important;stroke-width:calc(2.5px / var(--hv-k,1))!important}
468
+ .hv-stage path.hv-flow{stroke-dasharray:calc(7px / var(--hv-k,1)) calc(6px / var(--hv-k,1))!important;animation:hv-dash .9s linear infinite}
469
+ @keyframes hv-dash{to{stroke-dashoffset:calc(-26px / var(--hv-k,1))}}
470
+ @media (prefers-reduced-motion:reduce){.hv-stage path.hv-flow{animation:none}}
471
+
472
+ .hv-mini{position:absolute;right:12px;bottom:44px;width:176px;height:120px;border:1px solid var(--hv-border);border-radius:var(--h-radius,6px);background:color-mix(in srgb,var(--hv-bg) 88%,transparent);color:var(--hv-muted);accent-color:var(--hv-accent);cursor:crosshair;touch-action:none}
473
+ @media (max-width:640px){.hv-mini{width:120px;height:82px}}
474
+ .hv-foot{display:flex;flex:none;flex-wrap:wrap;align-items:center;gap:4px 16px;min-height:32px;padding:6px 12px;border-top:1px solid var(--hv-border);font-size:12px;color:var(--hv-muted)}
475
+ .hv-hint{margin:0;flex:1 1 auto}
476
+ @media (max-width:640px){.hv-hint{display:none}}
477
+ .hv-toast{margin-inline-start:auto;color:var(--hv-text)}
478
+ .hv-toast:empty{display:none}
479
+ .hv-legend{display:flex;gap:14px;margin:0;padding:0;list-style:none}
480
+ .hv-legend li{display:inline-flex;align-items:center;gap:6px}
481
+ .hv-legend li::before{content:"";width:10px;height:10px;border-radius:2px;background:currentColor}
482
+ .hv-legend .hv-sel{color:var(--hv-accent)}
483
+ .hv-legend .hv-up{color:var(--hv-up)}
484
+ .hv-legend .hv-down{color:var(--hv-down)}
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType } from 'react';
2
- import { L as ListItem } from './types-DjXf6iPo.js';
2
+ import { L as ListItem } from './types-CwBCPh6K.js';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -23,6 +23,8 @@ interface CodeBlockProps {
23
23
  interface MermaidProps {
24
24
  /** The sandboxed document hyle produced for the diagram. Render it only inside an iframe with `sandbox="allow-scripts"`. */
25
25
  srcDoc: string;
26
+ /** The diagram text, extracted from `srcDoc` (at most 20,000 characters); undefined when it could not be extracted. */
27
+ source: string | undefined;
26
28
  title: string;
27
29
  }
28
30
  interface CalloutProps {
@@ -101,5 +101,24 @@ interface ResolvedDisabled {
101
101
  readonly kind: "disabled";
102
102
  }
103
103
  type Resolved = ResolvedArticle | ResolvedList | ResolvedRedirect | ResolvedNotFound | ResolvedDisabled;
104
+ /**
105
+ * The `data` of GET /cp1/read/mounts: where hyle serves content in the host's URL space. `prefix` "/" is a root mount.
106
+ * `reserved` lists paths the host app owns (exact paths, or "/x/*" for a path and everything under it); hyle refuses to publish onto them.
107
+ */
108
+ interface Mount {
109
+ readonly prefix: string;
110
+ readonly default_section: string;
111
+ }
112
+ interface Mounts {
113
+ readonly cp: 1;
114
+ readonly kind: "mounts";
115
+ readonly workspace_id: string;
116
+ readonly default_locale: string;
117
+ readonly supported_locales: readonly string[];
118
+ readonly mounts: readonly Mount[];
119
+ readonly reserved: readonly string[];
120
+ readonly cache: CacheInfo;
121
+ }
122
+ type MountsResult = Mounts | ResolvedDisabled;
104
123
 
105
- export type { Alternate as A, Breadcrumb as B, CacheInfo as C, Fallback as F, ListItem as L, NavItem as N, Resolved as R, TocEntry as T, ArticleContent as a, ResolvedArticle as b, ResolvedDisabled as c, ResolvedList as d, ResolvedNotFound as e, ResolvedRedirect as f };
124
+ export type { Alternate as A, Breadcrumb as B, CacheInfo as C, Fallback as F, ListItem as L, MountsResult as M, NavItem as N, Resolved as R, TocEntry as T, ArticleContent as a, Mount as b, Mounts as c, ResolvedArticle as d, ResolvedDisabled as e, ResolvedList as f, ResolvedNotFound as g, ResolvedRedirect as h };
@@ -101,5 +101,24 @@ interface ResolvedDisabled {
101
101
  readonly kind: "disabled";
102
102
  }
103
103
  type Resolved = ResolvedArticle | ResolvedList | ResolvedRedirect | ResolvedNotFound | ResolvedDisabled;
104
+ /**
105
+ * The `data` of GET /cp1/read/mounts: where hyle serves content in the host's URL space. `prefix` "/" is a root mount.
106
+ * `reserved` lists paths the host app owns (exact paths, or "/x/*" for a path and everything under it); hyle refuses to publish onto them.
107
+ */
108
+ interface Mount {
109
+ readonly prefix: string;
110
+ readonly default_section: string;
111
+ }
112
+ interface Mounts {
113
+ readonly cp: 1;
114
+ readonly kind: "mounts";
115
+ readonly workspace_id: string;
116
+ readonly default_locale: string;
117
+ readonly supported_locales: readonly string[];
118
+ readonly mounts: readonly Mount[];
119
+ readonly reserved: readonly string[];
120
+ readonly cache: CacheInfo;
121
+ }
122
+ type MountsResult = Mounts | ResolvedDisabled;
104
123
 
105
- export type { Alternate as A, Breadcrumb as B, CacheInfo as C, Fallback as F, ListItem as L, NavItem as N, Resolved as R, TocEntry as T, ArticleContent as a, ResolvedArticle as b, ResolvedDisabled as c, ResolvedList as d, ResolvedNotFound as e, ResolvedRedirect as f };
124
+ export type { Alternate as A, Breadcrumb as B, CacheInfo as C, Fallback as F, ListItem as L, MountsResult as M, NavItem as N, Resolved as R, TocEntry as T, ArticleContent as a, Mount as b, Mounts as c, ResolvedArticle as d, ResolvedDisabled as e, ResolvedList as f, ResolvedNotFound as g, ResolvedRedirect as h };
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType } from 'react';
2
- import { L as ListItem } from './types-DjXf6iPo.cjs';
2
+ import { L as ListItem } from './types-CwBCPh6K.cjs';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -23,6 +23,8 @@ interface CodeBlockProps {
23
23
  interface MermaidProps {
24
24
  /** The sandboxed document hyle produced for the diagram. Render it only inside an iframe with `sandbox="allow-scripts"`. */
25
25
  srcDoc: string;
26
+ /** The diagram text, extracted from `srcDoc` (at most 20,000 characters); undefined when it could not be extracted. */
27
+ source: string | undefined;
26
28
  title: string;
27
29
  }
28
30
  interface CalloutProps {
@@ -65,6 +65,11 @@ async function readCapped(res, max) {
65
65
  return Buffer.concat(chunks).toString("utf8");
66
66
  }
67
67
  var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound", "disabled"]);
68
+ var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
69
+ function isMounts(data) {
70
+ const mounts = data.mounts;
71
+ return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string");
72
+ }
68
73
  function createHyleClient(options) {
69
74
  let origin;
70
75
  try {
@@ -78,18 +83,14 @@ function createHyleClient(options) {
78
83
  if (!options.token) throw new TypeError("token is required");
79
84
  const base = options.baseUrl.replace(/\/+$/, "");
80
85
  const fetchImpl = options.fetch ?? fetch;
81
- async function resolve(opts) {
82
- const url = new URL(`${base}/cp1/read/resolve`);
83
- url.searchParams.set("path", opts.path);
84
- if (opts.locale !== void 0) url.searchParams.set("locale", opts.locale);
85
- if (opts.format !== void 0) url.searchParams.set("format", opts.format);
86
- if (opts.cursor !== void 0) url.searchParams.set("cursor", opts.cursor);
87
- if (opts.limit !== void 0) url.searchParams.set("limit", String(opts.limit));
88
- const headers = new Headers(opts.init?.headers);
86
+ async function get(pathname, query, init) {
87
+ const url = new URL(`${base}${pathname}`);
88
+ url.search = query.toString();
89
+ const headers = new Headers(init?.headers);
89
90
  headers.set("authorization", `Bearer ${options.token}`);
90
91
  const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
91
- const signal = opts.init?.signal ? AbortSignal.any([opts.init.signal, timeout]) : timeout;
92
- const res = await fetchImpl(url.toString(), { ...opts.init, method: "GET", headers, redirect: "error", signal });
92
+ const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
93
+ const res = await fetchImpl(url.toString(), { ...init, method: "GET", headers, redirect: "error", signal });
93
94
  const text = await readCapped(res, options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES);
94
95
  let parsed;
95
96
  try {
@@ -97,18 +98,31 @@ function createHyleClient(options) {
97
98
  } catch {
98
99
  parsed = void 0;
99
100
  }
100
- const data = parsed?.data;
101
- if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) return data;
101
+ return { parsed, status: res.status };
102
+ }
103
+ const failure = ({ parsed, status }) => {
102
104
  const err = parsed?.error;
103
- throw new Cp1ClientError(
104
- err?.code ?? "INVALID_RESPONSE",
105
- err?.message ?? `Unexpected response from hyle (HTTP ${res.status})`,
106
- res.status,
107
- err?.request_id ?? "",
108
- err?.details
109
- );
105
+ return new Cp1ClientError(err?.code ?? "INVALID_RESPONSE", err?.message ?? `Unexpected response from hyle (HTTP ${status})`, status, err?.request_id ?? "", err?.details);
106
+ };
107
+ async function resolve(opts) {
108
+ const query = new URLSearchParams({ path: opts.path });
109
+ if (opts.locale !== void 0) query.set("locale", opts.locale);
110
+ if (opts.format !== void 0) query.set("format", opts.format);
111
+ if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
112
+ if (opts.limit !== void 0) query.set("limit", String(opts.limit));
113
+ const reply = await get("/cp1/read/resolve", query, opts.init);
114
+ const data = reply.parsed?.data;
115
+ if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) return data;
116
+ throw failure(reply);
117
+ }
118
+ async function mounts(opts = {}) {
119
+ const reply = await get("/cp1/read/mounts", new URLSearchParams(), opts.init);
120
+ const data = reply.parsed?.data;
121
+ if (data?.cp === 1 && data.kind === "disabled") return data;
122
+ if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
123
+ throw failure(reply);
110
124
  }
111
- return { resolve };
125
+ return { resolve, mounts };
112
126
  }
113
127
 
114
128
  // src/tag-validation.ts
@@ -1,5 +1,5 @@
1
- import { H as HyleResolver } from './resolve-B_p0p4Zn.cjs';
2
- import './types-DjXf6iPo.cjs';
1
+ import { H as HyleResolver } from './resolve-36-Ng1H0.cjs';
2
+ import './types-CwBCPh6K.cjs';
3
3
 
4
4
  /**
5
5
  * The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
@@ -1,5 +1,5 @@
1
- import { H as HyleResolver } from './resolve-fMx2W8RR.js';
2
- import './types-DjXf6iPo.js';
1
+ import { H as HyleResolver } from './resolve-1rQntRBh.js';
2
+ import './types-CwBCPh6K.js';
3
3
 
4
4
  /**
5
5
  * The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
package/dist/use-cache.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  DEFAULT_REVALIDATE
3
- } from "./chunk-7VCMJUPC.js";
3
+ } from "./chunk-OW6S7IZX.js";
4
4
  import {
5
5
  createHyleClient,
6
6
  isValidCacheTag
7
- } from "./chunk-HFUJRNFP.js";
7
+ } from "./chunk-4OB77ZOD.js";
8
8
 
9
9
  // src/next/use-cache.ts
10
10
  import { cacheLife, cacheTag } from "next/cache";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tdacorp/hyle-sdk",
3
- "version": "0.2.1",
3
+ "version": "0.5.0",
4
4
  "description": "hyle SDK: a typed client for hyle's resolve endpoint, a hast renderer for React, and a Next.js catch-all page with tag-based revalidation.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -63,15 +63,20 @@
63
63
  "./styles.css": "./dist/styles.css",
64
64
  "./package.json": "./package.json"
65
65
  },
66
+ "bin": {
67
+ "hyle-sdk-check-routes": "./bin/hyle-sdk-check-routes.mjs"
68
+ },
66
69
  "main": "./dist/index.cjs",
67
70
  "module": "./dist/index.js",
68
71
  "types": "./dist/index.d.ts",
69
72
  "files": [
73
+ "bin",
70
74
  "dist",
71
75
  "LICENSE"
72
76
  ],
73
77
  "dependencies": {
74
- "hast-util-to-jsx-runtime": "^2.3.6"
78
+ "hast-util-to-jsx-runtime": "^2.3.6",
79
+ "mermaid": "~11.9.0"
75
80
  },
76
81
  "peerDependencies": {
77
82
  "next": ">=16",
@@ -106,7 +111,7 @@
106
111
  "tdacorp"
107
112
  ],
108
113
  "scripts": {
109
- "build": "tsup && cp src/styles.css dist/styles.css",
114
+ "build": "rimraf dist && tsup && cp src/styles.css dist/styles.css",
110
115
  "clean": "rimraf dist",
111
116
  "test": "vitest run",
112
117
  "typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit",
@@ -1,290 +0,0 @@
1
- // src/errors.ts
2
- var Cp1ClientError = class extends Error {
3
- code;
4
- status;
5
- requestId;
6
- details;
7
- constructor(code, message, status, requestId, details) {
8
- super(message);
9
- this.name = "Cp1ClientError";
10
- this.code = code;
11
- this.status = status;
12
- this.requestId = requestId;
13
- this.details = details;
14
- }
15
- };
16
-
17
- // src/client.ts
18
- var DEFAULT_TIMEOUT_MS = 1e4;
19
- var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
20
- var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
21
- async function readCapped(res, max) {
22
- const tooLarge = () => new Cp1ClientError("RESPONSE_TOO_LARGE", `hyle response exceeds ${max} bytes`, res.status, "");
23
- if (Number(res.headers.get("content-length")) > max) throw tooLarge();
24
- if (!res.body) return "";
25
- const reader = res.body.getReader();
26
- const chunks = [];
27
- let total = 0;
28
- for (; ; ) {
29
- const { done, value } = await reader.read();
30
- if (done) break;
31
- total += value.byteLength;
32
- if (total > max) {
33
- await reader.cancel();
34
- throw tooLarge();
35
- }
36
- chunks.push(value);
37
- }
38
- return Buffer.concat(chunks).toString("utf8");
39
- }
40
- var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound", "disabled"]);
41
- function createHyleClient(options) {
42
- let origin;
43
- try {
44
- origin = new URL(options.baseUrl);
45
- } catch {
46
- throw new TypeError("baseUrl must be an https origin");
47
- }
48
- if (origin.protocol !== "https:" && !(origin.protocol === "http:" && (options.allowInsecureHttp || LOOPBACK.has(origin.hostname)))) {
49
- throw new TypeError("baseUrl must be https (http is allowed only for localhost, or with allowInsecureHttp)");
50
- }
51
- if (!options.token) throw new TypeError("token is required");
52
- const base = options.baseUrl.replace(/\/+$/, "");
53
- const fetchImpl = options.fetch ?? fetch;
54
- async function resolve(opts) {
55
- const url = new URL(`${base}/cp1/read/resolve`);
56
- url.searchParams.set("path", opts.path);
57
- if (opts.locale !== void 0) url.searchParams.set("locale", opts.locale);
58
- if (opts.format !== void 0) url.searchParams.set("format", opts.format);
59
- if (opts.cursor !== void 0) url.searchParams.set("cursor", opts.cursor);
60
- if (opts.limit !== void 0) url.searchParams.set("limit", String(opts.limit));
61
- const headers = new Headers(opts.init?.headers);
62
- headers.set("authorization", `Bearer ${options.token}`);
63
- const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
64
- const signal = opts.init?.signal ? AbortSignal.any([opts.init.signal, timeout]) : timeout;
65
- const res = await fetchImpl(url.toString(), { ...opts.init, method: "GET", headers, redirect: "error", signal });
66
- const text = await readCapped(res, options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES);
67
- let parsed;
68
- try {
69
- parsed = JSON.parse(text);
70
- } catch {
71
- parsed = void 0;
72
- }
73
- const data = parsed?.data;
74
- if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) return data;
75
- const err = parsed?.error;
76
- throw new Cp1ClientError(
77
- err?.code ?? "INVALID_RESPONSE",
78
- err?.message ?? `Unexpected response from hyle (HTTP ${res.status})`,
79
- res.status,
80
- err?.request_id ?? "",
81
- err?.details
82
- );
83
- }
84
- return { resolve };
85
- }
86
-
87
- // src/delivery-dedupe.ts
88
- var DeliveryDedupe = class {
89
- constructor(capacity = 1e3) {
90
- this.capacity = capacity;
91
- }
92
- capacity;
93
- seen = /* @__PURE__ */ new Map();
94
- /** True if this id was already recorded (a duplicate delivery). */
95
- has(deliveryId) {
96
- return this.seen.has(deliveryId);
97
- }
98
- add(deliveryId) {
99
- this.seen.delete(deliveryId);
100
- this.seen.set(deliveryId, true);
101
- if (this.seen.size > this.capacity) {
102
- const oldest = this.seen.keys().next().value;
103
- if (oldest !== void 0) this.seen.delete(oldest);
104
- }
105
- }
106
- };
107
-
108
- // src/signature.ts
109
- import { createHmac, timingSafeEqual } from "crypto";
110
- var SIGNATURE_HEX = /^[0-9a-f]{64}$/;
111
- function parseSignatureHeader(header) {
112
- let timestamp;
113
- const signatures = [];
114
- for (const part of header.split(",")) {
115
- const [key, value] = part.split("=", 2);
116
- if (key === "t" && value) {
117
- const parsed = Number(value);
118
- if (Number.isFinite(parsed)) timestamp = parsed;
119
- } else if (key === "v1" && value && SIGNATURE_HEX.test(value)) {
120
- signatures.push(value);
121
- }
122
- }
123
- if (timestamp === void 0 || signatures.length === 0) return void 0;
124
- return { timestamp, signatures };
125
- }
126
- function computeSignature(secret, timestamp, rawBody) {
127
- return createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
128
- }
129
- function signaturesEqual(a, b) {
130
- const bufA = Buffer.from(a, "hex");
131
- const bufB = Buffer.from(b, "hex");
132
- if (bufA.length !== bufB.length) return false;
133
- return timingSafeEqual(bufA, bufB);
134
- }
135
- function verifyHyleSignature(params) {
136
- const secrets = params.secrets.filter((s) => s !== "");
137
- if (!params.header || secrets.length === 0) return false;
138
- const parsed = parseSignatureHeader(params.header);
139
- if (!parsed) return false;
140
- const tolerance = params.toleranceSeconds ?? 300;
141
- const now = (params.now ?? Date.now)() / 1e3;
142
- if (Math.abs(now - parsed.timestamp) > tolerance) return false;
143
- for (const secret of secrets) {
144
- const expected = computeSignature(secret, parsed.timestamp, params.rawBody);
145
- for (const candidate of parsed.signatures) {
146
- if (signaturesEqual(candidate, expected)) return true;
147
- }
148
- }
149
- return false;
150
- }
151
-
152
- // src/tag-validation.ts
153
- var CACHE_TAG_PATTERN = /^hyle:1:(pub|doc|sec|link|ws):[0-9a-f-]{36}(:[\x21-\x7e]{1,200})?$/;
154
- function isValidCacheTag(tag) {
155
- return CACHE_TAG_PATTERN.test(tag);
156
- }
157
-
158
- // src/revalidation-callback.ts
159
- var MAX_BODY_BYTES = 65536;
160
- var MAX_TAGS = 1e3;
161
- function createRevalidationCallbackRoute(options) {
162
- const dedupe = new DeliveryDedupe(options.dedupeCapacity);
163
- return {
164
- async POST(req) {
165
- const rawBody = await readCapped2(req);
166
- if (rawBody === void 0) return new Response(null, { status: 413 });
167
- const verified = verifyHyleSignature({
168
- header: req.headers.get("hyle-signature"),
169
- rawBody,
170
- secrets: options.secrets,
171
- ...options.toleranceSeconds !== void 0 ? { toleranceSeconds: options.toleranceSeconds } : {},
172
- ...options.now !== void 0 ? { now: options.now } : {}
173
- });
174
- if (!verified) {
175
- return new Response(null, { status: 401 });
176
- }
177
- let payload;
178
- try {
179
- payload = JSON.parse(rawBody);
180
- } catch {
181
- return new Response(null, { status: 400 });
182
- }
183
- if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return new Response(null, { status: 400 });
184
- const body = payload;
185
- if (body.cp !== 1) {
186
- return okResponse(0);
187
- }
188
- const tags = body.tags ?? [];
189
- if (typeof body.workspace_id !== "string" || !Array.isArray(tags) || tags.length > MAX_TAGS || !tags.every((t) => typeof t === "string")) {
190
- return new Response(null, { status: 400 });
191
- }
192
- if (body.workspace_id !== options.workspaceId) {
193
- return okResponse(0);
194
- }
195
- const deliveryId = req.headers.get("hyle-delivery-id");
196
- if (deliveryId && dedupe.has(deliveryId)) {
197
- return okResponse(0);
198
- }
199
- let purged = 0;
200
- try {
201
- for (const tag of tags) {
202
- if (!isValidCacheTag(tag)) continue;
203
- options.revalidateTag(tag);
204
- purged += 1;
205
- }
206
- } catch {
207
- return new Response(null, { status: 500 });
208
- }
209
- if (deliveryId) dedupe.add(deliveryId);
210
- return okResponse(purged);
211
- }
212
- };
213
- }
214
- async function readCapped2(req) {
215
- const declared = Number(req.headers.get("content-length"));
216
- if (Number.isFinite(declared) && declared > MAX_BODY_BYTES) return void 0;
217
- if (!req.body) return "";
218
- const reader = req.body.getReader();
219
- const chunks = [];
220
- let total = 0;
221
- for (; ; ) {
222
- const { done, value } = await reader.read();
223
- if (done) break;
224
- total += value.byteLength;
225
- if (total > MAX_BODY_BYTES) {
226
- await reader.cancel();
227
- return void 0;
228
- }
229
- chunks.push(value);
230
- }
231
- return Buffer.concat(chunks).toString("utf8");
232
- }
233
- function okResponse(purged) {
234
- return new Response(JSON.stringify({ ok: true, purged }), {
235
- status: 200,
236
- headers: { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" }
237
- });
238
- }
239
-
240
- // src/sitemap.ts
241
- var PAGE_LIMIT = 100;
242
- var DEFAULT_MAX_PAGES = 20;
243
- var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
244
- var UNSAFE_PATH = /[\\?#<>&"'\u0000- \u007f]/;
245
- async function listPublicationPaths(options) {
246
- const maxPages = options.maxPages ?? DEFAULT_MAX_PAGES;
247
- const prefix = `${options.basePath}/`;
248
- const indexes = [options.basePath || "/"];
249
- for (const slug of options.sections ?? []) if (slug !== "posts" && SECTION_SLUG.test(slug)) indexes.push(`${options.basePath}/${slug}`);
250
- const found = /* @__PURE__ */ new Map();
251
- let complete = true;
252
- try {
253
- for (const index of new Set(indexes)) {
254
- let cursor;
255
- for (let page = 0; page < maxPages; page++) {
256
- const result = await options.client.resolve({
257
- path: index,
258
- limit: PAGE_LIMIT,
259
- ...options.locale !== void 0 ? { locale: options.locale } : {},
260
- ...cursor !== void 0 ? { cursor } : {}
261
- });
262
- if (result.kind !== "list") {
263
- complete = false;
264
- break;
265
- }
266
- for (const item of result.items) {
267
- if (item.canonical_path.startsWith(prefix) && !UNSAFE_PATH.test(item.canonical_path)) found.set(item.canonical_path, item.published_at);
268
- }
269
- if (!result.next_cursor) break;
270
- if (page === maxPages - 1) complete = false;
271
- cursor = result.next_cursor;
272
- }
273
- }
274
- } catch {
275
- complete = false;
276
- }
277
- return { paths: [...found].map(([path, publishedAt]) => ({ path, publishedAt })), complete };
278
- }
279
-
280
- export {
281
- Cp1ClientError,
282
- createHyleClient,
283
- DeliveryDedupe,
284
- parseSignatureHeader,
285
- verifyHyleSignature,
286
- CACHE_TAG_PATTERN,
287
- isValidCacheTag,
288
- createRevalidationCallbackRoute,
289
- listPublicationPaths
290
- };