@nifrajs/web 3.5.0 → 4.0.2
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/dist/backend-only.d.ts +15 -0
- package/dist/backend-only.d.ts.map +1 -0
- package/dist/backend-only.js +16 -0
- package/dist/backend-only.js.map +1 -0
- package/dist/boundary.d.ts +5 -0
- package/dist/boundary.d.ts.map +1 -1
- package/dist/boundary.js +11 -2
- package/dist/boundary.js.map +1 -1
- package/dist/build-plan.d.ts +18 -6
- package/dist/build-plan.d.ts.map +1 -1
- package/dist/build-plan.js +82 -34
- package/dist/build-plan.js.map +1 -1
- package/dist/build-vite.d.ts +4 -0
- package/dist/build-vite.d.ts.map +1 -1
- package/dist/build-vite.js +68 -13
- package/dist/build-vite.js.map +1 -1
- package/dist/build.d.ts +57 -23
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +356 -85
- package/dist/build.js.map +1 -1
- package/dist/bun-dev-entry.d.ts +1 -1
- package/dist/bun-dev-entry.js +1 -1
- package/dist/cdn.d.ts +74 -0
- package/dist/cdn.d.ts.map +1 -0
- package/dist/cdn.js +132 -0
- package/dist/cdn.js.map +1 -0
- package/dist/client.d.ts +3 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +136 -35
- package/dist/client.js.map +1 -1
- package/dist/conformance.d.ts +4 -3
- package/dist/conformance.d.ts.map +1 -1
- package/dist/conformance.js +12 -3
- package/dist/conformance.js.map +1 -1
- package/dist/csp.d.ts +93 -0
- package/dist/csp.d.ts.map +1 -0
- package/dist/csp.js +122 -0
- package/dist/csp.js.map +1 -0
- package/dist/dev-client.d.ts +76 -0
- package/dist/dev-client.d.ts.map +1 -0
- package/dist/dev-client.js +280 -0
- package/dist/dev-client.js.map +1 -0
- package/dist/dev-diagnostics.d.ts +26 -2
- package/dist/dev-diagnostics.d.ts.map +1 -1
- package/dist/dev-diagnostics.js +38 -7
- package/dist/dev-diagnostics.js.map +1 -1
- package/dist/dev-error.d.ts +4 -13
- package/dist/dev-error.d.ts.map +1 -1
- package/dist/dev-error.js +46 -4
- package/dist/dev-error.js.map +1 -1
- package/dist/dev-feed.d.ts +298 -0
- package/dist/dev-feed.d.ts.map +1 -0
- package/dist/dev-feed.js +797 -0
- package/dist/dev-feed.js.map +1 -0
- package/dist/dev-indicator.d.ts +38 -0
- package/dist/dev-indicator.d.ts.map +1 -0
- package/dist/dev-indicator.js +93 -0
- package/dist/dev-indicator.js.map +1 -0
- package/dist/dev-session.d.ts +77 -0
- package/dist/dev-session.d.ts.map +1 -0
- package/dist/dev-session.js +580 -0
- package/dist/dev-session.js.map +1 -0
- package/dist/dev-sourcemap.d.ts +27 -0
- package/dist/dev-sourcemap.d.ts.map +1 -0
- package/dist/dev-sourcemap.js +235 -0
- package/dist/dev-sourcemap.js.map +1 -0
- package/dist/dev-ssr-graph.d.ts.map +1 -1
- package/dist/dev-ssr-graph.js +13 -5
- package/dist/dev-ssr-graph.js.map +1 -1
- package/dist/dev.d.ts +15 -2
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +69 -44
- package/dist/dev.js.map +1 -1
- package/dist/diagnostic-catalog.d.ts +35 -0
- package/dist/diagnostic-catalog.d.ts.map +1 -0
- package/dist/diagnostic-catalog.js +203 -0
- package/dist/diagnostic-catalog.js.map +1 -0
- package/dist/diagnostic-prompt.d.ts +49 -0
- package/dist/diagnostic-prompt.d.ts.map +1 -0
- package/dist/diagnostic-prompt.js +303 -0
- package/dist/diagnostic-prompt.js.map +1 -0
- package/dist/diagnostic.d.ts +17 -23
- package/dist/diagnostic.d.ts.map +1 -1
- package/dist/diagnostic.js +31 -39
- package/dist/diagnostic.js.map +1 -1
- package/dist/draft.d.ts.map +1 -1
- package/dist/draft.js +4 -1
- package/dist/draft.js.map +1 -1
- package/dist/fn.d.ts +5 -0
- package/dist/fn.d.ts.map +1 -1
- package/dist/fn.js +13 -3
- package/dist/fn.js.map +1 -1
- package/dist/fs.d.ts.map +1 -1
- package/dist/fs.js +4 -2
- package/dist/fs.js.map +1 -1
- package/dist/index.d.ts +13 -15
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -12
- package/dist/index.js.map +1 -1
- package/dist/internal/cdn/cloudflare.d.ts +48 -0
- package/dist/internal/cdn/cloudflare.d.ts.map +1 -0
- package/dist/internal/cdn/cloudflare.js +94 -0
- package/dist/internal/cdn/cloudflare.js.map +1 -0
- package/dist/internal/cdn/core.d.ts +91 -0
- package/dist/internal/cdn/core.d.ts.map +1 -0
- package/dist/internal/cdn/core.js +220 -0
- package/dist/internal/cdn/core.js.map +1 -0
- package/dist/internal/cdn/fastly.d.ts +17 -0
- package/dist/internal/cdn/fastly.d.ts.map +1 -0
- package/dist/internal/cdn/fastly.js +43 -0
- package/dist/internal/cdn/fastly.js.map +1 -0
- package/dist/internal/cdn/vercel.d.ts +31 -0
- package/dist/internal/cdn/vercel.d.ts.map +1 -0
- package/dist/internal/cdn/vercel.js +56 -0
- package/dist/internal/cdn/vercel.js.map +1 -0
- package/dist/internal/code-unit-order.d.ts +4 -0
- package/dist/internal/code-unit-order.d.ts.map +1 -0
- package/dist/internal/code-unit-order.js +6 -0
- package/dist/internal/code-unit-order.js.map +1 -0
- package/dist/internal/codegen.d.ts.map +1 -1
- package/dist/internal/codegen.js +141 -25
- package/dist/internal/codegen.js.map +1 -1
- package/dist/internal/dev-csp.d.ts +24 -0
- package/dist/internal/dev-csp.d.ts.map +1 -0
- package/dist/internal/dev-csp.js +160 -0
- package/dist/internal/dev-csp.js.map +1 -0
- package/dist/internal/dev-reserved.d.ts +25 -0
- package/dist/internal/dev-reserved.d.ts.map +1 -0
- package/dist/internal/dev-reserved.js +39 -0
- package/dist/internal/dev-reserved.js.map +1 -0
- package/dist/internal/html-spans.d.ts +10 -0
- package/dist/internal/html-spans.d.ts.map +1 -0
- package/dist/internal/html-spans.js +46 -0
- package/dist/internal/html-spans.js.map +1 -0
- package/dist/internal/loading-runtime.d.ts +44 -0
- package/dist/internal/loading-runtime.d.ts.map +1 -0
- package/dist/internal/loading-runtime.js +206 -0
- package/dist/internal/loading-runtime.js.map +1 -0
- package/dist/internal/matches-runtime.d.ts +8 -0
- package/dist/internal/matches-runtime.d.ts.map +1 -0
- package/dist/internal/matches-runtime.js +61 -0
- package/dist/internal/matches-runtime.js.map +1 -0
- package/dist/internal/mount-shadow.d.ts +36 -0
- package/dist/internal/mount-shadow.d.ts.map +1 -0
- package/dist/internal/mount-shadow.js +65 -0
- package/dist/internal/mount-shadow.js.map +1 -0
- package/dist/internal/node-builtins.d.ts +3 -0
- package/dist/internal/node-builtins.d.ts.map +1 -0
- package/dist/internal/node-builtins.js +79 -0
- package/dist/internal/node-builtins.js.map +1 -0
- package/dist/internal/output-guard.d.ts +65 -0
- package/dist/internal/output-guard.d.ts.map +1 -0
- package/dist/internal/output-guard.js +630 -0
- package/dist/internal/output-guard.js.map +1 -0
- package/dist/internal/page-execution.d.ts +20 -8
- package/dist/internal/page-execution.d.ts.map +1 -1
- package/dist/internal/page-execution.js +571 -105
- package/dist/internal/page-execution.js.map +1 -1
- package/dist/internal/parity.d.ts +21 -0
- package/dist/internal/parity.d.ts.map +1 -1
- package/dist/internal/parity.js +104 -22
- package/dist/internal/parity.js.map +1 -1
- package/dist/internal/private-env.d.ts +12 -0
- package/dist/internal/private-env.d.ts.map +1 -0
- package/dist/internal/private-env.js +335 -0
- package/dist/internal/private-env.js.map +1 -0
- package/dist/internal/public-url.d.ts +3 -0
- package/dist/internal/public-url.d.ts.map +1 -0
- package/dist/internal/public-url.js +18 -0
- package/dist/internal/public-url.js.map +1 -0
- package/dist/internal/render-document.d.ts +25 -19
- package/dist/internal/render-document.d.ts.map +1 -1
- package/dist/internal/render-document.js +77 -61
- package/dist/internal/render-document.js.map +1 -1
- package/dist/internal/response-controls.d.ts +75 -0
- package/dist/internal/response-controls.d.ts.map +1 -0
- package/dist/internal/response-controls.js +256 -0
- package/dist/internal/response-controls.js.map +1 -0
- package/dist/internal/runtime-contract.d.ts +11 -16
- package/dist/internal/runtime-contract.d.ts.map +1 -1
- package/dist/internal/runtime-contract.js.map +1 -1
- package/dist/internal/secret-scan.d.ts +104 -0
- package/dist/internal/secret-scan.d.ts.map +1 -0
- package/dist/internal/secret-scan.js +503 -0
- package/dist/internal/secret-scan.js.map +1 -0
- package/dist/internal/server-boundary.d.ts +6 -29
- package/dist/internal/server-boundary.d.ts.map +1 -1
- package/dist/internal/server-boundary.js +6 -66
- package/dist/internal/server-boundary.js.map +1 -1
- package/dist/internal/source-map.d.ts +47 -0
- package/dist/internal/source-map.d.ts.map +1 -0
- package/dist/internal/source-map.js +225 -0
- package/dist/internal/source-map.js.map +1 -0
- package/dist/internal/target-compat.d.ts +27 -0
- package/dist/internal/target-compat.d.ts.map +1 -0
- package/dist/internal/target-compat.js +77 -0
- package/dist/internal/target-compat.js.map +1 -0
- package/dist/internal/timing-safe-equal.d.ts +6 -0
- package/dist/internal/timing-safe-equal.d.ts.map +1 -1
- package/dist/internal/timing-safe-equal.js +10 -0
- package/dist/internal/timing-safe-equal.js.map +1 -1
- package/dist/internal/vitals-runtime.d.ts +18 -0
- package/dist/internal/vitals-runtime.d.ts.map +1 -0
- package/dist/internal/vitals-runtime.js +38 -0
- package/dist/internal/vitals-runtime.js.map +1 -0
- package/dist/internal/web-app.d.ts +38 -9
- package/dist/internal/web-app.d.ts.map +1 -1
- package/dist/internal/web-app.js +199 -59
- package/dist/internal/web-app.js.map +1 -1
- package/dist/internal/zone-graph.d.ts +89 -0
- package/dist/internal/zone-graph.d.ts.map +1 -0
- package/dist/internal/zone-graph.js +492 -0
- package/dist/internal/zone-graph.js.map +1 -0
- package/dist/isr.d.ts +83 -6
- package/dist/isr.d.ts.map +1 -1
- package/dist/isr.js +263 -36
- package/dist/isr.js.map +1 -1
- package/dist/llms-txt.d.ts.map +1 -1
- package/dist/llms-txt.js +31 -6
- package/dist/llms-txt.js.map +1 -1
- package/dist/manifest.d.ts +220 -13
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +394 -9
- package/dist/manifest.js.map +1 -1
- package/dist/module-graph.d.ts +26 -5
- package/dist/module-graph.d.ts.map +1 -1
- package/dist/module-graph.js +17 -7
- package/dist/module-graph.js.map +1 -1
- package/dist/navigation.d.ts +17 -3
- package/dist/navigation.d.ts.map +1 -1
- package/dist/navigation.js +11 -5
- package/dist/navigation.js.map +1 -1
- package/dist/nonce.d.ts +47 -0
- package/dist/nonce.d.ts.map +1 -0
- package/dist/nonce.js +63 -0
- package/dist/nonce.js.map +1 -0
- package/dist/plugins/css-modules.d.ts.map +1 -1
- package/dist/plugins/css-modules.js +4 -3
- package/dist/plugins/css-modules.js.map +1 -1
- package/dist/plugins/kit.d.ts +9 -0
- package/dist/plugins/kit.d.ts.map +1 -1
- package/dist/plugins/kit.js +18 -0
- package/dist/plugins/kit.js.map +1 -1
- package/dist/plugins/svg.d.ts +22 -3
- package/dist/plugins/svg.d.ts.map +1 -1
- package/dist/plugins/svg.js +112 -1
- package/dist/plugins/svg.js.map +1 -1
- package/dist/plugins/vite-leak-guard.d.ts +107 -3
- package/dist/plugins/vite-leak-guard.d.ts.map +1 -1
- package/dist/plugins/vite-leak-guard.js +378 -17
- package/dist/plugins/vite-leak-guard.js.map +1 -1
- package/dist/plugins/vite-zone-guard.d.ts +61 -0
- package/dist/plugins/vite-zone-guard.d.ts.map +1 -0
- package/dist/plugins/vite-zone-guard.js +208 -0
- package/dist/plugins/vite-zone-guard.js.map +1 -0
- package/dist/plugins/zone-guard.d.ts +27 -0
- package/dist/plugins/zone-guard.d.ts.map +1 -0
- package/dist/plugins/zone-guard.js +80 -0
- package/dist/plugins/zone-guard.js.map +1 -0
- package/dist/prerender.d.ts +10 -0
- package/dist/prerender.d.ts.map +1 -1
- package/dist/prerender.js +35 -3
- package/dist/prerender.js.map +1 -1
- package/dist/public-dir.d.ts +9 -0
- package/dist/public-dir.d.ts.map +1 -1
- package/dist/public-dir.js +67 -9
- package/dist/public-dir.js.map +1 -1
- package/dist/pwa-manifest.d.ts +68 -0
- package/dist/pwa-manifest.d.ts.map +1 -0
- package/dist/pwa-manifest.js +178 -0
- package/dist/pwa-manifest.js.map +1 -0
- package/dist/query.js +4 -4
- package/dist/query.js.map +1 -1
- package/dist/render-seam.d.ts +42 -2
- package/dist/render-seam.d.ts.map +1 -1
- package/dist/render-seam.js +6 -0
- package/dist/render-seam.js.map +1 -1
- package/dist/route-manifest.d.ts +3 -0
- package/dist/route-manifest.d.ts.map +1 -1
- package/dist/route-manifest.js +26 -3
- package/dist/route-manifest.js.map +1 -1
- package/dist/route-types.d.ts +24 -0
- package/dist/route-types.d.ts.map +1 -0
- package/dist/route-types.js +195 -0
- package/dist/route-types.js.map +1 -0
- package/dist/router.d.ts +28 -6
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +129 -40
- package/dist/router.js.map +1 -1
- package/dist/vitals.d.ts +33 -0
- package/dist/vitals.d.ts.map +1 -0
- package/dist/vitals.js +16 -0
- package/dist/vitals.js.map +1 -0
- package/dist/vite.d.ts +16 -1
- package/dist/vite.d.ts.map +1 -1
- package/dist/vite.js +248 -43
- package/dist/vite.js.map +1 -1
- package/dist/zones.d.ts +70 -0
- package/dist/zones.d.ts.map +1 -0
- package/dist/zones.js +365 -0
- package/dist/zones.js.map +1 -0
- package/package.json +67 -14
- package/src/backend-only.ts +16 -0
- package/src/boundary.ts +18 -5
- package/src/build-plan.ts +90 -35
- package/src/build-vite.ts +77 -11
- package/src/build.ts +466 -96
- package/src/bun-dev-entry.ts +1 -1
- package/src/cdn.ts +216 -0
- package/src/client.ts +135 -36
- package/src/conformance.ts +16 -3
- package/src/csp.ts +194 -0
- package/src/dev-client.ts +349 -0
- package/src/dev-diagnostics.ts +60 -7
- package/src/dev-error.ts +49 -5
- package/src/dev-feed.ts +1140 -0
- package/src/dev-indicator.ts +113 -0
- package/src/dev-session.ts +729 -0
- package/src/dev-sourcemap.ts +281 -0
- package/src/dev-ssr-graph.ts +16 -5
- package/src/dev.ts +86 -43
- package/src/diagnostic-catalog.ts +243 -0
- package/src/diagnostic-prompt.ts +355 -0
- package/src/diagnostic.ts +63 -66
- package/src/draft.ts +4 -1
- package/src/fn.ts +19 -3
- package/src/fs.ts +13 -2
- package/src/index.ts +42 -10
- package/src/internal/cdn/cloudflare.ts +146 -0
- package/src/internal/cdn/core.ts +316 -0
- package/src/internal/cdn/fastly.ts +62 -0
- package/src/internal/cdn/vercel.ts +95 -0
- package/src/internal/code-unit-order.ts +5 -0
- package/src/internal/codegen.ts +161 -24
- package/src/internal/dev-csp.ts +176 -0
- package/src/internal/dev-reserved.ts +52 -0
- package/src/internal/html-spans.ts +50 -0
- package/src/internal/loading-runtime.ts +244 -0
- package/src/internal/matches-runtime.ts +62 -0
- package/src/internal/mount-shadow.ts +88 -0
- package/src/internal/node-builtins.ts +79 -0
- package/src/internal/output-guard.ts +701 -0
- package/src/internal/page-execution.ts +795 -185
- package/src/internal/parity.ts +150 -36
- package/src/internal/private-env.ts +334 -0
- package/src/internal/public-url.ts +22 -0
- package/src/internal/render-document.ts +114 -67
- package/src/internal/response-controls.ts +284 -0
- package/src/internal/runtime-contract.ts +10 -15
- package/src/internal/secret-scan.ts +638 -0
- package/src/internal/server-boundary.ts +6 -69
- package/src/internal/source-map.ts +256 -0
- package/src/internal/target-compat.ts +92 -0
- package/src/internal/timing-safe-equal.ts +13 -0
- package/src/internal/vitals-runtime.ts +53 -0
- package/src/internal/web-app.ts +262 -84
- package/src/internal/zone-graph.ts +593 -0
- package/src/isr.ts +325 -37
- package/src/llms-txt.ts +28 -4
- package/src/manifest.ts +682 -16
- package/src/module-graph.ts +53 -9
- package/src/navigation.ts +29 -6
- package/src/nonce.ts +104 -0
- package/src/plugins/css-modules.ts +5 -3
- package/src/plugins/kit.ts +24 -0
- package/src/plugins/svg.ts +135 -4
- package/src/plugins/vite-leak-guard.ts +529 -16
- package/src/plugins/vite-zone-guard.ts +263 -0
- package/src/plugins/zone-guard.ts +119 -0
- package/src/prerender.ts +49 -3
- package/src/public-dir.ts +69 -8
- package/src/pwa-manifest.ts +226 -0
- package/src/query.ts +4 -4
- package/src/render-seam.ts +46 -1
- package/src/route-manifest.ts +15 -3
- package/src/route-types.ts +264 -0
- package/src/router.ts +163 -63
- package/src/vitals.ts +44 -0
- package/src/vite.ts +257 -42
- package/src/zones.ts +430 -0
- package/dist/plugins/vite-server-only.d.ts +0 -49
- package/dist/plugins/vite-server-only.d.ts.map +0 -1
- package/dist/plugins/vite-server-only.js +0 -57
- package/dist/plugins/vite-server-only.js.map +0 -1
- package/dist/server-only.d.ts +0 -21
- package/dist/server-only.d.ts.map +0 -1
- package/dist/server-only.js +0 -25
- package/dist/server-only.js.map +0 -1
- package/src/plugins/vite-server-only.ts +0 -75
- package/src/server-only.ts +0 -25
package/dist/isr.d.ts
CHANGED
|
@@ -28,8 +28,29 @@ export interface CacheStore {
|
|
|
28
28
|
/** Drop every cached response carrying `tag`, when the backend supports tag invalidation. */
|
|
29
29
|
readonly invalidateTag?: (tag: string) => Promise<void>;
|
|
30
30
|
}
|
|
31
|
+
export declare function normalizeTags(tags: readonly string[] | undefined): readonly string[];
|
|
32
|
+
/** The route tags a response carries on {@link ISR_REVALIDATE_TAGS_HEADER}; malformed means none. */
|
|
33
|
+
export declare function tagsFromHeader(value: string | null): readonly string[];
|
|
31
34
|
/** Validate and serialize route-declared ISR tags for the internal response header. */
|
|
32
35
|
export declare function serializeISRTags(tags: readonly string[]): string | undefined;
|
|
36
|
+
/** What a `revalidateTags` function is given: the URL and route params only, both already public. */
|
|
37
|
+
export interface RevalidateTagsInput {
|
|
38
|
+
readonly params: Readonly<Record<string, string>>;
|
|
39
|
+
readonly url: URL;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* A route's `revalidateTags`: a fixed list, or one computed per request from its params and URL. The
|
|
43
|
+
* function is declared as a method so a route may annotate its own params (`{ params: { id: string } }`).
|
|
44
|
+
*/
|
|
45
|
+
export type RevalidateTags = readonly string[] | {
|
|
46
|
+
tags(input: RevalidateTagsInput): readonly string[];
|
|
47
|
+
}["tags"];
|
|
48
|
+
/**
|
|
49
|
+
* The tags `declared` gives this request. A fixed list is returned as declared (it is validated when
|
|
50
|
+
* the header is written). A function's result keeps its valid, distinct tags, at most 32; anything
|
|
51
|
+
* else is dropped with one warning per route, naming the route but never the tag.
|
|
52
|
+
*/
|
|
53
|
+
export declare function routeTags(declared: RevalidateTags, input: RevalidateTagsInput, routeId: string): readonly string[];
|
|
33
54
|
export interface MemoryCacheStoreOptions {
|
|
34
55
|
/** Allow the in-memory store in production. Off by default - per-instance caching means revalidation
|
|
35
56
|
* won't propagate across instances and each instance caches separately. */
|
|
@@ -132,6 +153,13 @@ export declare const ISR_REVALIDATE_TAGS_HEADER = "x-nifra-isr-tags";
|
|
|
132
153
|
* refetch): this one is an integer TTL the *wrapper* reads, so the two channels never alias.
|
|
133
154
|
*/
|
|
134
155
|
export declare const ISR_REVALIDATE_HEADER = "x-nifra-isr-revalidate";
|
|
156
|
+
/** A `createWebApp` app answers this with a function that turns its ISR headers on. A wrapper that
|
|
157
|
+
* reads them calls it, so an app nothing caches never sends a route's freshness or tags. */
|
|
158
|
+
export declare const CACHE_CHANNEL: unique symbol;
|
|
159
|
+
/** Ask `app` to emit its ISR headers; an app without the channel emits whatever it emits. */
|
|
160
|
+
export declare function openCacheChannel(app: object): void;
|
|
161
|
+
/** Drop the ISR headers from a response that leaves the cache layer. */
|
|
162
|
+
export declare function withoutCacheChannel(res: Response): Response;
|
|
135
163
|
export interface ISROptions {
|
|
136
164
|
readonly store: CacheStore;
|
|
137
165
|
/** Default freshness window (**seconds**) for a cached page; older ⇒ stale (served, regenerated
|
|
@@ -140,15 +168,35 @@ export interface ISROptions {
|
|
|
140
168
|
readonly revalidate: number;
|
|
141
169
|
/** Monotonic clock (ms) - injected for testability; production passes `() => Date.now()`. */
|
|
142
170
|
readonly now: () => number;
|
|
143
|
-
/** Cache key for a request. Default: `origin + pathname
|
|
144
|
-
* entries across tenants. Return `null` to bypass the cache for
|
|
145
|
-
* app, uncached). */
|
|
171
|
+
/** Cache key for a request. Default: `origin + pathname`, plus the query parameters `query` admits,
|
|
172
|
+
* so host-routed apps do not share entries across tenants. Return `null` to bypass the cache for
|
|
173
|
+
* this request (it goes straight to the app, uncached). Replaces `query` entirely. */
|
|
146
174
|
readonly key?: (req: Request) => string | null;
|
|
175
|
+
/**
|
|
176
|
+
* How the query string reaches the default key. Default `"bypass"`: a request carrying any query
|
|
177
|
+
* parameter skips the cache - rendered fresh, never stored - so `?a=1`, `?a=2`, ... cannot each
|
|
178
|
+
* store a full page. A list caches by those parameters only, in any order (`?b=2&a=1` and
|
|
179
|
+
* `?a=1&b=2` share an entry); a request carrying any other parameter still bypasses, because a
|
|
180
|
+
* loader that reads it would otherwise be served another request's page. `"all"` keys on the whole
|
|
181
|
+
* query string, so every distinct query is a new entry.
|
|
182
|
+
*/
|
|
183
|
+
readonly query?: ISRQuery;
|
|
147
184
|
/** Draft/preview secret (the same one given to `createWebApp({ draftSecret })` + `enableDraft`). When
|
|
148
185
|
* set, a request carrying a valid signed draft cookie **bypasses the cache** - editors always render
|
|
149
186
|
* fresh, and a draft render is never written to the store (it can't poison the public cache). */
|
|
150
187
|
readonly draftSecret?: string;
|
|
151
188
|
}
|
|
189
|
+
/** Which query parameters an ISR key carries - see {@link ISROptions.query}. */
|
|
190
|
+
export type ISRQuery = "bypass" | "all" | readonly string[];
|
|
191
|
+
/** The default key for a URL under a `query` policy, or `null` when the URL must bypass the cache. */
|
|
192
|
+
export declare const urlKeyOf: (query?: ISRQuery) => ((url: URL) => string | null);
|
|
193
|
+
/**
|
|
194
|
+
* Whether `res` may be stored by a shared cache and served to anyone requesting `req`'s URL: a
|
|
195
|
+
* full-document `GET` 200 `text/html` with no Set-Cookie, no `private`/`no-store`, no `Vary` beyond
|
|
196
|
+
* the data header, and, for a request carrying a cookie or Authorization, an explicit `public`.
|
|
197
|
+
* The one rule both `withISR` and `@nifrajs/web/cdn` cache by.
|
|
198
|
+
*/
|
|
199
|
+
export declare const isCacheablePage: (req: Request, res: Response) => boolean;
|
|
152
200
|
/**
|
|
153
201
|
* Wrap a nifra app with **Incremental Static Regeneration**: a cacheable page is served from
|
|
154
202
|
* {@link CacheStore} when fresh, served **stale while a fresh copy regenerates in the background**
|
|
@@ -161,6 +209,24 @@ export interface ISROptions {
|
|
|
161
209
|
* GET 200s are cached; everything else (assets, data-mode GETs, redirects, errors) passes through.
|
|
162
210
|
*/
|
|
163
211
|
export declare function withISR(app: ISRApp, options: ISROptions): (req: Request, platform?: ISRPlatform) => Promise<Response>;
|
|
212
|
+
/** What a CDN purge came to: sent and accepted, queued behind a rate limit or retry, or refused. */
|
|
213
|
+
export interface CdnPurgeOutcome {
|
|
214
|
+
readonly cdn: "accepted" | "queued" | "failed";
|
|
215
|
+
/** Whether the same purge may succeed if sent again. */
|
|
216
|
+
readonly retryable: boolean;
|
|
217
|
+
/** A short reason when it did not succeed (never the provider's credentials). */
|
|
218
|
+
readonly error?: string;
|
|
219
|
+
}
|
|
220
|
+
/** A CDN a revalidation purges after the origin store; every `@nifrajs/web/cdn` provider is one. */
|
|
221
|
+
export interface CdnPurgeTarget {
|
|
222
|
+
purge(target: {
|
|
223
|
+
readonly tags?: readonly string[];
|
|
224
|
+
readonly paths?: readonly string[];
|
|
225
|
+
}, platform?: ISRPlatform): Promise<CdnPurgeOutcome>;
|
|
226
|
+
}
|
|
227
|
+
/** Most paths and tags one revalidation request may name, so a leaked token cannot fan out. */
|
|
228
|
+
export declare const MAX_REVALIDATE_PATHS = 100;
|
|
229
|
+
export declare const MAX_REVALIDATE_TAGS = 32;
|
|
164
230
|
export interface RevalidateEndpointOptions {
|
|
165
231
|
readonly store: CacheStore;
|
|
166
232
|
/** Shared secret; the request's token must match it (constant-time). */
|
|
@@ -170,14 +236,25 @@ export interface RevalidateEndpointOptions {
|
|
|
170
236
|
/** Map a to-purge path → its cache key - MUST match the `withISR` `key` fn. The default uses the
|
|
171
237
|
* revalidation request's origin plus the purged path, matching `withISR`'s default host-aware key. */
|
|
172
238
|
readonly key?: (path: string, req: Request) => string;
|
|
239
|
+
/** The `query` policy given to `withISR`, so a purged path's query string is keyed the same way.
|
|
240
|
+
* Default `"bypass"`. A path whose query `withISR` never caches is refused with `400`. Ignored
|
|
241
|
+
* when `key` is supplied. */
|
|
242
|
+
readonly query?: ISRQuery;
|
|
243
|
+
/**
|
|
244
|
+
* A CDN to purge after the origin store (a `@nifrajs/web/cdn` provider). The origin goes first so a
|
|
245
|
+
* CDN refetch cannot repopulate from a stale origin entry. The reply is `200` when the CDN accepted
|
|
246
|
+
* the purge, `202` when it is queued (rate limit or retry), and `502` when the CDN refused it.
|
|
247
|
+
*/
|
|
248
|
+
readonly cdn?: CdnPurgeTarget;
|
|
173
249
|
}
|
|
174
250
|
/**
|
|
175
|
-
* An **on-demand revalidation** (purge) endpoint - a `fetch` handler that drops
|
|
251
|
+
* An **on-demand revalidation** (purge) endpoint - a `fetch` handler that drops cached pages by path
|
|
176
252
|
* or invalidates every entry carrying a tag. `POST` with the secret in the token header and either
|
|
177
|
-
* `?path=/blog/x`, `?tag=products`,
|
|
253
|
+
* `?path=/blog/x`, `?tag=products`, a JSON `{ "path": "/blog/x" }` / `{ "tag": "products" }` body, or a
|
|
254
|
+
* batch `{ "paths": [...], "tags": [...] }` of at most 100 paths and 32 tags.
|
|
178
255
|
* The token is checked in **constant time** (wrong/missing → `401`); malformed targets → `400`;
|
|
179
256
|
* non-POST → `405`. A store without tag support returns `501` for tag requests. Mount it on a nifra route, e.g.
|
|
180
257
|
* `app.post("/__nifra/revalidate", (c) => handler(c.req))`.
|
|
181
258
|
*/
|
|
182
|
-
export declare function revalidateEndpoint(options: RevalidateEndpointOptions): (req: Request) => Promise<Response>;
|
|
259
|
+
export declare function revalidateEndpoint(options: RevalidateEndpointOptions): (req: Request, platform?: ISRPlatform) => Promise<Response>;
|
|
183
260
|
//# sourceMappingURL=isr.d.ts.map
|
package/dist/isr.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isr.d.ts","sourceRoot":"","sources":["../src/isr.ts"],"names":[],"mappings":"AAWA,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,wDAAwD;IACxD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IAClD,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;IACzB,sGAAsG;IACtG,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,gGAAgG;IAChG,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAClC;AAED;;;;;GAKG;AACH,MAAM,WAAW,UAAU;IACzB,4DAA4D;IAC5D,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,GAAG,SAAS,CAAC,CAAA;IACrD,gDAAgD;IAChD,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACtD,sEAAsE;IACtE,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAClC,6FAA6F;IAC7F,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CACxD;
|
|
1
|
+
{"version":3,"file":"isr.d.ts","sourceRoot":"","sources":["../src/isr.ts"],"names":[],"mappings":"AAWA,kFAAkF;AAClF,MAAM,WAAW,cAAc;IAC7B,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,wDAAwD;IACx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B,GACjC,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CA+F7D"}
|
package/dist/isr.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* This module is the store primitive; the SWR wrapper (`withISR`) builds on it next.
|
|
8
8
|
*/
|
|
9
9
|
import { isDraftEnabled } from "./draft.js";
|
|
10
|
-
import { timingSafeEqual } from "./internal/timing-safe-equal.js";
|
|
10
|
+
import { assertTokenSecret, timingSafeEqual } from "./internal/timing-safe-equal.js";
|
|
11
11
|
const ISR_TAG_PATTERN = /^[A-Za-z][A-Za-z0-9._:/-]{0,127}$/;
|
|
12
12
|
const MAX_ISR_TAGS = 32;
|
|
13
13
|
function normalizeTag(tag) {
|
|
@@ -16,7 +16,7 @@ function normalizeTag(tag) {
|
|
|
16
16
|
}
|
|
17
17
|
return tag;
|
|
18
18
|
}
|
|
19
|
-
function normalizeTags(tags) {
|
|
19
|
+
export function normalizeTags(tags) {
|
|
20
20
|
if (tags === undefined)
|
|
21
21
|
return [];
|
|
22
22
|
if (!Array.isArray(tags) || tags.length > MAX_ISR_TAGS) {
|
|
@@ -27,7 +27,8 @@ function normalizeTags(tags) {
|
|
|
27
27
|
unique.add(normalizeTag(tag));
|
|
28
28
|
return Object.freeze([...unique]);
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
/** The route tags a response carries on {@link ISR_REVALIDATE_TAGS_HEADER}; malformed means none. */
|
|
31
|
+
export function tagsFromHeader(value) {
|
|
31
32
|
if (value === null || value.trim() === "")
|
|
32
33
|
return [];
|
|
33
34
|
try {
|
|
@@ -44,6 +45,32 @@ export function serializeISRTags(tags) {
|
|
|
44
45
|
const normalized = normalizeTags(tags);
|
|
45
46
|
return normalized.length === 0 ? undefined : normalized.join(",");
|
|
46
47
|
}
|
|
48
|
+
const warnedTagRoutes = new Set();
|
|
49
|
+
/**
|
|
50
|
+
* The tags `declared` gives this request. A fixed list is returned as declared (it is validated when
|
|
51
|
+
* the header is written). A function's result keeps its valid, distinct tags, at most 32; anything
|
|
52
|
+
* else is dropped with one warning per route, naming the route but never the tag.
|
|
53
|
+
*/
|
|
54
|
+
export function routeTags(declared, input, routeId) {
|
|
55
|
+
if (typeof declared !== "function")
|
|
56
|
+
return declared;
|
|
57
|
+
const result = declared(input);
|
|
58
|
+
const listed = Array.isArray(result) ? result : [];
|
|
59
|
+
const kept = new Set();
|
|
60
|
+
let dropped = 0;
|
|
61
|
+
for (const tag of listed) {
|
|
62
|
+
if (typeof tag === "string" && ISR_TAG_PATTERN.test(tag) && kept.size < MAX_ISR_TAGS) {
|
|
63
|
+
kept.add(tag);
|
|
64
|
+
}
|
|
65
|
+
else
|
|
66
|
+
dropped++;
|
|
67
|
+
}
|
|
68
|
+
if ((dropped > 0 || !Array.isArray(result)) && !warnedTagRoutes.has(routeId)) {
|
|
69
|
+
warnedTagRoutes.add(routeId);
|
|
70
|
+
console.warn(`[nifra/web] NIFRA_CDN_TAG_INVALID: revalidateTags of route "${routeId}" returned ${Array.isArray(result) ? `${dropped} tag(s) that are not a letter followed by up to 127 of A-Z a-z 0-9 . _ : / -, or past the first 32` : "something other than an array"}; those were dropped.`);
|
|
71
|
+
}
|
|
72
|
+
return [...kept];
|
|
73
|
+
}
|
|
47
74
|
/**
|
|
48
75
|
* In-process ISR cache. Refuses to run in production unless explicitly allowed (mirrors the
|
|
49
76
|
* rate-limit `MemoryStore` - a per-instance cache is unsafe across instances). Bounded **LRU**: a
|
|
@@ -269,10 +296,68 @@ export const ISR_REVALIDATE_TAGS_HEADER = "x-nifra-isr-tags";
|
|
|
269
296
|
* refetch): this one is an integer TTL the *wrapper* reads, so the two channels never alias.
|
|
270
297
|
*/
|
|
271
298
|
export const ISR_REVALIDATE_HEADER = "x-nifra-isr-revalidate";
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
299
|
+
/** A `createWebApp` app answers this with a function that turns its ISR headers on. A wrapper that
|
|
300
|
+
* reads them calls it, so an app nothing caches never sends a route's freshness or tags. */
|
|
301
|
+
export const CACHE_CHANNEL = Symbol.for("nifra.web.cacheChannel");
|
|
302
|
+
/** Ask `app` to emit its ISR headers; an app without the channel emits whatever it emits. */
|
|
303
|
+
export function openCacheChannel(app) {
|
|
304
|
+
const open = Reflect.get(app, CACHE_CHANNEL);
|
|
305
|
+
if (typeof open === "function")
|
|
306
|
+
open();
|
|
307
|
+
}
|
|
308
|
+
/** Drop the ISR headers from a response that leaves the cache layer. */
|
|
309
|
+
export function withoutCacheChannel(res) {
|
|
310
|
+
if (!res.headers.has(ISR_REVALIDATE_HEADER) && !res.headers.has(ISR_REVALIDATE_TAGS_HEADER)) {
|
|
311
|
+
return res;
|
|
312
|
+
}
|
|
313
|
+
try {
|
|
314
|
+
res.headers.delete(ISR_REVALIDATE_HEADER);
|
|
315
|
+
res.headers.delete(ISR_REVALIDATE_TAGS_HEADER);
|
|
316
|
+
return res;
|
|
317
|
+
}
|
|
318
|
+
catch {
|
|
319
|
+
// A `fetch()` response has immutable headers: rebuild it around the same body instead.
|
|
320
|
+
const headers = new Headers(res.headers);
|
|
321
|
+
headers.delete(ISR_REVALIDATE_HEADER);
|
|
322
|
+
headers.delete(ISR_REVALIDATE_TAGS_HEADER);
|
|
323
|
+
return new Response(res.body, { status: res.status, statusText: res.statusText, headers });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/** `createWebApp`'s marker for how its documents meet a CSP (see `DOCUMENT_POLICY` in ./csp.ts). Read
|
|
327
|
+
* through the global symbol registry so a cache wrapper never imports the CSP module. */
|
|
328
|
+
const DOCUMENT_POLICY = Symbol.for("nifra.web.documentPolicy");
|
|
329
|
+
/** Remembered `no-store` keys per `withISR` wrapper. */
|
|
330
|
+
const MAX_UNCACHEABLE_KEYS = 1024;
|
|
331
|
+
/** The default key for a URL under a `query` policy, or `null` when the URL must bypass the cache. */
|
|
332
|
+
export const urlKeyOf = (query = "bypass") => {
|
|
333
|
+
if (query === "all")
|
|
334
|
+
return (url) => url.origin + url.pathname + url.search;
|
|
335
|
+
if (query !== "bypass" && !Array.isArray(query)) {
|
|
336
|
+
throw new TypeError('[nifra/web] ISR query must be "bypass", "all", or a list of parameter names');
|
|
337
|
+
}
|
|
338
|
+
const allowed = new Set(query === "bypass" ? [] : query);
|
|
339
|
+
for (const name of allowed) {
|
|
340
|
+
if (typeof name !== "string" || name === "") {
|
|
341
|
+
throw new TypeError("[nifra/web] ISR query parameter names must be non-empty strings");
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return (url) => {
|
|
345
|
+
if (url.search === "")
|
|
346
|
+
return url.origin + url.pathname;
|
|
347
|
+
if (allowed.size === 0)
|
|
348
|
+
return null;
|
|
349
|
+
const entries = [];
|
|
350
|
+
for (const entry of url.searchParams) {
|
|
351
|
+
if (!allowed.has(entry[0]))
|
|
352
|
+
return null;
|
|
353
|
+
entries.push(entry);
|
|
354
|
+
}
|
|
355
|
+
// Stable by name, so a repeated name keeps its value order (`getAll` can tell them apart).
|
|
356
|
+
entries.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
357
|
+
return `${url.origin}${url.pathname}?${new URLSearchParams(entries)}`;
|
|
358
|
+
};
|
|
275
359
|
};
|
|
360
|
+
const requestKeyOf = (urlKey) => (req) => urlKey(new URL(req.url));
|
|
276
361
|
function assertRevalidate(value, name) {
|
|
277
362
|
if (!Number.isFinite(value) || value < 0) {
|
|
278
363
|
throw new RangeError(`[nifra/web] ${name} must be a finite non-negative number`);
|
|
@@ -293,11 +378,26 @@ const cacheControlHas = (headers, names) => {
|
|
|
293
378
|
const hasSetCookie = (headers) => headers.has("set-cookie") || (headers.getSetCookie?.().length ?? 0) > 0;
|
|
294
379
|
const requestCarriesPrivateState = (req) => req.headers.has("authorization") || req.headers.has("cookie");
|
|
295
380
|
const responseIsExplicitlyPublic = (res) => cacheControlHas(res.headers, ["public"]);
|
|
381
|
+
// `x-nifra-data` alone is not a variation the URL key misses: a navigation data request never reads
|
|
382
|
+
// or writes the store, so every stored entry is the document.
|
|
296
383
|
const responseDeclaresVary = (res) => {
|
|
297
384
|
const value = res.headers.get("vary");
|
|
298
|
-
|
|
385
|
+
if (value === null)
|
|
386
|
+
return false;
|
|
387
|
+
for (const part of value.split(",")) {
|
|
388
|
+
const name = part.trim().toLowerCase();
|
|
389
|
+
if (name !== "" && name !== "x-nifra-data")
|
|
390
|
+
return true;
|
|
391
|
+
}
|
|
392
|
+
return false;
|
|
299
393
|
};
|
|
300
|
-
|
|
394
|
+
/**
|
|
395
|
+
* Whether `res` may be stored by a shared cache and served to anyone requesting `req`'s URL: a
|
|
396
|
+
* full-document `GET` 200 `text/html` with no Set-Cookie, no `private`/`no-store`, no `Vary` beyond
|
|
397
|
+
* the data header, and, for a request carrying a cookie or Authorization, an explicit `public`.
|
|
398
|
+
* The one rule both `withISR` and `@nifrajs/web/cdn` cache by.
|
|
399
|
+
*/
|
|
400
|
+
export const isCacheablePage = (req, res) => {
|
|
301
401
|
if (req.method !== "GET")
|
|
302
402
|
return false;
|
|
303
403
|
if (req.headers.get("x-nifra-data") !== null)
|
|
@@ -341,6 +441,7 @@ const CACHEABLE_RESPONSE_HEADERS = new Set([
|
|
|
341
441
|
"vary",
|
|
342
442
|
"x-content-type-options",
|
|
343
443
|
"x-frame-options",
|
|
444
|
+
"x-robots-tag",
|
|
344
445
|
]);
|
|
345
446
|
const isCacheableResponseHeader = (key) => {
|
|
346
447
|
const normalized = key.toLowerCase();
|
|
@@ -385,9 +486,44 @@ const isInvalidationResponse = (res) => res.status === 404 || res.status === 410
|
|
|
385
486
|
export function withISR(app, options) {
|
|
386
487
|
const { store, now } = options;
|
|
387
488
|
assertRevalidate(options.revalidate, "revalidate");
|
|
388
|
-
const keyOf = options.key ??
|
|
489
|
+
const keyOf = options.key ?? requestKeyOf(urlKeyOf(options.query));
|
|
389
490
|
const draftSecret = options.draftSecret;
|
|
390
491
|
const regenerating = new Set();
|
|
492
|
+
openCacheChannel(app);
|
|
493
|
+
// An outer cache layer (`withCdn`) opens this wrapper's own channel: cached responses then carry how
|
|
494
|
+
// much freshness they have left and their tags, so the CDN never holds a page longer than ISR would.
|
|
495
|
+
let channelOpen = false;
|
|
496
|
+
const advertise = (headers, remainingMs, tags) => {
|
|
497
|
+
if (!channelOpen)
|
|
498
|
+
return;
|
|
499
|
+
headers.set(ISR_REVALIDATE_HEADER, String(Math.max(0, Math.floor(remainingMs / 1000))));
|
|
500
|
+
const serialized = tags.length === 0 ? undefined : tags.join(",");
|
|
501
|
+
if (serialized !== undefined)
|
|
502
|
+
headers.set(ISR_REVALIDATE_TAGS_HEADER, serialized);
|
|
503
|
+
};
|
|
504
|
+
const served = (entry, status) => {
|
|
505
|
+
const res = responseFrom(entry, status);
|
|
506
|
+
advertise(res.headers, status === "stale" ? 0 : entry.revalidate - (now() - entry.storedAt), entry.tags ?? []);
|
|
507
|
+
return res;
|
|
508
|
+
};
|
|
509
|
+
if (app[DOCUMENT_POLICY] === "nonce") {
|
|
510
|
+
console.warn("[nifra/web] withISR wraps an app whose every document carries a CSP nonce. Such documents are " +
|
|
511
|
+
"`private, no-store`, so this cache will never store a page. Use " +
|
|
512
|
+
"`createWebApp({ csp: createCspPolicy(...) })` instead of `nonce` to cache pages under a CSP.");
|
|
513
|
+
}
|
|
514
|
+
// Keys whose last render declared itself `private` or `no-store`, with when that memo expires. A
|
|
515
|
+
// remembered key skips the store lookup (a network round trip on a shared store) and renders fresh;
|
|
516
|
+
// a render that turns out cacheable is stored and forgets the key. So the memo can only cost a cache
|
|
517
|
+
// hit, never serve the wrong page. Bounded, oldest first, so a URL flood cannot grow it.
|
|
518
|
+
const uncacheable = new Map();
|
|
519
|
+
const rememberUncacheable = (key, res) => {
|
|
520
|
+
if (options.revalidate === 0 || !cacheControlHas(res.headers, ["private", "no-store"]))
|
|
521
|
+
return;
|
|
522
|
+
if (uncacheable.size >= MAX_UNCACHEABLE_KEYS) {
|
|
523
|
+
uncacheable.delete(uncacheable.keys().next().value);
|
|
524
|
+
}
|
|
525
|
+
uncacheable.set(key, now() + options.revalidate * 1000);
|
|
526
|
+
};
|
|
391
527
|
// Per-page TTL (ms): the app's `x-nifra-isr-revalidate` header (seconds) if present, else the default.
|
|
392
528
|
const ttlMs = (res) => {
|
|
393
529
|
const header = res.headers.get(ISR_REVALIDATE_HEADER);
|
|
@@ -397,8 +533,11 @@ export function withISR(app, options) {
|
|
|
397
533
|
};
|
|
398
534
|
const render = async (req, platform, key) => {
|
|
399
535
|
const res = await app.fetch(req, platform);
|
|
400
|
-
if (!isCacheablePage(req, res))
|
|
401
|
-
|
|
536
|
+
if (!isCacheablePage(req, res)) {
|
|
537
|
+
rememberUncacheable(key, res);
|
|
538
|
+
return withoutCacheChannel(res);
|
|
539
|
+
}
|
|
540
|
+
uncacheable.delete(key);
|
|
402
541
|
const body = await res.text();
|
|
403
542
|
const tags = tagsOf(res);
|
|
404
543
|
const entry = {
|
|
@@ -410,10 +549,12 @@ export function withISR(app, options) {
|
|
|
410
549
|
...(tags.length === 0 ? {} : { tags }),
|
|
411
550
|
};
|
|
412
551
|
await store.set(key, entry);
|
|
413
|
-
|
|
552
|
+
const fresh = new Response(body, {
|
|
414
553
|
status: res.status,
|
|
415
554
|
headers: { ...entry.headers, [ISR_STATUS_HEADER]: "miss" },
|
|
416
555
|
});
|
|
556
|
+
advertise(fresh.headers, entry.revalidate, tags);
|
|
557
|
+
return fresh;
|
|
417
558
|
};
|
|
418
559
|
// Background regeneration (single-flight per key) - a failed regen keeps the stale entry; the next
|
|
419
560
|
// stale hit retries. Never throws (it runs detached / under waitUntil).
|
|
@@ -451,46 +592,75 @@ export function withISR(app, options) {
|
|
|
451
592
|
regenerating.delete(key);
|
|
452
593
|
}
|
|
453
594
|
};
|
|
454
|
-
|
|
595
|
+
const handler = async (req, platform) => {
|
|
455
596
|
// A data-mode soft-nav GET bypasses the cache entirely: entries are full HTML documents keyed
|
|
456
597
|
// by URL, and serving one to a loader-data fetch would hand the client HTML where it expects
|
|
457
598
|
// the loader payload. (The write path already refuses to cache data-mode responses.)
|
|
458
599
|
const key = req.method === "GET" && req.headers.get("x-nifra-data") === null ? keyOf(req) : null;
|
|
459
600
|
if (key === null)
|
|
460
|
-
return app.fetch(req, platform);
|
|
601
|
+
return withoutCacheChannel(await app.fetch(req, platform));
|
|
461
602
|
// Draft/preview: an editor (valid signed cookie) always renders fresh and is never cached, so
|
|
462
603
|
// unpublished content can't leak into the public cache (and the editor isn't served a stale page).
|
|
463
604
|
if (draftSecret !== undefined && (await isDraftEnabled(req, draftSecret))) {
|
|
464
|
-
return app.fetch(req, platform);
|
|
605
|
+
return withoutCacheChannel(await app.fetch(req, platform));
|
|
606
|
+
}
|
|
607
|
+
const until = uncacheable.get(key);
|
|
608
|
+
if (until !== undefined) {
|
|
609
|
+
if (now() < until)
|
|
610
|
+
return render(req, platform, key);
|
|
611
|
+
uncacheable.delete(key);
|
|
465
612
|
}
|
|
466
613
|
const hit = await store.get(key);
|
|
467
614
|
if (hit !== undefined) {
|
|
468
615
|
if (now() - hit.storedAt < hit.revalidate)
|
|
469
|
-
return
|
|
616
|
+
return served(hit, "hit");
|
|
470
617
|
// Stale: serve it now, regenerate behind it (waitUntil keeps the edge worker alive for the regen).
|
|
471
618
|
const task = regenerate(req, platform, key);
|
|
472
619
|
if (typeof platform?.waitUntil === "function")
|
|
473
620
|
platform.waitUntil(task);
|
|
474
621
|
else
|
|
475
622
|
void task.catch(() => { });
|
|
476
|
-
return
|
|
623
|
+
return served(hit, "stale");
|
|
477
624
|
}
|
|
478
625
|
return render(req, platform, key);
|
|
479
626
|
};
|
|
627
|
+
Object.defineProperty(handler, CACHE_CHANNEL, {
|
|
628
|
+
value: () => {
|
|
629
|
+
channelOpen = true;
|
|
630
|
+
},
|
|
631
|
+
});
|
|
632
|
+
return handler;
|
|
480
633
|
}
|
|
481
634
|
const jsonError = (status, error) => Response.json({ ok: false, error }, { status });
|
|
635
|
+
/** Most paths and tags one revalidation request may name, so a leaked token cannot fan out. */
|
|
636
|
+
export const MAX_REVALIDATE_PATHS = 100;
|
|
637
|
+
export const MAX_REVALIDATE_TAGS = MAX_ISR_TAGS;
|
|
638
|
+
const stringList = (value) => {
|
|
639
|
+
if (value === undefined)
|
|
640
|
+
return undefined;
|
|
641
|
+
if (!Array.isArray(value) || !value.every((item) => typeof item === "string"))
|
|
642
|
+
return null;
|
|
643
|
+
return value;
|
|
644
|
+
};
|
|
482
645
|
/**
|
|
483
|
-
* An **on-demand revalidation** (purge) endpoint - a `fetch` handler that drops
|
|
646
|
+
* An **on-demand revalidation** (purge) endpoint - a `fetch` handler that drops cached pages by path
|
|
484
647
|
* or invalidates every entry carrying a tag. `POST` with the secret in the token header and either
|
|
485
|
-
* `?path=/blog/x`, `?tag=products`,
|
|
648
|
+
* `?path=/blog/x`, `?tag=products`, a JSON `{ "path": "/blog/x" }` / `{ "tag": "products" }` body, or a
|
|
649
|
+
* batch `{ "paths": [...], "tags": [...] }` of at most 100 paths and 32 tags.
|
|
486
650
|
* The token is checked in **constant time** (wrong/missing → `401`); malformed targets → `400`;
|
|
487
651
|
* non-POST → `405`. A store without tag support returns `501` for tag requests. Mount it on a nifra route, e.g.
|
|
488
652
|
* `app.post("/__nifra/revalidate", (c) => handler(c.req))`.
|
|
489
653
|
*/
|
|
490
654
|
export function revalidateEndpoint(options) {
|
|
655
|
+
// An empty secret matches a request that omits the header (`"" === ""`), so an unset env var passed
|
|
656
|
+
// through `?? ""` would open the purge to anyone. Refuse it at construction instead.
|
|
657
|
+
assertTokenSecret(options.secret, "revalidateEndpoint");
|
|
491
658
|
const tokenHeader = options.tokenHeader ?? "x-nifra-revalidate-token";
|
|
492
|
-
const
|
|
493
|
-
|
|
659
|
+
const urlKey = options.key === undefined ? urlKeyOf(options.query) : undefined;
|
|
660
|
+
// Joined as text, never resolved against the origin: `//host/x` must stay a path on this origin.
|
|
661
|
+
const keyOf = options.key ??
|
|
662
|
+
((path, req) => urlKey?.(new URL(new URL(req.url).origin + path)) ?? null);
|
|
663
|
+
return async (req, platform) => {
|
|
494
664
|
if (req.method !== "POST")
|
|
495
665
|
return jsonError(405, "method_not_allowed");
|
|
496
666
|
if (!timingSafeEqual(req.headers.get(tokenHeader) ?? "", options.secret)) {
|
|
@@ -499,33 +669,90 @@ export function revalidateEndpoint(options) {
|
|
|
499
669
|
const url = new URL(req.url);
|
|
500
670
|
let path = url.searchParams.get("path");
|
|
501
671
|
let tag = url.searchParams.get("tag");
|
|
672
|
+
let batch;
|
|
502
673
|
if (path === null && tag === null) {
|
|
503
674
|
const body = await req.json().catch(() => null);
|
|
504
675
|
if (typeof body === "object" && body !== null) {
|
|
505
676
|
const candidate = body;
|
|
506
|
-
|
|
507
|
-
|
|
677
|
+
if (candidate.paths !== undefined || candidate.tags !== undefined) {
|
|
678
|
+
const paths = stringList(candidate.paths);
|
|
679
|
+
const tags = stringList(candidate.tags);
|
|
680
|
+
if (paths === null || tags === null)
|
|
681
|
+
return jsonError(400, "invalid_batch");
|
|
682
|
+
if ((paths?.length ?? 0) > MAX_REVALIDATE_PATHS)
|
|
683
|
+
return jsonError(400, "too_many_paths");
|
|
684
|
+
if ((tags?.length ?? 0) > MAX_REVALIDATE_TAGS)
|
|
685
|
+
return jsonError(400, "too_many_tags");
|
|
686
|
+
batch = { paths: paths ?? [], tags: tags ?? [] };
|
|
687
|
+
if (batch.paths.length + batch.tags.length === 0)
|
|
688
|
+
return jsonError(400, "empty_batch");
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
path = typeof candidate.path === "string" ? candidate.path : null;
|
|
692
|
+
tag = typeof candidate.tag === "string" ? candidate.tag : null;
|
|
693
|
+
}
|
|
508
694
|
}
|
|
509
695
|
}
|
|
510
|
-
if (
|
|
511
|
-
|
|
512
|
-
|
|
696
|
+
if (batch === undefined) {
|
|
697
|
+
if (path !== null && tag !== null)
|
|
698
|
+
return jsonError(400, "choose_path_or_tag");
|
|
699
|
+
if (path === null && tag === null)
|
|
700
|
+
return jsonError(400, "invalid_path");
|
|
701
|
+
batch = { paths: path === null ? [] : [path], tags: tag === null ? [] : [tag] };
|
|
702
|
+
}
|
|
703
|
+
const tags = [...new Set(batch.tags)];
|
|
704
|
+
for (const candidate of tags) {
|
|
513
705
|
try {
|
|
514
|
-
normalizeTag(
|
|
706
|
+
normalizeTag(candidate);
|
|
515
707
|
}
|
|
516
708
|
catch {
|
|
517
709
|
return jsonError(400, "invalid_tag");
|
|
518
710
|
}
|
|
519
|
-
if (options.store.invalidateTag === undefined) {
|
|
520
|
-
return jsonError(501, "tag_invalidation_not_supported");
|
|
521
|
-
}
|
|
522
|
-
await options.store.invalidateTag(tag);
|
|
523
|
-
return Response.json({ revalidatedTag: tag });
|
|
524
711
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
712
|
+
const paths = [...new Set(batch.paths)];
|
|
713
|
+
const keys = [];
|
|
714
|
+
for (const candidate of paths) {
|
|
715
|
+
if (!candidate.startsWith("/"))
|
|
716
|
+
return jsonError(400, "invalid_path");
|
|
717
|
+
const key = keyOf(candidate, req);
|
|
718
|
+
if (key === null)
|
|
719
|
+
return jsonError(400, "uncached_query");
|
|
720
|
+
keys.push(key);
|
|
721
|
+
}
|
|
722
|
+
const invalidateTag = options.store.invalidateTag;
|
|
723
|
+
if (tags.length > 0 && invalidateTag === undefined) {
|
|
724
|
+
return jsonError(501, "tag_invalidation_not_supported");
|
|
725
|
+
}
|
|
726
|
+
for (const key of keys)
|
|
727
|
+
await options.store.delete(key);
|
|
728
|
+
for (const candidate of tags)
|
|
729
|
+
await invalidateTag?.call(options.store, candidate);
|
|
730
|
+
const done = path !== null
|
|
731
|
+
? { revalidated: path }
|
|
732
|
+
: tag !== null
|
|
733
|
+
? { revalidatedTag: tag }
|
|
734
|
+
: { revalidated: paths, revalidatedTags: tags };
|
|
735
|
+
if (options.cdn === undefined)
|
|
736
|
+
return Response.json(done);
|
|
737
|
+
let outcome;
|
|
738
|
+
try {
|
|
739
|
+
outcome = await options.cdn.purge({ tags, paths }, platform);
|
|
740
|
+
}
|
|
741
|
+
catch {
|
|
742
|
+
outcome = { cdn: "failed", retryable: true, error: "cdn_purge_threw" };
|
|
743
|
+
}
|
|
744
|
+
if (outcome.cdn === "failed") {
|
|
745
|
+
const failure = {
|
|
746
|
+
ok: false,
|
|
747
|
+
error: "cdn_purge_failed",
|
|
748
|
+
origin: "done",
|
|
749
|
+
retryable: outcome.retryable,
|
|
750
|
+
};
|
|
751
|
+
if (outcome.error !== undefined)
|
|
752
|
+
failure.reason = outcome.error;
|
|
753
|
+
return Response.json(failure, { status: 502 });
|
|
754
|
+
}
|
|
755
|
+
return Response.json({ ...done, cdn: outcome.cdn }, { status: outcome.cdn === "queued" ? 202 : 200 });
|
|
529
756
|
};
|
|
530
757
|
}
|
|
531
758
|
//# sourceMappingURL=isr.js.map
|