payload-live-preview 2.0.0-beta.0 → 2.0.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 (109) hide show
  1. package/README.md +60 -775
  2. package/dist/adapters/astro/PreviewBoundary.astro +2 -2
  3. package/dist/adapters/astro/index.d.ts +28 -154
  4. package/dist/adapters/astro/index.js +1 -1
  5. package/dist/adapters/astro/index.js.map +1 -1
  6. package/dist/adapters/astro/middleware-entry.d.ts +3 -2
  7. package/dist/adapters/astro/middleware-entry.js +1 -1
  8. package/dist/adapters/astro/middleware-entry.js.map +1 -1
  9. package/dist/adapters/nextjs/index.d.ts +247 -6
  10. package/dist/adapters/nextjs/index.js +1 -1
  11. package/dist/adapters/nextjs/index.js.map +1 -1
  12. package/dist/adapters/nuxt/index.d.ts +58 -3
  13. package/dist/adapters/nuxt/index.js +1 -1
  14. package/dist/adapters/nuxt/index.js.map +1 -1
  15. package/dist/adapters/nuxt/module.d.ts +82 -0
  16. package/dist/adapters/nuxt/module.js +2 -0
  17. package/dist/adapters/nuxt/module.js.map +1 -0
  18. package/dist/adapters/react/index.d.ts +110 -0
  19. package/dist/adapters/react/index.js +3 -0
  20. package/dist/adapters/react/index.js.map +1 -0
  21. package/dist/adapters/sveltekit/index.d.ts +65 -7
  22. package/dist/adapters/sveltekit/index.js +1 -1
  23. package/dist/adapters/sveltekit/index.js.map +1 -1
  24. package/dist/adapters/vue/index.d.ts +56 -0
  25. package/dist/adapters/vue/index.js +2 -0
  26. package/dist/adapters/vue/index.js.map +1 -0
  27. package/dist/annotate.d.ts +161 -0
  28. package/dist/annotate.js +2 -0
  29. package/dist/annotate.js.map +1 -0
  30. package/dist/client.cjs +1 -1
  31. package/dist/client.cjs.map +1 -1
  32. package/dist/client.d.cts +182 -9
  33. package/dist/client.d.ts +182 -9
  34. package/dist/client.js +1 -1
  35. package/dist/client.js.map +1 -1
  36. package/dist/codegen-astro.js +1 -1
  37. package/dist/codegen-astro.js.map +1 -1
  38. package/dist/codegen-cli.js +1 -1
  39. package/dist/codegen-cli.js.map +1 -1
  40. package/dist/codegen.cjs +1 -1
  41. package/dist/codegen.cjs.map +1 -1
  42. package/dist/codegen.d.cts +129 -4
  43. package/dist/codegen.d.ts +129 -4
  44. package/dist/codegen.js +1 -1
  45. package/dist/codegen.js.map +1 -1
  46. package/dist/core.cjs +1 -1
  47. package/dist/core.cjs.map +1 -1
  48. package/dist/core.d.cts +264 -73
  49. package/dist/core.d.ts +264 -73
  50. package/dist/core.js +1 -1
  51. package/dist/core.js.map +1 -1
  52. package/dist/doctor-cli.d.ts +1 -1
  53. package/dist/doctor-cli.js +1 -1
  54. package/dist/doctor-cli.js.map +1 -1
  55. package/dist/doctor.d.ts +7 -6
  56. package/dist/doctor.js +1 -1
  57. package/dist/doctor.js.map +1 -1
  58. package/dist/document-session-BfBfLVpg.d.ts +53 -0
  59. package/dist/fragment-endpoint-3Mlz7GDz.d.ts +189 -0
  60. package/dist/fragment.cjs +1 -1
  61. package/dist/fragment.cjs.map +1 -1
  62. package/dist/fragment.d.cts +64 -18
  63. package/dist/fragment.d.ts +64 -18
  64. package/dist/fragment.js +1 -1
  65. package/dist/fragment.js.map +1 -1
  66. package/dist/index.cjs +1 -1
  67. package/dist/index.cjs.map +1 -1
  68. package/dist/index.d.cts +422 -83
  69. package/dist/index.d.ts +422 -83
  70. package/dist/index.js +1 -1
  71. package/dist/index.js.map +1 -1
  72. package/dist/lean.cjs +2 -0
  73. package/dist/lean.cjs.map +1 -0
  74. package/dist/lean.d.cts +44 -0
  75. package/dist/lean.d.ts +44 -0
  76. package/dist/lean.js +2 -0
  77. package/dist/lean.js.map +1 -0
  78. package/dist/lexical.cjs +1 -1
  79. package/dist/lexical.cjs.map +1 -1
  80. package/dist/lexical.d.cts +19 -1
  81. package/dist/lexical.d.ts +19 -1
  82. package/dist/lexical.js +1 -1
  83. package/dist/lexical.js.map +1 -1
  84. package/dist/locals-DBXDMxOA.d.ts +45 -0
  85. package/dist/{middleware-CEPsY1P7.d.ts → middleware-Bx9I7PXW.d.ts} +14 -14
  86. package/dist/migrate.d.ts +4 -3
  87. package/dist/migrate.js +1 -1
  88. package/dist/migrate.js.map +1 -1
  89. package/dist/{options-CEzzfHJu.d.ts → options-BW1eqXvc.d.ts} +90 -2
  90. package/dist/plugins.cjs +1 -1
  91. package/dist/plugins.cjs.map +1 -1
  92. package/dist/plugins.d.cts +111 -6
  93. package/dist/plugins.d.ts +111 -6
  94. package/dist/plugins.js +1 -1
  95. package/dist/plugins.js.map +1 -1
  96. package/dist/{probe-CYtvj_Lm.d.ts → probe-CELeUciC.d.ts} +26 -4
  97. package/dist/server.cjs +1 -1
  98. package/dist/server.cjs.map +1 -1
  99. package/dist/server.d.cts +67 -13
  100. package/dist/server.d.ts +67 -13
  101. package/dist/server.js +1 -1
  102. package/dist/server.js.map +1 -1
  103. package/dist/structural.cjs +2 -2
  104. package/dist/structural.cjs.map +1 -1
  105. package/dist/structural.d.cts +47 -4
  106. package/dist/structural.d.ts +47 -4
  107. package/dist/structural.js +2 -2
  108. package/dist/structural.js.map +1 -1
  109. package/package.json +77 -9
@@ -24,8 +24,8 @@
24
24
  * ```
25
25
  *
26
26
  * `data-payload-strategy="patch"` is written explicitly: the wrapper is a
27
- * patch target, and markup that needs the future fragment strategy says so
28
- * with a different value.
27
+ * patch target; markup a server renders instead lives in a
28
+ * `data-payload-fragment` boundary (docs/hybrid.md).
29
29
  */
30
30
 
31
31
  interface Props {
@@ -1,7 +1,10 @@
1
- import { L as LivePreviewAstroOptions } from '../../middleware-CEPsY1P7.js';
2
- export { a as LivePreviewMiddleware, c as createLivePreviewMiddleware } from '../../middleware-CEPsY1P7.js';
3
- import { P as PreviewAuthorizationRequest, A as AuthorizedPreviewScope, a as AuthorizedPreviewContext } from '../../options-CEzzfHJu.js';
4
- export { b as PreviewAdapterOptions, c as PreviewRequestLike, d as PreviewRequestOptions, h as hasPreviewIntent } from '../../options-CEzzfHJu.js';
1
+ import { L as LivePreviewAstroOptions } from '../../middleware-Bx9I7PXW.js';
2
+ export { a as LivePreviewMiddleware, c as createLivePreviewMiddleware } from '../../middleware-Bx9I7PXW.js';
3
+ import { h as hasPreviewIntent } from '../../options-BW1eqXvc.js';
4
+ export { P as PreviewAdapterOptions, a as PreviewRequestLike, b as PreviewRequestOptions, c as PreviewSignal } from '../../options-BW1eqXvc.js';
5
+ import { F as FragmentEndpointOptions$1, a as FragmentRegistry$1, b as FragmentRegistryEntry$1, c as FragmentRenderer$1 } from '../../fragment-endpoint-3Mlz7GDz.js';
6
+ export { d as FragmentRenderInput } from '../../fragment-endpoint-3Mlz7GDz.js';
7
+ export { A as AUTHORIZATION_LOCALS_KEY, a as AUTHORIZATION_OUTCOME_LOCALS_KEY, L as LivePreviewLocals, N as NONCE_LOCALS_KEY } from '../../locals-DBXDMxOA.js';
5
8
 
6
9
  /**
7
10
  * The Astro integration for `astro.config.mjs`: `livePreview({ ... })`.
@@ -62,15 +65,6 @@ interface AstroIntegrationLike {
62
65
  /** Build the integration. The injected runtime stays inert outside the admin's preview iframe. */
63
66
  declare function livePreview(options?: LivePreviewAstroOptions): AstroIntegrationLike;
64
67
 
65
- /** What a decision publishes for templates on `locals` (Astro, SvelteKit) or `event.context` (Nuxt). */
66
-
67
- /** The request-scoped nonce, for templates that nonce their own scripts. */
68
- declare const NONCE_LOCALS_KEY = "livePreviewNonce";
69
- /** The verified `AuthorizedPreviewContext`; absent unless `authorizePreview` authorized. */
70
- declare const AUTHORIZATION_LOCALS_KEY = "livePreviewAuthorization";
71
- /** The hook's `PreviewAuthorizationOutcome`; absent when no hook ran. */
72
- declare const AUTHORIZATION_OUTCOME_LOCALS_KEY = "livePreviewAuthorizationOutcome";
73
-
74
68
  /**
75
69
  * Manual embedding for `.astro` templates, for the cases the integration's
76
70
  * automatic injection does not fit (one layout, a conditional).
@@ -84,156 +78,36 @@ interface RenderScriptOptions extends LivePreviewAstroOptions {
84
78
  declare function renderLivePreviewScript(options?: RenderScriptOptions): string;
85
79
 
86
80
  /**
87
- * The `payload-session` strategy: forward exactly one named cookie to
88
- * `GET <serverURL>/api/<usersSlug>/me` and authorize when a user comes back.
81
+ * The 1.x names that 2.0 renamed, kept so a 1.x project compiles unchanged.
82
+ *
83
+ * A file of its own, and a small one: everything deprecated for 3.0 that the
84
+ * rename ledger produced lives here, so removing it is one deletion rather than
85
+ * a search. It also keeps the alias out of the module that defines the real
86
+ * function, where two exports of one value read as an accident.
87
+ *
88
+ * Measured against the published 1.8.1 declarations, entry by entry, not
89
+ * guessed: `isPreviewRequest` was exported from the root **and** from
90
+ * `./astro`, so it is re-exported from both. The other seven names 2.0 dropped
91
+ * moved behind `definePreview()` or changed shape, where an alias would restore
92
+ * the very defaults the move removed (ADR 0007, ledger rows 1 and 9).
89
93
  */
90
94
 
91
- /** A `fetch`-compatible function, injectable for tests. */
92
- type FetchLike = (input: string, init: {
93
- readonly headers: Record<string, string>;
94
- readonly signal: AbortSignal;
95
- }) => Promise<{
96
- readonly ok: boolean;
97
- readonly status: number;
98
- json(): Promise<unknown>;
99
- }>;
100
- interface PayloadSessionStrategy {
101
- readonly type: 'payload-session';
102
- /** Payload server origin, e.g. `https://cms.example.com`. */
103
- readonly serverURL: string;
104
- /** Auth collection slug; `users` unless the project renamed it. */
105
- readonly usersSlug?: string;
106
- /** Cookie name; Payload's default is `payload-token`. */
107
- readonly cookieName?: string;
108
- /** Upper bound for the `/me` round trip. Below 250 ms is raised to 250 ms; default 3000. */
109
- readonly timeoutMs?: number;
110
- /** Longest cookie value accepted; longer ones are refused as `invalid`. Default 4096. */
111
- readonly maxCookieLength?: number;
112
- readonly fetch?: FetchLike;
113
- /** Clock, Unix milliseconds. Injectable for tests. */
114
- readonly now?: () => number;
115
- }
116
-
117
95
  /**
118
- * The `signed-token` strategy: a short-lived HMAC-SHA256 token minted by the
119
- * Payload side and verified by the site. Format and bindings: ADR 0006 §3.
96
+ * @deprecated Use `hasPreviewIntent`; removed in 3.0. `pll migrate` rewrites it.
120
97
  */
98
+ declare const isPreviewRequest: typeof hasPreviewIntent;
121
99
 
122
- /** The subset of Web Crypto the token strategy needs, injectable for environments that expose it elsewhere. */
123
- interface SubtleCryptoLike {
124
- readonly subtle: {
125
- importKey(format: 'raw', keyData: Uint8Array, algorithm: {
126
- readonly name: 'HMAC';
127
- readonly hash: 'SHA-256';
128
- }, extractable: false, keyUsages: readonly ('sign' | 'verify')[]): Promise<CryptoKey>;
129
- sign(algorithm: 'HMAC', key: CryptoKey, data: Uint8Array): Promise<ArrayBuffer>;
130
- verify(algorithm: 'HMAC', key: CryptoKey, signature: Uint8Array, data: Uint8Array): Promise<boolean>;
131
- };
132
- getRandomValues<T extends Uint8Array>(array: T): T;
133
- }
134
- /** Where a signed token is read from on the request. */
135
- type PreviewTokenTransport = {
136
- readonly kind: 'query';
137
- readonly param?: string;
138
- } | {
139
- readonly kind: 'header';
140
- readonly name?: string;
141
- };
142
- /**
143
- * Optional replay store. Not shipped: a per-process memory is useless behind
144
- * a load balancer, so the store is a deployment decision.
145
- */
146
- interface PreviewTokenReplayStore {
147
- isUsed(id: string): Promise<boolean> | boolean;
148
- markUsed(id: string, expiresAt: number): Promise<void> | void;
149
- }
150
- interface SignedTokenStrategy {
151
- readonly type: 'signed-token';
152
- /** Shared secret, at least 32 bytes; shorter ones are refused on first use. */
153
- readonly secret: string | Uint8Array;
154
- /** The site origin tokens must name, e.g. `https://www.example.com`. */
155
- readonly audience: string;
156
- /** Purpose string tokens must carry. Default `live-preview`. */
157
- readonly purpose?: string;
158
- /** Default: query parameter `previewToken`. */
159
- readonly transport?: PreviewTokenTransport;
160
- /** Resolve the request's locale for the `loc` binding. Unset: tokens with `loc` are refused as `wrong-locale`. */
161
- readonly locale?: (request: PreviewAuthorizationRequest) => string | undefined;
162
- readonly replay?: PreviewTokenReplayStore;
163
- readonly crypto?: SubtleCryptoLike;
164
- readonly now?: () => number;
165
- }
166
-
167
- /**
168
- * Authorized preview context: the one verdict every privileged preview
169
- * decision is keyed on. Intent (`?preview=true`, an iframe destination, a
170
- * referer) is client-chosen; this turns a session, a signed token or the
171
- * application's own verifier into a branded context. Threat model: ADR 0006.
172
- */
173
-
174
- /** Claims a consumer verifier returns for a request it accepts. */
175
- interface PreviewVerifierClaims {
176
- readonly subject?: string;
177
- readonly expiresAt?: number;
178
- readonly scope?: AuthorizedPreviewScope;
179
- readonly payloadHeaders?: Readonly<Record<string, string>>;
180
- }
181
- /** The application's own verification: claims authorize, `null` refuses, a throw is `unavailable`. */
182
- interface VerifierStrategy {
183
- readonly type: 'verifier';
184
- readonly verify: (request: PreviewAuthorizationRequest) => Promise<PreviewVerifierClaims | null> | PreviewVerifierClaims | null;
185
- readonly now?: () => number;
186
- }
187
- type PreviewAuthorizationStrategy = PayloadSessionStrategy | SignedTokenStrategy | VerifierStrategy;
188
-
189
- /**
190
- * The Astro fragment endpoint (ADR 0011): renders a registered component
191
- * boundary from unsaved form state for an authorized preview, and nothing
192
- * else. The browser names a registry id; the server decides what it renders.
193
- */
194
-
195
- /** Everything a registry entry may use to compute its props. */
196
- interface FragmentRenderInput {
197
- readonly id: string;
198
- readonly key: string | undefined;
199
- readonly revision: number;
200
- readonly fields: Readonly<Record<string, unknown>>;
201
- readonly locale: string | undefined;
202
- readonly collectionSlug: string | undefined;
203
- readonly globalSlug: string | undefined;
204
- readonly route: string;
205
- readonly authorization: AuthorizedPreviewContext;
206
- readonly request: Request;
207
- }
208
100
  /** An Astro component as `import Hero from './Hero.astro'` yields it. */
209
101
  type AstroComponentLike = object;
210
- interface FragmentRegistryEntry<Props extends Record<string, unknown> = Record<string, unknown>> {
211
- readonly component: AstroComponentLike;
212
- /** Props for the component, computed from the input; never from request-controlled code. */
213
- readonly props: (input: FragmentRenderInput) => Props | Promise<Props>;
214
- }
215
- type FragmentRegistry = Readonly<Record<string, FragmentRegistryEntry>>;
216
- /** Renders a component with props to HTML; the default uses Astro's container API. */
217
- type FragmentRenderer = (component: AstroComponentLike, props: Record<string, unknown>, input: FragmentRenderInput) => Promise<string>;
218
- interface FragmentEndpointOptions {
219
- /** The only things this endpoint can render. */
220
- readonly registry: FragmentRegistry;
221
- /** How a preview request is authorized; the same strategies as `authorizePreviewRequest()`. */
222
- readonly authorize: PreviewAuthorizationStrategy;
223
- /** Override the renderer (tests, other component systems). Default: Astro container. */
224
- readonly render?: FragmentRenderer;
225
- /** Origins besides the page's own that may call the endpoint. Default: none. */
226
- readonly allowedOrigins?: readonly string[];
227
- readonly limits?: {
228
- /** Largest request body. Default 64 KiB. */
229
- readonly bodyBytes?: number;
230
- /** Render timeout. Default 5000 ms. */
231
- readonly timeoutMs?: number;
232
- };
233
- }
102
+ type FragmentRegistryEntry<Props extends object = object> = FragmentRegistryEntry$1<AstroComponentLike, Props>;
103
+ /** @internal */
104
+ type FragmentRegistry = FragmentRegistry$1<AstroComponentLike>;
105
+ /** @internal */
106
+ type FragmentRenderer = FragmentRenderer$1<AstroComponentLike>;
107
+ type FragmentEndpointOptions = FragmentEndpointOptions$1<AstroComponentLike>;
234
108
  /** Build the endpoint; export it as the `POST` of a non-prerendered Astro API route. */
235
109
  declare function createFragmentEndpoint(options: FragmentEndpointOptions): (context: {
236
110
  readonly request: Request;
237
111
  }) => Promise<Response>;
238
112
 
239
- export { AUTHORIZATION_LOCALS_KEY, AUTHORIZATION_OUTCOME_LOCALS_KEY, type AstroComponentLike, type AstroIntegrationLike, type FragmentEndpointOptions, type FragmentRegistry, type FragmentRegistryEntry, type FragmentRenderInput, type FragmentRenderer, LivePreviewAstroOptions, NONCE_LOCALS_KEY, type RenderScriptOptions, createFragmentEndpoint, livePreview, renderLivePreviewScript };
113
+ export { type AstroComponentLike, type AstroIntegrationLike, type FragmentEndpointOptions, type FragmentRegistry, type FragmentRegistryEntry, type FragmentRenderer, LivePreviewAstroOptions, type RenderScriptOptions, createFragmentEndpoint, hasPreviewIntent, isPreviewRequest, livePreview, renderLivePreviewScript };