@tdacorp/hyle-sdk 0.24.0 → 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.
- package/README.md +7 -5
- package/dist/{embed-B7T--kTT.d.cts → brand-CwXvdSkk.d.ts} +14 -2
- package/dist/{embed-DavTgSU4.d.ts → brand-IuZSB9UX.d.cts} +14 -2
- package/dist/check-routes-bin.js +10 -5
- package/dist/{chunk-4REU4HJI.js → chunk-3UQGU62T.js} +22 -5
- package/dist/{chunk-SY2FMIRZ.js → chunk-IDBQSMWT.js} +1 -1
- package/dist/{chunk-5TKJH2XC.js → chunk-NUQQ6VHH.js} +267 -43
- package/dist/{chunk-Y3BACEWA.js → chunk-T4EZAQFU.js} +129 -3
- package/dist/chunk-VAR2B7S6.js +82 -0
- package/dist/{chunk-U74B7AUG.js → chunk-ZWKAEWEW.js} +22 -74
- package/dist/{client-BErei7cE.d.ts → client-B2zi_BGq.d.ts} +11 -4
- package/dist/{client-DrB2vcTi.d.cts → client-DBZTvcCh.d.cts} +11 -4
- package/dist/comments.cjs +25 -1
- package/dist/comments.js +4 -2
- package/dist/html.cjs +129 -3
- package/dist/html.js +1 -1
- package/dist/index.cjs +22 -5
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1 -1
- package/dist/next.cjs +674 -211
- package/dist/next.d.cts +44 -18
- package/dist/next.d.ts +44 -18
- package/dist/next.js +241 -135
- package/dist/react.cjs +401 -46
- package/dist/react.d.cts +114 -4
- package/dist/react.d.ts +114 -4
- package/dist/react.js +14 -4
- package/dist/reactions.cjs +25 -1
- package/dist/reactions.js +4 -2
- package/dist/{resolve-03IVloXU.d.cts → resolve-0nGnsIHo.d.cts} +1 -1
- package/dist/{resolve-BseM68oy.d.ts → resolve-CguSaZLa.d.ts} +1 -1
- package/dist/{revalidation-callback-BQl77tQR.d.cts → revalidation-callback-FT9ik1dh.d.cts} +11 -0
- package/dist/{revalidation-callback-BQl77tQR.d.ts → revalidation-callback-FT9ik1dh.d.ts} +11 -0
- package/dist/share-client.cjs +498 -0
- package/dist/share-client.d.cts +99 -0
- package/dist/share-client.d.ts +99 -0
- package/dist/share-client.js +390 -0
- package/dist/styles.css +176 -1
- package/dist/{types-Dx-fEiZd.d.cts → types-CdaIzSjg.d.cts} +10 -3
- package/dist/{types-Dx-fEiZd.d.ts → types-CdaIzSjg.d.ts} +10 -3
- package/dist/use-cache.cjs +10 -5
- package/dist/use-cache.d.cts +3 -3
- package/dist/use-cache.d.ts +3 -3
- package/dist/use-cache.js +2 -2
- package/package.json +1 -1
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-
|
|
27
|
+
} from "./chunk-NUQQ6VHH.js";
|
|
23
28
|
import {
|
|
24
29
|
stringsFor
|
|
25
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-T4EZAQFU.js";
|
|
26
31
|
import {
|
|
27
32
|
DEFAULT_REVALIDATE,
|
|
28
33
|
fetchResolver,
|
|
29
34
|
workspaceTags
|
|
30
|
-
} from "./chunk-
|
|
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-
|
|
48
|
+
} from "./chunk-3UQGU62T.js";
|
|
44
49
|
import {
|
|
45
50
|
ASSET_CONTENT_TYPES,
|
|
46
51
|
ASSET_FILE,
|
|
@@ -383,9 +388,9 @@ function createEngagementRoute(options) {
|
|
|
383
388
|
try {
|
|
384
389
|
const early = await options.onRequest(req, { action: route.action(req.method) });
|
|
385
390
|
if (early instanceof Response) {
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
return new Response(early.body, { status: early.status, headers });
|
|
391
|
+
const headers2 = new Headers(early.headers);
|
|
392
|
+
headers2.set("cache-control", "no-store");
|
|
393
|
+
return new Response(early.body, { status: early.status, headers: headers2 });
|
|
389
394
|
}
|
|
390
395
|
} catch {
|
|
391
396
|
return refuse(502, "UPSTREAM_ERROR");
|
|
@@ -413,11 +418,11 @@ function createEngagementRoute(options) {
|
|
|
413
418
|
if (built.body) baseHeaders.set("content-type", "application/json");
|
|
414
419
|
const target = `${config.base}/cp1/engage${built.upstream}${built.query ? `?${built.query}` : ""}`;
|
|
415
420
|
const call = async (withAssertion = assertion) => {
|
|
416
|
-
const
|
|
417
|
-
if (withAssertion)
|
|
421
|
+
const headers2 = new Headers(baseHeaders);
|
|
422
|
+
if (withAssertion) headers2.set("hyle-reader-assertion", withAssertion);
|
|
418
423
|
const res = await fetchImpl(target, {
|
|
419
424
|
method: req.method,
|
|
420
|
-
headers,
|
|
425
|
+
headers: headers2,
|
|
421
426
|
...built.body ? { body: JSON.stringify(built.body) } : {},
|
|
422
427
|
redirect: "error",
|
|
423
428
|
signal: AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS)
|
|
@@ -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
|
|
460
|
-
const { result, failure } = await resolveEmbed(options, () => resolve(path, route.locale, limit,
|
|
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 });
|
|
@@ -739,7 +744,7 @@ function hyleMetadata(options) {
|
|
|
739
744
|
import { unstable_rethrow as unstable_rethrow3 } from "next/navigation";
|
|
740
745
|
var xml = (value) => value.replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
741
746
|
var tag = (name, value) => `<${name}>${xml(value)}</${name}>`;
|
|
742
|
-
var response = (body, status,
|
|
747
|
+
var response = (body, status, headers2) => new Response(body, { status, ...headers2 ? { headers: headers2 } : {} });
|
|
743
748
|
async function hyleFeed(options) {
|
|
744
749
|
const origin = options.siteOrigin;
|
|
745
750
|
if (!origin || !BARE_HTTPS_ORIGIN.test(origin)) {
|
|
@@ -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 = {
|
|
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
|
|
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,123 +896,106 @@ 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
|
|
874
|
-
var
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
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 });
|
|
913
|
+
}
|
|
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" };
|
|
900
917
|
}
|
|
901
|
-
async function drawProtectedShare(options, slug, docSlug) {
|
|
918
|
+
async function drawProtectedShare(options, slug, docSlug, clientIp, { locked = false } = {}) {
|
|
902
919
|
const client = createHyleClient({ baseUrl: options.baseUrl, token: options.token });
|
|
920
|
+
const visitor = { clientIp };
|
|
903
921
|
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 === "
|
|
922
|
+
const share = password === void 0 ? void 0 : await client.protected(slug, password, docSlug, visitor);
|
|
923
|
+
if (share?.kind === "limited") return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
924
|
+
PRIVATE_META,
|
|
925
|
+
gate("attempts", slug, share.retryAfterSeconds, options.host)
|
|
926
|
+
] });
|
|
927
|
+
if (share?.kind === "disabled") notFound2();
|
|
906
928
|
if (share?.kind === "protected") {
|
|
907
|
-
if (docSlug !== void 0 && share.doc_slug !== docSlug)
|
|
908
|
-
const
|
|
909
|
-
const
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
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: [
|
|
933
|
+
PRIVATE_META,
|
|
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
|
+
)
|
|
918
952
|
] });
|
|
919
953
|
}
|
|
920
|
-
const
|
|
921
|
-
if (
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
954
|
+
const gateReply = await client.protectedGate(slug, visitor);
|
|
955
|
+
if (gateReply.kind === "limited") return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
956
|
+
PRIVATE_META,
|
|
957
|
+
gate("attempts", slug, gateReply.retryAfterSeconds, options.host)
|
|
958
|
+
] });
|
|
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: [
|
|
963
|
+
PRIVATE_META,
|
|
964
|
+
/* @__PURE__ */ jsx3(ShareGate, { state, slug, docSlug, unlockAction: UNLOCK_PATH, host: options.host, theme })
|
|
926
965
|
] });
|
|
927
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
|
+
}
|
|
928
979
|
function createProtectedUnlockRoute() {
|
|
929
980
|
return {
|
|
930
981
|
async POST(req) {
|
|
931
|
-
const
|
|
932
|
-
if (
|
|
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);
|
|
982
|
+
const fields = await readProtectedForm(req);
|
|
983
|
+
if (fields instanceof Response) return fields;
|
|
938
984
|
const slug = fields.get("slug") ?? "";
|
|
939
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}` });
|
|
940
994
|
const password = fields.get("password") ?? "";
|
|
941
|
-
const headers = new Headers({ ...PRIVATE_HEADERS, Location: `/${slug}` });
|
|
942
995
|
if (PROTECTED_PASSWORD.test(password)) {
|
|
943
|
-
const
|
|
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`);
|
|
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`);
|
|
945
997
|
}
|
|
946
|
-
return new Response(null, { status: 303, headers });
|
|
998
|
+
return new Response(null, { status: 303, headers: headers2 });
|
|
947
999
|
}
|
|
948
1000
|
};
|
|
949
1001
|
}
|
|
@@ -980,10 +1032,24 @@ function mountsLoader(config, ttlMs) {
|
|
|
980
1032
|
}
|
|
981
1033
|
}
|
|
982
1034
|
if (ttlMs === void 0) return fetchLoaded;
|
|
983
|
-
let
|
|
1035
|
+
let ready;
|
|
1036
|
+
let read;
|
|
1037
|
+
let until = 0;
|
|
1038
|
+
let pending = false;
|
|
984
1039
|
return function load() {
|
|
985
|
-
if (
|
|
986
|
-
|
|
1040
|
+
if (until <= Date.now() && !pending) {
|
|
1041
|
+
pending = true;
|
|
1042
|
+
until = Date.now() + ttlMs;
|
|
1043
|
+
read = fetchLoaded().then(
|
|
1044
|
+
(loaded) => ready = loaded,
|
|
1045
|
+
(error) => {
|
|
1046
|
+
ready = void 0;
|
|
1047
|
+
throw error;
|
|
1048
|
+
}
|
|
1049
|
+
);
|
|
1050
|
+
read.then(() => pending = false, () => pending = false);
|
|
1051
|
+
}
|
|
1052
|
+
return ready ? Promise.resolve(ready) : read;
|
|
987
1053
|
};
|
|
988
1054
|
}
|
|
989
1055
|
var asArray = (options) => Array.isArray(options) ? options : [options];
|
|
@@ -1062,10 +1128,10 @@ function createRouter(options, make, share) {
|
|
|
1062
1128
|
};
|
|
1063
1129
|
}
|
|
1064
1130
|
function hyleRootPage(options) {
|
|
1065
|
-
const route = createRouter(options, hylePage, (
|
|
1131
|
+
const route = createRouter(options, hylePage, () => async () => notFound3());
|
|
1066
1132
|
return async function HyleRootPage({ params, searchParams }) {
|
|
1067
1133
|
const hit = await route(await params ?? {});
|
|
1068
|
-
if (!hit)
|
|
1134
|
+
if (!hit) notFound3();
|
|
1069
1135
|
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
1070
1136
|
};
|
|
1071
1137
|
}
|
|
@@ -1092,9 +1158,9 @@ function markdownRewritePath(pathname) {
|
|
|
1092
1158
|
if (!pathname.startsWith("/") || !pathname.endsWith(".md") || pathname.endsWith("/.md") || pathname.startsWith("/api/")) return void 0;
|
|
1093
1159
|
return MD_ROUTE_PREFIX + pathname.slice(0, -3);
|
|
1094
1160
|
}
|
|
1095
|
-
var reply = (body, status,
|
|
1161
|
+
var reply = (body, status, headers2 = {}) => (
|
|
1096
1162
|
// noindex on every answer: the .md twin must never compete with the page it mirrors.
|
|
1097
|
-
new Response(body, { status, headers: { "X-Robots-Tag": "noindex", ...
|
|
1163
|
+
new Response(body, { status, headers: { "X-Robots-Tag": "noindex", ...headers2 } })
|
|
1098
1164
|
);
|
|
1099
1165
|
function createMarkdownRoute(options) {
|
|
1100
1166
|
const mounts = rootMounts(options);
|
|
@@ -1173,7 +1239,7 @@ var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidat
|
|
|
1173
1239
|
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
1174
1240
|
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
1175
1241
|
var PRIVATE_HEADERS2 = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
|
|
1176
|
-
var empty = (status,
|
|
1242
|
+
var empty = (status, headers2 = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers2 } });
|
|
1177
1243
|
var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
1178
1244
|
var THEME_CACHE_CONTROL = "public, max-age=31536000, immutable";
|
|
1179
1245
|
var OUTDATED_THEME_CACHE_CONTROL = "public, max-age=60";
|
|
@@ -1194,8 +1260,8 @@ async function serveTheme(client, scope, hash, timeoutMs, head) {
|
|
|
1194
1260
|
const current = await sha256Hex(css);
|
|
1195
1261
|
if (current !== hash && upstream.headers.get(THEME_SCOPE_HEADER) !== scope) return empty(404);
|
|
1196
1262
|
const cache = current === hash ? THEME_CACHE_CONTROL : OUTDATED_THEME_CACHE_CONTROL;
|
|
1197
|
-
const
|
|
1198
|
-
return new Response(head ? null : css, { status: 200, headers });
|
|
1263
|
+
const headers2 = { "Content-Type": "text/css; charset=utf-8", "Cache-Control": cache, ETag: `"${current}"`, ...SAFE_HEADERS };
|
|
1264
|
+
return new Response(head ? null : css, { status: 200, headers: headers2 });
|
|
1199
1265
|
} catch {
|
|
1200
1266
|
return empty(502);
|
|
1201
1267
|
}
|
|
@@ -1279,22 +1345,22 @@ function createAssetRoute(options) {
|
|
|
1279
1345
|
drop();
|
|
1280
1346
|
return empty(502);
|
|
1281
1347
|
}
|
|
1282
|
-
const
|
|
1283
|
-
if (etag)
|
|
1348
|
+
const headers2 = new Headers({ "Content-Type": type, "Accept-Ranges": "bytes", "Cache-Control": upstream.status === 206 ? PARTIAL_CACHE_CONTROL : CACHE_CONTROL, Vary: "Range", ...SAFE_HEADERS });
|
|
1349
|
+
if (etag) headers2.set("ETag", etag);
|
|
1284
1350
|
const contentRange = upstream.headers.get("content-range");
|
|
1285
|
-
if (upstream.status === 206 && contentRange)
|
|
1286
|
-
if (!upstream.headers.get("content-encoding") && upstream.headers.get("content-length"))
|
|
1351
|
+
if (upstream.status === 206 && contentRange) headers2.set("Content-Range", contentRange);
|
|
1352
|
+
if (!upstream.headers.get("content-encoding") && upstream.headers.get("content-length")) headers2.set("Content-Length", String(length));
|
|
1287
1353
|
if (head) {
|
|
1288
1354
|
drop();
|
|
1289
|
-
return new Response(null, { status: upstream.status, headers });
|
|
1355
|
+
return new Response(null, { status: upstream.status, headers: headers2 });
|
|
1290
1356
|
}
|
|
1291
|
-
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers });
|
|
1357
|
+
return new Response(capped(upstream.body, maxBytes), { status: upstream.status, headers: headers2 });
|
|
1292
1358
|
}
|
|
1293
1359
|
return { GET: (req, ctx) => serve(req, ctx, false), HEAD: (req, ctx) => serve(req, ctx, true) };
|
|
1294
1360
|
}
|
|
1295
1361
|
|
|
1296
1362
|
// src/next/og.tsx
|
|
1297
|
-
import { jsx as
|
|
1363
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1298
1364
|
var SIZE = { width: 1200, height: 630 };
|
|
1299
1365
|
var MAX_TITLE = 140;
|
|
1300
1366
|
function createOgImageRoute(options) {
|
|
@@ -1324,9 +1390,9 @@ function createOgImageRoute(options) {
|
|
|
1324
1390
|
const chars = [...title];
|
|
1325
1391
|
const shown = chars.length > MAX_TITLE ? `${chars.slice(0, MAX_TITLE - 1).join("")}\u2026` : title;
|
|
1326
1392
|
return new ImageResponse(
|
|
1327
|
-
/* @__PURE__ */
|
|
1328
|
-
/* @__PURE__ */
|
|
1329
|
-
options.siteName ? /* @__PURE__ */
|
|
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
|
|
1330
1396
|
] }),
|
|
1331
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.
|
|
1332
1398
|
{ ...SIZE, headers: { "cache-control": "public, max-age=3600, s-maxage=31536000, immutable" } }
|
|
@@ -1335,28 +1401,68 @@ function createOgImageRoute(options) {
|
|
|
1335
1401
|
};
|
|
1336
1402
|
}
|
|
1337
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
|
+
|
|
1338
1438
|
// src/next/protected-view.ts
|
|
1439
|
+
import { headers } from "next/headers";
|
|
1339
1440
|
import { notFound as notFound5 } from "next/navigation";
|
|
1340
1441
|
import { NextResponse } from "next/server";
|
|
1341
1442
|
var VIEW_PATH = "/hyle-protected/view";
|
|
1342
1443
|
var MOUNTS_SNAPSHOT_MS = 3e4;
|
|
1444
|
+
var DEFAULT_LOOKUP_TIMEOUT_MS = 1500;
|
|
1343
1445
|
var SHARE_PATH = /^\/[a-z0-9-]+(?:\/[a-z0-9-]+){0,4}$/;
|
|
1344
|
-
function hyleProtectedProxy(options) {
|
|
1446
|
+
function hyleProtectedProxy(options, { lookupTimeoutMs = DEFAULT_LOOKUP_TIMEOUT_MS } = {}) {
|
|
1345
1447
|
const mounts = rootMounts(options, MOUNTS_SNAPSHOT_MS);
|
|
1346
1448
|
return async function protectedProxy(req) {
|
|
1347
1449
|
const path = req.nextUrl.pathname;
|
|
1348
1450
|
if (!SHARE_PATH.test(path)) return void 0;
|
|
1349
|
-
|
|
1350
|
-
|
|
1451
|
+
let timer;
|
|
1452
|
+
const deadline = new Promise((resolve) => timer = setTimeout(resolve, lookupTimeoutMs));
|
|
1453
|
+
const hit = await Promise.race([mounts.locate(path).catch(() => void 0), deadline]).finally(() => clearTimeout(timer));
|
|
1454
|
+
return hit && "share" in hit ? NextResponse.rewrite(new URL(`${VIEW_PATH}${path}${req.nextUrl.search}`, req.url)) : void 0;
|
|
1351
1455
|
};
|
|
1352
1456
|
}
|
|
1353
|
-
|
|
1457
|
+
var forwardedClientIp = (h) => h.get("x-forwarded-for")?.split(",")[0]?.trim() || h.get("x-real-ip")?.trim() || void 0;
|
|
1458
|
+
function hyleProtectedPage(options, { clientIp = forwardedClientIp } = {}) {
|
|
1354
1459
|
const mounts = rootMounts(options);
|
|
1355
|
-
return async function HyleProtectedPage({ params }) {
|
|
1460
|
+
return async function HyleProtectedPage({ params, searchParams }) {
|
|
1356
1461
|
const path = `/${((await params).path ?? []).join("/")}`;
|
|
1357
1462
|
const hit = SHARE_PATH.test(path) ? await mounts.locate(path) : void 0;
|
|
1358
1463
|
if (!hit || !("share" in hit)) notFound5();
|
|
1359
|
-
|
|
1464
|
+
const locked = (await searchParams)?.locked === "1";
|
|
1465
|
+
return drawProtectedShare(hit.share.config, hit.share.slug, hit.share.docSlug, clientIp(await headers()), { locked });
|
|
1360
1466
|
};
|
|
1361
1467
|
}
|
|
1362
1468
|
export {
|