@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/README.md +49 -8
- package/dist/check-routes-bin.js +168 -19
- package/dist/{chunk-4OB77ZOD.js → chunk-54JF4E53.js} +93 -11
- package/dist/chunk-67IOIAVW.js +35 -0
- package/dist/{chunk-SO6H2UGL.js → chunk-6LW33475.js} +110 -66
- package/dist/{chunk-OW6S7IZX.js → chunk-XKR74Y5G.js} +3 -2
- package/dist/docs-enhance.cjs +97 -0
- package/dist/docs-enhance.d.cts +16 -0
- package/dist/docs-enhance.d.ts +16 -0
- package/dist/docs-enhance.js +73 -0
- package/dist/index.cjs +97 -11
- package/dist/index.d.cts +61 -7
- package/dist/index.d.ts +61 -7
- package/dist/index.js +6 -1
- package/dist/next.cjs +211 -56
- package/dist/next.d.cts +47 -5
- package/dist/next.d.ts +47 -5
- package/dist/next.js +84 -5
- package/dist/react.cjs +118 -65
- package/dist/react.d.cts +35 -32
- package/dist/react.d.ts +35 -32
- package/dist/react.js +2 -1
- package/dist/{resolve-1rQntRBh.d.ts → resolve-D2rnnho9.d.cts} +2 -2
- package/dist/{resolve-36-Ng1H0.d.cts → resolve-Dpb6Orsj.d.ts} +2 -2
- package/dist/styles.css +32 -21
- package/dist/{types-DnPzhrFx.d.cts → types-BPPZrYOZ.d.cts} +1 -1
- package/dist/{types-BoyBWF2F.d.ts → types-C1eCQ2As.d.ts} +1 -1
- package/dist/{types-CwBCPh6K.d.cts → types-CHxH5E0S.d.cts} +15 -1
- package/dist/{types-CwBCPh6K.d.ts → types-CHxH5E0S.d.ts} +15 -1
- package/dist/use-cache.cjs +26 -7
- package/dist/use-cache.d.cts +2 -2
- package/dist/use-cache.d.ts +2 -2
- package/dist/use-cache.js +6 -5
- package/package.json +1 -1
package/dist/next.cjs
CHANGED
|
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var next_exports = {};
|
|
22
22
|
__export(next_exports, {
|
|
23
23
|
MOUNTS_MAX_STALE_MS: () => MOUNTS_MAX_STALE_MS,
|
|
24
|
+
createAssetRoute: () => createAssetRoute,
|
|
24
25
|
createRevalidateRoute: () => createRevalidateRoute,
|
|
25
26
|
fetchResolver: () => fetchResolver,
|
|
26
27
|
hyleMetadata: () => hyleMetadata,
|
|
@@ -36,6 +37,32 @@ module.exports = __toCommonJS(next_exports);
|
|
|
36
37
|
// src/next/page.tsx
|
|
37
38
|
var import_navigation2 = require("next/navigation");
|
|
38
39
|
|
|
40
|
+
// src/asset-path.ts
|
|
41
|
+
var ASSET_ROUTE_PREFIX = "/api/hyle/assets";
|
|
42
|
+
var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
|
|
43
|
+
var EXTENSIONS = "png|jpg|gif|webp|svg|pdf|mp4|webm|mp3|ogg";
|
|
44
|
+
var ASSET_FILE = new RegExp(`^${UUID}(?:\\.(?:${EXTENSIONS}))?$`);
|
|
45
|
+
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)$`, "i");
|
|
46
|
+
function hostAssetSrc(src) {
|
|
47
|
+
const file = HYLE_ASSET_URL.exec(src)?.[1];
|
|
48
|
+
return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}` : src;
|
|
49
|
+
}
|
|
50
|
+
function hostAssetHtml(html) {
|
|
51
|
+
return html.replace(new RegExp(`(\\ssrc=")(/assets/${UUID}(?:\\.(?:${EXTENSIONS}))?)(")`, "gi"), (_m, open, url, close) => `${open}${hostAssetSrc(url)}${close}`);
|
|
52
|
+
}
|
|
53
|
+
var ASSET_CONTENT_TYPES = /* @__PURE__ */ new Set([
|
|
54
|
+
"image/png",
|
|
55
|
+
"image/jpeg",
|
|
56
|
+
"image/gif",
|
|
57
|
+
"image/webp",
|
|
58
|
+
"image/svg+xml",
|
|
59
|
+
"application/pdf",
|
|
60
|
+
"video/mp4",
|
|
61
|
+
"video/webm",
|
|
62
|
+
"audio/mpeg",
|
|
63
|
+
"audio/ogg"
|
|
64
|
+
]);
|
|
65
|
+
|
|
39
66
|
// src/errors.ts
|
|
40
67
|
var Cp1ClientError = class extends Error {
|
|
41
68
|
code;
|
|
@@ -81,16 +108,19 @@ function isMounts(data) {
|
|
|
81
108
|
const mounts = data.mounts;
|
|
82
109
|
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");
|
|
83
110
|
}
|
|
84
|
-
function
|
|
111
|
+
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
85
112
|
let origin;
|
|
86
113
|
try {
|
|
87
|
-
origin = new URL(
|
|
114
|
+
origin = new URL(baseUrl);
|
|
88
115
|
} catch {
|
|
89
116
|
throw new TypeError("baseUrl must be an https origin");
|
|
90
117
|
}
|
|
91
|
-
if (origin.protocol !== "https:" && !(origin.protocol === "http:" && (
|
|
118
|
+
if (origin.protocol !== "https:" && !(origin.protocol === "http:" && (allowInsecureHttp || LOOPBACK.has(origin.hostname)))) {
|
|
92
119
|
throw new TypeError("baseUrl must be https (http is allowed only for localhost, or with allowInsecureHttp)");
|
|
93
120
|
}
|
|
121
|
+
}
|
|
122
|
+
function createHyleClient(options) {
|
|
123
|
+
checkBaseUrl(options.baseUrl, options.allowInsecureHttp);
|
|
94
124
|
if (!options.token) throw new TypeError("token is required");
|
|
95
125
|
const base = options.baseUrl.replace(/\/+$/, "");
|
|
96
126
|
const fetchImpl = options.fetch ?? fetch;
|
|
@@ -119,6 +149,7 @@ function createHyleClient(options) {
|
|
|
119
149
|
const query = new URLSearchParams({ path: opts.path });
|
|
120
150
|
if (opts.locale !== void 0) query.set("locale", opts.locale);
|
|
121
151
|
if (opts.format !== void 0) query.set("format", opts.format);
|
|
152
|
+
if (opts.nav !== void 0) query.set("nav", opts.nav);
|
|
122
153
|
if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
|
|
123
154
|
if (opts.limit !== void 0) query.set("limit", String(opts.limit));
|
|
124
155
|
const reply = await get("/cp1/read/resolve", query, opts.init);
|
|
@@ -133,7 +164,16 @@ function createHyleClient(options) {
|
|
|
133
164
|
if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
|
|
134
165
|
throw failure(reply);
|
|
135
166
|
}
|
|
136
|
-
|
|
167
|
+
async function asset(file, opts = {}) {
|
|
168
|
+
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
169
|
+
const headers = new Headers({ authorization: `Bearer ${options.token}` });
|
|
170
|
+
for (const name of ["range", "if-range", "if-none-match"]) {
|
|
171
|
+
const value = opts.headers?.[name];
|
|
172
|
+
if (value) headers.set(name, value);
|
|
173
|
+
}
|
|
174
|
+
return fetchImpl(`${base}/cp1/read/assets/${file}`, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
175
|
+
}
|
|
176
|
+
return { resolve, mounts, asset };
|
|
137
177
|
}
|
|
138
178
|
|
|
139
179
|
// src/delivery-dedupe.ts
|
|
@@ -364,7 +404,8 @@ var SHAPES = {
|
|
|
364
404
|
] }),
|
|
365
405
|
chev: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m6 3.5 4.5 4.5L6 12.5" }),
|
|
366
406
|
"chev-down": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m3.5 6 4.5 4.5L12.5 6" }),
|
|
367
|
-
"chev-left": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" })
|
|
407
|
+
"chev-left": /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M10 3.5 5.5 8 10 12.5" }),
|
|
408
|
+
x: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "m4 4 8 8M12 4l-8 8" })
|
|
368
409
|
};
|
|
369
410
|
function Icon({ name, className }) {
|
|
370
411
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("svg", { className: className ? `hyle-ic ${className}` : "hyle-ic", viewBox: "0 0 16 16", "aria-hidden": "true", children: SHAPES[name] });
|
|
@@ -525,6 +566,7 @@ function clean(node, depth, ctx2, budget) {
|
|
|
525
566
|
if (Object.hasOwn(rules, key) && rules[key](value, inner)) properties[key] = value;
|
|
526
567
|
}
|
|
527
568
|
}
|
|
569
|
+
if ((tag === "img" || tag === "video" || tag === "audio") && typeof properties.src === "string") properties.src = hostAssetSrc(properties.src);
|
|
528
570
|
if (tag === "iframe") {
|
|
529
571
|
if (properties.sandbox === void 0 || properties.srcdoc === void 0) return [];
|
|
530
572
|
properties.sandbox = "allow-scripts";
|
|
@@ -671,6 +713,8 @@ var en = {
|
|
|
671
713
|
emptyBody: "Documents published to this section will appear here, newest first.",
|
|
672
714
|
docs: "Documentation",
|
|
673
715
|
menu: "Menu",
|
|
716
|
+
closeMenu: "Close menu",
|
|
717
|
+
updated: "Last updated",
|
|
674
718
|
nfKind: "404 \xB7 Not found",
|
|
675
719
|
nfTitle: "This page does not exist",
|
|
676
720
|
nfBody: "The address may be mistyped, or the document may have been unpublished or moved.",
|
|
@@ -712,6 +756,8 @@ var fr = {
|
|
|
712
756
|
emptyBody: "Les documents publi\xE9s dans cette section appara\xEEtront ici, du plus r\xE9cent au plus ancien.",
|
|
713
757
|
docs: "Documentation",
|
|
714
758
|
menu: "Menu",
|
|
759
|
+
closeMenu: "Fermer le menu",
|
|
760
|
+
updated: "Derni\xE8re mise \xE0 jour",
|
|
715
761
|
nfKind: "404 \xB7 Introuvable",
|
|
716
762
|
nfTitle: "Cette page n'existe pas",
|
|
717
763
|
nfBody: "L'adresse est peut-\xEAtre mal saisie, ou le document a \xE9t\xE9 d\xE9publi\xE9 ou d\xE9plac\xE9.",
|
|
@@ -753,6 +799,8 @@ var es = {
|
|
|
753
799
|
emptyBody: "Los documentos publicados en esta secci\xF3n aparecer\xE1n aqu\xED, del m\xE1s reciente al m\xE1s antiguo.",
|
|
754
800
|
docs: "Documentaci\xF3n",
|
|
755
801
|
menu: "Men\xFA",
|
|
802
|
+
closeMenu: "Cerrar el men\xFA",
|
|
803
|
+
updated: "\xDAltima actualizaci\xF3n",
|
|
756
804
|
nfKind: "404 \xB7 No encontrada",
|
|
757
805
|
nfTitle: "Esta p\xE1gina no existe",
|
|
758
806
|
nfBody: "Puede que la direcci\xF3n est\xE9 mal escrita, o que el documento se haya despublicado o movido.",
|
|
@@ -872,7 +920,7 @@ function HastContent({ tree, title, components = {}, locale }) {
|
|
|
872
920
|
});
|
|
873
921
|
}
|
|
874
922
|
function TrustedServerHtml({ html }) {
|
|
875
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { dangerouslySetInnerHTML: { __html: html } });
|
|
923
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { dangerouslySetInnerHTML: { __html: hostAssetHtml(html) } });
|
|
876
924
|
}
|
|
877
925
|
|
|
878
926
|
// src/react/index.ts
|
|
@@ -1055,65 +1103,96 @@ function ListPage({ list, olderHref, description, ...base }) {
|
|
|
1055
1103
|
] }) : null
|
|
1056
1104
|
] }) });
|
|
1057
1105
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1106
|
+
|
|
1107
|
+
// src/react/docs.tsx
|
|
1108
|
+
var import_docs_enhance = require("./docs-enhance.cjs");
|
|
1109
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1110
|
+
var ROOT_ID = "hyle-docs";
|
|
1111
|
+
var NAV_ID = "hyle-docs-nav";
|
|
1112
|
+
function navTreeOf(article) {
|
|
1113
|
+
if (article.nav && !article.nav.truncated && article.nav.items.length > 0) return article.nav.items;
|
|
1114
|
+
const { publication: pub } = article;
|
|
1115
|
+
const here = {
|
|
1116
|
+
slug: pub.slug,
|
|
1117
|
+
title: pub.title,
|
|
1118
|
+
canonical_path: pub.canonical_path,
|
|
1119
|
+
children: article.children.map((child) => ({ ...child, children: [] }))
|
|
1120
|
+
};
|
|
1121
|
+
return [article.ancestors.reduceRight((inner, a) => ({ ...a, children: [inner] }), here)];
|
|
1122
|
+
}
|
|
1123
|
+
function pathTo(nodes, path) {
|
|
1124
|
+
for (const node of nodes) {
|
|
1125
|
+
if (node.canonical_path === path) return [node.canonical_path];
|
|
1126
|
+
const below = pathTo(node.children, path);
|
|
1127
|
+
if (below.length > 0) return [node.canonical_path, ...below];
|
|
1128
|
+
}
|
|
1129
|
+
return [];
|
|
1130
|
+
}
|
|
1131
|
+
function Branch({ nodes, current, onPath, c }) {
|
|
1132
|
+
const { Link } = c;
|
|
1133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { children: nodes.map((node) => {
|
|
1134
|
+
const link = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Link, { href: c.href(node.canonical_path), ...node.canonical_path === current ? { "aria-current": "page" } : {}, children: node.title });
|
|
1135
|
+
if (node.children.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { children: link }, node.canonical_path);
|
|
1136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("details", { ...onPath.has(node.canonical_path) ? { open: true } : {}, children: [
|
|
1137
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("summary", { children: [
|
|
1138
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "chev" }),
|
|
1139
|
+
link
|
|
1140
|
+
] }),
|
|
1141
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Branch, { nodes: node.children, current, onPath, c })
|
|
1142
|
+
] }) }, node.canonical_path);
|
|
1143
|
+
}) });
|
|
1072
1144
|
}
|
|
1073
1145
|
function DocsPage({ article, ...base }) {
|
|
1074
1146
|
const { publication: pub } = article;
|
|
1075
1147
|
const c = ctx(base, pub.locale);
|
|
1076
1148
|
const { Link, s } = c;
|
|
1077
1149
|
const toc = Toc({ toc: article.toc, c });
|
|
1150
|
+
const tree = navTreeOf(article);
|
|
1151
|
+
const onPath = new Set(pathTo(tree, pub.canonical_path));
|
|
1078
1152
|
const siteName = article.breadcrumbs[0]?.title ?? "";
|
|
1079
|
-
const
|
|
1080
|
-
const side = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
1081
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "hyle-side-head", children: [
|
|
1082
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: siteName }),
|
|
1083
|
-
version
|
|
1084
|
-
] }),
|
|
1085
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "docs.sidebar-header", slots: base.slots, className: "hyle-side-slot" }),
|
|
1086
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DocsTree, { article, c }),
|
|
1087
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Slot, { name: "docs.sidebar-footer", slots: base.slots, className: "hyle-side-slot" })
|
|
1088
|
-
] });
|
|
1153
|
+
const headingIds = article.toc.filter((t) => t.depth === 2 || t.depth === 3).map((t) => scopeId(t.id));
|
|
1089
1154
|
const notTranslated = article.fallback ? s.fallbackTitle.replace("{language}", languageName(article.fallback.requested_locale, c.locale)) : void 0;
|
|
1090
|
-
return /* @__PURE__ */ (0,
|
|
1091
|
-
/* @__PURE__ */ (0,
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1155
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Shell, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-docs", id: ROOT_ID, lang: c.locale, children: [
|
|
1156
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_docs_enhance.DocsEnhance, { headingIds, rootId: ROOT_ID }),
|
|
1157
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { type: "button", className: "hyle-nav-bar", popoverTarget: NAV_ID, children: [
|
|
1158
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "file" }),
|
|
1159
|
+
s.menu,
|
|
1160
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "cur", children: pub.title }),
|
|
1161
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "chev-down", className: "hyle-chev" })
|
|
1162
|
+
] }),
|
|
1163
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("aside", { className: "hyle-nav-d", id: NAV_ID, popover: "auto", "aria-label": s.docs, children: [
|
|
1164
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-side-head", children: [
|
|
1165
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: siteName }),
|
|
1166
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Slot, { name: "docs.version", slots: base.slots, tag: "span" }),
|
|
1167
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "hyle-nav-x", popoverTarget: NAV_ID, popoverTargetAction: "hide", "aria-label": s.closeMenu, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "x" }) })
|
|
1097
1168
|
] }),
|
|
1098
|
-
/* @__PURE__ */ (0,
|
|
1169
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Slot, { name: "docs.sidebar-header", slots: base.slots, className: "hyle-side-slot" }),
|
|
1170
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("nav", { className: "hyle-tree", "aria-label": s.docs, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Branch, { nodes: tree, current: pub.canonical_path, onPath, c }) }),
|
|
1171
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Slot, { name: "docs.sidebar-footer", slots: base.slots, className: "hyle-side-slot" })
|
|
1099
1172
|
] }),
|
|
1100
|
-
/* @__PURE__ */ (0,
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
/* @__PURE__ */ (0,
|
|
1104
|
-
|
|
1105
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("b", { children: notTranslated }),
|
|
1173
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-docs-main", "data-hyle-page": "docs", children: [
|
|
1174
|
+
notTranslated ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "hyle-banner", "data-kind": "warn", role: "status", children: [
|
|
1175
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "alert" }),
|
|
1176
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1177
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("b", { children: notTranslated }),
|
|
1106
1178
|
" ",
|
|
1107
1179
|
s.fallbackBody
|
|
1108
1180
|
] })
|
|
1109
1181
|
] }) : null,
|
|
1110
|
-
/* @__PURE__ */ (0,
|
|
1111
|
-
/* @__PURE__ */ (0,
|
|
1112
|
-
pub.description ? /* @__PURE__ */ (0,
|
|
1182
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("nav", { className: "hyle-crumbs", "aria-label": s.crumbs, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ol", { children: article.breadcrumbs.map((b, i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { "aria-current": i === article.breadcrumbs.length - 1 ? "page" : void 0, children: i === article.breadcrumbs.length - 1 ? b.title : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Link, { href: c.href(b.canonical_path), children: b.title }) }, b.canonical_path)) }) }),
|
|
1183
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h1", { className: "hyle-title", children: pub.title }),
|
|
1184
|
+
pub.description ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "hyle-desc", children: pub.description }) : null,
|
|
1185
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "hyle-updated", children: [
|
|
1186
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Icon, { name: "calendar" }),
|
|
1187
|
+
s.updated,
|
|
1188
|
+
" ",
|
|
1189
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("time", { dateTime: pub.updated_at, title: pub.updated_at, children: formatDate(pub.updated_at, c.locale) })
|
|
1190
|
+
] }),
|
|
1113
1191
|
toc.narrow,
|
|
1114
|
-
/* @__PURE__ */ (0,
|
|
1115
|
-
/* @__PURE__ */ (0,
|
|
1116
|
-
/* @__PURE__ */ (0,
|
|
1192
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Body, { article, components: base.components, locale: c.locale }),
|
|
1193
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Pager, { prev: article.prev, next: article.next, c }),
|
|
1194
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Slot, { name: "docs.after", slots: base.slots, className: "hyle-after" }),
|
|
1195
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "hyle-docs-end", "aria-hidden": "true" })
|
|
1117
1196
|
] }),
|
|
1118
1197
|
toc.wide
|
|
1119
1198
|
] }) });
|
|
@@ -1168,8 +1247,9 @@ function fetchResolver(options) {
|
|
|
1168
1247
|
const client = createHyleClient({ baseUrl: options.baseUrl, token: options.token });
|
|
1169
1248
|
const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
|
|
1170
1249
|
const tags = workspaceTags(options.workspaceId, options.sections);
|
|
1171
|
-
return (path, locale, limit, cursor) => client.resolve({
|
|
1250
|
+
return (path, locale, limit, cursor, nav) => client.resolve({
|
|
1172
1251
|
path,
|
|
1252
|
+
...nav !== void 0 ? { nav } : {},
|
|
1173
1253
|
...locale !== void 0 ? { locale } : {},
|
|
1174
1254
|
...limit !== void 0 ? { limit } : {},
|
|
1175
1255
|
...cursor !== void 0 ? { cursor } : {},
|
|
@@ -1201,7 +1281,7 @@ function isRejectedRequest(error) {
|
|
|
1201
1281
|
}
|
|
1202
1282
|
|
|
1203
1283
|
// src/next/page.tsx
|
|
1204
|
-
var
|
|
1284
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1205
1285
|
function hylePage(options) {
|
|
1206
1286
|
const resolve = resolverFor(options);
|
|
1207
1287
|
return async function HylePage({ params, searchParams }) {
|
|
@@ -1209,17 +1289,17 @@ function hylePage(options) {
|
|
|
1209
1289
|
if (path === void 0) (0, import_navigation2.notFound)();
|
|
1210
1290
|
try {
|
|
1211
1291
|
const cursor = options.paginate === "searchParams" ? validCursor((await searchParams)?.cursor) : void 0;
|
|
1212
|
-
const result = await resolve(path, locale, options.listLimit, cursor);
|
|
1292
|
+
const result = await resolve(path, locale, options.listLimit, cursor, options.layout === "docs" ? "tree" : void 0);
|
|
1213
1293
|
switch (result.kind) {
|
|
1214
1294
|
case "article": {
|
|
1215
1295
|
const props = { article: result, components: options.components, slots: options.slots, locale, toHref };
|
|
1216
|
-
return options.layout === "docs" ? /* @__PURE__ */ (0,
|
|
1296
|
+
return options.layout === "docs" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DocsPage, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ArticlePage, { ...props });
|
|
1217
1297
|
}
|
|
1218
1298
|
case "list": {
|
|
1219
1299
|
const list = options.list?.title ? { ...result, section: { ...result.section, title: options.list.title } } : result;
|
|
1220
1300
|
const next = options.paginate === "searchParams" ? validCursor(result.next_cursor) : void 0;
|
|
1221
1301
|
const olderHref = next ? `${toHref(path)}?cursor=${next}` : void 0;
|
|
1222
|
-
return /* @__PURE__ */ (0,
|
|
1302
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ListPage, { list, ...olderHref ? { olderHref } : {}, ...options.list?.description ? { description: options.list.description } : {}, components: options.components, slots: options.slots, locale, toHref });
|
|
1223
1303
|
}
|
|
1224
1304
|
case "redirect": {
|
|
1225
1305
|
const to = safeRedirectTarget(result.to);
|
|
@@ -1279,7 +1359,7 @@ function hyleMetadata(options) {
|
|
|
1279
1359
|
const { path, locale, toHref } = routeContext(options, await params ?? {});
|
|
1280
1360
|
if (path === void 0) return {};
|
|
1281
1361
|
try {
|
|
1282
|
-
const result = await resolve(path, locale, options.listLimit);
|
|
1362
|
+
const result = await resolve(path, locale, options.listLimit, void 0, options.layout === "docs" ? "tree" : void 0);
|
|
1283
1363
|
if (result.kind === "list") {
|
|
1284
1364
|
const title = options.list?.title || result.section.title;
|
|
1285
1365
|
const description2 = options.list?.description;
|
|
@@ -1452,9 +1532,84 @@ async function hyleRootSitemap(options, sitemap) {
|
|
|
1452
1532
|
}
|
|
1453
1533
|
return [...entries.values()];
|
|
1454
1534
|
}
|
|
1535
|
+
|
|
1536
|
+
// src/next/asset.ts
|
|
1537
|
+
var DEFAULT_MAX_BYTES = 16 * 1024 * 1024;
|
|
1538
|
+
var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
1539
|
+
var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
|
|
1540
|
+
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
1541
|
+
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
1542
|
+
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
1543
|
+
var isSwitchedOff2 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
1544
|
+
function capped(body, max) {
|
|
1545
|
+
let seen = 0;
|
|
1546
|
+
return body.pipeThrough(
|
|
1547
|
+
new TransformStream({
|
|
1548
|
+
transform(chunk, controller) {
|
|
1549
|
+
seen += chunk.byteLength;
|
|
1550
|
+
if (seen > max) return controller.error(new Error("asset too large"));
|
|
1551
|
+
controller.enqueue(chunk);
|
|
1552
|
+
}
|
|
1553
|
+
})
|
|
1554
|
+
);
|
|
1555
|
+
}
|
|
1556
|
+
function createAssetRoute(options) {
|
|
1557
|
+
let client;
|
|
1558
|
+
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
1559
|
+
async function serve(req, ctx2, head) {
|
|
1560
|
+
if (isSwitchedOff2((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
1561
|
+
const file = (await ctx2.params).file;
|
|
1562
|
+
if (typeof file !== "string" || !ASSET_FILE.test(file)) return empty(404);
|
|
1563
|
+
try {
|
|
1564
|
+
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
1565
|
+
} catch {
|
|
1566
|
+
return empty(404);
|
|
1567
|
+
}
|
|
1568
|
+
let upstream;
|
|
1569
|
+
try {
|
|
1570
|
+
upstream = await client.asset(file, {
|
|
1571
|
+
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS2,
|
|
1572
|
+
headers: { range: req.headers.get("range"), "if-range": req.headers.get("if-range"), "if-none-match": req.headers.get("if-none-match") }
|
|
1573
|
+
});
|
|
1574
|
+
} catch {
|
|
1575
|
+
return empty(502);
|
|
1576
|
+
}
|
|
1577
|
+
const drop = () => void upstream.body?.cancel().catch(() => {
|
|
1578
|
+
});
|
|
1579
|
+
const etag = upstream.headers.get("etag");
|
|
1580
|
+
if (upstream.status === 304) {
|
|
1581
|
+
drop();
|
|
1582
|
+
return new Response(null, { status: 304, headers: { "Cache-Control": CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS, ...etag ? { ETag: etag } : {} } });
|
|
1583
|
+
}
|
|
1584
|
+
if (upstream.status === 404 || upstream.status === 416) {
|
|
1585
|
+
drop();
|
|
1586
|
+
const range = upstream.status === 416 ? upstream.headers.get("content-range") : null;
|
|
1587
|
+
return empty(upstream.status, range ? { "Content-Range": range } : {});
|
|
1588
|
+
}
|
|
1589
|
+
const type = upstream.headers.get("content-type")?.split(";")[0]?.trim().toLowerCase();
|
|
1590
|
+
const length = Number(upstream.headers.get("content-length"));
|
|
1591
|
+
const expectedStatus = upstream.status === 200 || upstream.status === 206;
|
|
1592
|
+
if (!expectedStatus || !upstream.body || !type || !ASSET_CONTENT_TYPES.has(type) || Number.isFinite(length) && length > maxBytes) {
|
|
1593
|
+
drop();
|
|
1594
|
+
return empty(502);
|
|
1595
|
+
}
|
|
1596
|
+
const headers = new Headers({ "Content-Type": type, "Accept-Ranges": "bytes", "Cache-Control": upstream.status === 206 ? PARTIAL_CACHE_CONTROL : CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS });
|
|
1597
|
+
if (etag) headers.set("ETag", etag);
|
|
1598
|
+
const contentRange = upstream.headers.get("content-range");
|
|
1599
|
+
if (upstream.status === 206 && contentRange) headers.set("Content-Range", contentRange);
|
|
1600
|
+
if (!upstream.headers.get("content-encoding") && upstream.headers.get("content-length")) headers.set("Content-Length", String(length));
|
|
1601
|
+
if (head) {
|
|
1602
|
+
drop();
|
|
1603
|
+
return new Response(null, { status: upstream.status, headers });
|
|
1604
|
+
}
|
|
1605
|
+
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers });
|
|
1606
|
+
}
|
|
1607
|
+
return { GET: (req, ctx2) => serve(req, ctx2, false), HEAD: (req, ctx2) => serve(req, ctx2, true) };
|
|
1608
|
+
}
|
|
1455
1609
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1456
1610
|
0 && (module.exports = {
|
|
1457
1611
|
MOUNTS_MAX_STALE_MS,
|
|
1612
|
+
createAssetRoute,
|
|
1458
1613
|
createRevalidateRoute,
|
|
1459
1614
|
fetchResolver,
|
|
1460
1615
|
hyleMetadata,
|
package/dist/next.d.cts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { H as HyleComponents, a as HyleSlots } from './types-
|
|
3
|
-
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-
|
|
4
|
-
export { f as fetchResolver, w as workspaceTags } from './resolve-
|
|
2
|
+
import { H as HyleComponents, a as HyleSlots } from './types-BPPZrYOZ.cjs';
|
|
3
|
+
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-D2rnnho9.cjs';
|
|
4
|
+
export { f as fetchResolver, w as workspaceTags } from './resolve-D2rnnho9.cjs';
|
|
5
5
|
import { MetadataRoute, Metadata } from 'next';
|
|
6
6
|
import { a as RevalidationCallbackRoute } from './revalidation-callback-D7Ms_Puz.cjs';
|
|
7
|
-
import './types-
|
|
7
|
+
import './types-CHxH5E0S.cjs';
|
|
8
8
|
|
|
9
9
|
type RouteParams = Record<string, string | string[] | undefined>;
|
|
10
10
|
interface CommonOptions {
|
|
@@ -185,4 +185,46 @@ interface HyleRootSitemapOptions {
|
|
|
185
185
|
*/
|
|
186
186
|
declare function hyleRootSitemap(options: Configs, sitemap: HyleRootSitemapOptions): Promise<MetadataRoute.Sitemap>;
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
interface AssetRouteOptions {
|
|
189
|
+
/** hyle's origin (HYLE_TARGET_BASE_URL). */
|
|
190
|
+
readonly baseUrl: string | undefined;
|
|
191
|
+
/** This workspace's target credential (HYLE_TARGET_TOKEN). Used only server-side; it never reaches the browser. */
|
|
192
|
+
readonly token: string | undefined;
|
|
193
|
+
/** Environment to read the site switch from. Default process.env. */
|
|
194
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
195
|
+
/** Refuse (502) an asset larger than this many bytes. Default 16 MiB; hyle's own upload limit is 4 MiB. */
|
|
196
|
+
readonly maxBytes?: number;
|
|
197
|
+
/** Abort the upstream request, body included, after this many milliseconds. Default 30000. */
|
|
198
|
+
readonly timeoutMs?: number;
|
|
199
|
+
/** Injectable for tests. */
|
|
200
|
+
readonly fetch?: typeof fetch;
|
|
201
|
+
}
|
|
202
|
+
interface AssetRoute {
|
|
203
|
+
GET(req: Request, ctx: {
|
|
204
|
+
params: Promise<{
|
|
205
|
+
file?: string;
|
|
206
|
+
}>;
|
|
207
|
+
}): Promise<Response>;
|
|
208
|
+
HEAD(req: Request, ctx: {
|
|
209
|
+
params: Promise<{
|
|
210
|
+
file?: string;
|
|
211
|
+
}>;
|
|
212
|
+
}): Promise<Response>;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* `export const { GET, HEAD } = createAssetRoute({ ... })` in `app/api/hyle/assets/[file]/route.ts` (ADR 0015).
|
|
216
|
+
*
|
|
217
|
+
* The SDK rewrites hyle's `/assets/<uuid>.<ext>` in rendered content to `/api/hyle/assets/<uuid>.<ext>`; this route answers it by
|
|
218
|
+
* asking hyle for exactly that file with the target credential and streaming the bytes back, same-origin, so a strict
|
|
219
|
+
* `img-src 'self'` (and `media-src 'self'`) CSP needs no change. hyle serves only assets that a currently published page of this
|
|
220
|
+
* workspace references, so an unpublished or other workspace's asset is a 404 here too.
|
|
221
|
+
*
|
|
222
|
+
* Safety: the only input is the `file` segment, matched against `<uuid>[.<ext>]` before anything is sent, so this is not an open
|
|
223
|
+
* proxy. The browser's cookies and authorization header are never forwarded; only `Range`, `If-Range` and `If-None-Match` are.
|
|
224
|
+
* The response headers are built here (no upstream header is copied blindly), the content type must be on the asset allowlist,
|
|
225
|
+
* the body is size-capped and time-bounded, and every failure is an empty 404 or 502 that says nothing about hyle.
|
|
226
|
+
* The site switch `HYLE_CONTENT_ENABLED=0`/`false`, or missing configuration, answers 404.
|
|
227
|
+
*/
|
|
228
|
+
declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
|
|
229
|
+
|
|
230
|
+
export { type AssetRoute, type AssetRouteOptions, FetchResolverOptions, type HyleNextOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, MOUNTS_MAX_STALE_MS, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createRevalidateRoute, hyleMetadata, hylePage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap };
|
package/dist/next.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ReactElement } from 'react';
|
|
2
|
-
import { H as HyleComponents, a as HyleSlots } from './types-
|
|
3
|
-
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-
|
|
4
|
-
export { f as fetchResolver, w as workspaceTags } from './resolve-
|
|
2
|
+
import { H as HyleComponents, a as HyleSlots } from './types-C1eCQ2As.js';
|
|
3
|
+
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-Dpb6Orsj.js';
|
|
4
|
+
export { f as fetchResolver, w as workspaceTags } from './resolve-Dpb6Orsj.js';
|
|
5
5
|
import { MetadataRoute, Metadata } from 'next';
|
|
6
6
|
import { a as RevalidationCallbackRoute } from './revalidation-callback-D7Ms_Puz.js';
|
|
7
|
-
import './types-
|
|
7
|
+
import './types-CHxH5E0S.js';
|
|
8
8
|
|
|
9
9
|
type RouteParams = Record<string, string | string[] | undefined>;
|
|
10
10
|
interface CommonOptions {
|
|
@@ -185,4 +185,46 @@ interface HyleRootSitemapOptions {
|
|
|
185
185
|
*/
|
|
186
186
|
declare function hyleRootSitemap(options: Configs, sitemap: HyleRootSitemapOptions): Promise<MetadataRoute.Sitemap>;
|
|
187
187
|
|
|
188
|
-
|
|
188
|
+
interface AssetRouteOptions {
|
|
189
|
+
/** hyle's origin (HYLE_TARGET_BASE_URL). */
|
|
190
|
+
readonly baseUrl: string | undefined;
|
|
191
|
+
/** This workspace's target credential (HYLE_TARGET_TOKEN). Used only server-side; it never reaches the browser. */
|
|
192
|
+
readonly token: string | undefined;
|
|
193
|
+
/** Environment to read the site switch from. Default process.env. */
|
|
194
|
+
readonly env?: Readonly<Record<string, string | undefined>>;
|
|
195
|
+
/** Refuse (502) an asset larger than this many bytes. Default 16 MiB; hyle's own upload limit is 4 MiB. */
|
|
196
|
+
readonly maxBytes?: number;
|
|
197
|
+
/** Abort the upstream request, body included, after this many milliseconds. Default 30000. */
|
|
198
|
+
readonly timeoutMs?: number;
|
|
199
|
+
/** Injectable for tests. */
|
|
200
|
+
readonly fetch?: typeof fetch;
|
|
201
|
+
}
|
|
202
|
+
interface AssetRoute {
|
|
203
|
+
GET(req: Request, ctx: {
|
|
204
|
+
params: Promise<{
|
|
205
|
+
file?: string;
|
|
206
|
+
}>;
|
|
207
|
+
}): Promise<Response>;
|
|
208
|
+
HEAD(req: Request, ctx: {
|
|
209
|
+
params: Promise<{
|
|
210
|
+
file?: string;
|
|
211
|
+
}>;
|
|
212
|
+
}): Promise<Response>;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* `export const { GET, HEAD } = createAssetRoute({ ... })` in `app/api/hyle/assets/[file]/route.ts` (ADR 0015).
|
|
216
|
+
*
|
|
217
|
+
* The SDK rewrites hyle's `/assets/<uuid>.<ext>` in rendered content to `/api/hyle/assets/<uuid>.<ext>`; this route answers it by
|
|
218
|
+
* asking hyle for exactly that file with the target credential and streaming the bytes back, same-origin, so a strict
|
|
219
|
+
* `img-src 'self'` (and `media-src 'self'`) CSP needs no change. hyle serves only assets that a currently published page of this
|
|
220
|
+
* workspace references, so an unpublished or other workspace's asset is a 404 here too.
|
|
221
|
+
*
|
|
222
|
+
* Safety: the only input is the `file` segment, matched against `<uuid>[.<ext>]` before anything is sent, so this is not an open
|
|
223
|
+
* proxy. The browser's cookies and authorization header are never forwarded; only `Range`, `If-Range` and `If-None-Match` are.
|
|
224
|
+
* The response headers are built here (no upstream header is copied blindly), the content type must be on the asset allowlist,
|
|
225
|
+
* the body is size-capped and time-bounded, and every failure is an empty 404 or 502 that says nothing about hyle.
|
|
226
|
+
* The site switch `HYLE_CONTENT_ENABLED=0`/`false`, or missing configuration, answers 404.
|
|
227
|
+
*/
|
|
228
|
+
declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
|
|
229
|
+
|
|
230
|
+
export { type AssetRoute, type AssetRouteOptions, FetchResolverOptions, type HyleNextOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, MOUNTS_MAX_STALE_MS, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createRevalidateRoute, hyleMetadata, hylePage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap };
|