@uniformdev/canvas-next 19.58.2-alpha.0 → 19.58.2-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.
@@ -4,11 +4,10 @@ import { white as white2 } from "colorette";
4
4
  // src/logging/logCompositionIssues.ts
5
5
  import { gray, green, italic, red, white, yellow } from "colorette";
6
6
  function logCompositionIssues(prefix, issues, colour = "red") {
7
- const reversedIssues = [...issues].reverse();
8
7
  const colours = { red, green, yellow, white };
9
8
  console.error(
10
9
  `${colours[colour](prefix)}
11
- ${reversedIssues.map(
10
+ ${issues.map(
12
11
  (issue) => `${colours[colour](">")} ${italic(gray(indent(issue.type.toUpperCase(), 7)))} ${renderIssue(issue)}`
13
12
  ).join("\n")}`
14
13
  );
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logCompositionResponse
3
- } from "./chunk-6IDBHA5X.mjs";
3
+ } from "./chunk-JQWYBVLI.mjs";
4
4
  import {
5
5
  resolveSlugFromParams
6
6
  } from "./chunk-TR7V6ABJ.mjs";
package/dist/index.esm.js CHANGED
@@ -51,7 +51,8 @@ var UniformRichTextNode = ({
51
51
  // src/preview/previewHandlerGet.ts
52
52
  import {
53
53
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
54
- IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
54
+ IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
55
+ SECRET_QUERY_STRING_PARAM
55
56
  } from "@uniformdev/canvas";
56
57
  import { isAllowedReferrer } from "@uniformdev/canvas";
57
58
  var BASE_URL_EXAMPLE = "https://example.com";
@@ -62,10 +63,16 @@ var getQueryParam = (req, paramName) => {
62
63
  }
63
64
  return Array.isArray(value) ? value[0] : value;
64
65
  };
65
- var queryParamsToPreserve = [
66
+ var contextualEditingQueryParams = [
66
67
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
67
68
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
68
69
  ];
70
+ var compositionQueryParam = {
71
+ id: "id",
72
+ slug: "slug",
73
+ path: "path",
74
+ locale: "locale"
75
+ };
69
76
  var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault, playgroundPath } = {}) => async (req, res) => {
70
77
  const isConfigCheck = getQueryParam(req, "is_config_check") === "true";
71
78
  if (isConfigCheck) {
@@ -82,10 +89,10 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
82
89
  if (isPlayground && playgroundPath) {
83
90
  pathToRedirectTo = playgroundPath;
84
91
  }
85
- const id = getQueryParam(req, "id");
86
- const slug = getQueryParam(req, "slug");
87
- const path = getQueryParam(req, "path");
88
- const locale = getQueryParam(req, "locale");
92
+ const id = getQueryParam(req, compositionQueryParam.id);
93
+ const slug = getQueryParam(req, compositionQueryParam.slug);
94
+ const path = getQueryParam(req, compositionQueryParam.path);
95
+ const locale = getQueryParam(req, compositionQueryParam.locale);
89
96
  if (typeof pathToRedirectTo === "undefined") {
90
97
  pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
91
98
  }
@@ -100,7 +107,7 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
100
107
  }
101
108
  const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
102
109
  const isUsingPreviewSecret = Boolean(previewSecret);
103
- if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
110
+ if (isUsingPreviewSecret && req.query[SECRET_QUERY_STRING_PARAM] !== previewSecret) {
104
111
  return res.status(401).json({ message: "Invalid token" });
105
112
  }
106
113
  const isUniformContextualEditing = req.query[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true" && isAllowedReferrer(req.headers.referer);
@@ -127,12 +134,10 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
127
134
  cookies == null ? void 0 : cookies.map((cookie) => cookie.replace("SameSite=Lax", "SameSite=None;Secure"))
128
135
  );
129
136
  const redirectionUrl = new URL(pathToRedirectTo, BASE_URL_EXAMPLE);
130
- if (isUniformContextualEditing) {
131
- queryParamsToPreserve.forEach((param) => {
132
- const paramValue = req.query[param];
133
- if (typeof paramValue === "string") {
134
- redirectionUrl.searchParams.append(param, paramValue);
135
- }
137
+ assignRequestQueryToSearchParams(redirectionUrl.searchParams, req.query);
138
+ if (!isUniformContextualEditing) {
139
+ contextualEditingQueryParams.forEach((param) => {
140
+ redirectionUrl.searchParams.delete(param);
136
141
  });
137
142
  }
138
143
  const fullPathToRedirectTo = redirectionUrl.href.replace(BASE_URL_EXAMPLE, "");
@@ -146,6 +151,25 @@ function validateLocalRedirectUrl(pathToRedirectTo) {
146
151
  throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
147
152
  }
148
153
  }
154
+ var assignRequestQueryToSearchParams = (searchParams, query) => {
155
+ const compositionQueryParamNames = Object.values(compositionQueryParam);
156
+ Object.entries(query).forEach(([name, value]) => {
157
+ if (name === SECRET_QUERY_STRING_PARAM) {
158
+ return;
159
+ }
160
+ if (compositionQueryParamNames.includes(name)) {
161
+ return;
162
+ }
163
+ if (typeof value === "undefined") {
164
+ return;
165
+ }
166
+ if (typeof value === "object") {
167
+ value.forEach((singleValue) => searchParams.append(name, singleValue));
168
+ return;
169
+ }
170
+ searchParams.append(name, value);
171
+ });
172
+ };
149
173
 
150
174
  // src/preview/previewHandlerPost.ts
151
175
  import { generateHash } from "@uniformdev/canvas";
package/dist/index.js CHANGED
@@ -105,10 +105,16 @@ var getQueryParam = (req, paramName) => {
105
105
  }
106
106
  return Array.isArray(value) ? value[0] : value;
107
107
  };
108
- var queryParamsToPreserve = [
108
+ var contextualEditingQueryParams = [
109
109
  import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
110
110
  import_canvas.IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
111
111
  ];
112
+ var compositionQueryParam = {
113
+ id: "id",
114
+ slug: "slug",
115
+ path: "path",
116
+ locale: "locale"
117
+ };
112
118
  var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault, playgroundPath } = {}) => async (req, res) => {
113
119
  const isConfigCheck = getQueryParam(req, "is_config_check") === "true";
114
120
  if (isConfigCheck) {
@@ -125,10 +131,10 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
125
131
  if (isPlayground && playgroundPath) {
126
132
  pathToRedirectTo = playgroundPath;
127
133
  }
128
- const id = getQueryParam(req, "id");
129
- const slug = getQueryParam(req, "slug");
130
- const path = getQueryParam(req, "path");
131
- const locale = getQueryParam(req, "locale");
134
+ const id = getQueryParam(req, compositionQueryParam.id);
135
+ const slug = getQueryParam(req, compositionQueryParam.slug);
136
+ const path = getQueryParam(req, compositionQueryParam.path);
137
+ const locale = getQueryParam(req, compositionQueryParam.locale);
132
138
  if (typeof pathToRedirectTo === "undefined") {
133
139
  pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
134
140
  }
@@ -143,7 +149,7 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
143
149
  }
144
150
  const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
145
151
  const isUsingPreviewSecret = Boolean(previewSecret);
146
- if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
152
+ if (isUsingPreviewSecret && req.query[import_canvas.SECRET_QUERY_STRING_PARAM] !== previewSecret) {
147
153
  return res.status(401).json({ message: "Invalid token" });
148
154
  }
149
155
  const isUniformContextualEditing = req.query[import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true" && (0, import_canvas2.isAllowedReferrer)(req.headers.referer);
@@ -170,12 +176,10 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
170
176
  cookies == null ? void 0 : cookies.map((cookie) => cookie.replace("SameSite=Lax", "SameSite=None;Secure"))
171
177
  );
172
178
  const redirectionUrl = new URL(pathToRedirectTo, BASE_URL_EXAMPLE);
173
- if (isUniformContextualEditing) {
174
- queryParamsToPreserve.forEach((param) => {
175
- const paramValue = req.query[param];
176
- if (typeof paramValue === "string") {
177
- redirectionUrl.searchParams.append(param, paramValue);
178
- }
179
+ assignRequestQueryToSearchParams(redirectionUrl.searchParams, req.query);
180
+ if (!isUniformContextualEditing) {
181
+ contextualEditingQueryParams.forEach((param) => {
182
+ redirectionUrl.searchParams.delete(param);
179
183
  });
180
184
  }
181
185
  const fullPathToRedirectTo = redirectionUrl.href.replace(BASE_URL_EXAMPLE, "");
@@ -189,6 +193,25 @@ function validateLocalRedirectUrl(pathToRedirectTo) {
189
193
  throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
190
194
  }
191
195
  }
196
+ var assignRequestQueryToSearchParams = (searchParams, query) => {
197
+ const compositionQueryParamNames = Object.values(compositionQueryParam);
198
+ Object.entries(query).forEach(([name, value]) => {
199
+ if (name === import_canvas.SECRET_QUERY_STRING_PARAM) {
200
+ return;
201
+ }
202
+ if (compositionQueryParamNames.includes(name)) {
203
+ return;
204
+ }
205
+ if (typeof value === "undefined") {
206
+ return;
207
+ }
208
+ if (typeof value === "object") {
209
+ value.forEach((singleValue) => searchParams.append(name, singleValue));
210
+ return;
211
+ }
212
+ searchParams.append(name, value);
213
+ });
214
+ };
192
215
 
193
216
  // src/preview/previewHandlerPost.ts
194
217
  var import_canvas3 = require("@uniformdev/canvas");
package/dist/index.mjs CHANGED
@@ -51,7 +51,8 @@ var UniformRichTextNode = ({
51
51
  // src/preview/previewHandlerGet.ts
52
52
  import {
53
53
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM,
54
- IN_CONTEXT_EDITOR_QUERY_STRING_PARAM
54
+ IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
55
+ SECRET_QUERY_STRING_PARAM
55
56
  } from "@uniformdev/canvas";
56
57
  import { isAllowedReferrer } from "@uniformdev/canvas";
57
58
  var BASE_URL_EXAMPLE = "https://example.com";
@@ -62,10 +63,16 @@ var getQueryParam = (req, paramName) => {
62
63
  }
63
64
  return Array.isArray(value) ? value[0] : value;
64
65
  };
65
- var queryParamsToPreserve = [
66
+ var contextualEditingQueryParams = [
66
67
  IN_CONTEXT_EDITOR_QUERY_STRING_PARAM,
67
68
  IN_CONTEXT_EDITOR_PLAYGROUND_QUERY_STRING_PARAM
68
69
  ];
70
+ var compositionQueryParam = {
71
+ id: "id",
72
+ slug: "slug",
73
+ path: "path",
74
+ locale: "locale"
75
+ };
69
76
  var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault, playgroundPath } = {}) => async (req, res) => {
70
77
  const isConfigCheck = getQueryParam(req, "is_config_check") === "true";
71
78
  if (isConfigCheck) {
@@ -82,10 +89,10 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
82
89
  if (isPlayground && playgroundPath) {
83
90
  pathToRedirectTo = playgroundPath;
84
91
  }
85
- const id = getQueryParam(req, "id");
86
- const slug = getQueryParam(req, "slug");
87
- const path = getQueryParam(req, "path");
88
- const locale = getQueryParam(req, "locale");
92
+ const id = getQueryParam(req, compositionQueryParam.id);
93
+ const slug = getQueryParam(req, compositionQueryParam.slug);
94
+ const path = getQueryParam(req, compositionQueryParam.path);
95
+ const locale = getQueryParam(req, compositionQueryParam.locale);
89
96
  if (typeof pathToRedirectTo === "undefined") {
90
97
  pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
91
98
  }
@@ -100,7 +107,7 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
100
107
  }
101
108
  const previewSecret = typeof secret === "function" ? secret == null ? void 0 : secret() : secret;
102
109
  const isUsingPreviewSecret = Boolean(previewSecret);
103
- if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
110
+ if (isUsingPreviewSecret && req.query[SECRET_QUERY_STRING_PARAM] !== previewSecret) {
104
111
  return res.status(401).json({ message: "Invalid token" });
105
112
  }
106
113
  const isUniformContextualEditing = req.query[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true" && isAllowedReferrer(req.headers.referer);
@@ -127,12 +134,10 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
127
134
  cookies == null ? void 0 : cookies.map((cookie) => cookie.replace("SameSite=Lax", "SameSite=None;Secure"))
128
135
  );
129
136
  const redirectionUrl = new URL(pathToRedirectTo, BASE_URL_EXAMPLE);
130
- if (isUniformContextualEditing) {
131
- queryParamsToPreserve.forEach((param) => {
132
- const paramValue = req.query[param];
133
- if (typeof paramValue === "string") {
134
- redirectionUrl.searchParams.append(param, paramValue);
135
- }
137
+ assignRequestQueryToSearchParams(redirectionUrl.searchParams, req.query);
138
+ if (!isUniformContextualEditing) {
139
+ contextualEditingQueryParams.forEach((param) => {
140
+ redirectionUrl.searchParams.delete(param);
136
141
  });
137
142
  }
138
143
  const fullPathToRedirectTo = redirectionUrl.href.replace(BASE_URL_EXAMPLE, "");
@@ -146,6 +151,25 @@ function validateLocalRedirectUrl(pathToRedirectTo) {
146
151
  throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
147
152
  }
148
153
  }
154
+ var assignRequestQueryToSearchParams = (searchParams, query) => {
155
+ const compositionQueryParamNames = Object.values(compositionQueryParam);
156
+ Object.entries(query).forEach(([name, value]) => {
157
+ if (name === SECRET_QUERY_STRING_PARAM) {
158
+ return;
159
+ }
160
+ if (compositionQueryParamNames.includes(name)) {
161
+ return;
162
+ }
163
+ if (typeof value === "undefined") {
164
+ return;
165
+ }
166
+ if (typeof value === "object") {
167
+ value.forEach((singleValue) => searchParams.append(name, singleValue));
168
+ return;
169
+ }
170
+ searchParams.append(name, value);
171
+ });
172
+ };
149
173
 
150
174
  // src/preview/previewHandlerPost.ts
151
175
  import { generateHash } from "@uniformdev/canvas";
@@ -35,11 +35,10 @@ var import_canvas = require("@uniformdev/canvas");
35
35
  // src/logging/logCompositionIssues.ts
36
36
  var import_colorette = require("colorette");
37
37
  function logCompositionIssues(prefix, issues, colour = "red") {
38
- const reversedIssues = [...issues].reverse();
39
38
  const colours = { red: import_colorette.red, green: import_colorette.green, yellow: import_colorette.yellow, white: import_colorette.white };
40
39
  console.error(
41
40
  `${colours[colour](prefix)}
42
- ${reversedIssues.map(
41
+ ${issues.map(
43
42
  (issue) => `${colours[colour](">")} ${(0, import_colorette.italic)((0, import_colorette.gray)(indent(issue.type.toUpperCase(), 7)))} ${renderIssue(issue)}`
44
43
  ).join("\n")}`
45
44
  );
@@ -5,8 +5,8 @@ import {
5
5
  withUniformGetServerSideProps,
6
6
  withUniformGetStaticPaths,
7
7
  withUniformGetStaticProps
8
- } from "../chunk-23O4NSDU.mjs";
9
- import "../chunk-6IDBHA5X.mjs";
8
+ } from "../chunk-ZLQ2WCJC.mjs";
9
+ import "../chunk-JQWYBVLI.mjs";
10
10
  import "../chunk-TR7V6ABJ.mjs";
11
11
  export {
12
12
  getServerSideProps,
@@ -35,11 +35,10 @@ var import_canvas = require("@uniformdev/canvas");
35
35
  // src/logging/logCompositionIssues.ts
36
36
  var import_colorette = require("colorette");
37
37
  function logCompositionIssues(prefix, issues, colour = "red") {
38
- const reversedIssues = [...issues].reverse();
39
38
  const colours = { red: import_colorette.red, green: import_colorette.green, yellow: import_colorette.yellow, white: import_colorette.white };
40
39
  console.error(
41
40
  `${colours[colour](prefix)}
42
- ${reversedIssues.map(
41
+ ${issues.map(
43
42
  (issue) => `${colours[colour](">")} ${(0, import_colorette.italic)((0, import_colorette.gray)(indent(issue.type.toUpperCase(), 7)))} ${renderIssue(issue)}`
44
43
  ).join("\n")}`
45
44
  );
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  withUniformGetStaticPaths
3
- } from "../chunk-23O4NSDU.mjs";
3
+ } from "../chunk-ZLQ2WCJC.mjs";
4
4
  import {
5
5
  logCompositionResponse
6
- } from "../chunk-6IDBHA5X.mjs";
6
+ } from "../chunk-JQWYBVLI.mjs";
7
7
  import {
8
8
  resolveSlugFromParams
9
9
  } from "../chunk-TR7V6ABJ.mjs";
@@ -35,11 +35,10 @@ var import_canvas = require("@uniformdev/canvas");
35
35
  // src/logging/logCompositionIssues.ts
36
36
  var import_colorette = require("colorette");
37
37
  function logCompositionIssues(prefix, issues, colour = "red") {
38
- const reversedIssues = [...issues].reverse();
39
38
  const colours = { red: import_colorette.red, green: import_colorette.green, yellow: import_colorette.yellow, white: import_colorette.white };
40
39
  console.error(
41
40
  `${colours[colour](prefix)}
42
- ${reversedIssues.map(
41
+ ${issues.map(
43
42
  (issue) => `${colours[colour](">")} ${(0, import_colorette.italic)((0, import_colorette.gray)(indent(issue.type.toUpperCase(), 7)))} ${renderIssue(issue)}`
44
43
  ).join("\n")}`
45
44
  );
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logCompositionResponse
3
- } from "../chunk-6IDBHA5X.mjs";
3
+ } from "../chunk-JQWYBVLI.mjs";
4
4
  import {
5
5
  resolveSlugFromParams
6
6
  } from "../chunk-TR7V6ABJ.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "19.58.2-alpha.0+68d890cf9",
3
+ "version": "19.58.2-alpha.11+9a1da0c41",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -67,11 +67,11 @@
67
67
  "document": "api-extractor run --local"
68
68
  },
69
69
  "dependencies": {
70
- "@uniformdev/canvas": "19.58.2-alpha.0+68d890cf9",
71
- "@uniformdev/canvas-react": "19.58.2-alpha.0+68d890cf9",
72
- "@uniformdev/project-map": "19.58.2-alpha.0+68d890cf9",
73
- "@uniformdev/redirect": "19.58.2-alpha.0+68d890cf9",
74
- "@uniformdev/richtext": "19.58.2-alpha.0+68d890cf9",
70
+ "@uniformdev/canvas": "19.58.2-alpha.11+9a1da0c41",
71
+ "@uniformdev/canvas-react": "19.58.2-alpha.11+9a1da0c41",
72
+ "@uniformdev/project-map": "19.58.2-alpha.11+9a1da0c41",
73
+ "@uniformdev/redirect": "19.58.2-alpha.11+9a1da0c41",
74
+ "@uniformdev/richtext": "19.58.2-alpha.11+9a1da0c41",
75
75
  "colorette": "2.0.20"
76
76
  },
77
77
  "peerDependencies": {
@@ -91,5 +91,5 @@
91
91
  "publishConfig": {
92
92
  "access": "public"
93
93
  },
94
- "gitHead": "68d890cf94dc44136dd88bcc2d703248bae10bea"
94
+ "gitHead": "9a1da0c4162d8d70477d87a876eeaaf4525d94ac"
95
95
  }