@uniformdev/canvas-next 19.14.1-alpha.1 → 19.14.1-alpha.11

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,3 +1,6 @@
1
+ import {
2
+ logCompositionResponse
3
+ } from "./chunk-6IDBHA5X.mjs";
1
4
  import {
2
5
  resolveSlugFromParams
3
6
  } from "./chunk-TR7V6ABJ.mjs";
@@ -7,8 +10,7 @@ import {
7
10
  CANVAS_DRAFT_STATE,
8
11
  CANVAS_PUBLISHED_STATE,
9
12
  CanvasClient,
10
- EMPTY_COMPOSITION,
11
- logCompositionResponse
13
+ EMPTY_COMPOSITION
12
14
  } from "@uniformdev/canvas";
13
15
  var withUniformGetServerSideProps = (options) => {
14
16
  const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
@@ -95,8 +97,7 @@ import {
95
97
  CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
96
98
  CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
97
99
  CanvasClient as CanvasClient2,
98
- EMPTY_COMPOSITION as EMPTY_COMPOSITION2,
99
- logCompositionResponse as logCompositionResponse2
100
+ EMPTY_COMPOSITION as EMPTY_COMPOSITION2
100
101
  } from "@uniformdev/canvas";
101
102
  var withUniformGetStaticProps = (options) => {
102
103
  var _a;
@@ -132,7 +133,7 @@ var withUniformGetStaticProps = (options) => {
132
133
  const duration = Date.now() - time;
133
134
  composition = response.composition;
134
135
  if (!(options == null ? void 0 : options.silent)) {
135
- logCompositionResponse2(response, duration);
136
+ logCompositionResponse(response, duration);
136
137
  }
137
138
  } catch (e) {
138
139
  console.error("[canvas-next] Failed to fetch composition", e);
@@ -0,0 +1,109 @@
1
+ // src/logging/logCompositionResponse.ts
2
+ import { white as white2 } from "colorette";
3
+
4
+ // src/logging/logCompositionIssues.ts
5
+ import { gray, green, italic, red, white, yellow } from "colorette";
6
+ function logCompositionIssues(prefix, issues, colour = "red") {
7
+ const reversedIssues = [...issues].reverse();
8
+ const colours = { red, green, yellow, white };
9
+ console.error(
10
+ `${colours[colour](prefix)}
11
+ ${reversedIssues.map(
12
+ (issue) => `${colours[colour](">")} ${italic(gray(indent(issue.type.toUpperCase(), 7)))} ${renderIssue(issue)}`
13
+ ).join("\n")}`
14
+ );
15
+ }
16
+ function renderIssue(issue) {
17
+ var _a;
18
+ let path;
19
+ let type;
20
+ let message = issue.message;
21
+ let detail;
22
+ if (issue.type !== "config") {
23
+ path = issue.componentPath;
24
+ type = issue.componentType;
25
+ message = issue.message;
26
+ }
27
+ if (issue.type === "binding") {
28
+ detail = `Binding expression: ${(_a = issue.expression) == null ? void 0 : _a.pointer}`;
29
+ } else if (issue.type === "data") {
30
+ detail = `Data resource name: ${issue.dataName}, data type: ${issue.dataType}`;
31
+ }
32
+ if (issue.type === "input") {
33
+ detail = issue.inputName;
34
+ }
35
+ let result = `${white(blockify(message))}`;
36
+ if (detail) {
37
+ result += `
38
+ ${indent(" ", 10)}${gray(`${detail}`)}`;
39
+ }
40
+ if (path && type) {
41
+ result += `
42
+ ${indent(" ", 10)}${gray(`Occurred on component ${type} at slot path ${path}`)}`;
43
+ }
44
+ return result;
45
+ }
46
+ function indent(str, len) {
47
+ const indent2 = len != null ? len : 10;
48
+ return str.padStart(indent2);
49
+ }
50
+ function blockify(str, len) {
51
+ const indentSize = len != null ? len : 10;
52
+ return str.split("\n").map((line, index) => index === 0 ? line : `${indent(" ", indentSize)}${line}`).join("\n");
53
+ }
54
+
55
+ // src/logging/logCompositionResponse.ts
56
+ function logCompositionResponse(compositionApiResponse, duration) {
57
+ var _a, _b;
58
+ const resErrors = (_a = compositionApiResponse.errors) != null ? _a : [];
59
+ const resWarnings = (_b = compositionApiResponse.warnings) != null ? _b : [];
60
+ if (resErrors.length > 0) {
61
+ logCompositionIssues(
62
+ `Composition data error${resErrors.length === 1 ? "" : "s"}; some content may be missing`,
63
+ resErrors,
64
+ "red"
65
+ );
66
+ }
67
+ if (resWarnings.length > 0) {
68
+ logCompositionIssues(
69
+ `Composition data warning${resWarnings.length === 1 ? "" : "s"}; some content may be missing`,
70
+ resWarnings,
71
+ "yellow"
72
+ );
73
+ }
74
+ if (compositionApiResponse.diagnostics) {
75
+ console.log(`
76
+ Diagnostics`);
77
+ const { compositionFetch, data } = compositionApiResponse.diagnostics;
78
+ const table = {
79
+ [`${white2("Composition")}`]: {
80
+ "Duration (ms)": resolveDiagnosticsDuration(compositionFetch),
81
+ "Edge Cached": compositionFetch == null ? void 0 : compositionFetch.cacheHit
82
+ }
83
+ };
84
+ if (data) {
85
+ data.forEach((d) => {
86
+ table[d.dataName] = {
87
+ "Duration (ms)": resolveDiagnosticsDuration(d.performance),
88
+ "Edge Cached": d.performance.cacheHit,
89
+ "Retry Count": d.performance.retryCount
90
+ };
91
+ });
92
+ }
93
+ table["Total Response"] = {
94
+ "Duration (ms)": duration != null ? duration : "no data"
95
+ };
96
+ console.table(table);
97
+ }
98
+ }
99
+ function resolveDiagnosticsDuration(data) {
100
+ var _a, _b;
101
+ if (!data) {
102
+ return "no data";
103
+ }
104
+ return (_b = (_a = data.duration) != null ? _a : data.total) != null ? _b : "no data";
105
+ }
106
+
107
+ export {
108
+ logCompositionResponse
109
+ };
@@ -32,6 +32,7 @@ declare const withUniformGetServerSideProps: <TProps extends {
32
32
  withComponentIDs?: boolean | undefined;
33
33
  withTotalCount?: boolean | undefined;
34
34
  withUIStatus?: boolean | undefined;
35
+ withContentSourceMap?: boolean | undefined;
35
36
  } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption>, "state"> | undefined;
36
37
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
37
38
  callback?: UniformGetServerSideProps<TProps> | undefined;
@@ -62,6 +63,7 @@ declare const withUniformGetStaticProps: <TProps extends {
62
63
  withComponentIDs?: boolean | undefined;
63
64
  withTotalCount?: boolean | undefined;
64
65
  withUIStatus?: boolean | undefined;
66
+ withContentSourceMap?: boolean | undefined;
65
67
  } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "projectMapNodePath">> & _uniformdev_canvas.SpecificProjectMap & DataResolutionOption>, "state"> | undefined;
66
68
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
67
69
  callback?: UniformGetStaticProps<TProps> | undefined;
@@ -31,6 +31,112 @@ module.exports = __toCommonJS(project_map_exports);
31
31
 
32
32
  // src/project-map/withUniformGetServerSideProps.ts
33
33
  var import_canvas = require("@uniformdev/canvas");
34
+
35
+ // src/logging/logCompositionIssues.ts
36
+ var import_colorette = require("colorette");
37
+ function logCompositionIssues(prefix, issues, colour = "red") {
38
+ const reversedIssues = [...issues].reverse();
39
+ const colours = { red: import_colorette.red, green: import_colorette.green, yellow: import_colorette.yellow, white: import_colorette.white };
40
+ console.error(
41
+ `${colours[colour](prefix)}
42
+ ${reversedIssues.map(
43
+ (issue) => `${colours[colour](">")} ${(0, import_colorette.italic)((0, import_colorette.gray)(indent(issue.type.toUpperCase(), 7)))} ${renderIssue(issue)}`
44
+ ).join("\n")}`
45
+ );
46
+ }
47
+ function renderIssue(issue) {
48
+ var _a;
49
+ let path;
50
+ let type;
51
+ let message = issue.message;
52
+ let detail;
53
+ if (issue.type !== "config") {
54
+ path = issue.componentPath;
55
+ type = issue.componentType;
56
+ message = issue.message;
57
+ }
58
+ if (issue.type === "binding") {
59
+ detail = `Binding expression: ${(_a = issue.expression) == null ? void 0 : _a.pointer}`;
60
+ } else if (issue.type === "data") {
61
+ detail = `Data resource name: ${issue.dataName}, data type: ${issue.dataType}`;
62
+ }
63
+ if (issue.type === "input") {
64
+ detail = issue.inputName;
65
+ }
66
+ let result = `${(0, import_colorette.white)(blockify(message))}`;
67
+ if (detail) {
68
+ result += `
69
+ ${indent(" ", 10)}${(0, import_colorette.gray)(`${detail}`)}`;
70
+ }
71
+ if (path && type) {
72
+ result += `
73
+ ${indent(" ", 10)}${(0, import_colorette.gray)(`Occurred on component ${type} at slot path ${path}`)}`;
74
+ }
75
+ return result;
76
+ }
77
+ function indent(str, len) {
78
+ const indent2 = len != null ? len : 10;
79
+ return str.padStart(indent2);
80
+ }
81
+ function blockify(str, len) {
82
+ const indentSize = len != null ? len : 10;
83
+ return str.split("\n").map((line, index) => index === 0 ? line : `${indent(" ", indentSize)}${line}`).join("\n");
84
+ }
85
+
86
+ // src/logging/logCompositionResponse.ts
87
+ var import_colorette2 = require("colorette");
88
+ function logCompositionResponse(compositionApiResponse, duration) {
89
+ var _a, _b;
90
+ const resErrors = (_a = compositionApiResponse.errors) != null ? _a : [];
91
+ const resWarnings = (_b = compositionApiResponse.warnings) != null ? _b : [];
92
+ if (resErrors.length > 0) {
93
+ logCompositionIssues(
94
+ `Composition data error${resErrors.length === 1 ? "" : "s"}; some content may be missing`,
95
+ resErrors,
96
+ "red"
97
+ );
98
+ }
99
+ if (resWarnings.length > 0) {
100
+ logCompositionIssues(
101
+ `Composition data warning${resWarnings.length === 1 ? "" : "s"}; some content may be missing`,
102
+ resWarnings,
103
+ "yellow"
104
+ );
105
+ }
106
+ if (compositionApiResponse.diagnostics) {
107
+ console.log(`
108
+ Diagnostics`);
109
+ const { compositionFetch, data } = compositionApiResponse.diagnostics;
110
+ const table = {
111
+ [`${(0, import_colorette2.white)("Composition")}`]: {
112
+ "Duration (ms)": resolveDiagnosticsDuration(compositionFetch),
113
+ "Edge Cached": compositionFetch == null ? void 0 : compositionFetch.cacheHit
114
+ }
115
+ };
116
+ if (data) {
117
+ data.forEach((d) => {
118
+ table[d.dataName] = {
119
+ "Duration (ms)": resolveDiagnosticsDuration(d.performance),
120
+ "Edge Cached": d.performance.cacheHit,
121
+ "Retry Count": d.performance.retryCount
122
+ };
123
+ });
124
+ }
125
+ table["Total Response"] = {
126
+ "Duration (ms)": duration != null ? duration : "no data"
127
+ };
128
+ console.table(table);
129
+ }
130
+ }
131
+ function resolveDiagnosticsDuration(data) {
132
+ var _a, _b;
133
+ if (!data) {
134
+ return "no data";
135
+ }
136
+ return (_b = (_a = data.duration) != null ? _a : data.total) != null ? _b : "no data";
137
+ }
138
+
139
+ // src/project-map/withUniformGetServerSideProps.ts
34
140
  var withUniformGetServerSideProps = (options) => {
35
141
  const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
36
142
  apiKey: process.env.UNIFORM_API_KEY,
@@ -61,7 +167,7 @@ var withUniformGetServerSideProps = (options) => {
61
167
  const duration = Date.now() - time;
62
168
  composition = response.composition;
63
169
  if (!(options == null ? void 0 : options.silent)) {
64
- (0, import_canvas.logCompositionResponse)(response, duration);
170
+ logCompositionResponse(response, duration);
65
171
  }
66
172
  } catch (e) {
67
173
  console.error("[canvas-next] Failed to fetch composition", e);
@@ -157,7 +263,7 @@ var withUniformGetStaticProps = (options) => {
157
263
  const duration = Date.now() - time;
158
264
  composition = response.composition;
159
265
  if (!(options == null ? void 0 : options.silent)) {
160
- (0, import_canvas3.logCompositionResponse)(response, duration);
266
+ logCompositionResponse(response, duration);
161
267
  }
162
268
  } catch (e) {
163
269
  console.error("[canvas-next] Failed to fetch composition", e);
@@ -5,7 +5,8 @@ import {
5
5
  withUniformGetServerSideProps,
6
6
  withUniformGetStaticPaths,
7
7
  withUniformGetStaticProps
8
- } from "../chunk-ZOXJSPVQ.mjs";
8
+ } from "../chunk-23O4NSDU.mjs";
9
+ import "../chunk-6IDBHA5X.mjs";
9
10
  import "../chunk-TR7V6ABJ.mjs";
10
11
  export {
11
12
  getServerSideProps,
@@ -136,7 +136,7 @@ declare const unstable_getServerSideProps: next.GetServerSideProps<{
136
136
  } | undefined;
137
137
  _overridability?: {
138
138
  parameters?: {
139
- [key: string]: "yes" | "no";
139
+ [key: string]: "no" | "yes";
140
140
  } | undefined;
141
141
  variants?: boolean | undefined;
142
142
  } | undefined;
@@ -172,7 +172,7 @@ declare const unstable_getServerSideProps: next.GetServerSideProps<{
172
172
  } | undefined;
173
173
  _overridability?: {
174
174
  parameters?: {
175
- [key: string]: "yes" | "no";
175
+ [key: string]: "no" | "yes";
176
176
  } | undefined;
177
177
  variants?: boolean | undefined;
178
178
  } | undefined;
@@ -255,7 +255,7 @@ declare const unstable_getStaticProps: next.GetStaticProps<{
255
255
  } | undefined;
256
256
  _overridability?: {
257
257
  parameters?: {
258
- [key: string]: "yes" | "no";
258
+ [key: string]: "no" | "yes";
259
259
  } | undefined;
260
260
  variants?: boolean | undefined;
261
261
  } | undefined;
@@ -291,7 +291,7 @@ declare const unstable_getStaticProps: next.GetStaticProps<{
291
291
  } | undefined;
292
292
  _overridability?: {
293
293
  parameters?: {
294
- [key: string]: "yes" | "no";
294
+ [key: string]: "no" | "yes";
295
295
  } | undefined;
296
296
  variants?: boolean | undefined;
297
297
  } | undefined;
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/route/index.ts
@@ -41,6 +31,160 @@ module.exports = __toCommonJS(route_exports);
41
31
 
42
32
  // src/project-map/withUniformGetServerSideProps.ts
43
33
  var import_canvas = require("@uniformdev/canvas");
34
+
35
+ // src/logging/logCompositionIssues.ts
36
+ var import_colorette = require("colorette");
37
+ function logCompositionIssues(prefix, issues, colour = "red") {
38
+ const reversedIssues = [...issues].reverse();
39
+ const colours = { red: import_colorette.red, green: import_colorette.green, yellow: import_colorette.yellow, white: import_colorette.white };
40
+ console.error(
41
+ `${colours[colour](prefix)}
42
+ ${reversedIssues.map(
43
+ (issue) => `${colours[colour](">")} ${(0, import_colorette.italic)((0, import_colorette.gray)(indent(issue.type.toUpperCase(), 7)))} ${renderIssue(issue)}`
44
+ ).join("\n")}`
45
+ );
46
+ }
47
+ function renderIssue(issue) {
48
+ var _a;
49
+ let path;
50
+ let type;
51
+ let message = issue.message;
52
+ let detail;
53
+ if (issue.type !== "config") {
54
+ path = issue.componentPath;
55
+ type = issue.componentType;
56
+ message = issue.message;
57
+ }
58
+ if (issue.type === "binding") {
59
+ detail = `Binding expression: ${(_a = issue.expression) == null ? void 0 : _a.pointer}`;
60
+ } else if (issue.type === "data") {
61
+ detail = `Data resource name: ${issue.dataName}, data type: ${issue.dataType}`;
62
+ }
63
+ if (issue.type === "input") {
64
+ detail = issue.inputName;
65
+ }
66
+ let result = `${(0, import_colorette.white)(blockify(message))}`;
67
+ if (detail) {
68
+ result += `
69
+ ${indent(" ", 10)}${(0, import_colorette.gray)(`${detail}`)}`;
70
+ }
71
+ if (path && type) {
72
+ result += `
73
+ ${indent(" ", 10)}${(0, import_colorette.gray)(`Occurred on component ${type} at slot path ${path}`)}`;
74
+ }
75
+ return result;
76
+ }
77
+ function indent(str, len) {
78
+ const indent2 = len != null ? len : 10;
79
+ return str.padStart(indent2);
80
+ }
81
+ function blockify(str, len) {
82
+ const indentSize = len != null ? len : 10;
83
+ return str.split("\n").map((line, index) => index === 0 ? line : `${indent(" ", indentSize)}${line}`).join("\n");
84
+ }
85
+
86
+ // src/logging/logCompositionResponse.ts
87
+ var import_colorette2 = require("colorette");
88
+ function logCompositionResponse(compositionApiResponse, duration) {
89
+ var _a, _b;
90
+ const resErrors = (_a = compositionApiResponse.errors) != null ? _a : [];
91
+ const resWarnings = (_b = compositionApiResponse.warnings) != null ? _b : [];
92
+ if (resErrors.length > 0) {
93
+ logCompositionIssues(
94
+ `Composition data error${resErrors.length === 1 ? "" : "s"}; some content may be missing`,
95
+ resErrors,
96
+ "red"
97
+ );
98
+ }
99
+ if (resWarnings.length > 0) {
100
+ logCompositionIssues(
101
+ `Composition data warning${resWarnings.length === 1 ? "" : "s"}; some content may be missing`,
102
+ resWarnings,
103
+ "yellow"
104
+ );
105
+ }
106
+ if (compositionApiResponse.diagnostics) {
107
+ console.log(`
108
+ Diagnostics`);
109
+ const { compositionFetch, data } = compositionApiResponse.diagnostics;
110
+ const table = {
111
+ [`${(0, import_colorette2.white)("Composition")}`]: {
112
+ "Duration (ms)": resolveDiagnosticsDuration(compositionFetch),
113
+ "Edge Cached": compositionFetch == null ? void 0 : compositionFetch.cacheHit
114
+ }
115
+ };
116
+ if (data) {
117
+ data.forEach((d) => {
118
+ table[d.dataName] = {
119
+ "Duration (ms)": resolveDiagnosticsDuration(d.performance),
120
+ "Edge Cached": d.performance.cacheHit,
121
+ "Retry Count": d.performance.retryCount
122
+ };
123
+ });
124
+ }
125
+ table["Total Response"] = {
126
+ "Duration (ms)": duration != null ? duration : "no data"
127
+ };
128
+ console.table(table);
129
+ }
130
+ }
131
+ function resolveDiagnosticsDuration(data) {
132
+ var _a, _b;
133
+ if (!data) {
134
+ return "no data";
135
+ }
136
+ return (_b = (_a = data.duration) != null ? _a : data.total) != null ? _b : "no data";
137
+ }
138
+
139
+ // src/logging/logCompositionRouteResponse.ts
140
+ var import_colorette3 = require("colorette");
141
+ function logRouteCompositionResponse(matched, duration) {
142
+ var _a, _b;
143
+ const resErrors = (_a = matched.compositionApiResponse.errors) != null ? _a : [];
144
+ const resWarnings = (_b = matched.compositionApiResponse.warnings) != null ? _b : [];
145
+ const colour = resErrors.length > 0 ? import_colorette3.red : resWarnings.length > 0 ? import_colorette3.yellow : import_colorette3.green;
146
+ console.log(`${colour("Matched")} ${matched.type} ${matched.matchedRoute} (${duration}ms)`);
147
+ if (matched.dynamicInputs) {
148
+ const entries = Object.entries(matched.dynamicInputs);
149
+ if (entries.length > 0) {
150
+ console.log(
151
+ ` ${(0, import_colorette3.gray)("Matched dynamic inputs:\n ")}`,
152
+ entries.map(([k, v]) => `${k}: ${v}`).join("\n ")
153
+ );
154
+ }
155
+ }
156
+ logCompositionResponse(matched.compositionApiResponse, duration);
157
+ }
158
+
159
+ // src/logging/logNotFoundRouteResponse.ts
160
+ var import_colorette4 = require("colorette");
161
+ function logNotFoundRouteResponse(_matched, duration) {
162
+ console.log(`${(0, import_colorette4.yellow)("Not found")} no project map or redirect path match (${duration}ms)`);
163
+ }
164
+
165
+ // src/logging/logRedirectRouteResponse.ts
166
+ var import_colorette5 = require("colorette");
167
+ function logRedirectRouteResponse(matched, duration) {
168
+ console.log(
169
+ `${(0, import_colorette5.green)("Matched")} ${matched.type} ${matched.matchedRoute} (${duration}ms)
170
+ Target: ${matched.redirect.targetUrl}`
171
+ );
172
+ }
173
+
174
+ // src/logging/logRouteResponse.ts
175
+ function logRouteResponse(response, duration) {
176
+ if (response.type === "redirect") {
177
+ logRedirectRouteResponse(response, duration);
178
+ return;
179
+ }
180
+ if (response.type === "notFound") {
181
+ logNotFoundRouteResponse(response, duration);
182
+ return;
183
+ }
184
+ logRouteCompositionResponse(response, duration);
185
+ }
186
+
187
+ // src/project-map/withUniformGetServerSideProps.ts
44
188
  var withUniformGetServerSideProps = (options) => {
45
189
  const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
46
190
  apiKey: process.env.UNIFORM_API_KEY,
@@ -71,7 +215,7 @@ var withUniformGetServerSideProps = (options) => {
71
215
  const duration = Date.now() - time;
72
216
  composition = response.composition;
73
217
  if (!(options == null ? void 0 : options.silent)) {
74
- (0, import_canvas.logCompositionResponse)(response, duration);
218
+ logCompositionResponse(response, duration);
75
219
  }
76
220
  } catch (e) {
77
221
  console.error("[canvas-next] Failed to fetch composition", e);
@@ -167,7 +311,7 @@ var withUniformGetStaticProps = (options) => {
167
311
  const duration = Date.now() - time;
168
312
  composition = response.composition;
169
313
  if (!(options == null ? void 0 : options.silent)) {
170
- (0, import_canvas3.logCompositionResponse)(response, duration);
314
+ logCompositionResponse(response, duration);
171
315
  }
172
316
  } catch (e) {
173
317
  console.error("[canvas-next] Failed to fetch composition", e);
@@ -195,8 +339,7 @@ var import_redirect = require("@uniformdev/redirect");
195
339
 
196
340
  // src/route/createRouteFetcher.ts
197
341
  var import_canvas4 = require("@uniformdev/canvas");
198
- var import_ansi_colors = __toESM(require("ansi-colors"));
199
- var { red } = import_ansi_colors.default;
342
+ var import_colorette6 = require("colorette");
200
343
  function createRouteFetcher(options) {
201
344
  const {
202
345
  handleNotFound,
@@ -292,7 +435,7 @@ function createRouteFetcher(options) {
292
435
  });
293
436
  const duration = Date.now() - time;
294
437
  if (!silent) {
295
- (0, import_canvas4.logRouteResponse)(response, duration);
438
+ logRouteResponse(response, duration);
296
439
  }
297
440
  if (response.type === "redirect") {
298
441
  return invokeRedirectResult(response, duration);
@@ -306,7 +449,7 @@ function createRouteFetcher(options) {
306
449
  }
307
450
  return handleResult;
308
451
  } catch (e) {
309
- console.error(red("Failed to fetch route"), e);
452
+ console.error((0, import_colorette6.red)("Failed to fetch route"), e);
310
453
  if (e instanceof import_canvas4.ApiClientError) {
311
454
  if (e.statusCode === 404) {
312
455
  return invokeNotFoundResult({ type: "notFound" }, 0);
@@ -1,10 +1,61 @@
1
1
  import {
2
2
  withUniformGetStaticPaths
3
- } from "../chunk-ZOXJSPVQ.mjs";
3
+ } from "../chunk-23O4NSDU.mjs";
4
+ import {
5
+ logCompositionResponse
6
+ } from "../chunk-6IDBHA5X.mjs";
4
7
  import {
5
8
  resolveSlugFromParams
6
9
  } from "../chunk-TR7V6ABJ.mjs";
7
10
 
11
+ // src/logging/logCompositionRouteResponse.ts
12
+ import { gray, green, red, yellow } from "colorette";
13
+ function logRouteCompositionResponse(matched, duration) {
14
+ var _a, _b;
15
+ const resErrors = (_a = matched.compositionApiResponse.errors) != null ? _a : [];
16
+ const resWarnings = (_b = matched.compositionApiResponse.warnings) != null ? _b : [];
17
+ const colour = resErrors.length > 0 ? red : resWarnings.length > 0 ? yellow : green;
18
+ console.log(`${colour("Matched")} ${matched.type} ${matched.matchedRoute} (${duration}ms)`);
19
+ if (matched.dynamicInputs) {
20
+ const entries = Object.entries(matched.dynamicInputs);
21
+ if (entries.length > 0) {
22
+ console.log(
23
+ ` ${gray("Matched dynamic inputs:\n ")}`,
24
+ entries.map(([k, v]) => `${k}: ${v}`).join("\n ")
25
+ );
26
+ }
27
+ }
28
+ logCompositionResponse(matched.compositionApiResponse, duration);
29
+ }
30
+
31
+ // src/logging/logNotFoundRouteResponse.ts
32
+ import { yellow as yellow2 } from "colorette";
33
+ function logNotFoundRouteResponse(_matched, duration) {
34
+ console.log(`${yellow2("Not found")} no project map or redirect path match (${duration}ms)`);
35
+ }
36
+
37
+ // src/logging/logRedirectRouteResponse.ts
38
+ import { green as green2 } from "colorette";
39
+ function logRedirectRouteResponse(matched, duration) {
40
+ console.log(
41
+ `${green2("Matched")} ${matched.type} ${matched.matchedRoute} (${duration}ms)
42
+ Target: ${matched.redirect.targetUrl}`
43
+ );
44
+ }
45
+
46
+ // src/logging/logRouteResponse.ts
47
+ function logRouteResponse(response, duration) {
48
+ if (response.type === "redirect") {
49
+ logRedirectRouteResponse(response, duration);
50
+ return;
51
+ }
52
+ if (response.type === "notFound") {
53
+ logNotFoundRouteResponse(response, duration);
54
+ return;
55
+ }
56
+ logRouteCompositionResponse(response, duration);
57
+ }
58
+
8
59
  // src/route/withUniformGetServerSideProps.ts
9
60
  import { RedirectClient } from "@uniformdev/redirect";
10
61
 
@@ -12,11 +63,9 @@ import { RedirectClient } from "@uniformdev/redirect";
12
63
  import {
13
64
  ApiClientError,
14
65
  EMPTY_COMPOSITION,
15
- logRouteResponse,
16
66
  unstable_RouteClient
17
67
  } from "@uniformdev/canvas";
18
- import ansicolors from "ansi-colors";
19
- var { red } = ansicolors;
68
+ import { red as red2 } from "colorette";
20
69
  function createRouteFetcher(options) {
21
70
  const {
22
71
  handleNotFound,
@@ -126,7 +175,7 @@ function createRouteFetcher(options) {
126
175
  }
127
176
  return handleResult;
128
177
  } catch (e) {
129
- console.error(red("Failed to fetch route"), e);
178
+ console.error(red2("Failed to fetch route"), e);
130
179
  if (e instanceof ApiClientError) {
131
180
  if (e.statusCode === 404) {
132
181
  return invokeNotFoundResult({ type: "notFound" }, 0);
@@ -28,6 +28,7 @@ declare const withUniformGetServerSideProps: <TProps extends {
28
28
  withComponentIDs?: boolean | undefined;
29
29
  withTotalCount?: boolean | undefined;
30
30
  withUIStatus?: boolean | undefined;
31
+ withContentSourceMap?: boolean | undefined;
31
32
  } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
32
33
  callback?: UniformGetServerSideProps<TProps> | undefined;
33
34
  /** Disables logging of response information and timings */
@@ -73,6 +74,7 @@ declare const withUniformGetStaticProps: <TProps extends {
73
74
  withComponentIDs?: boolean | undefined;
74
75
  withTotalCount?: boolean | undefined;
75
76
  withUIStatus?: boolean | undefined;
77
+ withContentSourceMap?: boolean | undefined;
76
78
  } & Required<Pick<_uniformdev_canvas.CompositionGetParameters, "slug">> & DataResolutionOption>, "state"> | undefined;
77
79
  /** Custom handler to specify return value and modify composition - e.g. enhance with CMS data */
78
80
  callback?: UniformGetStaticProps<TProps> | undefined;
@@ -31,6 +31,112 @@ module.exports = __toCommonJS(slug_exports);
31
31
 
32
32
  // src/slug/withUniformGetServerSideProps.ts
33
33
  var import_canvas = require("@uniformdev/canvas");
34
+
35
+ // src/logging/logCompositionIssues.ts
36
+ var import_colorette = require("colorette");
37
+ function logCompositionIssues(prefix, issues, colour = "red") {
38
+ const reversedIssues = [...issues].reverse();
39
+ const colours = { red: import_colorette.red, green: import_colorette.green, yellow: import_colorette.yellow, white: import_colorette.white };
40
+ console.error(
41
+ `${colours[colour](prefix)}
42
+ ${reversedIssues.map(
43
+ (issue) => `${colours[colour](">")} ${(0, import_colorette.italic)((0, import_colorette.gray)(indent(issue.type.toUpperCase(), 7)))} ${renderIssue(issue)}`
44
+ ).join("\n")}`
45
+ );
46
+ }
47
+ function renderIssue(issue) {
48
+ var _a;
49
+ let path;
50
+ let type;
51
+ let message = issue.message;
52
+ let detail;
53
+ if (issue.type !== "config") {
54
+ path = issue.componentPath;
55
+ type = issue.componentType;
56
+ message = issue.message;
57
+ }
58
+ if (issue.type === "binding") {
59
+ detail = `Binding expression: ${(_a = issue.expression) == null ? void 0 : _a.pointer}`;
60
+ } else if (issue.type === "data") {
61
+ detail = `Data resource name: ${issue.dataName}, data type: ${issue.dataType}`;
62
+ }
63
+ if (issue.type === "input") {
64
+ detail = issue.inputName;
65
+ }
66
+ let result = `${(0, import_colorette.white)(blockify(message))}`;
67
+ if (detail) {
68
+ result += `
69
+ ${indent(" ", 10)}${(0, import_colorette.gray)(`${detail}`)}`;
70
+ }
71
+ if (path && type) {
72
+ result += `
73
+ ${indent(" ", 10)}${(0, import_colorette.gray)(`Occurred on component ${type} at slot path ${path}`)}`;
74
+ }
75
+ return result;
76
+ }
77
+ function indent(str, len) {
78
+ const indent2 = len != null ? len : 10;
79
+ return str.padStart(indent2);
80
+ }
81
+ function blockify(str, len) {
82
+ const indentSize = len != null ? len : 10;
83
+ return str.split("\n").map((line, index) => index === 0 ? line : `${indent(" ", indentSize)}${line}`).join("\n");
84
+ }
85
+
86
+ // src/logging/logCompositionResponse.ts
87
+ var import_colorette2 = require("colorette");
88
+ function logCompositionResponse(compositionApiResponse, duration) {
89
+ var _a, _b;
90
+ const resErrors = (_a = compositionApiResponse.errors) != null ? _a : [];
91
+ const resWarnings = (_b = compositionApiResponse.warnings) != null ? _b : [];
92
+ if (resErrors.length > 0) {
93
+ logCompositionIssues(
94
+ `Composition data error${resErrors.length === 1 ? "" : "s"}; some content may be missing`,
95
+ resErrors,
96
+ "red"
97
+ );
98
+ }
99
+ if (resWarnings.length > 0) {
100
+ logCompositionIssues(
101
+ `Composition data warning${resWarnings.length === 1 ? "" : "s"}; some content may be missing`,
102
+ resWarnings,
103
+ "yellow"
104
+ );
105
+ }
106
+ if (compositionApiResponse.diagnostics) {
107
+ console.log(`
108
+ Diagnostics`);
109
+ const { compositionFetch, data } = compositionApiResponse.diagnostics;
110
+ const table = {
111
+ [`${(0, import_colorette2.white)("Composition")}`]: {
112
+ "Duration (ms)": resolveDiagnosticsDuration(compositionFetch),
113
+ "Edge Cached": compositionFetch == null ? void 0 : compositionFetch.cacheHit
114
+ }
115
+ };
116
+ if (data) {
117
+ data.forEach((d) => {
118
+ table[d.dataName] = {
119
+ "Duration (ms)": resolveDiagnosticsDuration(d.performance),
120
+ "Edge Cached": d.performance.cacheHit,
121
+ "Retry Count": d.performance.retryCount
122
+ };
123
+ });
124
+ }
125
+ table["Total Response"] = {
126
+ "Duration (ms)": duration != null ? duration : "no data"
127
+ };
128
+ console.table(table);
129
+ }
130
+ }
131
+ function resolveDiagnosticsDuration(data) {
132
+ var _a, _b;
133
+ if (!data) {
134
+ return "no data";
135
+ }
136
+ return (_b = (_a = data.duration) != null ? _a : data.total) != null ? _b : "no data";
137
+ }
138
+
139
+ // src/slug/withUniformGetServerSideProps.ts
34
140
  var withUniformGetServerSideProps = (options) => {
35
141
  const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
36
142
  apiKey: process.env.UNIFORM_API_KEY,
@@ -59,7 +165,7 @@ var withUniformGetServerSideProps = (options) => {
59
165
  const duration = Date.now() - time;
60
166
  composition = response.composition;
61
167
  if (!(options == null ? void 0 : options.silent)) {
62
- (0, import_canvas.logCompositionResponse)(response, duration);
168
+ logCompositionResponse(response, duration);
63
169
  }
64
170
  } catch (e) {
65
171
  console.error("[canvas-next] Failed to fetch composition", e);
@@ -150,7 +256,7 @@ var withUniformGetStaticProps = (options) => {
150
256
  const duration = Date.now() - time;
151
257
  composition = response.composition;
152
258
  if (!(options == null ? void 0 : options.silent)) {
153
- (0, import_canvas3.logCompositionResponse)(response, duration);
259
+ logCompositionResponse(response, duration);
154
260
  }
155
261
  } catch (e) {
156
262
  console.error("[canvas-next] Failed to fetch composition", e);
@@ -1,3 +1,6 @@
1
+ import {
2
+ logCompositionResponse
3
+ } from "../chunk-6IDBHA5X.mjs";
1
4
  import {
2
5
  resolveSlugFromParams
3
6
  } from "../chunk-TR7V6ABJ.mjs";
@@ -7,8 +10,7 @@ import {
7
10
  CANVAS_DRAFT_STATE,
8
11
  CANVAS_PUBLISHED_STATE,
9
12
  CanvasClient,
10
- EMPTY_COMPOSITION,
11
- logCompositionResponse
13
+ EMPTY_COMPOSITION
12
14
  } from "@uniformdev/canvas";
13
15
  var withUniformGetServerSideProps = (options) => {
14
16
  const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
@@ -92,8 +94,7 @@ import {
92
94
  CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
93
95
  CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
94
96
  CanvasClient as CanvasClient3,
95
- EMPTY_COMPOSITION as EMPTY_COMPOSITION2,
96
- logCompositionResponse as logCompositionResponse2
97
+ EMPTY_COMPOSITION as EMPTY_COMPOSITION2
97
98
  } from "@uniformdev/canvas";
98
99
  var withUniformGetStaticProps = (options) => {
99
100
  var _a;
@@ -127,7 +128,7 @@ var withUniformGetStaticProps = (options) => {
127
128
  const duration = Date.now() - time;
128
129
  composition = response.composition;
129
130
  if (!(options == null ? void 0 : options.silent)) {
130
- logCompositionResponse2(response, duration);
131
+ logCompositionResponse(response, duration);
131
132
  }
132
133
  } catch (e) {
133
134
  console.error("[canvas-next] Failed to fetch composition", e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "19.14.1-alpha.1+597b21eaa",
3
+ "version": "19.14.1-alpha.11+89dabee14",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -63,12 +63,12 @@
63
63
  "document": "api-extractor run --local"
64
64
  },
65
65
  "dependencies": {
66
- "@uniformdev/canvas": "19.14.1-alpha.1+597b21eaa",
67
- "@uniformdev/canvas-react": "19.14.1-alpha.1+597b21eaa",
68
- "@uniformdev/project-map": "19.14.1-alpha.1+597b21eaa",
69
- "@uniformdev/redirect": "19.14.1-alpha.1+597b21eaa",
70
- "@uniformdev/richtext": "19.14.1-alpha.1+597b21eaa",
71
- "ansi-colors": "^4.1.3"
66
+ "@uniformdev/canvas": "19.14.1-alpha.11+89dabee14",
67
+ "@uniformdev/canvas-react": "19.14.1-alpha.11+89dabee14",
68
+ "@uniformdev/project-map": "19.14.1-alpha.11+89dabee14",
69
+ "@uniformdev/redirect": "19.14.1-alpha.11+89dabee14",
70
+ "@uniformdev/richtext": "19.14.1-alpha.11+89dabee14",
71
+ "colorette": "2.0.20"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "next": ">= 12.0.0",
@@ -87,5 +87,5 @@
87
87
  "publishConfig": {
88
88
  "access": "public"
89
89
  },
90
- "gitHead": "597b21eaa0a61271b8951de1d443019868f7699c"
90
+ "gitHead": "89dabee148728ef7f329e18b7194766a9e6b9631"
91
91
  }