@uniformdev/next-app-router 20.81.0 → 20.81.1-alpha.7.sha-91a5b13e0c
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/{UniformComposition-DBO-oo7J.d.ts → UniformComposition-C00_YDOg.d.ts} +11 -31
- package/dist/{UniformComposition-le6UEB_r.d.mts → UniformComposition-DiArCpVQ.d.mts} +11 -31
- package/dist/cache.d.mts +24 -6
- package/dist/cache.d.ts +24 -6
- package/dist/cache.js +410 -831
- package/dist/cache.mjs +405 -829
- package/dist/compat.d.mts +2 -4
- package/dist/compat.d.ts +2 -4
- package/dist/component.d.mts +10 -1
- package/dist/component.d.ts +10 -1
- package/dist/component.js +113 -617
- package/dist/component.mjs +112 -640
- package/dist/composition-BvOM-LIW.d.mts +28 -0
- package/dist/composition-BvOM-LIW.d.ts +28 -0
- package/dist/config/default.js +0 -1
- package/dist/config/default.mjs +0 -1
- package/dist/createCachedManifestProvider-C7faGJJ8.d.mts +69 -0
- package/dist/createCachedManifestProvider-C7faGJJ8.d.ts +69 -0
- package/dist/edge.d.mts +57 -0
- package/dist/edge.d.ts +57 -0
- package/dist/edge.js +1105 -0
- package/dist/edge.mjs +1073 -0
- package/dist/handler.d.mts +15 -2
- package/dist/handler.d.ts +15 -2
- package/dist/handler.js +134 -628
- package/dist/handler.mjs +132 -626
- package/dist/index.d.mts +73 -42
- package/dist/index.d.ts +73 -42
- package/dist/index.esm.js +2032 -5629
- package/dist/index.js +2068 -5661
- package/dist/index.mjs +2032 -5629
- package/dist/middleware.d.mts +52 -13
- package/dist/middleware.d.ts +52 -13
- package/dist/middleware.js +410 -5746
- package/dist/middleware.mjs +417 -5776
- package/dist/resolveRouteFromPath-BHJGOpBN.d.ts +82 -0
- package/dist/resolveRouteFromPath-BsZUVkRX.d.mts +82 -0
- package/dist/vercel.d.mts +24 -0
- package/dist/vercel.d.ts +24 -0
- package/dist/vercel.js +703 -0
- package/dist/vercel.mjs +675 -0
- package/package.json +37 -9
- package/dist/client-BElN_CWD.d.mts +0 -786
- package/dist/client-BElN_CWD.d.ts +0 -786
- package/dist/resolveRouteFromCode-BOvjIvM2.d.ts +0 -18
- package/dist/resolveRouteFromCode-CuJ4JHeb.d.mts +0 -18
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RouteGetResponseEdgehancedComposition, RouteGetResponseRedirect } from '@uniformdev/canvas';
|
|
2
|
+
import { PageState } from '@uniformdev/next-app-router-shared';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A composition resolved for a page, with the page state it was resolved for. `UniformComposition`
|
|
6
|
+
* renders it, and the same object can be reused by `generateMetadata`, layouts, or another
|
|
7
|
+
* resolver that should carry the page state through.
|
|
8
|
+
*/
|
|
9
|
+
type ResolvedComposition = {
|
|
10
|
+
pageState: PageState;
|
|
11
|
+
route: RouteGetResponseEdgehancedComposition;
|
|
12
|
+
};
|
|
13
|
+
/** A route that matched a redirect, with the page state it was resolved for. */
|
|
14
|
+
type ResolvedRedirect = {
|
|
15
|
+
pageState: PageState;
|
|
16
|
+
route: RouteGetResponseRedirect;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* What a resolver returns: a {@link ResolvedComposition}, a {@link ResolvedRedirect}, or the page
|
|
20
|
+
* state with no `route` when nothing matched. `requireComposition` handles the redirect and not
|
|
21
|
+
* found cases with Next.js navigation; `route.type` narrows it for custom handling.
|
|
22
|
+
*/
|
|
23
|
+
type ResolvedRouteResult = ResolvedComposition | ResolvedRedirect | {
|
|
24
|
+
pageState: PageState;
|
|
25
|
+
route: undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type { ResolvedRouteResult as R, ResolvedComposition as a, ResolvedRedirect as b };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { RouteGetResponseEdgehancedComposition, RouteGetResponseRedirect } from '@uniformdev/canvas';
|
|
2
|
+
import { PageState } from '@uniformdev/next-app-router-shared';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A composition resolved for a page, with the page state it was resolved for. `UniformComposition`
|
|
6
|
+
* renders it, and the same object can be reused by `generateMetadata`, layouts, or another
|
|
7
|
+
* resolver that should carry the page state through.
|
|
8
|
+
*/
|
|
9
|
+
type ResolvedComposition = {
|
|
10
|
+
pageState: PageState;
|
|
11
|
+
route: RouteGetResponseEdgehancedComposition;
|
|
12
|
+
};
|
|
13
|
+
/** A route that matched a redirect, with the page state it was resolved for. */
|
|
14
|
+
type ResolvedRedirect = {
|
|
15
|
+
pageState: PageState;
|
|
16
|
+
route: RouteGetResponseRedirect;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* What a resolver returns: a {@link ResolvedComposition}, a {@link ResolvedRedirect}, or the page
|
|
20
|
+
* state with no `route` when nothing matched. `requireComposition` handles the redirect and not
|
|
21
|
+
* found cases with Next.js navigation; `route.type` narrows it for custom handling.
|
|
22
|
+
*/
|
|
23
|
+
type ResolvedRouteResult = ResolvedComposition | ResolvedRedirect | {
|
|
24
|
+
pageState: PageState;
|
|
25
|
+
route: undefined;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type { ResolvedRouteResult as R, ResolvedComposition as a, ResolvedRedirect as b };
|
package/dist/config/default.js
CHANGED
package/dist/config/default.mjs
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ManifestV2 } from '@uniformdev/context';
|
|
2
|
+
|
|
3
|
+
type ManifestProviderOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Extends the request's lifetime until the promise settles, for work like writing the manifest
|
|
6
|
+
* to a cache after the response is sent. The edge middleware passes the proxy's
|
|
7
|
+
* `event.waitUntil`.
|
|
8
|
+
*/
|
|
9
|
+
waitUntil: (promise: Promise<unknown>) => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Loads the Context manifest the edge middleware chooses variants with. Called once per HTML
|
|
13
|
+
* document request. Resolves to the manifest or throws.
|
|
14
|
+
*/
|
|
15
|
+
type ManifestProvider = (options: ManifestProviderOptions) => Promise<ManifestV2>;
|
|
16
|
+
/**
|
|
17
|
+
* A platform's shared cache, which a cached manifest provider stores the manifest in between
|
|
18
|
+
* instances. Vercel's runtime cache from `getCache()` in `@vercel/functions` matches this shape.
|
|
19
|
+
*/
|
|
20
|
+
type ManifestCache = {
|
|
21
|
+
/** Resolves to the stored value, or `null` or `undefined` when there is none. */
|
|
22
|
+
get: (key: string) => Promise<unknown>;
|
|
23
|
+
set: (key: string, value: ManifestV2, options: {
|
|
24
|
+
ttl: number;
|
|
25
|
+
tags: string[];
|
|
26
|
+
}) => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type CreateCachedManifestProviderOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* The platform's shared cache. Without one, each instance loads the manifest from the API
|
|
32
|
+
* whenever its copy is older than `maxAge`.
|
|
33
|
+
*/
|
|
34
|
+
cache?: ManifestCache;
|
|
35
|
+
/**
|
|
36
|
+
* Returned when the manifest cannot be loaded and the instance has no earlier copy, for
|
|
37
|
+
* example a manifest baked into the build with `uniform context manifest download`.
|
|
38
|
+
*/
|
|
39
|
+
fallback?: ManifestV2;
|
|
40
|
+
/**
|
|
41
|
+
* Seconds an entry lives in `cache`. Publishing the manifest expires it sooner when the
|
|
42
|
+
* preview route handler expires the `manifest` tag in the same cache.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue 3600
|
|
45
|
+
*/
|
|
46
|
+
ttl?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Seconds an instance reuses the manifest it loaded before checking `cache` again. Bounds how
|
|
49
|
+
* long an instance keeps serving a manifest after it is published.
|
|
50
|
+
*
|
|
51
|
+
* @defaultValue 10
|
|
52
|
+
*/
|
|
53
|
+
maxAge?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Loads the published manifest when `cache` has none.
|
|
56
|
+
*
|
|
57
|
+
* @defaultValue the Uniform API, with the project and key from the `UNIFORM_*` env vars
|
|
58
|
+
*/
|
|
59
|
+
fetchManifest?: () => Promise<ManifestV2>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Creates a manifest provider that keeps the manifest in memory for `maxAge`, then reads it from
|
|
63
|
+
* the platform's shared `cache`, then from the Uniform API, writing what it fetched back to the
|
|
64
|
+
* cache. Concurrent requests share one load. When loading fails, it returns the last manifest it
|
|
65
|
+
* loaded, then `fallback`, and otherwise rethrows.
|
|
66
|
+
*/
|
|
67
|
+
declare const createCachedManifestProvider: ({ cache, fallback, ttl, maxAge, fetchManifest, }?: CreateCachedManifestProviderOptions) => ManifestProvider;
|
|
68
|
+
|
|
69
|
+
export { type CreateCachedManifestProviderOptions as C, type ManifestProvider as M, type ManifestProviderOptions as a, type ManifestCache as b, createCachedManifestProvider as c };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ManifestV2 } from '@uniformdev/context';
|
|
2
|
+
|
|
3
|
+
type ManifestProviderOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Extends the request's lifetime until the promise settles, for work like writing the manifest
|
|
6
|
+
* to a cache after the response is sent. The edge middleware passes the proxy's
|
|
7
|
+
* `event.waitUntil`.
|
|
8
|
+
*/
|
|
9
|
+
waitUntil: (promise: Promise<unknown>) => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Loads the Context manifest the edge middleware chooses variants with. Called once per HTML
|
|
13
|
+
* document request. Resolves to the manifest or throws.
|
|
14
|
+
*/
|
|
15
|
+
type ManifestProvider = (options: ManifestProviderOptions) => Promise<ManifestV2>;
|
|
16
|
+
/**
|
|
17
|
+
* A platform's shared cache, which a cached manifest provider stores the manifest in between
|
|
18
|
+
* instances. Vercel's runtime cache from `getCache()` in `@vercel/functions` matches this shape.
|
|
19
|
+
*/
|
|
20
|
+
type ManifestCache = {
|
|
21
|
+
/** Resolves to the stored value, or `null` or `undefined` when there is none. */
|
|
22
|
+
get: (key: string) => Promise<unknown>;
|
|
23
|
+
set: (key: string, value: ManifestV2, options: {
|
|
24
|
+
ttl: number;
|
|
25
|
+
tags: string[];
|
|
26
|
+
}) => Promise<void>;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type CreateCachedManifestProviderOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* The platform's shared cache. Without one, each instance loads the manifest from the API
|
|
32
|
+
* whenever its copy is older than `maxAge`.
|
|
33
|
+
*/
|
|
34
|
+
cache?: ManifestCache;
|
|
35
|
+
/**
|
|
36
|
+
* Returned when the manifest cannot be loaded and the instance has no earlier copy, for
|
|
37
|
+
* example a manifest baked into the build with `uniform context manifest download`.
|
|
38
|
+
*/
|
|
39
|
+
fallback?: ManifestV2;
|
|
40
|
+
/**
|
|
41
|
+
* Seconds an entry lives in `cache`. Publishing the manifest expires it sooner when the
|
|
42
|
+
* preview route handler expires the `manifest` tag in the same cache.
|
|
43
|
+
*
|
|
44
|
+
* @defaultValue 3600
|
|
45
|
+
*/
|
|
46
|
+
ttl?: number;
|
|
47
|
+
/**
|
|
48
|
+
* Seconds an instance reuses the manifest it loaded before checking `cache` again. Bounds how
|
|
49
|
+
* long an instance keeps serving a manifest after it is published.
|
|
50
|
+
*
|
|
51
|
+
* @defaultValue 10
|
|
52
|
+
*/
|
|
53
|
+
maxAge?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Loads the published manifest when `cache` has none.
|
|
56
|
+
*
|
|
57
|
+
* @defaultValue the Uniform API, with the project and key from the `UNIFORM_*` env vars
|
|
58
|
+
*/
|
|
59
|
+
fetchManifest?: () => Promise<ManifestV2>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Creates a manifest provider that keeps the manifest in memory for `maxAge`, then reads it from
|
|
63
|
+
* the platform's shared `cache`, then from the Uniform API, writing what it fetched back to the
|
|
64
|
+
* cache. Concurrent requests share one load. When loading fails, it returns the last manifest it
|
|
65
|
+
* loaded, then `fallback`, and otherwise rethrows.
|
|
66
|
+
*/
|
|
67
|
+
declare const createCachedManifestProvider: ({ cache, fallback, ttl, maxAge, fetchManifest, }?: CreateCachedManifestProviderOptions) => ManifestProvider;
|
|
68
|
+
|
|
69
|
+
export { type CreateCachedManifestProviderOptions as C, type ManifestProvider as M, type ManifestProviderOptions as a, type ManifestCache as b, createCachedManifestProvider as c };
|
package/dist/edge.d.mts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ManifestV2 } from '@uniformdev/context';
|
|
2
|
+
import { TransformEdgeStreamOptions } from '@uniformdev/context-edge';
|
|
3
|
+
import { NextRequest, NextFetchEvent } from 'next/server';
|
|
4
|
+
import { M as ManifestProvider, a as ManifestProviderOptions } from './createCachedManifestProvider-C7faGJJ8.mjs';
|
|
5
|
+
export { C as CreateCachedManifestProviderOptions, b as ManifestCache, c as createCachedManifestProvider } from './createCachedManifestProvider-C7faGJJ8.mjs';
|
|
6
|
+
import { HandleOptions } from './middleware.mjs';
|
|
7
|
+
import '@uniformdev/next-app-router-shared';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Marks the edge middleware's own fetch of the rendered page, so the middleware lets it through
|
|
11
|
+
* when the matcher also covers the rewrite destination.
|
|
12
|
+
*/
|
|
13
|
+
declare const UNIFORM_EDGE_ORIGIN_HEADER = "x-uniform-edge-origin";
|
|
14
|
+
type UniformEdgeMiddlewareOptions = HandleOptions & {
|
|
15
|
+
/**
|
|
16
|
+
* The project's Context manifest, which chooses the visitor's variants.
|
|
17
|
+
*
|
|
18
|
+
* Pass a manifest baked into the build (for example with `uniform context manifest download`)
|
|
19
|
+
* so the middleware makes no network calls. Signals and tests published after the build are
|
|
20
|
+
* then out of date at the edge until the next build.
|
|
21
|
+
*
|
|
22
|
+
* Pass a provider, such as `vercelManifestProvider` from `@uniformdev/next-app-router/vercel`
|
|
23
|
+
* or one made with `createCachedManifestProvider`, to load the published manifest at runtime.
|
|
24
|
+
* It is called for HTML document requests only, alongside the fetch of the page.
|
|
25
|
+
*/
|
|
26
|
+
manifest: ManifestV2 | ManifestProvider;
|
|
27
|
+
/**
|
|
28
|
+
* Called when the manifest provider throws, and when the NESI transform fails. A provider
|
|
29
|
+
* failure receives the error, and the edge chooses with an empty manifest: personalizations
|
|
30
|
+
* show their defaults, and the browser chooses tests after hydration. A transform failure
|
|
31
|
+
* also receives the decoded HTML chunk that triggered it, when available, and the response
|
|
32
|
+
* ends at the point of failure.
|
|
33
|
+
*/
|
|
34
|
+
onError?: TransformEdgeStreamOptions['onError'];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Returns middleware that rewrites each request to its Uniform code like `uniformMiddleware`, and
|
|
38
|
+
* processes the NESI tags in the page at the edge. HTML document requests fetch the page rendered
|
|
39
|
+
* for the route's code and keep only the visitor's variants from the tags it contains, which
|
|
40
|
+
* `UniformComposition` renders for published personalizations and tests when `edgeMode` is enabled
|
|
41
|
+
* in `uniform.server.config`. Client navigations, prefetches and draft requests are rewritten, and
|
|
42
|
+
* their variants are chosen in the browser.
|
|
43
|
+
*
|
|
44
|
+
* Requires the optional peer dependency `@uniformdev/context-edge`.
|
|
45
|
+
*/
|
|
46
|
+
declare const uniformEdgeMiddleware: (options: UniformEdgeMiddlewareOptions) => (request: NextRequest, event?: Pick<NextFetchEvent, "waitUntil">) => Promise<Response>;
|
|
47
|
+
/**
|
|
48
|
+
* Handles one request the way {@link uniformEdgeMiddleware} does. The transformed response is
|
|
49
|
+
* personalized, so it is marked `private, no-store`. `waitUntil` is handed to a manifest provider
|
|
50
|
+
* for background work, and defaults to letting the promise run unobserved.
|
|
51
|
+
*/
|
|
52
|
+
declare const handleUniformEdgeRoute: ({ request, manifest, onError, waitUntil, ...options }: UniformEdgeMiddlewareOptions & {
|
|
53
|
+
request: NextRequest;
|
|
54
|
+
waitUntil?: ManifestProviderOptions["waitUntil"];
|
|
55
|
+
}) => Promise<Response>;
|
|
56
|
+
|
|
57
|
+
export { ManifestProvider, ManifestProviderOptions, UNIFORM_EDGE_ORIGIN_HEADER, type UniformEdgeMiddlewareOptions, handleUniformEdgeRoute, uniformEdgeMiddleware };
|
package/dist/edge.d.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ManifestV2 } from '@uniformdev/context';
|
|
2
|
+
import { TransformEdgeStreamOptions } from '@uniformdev/context-edge';
|
|
3
|
+
import { NextRequest, NextFetchEvent } from 'next/server';
|
|
4
|
+
import { M as ManifestProvider, a as ManifestProviderOptions } from './createCachedManifestProvider-C7faGJJ8.js';
|
|
5
|
+
export { C as CreateCachedManifestProviderOptions, b as ManifestCache, c as createCachedManifestProvider } from './createCachedManifestProvider-C7faGJJ8.js';
|
|
6
|
+
import { HandleOptions } from './middleware.js';
|
|
7
|
+
import '@uniformdev/next-app-router-shared';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Marks the edge middleware's own fetch of the rendered page, so the middleware lets it through
|
|
11
|
+
* when the matcher also covers the rewrite destination.
|
|
12
|
+
*/
|
|
13
|
+
declare const UNIFORM_EDGE_ORIGIN_HEADER = "x-uniform-edge-origin";
|
|
14
|
+
type UniformEdgeMiddlewareOptions = HandleOptions & {
|
|
15
|
+
/**
|
|
16
|
+
* The project's Context manifest, which chooses the visitor's variants.
|
|
17
|
+
*
|
|
18
|
+
* Pass a manifest baked into the build (for example with `uniform context manifest download`)
|
|
19
|
+
* so the middleware makes no network calls. Signals and tests published after the build are
|
|
20
|
+
* then out of date at the edge until the next build.
|
|
21
|
+
*
|
|
22
|
+
* Pass a provider, such as `vercelManifestProvider` from `@uniformdev/next-app-router/vercel`
|
|
23
|
+
* or one made with `createCachedManifestProvider`, to load the published manifest at runtime.
|
|
24
|
+
* It is called for HTML document requests only, alongside the fetch of the page.
|
|
25
|
+
*/
|
|
26
|
+
manifest: ManifestV2 | ManifestProvider;
|
|
27
|
+
/**
|
|
28
|
+
* Called when the manifest provider throws, and when the NESI transform fails. A provider
|
|
29
|
+
* failure receives the error, and the edge chooses with an empty manifest: personalizations
|
|
30
|
+
* show their defaults, and the browser chooses tests after hydration. A transform failure
|
|
31
|
+
* also receives the decoded HTML chunk that triggered it, when available, and the response
|
|
32
|
+
* ends at the point of failure.
|
|
33
|
+
*/
|
|
34
|
+
onError?: TransformEdgeStreamOptions['onError'];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Returns middleware that rewrites each request to its Uniform code like `uniformMiddleware`, and
|
|
38
|
+
* processes the NESI tags in the page at the edge. HTML document requests fetch the page rendered
|
|
39
|
+
* for the route's code and keep only the visitor's variants from the tags it contains, which
|
|
40
|
+
* `UniformComposition` renders for published personalizations and tests when `edgeMode` is enabled
|
|
41
|
+
* in `uniform.server.config`. Client navigations, prefetches and draft requests are rewritten, and
|
|
42
|
+
* their variants are chosen in the browser.
|
|
43
|
+
*
|
|
44
|
+
* Requires the optional peer dependency `@uniformdev/context-edge`.
|
|
45
|
+
*/
|
|
46
|
+
declare const uniformEdgeMiddleware: (options: UniformEdgeMiddlewareOptions) => (request: NextRequest, event?: Pick<NextFetchEvent, "waitUntil">) => Promise<Response>;
|
|
47
|
+
/**
|
|
48
|
+
* Handles one request the way {@link uniformEdgeMiddleware} does. The transformed response is
|
|
49
|
+
* personalized, so it is marked `private, no-store`. `waitUntil` is handed to a manifest provider
|
|
50
|
+
* for background work, and defaults to letting the promise run unobserved.
|
|
51
|
+
*/
|
|
52
|
+
declare const handleUniformEdgeRoute: ({ request, manifest, onError, waitUntil, ...options }: UniformEdgeMiddlewareOptions & {
|
|
53
|
+
request: NextRequest;
|
|
54
|
+
waitUntil?: ManifestProviderOptions["waitUntil"];
|
|
55
|
+
}) => Promise<Response>;
|
|
56
|
+
|
|
57
|
+
export { ManifestProvider, ManifestProviderOptions, UNIFORM_EDGE_ORIGIN_HEADER, type UniformEdgeMiddlewareOptions, handleUniformEdgeRoute, uniformEdgeMiddleware };
|