@uniformdev/canvas-next 18.9.1-alpha.4 → 18.11.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.
@@ -3,26 +3,66 @@ import { ParsedUrlQuery } from 'querystring';
3
3
  import { c as UniformGetServerSideProps, b as UniformGetStaticProps, a as UniformPreviewData } from '../models-6ff72d91.js';
4
4
  import * as next from 'next';
5
5
  import { GetServerSideProps, GetStaticProps } from 'next';
6
- import { CanvasClient } from '@uniformdev/canvas';
7
- import { ProjectMapClient } from '@uniformdev/project-map';
6
+ import * as _uniformdev_canvas_dist_createEventBus_60ff8dc4 from '@uniformdev/canvas/dist/createEventBus-60ff8dc4';
7
+ import { CanvasClient, DataResolutionOptionNegative } from '@uniformdev/canvas';
8
+ import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
8
9
  import '@uniformdev/canvas-react';
9
10
 
10
11
  declare const withUniformGetServerSideProps: <TProps extends {
11
12
  [key: string]: any;
12
13
  } = {
13
14
  [key: string]: any;
14
- }>(callback?: UniformGetServerSideProps<TProps, querystring.ParsedUrlQuery, next.PreviewData> | undefined, options?: {
15
- client?: CanvasClient;
16
- projectMapId?: string;
17
- }) => GetServerSideProps<TProps, querystring.ParsedUrlQuery, next.PreviewData>;
15
+ }>(options?: {
16
+ /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
17
+ client?: CanvasClient | undefined;
18
+ /** Pathname prefix (or base url) that you don't want to be used on PM API request. */
19
+ prefix?: string | undefined;
20
+ /** Composition published state. If TRUE - draft composition will be used as well */
21
+ preview?: boolean | undefined;
22
+ projectMapId?: string | undefined;
23
+ /** Way to override getCompositionByNodePath request params */
24
+ requestOptions?: Partial<{
25
+ skipEnhance?: boolean | undefined;
26
+ skipPatternResolution?: boolean | undefined;
27
+ state?: number | undefined;
28
+ withComponentIDs?: boolean | undefined;
29
+ withTotalCount?: boolean | undefined;
30
+ withUIStatus?: boolean | undefined;
31
+ } & Required<Pick<_uniformdev_canvas_dist_createEventBus_60ff8dc4.C, "projectMapId" | "projectMapNodePath">> & DataResolutionOptionNegative> | undefined;
32
+ /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
33
+ callback?: UniformGetServerSideProps<TProps, querystring.ParsedUrlQuery, next.PreviewData> | undefined;
34
+ } | undefined) => GetServerSideProps<TProps, querystring.ParsedUrlQuery, next.PreviewData>;
18
35
 
19
36
  declare const withUniformGetStaticPaths: (options?: {
20
- projectMapId?: string;
21
- rootPath?: string;
22
- prefix?: string;
23
- client?: ProjectMapClient;
24
- preview?: boolean;
25
- }) => () => Promise<{
37
+ projectMapId?: string | undefined;
38
+ /** Starting path to fetch nodes from */
39
+ rootPath?: string | undefined;
40
+ /** Pathname prefix (or base url) that you don't want to be used on PM API request. */
41
+ prefix?: string | undefined;
42
+ /** Composition published state. If TRUE - draft composition will be used as well */
43
+ preview?: boolean | undefined;
44
+ /** Way to override getNodes request params */
45
+ requestOptions?: Partial<{
46
+ projectMapId: string;
47
+ projectId: string;
48
+ id?: string | undefined;
49
+ path?: string | undefined;
50
+ compositionId?: string | undefined;
51
+ limit?: number | undefined;
52
+ offset?: number | undefined;
53
+ depth?: number | undefined;
54
+ state?: number | undefined;
55
+ tree?: boolean | undefined;
56
+ search?: string | undefined;
57
+ expanded?: boolean | undefined;
58
+ withCompositionData?: boolean | undefined;
59
+ withCompositionUIStatus?: boolean | undefined;
60
+ }> | undefined;
61
+ /** Way to modify list of nodes before building array of paths */
62
+ callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
63
+ /** Way to override default ProjectMapClient, to override some constructor params, such as fetch instance, etc */
64
+ client?: ProjectMapClient | undefined;
65
+ } | undefined) => () => Promise<{
26
66
  paths: string[] | undefined;
27
67
  fallback: boolean;
28
68
  }>;
@@ -31,16 +71,33 @@ declare const withUniformGetStaticProps: <TProps extends {
31
71
  [key: string]: any;
32
72
  } = {
33
73
  [key: string]: any;
34
- }>(callback?: UniformGetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData> | undefined, options?: {
35
- projectMapId?: string;
36
- param?: string;
37
- prefix?: string;
38
- client?: CanvasClient;
74
+ }>(options: {
75
+ projectMapId?: string | undefined;
76
+ /** Name of dynamic parameter coming from getStaticPath, usually specified in page file name (e.g. [...slug].jsx will have param = 'slug' */
77
+ param: string;
78
+ /** Pathname prefix (or base url) that you don't want to be used on PM API request. */
79
+ prefix?: string | undefined;
80
+ /** Composition published state. If TRUE - draft composition will be used as well */
81
+ preview?: boolean | undefined;
82
+ /** Way to override default CanvasClient, to override some constructor params, such as fetch instance, etc */
83
+ client?: CanvasClient | undefined;
84
+ /** Way to override getCompositionByNodePath request params */
85
+ requestOptions?: Partial<{
86
+ skipEnhance?: boolean | undefined;
87
+ skipPatternResolution?: boolean | undefined;
88
+ state?: number | undefined;
89
+ withComponentIDs?: boolean | undefined;
90
+ withTotalCount?: boolean | undefined;
91
+ withUIStatus?: boolean | undefined;
92
+ } & Required<Pick<_uniformdev_canvas_dist_createEventBus_60ff8dc4.C, "projectMapId" | "projectMapNodePath">> & DataResolutionOptionNegative> | undefined;
93
+ /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
94
+ callback?: UniformGetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData> | undefined;
39
95
  }) => GetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData>;
40
96
 
41
97
  declare const getServerSideProps: next.GetServerSideProps<{
42
98
  [key: string]: any;
43
99
  }, querystring.ParsedUrlQuery, next.PreviewData>;
100
+ /** Ready to go getStaticProps for dynamic route with 'path' param for [[...path]].jsx */
44
101
  declare const getStaticProps: next.GetStaticProps<{
45
102
  [key: string]: any;
46
103
  }, querystring.ParsedUrlQuery, UniformPreviewData>;
@@ -31,7 +31,7 @@ module.exports = __toCommonJS(project_map_exports);
31
31
 
32
32
  // src/project-map/withUniformGetServerSideProps.ts
33
33
  var import_canvas = require("@uniformdev/canvas");
34
- var withUniformGetServerSideProps = (callback, options) => {
34
+ var withUniformGetServerSideProps = (options) => {
35
35
  return async function wrappedGetServerSideProps(context) {
36
36
  var _a;
37
37
  if (!process.env.UNIFORM_API_KEY) {
@@ -51,21 +51,26 @@ var withUniformGetServerSideProps = (callback, options) => {
51
51
  projectId: process.env.UNIFORM_PROJECT_ID,
52
52
  apiHost: process.env.UNIFORM_CLI_BASE_URL
53
53
  });
54
- const { preview } = context;
55
- const response = await canvasClient.unstable_getCompositionByNodePath({
56
- projectMapId,
57
- projectMapNodePath: context.resolvedUrl,
58
- state: preview ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
59
- });
60
- if (!response) {
54
+ const preview = context.preview || (options == null ? void 0 : options.preview);
55
+ let composition = void 0;
56
+ try {
57
+ const response = await canvasClient.unstable_getCompositionByNodePath({
58
+ ...options == null ? void 0 : options.requestOptions,
59
+ projectMapId,
60
+ projectMapNodePath: (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl,
61
+ state: preview ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
62
+ });
63
+ composition = response.composition;
64
+ } catch (e) {
65
+ console.error("[canvas-next] Failed to fetch composition", e);
61
66
  return {
62
67
  notFound: true
63
68
  };
64
69
  }
65
- const ret = callback ? await callback(context, response.composition) : { props: {} };
70
+ const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
66
71
  if (Object.hasOwn(ret, "props")) {
67
72
  const casted = ret;
68
- casted.props["data"] = response.composition;
73
+ casted.props["data"] = composition;
69
74
  }
70
75
  return ret;
71
76
  };
@@ -76,7 +81,7 @@ var import_canvas2 = require("@uniformdev/canvas");
76
81
  var import_project_map = require("@uniformdev/project-map");
77
82
  var withUniformGetStaticPaths = (options) => {
78
83
  return async function wrappedGetStaticPaths() {
79
- var _a, _b, _c, _d;
84
+ var _a, _b;
80
85
  if (!process.env.UNIFORM_API_KEY) {
81
86
  throw new Error("UNIFORM_API_KEY is not defined.");
82
87
  }
@@ -95,14 +100,15 @@ var withUniformGetStaticPaths = (options) => {
95
100
  apiHost: process.env.UNIFORM_CLI_BASE_URL
96
101
  });
97
102
  const response = await projectMapClient.getNodes({
103
+ ...options == null ? void 0 : options.requestOptions,
104
+ path: options == null ? void 0 : options.rootPath,
98
105
  projectMapId,
99
- path: (_c = options == null ? void 0 : options.rootPath) != null ? _c : "/",
100
- depth: -1,
101
106
  state: (options == null ? void 0 : options.preview) ? import_canvas2.CANVAS_DRAFT_STATE : import_canvas2.CANVAS_PUBLISHED_STATE
102
107
  });
103
- const paths = (_d = response.nodes) == null ? void 0 : _d.filter((node) => Boolean(node.compositionId)).map((node) => {
108
+ const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
109
+ const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
104
110
  var _a2;
105
- return ((_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : "") + node.path;
111
+ return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
106
112
  });
107
113
  return {
108
114
  paths,
@@ -126,9 +132,9 @@ var resolveSlugFromParams = ({
126
132
  };
127
133
 
128
134
  // src/project-map/withUniformGetStaticProps.ts
129
- var withUniformGetStaticProps = (callback, options) => {
135
+ var withUniformGetStaticProps = (options) => {
130
136
  return async function wrappedGetStaticProps(context) {
131
- var _a, _b, _c;
137
+ var _a, _b;
132
138
  if (!process.env.UNIFORM_API_KEY) {
133
139
  throw new Error("UNIFORM_API_KEY is not defined.");
134
140
  }
@@ -142,11 +148,11 @@ var withUniformGetStaticProps = (callback, options) => {
142
148
  );
143
149
  }
144
150
  const pathString = resolveSlugFromParams({
145
- param: (_b = options == null ? void 0 : options.param) != null ? _b : "path",
151
+ param: options == null ? void 0 : options.param,
146
152
  params: context == null ? void 0 : context.params,
147
153
  prefix: options == null ? void 0 : options.prefix
148
154
  });
149
- const canvasClient = (_c = options == null ? void 0 : options.client) != null ? _c : new import_canvas3.CanvasClient({
155
+ const canvasClient = (_b = options == null ? void 0 : options.client) != null ? _b : new import_canvas3.CanvasClient({
150
156
  apiKey: process.env.UNIFORM_API_KEY,
151
157
  projectId: process.env.UNIFORM_PROJECT_ID,
152
158
  apiHost: process.env.UNIFORM_CLI_BASE_URL
@@ -155,9 +161,10 @@ var withUniformGetStaticProps = (callback, options) => {
155
161
  let composition = void 0;
156
162
  try {
157
163
  const response = await canvasClient.unstable_getCompositionByNodePath({
164
+ ...options == null ? void 0 : options.requestOptions,
158
165
  projectMapId,
159
166
  projectMapNodePath: pathString,
160
- state: preview ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE
167
+ state: preview || (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE
161
168
  });
162
169
  composition = response.composition;
163
170
  } catch (e) {
@@ -168,7 +175,7 @@ var withUniformGetStaticProps = (callback, options) => {
168
175
  };
169
176
  }
170
177
  }
171
- const ret = callback ? await callback(context, composition) : { props: {} };
178
+ const ret = options.callback ? await options.callback(context, composition) : { props: {} };
172
179
  if (composition && Object.hasOwn(ret, "props")) {
173
180
  const casted = ret;
174
181
  casted.props["data"] = composition;
@@ -179,7 +186,7 @@ var withUniformGetStaticProps = (callback, options) => {
179
186
 
180
187
  // src/project-map/index.ts
181
188
  var getServerSideProps = withUniformGetServerSideProps();
182
- var getStaticProps = withUniformGetStaticProps();
189
+ var getStaticProps = withUniformGetStaticProps({ param: "path" });
183
190
  var getStaticPaths = withUniformGetStaticPaths();
184
191
  // Annotate the CommonJS export names for ESM import in node:
185
192
  0 && (module.exports = {
@@ -3,8 +3,12 @@ import {
3
3
  } from "../chunk-SH3D2DYY.mjs";
4
4
 
5
5
  // src/project-map/withUniformGetServerSideProps.ts
6
- import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE, CanvasClient } from "@uniformdev/canvas";
7
- var withUniformGetServerSideProps = (callback, options) => {
6
+ import {
7
+ CANVAS_DRAFT_STATE,
8
+ CANVAS_PUBLISHED_STATE,
9
+ CanvasClient
10
+ } from "@uniformdev/canvas";
11
+ var withUniformGetServerSideProps = (options) => {
8
12
  return async function wrappedGetServerSideProps(context) {
9
13
  var _a;
10
14
  if (!process.env.UNIFORM_API_KEY) {
@@ -24,21 +28,26 @@ var withUniformGetServerSideProps = (callback, options) => {
24
28
  projectId: process.env.UNIFORM_PROJECT_ID,
25
29
  apiHost: process.env.UNIFORM_CLI_BASE_URL
26
30
  });
27
- const { preview } = context;
28
- const response = await canvasClient.unstable_getCompositionByNodePath({
29
- projectMapId,
30
- projectMapNodePath: context.resolvedUrl,
31
- state: preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
32
- });
33
- if (!response) {
31
+ const preview = context.preview || (options == null ? void 0 : options.preview);
32
+ let composition = void 0;
33
+ try {
34
+ const response = await canvasClient.unstable_getCompositionByNodePath({
35
+ ...options == null ? void 0 : options.requestOptions,
36
+ projectMapId,
37
+ projectMapNodePath: (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl,
38
+ state: preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
39
+ });
40
+ composition = response.composition;
41
+ } catch (e) {
42
+ console.error("[canvas-next] Failed to fetch composition", e);
34
43
  return {
35
44
  notFound: true
36
45
  };
37
46
  }
38
- const ret = callback ? await callback(context, response.composition) : { props: {} };
47
+ const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
39
48
  if (Object.hasOwn(ret, "props")) {
40
49
  const casted = ret;
41
- casted.props["data"] = response.composition;
50
+ casted.props["data"] = composition;
42
51
  }
43
52
  return ret;
44
53
  };
@@ -46,10 +55,12 @@ var withUniformGetServerSideProps = (callback, options) => {
46
55
 
47
56
  // src/project-map/withUniformGetStaticPaths.ts
48
57
  import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
49
- import { ProjectMapClient } from "@uniformdev/project-map";
58
+ import {
59
+ ProjectMapClient
60
+ } from "@uniformdev/project-map";
50
61
  var withUniformGetStaticPaths = (options) => {
51
62
  return async function wrappedGetStaticPaths() {
52
- var _a, _b, _c, _d;
63
+ var _a, _b;
53
64
  if (!process.env.UNIFORM_API_KEY) {
54
65
  throw new Error("UNIFORM_API_KEY is not defined.");
55
66
  }
@@ -68,14 +79,15 @@ var withUniformGetStaticPaths = (options) => {
68
79
  apiHost: process.env.UNIFORM_CLI_BASE_URL
69
80
  });
70
81
  const response = await projectMapClient.getNodes({
82
+ ...options == null ? void 0 : options.requestOptions,
83
+ path: options == null ? void 0 : options.rootPath,
71
84
  projectMapId,
72
- path: (_c = options == null ? void 0 : options.rootPath) != null ? _c : "/",
73
- depth: -1,
74
85
  state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
75
86
  });
76
- const paths = (_d = response.nodes) == null ? void 0 : _d.filter((node) => Boolean(node.compositionId)).map((node) => {
87
+ const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
88
+ const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
77
89
  var _a2;
78
- return ((_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : "") + node.path;
90
+ return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
79
91
  });
80
92
  return {
81
93
  paths,
@@ -90,9 +102,9 @@ import {
90
102
  CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
91
103
  CanvasClient as CanvasClient2
92
104
  } from "@uniformdev/canvas";
93
- var withUniformGetStaticProps = (callback, options) => {
105
+ var withUniformGetStaticProps = (options) => {
94
106
  return async function wrappedGetStaticProps(context) {
95
- var _a, _b, _c;
107
+ var _a, _b;
96
108
  if (!process.env.UNIFORM_API_KEY) {
97
109
  throw new Error("UNIFORM_API_KEY is not defined.");
98
110
  }
@@ -106,11 +118,11 @@ var withUniformGetStaticProps = (callback, options) => {
106
118
  );
107
119
  }
108
120
  const pathString = resolveSlugFromParams({
109
- param: (_b = options == null ? void 0 : options.param) != null ? _b : "path",
121
+ param: options == null ? void 0 : options.param,
110
122
  params: context == null ? void 0 : context.params,
111
123
  prefix: options == null ? void 0 : options.prefix
112
124
  });
113
- const canvasClient = (_c = options == null ? void 0 : options.client) != null ? _c : new CanvasClient2({
125
+ const canvasClient = (_b = options == null ? void 0 : options.client) != null ? _b : new CanvasClient2({
114
126
  apiKey: process.env.UNIFORM_API_KEY,
115
127
  projectId: process.env.UNIFORM_PROJECT_ID,
116
128
  apiHost: process.env.UNIFORM_CLI_BASE_URL
@@ -119,9 +131,10 @@ var withUniformGetStaticProps = (callback, options) => {
119
131
  let composition = void 0;
120
132
  try {
121
133
  const response = await canvasClient.unstable_getCompositionByNodePath({
134
+ ...options == null ? void 0 : options.requestOptions,
122
135
  projectMapId,
123
136
  projectMapNodePath: pathString,
124
- state: preview ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
137
+ state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
125
138
  });
126
139
  composition = response.composition;
127
140
  } catch (e) {
@@ -132,7 +145,7 @@ var withUniformGetStaticProps = (callback, options) => {
132
145
  };
133
146
  }
134
147
  }
135
- const ret = callback ? await callback(context, composition) : { props: {} };
148
+ const ret = options.callback ? await options.callback(context, composition) : { props: {} };
136
149
  if (composition && Object.hasOwn(ret, "props")) {
137
150
  const casted = ret;
138
151
  casted.props["data"] = composition;
@@ -143,7 +156,7 @@ var withUniformGetStaticProps = (callback, options) => {
143
156
 
144
157
  // src/project-map/index.ts
145
158
  var getServerSideProps = withUniformGetServerSideProps();
146
- var getStaticProps = withUniformGetStaticProps();
159
+ var getStaticProps = withUniformGetStaticProps({ param: "path" });
147
160
  var getStaticPaths = withUniformGetStaticPaths();
148
161
  export {
149
162
  getServerSideProps,
@@ -3,24 +3,43 @@ import { GetServerSideProps, GetStaticProps } from 'next';
3
3
  import * as querystring from 'querystring';
4
4
  import { ParsedUrlQuery } from 'querystring';
5
5
  import { c as UniformGetServerSideProps, a as UniformPreviewData, b as UniformGetStaticProps } from '../models-6ff72d91.js';
6
- import { CanvasClient } from '@uniformdev/canvas';
6
+ import * as _uniformdev_canvas_dist_createEventBus_60ff8dc4 from '@uniformdev/canvas/dist/createEventBus-60ff8dc4';
7
+ import { CanvasClient, DataResolutionOptionNegative, CompositionGetParameters, CompositionGetResponse } from '@uniformdev/canvas';
7
8
  import '@uniformdev/canvas-react';
8
9
 
9
10
  declare const withUniformGetServerSideProps: <TProps extends {
10
11
  [key: string]: any;
11
12
  } = {
12
13
  [key: string]: any;
13
- }>(callback?: UniformGetServerSideProps<TProps, ParsedUrlQuery, next.PreviewData> | undefined, options?: {
14
- param?: string;
15
- prefix?: string;
16
- client?: CanvasClient;
17
- }) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
14
+ }>(options?: {
15
+ param: string;
16
+ prefix?: string | undefined;
17
+ preview?: boolean | undefined;
18
+ client?: CanvasClient | undefined;
19
+ requestOptions?: Partial<{
20
+ skipEnhance?: boolean | undefined;
21
+ skipPatternResolution?: boolean | undefined;
22
+ state?: number | undefined;
23
+ withComponentIDs?: boolean | undefined;
24
+ withTotalCount?: boolean | undefined;
25
+ withUIStatus?: boolean | undefined;
26
+ } & Required<Pick<_uniformdev_canvas_dist_createEventBus_60ff8dc4.C, "slug">> & DataResolutionOptionNegative> | undefined;
27
+ callback?: UniformGetServerSideProps<TProps, ParsedUrlQuery, next.PreviewData> | undefined;
28
+ } | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
18
29
 
19
30
  declare const withUniformGetStaticPaths: (options?: {
20
- prefix?: string;
21
- client?: CanvasClient;
22
- preview?: boolean;
23
- }) => () => Promise<{
31
+ projectMapId?: string | undefined;
32
+ /** Pathname prefix (or base url) that you don't want to be used on PM API request. */
33
+ prefix?: string | undefined;
34
+ /** Composition published state. If TRUE - draft composition will be used as well */
35
+ preview?: boolean | undefined;
36
+ /** Way to override getCompositionList request params */
37
+ requestOptions?: Partial<CompositionGetParameters> | undefined;
38
+ /** Way to modify list of slugs before building array of paths */
39
+ callback?: ((compositions: CompositionGetResponse[]) => Promise<CompositionGetResponse[]>) | undefined;
40
+ /** Way to override default ProjectMapClient, to override some constructor params, such as fetch instance, etc */
41
+ client?: CanvasClient | undefined;
42
+ } | undefined) => () => Promise<{
24
43
  paths: string[];
25
44
  fallback: boolean;
26
45
  }>;
@@ -29,15 +48,32 @@ declare const withUniformGetStaticProps: <TProps extends {
29
48
  [key: string]: any;
30
49
  } = {
31
50
  [key: string]: any;
32
- }>(callback?: UniformGetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData> | undefined, options?: {
33
- param?: string;
34
- prefix?: string;
35
- client?: CanvasClient;
51
+ }>(options: {
52
+ /** Name of dynamic parameter coming from getStaticPath, usually specified in page file name (e.g. [...slug].jsx will have param = 'slug' */
53
+ param: string;
54
+ /** Pathname prefix (or base url) that you don't want to be used on PM API request. */
55
+ prefix?: string | undefined;
56
+ /** Composition published state. If TRUE - draft composition will be used as well */
57
+ preview?: boolean | undefined;
58
+ /** Way to override default CanvasClient, to override some constructor params, such as fetch instance, etc */
59
+ client?: CanvasClient | undefined;
60
+ /** Way to override getCompositionBySlug request params */
61
+ requestOptions?: Partial<{
62
+ skipEnhance?: boolean | undefined;
63
+ skipPatternResolution?: boolean | undefined;
64
+ state?: number | undefined;
65
+ withComponentIDs?: boolean | undefined;
66
+ withTotalCount?: boolean | undefined;
67
+ withUIStatus?: boolean | undefined;
68
+ } & Required<Pick<_uniformdev_canvas_dist_createEventBus_60ff8dc4.C, "slug">> & DataResolutionOptionNegative> | undefined;
69
+ /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
70
+ callback?: UniformGetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData> | undefined;
36
71
  }) => GetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData>;
37
72
 
38
73
  declare const getServerSideProps: next.GetServerSideProps<{
39
74
  [key: string]: any;
40
75
  }, querystring.ParsedUrlQuery, UniformPreviewData>;
76
+ /** Ready to go getStaticProps for dynamic route with 'slug' param for [[...slug]].jsx */
41
77
  declare const getStaticProps: next.GetStaticProps<{
42
78
  [key: string]: any;
43
79
  }, querystring.ParsedUrlQuery, UniformPreviewData>;
@@ -44,7 +44,7 @@ var resolveSlugFromParams = ({
44
44
  };
45
45
 
46
46
  // src/slug/withUniformGetServerSideProps.ts
47
- var withUniformGetServerSideProps = (callback, options) => {
47
+ var withUniformGetServerSideProps = (options) => {
48
48
  return async function wrappedGetServerSideProps(context) {
49
49
  if (!process.env.UNIFORM_API_KEY) {
50
50
  throw new Error("UNIFORM_API_KEY is not defined.");
@@ -66,8 +66,9 @@ var withUniformGetServerSideProps = (callback, options) => {
66
66
  let composition = void 0;
67
67
  try {
68
68
  const response = await canvasClient.getCompositionBySlug({
69
+ ...options == null ? void 0 : options.requestOptions,
69
70
  slug: slugString,
70
- state: preview ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
71
+ state: preview || (options == null ? void 0 : options.preview) ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
71
72
  });
72
73
  composition = response.composition;
73
74
  } catch (e) {
@@ -78,7 +79,7 @@ var withUniformGetServerSideProps = (callback, options) => {
78
79
  };
79
80
  }
80
81
  }
81
- const ret = callback ? await callback(context, composition) : { props: {} };
82
+ const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
82
83
  if (composition && Object.hasOwn(ret, "props")) {
83
84
  const casted = ret;
84
85
  casted.props["data"] = composition;
@@ -104,13 +105,13 @@ var withUniformGetStaticPaths = (options) => {
104
105
  apiHost: process.env.UNIFORM_CLI_BASE_URL
105
106
  });
106
107
  const response = await canvasClient.getCompositionList({
108
+ ...options == null ? void 0 : options.requestOptions,
107
109
  state: (options == null ? void 0 : options.preview) ? import_canvas2.CANVAS_DRAFT_STATE : import_canvas2.CANVAS_PUBLISHED_STATE
108
110
  });
109
- const paths = response.compositions.filter((reference) => {
111
+ const compositions = (options == null ? void 0 : options.callback) ? await options.callback(response.compositions) : response.compositions;
112
+ const paths = compositions.filter((reference) => !!reference.composition._slug).map((composition) => {
110
113
  var _a2;
111
- return !!((_a2 = reference.composition._slug) == null ? void 0 : _a2.length);
112
- }).map((composition) => {
113
- return composition.composition._slug;
114
+ return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${composition.composition._slug}`;
114
115
  });
115
116
  return {
116
117
  paths,
@@ -121,7 +122,7 @@ var withUniformGetStaticPaths = (options) => {
121
122
 
122
123
  // src/slug/withUniformGetStaticProps.ts
123
124
  var import_canvas3 = require("@uniformdev/canvas");
124
- var withUniformGetStaticProps = (callback, options) => {
125
+ var withUniformGetStaticProps = (options) => {
125
126
  return async function wrappedGetStaticProps(context) {
126
127
  var _a;
127
128
  if (!process.env.UNIFORM_API_KEY) {
@@ -145,7 +146,8 @@ var withUniformGetStaticProps = (callback, options) => {
145
146
  try {
146
147
  const response = await canvasClient.getCompositionBySlug({
147
148
  slug: slugString,
148
- state: preview ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE
149
+ state: preview || (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE,
150
+ ...options == null ? void 0 : options.requestOptions
149
151
  });
150
152
  composition = response.composition;
151
153
  } catch (e) {
@@ -156,7 +158,7 @@ var withUniformGetStaticProps = (callback, options) => {
156
158
  };
157
159
  }
158
160
  }
159
- const ret = callback ? await callback(context, composition) : { props: {} };
161
+ const ret = options.callback ? await options.callback(context, composition) : { props: {} };
160
162
  if (composition && Object.hasOwn(ret, "props")) {
161
163
  const casted = ret;
162
164
  casted.props["data"] = composition;
@@ -167,7 +169,7 @@ var withUniformGetStaticProps = (callback, options) => {
167
169
 
168
170
  // src/slug/index.ts
169
171
  var getServerSideProps = withUniformGetServerSideProps();
170
- var getStaticProps = withUniformGetStaticProps();
172
+ var getStaticProps = withUniformGetStaticProps({ param: "slug" });
171
173
  var getStaticPaths = withUniformGetStaticPaths();
172
174
  // Annotate the CommonJS export names for ESM import in node:
173
175
  0 && (module.exports = {
@@ -8,7 +8,7 @@ import {
8
8
  CANVAS_PUBLISHED_STATE,
9
9
  CanvasClient
10
10
  } from "@uniformdev/canvas";
11
- var withUniformGetServerSideProps = (callback, options) => {
11
+ var withUniformGetServerSideProps = (options) => {
12
12
  return async function wrappedGetServerSideProps(context) {
13
13
  if (!process.env.UNIFORM_API_KEY) {
14
14
  throw new Error("UNIFORM_API_KEY is not defined.");
@@ -30,8 +30,9 @@ var withUniformGetServerSideProps = (callback, options) => {
30
30
  let composition = void 0;
31
31
  try {
32
32
  const response = await canvasClient.getCompositionBySlug({
33
+ ...options == null ? void 0 : options.requestOptions,
33
34
  slug: slugString,
34
- state: preview ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
35
+ state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
35
36
  });
36
37
  composition = response.composition;
37
38
  } catch (e) {
@@ -42,7 +43,7 @@ var withUniformGetServerSideProps = (callback, options) => {
42
43
  };
43
44
  }
44
45
  }
45
- const ret = callback ? await callback(context, composition) : { props: {} };
46
+ const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
46
47
  if (composition && Object.hasOwn(ret, "props")) {
47
48
  const casted = ret;
48
49
  casted.props["data"] = composition;
@@ -52,7 +53,11 @@ var withUniformGetServerSideProps = (callback, options) => {
52
53
  };
53
54
 
54
55
  // src/slug/withUniformGetStaticPaths.ts
55
- import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2, CanvasClient as CanvasClient2 } from "@uniformdev/canvas";
56
+ import {
57
+ CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2,
58
+ CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2,
59
+ CanvasClient as CanvasClient2
60
+ } from "@uniformdev/canvas";
56
61
  var withUniformGetStaticPaths = (options) => {
57
62
  return async function wrappedGetStaticPaths() {
58
63
  var _a;
@@ -68,13 +73,13 @@ var withUniformGetStaticPaths = (options) => {
68
73
  apiHost: process.env.UNIFORM_CLI_BASE_URL
69
74
  });
70
75
  const response = await canvasClient.getCompositionList({
76
+ ...options == null ? void 0 : options.requestOptions,
71
77
  state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
72
78
  });
73
- const paths = response.compositions.filter((reference) => {
79
+ const compositions = (options == null ? void 0 : options.callback) ? await options.callback(response.compositions) : response.compositions;
80
+ const paths = compositions.filter((reference) => !!reference.composition._slug).map((composition) => {
74
81
  var _a2;
75
- return !!((_a2 = reference.composition._slug) == null ? void 0 : _a2.length);
76
- }).map((composition) => {
77
- return composition.composition._slug;
82
+ return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${composition.composition._slug}`;
78
83
  });
79
84
  return {
80
85
  paths,
@@ -89,7 +94,7 @@ import {
89
94
  CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
90
95
  CanvasClient as CanvasClient3
91
96
  } from "@uniformdev/canvas";
92
- var withUniformGetStaticProps = (callback, options) => {
97
+ var withUniformGetStaticProps = (options) => {
93
98
  return async function wrappedGetStaticProps(context) {
94
99
  var _a;
95
100
  if (!process.env.UNIFORM_API_KEY) {
@@ -113,7 +118,8 @@ var withUniformGetStaticProps = (callback, options) => {
113
118
  try {
114
119
  const response = await canvasClient.getCompositionBySlug({
115
120
  slug: slugString,
116
- state: preview ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
121
+ state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3,
122
+ ...options == null ? void 0 : options.requestOptions
117
123
  });
118
124
  composition = response.composition;
119
125
  } catch (e) {
@@ -124,7 +130,7 @@ var withUniformGetStaticProps = (callback, options) => {
124
130
  };
125
131
  }
126
132
  }
127
- const ret = callback ? await callback(context, composition) : { props: {} };
133
+ const ret = options.callback ? await options.callback(context, composition) : { props: {} };
128
134
  if (composition && Object.hasOwn(ret, "props")) {
129
135
  const casted = ret;
130
136
  casted.props["data"] = composition;
@@ -135,7 +141,7 @@ var withUniformGetStaticProps = (callback, options) => {
135
141
 
136
142
  // src/slug/index.ts
137
143
  var getServerSideProps = withUniformGetServerSideProps();
138
- var getStaticProps = withUniformGetStaticProps();
144
+ var getStaticProps = withUniformGetStaticProps({ param: "slug" });
139
145
  var getStaticPaths = withUniformGetStaticPaths();
140
146
  export {
141
147
  getServerSideProps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "18.9.1-alpha.4+62fc5d7ec",
3
+ "version": "18.11.0",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -52,9 +52,9 @@
52
52
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\""
53
53
  },
54
54
  "dependencies": {
55
- "@uniformdev/canvas": "18.9.1-alpha.4+62fc5d7ec",
56
- "@uniformdev/canvas-react": "18.9.1-alpha.4+62fc5d7ec",
57
- "@uniformdev/project-map": "18.9.1-alpha.4+62fc5d7ec"
55
+ "@uniformdev/canvas": "18.11.0",
56
+ "@uniformdev/canvas-react": "18.11.0",
57
+ "@uniformdev/project-map": "18.11.0"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "next": ">= 12.0.0",
@@ -73,5 +73,5 @@
73
73
  "publishConfig": {
74
74
  "access": "public"
75
75
  },
76
- "gitHead": "62fc5d7ecb13c2a8e74fab5b19524479c9d550df"
76
+ "gitHead": "87433008a407efd686f3ab0d37eb5ceece6e66db"
77
77
  }