@uniformdev/canvas-next 19.8.0 → 19.9.2-alpha.3

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,170 +1,227 @@
1
+ import {
2
+ withUniformGetStaticPaths
3
+ } from "../chunk-ZOXJSPVQ.mjs";
4
+ import {
5
+ resolveSlugFromParams
6
+ } from "../chunk-TR7V6ABJ.mjs";
7
+
1
8
  // src/route/withUniformGetServerSideProps.ts
9
+ import { RedirectClient } from "@uniformdev/redirect";
10
+
11
+ // src/route/createRouteFetcher.ts
2
12
  import {
3
13
  ApiClientError,
4
14
  EMPTY_COMPOSITION,
15
+ logRouteResponse,
5
16
  unstable_RouteClient
6
17
  } from "@uniformdev/canvas";
7
- import chalk3 from "chalk";
8
-
9
- // src/route/defaultHandleComposition.ts
10
- import chalk2 from "chalk";
11
-
12
- // src/route/logIssues.ts
13
- import chalk from "chalk";
14
- function unstable_logIssues(prefix, issues, colour) {
15
- colour = colour != null ? colour : "red";
16
- const reversedIssues = [...issues].reverse();
17
- console.error(
18
- `${chalk[colour](prefix)}
19
- ${reversedIssues.map(
20
- (issue) => `${chalk[colour](">")} ${chalk.italic.gray(indent(issue.type.toUpperCase(), 7))} ${renderIssue(
21
- issue
22
- )}`
23
- ).join("\n")}`
24
- );
25
- }
26
- function renderIssue(issue) {
27
- var _a;
28
- let path;
29
- let type;
30
- let message = issue.message;
31
- let detail;
32
- if (issue.type !== "config") {
33
- path = issue.componentPath;
34
- type = issue.componentType;
35
- message = issue.message;
36
- }
37
- if (issue.type === "binding") {
38
- detail = `Binding expression: ${(_a = issue.expression) == null ? void 0 : _a.pointer}`;
39
- } else if (issue.type === "data") {
40
- detail = `Data resource name: ${issue.dataName}, data type: ${issue.dataType}`;
41
- }
42
- if (issue.type === "input") {
43
- detail = issue.inputName;
44
- }
45
- let result = `${chalk.white(blockify(message))}`;
46
- if (detail) {
47
- result += `
48
- ${indent(" ", 10)}${chalk.gray(`${detail}`)}`;
49
- }
50
- if (path && type) {
51
- result += `
52
- ${indent(" ", 10)}${chalk.gray(`Occurred on component ${type} at slot path ${path}`)}`;
53
- }
54
- return result;
55
- }
56
- function indent(str, len) {
57
- const indent2 = len != null ? len : 10;
58
- return str.padStart(indent2);
59
- }
60
- function blockify(str, len) {
61
- const indentSize = len != null ? len : 10;
62
- return str.split("\n").map((line, index) => index === 0 ? line : `${indent(" ", indentSize)}${line}`).join("\n");
63
- }
64
-
65
- // src/route/defaultHandleComposition.ts
66
- function defaultHandleComposition(matched) {
67
- var _a, _b;
68
- const resErrors = (_a = matched.compositionApiResponse.errors) != null ? _a : [];
69
- const resWarnings = (_b = matched.compositionApiResponse.warnings) != null ? _b : [];
70
- const colour = resErrors.length > 0 ? "red" : resWarnings.length > 0 ? "yellow" : "green";
71
- console.log(`[canvas-next] ${chalk2[colour]("matched")} ${matched.matchedRoute}`, matched.type);
72
- if (matched.dynamicInputs) {
73
- const entries = Object.entries(matched.dynamicInputs);
74
- if (entries.length > 0) {
75
- console.log(
76
- ` ${chalk2.gray("Matched dynamic inputs:\n ")}`,
77
- entries.map(([k, v]) => `${k}: ${v}`).join("\n ")
78
- );
79
- }
80
- }
81
- if (resErrors.length > 0) {
82
- unstable_logIssues(
83
- `[canvas-next] ${matched.matchedRoute} composition data error${resErrors.length === 1 ? "" : "s"}; some content may be missing`,
84
- resErrors,
85
- "red"
18
+ import ansicolors from "ansi-colors";
19
+ var { red } = ansicolors;
20
+ function createRouteFetcher(options) {
21
+ const {
22
+ handleNotFound,
23
+ handleComposition,
24
+ handleRedirect,
25
+ defaultHandleComposition,
26
+ defaultHandleNotFound,
27
+ defaultHandleRedirect,
28
+ modifyPath,
29
+ projectMapId = process.env.UNIFORM_PROJECT_MAP_ID,
30
+ client,
31
+ prefix,
32
+ requestOptions,
33
+ silent,
34
+ parseContext
35
+ } = options;
36
+ const routeClient = client || new unstable_RouteClient({
37
+ apiKey: process.env.UNIFORM_API_KEY,
38
+ projectId: process.env.UNIFORM_PROJECT_ID,
39
+ edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
40
+ });
41
+ const handleModifyPath = modifyPath != null ? modifyPath : (path) => decodeURI(path);
42
+ return async function fetcher(context) {
43
+ const { contextualEditingCompositionId, resolvedUrl } = parseContext(context);
44
+ let nodePath = prefix ? resolvedUrl.replace(new RegExp(`^${prefix}`), "") : resolvedUrl;
45
+ nodePath = handleModifyPath(nodePath, context);
46
+ const invokeRedirectResult = (redirect, duration) => (handleRedirect != null ? handleRedirect : defaultHandleRedirect)(
47
+ nodePath,
48
+ redirect,
49
+ context,
50
+ (response) => defaultHandleRedirect(
51
+ nodePath,
52
+ response,
53
+ context,
54
+ () => {
55
+ throw new Error();
56
+ },
57
+ duration
58
+ ),
59
+ duration
86
60
  );
87
- }
88
- if (resWarnings.length > 0) {
89
- unstable_logIssues(
90
- `[canvas-next] ${matched.matchedRoute} composition data warning${resWarnings.length === 1 ? "" : "s"}; some content may be missing`,
91
- resWarnings,
92
- "yellow"
61
+ const invokeNotFoundResult = (response, duration) => (handleNotFound != null ? handleNotFound : defaultHandleNotFound)(
62
+ response,
63
+ context,
64
+ (response2) => defaultHandleNotFound(
65
+ response2,
66
+ context,
67
+ () => {
68
+ throw new Error();
69
+ },
70
+ duration
71
+ ),
72
+ duration
93
73
  );
94
- }
95
- if (matched.compositionApiResponse.diagnostics) {
96
- console.log(`[canvas-next] ${chalk2.green("Route diagnostics are enabled. Diagnostic data:")}`);
97
- console.log(JSON.stringify(matched.compositionApiResponse.diagnostics, null, 2));
98
- }
99
- return matched.compositionApiResponse.composition;
100
- }
101
-
102
- // src/route/withUniformGetServerSideProps.ts
103
- var unstable_withUniformGetServerSideProps = (options) => {
104
- var _a, _b, _c, _d;
105
- const handleRedirect = (_a = options == null ? void 0 : options.handleRedirect) != null ? _a : () => {
106
- throw new Error(`Redirects are not yet implemented by default. Please override handleRedirect option.`);
107
- };
108
- const handleNotFound = (_b = options == null ? void 0 : options.handleNotFound) != null ? _b : () => ({ notFound: true });
109
- const handleComposition = (_c = options == null ? void 0 : options.handleComposition) != null ? _c : defaultHandleComposition;
110
- const handleModifyPath = (_d = options == null ? void 0 : options.modifyPath) != null ? _d : (path) => decodeURI(path);
111
- return async function wrappedGetServerSideProps(context) {
112
- var _a2, _b2;
113
- const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
114
- const routeClient = (options == null ? void 0 : options.client) || new unstable_RouteClient({
115
- apiKey: process.env.UNIFORM_API_KEY,
116
- projectId: process.env.UNIFORM_PROJECT_ID,
117
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
118
- });
119
- const { previewData } = context;
120
- let composition = void 0;
121
- let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
122
- nodePath = handleModifyPath(nodePath, context);
123
- if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
124
- composition = { ...EMPTY_COMPOSITION, _id: (_b2 = previewData.compositionId) != null ? _b2 : EMPTY_COMPOSITION._id };
74
+ const invokeCompositionResult = (response, duration) => (handleComposition != null ? handleComposition : defaultHandleComposition)(
75
+ response,
76
+ context,
77
+ (response2) => defaultHandleComposition(
78
+ response2,
79
+ context,
80
+ () => {
81
+ throw new Error();
82
+ },
83
+ duration
84
+ ),
85
+ duration
86
+ );
87
+ if (contextualEditingCompositionId) {
88
+ const previewEmptyComposition = await invokeCompositionResult(
89
+ {
90
+ type: "composition",
91
+ matchedRoute: "contextual-editing",
92
+ compositionApiResponse: {
93
+ composition: {
94
+ ...EMPTY_COMPOSITION,
95
+ _id: contextualEditingCompositionId != null ? contextualEditingCompositionId : EMPTY_COMPOSITION._id
96
+ }
97
+ }
98
+ },
99
+ 0
100
+ );
101
+ return previewEmptyComposition;
125
102
  } else {
126
103
  try {
127
- console.log("[canvas-next] get route", nodePath);
104
+ console.log("Fetch route", nodePath);
105
+ const time = Date.now();
128
106
  const response = await routeClient.getRoute({
129
- ...options == null ? void 0 : options.requestOptions,
107
+ ...requestOptions,
130
108
  projectMapId,
131
109
  path: nodePath
132
110
  });
111
+ const duration = Date.now() - time;
112
+ if (!silent) {
113
+ logRouteResponse(response, duration);
114
+ }
133
115
  if (response.type === "redirect") {
134
- return handleRedirect(response, context);
116
+ return invokeRedirectResult(response, duration);
135
117
  }
136
118
  if (response.type === "notFound") {
137
- return handleNotFound(response, context);
119
+ return invokeNotFoundResult(response, duration);
138
120
  }
139
- const handleResult = handleComposition(response, context, defaultHandleComposition);
121
+ const handleResult = await invokeCompositionResult(response, duration);
140
122
  if (!handleResult) {
141
- return { notFound: true };
123
+ return invokeNotFoundResult({ type: "notFound" }, duration);
142
124
  }
143
- composition = handleResult;
125
+ return handleResult;
144
126
  } catch (e) {
145
- console.error(chalk3.red("[canvas-next] Failed to fetch composition"), e);
127
+ console.error(red("Failed to fetch route"), e);
146
128
  if (e instanceof ApiClientError) {
147
129
  if (e.statusCode === 404) {
148
- return { notFound: true };
130
+ return invokeNotFoundResult({ type: "notFound" }, 0);
149
131
  }
150
- throw new Error(`Failed to fetch composition. See server logs for details.`);
132
+ throw new Error(`Failed to fetch route. See server logs for details.`);
151
133
  }
152
134
  throw e;
153
135
  }
154
136
  }
155
- const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
156
- if (Object.hasOwn(ret, "props")) {
157
- const casted = ret;
158
- casted.props["data"] = composition;
137
+ };
138
+ }
139
+
140
+ // src/route/withUniformGetServerSideProps.ts
141
+ var unstable_withUniformGetServerSideProps = (options) => {
142
+ const defaultHandleRedirect = (requestUrl, matched) => {
143
+ return {
144
+ redirect: {
145
+ destination: RedirectClient.getTargetVariableExpandedUrl(requestUrl, matched.redirect),
146
+ statusCode: matched.redirect.targetStatusCode
147
+ }
148
+ };
149
+ };
150
+ const defaultHandleNotFound = () => ({
151
+ notFound: true
152
+ });
153
+ const defaultHandleComposition = async (matched) => {
154
+ return {
155
+ props: {
156
+ data: matched.compositionApiResponse.composition
157
+ }
158
+ };
159
+ };
160
+ const routeFetcher = createRouteFetcher({
161
+ ...options,
162
+ defaultHandleComposition,
163
+ defaultHandleNotFound,
164
+ defaultHandleRedirect,
165
+ parseContext(context) {
166
+ var _a;
167
+ return {
168
+ contextualEditingCompositionId: (_a = context.previewData) == null ? void 0 : _a.compositionId,
169
+ resolvedUrl: context.resolvedUrl
170
+ };
159
171
  }
160
- return ret;
172
+ });
173
+ return routeFetcher;
174
+ };
175
+
176
+ // src/route/withUniformGetStaticProps.ts
177
+ import { RedirectClient as RedirectClient2 } from "@uniformdev/redirect";
178
+ var unstable_withUniformGetStaticProps = (options) => {
179
+ const defaultHandleRedirect = (requestUrl, matched) => {
180
+ return {
181
+ redirect: {
182
+ destination: RedirectClient2.getTargetVariableExpandedUrl(requestUrl, matched.redirect),
183
+ statusCode: matched.redirect.targetStatusCode
184
+ }
185
+ };
186
+ };
187
+ const defaultHandleNotFound = () => ({
188
+ notFound: true
189
+ });
190
+ const defaultHandleComposition = async (matched) => {
191
+ return {
192
+ props: {
193
+ data: matched.compositionApiResponse.composition
194
+ }
195
+ };
161
196
  };
197
+ const routeFetcher = createRouteFetcher({
198
+ ...options,
199
+ defaultHandleComposition,
200
+ defaultHandleNotFound,
201
+ defaultHandleRedirect,
202
+ parseContext(context) {
203
+ var _a, _b;
204
+ return {
205
+ contextualEditingCompositionId: (_a = context.previewData) == null ? void 0 : _a.compositionId,
206
+ resolvedUrl: resolveSlugFromParams({
207
+ params: context.params,
208
+ param: (_b = options == null ? void 0 : options.param) != null ? _b : "route"
209
+ })
210
+ };
211
+ }
212
+ });
213
+ return routeFetcher;
162
214
  };
163
215
 
164
216
  // src/route/index.ts
165
217
  var unstable_getServerSideProps = unstable_withUniformGetServerSideProps();
218
+ var unstable_getStaticProps = unstable_withUniformGetStaticProps();
219
+ var getStaticPaths = withUniformGetStaticPaths();
166
220
  export {
221
+ getStaticPaths,
167
222
  unstable_getServerSideProps,
168
- unstable_logIssues,
169
- unstable_withUniformGetServerSideProps
223
+ unstable_getStaticProps,
224
+ unstable_withUniformGetServerSideProps,
225
+ unstable_withUniformGetStaticProps,
226
+ withUniformGetStaticPaths
170
227
  };
@@ -20,7 +20,7 @@ declare const withUniformGetServerSideProps: <TProps extends {
20
20
  preview?: boolean | undefined;
21
21
  /** If you need to override the default client, you can pass it here */
22
22
  client?: CanvasClient | undefined;
23
- requestOptions?: Partial<{
23
+ requestOptions?: Omit<Partial<{
24
24
  skipEnhance?: boolean | undefined;
25
25
  skipPatternResolution?: boolean | undefined;
26
26
  skipOverridesResolution?: boolean | undefined;
@@ -28,8 +28,10 @@ declare const withUniformGetServerSideProps: <TProps extends {
28
28
  withComponentIDs?: boolean | undefined;
29
29
  withTotalCount?: boolean | undefined;
30
30
  withUIStatus?: boolean | undefined;
31
- } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption> | undefined;
31
+ } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
32
32
  callback?: UniformGetServerSideProps<TProps> | undefined;
33
+ /** Disables logging of response information and timings */
34
+ silent?: boolean | undefined;
33
35
  } | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
34
36
 
35
37
  declare const withUniformGetStaticPaths: (options?: {
@@ -63,7 +65,7 @@ declare const withUniformGetStaticProps: <TProps extends {
63
65
  /** If you need to override the default client, you can pass it here */
64
66
  client?: CanvasClient | undefined;
65
67
  /** Way to override getCompositionBySlug request params */
66
- requestOptions?: Partial<{
68
+ requestOptions?: Omit<Partial<{
67
69
  skipEnhance?: boolean | undefined;
68
70
  skipPatternResolution?: boolean | undefined;
69
71
  skipOverridesResolution?: boolean | undefined;
@@ -71,9 +73,11 @@ declare const withUniformGetStaticProps: <TProps extends {
71
73
  withComponentIDs?: boolean | undefined;
72
74
  withTotalCount?: boolean | undefined;
73
75
  withUIStatus?: boolean | undefined;
74
- } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption> | undefined;
76
+ } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
75
77
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
76
78
  callback?: UniformGetStaticProps<TProps> | undefined;
79
+ /** Disables logging of response information and timings */
80
+ silent?: boolean | undefined;
77
81
  }) => GetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData>;
78
82
 
79
83
  declare const getServerSideProps: next.GetServerSideProps<{
@@ -32,14 +32,14 @@ module.exports = __toCommonJS(slug_exports);
32
32
  // src/slug/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;
37
- const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
38
- apiKey: process.env.UNIFORM_API_KEY,
39
- projectId: process.env.UNIFORM_PROJECT_ID,
40
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
41
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
42
- });
43
43
  const { preview, previewData } = context;
44
44
  let composition = void 0;
45
45
  let slug = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
@@ -50,12 +50,17 @@ var withUniformGetServerSideProps = (options) => {
50
50
  composition = { ...import_canvas.EMPTY_COMPOSITION, _id: (_a = previewData.compositionId) != null ? _a : import_canvas.EMPTY_COMPOSITION._id };
51
51
  } else {
52
52
  try {
53
+ const time = Date.now();
53
54
  const response = await canvasClient.getCompositionBySlug({
54
55
  ...options == null ? void 0 : options.requestOptions,
55
56
  slug,
56
57
  state: preview || (options == null ? void 0 : options.preview) ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
57
58
  });
59
+ const duration = Date.now() - time;
58
60
  composition = response.composition;
61
+ if (!(options == null ? void 0 : options.silent)) {
62
+ (0, import_canvas.logCompositionResponse)(response, duration);
63
+ }
59
64
  } catch (e) {
60
65
  console.error("[canvas-next] Failed to fetch composition", e);
61
66
  return {
@@ -102,7 +107,7 @@ var withUniformGetStaticPaths = (options) => {
102
107
  // src/slug/withUniformGetStaticProps.ts
103
108
  var import_canvas3 = require("@uniformdev/canvas");
104
109
 
105
- // src/helpers/slug.ts
110
+ // src/helpers/resolveSlugFromParams.ts
106
111
  var resolveSlugFromParams = ({
107
112
  param = "slug",
108
113
  params
@@ -114,8 +119,15 @@ var resolveSlugFromParams = ({
114
119
 
115
120
  // src/slug/withUniformGetStaticProps.ts
116
121
  var withUniformGetStaticProps = (options) => {
122
+ var _a;
123
+ const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new import_canvas3.CanvasClient({
124
+ apiKey: process.env.UNIFORM_API_KEY,
125
+ projectId: process.env.UNIFORM_PROJECT_ID,
126
+ apiHost: process.env.UNIFORM_CLI_BASE_URL,
127
+ edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
128
+ });
117
129
  return async function wrappedGetStaticProps(context) {
118
- var _a, _b;
130
+ var _a2;
119
131
  let slugString = resolveSlugFromParams({
120
132
  param: options == null ? void 0 : options.param,
121
133
  params: context == null ? void 0 : context.params
@@ -123,24 +135,23 @@ var withUniformGetStaticProps = (options) => {
123
135
  if (options == null ? void 0 : options.modifySlug) {
124
136
  slugString = options.modifySlug(slugString, context);
125
137
  }
126
- const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new import_canvas3.CanvasClient({
127
- apiKey: process.env.UNIFORM_API_KEY,
128
- projectId: process.env.UNIFORM_PROJECT_ID,
129
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
130
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
131
- });
132
138
  const { preview, previewData } = context;
133
139
  let composition = void 0;
134
140
  if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
135
- composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas3.EMPTY_COMPOSITION._id };
141
+ composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_a2 = previewData.compositionId) != null ? _a2 : import_canvas3.EMPTY_COMPOSITION._id };
136
142
  } else {
137
143
  try {
144
+ const time = Date.now();
138
145
  const response = await canvasClient.getCompositionBySlug({
139
146
  slug: slugString,
140
147
  state: preview || (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE,
141
148
  ...options == null ? void 0 : options.requestOptions
142
149
  });
150
+ const duration = Date.now() - time;
143
151
  composition = response.composition;
152
+ if (!(options == null ? void 0 : options.silent)) {
153
+ (0, import_canvas3.logCompositionResponse)(response, duration);
154
+ }
144
155
  } catch (e) {
145
156
  console.error("[canvas-next] Failed to fetch composition", e);
146
157
  return {
@@ -1,23 +1,24 @@
1
1
  import {
2
2
  resolveSlugFromParams
3
- } from "../chunk-2MI7UYW7.mjs";
3
+ } from "../chunk-TR7V6ABJ.mjs";
4
4
 
5
5
  // src/slug/withUniformGetServerSideProps.ts
6
6
  import {
7
7
  CANVAS_DRAFT_STATE,
8
8
  CANVAS_PUBLISHED_STATE,
9
9
  CanvasClient,
10
- EMPTY_COMPOSITION
10
+ EMPTY_COMPOSITION,
11
+ logCompositionResponse
11
12
  } from "@uniformdev/canvas";
12
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
+ });
13
20
  return async function wrappedGetServerSideProps(context) {
14
21
  var _a;
15
- const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
16
- apiKey: process.env.UNIFORM_API_KEY,
17
- projectId: process.env.UNIFORM_PROJECT_ID,
18
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
19
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
20
- });
21
22
  const { preview, previewData } = context;
22
23
  let composition = void 0;
23
24
  let slug = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
@@ -28,12 +29,17 @@ var withUniformGetServerSideProps = (options) => {
28
29
  composition = { ...EMPTY_COMPOSITION, _id: (_a = previewData.compositionId) != null ? _a : EMPTY_COMPOSITION._id };
29
30
  } else {
30
31
  try {
32
+ const time = Date.now();
31
33
  const response = await canvasClient.getCompositionBySlug({
32
34
  ...options == null ? void 0 : options.requestOptions,
33
35
  slug,
34
36
  state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
35
37
  });
38
+ const duration = Date.now() - time;
36
39
  composition = response.composition;
40
+ if (!(options == null ? void 0 : options.silent)) {
41
+ logCompositionResponse(response, duration);
42
+ }
37
43
  } catch (e) {
38
44
  console.error("[canvas-next] Failed to fetch composition", e);
39
45
  return {
@@ -86,11 +92,19 @@ import {
86
92
  CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
87
93
  CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
88
94
  CanvasClient as CanvasClient3,
89
- EMPTY_COMPOSITION as EMPTY_COMPOSITION2
95
+ EMPTY_COMPOSITION as EMPTY_COMPOSITION2,
96
+ logCompositionResponse as logCompositionResponse2
90
97
  } from "@uniformdev/canvas";
91
98
  var withUniformGetStaticProps = (options) => {
99
+ var _a;
100
+ const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient3({
101
+ apiKey: process.env.UNIFORM_API_KEY,
102
+ projectId: process.env.UNIFORM_PROJECT_ID,
103
+ apiHost: process.env.UNIFORM_CLI_BASE_URL,
104
+ edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
105
+ });
92
106
  return async function wrappedGetStaticProps(context) {
93
- var _a, _b;
107
+ var _a2;
94
108
  let slugString = resolveSlugFromParams({
95
109
  param: options == null ? void 0 : options.param,
96
110
  params: context == null ? void 0 : context.params
@@ -98,24 +112,23 @@ var withUniformGetStaticProps = (options) => {
98
112
  if (options == null ? void 0 : options.modifySlug) {
99
113
  slugString = options.modifySlug(slugString, context);
100
114
  }
101
- const canvasClient = (_a = options == null ? void 0 : options.client) != null ? _a : new CanvasClient3({
102
- apiKey: process.env.UNIFORM_API_KEY,
103
- projectId: process.env.UNIFORM_PROJECT_ID,
104
- apiHost: process.env.UNIFORM_CLI_BASE_URL,
105
- edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
106
- });
107
115
  const { preview, previewData } = context;
108
116
  let composition = void 0;
109
117
  if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
110
- composition = { ...EMPTY_COMPOSITION2, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION2._id };
118
+ composition = { ...EMPTY_COMPOSITION2, _id: (_a2 = previewData.compositionId) != null ? _a2 : EMPTY_COMPOSITION2._id };
111
119
  } else {
112
120
  try {
121
+ const time = Date.now();
113
122
  const response = await canvasClient.getCompositionBySlug({
114
123
  slug: slugString,
115
124
  state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3,
116
125
  ...options == null ? void 0 : options.requestOptions
117
126
  });
127
+ const duration = Date.now() - time;
118
128
  composition = response.composition;
129
+ if (!(options == null ? void 0 : options.silent)) {
130
+ logCompositionResponse2(response, duration);
131
+ }
119
132
  } catch (e) {
120
133
  console.error("[canvas-next] Failed to fetch composition", e);
121
134
  return {
@@ -0,0 +1,38 @@
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
+ }> | undefined;
29
+ /** Way to modify list of nodes before building array of paths */
30
+ callback?: ((nodes: ProjectMapNodeGetResponse['nodes']) => Promise<ProjectMapNodeGetResponse['nodes']>) | undefined;
31
+ /** If you need to override the default client, you can pass it here */
32
+ client?: ProjectMapClient | undefined;
33
+ } | undefined) => () => Promise<{
34
+ paths: string[] | undefined;
35
+ fallback: boolean;
36
+ }>;
37
+
38
+ export { withUniformGetStaticPaths as w };