@tdacorp/hyle-sdk 0.24.1 → 0.26.1

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 (44) hide show
  1. package/README.md +2 -2
  2. package/dist/{embed-BaLQbE_n.d.ts → brand-CwXvdSkk.d.ts} +14 -2
  3. package/dist/{embed-BrrGgkgQ.d.cts → brand-IuZSB9UX.d.cts} +14 -2
  4. package/dist/{chunk-RCK4NCYC.js → chunk-3UQGU62T.js} +12 -0
  5. package/dist/{chunk-O4QWHXVH.js → chunk-IDBQSMWT.js} +1 -1
  6. package/dist/{chunk-5TKJH2XC.js → chunk-NUQQ6VHH.js} +267 -43
  7. package/dist/{chunk-Y3BACEWA.js → chunk-T4EZAQFU.js} +129 -3
  8. package/dist/chunk-VAR2B7S6.js +82 -0
  9. package/dist/{chunk-U74B7AUG.js → chunk-ZWKAEWEW.js} +22 -74
  10. package/dist/{client-DN38IP63.d.ts → client-B2zi_BGq.d.ts} +1 -1
  11. package/dist/{client-CI-3cHtc.d.cts → client-DBZTvcCh.d.cts} +1 -1
  12. package/dist/comments.cjs +25 -1
  13. package/dist/comments.js +4 -2
  14. package/dist/html.cjs +129 -3
  15. package/dist/html.js +1 -1
  16. package/dist/index.cjs +12 -0
  17. package/dist/index.d.cts +4 -4
  18. package/dist/index.d.ts +4 -4
  19. package/dist/index.js +1 -1
  20. package/dist/next.cjs +593 -177
  21. package/dist/next.d.cts +27 -11
  22. package/dist/next.d.ts +27 -11
  23. package/dist/next.js +188 -124
  24. package/dist/react.cjs +401 -46
  25. package/dist/react.d.cts +114 -4
  26. package/dist/react.d.ts +114 -4
  27. package/dist/react.js +14 -4
  28. package/dist/reactions.cjs +25 -1
  29. package/dist/reactions.js +4 -2
  30. package/dist/{resolve-Ce_yz8gC.d.cts → resolve-0nGnsIHo.d.cts} +1 -1
  31. package/dist/{resolve-DMHbYyTS.d.ts → resolve-CguSaZLa.d.ts} +1 -1
  32. package/dist/{revalidation-callback-BQl77tQR.d.cts → revalidation-callback-FT9ik1dh.d.cts} +11 -0
  33. package/dist/{revalidation-callback-BQl77tQR.d.ts → revalidation-callback-FT9ik1dh.d.ts} +11 -0
  34. package/dist/share-client.cjs +498 -0
  35. package/dist/share-client.d.cts +99 -0
  36. package/dist/share-client.d.ts +99 -0
  37. package/dist/share-client.js +390 -0
  38. package/dist/styles.css +176 -1
  39. package/dist/{types-CxE8kLeo.d.cts → types-CdaIzSjg.d.cts} +2 -0
  40. package/dist/{types-CxE8kLeo.d.ts → types-CdaIzSjg.d.ts} +2 -0
  41. package/dist/use-cache.d.cts +3 -3
  42. package/dist/use-cache.d.ts +3 -3
  43. package/dist/use-cache.js +2 -2
  44. package/package.json +1 -1
package/dist/next.d.cts CHANGED
@@ -1,13 +1,13 @@
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-BrrGgkgQ.cjs';
3
- export { c as HyleCommentsFallback } from './embed-BrrGgkgQ.cjs';
4
- import { F as FetchResolverOptions, H as HyleResolver } from './resolve-Ce_yz8gC.cjs';
5
- export { f as fetchResolver, w as workspaceTags } from './resolve-Ce_yz8gC.cjs';
2
+ import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, S as ShareHost, b as EmbedHeading } from './brand-IuZSB9UX.cjs';
3
+ export { c as HyleCommentsFallback } from './brand-IuZSB9UX.cjs';
4
+ import { F as FetchResolverOptions, H as HyleResolver } from './resolve-0nGnsIHo.cjs';
5
+ export { f as fetchResolver, w as workspaceTags } from './resolve-0nGnsIHo.cjs';
6
6
  import { MetadataRoute, ResolvingMetadata, Metadata } from 'next';
7
- import { R as RevalidationCallbackOptions, b as RevalidationCallbackRoute } from './revalidation-callback-BQl77tQR.cjs';
8
- import { c as HyleCredential } from './client-CI-3cHtc.cjs';
7
+ import { R as RevalidationCallbackOptions, b as RevalidationCallbackRoute } from './revalidation-callback-FT9ik1dh.cjs';
8
+ import { c as HyleCredential } from './client-DBZTvcCh.cjs';
9
9
  import { NextRequest, NextResponse } from 'next/server';
10
- import './types-CxE8kLeo.cjs';
10
+ import './types-CdaIzSjg.cjs';
11
11
 
12
12
  type RouteParams = Record<string, string | string[] | undefined>;
13
13
  interface CommonOptions {
@@ -222,6 +222,16 @@ interface RevalidateRouteOptions {
222
222
  readonly secrets: readonly (string | undefined)[];
223
223
  /** Comment notifications, see `RevalidationCallbackOptions.onCommentEvent`. */
224
224
  readonly onCommentEvent?: RevalidationCallbackOptions["onCommentEvent"];
225
+ /**
226
+ * Tell search engines (IndexNow) about the addresses a publish changed. Submits only in production and only with a key.
227
+ * The origin is this option's alone, never the payload's, and must be a bare https origin (else logged and off).
228
+ * `localePrefix` is the host's, as in `hylePage` (docs/cp1-spec.md section 5.3.5).
229
+ */
230
+ readonly indexNow?: {
231
+ readonly origin: string;
232
+ readonly key: string | undefined;
233
+ readonly localePrefix?: (locale: string) => string;
234
+ };
225
235
  /** Environment to read the site switch from. Default process.env. */
226
236
  readonly env?: Readonly<Record<string, string | undefined>>;
227
237
  }
@@ -247,6 +257,8 @@ type HyleRootConfig = Omit<Extract<HyleNextOptions, {
247
257
  * (a given `list` or `jsonLd` replaces the config's whole value). Lets one mount carry its own `titleTemplate`, `ogImage`, `jsonLd`, `list` or `siteOrigin`.
248
258
  */
249
259
  readonly mountOptions?: Readonly<Record<string, Partial<Pick<CommonOptions, "titleTemplate" | "list" | "ogImage" | "jsonLd" | "siteOrigin">>>>;
260
+ /** The host's logo and name in a protected share's bar (`chrome.brand` is the slot alternative). Only protected shares read it. */
261
+ readonly host?: ShareHost;
250
262
  };
251
263
  type Configs = HyleRootConfig | readonly HyleRootConfig[];
252
264
  /** How long a mounts copy that could not be refreshed may still be used. Past this a transient failure is rethrown. */
@@ -546,10 +558,11 @@ declare function hylePreviewPage(options: HylePreviewPageOptions): (props: PageP
546
558
  declare const hyleProtectedMetadata: Metadata;
547
559
  /**
548
560
  * `export const { POST } = createProtectedUnlockRoute()` in `app/hyle-protected/unlock/route.ts` (ADR 0040). The password form
549
- * posts `slug` and `password` here; the route sets the password in the share's HttpOnly cookie (scoped to `/<slug>` and to the asset route, so no other request of the host carries it) and sends the visitor to `/<slug>`,
550
- * where the page checks it with hyle. It never calls hyle, so a view is one open. Only a same-origin POST with a form body of at
551
- * most 1 KiB is read. The cookie is set only for a password of the right shape, and the redirect target is built from the
552
- * validated slug alone.
561
+ * posts `slug`, `password` and the optional `docSlug` here; the Lock button posts `slug` and `lock=1`. A password sets the share's
562
+ * HttpOnly cookie (scoped to `/<slug>` and the asset route, so no other request of the host carries it) and sends the visitor to
563
+ * the share, where the page checks it with hyle. `lock=1` clears that cookie on both paths and sends the visitor to the gate with
564
+ * `?locked=1`. It never calls hyle, so a view is one open. Only a same-origin POST with a form body of at most 1 KiB is read, and
565
+ * the redirect is built from the validated slugs alone.
553
566
  */
554
567
  declare function createProtectedUnlockRoute(): {
555
568
  POST: (req: Request) => Promise<Response>;
@@ -582,6 +595,9 @@ declare function hyleProtectedPage(options: Configs, { clientIp }?: {
582
595
  readonly params: Promise<{
583
596
  readonly path?: string[];
584
597
  }>;
598
+ readonly searchParams?: Promise<{
599
+ readonly locked?: string | string[];
600
+ }>;
585
601
  }) => Promise<ReactElement>;
586
602
 
587
603
  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, hyleProtectedProxy, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap, markdownRewritePath };
package/dist/next.d.ts CHANGED
@@ -1,13 +1,13 @@
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-BaLQbE_n.js';
3
- export { c as HyleCommentsFallback } from './embed-BaLQbE_n.js';
4
- import { F as FetchResolverOptions, H as HyleResolver } from './resolve-DMHbYyTS.js';
5
- export { f as fetchResolver, w as workspaceTags } from './resolve-DMHbYyTS.js';
2
+ import { A as ArticleRef, O as OgImage, J as JsonLdConfig, H as HyleComponents, a as HyleSlots, E as EngagementConfig, S as ShareHost, b as EmbedHeading } from './brand-CwXvdSkk.js';
3
+ export { c as HyleCommentsFallback } from './brand-CwXvdSkk.js';
4
+ import { F as FetchResolverOptions, H as HyleResolver } from './resolve-CguSaZLa.js';
5
+ export { f as fetchResolver, w as workspaceTags } from './resolve-CguSaZLa.js';
6
6
  import { MetadataRoute, ResolvingMetadata, Metadata } from 'next';
7
- import { R as RevalidationCallbackOptions, b as RevalidationCallbackRoute } from './revalidation-callback-BQl77tQR.js';
8
- import { c as HyleCredential } from './client-DN38IP63.js';
7
+ import { R as RevalidationCallbackOptions, b as RevalidationCallbackRoute } from './revalidation-callback-FT9ik1dh.js';
8
+ import { c as HyleCredential } from './client-B2zi_BGq.js';
9
9
  import { NextRequest, NextResponse } from 'next/server';
10
- import './types-CxE8kLeo.js';
10
+ import './types-CdaIzSjg.js';
11
11
 
12
12
  type RouteParams = Record<string, string | string[] | undefined>;
13
13
  interface CommonOptions {
@@ -222,6 +222,16 @@ interface RevalidateRouteOptions {
222
222
  readonly secrets: readonly (string | undefined)[];
223
223
  /** Comment notifications, see `RevalidationCallbackOptions.onCommentEvent`. */
224
224
  readonly onCommentEvent?: RevalidationCallbackOptions["onCommentEvent"];
225
+ /**
226
+ * Tell search engines (IndexNow) about the addresses a publish changed. Submits only in production and only with a key.
227
+ * The origin is this option's alone, never the payload's, and must be a bare https origin (else logged and off).
228
+ * `localePrefix` is the host's, as in `hylePage` (docs/cp1-spec.md section 5.3.5).
229
+ */
230
+ readonly indexNow?: {
231
+ readonly origin: string;
232
+ readonly key: string | undefined;
233
+ readonly localePrefix?: (locale: string) => string;
234
+ };
225
235
  /** Environment to read the site switch from. Default process.env. */
226
236
  readonly env?: Readonly<Record<string, string | undefined>>;
227
237
  }
@@ -247,6 +257,8 @@ type HyleRootConfig = Omit<Extract<HyleNextOptions, {
247
257
  * (a given `list` or `jsonLd` replaces the config's whole value). Lets one mount carry its own `titleTemplate`, `ogImage`, `jsonLd`, `list` or `siteOrigin`.
248
258
  */
249
259
  readonly mountOptions?: Readonly<Record<string, Partial<Pick<CommonOptions, "titleTemplate" | "list" | "ogImage" | "jsonLd" | "siteOrigin">>>>;
260
+ /** The host's logo and name in a protected share's bar (`chrome.brand` is the slot alternative). Only protected shares read it. */
261
+ readonly host?: ShareHost;
250
262
  };
251
263
  type Configs = HyleRootConfig | readonly HyleRootConfig[];
252
264
  /** How long a mounts copy that could not be refreshed may still be used. Past this a transient failure is rethrown. */
@@ -546,10 +558,11 @@ declare function hylePreviewPage(options: HylePreviewPageOptions): (props: PageP
546
558
  declare const hyleProtectedMetadata: Metadata;
547
559
  /**
548
560
  * `export const { POST } = createProtectedUnlockRoute()` in `app/hyle-protected/unlock/route.ts` (ADR 0040). The password form
549
- * posts `slug` and `password` here; the route sets the password in the share's HttpOnly cookie (scoped to `/<slug>` and to the asset route, so no other request of the host carries it) and sends the visitor to `/<slug>`,
550
- * where the page checks it with hyle. It never calls hyle, so a view is one open. Only a same-origin POST with a form body of at
551
- * most 1 KiB is read. The cookie is set only for a password of the right shape, and the redirect target is built from the
552
- * validated slug alone.
561
+ * posts `slug`, `password` and the optional `docSlug` here; the Lock button posts `slug` and `lock=1`. A password sets the share's
562
+ * HttpOnly cookie (scoped to `/<slug>` and the asset route, so no other request of the host carries it) and sends the visitor to
563
+ * the share, where the page checks it with hyle. `lock=1` clears that cookie on both paths and sends the visitor to the gate with
564
+ * `?locked=1`. It never calls hyle, so a view is one open. Only a same-origin POST with a form body of at most 1 KiB is read, and
565
+ * the redirect is built from the validated slugs alone.
553
566
  */
554
567
  declare function createProtectedUnlockRoute(): {
555
568
  POST: (req: Request) => Promise<Response>;
@@ -582,6 +595,9 @@ declare function hyleProtectedPage(options: Configs, { clientIp }?: {
582
595
  readonly params: Promise<{
583
596
  readonly path?: string[];
584
597
  }>;
598
+ readonly searchParams?: Promise<{
599
+ readonly locked?: string | string[];
600
+ }>;
585
601
  }) => Promise<ReactElement>;
586
602
 
587
603
  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, hyleProtectedProxy, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap, markdownRewritePath };
package/dist/next.js CHANGED
@@ -9,6 +9,10 @@ import {
9
9
  HyleListView,
10
10
  ListPage,
11
11
  REACTION_KINDS,
12
+ SIDE_COOKIE,
13
+ ShareChrome,
14
+ ShareGate,
15
+ THEME_COOKIE,
12
16
  absoluteUrl,
13
17
  articleAuthor,
14
18
  bareOrigin,
@@ -17,17 +21,18 @@ import {
17
21
  modifiedAt,
18
22
  parseListing,
19
23
  readingMinutes,
24
+ themeFromCookie,
20
25
  validOgImage,
21
26
  wordCountOf
22
- } from "./chunk-5TKJH2XC.js";
27
+ } from "./chunk-NUQQ6VHH.js";
23
28
  import {
24
29
  stringsFor
25
- } from "./chunk-Y3BACEWA.js";
30
+ } from "./chunk-T4EZAQFU.js";
26
31
  import {
27
32
  DEFAULT_REVALIDATE,
28
33
  fetchResolver,
29
34
  workspaceTags
30
- } from "./chunk-O4QWHXVH.js";
35
+ } from "./chunk-IDBQSMWT.js";
31
36
  import {
32
37
  Cp1ClientError,
33
38
  checkBaseUrl,
@@ -40,7 +45,7 @@ import {
40
45
  listPublicationPaths,
41
46
  readCapped,
42
47
  signReaderAssertion
43
- } from "./chunk-RCK4NCYC.js";
48
+ } from "./chunk-3UQGU62T.js";
44
49
  import {
45
50
  ASSET_CONTENT_TYPES,
46
51
  ASSET_FILE,
@@ -456,8 +461,8 @@ async function HyleList({ options, limit = 5, locale, layout, title, headingLeve
456
461
  const route = routeContext(locale ? { ...options, locale } : options, {});
457
462
  const path = sitePathFrom(route.basePath, void 0);
458
463
  if (path === void 0) return null;
459
- const after = validCursor(cursor);
460
- const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit, after), after);
464
+ const after2 = validCursor(cursor);
465
+ const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit, after2), after2);
461
466
  if (failure !== void 0) return failure;
462
467
  const next = olderHref && result?.kind === "list" ? validCursor(result.next_cursor) : void 0;
463
468
  return /* @__PURE__ */ jsx(HyleListView, { items: result?.kind === "list" ? result.items : [], theme: result?.kind === "list" ? result.theme : void 0, layout, title, headingLevel, moreHref, olderHref: next ? olderHref?.(next) : void 0, components: options.components, slots: options.slots, locale: route.locale, toHref: route.toHref });
@@ -778,10 +783,62 @@ async function hyleFeed(options) {
778
783
  }
779
784
 
780
785
  // src/next/revalidate.ts
786
+ import { after } from "next/server";
781
787
  import { revalidateTag } from "next/cache";
788
+
789
+ // src/indexnow.ts
790
+ var INDEXNOW_ENDPOINT = "https://api.indexnow.org/indexnow";
791
+ var ATTEMPTS = 3;
792
+ var TIMEOUT_MS = 3e3;
793
+ var RETRY_DELAY_MS = 500;
794
+ async function submitIndexNow(site, urls) {
795
+ try {
796
+ const base = new URL(site.origin);
797
+ const prefix = site.localePrefix ?? (() => "");
798
+ const urlList = urls.map((url) => new URL(encodeURI((url.locale ? prefix(url.locale) : "") + url.path.normalize("NFC")), base)).filter((url) => url.origin === base.origin).map((url) => url.href);
799
+ if (urlList.length === 0) return;
800
+ const body = JSON.stringify({ host: base.host, key: site.key, urlList });
801
+ let status;
802
+ for (let attempt = 1; attempt <= ATTEMPTS; attempt++) {
803
+ status = await postOnce(body);
804
+ if (status !== void 0 && status < 500) break;
805
+ if (attempt < ATTEMPTS) await new Promise((resolve) => setTimeout(resolve, RETRY_DELAY_MS));
806
+ }
807
+ console.log(`hyle: IndexNow ${status ?? "no answer"} for ${urlList.length} url(s) on ${base.host}`);
808
+ } catch (error) {
809
+ console.error("hyle: IndexNow not submitted", error instanceof Error ? error.name : "unknown");
810
+ }
811
+ }
812
+ async function postOnce(body) {
813
+ try {
814
+ const res = await fetch(INDEXNOW_ENDPOINT, {
815
+ method: "POST",
816
+ headers: { "Content-Type": "application/json; charset=utf-8" },
817
+ body,
818
+ signal: AbortSignal.timeout(TIMEOUT_MS)
819
+ });
820
+ await res.body?.cancel().catch(() => void 0);
821
+ return res.status;
822
+ } catch {
823
+ return void 0;
824
+ }
825
+ }
826
+
827
+ // src/next/revalidate.ts
782
828
  var isSwitchedOff2 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
829
+ function indexNowSite(option) {
830
+ const key = option?.key?.trim();
831
+ if (!option || !key) return void 0;
832
+ try {
833
+ return { origin: httpsOrigin(option.origin), key, localePrefix: option.localePrefix };
834
+ } catch {
835
+ console.error("hyle: IndexNow disabled, origin is not a bare https origin");
836
+ return void 0;
837
+ }
838
+ }
783
839
  function createRevalidateRoute(options) {
784
840
  let cached;
841
+ const indexNow = indexNowSite(options.indexNow);
785
842
  return {
786
843
  async POST(req) {
787
844
  if (isSwitchedOff2((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return new Response(null, { status: 404 });
@@ -791,7 +848,19 @@ function createRevalidateRoute(options) {
791
848
  if (!workspaceId || secrets.length === 0) return new Response(null, { status: 503 });
792
849
  const key = `${workspaceId}\0${secrets.join("\0")}`;
793
850
  if (cached?.key !== key) {
794
- cached = { key, route: createRevalidationCallbackRoute({ workspaceId, secrets, revalidateTag: (tag2) => revalidateTag(tag2, { expire: 0 }), onCommentEvent: options.onCommentEvent }) };
851
+ cached = {
852
+ key,
853
+ route: createRevalidationCallbackRoute({
854
+ workspaceId,
855
+ secrets,
856
+ revalidateTag: (tag2) => revalidateTag(tag2, { expire: 0 }),
857
+ onCommentEvent: options.onCommentEvent,
858
+ onIndexUrls: (urls) => {
859
+ const env = options.env ?? process.env;
860
+ if (indexNow && (env.VERCEL_ENV ?? env.NODE_ENV) === "production") after(() => submitIndexNow(indexNow, urls));
861
+ }
862
+ })
863
+ };
795
864
  }
796
865
  return cached.route.POST(req);
797
866
  }
@@ -799,7 +868,7 @@ function createRevalidateRoute(options) {
799
868
  }
800
869
 
801
870
  // src/next/root.ts
802
- import { notFound as notFound4, unstable_rethrow as unstable_rethrow4 } from "next/navigation";
871
+ import { notFound as notFound3, unstable_rethrow as unstable_rethrow4 } from "next/navigation";
803
872
 
804
873
  // src/next/mount-match.ts
805
874
  function activeMounts(mounts) {
@@ -827,144 +896,104 @@ function isReserved(path, reserved) {
827
896
 
828
897
  // src/next/protected.tsx
829
898
  import { cookies } from "next/headers";
830
- import { notFound as notFound3 } from "next/navigation";
831
-
832
- // src/next/preview.tsx
833
899
  import { notFound as notFound2 } from "next/navigation";
834
900
  import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
835
- function drawArticle(article, options) {
836
- const { locale } = article.publication;
837
- const toHref = (sitePath, linkLocale = locale) => (options.localePrefix?.(linkLocale) ?? "") + sitePath;
838
- const props = { article, components: options.components, slots: options.slots, locale, toHref };
839
- return options.layout === "docs" ? /* @__PURE__ */ jsx3(DocsPage, { ...props }) : /* @__PURE__ */ jsx3(ArticlePage, { ...props });
840
- }
841
- var hylePreviewMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
842
- var BANNER = {
843
- position: "sticky",
844
- top: 0,
845
- zIndex: 2147483647,
846
- padding: "8px 16px",
847
- background: "#fde047",
848
- color: "#1a1a1a",
849
- font: "600 14px/1.4 system-ui, sans-serif",
850
- textAlign: "center"
851
- };
852
- function hylePreviewPage(options) {
853
- return async function HylePreviewPage({ searchParams }) {
854
- const { token } = await searchParams ?? {};
855
- const result = await createHyleClient(options).preview(typeof token === "string" ? token : void 0);
856
- if (result.kind !== "preview") notFound2();
857
- return /* @__PURE__ */ jsxs(Fragment, { children: [
858
- /* @__PURE__ */ jsx3("meta", { name: "robots", content: "noindex, nofollow" }),
859
- /* @__PURE__ */ jsx3("meta", { name: "referrer", content: "no-referrer" }),
860
- /* @__PURE__ */ jsx3("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
861
- drawArticle(result.article, options)
862
- ] });
863
- };
864
- }
865
-
866
- // src/next/protected.tsx
867
- import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
868
901
  var hyleProtectedMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
869
902
  var COOKIE_MAX_AGE_SECONDS = 12 * 60 * 60;
870
903
  var UNLOCK_MAX_BYTES = 1024;
871
904
  var PRIVATE_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
872
905
  var UNLOCK_PATH = "/hyle-protected/unlock";
873
- var PASSWORD_FIELD = "hyle-protected-password";
874
- var ERROR_ID = "hyle-protected-error";
875
- function PasswordForm({ slug, failed }) {
876
- return /* @__PURE__ */ jsxs2("main", { children: [
877
- /* @__PURE__ */ jsx4("h1", { children: "Password required" }),
878
- /* @__PURE__ */ jsxs2("form", { method: "post", action: UNLOCK_PATH, autoComplete: "off", children: [
879
- /* @__PURE__ */ jsx4("input", { type: "hidden", name: "slug", value: slug }),
880
- /* @__PURE__ */ jsx4("label", { htmlFor: PASSWORD_FIELD, children: "Password" }),
881
- /* @__PURE__ */ jsx4(
882
- "input",
883
- {
884
- id: PASSWORD_FIELD,
885
- name: "password",
886
- type: "password",
887
- autoComplete: "off",
888
- spellCheck: false,
889
- required: true,
890
- minLength: 12,
891
- maxLength: 128,
892
- "aria-invalid": failed || void 0,
893
- "aria-describedby": failed ? ERROR_ID : void 0
894
- }
895
- ),
896
- /* @__PURE__ */ jsx4("button", { type: "submit", children: "Open" }),
897
- failed ? /* @__PURE__ */ jsx4("p", { id: ERROR_ID, role: "alert", children: "Wrong or expired password." }) : null
898
- ] })
899
- ] });
906
+ var DOC_SLUG = /^[a-z0-9-]{1,200}$/;
907
+ var PRIVATE_META = /* @__PURE__ */ jsxs(Fragment, { children: [
908
+ /* @__PURE__ */ jsx3("meta", { name: "robots", content: "noindex, nofollow" }),
909
+ /* @__PURE__ */ jsx3("meta", { name: "referrer", content: "no-referrer" })
910
+ ] });
911
+ function gate(state, slug, retryAfterSeconds, host) {
912
+ return /* @__PURE__ */ jsx3(ShareGate, { state, slug, unlockAction: UNLOCK_PATH, retryAfterSeconds, host });
900
913
  }
901
- function TooManyAttempts({ seconds }) {
902
- return /* @__PURE__ */ jsxs2("main", { children: [
903
- /* @__PURE__ */ jsx4("h1", { children: "Too many attempts, try again later" }),
904
- /* @__PURE__ */ jsxs2("p", { role: "alert", children: [
905
- "Try again in ",
906
- seconds,
907
- " ",
908
- seconds === 1 ? "second" : "seconds",
909
- "."
910
- ] })
911
- ] });
914
+ async function visitorPrefs() {
915
+ const jar = await cookies();
916
+ return { theme: themeFromCookie(jar.get(THEME_COOKIE)?.value), sidebarOpen: jar.get(SIDE_COOKIE)?.value !== "closed" };
912
917
  }
913
- var PRIVATE_META = /* @__PURE__ */ jsxs2(Fragment2, { children: [
914
- /* @__PURE__ */ jsx4("meta", { name: "robots", content: "noindex, nofollow" }),
915
- /* @__PURE__ */ jsx4("meta", { name: "referrer", content: "no-referrer" })
916
- ] });
917
- async function drawProtectedShare(options, slug, docSlug, clientIp) {
918
+ async function drawProtectedShare(options, slug, docSlug, clientIp, { locked = false } = {}) {
918
919
  const client = createHyleClient({ baseUrl: options.baseUrl, token: options.token });
919
920
  const visitor = { clientIp };
920
921
  const password = (await cookies()).get(await protectedCookieName(slug))?.value;
921
922
  const share = password === void 0 ? void 0 : await client.protected(slug, password, docSlug, visitor);
922
- if (share?.kind === "limited") return /* @__PURE__ */ jsxs2(Fragment2, { children: [
923
+ if (share?.kind === "limited") return /* @__PURE__ */ jsxs(Fragment, { children: [
923
924
  PRIVATE_META,
924
- /* @__PURE__ */ jsx4(TooManyAttempts, { seconds: share.retryAfterSeconds })
925
+ gate("attempts", slug, share.retryAfterSeconds, options.host)
925
926
  ] });
926
- if (share?.kind === "disabled") notFound3();
927
+ if (share?.kind === "disabled") notFound2();
927
928
  if (share?.kind === "protected") {
928
- if (docSlug !== void 0 && share.doc_slug !== docSlug) notFound3();
929
- const here = `/${slug}/${share.doc_slug}`;
930
- const article = {
931
- ...share.article,
932
- publication: { ...share.article.publication, canonical_path: here },
933
- nav: { truncated: false, items: share.documents.map((d) => ({ slug: d.doc_slug, title: d.title, canonical_path: `/${slug}/${d.doc_slug}`, children: [] })) }
934
- };
935
- return /* @__PURE__ */ jsxs2(Fragment2, { children: [
929
+ if (docSlug !== void 0 && share.doc_slug !== docSlug) notFound2();
930
+ const article = { ...share.article, publication: { ...share.article.publication, canonical_path: `/${slug}/${share.doc_slug}` } };
931
+ const { theme: theme2, sidebarOpen } = await visitorPrefs();
932
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
936
933
  PRIVATE_META,
937
- drawArticle(article, { ...options, layout: share.documents.length > 1 ? "docs" : "article" })
934
+ /* @__PURE__ */ jsx3(
935
+ ShareChrome,
936
+ {
937
+ name: share.name,
938
+ expiresAt: share.expires_at,
939
+ documents: share.documents,
940
+ article,
941
+ docSlug: share.doc_slug,
942
+ host: options.host,
943
+ theme: theme2,
944
+ sidebarOpen,
945
+ slots: options.slots,
946
+ components: options.components,
947
+ hrefFor: (doc) => `/${slug}/${doc}`,
948
+ lockAction: UNLOCK_PATH,
949
+ slug
950
+ }
951
+ )
938
952
  ] });
939
953
  }
940
- const gate = await client.protectedGate(slug, visitor);
941
- if (gate.kind === "limited") return /* @__PURE__ */ jsxs2(Fragment2, { children: [
954
+ const gateReply = await client.protectedGate(slug, visitor);
955
+ if (gateReply.kind === "limited") return /* @__PURE__ */ jsxs(Fragment, { children: [
942
956
  PRIVATE_META,
943
- /* @__PURE__ */ jsx4(TooManyAttempts, { seconds: gate.retryAfterSeconds })
957
+ gate("attempts", slug, gateReply.retryAfterSeconds, options.host)
944
958
  ] });
945
- if (gate.kind !== "gate") notFound3();
946
- return /* @__PURE__ */ jsxs2(Fragment2, { children: [
959
+ if (gateReply.kind !== "gate") notFound2();
960
+ const { theme } = await visitorPrefs();
961
+ const state = locked ? "locked" : password !== void 0 ? "wrong" : "password";
962
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
947
963
  PRIVATE_META,
948
- /* @__PURE__ */ jsx4(PasswordForm, { slug, failed: password !== void 0 })
964
+ /* @__PURE__ */ jsx3(ShareGate, { state, slug, docSlug, unlockAction: UNLOCK_PATH, host: options.host, theme })
949
965
  ] });
950
966
  }
967
+ async function readProtectedForm(req) {
968
+ const site = req.headers.get("sec-fetch-site");
969
+ if (site === null ? originMismatch(req) : site !== "same-origin") return new Response(null, { status: 403, headers: PRIVATE_HEADERS });
970
+ if (!/^application\/x-www-form-urlencoded(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return new Response(null, { status: 415, headers: PRIVATE_HEADERS });
971
+ if (Number(req.headers.get("content-length")) > UNLOCK_MAX_BYTES) return new Response(null, { status: 413, headers: PRIVATE_HEADERS });
972
+ const form = await readCapped(new Response(req.body), UNLOCK_MAX_BYTES).catch(() => void 0);
973
+ if (form === void 0) return new Response(null, { status: 413, headers: PRIVATE_HEADERS });
974
+ return new URLSearchParams(form);
975
+ }
976
+ function sharePaths(slug) {
977
+ return [`/${slug}`, ASSET_ROUTE_PREFIX];
978
+ }
951
979
  function createProtectedUnlockRoute() {
952
980
  return {
953
981
  async POST(req) {
954
- const site = req.headers.get("sec-fetch-site");
955
- if (site === null ? originMismatch(req) : site !== "same-origin") return new Response(null, { status: 403, headers: PRIVATE_HEADERS });
956
- if (!/^application\/x-www-form-urlencoded(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return new Response(null, { status: 415, headers: PRIVATE_HEADERS });
957
- if (Number(req.headers.get("content-length")) > UNLOCK_MAX_BYTES) return new Response(null, { status: 413, headers: PRIVATE_HEADERS });
958
- const form = await readCapped(new Response(req.body), UNLOCK_MAX_BYTES).catch(() => void 0);
959
- if (form === void 0) return new Response(null, { status: 413, headers: PRIVATE_HEADERS });
960
- const fields = new URLSearchParams(form);
982
+ const fields = await readProtectedForm(req);
983
+ if (fields instanceof Response) return fields;
961
984
  const slug = fields.get("slug") ?? "";
962
985
  if (!PROTECTED_SLUG.test(slug)) return new Response(null, { status: 404, headers: PRIVATE_HEADERS });
986
+ const name = await protectedCookieName(slug);
987
+ if (fields.get("lock") === "1") {
988
+ const headers3 = new Headers({ ...PRIVATE_HEADERS, Location: `/${slug}?locked=1` });
989
+ for (const path of sharePaths(slug)) headers3.append("Set-Cookie", `${name}=; Max-Age=0; Path=${path}; HttpOnly; Secure; SameSite=Lax`);
990
+ return new Response(null, { status: 303, headers: headers3 });
991
+ }
992
+ const doc = fields.get("docSlug") ?? "";
993
+ const headers2 = new Headers({ ...PRIVATE_HEADERS, Location: DOC_SLUG.test(doc) ? `/${slug}/${doc}` : `/${slug}` });
963
994
  const password = fields.get("password") ?? "";
964
- const headers2 = new Headers({ ...PRIVATE_HEADERS, Location: `/${slug}` });
965
995
  if (PROTECTED_PASSWORD.test(password)) {
966
- const name = await protectedCookieName(slug);
967
- for (const path of [`/${slug}`, ASSET_ROUTE_PREFIX]) headers2.append("Set-Cookie", `${name}=${password}; Max-Age=${COOKIE_MAX_AGE_SECONDS}; Path=${path}; HttpOnly; Secure; SameSite=Lax`);
996
+ for (const path of sharePaths(slug)) headers2.append("Set-Cookie", `${name}=${password}; Max-Age=${COOKIE_MAX_AGE_SECONDS}; Path=${path}; HttpOnly; Secure; SameSite=Lax`);
968
997
  }
969
998
  return new Response(null, { status: 303, headers: headers2 });
970
999
  }
@@ -1099,10 +1128,10 @@ function createRouter(options, make, share) {
1099
1128
  };
1100
1129
  }
1101
1130
  function hyleRootPage(options) {
1102
- const route = createRouter(options, hylePage, () => async () => notFound4());
1131
+ const route = createRouter(options, hylePage, () => async () => notFound3());
1103
1132
  return async function HyleRootPage({ params, searchParams }) {
1104
1133
  const hit = await route(await params ?? {});
1105
- if (!hit) notFound4();
1134
+ if (!hit) notFound3();
1106
1135
  return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
1107
1136
  };
1108
1137
  }
@@ -1331,7 +1360,7 @@ function createAssetRoute(options) {
1331
1360
  }
1332
1361
 
1333
1362
  // src/next/og.tsx
1334
- import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
1363
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
1335
1364
  var SIZE = { width: 1200, height: 630 };
1336
1365
  var MAX_TITLE = 140;
1337
1366
  function createOgImageRoute(options) {
@@ -1361,9 +1390,9 @@ function createOgImageRoute(options) {
1361
1390
  const chars = [...title];
1362
1391
  const shown = chars.length > MAX_TITLE ? `${chars.slice(0, MAX_TITLE - 1).join("")}\u2026` : title;
1363
1392
  return new ImageResponse(
1364
- /* @__PURE__ */ jsxs3("div", { style: { display: "flex", flexDirection: "column", justifyContent: "space-between", width: "100%", height: "100%", padding: 80, background: "#111827", color: "#ffffff" }, children: [
1365
- /* @__PURE__ */ jsx5("div", { style: { fontSize: 64, fontWeight: 700, lineHeight: 1.2 }, children: shown }),
1366
- options.siteName ? /* @__PURE__ */ jsx5("div", { style: { fontSize: 32, color: "#9ca3af" }, children: options.siteName }) : null
1393
+ /* @__PURE__ */ jsxs2("div", { style: { display: "flex", flexDirection: "column", justifyContent: "space-between", width: "100%", height: "100%", padding: 80, background: "#111827", color: "#ffffff" }, children: [
1394
+ /* @__PURE__ */ jsx4("div", { style: { fontSize: 64, fontWeight: 700, lineHeight: 1.2 }, children: shown }),
1395
+ options.siteName ? /* @__PURE__ */ jsx4("div", { style: { fontSize: 32, color: "#9ca3af" }, children: options.siteName }) : null
1367
1396
  ] }),
1368
1397
  // shortcut: @vercel/og fetches Google Fonts / emoji assets at render time for non-Latin titles and emoji (no switch to disable it), upgrade to a satori render with bundled fonts if a host needs zero egress.
1369
1398
  { ...SIZE, headers: { "cache-control": "public, max-age=3600, s-maxage=31536000, immutable" } }
@@ -1372,6 +1401,40 @@ function createOgImageRoute(options) {
1372
1401
  };
1373
1402
  }
1374
1403
 
1404
+ // src/next/preview.tsx
1405
+ import { notFound as notFound4 } from "next/navigation";
1406
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
1407
+ function drawArticle(article, options) {
1408
+ const { locale } = article.publication;
1409
+ const toHref = (sitePath, linkLocale = locale) => (options.localePrefix?.(linkLocale) ?? "") + sitePath;
1410
+ const props = { article, components: options.components, slots: options.slots, locale, toHref };
1411
+ return options.layout === "docs" ? /* @__PURE__ */ jsx5(DocsPage, { ...props }) : /* @__PURE__ */ jsx5(ArticlePage, { ...props });
1412
+ }
1413
+ var hylePreviewMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
1414
+ var BANNER = {
1415
+ position: "sticky",
1416
+ top: 0,
1417
+ zIndex: 2147483647,
1418
+ padding: "8px 16px",
1419
+ background: "#fde047",
1420
+ color: "#1a1a1a",
1421
+ font: "600 14px/1.4 system-ui, sans-serif",
1422
+ textAlign: "center"
1423
+ };
1424
+ function hylePreviewPage(options) {
1425
+ return async function HylePreviewPage({ searchParams }) {
1426
+ const { token } = await searchParams ?? {};
1427
+ const result = await createHyleClient(options).preview(typeof token === "string" ? token : void 0);
1428
+ if (result.kind !== "preview") notFound4();
1429
+ return /* @__PURE__ */ jsxs3(Fragment2, { children: [
1430
+ /* @__PURE__ */ jsx5("meta", { name: "robots", content: "noindex, nofollow" }),
1431
+ /* @__PURE__ */ jsx5("meta", { name: "referrer", content: "no-referrer" }),
1432
+ /* @__PURE__ */ jsx5("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
1433
+ drawArticle(result.article, options)
1434
+ ] });
1435
+ };
1436
+ }
1437
+
1375
1438
  // src/next/protected-view.ts
1376
1439
  import { headers } from "next/headers";
1377
1440
  import { notFound as notFound5 } from "next/navigation";
@@ -1388,17 +1451,18 @@ function hyleProtectedProxy(options, { lookupTimeoutMs = DEFAULT_LOOKUP_TIMEOUT_
1388
1451
  let timer;
1389
1452
  const deadline = new Promise((resolve) => timer = setTimeout(resolve, lookupTimeoutMs));
1390
1453
  const hit = await Promise.race([mounts.locate(path).catch(() => void 0), deadline]).finally(() => clearTimeout(timer));
1391
- return hit && "share" in hit ? NextResponse.rewrite(new URL(`${VIEW_PATH}${path}`, req.url)) : void 0;
1454
+ return hit && "share" in hit ? NextResponse.rewrite(new URL(`${VIEW_PATH}${path}${req.nextUrl.search}`, req.url)) : void 0;
1392
1455
  };
1393
1456
  }
1394
1457
  var forwardedClientIp = (h) => h.get("x-forwarded-for")?.split(",")[0]?.trim() || h.get("x-real-ip")?.trim() || void 0;
1395
1458
  function hyleProtectedPage(options, { clientIp = forwardedClientIp } = {}) {
1396
1459
  const mounts = rootMounts(options);
1397
- return async function HyleProtectedPage({ params }) {
1460
+ return async function HyleProtectedPage({ params, searchParams }) {
1398
1461
  const path = `/${((await params).path ?? []).join("/")}`;
1399
1462
  const hit = SHARE_PATH.test(path) ? await mounts.locate(path) : void 0;
1400
1463
  if (!hit || !("share" in hit)) notFound5();
1401
- return drawProtectedShare(hit.share.config, hit.share.slug, hit.share.docSlug, clientIp(await headers()));
1464
+ const locked = (await searchParams)?.locked === "1";
1465
+ return drawProtectedShare(hit.share.config, hit.share.slug, hit.share.docSlug, clientIp(await headers()), { locked });
1402
1466
  };
1403
1467
  }
1404
1468
  export {