@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.
- package/README.md +105 -4
- package/bin/hyle-sdk-check-routes.mjs +3 -0
- package/dist/check-routes-bin.js +389 -0
- package/dist/chunk-4OB77ZOD.js +455 -0
- package/dist/chunk-BUJFMR3M.js +38 -0
- package/dist/{chunk-7VCMJUPC.js → chunk-OW6S7IZX.js} +1 -1
- package/dist/{chunk-MHVWHSKC.js → chunk-SO6H2UGL.js} +124 -6
- package/dist/diagram-viewer-DYX6R63Y.js +1132 -0
- package/dist/index.cjs +191 -20
- package/dist/index.d.cts +95 -3
- package/dist/index.d.ts +95 -3
- package/dist/index.js +13 -1
- package/dist/mermaid-diagram.cjs +1395 -0
- package/dist/mermaid-diagram.d.cts +55 -0
- package/dist/mermaid-diagram.d.ts +55 -0
- package/dist/mermaid-diagram.js +140 -0
- package/dist/next.cjs +286 -27
- package/dist/next.d.cts +51 -5
- package/dist/next.d.ts +51 -5
- package/dist/next.js +131 -5
- package/dist/react.cjs +124 -5
- package/dist/react.d.cts +60 -4
- package/dist/react.d.ts +60 -4
- package/dist/react.js +3 -1
- package/dist/{resolve-fMx2W8RR.d.ts → resolve-1rQntRBh.d.ts} +1 -1
- package/dist/{resolve-B_p0p4Zn.d.cts → resolve-36-Ng1H0.d.cts} +1 -1
- package/dist/styles.css +82 -1
- package/dist/{types-BNaGecO7.d.ts → types-BoyBWF2F.d.ts} +3 -1
- package/dist/{types-DjXf6iPo.d.cts → types-CwBCPh6K.d.cts} +20 -1
- package/dist/{types-DjXf6iPo.d.ts → types-CwBCPh6K.d.ts} +20 -1
- package/dist/{types-DLWvqanV.d.cts → types-DnPzhrFx.d.cts} +3 -1
- package/dist/use-cache.cjs +34 -20
- package/dist/use-cache.d.cts +2 -2
- package/dist/use-cache.d.ts +2 -2
- package/dist/use-cache.js +2 -2
- package/package.json +8 -3
- package/dist/chunk-HFUJRNFP.js +0 -290
package/dist/index.cjs
CHANGED
|
@@ -23,11 +23,17 @@ __export(src_exports, {
|
|
|
23
23
|
CACHE_TAG_PATTERN: () => CACHE_TAG_PATTERN,
|
|
24
24
|
Cp1ClientError: () => Cp1ClientError,
|
|
25
25
|
DeliveryDedupe: () => DeliveryDedupe,
|
|
26
|
+
checkRoutes: () => checkRoutes,
|
|
26
27
|
createHyleClient: () => createHyleClient,
|
|
27
28
|
createRevalidationCallbackRoute: () => createRevalidationCallbackRoute,
|
|
29
|
+
formatReport: () => formatReport,
|
|
30
|
+
hostRoutesFromManifests: () => hostRoutesFromManifests,
|
|
28
31
|
isValidCacheTag: () => isValidCacheTag,
|
|
29
32
|
listPublicationPaths: () => listPublicationPaths,
|
|
33
|
+
normalizeRoute: () => normalizeRoute,
|
|
30
34
|
parseSignatureHeader: () => parseSignatureHeader,
|
|
35
|
+
reservedFor: () => reservedFor,
|
|
36
|
+
routeMatches: () => routeMatches,
|
|
31
37
|
verifyHyleSignature: () => verifyHyleSignature
|
|
32
38
|
});
|
|
33
39
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -72,6 +78,11 @@ async function readCapped(res, max) {
|
|
|
72
78
|
return Buffer.concat(chunks).toString("utf8");
|
|
73
79
|
}
|
|
74
80
|
var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound", "disabled"]);
|
|
81
|
+
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
82
|
+
function isMounts(data) {
|
|
83
|
+
const mounts = data.mounts;
|
|
84
|
+
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");
|
|
85
|
+
}
|
|
75
86
|
function createHyleClient(options) {
|
|
76
87
|
let origin;
|
|
77
88
|
try {
|
|
@@ -85,18 +96,14 @@ function createHyleClient(options) {
|
|
|
85
96
|
if (!options.token) throw new TypeError("token is required");
|
|
86
97
|
const base = options.baseUrl.replace(/\/+$/, "");
|
|
87
98
|
const fetchImpl = options.fetch ?? fetch;
|
|
88
|
-
async function
|
|
89
|
-
const url = new URL(`${base}
|
|
90
|
-
url.
|
|
91
|
-
|
|
92
|
-
if (opts.format !== void 0) url.searchParams.set("format", opts.format);
|
|
93
|
-
if (opts.cursor !== void 0) url.searchParams.set("cursor", opts.cursor);
|
|
94
|
-
if (opts.limit !== void 0) url.searchParams.set("limit", String(opts.limit));
|
|
95
|
-
const headers = new Headers(opts.init?.headers);
|
|
99
|
+
async function get(pathname, query, init) {
|
|
100
|
+
const url = new URL(`${base}${pathname}`);
|
|
101
|
+
url.search = query.toString();
|
|
102
|
+
const headers = new Headers(init?.headers);
|
|
96
103
|
headers.set("authorization", `Bearer ${options.token}`);
|
|
97
104
|
const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
98
|
-
const signal =
|
|
99
|
-
const res = await fetchImpl(url.toString(), { ...
|
|
105
|
+
const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
|
|
106
|
+
const res = await fetchImpl(url.toString(), { ...init, method: "GET", headers, redirect: "error", signal });
|
|
100
107
|
const text = await readCapped(res, options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES);
|
|
101
108
|
let parsed;
|
|
102
109
|
try {
|
|
@@ -104,18 +111,31 @@ function createHyleClient(options) {
|
|
|
104
111
|
} catch {
|
|
105
112
|
parsed = void 0;
|
|
106
113
|
}
|
|
107
|
-
|
|
108
|
-
|
|
114
|
+
return { parsed, status: res.status };
|
|
115
|
+
}
|
|
116
|
+
const failure = ({ parsed, status }) => {
|
|
109
117
|
const err = parsed?.error;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
);
|
|
118
|
+
return new Cp1ClientError(err?.code ?? "INVALID_RESPONSE", err?.message ?? `Unexpected response from hyle (HTTP ${status})`, status, err?.request_id ?? "", err?.details);
|
|
119
|
+
};
|
|
120
|
+
async function resolve(opts) {
|
|
121
|
+
const query = new URLSearchParams({ path: opts.path });
|
|
122
|
+
if (opts.locale !== void 0) query.set("locale", opts.locale);
|
|
123
|
+
if (opts.format !== void 0) query.set("format", opts.format);
|
|
124
|
+
if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
|
|
125
|
+
if (opts.limit !== void 0) query.set("limit", String(opts.limit));
|
|
126
|
+
const reply = await get("/cp1/read/resolve", query, opts.init);
|
|
127
|
+
const data = reply.parsed?.data;
|
|
128
|
+
if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) return data;
|
|
129
|
+
throw failure(reply);
|
|
130
|
+
}
|
|
131
|
+
async function mounts(opts = {}) {
|
|
132
|
+
const reply = await get("/cp1/read/mounts", new URLSearchParams(), opts.init);
|
|
133
|
+
const data = reply.parsed?.data;
|
|
134
|
+
if (data?.cp === 1 && data.kind === "disabled") return data;
|
|
135
|
+
if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
|
|
136
|
+
throw failure(reply);
|
|
117
137
|
}
|
|
118
|
-
return { resolve };
|
|
138
|
+
return { resolve, mounts };
|
|
119
139
|
}
|
|
120
140
|
|
|
121
141
|
// src/delivery-dedupe.ts
|
|
@@ -310,15 +330,166 @@ async function listPublicationPaths(options) {
|
|
|
310
330
|
}
|
|
311
331
|
return { paths: [...found].map(([path, publishedAt]) => ({ path, publishedAt })), complete };
|
|
312
332
|
}
|
|
333
|
+
|
|
334
|
+
// src/route-check.ts
|
|
335
|
+
var NOT_ROUTES = /* @__PURE__ */ new Set(["/_not-found", "/_global-error", "/_app", "/_error", "/_document", "/404", "/500"]);
|
|
336
|
+
var LOCALE_PARAM = "locale";
|
|
337
|
+
function normalizeRoute(key) {
|
|
338
|
+
const segments = key.replace(/\/(page|route)$/, "").split("/").filter((s) => s !== "");
|
|
339
|
+
if (segments.some((s) => s.startsWith("@") || /^\(\.{1,3}\)/.test(s))) return void 0;
|
|
340
|
+
const route = `/${segments.filter((s) => !/^\(.*\)$/.test(s)).join("/")}`;
|
|
341
|
+
return NOT_ROUTES.has(route) ? void 0 : route;
|
|
342
|
+
}
|
|
343
|
+
function hostRoutesFromManifests({ routesManifest, appPaths }) {
|
|
344
|
+
const keys = [...(routesManifest?.staticRoutes ?? []).map((r) => r.page), ...(routesManifest?.dynamicRoutes ?? []).map((r) => r.page), ...Object.keys(appPaths ?? {})];
|
|
345
|
+
return [...new Set(keys.map(normalizeRoute).filter((r) => r !== void 0))].sort();
|
|
346
|
+
}
|
|
347
|
+
var segmentsOf = (path) => path.split("/").filter((s) => s !== "");
|
|
348
|
+
function parse(route) {
|
|
349
|
+
return segmentsOf(route).map((value) => {
|
|
350
|
+
const optional = /^\[\[\.\.\.([^\]]+)\]\]$/.exec(value);
|
|
351
|
+
if (optional) return { kind: "optional-catch-all", name: optional[1] };
|
|
352
|
+
const rest = /^\[\.\.\.([^\]]+)\]$/.exec(value);
|
|
353
|
+
if (rest) return { kind: "catch-all", name: rest[1] };
|
|
354
|
+
const one = /^\[([^\]]+)\]$/.exec(value);
|
|
355
|
+
return one ? { kind: "dynamic", name: one[1] } : { kind: "static", value };
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
var isDynamic = (route) => parse(route).some((s) => s.kind !== "static");
|
|
359
|
+
function routeMatches(route, path) {
|
|
360
|
+
const pattern = parse(route);
|
|
361
|
+
const parts = segmentsOf(path);
|
|
362
|
+
for (const [i, seg] of pattern.entries()) {
|
|
363
|
+
if (seg.kind === "optional-catch-all") return i === pattern.length - 1;
|
|
364
|
+
if (seg.kind === "catch-all") return i === pattern.length - 1 && parts.length > i;
|
|
365
|
+
if (i >= parts.length || seg.kind === "static" && seg.value !== parts[i]) return false;
|
|
366
|
+
}
|
|
367
|
+
return parts.length === pattern.length;
|
|
368
|
+
}
|
|
369
|
+
var RANK = { static: 0, dynamic: 1, "catch-all": 2, "optional-catch-all": 3 };
|
|
370
|
+
function compareSpecificity(a, b) {
|
|
371
|
+
const [pa, pb] = [parse(a), parse(b)];
|
|
372
|
+
for (let i = 0; i < Math.min(pa.length, pb.length); i++) {
|
|
373
|
+
const d = RANK[pa[i].kind] - RANK[pb[i].kind];
|
|
374
|
+
if (d !== 0) return d;
|
|
375
|
+
}
|
|
376
|
+
return pa.length - pb.length;
|
|
377
|
+
}
|
|
378
|
+
function withLocale(path, locale) {
|
|
379
|
+
if (!locale) return [path];
|
|
380
|
+
const prefixed = (l) => path === "/" ? `/${l}` : `/${l}${path}`;
|
|
381
|
+
if (locale.prefix === "never") return [path];
|
|
382
|
+
return locale.locales.map((l) => locale.prefix === "as-needed" && l === locale.defaultLocale ? path : prefixed(l));
|
|
383
|
+
}
|
|
384
|
+
function expandLocale(route, locale) {
|
|
385
|
+
const [first, ...rest] = segmentsOf(route);
|
|
386
|
+
if (!locale || first !== `[${LOCALE_PARAM}]`) return [route];
|
|
387
|
+
return [...new Set(withLocale(`/${rest.join("/")}`, locale))];
|
|
388
|
+
}
|
|
389
|
+
var MAX_EXAMPLES = 5;
|
|
390
|
+
function checkRoutes(input) {
|
|
391
|
+
const { locale } = input;
|
|
392
|
+
const hyleParam = input.hyleParam ?? "hyle";
|
|
393
|
+
const routes = [...new Set(input.hostRoutes.flatMap((r) => expandLocale(r, locale)))];
|
|
394
|
+
const staticRoutes = new Set(routes.filter((r) => !isDynamic(r)));
|
|
395
|
+
const dynamicRoutes = routes.filter(isDynamic);
|
|
396
|
+
const catchAlls = dynamicRoutes.filter((r) => {
|
|
397
|
+
const last = parse(r).at(-1);
|
|
398
|
+
return (last?.kind === "catch-all" || last?.kind === "optional-catch-all") && last.name === hyleParam;
|
|
399
|
+
});
|
|
400
|
+
const notes = [];
|
|
401
|
+
const shadowedHylePaths = input.hylePaths.flatMap(
|
|
402
|
+
(path) => withLocale(path, locale).filter((url) => staticRoutes.has(url)).map((url) => ({ path, url, route: url }))
|
|
403
|
+
);
|
|
404
|
+
const mountCollisions = [];
|
|
405
|
+
for (const prefix of input.mounts) {
|
|
406
|
+
if (prefix === "/") {
|
|
407
|
+
if (staticRoutes.has("/")) notes.push(`root mount: the host's own home page owns "/", so hyle's index page is not served there (pages below it are)`);
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
for (const url of withLocale(prefix, locale)) if (staticRoutes.has(url)) mountCollisions.push({ prefix, url, route: url });
|
|
411
|
+
}
|
|
412
|
+
const urls = [...new Set([...input.hylePaths, ...input.mounts.filter((m) => m !== "/")].flatMap((p) => withLocale(p, locale)))];
|
|
413
|
+
const dynamicOverlaps = [];
|
|
414
|
+
for (const route of dynamicRoutes) {
|
|
415
|
+
const matched = urls.filter((u) => routeMatches(route, u));
|
|
416
|
+
if (catchAlls.includes(route)) {
|
|
417
|
+
dynamicOverlaps.push({ route, verdict: "hyle-catch-all", matches: matched.length, examples: matched.slice(0, MAX_EXAMPLES) });
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
const hostWins = matched.filter((u) => {
|
|
421
|
+
const best = catchAlls.filter((c) => routeMatches(c, u)).sort(compareSpecificity)[0];
|
|
422
|
+
return best === void 0 || compareSpecificity(route, best) <= 0;
|
|
423
|
+
});
|
|
424
|
+
if (matched.length === 0) continue;
|
|
425
|
+
const shown = hostWins.length > 0 ? hostWins : matched;
|
|
426
|
+
dynamicOverlaps.push({ route, verdict: hostWins.length > 0 ? "host-wins" : "hyle-wins", matches: shown.length, examples: shown.slice(0, MAX_EXAMPLES) });
|
|
427
|
+
}
|
|
428
|
+
if (catchAlls.length === 0) notes.push(`no hyle catch-all route (a "[...${hyleParam}]" or "[[...${hyleParam}]]" page) was found in the host routes`);
|
|
429
|
+
return { shadowedHylePaths, mountCollisions, dynamicOverlaps, notes, ok: shadowedHylePaths.length === 0 && mountCollisions.length === 0 };
|
|
430
|
+
}
|
|
431
|
+
function reservedFor(hostRoutes, options = {}) {
|
|
432
|
+
const dropLocale = (route) => {
|
|
433
|
+
const [first, ...rest] = segmentsOf(route);
|
|
434
|
+
return options.locale && first === `[${LOCALE_PARAM}]` ? `/${rest.join("/")}` : route;
|
|
435
|
+
};
|
|
436
|
+
const exact = new Set(hostRoutes.map(dropLocale).filter((r) => !isDynamic(r)));
|
|
437
|
+
const mounts = options.mounts?.filter((m) => m !== "/");
|
|
438
|
+
const groups = /* @__PURE__ */ new Map();
|
|
439
|
+
for (const route of exact) {
|
|
440
|
+
const [first, ...rest] = segmentsOf(route);
|
|
441
|
+
if (first !== void 0 && rest.length > 0) groups.set(first, [...groups.get(first) ?? [], route]);
|
|
442
|
+
}
|
|
443
|
+
for (const [first, members] of groups) {
|
|
444
|
+
const onMount = mounts?.some((m) => m === `/${first}` || m.startsWith(`/${first}/`)) ?? true;
|
|
445
|
+
if (members.length < 2 || onMount) continue;
|
|
446
|
+
for (const m of members) exact.delete(m);
|
|
447
|
+
exact.delete(`/${first}`);
|
|
448
|
+
exact.add(`/${first}/*`);
|
|
449
|
+
}
|
|
450
|
+
return [...exact].sort();
|
|
451
|
+
}
|
|
452
|
+
function formatReport(report) {
|
|
453
|
+
const lines = [];
|
|
454
|
+
const section = (title, rows, empty) => lines.push(`${title}`, ...rows.length ? rows.map((r) => ` ${printable(r)}`) : [` ${empty}`], "");
|
|
455
|
+
section(
|
|
456
|
+
"(a) hyle paths shadowed by host static routes (the hyle page is never served):",
|
|
457
|
+
report.shadowedHylePaths.map((s) => `${s.url} (hyle path ${s.path})`),
|
|
458
|
+
"none"
|
|
459
|
+
);
|
|
460
|
+
section("(c) mounts whose prefix is a host static route (the mount's index page is never served):", report.mountCollisions.map((m) => `${m.url} (mount ${m.prefix})`), "none");
|
|
461
|
+
section(
|
|
462
|
+
"(b) host dynamic routes matching hyle URLs:",
|
|
463
|
+
report.dynamicOverlaps.map((d) => {
|
|
464
|
+
const label = { "hyle-catch-all": "OK: this is hyle's catch-all", "hyle-wins": "OK: hyle's catch-all is more specific", "host-wins": "WARN: the host route is served, hyle content is hidden" }[d.verdict];
|
|
465
|
+
return `${d.route} ${label} (${d.matches} URLs, e.g. ${d.examples.join(", ") || "-"})`;
|
|
466
|
+
}),
|
|
467
|
+
"none"
|
|
468
|
+
);
|
|
469
|
+
if (report.notes.length) section("notes:", report.notes, "");
|
|
470
|
+
lines.push(report.ok ? "RESULT: no collisions" : "RESULT: collisions found");
|
|
471
|
+
return lines.join("\n");
|
|
472
|
+
}
|
|
473
|
+
var MAX_PRINTED = 200;
|
|
474
|
+
var printable = (text) => {
|
|
475
|
+
const clean = text.replace(/\u001b(?:\[[0-?]*[ -/]*[@-~]|\][^\u0007\u001b]*(?:\u0007|\u001b\\)?|.)?/g, "").replace(/[\u0000-\u001f\u007f-\u009f]/g, "");
|
|
476
|
+
return clean.length > MAX_PRINTED ? `${clean.slice(0, MAX_PRINTED)}...` : clean;
|
|
477
|
+
};
|
|
313
478
|
// Annotate the CommonJS export names for ESM import in node:
|
|
314
479
|
0 && (module.exports = {
|
|
315
480
|
CACHE_TAG_PATTERN,
|
|
316
481
|
Cp1ClientError,
|
|
317
482
|
DeliveryDedupe,
|
|
483
|
+
checkRoutes,
|
|
318
484
|
createHyleClient,
|
|
319
485
|
createRevalidationCallbackRoute,
|
|
486
|
+
formatReport,
|
|
487
|
+
hostRoutesFromManifests,
|
|
320
488
|
isValidCacheTag,
|
|
321
489
|
listPublicationPaths,
|
|
490
|
+
normalizeRoute,
|
|
322
491
|
parseSignatureHeader,
|
|
492
|
+
reservedFor,
|
|
493
|
+
routeMatches,
|
|
323
494
|
verifyHyleSignature
|
|
324
495
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as Resolved } from './types-
|
|
2
|
-
export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, F as Fallback, L as ListItem, N as NavItem,
|
|
1
|
+
import { R as Resolved, M as MountsResult } from './types-CwBCPh6K.cjs';
|
|
2
|
+
export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, F as Fallback, L as ListItem, b as Mount, c as Mounts, N as NavItem, d as ResolvedArticle, e as ResolvedDisabled, f as ResolvedList, g as ResolvedNotFound, h as ResolvedRedirect, T as TocEntry } from './types-CwBCPh6K.cjs';
|
|
3
3
|
export { R as RevalidationCallbackOptions, a as RevalidationCallbackRoute, b as RevalidationPayload, c as createRevalidationCallbackRoute } from './revalidation-callback-D7Ms_Puz.cjs';
|
|
4
4
|
|
|
5
5
|
/** `next` is a Next.js fetch extension with no lib.dom type; typed structurally so this module needs no Next import. */
|
|
@@ -33,8 +33,13 @@ interface ResolveOptions {
|
|
|
33
33
|
/** Extra fetch options (for example Next's `next: { tags, revalidate }`). Method, body and the auth header cannot be overridden. */
|
|
34
34
|
readonly init?: HyleRequestInit;
|
|
35
35
|
}
|
|
36
|
+
interface MountsOptions {
|
|
37
|
+
/** Extra fetch options (for example Next's `next: { tags, revalidate }`). Method, body and the auth header cannot be overridden. */
|
|
38
|
+
readonly init?: HyleRequestInit;
|
|
39
|
+
}
|
|
36
40
|
declare function createHyleClient(options: HyleClientOptions): {
|
|
37
41
|
resolve: (opts: ResolveOptions) => Promise<Resolved>;
|
|
42
|
+
mounts: (opts?: MountsOptions) => Promise<MountsResult>;
|
|
38
43
|
};
|
|
39
44
|
type HyleClient = ReturnType<typeof createHyleClient>;
|
|
40
45
|
|
|
@@ -128,4 +133,91 @@ interface ListPublicationPathsOptions {
|
|
|
128
133
|
*/
|
|
129
134
|
declare function listPublicationPaths(options: ListPublicationPathsOptions): Promise<PublicationPaths>;
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Route-collision analysis between a Next host app and the paths hyle serves. Pure: the CLI (`hyle-sdk-check-routes`) reads
|
|
138
|
+
* `.next` and calls hyle, then hands plain data to these functions. A host route always wins over `hyleRootPage` (Next matches
|
|
139
|
+
* specific routes first), so a collision never breaks the host: it silently hides hyle content.
|
|
140
|
+
*/
|
|
141
|
+
type LocalePrefix = "as-needed" | "always" | "never";
|
|
142
|
+
interface LocaleOptions {
|
|
143
|
+
readonly locales: readonly string[];
|
|
144
|
+
readonly defaultLocale: string;
|
|
145
|
+
/** next-intl's `localePrefix`: "as-needed" leaves the default locale unprefixed. */
|
|
146
|
+
readonly prefix: LocalePrefix;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A host route key as a URL pattern: "/(site)/[locale]/about/page" -> "/[locale]/about". Handles `.next/server/app-paths-manifest.json`
|
|
150
|
+
* keys (trailing "/page" or "/route") and routes-manifest pages. Route groups "(x)" are removed. Returns undefined for what is not a
|
|
151
|
+
* URL a visitor can request: parallel-route slots "@x", intercepting routes "(.)x", and Next's internal pages.
|
|
152
|
+
*/
|
|
153
|
+
declare function normalizeRoute(key: string): string | undefined;
|
|
154
|
+
interface NextManifests {
|
|
155
|
+
readonly routesManifest?: {
|
|
156
|
+
readonly staticRoutes?: readonly {
|
|
157
|
+
readonly page: string;
|
|
158
|
+
}[];
|
|
159
|
+
readonly dynamicRoutes?: readonly {
|
|
160
|
+
readonly page: string;
|
|
161
|
+
}[];
|
|
162
|
+
};
|
|
163
|
+
readonly appPaths?: Readonly<Record<string, string>>;
|
|
164
|
+
}
|
|
165
|
+
/** Every host route pattern from `routes-manifest.json` and `server/app-paths-manifest.json`, normalized, de-duplicated and sorted. */
|
|
166
|
+
declare function hostRoutesFromManifests({ routesManifest, appPaths }: NextManifests): string[];
|
|
167
|
+
/** Does the route pattern match the URL path? `[x]` is one segment, `[...x]` one or more, `[[...x]]` zero or more. */
|
|
168
|
+
declare function routeMatches(route: string, path: string): boolean;
|
|
169
|
+
interface RouteCheckInput {
|
|
170
|
+
/** From `hostRoutesFromManifests`. */
|
|
171
|
+
readonly hostRoutes: readonly string[];
|
|
172
|
+
/** The mount prefixes hyle reports: "/" for a root mount. */
|
|
173
|
+
readonly mounts: readonly string[];
|
|
174
|
+
/** Every published page path (`listPublicationPaths`), in hyle's path space (no host locale prefix). */
|
|
175
|
+
readonly hylePaths: readonly string[];
|
|
176
|
+
readonly locale?: LocaleOptions;
|
|
177
|
+
/** The param name of the host's hyle catch-all (`[...hyle]`). Default "hyle". */
|
|
178
|
+
readonly hyleParam?: string;
|
|
179
|
+
}
|
|
180
|
+
interface DynamicOverlap {
|
|
181
|
+
readonly route: string;
|
|
182
|
+
/**
|
|
183
|
+
* "hyle-catch-all": the route is hyle's own catch-all, fine. "hyle-wins": it matches hyle URLs but hyle's catch-all is more specific, fine.
|
|
184
|
+
* "host-wins": Next serves this route for URLs hyle publishes, so that hyle content is never shown.
|
|
185
|
+
*/
|
|
186
|
+
readonly verdict: "hyle-catch-all" | "hyle-wins" | "host-wins";
|
|
187
|
+
readonly matches: number;
|
|
188
|
+
readonly examples: readonly string[];
|
|
189
|
+
}
|
|
190
|
+
interface RouteCheckReport {
|
|
191
|
+
/** (a) A published hyle page at a URL a static host route owns: never served. */
|
|
192
|
+
readonly shadowedHylePaths: readonly {
|
|
193
|
+
readonly path: string;
|
|
194
|
+
readonly url: string;
|
|
195
|
+
readonly route: string;
|
|
196
|
+
}[];
|
|
197
|
+
/** (c) A mount prefix that is itself a static host route: the mount's index page is never served. */
|
|
198
|
+
readonly mountCollisions: readonly {
|
|
199
|
+
readonly prefix: string;
|
|
200
|
+
readonly url: string;
|
|
201
|
+
readonly route: string;
|
|
202
|
+
}[];
|
|
203
|
+
/** (b) Host dynamic routes matching hyle URLs, grouped by route. */
|
|
204
|
+
readonly dynamicOverlaps: readonly DynamicOverlap[];
|
|
205
|
+
readonly notes: readonly string[];
|
|
206
|
+
/** False when (a) or (c) found something. */
|
|
207
|
+
readonly ok: boolean;
|
|
208
|
+
}
|
|
209
|
+
declare function checkRoutes(input: RouteCheckInput): RouteCheckReport;
|
|
210
|
+
/**
|
|
211
|
+
* The host's static routes in hyle's Reserved paths format: exact paths, and "/x/*" for a segment with two or more routes under it
|
|
212
|
+
* (route groups such as "/api/*"). A segment is NOT collapsed when a non-root mount prefix lies on it, so "/learn/about" stays exact
|
|
213
|
+
* while a mount serves "/learn/notes". Without `mounts` (hyle unreachable) nothing is collapsed. The leading locale segment is dropped
|
|
214
|
+
* because hyle's paths carry no host locale prefix.
|
|
215
|
+
*/
|
|
216
|
+
declare function reservedFor(hostRoutes: readonly string[], options?: {
|
|
217
|
+
readonly locale?: LocaleOptions;
|
|
218
|
+
readonly mounts?: readonly string[];
|
|
219
|
+
}): string[];
|
|
220
|
+
/** The human report. */
|
|
221
|
+
declare function formatReport(report: RouteCheckReport): string;
|
|
222
|
+
|
|
223
|
+
export { CACHE_TAG_PATTERN, Cp1ClientError, DeliveryDedupe, type DynamicOverlap, type HyleClient, type HyleClientOptions, type HyleRequestInit, type ListPublicationPathsOptions, type LocaleOptions, type LocalePrefix, type MountsOptions, MountsResult, type NextManifests, type ParsedSignatureHeader, type PublicationPath, type PublicationPaths, type ResolveOptions, Resolved, type RouteCheckInput, type RouteCheckReport, type VerifySignatureParams, checkRoutes, createHyleClient, formatReport, hostRoutesFromManifests, isValidCacheTag, listPublicationPaths, normalizeRoute, parseSignatureHeader, reservedFor, routeMatches, verifyHyleSignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { R as Resolved } from './types-
|
|
2
|
-
export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, F as Fallback, L as ListItem, N as NavItem,
|
|
1
|
+
import { R as Resolved, M as MountsResult } from './types-CwBCPh6K.js';
|
|
2
|
+
export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, F as Fallback, L as ListItem, b as Mount, c as Mounts, N as NavItem, d as ResolvedArticle, e as ResolvedDisabled, f as ResolvedList, g as ResolvedNotFound, h as ResolvedRedirect, T as TocEntry } from './types-CwBCPh6K.js';
|
|
3
3
|
export { R as RevalidationCallbackOptions, a as RevalidationCallbackRoute, b as RevalidationPayload, c as createRevalidationCallbackRoute } from './revalidation-callback-D7Ms_Puz.js';
|
|
4
4
|
|
|
5
5
|
/** `next` is a Next.js fetch extension with no lib.dom type; typed structurally so this module needs no Next import. */
|
|
@@ -33,8 +33,13 @@ interface ResolveOptions {
|
|
|
33
33
|
/** Extra fetch options (for example Next's `next: { tags, revalidate }`). Method, body and the auth header cannot be overridden. */
|
|
34
34
|
readonly init?: HyleRequestInit;
|
|
35
35
|
}
|
|
36
|
+
interface MountsOptions {
|
|
37
|
+
/** Extra fetch options (for example Next's `next: { tags, revalidate }`). Method, body and the auth header cannot be overridden. */
|
|
38
|
+
readonly init?: HyleRequestInit;
|
|
39
|
+
}
|
|
36
40
|
declare function createHyleClient(options: HyleClientOptions): {
|
|
37
41
|
resolve: (opts: ResolveOptions) => Promise<Resolved>;
|
|
42
|
+
mounts: (opts?: MountsOptions) => Promise<MountsResult>;
|
|
38
43
|
};
|
|
39
44
|
type HyleClient = ReturnType<typeof createHyleClient>;
|
|
40
45
|
|
|
@@ -128,4 +133,91 @@ interface ListPublicationPathsOptions {
|
|
|
128
133
|
*/
|
|
129
134
|
declare function listPublicationPaths(options: ListPublicationPathsOptions): Promise<PublicationPaths>;
|
|
130
135
|
|
|
131
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Route-collision analysis between a Next host app and the paths hyle serves. Pure: the CLI (`hyle-sdk-check-routes`) reads
|
|
138
|
+
* `.next` and calls hyle, then hands plain data to these functions. A host route always wins over `hyleRootPage` (Next matches
|
|
139
|
+
* specific routes first), so a collision never breaks the host: it silently hides hyle content.
|
|
140
|
+
*/
|
|
141
|
+
type LocalePrefix = "as-needed" | "always" | "never";
|
|
142
|
+
interface LocaleOptions {
|
|
143
|
+
readonly locales: readonly string[];
|
|
144
|
+
readonly defaultLocale: string;
|
|
145
|
+
/** next-intl's `localePrefix`: "as-needed" leaves the default locale unprefixed. */
|
|
146
|
+
readonly prefix: LocalePrefix;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* A host route key as a URL pattern: "/(site)/[locale]/about/page" -> "/[locale]/about". Handles `.next/server/app-paths-manifest.json`
|
|
150
|
+
* keys (trailing "/page" or "/route") and routes-manifest pages. Route groups "(x)" are removed. Returns undefined for what is not a
|
|
151
|
+
* URL a visitor can request: parallel-route slots "@x", intercepting routes "(.)x", and Next's internal pages.
|
|
152
|
+
*/
|
|
153
|
+
declare function normalizeRoute(key: string): string | undefined;
|
|
154
|
+
interface NextManifests {
|
|
155
|
+
readonly routesManifest?: {
|
|
156
|
+
readonly staticRoutes?: readonly {
|
|
157
|
+
readonly page: string;
|
|
158
|
+
}[];
|
|
159
|
+
readonly dynamicRoutes?: readonly {
|
|
160
|
+
readonly page: string;
|
|
161
|
+
}[];
|
|
162
|
+
};
|
|
163
|
+
readonly appPaths?: Readonly<Record<string, string>>;
|
|
164
|
+
}
|
|
165
|
+
/** Every host route pattern from `routes-manifest.json` and `server/app-paths-manifest.json`, normalized, de-duplicated and sorted. */
|
|
166
|
+
declare function hostRoutesFromManifests({ routesManifest, appPaths }: NextManifests): string[];
|
|
167
|
+
/** Does the route pattern match the URL path? `[x]` is one segment, `[...x]` one or more, `[[...x]]` zero or more. */
|
|
168
|
+
declare function routeMatches(route: string, path: string): boolean;
|
|
169
|
+
interface RouteCheckInput {
|
|
170
|
+
/** From `hostRoutesFromManifests`. */
|
|
171
|
+
readonly hostRoutes: readonly string[];
|
|
172
|
+
/** The mount prefixes hyle reports: "/" for a root mount. */
|
|
173
|
+
readonly mounts: readonly string[];
|
|
174
|
+
/** Every published page path (`listPublicationPaths`), in hyle's path space (no host locale prefix). */
|
|
175
|
+
readonly hylePaths: readonly string[];
|
|
176
|
+
readonly locale?: LocaleOptions;
|
|
177
|
+
/** The param name of the host's hyle catch-all (`[...hyle]`). Default "hyle". */
|
|
178
|
+
readonly hyleParam?: string;
|
|
179
|
+
}
|
|
180
|
+
interface DynamicOverlap {
|
|
181
|
+
readonly route: string;
|
|
182
|
+
/**
|
|
183
|
+
* "hyle-catch-all": the route is hyle's own catch-all, fine. "hyle-wins": it matches hyle URLs but hyle's catch-all is more specific, fine.
|
|
184
|
+
* "host-wins": Next serves this route for URLs hyle publishes, so that hyle content is never shown.
|
|
185
|
+
*/
|
|
186
|
+
readonly verdict: "hyle-catch-all" | "hyle-wins" | "host-wins";
|
|
187
|
+
readonly matches: number;
|
|
188
|
+
readonly examples: readonly string[];
|
|
189
|
+
}
|
|
190
|
+
interface RouteCheckReport {
|
|
191
|
+
/** (a) A published hyle page at a URL a static host route owns: never served. */
|
|
192
|
+
readonly shadowedHylePaths: readonly {
|
|
193
|
+
readonly path: string;
|
|
194
|
+
readonly url: string;
|
|
195
|
+
readonly route: string;
|
|
196
|
+
}[];
|
|
197
|
+
/** (c) A mount prefix that is itself a static host route: the mount's index page is never served. */
|
|
198
|
+
readonly mountCollisions: readonly {
|
|
199
|
+
readonly prefix: string;
|
|
200
|
+
readonly url: string;
|
|
201
|
+
readonly route: string;
|
|
202
|
+
}[];
|
|
203
|
+
/** (b) Host dynamic routes matching hyle URLs, grouped by route. */
|
|
204
|
+
readonly dynamicOverlaps: readonly DynamicOverlap[];
|
|
205
|
+
readonly notes: readonly string[];
|
|
206
|
+
/** False when (a) or (c) found something. */
|
|
207
|
+
readonly ok: boolean;
|
|
208
|
+
}
|
|
209
|
+
declare function checkRoutes(input: RouteCheckInput): RouteCheckReport;
|
|
210
|
+
/**
|
|
211
|
+
* The host's static routes in hyle's Reserved paths format: exact paths, and "/x/*" for a segment with two or more routes under it
|
|
212
|
+
* (route groups such as "/api/*"). A segment is NOT collapsed when a non-root mount prefix lies on it, so "/learn/about" stays exact
|
|
213
|
+
* while a mount serves "/learn/notes". Without `mounts` (hyle unreachable) nothing is collapsed. The leading locale segment is dropped
|
|
214
|
+
* because hyle's paths carry no host locale prefix.
|
|
215
|
+
*/
|
|
216
|
+
declare function reservedFor(hostRoutes: readonly string[], options?: {
|
|
217
|
+
readonly locale?: LocaleOptions;
|
|
218
|
+
readonly mounts?: readonly string[];
|
|
219
|
+
}): string[];
|
|
220
|
+
/** The human report. */
|
|
221
|
+
declare function formatReport(report: RouteCheckReport): string;
|
|
222
|
+
|
|
223
|
+
export { CACHE_TAG_PATTERN, Cp1ClientError, DeliveryDedupe, type DynamicOverlap, type HyleClient, type HyleClientOptions, type HyleRequestInit, type ListPublicationPathsOptions, type LocaleOptions, type LocalePrefix, type MountsOptions, MountsResult, type NextManifests, type ParsedSignatureHeader, type PublicationPath, type PublicationPaths, type ResolveOptions, Resolved, type RouteCheckInput, type RouteCheckReport, type VerifySignatureParams, checkRoutes, createHyleClient, formatReport, hostRoutesFromManifests, isValidCacheTag, listPublicationPaths, normalizeRoute, parseSignatureHeader, reservedFor, routeMatches, verifyHyleSignature };
|
package/dist/index.js
CHANGED
|
@@ -2,21 +2,33 @@ import {
|
|
|
2
2
|
CACHE_TAG_PATTERN,
|
|
3
3
|
Cp1ClientError,
|
|
4
4
|
DeliveryDedupe,
|
|
5
|
+
checkRoutes,
|
|
5
6
|
createHyleClient,
|
|
6
7
|
createRevalidationCallbackRoute,
|
|
8
|
+
formatReport,
|
|
9
|
+
hostRoutesFromManifests,
|
|
7
10
|
isValidCacheTag,
|
|
8
11
|
listPublicationPaths,
|
|
12
|
+
normalizeRoute,
|
|
9
13
|
parseSignatureHeader,
|
|
14
|
+
reservedFor,
|
|
15
|
+
routeMatches,
|
|
10
16
|
verifyHyleSignature
|
|
11
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-4OB77ZOD.js";
|
|
12
18
|
export {
|
|
13
19
|
CACHE_TAG_PATTERN,
|
|
14
20
|
Cp1ClientError,
|
|
15
21
|
DeliveryDedupe,
|
|
22
|
+
checkRoutes,
|
|
16
23
|
createHyleClient,
|
|
17
24
|
createRevalidationCallbackRoute,
|
|
25
|
+
formatReport,
|
|
26
|
+
hostRoutesFromManifests,
|
|
18
27
|
isValidCacheTag,
|
|
19
28
|
listPublicationPaths,
|
|
29
|
+
normalizeRoute,
|
|
20
30
|
parseSignatureHeader,
|
|
31
|
+
reservedFor,
|
|
32
|
+
routeMatches,
|
|
21
33
|
verifyHyleSignature
|
|
22
34
|
};
|