@tdacorp/hyle-sdk 0.22.2 → 0.23.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.
Files changed (36) hide show
  1. package/README.md +32 -1
  2. package/dist/check-routes-bin.js +26 -6
  3. package/dist/{chunk-IW3TUD4G.js → chunk-JHZJOJDC.js} +1 -1
  4. package/dist/{chunk-ZIW6FDU2.js → chunk-UFMKLCXS.js} +2 -2
  5. package/dist/{chunk-7T5EEJHK.js → chunk-VUML2UPD.js} +1 -1
  6. package/dist/{chunk-DUPT6XLB.js → chunk-VXARM37R.js} +12 -1
  7. package/dist/{chunk-KU7LWK4E.js → chunk-YHXE3TGS.js} +26 -7
  8. package/dist/{client-BGjmEWhN.d.cts → client--ighAWaj.d.ts} +7 -1
  9. package/dist/{client-D0LTpr3Y.d.ts → client-DK-S2580.d.cts} +7 -1
  10. package/dist/comments.cjs +4 -1
  11. package/dist/comments.js +4 -1
  12. package/dist/{embed-CbtsbZs3.d.cts → embed-XT0x_Jaa.d.cts} +1 -1
  13. package/dist/{embed-Cf_2ZR5x.d.ts → embed-g7NT1CyB.d.ts} +1 -1
  14. package/dist/html.cjs +4 -1
  15. package/dist/html.js +2 -2
  16. package/dist/index.cjs +26 -6
  17. package/dist/index.d.cts +3 -3
  18. package/dist/index.d.ts +3 -3
  19. package/dist/index.js +2 -2
  20. package/dist/next.cjs +128 -18
  21. package/dist/next.d.cts +42 -7
  22. package/dist/next.d.ts +42 -7
  23. package/dist/next.js +108 -18
  24. package/dist/react.cjs +4 -1
  25. package/dist/react.d.cts +3 -3
  26. package/dist/react.d.ts +3 -3
  27. package/dist/react.js +3 -3
  28. package/dist/{resolve-BysHtZ_i.d.ts → resolve-BqC9l5RH.d.ts} +1 -1
  29. package/dist/{resolve-BnIv7aB7.d.cts → resolve-CiZCPysX.d.cts} +1 -1
  30. package/dist/{types-D09Z072G.d.cts → types-b9QbmEDd.d.cts} +13 -1
  31. package/dist/{types-D09Z072G.d.ts → types-b9QbmEDd.d.ts} +13 -1
  32. package/dist/use-cache.cjs +26 -6
  33. package/dist/use-cache.d.cts +3 -3
  34. package/dist/use-cache.d.ts +3 -3
  35. package/dist/use-cache.js +3 -3
  36. 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-ZIW6FDU2.js";
22
+ } from "./chunk-UFMKLCXS.js";
23
23
  import {
24
24
  stringsFor
25
- } from "./chunk-IW3TUD4G.js";
25
+ } from "./chunk-JHZJOJDC.js";
26
26
  import {
27
27
  DEFAULT_REVALIDATE,
28
28
  fetchResolver,
29
29
  workspaceTags
30
- } from "./chunk-7T5EEJHK.js";
30
+ } from "./chunk-VUML2UPD.js";
31
31
  import {
32
32
  Cp1ClientError,
33
33
  checkBaseUrl,
@@ -40,15 +40,19 @@ import {
40
40
  listPublicationPaths,
41
41
  readCapped,
42
42
  signReaderAssertion
43
- } from "./chunk-KU7LWK4E.js";
43
+ } from "./chunk-YHXE3TGS.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
- THEME_FILE
51
- } from "./chunk-DUPT6XLB.js";
50
+ PROTECTED_ID,
51
+ PROTECTED_PARAM,
52
+ PROTECTED_PASSWORD,
53
+ THEME_FILE,
54
+ protectedCookieName
55
+ } from "./chunk-VXARM37R.js";
52
56
 
53
57
  // src/next/page.tsx
54
58
  import { notFound, permanentRedirect, redirect } from "next/navigation";
@@ -225,6 +229,10 @@ function sameOriginProblem(req, write, allowedOrigins) {
225
229
  const site = req.headers.get("sec-fetch-site");
226
230
  if (site !== null && site !== "same-origin") return true;
227
231
  if (!write) return false;
232
+ if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
233
+ return originMismatch(req, allowedOrigins);
234
+ }
235
+ function originMismatch(req, allowedOrigins) {
228
236
  const origin = req.headers.get("origin");
229
237
  if (origin === null) return true;
230
238
  let parsed;
@@ -233,7 +241,6 @@ function sameOriginProblem(req, write, allowedOrigins) {
233
241
  } catch {
234
242
  return true;
235
243
  }
236
- if (req.headers.get(ENGAGE_CSRF_HEADER) !== "1") return true;
237
244
  if (allowedOrigins) return !allowedOrigins.some((o) => safeOrigin(o) === parsed.origin);
238
245
  const host = req.headers.get("x-forwarded-host")?.split(",")[0]?.trim() || req.headers.get("host") || new URL(req.url).host;
239
246
  const proto = req.headers.get("x-forwarded-proto")?.split(",")[0]?.trim().toLowerCase();
@@ -1021,7 +1028,7 @@ var DEFAULT_TIMEOUT_MS2 = 3e4;
1021
1028
  var CACHE_CONTROL = "public, max-age=3600, s-maxage=86400, stale-while-revalidate=86400";
1022
1029
  var PARTIAL_CACHE_CONTROL = "no-store";
1023
1030
  var SAFE_HEADERS = { "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" };
1024
- var PREVIEW_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
1031
+ var PRIVATE_HEADERS = { "Cache-Control": "no-store", "Referrer-Policy": "no-referrer", "X-Robots-Tag": "noindex, nofollow" };
1025
1032
  var empty = (status, headers = {}) => new Response(null, { status, headers: { "Cache-Control": "no-store", ...headers } });
1026
1033
  var isSwitchedOff3 = (value) => ["0", "false"].includes(value?.trim().toLowerCase() ?? "");
1027
1034
  var THEME_CACHE_CONTROL = "public, max-age=31536000, immutable";
@@ -1049,6 +1056,12 @@ async function serveTheme(client, scope, hash, timeoutMs, head) {
1049
1056
  return empty(502);
1050
1057
  }
1051
1058
  }
1059
+ function protectedAccessFor(req, pageId) {
1060
+ if (!PROTECTED_ID.test(pageId)) return void 0;
1061
+ const name = protectedCookieName(pageId);
1062
+ 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) ? { pageId, password } : void 0;
1064
+ }
1052
1065
  function capped(body, max) {
1053
1066
  let seen = 0;
1054
1067
  return body.pipeThrough(
@@ -1065,17 +1078,21 @@ function createAssetRoute(options) {
1065
1078
  let client;
1066
1079
  const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
1067
1080
  async function serve(req, ctx, head) {
1068
- const previewToken = new URL(req.url).searchParams.get(PREVIEW_PARAM);
1069
- const res = await relay(req, ctx, head, previewToken);
1070
- if (previewToken !== null) for (const [name, value] of Object.entries(PREVIEW_HEADERS)) res.headers.set(name, value);
1081
+ const query = new URL(req.url).searchParams;
1082
+ const previewToken = query.get(PREVIEW_PARAM);
1083
+ const pageId = query.get(PROTECTED_PARAM);
1084
+ const res = await relay(req, ctx, head, previewToken, pageId);
1085
+ if (previewToken !== null || pageId !== null) for (const [name, value] of Object.entries(PRIVATE_HEADERS)) res.headers.set(name, value);
1071
1086
  return res;
1072
1087
  }
1073
- async function relay(req, ctx, head, previewToken) {
1088
+ async function relay(req, ctx, head, previewToken, pageId) {
1074
1089
  if (isSwitchedOff3((options.env ?? process.env).HYLE_CONTENT_ENABLED)) return empty(404);
1075
1090
  const file = (await ctx.params).file;
1076
1091
  const [, themeScope, themeHash] = typeof file === "string" ? THEME_FILE.exec(file) ?? [] : [];
1077
1092
  if (typeof file !== "string" || !themeHash && !ASSET_FILE.test(file)) return empty(404);
1078
1093
  if (previewToken !== null && !PREVIEW_TOKEN.test(previewToken)) return empty(404);
1094
+ const protectedAccess = pageId === null ? void 0 : protectedAccessFor(req, pageId);
1095
+ if (pageId !== null && protectedAccess === void 0) return empty(404);
1079
1096
  try {
1080
1097
  client ??= createHyleClient({ baseUrl: options.baseUrl?.trim() ?? "", token: options.token?.trim() ?? "", ...options.fetch ? { fetch: options.fetch } : {} });
1081
1098
  } catch {
@@ -1087,6 +1104,7 @@ function createAssetRoute(options) {
1087
1104
  upstream = await client.asset(file, {
1088
1105
  timeoutMs: options.timeoutMs ?? DEFAULT_TIMEOUT_MS2,
1089
1106
  ...previewToken === null ? {} : { previewToken },
1107
+ ...protectedAccess === void 0 ? {} : { protectedAccess },
1090
1108
  headers: { range: req.headers.get("range"), "if-range": req.headers.get("if-range"), "if-none-match": req.headers.get("if-none-match") }
1091
1109
  });
1092
1110
  } catch {
@@ -1105,7 +1123,7 @@ function createAssetRoute(options) {
1105
1123
  const range = upstream.headers.get("content-range");
1106
1124
  return empty(416, range ? { "Content-Range": range } : {});
1107
1125
  }
1108
- if (upstream.status === 429 && previewToken !== null) {
1126
+ if (upstream.status === 429 && (previewToken !== null || pageId !== null)) {
1109
1127
  drop();
1110
1128
  const wait = upstream.headers.get("retry-after");
1111
1129
  return empty(429, wait ? { "Retry-After": wait } : {});
@@ -1176,6 +1194,12 @@ function createOgImageRoute(options) {
1176
1194
  // src/next/preview.tsx
1177
1195
  import { notFound as notFound3 } from "next/navigation";
1178
1196
  import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
1197
+ function drawArticle(article, options) {
1198
+ const { locale } = article.publication;
1199
+ const toHref = (sitePath, linkLocale = locale) => (options.localePrefix?.(linkLocale) ?? "") + sitePath;
1200
+ const props = { article, components: options.components, slots: options.slots, locale, toHref };
1201
+ return options.layout === "docs" ? /* @__PURE__ */ jsx4(DocsPage, { ...props }) : /* @__PURE__ */ jsx4(ArticlePage, { ...props });
1202
+ }
1179
1203
  var hylePreviewMetadata = { robots: { index: false, follow: false }, referrer: "no-referrer" };
1180
1204
  var BANNER = {
1181
1205
  position: "sticky",
@@ -1192,18 +1216,81 @@ function hylePreviewPage(options) {
1192
1216
  const { token } = await searchParams ?? {};
1193
1217
  const result = await createHyleClient(options).preview(typeof token === "string" ? token : void 0);
1194
1218
  if (result.kind !== "preview") notFound3();
1195
- const { article } = result;
1196
- const { locale } = article.publication;
1197
- const toHref = (sitePath, linkLocale = locale) => (options.localePrefix?.(linkLocale) ?? "") + sitePath;
1198
- const props = { article, components: options.components, slots: options.slots, locale, toHref };
1199
1219
  return /* @__PURE__ */ jsxs2(Fragment, { children: [
1200
1220
  /* @__PURE__ */ jsx4("meta", { name: "robots", content: "noindex, nofollow" }),
1201
1221
  /* @__PURE__ */ jsx4("meta", { name: "referrer", content: "no-referrer" }),
1202
1222
  /* @__PURE__ */ jsx4("div", { role: "status", style: BANNER, children: "Unpublished draft preview" }),
1203
- options.layout === "docs" ? /* @__PURE__ */ jsx4(DocsPage, { ...props }) : /* @__PURE__ */ jsx4(ArticlePage, { ...props })
1223
+ drawArticle(result.article, options)
1204
1224
  ] });
1205
1225
  };
1206
1226
  }
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
+ function hyleProtectedPage(options) {
1264
+ return async function HyleProtectedPage({ params }) {
1265
+ const { id } = await params;
1266
+ if (typeof id !== "string" || !PROTECTED_ID.test(id)) notFound4();
1267
+ const password = (await cookies()).get(protectedCookieName(id))?.value;
1268
+ const result = password === void 0 ? void 0 : await createHyleClient(options).protected(id, password);
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
+ }
1292
+ };
1293
+ }
1207
1294
  export {
1208
1295
  ENGAGE_CSRF_HEADER,
1209
1296
  HyleArticle,
@@ -1216,6 +1303,7 @@ export {
1216
1303
  createLlmsTxtRoute,
1217
1304
  createMarkdownRoute,
1218
1305
  createOgImageRoute,
1306
+ createProtectedUnlockRoute,
1219
1307
  createRevalidateRoute,
1220
1308
  fetchResolver,
1221
1309
  hyleFeed,
@@ -1224,6 +1312,8 @@ export {
1224
1312
  hylePage,
1225
1313
  hylePreviewMetadata,
1226
1314
  hylePreviewPage,
1315
+ hyleProtectedMetadata,
1316
+ hyleProtectedPage,
1227
1317
  hyleRootMetadata,
1228
1318
  hyleRootPage,
1229
1319
  hyleRootSitemap,
package/dist/react.cjs CHANGED
@@ -73,7 +73,10 @@ var PREVIEW_TOKEN_SOURCE = "hyle_pv_[A-Za-z0-9_-]{43}";
73
73
  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
- var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
76
+ var PROTECTED_PARAM = "hyle_protected";
77
+ var PROTECTED_ID = new RegExp(`^${UUID}$`);
78
+ var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
79
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
77
80
  function hostAssetSrc(src) {
78
81
  const [, file, query = ""] = HYLE_ASSET_URL.exec(src) ?? [];
79
82
  return file ? `${ASSET_ROUTE_PREFIX}/${file.toLowerCase()}${query}` : 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-CbtsbZs3.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-CbtsbZs3.cjs';
3
+ import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-XT0x_Jaa.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-XT0x_Jaa.cjs';
5
5
  export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-BpY_AdZh.cjs';
6
- import { j as ResolvedArticle, L as ListItem, o as TocEntry, l as ResolvedList, c as EngageListing, T as ThemeRef } from './types-D09Z072G.cjs';
6
+ import { k as ResolvedArticle, L as ListItem, p as TocEntry, m as ResolvedList, c as EngageListing, T as ThemeRef } from './types-b9QbmEDd.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-Cf_2ZR5x.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-Cf_2ZR5x.js';
3
+ import { H as HyleComponents, P as PageBaseProps, E as EngagementConfig, J as JsonLdConfig } from './embed-g7NT1CyB.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-g7NT1CyB.js';
5
5
  export { H as HastLimitError, i as isSafeUrl, s as sanitizeHast, a as scopeId } from './sanitize-BpY_AdZh.js';
6
- import { j as ResolvedArticle, L as ListItem, o as TocEntry, l as ResolvedList, c as EngageListing, T as ThemeRef } from './types-D09Z072G.js';
6
+ import { k as ResolvedArticle, L as ListItem, p as TocEntry, m as ResolvedList, c as EngageListing, T as ThemeRef } from './types-b9QbmEDd.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-ZIW6FDU2.js";
23
+ } from "./chunk-UFMKLCXS.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-IW3TUD4G.js";
32
- import "./chunk-DUPT6XLB.js";
31
+ } from "./chunk-JHZJOJDC.js";
32
+ import "./chunk-VXARM37R.js";
33
33
  export {
34
34
  ArticlePage,
35
35
  Comments,
@@ -1,4 +1,4 @@
1
- import { i as Resolved } from './types-D09Z072G.js';
1
+ import { j as Resolved } from './types-b9QbmEDd.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>;
@@ -1,4 +1,4 @@
1
- import { i as Resolved } from './types-D09Z072G.cjs';
1
+ import { j as Resolved } from './types-b9QbmEDd.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>;
@@ -276,5 +276,17 @@ type HylePreview =
276
276
  } | {
277
277
  readonly kind: "disabled";
278
278
  };
279
+ /** The `data` of GET /cp1/read/_protected (hyle ADR 0039): a password-protected page, or why there is none. */
280
+ type HyleProtected =
281
+ /** `expires_at`: when the page stops working, or null for none. The article's asset addresses carry the page id. */
282
+ {
283
+ readonly kind: "protected";
284
+ readonly expires_at: string | null;
285
+ readonly article: ResolvedArticle;
286
+ } | {
287
+ readonly kind: "notfound";
288
+ } | {
289
+ readonly kind: "disabled";
290
+ };
279
291
 
280
- export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, Mounts as d, MountsResult as e, NavNode as f, NavTree as g, ReactionKind as h, Resolved as i, ResolvedArticle as j, ResolvedDisabled as k, ResolvedList as l, ResolvedNotFound as m, ResolvedRedirect as n, TocEntry as o };
292
+ export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, HyleProtected as d, Mounts as e, MountsResult as f, NavNode as g, NavTree as h, ReactionKind as i, Resolved as j, ResolvedArticle as k, ResolvedDisabled as l, ResolvedList as m, ResolvedNotFound as n, ResolvedRedirect as o, TocEntry as p };
@@ -276,5 +276,17 @@ type HylePreview =
276
276
  } | {
277
277
  readonly kind: "disabled";
278
278
  };
279
+ /** The `data` of GET /cp1/read/_protected (hyle ADR 0039): a password-protected page, or why there is none. */
280
+ type HyleProtected =
281
+ /** `expires_at`: when the page stops working, or null for none. The article's asset addresses carry the page id. */
282
+ {
283
+ readonly kind: "protected";
284
+ readonly expires_at: string | null;
285
+ readonly article: ResolvedArticle;
286
+ } | {
287
+ readonly kind: "notfound";
288
+ } | {
289
+ readonly kind: "disabled";
290
+ };
279
291
 
280
- export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, Mounts as d, MountsResult as e, NavNode as f, NavTree as g, ReactionKind as h, Resolved as i, ResolvedArticle as j, ResolvedDisabled as k, ResolvedList as l, ResolvedNotFound as m, ResolvedRedirect as n, TocEntry as o };
292
+ export type { Alternate as A, Breadcrumb as B, CacheInfo as C, DocumentMetaFields as D, EngageComment as E, Fallback as F, HylePreview as H, ListItem as L, Mount as M, NavItem as N, ReactionCounts as R, ThemeRef as T, VoteValue as V, ArticleContent as a, EngageHeldComment as b, EngageListing as c, HyleProtected as d, Mounts as e, MountsResult as f, NavNode as g, NavTree as h, ReactionKind as i, Resolved as j, ResolvedArticle as k, ResolvedDisabled as l, ResolvedList as m, ResolvedNotFound as n, ResolvedRedirect as o, TocEntry as p };
@@ -35,7 +35,12 @@ var PREVIEW_TOKEN = new RegExp(`^${PREVIEW_TOKEN_SOURCE}$`);
35
35
  var PREVIEW_HEADER = "cp-preview";
36
36
  var PREVIEW_PARAM = "hyle_preview";
37
37
  var PREVIEW_QUERY_SOURCE = `\\?${PREVIEW_PARAM}=${PREVIEW_TOKEN_SOURCE}`;
38
- var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE})?$`, "i");
38
+ var PROTECTED_PARAM = "hyle_protected";
39
+ var PROTECTED_HEADER = "cp-protected";
40
+ var PROTECTED_ID = new RegExp(`^${UUID}$`);
41
+ var PROTECTED_PASSWORD = /^[A-Za-z0-9]{16}$/;
42
+ var PROTECTED_QUERY_SOURCE = `\\?${PROTECTED_PARAM}=${UUID}`;
43
+ var HYLE_ASSET_URL = new RegExp(`^/assets/(${UUID}(?:\\.(?:${EXTENSIONS}))?)(${PREVIEW_QUERY_SOURCE}|${PROTECTED_QUERY_SOURCE})?$`, "i");
39
44
 
40
45
  // src/errors.ts
41
46
  var Cp1ClientError = class extends Error {
@@ -67,8 +72,8 @@ function mapNode(node, mark, depth) {
67
72
  ...Array.isArray(children) ? { children: children.map((child) => mapNode(child, mark, depth + 1)) } : {}
68
73
  };
69
74
  }
70
- function withPreviewAssets(article, token) {
71
- const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${PREVIEW_PARAM}=${token}`) : value;
75
+ function withAssetQuery(article, query) {
76
+ const mark = (value) => typeof value === "string" ? value.replace(ASSET_PATH, (path) => `${path}?${query}`) : value;
72
77
  const { publication, content } = article;
73
78
  return {
74
79
  ...article,
@@ -197,7 +202,18 @@ function createHyleClient(options) {
197
202
  if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
198
203
  const article = data?.article;
199
204
  if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
200
- return { kind: "preview", expires_at: data.expires_at, article: withPreviewAssets(article, token) };
205
+ return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
206
+ }
207
+ async function protectedPage(pageId, password) {
208
+ if (!PROTECTED_ID.test(pageId) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
209
+ const reply = await get("/cp1/read/_protected", new URLSearchParams(), { headers: { [PROTECTED_HEADER]: `${pageId}.${password}` }, cache: "no-store" });
210
+ if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
211
+ const data = reply.parsed?.data;
212
+ if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
213
+ const article = data?.article;
214
+ const expires = data?.expires_at;
215
+ if (data?.cp !== 1 || data.kind !== "protected" || typeof expires !== "string" && expires !== null || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
216
+ return { kind: "protected", expires_at: expires, article: withAssetQuery(article, `${PROTECTED_PARAM}=${pageId}`) };
201
217
  }
202
218
  async function asset(file, opts = {}) {
203
219
  if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
@@ -211,8 +227,12 @@ function createHyleClient(options) {
211
227
  const value = opts.headers?.[name];
212
228
  if (value) headers.set(name, value);
213
229
  }
230
+ const { protectedAccess } = opts;
231
+ 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");
214
232
  if (previewToken !== void 0) headers.set(PREVIEW_HEADER, previewToken);
215
- return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...previewToken === void 0 ? {} : { cache: "no-store" } });
233
+ if (protectedAccess !== void 0) headers.set(PROTECTED_HEADER, `${protectedAccess.pageId}.${protectedAccess.password}`);
234
+ const uncached = previewToken !== void 0 || protectedAccess !== void 0;
235
+ return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS), ...uncached ? { cache: "no-store" } : {} });
216
236
  }
217
237
  async function theme(opts = {}) {
218
238
  const url = `${base}/cp1/read/theme.css`;
@@ -221,7 +241,7 @@ function createHyleClient(options) {
221
241
  if (applied) await applied;
222
242
  return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
223
243
  }
224
- return { resolve, mounts, pushPosts, preview, asset, theme };
244
+ return { resolve, mounts, pushPosts, preview, protected: protectedPage, asset, theme };
225
245
  }
226
246
 
227
247
  // src/tag-validation.ts
@@ -1,6 +1,6 @@
1
- import { H as HyleAuth } from './client-BGjmEWhN.cjs';
2
- import { H as HyleResolver } from './resolve-BnIv7aB7.cjs';
3
- import './types-D09Z072G.cjs';
1
+ import { H as HyleAuth } from './client-DK-S2580.cjs';
2
+ import { H as HyleResolver } from './resolve-CiZCPysX.cjs';
3
+ import './types-b9QbmEDd.cjs';
4
4
 
5
5
  /**
6
6
  * The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
@@ -1,6 +1,6 @@
1
- import { H as HyleAuth } from './client-D0LTpr3Y.js';
2
- import { H as HyleResolver } from './resolve-BysHtZ_i.js';
3
- import './types-D09Z072G.js';
1
+ import { H as HyleAuth } from './client--ighAWaj.js';
2
+ import { H as HyleResolver } from './resolve-BqC9l5RH.js';
3
+ import './types-b9QbmEDd.js';
4
4
 
5
5
  /**
6
6
  * The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
package/dist/use-cache.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  DEFAULT_REVALIDATE
3
- } from "./chunk-7T5EEJHK.js";
3
+ } from "./chunk-VUML2UPD.js";
4
4
  import {
5
5
  createHyleClient,
6
6
  isValidCacheTag
7
- } from "./chunk-KU7LWK4E.js";
8
- import "./chunk-DUPT6XLB.js";
7
+ } from "./chunk-YHXE3TGS.js";
8
+ import "./chunk-VXARM37R.js";
9
9
 
10
10
  // src/next/use-cache.ts
11
11
  import { cacheLife, cacheTag } from "next/cache";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tdacorp/hyle-sdk",
3
- "version": "0.22.2",
3
+ "version": "0.23.0",
4
4
  "description": "hyle SDK: a typed client for hyle's resolve endpoint, a hast renderer for React, and a Next.js catch-all page with tag-based revalidation.",
5
5
  "license": "MIT",
6
6
  "repository": {