@tdacorp/hyle-sdk 0.3.0 → 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 +92 -3
- 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-EARQBSMF.js → chunk-SO6H2UGL.js} +102 -4
- 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 +1267 -16
- package/dist/mermaid-diagram.d.cts +39 -1
- package/dist/mermaid-diagram.d.ts +39 -1
- package/dist/mermaid-diagram.js +35 -5
- package/dist/next.cjs +266 -26
- package/dist/next.d.cts +51 -5
- package/dist/next.d.ts +51 -5
- package/dist/next.js +131 -5
- package/dist/react.cjs +102 -4
- package/dist/react.d.cts +44 -4
- package/dist/react.d.ts +44 -4
- package/dist/react.js +1 -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 +76 -0
- package/dist/{types-CBvLhUPr.d.ts → types-BoyBWF2F.d.ts} +1 -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-D0qoLh4E.d.cts → types-DnPzhrFx.d.cts} +1 -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 +5 -1
- package/dist/chunk-HFUJRNFP.js +0 -290
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
var Cp1ClientError = class extends Error {
|
|
3
|
+
code;
|
|
4
|
+
status;
|
|
5
|
+
requestId;
|
|
6
|
+
details;
|
|
7
|
+
constructor(code, message, status, requestId, details) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.name = "Cp1ClientError";
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.requestId = requestId;
|
|
13
|
+
this.details = details;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// src/client.ts
|
|
18
|
+
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
19
|
+
var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
20
|
+
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
21
|
+
async function readCapped(res, max) {
|
|
22
|
+
const tooLarge = () => new Cp1ClientError("RESPONSE_TOO_LARGE", `hyle response exceeds ${max} bytes`, res.status, "");
|
|
23
|
+
if (Number(res.headers.get("content-length")) > max) throw tooLarge();
|
|
24
|
+
if (!res.body) return "";
|
|
25
|
+
const reader = res.body.getReader();
|
|
26
|
+
const chunks = [];
|
|
27
|
+
let total = 0;
|
|
28
|
+
for (; ; ) {
|
|
29
|
+
const { done, value } = await reader.read();
|
|
30
|
+
if (done) break;
|
|
31
|
+
total += value.byteLength;
|
|
32
|
+
if (total > max) {
|
|
33
|
+
await reader.cancel();
|
|
34
|
+
throw tooLarge();
|
|
35
|
+
}
|
|
36
|
+
chunks.push(value);
|
|
37
|
+
}
|
|
38
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
39
|
+
}
|
|
40
|
+
var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound", "disabled"]);
|
|
41
|
+
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
42
|
+
function isMounts(data) {
|
|
43
|
+
const mounts = data.mounts;
|
|
44
|
+
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");
|
|
45
|
+
}
|
|
46
|
+
function createHyleClient(options) {
|
|
47
|
+
let origin;
|
|
48
|
+
try {
|
|
49
|
+
origin = new URL(options.baseUrl);
|
|
50
|
+
} catch {
|
|
51
|
+
throw new TypeError("baseUrl must be an https origin");
|
|
52
|
+
}
|
|
53
|
+
if (origin.protocol !== "https:" && !(origin.protocol === "http:" && (options.allowInsecureHttp || LOOPBACK.has(origin.hostname)))) {
|
|
54
|
+
throw new TypeError("baseUrl must be https (http is allowed only for localhost, or with allowInsecureHttp)");
|
|
55
|
+
}
|
|
56
|
+
if (!options.token) throw new TypeError("token is required");
|
|
57
|
+
const base = options.baseUrl.replace(/\/+$/, "");
|
|
58
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
59
|
+
async function get(pathname, query, init) {
|
|
60
|
+
const url = new URL(`${base}${pathname}`);
|
|
61
|
+
url.search = query.toString();
|
|
62
|
+
const headers = new Headers(init?.headers);
|
|
63
|
+
headers.set("authorization", `Bearer ${options.token}`);
|
|
64
|
+
const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
65
|
+
const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
|
|
66
|
+
const res = await fetchImpl(url.toString(), { ...init, method: "GET", headers, redirect: "error", signal });
|
|
67
|
+
const text = await readCapped(res, options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES);
|
|
68
|
+
let parsed;
|
|
69
|
+
try {
|
|
70
|
+
parsed = JSON.parse(text);
|
|
71
|
+
} catch {
|
|
72
|
+
parsed = void 0;
|
|
73
|
+
}
|
|
74
|
+
return { parsed, status: res.status };
|
|
75
|
+
}
|
|
76
|
+
const failure = ({ parsed, status }) => {
|
|
77
|
+
const err = parsed?.error;
|
|
78
|
+
return new Cp1ClientError(err?.code ?? "INVALID_RESPONSE", err?.message ?? `Unexpected response from hyle (HTTP ${status})`, status, err?.request_id ?? "", err?.details);
|
|
79
|
+
};
|
|
80
|
+
async function resolve(opts) {
|
|
81
|
+
const query = new URLSearchParams({ path: opts.path });
|
|
82
|
+
if (opts.locale !== void 0) query.set("locale", opts.locale);
|
|
83
|
+
if (opts.format !== void 0) query.set("format", opts.format);
|
|
84
|
+
if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
|
|
85
|
+
if (opts.limit !== void 0) query.set("limit", String(opts.limit));
|
|
86
|
+
const reply = await get("/cp1/read/resolve", query, opts.init);
|
|
87
|
+
const data = reply.parsed?.data;
|
|
88
|
+
if (data && data.cp === 1 && typeof data.kind === "string" && KINDS.has(data.kind)) return data;
|
|
89
|
+
throw failure(reply);
|
|
90
|
+
}
|
|
91
|
+
async function mounts(opts = {}) {
|
|
92
|
+
const reply = await get("/cp1/read/mounts", new URLSearchParams(), opts.init);
|
|
93
|
+
const data = reply.parsed?.data;
|
|
94
|
+
if (data?.cp === 1 && data.kind === "disabled") return data;
|
|
95
|
+
if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
|
|
96
|
+
throw failure(reply);
|
|
97
|
+
}
|
|
98
|
+
return { resolve, mounts };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/delivery-dedupe.ts
|
|
102
|
+
var DeliveryDedupe = class {
|
|
103
|
+
constructor(capacity = 1e3) {
|
|
104
|
+
this.capacity = capacity;
|
|
105
|
+
}
|
|
106
|
+
capacity;
|
|
107
|
+
seen = /* @__PURE__ */ new Map();
|
|
108
|
+
/** True if this id was already recorded (a duplicate delivery). */
|
|
109
|
+
has(deliveryId) {
|
|
110
|
+
return this.seen.has(deliveryId);
|
|
111
|
+
}
|
|
112
|
+
add(deliveryId) {
|
|
113
|
+
this.seen.delete(deliveryId);
|
|
114
|
+
this.seen.set(deliveryId, true);
|
|
115
|
+
if (this.seen.size > this.capacity) {
|
|
116
|
+
const oldest = this.seen.keys().next().value;
|
|
117
|
+
if (oldest !== void 0) this.seen.delete(oldest);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/signature.ts
|
|
123
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
124
|
+
var SIGNATURE_HEX = /^[0-9a-f]{64}$/;
|
|
125
|
+
function parseSignatureHeader(header) {
|
|
126
|
+
let timestamp;
|
|
127
|
+
const signatures = [];
|
|
128
|
+
for (const part of header.split(",")) {
|
|
129
|
+
const [key, value] = part.split("=", 2);
|
|
130
|
+
if (key === "t" && value) {
|
|
131
|
+
const parsed = Number(value);
|
|
132
|
+
if (Number.isFinite(parsed)) timestamp = parsed;
|
|
133
|
+
} else if (key === "v1" && value && SIGNATURE_HEX.test(value)) {
|
|
134
|
+
signatures.push(value);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (timestamp === void 0 || signatures.length === 0) return void 0;
|
|
138
|
+
return { timestamp, signatures };
|
|
139
|
+
}
|
|
140
|
+
function computeSignature(secret, timestamp, rawBody) {
|
|
141
|
+
return createHmac("sha256", secret).update(`${timestamp}.${rawBody}`).digest("hex");
|
|
142
|
+
}
|
|
143
|
+
function signaturesEqual(a, b) {
|
|
144
|
+
const bufA = Buffer.from(a, "hex");
|
|
145
|
+
const bufB = Buffer.from(b, "hex");
|
|
146
|
+
if (bufA.length !== bufB.length) return false;
|
|
147
|
+
return timingSafeEqual(bufA, bufB);
|
|
148
|
+
}
|
|
149
|
+
function verifyHyleSignature(params) {
|
|
150
|
+
const secrets = params.secrets.filter((s) => s !== "");
|
|
151
|
+
if (!params.header || secrets.length === 0) return false;
|
|
152
|
+
const parsed = parseSignatureHeader(params.header);
|
|
153
|
+
if (!parsed) return false;
|
|
154
|
+
const tolerance = params.toleranceSeconds ?? 300;
|
|
155
|
+
const now = (params.now ?? Date.now)() / 1e3;
|
|
156
|
+
if (Math.abs(now - parsed.timestamp) > tolerance) return false;
|
|
157
|
+
for (const secret of secrets) {
|
|
158
|
+
const expected = computeSignature(secret, parsed.timestamp, params.rawBody);
|
|
159
|
+
for (const candidate of parsed.signatures) {
|
|
160
|
+
if (signaturesEqual(candidate, expected)) return true;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/tag-validation.ts
|
|
167
|
+
var CACHE_TAG_PATTERN = /^hyle:1:(pub|doc|sec|link|ws):[0-9a-f-]{36}(:[\x21-\x7e]{1,200})?$/;
|
|
168
|
+
function isValidCacheTag(tag) {
|
|
169
|
+
return CACHE_TAG_PATTERN.test(tag);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/revalidation-callback.ts
|
|
173
|
+
var MAX_BODY_BYTES = 65536;
|
|
174
|
+
var MAX_TAGS = 1e3;
|
|
175
|
+
function createRevalidationCallbackRoute(options) {
|
|
176
|
+
const dedupe = new DeliveryDedupe(options.dedupeCapacity);
|
|
177
|
+
return {
|
|
178
|
+
async POST(req) {
|
|
179
|
+
const rawBody = await readCapped2(req);
|
|
180
|
+
if (rawBody === void 0) return new Response(null, { status: 413 });
|
|
181
|
+
const verified = verifyHyleSignature({
|
|
182
|
+
header: req.headers.get("hyle-signature"),
|
|
183
|
+
rawBody,
|
|
184
|
+
secrets: options.secrets,
|
|
185
|
+
...options.toleranceSeconds !== void 0 ? { toleranceSeconds: options.toleranceSeconds } : {},
|
|
186
|
+
...options.now !== void 0 ? { now: options.now } : {}
|
|
187
|
+
});
|
|
188
|
+
if (!verified) {
|
|
189
|
+
return new Response(null, { status: 401 });
|
|
190
|
+
}
|
|
191
|
+
let payload;
|
|
192
|
+
try {
|
|
193
|
+
payload = JSON.parse(rawBody);
|
|
194
|
+
} catch {
|
|
195
|
+
return new Response(null, { status: 400 });
|
|
196
|
+
}
|
|
197
|
+
if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return new Response(null, { status: 400 });
|
|
198
|
+
const body = payload;
|
|
199
|
+
if (body.cp !== 1) {
|
|
200
|
+
return okResponse(0);
|
|
201
|
+
}
|
|
202
|
+
const tags = body.tags ?? [];
|
|
203
|
+
if (typeof body.workspace_id !== "string" || !Array.isArray(tags) || tags.length > MAX_TAGS || !tags.every((t) => typeof t === "string")) {
|
|
204
|
+
return new Response(null, { status: 400 });
|
|
205
|
+
}
|
|
206
|
+
if (body.workspace_id !== options.workspaceId) {
|
|
207
|
+
return okResponse(0);
|
|
208
|
+
}
|
|
209
|
+
const deliveryId = req.headers.get("hyle-delivery-id");
|
|
210
|
+
if (deliveryId && dedupe.has(deliveryId)) {
|
|
211
|
+
return okResponse(0);
|
|
212
|
+
}
|
|
213
|
+
let purged = 0;
|
|
214
|
+
try {
|
|
215
|
+
for (const tag of tags) {
|
|
216
|
+
if (!isValidCacheTag(tag)) continue;
|
|
217
|
+
options.revalidateTag(tag);
|
|
218
|
+
purged += 1;
|
|
219
|
+
}
|
|
220
|
+
} catch {
|
|
221
|
+
return new Response(null, { status: 500 });
|
|
222
|
+
}
|
|
223
|
+
if (deliveryId) dedupe.add(deliveryId);
|
|
224
|
+
return okResponse(purged);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
async function readCapped2(req) {
|
|
229
|
+
const declared = Number(req.headers.get("content-length"));
|
|
230
|
+
if (Number.isFinite(declared) && declared > MAX_BODY_BYTES) return void 0;
|
|
231
|
+
if (!req.body) return "";
|
|
232
|
+
const reader = req.body.getReader();
|
|
233
|
+
const chunks = [];
|
|
234
|
+
let total = 0;
|
|
235
|
+
for (; ; ) {
|
|
236
|
+
const { done, value } = await reader.read();
|
|
237
|
+
if (done) break;
|
|
238
|
+
total += value.byteLength;
|
|
239
|
+
if (total > MAX_BODY_BYTES) {
|
|
240
|
+
await reader.cancel();
|
|
241
|
+
return void 0;
|
|
242
|
+
}
|
|
243
|
+
chunks.push(value);
|
|
244
|
+
}
|
|
245
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
246
|
+
}
|
|
247
|
+
function okResponse(purged) {
|
|
248
|
+
return new Response(JSON.stringify({ ok: true, purged }), {
|
|
249
|
+
status: 200,
|
|
250
|
+
headers: { "Content-Type": "application/json; charset=utf-8", "Cache-Control": "no-store" }
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/sitemap.ts
|
|
255
|
+
var PAGE_LIMIT = 100;
|
|
256
|
+
var DEFAULT_MAX_PAGES = 20;
|
|
257
|
+
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
258
|
+
var UNSAFE_PATH = /[\\?#<>&"'\u0000- \u007f]/;
|
|
259
|
+
async function listPublicationPaths(options) {
|
|
260
|
+
const maxPages = options.maxPages ?? DEFAULT_MAX_PAGES;
|
|
261
|
+
const prefix = `${options.basePath}/`;
|
|
262
|
+
const indexes = [options.basePath || "/"];
|
|
263
|
+
for (const slug of options.sections ?? []) if (slug !== "posts" && SECTION_SLUG.test(slug)) indexes.push(`${options.basePath}/${slug}`);
|
|
264
|
+
const found = /* @__PURE__ */ new Map();
|
|
265
|
+
let complete = true;
|
|
266
|
+
try {
|
|
267
|
+
for (const index of new Set(indexes)) {
|
|
268
|
+
let cursor;
|
|
269
|
+
for (let page = 0; page < maxPages; page++) {
|
|
270
|
+
const result = await options.client.resolve({
|
|
271
|
+
path: index,
|
|
272
|
+
limit: PAGE_LIMIT,
|
|
273
|
+
...options.locale !== void 0 ? { locale: options.locale } : {},
|
|
274
|
+
...cursor !== void 0 ? { cursor } : {}
|
|
275
|
+
});
|
|
276
|
+
if (result.kind !== "list") {
|
|
277
|
+
complete = false;
|
|
278
|
+
break;
|
|
279
|
+
}
|
|
280
|
+
for (const item of result.items) {
|
|
281
|
+
if (item.canonical_path.startsWith(prefix) && !UNSAFE_PATH.test(item.canonical_path)) found.set(item.canonical_path, item.published_at);
|
|
282
|
+
}
|
|
283
|
+
if (!result.next_cursor) break;
|
|
284
|
+
if (page === maxPages - 1) complete = false;
|
|
285
|
+
cursor = result.next_cursor;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} catch {
|
|
289
|
+
complete = false;
|
|
290
|
+
}
|
|
291
|
+
return { paths: [...found].map(([path, publishedAt]) => ({ path, publishedAt })), complete };
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/route-check.ts
|
|
295
|
+
var NOT_ROUTES = /* @__PURE__ */ new Set(["/_not-found", "/_global-error", "/_app", "/_error", "/_document", "/404", "/500"]);
|
|
296
|
+
var LOCALE_PARAM = "locale";
|
|
297
|
+
function normalizeRoute(key) {
|
|
298
|
+
const segments = key.replace(/\/(page|route)$/, "").split("/").filter((s) => s !== "");
|
|
299
|
+
if (segments.some((s) => s.startsWith("@") || /^\(\.{1,3}\)/.test(s))) return void 0;
|
|
300
|
+
const route = `/${segments.filter((s) => !/^\(.*\)$/.test(s)).join("/")}`;
|
|
301
|
+
return NOT_ROUTES.has(route) ? void 0 : route;
|
|
302
|
+
}
|
|
303
|
+
function hostRoutesFromManifests({ routesManifest, appPaths }) {
|
|
304
|
+
const keys = [...(routesManifest?.staticRoutes ?? []).map((r) => r.page), ...(routesManifest?.dynamicRoutes ?? []).map((r) => r.page), ...Object.keys(appPaths ?? {})];
|
|
305
|
+
return [...new Set(keys.map(normalizeRoute).filter((r) => r !== void 0))].sort();
|
|
306
|
+
}
|
|
307
|
+
var segmentsOf = (path) => path.split("/").filter((s) => s !== "");
|
|
308
|
+
function parse(route) {
|
|
309
|
+
return segmentsOf(route).map((value) => {
|
|
310
|
+
const optional = /^\[\[\.\.\.([^\]]+)\]\]$/.exec(value);
|
|
311
|
+
if (optional) return { kind: "optional-catch-all", name: optional[1] };
|
|
312
|
+
const rest = /^\[\.\.\.([^\]]+)\]$/.exec(value);
|
|
313
|
+
if (rest) return { kind: "catch-all", name: rest[1] };
|
|
314
|
+
const one = /^\[([^\]]+)\]$/.exec(value);
|
|
315
|
+
return one ? { kind: "dynamic", name: one[1] } : { kind: "static", value };
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
var isDynamic = (route) => parse(route).some((s) => s.kind !== "static");
|
|
319
|
+
function routeMatches(route, path) {
|
|
320
|
+
const pattern = parse(route);
|
|
321
|
+
const parts = segmentsOf(path);
|
|
322
|
+
for (const [i, seg] of pattern.entries()) {
|
|
323
|
+
if (seg.kind === "optional-catch-all") return i === pattern.length - 1;
|
|
324
|
+
if (seg.kind === "catch-all") return i === pattern.length - 1 && parts.length > i;
|
|
325
|
+
if (i >= parts.length || seg.kind === "static" && seg.value !== parts[i]) return false;
|
|
326
|
+
}
|
|
327
|
+
return parts.length === pattern.length;
|
|
328
|
+
}
|
|
329
|
+
var RANK = { static: 0, dynamic: 1, "catch-all": 2, "optional-catch-all": 3 };
|
|
330
|
+
function compareSpecificity(a, b) {
|
|
331
|
+
const [pa, pb] = [parse(a), parse(b)];
|
|
332
|
+
for (let i = 0; i < Math.min(pa.length, pb.length); i++) {
|
|
333
|
+
const d = RANK[pa[i].kind] - RANK[pb[i].kind];
|
|
334
|
+
if (d !== 0) return d;
|
|
335
|
+
}
|
|
336
|
+
return pa.length - pb.length;
|
|
337
|
+
}
|
|
338
|
+
function withLocale(path, locale) {
|
|
339
|
+
if (!locale) return [path];
|
|
340
|
+
const prefixed = (l) => path === "/" ? `/${l}` : `/${l}${path}`;
|
|
341
|
+
if (locale.prefix === "never") return [path];
|
|
342
|
+
return locale.locales.map((l) => locale.prefix === "as-needed" && l === locale.defaultLocale ? path : prefixed(l));
|
|
343
|
+
}
|
|
344
|
+
function expandLocale(route, locale) {
|
|
345
|
+
const [first, ...rest] = segmentsOf(route);
|
|
346
|
+
if (!locale || first !== `[${LOCALE_PARAM}]`) return [route];
|
|
347
|
+
return [...new Set(withLocale(`/${rest.join("/")}`, locale))];
|
|
348
|
+
}
|
|
349
|
+
var MAX_EXAMPLES = 5;
|
|
350
|
+
function checkRoutes(input) {
|
|
351
|
+
const { locale } = input;
|
|
352
|
+
const hyleParam = input.hyleParam ?? "hyle";
|
|
353
|
+
const routes = [...new Set(input.hostRoutes.flatMap((r) => expandLocale(r, locale)))];
|
|
354
|
+
const staticRoutes = new Set(routes.filter((r) => !isDynamic(r)));
|
|
355
|
+
const dynamicRoutes = routes.filter(isDynamic);
|
|
356
|
+
const catchAlls = dynamicRoutes.filter((r) => {
|
|
357
|
+
const last = parse(r).at(-1);
|
|
358
|
+
return (last?.kind === "catch-all" || last?.kind === "optional-catch-all") && last.name === hyleParam;
|
|
359
|
+
});
|
|
360
|
+
const notes = [];
|
|
361
|
+
const shadowedHylePaths = input.hylePaths.flatMap(
|
|
362
|
+
(path) => withLocale(path, locale).filter((url) => staticRoutes.has(url)).map((url) => ({ path, url, route: url }))
|
|
363
|
+
);
|
|
364
|
+
const mountCollisions = [];
|
|
365
|
+
for (const prefix of input.mounts) {
|
|
366
|
+
if (prefix === "/") {
|
|
367
|
+
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)`);
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
for (const url of withLocale(prefix, locale)) if (staticRoutes.has(url)) mountCollisions.push({ prefix, url, route: url });
|
|
371
|
+
}
|
|
372
|
+
const urls = [...new Set([...input.hylePaths, ...input.mounts.filter((m) => m !== "/")].flatMap((p) => withLocale(p, locale)))];
|
|
373
|
+
const dynamicOverlaps = [];
|
|
374
|
+
for (const route of dynamicRoutes) {
|
|
375
|
+
const matched = urls.filter((u) => routeMatches(route, u));
|
|
376
|
+
if (catchAlls.includes(route)) {
|
|
377
|
+
dynamicOverlaps.push({ route, verdict: "hyle-catch-all", matches: matched.length, examples: matched.slice(0, MAX_EXAMPLES) });
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
const hostWins = matched.filter((u) => {
|
|
381
|
+
const best = catchAlls.filter((c) => routeMatches(c, u)).sort(compareSpecificity)[0];
|
|
382
|
+
return best === void 0 || compareSpecificity(route, best) <= 0;
|
|
383
|
+
});
|
|
384
|
+
if (matched.length === 0) continue;
|
|
385
|
+
const shown = hostWins.length > 0 ? hostWins : matched;
|
|
386
|
+
dynamicOverlaps.push({ route, verdict: hostWins.length > 0 ? "host-wins" : "hyle-wins", matches: shown.length, examples: shown.slice(0, MAX_EXAMPLES) });
|
|
387
|
+
}
|
|
388
|
+
if (catchAlls.length === 0) notes.push(`no hyle catch-all route (a "[...${hyleParam}]" or "[[...${hyleParam}]]" page) was found in the host routes`);
|
|
389
|
+
return { shadowedHylePaths, mountCollisions, dynamicOverlaps, notes, ok: shadowedHylePaths.length === 0 && mountCollisions.length === 0 };
|
|
390
|
+
}
|
|
391
|
+
function reservedFor(hostRoutes, options = {}) {
|
|
392
|
+
const dropLocale = (route) => {
|
|
393
|
+
const [first, ...rest] = segmentsOf(route);
|
|
394
|
+
return options.locale && first === `[${LOCALE_PARAM}]` ? `/${rest.join("/")}` : route;
|
|
395
|
+
};
|
|
396
|
+
const exact = new Set(hostRoutes.map(dropLocale).filter((r) => !isDynamic(r)));
|
|
397
|
+
const mounts = options.mounts?.filter((m) => m !== "/");
|
|
398
|
+
const groups = /* @__PURE__ */ new Map();
|
|
399
|
+
for (const route of exact) {
|
|
400
|
+
const [first, ...rest] = segmentsOf(route);
|
|
401
|
+
if (first !== void 0 && rest.length > 0) groups.set(first, [...groups.get(first) ?? [], route]);
|
|
402
|
+
}
|
|
403
|
+
for (const [first, members] of groups) {
|
|
404
|
+
const onMount = mounts?.some((m) => m === `/${first}` || m.startsWith(`/${first}/`)) ?? true;
|
|
405
|
+
if (members.length < 2 || onMount) continue;
|
|
406
|
+
for (const m of members) exact.delete(m);
|
|
407
|
+
exact.delete(`/${first}`);
|
|
408
|
+
exact.add(`/${first}/*`);
|
|
409
|
+
}
|
|
410
|
+
return [...exact].sort();
|
|
411
|
+
}
|
|
412
|
+
function formatReport(report) {
|
|
413
|
+
const lines = [];
|
|
414
|
+
const section = (title, rows, empty) => lines.push(`${title}`, ...rows.length ? rows.map((r) => ` ${printable(r)}`) : [` ${empty}`], "");
|
|
415
|
+
section(
|
|
416
|
+
"(a) hyle paths shadowed by host static routes (the hyle page is never served):",
|
|
417
|
+
report.shadowedHylePaths.map((s) => `${s.url} (hyle path ${s.path})`),
|
|
418
|
+
"none"
|
|
419
|
+
);
|
|
420
|
+
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");
|
|
421
|
+
section(
|
|
422
|
+
"(b) host dynamic routes matching hyle URLs:",
|
|
423
|
+
report.dynamicOverlaps.map((d) => {
|
|
424
|
+
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];
|
|
425
|
+
return `${d.route} ${label} (${d.matches} URLs, e.g. ${d.examples.join(", ") || "-"})`;
|
|
426
|
+
}),
|
|
427
|
+
"none"
|
|
428
|
+
);
|
|
429
|
+
if (report.notes.length) section("notes:", report.notes, "");
|
|
430
|
+
lines.push(report.ok ? "RESULT: no collisions" : "RESULT: collisions found");
|
|
431
|
+
return lines.join("\n");
|
|
432
|
+
}
|
|
433
|
+
var MAX_PRINTED = 200;
|
|
434
|
+
var printable = (text) => {
|
|
435
|
+
const clean = text.replace(/\u001b(?:\[[0-?]*[ -/]*[@-~]|\][^\u0007\u001b]*(?:\u0007|\u001b\\)?|.)?/g, "").replace(/[\u0000-\u001f\u007f-\u009f]/g, "");
|
|
436
|
+
return clean.length > MAX_PRINTED ? `${clean.slice(0, MAX_PRINTED)}...` : clean;
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
export {
|
|
440
|
+
Cp1ClientError,
|
|
441
|
+
createHyleClient,
|
|
442
|
+
DeliveryDedupe,
|
|
443
|
+
parseSignatureHeader,
|
|
444
|
+
verifyHyleSignature,
|
|
445
|
+
CACHE_TAG_PATTERN,
|
|
446
|
+
isValidCacheTag,
|
|
447
|
+
createRevalidationCallbackRoute,
|
|
448
|
+
listPublicationPaths,
|
|
449
|
+
normalizeRoute,
|
|
450
|
+
hostRoutesFromManifests,
|
|
451
|
+
routeMatches,
|
|
452
|
+
checkRoutes,
|
|
453
|
+
reservedFor,
|
|
454
|
+
formatReport
|
|
455
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// src/react/viewer/labels.ts
|
|
2
|
+
var VIEWER_LABELS_EN = {
|
|
3
|
+
expand: "Expand diagram",
|
|
4
|
+
expandHint: "Expand",
|
|
5
|
+
viewer: "Diagram viewer",
|
|
6
|
+
close: "Close",
|
|
7
|
+
zoomIn: "Zoom in",
|
|
8
|
+
zoomOut: "Zoom out",
|
|
9
|
+
fit: "Fit to window",
|
|
10
|
+
actual: "Actual size",
|
|
11
|
+
search: "Find in diagram",
|
|
12
|
+
searchPlaceholder: "Find",
|
|
13
|
+
noMatch: "No match",
|
|
14
|
+
matchOf: "{n} of {total}",
|
|
15
|
+
copySource: "Copy diagram source",
|
|
16
|
+
downloadSvg: "Download SVG",
|
|
17
|
+
downloadPng: "Download PNG",
|
|
18
|
+
copyImage: "Copy as image",
|
|
19
|
+
pngScale: "PNG scale",
|
|
20
|
+
fullscreen: "Fullscreen",
|
|
21
|
+
exitFullscreen: "Exit fullscreen",
|
|
22
|
+
copied: "Copied",
|
|
23
|
+
saved: "Saved",
|
|
24
|
+
unavailable: "Not available here",
|
|
25
|
+
hint: "Scroll to zoom, drag to pan, click a node to trace its paths, press / to search",
|
|
26
|
+
legendSelected: "Selected",
|
|
27
|
+
legendUpstream: "Upstream",
|
|
28
|
+
legendDownstream: "Downstream",
|
|
29
|
+
outgoing: "outgoing",
|
|
30
|
+
tracing: "{label}: {up} upstream, {down} downstream",
|
|
31
|
+
map: "Overview map"
|
|
32
|
+
};
|
|
33
|
+
var fill = (template, values) => template.replace(/\{(\w+)\}/g, (m, k) => k in values ? String(values[k]) : m);
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
VIEWER_LABELS_EN,
|
|
37
|
+
fill
|
|
38
|
+
};
|
|
@@ -219,6 +219,101 @@ function sanitizeHast(tree, title) {
|
|
|
219
219
|
return { type: "root", children: raw.filter((n) => n !== skip).flatMap((n) => clean(n, 0, { katex: false }, budget)) };
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
// src/react/viewer/labels.ts
|
|
223
|
+
var VIEWER_LABELS_EN = {
|
|
224
|
+
expand: "Expand diagram",
|
|
225
|
+
expandHint: "Expand",
|
|
226
|
+
viewer: "Diagram viewer",
|
|
227
|
+
close: "Close",
|
|
228
|
+
zoomIn: "Zoom in",
|
|
229
|
+
zoomOut: "Zoom out",
|
|
230
|
+
fit: "Fit to window",
|
|
231
|
+
actual: "Actual size",
|
|
232
|
+
search: "Find in diagram",
|
|
233
|
+
searchPlaceholder: "Find",
|
|
234
|
+
noMatch: "No match",
|
|
235
|
+
matchOf: "{n} of {total}",
|
|
236
|
+
copySource: "Copy diagram source",
|
|
237
|
+
downloadSvg: "Download SVG",
|
|
238
|
+
downloadPng: "Download PNG",
|
|
239
|
+
copyImage: "Copy as image",
|
|
240
|
+
pngScale: "PNG scale",
|
|
241
|
+
fullscreen: "Fullscreen",
|
|
242
|
+
exitFullscreen: "Exit fullscreen",
|
|
243
|
+
copied: "Copied",
|
|
244
|
+
saved: "Saved",
|
|
245
|
+
unavailable: "Not available here",
|
|
246
|
+
hint: "Scroll to zoom, drag to pan, click a node to trace its paths, press / to search",
|
|
247
|
+
legendSelected: "Selected",
|
|
248
|
+
legendUpstream: "Upstream",
|
|
249
|
+
legendDownstream: "Downstream",
|
|
250
|
+
outgoing: "outgoing",
|
|
251
|
+
tracing: "{label}: {up} upstream, {down} downstream",
|
|
252
|
+
map: "Overview map"
|
|
253
|
+
};
|
|
254
|
+
var VIEWER_LABELS_FR = {
|
|
255
|
+
expand: "Agrandir le sch\xE9ma",
|
|
256
|
+
expandHint: "Agrandir",
|
|
257
|
+
viewer: "Visionneuse de sch\xE9ma",
|
|
258
|
+
close: "Fermer",
|
|
259
|
+
zoomIn: "Zoom avant",
|
|
260
|
+
zoomOut: "Zoom arri\xE8re",
|
|
261
|
+
fit: "Ajuster \xE0 la fen\xEAtre",
|
|
262
|
+
actual: "Taille r\xE9elle",
|
|
263
|
+
search: "Rechercher dans le sch\xE9ma",
|
|
264
|
+
searchPlaceholder: "Rechercher",
|
|
265
|
+
noMatch: "Aucun r\xE9sultat",
|
|
266
|
+
matchOf: "{n} sur {total}",
|
|
267
|
+
copySource: "Copier la source du sch\xE9ma",
|
|
268
|
+
downloadSvg: "T\xE9l\xE9charger le SVG",
|
|
269
|
+
downloadPng: "T\xE9l\xE9charger le PNG",
|
|
270
|
+
copyImage: "Copier comme image",
|
|
271
|
+
pngScale: "\xC9chelle du PNG",
|
|
272
|
+
fullscreen: "Plein \xE9cran",
|
|
273
|
+
exitFullscreen: "Quitter le plein \xE9cran",
|
|
274
|
+
copied: "Copi\xE9",
|
|
275
|
+
saved: "Enregistr\xE9",
|
|
276
|
+
unavailable: "Indisponible ici",
|
|
277
|
+
hint: "Molette pour zoomer, glisser pour d\xE9placer, cliquer un n\u0153ud pour suivre ses chemins, / pour chercher",
|
|
278
|
+
legendSelected: "S\xE9lection",
|
|
279
|
+
legendUpstream: "En amont",
|
|
280
|
+
legendDownstream: "En aval",
|
|
281
|
+
outgoing: "sortants",
|
|
282
|
+
tracing: "{label} : {up} en amont, {down} en aval",
|
|
283
|
+
map: "Carte d'ensemble"
|
|
284
|
+
};
|
|
285
|
+
var VIEWER_LABELS_ES = {
|
|
286
|
+
expand: "Ampliar el diagrama",
|
|
287
|
+
expandHint: "Ampliar",
|
|
288
|
+
viewer: "Visor de diagramas",
|
|
289
|
+
close: "Cerrar",
|
|
290
|
+
zoomIn: "Acercar",
|
|
291
|
+
zoomOut: "Alejar",
|
|
292
|
+
fit: "Ajustar a la ventana",
|
|
293
|
+
actual: "Tama\xF1o real",
|
|
294
|
+
search: "Buscar en el diagrama",
|
|
295
|
+
searchPlaceholder: "Buscar",
|
|
296
|
+
noMatch: "Sin resultados",
|
|
297
|
+
matchOf: "{n} de {total}",
|
|
298
|
+
copySource: "Copiar el c\xF3digo del diagrama",
|
|
299
|
+
downloadSvg: "Descargar SVG",
|
|
300
|
+
downloadPng: "Descargar PNG",
|
|
301
|
+
copyImage: "Copiar como imagen",
|
|
302
|
+
pngScale: "Escala del PNG",
|
|
303
|
+
fullscreen: "Pantalla completa",
|
|
304
|
+
exitFullscreen: "Salir de pantalla completa",
|
|
305
|
+
copied: "Copiado",
|
|
306
|
+
saved: "Guardado",
|
|
307
|
+
unavailable: "No disponible aqu\xED",
|
|
308
|
+
hint: "Rueda para acercar, arrastra para mover, pulsa un nodo para seguir sus caminos, / para buscar",
|
|
309
|
+
legendSelected: "Seleccionado",
|
|
310
|
+
legendUpstream: "Aguas arriba",
|
|
311
|
+
legendDownstream: "Aguas abajo",
|
|
312
|
+
outgoing: "salientes",
|
|
313
|
+
tracing: "{label}: {up} aguas arriba, {down} aguas abajo",
|
|
314
|
+
map: "Mapa general"
|
|
315
|
+
};
|
|
316
|
+
|
|
222
317
|
// src/react/strings.ts
|
|
223
318
|
var en = {
|
|
224
319
|
toc: "On this page",
|
|
@@ -258,7 +353,8 @@ var en = {
|
|
|
258
353
|
rdFallback: "If nothing happens, go to the new address.",
|
|
259
354
|
unKind: "Unavailable",
|
|
260
355
|
unTitle: "This page is temporarily unavailable",
|
|
261
|
-
unBody: "The content could not be loaded. Please try again in a moment."
|
|
356
|
+
unBody: "The content could not be loaded. Please try again in a moment.",
|
|
357
|
+
viewer: VIEWER_LABELS_EN
|
|
262
358
|
};
|
|
263
359
|
var fr = {
|
|
264
360
|
toc: "Sur cette page",
|
|
@@ -298,7 +394,8 @@ var fr = {
|
|
|
298
394
|
rdFallback: "Si rien ne se passe, allez \xE0 la nouvelle adresse.",
|
|
299
395
|
unKind: "Indisponible",
|
|
300
396
|
unTitle: "Cette page est momentan\xE9ment indisponible",
|
|
301
|
-
unBody: "Le contenu n'a pas pu \xEAtre charg\xE9. R\xE9essayez dans un instant."
|
|
397
|
+
unBody: "Le contenu n'a pas pu \xEAtre charg\xE9. R\xE9essayez dans un instant.",
|
|
398
|
+
viewer: VIEWER_LABELS_FR
|
|
302
399
|
};
|
|
303
400
|
var es = {
|
|
304
401
|
toc: "En esta p\xE1gina",
|
|
@@ -338,7 +435,8 @@ var es = {
|
|
|
338
435
|
rdFallback: "Si no pasa nada, ve a la nueva direcci\xF3n.",
|
|
339
436
|
unKind: "No disponible",
|
|
340
437
|
unTitle: "Esta p\xE1gina no est\xE1 disponible por el momento",
|
|
341
|
-
unBody: "No se pudo cargar el contenido. Int\xE9ntalo de nuevo en un momento."
|
|
438
|
+
unBody: "No se pudo cargar el contenido. Int\xE9ntalo de nuevo en un momento.",
|
|
439
|
+
viewer: VIEWER_LABELS_ES
|
|
342
440
|
};
|
|
343
441
|
var TABLE = { en, fr, es };
|
|
344
442
|
function stringsFor(locale) {
|
|
@@ -406,7 +504,7 @@ function buildComponents(c, s) {
|
|
|
406
504
|
if (typeof srcDoc !== "string") return null;
|
|
407
505
|
const source = mermaidSource(srcDoc);
|
|
408
506
|
if (c.Mermaid) return /* @__PURE__ */ jsx3(c.Mermaid, { srcDoc, source, title: s.diagram });
|
|
409
|
-
if (source !== void 0) return /* @__PURE__ */ jsx3(MermaidDiagram, { source, title: s.diagram, errorText: s.diagramError });
|
|
507
|
+
if (source !== void 0) return /* @__PURE__ */ jsx3(MermaidDiagram, { source, title: s.diagram, errorText: s.diagramError, labels: s.viewer });
|
|
410
508
|
return /* @__PURE__ */ jsx3("figure", { className: "hyle-mermaid", "data-slot-component": "Mermaid", children: /* @__PURE__ */ jsx3("iframe", { srcDoc, sandbox: String(sandbox), title: s.diagram, loading: "lazy", referrerPolicy: "no-referrer", ...{ csp: MERMAID_FRAME_CSP } }) });
|
|
411
509
|
};
|
|
412
510
|
const Heading = (level) => function HyleHeading({ id, children, ...rest }) {
|