@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.
Files changed (46) hide show
  1. package/README.md +7 -5
  2. package/dist/{embed-B7T--kTT.d.cts → brand-CwXvdSkk.d.ts} +14 -2
  3. package/dist/{embed-DavTgSU4.d.ts → brand-IuZSB9UX.d.cts} +14 -2
  4. package/dist/check-routes-bin.js +10 -5
  5. package/dist/{chunk-4REU4HJI.js → chunk-3UQGU62T.js} +22 -5
  6. package/dist/{chunk-SY2FMIRZ.js → chunk-IDBQSMWT.js} +1 -1
  7. package/dist/{chunk-5TKJH2XC.js → chunk-NUQQ6VHH.js} +267 -43
  8. package/dist/{chunk-Y3BACEWA.js → chunk-T4EZAQFU.js} +129 -3
  9. package/dist/chunk-VAR2B7S6.js +82 -0
  10. package/dist/{chunk-U74B7AUG.js → chunk-ZWKAEWEW.js} +22 -74
  11. package/dist/{client-BErei7cE.d.ts → client-B2zi_BGq.d.ts} +11 -4
  12. package/dist/{client-DrB2vcTi.d.cts → client-DBZTvcCh.d.cts} +11 -4
  13. package/dist/comments.cjs +25 -1
  14. package/dist/comments.js +4 -2
  15. package/dist/html.cjs +129 -3
  16. package/dist/html.js +1 -1
  17. package/dist/index.cjs +22 -5
  18. package/dist/index.d.cts +4 -4
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +1 -1
  21. package/dist/next.cjs +674 -211
  22. package/dist/next.d.cts +44 -18
  23. package/dist/next.d.ts +44 -18
  24. package/dist/next.js +241 -135
  25. package/dist/react.cjs +401 -46
  26. package/dist/react.d.cts +114 -4
  27. package/dist/react.d.ts +114 -4
  28. package/dist/react.js +14 -4
  29. package/dist/reactions.cjs +25 -1
  30. package/dist/reactions.js +4 -2
  31. package/dist/{resolve-03IVloXU.d.cts → resolve-0nGnsIHo.d.cts} +1 -1
  32. package/dist/{resolve-BseM68oy.d.ts → resolve-CguSaZLa.d.ts} +1 -1
  33. package/dist/{revalidation-callback-BQl77tQR.d.cts → revalidation-callback-FT9ik1dh.d.cts} +11 -0
  34. package/dist/{revalidation-callback-BQl77tQR.d.ts → revalidation-callback-FT9ik1dh.d.ts} +11 -0
  35. package/dist/share-client.cjs +498 -0
  36. package/dist/share-client.d.cts +99 -0
  37. package/dist/share-client.d.ts +99 -0
  38. package/dist/share-client.js +390 -0
  39. package/dist/styles.css +176 -1
  40. package/dist/{types-Dx-fEiZd.d.cts → types-CdaIzSjg.d.cts} +10 -3
  41. package/dist/{types-Dx-fEiZd.d.ts → types-CdaIzSjg.d.ts} +10 -3
  42. package/dist/use-cache.cjs +10 -5
  43. package/dist/use-cache.d.cts +3 -3
  44. package/dist/use-cache.d.ts +3 -3
  45. package/dist/use-cache.js +2 -2
  46. package/package.json +1 -1
package/README.md CHANGED
@@ -153,7 +153,7 @@ export default function Wrapper(props) { return <Suspense fallback={null}><Page
153
153
 
154
154
  The credential is never part of a cache key: entries are keyed by `baseUrl` plus `workspaceId` (pass both to `cachedResolver`), and the token stays in a module-level map. A switched-off read surface (`kind: "disabled"`) is cached for at most 30 s, so turning it back on is not delayed by the full window.
155
155
 
156
- The revalidate route expires tags immediately (`revalidateTag(tag, { expire: 0 })`), so no stale page is served after a purge. `HYLE_CONTENT_ENABLED=0` (or `false`) answers 404 from the route, the site-side rollback switch; nothing configured is also 404; partly configured is 503.
156
+ The revalidate route expires tags immediately (`revalidateTag(tag, { expire: 0 })`), so no stale page is served after a purge. With `indexNow: { origin, key }` (for example `{ origin: "https://www.example.com", key: process.env.HYLE_INDEXNOW_KEY }`) it also submits the addresses a publish changed to IndexNow (Bing, Yandex and others; Google does not take part) after the purge. It submits only in production (`VERCEL_ENV`, else `NODE_ENV`) and only with a key, and a failure is logged and never changes hyle's answer. Set `HYLE_INDEXNOW_KEY` in production only: off Vercel the gate is `NODE_ENV`, so a staging server built in production mode would submit too. Pass `localePrefix` as you pass it to `hylePage`, and serve the key at `/<key>.txt` from `public/`. `HYLE_CONTENT_ENABLED=0` (or `false`) answers 404 from the route, the site-side rollback switch; nothing configured is also 404; partly configured is 503.
157
157
 
158
158
  ### List pages
159
159
 
@@ -427,7 +427,7 @@ The token is a bearer secret for that draft, together with your read credential,
427
427
 
428
428
  ## Protected shares
429
429
 
430
- A protected share is a named group of documents that a visitor opens with a password (hyle ADR 0040). It is never published: it is in no list, sitemap, feed or search, and its pages are `noindex`. The share is reachable at a slug on your site, for example `/news/field-notes`, and `/news/field-notes/<doc>` for one of its documents. Your existing catch-all serves it, so the only route file to add is the unlock route:
430
+ A protected share is a named group of documents that a visitor opens with a password (hyle ADR 0040). It is never published: it is in no list, sitemap, feed or search, and its pages are `noindex`. The share is reachable at a slug on your site, for example `/news/field-notes`, and `/news/field-notes/<doc>` for one of its documents. The proxy rewrite (below) is what serves a share; the unlock route is the one more file:
431
431
 
432
432
  ```ts
433
433
  // app/hyle-protected/unlock/route.ts
@@ -436,7 +436,7 @@ import { createProtectedUnlockRoute } from "@tdacorp/hyle-sdk/next";
436
436
  export const { POST } = createProtectedUnlockRoute();
437
437
  ```
438
438
 
439
- `hyleRootPage` checks the slugs hyle reports in `GET /cp1/read/mounts` (`protected`) together with the mounts, and a path under a live slug is drawn without any resolve call. The longest entry wins, a share beating a mount only when it is longer, or equally long and of the same workspace config: one workspace's share never hides another workspace's mount. **A share hides everything under its slug** (`/<slug>` and `/<slug>/<doc>`), so a slug must not be a path or the parent of a path your host serves itself (`/learn` would take your own `/learn/notes`). hyle refuses a slug at, above or under a reserved path (`reserved_paths`, and the routes `hyle-sdk-check-routes --sync` sends as `host_reserved_paths`); a host route that was never synced is yours to keep out of share slugs. Without a cookie the page shows a password form (labelled, `autocomplete="off"`, the error announced) under a generic "Password required" heading. hyle's gate reply carries no share name, so a slug reveals only that a share exists. The form posts `slug` and `password` to `/hyle-protected/unlock`. The unlock route checks that the POST is same-origin and that its form body is at most 1 KiB, stores the password in an `HttpOnly`, `Secure`, `SameSite=Lax` cookie for 12 hours, scoped to `Path=/<slug>` and, for the share's images, to `Path=/api/hyle/assets` (never `Path=/`, so no other request of your host carries it), and redirects to `/<slug>`. It never calls hyle, so one view is one open. The page then asks hyle with `client.protected(slug, password, docSlug?)`: a wrong or expired password shows the form again with "Wrong or expired password". A good one draws one document as an article, or several as the docs layout with a sidebar that highlights the current document. The cookie is named `hyle_p_` and 16 characters of a hash of the slug, so one visitor can hold a password for each share.
439
+ `hyleRootPage` checks the slugs hyle reports in `GET /cp1/read/mounts` (`protected`) together with the mounts, so the longest entry wins (and a path under a live slug makes no resolve call), but **`hyleRootPage` never draws a share: a path under a live slug is `notFound()` there**, because a share is read with the visitor's cookie and the catch-all may be ISR, where reading a cookie is a 500. The proxy rewrite below is what serves a share, on every host, so a host without it shows its shares as 404. The longest entry wins, a share beating a mount only when it is longer, or equally long and of the same workspace config: one workspace's share never hides another workspace's mount. **A share hides everything under its slug** (`/<slug>` and `/<slug>/<doc>`), so a slug must not be a path or the parent of a path your host serves itself (`/learn` would take your own `/learn/notes`). hyle refuses a slug at, above or under a reserved path (`reserved_paths`, and the routes `hyle-sdk-check-routes --sync` sends as `host_reserved_paths`); a host route that was never synced is yours to keep out of share slugs. Without a cookie the page shows a password form (labelled, `autocomplete="off"`, the error announced) under a generic "Password required" heading. hyle's gate reply carries no share name, so a slug reveals only that a share exists. The form posts `slug`, `password` and the optional `docSlug` to `/hyle-protected/unlock`; the route answers a document slug only when it is a slug, and appends it to the redirect. The unlock route checks that the POST is same-origin and that its form body is at most 1 KiB, stores the password in an `HttpOnly`, `Secure`, `SameSite=Lax` cookie for 12 hours, scoped to `Path=/<slug>` and, for the share's images, to `Path=/api/hyle/assets` (never `Path=/`, so no other request of your host carries it), and redirects to `/<slug>`. It never calls hyle, so one view is one open. The page then asks hyle with `client.protected(slug, password, docSlug?)`: a wrong or expired password shows the form again with "Wrong or expired password". A good one is drawn by `ShareChrome`, the same way for one document and for several: a bar (the share's name and the current document, search over the share's own titles and descriptions, a theme menu, the expiry and a Lock button), the document list (not drawn for one document), and the article with its contents. The Lock button posts `slug` and `lock=1` to the same unlock route: it clears the cookie on both paths and sends the visitor to the gate with `?locked=1`, which says "Locked" and shows no name. A share is not drawn with the article layout: its cover, author and `article.*` slots (`article.before`, `article.meta`, `article.aside`, `article.after`) are not drawn, while `components` and the `chrome.*` slots are. The cookie is named `hyle_p_` and 16 characters of a hash of the slug, so one visitor can hold a password for each share.
440
440
 
441
441
  The password must be 12 to 128 visible ASCII characters (no space, quote, comma, semicolon, percent sign or backslash), so it fits a cookie and a header unchanged. It is sent to hyle only in the `cp-protected` header, and a malformed slug or password is refused before anything is sent. The redirect target is built from the validated slug alone. Nothing is logged. Keep analytics off the protected paths: a page URL is shared with the person who holds the password.
442
442
 
@@ -444,7 +444,7 @@ Every answer that involves a protected share is `Cache-Control: no-store`, `X-Ro
444
444
 
445
445
  Images of a share go through `createAssetRoute` (`?hyle_protected=<slug>` reads the same cookie, and the route asks hyle for `?protected=<slug>` with the password in `cp-protected`). A basePath, or a locale-prefix middleware that rewrites or redirects the share paths, breaks it: leave the share slugs and `/hyle-protected/unlock` out of any basePath, locale or rewrite rule.
446
446
 
447
- **A static or ISR catch-all needs two more files.** A share is read with the visitor's cookie, and a page with `export const revalidate = 3600` or `generateStaticParams` cannot read a cookie at request time: Next answers 500 (`DYNAMIC_SERVER_USAGE`) for the password form and the share alike (measured on Next 16.5; a catch-all with `export const dynamic = "force-dynamic"`, or with neither `revalidate` nor `generateStaticParams`, is rendered per request and needs nothing here). On such a host a share is drawn by a dynamic route that the host's proxy rewrites to, so the share URL does not change and the other pages stay cached:
447
+ **A share needs two more files: a proxy and a view route.** A share is read with the visitor's cookie, and a page with `export const revalidate = 3600` or `generateStaticParams` cannot read a cookie at request time: Next answers 500 (`DYNAMIC_SERVER_USAGE`, measured on Next 16.5). So a share is drawn by a dynamic route that the host's proxy rewrites to, so the share URL does not change and the other pages stay cached:
448
448
 
449
449
  ```ts
450
450
  // proxy.ts (Next 16; middleware.ts on older versions). Keep your own matcher, and leave /_next, /api and /hyle-protected out of it.
@@ -468,7 +468,9 @@ export const metadata = hyleProtectedMetadata;
468
468
  export default hyleProtectedPage(configs);
469
469
  ```
470
470
 
471
- `hyleProtectedProxy` rewrites a path to `/hyle-protected/view/<path>` only when it is under a slug hyle lists as protected, and returns `undefined` for everything else. A proxy has no fetch cache, so it keeps one read of hyle's mounts per config in memory for 30 seconds (shared by concurrent requests; the last good copy is used when a refresh fails) and matches every path against it locally, so random paths cost no call to hyle: a new share is rewritten within 30 seconds, a mounts read that fails with no copy counts as "not a share" for those 30 seconds. Without the proxy, a share on such a host is the 500 above.
471
+ `hyleProtectedProxy` rewrites a path to `/hyle-protected/view/<path>` only when it is under a slug hyle lists as protected, and returns `undefined` for everything else. A proxy has no fetch cache, so it keeps one read of hyle's mounts per config in memory and matches every path against it locally, so random paths cost no call to hyle. It is stale-while-revalidate: once it has a copy it answers from it at once, and after 30 seconds ONE read refreshes it in the background (a failed refresh keeps the copy), so a slow hyle delays no request; a new share is rewritten within about 30 seconds. Only a cold start (no copy yet) waits, for at most `lookupTimeoutMs` (`hyleProtectedProxy(configs, { lookupTimeoutMs })`, default 1500), after which the request goes on as a normal, non-share request while the read finishes; a mounts read that fails with no copy counts as "not a share" for those 30 seconds. Without the proxy a share path reaches the catch-all, which answers 404.
472
+
473
+ The view route reads the visitor's address from the first `x-forwarded-for` hop, else `x-real-ip`, and sends it to hyle as `X-Forwarded-For` with the gate and open reads (`hyleProtectedPage(configs, { clientIp: (headers) => ... })` reads it from elsewhere; a value that is not an IPv4 or IPv6 literal is dropped). The first hop is the visitor's only when your edge overwrites that header. hyle's site read surface does not use it yet. When hyle answers 429 (too many attempts), the view draws a page headed "Too many attempts, try again later" with the seconds to wait taken from `Retry-After`; an App Router page cannot set a status or header, so it is drawn with status 200. `client.protected(slug, password, docSlug?, { clientIp })` and `client.protectedGate(slug, { clientIp })` return `{ kind: "limited", retryAfterSeconds }` for a 429.
472
474
 
473
475
  Requires a Hyle with migration 0111 and the `GET /cp1/read/_protected` and `GET /cp1/read/_protected/gate` routes (ADR 0040).
474
476
 
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
2
- import { m as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-Dx-fEiZd.cjs';
2
+ import { n as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-CdaIzSjg.js';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -80,6 +80,10 @@ interface HyleSlots {
80
80
  "notfound.body"?: ReactNode;
81
81
  "notfound.actions"?: ReactNode;
82
82
  "redirecting.body"?: ReactNode;
83
+ /** The protected share chrome (decision 109): the host's logo and name, in place of the `host` option. */
84
+ "chrome.brand"?: ReactNode;
85
+ /** The protected share chrome: an extra block under the document list's foot. */
86
+ "chrome.sidebar-footer"?: ReactNode;
83
87
  }
84
88
  /** Props every page shares. */
85
89
  interface PageBaseProps {
@@ -180,4 +184,12 @@ declare function HyleCommentsFallback({ locale }: {
180
184
  locale?: string | undefined;
181
185
  }): ReactElement;
182
186
 
183
- export { type ArticleRef as A, type CalloutKind as C, type EngagementConfig as E, type HyleComponents as H, type ImageProps as I, type JsonLdConfig as J, type LinkProps as L, type MermaidProps as M, type OgImage as O, type PageBaseProps as P, type HyleSlots as a, type EmbedHeading as b, HyleCommentsFallback as c, type CalloutProps as d, type CodeBlockProps as e, HyleArticleView as f, type HyleArticleViewProps as g, HyleListView as h, type HyleListViewProps as i, type ListItemProps as j };
187
+ /** The host of a share page: its logo and name, the only part of the chrome the host contributes (decision 109). */
188
+ interface ShareHost {
189
+ readonly name: string;
190
+ readonly logo?: ReactNode;
191
+ /** Where the logo links; defaults to the host's root. */
192
+ readonly href?: string;
193
+ }
194
+
195
+ export { type ArticleRef as A, type CalloutKind as C, type EngagementConfig as E, type HyleComponents as H, type ImageProps as I, type JsonLdConfig as J, type LinkProps as L, type MermaidProps as M, type OgImage as O, type PageBaseProps as P, type ShareHost as S, type HyleSlots as a, type EmbedHeading as b, HyleCommentsFallback as c, type CalloutProps as d, type CodeBlockProps as e, HyleArticleView as f, type HyleArticleViewProps as g, HyleListView as h, type HyleListViewProps as i, type ListItemProps as j };
@@ -1,5 +1,5 @@
1
1
  import { ElementType, ReactNode, ComponentType, ReactElement } from 'react';
2
- import { m as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-Dx-fEiZd.js';
2
+ import { n as ResolvedArticle, L as ListItem, T as ThemeRef } from './types-CdaIzSjg.cjs';
3
3
 
4
4
  type CalloutKind = "note" | "tip" | "important" | "warning" | "caution";
5
5
  interface LinkProps {
@@ -80,6 +80,10 @@ interface HyleSlots {
80
80
  "notfound.body"?: ReactNode;
81
81
  "notfound.actions"?: ReactNode;
82
82
  "redirecting.body"?: ReactNode;
83
+ /** The protected share chrome (decision 109): the host's logo and name, in place of the `host` option. */
84
+ "chrome.brand"?: ReactNode;
85
+ /** The protected share chrome: an extra block under the document list's foot. */
86
+ "chrome.sidebar-footer"?: ReactNode;
83
87
  }
84
88
  /** Props every page shares. */
85
89
  interface PageBaseProps {
@@ -180,4 +184,12 @@ declare function HyleCommentsFallback({ locale }: {
180
184
  locale?: string | undefined;
181
185
  }): ReactElement;
182
186
 
183
- export { type ArticleRef as A, type CalloutKind as C, type EngagementConfig as E, type HyleComponents as H, type ImageProps as I, type JsonLdConfig as J, type LinkProps as L, type MermaidProps as M, type OgImage as O, type PageBaseProps as P, type HyleSlots as a, type EmbedHeading as b, HyleCommentsFallback as c, type CalloutProps as d, type CodeBlockProps as e, HyleArticleView as f, type HyleArticleViewProps as g, HyleListView as h, type HyleListViewProps as i, type ListItemProps as j };
187
+ /** The host of a share page: its logo and name, the only part of the chrome the host contributes (decision 109). */
188
+ interface ShareHost {
189
+ readonly name: string;
190
+ readonly logo?: ReactNode;
191
+ /** Where the logo links; defaults to the host's root. */
192
+ readonly href?: string;
193
+ }
194
+
195
+ export { type ArticleRef as A, type CalloutKind as C, type EngagementConfig as E, type HyleComponents as H, type ImageProps as I, type JsonLdConfig as J, type LinkProps as L, type MermaidProps as M, type OgImage as O, type PageBaseProps as P, type ShareHost as S, type HyleSlots as a, type EmbedHeading as b, HyleCommentsFallback as c, type CalloutProps as d, type CodeBlockProps as e, HyleArticleView as f, type HyleArticleViewProps as g, HyleListView as h, type HyleListViewProps as i, type ListItemProps as j };
@@ -76,6 +76,8 @@ function applyCredential(headers, credential, method, url) {
76
76
  headers.set("cp-workspace", workspaceId);
77
77
  });
78
78
  }
79
+ var IP_LITERAL = /^[0-9a-fA-F:.]{2,45}$/;
80
+ var visitorHeaders = ({ clientIp }) => clientIp !== void 0 && IP_LITERAL.test(clientIp) ? { "x-forwarded-for": clientIp } : {};
79
81
  var DEFAULT_TIMEOUT_MS = 1e4;
80
82
  var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
81
83
  var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
@@ -137,7 +139,7 @@ function createHyleClient(options) {
137
139
  } catch {
138
140
  parsed = void 0;
139
141
  }
140
- return { parsed, status: res.status };
142
+ return { parsed, status: res.status, retryAfter: res.headers.get("retry-after") };
141
143
  }
142
144
  const failure = ({ parsed, status }) => {
143
145
  const err = parsed?.error;
@@ -185,19 +187,22 @@ function createHyleClient(options) {
185
187
  if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
186
188
  return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
187
189
  }
188
- async function protectedGate(slug) {
190
+ const limited = ({ retryAfter }) => ({ kind: "limited", retryAfterSeconds: Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60)) });
191
+ async function protectedGate(slug, opts = {}) {
189
192
  if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
190
- const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
193
+ const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { headers: visitorHeaders(opts), cache: "no-store" });
194
+ if (reply.status === 429) return limited(reply);
191
195
  if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
192
196
  const data = reply.parsed?.data;
193
197
  if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
194
198
  if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
195
199
  throw failure(reply);
196
200
  }
197
- async function protectedShare(slug, password, docSlug) {
201
+ async function protectedShare(slug, password, docSlug, opts = {}) {
198
202
  if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
199
203
  const path = docSlug === void 0 ? slug : `${slug}/${docSlug}`;
200
- const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { [PROTECTED_HEADER]: password }, cache: "no-store" });
204
+ const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { ...visitorHeaders(opts), [PROTECTED_HEADER]: password }, cache: "no-store" });
205
+ if (reply.status === 429) return limited(reply);
201
206
  if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
202
207
  const data = reply.parsed?.data;
203
208
  if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
@@ -65,6 +65,8 @@ function applyCredential(headers, credential, method, url) {
65
65
  headers.set("cp-workspace", workspaceId);
66
66
  });
67
67
  }
68
+ var IP_LITERAL = /^[0-9a-fA-F:.]{2,45}$/;
69
+ var visitorHeaders = ({ clientIp }) => clientIp !== void 0 && IP_LITERAL.test(clientIp) ? { "x-forwarded-for": clientIp } : {};
68
70
  var DEFAULT_TIMEOUT_MS = 1e4;
69
71
  var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
70
72
  var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
@@ -137,7 +139,7 @@ function createHyleClient(options) {
137
139
  } catch {
138
140
  parsed = void 0;
139
141
  }
140
- return { parsed, status: res.status };
142
+ return { parsed, status: res.status, retryAfter: res.headers.get("retry-after") };
141
143
  }
142
144
  const failure = ({ parsed, status }) => {
143
145
  const err = parsed?.error;
@@ -185,19 +187,22 @@ function createHyleClient(options) {
185
187
  if (data?.cp !== 1 || data.kind !== "preview" || typeof data.expires_at !== "string" || article?.kind !== "article" || article.content?.format !== "hast" || !article.publication) throw failure(reply);
186
188
  return { kind: "preview", expires_at: data.expires_at, article: withAssetQuery(article, `${PREVIEW_PARAM}=${token}`) };
187
189
  }
188
- async function protectedGate(slug) {
190
+ const limited = ({ retryAfter }) => ({ kind: "limited", retryAfterSeconds: Math.min(3600, Math.max(1, Math.trunc(Number(retryAfter)) || 60)) });
191
+ async function protectedGate(slug, opts = {}) {
189
192
  if (!PROTECTED_SLUG.test(slug)) return { kind: "notfound" };
190
- const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { cache: "no-store" });
193
+ const reply = await get("/cp1/read/_protected/gate", new URLSearchParams({ path: slug }), { headers: visitorHeaders(opts), cache: "no-store" });
194
+ if (reply.status === 429) return limited(reply);
191
195
  if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
192
196
  const data = reply.parsed?.data;
193
197
  if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
194
198
  if (data?.cp === 1 && data.kind === "gate") return { kind: "gate" };
195
199
  throw failure(reply);
196
200
  }
197
- async function protectedShare(slug, password, docSlug) {
201
+ async function protectedShare(slug, password, docSlug, opts = {}) {
198
202
  if (!PROTECTED_SLUG.test(slug) || docSlug !== void 0 && !PROTECTED_DOC_SLUG.test(docSlug) || !PROTECTED_PASSWORD.test(password)) return { kind: "notfound" };
199
203
  const path = docSlug === void 0 ? slug : `${slug}/${docSlug}`;
200
- const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { [PROTECTED_HEADER]: password }, cache: "no-store" });
204
+ const reply = await get("/cp1/read/_protected", new URLSearchParams({ path }), { headers: { ...visitorHeaders(opts), [PROTECTED_HEADER]: password }, cache: "no-store" });
205
+ if (reply.status === 429) return limited(reply);
201
206
  if (reply.status === 404 && reply.parsed?.error?.code === "NOT_FOUND") return { kind: "notfound" };
202
207
  const data = reply.parsed?.data;
203
208
  if (data?.cp === 1 && data.kind === "disabled") return { kind: "disabled" };
@@ -381,6 +386,10 @@ async function runHook(hook, event) {
381
386
  clearTimeout(timer);
382
387
  }
383
388
  }
389
+ function parseIndexUrls(value) {
390
+ if (!Array.isArray(value)) return [];
391
+ return value.flatMap((item) => isRecord(item) && isEventPath(item.path) && isText(item.locale) ? [{ path: item.path, locale: item.locale }] : []);
392
+ }
384
393
  function createRevalidationCallbackRoute(options) {
385
394
  const dedupe = new DeliveryDedupe(options.dedupeCapacity);
386
395
  return {
@@ -433,6 +442,14 @@ function createRevalidationCallbackRoute(options) {
433
442
  const hook = options.onCommentEvent;
434
443
  const event = hook && parseCommentEvent(body);
435
444
  if (hook && event) await runHook(hook, event);
445
+ const indexUrls = parseIndexUrls(body.index_urls);
446
+ if (options.onIndexUrls && indexUrls.length > 0) {
447
+ try {
448
+ options.onIndexUrls(indexUrls);
449
+ } catch {
450
+ console.error("hyle: onIndexUrls failed");
451
+ }
452
+ }
436
453
  return okResponse(purged);
437
454
  }
438
455
  };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  createHyleClient,
3
3
  isValidCacheTag
4
- } from "./chunk-4REU4HJI.js";
4
+ } from "./chunk-3UQGU62T.js";
5
5
 
6
6
  // src/next/resolve.ts
7
7
  var DEFAULT_REVALIDATE = 86400;