@tdacorp/hyle-sdk 0.3.0 → 0.8.1

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 (38) hide show
  1. package/README.md +135 -5
  2. package/bin/hyle-sdk-check-routes.mjs +3 -0
  3. package/dist/check-routes-bin.js +537 -0
  4. package/dist/chunk-67IOIAVW.js +35 -0
  5. package/dist/chunk-BUJFMR3M.js +38 -0
  6. package/dist/chunk-EBNIKRQH.js +536 -0
  7. package/dist/{chunk-EARQBSMF.js → chunk-LGW2KP4X.js} +109 -5
  8. package/dist/{chunk-7VCMJUPC.js → chunk-N4QYPO7S.js} +1 -1
  9. package/dist/diagram-viewer-DYX6R63Y.js +1132 -0
  10. package/dist/index.cjs +279 -23
  11. package/dist/index.d.cts +147 -3
  12. package/dist/index.d.ts +147 -3
  13. package/dist/index.js +18 -1
  14. package/dist/mermaid-diagram.cjs +1267 -16
  15. package/dist/mermaid-diagram.d.cts +39 -1
  16. package/dist/mermaid-diagram.d.ts +39 -1
  17. package/dist/mermaid-diagram.js +35 -5
  18. package/dist/next.cjs +385 -30
  19. package/dist/next.d.cts +93 -5
  20. package/dist/next.d.ts +93 -5
  21. package/dist/next.js +210 -5
  22. package/dist/react.cjs +118 -5
  23. package/dist/react.d.cts +44 -4
  24. package/dist/react.d.ts +44 -4
  25. package/dist/react.js +2 -1
  26. package/dist/{resolve-fMx2W8RR.d.ts → resolve-1rQntRBh.d.ts} +1 -1
  27. package/dist/{resolve-B_p0p4Zn.d.cts → resolve-36-Ng1H0.d.cts} +1 -1
  28. package/dist/styles.css +76 -0
  29. package/dist/{types-CBvLhUPr.d.ts → types-BoyBWF2F.d.ts} +1 -1
  30. package/dist/{types-DjXf6iPo.d.cts → types-CwBCPh6K.d.cts} +20 -1
  31. package/dist/{types-DjXf6iPo.d.ts → types-CwBCPh6K.d.ts} +20 -1
  32. package/dist/{types-D0qoLh4E.d.cts → types-DnPzhrFx.d.cts} +1 -1
  33. package/dist/use-cache.cjs +55 -23
  34. package/dist/use-cache.d.cts +2 -2
  35. package/dist/use-cache.d.ts +2 -2
  36. package/dist/use-cache.js +3 -2
  37. package/package.json +5 -1
  38. package/dist/chunk-HFUJRNFP.js +0 -290
package/dist/react.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as react from 'react';
2
2
  import { ReactElement } from 'react';
3
- import { H as HyleComponents, P as PageBaseProps } from './types-CBvLhUPr.js';
4
- export { C as CalloutKind, b as CalloutProps, c as CodeBlockProps, a as HyleSlots, I as ImageProps, L as LinkProps, d as ListItemProps, M as MermaidProps } from './types-CBvLhUPr.js';
3
+ import { H as HyleComponents, P as PageBaseProps } from './types-BoyBWF2F.js';
4
+ export { C as CalloutKind, b as CalloutProps, c as CodeBlockProps, a as HyleSlots, I as ImageProps, L as LinkProps, d as ListItemProps, M as MermaidProps } from './types-BoyBWF2F.js';
5
5
  import { Root } from 'hast';
6
- import { b as ResolvedArticle, d as ResolvedList } from './types-DjXf6iPo.js';
6
+ import { d as ResolvedArticle, f as ResolvedList } from './types-CwBCPh6K.js';
7
7
 
8
8
  interface HastContentProps {
9
9
  /** `content.tree` from an article result. Anything that is not a hast root renders nothing. */
@@ -24,6 +24,42 @@ declare function TrustedServerHtml({ html }: {
24
24
  html: string;
25
25
  }): ReactElement;
26
26
 
27
+ /**
28
+ * Every string the diagram viewer shows. Pure data, so the client component can carry the English defaults without importing
29
+ * the viewer chunk, and the server passes the host's locale in (strings.ts holds fr and es, unreviewed drafts like the rest).
30
+ */
31
+ interface ViewerLabels {
32
+ expand: string;
33
+ expandHint: string;
34
+ viewer: string;
35
+ close: string;
36
+ zoomIn: string;
37
+ zoomOut: string;
38
+ fit: string;
39
+ actual: string;
40
+ search: string;
41
+ searchPlaceholder: string;
42
+ noMatch: string;
43
+ matchOf: string;
44
+ copySource: string;
45
+ downloadSvg: string;
46
+ downloadPng: string;
47
+ copyImage: string;
48
+ pngScale: string;
49
+ fullscreen: string;
50
+ exitFullscreen: string;
51
+ copied: string;
52
+ saved: string;
53
+ unavailable: string;
54
+ hint: string;
55
+ legendSelected: string;
56
+ legendUpstream: string;
57
+ legendDownstream: string;
58
+ outgoing: string;
59
+ tracing: string;
60
+ map: string;
61
+ }
62
+
27
63
  /**
28
64
  * The SDK's only client component. It receives the diagram text and presentational strings and nothing else: never a token,
29
65
  * base URL or client (a test pins this). Mermaid is a dynamic import, so the chunk loads only on pages that have a diagram,
@@ -35,8 +71,10 @@ interface MermaidDiagramProps {
35
71
  title: string;
36
72
  /** Shown when Mermaid cannot render the source. */
37
73
  errorText: string;
74
+ /** Strings of the diagram viewer (English when omitted). */
75
+ labels?: ViewerLabels;
38
76
  }
39
- declare function MermaidDiagram({ source, title, errorText }: MermaidDiagramProps): react.JSX.Element;
77
+ declare function MermaidDiagram({ source, title, errorText, labels }: MermaidDiagramProps): react.JSX.Element;
40
78
 
41
79
  /**
42
80
  * Defense in depth. hyle sanitizes server-side (packages/renderer/src/render.ts); this guard repeats the same allowlist
@@ -90,6 +128,7 @@ declare function Redirecting({ from, to, ...base }: RedirectingProps): ReactElem
90
128
  * Chrome strings for en, fr and es. The fr and es copy is a draft carried over from the design kit and has not been
91
129
  * reviewed by a native speaker. Content itself is never translated here; it comes from hyle.
92
130
  */
131
+
93
132
  declare const en: {
94
133
  toc: string;
95
134
  prev: string;
@@ -129,6 +168,7 @@ declare const en: {
129
168
  unKind: string;
130
169
  unTitle: string;
131
170
  unBody: string;
171
+ viewer: ViewerLabels;
132
172
  };
133
173
  type Strings = typeof en;
134
174
  /** Strings for a BCP 47 tag; the primary subtag decides, anything unknown falls back to English. */
package/dist/react.js CHANGED
@@ -13,7 +13,8 @@ import {
13
13
  sanitizeHast,
14
14
  scopeId,
15
15
  stringsFor
16
- } from "./chunk-EARQBSMF.js";
16
+ } from "./chunk-LGW2KP4X.js";
17
+ import "./chunk-67IOIAVW.js";
17
18
  export {
18
19
  ArticlePage,
19
20
  DocsPage,
@@ -1,4 +1,4 @@
1
- import { R as Resolved } from './types-DjXf6iPo.js';
1
+ import { R as Resolved } from './types-CwBCPh6K.js';
2
2
 
3
3
  /** Resolves a site path to a result. The two built-in strategies are `fetchResolver` (default) and `cachedResolver` (`@tdacorp/hyle-sdk/next/use-cache`). */
4
4
  type HyleResolver = (path: string, locale: string | undefined, limit?: number, cursor?: string) => Promise<Resolved>;
@@ -1,4 +1,4 @@
1
- import { R as Resolved } from './types-DjXf6iPo.cjs';
1
+ import { R as Resolved } from './types-CwBCPh6K.cjs';
2
2
 
3
3
  /** Resolves a site path to a result. The two built-in strategies are `fetchResolver` (default) and `cachedResolver` (`@tdacorp/hyle-sdk/next/use-cache`). */
4
4
  type HyleResolver = (path: string, locale: string | undefined, limit?: number, cursor?: string) => Promise<Resolved>;
package/dist/styles.css CHANGED
@@ -406,3 +406,79 @@
406
406
  .hyle-mermaid-svg{display:flex;justify-content:center;padding:16px;contain:paint}
407
407
  .hyle-mermaid-svg svg{position:static!important;max-width:100%;height:auto}
408
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 {
@@ -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 {
@@ -25,6 +25,12 @@ __export(use_cache_exports, {
25
25
  module.exports = __toCommonJS(use_cache_exports);
26
26
  var import_cache = require("next/cache");
27
27
 
28
+ // src/asset-path.ts
29
+ var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
30
+ var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
31
+ var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
32
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
33
+
28
34
  // src/errors.ts
29
35
  var Cp1ClientError = class extends Error {
30
36
  code;
@@ -65,31 +71,35 @@ async function readCapped(res, max) {
65
71
  return Buffer.concat(chunks).toString("utf8");
66
72
  }
67
73
  var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound", "disabled"]);
68
- function createHyleClient(options) {
74
+ var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
75
+ function isMounts(data) {
76
+ const mounts = data.mounts;
77
+ 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");
78
+ }
79
+ function checkBaseUrl(baseUrl, allowInsecureHttp) {
69
80
  let origin;
70
81
  try {
71
- origin = new URL(options.baseUrl);
82
+ origin = new URL(baseUrl);
72
83
  } catch {
73
84
  throw new TypeError("baseUrl must be an https origin");
74
85
  }
75
- if (origin.protocol !== "https:" && !(origin.protocol === "http:" && (options.allowInsecureHttp || LOOPBACK.has(origin.hostname)))) {
86
+ if (origin.protocol !== "https:" && !(origin.protocol === "http:" && (allowInsecureHttp || LOOPBACK.has(origin.hostname)))) {
76
87
  throw new TypeError("baseUrl must be https (http is allowed only for localhost, or with allowInsecureHttp)");
77
88
  }
89
+ }
90
+ function createHyleClient(options) {
91
+ checkBaseUrl(options.baseUrl, options.allowInsecureHttp);
78
92
  if (!options.token) throw new TypeError("token is required");
79
93
  const base = options.baseUrl.replace(/\/+$/, "");
80
94
  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);
95
+ async function get(pathname, query, init) {
96
+ const url = new URL(`${base}${pathname}`);
97
+ url.search = query.toString();
98
+ const headers = new Headers(init?.headers);
89
99
  headers.set("authorization", `Bearer ${options.token}`);
90
100
  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 });
101
+ const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
102
+ const res = await fetchImpl(url.toString(), { ...init, method: "GET", headers, redirect: "error", signal });
93
103
  const text = await readCapped(res, options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES);
94
104
  let parsed;
95
105
  try {
@@ -97,18 +107,40 @@ function createHyleClient(options) {
97
107
  } catch {
98
108
  parsed = void 0;
99
109
  }
100
- const data = parsed?.data;
101
- if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) return data;
110
+ return { parsed, status: res.status };
111
+ }
112
+ const failure = ({ parsed, status }) => {
102
113
  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
- );
114
+ return new Cp1ClientError(err?.code ?? "INVALID_RESPONSE", err?.message ?? `Unexpected response from hyle (HTTP ${status})`, status, err?.request_id ?? "", err?.details);
115
+ };
116
+ async function resolve(opts) {
117
+ const query = new URLSearchParams({ path: opts.path });
118
+ if (opts.locale !== void 0) query.set("locale", opts.locale);
119
+ if (opts.format !== void 0) query.set("format", opts.format);
120
+ if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
121
+ if (opts.limit !== void 0) query.set("limit", String(opts.limit));
122
+ const reply = await get("/cp1/read/resolve", query, opts.init);
123
+ const data = reply.parsed?.data;
124
+ if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) return data;
125
+ throw failure(reply);
126
+ }
127
+ async function mounts(opts = {}) {
128
+ const reply = await get("/cp1/read/mounts", new URLSearchParams(), opts.init);
129
+ const data = reply.parsed?.data;
130
+ if (data?.cp === 1 && data.kind === "disabled") return data;
131
+ if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
132
+ throw failure(reply);
133
+ }
134
+ async function asset(file, opts = {}) {
135
+ if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
136
+ const headers = new Headers({ authorization: `Bearer ${options.token}` });
137
+ for (const name of ["range", "if-range", "if-none-match"]) {
138
+ const value = opts.headers?.[name];
139
+ if (value) headers.set(name, value);
140
+ }
141
+ return fetchImpl(`${base}/cp1/read/assets/${file}`, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
110
142
  }
111
- return { resolve };
143
+ return { resolve, mounts, asset };
112
144
  }
113
145
 
114
146
  // 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,11 @@
1
1
  import {
2
2
  DEFAULT_REVALIDATE
3
- } from "./chunk-7VCMJUPC.js";
3
+ } from "./chunk-N4QYPO7S.js";
4
4
  import {
5
5
  createHyleClient,
6
6
  isValidCacheTag
7
- } from "./chunk-HFUJRNFP.js";
7
+ } from "./chunk-EBNIKRQH.js";
8
+ import "./chunk-67IOIAVW.js";
8
9
 
9
10
  // src/next/use-cache.ts
10
11
  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.3.0",
3
+ "version": "0.8.1",
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,10 +63,14 @@
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
  ],