@uniformdev/canvas-next 19.9.2-alpha.3 → 19.10.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/resolveSlugFromParams.ts
1
+ // src/helpers/slug.ts
2
2
  var resolveSlugFromParams = ({
3
3
  param = "slug",
4
4
  params
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  resolveSlugFromParams
3
- } from "./chunk-TR7V6ABJ.mjs";
3
+ } from "./chunk-2MI7UYW7.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/resolveSlugFromParams.ts
30
+ // src/helpers/slug.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-TR7V6ABJ.mjs";
3
+ } from "./chunk-2MI7UYW7.mjs";
4
4
 
5
5
  // src/preview/previewHandlerGet.ts
6
6
  import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
@@ -5,9 +5,8 @@ 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
- export { w as withUniformGetStaticPaths } from '../withUniformGetStaticPaths-6a31a8f8.js';
8
+ import { ProjectMapNodeGetResponse, ProjectMapClient } from '@uniformdev/project-map';
9
9
  import '@uniformdev/canvas-react';
10
- import '@uniformdev/project-map';
11
10
 
12
11
  declare const withUniformGetServerSideProps: <TProps extends {
13
12
  [key: string]: any;
@@ -24,7 +23,7 @@ declare const withUniformGetServerSideProps: <TProps extends {
24
23
  preview?: boolean | undefined;
25
24
  projectMapId?: string | undefined;
26
25
  /** Way to override getCompositionByNodePath request params */
27
- requestOptions?: Omit<Partial<{
26
+ requestOptions?: Partial<{
28
27
  skipEnhance?: boolean | undefined;
29
28
  skipPatternResolution?: boolean | undefined;
30
29
  skipOverridesResolution?: boolean | undefined;
@@ -32,13 +31,46 @@ declare const withUniformGetServerSideProps: <TProps extends {
32
31
  withComponentIDs?: boolean | undefined;
33
32
  withTotalCount?: boolean | undefined;
34
33
  withUIStatus?: boolean | undefined;
35
- } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption>, "state"> | undefined;
34
+ } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption> | undefined;
36
35
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
37
36
  callback?: UniformGetServerSideProps<TProps> | undefined;
38
- /** Disables logging of response information and timings */
39
- silent?: boolean | undefined;
40
37
  } | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
41
38
 
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
+
42
74
  declare const withUniformGetStaticProps: <TProps extends {
43
75
  [key: string]: any;
44
76
  } = {
@@ -54,7 +86,7 @@ declare const withUniformGetStaticProps: <TProps extends {
54
86
  /** If you need to override the default client, you can pass it here */
55
87
  client?: CanvasClient | undefined;
56
88
  /** Way to override getCompositionByNodePath request params */
57
- requestOptions?: Omit<Partial<{
89
+ requestOptions?: Partial<{
58
90
  skipEnhance?: boolean | undefined;
59
91
  skipPatternResolution?: boolean | undefined;
60
92
  skipOverridesResolution?: boolean | undefined;
@@ -62,11 +94,9 @@ declare const withUniformGetStaticProps: <TProps extends {
62
94
  withComponentIDs?: boolean | undefined;
63
95
  withTotalCount?: boolean | undefined;
64
96
  withUIStatus?: boolean | undefined;
65
- } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption>, "state"> | undefined;
97
+ } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption> | undefined;
66
98
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
67
99
  callback?: UniformGetStaticProps<TProps> | undefined;
68
- /** Disables logging of response information and timings */
69
- silent?: boolean | undefined;
70
100
  }) => GetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData>;
71
101
 
72
102
  declare const getServerSideProps: next.GetServerSideProps<{
@@ -81,4 +111,4 @@ declare const getStaticPaths: () => Promise<{
81
111
  fallback: boolean;
82
112
  }>;
83
113
 
84
- export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticProps };
114
+ export { getServerSideProps, getStaticPaths, getStaticProps, withUniformGetServerSideProps, withUniformGetStaticPaths, 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
- });
41
35
  return async function wrappedGetServerSideProps(context) {
42
36
  var _a, _b;
43
37
  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,18 +51,13 @@ 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();
55
54
  const response = await canvasClient.getCompositionByNodePath({
56
55
  ...options == null ? void 0 : options.requestOptions,
57
56
  projectMapId,
58
57
  projectMapNodePath: nodePath,
59
58
  state: preview || (options == null ? void 0 : options.preview) ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
60
59
  });
61
- const duration = Date.now() - time;
62
60
  composition = response.composition;
63
- if (!(options == null ? void 0 : options.silent)) {
64
- (0, import_canvas.logCompositionResponse)(response, duration);
65
- }
66
61
  } catch (e) {
67
62
  console.error("[canvas-next] Failed to fetch composition", e);
68
63
  return {
@@ -112,7 +107,7 @@ var withUniformGetStaticPaths = (options) => {
112
107
  // src/project-map/withUniformGetStaticProps.ts
113
108
  var import_canvas3 = require("@uniformdev/canvas");
114
109
 
115
- // src/helpers/resolveSlugFromParams.ts
110
+ // src/helpers/slug.ts
116
111
  var resolveSlugFromParams = ({
117
112
  param = "slug",
118
113
  params
@@ -124,16 +119,9 @@ var resolveSlugFromParams = ({
124
119
 
125
120
  // src/project-map/withUniformGetStaticProps.ts
126
121
  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
- });
134
122
  return async function wrappedGetStaticProps(context) {
135
- var _a2, _b;
136
- const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
123
+ var _a, _b, _c;
124
+ const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
137
125
  let pathString = resolveSlugFromParams({
138
126
  param: options == null ? void 0 : options.param,
139
127
  params: context == null ? void 0 : context.params
@@ -141,24 +129,25 @@ var withUniformGetStaticProps = (options) => {
141
129
  if (options == null ? void 0 : options.modifyPath) {
142
130
  pathString = options.modifyPath(pathString, context);
143
131
  }
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
+ });
144
138
  const { preview, previewData } = context;
145
139
  let composition = void 0;
146
140
  if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
147
- composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas3.EMPTY_COMPOSITION._id };
141
+ composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_c = previewData.compositionId) != null ? _c : import_canvas3.EMPTY_COMPOSITION._id };
148
142
  } else {
149
143
  try {
150
- const time = Date.now();
151
144
  const response = await canvasClient.getCompositionByNodePath({
152
145
  ...options == null ? void 0 : options.requestOptions,
153
146
  projectMapId,
154
147
  projectMapNodePath: pathString,
155
148
  state: preview || (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE
156
149
  });
157
- const duration = Date.now() - time;
158
150
  composition = response.composition;
159
- if (!(options == null ? void 0 : options.silent)) {
160
- (0, import_canvas3.logCompositionResponse)(response, duration);
161
- }
162
151
  } catch (e) {
163
152
  console.error("[canvas-next] Failed to fetch composition", e);
164
153
  return {
@@ -1,12 +1,146 @@
1
1
  import {
2
- getServerSideProps,
3
- getStaticPaths,
4
- getStaticProps,
5
- withUniformGetServerSideProps,
6
- withUniformGetStaticPaths,
7
- withUniformGetStaticProps
8
- } from "../chunk-ZOXJSPVQ.mjs";
9
- import "../chunk-TR7V6ABJ.mjs";
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();
10
144
  export {
11
145
  getServerSideProps,
12
146
  getStaticPaths,