@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,227 +1,179 @@
1
- import {
2
- withUniformGetStaticPaths
3
- } from "../chunk-ZOXJSPVQ.mjs";
4
- import {
5
- resolveSlugFromParams
6
- } from "../chunk-TR7V6ABJ.mjs";
7
-
8
1
  // src/route/withUniformGetServerSideProps.ts
9
- import { RedirectClient } from "@uniformdev/redirect";
10
-
11
- // src/route/createRouteFetcher.ts
12
2
  import {
13
3
  ApiClientError,
14
4
  EMPTY_COMPOSITION,
15
- logRouteResponse,
16
5
  unstable_RouteClient
17
6
  } from "@uniformdev/canvas";
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
60
- );
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
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"
73
86
  );
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
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"
86
93
  );
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;
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/defaultHandleRedirect.ts
103
+ import { RedirectClient } from "@uniformdev/redirect";
104
+ function defaultHandleRedirect(matched, requestUrl) {
105
+ return {
106
+ redirect: {
107
+ destination: RedirectClient.getTargetVariableExpandedUrl(requestUrl, matched.redirect),
108
+ statusCode: matched.redirect.targetStatusCode
109
+ }
110
+ };
111
+ }
112
+
113
+ // src/route/withUniformGetServerSideProps.ts
114
+ var unstable_withUniformGetServerSideProps = (options) => {
115
+ var _a, _b, _c, _d;
116
+ const handleNotFound = (_a = options == null ? void 0 : options.handleNotFound) != null ? _a : () => ({ notFound: true });
117
+ const handleComposition = (_b = options == null ? void 0 : options.handleComposition) != null ? _b : defaultHandleComposition;
118
+ const handleRedirect = (_c = options == null ? void 0 : options.handleRedirect) != null ? _c : defaultHandleRedirect;
119
+ const handleModifyPath = (_d = options == null ? void 0 : options.modifyPath) != null ? _d : (path) => decodeURI(path);
120
+ return async function wrappedGetServerSideProps(context) {
121
+ var _a2, _b2;
122
+ const projectMapId = (_a2 = options == null ? void 0 : options.projectMapId) != null ? _a2 : process.env.UNIFORM_PROJECT_MAP_ID;
123
+ const routeClient = (options == null ? void 0 : options.client) || new unstable_RouteClient({
124
+ apiKey: process.env.UNIFORM_API_KEY,
125
+ projectId: process.env.UNIFORM_PROJECT_ID,
126
+ edgeApiHost: process.env.UNIFORM_CLI_BASE_EDGE_URL
127
+ });
128
+ const { previewData } = context;
129
+ let composition = void 0;
130
+ let nodePath = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
131
+ nodePath = handleModifyPath(nodePath, context);
132
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
133
+ composition = { ...EMPTY_COMPOSITION, _id: (_b2 = previewData.compositionId) != null ? _b2 : EMPTY_COMPOSITION._id };
102
134
  } else {
103
135
  try {
104
- console.log("Fetch route", nodePath);
105
- const time = Date.now();
136
+ console.log("[canvas-next] get route", nodePath);
106
137
  const response = await routeClient.getRoute({
107
- ...requestOptions,
138
+ ...options == null ? void 0 : options.requestOptions,
108
139
  projectMapId,
109
140
  path: nodePath
110
141
  });
111
- const duration = Date.now() - time;
112
- if (!silent) {
113
- logRouteResponse(response, duration);
114
- }
115
142
  if (response.type === "redirect") {
116
- return invokeRedirectResult(response, duration);
143
+ return handleRedirect(response, nodePath, context, defaultHandleRedirect);
117
144
  }
118
145
  if (response.type === "notFound") {
119
- return invokeNotFoundResult(response, duration);
146
+ return handleNotFound(response, context);
120
147
  }
121
- const handleResult = await invokeCompositionResult(response, duration);
148
+ const handleResult = handleComposition(response, context, defaultHandleComposition);
122
149
  if (!handleResult) {
123
- return invokeNotFoundResult({ type: "notFound" }, duration);
150
+ return { notFound: true };
124
151
  }
125
- return handleResult;
152
+ composition = handleResult;
126
153
  } catch (e) {
127
- console.error(red("Failed to fetch route"), e);
154
+ console.error(chalk3.red("[canvas-next] Failed to fetch composition"), e);
128
155
  if (e instanceof ApiClientError) {
129
156
  if (e.statusCode === 404) {
130
- return invokeNotFoundResult({ type: "notFound" }, 0);
157
+ return { notFound: true };
131
158
  }
132
- throw new Error(`Failed to fetch route. See server logs for details.`);
159
+ throw new Error(`Failed to fetch composition. See server logs for details.`);
133
160
  }
134
161
  throw e;
135
162
  }
136
163
  }
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
- };
164
+ const ret = (options == null ? void 0 : options.callback) ? await options.callback(context, composition) : { props: {} };
165
+ if (Object.hasOwn(ret, "props")) {
166
+ const casted = ret;
167
+ casted.props["data"] = composition;
171
168
  }
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
- };
169
+ return ret;
186
170
  };
187
- const defaultHandleNotFound = () => ({
188
- notFound: true
189
- });
190
- const defaultHandleComposition = async (matched) => {
191
- return {
192
- props: {
193
- data: matched.compositionApiResponse.composition
194
- }
195
- };
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;
214
171
  };
215
172
 
216
173
  // src/route/index.ts
217
174
  var unstable_getServerSideProps = unstable_withUniformGetServerSideProps();
218
- var unstable_getStaticProps = unstable_withUniformGetStaticProps();
219
- var getStaticPaths = withUniformGetStaticPaths();
220
175
  export {
221
- getStaticPaths,
222
176
  unstable_getServerSideProps,
223
- unstable_getStaticProps,
224
- unstable_withUniformGetServerSideProps,
225
- unstable_withUniformGetStaticProps,
226
- withUniformGetStaticPaths
177
+ unstable_logIssues,
178
+ unstable_withUniformGetServerSideProps
227
179
  };
@@ -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?: Omit<Partial<{
23
+ requestOptions?: Partial<{
24
24
  skipEnhance?: boolean | undefined;
25
25
  skipPatternResolution?: boolean | undefined;
26
26
  skipOverridesResolution?: boolean | undefined;
@@ -28,10 +28,8 @@ 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>, "state"> | undefined;
31
+ } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption> | undefined;
32
32
  callback?: UniformGetServerSideProps<TProps> | undefined;
33
- /** Disables logging of response information and timings */
34
- silent?: boolean | undefined;
35
33
  } | undefined) => GetServerSideProps<TProps, ParsedUrlQuery, UniformPreviewData>;
36
34
 
37
35
  declare const withUniformGetStaticPaths: (options?: {
@@ -65,7 +63,7 @@ declare const withUniformGetStaticProps: <TProps extends {
65
63
  /** If you need to override the default client, you can pass it here */
66
64
  client?: CanvasClient | undefined;
67
65
  /** Way to override getCompositionBySlug request params */
68
- requestOptions?: Omit<Partial<{
66
+ requestOptions?: Partial<{
69
67
  skipEnhance?: boolean | undefined;
70
68
  skipPatternResolution?: boolean | undefined;
71
69
  skipOverridesResolution?: boolean | undefined;
@@ -73,11 +71,9 @@ declare const withUniformGetStaticProps: <TProps extends {
73
71
  withComponentIDs?: boolean | undefined;
74
72
  withTotalCount?: boolean | undefined;
75
73
  withUIStatus?: boolean | undefined;
76
- } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
74
+ } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption> | undefined;
77
75
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
78
76
  callback?: UniformGetStaticProps<TProps> | undefined;
79
- /** Disables logging of response information and timings */
80
- silent?: boolean | undefined;
81
77
  }) => GetStaticProps<TProps, ParsedUrlQuery, UniformPreviewData>;
82
78
 
83
79
  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
- });
41
35
  return async function wrappedGetServerSideProps(context) {
42
36
  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,17 +50,12 @@ 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();
54
53
  const response = await canvasClient.getCompositionBySlug({
55
54
  ...options == null ? void 0 : options.requestOptions,
56
55
  slug,
57
56
  state: preview || (options == null ? void 0 : options.preview) ? import_canvas.CANVAS_DRAFT_STATE : import_canvas.CANVAS_PUBLISHED_STATE
58
57
  });
59
- const duration = Date.now() - time;
60
58
  composition = response.composition;
61
- if (!(options == null ? void 0 : options.silent)) {
62
- (0, import_canvas.logCompositionResponse)(response, duration);
63
- }
64
59
  } catch (e) {
65
60
  console.error("[canvas-next] Failed to fetch composition", e);
66
61
  return {
@@ -107,7 +102,7 @@ var withUniformGetStaticPaths = (options) => {
107
102
  // src/slug/withUniformGetStaticProps.ts
108
103
  var import_canvas3 = require("@uniformdev/canvas");
109
104
 
110
- // src/helpers/resolveSlugFromParams.ts
105
+ // src/helpers/slug.ts
111
106
  var resolveSlugFromParams = ({
112
107
  param = "slug",
113
108
  params
@@ -119,15 +114,8 @@ var resolveSlugFromParams = ({
119
114
 
120
115
  // src/slug/withUniformGetStaticProps.ts
121
116
  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
- });
129
117
  return async function wrappedGetStaticProps(context) {
130
- var _a2;
118
+ var _a, _b;
131
119
  let slugString = resolveSlugFromParams({
132
120
  param: options == null ? void 0 : options.param,
133
121
  params: context == null ? void 0 : context.params
@@ -135,23 +123,24 @@ var withUniformGetStaticProps = (options) => {
135
123
  if (options == null ? void 0 : options.modifySlug) {
136
124
  slugString = options.modifySlug(slugString, context);
137
125
  }
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
+ });
138
132
  const { preview, previewData } = context;
139
133
  let composition = void 0;
140
134
  if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
141
- composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_a2 = previewData.compositionId) != null ? _a2 : import_canvas3.EMPTY_COMPOSITION._id };
135
+ composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas3.EMPTY_COMPOSITION._id };
142
136
  } else {
143
137
  try {
144
- const time = Date.now();
145
138
  const response = await canvasClient.getCompositionBySlug({
146
139
  slug: slugString,
147
140
  state: preview || (options == null ? void 0 : options.preview) ? import_canvas3.CANVAS_DRAFT_STATE : import_canvas3.CANVAS_PUBLISHED_STATE,
148
141
  ...options == null ? void 0 : options.requestOptions
149
142
  });
150
- const duration = Date.now() - time;
151
143
  composition = response.composition;
152
- if (!(options == null ? void 0 : options.silent)) {
153
- (0, import_canvas3.logCompositionResponse)(response, duration);
154
- }
155
144
  } catch (e) {
156
145
  console.error("[canvas-next] Failed to fetch composition", e);
157
146
  return {
@@ -1,24 +1,23 @@
1
1
  import {
2
2
  resolveSlugFromParams
3
- } from "../chunk-TR7V6ABJ.mjs";
3
+ } from "../chunk-2MI7UYW7.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,
11
- logCompositionResponse
10
+ EMPTY_COMPOSITION
12
11
  } from "@uniformdev/canvas";
13
12
  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
13
  return async function wrappedGetServerSideProps(context) {
21
14
  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
+ });
22
21
  const { preview, previewData } = context;
23
22
  let composition = void 0;
24
23
  let slug = (options == null ? void 0 : options.prefix) ? context.resolvedUrl.replace(new RegExp(`^${options.prefix}`), "") : context.resolvedUrl;
@@ -29,17 +28,12 @@ var withUniformGetServerSideProps = (options) => {
29
28
  composition = { ...EMPTY_COMPOSITION, _id: (_a = previewData.compositionId) != null ? _a : EMPTY_COMPOSITION._id };
30
29
  } else {
31
30
  try {
32
- const time = Date.now();
33
31
  const response = await canvasClient.getCompositionBySlug({
34
32
  ...options == null ? void 0 : options.requestOptions,
35
33
  slug,
36
34
  state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE
37
35
  });
38
- const duration = Date.now() - time;
39
36
  composition = response.composition;
40
- if (!(options == null ? void 0 : options.silent)) {
41
- logCompositionResponse(response, duration);
42
- }
43
37
  } catch (e) {
44
38
  console.error("[canvas-next] Failed to fetch composition", e);
45
39
  return {
@@ -92,19 +86,11 @@ import {
92
86
  CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
93
87
  CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
94
88
  CanvasClient as CanvasClient3,
95
- EMPTY_COMPOSITION as EMPTY_COMPOSITION2,
96
- logCompositionResponse as logCompositionResponse2
89
+ EMPTY_COMPOSITION as EMPTY_COMPOSITION2
97
90
  } from "@uniformdev/canvas";
98
91
  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
- });
106
92
  return async function wrappedGetStaticProps(context) {
107
- var _a2;
93
+ var _a, _b;
108
94
  let slugString = resolveSlugFromParams({
109
95
  param: options == null ? void 0 : options.param,
110
96
  params: context == null ? void 0 : context.params
@@ -112,23 +98,24 @@ var withUniformGetStaticProps = (options) => {
112
98
  if (options == null ? void 0 : options.modifySlug) {
113
99
  slugString = options.modifySlug(slugString, context);
114
100
  }
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
+ });
115
107
  const { preview, previewData } = context;
116
108
  let composition = void 0;
117
109
  if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
118
- composition = { ...EMPTY_COMPOSITION2, _id: (_a2 = previewData.compositionId) != null ? _a2 : EMPTY_COMPOSITION2._id };
110
+ composition = { ...EMPTY_COMPOSITION2, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION2._id };
119
111
  } else {
120
112
  try {
121
- const time = Date.now();
122
113
  const response = await canvasClient.getCompositionBySlug({
123
114
  slug: slugString,
124
115
  state: preview || (options == null ? void 0 : options.preview) ? CANVAS_DRAFT_STATE3 : CANVAS_PUBLISHED_STATE3,
125
116
  ...options == null ? void 0 : options.requestOptions
126
117
  });
127
- const duration = Date.now() - time;
128
118
  composition = response.composition;
129
- if (!(options == null ? void 0 : options.silent)) {
130
- logCompositionResponse2(response, duration);
131
- }
132
119
  } catch (e) {
133
120
  console.error("[canvas-next] Failed to fetch composition", e);
134
121
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "19.9.2-alpha.3+547c8b11d",
3
+ "version": "19.10.0",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -63,11 +63,11 @@
63
63
  "document": "api-extractor run --local"
64
64
  },
65
65
  "dependencies": {
66
- "@uniformdev/canvas": "19.9.2-alpha.3+547c8b11d",
67
- "@uniformdev/canvas-react": "19.9.2-alpha.3+547c8b11d",
68
- "@uniformdev/project-map": "19.9.2-alpha.3+547c8b11d",
69
- "@uniformdev/redirect": "19.9.2-alpha.3+547c8b11d",
70
- "ansi-colors": "^4.1.3"
66
+ "@uniformdev/canvas": "19.10.0",
67
+ "@uniformdev/canvas-react": "19.10.0",
68
+ "@uniformdev/project-map": "19.10.0",
69
+ "@uniformdev/redirect": "19.10.0",
70
+ "chalk": "^5.2.0"
71
71
  },
72
72
  "peerDependencies": {
73
73
  "next": ">= 12.0.0",
@@ -86,5 +86,5 @@
86
86
  "publishConfig": {
87
87
  "access": "public"
88
88
  },
89
- "gitHead": "547c8b11d4655b34250c2fbe3f016c9bc12c3905"
89
+ "gitHead": "149f942da715ed802545850283f9b99291829a04"
90
90
  }