@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.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,19 +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
|
-
|
|
50
|
+
PROTECTED_DOC_SLUG,
|
|
51
51
|
PROTECTED_PARAM,
|
|
52
52
|
PROTECTED_PASSWORD,
|
|
53
|
+
PROTECTED_SLUG,
|
|
53
54
|
THEME_FILE,
|
|
54
55
|
protectedCookieName
|
|
55
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-BDFMNY76.js";
|
|
56
57
|
|
|
57
58
|
// src/next/page.tsx
|
|
58
59
|
import { notFound, permanentRedirect, redirect } from "next/navigation";
|
|
@@ -798,7 +799,7 @@ function createRevalidateRoute(options) {
|
|
|
798
799
|
}
|
|
799
800
|
|
|
800
801
|
// src/next/root.ts
|
|
801
|
-
import { notFound as
|
|
802
|
+
import { notFound as notFound4, unstable_rethrow as unstable_rethrow4 } from "next/navigation";
|
|
802
803
|
|
|
803
804
|
// src/next/mount-match.ts
|
|
804
805
|
function activeMounts(mounts) {
|
|
@@ -824,24 +825,147 @@ function isReserved(path, reserved) {
|
|
|
824
825
|
return reserved.some((entry) => entry.endsWith("/*") ? prefixMatches(entry.slice(0, -2), path) : entry === path);
|
|
825
826
|
}
|
|
826
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
|
+
|
|
827
951
|
// src/next/root.ts
|
|
828
952
|
var MOUNTS_MAX_STALE_MS = 15 * 60 * 1e3;
|
|
829
953
|
var SECTION_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
830
|
-
var NONE = { mounts: [], reserved: [], defaultLocale: "" };
|
|
954
|
+
var NONE = { mounts: [], reserved: [], defaultLocale: "", protected: [] };
|
|
831
955
|
var lastKnownGood = /* @__PURE__ */ new Map();
|
|
832
|
-
function mountsLoader(config) {
|
|
956
|
+
function mountsLoader(config, ttlMs) {
|
|
833
957
|
if (!config.workspaceId) throw new TypeError("hyleRootPage: `workspaceId` is required for the fetch cache");
|
|
834
958
|
const client = createHyleClient({ baseUrl: config.baseUrl, token: config.token });
|
|
835
959
|
const init = { next: { revalidate: config.revalidate ?? DEFAULT_REVALIDATE, tags: workspaceTags(config.workspaceId).slice(0, 1) } };
|
|
836
960
|
const key = `${new URL(config.baseUrl).origin}|${config.workspaceId}`;
|
|
837
|
-
|
|
961
|
+
async function fetchLoaded() {
|
|
838
962
|
try {
|
|
839
963
|
const result = await client.mounts({ init });
|
|
840
964
|
if (result.kind !== "mounts") {
|
|
841
965
|
lastKnownGood.delete(key);
|
|
842
966
|
return NONE;
|
|
843
967
|
}
|
|
844
|
-
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 ?? [] };
|
|
845
969
|
lastKnownGood.set(key, { loaded, at: Date.now() });
|
|
846
970
|
return loaded;
|
|
847
971
|
} catch (error) {
|
|
@@ -854,15 +978,21 @@ function mountsLoader(config) {
|
|
|
854
978
|
if (kept && Date.now() - kept.at <= MOUNTS_MAX_STALE_MS) return kept.loaded;
|
|
855
979
|
throw error;
|
|
856
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;
|
|
857
987
|
};
|
|
858
988
|
}
|
|
859
989
|
var asArray = (options) => Array.isArray(options) ? options : [options];
|
|
860
|
-
function setup(options) {
|
|
990
|
+
function setup(options, ttlMs) {
|
|
861
991
|
const configs = asArray(options);
|
|
862
992
|
if (configs.length === 0) throw new TypeError("hyleRootPage: pass at least one workspace config");
|
|
863
993
|
const param = configs[0].param ?? "hyle";
|
|
864
994
|
if (configs.some((c) => (c.param ?? "hyle") !== param)) throw new TypeError("hyleRootPage: every config must use the same `param`");
|
|
865
|
-
return { configs, param, loaders: configs.map(mountsLoader) };
|
|
995
|
+
return { configs, param, loaders: configs.map((config) => mountsLoader(config, ttlMs)) };
|
|
866
996
|
}
|
|
867
997
|
var sectionsOf = (config, mount) => [
|
|
868
998
|
...config.sections ?? [],
|
|
@@ -872,20 +1002,33 @@ function mountOptionsOf(config, mount) {
|
|
|
872
1002
|
const { mountOptions, ...rest } = config;
|
|
873
1003
|
return { ...rest, ...mountOptions?.[mount.prefix === "" ? "/" : mount.prefix], basePath: mount.prefix, sections: sectionsOf(config, mount) };
|
|
874
1004
|
}
|
|
875
|
-
function rootMounts(options) {
|
|
876
|
-
const { configs, param, loaders } = setup(options);
|
|
1005
|
+
function rootMounts(options, ttlMs) {
|
|
1006
|
+
const { configs, param, loaders } = setup(options, ttlMs);
|
|
877
1007
|
return {
|
|
878
1008
|
param,
|
|
879
1009
|
async locate(path) {
|
|
880
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
|
+
});
|
|
881
1020
|
let best;
|
|
882
|
-
loaded.forEach(({ mounts, reserved },
|
|
1021
|
+
loaded.forEach(({ mounts, reserved }, index) => {
|
|
883
1022
|
if (isReserved(path, reserved)) return;
|
|
884
|
-
for (const
|
|
1023
|
+
for (const mount of mounts) if (prefixMatches(mount.prefix, path) && (!best || mount.depth > best.mount.depth)) best = { index, mount };
|
|
885
1024
|
});
|
|
886
|
-
|
|
887
|
-
const
|
|
888
|
-
|
|
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 };
|
|
889
1032
|
},
|
|
890
1033
|
async all() {
|
|
891
1034
|
const out = [];
|
|
@@ -897,7 +1040,7 @@ function rootMounts(options) {
|
|
|
897
1040
|
}
|
|
898
1041
|
};
|
|
899
1042
|
}
|
|
900
|
-
function createRouter(options, make) {
|
|
1043
|
+
function createRouter(options, make, share) {
|
|
901
1044
|
const mounts = rootMounts(options);
|
|
902
1045
|
const handlers = /* @__PURE__ */ new Map();
|
|
903
1046
|
return async function route(params) {
|
|
@@ -907,6 +1050,7 @@ function createRouter(options, make) {
|
|
|
907
1050
|
if (path === void 0 || path === "/" || !segments) return void 0;
|
|
908
1051
|
const hit = await mounts.locate(path);
|
|
909
1052
|
if (!hit) return void 0;
|
|
1053
|
+
if ("share" in hit) return { handler: share(hit.share), params };
|
|
910
1054
|
const { mount, index } = hit;
|
|
911
1055
|
const id = `${index}|${mount.prefix}|${mount.defaultSection}`;
|
|
912
1056
|
let handler = handlers.get(id);
|
|
@@ -918,15 +1062,15 @@ function createRouter(options, make) {
|
|
|
918
1062
|
};
|
|
919
1063
|
}
|
|
920
1064
|
function hyleRootPage(options) {
|
|
921
|
-
const route = createRouter(options, hylePage);
|
|
1065
|
+
const route = createRouter(options, hylePage, (s) => () => drawProtectedShare(s.config, s.slug, s.docSlug));
|
|
922
1066
|
return async function HyleRootPage({ params, searchParams }) {
|
|
923
1067
|
const hit = await route(await params ?? {});
|
|
924
|
-
if (!hit)
|
|
1068
|
+
if (!hit) notFound4();
|
|
925
1069
|
return hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} });
|
|
926
1070
|
};
|
|
927
1071
|
}
|
|
928
1072
|
function hyleRootMetadata(options) {
|
|
929
|
-
const route = createRouter(options, hyleMetadata);
|
|
1073
|
+
const route = createRouter(options, hyleMetadata, () => async () => hyleProtectedMetadata);
|
|
930
1074
|
return async function generateMetadata({ params, searchParams }, parent) {
|
|
931
1075
|
const hit = await route(await params ?? {});
|
|
932
1076
|
return hit ? hit.handler({ params: Promise.resolve(hit.params), ...searchParams ? { searchParams } : {} }, parent) : {};
|
|
@@ -962,7 +1106,7 @@ function createMarkdownRoute(options) {
|
|
|
962
1106
|
if (path === void 0 || path === "/") return reply(null, 404);
|
|
963
1107
|
try {
|
|
964
1108
|
const hit = await mounts.locate(path);
|
|
965
|
-
if (!hit) return reply(null, 404);
|
|
1109
|
+
if (!hit || "share" in hit) return reply(null, 404);
|
|
966
1110
|
const { locale, toHref } = routeContext({ ...hit.options, basePath: "", param: "path" }, params);
|
|
967
1111
|
const result = await resolverFor(hit.options)(path, locale, void 0, void 0, void 0, "md");
|
|
968
1112
|
if (result.kind === "article" && result.content.format === "md") {
|
|
@@ -1028,7 +1172,7 @@ var DEFAULT_TIMEOUT_MS2 = 3e4;
|
|
|
1028
1172
|
var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
|
|
1029
1173
|
var PARTIAL_CACHE_CONTROL = "no-store";
|
|
1030
1174
|
var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
|
|
1031
|
-
var
|
|
1175
|
+
var PRIVATE_HEADERS2 = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
|
|
1032
1176
|
var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
|
|
1033
1177
|
var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
|
|
1034
1178
|
var THEME_CACHE_CONTROL = "public, max-age=31536000, immutable";
|
|
@@ -1056,11 +1200,11 @@ async function serveTheme(client, scope, hash, timeoutMs, head) {
|
|
|
1056
1200
|
return empty(502);
|
|
1057
1201
|
}
|
|
1058
1202
|
}
|
|
1059
|
-
function protectedAccessFor(req,
|
|
1060
|
-
if (!
|
|
1061
|
-
const name = protectedCookieName(
|
|
1203
|
+
async function protectedAccessFor(req, slug) {
|
|
1204
|
+
if (!PROTECTED_SLUG.test(slug)) return void 0;
|
|
1205
|
+
const name = await protectedCookieName(slug);
|
|
1062
1206
|
const password = req.headers.get("cookie")?.split(";").map((c) => c.trim()).find((c) => c.startsWith(`${name}=`))?.slice(name.length + 1);
|
|
1063
|
-
return password !== void 0 && PROTECTED_PASSWORD.test(password) ? {
|
|
1207
|
+
return password !== void 0 && PROTECTED_PASSWORD.test(password) ? { slug, password } : void 0;
|
|
1064
1208
|
}
|
|
1065
1209
|
function capped(body, max) {
|
|
1066
1210
|
let seen = 0;
|
|
@@ -1080,19 +1224,19 @@ function createAssetRoute(options) {
|
|
|
1080
1224
|
async function serve(req, ctx, head) {
|
|
1081
1225
|
const query = new URL(req.url).searchParams;
|
|
1082
1226
|
const previewToken = query.get(PREVIEW_PARAM);
|
|
1083
|
-
const
|
|
1084
|
-
const res = await relay(req, ctx, head, previewToken,
|
|
1085
|
-
if (previewToken !== null ||
|
|
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);
|
|
1086
1230
|
return res;
|
|
1087
1231
|
}
|
|
1088
|
-
async function relay(req, ctx, head, previewToken,
|
|
1232
|
+
async function relay(req, ctx, head, previewToken, slug) {
|
|
1089
1233
|
if (isSwitchedOff3((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
|
|
1090
1234
|
const file = (await ctx.params).file;
|
|
1091
1235
|
const [, themeScope, themeHash] = typeof file === "string" ? THEME_FILE.exec(file) ?? [] : [];
|
|
1092
1236
|
if (typeof file !== "string" || !themeHash && !ASSET_FILE.test(file)) return empty(404);
|
|
1093
1237
|
if (previewToken !== null && !PREVIEW_TOKEN.test(previewToken)) return empty(404);
|
|
1094
|
-
const protectedAccess =
|
|
1095
|
-
if (
|
|
1238
|
+
const protectedAccess = slug === null ? void 0 : await protectedAccessFor(req, slug);
|
|
1239
|
+
if (slug !== null && protectedAccess === void 0) return empty(404);
|
|
1096
1240
|
try {
|
|
1097
1241
|
client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
|
|
1098
1242
|
} catch {
|
|
@@ -1123,7 +1267,7 @@ function createAssetRoute(options) {
|
|
|
1123
1267
|
const range = upstream.headers.get("content-range");
|
|
1124
1268
|
return empty(416, range ? { "Content-Range": range } : {});
|
|
1125
1269
|
}
|
|
1126
|
-
if (upstream.status === 429 && (previewToken !== null ||
|
|
1270
|
+
if (upstream.status === 429 && (previewToken !== null || slug !== null)) {
|
|
1127
1271
|
drop();
|
|
1128
1272
|
const wait = upstream.headers.get("retry-after");
|
|
1129
1273
|
return empty(429, wait ? { "Retry-After": wait } : {});
|
|
@@ -1150,7 +1294,7 @@ function createAssetRoute(options) {
|
|
|
1150
1294
|
}
|
|
1151
1295
|
|
|
1152
1296
|
// src/next/og.tsx
|
|
1153
|
-
import { jsx as
|
|
1297
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1154
1298
|
var SIZE = { width: 1200, height: 630 };
|
|
1155
1299
|
var MAX_TITLE = 140;
|
|
1156
1300
|
function createOgImageRoute(options) {
|
|
@@ -1180,9 +1324,9 @@ function createOgImageRoute(options) {
|
|
|
1180
1324
|
const chars = [...title];
|
|
1181
1325
|
const shown = chars.length > MAX_TITLE ? `${chars.slice(0, MAX_TITLE - 1).join("")}\u2026` : title;
|
|
1182
1326
|
return new ImageResponse(
|
|
1183
|
-
/* @__PURE__ */
|
|
1184
|
-
/* @__PURE__ */
|
|
1185
|
-
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
|
|
1186
1330
|
] }),
|
|
1187
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.
|
|
1188
1332
|
{ ...SIZE, headers: { "cache-control": "public, max-age=3600, s-maxage=31536000, immutable" } }
|
|
@@ -1191,104 +1335,28 @@ function createOgImageRoute(options) {
|
|
|
1191
1335
|
};
|
|
1192
1336
|
}
|
|
1193
1337
|
|
|
1194
|
-
// src/next/
|
|
1195
|
-
import { notFound as
|
|
1196
|
-
import {
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
zIndex: 2147483647,
|
|
1208
|
-
padding: "8px 16px",
|
|
1209
|
-
background: "#fde047",
|
|
1210
|
-
color: "#1a1a1a",
|
|
1211
|
-
font: "600 14px/1.4 system-ui, sans-serif",
|
|
1212
|
-
textAlign: "center"
|
|
1213
|
-
};
|
|
1214
|
-
function hylePreviewPage(options) {
|
|
1215
|
-
return async function HylePreviewPage({ searchParams }) {
|
|
1216
|
-
const { token } = await searchParams ?? {};
|
|
1217
|
-
const result = await createHyleClient(options).preview(typeof token === "string" ? token : void 0);
|
|
1218
|
-
if (result.kind !== "preview") notFound3();
|
|
1219
|
-
return /* @__PURE__ */ jsxs2(Fragment, { children: [
|
|
1220
|
-
/* @__PURE__ */ jsx4("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
1221
|
-
/* @__PURE__ */ jsx4("meta", { name: "referrer", content: "no-referrer" }),
|
|
1222
|
-
/* @__PURE__ */ jsx4("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
|
|
1223
|
-
drawArticle(result.article, options)
|
|
1224
|
-
] });
|
|
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;
|
|
1225
1351
|
};
|
|
1226
1352
|
}
|
|
1227
|
-
|
|
1228
|
-
// src/next/protected.tsx
|
|
1229
|
-
import { cookies } from "next/headers";
|
|
1230
|
-
import { notFound as notFound4 } from "next/navigation";
|
|
1231
|
-
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1232
|
-
var hyleProtectedMetadata = { robots: { index: false, follow: false }, referrer: "same-origin" };
|
|
1233
|
-
var COOKIE_MAX_AGE_SECONDS = 12 * 60 * 60;
|
|
1234
|
-
var UNLOCK_MAX_BYTES = 1024;
|
|
1235
|
-
var PRIVATE_HEADERS2 = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
|
|
1236
|
-
var PASSWORD_FIELD = "hyle-protected-password";
|
|
1237
|
-
var ERROR_ID = "hyle-protected-error";
|
|
1238
|
-
function PasswordForm({ pageId, failed }) {
|
|
1239
|
-
return /* @__PURE__ */ jsxs3("main", { children: [
|
|
1240
|
-
/* @__PURE__ */ jsx5("h1", { children: "Protected page" }),
|
|
1241
|
-
/* @__PURE__ */ jsxs3("form", { method: "post", action: `/p/${pageId}/unlock`, autoComplete: "off", children: [
|
|
1242
|
-
/* @__PURE__ */ jsx5("label", { htmlFor: PASSWORD_FIELD, children: "Password" }),
|
|
1243
|
-
/* @__PURE__ */ jsx5(
|
|
1244
|
-
"input",
|
|
1245
|
-
{
|
|
1246
|
-
id: PASSWORD_FIELD,
|
|
1247
|
-
name: "password",
|
|
1248
|
-
type: "password",
|
|
1249
|
-
autoComplete: "off",
|
|
1250
|
-
spellCheck: false,
|
|
1251
|
-
required: true,
|
|
1252
|
-
pattern: "[A-Za-z0-9]{16}",
|
|
1253
|
-
title: "16 letters or digits",
|
|
1254
|
-
"aria-invalid": failed || void 0,
|
|
1255
|
-
"aria-describedby": failed ? ERROR_ID : void 0
|
|
1256
|
-
}
|
|
1257
|
-
),
|
|
1258
|
-
/* @__PURE__ */ jsx5("button", { type: "submit", children: "Open" }),
|
|
1259
|
-
failed ? /* @__PURE__ */ jsx5("p", { id: ERROR_ID, role: "alert", children: "Wrong or expired password." }) : null
|
|
1260
|
-
] })
|
|
1261
|
-
] });
|
|
1262
|
-
}
|
|
1263
1353
|
function hyleProtectedPage(options) {
|
|
1354
|
+
const mounts = rootMounts(options);
|
|
1264
1355
|
return async function HyleProtectedPage({ params }) {
|
|
1265
|
-
const
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
if (result?.kind === "disabled") notFound4();
|
|
1270
|
-
return /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
1271
|
-
/* @__PURE__ */ jsx5("meta", { name: "robots", content: "noindex, nofollow" }),
|
|
1272
|
-
/* @__PURE__ */ jsx5("meta", { name: "referrer", content: "same-origin" }),
|
|
1273
|
-
result?.kind === "protected" ? drawArticle(result.article, options) : /* @__PURE__ */ jsx5(PasswordForm, { pageId: id, failed: result !== void 0 })
|
|
1274
|
-
] });
|
|
1275
|
-
};
|
|
1276
|
-
}
|
|
1277
|
-
function createProtectedUnlockRoute() {
|
|
1278
|
-
return {
|
|
1279
|
-
async POST(req, ctx) {
|
|
1280
|
-
const { id } = await ctx.params;
|
|
1281
|
-
if (typeof id !== "string" || !PROTECTED_ID.test(id)) return new Response(null, { status: 404, headers: PRIVATE_HEADERS2 });
|
|
1282
|
-
const site = req.headers.get("sec-fetch-site");
|
|
1283
|
-
if (site === null ? originMismatch(req) : site !== "same-origin") return new Response(null, { status: 403, headers: PRIVATE_HEADERS2 });
|
|
1284
|
-
if (!/^application\/x-www-form-urlencoded(\s*;|$)/i.test(req.headers.get("content-type") ?? "")) return new Response(null, { status: 415, headers: PRIVATE_HEADERS2 });
|
|
1285
|
-
if (Number(req.headers.get("content-length")) > UNLOCK_MAX_BYTES) return new Response(null, { status: 413, headers: PRIVATE_HEADERS2 });
|
|
1286
|
-
const form = await readCapped(new Response(req.body), UNLOCK_MAX_BYTES).catch(() => void 0);
|
|
1287
|
-
if (form === void 0) return new Response(null, { status: 413, headers: PRIVATE_HEADERS2 });
|
|
1288
|
-
const password = new URLSearchParams(form).get("password") ?? "";
|
|
1289
|
-
const cookie = PROTECTED_PASSWORD.test(password) ? { "Set-Cookie": `${protectedCookieName(id)}=${password}; Max-Age=${COOKIE_MAX_AGE_SECONDS}; Path=/; HttpOnly; Secure; SameSite=Lax` } : {};
|
|
1290
|
-
return new Response(null, { status: 303, headers: { ...PRIVATE_HEADERS2, Location: `/p/${id}`, ...cookie } });
|
|
1291
|
-
}
|
|
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);
|
|
1292
1360
|
};
|
|
1293
1361
|
}
|
|
1294
1362
|
export {
|
|
@@ -1314,6 +1382,7 @@ export {
|
|
|
1314
1382
|
hylePreviewPage,
|
|
1315
1383
|
hyleProtectedMetadata,
|
|
1316
1384
|
hyleProtectedPage,
|
|
1385
|
+
hyleProtectedProxy,
|
|
1317
1386
|
hyleRootMetadata,
|
|
1318
1387
|
hyleRootPage,
|
|
1319
1388
|
hyleRootSitemap,
|
package/dist/react.cjs
CHANGED
|
@@ -74,8 +74,9 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
|
|
|
74
74
|
var PREVIEW_PARAM = "hyle_preview";
|
|
75
75
|
var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
|
|
76
76
|
var PROTECTED_PARAM = "hyle_protected";
|
|
77
|
-
var
|
|
78
|
-
var
|
|
77
|
+
var SHARE_SLUG = "[a-z0-9-]+(?:/[a-z0-9-]+){0,3}";
|
|
78
|
+
var PROTECTED_SLUG = new RegExp(`^${SHARE_SLUG}$`);
|
|
79
|
+
var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${SHARE_SLUG}`;
|
|
79
80
|
var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
|
|
80
81
|
function hostAssetSrc(src) {
|
|
81
82
|
const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
|
package/dist/react.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-
|
|
4
|
-
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-
|
|
3
|
+
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-B7T--kTT.cjs';
|
|
4
|
+
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-B7T--kTT.cjs';
|
|
5
5
|
export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-BpY_AdZh.cjs';
|
|
6
|
-
import {
|
|
6
|
+
import { m as ResolvedArticle, L as ListItem, r as TocEntry, o as ResolvedList, c as EngageListing, T as ThemeRef } from './types-Dx-fEiZd.cjs';
|
|
7
7
|
import 'hast';
|
|
8
8
|
|
|
9
9
|
interface HastContentProps {
|
package/dist/react.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ReactElement, ReactNode } from 'react';
|
|
3
|
-
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-
|
|
4
|
-
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-
|
|
3
|
+
import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-DavTgSU4.js';
|
|
4
|
+
export { A as ArticleRef, C as CalloutKind, d as CalloutProps, e as CodeBlockProps, b as EmbedHeading, f as HyleArticleView, g as HyleArticleViewProps, h as HyleListView, i as HyleListViewProps, a as HyleSlots, I as ImageProps, L as LinkProps, j as ListItemProps, M as MermaidProps, O as OgImage } from './embed-DavTgSU4.js';
|
|
5
5
|
export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-BpY_AdZh.js';
|
|
6
|
-
import {
|
|
6
|
+
import { m as ResolvedArticle, L as ListItem, r as TocEntry, o as ResolvedList, c as EngageListing, T as ThemeRef } from './types-Dx-fEiZd.js';
|
|
7
7
|
import 'hast';
|
|
8
8
|
|
|
9
9
|
interface HastContentProps {
|
package/dist/react.js
CHANGED
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
isClampedSource,
|
|
21
21
|
isLargeDiagram,
|
|
22
22
|
stripMermaidConfig
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-5TKJH2XC.js";
|
|
24
24
|
import {
|
|
25
25
|
HastLimitError,
|
|
26
26
|
VIEWER_LABELS_EN,
|
|
@@ -28,8 +28,8 @@ import {
|
|
|
28
28
|
sanitizeHast,
|
|
29
29
|
scopeId,
|
|
30
30
|
stringsFor
|
|
31
|
-
} from "./chunk-
|
|
32
|
-
import "./chunk-
|
|
31
|
+
} from "./chunk-Y3BACEWA.js";
|
|
32
|
+
import "./chunk-BDFMNY76.js";
|
|
33
33
|
export {
|
|
34
34
|
ArticlePage,
|
|
35
35
|
Comments,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as Resolved } from './types-Dx-fEiZd.cjs';
|
|
2
2
|
|
|
3
3
|
/** Resolves a site path to a result. The two built-in strategies are `fetchResolver` (default) and `cachedResolver` (`@tdacorp/hyle-sdk/next/use-cache`). */
|
|
4
4
|
type HyleResolver = (path: string, locale: string | undefined, limit?: number, cursor?: string, nav?: "tree", format?: "md") => Promise<Resolved>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { l as Resolved } from './types-Dx-fEiZd.js';
|
|
2
2
|
|
|
3
3
|
/** Resolves a site path to a result. The two built-in strategies are `fetchResolver` (default) and `cachedResolver` (`@tdacorp/hyle-sdk/next/use-cache`). */
|
|
4
4
|
type HyleResolver = (path: string, locale: string | undefined, limit?: number, cursor?: string, nav?: "tree", format?: "md") => Promise<Resolved>;
|