@decocms/nextjs 8.5.1 → 8.6.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 (46) hide show
  1. package/README.md +81 -14
  2. package/dist/assignments.d.ts +95 -0
  3. package/dist/assignments.d.ts.map +1 -0
  4. package/dist/assignments.js +229 -0
  5. package/dist/assignments.js.map +1 -0
  6. package/dist/draft.d.ts +9 -7
  7. package/dist/draft.d.ts.map +1 -1
  8. package/dist/draft.js +10 -8
  9. package/dist/draft.js.map +1 -1
  10. package/dist/drafts.d.ts +29 -60
  11. package/dist/drafts.d.ts.map +1 -1
  12. package/dist/drafts.js +38 -117
  13. package/dist/drafts.js.map +1 -1
  14. package/dist/index.d.ts +5 -2
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +5 -2
  17. package/dist/index.js.map +1 -1
  18. package/dist/instrumentation/index.d.ts +1 -1
  19. package/dist/instrumentation/index.js +3 -3
  20. package/dist/instrumentation/index.js.map +1 -1
  21. package/dist/proxy/index.d.ts +134 -30
  22. package/dist/proxy/index.d.ts.map +1 -1
  23. package/dist/proxy/index.js +169 -37
  24. package/dist/proxy/index.js.map +1 -1
  25. package/dist/server/index.d.ts +59 -20
  26. package/dist/server/index.d.ts.map +1 -1
  27. package/dist/server/index.js +129 -25
  28. package/dist/server/index.js.map +1 -1
  29. package/dist/server/slot.d.ts +19 -4
  30. package/dist/server/slot.d.ts.map +1 -1
  31. package/dist/server/slot.js +3 -9
  32. package/dist/server/slot.js.map +1 -1
  33. package/dist/visitor.d.ts +16 -0
  34. package/dist/visitor.d.ts.map +1 -0
  35. package/dist/visitor.js +16 -0
  36. package/dist/visitor.js.map +1 -0
  37. package/package.json +3 -3
  38. package/src/assignments.ts +278 -0
  39. package/src/draft.ts +10 -8
  40. package/src/drafts.ts +38 -126
  41. package/src/index.ts +5 -2
  42. package/src/instrumentation/index.ts +3 -3
  43. package/src/proxy/index.ts +269 -56
  44. package/src/server/index.ts +152 -33
  45. package/src/server/slot.ts +18 -5
  46. package/src/visitor.ts +16 -0
@@ -1,14 +1,27 @@
1
1
  /**
2
- * The draft a request renders, held for the request's Server Components.
3
- * React's `cache()` gives one slot per request in the React Server
2
+ * What a request renders, held for the request's Server Components: the
3
+ * version (a draft, or an old release, with its preview's moment and switched
4
+ * tests and campaigns), the visitor and the tests and campaigns the proxy
5
+ * decided. React's `cache()` gives one slot per request in the React Server
4
6
  * Components graph, the scope a draft needs; no `next/headers` here, so the
5
7
  * root components can read it without binding anything.
6
8
  */
9
+ import type { RequestVersion } from "@decocms/blocks";
10
+ import type { Visitor } from "@decocms/blocks/experiments";
7
11
  import { cache } from "react";
12
+ import type { PathAssignments } from "../assignments.ts";
8
13
 
9
- export const draftSlot = cache((): { pointer: string | null } => ({ pointer: null }));
14
+ interface DraftSlot {
15
+ version: RequestVersion | null;
16
+ visitor: Visitor | null;
17
+ assignments: PathAssignments | null;
18
+ }
19
+
20
+ export const draftSlot = cache(
21
+ (): DraftSlot => ({ version: null, visitor: null, assignments: null }),
22
+ );
10
23
 
11
- /** The draft pointer bound to this request (`bindDraft`), or `null` when it renders the release. */
24
+ /** The version bound to this request (`bindDraft`), or `null` when it renders the current release. */
12
25
  export function activeDraftPointer(): string | null {
13
- return draftSlot().pointer;
26
+ return draftSlot().version?.version ?? null;
14
27
  }
package/src/visitor.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * How the proxy hands the pages the visitor: the request header it forwards
3
+ * once it read the visitor (`readVisitor` from `@decocms/blocks/experiments`,
4
+ * a new one on a first visit). The proxy writes it (`visitorRequestHeaders`
5
+ * from `@decocms/nextjs/proxy`); the pages read it (`bindDraft`, then
6
+ * `contentClient`, from `@decocms/nextjs/server`). The package's own copy: it
7
+ * never imports `@decocms/tanstack`. No imports, no state: safe in every
8
+ * bundle.
9
+ */
10
+
11
+ /**
12
+ * The request header carrying the visitor, in its stored form (the
13
+ * `deco_segment` cookie's value, `serializeVisitor`). The proxy removes any
14
+ * copy that arrives from outside (`draftRequestHeaders`).
15
+ */
16
+ export const VISITOR_HEADER = "x-deco-visitor";