@tdacorp/hyle-sdk 0.3.0 → 0.8.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 (38) hide show
  1. package/README.md +135 -5
  2. package/bin/hyle-sdk-check-routes.mjs +3 -0
  3. package/dist/check-routes-bin.js +537 -0
  4. package/dist/chunk-67IOIAVW.js +35 -0
  5. package/dist/chunk-BUJFMR3M.js +38 -0
  6. package/dist/chunk-EBNIKRQH.js +536 -0
  7. package/dist/{chunk-EARQBSMF.js → chunk-LGW2KP4X.js} +109 -5
  8. package/dist/{chunk-7VCMJUPC.js → chunk-N4QYPO7S.js} +1 -1
  9. package/dist/diagram-viewer-DYX6R63Y.js +1132 -0
  10. package/dist/index.cjs +279 -23
  11. package/dist/index.d.cts +147 -3
  12. package/dist/index.d.ts +147 -3
  13. package/dist/index.js +18 -1
  14. package/dist/mermaid-diagram.cjs +1267 -16
  15. package/dist/mermaid-diagram.d.cts +39 -1
  16. package/dist/mermaid-diagram.d.ts +39 -1
  17. package/dist/mermaid-diagram.js +35 -5
  18. package/dist/next.cjs +385 -30
  19. package/dist/next.d.cts +93 -5
  20. package/dist/next.d.ts +93 -5
  21. package/dist/next.js +210 -5
  22. package/dist/react.cjs +118 -5
  23. package/dist/react.d.cts +44 -4
  24. package/dist/react.d.ts +44 -4
  25. package/dist/react.js +2 -1
  26. package/dist/{resolve-fMx2W8RR.d.ts → resolve-1rQntRBh.d.ts} +1 -1
  27. package/dist/{resolve-B_p0p4Zn.d.cts → resolve-36-Ng1H0.d.cts} +1 -1
  28. package/dist/styles.css +76 -0
  29. package/dist/{types-CBvLhUPr.d.ts → types-BoyBWF2F.d.ts} +1 -1
  30. package/dist/{types-DjXf6iPo.d.cts → types-CwBCPh6K.d.cts} +20 -1
  31. package/dist/{types-DjXf6iPo.d.ts → types-CwBCPh6K.d.ts} +20 -1
  32. package/dist/{types-D0qoLh4E.d.cts → types-DnPzhrFx.d.cts} +1 -1
  33. package/dist/use-cache.cjs +55 -23
  34. package/dist/use-cache.d.cts +2 -2
  35. package/dist/use-cache.d.ts +2 -2
  36. package/dist/use-cache.js +3 -2
  37. package/package.json +5 -1
  38. package/dist/chunk-HFUJRNFP.js +0 -290
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as Resolved } from './types-DjXf6iPo.js';
2
- export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, F as Fallback, L as ListItem, N as NavItem, b as ResolvedArticle, c as ResolvedDisabled, d as ResolvedList, e as ResolvedNotFound, f as ResolvedRedirect, T as TocEntry } from './types-DjXf6iPo.js';
1
+ import { R as Resolved, M as MountsResult } from './types-CwBCPh6K.js';
2
+ export { A as Alternate, a as ArticleContent, B as Breadcrumb, C as CacheInfo, F as Fallback, L as ListItem, b as Mount, c as Mounts, N as NavItem, d as ResolvedArticle, e as ResolvedDisabled, f as ResolvedList, g as ResolvedNotFound, h as ResolvedRedirect, T as TocEntry } from './types-CwBCPh6K.js';
3
3
  export { R as RevalidationCallbackOptions, a as RevalidationCallbackRoute, b as RevalidationPayload, c as createRevalidationCallbackRoute } from './revalidation-callback-D7Ms_Puz.js';
4
4
 
5
5
  /** `next` is a Next.js fetch extension with no lib.dom type; typed structurally so this module needs no Next import. */
@@ -33,8 +33,24 @@ interface ResolveOptions {
33
33
  /** Extra fetch options (for example Next's `next: { tags, revalidate }`). Method, body and the auth header cannot be overridden. */
34
34
  readonly init?: HyleRequestInit;
35
35
  }
36
+ interface MountsOptions {
37
+ /** Extra fetch options (for example Next's `next: { tags, revalidate }`). Method, body and the auth header cannot be overridden. */
38
+ readonly init?: HyleRequestInit;
39
+ }
40
+ interface AssetOptions {
41
+ /** Only these request headers are sent upstream: a browser's own cache validators and byte range. Everything else is dropped. */
42
+ readonly headers?: {
43
+ readonly range?: string | null;
44
+ readonly "if-range"?: string | null;
45
+ readonly "if-none-match"?: string | null;
46
+ };
47
+ /** Abort after this many milliseconds, body included. Default: the client's `timeoutMs`. */
48
+ readonly timeoutMs?: number;
49
+ }
36
50
  declare function createHyleClient(options: HyleClientOptions): {
37
51
  resolve: (opts: ResolveOptions) => Promise<Resolved>;
52
+ mounts: (opts?: MountsOptions) => Promise<MountsResult>;
53
+ asset: (file: string, opts?: AssetOptions) => Promise<Response>;
38
54
  };
39
55
  type HyleClient = ReturnType<typeof createHyleClient>;
40
56
 
@@ -46,6 +62,41 @@ declare class Cp1ClientError extends Error {
46
62
  constructor(code: string, message: string, status: number, requestId: string, details?: Record<string, unknown>);
47
63
  }
48
64
 
65
+ interface HostSyncInput {
66
+ /** hyle's origin. */
67
+ readonly baseUrl: string;
68
+ /** A CONTROL credential (hyle_tc_...) holding hyle.workspace.manage on the workspace. Never a target (read) token. */
69
+ readonly token: string;
70
+ /** The workspace to write, from `client.mounts()`; the credential must be granted on it. */
71
+ readonly workspaceId: string;
72
+ /** The host's complete list of reserved paths (a replace). */
73
+ readonly paths: readonly string[];
74
+ readonly host: string;
75
+ readonly buildId: string;
76
+ readonly fetch?: typeof fetch;
77
+ readonly timeoutMs?: number;
78
+ readonly allowInsecureHttp?: boolean;
79
+ }
80
+ interface HostSyncResult {
81
+ /** What hyle stored: sorted, de-duplicated. */
82
+ readonly paths: readonly string[];
83
+ /** False when hyle already held exactly this list. */
84
+ readonly changed: boolean;
85
+ readonly syncedAt: string;
86
+ /** Published hyle URLs the list now covers. hyle unpublishes nothing; the host decides what to do. */
87
+ readonly conflicts: {
88
+ readonly total: number;
89
+ readonly offenders: readonly string[];
90
+ };
91
+ }
92
+ /**
93
+ * Reports the host's reserved paths to hyle (ADR 0016): `PUT /cp1/control/workspace/host-reserved-paths`. Idempotent (resending the
94
+ * same list changes nothing), so a retry or a repeated deploy is safe; the random Idempotency-Key only satisfies the control
95
+ * surface's mutation rule. Throws `TypeError` before any request for a wrong token kind or an insecure URL, and `Cp1ClientError`
96
+ * for anything hyle answers or the network does.
97
+ */
98
+ declare function syncHostReserved(input: HostSyncInput): Promise<HostSyncResult>;
99
+
49
100
  /**
50
101
  * docs/cp1-spec.md section 5.2: `Hyle-Signature: t=<unix seconds>,v1=<hex>,v1=<hex>`.
51
102
  * Multiple v1= values support dual-secret rotation with no receiver-side
@@ -128,4 +179,97 @@ interface ListPublicationPathsOptions {
128
179
  */
129
180
  declare function listPublicationPaths(options: ListPublicationPathsOptions): Promise<PublicationPaths>;
130
181
 
131
- export { CACHE_TAG_PATTERN, Cp1ClientError, DeliveryDedupe, type HyleClient, type HyleClientOptions, type HyleRequestInit, type ListPublicationPathsOptions, type ParsedSignatureHeader, type PublicationPath, type PublicationPaths, type ResolveOptions, Resolved, type VerifySignatureParams, createHyleClient, isValidCacheTag, listPublicationPaths, parseSignatureHeader, verifyHyleSignature };
182
+ /**
183
+ * Route-collision analysis between a Next host app and the paths hyle serves. Pure: the CLI (`hyle-sdk-check-routes`) reads
184
+ * `.next` and calls hyle, then hands plain data to these functions. A host route always wins over `hyleRootPage` (Next matches
185
+ * specific routes first), so a collision never breaks the host: it silently hides hyle content.
186
+ */
187
+ type LocalePrefix = "as-needed" | "always" | "never";
188
+ interface LocaleOptions {
189
+ readonly locales: readonly string[];
190
+ readonly defaultLocale: string;
191
+ /** next-intl's `localePrefix`: "as-needed" leaves the default locale unprefixed. */
192
+ readonly prefix: LocalePrefix;
193
+ }
194
+ /**
195
+ * A host route key as a URL pattern: "/(site)/[locale]/about/page" -> "/[locale]/about". Handles `.next/server/app-paths-manifest.json`
196
+ * keys (trailing "/page" or "/route") and routes-manifest pages. Route groups "(x)" are removed. Returns undefined for what is not a
197
+ * URL a visitor can request: parallel-route slots "@x", intercepting routes "(.)x", and Next's internal pages.
198
+ */
199
+ declare function normalizeRoute(key: string): string | undefined;
200
+ interface NextManifests {
201
+ readonly routesManifest?: {
202
+ readonly staticRoutes?: readonly {
203
+ readonly page: string;
204
+ }[];
205
+ readonly dynamicRoutes?: readonly {
206
+ readonly page: string;
207
+ }[];
208
+ };
209
+ readonly appPaths?: Readonly<Record<string, string>>;
210
+ }
211
+ /** Every host route pattern from `routes-manifest.json` and `server/app-paths-manifest.json`, normalized, de-duplicated and sorted. */
212
+ declare function hostRoutesFromManifests({ routesManifest, appPaths }: NextManifests): string[];
213
+ /** Does the route pattern match the URL path? `[x]` is one segment, `[...x]` one or more, `[[...x]]` zero or more. */
214
+ declare function routeMatches(route: string, path: string): boolean;
215
+ interface RouteCheckInput {
216
+ /** From `hostRoutesFromManifests`. */
217
+ readonly hostRoutes: readonly string[];
218
+ /** The mount prefixes hyle reports: "/" for a root mount. */
219
+ readonly mounts: readonly string[];
220
+ /** Every published page path (`listPublicationPaths`), in hyle's path space (no host locale prefix). */
221
+ readonly hylePaths: readonly string[];
222
+ readonly locale?: LocaleOptions;
223
+ /** The param name of the host's hyle catch-all (`[...hyle]`). Default "hyle". */
224
+ readonly hyleParam?: string;
225
+ }
226
+ interface DynamicOverlap {
227
+ readonly route: string;
228
+ /**
229
+ * "hyle-catch-all": the route is hyle's own catch-all, fine. "hyle-wins": it matches hyle URLs but hyle's catch-all is more specific, fine.
230
+ * "host-wins": Next serves this route for URLs hyle publishes, so that hyle content is never shown.
231
+ */
232
+ readonly verdict: "hyle-catch-all" | "hyle-wins" | "host-wins";
233
+ readonly matches: number;
234
+ readonly examples: readonly string[];
235
+ }
236
+ interface RouteCheckReport {
237
+ /** (a) A published hyle page at a URL a static host route owns: never served. */
238
+ readonly shadowedHylePaths: readonly {
239
+ readonly path: string;
240
+ readonly url: string;
241
+ readonly route: string;
242
+ }[];
243
+ /** (c) A mount prefix that is itself a static host route: the mount's index page is never served. */
244
+ readonly mountCollisions: readonly {
245
+ readonly prefix: string;
246
+ readonly url: string;
247
+ readonly route: string;
248
+ }[];
249
+ /** (b) Host dynamic routes matching hyle URLs, grouped by route. */
250
+ readonly dynamicOverlaps: readonly DynamicOverlap[];
251
+ readonly notes: readonly string[];
252
+ /** False when (a) or (c) found something. */
253
+ readonly ok: boolean;
254
+ }
255
+ declare function checkRoutes(input: RouteCheckInput): RouteCheckReport;
256
+ /** Paths the SDK's own components serve inside a host app, always reserved on top of the host's routes: the asset route (ADR 0015). */
257
+ declare const SDK_OWN_RESERVED: readonly string[];
258
+ /**
259
+ * The host's routes in hyle's Reserved paths format. Static routes are exact paths, and "/x/*" for a segment with two or more
260
+ * routes under it (route groups such as "/api/*"). A dynamic route ("/shop/[id]", "/docs/[...slug]") becomes the wildcard on its
261
+ * static prefix ("/shop/*", "/docs/*"); one with no static prefix, and hyle's own catch-all (`hyleParam`, default "hyle"), are
262
+ * skipped. A segment is NOT collapsed, and a wildcard is not made, when a non-root mount prefix lies on it, so "/learn/about" stays
263
+ * exact while a mount serves "/learn/notes". Without `mounts` (hyle unreachable) nothing is collapsed. The leading locale segment
264
+ * is dropped because hyle's paths carry no host locale prefix. Per-build hashed metadata routes are omitted, an entry another
265
+ * wildcard already covers is dropped, and the result is sorted.
266
+ */
267
+ declare function reservedFor(hostRoutes: readonly string[], options?: {
268
+ readonly locale?: LocaleOptions;
269
+ readonly mounts?: readonly string[];
270
+ readonly hyleParam?: string;
271
+ }): string[];
272
+ /** The human report. */
273
+ declare function formatReport(report: RouteCheckReport): string;
274
+
275
+ export { type AssetOptions, CACHE_TAG_PATTERN, Cp1ClientError, DeliveryDedupe, type DynamicOverlap, type HostSyncInput, type HostSyncResult, type HyleClient, type HyleClientOptions, type HyleRequestInit, type ListPublicationPathsOptions, type LocaleOptions, type LocalePrefix, type MountsOptions, MountsResult, type NextManifests, type ParsedSignatureHeader, type PublicationPath, type PublicationPaths, type ResolveOptions, Resolved, type RouteCheckInput, type RouteCheckReport, SDK_OWN_RESERVED, type VerifySignatureParams, checkRoutes, createHyleClient, formatReport, hostRoutesFromManifests, isValidCacheTag, listPublicationPaths, normalizeRoute, parseSignatureHeader, reservedFor, routeMatches, syncHostReserved, verifyHyleSignature };
package/dist/index.js CHANGED
@@ -2,21 +2,38 @@ import {
2
2
  CACHE_TAG_PATTERN,
3
3
  Cp1ClientError,
4
4
  DeliveryDedupe,
5
+ SDK_OWN_RESERVED,
6
+ checkRoutes,
5
7
  createHyleClient,
6
8
  createRevalidationCallbackRoute,
9
+ formatReport,
10
+ hostRoutesFromManifests,
7
11
  isValidCacheTag,
8
12
  listPublicationPaths,
13
+ normalizeRoute,
9
14
  parseSignatureHeader,
15
+ reservedFor,
16
+ routeMatches,
17
+ syncHostReserved,
10
18
  verifyHyleSignature
11
- } from "./chunk-HFUJRNFP.js";
19
+ } from "./chunk-EBNIKRQH.js";
20
+ import "./chunk-67IOIAVW.js";
12
21
  export {
13
22
  CACHE_TAG_PATTERN,
14
23
  Cp1ClientError,
15
24
  DeliveryDedupe,
25
+ SDK_OWN_RESERVED,
26
+ checkRoutes,
16
27
  createHyleClient,
17
28
  createRevalidationCallbackRoute,
29
+ formatReport,
30
+ hostRoutesFromManifests,
18
31
  isValidCacheTag,
19
32
  listPublicationPaths,
33
+ normalizeRoute,
20
34
  parseSignatureHeader,
35
+ reservedFor,
36
+ routeMatches,
37
+ syncHostReserved,
21
38
  verifyHyleSignature
22
39
  };