@tdacorp/hyle-sdk 0.9.0 → 0.11.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 (37) hide show
  1. package/README.md +80 -2
  2. package/bin/hyle-sdk-engage-keygen.mjs +3 -0
  3. package/dist/check-routes-bin.js +5 -1
  4. package/dist/{chunk-54JF4E53.js → chunk-N7ZQUAGM.js} +45 -2
  5. package/dist/chunk-R5EMI4HQ.js +61 -0
  6. package/dist/{chunk-6LW33475.js → chunk-S3LT6G4M.js} +536 -50
  7. package/dist/{chunk-XKR74Y5G.js → chunk-S7PCCEHP.js} +1 -1
  8. package/dist/comments.cjs +1048 -0
  9. package/dist/comments.d.cts +152 -0
  10. package/dist/comments.d.ts +152 -0
  11. package/dist/comments.js +1025 -0
  12. package/dist/{types-C1eCQ2As.d.ts → embed-BC8Tlc6A.d.cts} +44 -3
  13. package/dist/{types-BPPZrYOZ.d.cts → embed-CwSzvBUO.d.ts} +44 -3
  14. package/dist/engage-keygen-bin.js +67 -0
  15. package/dist/index.cjs +26 -1
  16. package/dist/index.d.cts +11 -3
  17. package/dist/index.d.ts +11 -3
  18. package/dist/index.js +5 -1
  19. package/dist/mermaid-diagram.js +9 -54
  20. package/dist/next.cjs +940 -58
  21. package/dist/next.d.cts +149 -6
  22. package/dist/next.d.ts +149 -6
  23. package/dist/next.js +390 -11
  24. package/dist/react.cjs +339 -49
  25. package/dist/react.d.cts +112 -7
  26. package/dist/react.d.ts +112 -7
  27. package/dist/react.js +7 -1
  28. package/dist/{resolve-Dpb6Orsj.d.ts → resolve-BYL8jMg0.d.ts} +1 -1
  29. package/dist/{resolve-D2rnnho9.d.cts → resolve-Ra8-y2U-.d.cts} +1 -1
  30. package/dist/styles.css +117 -0
  31. package/dist/{types-CHxH5E0S.d.cts → types-C72FwzOd.d.cts} +57 -1
  32. package/dist/{types-CHxH5E0S.d.ts → types-C72FwzOd.d.ts} +57 -1
  33. package/dist/use-cache.cjs +5 -1
  34. package/dist/use-cache.d.cts +2 -2
  35. package/dist/use-cache.d.ts +2 -2
  36. package/dist/use-cache.js +2 -2
  37. package/package.json +4 -3
package/dist/next.d.cts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { ReactElement } from 'react';
2
- import { H as HyleComponents, a as HyleSlots } from './types-BPPZrYOZ.cjs';
3
- import { F as FetchResolverOptions, H as HyleResolver } from './resolve-D2rnnho9.cjs';
4
- export { f as fetchResolver, w as workspaceTags } from './resolve-D2rnnho9.cjs';
2
+ import { H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-BC8Tlc6A.cjs';
3
+ export { c as HyleCommentsFallback } from './embed-BC8Tlc6A.cjs';
4
+ import { F as FetchResolverOptions, H as HyleResolver } from './resolve-Ra8-y2U-.cjs';
5
+ export { f as fetchResolver, w as workspaceTags } from './resolve-Ra8-y2U-.cjs';
5
6
  import { MetadataRoute, Metadata } from 'next';
6
7
  import { a as RevalidationCallbackRoute } from './revalidation-callback-D7Ms_Puz.cjs';
7
- import './types-CHxH5E0S.cjs';
8
+ import './types-C72FwzOd.cjs';
8
9
 
9
10
  type RouteParams = Record<string, string | string[] | undefined>;
10
11
  interface CommonOptions {
@@ -23,8 +24,21 @@ interface CommonOptions {
23
24
  * back to redirect targets, canonical URLs, hreflang alternates and in-page links. Default: no prefix.
24
25
  */
25
26
  readonly localePrefix?: (locale: string) => string;
27
+ /**
28
+ * The site's public origin, for example "https://tdacorp.in": https, no trailing slash, no path. Structured data needs absolute
29
+ * URLs and the SDK cannot know the host's domain, so without it nothing is emitted. With it, article pages (layout "article")
30
+ * carry one BlogPosting and BreadcrumbList JSON-LD script. A value that is not a bare https origin emits nothing: pass the
31
+ * same origin you give `hyleSitemap`.
32
+ */
33
+ readonly siteOrigin?: string;
26
34
  readonly components?: HyleComponents;
27
35
  readonly slots?: HyleSlots;
36
+ /**
37
+ * Comments and likes under articles (ADR 0017); layout "article" only. Default off. Needs `createEngagementRoute` mounted at
38
+ * `app/api/hyle/engage/[...path]/route.ts` and engagement switched on for the workspace in hyle; the section is fetched in the
39
+ * browser, so the cached page never changes when someone likes.
40
+ */
41
+ readonly engagement?: EngagementConfig;
28
42
  /** "docs" renders articles as DocsPage (tree nav). Default "article". */
29
43
  readonly layout?: "article" | "docs";
30
44
  /** Items per list page (server default 20, maximum 100). */
@@ -115,7 +129,9 @@ declare function hyleSitemap(options: HyleSitemapOptions): Promise<MetadataRoute
115
129
  /**
116
130
  * `export const generateMetadata = hyleMetadata({ ... })` with the same options as `hylePage`. Title, description, a canonical
117
131
  * URL in the page's own locale (so a fallback copy under another locale prefix points at the original), hreflang alternates
118
- * from the response's `alternates`, and Open Graph. Paths are relative: set `metadataBase` in the host's root layout.
132
+ * from the response's `alternates` plus `x-default`, and Open Graph. A list page canonicals to itself; with `paginate` a cursor
133
+ * page canonicals to its own `?cursor=` URL (never to the first page) and its title gets an "Older posts" suffix.
134
+ * Paths are relative: set `metadataBase` in the host's root layout.
119
135
  * Redirects, 404s and a switched-off read surface produce no metadata; `hylePage` handles those. A 4xx rejection of the request
120
136
  * gives no metadata; any other failure (network, timeout, 5xx, 401, 403, 429) is rethrown, so a transient outage is not
121
137
  * cached as a page; Next control flow is rethrown.
@@ -227,4 +243,131 @@ interface AssetRoute {
227
243
  */
228
244
  declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
229
245
 
230
- export { type AssetRoute, type AssetRouteOptions, FetchResolverOptions, type HyleNextOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, MOUNTS_MAX_STALE_MS, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createRevalidateRoute, hyleMetadata, hylePage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap };
246
+ interface HyleListProps {
247
+ readonly options: HyleNextOptions;
248
+ /** A section slug other than the mount's default ("posts"). Default: the default section. */
249
+ readonly section?: string | undefined;
250
+ /** Items to show (the server maximum is 100). Default 5. */
251
+ readonly limit?: number | undefined;
252
+ /** The visitor's locale. Needed under a dynamic `options.locale`, which a component cannot evaluate; else `options.locale` is used. */
253
+ readonly locale?: string | undefined;
254
+ readonly layout?: "list" | "grid" | undefined;
255
+ readonly title?: string | undefined;
256
+ readonly headingLevel?: EmbedHeading | undefined;
257
+ /** Where "View all" goes, usually the mount's index. Omit to hide it. */
258
+ readonly moreHref?: string | undefined;
259
+ }
260
+ /** The newest articles of a section as a list or a grid of links to the mount. Slots: `list.item`, `list.empty`. */
261
+ declare function HyleList({ options, section, limit, locale, layout, title, headingLevel, moreHref }: HyleListProps): Promise<ReactElement | null>;
262
+ interface HyleArticleProps {
263
+ readonly options: HyleNextOptions;
264
+ /** The article's canonical site path, as hyle sends it (`canonical_path`, with the workspace prefix, no locale prefix). */
265
+ readonly path: string;
266
+ readonly locale?: string | undefined;
267
+ readonly headingLevel?: EmbedHeading | undefined;
268
+ }
269
+ /**
270
+ * One article, body included. It links to the canonical page on the mount and sets nothing in the document head: a host that
271
+ * embeds a full article must point its own page's canonical URL at that mount URL, or the two pages compete.
272
+ */
273
+ declare function HyleArticle({ options, path, locale, headingLevel }: HyleArticleProps): Promise<ReactElement | null>;
274
+ interface HyleCommentsProps {
275
+ /** `token` is the target credential. It is used only in the server-side request below and never reaches a client component. */
276
+ readonly options: {
277
+ readonly baseUrl: string;
278
+ readonly token: string;
279
+ readonly locale?: string | undefined;
280
+ };
281
+ /** The article's canonical site path (`publication.canonical_path`). */
282
+ readonly path: string;
283
+ /** Seconds the listing is cached before it is refreshed in the background. Default 60. */
284
+ readonly revalidate?: number | undefined;
285
+ /**
286
+ * Also let readers comment and like (needs `createEngagementRoute`, as for `ArticlePage`'s `engagement`): the `Comments` island is
287
+ * rendered from this same listing, so the thread is in the server HTML either way and nothing shows twice. Without it the
288
+ * thread is read-only. `true` uses the defaults.
289
+ */
290
+ readonly interactive?: EngagementConfig | true | undefined;
291
+ }
292
+ /**
293
+ * The public comments of an article as crawlable server-rendered HTML. The request carries the target credential as the only
294
+ * credential: no reader assertion, no cookie and no header of the visitor, so every visitor shares one cached listing. Wrap it in
295
+ * `<Suspense fallback={<HyleCommentsFallback />}>` to stream it. A 404 (engagement off, unknown article), a network error or a
296
+ * malformed answer renders nothing.
297
+ */
298
+ declare function HyleComments({ options, path, revalidate, interactive }: HyleCommentsProps): Promise<ReactElement | null>;
299
+
300
+ /** The signed-in reader as the host knows them: an opaque stable id and a display name (both go into hyle). */
301
+ interface EngageReader {
302
+ readonly sub: string;
303
+ readonly name: string;
304
+ }
305
+ interface EngagementRouteOptions {
306
+ /** hyle's origin (HYLE_TARGET_BASE_URL). */
307
+ readonly baseUrl: string | undefined;
308
+ /** This workspace's target credential (HYLE_TARGET_TOKEN), server side only. */
309
+ readonly token: string | undefined;
310
+ /** The target credential's workspace id: hyle refuses an assertion whose `workspace` claim differs. */
311
+ readonly workspaceId: string | undefined;
312
+ /** The Ed25519 private seed from `hyle-sdk-engage-keygen` (HYLE_ENGAGE_SIGNING_KEY). Its public half is registered in hyle. */
313
+ readonly signingKey: string | undefined;
314
+ /**
315
+ * The host's own session check, called per request with that request. Return `{ sub, name }` for a signed-in reader, or
316
+ * null/undefined for none. A throw counts as none. The SDK never reads the visitor's cookies itself.
317
+ */
318
+ readonly getReader: (req: Request) => Promise<EngageReader | null | undefined> | EngageReader | null | undefined;
319
+ /**
320
+ * The exact origins that may write, for example ["https://www.example.com"]. When set, a write's `Origin` must equal one of them
321
+ * (scheme, host and port) and nothing is derived from request headers. Default: derived from `X-Forwarded-Host` or `Host`, and
322
+ * checked against `X-Forwarded-Proto` when the proxy sends it. Behind a proxy that rewrites Host or terminates TLS without
323
+ * forwarding those headers, set this.
324
+ */
325
+ readonly allowedOrigins?: readonly string[];
326
+ /**
327
+ * Called for every matched request before any work (after the allowlist and CSRF checks), with the action name:
328
+ * "session", "comments.list", "comments.create", "comments.edit", "comments.delete", "reactions.add" or "reactions.remove".
329
+ * Return a Response (for example a 429 from your own rate limiter) to answer instead; return nothing to continue. A throw is a 502.
330
+ * hyle rate-limits too, but every anonymous read reaches your server first: limit /api/hyle/engage in your own middleware or here.
331
+ */
332
+ readonly onRequest?: (req: Request, info: {
333
+ readonly action: string;
334
+ }) => Response | void | Promise<Response | void>;
335
+ /** How long an identical comments listing is shared between visitors, in milliseconds. Default 3000; 0 turns it off. */
336
+ readonly cacheTtlMs?: number;
337
+ /** Environment to read the kill switch from. Default process.env. */
338
+ readonly env?: Readonly<Record<string, string | undefined>>;
339
+ /** Abort the upstream request after this many milliseconds. Default 10000. */
340
+ readonly timeoutMs?: number;
341
+ /** Injectable for tests. */
342
+ readonly fetch?: typeof fetch;
343
+ }
344
+ type EngagementRouteContext = {
345
+ params: Promise<{
346
+ path?: string[];
347
+ }>;
348
+ };
349
+ type EngagementHandler = (req: Request, ctx: EngagementRouteContext) => Promise<Response>;
350
+ interface EngagementRoute {
351
+ GET: EngagementHandler;
352
+ POST: EngagementHandler;
353
+ PATCH: EngagementHandler;
354
+ PUT: EngagementHandler;
355
+ DELETE: EngagementHandler;
356
+ }
357
+ /** The header every write must carry: a cross-origin page cannot add it without a CORS preflight, which this route never grants. */
358
+ declare const ENGAGE_CSRF_HEADER = "x-hyle-engage";
359
+ /**
360
+ * `export const { GET, POST, PATCH, PUT, DELETE } = createEngagementRoute({ ... })` in `app/api/hyle/engage/[...path]/route.ts`
361
+ * (ADR 0017). The browser talks only to this same-origin route; it calls hyle server to server with the target credential and,
362
+ * for a write, a fresh 30 s Ed25519 assertion of the reader that `getReader` returned. The browser's cookies and Authorization
363
+ * header are never forwarded, and no browser-supplied header or query key reaches hyle.
364
+ *
365
+ * Safety: a strict allowlist of (method, path) pairs with rebuilt bodies (known keys only, validated), so this is not an open
366
+ * proxy; writes need same-origin (`Sec-Fetch-Site`, `Origin` equal to the host) AND the `x-hyle-engage: 1` header AND a JSON
367
+ * content type; every response is `Cache-Control: no-store`; failures are a fixed set of codes (404, 502, 429, 400, 409, 413,
368
+ * 415, 401, 403) that say nothing about hyle. `HYLE_ENGAGE_ENABLED=0`/`false` (or `HYLE_CONTENT_ENABLED=0`), or missing or
369
+ * invalid configuration, answers 404 everywhere.
370
+ */
371
+ declare function createEngagementRoute(options: EngagementRouteOptions): EngagementRoute;
372
+
373
+ export { type AssetRoute, type AssetRouteOptions, ENGAGE_CSRF_HEADER, type EngageReader, type EngagementRoute, type EngagementRouteOptions, FetchResolverOptions, HyleArticle, type HyleArticleProps, HyleComments, type HyleCommentsProps, HyleList, type HyleListProps, type HyleNextOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, MOUNTS_MAX_STALE_MS, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createEngagementRoute, createRevalidateRoute, hyleMetadata, hylePage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap };
package/dist/next.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { ReactElement } from 'react';
2
- import { H as HyleComponents, a as HyleSlots } from './types-C1eCQ2As.js';
3
- import { F as FetchResolverOptions, H as HyleResolver } from './resolve-Dpb6Orsj.js';
4
- export { f as fetchResolver, w as workspaceTags } from './resolve-Dpb6Orsj.js';
2
+ import { H as HyleComponents, a as HyleSlots, E as EngagementConfig, b as EmbedHeading } from './embed-CwSzvBUO.js';
3
+ export { c as HyleCommentsFallback } from './embed-CwSzvBUO.js';
4
+ import { F as FetchResolverOptions, H as HyleResolver } from './resolve-BYL8jMg0.js';
5
+ export { f as fetchResolver, w as workspaceTags } from './resolve-BYL8jMg0.js';
5
6
  import { MetadataRoute, Metadata } from 'next';
6
7
  import { a as RevalidationCallbackRoute } from './revalidation-callback-D7Ms_Puz.js';
7
- import './types-CHxH5E0S.js';
8
+ import './types-C72FwzOd.js';
8
9
 
9
10
  type RouteParams = Record<string, string | string[] | undefined>;
10
11
  interface CommonOptions {
@@ -23,8 +24,21 @@ interface CommonOptions {
23
24
  * back to redirect targets, canonical URLs, hreflang alternates and in-page links. Default: no prefix.
24
25
  */
25
26
  readonly localePrefix?: (locale: string) => string;
27
+ /**
28
+ * The site's public origin, for example "https://tdacorp.in": https, no trailing slash, no path. Structured data needs absolute
29
+ * URLs and the SDK cannot know the host's domain, so without it nothing is emitted. With it, article pages (layout "article")
30
+ * carry one BlogPosting and BreadcrumbList JSON-LD script. A value that is not a bare https origin emits nothing: pass the
31
+ * same origin you give `hyleSitemap`.
32
+ */
33
+ readonly siteOrigin?: string;
26
34
  readonly components?: HyleComponents;
27
35
  readonly slots?: HyleSlots;
36
+ /**
37
+ * Comments and likes under articles (ADR 0017); layout "article" only. Default off. Needs `createEngagementRoute` mounted at
38
+ * `app/api/hyle/engage/[...path]/route.ts` and engagement switched on for the workspace in hyle; the section is fetched in the
39
+ * browser, so the cached page never changes when someone likes.
40
+ */
41
+ readonly engagement?: EngagementConfig;
28
42
  /** "docs" renders articles as DocsPage (tree nav). Default "article". */
29
43
  readonly layout?: "article" | "docs";
30
44
  /** Items per list page (server default 20, maximum 100). */
@@ -115,7 +129,9 @@ declare function hyleSitemap(options: HyleSitemapOptions): Promise<MetadataRoute
115
129
  /**
116
130
  * `export const generateMetadata = hyleMetadata({ ... })` with the same options as `hylePage`. Title, description, a canonical
117
131
  * URL in the page's own locale (so a fallback copy under another locale prefix points at the original), hreflang alternates
118
- * from the response's `alternates`, and Open Graph. Paths are relative: set `metadataBase` in the host's root layout.
132
+ * from the response's `alternates` plus `x-default`, and Open Graph. A list page canonicals to itself; with `paginate` a cursor
133
+ * page canonicals to its own `?cursor=` URL (never to the first page) and its title gets an "Older posts" suffix.
134
+ * Paths are relative: set `metadataBase` in the host's root layout.
119
135
  * Redirects, 404s and a switched-off read surface produce no metadata; `hylePage` handles those. A 4xx rejection of the request
120
136
  * gives no metadata; any other failure (network, timeout, 5xx, 401, 403, 429) is rethrown, so a transient outage is not
121
137
  * cached as a page; Next control flow is rethrown.
@@ -227,4 +243,131 @@ interface AssetRoute {
227
243
  */
228
244
  declare function createAssetRoute(options: AssetRouteOptions): AssetRoute;
229
245
 
230
- export { type AssetRoute, type AssetRouteOptions, FetchResolverOptions, type HyleNextOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, MOUNTS_MAX_STALE_MS, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createRevalidateRoute, hyleMetadata, hylePage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap };
246
+ interface HyleListProps {
247
+ readonly options: HyleNextOptions;
248
+ /** A section slug other than the mount's default ("posts"). Default: the default section. */
249
+ readonly section?: string | undefined;
250
+ /** Items to show (the server maximum is 100). Default 5. */
251
+ readonly limit?: number | undefined;
252
+ /** The visitor's locale. Needed under a dynamic `options.locale`, which a component cannot evaluate; else `options.locale` is used. */
253
+ readonly locale?: string | undefined;
254
+ readonly layout?: "list" | "grid" | undefined;
255
+ readonly title?: string | undefined;
256
+ readonly headingLevel?: EmbedHeading | undefined;
257
+ /** Where "View all" goes, usually the mount's index. Omit to hide it. */
258
+ readonly moreHref?: string | undefined;
259
+ }
260
+ /** The newest articles of a section as a list or a grid of links to the mount. Slots: `list.item`, `list.empty`. */
261
+ declare function HyleList({ options, section, limit, locale, layout, title, headingLevel, moreHref }: HyleListProps): Promise<ReactElement | null>;
262
+ interface HyleArticleProps {
263
+ readonly options: HyleNextOptions;
264
+ /** The article's canonical site path, as hyle sends it (`canonical_path`, with the workspace prefix, no locale prefix). */
265
+ readonly path: string;
266
+ readonly locale?: string | undefined;
267
+ readonly headingLevel?: EmbedHeading | undefined;
268
+ }
269
+ /**
270
+ * One article, body included. It links to the canonical page on the mount and sets nothing in the document head: a host that
271
+ * embeds a full article must point its own page's canonical URL at that mount URL, or the two pages compete.
272
+ */
273
+ declare function HyleArticle({ options, path, locale, headingLevel }: HyleArticleProps): Promise<ReactElement | null>;
274
+ interface HyleCommentsProps {
275
+ /** `token` is the target credential. It is used only in the server-side request below and never reaches a client component. */
276
+ readonly options: {
277
+ readonly baseUrl: string;
278
+ readonly token: string;
279
+ readonly locale?: string | undefined;
280
+ };
281
+ /** The article's canonical site path (`publication.canonical_path`). */
282
+ readonly path: string;
283
+ /** Seconds the listing is cached before it is refreshed in the background. Default 60. */
284
+ readonly revalidate?: number | undefined;
285
+ /**
286
+ * Also let readers comment and like (needs `createEngagementRoute`, as for `ArticlePage`'s `engagement`): the `Comments` island is
287
+ * rendered from this same listing, so the thread is in the server HTML either way and nothing shows twice. Without it the
288
+ * thread is read-only. `true` uses the defaults.
289
+ */
290
+ readonly interactive?: EngagementConfig | true | undefined;
291
+ }
292
+ /**
293
+ * The public comments of an article as crawlable server-rendered HTML. The request carries the target credential as the only
294
+ * credential: no reader assertion, no cookie and no header of the visitor, so every visitor shares one cached listing. Wrap it in
295
+ * `<Suspense fallback={<HyleCommentsFallback />}>` to stream it. A 404 (engagement off, unknown article), a network error or a
296
+ * malformed answer renders nothing.
297
+ */
298
+ declare function HyleComments({ options, path, revalidate, interactive }: HyleCommentsProps): Promise<ReactElement | null>;
299
+
300
+ /** The signed-in reader as the host knows them: an opaque stable id and a display name (both go into hyle). */
301
+ interface EngageReader {
302
+ readonly sub: string;
303
+ readonly name: string;
304
+ }
305
+ interface EngagementRouteOptions {
306
+ /** hyle's origin (HYLE_TARGET_BASE_URL). */
307
+ readonly baseUrl: string | undefined;
308
+ /** This workspace's target credential (HYLE_TARGET_TOKEN), server side only. */
309
+ readonly token: string | undefined;
310
+ /** The target credential's workspace id: hyle refuses an assertion whose `workspace` claim differs. */
311
+ readonly workspaceId: string | undefined;
312
+ /** The Ed25519 private seed from `hyle-sdk-engage-keygen` (HYLE_ENGAGE_SIGNING_KEY). Its public half is registered in hyle. */
313
+ readonly signingKey: string | undefined;
314
+ /**
315
+ * The host's own session check, called per request with that request. Return `{ sub, name }` for a signed-in reader, or
316
+ * null/undefined for none. A throw counts as none. The SDK never reads the visitor's cookies itself.
317
+ */
318
+ readonly getReader: (req: Request) => Promise<EngageReader | null | undefined> | EngageReader | null | undefined;
319
+ /**
320
+ * The exact origins that may write, for example ["https://www.example.com"]. When set, a write's `Origin` must equal one of them
321
+ * (scheme, host and port) and nothing is derived from request headers. Default: derived from `X-Forwarded-Host` or `Host`, and
322
+ * checked against `X-Forwarded-Proto` when the proxy sends it. Behind a proxy that rewrites Host or terminates TLS without
323
+ * forwarding those headers, set this.
324
+ */
325
+ readonly allowedOrigins?: readonly string[];
326
+ /**
327
+ * Called for every matched request before any work (after the allowlist and CSRF checks), with the action name:
328
+ * "session", "comments.list", "comments.create", "comments.edit", "comments.delete", "reactions.add" or "reactions.remove".
329
+ * Return a Response (for example a 429 from your own rate limiter) to answer instead; return nothing to continue. A throw is a 502.
330
+ * hyle rate-limits too, but every anonymous read reaches your server first: limit /api/hyle/engage in your own middleware or here.
331
+ */
332
+ readonly onRequest?: (req: Request, info: {
333
+ readonly action: string;
334
+ }) => Response | void | Promise<Response | void>;
335
+ /** How long an identical comments listing is shared between visitors, in milliseconds. Default 3000; 0 turns it off. */
336
+ readonly cacheTtlMs?: number;
337
+ /** Environment to read the kill switch from. Default process.env. */
338
+ readonly env?: Readonly<Record<string, string | undefined>>;
339
+ /** Abort the upstream request after this many milliseconds. Default 10000. */
340
+ readonly timeoutMs?: number;
341
+ /** Injectable for tests. */
342
+ readonly fetch?: typeof fetch;
343
+ }
344
+ type EngagementRouteContext = {
345
+ params: Promise<{
346
+ path?: string[];
347
+ }>;
348
+ };
349
+ type EngagementHandler = (req: Request, ctx: EngagementRouteContext) => Promise<Response>;
350
+ interface EngagementRoute {
351
+ GET: EngagementHandler;
352
+ POST: EngagementHandler;
353
+ PATCH: EngagementHandler;
354
+ PUT: EngagementHandler;
355
+ DELETE: EngagementHandler;
356
+ }
357
+ /** The header every write must carry: a cross-origin page cannot add it without a CORS preflight, which this route never grants. */
358
+ declare const ENGAGE_CSRF_HEADER = "x-hyle-engage";
359
+ /**
360
+ * `export const { GET, POST, PATCH, PUT, DELETE } = createEngagementRoute({ ... })` in `app/api/hyle/engage/[...path]/route.ts`
361
+ * (ADR 0017). The browser talks only to this same-origin route; it calls hyle server to server with the target credential and,
362
+ * for a write, a fresh 30 s Ed25519 assertion of the reader that `getReader` returned. The browser's cookies and Authorization
363
+ * header are never forwarded, and no browser-supplied header or query key reaches hyle.
364
+ *
365
+ * Safety: a strict allowlist of (method, path) pairs with rebuilt bodies (known keys only, validated), so this is not an open
366
+ * proxy; writes need same-origin (`Sec-Fetch-Site`, `Origin` equal to the host) AND the `x-hyle-engage: 1` header AND a JSON
367
+ * content type; every response is `Cache-Control: no-store`; failures are a fixed set of codes (404, 502, 429, 400, 409, 413,
368
+ * 415, 401, 403) that say nothing about hyle. `HYLE_ENGAGE_ENABLED=0`/`false` (or `HYLE_CONTENT_ENABLED=0`), or missing or
369
+ * invalid configuration, answers 404 everywhere.
370
+ */
371
+ declare function createEngagementRoute(options: EngagementRouteOptions): EngagementRoute;
372
+
373
+ export { type AssetRoute, type AssetRouteOptions, ENGAGE_CSRF_HEADER, type EngageReader, type EngagementRoute, type EngagementRouteOptions, FetchResolverOptions, HyleArticle, type HyleArticleProps, HyleComments, type HyleCommentsProps, HyleList, type HyleListProps, type HyleNextOptions, HyleResolver, type HyleRootConfig, type HyleRootSitemapOptions, type HyleSitemapOptions, MOUNTS_MAX_STALE_MS, type PageProps, type RevalidateRouteOptions, type RouteParams, createAssetRoute, createEngagementRoute, createRevalidateRoute, hyleMetadata, hylePage, hyleRootMetadata, hyleRootPage, hyleRootSitemap, hyleSitemap };