@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.
Files changed (46) hide show
  1. package/dist/{UniformComposition-DBO-oo7J.d.ts → UniformComposition-C00_YDOg.d.ts} +11 -31
  2. package/dist/{UniformComposition-le6UEB_r.d.mts → UniformComposition-DiArCpVQ.d.mts} +11 -31
  3. package/dist/cache.d.mts +24 -6
  4. package/dist/cache.d.ts +24 -6
  5. package/dist/cache.js +410 -831
  6. package/dist/cache.mjs +405 -829
  7. package/dist/compat.d.mts +2 -4
  8. package/dist/compat.d.ts +2 -4
  9. package/dist/component.d.mts +10 -1
  10. package/dist/component.d.ts +10 -1
  11. package/dist/component.js +113 -617
  12. package/dist/component.mjs +112 -640
  13. package/dist/composition-BvOM-LIW.d.mts +28 -0
  14. package/dist/composition-BvOM-LIW.d.ts +28 -0
  15. package/dist/config/default.js +0 -1
  16. package/dist/config/default.mjs +0 -1
  17. package/dist/createCachedManifestProvider-C7faGJJ8.d.mts +69 -0
  18. package/dist/createCachedManifestProvider-C7faGJJ8.d.ts +69 -0
  19. package/dist/edge.d.mts +57 -0
  20. package/dist/edge.d.ts +57 -0
  21. package/dist/edge.js +1105 -0
  22. package/dist/edge.mjs +1073 -0
  23. package/dist/handler.d.mts +15 -2
  24. package/dist/handler.d.ts +15 -2
  25. package/dist/handler.js +134 -628
  26. package/dist/handler.mjs +132 -626
  27. package/dist/index.d.mts +73 -42
  28. package/dist/index.d.ts +73 -42
  29. package/dist/index.esm.js +2032 -5629
  30. package/dist/index.js +2068 -5661
  31. package/dist/index.mjs +2032 -5629
  32. package/dist/middleware.d.mts +52 -13
  33. package/dist/middleware.d.ts +52 -13
  34. package/dist/middleware.js +410 -5746
  35. package/dist/middleware.mjs +417 -5776
  36. package/dist/resolveRouteFromPath-BHJGOpBN.d.ts +82 -0
  37. package/dist/resolveRouteFromPath-BsZUVkRX.d.mts +82 -0
  38. package/dist/vercel.d.mts +24 -0
  39. package/dist/vercel.d.ts +24 -0
  40. package/dist/vercel.js +703 -0
  41. package/dist/vercel.mjs +675 -0
  42. package/package.json +37 -9
  43. package/dist/client-BElN_CWD.d.mts +0 -786
  44. package/dist/client-BElN_CWD.d.ts +0 -786
  45. package/dist/resolveRouteFromCode-BOvjIvM2.d.ts +0 -18
  46. package/dist/resolveRouteFromCode-CuJ4JHeb.d.mts +0 -18
package/dist/index.d.mts CHANGED
@@ -1,15 +1,15 @@
1
- import { CanvasClient, CompositionDeliveryClient, RouteClient, ComponentInstance } from '@uniformdev/canvas';
2
- import { CacheMode, CanvasCacheMode, ManifestCacheMode, ProjectMapCacheMode, RewriteRequestPathResult } from '@uniformdev/next-app-router-shared';
1
+ import { CanvasClient, CompositionDeliveryClient, RouteClient, RouteGetResponseRedirect } from '@uniformdev/canvas';
2
+ import { CacheMode, CanvasCacheMode, ManifestCacheMode, ProjectMapCacheMode, RewriteRequestPathResult, PageState } from '@uniformdev/next-app-router-shared';
3
3
  import { ManifestClient } from '@uniformdev/context/api';
4
4
  import { ProjectMapClient } from '@uniformdev/project-map';
5
- import { U as UniformCompositionProps } from './UniformComposition-le6UEB_r.mjs';
6
- export { C as CompositionCache, a as ResolveComponentFunction, R as ResolveComponentResult, b as UniformComposition, c as createCompositionCache } from './UniformComposition-le6UEB_r.mjs';
5
+ import { U as UniformCompositionProps } from './UniformComposition-DiArCpVQ.mjs';
6
+ export { C as CompositionCache, a as ResolveComponentFunction, R as ResolveComponentResult, b as UniformComposition, c as createCompositionCache } from './UniformComposition-DiArCpVQ.mjs';
7
+ import { ClientContextComponent } from '@uniformdev/next-app-router-client';
7
8
  import React from 'react';
8
- export { D as DataClient, a as DefaultDataClient, E as EnhanceRouteOptions, G as GetRouteFromMiddlewareOptions, b as GetRouteFromPageStateOptions, c as GetRouteOptions, R as RewriteRouteOptions, d as RewriteRouteResult, e as expireMiddlewareCacheTag } from './client-BElN_CWD.mjs';
9
- import { a as ResolvedRouteResult } from './resolveRouteFromCode-CuJ4JHeb.mjs';
10
- export { R as ResolveRouteFunction, r as resolveRouteFromCode } from './resolveRouteFromCode-CuJ4JHeb.mjs';
11
- import '@uniformdev/next-app-router-client';
12
- import '@uniformdev/context';
9
+ import { a as ResolvedComposition, R as ResolvedRouteResult } from './composition-BvOM-LIW.mjs';
10
+ export { b as ResolvedRedirect } from './composition-BvOM-LIW.mjs';
11
+ import { d as ResolveRouteFunction } from './resolveRouteFromPath-BsZUVkRX.mjs';
12
+ export { R as ResolveCompositionByIdOptions, a as ResolveCompositionBySlugOptions, b as ResolveRouteFromCodeOptions, c as ResolveRouteFromPathOptions, r as resolveCompositionById, e as resolveCompositionBySlug, f as resolveRouteFromCode, g as resolveRouteFromPath } from './resolveRouteFromPath-BsZUVkRX.mjs';
13
13
 
14
14
  type SpecificCacheMode<TCacheMode extends CacheMode> = {
15
15
  cache: TCacheMode;
@@ -202,6 +202,23 @@ type PlaygroundParameters = {
202
202
  }>;
203
203
  };
204
204
 
205
+ type UniformContextProps = {
206
+ /**
207
+ * Component to initialize Uniform context on the client.
208
+ */
209
+ clientContextComponent?: ClientContextComponent;
210
+ /**
211
+ * The page's primary composition. It sets the composition metadata of the visitor's context and
212
+ * the default consent, and loads the contextual editing script in the editor and draft states.
213
+ */
214
+ result: ResolvedComposition | undefined;
215
+ };
216
+ /**
217
+ * Initializes Uniform context on the client and loads the contextual editing script. Render it
218
+ * once per page, next to one or more `UniformComposition` elements.
219
+ */
220
+ declare function UniformContext(props: UniformContextProps): React.JSX.Element;
221
+
205
222
  type UniformPageParameters = {
206
223
  params: Promise<{
207
224
  code: string;
@@ -211,8 +228,13 @@ type AwaitedUniformPageParameters = {
211
228
  params: Awaited<UniformPageParameters['params']>;
212
229
  };
213
230
 
214
- type UniformPlaygroundProps = UniformCompositionProps;
215
- declare const UniformPlayground: ({ resolveRoute, ...rest }: UniformPlaygroundProps) => Promise<React.JSX.Element>;
231
+ type UniformPlaygroundProps = UniformCompositionProps & Pick<UniformContextProps, 'clientContextComponent'>;
232
+ /**
233
+ * Renders a playground page in draft mode: the composition, usually from `resolvePlaygroundRoute`,
234
+ * with its `UniformContext`. Renders a message outside draft mode. Keep it out of layouts that
235
+ * render their own `UniformContext`, which would initialize Uniform context twice.
236
+ */
237
+ declare const UniformPlayground: ({ clientContextComponent, ...props }: UniformPlaygroundProps) => Promise<React.JSX.Element>;
216
238
 
217
239
  type CreateStaticParamsOptions = {
218
240
  paths: string[];
@@ -222,47 +244,56 @@ type CreateStaticParamsOptions = {
222
244
  locale?: string;
223
245
  };
224
246
  /**
225
- * Function to generate all possible page states for the given paths in playground mode.
226
- * @param options
227
- * @returns
247
+ * Generates the playground code for the first of the given paths. Playground requests are drafts,
248
+ * which evaluate while the page renders, so there is one code per composition.
228
249
  */
229
250
  declare const createUniformPlaygroundStaticParams: (options: CreateStaticParamsOptions) => Promise<{
230
251
  code: string;
231
252
  }[]>;
232
253
  /**
233
- * Function to generate all possible page states for the given paths.
234
- * @param options
235
- * @returns
254
+ * Generates one code per published composition among the given paths, for `generateStaticParams`
255
+ * of the `[code]` route. Codes carry the route, not an evaluation, so each path has one static page
256
+ * whose variants are chosen in the browser or at the edge.
236
257
  */
237
258
  declare const createUniformStaticParams: (options: CreateStaticParamsOptions) => Promise<{
238
259
  code: string;
239
260
  }[]>;
240
261
 
241
- type EvaluateTestsFunction = (test: {
242
- name: string;
243
- component: ComponentInstance;
244
- }) => boolean;
245
- type EvaluatePersonalizationsFunction = (personalization: {
246
- name: string;
247
- component: ComponentInstance;
248
- }) => boolean;
249
- type PrecomputeCompositionOptions = Pick<ResolvedRouteResult, 'pageState' | 'route'> & {
250
- /**
251
- * Whether to evaluate tests
252
- * @defaultValue true
253
- */
254
- evaluateTests?: boolean | EvaluateTestsFunction;
255
- /**
256
- * Whether to evaluate personalizations
257
- * @defaultValue true
258
- */
259
- evaluatePersonalizations?: boolean | EvaluatePersonalizationsFunction;
260
- };
261
- declare const precomputeComposition: ({ pageState, route, evaluatePersonalizations, evaluateTests, }: PrecomputeCompositionOptions) => Promise<void>;
262
-
263
- declare const resolvePlaygroundRoute: ({ code }: {
262
+ /**
263
+ * Reads the page state the middleware encoded in a `[code]` path segment: the route path,
264
+ * composition state, release, locale and preview settings. Pass it to `resolveCompositionById`
265
+ * or `resolveCompositionBySlug` to resolve the page's composition without the Route API.
266
+ */
267
+ declare const deserializePageState: ({ code }: {
264
268
  code: string;
265
- }) => Promise<ResolvedRouteResult>;
269
+ }) => PageState;
270
+
271
+ /**
272
+ * Returns the result when it resolved to a composition, ready for `UniformComposition`. Otherwise
273
+ * it throws through Next.js navigation: `notFound()` when nothing matched, `permanentRedirect` for
274
+ * 301 and 308 redirect targets, and `redirect` for the rest. The redirect target is built with
275
+ * `resolveRedirectHref`.
276
+ */
277
+ declare const requireComposition: (result: ResolvedRouteResult) => ResolvedComposition;
278
+
279
+ /**
280
+ * Resolves the composition of a playground code. The code carries the composition id, and the
281
+ * composition resolves in the editor state, falling back to the draft state. `route` is undefined
282
+ * outside draft mode, without fetching, and when the composition does not exist.
283
+ */
284
+ declare const resolvePlaygroundRoute: ResolveRouteFunction;
285
+
286
+ type ResolveRedirectHrefOptions = {
287
+ route: RouteGetResponseRedirect;
288
+ /** The path that matched the redirect, usually the result's `pageState.routePath`. */
289
+ routePath: string;
290
+ };
291
+ /**
292
+ * Builds the URL a redirect route sends the visitor to. Path variables in the target, such as
293
+ * `/new/:id`, are filled from `routePath`. Targets on the same domain come back as relative paths;
294
+ * absolute targets on another domain come back unchanged.
295
+ */
296
+ declare const resolveRedirectHref: ({ route, routePath }: ResolveRedirectHrefOptions) => string;
266
297
 
267
298
  type CustomRoute = {
268
299
  id: string;
@@ -276,4 +307,4 @@ declare const findRouteMatch: (routes: CustomRoute[], path: string) => RouteMatc
276
307
 
277
308
  declare const serverContext: <T>(defaultValue?: T) => [() => T | undefined, (v: T) => void];
278
309
 
279
- export { type AwaitedUniformPageParameters, type CreateStaticParamsOptions, type CustomRoute, type GetCanvasClientOptions, type GetCompositionDeliveryClientOptions, type GetManifestClientOptions, type GetProjectMapClientOptions, type GetRouteClientOptions, type PlaygroundParameters, type RouteMatch, UniformCompositionProps, type UniformPageParameters, UniformPlayground, createUniformPlaygroundStaticParams, createUniformStaticParams, findRouteMatch, getCanvasClient, getCompositionDeliveryClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, precomputeComposition, resolvePlaygroundRoute, serverContext };
310
+ export { type AwaitedUniformPageParameters, type CreateStaticParamsOptions, type CustomRoute, type GetCanvasClientOptions, type GetCompositionDeliveryClientOptions, type GetManifestClientOptions, type GetProjectMapClientOptions, type GetRouteClientOptions, type PlaygroundParameters, type ResolveRedirectHrefOptions, ResolveRouteFunction, ResolvedComposition, ResolvedRouteResult, type RouteMatch, UniformCompositionProps, UniformContext, type UniformContextProps, type UniformPageParameters, UniformPlayground, type UniformPlaygroundProps, createUniformPlaygroundStaticParams, createUniformStaticParams, deserializePageState, findRouteMatch, getCanvasClient, getCompositionDeliveryClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, requireComposition, resolvePlaygroundRoute, resolveRedirectHref, serverContext };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- import { CanvasClient, CompositionDeliveryClient, RouteClient, ComponentInstance } from '@uniformdev/canvas';
2
- import { CacheMode, CanvasCacheMode, ManifestCacheMode, ProjectMapCacheMode, RewriteRequestPathResult } from '@uniformdev/next-app-router-shared';
1
+ import { CanvasClient, CompositionDeliveryClient, RouteClient, RouteGetResponseRedirect } from '@uniformdev/canvas';
2
+ import { CacheMode, CanvasCacheMode, ManifestCacheMode, ProjectMapCacheMode, RewriteRequestPathResult, PageState } from '@uniformdev/next-app-router-shared';
3
3
  import { ManifestClient } from '@uniformdev/context/api';
4
4
  import { ProjectMapClient } from '@uniformdev/project-map';
5
- import { U as UniformCompositionProps } from './UniformComposition-DBO-oo7J.js';
6
- export { C as CompositionCache, a as ResolveComponentFunction, R as ResolveComponentResult, b as UniformComposition, c as createCompositionCache } from './UniformComposition-DBO-oo7J.js';
5
+ import { U as UniformCompositionProps } from './UniformComposition-C00_YDOg.js';
6
+ export { C as CompositionCache, a as ResolveComponentFunction, R as ResolveComponentResult, b as UniformComposition, c as createCompositionCache } from './UniformComposition-C00_YDOg.js';
7
+ import { ClientContextComponent } from '@uniformdev/next-app-router-client';
7
8
  import React from 'react';
8
- export { D as DataClient, a as DefaultDataClient, E as EnhanceRouteOptions, G as GetRouteFromMiddlewareOptions, b as GetRouteFromPageStateOptions, c as GetRouteOptions, R as RewriteRouteOptions, d as RewriteRouteResult, e as expireMiddlewareCacheTag } from './client-BElN_CWD.js';
9
- import { a as ResolvedRouteResult } from './resolveRouteFromCode-BOvjIvM2.js';
10
- export { R as ResolveRouteFunction, r as resolveRouteFromCode } from './resolveRouteFromCode-BOvjIvM2.js';
11
- import '@uniformdev/next-app-router-client';
12
- import '@uniformdev/context';
9
+ import { a as ResolvedComposition, R as ResolvedRouteResult } from './composition-BvOM-LIW.js';
10
+ export { b as ResolvedRedirect } from './composition-BvOM-LIW.js';
11
+ import { d as ResolveRouteFunction } from './resolveRouteFromPath-BHJGOpBN.js';
12
+ export { R as ResolveCompositionByIdOptions, a as ResolveCompositionBySlugOptions, b as ResolveRouteFromCodeOptions, c as ResolveRouteFromPathOptions, r as resolveCompositionById, e as resolveCompositionBySlug, f as resolveRouteFromCode, g as resolveRouteFromPath } from './resolveRouteFromPath-BHJGOpBN.js';
13
13
 
14
14
  type SpecificCacheMode<TCacheMode extends CacheMode> = {
15
15
  cache: TCacheMode;
@@ -202,6 +202,23 @@ type PlaygroundParameters = {
202
202
  }>;
203
203
  };
204
204
 
205
+ type UniformContextProps = {
206
+ /**
207
+ * Component to initialize Uniform context on the client.
208
+ */
209
+ clientContextComponent?: ClientContextComponent;
210
+ /**
211
+ * The page's primary composition. It sets the composition metadata of the visitor's context and
212
+ * the default consent, and loads the contextual editing script in the editor and draft states.
213
+ */
214
+ result: ResolvedComposition | undefined;
215
+ };
216
+ /**
217
+ * Initializes Uniform context on the client and loads the contextual editing script. Render it
218
+ * once per page, next to one or more `UniformComposition` elements.
219
+ */
220
+ declare function UniformContext(props: UniformContextProps): React.JSX.Element;
221
+
205
222
  type UniformPageParameters = {
206
223
  params: Promise<{
207
224
  code: string;
@@ -211,8 +228,13 @@ type AwaitedUniformPageParameters = {
211
228
  params: Awaited<UniformPageParameters['params']>;
212
229
  };
213
230
 
214
- type UniformPlaygroundProps = UniformCompositionProps;
215
- declare const UniformPlayground: ({ resolveRoute, ...rest }: UniformPlaygroundProps) => Promise<React.JSX.Element>;
231
+ type UniformPlaygroundProps = UniformCompositionProps & Pick<UniformContextProps, 'clientContextComponent'>;
232
+ /**
233
+ * Renders a playground page in draft mode: the composition, usually from `resolvePlaygroundRoute`,
234
+ * with its `UniformContext`. Renders a message outside draft mode. Keep it out of layouts that
235
+ * render their own `UniformContext`, which would initialize Uniform context twice.
236
+ */
237
+ declare const UniformPlayground: ({ clientContextComponent, ...props }: UniformPlaygroundProps) => Promise<React.JSX.Element>;
216
238
 
217
239
  type CreateStaticParamsOptions = {
218
240
  paths: string[];
@@ -222,47 +244,56 @@ type CreateStaticParamsOptions = {
222
244
  locale?: string;
223
245
  };
224
246
  /**
225
- * Function to generate all possible page states for the given paths in playground mode.
226
- * @param options
227
- * @returns
247
+ * Generates the playground code for the first of the given paths. Playground requests are drafts,
248
+ * which evaluate while the page renders, so there is one code per composition.
228
249
  */
229
250
  declare const createUniformPlaygroundStaticParams: (options: CreateStaticParamsOptions) => Promise<{
230
251
  code: string;
231
252
  }[]>;
232
253
  /**
233
- * Function to generate all possible page states for the given paths.
234
- * @param options
235
- * @returns
254
+ * Generates one code per published composition among the given paths, for `generateStaticParams`
255
+ * of the `[code]` route. Codes carry the route, not an evaluation, so each path has one static page
256
+ * whose variants are chosen in the browser or at the edge.
236
257
  */
237
258
  declare const createUniformStaticParams: (options: CreateStaticParamsOptions) => Promise<{
238
259
  code: string;
239
260
  }[]>;
240
261
 
241
- type EvaluateTestsFunction = (test: {
242
- name: string;
243
- component: ComponentInstance;
244
- }) => boolean;
245
- type EvaluatePersonalizationsFunction = (personalization: {
246
- name: string;
247
- component: ComponentInstance;
248
- }) => boolean;
249
- type PrecomputeCompositionOptions = Pick<ResolvedRouteResult, 'pageState' | 'route'> & {
250
- /**
251
- * Whether to evaluate tests
252
- * @defaultValue true
253
- */
254
- evaluateTests?: boolean | EvaluateTestsFunction;
255
- /**
256
- * Whether to evaluate personalizations
257
- * @defaultValue true
258
- */
259
- evaluatePersonalizations?: boolean | EvaluatePersonalizationsFunction;
260
- };
261
- declare const precomputeComposition: ({ pageState, route, evaluatePersonalizations, evaluateTests, }: PrecomputeCompositionOptions) => Promise<void>;
262
-
263
- declare const resolvePlaygroundRoute: ({ code }: {
262
+ /**
263
+ * Reads the page state the middleware encoded in a `[code]` path segment: the route path,
264
+ * composition state, release, locale and preview settings. Pass it to `resolveCompositionById`
265
+ * or `resolveCompositionBySlug` to resolve the page's composition without the Route API.
266
+ */
267
+ declare const deserializePageState: ({ code }: {
264
268
  code: string;
265
- }) => Promise<ResolvedRouteResult>;
269
+ }) => PageState;
270
+
271
+ /**
272
+ * Returns the result when it resolved to a composition, ready for `UniformComposition`. Otherwise
273
+ * it throws through Next.js navigation: `notFound()` when nothing matched, `permanentRedirect` for
274
+ * 301 and 308 redirect targets, and `redirect` for the rest. The redirect target is built with
275
+ * `resolveRedirectHref`.
276
+ */
277
+ declare const requireComposition: (result: ResolvedRouteResult) => ResolvedComposition;
278
+
279
+ /**
280
+ * Resolves the composition of a playground code. The code carries the composition id, and the
281
+ * composition resolves in the editor state, falling back to the draft state. `route` is undefined
282
+ * outside draft mode, without fetching, and when the composition does not exist.
283
+ */
284
+ declare const resolvePlaygroundRoute: ResolveRouteFunction;
285
+
286
+ type ResolveRedirectHrefOptions = {
287
+ route: RouteGetResponseRedirect;
288
+ /** The path that matched the redirect, usually the result's `pageState.routePath`. */
289
+ routePath: string;
290
+ };
291
+ /**
292
+ * Builds the URL a redirect route sends the visitor to. Path variables in the target, such as
293
+ * `/new/:id`, are filled from `routePath`. Targets on the same domain come back as relative paths;
294
+ * absolute targets on another domain come back unchanged.
295
+ */
296
+ declare const resolveRedirectHref: ({ route, routePath }: ResolveRedirectHrefOptions) => string;
266
297
 
267
298
  type CustomRoute = {
268
299
  id: string;
@@ -276,4 +307,4 @@ declare const findRouteMatch: (routes: CustomRoute[], path: string) => RouteMatc
276
307
 
277
308
  declare const serverContext: <T>(defaultValue?: T) => [() => T | undefined, (v: T) => void];
278
309
 
279
- export { type AwaitedUniformPageParameters, type CreateStaticParamsOptions, type CustomRoute, type GetCanvasClientOptions, type GetCompositionDeliveryClientOptions, type GetManifestClientOptions, type GetProjectMapClientOptions, type GetRouteClientOptions, type PlaygroundParameters, type RouteMatch, UniformCompositionProps, type UniformPageParameters, UniformPlayground, createUniformPlaygroundStaticParams, createUniformStaticParams, findRouteMatch, getCanvasClient, getCompositionDeliveryClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, precomputeComposition, resolvePlaygroundRoute, serverContext };
310
+ export { type AwaitedUniformPageParameters, type CreateStaticParamsOptions, type CustomRoute, type GetCanvasClientOptions, type GetCompositionDeliveryClientOptions, type GetManifestClientOptions, type GetProjectMapClientOptions, type GetRouteClientOptions, type PlaygroundParameters, type ResolveRedirectHrefOptions, ResolveRouteFunction, ResolvedComposition, ResolvedRouteResult, type RouteMatch, UniformCompositionProps, UniformContext, type UniformContextProps, type UniformPageParameters, UniformPlayground, type UniformPlaygroundProps, createUniformPlaygroundStaticParams, createUniformStaticParams, deserializePageState, findRouteMatch, getCanvasClient, getCompositionDeliveryClient, getManifest, getManifestClient, getProjectMapClient, getRouteClient, requireComposition, resolvePlaygroundRoute, resolveRedirectHref, serverContext };