@uniformdev/canvas-next 19.79.0 → 19.79.1-alpha.7

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.
@@ -1,6 +1,3 @@
1
- import {
2
- withUniformGetStaticPaths
3
- } from "../chunk-ZLQ2WCJC.mjs";
4
1
  import {
5
2
  logCompositionResponse
6
3
  } from "../chunk-JQWYBVLI.mjs";
@@ -8,6 +5,19 @@ import {
8
5
  resolveSlugFromParams
9
6
  } from "../chunk-TR7V6ABJ.mjs";
10
7
 
8
+ // src/route/withUniformGetServerSideProps.ts
9
+ import { CANVAS_DRAFT_STATE } from "@uniformdev/canvas";
10
+ import { getTargetVariableExpandedUrl } from "@uniformdev/redirect";
11
+
12
+ // src/route/createRouteFetcher.ts
13
+ import {
14
+ ApiClientError,
15
+ CANVAS_PUBLISHED_STATE,
16
+ EMPTY_COMPOSITION,
17
+ RouteClient
18
+ } from "@uniformdev/canvas";
19
+ import { red as red2 } from "colorette";
20
+
11
21
  // src/logging/logCompositionRouteResponse.ts
12
22
  import { gray, green, red, yellow } from "colorette";
13
23
  function logRouteCompositionResponse(matched, duration) {
@@ -56,18 +66,7 @@ function logRouteResponse(response, duration) {
56
66
  logRouteCompositionResponse(response, duration);
57
67
  }
58
68
 
59
- // src/route/withUniformGetServerSideProps.ts
60
- import { CANVAS_DRAFT_STATE } from "@uniformdev/canvas";
61
- import { getTargetVariableExpandedUrl } from "@uniformdev/redirect";
62
-
63
69
  // src/route/createRouteFetcher.ts
64
- import {
65
- ApiClientError,
66
- CANVAS_PUBLISHED_STATE,
67
- EMPTY_COMPOSITION,
68
- RouteClient
69
- } from "@uniformdev/canvas";
70
- import { red as red2 } from "colorette";
71
70
  function createRouteFetcher(options) {
72
71
  const {
73
72
  handleNotFound,
@@ -209,7 +208,8 @@ var withUniformGetServerSideProps = (options) => {
209
208
  return {
210
209
  redirect: {
211
210
  destination: getTargetVariableExpandedUrl(absoluteUrl, matched.redirect),
212
- statusCode: matched.redirect.targetStatusCode
211
+ statusCode: matched.redirect.targetStatusCode,
212
+ basePath: matched.redirect.targetPreserveIncomingDomain === false || matched.redirect.targetPreserveIncomingProtocol === false ? false : void 0
213
213
  }
214
214
  };
215
215
  };
@@ -242,8 +242,64 @@ var withUniformGetServerSideProps = (options) => {
242
242
  return routeFetcher;
243
243
  };
244
244
 
245
+ // src/route/withUniformGetStaticPaths.ts
246
+ import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
247
+ import {
248
+ ProjectMapClient
249
+ } from "@uniformdev/project-map";
250
+ import { RedirectClient } from "@uniformdev/redirect";
251
+ var findChildRedirects = async (allRedirects, parentPath) => {
252
+ const children = [];
253
+ let redirect = await allRedirects.next();
254
+ while (!redirect.done) {
255
+ const index = parentPath ? redirect.value.redirect.sourceUrl.indexOf(parentPath) : 0;
256
+ if (index > -1) {
257
+ children.push(redirect.value);
258
+ }
259
+ redirect = await allRedirects.next();
260
+ }
261
+ return children;
262
+ };
263
+ var withUniformGetStaticPaths = (options) => {
264
+ return async function wrappedGetStaticPaths() {
265
+ var _a, _b, _c;
266
+ const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
267
+ const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
268
+ apiKey: process.env.UNIFORM_API_KEY,
269
+ projectId: process.env.UNIFORM_PROJECT_ID,
270
+ apiHost: process.env.UNIFORM_CLI_BASE_URL
271
+ });
272
+ const finalRedirectClient = (_c = options == null ? void 0 : options.redirectClient) != null ? _c : new RedirectClient({
273
+ apiKey: process.env.UNIFORM_API_KEY,
274
+ projectId: process.env.UNIFORM_PROJECT_ID,
275
+ apiHost: process.env.UNIFORM_CLI_BASE_URL
276
+ });
277
+ const [response, redirectResponse] = await Promise.all([
278
+ projectMapClient.getNodes({
279
+ ...options == null ? void 0 : options.requestOptions,
280
+ path: options == null ? void 0 : options.rootPath,
281
+ projectMapId,
282
+ state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
283
+ }),
284
+ finalRedirectClient.getAllRedirects()
285
+ ]);
286
+ const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
287
+ const redirectSources = (await findChildRedirects(redirectResponse, options == null ? void 0 : options.rootPath)).map(
288
+ (r) => r.redirect.sourceUrl
289
+ );
290
+ const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
291
+ var _a2;
292
+ return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
293
+ });
294
+ return {
295
+ paths: [...paths != null ? paths : [], ...redirectSources],
296
+ fallback: true
297
+ };
298
+ };
299
+ };
300
+
245
301
  // src/route/withUniformGetStaticProps.ts
246
- import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2 } from "@uniformdev/canvas";
302
+ import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3 } from "@uniformdev/canvas";
247
303
  import { getTargetVariableExpandedUrl as getTargetVariableExpandedUrl2 } from "@uniformdev/redirect";
248
304
  var withUniformGetStaticProps = (options) => {
249
305
  const defaultHandleRedirect = (requestUrl, matched) => {
@@ -279,7 +335,7 @@ var withUniformGetStaticProps = (options) => {
279
335
  }),
280
336
  // auto engage draft content when in next preview mode
281
337
  // (can override with explicit setting of request options)
282
- defaultFetchState: context.preview ? CANVAS_DRAFT_STATE2 : void 0
338
+ defaultFetchState: context.preview ? CANVAS_DRAFT_STATE3 : void 0
283
339
  };
284
340
  }
285
341
  });
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, GetServerSideProps, GetStaticPropsContext, GetStaticProps } from 'next';
3
- import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models-f9fd03c4.js';
3
+ import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models--s4UGr5M.mjs';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
@@ -30,6 +30,7 @@ declare const withUniformGetServerSideProps: <TProps extends {
30
30
  withTotalCount?: boolean | undefined;
31
31
  withUIStatus?: boolean | undefined;
32
32
  withContentSourceMap?: boolean | undefined;
33
+ locale?: string | undefined;
33
34
  } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
34
35
  callback?: UniformGetServerSideProps<TProps> | undefined;
35
36
  /** Disables logging of response information and timings */
@@ -77,6 +78,7 @@ declare const withUniformGetStaticProps: <TProps extends {
77
78
  withTotalCount?: boolean | undefined;
78
79
  withUIStatus?: boolean | undefined;
79
80
  withContentSourceMap?: boolean | undefined;
81
+ locale?: string | undefined;
80
82
  } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
81
83
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
82
84
  callback?: UniformGetStaticProps<TProps> | undefined;
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, GetServerSideProps, GetStaticPropsContext, GetStaticProps } from 'next';
3
- import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models-f9fd03c4.js';
3
+ import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models--s4UGr5M.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
@@ -30,6 +30,7 @@ declare const withUniformGetServerSideProps: <TProps extends {
30
30
  withTotalCount?: boolean | undefined;
31
31
  withUIStatus?: boolean | undefined;
32
32
  withContentSourceMap?: boolean | undefined;
33
+ locale?: string | undefined;
33
34
  } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
34
35
  callback?: UniformGetServerSideProps<TProps> | undefined;
35
36
  /** Disables logging of response information and timings */
@@ -77,6 +78,7 @@ declare const withUniformGetStaticProps: <TProps extends {
77
78
  withTotalCount?: boolean | undefined;
78
79
  withUIStatus?: boolean | undefined;
79
80
  withContentSourceMap?: boolean | undefined;
81
+ locale?: string | undefined;
80
82
  } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
81
83
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
82
84
  callback?: UniformGetStaticProps<TProps> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "19.79.0",
3
+ "version": "19.79.1-alpha.7+bd4b0c6f4",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -67,11 +67,11 @@
67
67
  "document": "api-extractor run --local"
68
68
  },
69
69
  "dependencies": {
70
- "@uniformdev/canvas": "19.79.0",
71
- "@uniformdev/canvas-react": "19.79.0",
72
- "@uniformdev/project-map": "19.79.0",
73
- "@uniformdev/redirect": "19.79.0",
74
- "@uniformdev/richtext": "19.79.0",
70
+ "@uniformdev/canvas": "19.79.1-alpha.7+bd4b0c6f4",
71
+ "@uniformdev/canvas-react": "19.79.1-alpha.7+bd4b0c6f4",
72
+ "@uniformdev/project-map": "19.79.1-alpha.7+bd4b0c6f4",
73
+ "@uniformdev/redirect": "19.79.1-alpha.7+bd4b0c6f4",
74
+ "@uniformdev/richtext": "19.79.1-alpha.7+bd4b0c6f4",
75
75
  "colorette": "2.0.20"
76
76
  },
77
77
  "peerDependencies": {
@@ -80,7 +80,7 @@
80
80
  "react-dom": ">=16"
81
81
  },
82
82
  "devDependencies": {
83
- "@types/react": "18.2.21",
83
+ "@types/react": "18.2.40",
84
84
  "next": "13.4.12",
85
85
  "react": "18.2.0",
86
86
  "react-dom": "18.2.0"
@@ -91,5 +91,5 @@
91
91
  "publishConfig": {
92
92
  "access": "public"
93
93
  },
94
- "gitHead": "78f5ededbaa1a67d58d808eac23ab64769e14e10"
94
+ "gitHead": "bd4b0c6f4a67549f8eb7e127a85927c798e7eed0"
95
95
  }
@@ -1,166 +0,0 @@
1
- import {
2
- logCompositionResponse
3
- } from "./chunk-JQWYBVLI.mjs";
4
- import {
5
- resolveSlugFromParams
6
- } from "./chunk-TR7V6ABJ.mjs";
7
-
8
- // src/project-map/withUniformGetServerSideProps.ts
9
- import {
10
- CANVAS_DRAFT_STATE,
11
- CANVAS_PUBLISHED_STATE,
12
- CanvasClient,
13
- EMPTY_COMPOSITION
14
- } from "@uniformdev/canvas";
15
- var withUniformGetServerSideProps = (options) => {
16
- const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
17
- apiKey: process.env.UNIFORM_API_KEY,
18
- projectId: process.env.UNIFORM_PROJECT_ID,
19
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
20
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
21
- });
22
- return async function wrappedGetServerSideProps(context) {
23
- var _a, _b;
24
- const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
25
- const { preview, previewData } = context;
26
- let composition = void 0;
27
- let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
28
- if (options == null ? void 0 : options.modifyPath) {
29
- nodePath = options.modifyPath(nodePath, context);
30
- }
31
- if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
32
- composition = { ...EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION._id };
33
- } else {
34
- try {
35
- const time = Date.now();
36
- const response = await canvasClient.getCompositionByNodePath({
37
- ...options == null ? void 0 : options.requestOptions,
38
- projectMapId,
39
- projectMapNodePath: nodePath,
40
- state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
41
- });
42
- const duration = Date.now() - time;
43
- composition = response.composition;
44
- if (!(options == null ? void 0 : options.silent)) {
45
- logCompositionResponse(response, duration);
46
- }
47
- } catch (e) {
48
- console.error("[canvas-next] Failed to fetch composition", e);
49
- return {
50
- notFound: true
51
- };
52
- }
53
- }
54
- const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
55
- if (Object.hasOwn(ret, "props")) {
56
- const casted = ret;
57
- casted.props["data"] = composition;
58
- }
59
- return ret;
60
- };
61
- };
62
-
63
- // src/project-map/withUniformGetStaticPaths.ts
64
- import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
65
- import {
66
- ProjectMapClient
67
- } from "@uniformdev/project-map";
68
- var withUniformGetStaticPaths = (options) => {
69
- return async function wrappedGetStaticPaths() {
70
- var _a, _b;
71
- const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
72
- const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
73
- apiKey: process.env.UNIFORM_API_KEY,
74
- projectId: process.env.UNIFORM_PROJECT_ID,
75
- apiHost: process.env.UNIFORM_CLI_BASE_URL
76
- });
77
- const response = await projectMapClient.getNodes({
78
- ...options == null ? void 0 : options.requestOptions,
79
- path: options == null ? void 0 : options.rootPath,
80
- projectMapId,
81
- state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
82
- });
83
- const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
84
- const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
85
- var _a2;
86
- return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
87
- });
88
- return {
89
- paths,
90
- fallback: true
91
- };
92
- };
93
- };
94
-
95
- // src/project-map/withUniformGetStaticProps.ts
96
- import {
97
- CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
98
- CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
99
- CanvasClient as CanvasClient2,
100
- EMPTY_COMPOSITION as EMPTY_COMPOSITION2
101
- } from "@uniformdev/canvas";
102
- var withUniformGetStaticProps = (options) => {
103
- var _a;
104
- const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient2({
105
- apiKey: process.env.UNIFORM_API_KEY,
106
- projectId: process.env.UNIFORM_PROJECT_ID,
107
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
108
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
109
- });
110
- return async function wrappedGetStaticProps(context) {
111
- var _a2, _b;
112
- const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
113
- let pathString = resolveSlugFromParams({
114
- param: options == null ? void 0 : options.param,
115
- params: context == null ? void 0 : context.params
116
- });
117
- if (options == null ? void 0 : options.modifyPath) {
118
- pathString = options.modifyPath(pathString, context);
119
- }
120
- const { preview, previewData } = context;
121
- let composition = void 0;
122
- if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
123
- composition = { ...EMPTY_COMPOSITION2, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION2._id };
124
- } else {
125
- try {
126
- const time = Date.now();
127
- const response = await canvasClient.getCompositionByNodePath({
128
- ...options == null ? void 0 : options.requestOptions,
129
- projectMapId,
130
- projectMapNodePath: pathString,
131
- state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
132
- });
133
- const duration = Date.now() - time;
134
- composition = response.composition;
135
- if (!(options == null ? void 0 : options.silent)) {
136
- logCompositionResponse(response, duration);
137
- }
138
- } catch (e) {
139
- console.error("[canvas-next] Failed to fetch composition", e);
140
- return {
141
- notFound: true
142
- };
143
- }
144
- }
145
- const ret = options.callback ? await options.callback(context, composition) : { props: {} };
146
- if (composition && Object.hasOwn(ret, "props")) {
147
- const casted = ret;
148
- casted.props["data"] = composition;
149
- }
150
- return ret;
151
- };
152
- };
153
-
154
- // src/project-map/index.ts
155
- var getServerSideProps = withUniformGetServerSideProps();
156
- var getStaticProps = withUniformGetStaticProps({ param: "path" });
157
- var getStaticPaths = withUniformGetStaticPaths();
158
-
159
- export {
160
- withUniformGetServerSideProps,
161
- withUniformGetStaticPaths,
162
- withUniformGetStaticProps,
163
- getServerSideProps,
164
- getStaticProps,
165
- getStaticPaths
166
- };
@@ -1,39 +0,0 @@
1
- import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
2
-
3
- declare const withUniformGetStaticPaths: (options?: {
4
- projectMapId?: string | undefined;
5
- /** Starting path to fetch nodes from */
6
- rootPath?: string | undefined;
7
- /** A string that you want prepended to paths returned by your project map. Useful when calling from a nested folder which is not part of your project map structure */
8
- prefix?: string | undefined;
9
- /** Set to true if you want to include draft compositions */
10
- preview?: boolean | undefined;
11
- /** Way to override getNodes request params */
12
- requestOptions?: Partial<{
13
- projectMapId?: string | undefined;
14
- projectId: string;
15
- id?: string | undefined;
16
- path?: string | undefined;
17
- compositionId?: string | undefined;
18
- limit?: number | undefined;
19
- offset?: number | undefined;
20
- depth?: number | undefined;
21
- state?: number | undefined;
22
- tree?: boolean | undefined;
23
- search?: string | undefined;
24
- includeAncestors?: boolean | undefined;
25
- expanded?: boolean | undefined;
26
- withCompositionData?: boolean | undefined;
27
- withCompositionUIStatus?: boolean | undefined;
28
- withRedirectData?: boolean | undefined;
29
- }> | undefined;
30
- /** Way to modify list of nodes before building array of paths */
31
- callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
32
- /** If you need to override the default client, you can pass it here */
33
- client?: ProjectMapClient | undefined;
34
- } | undefined) => () => Promise<{
35
- paths: string[] | undefined;
36
- fallback: boolean;
37
- }>;
38
-
39
- export { withUniformGetStaticPaths as w };