@tdacorp/hyle-sdk 0.22.2 → 0.24.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 +48 -1
- package/dist/check-routes-bin.js +41 -8
- package/dist/{chunk-KU7LWK4E.js → chunk-4REU4HJI.js} +40 -9
- package/dist/{chunk-ZIW6FDU2.js → chunk-5TKJH2XC.js} +2 -2
- package/dist/{chunk-DUPT6XLB.js → chunk-BDFMNY76.js} +18 -1
- package/dist/{chunk-7T5EEJHK.js → chunk-SY2FMIRZ.js} +1 -1
- package/dist/{chunk-IW3TUD4G.js → chunk-Y3BACEWA.js} +1 -1
- package/dist/{client-BGjmEWhN.d.cts → client-BErei7cE.d.ts} +8 -1
- package/dist/{client-D0LTpr3Y.d.ts → client-DrB2vcTi.d.cts} +8 -1
- package/dist/comments.cjs +5 -1
- package/dist/comments.js +5 -1
- package/dist/{embed-CbtsbZs3.d.cts → embed-B7T--kTT.d.cts} +1 -1
- package/dist/{embed-Cf_2ZR5x.d.ts → embed-DavTgSU4.d.ts} +1 -1
- package/dist/html.cjs +5 -1
- package/dist/html.js +2 -2
- package/dist/index.cjs +41 -8
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/next.cjs +265 -70
- package/dist/next.d.cts +47 -7
- package/dist/next.d.ts +47 -7
- package/dist/next.js +224 -65
- package/dist/react.cjs +5 -1
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -3
- package/dist/{resolve-BnIv7aB7.d.cts → resolve-03IVloXU.d.cts} +1 -1
- package/dist/{resolve-BysHtZ_i.d.ts → resolve-BseM68oy.d.ts} +1 -1
- package/dist/{types-D09Z072G.d.cts → types-Dx-fEiZd.d.cts} +33 -1
- package/dist/{types-D09Z072G.d.ts → types-Dx-fEiZd.d.ts} +33 -1
- package/dist/use-cache.cjs +41 -8
- package/dist/use-cache.d.cts +3 -3
- package/dist/use-cache.d.ts +3 -3
- package/dist/use-cache.js +3 -3
- package/package.json +1 -1
package/dist/next.d.cts
CHANGED
|
@@ -1,12 +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-
|
|
3
|
-
export { c as HyleCommentsFallback } from './embed-
|
|
4
|
-
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-
|
|
5
|
-
export { f as fetchResolver, w as workspaceTags } from './resolve-
|
|
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-B7T--kTT.cjs';
|
|
3
|
+
export { c as HyleCommentsFallback } from './embed-B7T--kTT.cjs';
|
|
4
|
+
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-03IVloXU.cjs';
|
|
5
|
+
export { f as fetchResolver, w as workspaceTags } from './resolve-03IVloXU.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-
|
|
9
|
-
import '
|
|
8
|
+
import { c as HyleCredential } from './client-DrB2vcTi.cjs';
|
|
9
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
10
|
+
import './types-Dx-fEiZd.cjs';
|
|
10
11
|
|
|
11
12
|
type RouteParams = Record<string, string | string[] | undefined>;
|
|
12
13
|
interface CommonOptions {
|
|
@@ -386,6 +387,10 @@ interface AssetRoute {
|
|
|
386
387
|
* Draft preview (hyle ADR 0037): `?hyle_preview=<token>`, which the preview page puts on its own images, is sent to hyle as a
|
|
387
388
|
* header so that draft's assets load; every such answer is `no-store`. The token is never sent for the theme stylesheet,
|
|
388
389
|
* which is the credential's own with or without it. No other query parameter is read.
|
|
390
|
+
*
|
|
391
|
+
* Protected share (hyle ADR 0040): `?hyle_protected=<slug>` takes the password from that share's cookie (`hyle_p_<hash of slug>`, set by
|
|
392
|
+
* `createProtectedUnlockRoute`) and forwards it as the `cp-protected` header. A missing or malformed cookie is a 404 that reaches
|
|
393
|
+
* nobody; every such answer is private and `no-store`, as a draft's is.
|
|
389
394
|
*/
|
|
390
395
|
declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
|
|
391
396
|
|
|
@@ -534,4 +539,39 @@ declare const hylePreviewMetadata: Metadata;
|
|
|
534
539
|
*/
|
|
535
540
|
declare function hylePreviewPage(options: HylePreviewPageOptions): (props: PageProps) => Promise<ReactElement>;
|
|
536
541
|
|
|
537
|
-
|
|
542
|
+
/**
|
|
543
|
+
* The `robots` and `referrer` of a protected share (hyle ADR 0040). The unlock form is same-origin by `Sec-Fetch-Site`, so
|
|
544
|
+
* `no-referrer` does not stop it. The URL carries no secret.
|
|
545
|
+
*/
|
|
546
|
+
declare const hyleProtectedMetadata: Metadata;
|
|
547
|
+
/**
|
|
548
|
+
* `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.
|
|
553
|
+
*/
|
|
554
|
+
declare function createProtectedUnlockRoute(): {
|
|
555
|
+
POST: (req: Request) => Promise<Response>;
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* For a host whose catch-all is static or ISR (`revalidate`, `generateStaticParams`): reading the visitor's cookie there is a 500
|
|
560
|
+
* (`DYNAMIC_SERVER_USAGE`), so a share is drawn by a dynamic route instead. In the host's `proxy.ts`:
|
|
561
|
+
* `const share = hyleProtectedProxy(configs); export async function proxy(req) { return (await share(req)) ?? NextResponse.next(); }`.
|
|
562
|
+
* A path under a live share slug is REWRITTEN to `/hyle-protected/view/<path>` (the visitor's URL does not change); every other
|
|
563
|
+
* request returns undefined, so the host's ordinary pages stay cached. A proxy has no fetch cache, so it keeps ONE read of hyle's
|
|
564
|
+
* mounts per config in memory for 30 seconds (shared by concurrent requests, the last good copy used when a refresh fails) and
|
|
565
|
+
* matches every path against it locally: random paths never cost a call to hyle. The page behind the rewrite checks again through
|
|
566
|
+
* the usual mounts cache. A mounts read that fails with no copy counts as "not a share" for those 30 seconds rather than erroring
|
|
567
|
+
* every request of the host.
|
|
568
|
+
*/
|
|
569
|
+
declare function hyleProtectedProxy(options: Configs): (req: NextRequest) => Promise<NextResponse | undefined>;
|
|
570
|
+
/** The page of `app/hyle-protected/view/[[...path]]/page.tsx` (see `hyleProtectedProxy`): the share under the path, else `notFound()`. */
|
|
571
|
+
declare function hyleProtectedPage(options: Configs): (props: {
|
|
572
|
+
readonly params: Promise<{
|
|
573
|
+
readonly path?: string[];
|
|
574
|
+
}>;
|
|
575
|
+
}) => Promise<ReactElement>;
|
|
576
|
+
|
|
577
|
+
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,12 +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-
|
|
3
|
-
export { c as HyleCommentsFallback } from './embed-
|
|
4
|
-
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-
|
|
5
|
-
export { f as fetchResolver, w as workspaceTags } from './resolve-
|
|
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-DavTgSU4.js';
|
|
3
|
+
export { c as HyleCommentsFallback } from './embed-DavTgSU4.js';
|
|
4
|
+
import { F as FetchResolverOptions, H as HyleResolver } from './resolve-BseM68oy.js';
|
|
5
|
+
export { f as fetchResolver, w as workspaceTags } from './resolve-BseM68oy.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-
|
|
9
|
-
import '
|
|
8
|
+
import { c as HyleCredential } from './client-BErei7cE.js';
|
|
9
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
10
|
+
import './types-Dx-fEiZd.js';
|
|
10
11
|
|
|
11
12
|
type RouteParams = Record<string, string | string[] | undefined>;
|
|
12
13
|
interface CommonOptions {
|
|
@@ -386,6 +387,10 @@ interface AssetRoute {
|
|
|
386
387
|
* Draft preview (hyle ADR 0037): `?hyle_preview=<token>`, which the preview page puts on its own images, is sent to hyle as a
|
|
387
388
|
* header so that draft's assets load; every such answer is `no-store`. The token is never sent for the theme stylesheet,
|
|
388
389
|
* which is the credential's own with or without it. No other query parameter is read.
|
|
390
|
+
*
|
|
391
|
+
* Protected share (hyle ADR 0040): `?hyle_protected=<slug>` takes the password from that share's cookie (`hyle_p_<hash of slug>`, set by
|
|
392
|
+
* `createProtectedUnlockRoute`) and forwards it as the `cp-protected` header. A missing or malformed cookie is a 404 that reaches
|
|
393
|
+
* nobody; every such answer is private and `no-store`, as a draft's is.
|
|
389
394
|
*/
|
|
390
395
|
declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
|
|
391
396
|
|
|
@@ -534,4 +539,39 @@ declare const hylePreviewMetadata: Metadata;
|
|
|
534
539
|
*/
|
|
535
540
|
declare function hylePreviewPage(options: HylePreviewPageOptions): (props: PageProps) => Promise<ReactElement>;
|
|
536
541
|
|
|
537
|
-
|
|
542
|
+
/**
|
|
543
|
+
* The `robots` and `referrer` of a protected share (hyle ADR 0040). The unlock form is same-origin by `Sec-Fetch-Site`, so
|
|
544
|
+
* `no-referrer` does not stop it. The URL carries no secret.
|
|
545
|
+
*/
|
|
546
|
+
declare const hyleProtectedMetadata: Metadata;
|
|
547
|
+
/**
|
|
548
|
+
* `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.
|
|
553
|
+
*/
|
|
554
|
+
declare function createProtectedUnlockRoute(): {
|
|
555
|
+
POST: (req: Request) => Promise<Response>;
|
|
556
|
+
};
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* For a host whose catch-all is static or ISR (`revalidate`, `generateStaticParams`): reading the visitor's cookie there is a 500
|
|
560
|
+
* (`DYNAMIC_SERVER_USAGE`), so a share is drawn by a dynamic route instead. In the host's `proxy.ts`:
|
|
561
|
+
* `const share = hyleProtectedProxy(configs); export async function proxy(req) { return (await share(req)) ?? NextResponse.next(); }`.
|
|
562
|
+
* A path under a live share slug is REWRITTEN to `/hyle-protected/view/<path>` (the visitor's URL does not change); every other
|
|
563
|
+
* request returns undefined, so the host's ordinary pages stay cached. A proxy has no fetch cache, so it keeps ONE read of hyle's
|
|
564
|
+
* mounts per config in memory for 30 seconds (shared by concurrent requests, the last good copy used when a refresh fails) and
|
|
565
|
+
* matches every path against it locally: random paths never cost a call to hyle. The page behind the rewrite checks again through
|
|
566
|
+
* the usual mounts cache. A mounts read that fails with no copy counts as "not a share" for those 30 seconds rather than erroring
|
|
567
|
+
* every request of the host.
|
|
568
|
+
*/
|
|
569
|
+
declare function hyleProtectedProxy(options: Configs): (req: NextRequest) => Promise<NextResponse | undefined>;
|
|
570
|
+
/** The page of `app/hyle-protected/view/[[...path]]/page.tsx` (see `hyleProtectedProxy`): the share under the path, else `notFound()`. */
|
|
571
|
+
declare function hyleProtectedPage(options: Configs): (props: {
|
|
572
|
+
readonly params: Promise<{
|
|
573
|
+
readonly path?: string[];
|
|
574
|
+
}>;
|
|
575
|
+
}) => Promise<ReactElement>;
|
|
576
|
+
|
|
577
|
+
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
|
@@ -19,15 +19,15 @@ import {
|
|
|
19
19
|
readingMinutes,
|
|
20
20
|
validOgImage,
|
|
21
21
|
wordCountOf
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-5TKJH2XC.js";
|
|
23
23
|
import {
|
|
24
24
|
stringsFor
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-Y3BACEWA.js";
|
|
26
26
|
import {
|
|
27
27
|
DEFAULT_REVALIDATE,
|
|
28
28
|
fetchResolver,
|
|
29
29
|
workspaceTags
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-SY2FMIRZ.js";
|
|
31
31
|
import {
|
|
32
32
|
Cp1ClientError,
|
|
33
33
|
checkBaseUrl,
|
|
@@ -40,15 +40,20 @@ import {
|
|
|
40
40
|
listPublicationPaths,
|
|
41
41
|
readCapped,
|
|
42
42
|
signReaderAssertion
|
|
43
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-4REU4HJI.js";
|
|
44
44
|
import {
|
|
45
45
|
ASSET_CONTENT_TYPES,
|
|
46
46
|
ASSET_FILE,
|
|
47
47
|
ASSET_ROUTE_PREFIX,
|
|
48
48
|
PREVIEW_PARAM,
|
|
49
49
|
PREVIEW_TOKEN,
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
PROTECTED_DOC_SLUG,
|
|
51
|
+
PROTECTED_PARAM,
|
|
52
|
+
PROTECTED_PASSWORD,
|
|
53
|
+
PROTECTED_SLUG,
|
|
54
|
+
THEME_FILE,
|
|
55
|
+
protectedCookieName
|
|
56
|
+
} from "./chunk-BDFMNY76.js";
|
|
52
57
|
|
|
53
58
|
// src/next/page.tsx
|
|
54
59
|
import { notFound, permanentRedirect, redirect } from "next/navigation";
|
|
@@ -225,6 +230,10 @@ function sameOriginProblem(req, write, allowedOrigins) {
|
|
|
225
230
|
const site = req.headers.get("sec-fetch-site");
|
|
226
231
|
if (site !== null && site !== "same-origin") return true;
|
|
227
232
|
if (!write) return false;
|
|
233
|
+
if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
|
|
234
|
+
return originMismatch(req, allowedOrigins);
|
|
235
|
+
}
|
|
236
|
+
function originMismatch(req, allowedOrigins) {
|
|
228
237
|
const origin = req.headers.get("origin");
|
|
229
238
|
if (origin === null) return true;
|
|
230
239
|
let parsed;
|
|
@@ -233,7 +242,6 @@ function sameOriginProblem(req, write, allowedOrigins) {
|
|
|
233
242
|
} catch {
|
|
234
243
|
return true;
|
|
235
244
|
}
|
|
236
|
-
if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
|
|
237
245
|
if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
|
|
238
246
|
const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
|
|
239
247
|
const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
|
|
@@ -791,7 +799,7 @@ function createRevalidateRoute(options) {
|
|
|
791
799
|
}
|
|
792
800
|
|
|
793
801
|
// src/next/root.ts
|
|
794
|
-
import { notFound as
|
|
802
|
+
import { notFound as notFound4, unstable_rethrow as unstable_rethrow4 } from "next/navigation";
|
|
795
803
|
|
|
796
804
|
// src/next/mount-match.ts
|
|
797
805
|
function activeMounts(mounts) {
|
|
@@ -817,24 +825,147 @@ function isReserved(path, reserved) {
|
|
|
817
825
|
return reserved.some((entry) => entry.endsWith("/*") ? prefixMatches(entry.slice(0, -2), path) : entry === path);
|
|
818
826
|
}
|
|
819
827
|
|
|
828
|
+
// src/next/protected.tsx
|
|
829
|
+
import { cookies } from "next/headers";
|
|
830
|
+
import { notFound as notFound3 } from "next/navigation";
|
|
831
|
+
|
|
832
|
+
// src/next/preview.tsx
|
|
833
|
+
import { notFound as notFound2 } from "next/navigation";
|
|
834
|
+
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
|
+
var hyleProtectedMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
|
|
869
|
+
var COOKIE_MAX_AGE_SECONDS = 12 * 60 * 60;
|
|
870
|
+
var UNLOCK_MAX_BYTES = 1024;
|
|
871
|
+
var PRIVATE_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
|
|
872
|
+
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
|
+
] });
|
|
900
|
+
}
|
|
901
|
+
async function drawProtectedShare(options, slug, docSlug) {
|
|
902
|
+
const client = createHyleClient({ baseUrl: options.baseUrl, token: options.token });
|
|
903
|
+
const password = (await cookies()).get(await protectedCookieName(slug))?.value;
|
|
904
|
+
const share = password === void 0 ? void 0 : await client.protected(slug, password, docSlug);
|
|
905
|
+
if (share?.kind === "disabled") notFound3();
|
|
906
|
+
if (share?.kind === "protected") {
|
|
907
|
+
if (docSlug !== void 0 && share.doc_slug !== docSlug) notFound3();
|
|
908
|
+
const here = `/${slug}/${share.doc_slug}`;
|
|
909
|
+
const article = {
|
|
910
|
+
...share.article,
|
|
911
|
+
publication: { ...share.article.publication, canonical_path: here },
|
|
912
|
+
nav: { truncated: false, items: share.documents.map((d) => ({ slug: d.doc_slug, title: d.title, canonical_path: `/${slug}/${d.doc_slug}`, children: [] })) }
|
|
913
|
+
};
|
|
914
|
+
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
915
|
+
/* @__PURE__ */ jsx4("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
916
|
+
/* @__PURE__ */ jsx4("meta", { name: "referrer", content: "no-referrer" }),
|
|
917
|
+
drawArticle(article, { ...options, layout: share.documents.length > 1 ? "docs" : "article" })
|
|
918
|
+
] });
|
|
919
|
+
}
|
|
920
|
+
const gate = await client.protectedGate(slug);
|
|
921
|
+
if (gate.kind !== "gate") notFound3();
|
|
922
|
+
return /* @__PURE__ */ jsxs2(Fragment2, { children: [
|
|
923
|
+
/* @__PURE__ */ jsx4("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
924
|
+
/* @__PURE__ */ jsx4("meta", { name: "referrer", content: "no-referrer" }),
|
|
925
|
+
/* @__PURE__ */ jsx4(PasswordForm, { slug, failed: password !== void 0 })
|
|
926
|
+
] });
|
|
927
|
+
}
|
|
928
|
+
function createProtectedUnlockRoute() {
|
|
929
|
+
return {
|
|
930
|
+
async POST(req) {
|
|
931
|
+
const site = req.headers.get("sec-fetch-site");
|
|
932
|
+
if (site === null ? originMismatch(req) : site !== "same-origin") return new Response(null, { status: 403, headers: PRIVATE_HEADERS });
|
|
933
|
+
if (!/^application\/x-www-form-urlencoded(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return new Response(null, { status: 415, headers: PRIVATE_HEADERS });
|
|
934
|
+
if (Number(req.headers.get("content-length")) > UNLOCK_MAX_BYTES) return new Response(null, { status: 413, headers: PRIVATE_HEADERS });
|
|
935
|
+
const form = await readCapped(new Response(req.body), UNLOCK_MAX_BYTES).catch(() => void 0);
|
|
936
|
+
if (form === void 0) return new Response(null, { status: 413, headers: PRIVATE_HEADERS });
|
|
937
|
+
const fields = new URLSearchParams(form);
|
|
938
|
+
const slug = fields.get("slug") ?? "";
|
|
939
|
+
if (!PROTECTED_SLUG.test(slug)) return new Response(null, { status: 404, headers: PRIVATE_HEADERS });
|
|
940
|
+
const password = fields.get("password") ?? "";
|
|
941
|
+
const headers = new Headers({ ...PRIVATE_HEADERS, Location: `/${slug}` });
|
|
942
|
+
if (PROTECTED_PASSWORD.test(password)) {
|
|
943
|
+
const name = await protectedCookieName(slug);
|
|
944
|
+
for (const path of [`/${slug}`, ASSET_ROUTE_PREFIX]) headers.append("Set-Cookie", `${name}=${password}; Max-Age=${COOKIE_MAX_AGE_SECONDS}; Path=${path}; HttpOnly; Secure; SameSite=Lax`);
|
|
945
|
+
}
|
|
946
|
+
return new Response(null, { status: 303, headers });
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
|
|
820
951
|
// src/next/root.ts
|
|
821
952
|
var MOUNTS_MAX_STALE_MS = 15 * 60 * 1e3;
|
|
822
953
|
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
823
|
-
var NONE = { mounts: [], reserved: [], defaultLocale: "" };
|
|
954
|
+
var NONE = { mounts: [], reserved: [], defaultLocale: "", protected: [] };
|
|
824
955
|
var lastKnownGood = /* @__PURE__ */ new Map();
|
|
825
|
-
function mountsLoader(config) {
|
|
956
|
+
function mountsLoader(config, ttlMs) {
|
|
826
957
|
if (!config.workspaceId) throw new TypeError("hyleRootPage: `workspaceId` is required for the fetch cache");
|
|
827
958
|
const client = createHyleClient({ baseUrl: config.baseUrl, token: config.token });
|
|
828
959
|
const init = { next: { revalidate: config.revalidate ?? DEFAULT_REVALIDATE, tags: workspaceTags(config.workspaceId).slice(0, 1) } };
|
|
829
960
|
const key = `${new URL(config.baseUrl).origin}|${config.workspaceId}`;
|
|
830
|
-
|
|
961
|
+
async function fetchLoaded() {
|
|
831
962
|
try {
|
|
832
963
|
const result = await client.mounts({ init });
|
|
833
964
|
if (result.kind !== "mounts") {
|
|
834
965
|
lastKnownGood.delete(key);
|
|
835
966
|
return NONE;
|
|
836
967
|
}
|
|
837
|
-
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale };
|
|
968
|
+
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale, protected: result.protected ?? [] };
|
|
838
969
|
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
839
970
|
return loaded;
|
|
840
971
|
} catch (error) {
|
|
@@ -847,15 +978,21 @@ function mountsLoader(config) {
|
|
|
847
978
|
if (kept && Date.now() - kept.at <= MOUNTS_MAX_STALE_MS) return kept.loaded;
|
|
848
979
|
throw error;
|
|
849
980
|
}
|
|
981
|
+
}
|
|
982
|
+
if (ttlMs === void 0) return fetchLoaded;
|
|
983
|
+
let memo;
|
|
984
|
+
return function load() {
|
|
985
|
+
if (!memo || memo.until <= Date.now()) memo = { read: fetchLoaded(), until: Date.now() + ttlMs };
|
|
986
|
+
return memo.read;
|
|
850
987
|
};
|
|
851
988
|
}
|
|
852
989
|
var asArray = (options) => Array.isArray(options) ? options : [options];
|
|
853
|
-
function setup(options) {
|
|
990
|
+
function setup(options, ttlMs) {
|
|
854
991
|
const configs = asArray(options);
|
|
855
992
|
if (configs.length === 0) throw new TypeError("hyleRootPage: pass at least one workspace config");
|
|
856
993
|
const param = configs[0].param ?? "hyle";
|
|
857
994
|
if (configs.some((c) => (c.param ?? "hyle") !== param)) throw new TypeError("hyleRootPage: every config must use the same `param`");
|
|
858
|
-
return { configs, param, loaders: configs.map(mountsLoader) };
|
|
995
|
+
return { configs, param, loaders: configs.map((config) => mountsLoader(config, ttlMs)) };
|
|
859
996
|
}
|
|
860
997
|
var sectionsOf = (config, mount) => [
|
|
861
998
|
...config.sections ?? [],
|
|
@@ -865,20 +1002,33 @@ function mountOptionsOf(config, mount) {
|
|
|
865
1002
|
const { mountOptions, ...rest } = config;
|
|
866
1003
|
return { ...rest, ...mountOptions?.[mount.prefix === "" ? "/" : mount.prefix], basePath: mount.prefix, sections: sectionsOf(config, mount) };
|
|
867
1004
|
}
|
|
868
|
-
function rootMounts(options) {
|
|
869
|
-
const { configs, param, loaders } = setup(options);
|
|
1005
|
+
function rootMounts(options, ttlMs) {
|
|
1006
|
+
const { configs, param, loaders } = setup(options, ttlMs);
|
|
870
1007
|
return {
|
|
871
1008
|
param,
|
|
872
1009
|
async locate(path) {
|
|
873
1010
|
const loaded = await Promise.all(loaders.map((load) => load()));
|
|
1011
|
+
let share;
|
|
1012
|
+
loaded.forEach(({ protected: slugs }, index) => {
|
|
1013
|
+
for (const slug of slugs) {
|
|
1014
|
+
const depth = slug.split("/").length;
|
|
1015
|
+
if (!prefixMatches(`/${slug}`, path) || share && depth <= share.depth) continue;
|
|
1016
|
+
const docSlug = path === `/${slug}` ? void 0 : path.slice(slug.length + 2);
|
|
1017
|
+
if (docSlug === void 0 || PROTECTED_DOC_SLUG.test(docSlug)) share = { index, slug, depth, docSlug };
|
|
1018
|
+
}
|
|
1019
|
+
});
|
|
874
1020
|
let best;
|
|
875
|
-
loaded.forEach(({ mounts, reserved },
|
|
1021
|
+
loaded.forEach(({ mounts, reserved }, index) => {
|
|
876
1022
|
if (isReserved(path, reserved)) return;
|
|
877
|
-
for (const
|
|
1023
|
+
for (const mount of mounts) if (prefixMatches(mount.prefix, path) && (!best || mount.depth > best.mount.depth)) best = { index, mount };
|
|
878
1024
|
});
|
|
879
|
-
|
|
880
|
-
const
|
|
881
|
-
|
|
1025
|
+
const won = share;
|
|
1026
|
+
const mounted = best;
|
|
1027
|
+
if (won && (!mounted || won.depth > mounted.mount.depth || won.depth === mounted.mount.depth && won.index === mounted.index)) {
|
|
1028
|
+
return { share: { config: configs[won.index], slug: won.slug, docSlug: won.docSlug } };
|
|
1029
|
+
}
|
|
1030
|
+
if (!mounted) return void 0;
|
|
1031
|
+
return { options: mountOptionsOf(configs[mounted.index], mounted.mount), mount: mounted.mount, index: mounted.index };
|
|
882
1032
|
},
|
|
883
1033
|
async all() {
|
|
884
1034
|
const out = [];
|
|
@@ -890,7 +1040,7 @@ function rootMounts(options) {
|
|
|
890
1040
|
}
|
|
891
1041
|
};
|
|
892
1042
|
}
|
|
893
|
-
function createRouter(options, make) {
|
|
1043
|
+
function createRouter(options, make, share) {
|
|
894
1044
|
const mounts = rootMounts(options);
|
|
895
1045
|
const handlers = /* @__PURE__ */ new Map();
|
|
896
1046
|
return async function route(params) {
|
|
@@ -900,6 +1050,7 @@ function createRouter(options, make) {
|
|
|
900
1050
|
if (path === void 0 || path === "/" || !segments) return void 0;
|
|
901
1051
|
const hit = await mounts.locate(path);
|
|
902
1052
|
if (!hit) return void 0;
|
|
1053
|
+
if ("share" in hit) return { handler: share(hit.share), params };
|
|
903
1054
|
const { mount, index } = hit;
|
|
904
1055
|
const id = `${index}|${mount.prefix}|${mount.defaultSection}`;
|
|
905
1056
|
let handler = handlers.get(id);
|
|
@@ -911,15 +1062,15 @@ function createRouter(options, make) {
|
|
|
911
1062
|
};
|
|
912
1063
|
}
|
|
913
1064
|
function hyleRootPage(options) {
|
|
914
|
-
const route = createRouter(options, hylePage);
|
|
1065
|
+
const route = createRouter(options, hylePage, (s) => () => drawProtectedShare(s.config, s.slug, s.docSlug));
|
|
915
1066
|
return async function HyleRootPage({ params, searchParams }) {
|
|
916
1067
|
const hit = await route(await params ?? {});
|
|
917
|
-
if (!hit)
|
|
1068
|
+
if (!hit) notFound4();
|
|
918
1069
|
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
919
1070
|
};
|
|
920
1071
|
}
|
|
921
1072
|
function hyleRootMetadata(options) {
|
|
922
|
-
const route = createRouter(options, hyleMetadata);
|
|
1073
|
+
const route = createRouter(options, hyleMetadata, () => async () => hyleProtectedMetadata);
|
|
923
1074
|
return async function generateMetadata({ params, searchParams }, parent) {
|
|
924
1075
|
const hit = await route(await params ?? {});
|
|
925
1076
|
return hit ? hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} }, parent) : {};
|
|
@@ -955,7 +1106,7 @@ function createMarkdownRoute(options) {
|
|
|
955
1106
|
if (path === void 0 || path === "/") return reply(null, 404);
|
|
956
1107
|
try {
|
|
957
1108
|
const hit = await mounts.locate(path);
|
|
958
|
-
if (!hit) return reply(null, 404);
|
|
1109
|
+
if (!hit || "share" in hit) return reply(null, 404);
|
|
959
1110
|
const { locale, toHref } = routeContext({ ...hit.options, basePath: "", param: "path" }, params);
|
|
960
1111
|
const result = await resolverFor(hit.options)(path, locale, void 0, void 0, void 0, "md");
|
|
961
1112
|
if (result.kind === "article" && result.content.format === "md") {
|
|
@@ -1021,7 +1172,7 @@ var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
|
1021
1172
|
var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
|
|
1022
1173
|
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
1023
1174
|
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
1024
|
-
var
|
|
1175
|
+
var PRIVATE_HEADERS2 = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
|
|
1025
1176
|
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
1026
1177
|
var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
1027
1178
|
var THEME_CACHE_CONTROL = "public, max-age=31536000, immutable";
|
|
@@ -1049,6 +1200,12 @@ async function serveTheme(client, scope, hash, timeoutMs, head) {
|
|
|
1049
1200
|
return empty(502);
|
|
1050
1201
|
}
|
|
1051
1202
|
}
|
|
1203
|
+
async function protectedAccessFor(req, slug) {
|
|
1204
|
+
if (!PROTECTED_SLUG.test(slug)) return void 0;
|
|
1205
|
+
const name = await protectedCookieName(slug);
|
|
1206
|
+
const password = req.headers.get("cookie")?.split(";").map((c) => c.trim()).find((c) => c.startsWith(`${name}=`))?.slice(name.length + 1);
|
|
1207
|
+
return password !== void 0 && PROTECTED_PASSWORD.test(password) ? { slug, password } : void 0;
|
|
1208
|
+
}
|
|
1052
1209
|
function capped(body, max) {
|
|
1053
1210
|
let seen = 0;
|
|
1054
1211
|
return body.pipeThrough(
|
|
@@ -1065,17 +1222,21 @@ function createAssetRoute(options) {
|
|
|
1065
1222
|
let client;
|
|
1066
1223
|
const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
|
|
1067
1224
|
async function serve(req, ctx, head) {
|
|
1068
|
-
const
|
|
1069
|
-
const
|
|
1070
|
-
|
|
1225
|
+
const query = new URL(req.url).searchParams;
|
|
1226
|
+
const previewToken = query.get(PREVIEW_PARAM);
|
|
1227
|
+
const slug = query.get(PROTECTED_PARAM);
|
|
1228
|
+
const res = await relay(req, ctx, head, previewToken, slug);
|
|
1229
|
+
if (previewToken !== null || slug !== null) for (const [name, value] of Object.entries(PRIVATE_HEADERS2)) res.headers.set(name, value);
|
|
1071
1230
|
return res;
|
|
1072
1231
|
}
|
|
1073
|
-
async function relay(req, ctx, head, previewToken) {
|
|
1232
|
+
async function relay(req, ctx, head, previewToken, slug) {
|
|
1074
1233
|
if (isSwitchedOff3((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
1075
1234
|
const file = (await ctx.params).file;
|
|
1076
1235
|
const [, themeScope, themeHash] = typeof file === "string" ? THEME_FILE.exec(file) ?? [] : [];
|
|
1077
1236
|
if (typeof file !== "string" || !themeHash && !ASSET_FILE.test(file)) return empty(404);
|
|
1078
1237
|
if (previewToken !== null && !PREVIEW_TOKEN.test(previewToken)) return empty(404);
|
|
1238
|
+
const protectedAccess = slug === null ? void 0 : await protectedAccessFor(req, slug);
|
|
1239
|
+
if (slug !== null && protectedAccess === void 0) return empty(404);
|
|
1079
1240
|
try {
|
|
1080
1241
|
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
1081
1242
|
} catch {
|
|
@@ -1087,6 +1248,7 @@ function createAssetRoute(options) {
|
|
|
1087
1248
|
upstream = await client.asset(file, {
|
|
1088
1249
|
timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS2,
|
|
1089
1250
|
...previewToken === null ? {} : { previewToken },
|
|
1251
|
+
...protectedAccess === void 0 ? {} : { protectedAccess },
|
|
1090
1252
|
headers: { range: req.headers.get("range"), "if-range": req.headers.get("if-range"), "if-none-match": req.headers.get("if-none-match") }
|
|
1091
1253
|
});
|
|
1092
1254
|
} catch {
|
|
@@ -1105,7 +1267,7 @@ function createAssetRoute(options) {
|
|
|
1105
1267
|
const range = upstream.headers.get("content-range");
|
|
1106
1268
|
return empty(416, range ? { "Content-Range": range } : {});
|
|
1107
1269
|
}
|
|
1108
|
-
if (upstream.status === 429 && previewToken !== null) {
|
|
1270
|
+
if (upstream.status === 429 && (previewToken !== null || slug !== null)) {
|
|
1109
1271
|
drop();
|
|
1110
1272
|
const wait = upstream.headers.get("retry-after");
|
|
1111
1273
|
return empty(429, wait ? { "Retry-After": wait } : {});
|
|
@@ -1132,7 +1294,7 @@ function createAssetRoute(options) {
|
|
|
1132
1294
|
}
|
|
1133
1295
|
|
|
1134
1296
|
// src/next/og.tsx
|
|
1135
|
-
import { jsx as
|
|
1297
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1136
1298
|
var SIZE = { width: 1200, height: 630 };
|
|
1137
1299
|
var MAX_TITLE = 140;
|
|
1138
1300
|
function createOgImageRoute(options) {
|
|
@@ -1162,9 +1324,9 @@ function createOgImageRoute(options) {
|
|
|
1162
1324
|
const chars = [...title];
|
|
1163
1325
|
const shown = chars.length > MAX_TITLE ? `${chars.slice(0, MAX_TITLE - 1).join("")}\u2026` : title;
|
|
1164
1326
|
return new ImageResponse(
|
|
1165
|
-
/* @__PURE__ */
|
|
1166
|
-
/* @__PURE__ */
|
|
1167
|
-
options.siteName ? /* @__PURE__ */
|
|
1327
|
+
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", flexDirection: "column", justifyContent: "space-between", width: "100%", height: "100%", padding: 80, background: "#111827", color: "#ffffff" }, children: [
|
|
1328
|
+
/* @__PURE__ */ jsx5("div", { style: { fontSize: 64, fontWeight: 700, lineHeight: 1.2 }, children: shown }),
|
|
1329
|
+
options.siteName ? /* @__PURE__ */ jsx5("div", { style: { fontSize: 32, color: "#9ca3af" }, children: options.siteName }) : null
|
|
1168
1330
|
] }),
|
|
1169
1331
|
// 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.
|
|
1170
1332
|
{ ...SIZE, headers: { "cache-control": "public, max-age=3600, s-maxage=31536000, immutable" } }
|
|
@@ -1173,35 +1335,28 @@ function createOgImageRoute(options) {
|
|
|
1173
1335
|
};
|
|
1174
1336
|
}
|
|
1175
1337
|
|
|
1176
|
-
// src/next/
|
|
1177
|
-
import { notFound as
|
|
1178
|
-
import {
|
|
1179
|
-
var
|
|
1180
|
-
var
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
};
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
const
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
const props = { article, components: options.components, slots: options.slots, locale, toHref };
|
|
1199
|
-
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1200
|
-
/* @__PURE__ */ jsx4("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
1201
|
-
/* @__PURE__ */ jsx4("meta", { name: "referrer", content: "no-referrer" }),
|
|
1202
|
-
/* @__PURE__ */ jsx4("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
|
|
1203
|
-
options.layout === "docs" ? /* @__PURE__ */ jsx4(DocsPage, { ...props }) : /* @__PURE__ */ jsx4(ArticlePage, { ...props })
|
|
1204
|
-
] });
|
|
1338
|
+
// src/next/protected-view.ts
|
|
1339
|
+
import { notFound as notFound5 } from "next/navigation";
|
|
1340
|
+
import { NextResponse } from "next/server";
|
|
1341
|
+
var VIEW_PATH = "/hyle-protected/view";
|
|
1342
|
+
var MOUNTS_SNAPSHOT_MS = 3e4;
|
|
1343
|
+
var SHARE_PATH = /^\/[a-z0-9-]+(?:\/[a-z0-9-]+){0,4}$/;
|
|
1344
|
+
function hyleProtectedProxy(options) {
|
|
1345
|
+
const mounts = rootMounts(options, MOUNTS_SNAPSHOT_MS);
|
|
1346
|
+
return async function protectedProxy(req) {
|
|
1347
|
+
const path = req.nextUrl.pathname;
|
|
1348
|
+
if (!SHARE_PATH.test(path)) return void 0;
|
|
1349
|
+
const hit = await mounts.locate(path).catch(() => void 0);
|
|
1350
|
+
return hit && "share" in hit ? NextResponse.rewrite(new URL(`${VIEW_PATH}${path}`, req.url)) : void 0;
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
function hyleProtectedPage(options) {
|
|
1354
|
+
const mounts = rootMounts(options);
|
|
1355
|
+
return async function HyleProtectedPage({ params }) {
|
|
1356
|
+
const path = `/${((await params).path ?? []).join("/")}`;
|
|
1357
|
+
const hit = SHARE_PATH.test(path) ? await mounts.locate(path) : void 0;
|
|
1358
|
+
if (!hit || !("share" in hit)) notFound5();
|
|
1359
|
+
return drawProtectedShare(hit.share.config, hit.share.slug, hit.share.docSlug);
|
|
1205
1360
|
};
|
|
1206
1361
|
}
|
|
1207
1362
|
export {
|
|
@@ -1216,6 +1371,7 @@ export {
|
|
|
1216
1371
|
createLlmsTxtRoute,
|
|
1217
1372
|
createMarkdownRoute,
|
|
1218
1373
|
createOgImageRoute,
|
|
1374
|
+
createProtectedUnlockRoute,
|
|
1219
1375
|
createRevalidateRoute,
|
|
1220
1376
|
fetchResolver,
|
|
1221
1377
|
hyleFeed,
|
|
@@ -1224,6 +1380,9 @@ export {
|
|
|
1224
1380
|
hylePage,
|
|
1225
1381
|
hylePreviewMetadata,
|
|
1226
1382
|
hylePreviewPage,
|
|
1383
|
+
hyleProtectedMetadata,
|
|
1384
|
+
hyleProtectedPage,
|
|
1385
|
+
hyleProtectedProxy,
|
|
1227
1386
|
hyleRootMetadata,
|
|
1228
1387
|
hyleRootPage,
|
|
1229
1388
|
hyleRootSitemap,
|