@uniformdev/canvas-next 18.7.0 → 18.8.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.
package/dist/index.d.ts CHANGED
@@ -11,9 +11,14 @@ declare const resolveSlugFromParams: ({ param, params, prefix, }: {
11
11
  }) => string;
12
12
 
13
13
  type ResolveFullPath = (options: {
14
+ /** The ID of the composition */
14
15
  id?: string;
16
+ /** The slug of the composition */
15
17
  slug?: string;
18
+ /** The path of the project map node attached to the composition, if there is one */
16
19
  path?: string;
20
+ /** The preview locale selected in Visual Canvas, available only if Localization is set up */
21
+ locale?: string;
17
22
  }) => string | undefined;
18
23
  type CreatePreviewHandlerGetOptions = {
19
24
  secret?: () => string;
package/dist/index.esm.js CHANGED
@@ -4,12 +4,20 @@ import {
4
4
 
5
5
  // src/preview/previewHandlerGet.ts
6
6
  import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
7
+ var getQueryParam = (req, paramName) => {
8
+ const value = req.query[paramName];
9
+ if (typeof value === "undefined") {
10
+ return void 0;
11
+ }
12
+ return Array.isArray(value) ? value[0] : value;
13
+ };
7
14
  var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
8
15
  const queryParamsToPreserve = [IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
9
- const id = Array.isArray(req.query.id) ? req.query.id[0] : req.query.id;
10
- const slug = Array.isArray(req.query.slug) ? req.query.slug[0] : req.query.slug;
11
- const path = Array.isArray(req.query.path) ? req.query.path[0] : req.query.path;
12
- const pathToRedirectTo = resolveFullPath({ id, slug, path });
16
+ const id = getQueryParam(req, "id");
17
+ const slug = getQueryParam(req, "slug");
18
+ const path = getQueryParam(req, "path");
19
+ const locale = getQueryParam(req, "locale");
20
+ const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
13
21
  if (!pathToRedirectTo) {
14
22
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
15
23
  }
package/dist/index.js CHANGED
@@ -40,12 +40,20 @@ var resolveSlugFromParams = ({
40
40
 
41
41
  // src/preview/previewHandlerGet.ts
42
42
  var import_canvas = require("@uniformdev/canvas");
43
+ var getQueryParam = (req, paramName) => {
44
+ const value = req.query[paramName];
45
+ if (typeof value === "undefined") {
46
+ return void 0;
47
+ }
48
+ return Array.isArray(value) ? value[0] : value;
49
+ };
43
50
  var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
44
51
  const queryParamsToPreserve = [import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
45
- const id = Array.isArray(req.query.id) ? req.query.id[0] : req.query.id;
46
- const slug = Array.isArray(req.query.slug) ? req.query.slug[0] : req.query.slug;
47
- const path = Array.isArray(req.query.path) ? req.query.path[0] : req.query.path;
48
- const pathToRedirectTo = resolveFullPath({ id, slug, path });
52
+ const id = getQueryParam(req, "id");
53
+ const slug = getQueryParam(req, "slug");
54
+ const path = getQueryParam(req, "path");
55
+ const locale = getQueryParam(req, "locale");
56
+ const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
49
57
  if (!pathToRedirectTo) {
50
58
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
51
59
  }
package/dist/index.mjs CHANGED
@@ -4,12 +4,20 @@ import {
4
4
 
5
5
  // src/preview/previewHandlerGet.ts
6
6
  import { IN_CONTEXT_EDITOR_QUERY_STRING_PARAM } from "@uniformdev/canvas";
7
+ var getQueryParam = (req, paramName) => {
8
+ const value = req.query[paramName];
9
+ if (typeof value === "undefined") {
10
+ return void 0;
11
+ }
12
+ return Array.isArray(value) ? value[0] : value;
13
+ };
7
14
  var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefault } = {}) => async (req, res) => {
8
15
  const queryParamsToPreserve = [IN_CONTEXT_EDITOR_QUERY_STRING_PARAM];
9
- const id = Array.isArray(req.query.id) ? req.query.id[0] : req.query.id;
10
- const slug = Array.isArray(req.query.slug) ? req.query.slug[0] : req.query.slug;
11
- const path = Array.isArray(req.query.path) ? req.query.path[0] : req.query.path;
12
- const pathToRedirectTo = resolveFullPath({ id, slug, path });
16
+ const id = getQueryParam(req, "id");
17
+ const slug = getQueryParam(req, "slug");
18
+ const path = getQueryParam(req, "path");
19
+ const locale = getQueryParam(req, "locale");
20
+ const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
13
21
  if (!pathToRedirectTo) {
14
22
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
15
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "18.7.0",
3
+ "version": "18.8.0",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -52,9 +52,9 @@
52
52
  "format": "prettier --write \"src/**/*.{js,ts,tsx}\""
53
53
  },
54
54
  "dependencies": {
55
- "@uniformdev/canvas": "18.7.0",
56
- "@uniformdev/canvas-react": "18.7.0",
57
- "@uniformdev/project-map": "18.7.0"
55
+ "@uniformdev/canvas": "18.8.0",
56
+ "@uniformdev/canvas-react": "18.8.0",
57
+ "@uniformdev/project-map": "18.8.0"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "next": ">= 12.0.0",
@@ -73,5 +73,5 @@
73
73
  "publishConfig": {
74
74
  "access": "public"
75
75
  },
76
- "gitHead": "eaf3d0e5c1c124d6b449a2f2b16b327d6f3d3666"
76
+ "gitHead": "d1a61982946fad3479b8c1d5fdc89c241a5893df"
77
77
  }