payload-live-preview 1.8.0 → 2.0.0-beta.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.
- package/README.md +301 -93
- package/dist/adapters/astro/PreviewBoundary.astro +66 -0
- package/dist/adapters/astro/RichText.astro +6 -0
- package/dist/adapters/astro/index.d.ts +165 -134
- package/dist/adapters/astro/index.js +1 -1
- package/dist/adapters/astro/index.js.map +1 -1
- package/dist/adapters/astro/middleware-entry.d.ts +4 -9
- package/dist/adapters/astro/middleware-entry.js +1 -1
- package/dist/adapters/astro/middleware-entry.js.map +1 -1
- package/dist/adapters/nextjs/index.d.ts +13 -80
- package/dist/adapters/nextjs/index.js +1 -1
- package/dist/adapters/nextjs/index.js.map +1 -1
- package/dist/adapters/nuxt/index.d.ts +46 -106
- package/dist/adapters/nuxt/index.js +1 -1
- package/dist/adapters/nuxt/index.js.map +1 -1
- package/dist/adapters/sveltekit/index.d.ts +10 -75
- package/dist/adapters/sveltekit/index.js +1 -1
- package/dist/adapters/sveltekit/index.js.map +1 -1
- package/dist/client.cjs +2 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +747 -0
- package/dist/client.d.ts +747 -0
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -0
- package/dist/codegen-astro.d.ts +5 -27
- package/dist/codegen-astro.js +1 -1
- package/dist/codegen-astro.js.map +1 -1
- package/dist/codegen-cli.d.ts +3 -16
- package/dist/codegen-cli.js +1 -1
- package/dist/codegen-cli.js.map +1 -1
- package/dist/codegen.cjs +1 -1
- package/dist/codegen.cjs.map +1 -1
- package/dist/codegen.d.cts +37 -124
- package/dist/codegen.d.ts +37 -124
- package/dist/codegen.js +1 -1
- package/dist/codegen.js.map +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +647 -1100
- package/dist/core.d.ts +647 -1100
- package/dist/core.js +1 -1
- package/dist/core.js.map +1 -1
- package/dist/doctor-cli.d.ts +3 -28
- package/dist/doctor-cli.js +1 -1
- package/dist/doctor-cli.js.map +1 -1
- package/dist/doctor.d.ts +16 -32
- package/dist/doctor.js +1 -1
- package/dist/doctor.js.map +1 -1
- package/dist/fragment.cjs +2 -0
- package/dist/fragment.cjs.map +1 -0
- package/dist/fragment.d.cts +333 -0
- package/dist/fragment.d.ts +333 -0
- package/dist/fragment.js +2 -0
- package/dist/fragment.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +885 -1531
- package/dist/index.d.ts +885 -1531
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lexical.cjs +2 -0
- package/dist/lexical.cjs.map +1 -0
- package/dist/lexical.d.cts +90 -0
- package/dist/lexical.d.ts +90 -0
- package/dist/lexical.js +2 -0
- package/dist/lexical.js.map +1 -0
- package/dist/middleware-CEPsY1P7.d.ts +40 -0
- package/dist/migrate.d.ts +73 -0
- package/dist/migrate.js +2 -0
- package/dist/migrate.js.map +1 -0
- package/dist/options-CEzzfHJu.d.ts +197 -0
- package/dist/payload.cjs +1 -1
- package/dist/payload.cjs.map +1 -1
- package/dist/payload.d.cts +11 -80
- package/dist/payload.d.ts +11 -80
- package/dist/payload.js +1 -1
- package/dist/payload.js.map +1 -1
- package/dist/plugins.cjs +2 -0
- package/dist/plugins.cjs.map +1 -0
- package/dist/plugins.d.cts +509 -0
- package/dist/plugins.d.ts +509 -0
- package/dist/plugins.js +2 -0
- package/dist/plugins.js.map +1 -0
- package/dist/{probe-tMHdim5y.d.ts → probe-CYtvj_Lm.d.ts} +43 -77
- package/dist/server.cjs +2 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +435 -0
- package/dist/server.d.ts +435 -0
- package/dist/server.js +2 -0
- package/dist/server.js.map +1 -0
- package/dist/structural.cjs +3 -0
- package/dist/structural.cjs.map +1 -0
- package/dist/structural.d.cts +243 -0
- package/dist/structural.d.ts +243 -0
- package/dist/structural.js +3 -0
- package/dist/structural.js.map +1 -0
- package/package.json +86 -7
- package/dist/middleware-DD4Hwomt.d.ts +0 -189
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "payload-live-preview",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"description": "Live preview for Payload CMS in Astro and any SSR/static frontend (SvelteKit, Nuxt, Next.js, plain HTML). Patches the DOM live, no rebuild.",
|
|
5
5
|
"author": "relative23",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
|
-
"packageManager": "npm@
|
|
8
|
+
"packageManager": "npm@12.0.2",
|
|
9
9
|
"main": "./dist/index.cjs",
|
|
10
10
|
"module": "./dist/index.js",
|
|
11
11
|
"types": "./dist/index.d.ts",
|
|
@@ -76,6 +76,12 @@
|
|
|
76
76
|
"default": "./dist/doctor.js"
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
+
"./migrate": {
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./dist/migrate.d.ts",
|
|
82
|
+
"default": "./dist/migrate.js"
|
|
83
|
+
}
|
|
84
|
+
},
|
|
79
85
|
"./payload": {
|
|
80
86
|
"import": {
|
|
81
87
|
"types": "./dist/payload.d.ts",
|
|
@@ -86,7 +92,68 @@
|
|
|
86
92
|
"default": "./dist/payload.cjs"
|
|
87
93
|
}
|
|
88
94
|
},
|
|
95
|
+
"./server": {
|
|
96
|
+
"import": {
|
|
97
|
+
"types": "./dist/server.d.ts",
|
|
98
|
+
"default": "./dist/server.js"
|
|
99
|
+
},
|
|
100
|
+
"require": {
|
|
101
|
+
"types": "./dist/server.d.cts",
|
|
102
|
+
"default": "./dist/server.cjs"
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"./client": {
|
|
106
|
+
"import": {
|
|
107
|
+
"types": "./dist/client.d.ts",
|
|
108
|
+
"default": "./dist/client.js"
|
|
109
|
+
},
|
|
110
|
+
"require": {
|
|
111
|
+
"types": "./dist/client.d.cts",
|
|
112
|
+
"default": "./dist/client.cjs"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"./structural": {
|
|
116
|
+
"import": {
|
|
117
|
+
"types": "./dist/structural.d.ts",
|
|
118
|
+
"default": "./dist/structural.js"
|
|
119
|
+
},
|
|
120
|
+
"require": {
|
|
121
|
+
"types": "./dist/structural.d.cts",
|
|
122
|
+
"default": "./dist/structural.cjs"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"./lexical": {
|
|
126
|
+
"import": {
|
|
127
|
+
"types": "./dist/lexical.d.ts",
|
|
128
|
+
"default": "./dist/lexical.js"
|
|
129
|
+
},
|
|
130
|
+
"require": {
|
|
131
|
+
"types": "./dist/lexical.d.cts",
|
|
132
|
+
"default": "./dist/lexical.cjs"
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
"./plugins": {
|
|
136
|
+
"import": {
|
|
137
|
+
"types": "./dist/plugins.d.ts",
|
|
138
|
+
"default": "./dist/plugins.js"
|
|
139
|
+
},
|
|
140
|
+
"require": {
|
|
141
|
+
"types": "./dist/plugins.d.cts",
|
|
142
|
+
"default": "./dist/plugins.cjs"
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
"./fragment": {
|
|
146
|
+
"import": {
|
|
147
|
+
"types": "./dist/fragment.d.ts",
|
|
148
|
+
"default": "./dist/fragment.js"
|
|
149
|
+
},
|
|
150
|
+
"require": {
|
|
151
|
+
"types": "./dist/fragment.d.cts",
|
|
152
|
+
"default": "./dist/fragment.cjs"
|
|
153
|
+
}
|
|
154
|
+
},
|
|
89
155
|
"./astro/RichText.astro": "./dist/adapters/astro/RichText.astro",
|
|
156
|
+
"./astro/PreviewBoundary.astro": "./dist/adapters/astro/PreviewBoundary.astro",
|
|
90
157
|
"./astro/middleware-entry": {
|
|
91
158
|
"import": {
|
|
92
159
|
"types": "./dist/adapters/astro/middleware-entry.d.ts",
|
|
@@ -106,25 +173,34 @@
|
|
|
106
173
|
"sideEffects": false,
|
|
107
174
|
"scripts": {
|
|
108
175
|
"build:runtime": "tsx scripts/build-runtime.ts",
|
|
109
|
-
"build": "npm run build:runtime && tsx scripts/build-dist.ts && npm run build:assets && npm run test:bundle",
|
|
110
|
-
"build:assets": "node -e \"require('node:fs').copyFileSync('src/adapters/astro/
|
|
176
|
+
"build": "npm run build:runtime && tsx scripts/build-dist.ts && npm run build:assets && npm run test:bundle && npm run test:treeshake && npm run test:edge",
|
|
177
|
+
"build:assets": "node -e \"const fs=require('node:fs');for(const f of ['RichText','PreviewBoundary'])fs.copyFileSync('src/adapters/astro/'+f+'.astro','dist/adapters/astro/'+f+'.astro')\"",
|
|
111
178
|
"dev": "tsup --watch",
|
|
179
|
+
"pretest": "npm run build:runtime",
|
|
112
180
|
"test": "vitest run",
|
|
113
181
|
"test:watch": "vitest",
|
|
114
182
|
"test:unit": "vitest run tests/unit",
|
|
115
183
|
"test:integration": "vitest run tests/integration",
|
|
116
184
|
"test:e2e": "playwright test",
|
|
185
|
+
"check:fixtures": "tsx scripts/check-fixture-freshness.ts",
|
|
117
186
|
"test:e2e:real-payload": "playwright test --config playwright.real-payload.config.ts",
|
|
118
187
|
"test:a11y": "playwright test tests/e2e/specs/accessibility.spec.ts",
|
|
119
188
|
"test:soak": "playwright test --config playwright.soak.config.ts",
|
|
189
|
+
"test:browser-bench": "playwright test --config playwright.bench.config.ts",
|
|
120
190
|
"test:bench": "vitest bench tests/benchmarks",
|
|
121
191
|
"test:bench:codspeed": "vitest bench --run --config vitest.bench.config.ts",
|
|
122
192
|
"test:bundle": "tsx scripts/check-bundle-size.ts",
|
|
193
|
+
"test:treeshake": "tsx scripts/check-tree-shaking.ts",
|
|
194
|
+
"test:edge": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' tsx scripts/check-edge-runtime.ts",
|
|
195
|
+
"compat:check": "tsx scripts/compat-table.ts --check",
|
|
196
|
+
"compat:write": "tsx scripts/compat-table.ts --write",
|
|
123
197
|
"test:package": "tsx scripts/check-package.ts",
|
|
198
|
+
"audit:gate": "tsx scripts/audit-gate.ts",
|
|
199
|
+
"test:smoke": "tsx scripts/post-publish-smoke.ts",
|
|
124
200
|
"test:coverage": "vitest run --coverage",
|
|
125
201
|
"test:coverage:diff": "tsx scripts/coverage-policy.ts",
|
|
126
202
|
"test:policy": "tsx scripts/test-policy.ts",
|
|
127
|
-
"test:architecture": "tsx scripts/architecture-policy.ts && tsx scripts/
|
|
203
|
+
"test:architecture": "tsx scripts/architecture-policy.ts && tsx scripts/workflow-contracts.ts && tsx scripts/docs-contracts.ts && knip --no-progress --treat-config-hints-as-errors",
|
|
128
204
|
"test:property": "vitest run tests/unit/property",
|
|
129
205
|
"test:mutation": "stryker run stryker.config.js",
|
|
130
206
|
"test:mutation:policy:pr": "tsx scripts/mutation-policy.ts --policy quality/mutation-policy-pr.json --report test-results/stryker-pr.json",
|
|
@@ -141,7 +217,8 @@
|
|
|
141
217
|
"prepublishOnly": "npm run build && npm run check && npm run format:check && npm run test:package",
|
|
142
218
|
"changeset": "changeset",
|
|
143
219
|
"version": "changeset version && tsx scripts/sync-lockfile-metadata.ts",
|
|
144
|
-
"release": "tsx scripts/publish-artifact.ts"
|
|
220
|
+
"release": "tsx scripts/publish-artifact.ts",
|
|
221
|
+
"test:docs": "tsx scripts/docs-contracts.ts"
|
|
145
222
|
},
|
|
146
223
|
"devDependencies": {
|
|
147
224
|
"@arethetypeswrong/cli": "^0.18.5",
|
|
@@ -171,7 +248,9 @@
|
|
|
171
248
|
"tsx": "^4.23.12",
|
|
172
249
|
"typescript": "^5.9.3",
|
|
173
250
|
"typescript-eslint": "^8.67.0",
|
|
174
|
-
"
|
|
251
|
+
"vite": "^7.3.6",
|
|
252
|
+
"vitest": "^4.1.10",
|
|
253
|
+
"yaml": "^2.9.0"
|
|
175
254
|
},
|
|
176
255
|
"overrides": {
|
|
177
256
|
"qs": "6.15.3",
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public types for the Astro adapter.
|
|
3
|
-
*
|
|
4
|
-
* @module @adapters/astro/types
|
|
5
|
-
*/
|
|
6
|
-
interface LivePreviewAstroOptions {
|
|
7
|
-
/**
|
|
8
|
-
* How the integration wires the preview:
|
|
9
|
-
*
|
|
10
|
-
* - `'inline'` (default) — bake the runtime into every page at
|
|
11
|
-
* build time. For `output: 'static'` projects.
|
|
12
|
-
* - `'loader'` — inject a few hundred bytes that check the preview
|
|
13
|
-
* context and fetch the runtime as a hashed, SRI-verified asset only
|
|
14
|
-
* when it is one. Also for `output: 'static'`, and the better choice
|
|
15
|
-
* there: `'inline'` charges every ordinary visitor ~21 KB gzip for a
|
|
16
|
-
* feature only an editor uses.
|
|
17
|
-
* - `'middleware'` — auto-register the preview middleware:
|
|
18
|
-
* request-time injection into requests with preview intent,
|
|
19
|
-
* plus `frame-ancestors` CSP management. For `output: 'server'`.
|
|
20
|
-
* (`shouldInject` is unsupported here — options serialize into
|
|
21
|
-
* the build.)
|
|
22
|
-
*
|
|
23
|
-
* Intent signals are not authorization. If either response change
|
|
24
|
-
* must be access-controlled, compose `createLivePreviewMiddleware()`
|
|
25
|
-
* manually after an application-owned server-side authorization.
|
|
26
|
-
*/
|
|
27
|
-
readonly mode?: 'inline' | 'loader' | 'middleware';
|
|
28
|
-
/**
|
|
29
|
-
* Allowed Payload admin origin(s) for inbound browser messages and
|
|
30
|
-
* the optional Referer intent signal. This does not authenticate the
|
|
31
|
-
* incoming HTTP request or authorize draft access.
|
|
32
|
-
*/
|
|
33
|
-
readonly allowedOrigins?: readonly string[];
|
|
34
|
-
/**
|
|
35
|
-
* Payload server origin, e.g. `https://cms.example.com`. When set,
|
|
36
|
-
* incoming updates are re-fetched through the Payload REST API so
|
|
37
|
-
* relationship/upload fields render populated instead of as bare
|
|
38
|
-
* IDs. Strongly recommended for Payload 3.x.
|
|
39
|
-
*/
|
|
40
|
-
readonly serverURL?: string;
|
|
41
|
-
/** REST API route prefix used with `serverURL`. Defaults to `/api`. */
|
|
42
|
-
readonly apiRoute?: string;
|
|
43
|
-
/** Population depth used with `serverURL`. Defaults to `1`. */
|
|
44
|
-
readonly mergeDepth?: number;
|
|
45
|
-
/**
|
|
46
|
-
* Auto-inject the inline preview script. Default `true`. Disable to
|
|
47
|
-
* embed the script manually via `renderLivePreviewScript()`.
|
|
48
|
-
*/
|
|
49
|
-
readonly autoInject?: boolean;
|
|
50
|
-
/**
|
|
51
|
-
* When the middleware injects the script (integration-based
|
|
52
|
-
* injection is always build-time and unaffected):
|
|
53
|
-
*
|
|
54
|
-
* - `'preview-only'` (default) — only into responses carrying a
|
|
55
|
-
* preview-intent signal (`?preview=true` / `?draft=true` query,
|
|
56
|
-
* `Sec-Fetch-Dest: iframe`, or a referer from `allowedOrigins`).
|
|
57
|
-
* These client-controlled signals are a delivery optimisation,
|
|
58
|
-
* not authorization.
|
|
59
|
-
* - `'always'` — into every HTML response.
|
|
60
|
-
*/
|
|
61
|
-
readonly inject?: 'preview-only' | 'always';
|
|
62
|
-
/**
|
|
63
|
-
* Query parameters that mark a request as a preview (values `true`
|
|
64
|
-
* or `1`). Default: `['preview', 'draft', 'livePreview']`.
|
|
65
|
-
*/
|
|
66
|
-
readonly previewQueryParams?: readonly string[];
|
|
67
|
-
/**
|
|
68
|
-
* Which signals count as preview intent. Default: all three
|
|
69
|
-
* (`query`, `fetch-dest`, `referer`). Restrict to `['query']` when
|
|
70
|
-
* an unsolicited iframe load must never trigger preview handling
|
|
71
|
-
* (e.g. sites that serve `frame-ancestors 'none'` and only allow
|
|
72
|
-
* preview via the explicit `?preview=true` URL).
|
|
73
|
-
*/
|
|
74
|
-
readonly previewSignals?: readonly ('query' | 'fetch-dest' | 'referer')[];
|
|
75
|
-
/**
|
|
76
|
-
* Restrict script injection to requests where this function returns
|
|
77
|
-
* `true`. Applied on top of the `inject` mode. This is a synchronous
|
|
78
|
-
* route/content filter, not authentication, and it does not suppress
|
|
79
|
-
* the adapter's CSP handling. Perform authorization before invoking
|
|
80
|
-
* the middleware.
|
|
81
|
-
*/
|
|
82
|
-
readonly shouldInject?: (request: Request) => boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Content-Security-Policy management on responses carrying preview
|
|
85
|
-
* intent. The adapter does not authenticate those requests; invoke
|
|
86
|
-
* it only after authorization when this policy change is privileged:
|
|
87
|
-
*
|
|
88
|
-
* - `'frame-ancestors'` (default) — merge a `frame-ancestors`
|
|
89
|
-
* directive allowing the admin origins to embed the page.
|
|
90
|
-
* Existing CSP directives are preserved (union merge).
|
|
91
|
-
* - `'full'` — additionally manage `script-src` with a
|
|
92
|
-
* per-request nonce. Only useful when your whole page is
|
|
93
|
-
* nonce-disciplined; see `strictDynamic`.
|
|
94
|
-
* - `false` — never touch CSP headers.
|
|
95
|
-
*
|
|
96
|
-
* `true` is accepted as a legacy alias for `'frame-ancestors'`.
|
|
97
|
-
*/
|
|
98
|
-
readonly manageCsp?: boolean | 'frame-ancestors' | 'full';
|
|
99
|
-
/**
|
|
100
|
-
* Add `'strict-dynamic'` to the managed `script-src` (only with
|
|
101
|
-
* `manageCsp: 'full'`). ⚠️ Under CSP 3 this makes browsers ignore
|
|
102
|
-
* `'self'` and host sources — every script on the page must then
|
|
103
|
-
* carry the nonce or be loaded by a nonce-carrying script. Astro's
|
|
104
|
-
* own hydration scripts do NOT carry it, so leave this off unless
|
|
105
|
-
* you know your page is fully nonce-disciplined. Default `false`.
|
|
106
|
-
*/
|
|
107
|
-
readonly strictDynamic?: boolean;
|
|
108
|
-
/**
|
|
109
|
-
* Extra `frame-ancestors` sources to merge with the auto-detected
|
|
110
|
-
* ones. Always includes `'self'` and every entry in `allowedOrigins`.
|
|
111
|
-
*/
|
|
112
|
-
readonly frameAncestorsExtra?: readonly string[];
|
|
113
|
-
/**
|
|
114
|
-
* Extra `script-src` sources (e.g., a CDN) appended after the nonce
|
|
115
|
-
* (only with `manageCsp: 'full'`).
|
|
116
|
-
*/
|
|
117
|
-
readonly scriptSrcExtra?: readonly string[];
|
|
118
|
-
/** Enable verbose debug logging in the injected client. Defaults to `false`. */
|
|
119
|
-
readonly debug?: boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Debounce window for incoming updates. Default: 50 ms.
|
|
122
|
-
*/
|
|
123
|
-
readonly debounceMs?: number;
|
|
124
|
-
/**
|
|
125
|
-
* Heartbeat timeout in ms. Default `0` (disabled — the Payload admin
|
|
126
|
-
* sends no keepalive, so an idle timeout would cause false
|
|
127
|
-
* disconnects).
|
|
128
|
-
*/
|
|
129
|
-
readonly heartbeatMs?: number;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Astro middleware for Payload Live Preview.
|
|
134
|
-
*
|
|
135
|
-
* Responsibilities (per request):
|
|
136
|
-
*
|
|
137
|
-
* 1. Generate a per-response CSP nonce and stash it on
|
|
138
|
-
* `Astro.locals.livePreviewNonce` so consumers can reference it.
|
|
139
|
-
* 2. On requests carrying **preview intent** (see
|
|
140
|
-
* `isPreviewRequest`), rewrite the HTML response to inject the
|
|
141
|
-
* live-preview `<script>` tag.
|
|
142
|
-
* 3. On those requests, merge `frame-ancestors` into the
|
|
143
|
-
* `Content-Security-Policy` header so the Payload admin may embed
|
|
144
|
-
* the page. Full `script-src` nonce management is opt-in via
|
|
145
|
-
* `manageCsp: 'full'`.
|
|
146
|
-
*
|
|
147
|
-
* The intent signals are client-controlled and this middleware does
|
|
148
|
-
* not authenticate them. For protected preview responses, first verify
|
|
149
|
-
* an application-owned server session or short-lived authorization,
|
|
150
|
-
* then invoke this middleware with that same decision also governing
|
|
151
|
-
* draft reads, credentials, and cache policy. `shouldInject` filters
|
|
152
|
-
* script insertion only; it is not an authorization boundary and does
|
|
153
|
-
* not disable CSP handling.
|
|
154
|
-
*
|
|
155
|
-
* Prerendered pages are skipped entirely: Astro runs middleware at
|
|
156
|
-
* build time for those, where per-request nonces and response headers
|
|
157
|
-
* are meaningless.
|
|
158
|
-
*
|
|
159
|
-
* @module @adapters/astro/middleware
|
|
160
|
-
*/
|
|
161
|
-
|
|
162
|
-
type MiddlewareNext = () => Promise<Response>;
|
|
163
|
-
interface MiddlewareContext {
|
|
164
|
-
readonly request: Request;
|
|
165
|
-
readonly locals: Record<string, unknown>;
|
|
166
|
-
/** Present in Astro ≥ 5: `true` while prerendering at build time. */
|
|
167
|
-
readonly isPrerendered?: boolean;
|
|
168
|
-
}
|
|
169
|
-
type LivePreviewMiddleware = (context: MiddlewareContext, next: MiddlewareNext) => Promise<Response>;
|
|
170
|
-
/**
|
|
171
|
-
* Key on `Astro.locals` carrying the request-scoped nonce. Consumers
|
|
172
|
-
* can read `Astro.locals.livePreviewNonce` from `.astro` templates to
|
|
173
|
-
* set the `nonce` attribute on their own scripts.
|
|
174
|
-
*/
|
|
175
|
-
declare const NONCE_LOCALS_KEY = "livePreviewNonce";
|
|
176
|
-
/**
|
|
177
|
-
* Build the Astro-compatible middleware. Register it in
|
|
178
|
-
* `src/middleware.ts`:
|
|
179
|
-
*
|
|
180
|
-
* ```ts
|
|
181
|
-
* import { createLivePreviewMiddleware } from 'payload-live-preview/astro';
|
|
182
|
-
* export const onRequest = createLivePreviewMiddleware({
|
|
183
|
-
* allowedOrigins: [import.meta.env.PUBLIC_PAYLOAD_ADMIN_ORIGIN],
|
|
184
|
-
* });
|
|
185
|
-
* ```
|
|
186
|
-
*/
|
|
187
|
-
declare function createLivePreviewMiddleware(options?: LivePreviewAstroOptions): LivePreviewMiddleware;
|
|
188
|
-
|
|
189
|
-
export { type LivePreviewAstroOptions as L, NONCE_LOCALS_KEY as N, type LivePreviewMiddleware as a, createLivePreviewMiddleware as c };
|