@tdacorp/hyle-sdk 0.22.2 → 0.23.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.
Files changed (36) hide show
  1. package/README.md +32 -1
  2. package/dist/check-routes-bin.js +26 -6
  3. package/dist/{chunk-IW3TUD4G.js → chunk-JHZJOJDC.js} +1 -1
  4. package/dist/{chunk-ZIW6FDU2.js → chunk-UFMKLCXS.js} +2 -2
  5. package/dist/{chunk-7T5EEJHK.js → chunk-VUML2UPD.js} +1 -1
  6. package/dist/{chunk-DUPT6XLB.js → chunk-VXARM37R.js} +12 -1
  7. package/dist/{chunk-KU7LWK4E.js → chunk-YHXE3TGS.js} +26 -7
  8. package/dist/{client-BGjmEWhN.d.cts → client--ighAWaj.d.ts} +7 -1
  9. package/dist/{client-D0LTpr3Y.d.ts → client-DK-S2580.d.cts} +7 -1
  10. package/dist/comments.cjs +4 -1
  11. package/dist/comments.js +4 -1
  12. package/dist/{embed-CbtsbZs3.d.cts → embed-XT0x_Jaa.d.cts} +1 -1
  13. package/dist/{embed-Cf_2ZR5x.d.ts → embed-g7NT1CyB.d.ts} +1 -1
  14. package/dist/html.cjs +4 -1
  15. package/dist/html.js +2 -2
  16. package/dist/index.cjs +26 -6
  17. package/dist/index.d.cts +3 -3
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +2 -2
  20. package/dist/next.cjs +128 -18
  21. package/dist/next.d.cts +42 -7
  22. package/dist/next.d.ts +42 -7
  23. package/dist/next.js +108 -18
  24. package/dist/react.cjs +4 -1
  25. package/dist/react.d.cts +3 -3
  26. package/dist/react.d.ts +3 -3
  27. package/dist/react.js +3 -3
  28. package/dist/{resolve-BysHtZ_i.d.ts → resolve-BqC9l5RH.d.ts} +1 -1
  29. package/dist/{resolve-BnIv7aB7.d.cts → resolve-CiZCPysX.d.cts} +1 -1
  30. package/dist/{types-D09Z072G.d.cts → types-b9QbmEDd.d.cts} +13 -1
  31. package/dist/{types-D09Z072G.d.ts → types-b9QbmEDd.d.ts} +13 -1
  32. package/dist/use-cache.cjs +26 -6
  33. package/dist/use-cache.d.cts +3 -3
  34. package/dist/use-cache.d.ts +3 -3
  35. package/dist/use-cache.js +3 -3
  36. package/package.json +1 -1
package/dist/next.cjs CHANGED
@@ -31,6 +31,7 @@ __export(next_exports, {
31
31
  createLlmsTxtRoute: () => createLlmsTxtRoute,
32
32
  createMarkdownRoute: () => createMarkdownRoute,
33
33
  createOgImageRoute: () => createOgImageRoute,
34
+ createProtectedUnlockRoute: () => createProtectedUnlockRoute,
34
35
  createRevalidateRoute: () => createRevalidateRoute,
35
36
  fetchResolver: () => fetchResolver,
36
37
  hyleFeed: () => hyleFeed,
@@ -39,6 +40,8 @@ __export(next_exports, {
39
40
  hylePage: () => hylePage,
40
41
  hylePreviewMetadata: () => hylePreviewMetadata,
41
42
  hylePreviewPage: () => hylePreviewPage,
43
+ hyleProtectedMetadata: () => hyleProtectedMetadata,
44
+ hyleProtectedPage: () => hyleProtectedPage,
42
45
  hyleRootMetadata: () => hyleRootMetadata,
43
46
  hyleRootPage: () => hyleRootPage,
44
47
  hyleRootSitemap: () => hyleRootSitemap,
@@ -70,7 +73,13 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
70
73
  var PREVIEW_HEADER = "cp-preview";
71
74
  var PREVIEW_PARAM = "hyle_preview";
72
75
  var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
73
- var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
76
+ var PROTECTED_PARAM = "hyle_protected";
77
+ var PROTECTED_HEADER = "cp-protected";
78
+ var PROTECTED_ID = new RegExp(`^${UUID}$`);
79
+ var PROTECTED_PASSWORD = /^[A-Za-z0-9]{16}$/;
80
+ var protectedCookieName = (pageId) => `hyle_p_${pageId}`;
81
+ var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
82
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
74
83
  function hostAssetSrc(src) {
75
84
  const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
76
85
  return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : src;
@@ -122,8 +131,8 @@ function mapNode(node, mark, depth) {
122
131
  ...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
123
132
  };
124
133
  }
125
- function withPreviewAssets(article, token) {
126
- const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${PREVIEW_PARAM}=${token}`) : value;
134
+ function withAssetQuery(article, query) {
135
+ const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
127
136
  const { publication, content } = article;
128
137
  return {
129
138
  ...article,
@@ -263,7 +272,18 @@ function createHyleClient(options) {
263
272
  if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
264
273
  const article = data?.article;
265
274
  if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply2);
266
- return { kind: "preview", expires_at: data.expires_at, article: withPreviewAssets(article, token) };
275
+ return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
276
+ }
277
+ async function protectedPage(pageId, password) {
278
+ if (!PROTECTED_ID.test(pageId) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
279
+ const reply2 = await get("/cp1/read/_protected", new URLSearchParams(), { headers: { [PROTECTED_HEADER]: `${pageId}.${password}` }, cache: "no-store" });
280
+ if (reply2.status === 404 && reply2.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
281
+ const data = reply2.parsed?.data;
282
+ if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
283
+ const article = data?.article;
284
+ const expires = data?.expires_at;
285
+ if (data?.cp !== 1 || data.kind !== "protected" || typeof expires !== "string" && expires !== null || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply2);
286
+ return { kind: "protected", expires_at: expires, article: withAssetQuery(article, `${PROTECTED_PARAM}=${pageId}`) };
267
287
  }
268
288
  async function asset(file, opts = {}) {
269
289
  if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
@@ -277,8 +297,12 @@ function createHyleClient(options) {
277
297
  const value = opts.headers?.[name];
278
298
  if (value) headers.set(name, value);
279
299
  }
300
+ const { protectedAccess } = opts;
301
+ if (protectedAccess !== void 0 && !(PROTECTED_ID.test(protectedAccess.pageId) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a page id and password");
280
302
  if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
281
- return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...previewToken === void 0 ? {} : { cache: "no-store" } });
303
+ if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, `${protectedAccess.pageId}.${protectedAccess.password}`);
304
+ const uncached = previewToken !== void 0 || protectedAccess !== void 0;
305
+ return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
282
306
  }
283
307
  async function theme(opts = {}) {
284
308
  const url = `${base}/cp1/read/theme.css`;
@@ -287,7 +311,7 @@ function createHyleClient(options) {
287
311
  if (applied) await applied;
288
312
  return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
289
313
  }
290
- return { resolve, mounts, pushPosts, preview, asset, theme };
314
+ return { resolve, mounts, pushPosts, preview, protected: protectedPage, asset, theme };
291
315
  }
292
316
 
293
317
  // src/delivery-dedupe.ts
@@ -2523,6 +2547,10 @@ function sameOriginProblem(req, write, allowedOrigins) {
2523
2547
  const site = req.headers.get("sec-fetch-site");
2524
2548
  if (site !== null && site !== "same-origin") return true;
2525
2549
  if (!write) return false;
2550
+ if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
2551
+ return originMismatch(req, allowedOrigins);
2552
+ }
2553
+ function originMismatch(req, allowedOrigins) {
2526
2554
  const origin = req.headers.get("origin");
2527
2555
  if (origin === null) return true;
2528
2556
  let parsed;
@@ -2531,7 +2559,6 @@ function sameOriginProblem(req, write, allowedOrigins) {
2531
2559
  } catch {
2532
2560
  return true;
2533
2561
  }
2534
- if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
2535
2562
  if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
2536
2563
  const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
2537
2564
  const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
@@ -3319,7 +3346,7 @@ var DEFAULT_TIMEOUT_MS3 = 3e4;
3319
3346
  var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
3320
3347
  var PARTIAL_CACHE_CONTROL = "no-store";
3321
3348
  var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
3322
- var PREVIEW_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
3349
+ var PRIVATE_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
3323
3350
  var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
3324
3351
  var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
3325
3352
  var THEME_CACHE_CONTROL = "public, max-age=31536000, immutable";
@@ -3347,6 +3374,12 @@ async function serveTheme(client, scope, hash, timeoutMs, head) {
3347
3374
  return empty(502);
3348
3375
  }
3349
3376
  }
3377
+ function protectedAccessFor(req, pageId) {
3378
+ if (!PROTECTED_ID.test(pageId)) return void 0;
3379
+ const name = protectedCookieName(pageId);
3380
+ const password = req.headers.get("cookie")?.split(";").map((c) => c.trim()).find((c) => c.startsWith(`${name}=`))?.slice(name.length + 1);
3381
+ return password !== void 0 && PROTECTED_PASSWORD.test(password) ? { pageId, password } : void 0;
3382
+ }
3350
3383
  function capped(body, max) {
3351
3384
  let seen = 0;
3352
3385
  return body.pipeThrough(
@@ -3363,17 +3396,21 @@ function createAssetRoute(options) {
3363
3396
  let client;
3364
3397
  const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
3365
3398
  async function serve(req, ctx2, head) {
3366
- const previewToken = new URL(req.url).searchParams.get(PREVIEW_PARAM);
3367
- const res = await relay(req, ctx2, head, previewToken);
3368
- if (previewToken !== null) for (const [name, value] of Object.entries(PREVIEW_HEADERS)) res.headers.set(name, value);
3399
+ const query = new URL(req.url).searchParams;
3400
+ const previewToken = query.get(PREVIEW_PARAM);
3401
+ const pageId = query.get(PROTECTED_PARAM);
3402
+ const res = await relay(req, ctx2, head, previewToken, pageId);
3403
+ if (previewToken !== null || pageId !== null) for (const [name, value] of Object.entries(PRIVATE_HEADERS)) res.headers.set(name, value);
3369
3404
  return res;
3370
3405
  }
3371
- async function relay(req, ctx2, head, previewToken) {
3406
+ async function relay(req, ctx2, head, previewToken, pageId) {
3372
3407
  if (isSwitchedOff3((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
3373
3408
  const file = (await ctx2.params).file;
3374
3409
  const [, themeScope, themeHash] = typeof file === "string" ? THEME_FILE.exec(file) ?? [] : [];
3375
3410
  if (typeof file !== "string" || !themeHash && !ASSET_FILE.test(file)) return empty(404);
3376
3411
  if (previewToken !== null && !PREVIEW_TOKEN.test(previewToken)) return empty(404);
3412
+ const protectedAccess = pageId === null ? void 0 : protectedAccessFor(req, pageId);
3413
+ if (pageId !== null && protectedAccess === void 0) return empty(404);
3377
3414
  try {
3378
3415
  client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
3379
3416
  } catch {
@@ -3385,6 +3422,7 @@ function createAssetRoute(options) {
3385
3422
  upstream = await client.asset(file, {
3386
3423
  timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS3,
3387
3424
  ...previewToken === null ? {} : { previewToken },
3425
+ ...protectedAccess === void 0 ? {} : { protectedAccess },
3388
3426
  headers: { range: req.headers.get("range"), "if-range": req.headers.get("if-range"), "if-none-match": req.headers.get("if-none-match") }
3389
3427
  });
3390
3428
  } catch {
@@ -3403,7 +3441,7 @@ function createAssetRoute(options) {
3403
3441
  const range = upstream.headers.get("content-range");
3404
3442
  return empty(416, range ? { "Content-Range": range } : {});
3405
3443
  }
3406
- if (upstream.status === 429 && previewToken !== null) {
3444
+ if (upstream.status === 429 && (previewToken !== null || pageId !== null)) {
3407
3445
  drop();
3408
3446
  const wait = upstream.headers.get("retry-after");
3409
3447
  return empty(429, wait ? { "Retry-After": wait } : {});
@@ -3474,6 +3512,12 @@ function createOgImageRoute(options) {
3474
3512
  // src/next/preview.tsx
3475
3513
  var import_navigation7 = require("next/navigation");
3476
3514
  var import_jsx_runtime14 = require("react/jsx-runtime");
3515
+ function drawArticle(article, options) {
3516
+ const { locale } = article.publication;
3517
+ const toHref = (sitePath, linkLocale = locale) => (options.localePrefix?.(linkLocale) ?? "") + sitePath;
3518
+ const props = { article, components: options.components, slots: options.slots, locale, toHref };
3519
+ return options.layout === "docs" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DocsPage, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ArticlePage, { ...props });
3520
+ }
3477
3521
  var hylePreviewMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
3478
3522
  var BANNER = {
3479
3523
  position: "sticky",
@@ -3490,18 +3534,81 @@ function hylePreviewPage(options) {
3490
3534
  const { token } = await searchParams ?? {};
3491
3535
  const result = await createHyleClient(options).preview(typeof token === "string" ? token : void 0);
3492
3536
  if (result.kind !== "preview") (0, import_navigation7.notFound)();
3493
- const { article } = result;
3494
- const { locale } = article.publication;
3495
- const toHref = (sitePath, linkLocale = locale) => (options.localePrefix?.(linkLocale) ?? "") + sitePath;
3496
- const props = { article, components: options.components, slots: options.slots, locale, toHref };
3497
3537
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
3498
3538
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("meta", { name: "robots", content: "noindex, nofollow" }),
3499
3539
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("meta", { name: "referrer", content: "no-referrer" }),
3500
3540
  /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
3501
- options.layout === "docs" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(DocsPage, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ArticlePage, { ...props })
3541
+ drawArticle(result.article, options)
3542
+ ] });
3543
+ };
3544
+ }
3545
+
3546
+ // src/next/protected.tsx
3547
+ var import_headers = require("next/headers");
3548
+ var import_navigation8 = require("next/navigation");
3549
+ var import_jsx_runtime15 = require("react/jsx-runtime");
3550
+ var hyleProtectedMetadata = { robots: { index: false, follow: false }, referrer: "same-origin" };
3551
+ var COOKIE_MAX_AGE_SECONDS = 12 * 60 * 60;
3552
+ var UNLOCK_MAX_BYTES = 1024;
3553
+ var PRIVATE_HEADERS2 = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
3554
+ var PASSWORD_FIELD = "hyle-protected-password";
3555
+ var ERROR_ID = "hyle-protected-error";
3556
+ function PasswordForm({ pageId, failed }) {
3557
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("main", { children: [
3558
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("h1", { children: "Protected page" }),
3559
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("form", { method: "post", action: `/p/${pageId}/unlock`, autoComplete: "off", children: [
3560
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("label", { htmlFor: PASSWORD_FIELD, children: "Password" }),
3561
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3562
+ "input",
3563
+ {
3564
+ id: PASSWORD_FIELD,
3565
+ name: "password",
3566
+ type: "password",
3567
+ autoComplete: "off",
3568
+ spellCheck: false,
3569
+ required: true,
3570
+ pattern: "[A-Za-z0-9]{16}",
3571
+ title: "16 letters or digits",
3572
+ "aria-invalid": failed || void 0,
3573
+ "aria-describedby": failed ? ERROR_ID : void 0
3574
+ }
3575
+ ),
3576
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("button", { type: "submit", children: "Open" }),
3577
+ failed ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("p", { id: ERROR_ID, role: "alert", children: "Wrong or expired password." }) : null
3578
+ ] })
3579
+ ] });
3580
+ }
3581
+ function hyleProtectedPage(options) {
3582
+ return async function HyleProtectedPage({ params }) {
3583
+ const { id } = await params;
3584
+ if (typeof id !== "string" || !PROTECTED_ID.test(id)) (0, import_navigation8.notFound)();
3585
+ const password = (await (0, import_headers.cookies)()).get(protectedCookieName(id))?.value;
3586
+ const result = password === void 0 ? void 0 : await createHyleClient(options).protected(id, password);
3587
+ if (result?.kind === "disabled") (0, import_navigation8.notFound)();
3588
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(import_jsx_runtime15.Fragment, { children: [
3589
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("meta", { name: "robots", content: "noindex, nofollow" }),
3590
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("meta", { name: "referrer", content: "same-origin" }),
3591
+ result?.kind === "protected" ? drawArticle(result.article, options) : /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(PasswordForm, { pageId: id, failed: result !== void 0 })
3502
3592
  ] });
3503
3593
  };
3504
3594
  }
3595
+ function createProtectedUnlockRoute() {
3596
+ return {
3597
+ async POST(req, ctx2) {
3598
+ const { id } = await ctx2.params;
3599
+ if (typeof id !== "string" || !PROTECTED_ID.test(id)) return new Response(null, { status: 404, headers: PRIVATE_HEADERS2 });
3600
+ const site = req.headers.get("sec-fetch-site");
3601
+ if (site === null ? originMismatch(req) : site !== "same-origin") return new Response(null, { status: 403, headers: PRIVATE_HEADERS2 });
3602
+ if (!/^application\/x-www-form-urlencoded(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return new Response(null, { status: 415, headers: PRIVATE_HEADERS2 });
3603
+ if (Number(req.headers.get("content-length")) > UNLOCK_MAX_BYTES) return new Response(null, { status: 413, headers: PRIVATE_HEADERS2 });
3604
+ const form = await readCapped(new Response(req.body), UNLOCK_MAX_BYTES).catch(() => void 0);
3605
+ if (form === void 0) return new Response(null, { status: 413, headers: PRIVATE_HEADERS2 });
3606
+ const password = new URLSearchParams(form).get("password") ?? "";
3607
+ const cookie = PROTECTED_PASSWORD.test(password) ? { "Set-Cookie": `${protectedCookieName(id)}=${password}; Max-Age=${COOKIE_MAX_AGE_SECONDS}; Path=/; HttpOnly; Secure; SameSite=Lax` } : {};
3608
+ return new Response(null, { status: 303, headers: { ...PRIVATE_HEADERS2, Location: `/p/${id}`, ...cookie } });
3609
+ }
3610
+ };
3611
+ }
3505
3612
  // Annotate the CommonJS export names for ESM import in node:
3506
3613
  0 && (module.exports = {
3507
3614
  ENGAGE_CSRF_HEADER,
@@ -3515,6 +3622,7 @@ function hylePreviewPage(options) {
3515
3622
  createLlmsTxtRoute,
3516
3623
  createMarkdownRoute,
3517
3624
  createOgImageRoute,
3625
+ createProtectedUnlockRoute,
3518
3626
  createRevalidateRoute,
3519
3627
  fetchResolver,
3520
3628
  hyleFeed,
@@ -3523,6 +3631,8 @@ function hylePreviewPage(options) {
3523
3631
  hylePage,
3524
3632
  hylePreviewMetadata,
3525
3633
  hylePreviewPage,
3634
+ hyleProtectedMetadata,
3635
+ hyleProtectedPage,
3526
3636
  hyleRootMetadata,
3527
3637
  hyleRootPage,
3528
3638
  hyleRootSitemap,
package/dist/next.d.cts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ReactElement } from 'react';
2
- import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-CbtsbZs3.cjs';
3
- export { c as HyleCommentsFallback } from './embed-CbtsbZs3.cjs';
4
- import { F as FetchResolverOptions, H as HyleResolver } from './resolve-BnIv7aB7.cjs';
5
- export { f as fetchResolver, w as workspaceTags } from './resolve-BnIv7aB7.cjs';
2
+ import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-XT0x_Jaa.cjs';
3
+ export { c as HyleCommentsFallback } from './embed-XT0x_Jaa.cjs';
4
+ import { F as FetchResolverOptions, H as HyleResolver } from './resolve-CiZCPysX.cjs';
5
+ export { f as fetchResolver, w as workspaceTags } from './resolve-CiZCPysX.cjs';
6
6
  import { MetadataRoute, ResolvingMetadata, Metadata } from 'next';
7
7
  import { R as RevalidationCallbackOptions, b as RevalidationCallbackRoute } from './revalidation-callback-BQl77tQR.cjs';
8
- import { c as HyleCredential } from './client-BGjmEWhN.cjs';
9
- import './types-D09Z072G.cjs';
8
+ import { c as HyleCredential } from './client-DK-S2580.cjs';
9
+ import './types-b9QbmEDd.cjs';
10
10
 
11
11
  type RouteParams = Record<string, string | string[] | undefined>;
12
12
  interface CommonOptions {
@@ -386,6 +386,10 @@ interface AssetRoute {
386
386
  * Draft preview (hyle ADR 0037): `?hyle_preview=<token>`, which the preview page puts on its own images, is sent to hyle as a
387
387
  * header so that draft's assets load; every such answer is `no-store`. The token is never sent for the theme stylesheet,
388
388
  * which is the credential's own with or without it. No other query parameter is read.
389
+ *
390
+ * Protected page (hyle ADR 0039): `?hyle_protected=<pageId>` takes the password from that page's cookie (`hyle_p_<pageId>`, set by
391
+ * `createProtectedUnlockRoute`) and forwards it as the `cp-protected` header. A missing or malformed cookie is a 404 that reaches
392
+ * nobody; every such answer is private and `no-store`, as a draft's is.
389
393
  */
390
394
  declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
391
395
 
@@ -534,4 +538,35 @@ declare const hylePreviewMetadata: Metadata;
534
538
  */
535
539
  declare function hylePreviewPage(options: HylePreviewPageOptions): (props: PageProps) => Promise<ReactElement>;
536
540
 
537
- export { type AssetRoute, type AssetRouteOptions, ENGAGE_CSRF_HEADER, type EngageReader, type EngagementRoute, type EngagementRouteOptions, FetchResolverOptions, HyleArticle, type HyleArticleProps, HyleComments, type HyleCommentsProps, type HyleFeedOptions, HyleList, type HyleListProps, type HyleNextOptions, type HylePreviewPageOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, type LlmsTxtOptions, MOUNTS_MAX_STALE_MS, type MarkdownRoute, type OgImageRoute, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createEngagementRoute, createLlmsTxtRoute, createMarkdownRoute, createOgImageRoute, createRevalidateRoute, hyleFeed, hyleFeedLink, hyleMetadata, hylePage, hylePreviewMetadata, hylePreviewPage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap, markdownRewritePath };
541
+ /**
542
+ * `export const metadata = hyleProtectedMetadata`, next to `hyleProtectedPage`. The page also renders both tags itself. The
543
+ * referrer is `same-origin`, not `no-referrer`: a no-referrer page sends `Origin: null` on its own form POST, which the unlock
544
+ * route would refuse. The URL carries no secret.
545
+ */
546
+ declare const hyleProtectedMetadata: Metadata;
547
+ /**
548
+ * The page behind a protected link (ADR 0039): `export default hyleProtectedPage({ baseUrl, token })` in `app/p/[id]/page.tsx`.
549
+ * It reads the visitor's cookie for this page and asks hyle for it: no cookie shows the password form, a cookie hyle refuses
550
+ * shows the form with "Wrong or expired password", and a good one draws the article as a published page does. A malformed id
551
+ * or a switched-off surface is `notFound()`. The page reads cookies, so it is rendered per request and never cached.
552
+ */
553
+ declare function hyleProtectedPage(options: HylePreviewPageOptions): (props: {
554
+ params: Promise<{
555
+ id?: string;
556
+ }>;
557
+ }) => Promise<ReactElement>;
558
+ /**
559
+ * `export const { POST } = createProtectedUnlockRoute()` in `app/p/[id]/unlock/route.ts`. The form posts the password here; the
560
+ * route sets it in the page's HttpOnly cookie and sends the visitor back to `/p/<id>`, where the page checks it with hyle. It
561
+ * never calls hyle itself, so a view is one open. Only a same-origin POST with a form body of at most 1 KiB is read, and the
562
+ * password is stored only if it has the password's shape. The redirect target is built from the validated page id alone.
563
+ */
564
+ declare function createProtectedUnlockRoute(): {
565
+ POST: (req: Request, ctx: {
566
+ params: Promise<{
567
+ id?: string;
568
+ }>;
569
+ }) => Promise<Response>;
570
+ };
571
+
572
+ export { type AssetRoute, type AssetRouteOptions, ENGAGE_CSRF_HEADER, type EngageReader, type EngagementRoute, type EngagementRouteOptions, FetchResolverOptions, HyleArticle, type HyleArticleProps, HyleComments, type HyleCommentsProps, type HyleFeedOptions, HyleList, type HyleListProps, type HyleNextOptions, type HylePreviewPageOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, type LlmsTxtOptions, MOUNTS_MAX_STALE_MS, type MarkdownRoute, type OgImageRoute, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createEngagementRoute, createLlmsTxtRoute, createMarkdownRoute, createOgImageRoute, createProtectedUnlockRoute, createRevalidateRoute, hyleFeed, hyleFeedLink, hyleMetadata, hylePage, hylePreviewMetadata, hylePreviewPage, hyleProtectedMetadata, hyleProtectedPage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap, markdownRewritePath };
package/dist/next.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { ReactElement } from 'react';
2
- import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-Cf_2ZR5x.js';
3
- export { c as HyleCommentsFallback } from './embed-Cf_2ZR5x.js';
4
- import { F as FetchResolverOptions, H as HyleResolver } from './resolve-BysHtZ_i.js';
5
- export { f as fetchResolver, w as workspaceTags } from './resolve-BysHtZ_i.js';
2
+ import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-g7NT1CyB.js';
3
+ export { c as HyleCommentsFallback } from './embed-g7NT1CyB.js';
4
+ import { F as FetchResolverOptions, H as HyleResolver } from './resolve-BqC9l5RH.js';
5
+ export { f as fetchResolver, w as workspaceTags } from './resolve-BqC9l5RH.js';
6
6
  import { MetadataRoute, ResolvingMetadata, Metadata } from 'next';
7
7
  import { R as RevalidationCallbackOptions, b as RevalidationCallbackRoute } from './revalidation-callback-BQl77tQR.js';
8
- import { c as HyleCredential } from './client-D0LTpr3Y.js';
9
- import './types-D09Z072G.js';
8
+ import { c as HyleCredential } from './client--ighAWaj.js';
9
+ import './types-b9QbmEDd.js';
10
10
 
11
11
  type RouteParams = Record<string, string | string[] | undefined>;
12
12
  interface CommonOptions {
@@ -386,6 +386,10 @@ interface AssetRoute {
386
386
  * Draft preview (hyle ADR 0037): `?hyle_preview=<token>`, which the preview page puts on its own images, is sent to hyle as a
387
387
  * header so that draft's assets load; every such answer is `no-store`. The token is never sent for the theme stylesheet,
388
388
  * which is the credential's own with or without it. No other query parameter is read.
389
+ *
390
+ * Protected page (hyle ADR 0039): `?hyle_protected=<pageId>` takes the password from that page's cookie (`hyle_p_<pageId>`, set by
391
+ * `createProtectedUnlockRoute`) and forwards it as the `cp-protected` header. A missing or malformed cookie is a 404 that reaches
392
+ * nobody; every such answer is private and `no-store`, as a draft's is.
389
393
  */
390
394
  declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
391
395
 
@@ -534,4 +538,35 @@ declare const hylePreviewMetadata: Metadata;
534
538
  */
535
539
  declare function hylePreviewPage(options: HylePreviewPageOptions): (props: PageProps) => Promise<ReactElement>;
536
540
 
537
- export { type AssetRoute, type AssetRouteOptions, ENGAGE_CSRF_HEADER, type EngageReader, type EngagementRoute, type EngagementRouteOptions, FetchResolverOptions, HyleArticle, type HyleArticleProps, HyleComments, type HyleCommentsProps, type HyleFeedOptions, HyleList, type HyleListProps, type HyleNextOptions, type HylePreviewPageOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, type LlmsTxtOptions, MOUNTS_MAX_STALE_MS, type MarkdownRoute, type OgImageRoute, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createEngagementRoute, createLlmsTxtRoute, createMarkdownRoute, createOgImageRoute, createRevalidateRoute, hyleFeed, hyleFeedLink, hyleMetadata, hylePage, hylePreviewMetadata, hylePreviewPage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap, markdownRewritePath };
541
+ /**
542
+ * `export const metadata = hyleProtectedMetadata`, next to `hyleProtectedPage`. The page also renders both tags itself. The
543
+ * referrer is `same-origin`, not `no-referrer`: a no-referrer page sends `Origin: null` on its own form POST, which the unlock
544
+ * route would refuse. The URL carries no secret.
545
+ */
546
+ declare const hyleProtectedMetadata: Metadata;
547
+ /**
548
+ * The page behind a protected link (ADR 0039): `export default hyleProtectedPage({ baseUrl, token })` in `app/p/[id]/page.tsx`.
549
+ * It reads the visitor's cookie for this page and asks hyle for it: no cookie shows the password form, a cookie hyle refuses
550
+ * shows the form with "Wrong or expired password", and a good one draws the article as a published page does. A malformed id
551
+ * or a switched-off surface is `notFound()`. The page reads cookies, so it is rendered per request and never cached.
552
+ */
553
+ declare function hyleProtectedPage(options: HylePreviewPageOptions): (props: {
554
+ params: Promise<{
555
+ id?: string;
556
+ }>;
557
+ }) => Promise<ReactElement>;
558
+ /**
559
+ * `export const { POST } = createProtectedUnlockRoute()` in `app/p/[id]/unlock/route.ts`. The form posts the password here; the
560
+ * route sets it in the page's HttpOnly cookie and sends the visitor back to `/p/<id>`, where the page checks it with hyle. It
561
+ * never calls hyle itself, so a view is one open. Only a same-origin POST with a form body of at most 1 KiB is read, and the
562
+ * password is stored only if it has the password's shape. The redirect target is built from the validated page id alone.
563
+ */
564
+ declare function createProtectedUnlockRoute(): {
565
+ POST: (req: Request, ctx: {
566
+ params: Promise<{
567
+ id?: string;
568
+ }>;
569
+ }) => Promise<Response>;
570
+ };
571
+
572
+ export { type AssetRoute, type AssetRouteOptions, ENGAGE_CSRF_HEADER, type EngageReader, type EngagementRoute, type EngagementRouteOptions, FetchResolverOptions, HyleArticle, type HyleArticleProps, HyleComments, type HyleCommentsProps, type HyleFeedOptions, HyleList, type HyleListProps, type HyleNextOptions, type HylePreviewPageOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, type LlmsTxtOptions, MOUNTS_MAX_STALE_MS, type MarkdownRoute, type OgImageRoute, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createEngagementRoute, createLlmsTxtRoute, createMarkdownRoute, createOgImageRoute, createProtectedUnlockRoute, createRevalidateRoute, hyleFeed, hyleFeedLink, hyleMetadata, hylePage, hylePreviewMetadata, hylePreviewPage, hyleProtectedMetadata, hyleProtectedPage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap, markdownRewritePath };