@tdacorp/hyle-sdk 0.23.0 → 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 +35 -19
- package/dist/check-routes-bin.js +28 -15
- package/dist/{chunk-YHXE3TGS.js → chunk-4REU4HJI.js} +27 -15
- package/dist/{chunk-UFMKLCXS.js → chunk-5TKJH2XC.js} +2 -2
- package/dist/{chunk-VXARM37R.js → chunk-BDFMNY76.js} +11 -5
- package/dist/{chunk-VUML2UPD.js → chunk-SY2FMIRZ.js} +1 -1
- package/dist/{chunk-JHZJOJDC.js → chunk-Y3BACEWA.js} +1 -1
- package/dist/{client--ighAWaj.d.ts → client-BErei7cE.d.ts} +5 -4
- package/dist/{client-DK-S2580.d.cts → client-DrB2vcTi.d.cts} +5 -4
- package/dist/comments.cjs +3 -2
- package/dist/comments.js +3 -2
- package/dist/{embed-XT0x_Jaa.d.cts → embed-B7T--kTT.d.cts} +1 -1
- package/dist/{embed-g7NT1CyB.d.ts → embed-DavTgSU4.d.ts} +1 -1
- package/dist/html.cjs +3 -2
- package/dist/html.js +2 -2
- package/dist/index.cjs +28 -15
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +2 -2
- package/dist/next.cjs +233 -148
- package/dist/next.d.cts +36 -31
- package/dist/next.d.ts +36 -31
- package/dist/next.js +204 -135
- package/dist/react.cjs +3 -2
- package/dist/react.d.cts +3 -3
- package/dist/react.d.ts +3 -3
- package/dist/react.js +3 -3
- package/dist/{resolve-CiZCPysX.d.cts → resolve-03IVloXU.d.cts} +1 -1
- package/dist/{resolve-BqC9l5RH.d.ts → resolve-BseM68oy.d.ts} +1 -1
- package/dist/{types-b9QbmEDd.d.cts → types-Dx-fEiZd.d.cts} +25 -5
- package/dist/{types-b9QbmEDd.d.ts → types-Dx-fEiZd.d.ts} +25 -5
- package/dist/use-cache.cjs +28 -15
- 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.cjs
CHANGED
|
@@ -42,6 +42,7 @@ __export(next_exports, {
|
|
|
42
42
|
hylePreviewPage: () => hylePreviewPage,
|
|
43
43
|
hyleProtectedMetadata: () => hyleProtectedMetadata,
|
|
44
44
|
hyleProtectedPage: () => hyleProtectedPage,
|
|
45
|
+
hyleProtectedProxy: () => hyleProtectedProxy,
|
|
45
46
|
hyleRootMetadata: () => hyleRootMetadata,
|
|
46
47
|
hyleRootPage: () => hyleRootPage,
|
|
47
48
|
hyleRootSitemap: () => hyleRootSitemap,
|
|
@@ -75,10 +76,15 @@ var PREVIEW_PARAM = "hyle_preview";
|
|
|
75
76
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
76
77
|
var PROTECTED_PARAM = "hyle_protected";
|
|
77
78
|
var PROTECTED_HEADER = "cp-protected";
|
|
78
|
-
var
|
|
79
|
-
var
|
|
80
|
-
var
|
|
81
|
-
var
|
|
79
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
80
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
81
|
+
var PROTECTED_DOC_SLUG = /^[a-z0-9-]+$/;
|
|
82
|
+
var PROTECTED_PASSWORD = /^[\x21\x23-\x24\x26-\x2B\x2D-\x3A\x3C-\x5B\x5D-\x7E]{12,128}$/;
|
|
83
|
+
async function protectedCookieName(slug) {
|
|
84
|
+
const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(slug));
|
|
85
|
+
return `hyle_p_${Buffer.from(digest).toString("base64url").slice(0, 16)}`;
|
|
86
|
+
}
|
|
87
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
82
88
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
83
89
|
function hostAssetSrc(src) {
|
|
84
90
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
|
@@ -191,7 +197,7 @@ var KINDS = /* @__PURE__ */ new Set(["article", "list", "redirect", "notfound",
|
|
|
191
197
|
var isStrings = (value) => Array.isArray(value) && value.every((v) => typeof v === "string");
|
|
192
198
|
function isMounts(data) {
|
|
193
199
|
const mounts = data.mounts;
|
|
194
|
-
return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string");
|
|
200
|
+
return typeof data.workspace_id === "string" && isStrings(data.reserved) && isStrings(data.supported_locales) && Array.isArray(mounts) && mounts.every((m) => typeof m?.prefix === "string" && typeof m.default_section === "string") && (data.protected === void 0 || isStrings(data.protected));
|
|
195
201
|
}
|
|
196
202
|
function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
197
203
|
let origin;
|
|
@@ -274,22 +280,35 @@ function createHyleClient(options) {
|
|
|
274
280
|
if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply2);
|
|
275
281
|
return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
|
|
276
282
|
}
|
|
277
|
-
async function
|
|
278
|
-
if (!
|
|
279
|
-
const reply2 = await get("/cp1/read/_protected", new URLSearchParams(
|
|
283
|
+
async function protectedGate(slug) {
|
|
284
|
+
if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
|
|
285
|
+
const reply2 = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
|
|
286
|
+
if (reply2.status === 404 && reply2.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
287
|
+
const data = reply2.parsed?.data;
|
|
288
|
+
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
289
|
+
if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
|
|
290
|
+
throw failure(reply2);
|
|
291
|
+
}
|
|
292
|
+
async function protectedShare(slug, password, docSlug) {
|
|
293
|
+
if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
|
|
294
|
+
const path = docSlug === void 0 ? slug : `${slug}/${docSlug}`;
|
|
295
|
+
const reply2 = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { [PROTECTED_HEADER]: password }, cache: "no-store" });
|
|
280
296
|
if (reply2.status === 404 && reply2.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
|
|
281
297
|
const data = reply2.parsed?.data;
|
|
282
298
|
if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
|
|
283
299
|
const article = data?.article;
|
|
284
|
-
const expires = data
|
|
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}=${
|
|
300
|
+
const { name, expires_at: expires, documents, doc_slug: current } = data ?? {};
|
|
301
|
+
if (data?.cp !== 1 || data.kind !== "protected" || typeof name !== "string" || typeof expires !== "string" && expires !== null || !Array.isArray(documents) || typeof current !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply2);
|
|
302
|
+
return { cp: 1, kind: "protected", name, expires_at: expires, documents, doc_slug: current, article: withAssetQuery(article, `${PROTECTED_PARAM}=${slug}`) };
|
|
287
303
|
}
|
|
288
304
|
async function asset(file, opts = {}) {
|
|
289
305
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
290
306
|
const { previewToken } = opts;
|
|
291
307
|
if (previewToken !== void 0 && !PREVIEW_TOKEN.test(previewToken)) throw new TypeError("previewToken is not a preview token");
|
|
292
|
-
const
|
|
308
|
+
const { protectedAccess } = opts;
|
|
309
|
+
if (protectedAccess !== void 0 && !(PROTECTED_SLUG.test(protectedAccess.slug) && PROTECTED_PASSWORD.test(protectedAccess.password))) throw new TypeError("protectedAccess is not a share slug and password");
|
|
310
|
+
const query = protectedAccess === void 0 ? "" : `?protected=${encodeURIComponent(protectedAccess.slug)}`;
|
|
311
|
+
const url = `${base}/cp1/read/assets/${file}${query}`;
|
|
293
312
|
const headers = new Headers();
|
|
294
313
|
const applied = applyCredential(headers, options, "GET", url);
|
|
295
314
|
if (applied) await applied;
|
|
@@ -297,10 +316,8 @@ function createHyleClient(options) {
|
|
|
297
316
|
const value = opts.headers?.[name];
|
|
298
317
|
if (value) headers.set(name, value);
|
|
299
318
|
}
|
|
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");
|
|
302
319
|
if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
|
|
303
|
-
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER,
|
|
320
|
+
if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, protectedAccess.password);
|
|
304
321
|
const uncached = previewToken !== void 0 || protectedAccess !== void 0;
|
|
305
322
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
|
|
306
323
|
}
|
|
@@ -311,7 +328,7 @@ function createHyleClient(options) {
|
|
|
311
328
|
if (applied) await applied;
|
|
312
329
|
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
313
330
|
}
|
|
314
|
-
return { resolve, mounts, pushPosts, preview, protected:
|
|
331
|
+
return { resolve, mounts, pushPosts, preview, protectedGate, protected: protectedShare, asset, theme };
|
|
315
332
|
}
|
|
316
333
|
|
|
317
334
|
// src/delivery-dedupe.ts
|
|
@@ -3116,7 +3133,7 @@ function createRevalidateRoute(options) {
|
|
|
3116
3133
|
}
|
|
3117
3134
|
|
|
3118
3135
|
// src/next/root.ts
|
|
3119
|
-
var
|
|
3136
|
+
var import_navigation7 = require("next/navigation");
|
|
3120
3137
|
|
|
3121
3138
|
// src/next/mount-match.ts
|
|
3122
3139
|
function activeMounts(mounts) {
|
|
@@ -3142,28 +3159,151 @@ function isReserved(path, reserved) {
|
|
|
3142
3159
|
return reserved.some((entry) => entry.endsWith("/*") ? prefixMatches(entry.slice(0, -2), path) : entry === path);
|
|
3143
3160
|
}
|
|
3144
3161
|
|
|
3162
|
+
// src/next/protected.tsx
|
|
3163
|
+
var import_headers = require("next/headers");
|
|
3164
|
+
var import_navigation6 = require("next/navigation");
|
|
3165
|
+
|
|
3166
|
+
// src/next/preview.tsx
|
|
3167
|
+
var import_navigation5 = require("next/navigation");
|
|
3168
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
3169
|
+
function drawArticle(article, options) {
|
|
3170
|
+
const { locale } = article.publication;
|
|
3171
|
+
const toHref = (sitePath, linkLocale = locale) => (options.localePrefix?.(linkLocale) ?? "") + sitePath;
|
|
3172
|
+
const props = { article, components: options.components, slots: options.slots, locale, toHref };
|
|
3173
|
+
return options.layout === "docs" ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(DocsPage, { ...props }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(ArticlePage, { ...props });
|
|
3174
|
+
}
|
|
3175
|
+
var hylePreviewMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
|
|
3176
|
+
var BANNER = {
|
|
3177
|
+
position: "sticky",
|
|
3178
|
+
top: 0,
|
|
3179
|
+
zIndex: 2147483647,
|
|
3180
|
+
padding: "8px 16px",
|
|
3181
|
+
background: "#fde047",
|
|
3182
|
+
color: "#1a1a1a",
|
|
3183
|
+
font: "600 14px/1.4 system-ui, sans-serif",
|
|
3184
|
+
textAlign: "center"
|
|
3185
|
+
};
|
|
3186
|
+
function hylePreviewPage(options) {
|
|
3187
|
+
return async function HylePreviewPage({ searchParams }) {
|
|
3188
|
+
const { token } = await searchParams ?? {};
|
|
3189
|
+
const result = await createHyleClient(options).preview(typeof token === "string" ? token : void 0);
|
|
3190
|
+
if (result.kind !== "preview") (0, import_navigation5.notFound)();
|
|
3191
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
3192
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
3193
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("meta", { name: "referrer", content: "no-referrer" }),
|
|
3194
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
|
|
3195
|
+
drawArticle(result.article, options)
|
|
3196
|
+
] });
|
|
3197
|
+
};
|
|
3198
|
+
}
|
|
3199
|
+
|
|
3200
|
+
// src/next/protected.tsx
|
|
3201
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
3202
|
+
var hyleProtectedMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
|
|
3203
|
+
var COOKIE_MAX_AGE_SECONDS = 12 * 60 * 60;
|
|
3204
|
+
var UNLOCK_MAX_BYTES = 1024;
|
|
3205
|
+
var PRIVATE_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
|
|
3206
|
+
var UNLOCK_PATH = "/hyle-protected/unlock";
|
|
3207
|
+
var PASSWORD_FIELD = "hyle-protected-password";
|
|
3208
|
+
var ERROR_ID = "hyle-protected-error";
|
|
3209
|
+
function PasswordForm({ slug, failed }) {
|
|
3210
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("main", { children: [
|
|
3211
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("h1", { children: "Password required" }),
|
|
3212
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("form", { method: "post", action: UNLOCK_PATH, autoComplete: "off", children: [
|
|
3213
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("input", { type: "hidden", name: "slug", value: slug }),
|
|
3214
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("label", { htmlFor: PASSWORD_FIELD, children: "Password" }),
|
|
3215
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
3216
|
+
"input",
|
|
3217
|
+
{
|
|
3218
|
+
id: PASSWORD_FIELD,
|
|
3219
|
+
name: "password",
|
|
3220
|
+
type: "password",
|
|
3221
|
+
autoComplete: "off",
|
|
3222
|
+
spellCheck: false,
|
|
3223
|
+
required: true,
|
|
3224
|
+
minLength: 12,
|
|
3225
|
+
maxLength: 128,
|
|
3226
|
+
"aria-invalid": failed || void 0,
|
|
3227
|
+
"aria-describedby": failed ? ERROR_ID : void 0
|
|
3228
|
+
}
|
|
3229
|
+
),
|
|
3230
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("button", { type: "submit", children: "Open" }),
|
|
3231
|
+
failed ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("p", { id: ERROR_ID, role: "alert", children: "Wrong or expired password." }) : null
|
|
3232
|
+
] })
|
|
3233
|
+
] });
|
|
3234
|
+
}
|
|
3235
|
+
async function drawProtectedShare(options, slug, docSlug) {
|
|
3236
|
+
const client = createHyleClient({ baseUrl: options.baseUrl, token: options.token });
|
|
3237
|
+
const password = (await (0, import_headers.cookies)()).get(await protectedCookieName(slug))?.value;
|
|
3238
|
+
const share = password === void 0 ? void 0 : await client.protected(slug, password, docSlug);
|
|
3239
|
+
if (share?.kind === "disabled") (0, import_navigation6.notFound)();
|
|
3240
|
+
if (share?.kind === "protected") {
|
|
3241
|
+
if (docSlug !== void 0 && share.doc_slug !== docSlug) (0, import_navigation6.notFound)();
|
|
3242
|
+
const here = `/${slug}/${share.doc_slug}`;
|
|
3243
|
+
const article = {
|
|
3244
|
+
...share.article,
|
|
3245
|
+
publication: { ...share.article.publication, canonical_path: here },
|
|
3246
|
+
nav: { truncated: false, items: share.documents.map((d) => ({ slug: d.doc_slug, title: d.title, canonical_path: `/${slug}/${d.doc_slug}`, children: [] })) }
|
|
3247
|
+
};
|
|
3248
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
3249
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
3250
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("meta", { name: "referrer", content: "no-referrer" }),
|
|
3251
|
+
drawArticle(article, { ...options, layout: share.documents.length > 1 ? "docs" : "article" })
|
|
3252
|
+
] });
|
|
3253
|
+
}
|
|
3254
|
+
const gate = await client.protectedGate(slug);
|
|
3255
|
+
if (gate.kind !== "gate") (0, import_navigation6.notFound)();
|
|
3256
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
3257
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
3258
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("meta", { name: "referrer", content: "no-referrer" }),
|
|
3259
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(PasswordForm, { slug, failed: password !== void 0 })
|
|
3260
|
+
] });
|
|
3261
|
+
}
|
|
3262
|
+
function createProtectedUnlockRoute() {
|
|
3263
|
+
return {
|
|
3264
|
+
async POST(req) {
|
|
3265
|
+
const site = req.headers.get("sec-fetch-site");
|
|
3266
|
+
if (site === null ? originMismatch(req) : site !== "same-origin") return new Response(null, { status: 403, headers: PRIVATE_HEADERS });
|
|
3267
|
+
if (!/^application\/x-www-form-urlencoded(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return new Response(null, { status: 415, headers: PRIVATE_HEADERS });
|
|
3268
|
+
if (Number(req.headers.get("content-length")) > UNLOCK_MAX_BYTES) return new Response(null, { status: 413, headers: PRIVATE_HEADERS });
|
|
3269
|
+
const form = await readCapped(new Response(req.body), UNLOCK_MAX_BYTES).catch(() => void 0);
|
|
3270
|
+
if (form === void 0) return new Response(null, { status: 413, headers: PRIVATE_HEADERS });
|
|
3271
|
+
const fields = new URLSearchParams(form);
|
|
3272
|
+
const slug = fields.get("slug") ?? "";
|
|
3273
|
+
if (!PROTECTED_SLUG.test(slug)) return new Response(null, { status: 404, headers: PRIVATE_HEADERS });
|
|
3274
|
+
const password = fields.get("password") ?? "";
|
|
3275
|
+
const headers = new Headers({ ...PRIVATE_HEADERS, Location: `/${slug}` });
|
|
3276
|
+
if (PROTECTED_PASSWORD.test(password)) {
|
|
3277
|
+
const name = await protectedCookieName(slug);
|
|
3278
|
+
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`);
|
|
3279
|
+
}
|
|
3280
|
+
return new Response(null, { status: 303, headers });
|
|
3281
|
+
}
|
|
3282
|
+
};
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3145
3285
|
// src/next/root.ts
|
|
3146
3286
|
var MOUNTS_MAX_STALE_MS = 15 * 60 * 1e3;
|
|
3147
3287
|
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
3148
|
-
var NONE = { mounts: [], reserved: [], defaultLocale: "" };
|
|
3288
|
+
var NONE = { mounts: [], reserved: [], defaultLocale: "", protected: [] };
|
|
3149
3289
|
var lastKnownGood = /* @__PURE__ */ new Map();
|
|
3150
|
-
function mountsLoader(config) {
|
|
3290
|
+
function mountsLoader(config, ttlMs) {
|
|
3151
3291
|
if (!config.workspaceId) throw new TypeError("hyleRootPage: `workspaceId` is required for the fetch cache");
|
|
3152
3292
|
const client = createHyleClient({ baseUrl: config.baseUrl, token: config.token });
|
|
3153
3293
|
const init = { next: { revalidate: config.revalidate ?? DEFAULT_REVALIDATE, tags: workspaceTags(config.workspaceId).slice(0, 1) } };
|
|
3154
3294
|
const key = `${new URL(config.baseUrl).origin}|${config.workspaceId}`;
|
|
3155
|
-
|
|
3295
|
+
async function fetchLoaded() {
|
|
3156
3296
|
try {
|
|
3157
3297
|
const result = await client.mounts({ init });
|
|
3158
3298
|
if (result.kind !== "mounts") {
|
|
3159
3299
|
lastKnownGood.delete(key);
|
|
3160
3300
|
return NONE;
|
|
3161
3301
|
}
|
|
3162
|
-
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale };
|
|
3302
|
+
const loaded = { mounts: activeMounts(result.mounts), reserved: result.reserved, defaultLocale: result.default_locale, protected: result.protected ?? [] };
|
|
3163
3303
|
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
3164
3304
|
return loaded;
|
|
3165
3305
|
} catch (error) {
|
|
3166
|
-
(0,
|
|
3306
|
+
(0, import_navigation7.unstable_rethrow)(error);
|
|
3167
3307
|
if (error instanceof Cp1ClientError && (error.status === 401 || error.status === 403)) {
|
|
3168
3308
|
lastKnownGood.delete(key);
|
|
3169
3309
|
throw error;
|
|
@@ -3172,15 +3312,21 @@ function mountsLoader(config) {
|
|
|
3172
3312
|
if (kept && Date.now() - kept.at <= MOUNTS_MAX_STALE_MS) return kept.loaded;
|
|
3173
3313
|
throw error;
|
|
3174
3314
|
}
|
|
3315
|
+
}
|
|
3316
|
+
if (ttlMs === void 0) return fetchLoaded;
|
|
3317
|
+
let memo;
|
|
3318
|
+
return function load() {
|
|
3319
|
+
if (!memo || memo.until <= Date.now()) memo = { read: fetchLoaded(), until: Date.now() + ttlMs };
|
|
3320
|
+
return memo.read;
|
|
3175
3321
|
};
|
|
3176
3322
|
}
|
|
3177
3323
|
var asArray = (options) => Array.isArray(options) ? options : [options];
|
|
3178
|
-
function setup(options) {
|
|
3324
|
+
function setup(options, ttlMs) {
|
|
3179
3325
|
const configs = asArray(options);
|
|
3180
3326
|
if (configs.length === 0) throw new TypeError("hyleRootPage: pass at least one workspace config");
|
|
3181
3327
|
const param = configs[0].param ?? "hyle";
|
|
3182
3328
|
if (configs.some((c) => (c.param ?? "hyle") !== param)) throw new TypeError("hyleRootPage: every config must use the same `param`");
|
|
3183
|
-
return { configs, param, loaders: configs.map(mountsLoader) };
|
|
3329
|
+
return { configs, param, loaders: configs.map((config) => mountsLoader(config, ttlMs)) };
|
|
3184
3330
|
}
|
|
3185
3331
|
var sectionsOf = (config, mount) => [
|
|
3186
3332
|
...config.sections ?? [],
|
|
@@ -3190,20 +3336,33 @@ function mountOptionsOf(config, mount) {
|
|
|
3190
3336
|
const { mountOptions, ...rest } = config;
|
|
3191
3337
|
return { ...rest, ...mountOptions?.[mount.prefix === "" ? "/" : mount.prefix], basePath: mount.prefix, sections: sectionsOf(config, mount) };
|
|
3192
3338
|
}
|
|
3193
|
-
function rootMounts(options) {
|
|
3194
|
-
const { configs, param, loaders } = setup(options);
|
|
3339
|
+
function rootMounts(options, ttlMs) {
|
|
3340
|
+
const { configs, param, loaders } = setup(options, ttlMs);
|
|
3195
3341
|
return {
|
|
3196
3342
|
param,
|
|
3197
3343
|
async locate(path) {
|
|
3198
3344
|
const loaded = await Promise.all(loaders.map((load) => load()));
|
|
3345
|
+
let share;
|
|
3346
|
+
loaded.forEach(({ protected: slugs }, index) => {
|
|
3347
|
+
for (const slug of slugs) {
|
|
3348
|
+
const depth = slug.split("/").length;
|
|
3349
|
+
if (!prefixMatches(`/${slug}`, path) || share && depth <= share.depth) continue;
|
|
3350
|
+
const docSlug = path === `/${slug}` ? void 0 : path.slice(slug.length + 2);
|
|
3351
|
+
if (docSlug === void 0 || PROTECTED_DOC_SLUG.test(docSlug)) share = { index, slug, depth, docSlug };
|
|
3352
|
+
}
|
|
3353
|
+
});
|
|
3199
3354
|
let best;
|
|
3200
|
-
loaded.forEach(({ mounts, reserved },
|
|
3355
|
+
loaded.forEach(({ mounts, reserved }, index) => {
|
|
3201
3356
|
if (isReserved(path, reserved)) return;
|
|
3202
|
-
for (const
|
|
3357
|
+
for (const mount of mounts) if (prefixMatches(mount.prefix, path) && (!best || mount.depth > best.mount.depth)) best = { index, mount };
|
|
3203
3358
|
});
|
|
3204
|
-
|
|
3205
|
-
const
|
|
3206
|
-
|
|
3359
|
+
const won = share;
|
|
3360
|
+
const mounted = best;
|
|
3361
|
+
if (won && (!mounted || won.depth > mounted.mount.depth || won.depth === mounted.mount.depth && won.index === mounted.index)) {
|
|
3362
|
+
return { share: { config: configs[won.index], slug: won.slug, docSlug: won.docSlug } };
|
|
3363
|
+
}
|
|
3364
|
+
if (!mounted) return void 0;
|
|
3365
|
+
return { options: mountOptionsOf(configs[mounted.index], mounted.mount), mount: mounted.mount, index: mounted.index };
|
|
3207
3366
|
},
|
|
3208
3367
|
async all() {
|
|
3209
3368
|
const out = [];
|
|
@@ -3215,7 +3374,7 @@ function rootMounts(options) {
|
|
|
3215
3374
|
}
|
|
3216
3375
|
};
|
|
3217
3376
|
}
|
|
3218
|
-
function createRouter(options, make) {
|
|
3377
|
+
function createRouter(options, make, share) {
|
|
3219
3378
|
const mounts = rootMounts(options);
|
|
3220
3379
|
const handlers = /* @__PURE__ */ new Map();
|
|
3221
3380
|
return async function route(params) {
|
|
@@ -3225,6 +3384,7 @@ function createRouter(options, make) {
|
|
|
3225
3384
|
if (path === void 0 || path === "/" || !segments) return void 0;
|
|
3226
3385
|
const hit = await mounts.locate(path);
|
|
3227
3386
|
if (!hit) return void 0;
|
|
3387
|
+
if ("share" in hit) return { handler: share(hit.share), params };
|
|
3228
3388
|
const { mount, index } = hit;
|
|
3229
3389
|
const id = `${index}|${mount.prefix}|${mount.defaultSection}`;
|
|
3230
3390
|
let handler = handlers.get(id);
|
|
@@ -3236,15 +3396,15 @@ function createRouter(options, make) {
|
|
|
3236
3396
|
};
|
|
3237
3397
|
}
|
|
3238
3398
|
function hyleRootPage(options) {
|
|
3239
|
-
const route = createRouter(options, hylePage);
|
|
3399
|
+
const route = createRouter(options, hylePage, (s) => () => drawProtectedShare(s.config, s.slug, s.docSlug));
|
|
3240
3400
|
return async function HyleRootPage({ params, searchParams }) {
|
|
3241
3401
|
const hit = await route(await params ?? {});
|
|
3242
|
-
if (!hit) (0,
|
|
3402
|
+
if (!hit) (0, import_navigation7.notFound)();
|
|
3243
3403
|
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
3244
3404
|
};
|
|
3245
3405
|
}
|
|
3246
3406
|
function hyleRootMetadata(options) {
|
|
3247
|
-
const route = createRouter(options, hyleMetadata);
|
|
3407
|
+
const route = createRouter(options, hyleMetadata, () => async () => hyleProtectedMetadata);
|
|
3248
3408
|
return async function generateMetadata({ params, searchParams }, parent) {
|
|
3249
3409
|
const hit = await route(await params ?? {});
|
|
3250
3410
|
return hit ? hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} }, parent) : {};
|
|
@@ -3280,7 +3440,7 @@ function createMarkdownRoute(options) {
|
|
|
3280
3440
|
if (path === void 0 || path === "/") return reply(null, 404);
|
|
3281
3441
|
try {
|
|
3282
3442
|
const hit = await mounts.locate(path);
|
|
3283
|
-
if (!hit) return reply(null, 404);
|
|
3443
|
+
if (!hit || "share" in hit) return reply(null, 404);
|
|
3284
3444
|
const { locale, toHref } = routeContext({ ...hit.options, basePath: "", param: "path" }, params);
|
|
3285
3445
|
const result = await resolverFor(hit.options)(path, locale, void 0, void 0, void 0, "md");
|
|
3286
3446
|
if (result.kind === "article" && result.content.format === "md") {
|
|
@@ -3304,7 +3464,7 @@ function createMarkdownRoute(options) {
|
|
|
3304
3464
|
}
|
|
3305
3465
|
|
|
3306
3466
|
// src/next/llms.ts
|
|
3307
|
-
var
|
|
3467
|
+
var import_navigation8 = require("next/navigation");
|
|
3308
3468
|
var oneLine = (text) => text.replace(/\s+/g, " ").trim();
|
|
3309
3469
|
var linkTarget = (url) => url.replace(/[()]/g, (c) => c === "(" ? "%28" : "%29");
|
|
3310
3470
|
function createLlmsTxtRoute(options, llms) {
|
|
@@ -3329,7 +3489,7 @@ function createLlmsTxtRoute(options, llms) {
|
|
|
3329
3489
|
return new Response(`${lines.join("\n")}
|
|
3330
3490
|
`, { headers: { "Content-Type": "text/plain; charset=utf-8" } });
|
|
3331
3491
|
} catch (error) {
|
|
3332
|
-
(0,
|
|
3492
|
+
(0, import_navigation8.unstable_rethrow)(error);
|
|
3333
3493
|
console.error(`hyle: ${error instanceof Error ? error.name : "UnknownError"}`);
|
|
3334
3494
|
return new Response(null, { status: 503 });
|
|
3335
3495
|
}
|
|
@@ -3346,7 +3506,7 @@ var DEFAULT_TIMEOUT_MS3 = 3e4;
|
|
|
3346
3506
|
var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
|
|
3347
3507
|
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
3348
3508
|
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
3349
|
-
var
|
|
3509
|
+
var PRIVATE_HEADERS2 = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
|
|
3350
3510
|
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
3351
3511
|
var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
3352
3512
|
var THEME_CACHE_CONTROL = "public, max-age=31536000, immutable";
|
|
@@ -3374,11 +3534,11 @@ async function serveTheme(client, scope, hash, timeoutMs, head) {
|
|
|
3374
3534
|
return empty(502);
|
|
3375
3535
|
}
|
|
3376
3536
|
}
|
|
3377
|
-
function protectedAccessFor(req,
|
|
3378
|
-
if (!
|
|
3379
|
-
const name = protectedCookieName(
|
|
3537
|
+
async function protectedAccessFor(req, slug) {
|
|
3538
|
+
if (!PROTECTED_SLUG.test(slug)) return void 0;
|
|
3539
|
+
const name = await protectedCookieName(slug);
|
|
3380
3540
|
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) ? {
|
|
3541
|
+
return password !== void 0 && PROTECTED_PASSWORD.test(password) ? { slug, password } : void 0;
|
|
3382
3542
|
}
|
|
3383
3543
|
function capped(body, max) {
|
|
3384
3544
|
let seen = 0;
|
|
@@ -3398,19 +3558,19 @@ function createAssetRoute(options) {
|
|
|
3398
3558
|
async function serve(req, ctx2, head) {
|
|
3399
3559
|
const query = new URL(req.url).searchParams;
|
|
3400
3560
|
const previewToken = query.get(PREVIEW_PARAM);
|
|
3401
|
-
const
|
|
3402
|
-
const res = await relay(req, ctx2, head, previewToken,
|
|
3403
|
-
if (previewToken !== null ||
|
|
3561
|
+
const slug = query.get(PROTECTED_PARAM);
|
|
3562
|
+
const res = await relay(req, ctx2, head, previewToken, slug);
|
|
3563
|
+
if (previewToken !== null || slug !== null) for (const [name, value] of Object.entries(PRIVATE_HEADERS2)) res.headers.set(name, value);
|
|
3404
3564
|
return res;
|
|
3405
3565
|
}
|
|
3406
|
-
async function relay(req, ctx2, head, previewToken,
|
|
3566
|
+
async function relay(req, ctx2, head, previewToken, slug) {
|
|
3407
3567
|
if (isSwitchedOff3((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
3408
3568
|
const file = (await ctx2.params).file;
|
|
3409
3569
|
const [, themeScope, themeHash] = typeof file === "string" ? THEME_FILE.exec(file) ?? [] : [];
|
|
3410
3570
|
if (typeof file !== "string" || !themeHash && !ASSET_FILE.test(file)) return empty(404);
|
|
3411
3571
|
if (previewToken !== null && !PREVIEW_TOKEN.test(previewToken)) return empty(404);
|
|
3412
|
-
const protectedAccess =
|
|
3413
|
-
if (
|
|
3572
|
+
const protectedAccess = slug === null ? void 0 : await protectedAccessFor(req, slug);
|
|
3573
|
+
if (slug !== null && protectedAccess === void 0) return empty(404);
|
|
3414
3574
|
try {
|
|
3415
3575
|
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
3416
3576
|
} catch {
|
|
@@ -3441,7 +3601,7 @@ function createAssetRoute(options) {
|
|
|
3441
3601
|
const range = upstream.headers.get("content-range");
|
|
3442
3602
|
return empty(416, range ? { "Content-Range": range } : {});
|
|
3443
3603
|
}
|
|
3444
|
-
if (upstream.status === 429 && (previewToken !== null ||
|
|
3604
|
+
if (upstream.status === 429 && (previewToken !== null || slug !== null)) {
|
|
3445
3605
|
drop();
|
|
3446
3606
|
const wait = upstream.headers.get("retry-after");
|
|
3447
3607
|
return empty(429, wait ? { "Retry-After": wait } : {});
|
|
@@ -3468,7 +3628,7 @@ function createAssetRoute(options) {
|
|
|
3468
3628
|
}
|
|
3469
3629
|
|
|
3470
3630
|
// src/next/og.tsx
|
|
3471
|
-
var
|
|
3631
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
3472
3632
|
var SIZE = { width: 1200, height: 630 };
|
|
3473
3633
|
var MAX_TITLE = 140;
|
|
3474
3634
|
function createOgImageRoute(options) {
|
|
@@ -3498,9 +3658,9 @@ function createOgImageRoute(options) {
|
|
|
3498
3658
|
const chars = [...title];
|
|
3499
3659
|
const shown = chars.length > MAX_TITLE ? `${chars.slice(0, MAX_TITLE - 1).join("")}\u2026` : title;
|
|
3500
3660
|
return new import_og.ImageResponse(
|
|
3501
|
-
/* @__PURE__ */ (0,
|
|
3502
|
-
/* @__PURE__ */ (0,
|
|
3503
|
-
options.siteName ? /* @__PURE__ */ (0,
|
|
3661
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { style: { display: "flex", flexDirection: "column", justifyContent: "space-between", width: "100%", height: "100%", padding: 80, background: "#111827", color: "#ffffff" }, children: [
|
|
3662
|
+
/* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { style: { fontSize: 64, fontWeight: 700, lineHeight: 1.2 }, children: shown }),
|
|
3663
|
+
options.siteName ? /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { style: { fontSize: 32, color: "#9ca3af" }, children: options.siteName }) : null
|
|
3504
3664
|
] }),
|
|
3505
3665
|
// 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.
|
|
3506
3666
|
{ ...SIZE, headers: { "cache-control": "public, max-age=3600, s-maxage=31536000, immutable" } }
|
|
@@ -3509,104 +3669,28 @@ function createOgImageRoute(options) {
|
|
|
3509
3669
|
};
|
|
3510
3670
|
}
|
|
3511
3671
|
|
|
3512
|
-
// src/next/
|
|
3513
|
-
var
|
|
3514
|
-
var
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
zIndex: 2147483647,
|
|
3526
|
-
padding: "8px 16px",
|
|
3527
|
-
background: "#fde047",
|
|
3528
|
-
color: "#1a1a1a",
|
|
3529
|
-
font: "600 14px/1.4 system-ui, sans-serif",
|
|
3530
|
-
textAlign: "center"
|
|
3531
|
-
};
|
|
3532
|
-
function hylePreviewPage(options) {
|
|
3533
|
-
return async function HylePreviewPage({ searchParams }) {
|
|
3534
|
-
const { token } = await searchParams ?? {};
|
|
3535
|
-
const result = await createHyleClient(options).preview(typeof token === "string" ? token : void 0);
|
|
3536
|
-
if (result.kind !== "preview") (0, import_navigation7.notFound)();
|
|
3537
|
-
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
3538
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
3539
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("meta", { name: "referrer", content: "no-referrer" }),
|
|
3540
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
|
|
3541
|
-
drawArticle(result.article, options)
|
|
3542
|
-
] });
|
|
3672
|
+
// src/next/protected-view.ts
|
|
3673
|
+
var import_navigation9 = require("next/navigation");
|
|
3674
|
+
var import_server = require("next/server");
|
|
3675
|
+
var VIEW_PATH = "/hyle-protected/view";
|
|
3676
|
+
var MOUNTS_SNAPSHOT_MS = 3e4;
|
|
3677
|
+
var SHARE_PATH = /^\/[a-z0-9-]+(?:\/[a-z0-9-]+){0,4}$/;
|
|
3678
|
+
function hyleProtectedProxy(options) {
|
|
3679
|
+
const mounts = rootMounts(options, MOUNTS_SNAPSHOT_MS);
|
|
3680
|
+
return async function protectedProxy(req) {
|
|
3681
|
+
const path = req.nextUrl.pathname;
|
|
3682
|
+
if (!SHARE_PATH.test(path)) return void 0;
|
|
3683
|
+
const hit = await mounts.locate(path).catch(() => void 0);
|
|
3684
|
+
return hit && "share" in hit ? import_server.NextResponse.rewrite(new URL(`${VIEW_PATH}${path}`, req.url)) : void 0;
|
|
3543
3685
|
};
|
|
3544
3686
|
}
|
|
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
3687
|
function hyleProtectedPage(options) {
|
|
3688
|
+
const mounts = rootMounts(options);
|
|
3582
3689
|
return async function HyleProtectedPage({ params }) {
|
|
3583
|
-
const
|
|
3584
|
-
|
|
3585
|
-
|
|
3586
|
-
|
|
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 })
|
|
3592
|
-
] });
|
|
3593
|
-
};
|
|
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
|
-
}
|
|
3690
|
+
const path = `/${((await params).path ?? []).join("/")}`;
|
|
3691
|
+
const hit = SHARE_PATH.test(path) ? await mounts.locate(path) : void 0;
|
|
3692
|
+
if (!hit || !("share" in hit)) (0, import_navigation9.notFound)();
|
|
3693
|
+
return drawProtectedShare(hit.share.config, hit.share.slug, hit.share.docSlug);
|
|
3610
3694
|
};
|
|
3611
3695
|
}
|
|
3612
3696
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -3633,6 +3717,7 @@ function createProtectedUnlockRoute() {
|
|
|
3633
3717
|
hylePreviewPage,
|
|
3634
3718
|
hyleProtectedMetadata,
|
|
3635
3719
|
hyleProtectedPage,
|
|
3720
|
+
hyleProtectedProxy,
|
|
3636
3721
|
hyleRootMetadata,
|
|
3637
3722
|
hyleRootPage,
|
|
3638
3723
|
hyleRootSitemap,
|