@uniformdev/canvas-next 19.20.0 → 19.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -161,7 +161,7 @@ var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async
161
161
  res.setHeader("Access-Control-Allow-Origin", "*");
162
162
  res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
163
163
  res.setHeader("Access-Control-Allow-Methods", "GET");
164
- return res.status(204);
164
+ return res.status(204).end();
165
165
  }
166
166
  return res.status(501).json({ message: `Method "${method}" not implemented` });
167
167
  };
package/dist/index.js CHANGED
@@ -207,7 +207,7 @@ var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async
207
207
  res.setHeader("Access-Control-Allow-Origin", "*");
208
208
  res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
209
209
  res.setHeader("Access-Control-Allow-Methods", "GET");
210
- return res.status(204);
210
+ return res.status(204).end();
211
211
  }
212
212
  return res.status(501).json({ message: `Method "${method}" not implemented` });
213
213
  };
package/dist/index.mjs CHANGED
@@ -161,7 +161,7 @@ var createPreviewHandler = ({ secret, enhance, resolveFullPath } = {}) => async
161
161
  res.setHeader("Access-Control-Allow-Origin", "*");
162
162
  res.setHeader("Access-Control-Allow-Headers", "Origin, Content-Type, Accept");
163
163
  res.setHeader("Access-Control-Allow-Methods", "GET");
164
- return res.status(204);
164
+ return res.status(204).end();
165
165
  }
166
166
  return res.status(501).json({ message: `Method "${method}" not implemented` });
167
167
  };
@@ -4,7 +4,7 @@ import { a as UniformPreviewData } from '../models-092c0912.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  export { w as withUniformGetStaticPaths } from '../withUniformGetStaticPaths-6a31a8f8.js';
7
- import { RouteGetResponseEdgehancedComposition, RouteGetResponseNotFound, RouteGetResponseRedirect, unstable_RouteClient, RouteGetParameters, RootComponentInstance } from '@uniformdev/canvas';
7
+ import { RouteGetResponseEdgehancedComposition, RouteGetResponseNotFound, RouteGetResponseRedirect, RouteClient, RouteGetParameters, RootComponentInstance } from '@uniformdev/canvas';
8
8
  import '@uniformdev/canvas-react';
9
9
  import '@uniformdev/project-map';
10
10
 
@@ -13,15 +13,15 @@ type HandleRouteNotFoundFunction<TContext, TResult> = (result: RouteGetResponseN
13
13
  type HandleRouteRedirectFunction<TContext, TResult> = (requestUrl: string, redirect: RouteGetResponseRedirect, context: TContext, defaultHandler: (redirect: RouteGetResponseRedirect) => TResult, duration: number) => TResult;
14
14
  type RouteHandlerOptions<TContext, TResult, TSuccessResult> = {
15
15
  /** If you need to override the default client, you can pass it here */
16
- client?: unstable_RouteClient;
16
+ client?: RouteClient;
17
17
  /** A string that you want to strip from the resolved context.resolvedUrl. Useful when calling from a nested folder which is not part of your project map structure */
18
18
  prefix?: string;
19
19
  /** Useful when you need to modify the path passed to the API */
20
20
  modifyPath?: (path: string, context: TContext) => string;
21
21
  /** The project map ID to connect to. If not set, the default project map for the configured project will be used. */
22
22
  projectMapId?: string;
23
- /** Way to override getRoute request params */
24
- requestOptions?: Partial<RouteGetParameters>;
23
+ /** Way to override getRoute request params. Can also be a function to compute options based on context values. */
24
+ requestOptions?: Partial<RouteGetParameters> | ((context: TContext) => Partial<RouteGetParameters>);
25
25
  /** Disables logging of response information and timings */
26
26
  silent?: boolean;
27
27
  /** Override handling of a composition route response. Return null to signal not found. */
@@ -40,18 +40,18 @@ type RouteHandlerOptions<TContext, TResult, TSuccessResult> = {
40
40
  * Static and dynamic routing as well as redirection is automatically supported.
41
41
  * Custom behavior can be added by passing in options to hook to specific processing events.
42
42
  */
43
- declare const unstable_withUniformGetServerSideProps: <TProps extends {
43
+ declare const withUniformGetServerSideProps: <TProps extends {
44
44
  [key: string]: any;
45
45
  } = {
46
46
  data: RootComponentInstance;
47
47
  }>(options?: RouteHandlerOptions<GetServerSidePropsContext<ParsedUrlQuery, UniformPreviewData>, GetServerSidePropsResult<never>, GetServerSidePropsResult<TProps>> | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
48
48
 
49
49
  /**
50
- * Creates an implementation of `getServerSideProps` using the Uniform Route API.
50
+ * Creates an implementation of `getStaticProps` using the Uniform Route API.
51
51
  * Static and dynamic routing as well as redirection is automatically supported.
52
52
  * Custom behavior can be added by passing in options to hook to specific processing events.
53
53
  */
54
- declare const unstable_withUniformGetStaticProps: <TProps extends {
54
+ declare const withUniformGetStaticProps: <TProps extends {
55
55
  [key: string]: any;
56
56
  } = {
57
57
  data: RootComponentInstance;
@@ -60,7 +60,12 @@ declare const unstable_withUniformGetStaticProps: <TProps extends {
60
60
  param?: string | undefined;
61
61
  }) | undefined) => GetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData>;
62
62
 
63
- declare const unstable_getServerSideProps: next.GetServerSideProps<{
63
+ /**
64
+ * Default implementation of getServerSideProps with routes
65
+ * To configure custom behavior, use:
66
+ * export getServerSideProps = withUniformGetServerSideProps({ ... });
67
+ */
68
+ declare const getServerSideProps: next.GetServerSideProps<{
64
69
  data: {
65
70
  type: string;
66
71
  parameters?: {
@@ -179,7 +184,12 @@ declare const unstable_getServerSideProps: next.GetServerSideProps<{
179
184
  };
180
185
  }, querystring.ParsedUrlQuery, UniformPreviewData>;
181
186
 
182
- declare const unstable_getStaticProps: next.GetStaticProps<{
187
+ /**
188
+ * Default implementation of getStaticProps with routes
189
+ * To configure custom behavior, use:
190
+ * export getStaticProps = withUniformGetStaticProps({ ... });
191
+ */
192
+ declare const getStaticProps: next.GetStaticProps<{
183
193
  data: {
184
194
  type: string;
185
195
  parameters?: {
@@ -297,9 +307,16 @@ declare const unstable_getStaticProps: next.GetStaticProps<{
297
307
  } | undefined;
298
308
  };
299
309
  }, querystring.ParsedUrlQuery, UniformPreviewData>;
310
+ /**
311
+ * Default implementation of getStaticPaths with routes
312
+ * To configure custom behavior, use:
313
+ * export getStaticPaths = withUniformGetStaticProps({ ... });
314
+ *
315
+ * NOTE: fallback must be supported. You cannot generate static paths for dynamic routes which contain query parameters.
316
+ */
300
317
  declare const getStaticPaths: () => Promise<{
301
318
  paths: string[] | undefined;
302
319
  fallback: boolean;
303
320
  }>;
304
321
 
305
- export { HandleRouteCompositionFunction, HandleRouteNotFoundFunction, HandleRouteRedirectFunction, RouteHandlerOptions, getStaticPaths, unstable_getServerSideProps, unstable_getStaticProps, unstable_withUniformGetServerSideProps, unstable_withUniformGetStaticProps };
322
+ export { HandleRouteCompositionFunction, HandleRouteNotFoundFunction, HandleRouteRedirectFunction, RouteHandlerOptions, getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticProps };
@@ -20,12 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/route/index.ts
21
21
  var route_exports = {};
22
22
  __export(route_exports, {
23
+ getServerSideProps: () => getServerSideProps2,
23
24
  getStaticPaths: () => getStaticPaths2,
24
- unstable_getServerSideProps: () => unstable_getServerSideProps,
25
- unstable_getStaticProps: () => unstable_getStaticProps,
26
- unstable_withUniformGetServerSideProps: () => unstable_withUniformGetServerSideProps,
27
- unstable_withUniformGetStaticProps: () => unstable_withUniformGetStaticProps,
28
- withUniformGetStaticPaths: () => withUniformGetStaticPaths
25
+ getStaticProps: () => getStaticProps2,
26
+ withUniformGetServerSideProps: () => withUniformGetServerSideProps2,
27
+ withUniformGetStaticPaths: () => withUniformGetStaticPaths,
28
+ withUniformGetStaticProps: () => withUniformGetStaticProps2
29
29
  });
30
30
  module.exports = __toCommonJS(route_exports);
31
31
 
@@ -335,6 +335,7 @@ var getStaticProps = withUniformGetStaticProps({ param: "path" });
335
335
  var getStaticPaths = withUniformGetStaticPaths();
336
336
 
337
337
  // src/route/withUniformGetServerSideProps.ts
338
+ var import_canvas5 = require("@uniformdev/canvas");
338
339
  var import_redirect = require("@uniformdev/redirect");
339
340
 
340
341
  // src/route/createRouteFetcher.ts
@@ -356,14 +357,19 @@ function createRouteFetcher(options) {
356
357
  silent,
357
358
  parseContext
358
359
  } = options;
359
- const routeClient = client || new import_canvas4.unstable_RouteClient({
360
+ const routeClient = client || new import_canvas4.RouteClient({
360
361
  apiKey: process.env.UNIFORM_API_KEY,
361
362
  projectId: process.env.UNIFORM_PROJECT_ID,
362
363
  edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
363
364
  });
364
365
  const handleModifyPath = modifyPath != null ? modifyPath : (path) => decodeURI(path);
365
366
  return async function fetcher(context) {
366
- const { contextualEditingCompositionId, resolvedUrl } = parseContext(context);
367
+ var _a, _b;
368
+ const {
369
+ contextualEditingCompositionId,
370
+ resolvedUrl,
371
+ defaultFetchState: defaultPreviewState
372
+ } = parseContext(context);
367
373
  let nodePath = prefix ? resolvedUrl.replace(new RegExp(`^${prefix}`), "") : resolvedUrl;
368
374
  nodePath = handleModifyPath(nodePath, context);
369
375
  const invokeRedirectResult = (redirect, duration) => (handleRedirect != null ? handleRedirect : defaultHandleRedirect)(
@@ -427,9 +433,11 @@ function createRouteFetcher(options) {
427
433
  if (!silent) {
428
434
  console.log("Fetch route", nodePath);
429
435
  }
436
+ const resolvedOptions = typeof requestOptions === "function" ? requestOptions(context) : requestOptions;
430
437
  const time = Date.now();
431
438
  const response = await routeClient.getRoute({
432
- ...requestOptions,
439
+ ...resolvedOptions,
440
+ state: (_b = (_a = resolvedOptions == null ? void 0 : resolvedOptions.state) != null ? _a : defaultPreviewState) != null ? _b : import_canvas4.CANVAS_PUBLISHED_STATE,
433
441
  projectMapId,
434
442
  path: nodePath
435
443
  });
@@ -463,7 +471,7 @@ function createRouteFetcher(options) {
463
471
  }
464
472
 
465
473
  // src/route/withUniformGetServerSideProps.ts
466
- var unstable_withUniformGetServerSideProps = (options) => {
474
+ var withUniformGetServerSideProps2 = (options) => {
467
475
  const defaultHandleRedirect = (requestUrl, matched) => {
468
476
  if (matched.redirect.targetStatusCode > 400) {
469
477
  return {
@@ -496,7 +504,10 @@ var unstable_withUniformGetServerSideProps = (options) => {
496
504
  var _a;
497
505
  return {
498
506
  contextualEditingCompositionId: (_a = context.previewData) == null ? void 0 : _a.compositionId,
499
- resolvedUrl: context.resolvedUrl
507
+ resolvedUrl: context.resolvedUrl,
508
+ // auto engage draft content when in next preview mode
509
+ // (can override with explicit setting of request options)'
510
+ defaultFetchState: context.preview ? import_canvas5.CANVAS_DRAFT_STATE : void 0
500
511
  };
501
512
  }
502
513
  });
@@ -504,8 +515,9 @@ var unstable_withUniformGetServerSideProps = (options) => {
504
515
  };
505
516
 
506
517
  // src/route/withUniformGetStaticProps.ts
518
+ var import_canvas6 = require("@uniformdev/canvas");
507
519
  var import_redirect2 = require("@uniformdev/redirect");
508
- var unstable_withUniformGetStaticProps = (options) => {
520
+ var withUniformGetStaticProps2 = (options) => {
509
521
  const defaultHandleRedirect = (requestUrl, matched) => {
510
522
  return {
511
523
  redirect: {
@@ -536,7 +548,10 @@ var unstable_withUniformGetStaticProps = (options) => {
536
548
  resolvedUrl: resolveSlugFromParams({
537
549
  params: context.params,
538
550
  param: (_b = options == null ? void 0 : options.param) != null ? _b : "route"
539
- })
551
+ }),
552
+ // auto engage draft content when in next preview mode
553
+ // (can override with explicit setting of request options)
554
+ defaultFetchState: context.preview ? import_canvas6.CANVAS_DRAFT_STATE : void 0
540
555
  };
541
556
  }
542
557
  });
@@ -544,15 +559,15 @@ var unstable_withUniformGetStaticProps = (options) => {
544
559
  };
545
560
 
546
561
  // src/route/index.ts
547
- var unstable_getServerSideProps = unstable_withUniformGetServerSideProps();
548
- var unstable_getStaticProps = unstable_withUniformGetStaticProps();
562
+ var getServerSideProps2 = withUniformGetServerSideProps2();
563
+ var getStaticProps2 = withUniformGetStaticProps2();
549
564
  var getStaticPaths2 = withUniformGetStaticPaths();
550
565
  // Annotate the CommonJS export names for ESM import in node:
551
566
  0 && (module.exports = {
567
+ getServerSideProps,
552
568
  getStaticPaths,
553
- unstable_getServerSideProps,
554
- unstable_getStaticProps,
555
- unstable_withUniformGetServerSideProps,
556
- unstable_withUniformGetStaticProps,
557
- withUniformGetStaticPaths
569
+ getStaticProps,
570
+ withUniformGetServerSideProps,
571
+ withUniformGetStaticPaths,
572
+ withUniformGetStaticProps
558
573
  });
@@ -57,13 +57,15 @@ function logRouteResponse(response, duration) {
57
57
  }
58
58
 
59
59
  // src/route/withUniformGetServerSideProps.ts
60
+ import { CANVAS_DRAFT_STATE } from "@uniformdev/canvas";
60
61
  import { RedirectClient } from "@uniformdev/redirect";
61
62
 
62
63
  // src/route/createRouteFetcher.ts
63
64
  import {
64
65
  ApiClientError,
66
+ CANVAS_PUBLISHED_STATE,
65
67
  EMPTY_COMPOSITION,
66
- unstable_RouteClient
68
+ RouteClient
67
69
  } from "@uniformdev/canvas";
68
70
  import { red as red2 } from "colorette";
69
71
  function createRouteFetcher(options) {
@@ -82,14 +84,19 @@ function createRouteFetcher(options) {
82
84
  silent,
83
85
  parseContext
84
86
  } = options;
85
- const routeClient = client || new unstable_RouteClient({
87
+ const routeClient = client || new RouteClient({
86
88
  apiKey: process.env.UNIFORM_API_KEY,
87
89
  projectId: process.env.UNIFORM_PROJECT_ID,
88
90
  edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
89
91
  });
90
92
  const handleModifyPath = modifyPath != null ? modifyPath : (path) => decodeURI(path);
91
93
  return async function fetcher(context) {
92
- const { contextualEditingCompositionId, resolvedUrl } = parseContext(context);
94
+ var _a, _b;
95
+ const {
96
+ contextualEditingCompositionId,
97
+ resolvedUrl,
98
+ defaultFetchState: defaultPreviewState
99
+ } = parseContext(context);
93
100
  let nodePath = prefix ? resolvedUrl.replace(new RegExp(`^${prefix}`), "") : resolvedUrl;
94
101
  nodePath = handleModifyPath(nodePath, context);
95
102
  const invokeRedirectResult = (redirect, duration) => (handleRedirect != null ? handleRedirect : defaultHandleRedirect)(
@@ -153,9 +160,11 @@ function createRouteFetcher(options) {
153
160
  if (!silent) {
154
161
  console.log("Fetch route", nodePath);
155
162
  }
163
+ const resolvedOptions = typeof requestOptions === "function" ? requestOptions(context) : requestOptions;
156
164
  const time = Date.now();
157
165
  const response = await routeClient.getRoute({
158
- ...requestOptions,
166
+ ...resolvedOptions,
167
+ state: (_b = (_a = resolvedOptions == null ? void 0 : resolvedOptions.state) != null ? _a : defaultPreviewState) != null ? _b : CANVAS_PUBLISHED_STATE,
159
168
  projectMapId,
160
169
  path: nodePath
161
170
  });
@@ -189,7 +198,7 @@ function createRouteFetcher(options) {
189
198
  }
190
199
 
191
200
  // src/route/withUniformGetServerSideProps.ts
192
- var unstable_withUniformGetServerSideProps = (options) => {
201
+ var withUniformGetServerSideProps = (options) => {
193
202
  const defaultHandleRedirect = (requestUrl, matched) => {
194
203
  if (matched.redirect.targetStatusCode > 400) {
195
204
  return {
@@ -222,7 +231,10 @@ var unstable_withUniformGetServerSideProps = (options) => {
222
231
  var _a;
223
232
  return {
224
233
  contextualEditingCompositionId: (_a = context.previewData) == null ? void 0 : _a.compositionId,
225
- resolvedUrl: context.resolvedUrl
234
+ resolvedUrl: context.resolvedUrl,
235
+ // auto engage draft content when in next preview mode
236
+ // (can override with explicit setting of request options)'
237
+ defaultFetchState: context.preview ? CANVAS_DRAFT_STATE : void 0
226
238
  };
227
239
  }
228
240
  });
@@ -230,8 +242,9 @@ var unstable_withUniformGetServerSideProps = (options) => {
230
242
  };
231
243
 
232
244
  // src/route/withUniformGetStaticProps.ts
245
+ import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2 } from "@uniformdev/canvas";
233
246
  import { RedirectClient as RedirectClient2 } from "@uniformdev/redirect";
234
- var unstable_withUniformGetStaticProps = (options) => {
247
+ var withUniformGetStaticProps = (options) => {
235
248
  const defaultHandleRedirect = (requestUrl, matched) => {
236
249
  return {
237
250
  redirect: {
@@ -262,7 +275,10 @@ var unstable_withUniformGetStaticProps = (options) => {
262
275
  resolvedUrl: resolveSlugFromParams({
263
276
  params: context.params,
264
277
  param: (_b = options == null ? void 0 : options.param) != null ? _b : "route"
265
- })
278
+ }),
279
+ // auto engage draft content when in next preview mode
280
+ // (can override with explicit setting of request options)
281
+ defaultFetchState: context.preview ? CANVAS_DRAFT_STATE2 : void 0
266
282
  };
267
283
  }
268
284
  });
@@ -270,14 +286,14 @@ var unstable_withUniformGetStaticProps = (options) => {
270
286
  };
271
287
 
272
288
  // src/route/index.ts
273
- var unstable_getServerSideProps = unstable_withUniformGetServerSideProps();
274
- var unstable_getStaticProps = unstable_withUniformGetStaticProps();
289
+ var getServerSideProps = withUniformGetServerSideProps();
290
+ var getStaticProps = withUniformGetStaticProps();
275
291
  var getStaticPaths = withUniformGetStaticPaths();
276
292
  export {
293
+ getServerSideProps,
277
294
  getStaticPaths,
278
- unstable_getServerSideProps,
279
- unstable_getStaticProps,
280
- unstable_withUniformGetServerSideProps,
281
- unstable_withUniformGetStaticProps,
282
- withUniformGetStaticPaths
295
+ getStaticProps,
296
+ withUniformGetServerSideProps,
297
+ withUniformGetStaticPaths,
298
+ withUniformGetStaticProps
283
299
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "19.20.0",
3
+ "version": "19.21.0",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -63,11 +63,11 @@
63
63
  "document": "api-extractor run --local"
64
64
  },
65
65
  "dependencies": {
66
- "@uniformdev/canvas": "19.20.0",
67
- "@uniformdev/canvas-react": "19.20.0",
68
- "@uniformdev/project-map": "19.20.0",
69
- "@uniformdev/redirect": "19.20.0",
70
- "@uniformdev/richtext": "19.20.0",
66
+ "@uniformdev/canvas": "19.21.0",
67
+ "@uniformdev/canvas-react": "19.21.0",
68
+ "@uniformdev/project-map": "19.21.0",
69
+ "@uniformdev/redirect": "19.21.0",
70
+ "@uniformdev/richtext": "19.21.0",
71
71
  "colorette": "2.0.20"
72
72
  },
73
73
  "peerDependencies": {
@@ -87,5 +87,5 @@
87
87
  "publishConfig": {
88
88
  "access": "public"
89
89
  },
90
- "gitHead": "eb731fec3a9f35b9cc6d218e2a77861ccf00441a"
90
+ "gitHead": "3db4c0f1c775a5cf9677c6df294322cfbf79611e"
91
91
  }