@tdacorp/hyle-sdk 0.5.0 → 0.9.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.
package/dist/styles.css CHANGED
@@ -185,38 +185,49 @@
185
185
  .hyle-docs{display:grid;grid-template-columns:minmax(0,1fr);gap:24px 48px}
186
186
  .hyle-docs>*{min-width:0}
187
187
  .hyle-docs-main>*{max-width:var(--h-measure)}
188
- .hyle-nav-d{display:none}
189
- .hyle-nav-m{border:var(--h-border-width) solid var(--h-border);border-radius:var(--h-radius);background:var(--h-surface)}
190
- .hyle-nav-m>summary{display:flex;align-items:center;gap:8px;height:44px;padding:0 16px;cursor:pointer;font-size:14px;font-weight:600;list-style:none}
191
- .hyle-nav-m>summary::-webkit-details-marker{display:none}
192
- .hyle-nav-m>summary .cur{color:var(--h-text-muted);font-weight:400;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
193
- .hyle-nav-m>summary .hyle-chev{margin-left:auto}
194
- .hyle-nav-m[open]>summary .hyle-chev{transform:rotate(180deg)}
195
- .hyle-nav-m[open]>summary{border-bottom:1px solid var(--h-hairline)}
196
- .hyle-nav-m .hyle-tree{padding:12px}
197
- .hyle-side-head{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:12px}
198
- .hyle-side-head b{font-size:15px;font-weight:600}
188
+ .hyle-docs-main>.hyle-docs-end{display:block;height:1px}
189
+ .hyle-updated{display:flex;align-items:center;gap:8px;margin-top:16px;font-size:14px;color:var(--h-text-muted)}
190
+
191
+ /* sidebar: a popover drawer in a narrow mount (top layer, so a container's containment cannot trap it), a sticky column in a wide one */
192
+ .hyle-nav-bar{display:flex;align-items:center;gap:8px;width:100%;height:44px;padding:0 16px;border:var(--h-border-width) solid var(--h-border);border-radius:var(--h-radius);background:var(--h-surface);color:var(--h-text);font:600 14px/1 var(--h-font-sans);text-align:left;cursor:pointer}
193
+ .hyle-nav-bar .cur{min-width:0;overflow:hidden;color:var(--h-text-muted);font-weight:400;text-overflow:ellipsis;white-space:nowrap}
194
+ .hyle-nav-bar .hyle-chev{margin-left:auto}
195
+ .hyle-nav-d{color:var(--h-text);font-family:var(--h-font-sans);font-size:var(--h-font-size);line-height:var(--h-line-height)}
196
+ .hyle-nav-d:popover-open{display:block;position:fixed;inset:0 auto 0 0;width:min(320px,86vw);max-width:none;height:100dvh;max-height:none;margin:0;padding:16px;overflow:auto;overscroll-behavior:contain;border:0;border-right:var(--h-border-width) solid var(--h-border);border-radius:0;background:var(--h-surface);color:var(--h-text);box-shadow:var(--h-shadow)}
197
+ .hyle-nav-d::backdrop{background:rgb(0 0 0/.5)}
198
+ html:has(.hyle-nav-d:popover-open){overflow:hidden}
199
+ .hyle-nav-x{display:inline-grid;place-items:center;flex:none;width:32px;height:32px;margin-left:auto;padding:0;border:var(--h-border-width) solid var(--h-border);border-radius:var(--h-radius);background:transparent;color:var(--h-text);cursor:pointer}
200
+ .hyle-nav-x:hover{background:var(--h-surface-2)}
201
+ .hyle-side-head{display:flex;align-items:center;gap:8px;margin-bottom:12px}
202
+ .hyle-side-head b{min-width:0;font-size:15px;font-weight:600;overflow-wrap:anywhere}
199
203
  .hyle-side-slot{margin-bottom:12px}
204
+ @supports not selector(:popover-open){.hyle-nav-d{display:block;margin-bottom:0}.hyle-nav-bar,.hyle-nav-x{display:none}}
205
+
206
+ /* tree: the summary toggles (chevron), the link inside it navigates; the page's own group and its ancestors start open */
200
207
  .hyle-tree{font-size:14px;line-height:1.4}
201
208
  .hyle-tree ul{display:block}
202
- .hyle-tree details{margin-top:12px}
203
- .hyle-tree summary{display:flex;align-items:center;gap:8px;min-height:32px;padding:0 12px;margin-left:-12px;cursor:pointer;font-weight:600;color:var(--h-text);list-style:none;border-radius:min(var(--h-radius),6px)}
209
+ .hyle-tree li+li{margin-top:2px}
210
+ .hyle-tree ul ul{margin:2px 0 0 14px;padding-left:8px;border-left:1px solid var(--h-hairline)}
211
+ .hyle-tree summary{display:flex;align-items:center;list-style:none;cursor:pointer;border-radius:min(var(--h-radius),6px)}
204
212
  .hyle-tree summary::-webkit-details-marker{display:none}
205
- .hyle-tree summary .hyle-ic{width:14px;height:14px;color:var(--h-text-faint)}
206
- .hyle-tree details[open]>summary .hyle-ic{transform:rotate(90deg)}
207
213
  .hyle-tree summary:hover{background:var(--h-surface-2)}
208
- .hyle-tree ul ul{margin-left:0;padding-left:12px;border-left:1px solid var(--h-hairline);margin-top:4px}
209
- .hyle-tree li a{display:flex;align-items:center;min-height:32px;padding:4px 12px;margin-left:-12px;border-radius:min(var(--h-radius),6px);color:var(--h-text-muted);text-decoration:none}
210
- .hyle-tree li a:hover{background:var(--h-surface-2);color:var(--h-text)}
211
- .hyle-tree li a[aria-current="page"]{background:var(--h-surface-2);color:var(--h-text);font-weight:600}
214
+ .hyle-tree summary .hyle-ic{flex:none;box-sizing:content-box;width:14px;height:14px;padding:9px;color:var(--h-text-faint)}
215
+ .hyle-tree details[open]>summary .hyle-ic{transform:rotate(90deg)}
216
+ .hyle-tree a{display:flex;align-items:center;flex:1;min-width:0;min-height:32px;padding:4px 12px;border-radius:min(var(--h-radius),6px);color:var(--h-text-muted);text-decoration:none;overflow-wrap:anywhere}
217
+ .hyle-tree summary a{padding-left:0}
218
+ .hyle-tree li>a{padding-left:32px}
219
+ .hyle-tree a:hover{color:var(--h-text)}
220
+ .hyle-tree li>a:hover{background:var(--h-surface-2)}
221
+ .hyle-tree a[aria-current="page"]{color:var(--h-text);font-weight:600}
222
+ .hyle-tree li>a[aria-current="page"],.hyle-tree summary:has(>a[aria-current="page"]){background:var(--h-surface-2);box-shadow:inset 2px 0 0 var(--h-accent)}
212
223
  .hyle-tree li a .hyle-badge{margin-left:auto;height:20px;font-size:11px}
213
224
  .hyle-docs-main .hyle-crumbs{margin-bottom:16px}
214
225
  .hyle-docs-main .hyle-title{font-size:calc(var(--h-h1-size) * .9)}
215
226
  .hyle-docs .hyle-banner{margin-bottom:24px}
216
227
  @container hyle (min-width:760px){
217
228
  .hyle-docs{grid-template-columns:var(--h-nav-width) minmax(0,1fr)}
218
- .hyle-nav-m{display:none}
219
- .hyle-nav-d{display:block;position:sticky;top:calc(var(--h-sticky-top) + 24px);align-self:start;max-height:calc(100vh - var(--h-sticky-top) - 48px);overflow:auto;padding-right:16px}
229
+ .hyle-nav-bar,.hyle-nav-x{display:none}
230
+ .hyle-nav-d{display:block;position:sticky;inset:auto;top:calc(var(--h-sticky-top) + 24px);align-self:start;width:auto;height:auto;max-height:calc(100vh - var(--h-sticky-top) - 48px);margin:0;padding:0 16px 0 0;overflow:auto;border:0;background:transparent}
220
231
  }
221
232
  @container hyle (min-width:1100px){
222
233
  .hyle-docs{grid-template-columns:var(--h-nav-width) minmax(0,1fr) var(--h-toc-width)}
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType } from 'react';
2
- import { L as ListItem } from './types-CwBCPh6K.cjs';
2
+ import { L as ListItem } from './types-CHxH5E0S.cjs';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType } from 'react';
2
- import { L as ListItem } from './types-CwBCPh6K.js';
2
+ import { L as ListItem } from './types-CHxH5E0S.js';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -16,6 +16,18 @@ interface NavItem {
16
16
  readonly title: string;
17
17
  readonly canonical_path: string;
18
18
  }
19
+ /** One page of the section's navigation tree; `children` are its effective children in sibling order. */
20
+ interface NavNode extends NavItem {
21
+ readonly children: readonly NavNode[];
22
+ }
23
+ /**
24
+ * The whole section's navigation for the article's locale (hidden pages excluded, their children promoted).
25
+ * `truncated` (with empty `items`) means the section is too large to send as one tree.
26
+ */
27
+ interface NavTree {
28
+ readonly truncated: boolean;
29
+ readonly items: readonly NavNode[];
30
+ }
19
31
  interface Breadcrumb {
20
32
  readonly title: string;
21
33
  readonly canonical_path: string;
@@ -59,6 +71,8 @@ interface ResolvedArticle {
59
71
  readonly children: readonly NavItem[];
60
72
  readonly prev: NavItem | null;
61
73
  readonly next: NavItem | null;
74
+ /** Present only when requested with `nav: "tree"` (the docs layout does); absent from every other response. */
75
+ readonly nav?: NavTree;
62
76
  readonly alternates: readonly Alternate[];
63
77
  readonly fallback?: Fallback;
64
78
  readonly cache: CacheInfo;
@@ -121,4 +135,4 @@ interface Mounts {
121
135
  }
122
136
  type MountsResult = Mounts | ResolvedDisabled;
123
137
 
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 };
138
+ 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, NavNode as d, NavTree as e, ResolvedArticle as f, ResolvedDisabled as g, ResolvedList as h, ResolvedNotFound as i, ResolvedRedirect as j };
@@ -16,6 +16,18 @@ interface NavItem {
16
16
  readonly title: string;
17
17
  readonly canonical_path: string;
18
18
  }
19
+ /** One page of the section's navigation tree; `children` are its effective children in sibling order. */
20
+ interface NavNode extends NavItem {
21
+ readonly children: readonly NavNode[];
22
+ }
23
+ /**
24
+ * The whole section's navigation for the article's locale (hidden pages excluded, their children promoted).
25
+ * `truncated` (with empty `items`) means the section is too large to send as one tree.
26
+ */
27
+ interface NavTree {
28
+ readonly truncated: boolean;
29
+ readonly items: readonly NavNode[];
30
+ }
19
31
  interface Breadcrumb {
20
32
  readonly title: string;
21
33
  readonly canonical_path: string;
@@ -59,6 +71,8 @@ interface ResolvedArticle {
59
71
  readonly children: readonly NavItem[];
60
72
  readonly prev: NavItem | null;
61
73
  readonly next: NavItem | null;
74
+ /** Present only when requested with `nav: "tree"` (the docs layout does); absent from every other response. */
75
+ readonly nav?: NavTree;
62
76
  readonly alternates: readonly Alternate[];
63
77
  readonly fallback?: Fallback;
64
78
  readonly cache: CacheInfo;
@@ -121,4 +135,4 @@ interface Mounts {
121
135
  }
122
136
  type MountsResult = Mounts | ResolvedDisabled;
123
137
 
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 };
138
+ 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, NavNode as d, NavTree as e, ResolvedArticle as f, ResolvedDisabled as g, ResolvedList as h, ResolvedNotFound as i, ResolvedRedirect as j };
@@ -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;
@@ -70,16 +76,19 @@ function isMounts(data) {
70
76
  const mounts = data.mounts;
71
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");
72
78
  }
73
- function createHyleClient(options) {
79
+ function checkBaseUrl(baseUrl, allowInsecureHttp) {
74
80
  let origin;
75
81
  try {
76
- origin = new URL(options.baseUrl);
82
+ origin = new URL(baseUrl);
77
83
  } catch {
78
84
  throw new TypeError("baseUrl must be an https origin");
79
85
  }
80
- 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)))) {
81
87
  throw new TypeError("baseUrl must be https (http is allowed only for localhost, or with allowInsecureHttp)");
82
88
  }
89
+ }
90
+ function createHyleClient(options) {
91
+ checkBaseUrl(options.baseUrl, options.allowInsecureHttp);
83
92
  if (!options.token) throw new TypeError("token is required");
84
93
  const base = options.baseUrl.replace(/\/+$/, "");
85
94
  const fetchImpl = options.fetch ?? fetch;
@@ -108,6 +117,7 @@ function createHyleClient(options) {
108
117
  const query = new URLSearchParams({ path: opts.path });
109
118
  if (opts.locale !== void 0) query.set("locale", opts.locale);
110
119
  if (opts.format !== void 0) query.set("format", opts.format);
120
+ if (opts.nav !== void 0) query.set("nav", opts.nav);
111
121
  if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
112
122
  if (opts.limit !== void 0) query.set("limit", String(opts.limit));
113
123
  const reply = await get("/cp1/read/resolve", query, opts.init);
@@ -122,7 +132,16 @@ function createHyleClient(options) {
122
132
  if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
123
133
  throw failure(reply);
124
134
  }
125
- return { resolve, mounts };
135
+ async function asset(file, opts = {}) {
136
+ if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
137
+ const headers = new Headers({ authorization: `Bearer ${options.token}` });
138
+ for (const name of ["range", "if-range", "if-none-match"]) {
139
+ const value = opts.headers?.[name];
140
+ if (value) headers.set(name, value);
141
+ }
142
+ return fetchImpl(`${base}/cp1/read/assets/${file}`, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
143
+ }
144
+ return { resolve, mounts, asset };
126
145
  }
127
146
 
128
147
  // src/tag-validation.ts
@@ -139,11 +158,11 @@ var MAX_TAGS = 128;
139
158
  var DISABLED_REVALIDATE = 30;
140
159
  var tokens = /* @__PURE__ */ new Map();
141
160
  var keyOf = (baseUrl, workspaceId) => `${baseUrl}\0${workspaceId}`;
142
- async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor, revalidate) {
161
+ async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor, nav, revalidate) {
143
162
  "use cache";
144
163
  const token = tokens.get(keyOf(baseUrl, workspaceId));
145
164
  if (!token) throw new Error("hyle: unknown cache configuration");
146
- const result = await createHyleClient({ baseUrl, token }).resolve({ path, ...locale ? { locale } : {}, ...limit > 0 ? { limit } : {}, ...cursor ? { cursor } : {} });
165
+ const result = await createHyleClient({ baseUrl, token }).resolve({ path, ...locale ? { locale } : {}, ...limit > 0 ? { limit } : {}, ...cursor ? { cursor } : {}, ...nav === "tree" ? { nav: "tree" } : {} });
147
166
  if (result.kind !== "disabled") (0, import_cache.cacheTag)(...result.cache.tags.filter(isValidCacheTag).slice(0, MAX_TAGS));
148
167
  (0, import_cache.cacheLife)({ stale: 30, revalidate: result.kind === "disabled" ? Math.min(revalidate, DISABLED_REVALIDATE) : revalidate });
149
168
  return result;
@@ -151,7 +170,7 @@ async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor,
151
170
  function cachedResolver(options) {
152
171
  tokens.set(keyOf(options.baseUrl, options.workspaceId), options.token);
153
172
  const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
154
- return (path, locale, limit, cursor) => resolveCached(options.baseUrl, options.workspaceId, path, locale ?? "", limit ?? 0, cursor ?? "", revalidate);
173
+ return (path, locale, limit, cursor, nav) => resolveCached(options.baseUrl, options.workspaceId, path, locale ?? "", limit ?? 0, cursor ?? "", nav ?? "", revalidate);
155
174
  }
156
175
  // Annotate the CommonJS export names for ESM import in node:
157
176
  0 && (module.exports = {
@@ -1,5 +1,5 @@
1
- import { H as HyleResolver } from './resolve-36-Ng1H0.cjs';
2
- import './types-CwBCPh6K.cjs';
1
+ import { H as HyleResolver } from './resolve-D2rnnho9.cjs';
2
+ import './types-CHxH5E0S.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-1rQntRBh.js';
2
- import './types-CwBCPh6K.js';
1
+ import { H as HyleResolver } from './resolve-Dpb6Orsj.js';
2
+ import './types-CHxH5E0S.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-OW6S7IZX.js";
3
+ } from "./chunk-XKR74Y5G.js";
4
4
  import {
5
5
  createHyleClient,
6
6
  isValidCacheTag
7
- } from "./chunk-4OB77ZOD.js";
7
+ } from "./chunk-54JF4E53.js";
8
+ import "./chunk-67IOIAVW.js";
8
9
 
9
10
  // src/next/use-cache.ts
10
11
  import { cacheLife, cacheTag } from "next/cache";
@@ -12,11 +13,11 @@ var MAX_TAGS = 128;
12
13
  var DISABLED_REVALIDATE = 30;
13
14
  var tokens = /* @__PURE__ */ new Map();
14
15
  var keyOf = (baseUrl, workspaceId) => `${baseUrl}\0${workspaceId}`;
15
- async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor, revalidate) {
16
+ async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor, nav, revalidate) {
16
17
  "use cache";
17
18
  const token = tokens.get(keyOf(baseUrl, workspaceId));
18
19
  if (!token) throw new Error("hyle: unknown cache configuration");
19
- const result = await createHyleClient({ baseUrl, token }).resolve({ path, ...locale ? { locale } : {}, ...limit > 0 ? { limit } : {}, ...cursor ? { cursor } : {} });
20
+ const result = await createHyleClient({ baseUrl, token }).resolve({ path, ...locale ? { locale } : {}, ...limit > 0 ? { limit } : {}, ...cursor ? { cursor } : {}, ...nav === "tree" ? { nav: "tree" } : {} });
20
21
  if (result.kind !== "disabled") cacheTag(...result.cache.tags.filter(isValidCacheTag).slice(0, MAX_TAGS));
21
22
  cacheLife({ stale: 30, revalidate: result.kind === "disabled" ? Math.min(revalidate, DISABLED_REVALIDATE) : revalidate });
22
23
  return result;
@@ -24,7 +25,7 @@ async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor,
24
25
  function cachedResolver(options) {
25
26
  tokens.set(keyOf(options.baseUrl, options.workspaceId), options.token);
26
27
  const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
27
- return (path, locale, limit, cursor) => resolveCached(options.baseUrl, options.workspaceId, path, locale ?? "", limit ?? 0, cursor ?? "", revalidate);
28
+ return (path, locale, limit, cursor, nav) => resolveCached(options.baseUrl, options.workspaceId, path, locale ?? "", limit ?? 0, cursor ?? "", nav ?? "", revalidate);
28
29
  }
29
30
  export {
30
31
  cachedResolver
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tdacorp/hyle-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.9.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": {