@uniformdev/canvas-next 19.10.0 → 19.12.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.
@@ -1,4 +1,4 @@
1
- // src/helpers/slug.ts
1
+ // src/helpers/resolveSlugFromParams.ts
2
2
  var resolveSlugFromParams = ({
3
3
  param = "slug",
4
4
  params
@@ -0,0 +1,165 @@
1
+ import {
2
+ resolveSlugFromParams
3
+ } from "./chunk-TR7V6ABJ.mjs";
4
+
5
+ // src/project-map/withUniformGetServerSideProps.ts
6
+ import {
7
+ CANVAS_DRAFT_STATE,
8
+ CANVAS_PUBLISHED_STATE,
9
+ CanvasClient,
10
+ EMPTY_COMPOSITION,
11
+ logCompositionResponse
12
+ } from "@uniformdev/canvas";
13
+ var withUniformGetServerSideProps = (options) => {
14
+ const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
15
+ apiKey: process.env.UNIFORM_API_KEY,
16
+ projectId: process.env.UNIFORM_PROJECT_ID,
17
+ apiHost: process.env.UNIFORM_CLI_BASE_URL,
18
+ edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
19
+ });
20
+ return async function wrappedGetServerSideProps(context) {
21
+ var _a, _b;
22
+ const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
23
+ const { preview, previewData } = context;
24
+ let composition = void 0;
25
+ let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
26
+ if (options == null ? void 0 : options.modifyPath) {
27
+ nodePath = options.modifyPath(nodePath, context);
28
+ }
29
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
30
+ composition = { ...EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION._id };
31
+ } else {
32
+ try {
33
+ const time = Date.now();
34
+ const response = await canvasClient.getCompositionByNodePath({
35
+ ...options == null ? void 0 : options.requestOptions,
36
+ projectMapId,
37
+ projectMapNodePath: nodePath,
38
+ state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
39
+ });
40
+ const duration = Date.now() - time;
41
+ composition = response.composition;
42
+ if (!(options == null ? void 0 : options.silent)) {
43
+ logCompositionResponse(response, duration);
44
+ }
45
+ } catch (e) {
46
+ console.error("[canvas-next] Failed to fetch composition", e);
47
+ return {
48
+ notFound: true
49
+ };
50
+ }
51
+ }
52
+ const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
53
+ if (Object.hasOwn(ret, "props")) {
54
+ const casted = ret;
55
+ casted.props["data"] = composition;
56
+ }
57
+ return ret;
58
+ };
59
+ };
60
+
61
+ // src/project-map/withUniformGetStaticPaths.ts
62
+ import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
63
+ import {
64
+ ProjectMapClient
65
+ } from "@uniformdev/project-map";
66
+ var withUniformGetStaticPaths = (options) => {
67
+ return async function wrappedGetStaticPaths() {
68
+ var _a, _b;
69
+ const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
70
+ const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
71
+ apiKey: process.env.UNIFORM_API_KEY,
72
+ projectId: process.env.UNIFORM_PROJECT_ID,
73
+ apiHost: process.env.UNIFORM_CLI_BASE_URL
74
+ });
75
+ const response = await projectMapClient.getNodes({
76
+ ...options == null ? void 0 : options.requestOptions,
77
+ path: options == null ? void 0 : options.rootPath,
78
+ projectMapId,
79
+ state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
80
+ });
81
+ const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
82
+ const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
83
+ var _a2;
84
+ return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
85
+ });
86
+ return {
87
+ paths,
88
+ fallback: true
89
+ };
90
+ };
91
+ };
92
+
93
+ // src/project-map/withUniformGetStaticProps.ts
94
+ import {
95
+ CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
96
+ CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
97
+ CanvasClient as CanvasClient2,
98
+ EMPTY_COMPOSITION as EMPTY_COMPOSITION2,
99
+ logCompositionResponse as logCompositionResponse2
100
+ } from "@uniformdev/canvas";
101
+ var withUniformGetStaticProps = (options) => {
102
+ var _a;
103
+ const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient2({
104
+ apiKey: process.env.UNIFORM_API_KEY,
105
+ projectId: process.env.UNIFORM_PROJECT_ID,
106
+ apiHost: process.env.UNIFORM_CLI_BASE_URL,
107
+ edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
108
+ });
109
+ return async function wrappedGetStaticProps(context) {
110
+ var _a2, _b;
111
+ const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
112
+ let pathString = resolveSlugFromParams({
113
+ param: options == null ? void 0 : options.param,
114
+ params: context == null ? void 0 : context.params
115
+ });
116
+ if (options == null ? void 0 : options.modifyPath) {
117
+ pathString = options.modifyPath(pathString, context);
118
+ }
119
+ const { preview, previewData } = context;
120
+ let composition = void 0;
121
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
122
+ composition = { ...EMPTY_COMPOSITION2, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION2._id };
123
+ } else {
124
+ try {
125
+ const time = Date.now();
126
+ const response = await canvasClient.getCompositionByNodePath({
127
+ ...options == null ? void 0 : options.requestOptions,
128
+ projectMapId,
129
+ projectMapNodePath: pathString,
130
+ state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
131
+ });
132
+ const duration = Date.now() - time;
133
+ composition = response.composition;
134
+ if (!(options == null ? void 0 : options.silent)) {
135
+ logCompositionResponse2(response, duration);
136
+ }
137
+ } catch (e) {
138
+ console.error("[canvas-next] Failed to fetch composition", e);
139
+ return {
140
+ notFound: true
141
+ };
142
+ }
143
+ }
144
+ const ret = options.callback ? await options.callback(context, composition) : { props: {} };
145
+ if (composition && Object.hasOwn(ret, "props")) {
146
+ const casted = ret;
147
+ casted.props["data"] = composition;
148
+ }
149
+ return ret;
150
+ };
151
+ };
152
+
153
+ // src/project-map/index.ts
154
+ var getServerSideProps = withUniformGetServerSideProps();
155
+ var getStaticProps = withUniformGetStaticProps({ param: "path" });
156
+ var getStaticPaths = withUniformGetStaticPaths();
157
+
158
+ export {
159
+ withUniformGetServerSideProps,
160
+ withUniformGetStaticPaths,
161
+ withUniformGetStaticProps,
162
+ getServerSideProps,
163
+ getStaticProps,
164
+ getStaticPaths
165
+ };
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveSlugFromParams
3
- } from "./chunk-2MI7UYW7.mjs";
3
+ } from "./chunk-TR7V6ABJ.mjs";
4
4
 
5
5
  // src/preview/previewHandlerGet.ts
6
6
  import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ __export(src_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(src_exports);
29
29
 
30
- // src/helpers/slug.ts
30
+ // src/helpers/resolveSlugFromParams.ts
31
31
  var resolveSlugFromParams = ({
32
32
  param = "slug",
33
33
  params
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveSlugFromParams
3
- } from "./chunk-2MI7UYW7.mjs";
3
+ } from "./chunk-TR7V6ABJ.mjs";
4
4
 
5
5
  // src/preview/previewHandlerGet.ts
6
6
  import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
@@ -5,8 +5,9 @@ import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
7
7
  import { CanvasClient, DataResolutionOption } from '@uniformdev/canvas';
8
- import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
8
+ export { w as withUniformGetStaticPaths } from '../withUniformGetStaticPaths-6a31a8f8.js';
9
9
  import '@uniformdev/canvas-react';
10
+ import '@uniformdev/project-map';
10
11
 
11
12
  declare const withUniformGetServerSideProps: <TProps extends {
12
13
  [key: string]: any;
@@ -23,7 +24,7 @@ declare const withUniformGetServerSideProps: <TProps extends {
23
24
  preview?: boolean | undefined;
24
25
  projectMapId?: string | undefined;
25
26
  /** Way to override getCompositionByNodePath request params */
26
- requestOptions?: Partial<{
27
+ requestOptions?: Omit<Partial<{
27
28
  skipEnhance?: boolean | undefined;
28
29
  skipPatternResolution?: boolean | undefined;
29
30
  skipOverridesResolution?: boolean | undefined;
@@ -31,46 +32,13 @@ declare const withUniformGetServerSideProps: <TProps extends {
31
32
  withComponentIDs?: boolean | undefined;
32
33
  withTotalCount?: boolean | undefined;
33
34
  withUIStatus?: boolean | undefined;
34
- } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption> | undefined;
35
+ } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption>, "state"> | undefined;
35
36
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
36
37
  callback?: UniformGetServerSideProps<TProps> | undefined;
38
+ /** Disables logging of response information and timings */
39
+ silent?: boolean | undefined;
37
40
  } | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
38
41
 
39
- declare const withUniformGetStaticPaths: (options?: {
40
- projectMapId?: string | undefined;
41
- /** Starting path to fetch nodes from */
42
- rootPath?: string | undefined;
43
- /** 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 */
44
- prefix?: string | undefined;
45
- /** Set to true if you want to include draft compositions */
46
- preview?: boolean | undefined;
47
- /** Way to override getNodes request params */
48
- requestOptions?: Partial<{
49
- projectMapId?: string | undefined;
50
- projectId: string;
51
- id?: string | undefined;
52
- path?: string | undefined;
53
- compositionId?: string | undefined;
54
- limit?: number | undefined;
55
- offset?: number | undefined;
56
- depth?: number | undefined;
57
- state?: number | undefined;
58
- tree?: boolean | undefined;
59
- search?: string | undefined;
60
- includeAncestors?: boolean | undefined;
61
- expanded?: boolean | undefined;
62
- withCompositionData?: boolean | undefined;
63
- withCompositionUIStatus?: boolean | undefined;
64
- }> | undefined;
65
- /** Way to modify list of nodes before building array of paths */
66
- callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
67
- /** If you need to override the default client, you can pass it here */
68
- client?: ProjectMapClient | undefined;
69
- } | undefined) => () => Promise<{
70
- paths: string[] | undefined;
71
- fallback: boolean;
72
- }>;
73
-
74
42
  declare const withUniformGetStaticProps: <TProps extends {
75
43
  [key: string]: any;
76
44
  } = {
@@ -86,7 +54,7 @@ declare const withUniformGetStaticProps: <TProps extends {
86
54
  /** If you need to override the default client, you can pass it here */
87
55
  client?: CanvasClient | undefined;
88
56
  /** Way to override getCompositionByNodePath request params */
89
- requestOptions?: Partial<{
57
+ requestOptions?: Omit<Partial<{
90
58
  skipEnhance?: boolean | undefined;
91
59
  skipPatternResolution?: boolean | undefined;
92
60
  skipOverridesResolution?: boolean | undefined;
@@ -94,9 +62,11 @@ declare const withUniformGetStaticProps: <TProps extends {
94
62
  withComponentIDs?: boolean | undefined;
95
63
  withTotalCount?: boolean | undefined;
96
64
  withUIStatus?: boolean | undefined;
97
- } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption> | undefined;
65
+ } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption>, "state"> | undefined;
98
66
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
99
67
  callback?: UniformGetStaticProps<TProps> | undefined;
68
+ /** Disables logging of response information and timings */
69
+ silent?: boolean | undefined;
100
70
  }) => GetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData>;
101
71
 
102
72
  declare const getServerSideProps: next.GetServerSideProps<{
@@ -111,4 +81,4 @@ declare const getStaticPaths: () => Promise<{
111
81
  fallback: boolean;
112
82
  }>;
113
83
 
114
- export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticPaths, withUniformGetStaticProps };
84
+ export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticProps };
@@ -32,15 +32,15 @@ module.exports = __toCommonJS(project_map_exports);
32
32
  // src/project-map/withUniformGetServerSideProps.ts
33
33
  var import_canvas = require("@uniformdev/canvas");
34
34
  var withUniformGetServerSideProps = (options) => {
35
+ const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
36
+ apiKey: process.env.UNIFORM_API_KEY,
37
+ projectId: process.env.UNIFORM_PROJECT_ID,
38
+ apiHost: process.env.UNIFORM_CLI_BASE_URL,
39
+ edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
40
+ });
35
41
  return async function wrappedGetServerSideProps(context) {
36
42
  var _a, _b;
37
43
  const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
38
- const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
39
- apiKey: process.env.UNIFORM_API_KEY,
40
- projectId: process.env.UNIFORM_PROJECT_ID,
41
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
42
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
43
- });
44
44
  const { preview, previewData } = context;
45
45
  let composition = void 0;
46
46
  let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
@@ -51,13 +51,18 @@ var withUniformGetServerSideProps = (options) => {
51
51
  composition = { ...import_canvas.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas.EMPTY_COMPOSITION._id };
52
52
  } else {
53
53
  try {
54
+ const time = Date.now();
54
55
  const response = await canvasClient.getCompositionByNodePath({
55
56
  ...options == null ? void 0 : options.requestOptions,
56
57
  projectMapId,
57
58
  projectMapNodePath: nodePath,
58
59
  state: preview || (options == null ? void 0 : options.preview) ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
59
60
  });
61
+ const duration = Date.now() - time;
60
62
  composition = response.composition;
63
+ if (!(options == null ? void 0 : options.silent)) {
64
+ (0, import_canvas.logCompositionResponse)(response, duration);
65
+ }
61
66
  } catch (e) {
62
67
  console.error("[canvas-next] Failed to fetch composition", e);
63
68
  return {
@@ -107,7 +112,7 @@ var withUniformGetStaticPaths = (options) => {
107
112
  // src/project-map/withUniformGetStaticProps.ts
108
113
  var import_canvas3 = require("@uniformdev/canvas");
109
114
 
110
- // src/helpers/slug.ts
115
+ // src/helpers/resolveSlugFromParams.ts
111
116
  var resolveSlugFromParams = ({
112
117
  param = "slug",
113
118
  params
@@ -119,9 +124,16 @@ var resolveSlugFromParams = ({
119
124
 
120
125
  // src/project-map/withUniformGetStaticProps.ts
121
126
  var withUniformGetStaticProps = (options) => {
127
+ var _a;
128
+ const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new import_canvas3.CanvasClient({
129
+ apiKey: process.env.UNIFORM_API_KEY,
130
+ projectId: process.env.UNIFORM_PROJECT_ID,
131
+ apiHost: process.env.UNIFORM_CLI_BASE_URL,
132
+ edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
133
+ });
122
134
  return async function wrappedGetStaticProps(context) {
123
- var _a, _b, _c;
124
- const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
135
+ var _a2, _b;
136
+ const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
125
137
  let pathString = resolveSlugFromParams({
126
138
  param: options == null ? void 0 : options.param,
127
139
  params: context == null ? void 0 : context.params
@@ -129,25 +141,24 @@ var withUniformGetStaticProps = (options) => {
129
141
  if (options == null ? void 0 : options.modifyPath) {
130
142
  pathString = options.modifyPath(pathString, context);
131
143
  }
132
- const canvasClient = (_b = options == null ? void 0 : options.client) != null ? _b : new import_canvas3.CanvasClient({
133
- apiKey: process.env.UNIFORM_API_KEY,
134
- projectId: process.env.UNIFORM_PROJECT_ID,
135
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
136
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
137
- });
138
144
  const { preview, previewData } = context;
139
145
  let composition = void 0;
140
146
  if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
141
- composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_c = previewData.compositionId) != null ? _c : import_canvas3.EMPTY_COMPOSITION._id };
147
+ composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas3.EMPTY_COMPOSITION._id };
142
148
  } else {
143
149
  try {
150
+ const time = Date.now();
144
151
  const response = await canvasClient.getCompositionByNodePath({
145
152
  ...options == null ? void 0 : options.requestOptions,
146
153
  projectMapId,
147
154
  projectMapNodePath: pathString,
148
155
  state: preview || (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE
149
156
  });
157
+ const duration = Date.now() - time;
150
158
  composition = response.composition;
159
+ if (!(options == null ? void 0 : options.silent)) {
160
+ (0, import_canvas3.logCompositionResponse)(response, duration);
161
+ }
151
162
  } catch (e) {
152
163
  console.error("[canvas-next] Failed to fetch composition", e);
153
164
  return {
@@ -1,146 +1,12 @@
1
1
  import {
2
- resolveSlugFromParams
3
- } from "../chunk-2MI7UYW7.mjs";
4
-
5
- // src/project-map/withUniformGetServerSideProps.ts
6
- import {
7
- CANVAS_DRAFT_STATE,
8
- CANVAS_PUBLISHED_STATE,
9
- CanvasClient,
10
- EMPTY_COMPOSITION
11
- } from "@uniformdev/canvas";
12
- var withUniformGetServerSideProps = (options) => {
13
- return async function wrappedGetServerSideProps(context) {
14
- var _a, _b;
15
- const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
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
- const { preview, previewData } = context;
23
- let composition = void 0;
24
- let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
25
- if (options == null ? void 0 : options.modifyPath) {
26
- nodePath = options.modifyPath(nodePath, context);
27
- }
28
- if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
29
- composition = { ...EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION._id };
30
- } else {
31
- try {
32
- const response = await canvasClient.getCompositionByNodePath({
33
- ...options == null ? void 0 : options.requestOptions,
34
- projectMapId,
35
- projectMapNodePath: nodePath,
36
- state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
37
- });
38
- composition = response.composition;
39
- } catch (e) {
40
- console.error("[canvas-next] Failed to fetch composition", e);
41
- return {
42
- notFound: true
43
- };
44
- }
45
- }
46
- const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
47
- if (Object.hasOwn(ret, "props")) {
48
- const casted = ret;
49
- casted.props["data"] = composition;
50
- }
51
- return ret;
52
- };
53
- };
54
-
55
- // src/project-map/withUniformGetStaticPaths.ts
56
- import { CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE2, CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE2 } from "@uniformdev/canvas";
57
- import {
58
- ProjectMapClient
59
- } from "@uniformdev/project-map";
60
- var withUniformGetStaticPaths = (options) => {
61
- return async function wrappedGetStaticPaths() {
62
- var _a, _b;
63
- const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
64
- const projectMapClient = (_b = options == null ? void 0 : options.client) != null ? _b : new ProjectMapClient({
65
- apiKey: process.env.UNIFORM_API_KEY,
66
- projectId: process.env.UNIFORM_PROJECT_ID,
67
- apiHost: process.env.UNIFORM_CLI_BASE_URL
68
- });
69
- const response = await projectMapClient.getNodes({
70
- ...options == null ? void 0 : options.requestOptions,
71
- path: options == null ? void 0 : options.rootPath,
72
- projectMapId,
73
- state: (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE2 : CANVAS_PUBLISHED_STATE2
74
- });
75
- const nodes = (options == null ? void 0 : options.callback) ? await options.callback(response.nodes) : response.nodes;
76
- const paths = nodes == null ? void 0 : nodes.filter((node) => Boolean(node.compositionId)).map((node) => {
77
- var _a2;
78
- return `${(_a2 = options == null ? void 0 : options.prefix) != null ? _a2 : ""}${node.path}`;
79
- });
80
- return {
81
- paths,
82
- fallback: true
83
- };
84
- };
85
- };
86
-
87
- // src/project-map/withUniformGetStaticProps.ts
88
- import {
89
- CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
90
- CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
91
- CanvasClient as CanvasClient2,
92
- EMPTY_COMPOSITION as EMPTY_COMPOSITION2
93
- } from "@uniformdev/canvas";
94
- var withUniformGetStaticProps = (options) => {
95
- return async function wrappedGetStaticProps(context) {
96
- var _a, _b, _c;
97
- const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
98
- let pathString = resolveSlugFromParams({
99
- param: options == null ? void 0 : options.param,
100
- params: context == null ? void 0 : context.params
101
- });
102
- if (options == null ? void 0 : options.modifyPath) {
103
- pathString = options.modifyPath(pathString, context);
104
- }
105
- const canvasClient = (_b = options == null ? void 0 : options.client) != null ? _b : new CanvasClient2({
106
- apiKey: process.env.UNIFORM_API_KEY,
107
- projectId: process.env.UNIFORM_PROJECT_ID,
108
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
109
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
110
- });
111
- const { preview, previewData } = context;
112
- let composition = void 0;
113
- if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
114
- composition = { ...EMPTY_COMPOSITION2, _id: (_c = previewData.compositionId) != null ? _c : EMPTY_COMPOSITION2._id };
115
- } else {
116
- try {
117
- const response = await canvasClient.getCompositionByNodePath({
118
- ...options == null ? void 0 : options.requestOptions,
119
- projectMapId,
120
- projectMapNodePath: pathString,
121
- state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3
122
- });
123
- composition = response.composition;
124
- } catch (e) {
125
- console.error("[canvas-next] Failed to fetch composition", e);
126
- return {
127
- notFound: true
128
- };
129
- }
130
- }
131
- const ret = options.callback ? await options.callback(context, composition) : { props: {} };
132
- if (composition && Object.hasOwn(ret, "props")) {
133
- const casted = ret;
134
- casted.props["data"] = composition;
135
- }
136
- return ret;
137
- };
138
- };
139
-
140
- // src/project-map/index.ts
141
- var getServerSideProps = withUniformGetServerSideProps();
142
- var getStaticProps = withUniformGetStaticProps({ param: "path" });
143
- var getStaticPaths = withUniformGetStaticPaths();
2
+ getServerSideProps,
3
+ getStaticPaths,
4
+ getStaticProps,
5
+ withUniformGetServerSideProps,
6
+ withUniformGetStaticPaths,
7
+ withUniformGetStaticProps
8
+ } from "../chunk-ZOXJSPVQ.mjs";
9
+ import "../chunk-TR7V6ABJ.mjs";
144
10
  export {
145
11
  getServerSideProps,
146
12
  getStaticPaths,