@uniformdev/canvas-next 18.33.1-alpha.7 → 18.34.1-alpha.57

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
@@ -1,5 +1,5 @@
1
1
  import { ParsedUrlQuery } from 'querystring';
2
- export { U as UniformCompositionNextPage, c as UniformGetServerSideProps, b as UniformGetStaticProps, a as UniformPreviewData } from './models-6ff72d91.js';
2
+ export { U as UniformCompositionNextPage, c as UniformGetServerSideProps, b as UniformGetStaticProps, a as UniformPreviewData } from './models-092c0912.js';
3
3
  import { NextApiHandler, NextApiRequest } from 'next';
4
4
  import { RootComponentInstance } from '@uniformdev/canvas';
5
5
  import '@uniformdev/canvas-react';
package/dist/index.esm.js CHANGED
@@ -18,6 +18,7 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
18
18
  const path = getQueryParam(req, "path");
19
19
  const locale = getQueryParam(req, "locale");
20
20
  const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
21
+ validateLocalRedirectUrl(pathToRedirectTo);
21
22
  if (!pathToRedirectTo) {
22
23
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
23
24
  }
@@ -31,9 +32,22 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
31
32
  if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
32
33
  return res.status(401).json({ message: "Invalid token" });
33
34
  }
34
- res.setPreviewData({
35
- isUniformContextualEditing: req.query[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true"
36
- });
35
+ const isUniformContextualEditing = req.query[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true";
36
+ res.setPreviewData(
37
+ {
38
+ isUniformContextualEditing,
39
+ compositionId: id,
40
+ compositionSlug: slug,
41
+ compositionPath: path,
42
+ locale
43
+ },
44
+ {
45
+ // By default the preview cookies stays as long as the tab is open. And in contextual editing mode, people tend to open Canvas editor (one tab) and another tab to see published changes.
46
+ // This causes the second tab to still have the preview cookie, which causes unexpected behavior.
47
+ // This is more obvious in contextual editing mode because we skip the composition fetching and the user sees a blank page where they expected the published composition.
48
+ maxAge: isUniformContextualEditing ? 0 : void 0
49
+ }
50
+ );
37
51
  const cookies = res.getHeader("Set-Cookie");
38
52
  res.setHeader(
39
53
  "Set-Cookie",
@@ -50,9 +64,13 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
50
64
  res.redirect(urlToRedirectTo);
51
65
  };
52
66
  var resolveFullPathDefault = ({ slug, path }) => {
53
- const pathToRedirectTo = path || slug;
54
- return pathToRedirectTo != null ? pathToRedirectTo : "";
67
+ return path || slug;
55
68
  };
69
+ function validateLocalRedirectUrl(pathToRedirectTo) {
70
+ if (pathToRedirectTo == null ? void 0 : pathToRedirectTo.match(/^[a-z]+:\/\//g)) {
71
+ throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
72
+ }
73
+ }
56
74
 
57
75
  // src/preview/previewHandlerPost.ts
58
76
  import { generateHash } from "@uniformdev/canvas";
package/dist/index.js CHANGED
@@ -53,6 +53,7 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
53
53
  const path = getQueryParam(req, "path");
54
54
  const locale = getQueryParam(req, "locale");
55
55
  const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
56
+ validateLocalRedirectUrl(pathToRedirectTo);
56
57
  if (!pathToRedirectTo) {
57
58
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
58
59
  }
@@ -66,9 +67,22 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
66
67
  if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
67
68
  return res.status(401).json({ message: "Invalid token" });
68
69
  }
69
- res.setPreviewData({
70
- isUniformContextualEditing: req.query[import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true"
71
- });
70
+ const isUniformContextualEditing = req.query[import_canvas.IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true";
71
+ res.setPreviewData(
72
+ {
73
+ isUniformContextualEditing,
74
+ compositionId: id,
75
+ compositionSlug: slug,
76
+ compositionPath: path,
77
+ locale
78
+ },
79
+ {
80
+ // By default the preview cookies stays as long as the tab is open. And in contextual editing mode, people tend to open Canvas editor (one tab) and another tab to see published changes.
81
+ // This causes the second tab to still have the preview cookie, which causes unexpected behavior.
82
+ // This is more obvious in contextual editing mode because we skip the composition fetching and the user sees a blank page where they expected the published composition.
83
+ maxAge: isUniformContextualEditing ? 0 : void 0
84
+ }
85
+ );
72
86
  const cookies = res.getHeader("Set-Cookie");
73
87
  res.setHeader(
74
88
  "Set-Cookie",
@@ -85,9 +99,13 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
85
99
  res.redirect(urlToRedirectTo);
86
100
  };
87
101
  var resolveFullPathDefault = ({ slug, path }) => {
88
- const pathToRedirectTo = path || slug;
89
- return pathToRedirectTo != null ? pathToRedirectTo : "";
102
+ return path || slug;
90
103
  };
104
+ function validateLocalRedirectUrl(pathToRedirectTo) {
105
+ if (pathToRedirectTo == null ? void 0 : pathToRedirectTo.match(/^[a-z]+:\/\//g)) {
106
+ throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
107
+ }
108
+ }
91
109
 
92
110
  // src/preview/previewHandlerPost.ts
93
111
  var import_canvas2 = require("@uniformdev/canvas");
package/dist/index.mjs CHANGED
@@ -18,6 +18,7 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
18
18
  const path = getQueryParam(req, "path");
19
19
  const locale = getQueryParam(req, "locale");
20
20
  const pathToRedirectTo = resolveFullPath({ id, slug, path, locale });
21
+ validateLocalRedirectUrl(pathToRedirectTo);
21
22
  if (!pathToRedirectTo) {
22
23
  return res.status(400).json({ message: "Could not resolve the full path of the preview page" });
23
24
  }
@@ -31,9 +32,22 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
31
32
  if (isUsingPreviewSecret && req.query.secret !== previewSecret) {
32
33
  return res.status(401).json({ message: "Invalid token" });
33
34
  }
34
- res.setPreviewData({
35
- isUniformContextualEditing: req.query[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true"
36
- });
35
+ const isUniformContextualEditing = req.query[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM] === "true";
36
+ res.setPreviewData(
37
+ {
38
+ isUniformContextualEditing,
39
+ compositionId: id,
40
+ compositionSlug: slug,
41
+ compositionPath: path,
42
+ locale
43
+ },
44
+ {
45
+ // By default the preview cookies stays as long as the tab is open. And in contextual editing mode, people tend to open Canvas editor (one tab) and another tab to see published changes.
46
+ // This causes the second tab to still have the preview cookie, which causes unexpected behavior.
47
+ // This is more obvious in contextual editing mode because we skip the composition fetching and the user sees a blank page where they expected the published composition.
48
+ maxAge: isUniformContextualEditing ? 0 : void 0
49
+ }
50
+ );
37
51
  const cookies = res.getHeader("Set-Cookie");
38
52
  res.setHeader(
39
53
  "Set-Cookie",
@@ -50,9 +64,13 @@ var createPreviewHandlerGet = ({ secret, resolveFullPath = resolveFullPathDefaul
50
64
  res.redirect(urlToRedirectTo);
51
65
  };
52
66
  var resolveFullPathDefault = ({ slug, path }) => {
53
- const pathToRedirectTo = path || slug;
54
- return pathToRedirectTo != null ? pathToRedirectTo : "";
67
+ return path || slug;
55
68
  };
69
+ function validateLocalRedirectUrl(pathToRedirectTo) {
70
+ if (pathToRedirectTo == null ? void 0 : pathToRedirectTo.match(/^[a-z]+:\/\//g)) {
71
+ throw new Error("Tried to redirect to absolute URL with protocol. Disallowing open redirect.");
72
+ }
73
+ }
56
74
 
57
75
  // src/preview/previewHandlerPost.ts
58
76
  import { generateHash } from "@uniformdev/canvas";
@@ -6,6 +6,10 @@ import { ParsedUrlQuery } from 'querystring';
6
6
  type UniformCompositionNextPage<TProps = unknown> = NextPage<TProps & UniformCompositionProps>;
7
7
  type UniformPreviewData = PreviewData & {
8
8
  isUniformContextualEditing: boolean;
9
+ compositionId?: string;
10
+ compositionSlug?: string;
11
+ compositionPath?: string;
12
+ locale?: string;
9
13
  };
10
14
  type UniformGetStaticProps<P extends {
11
15
  [key: string]: any;
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, PreviewData, GetServerSideProps, GetStaticPropsContext, GetStaticProps } from 'next';
3
- import { c as UniformGetServerSideProps, a as UniformPreviewData, b as UniformGetStaticProps } from '../models-6ff72d91.js';
3
+ import { c as UniformGetServerSideProps, a as UniformPreviewData, b as UniformGetStaticProps } from '../models-092c0912.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
@@ -33,7 +33,7 @@ module.exports = __toCommonJS(project_map_exports);
33
33
  var import_canvas = require("@uniformdev/canvas");
34
34
  var withUniformGetServerSideProps = (options) => {
35
35
  return async function wrappedGetServerSideProps(context) {
36
- var _a;
36
+ var _a, _b;
37
37
  const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
38
38
  const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
39
39
  apiKey: process.env.UNIFORM_API_KEY,
@@ -47,7 +47,9 @@ var withUniformGetServerSideProps = (options) => {
47
47
  if (options == null ? void 0 : options.modifyPath) {
48
48
  nodePath = options.modifyPath(nodePath, context);
49
49
  }
50
- if (!(previewData == null ? void 0 : previewData.isUniformContextualEditing)) {
50
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
51
+ composition = { ...import_canvas.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas.EMPTY_COMPOSITION._id };
52
+ } else {
51
53
  try {
52
54
  const response = await canvasClient.getCompositionByNodePath({
53
55
  ...options == null ? void 0 : options.requestOptions,
@@ -118,7 +120,7 @@ var resolveSlugFromParams = ({
118
120
  // src/project-map/withUniformGetStaticProps.ts
119
121
  var withUniformGetStaticProps = (options) => {
120
122
  return async function wrappedGetStaticProps(context) {
121
- var _a, _b;
123
+ var _a, _b, _c;
122
124
  const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
123
125
  let pathString = resolveSlugFromParams({
124
126
  param: options == null ? void 0 : options.param,
@@ -135,7 +137,9 @@ var withUniformGetStaticProps = (options) => {
135
137
  });
136
138
  const { preview, previewData } = context;
137
139
  let composition = void 0;
138
- if (!(previewData == null ? void 0 : previewData.isUniformContextualEditing)) {
140
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
141
+ composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_c = previewData.compositionId) != null ? _c : import_canvas3.EMPTY_COMPOSITION._id };
142
+ } else {
139
143
  try {
140
144
  const response = await canvasClient.getCompositionByNodePath({
141
145
  ...options == null ? void 0 : options.requestOptions,
@@ -6,11 +6,12 @@ import {
6
6
  import {
7
7
  CANVAS_DRAFT_STATE,
8
8
  CANVAS_PUBLISHED_STATE,
9
- CanvasClient
9
+ CanvasClient,
10
+ EMPTY_COMPOSITION
10
11
  } from "@uniformdev/canvas";
11
12
  var withUniformGetServerSideProps = (options) => {
12
13
  return async function wrappedGetServerSideProps(context) {
13
- var _a;
14
+ var _a, _b;
14
15
  const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
15
16
  const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
16
17
  apiKey: process.env.UNIFORM_API_KEY,
@@ -24,7 +25,9 @@ var withUniformGetServerSideProps = (options) => {
24
25
  if (options == null ? void 0 : options.modifyPath) {
25
26
  nodePath = options.modifyPath(nodePath, context);
26
27
  }
27
- if (!(previewData == null ? void 0 : previewData.isUniformContextualEditing)) {
28
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
29
+ composition = { ...EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION._id };
30
+ } else {
28
31
  try {
29
32
  const response = await canvasClient.getCompositionByNodePath({
30
33
  ...options == null ? void 0 : options.requestOptions,
@@ -85,11 +88,12 @@ var withUniformGetStaticPaths = (options) => {
85
88
  import {
86
89
  CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
87
90
  CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
88
- CanvasClient as CanvasClient2
91
+ CanvasClient as CanvasClient2,
92
+ EMPTY_COMPOSITION as EMPTY_COMPOSITION2
89
93
  } from "@uniformdev/canvas";
90
94
  var withUniformGetStaticProps = (options) => {
91
95
  return async function wrappedGetStaticProps(context) {
92
- var _a, _b;
96
+ var _a, _b, _c;
93
97
  const projectMapId = (_a = options == null ? void 0 : options.projectMapId) != null ? _a : process.env.UNIFORM_PROJECT_MAP_ID;
94
98
  let pathString = resolveSlugFromParams({
95
99
  param: options == null ? void 0 : options.param,
@@ -106,7 +110,9 @@ var withUniformGetStaticProps = (options) => {
106
110
  });
107
111
  const { preview, previewData } = context;
108
112
  let composition = void 0;
109
- if (!(previewData == null ? void 0 : previewData.isUniformContextualEditing)) {
113
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
114
+ composition = { ...EMPTY_COMPOSITION2, _id: (_c = previewData.compositionId) != null ? _c : EMPTY_COMPOSITION2._id };
115
+ } else {
110
116
  try {
111
117
  const response = await canvasClient.getCompositionByNodePath({
112
118
  ...options == null ? void 0 : options.requestOptions,
@@ -1,6 +1,6 @@
1
1
  import * as next from 'next';
2
2
  import { GetServerSidePropsContext, GetServerSideProps, GetStaticPropsContext, GetStaticProps } from 'next';
3
- import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models-6ff72d91.js';
3
+ import { a as UniformPreviewData, c as UniformGetServerSideProps, b as UniformGetStaticProps } from '../models-092c0912.js';
4
4
  import * as querystring from 'querystring';
5
5
  import { ParsedUrlQuery } from 'querystring';
6
6
  import * as _uniformdev_canvas from '@uniformdev/canvas';
@@ -33,6 +33,7 @@ module.exports = __toCommonJS(slug_exports);
33
33
  var import_canvas = require("@uniformdev/canvas");
34
34
  var withUniformGetServerSideProps = (options) => {
35
35
  return async function wrappedGetServerSideProps(context) {
36
+ var _a;
36
37
  const canvasClient = (options == null ? void 0 : options.client) || new import_canvas.CanvasClient({
37
38
  apiKey: process.env.UNIFORM_API_KEY,
38
39
  projectId: process.env.UNIFORM_PROJECT_ID,
@@ -45,7 +46,9 @@ var withUniformGetServerSideProps = (options) => {
45
46
  if (options == null ? void 0 : options.modifySlug) {
46
47
  slug = options.modifySlug(slug, context);
47
48
  }
48
- if (!(previewData == null ? void 0 : previewData.isUniformContextualEditing)) {
49
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
50
+ composition = { ...import_canvas.EMPTY_COMPOSITION, _id: (_a = previewData.compositionId) != null ? _a : import_canvas.EMPTY_COMPOSITION._id };
51
+ } else {
49
52
  try {
50
53
  const response = await canvasClient.getCompositionBySlug({
51
54
  ...options == null ? void 0 : options.requestOptions,
@@ -112,7 +115,7 @@ var resolveSlugFromParams = ({
112
115
  // src/slug/withUniformGetStaticProps.ts
113
116
  var withUniformGetStaticProps = (options) => {
114
117
  return async function wrappedGetStaticProps(context) {
115
- var _a;
118
+ var _a, _b;
116
119
  let slugString = resolveSlugFromParams({
117
120
  param: options == null ? void 0 : options.param,
118
121
  params: context == null ? void 0 : context.params
@@ -128,7 +131,9 @@ var withUniformGetStaticProps = (options) => {
128
131
  });
129
132
  const { preview, previewData } = context;
130
133
  let composition = void 0;
131
- if (!(previewData == null ? void 0 : previewData.isUniformContextualEditing)) {
134
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
135
+ composition = { ...import_canvas3.EMPTY_COMPOSITION, _id: (_b = previewData.compositionId) != null ? _b : import_canvas3.EMPTY_COMPOSITION._id };
136
+ } else {
132
137
  try {
133
138
  const response = await canvasClient.getCompositionBySlug({
134
139
  slug: slugString,
@@ -6,10 +6,12 @@ import {
6
6
  import {
7
7
  CANVAS_DRAFT_STATE,
8
8
  CANVAS_PUBLISHED_STATE,
9
- CanvasClient
9
+ CanvasClient,
10
+ EMPTY_COMPOSITION
10
11
  } from "@uniformdev/canvas";
11
12
  var withUniformGetServerSideProps = (options) => {
12
13
  return async function wrappedGetServerSideProps(context) {
14
+ var _a;
13
15
  const canvasClient = (options == null ? void 0 : options.client) || new CanvasClient({
14
16
  apiKey: process.env.UNIFORM_API_KEY,
15
17
  projectId: process.env.UNIFORM_PROJECT_ID,
@@ -22,7 +24,9 @@ var withUniformGetServerSideProps = (options) => {
22
24
  if (options == null ? void 0 : options.modifySlug) {
23
25
  slug = options.modifySlug(slug, context);
24
26
  }
25
- if (!(previewData == null ? void 0 : previewData.isUniformContextualEditing)) {
27
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
28
+ composition = { ...EMPTY_COMPOSITION, _id: (_a = previewData.compositionId) != null ? _a : EMPTY_COMPOSITION._id };
29
+ } else {
26
30
  try {
27
31
  const response = await canvasClient.getCompositionBySlug({
28
32
  ...options == null ? void 0 : options.requestOptions,
@@ -81,11 +85,12 @@ var withUniformGetStaticPaths = (options) => {
81
85
  import {
82
86
  CANVAS_DRAFT_STATE as CANVAS_DRAFT_STATE3,
83
87
  CANVAS_PUBLISHED_STATE as CANVAS_PUBLISHED_STATE3,
84
- CanvasClient as CanvasClient3
88
+ CanvasClient as CanvasClient3,
89
+ EMPTY_COMPOSITION as EMPTY_COMPOSITION2
85
90
  } from "@uniformdev/canvas";
86
91
  var withUniformGetStaticProps = (options) => {
87
92
  return async function wrappedGetStaticProps(context) {
88
- var _a;
93
+ var _a, _b;
89
94
  let slugString = resolveSlugFromParams({
90
95
  param: options == null ? void 0 : options.param,
91
96
  params: context == null ? void 0 : context.params
@@ -101,7 +106,9 @@ var withUniformGetStaticProps = (options) => {
101
106
  });
102
107
  const { preview, previewData } = context;
103
108
  let composition = void 0;
104
- if (!(previewData == null ? void 0 : previewData.isUniformContextualEditing)) {
109
+ if (previewData == null ? void 0 : previewData.isUniformContextualEditing) {
110
+ composition = { ...EMPTY_COMPOSITION2, _id: (_b = previewData.compositionId) != null ? _b : EMPTY_COMPOSITION2._id };
111
+ } else {
105
112
  try {
106
113
  const response = await canvasClient.getCompositionBySlug({
107
114
  slug: slugString,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next",
3
- "version": "18.33.1-alpha.7+7127237a1",
3
+ "version": "18.34.1-alpha.57+d06712d70",
4
4
  "description": "Next.js SDK for Uniform Canvas",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -53,9 +53,9 @@
53
53
  "document": "api-extractor run --local"
54
54
  },
55
55
  "dependencies": {
56
- "@uniformdev/canvas": "18.33.1-alpha.7+7127237a1",
57
- "@uniformdev/canvas-react": "18.33.1-alpha.7+7127237a1",
58
- "@uniformdev/project-map": "18.33.1-alpha.7+7127237a1"
56
+ "@uniformdev/canvas": "18.34.1-alpha.57+d06712d70",
57
+ "@uniformdev/canvas-react": "18.34.1-alpha.57+d06712d70",
58
+ "@uniformdev/project-map": "18.34.1-alpha.57+d06712d70"
59
59
  },
60
60
  "peerDependencies": {
61
61
  "next": ">= 12.0.0",
@@ -63,8 +63,8 @@
63
63
  "react-dom": ">=16"
64
64
  },
65
65
  "devDependencies": {
66
- "@types/react": "18.0.31",
67
- "next": "13.2.4",
66
+ "@types/react": "18.0.33",
67
+ "next": "13.3.0",
68
68
  "react": "18.2.0",
69
69
  "react-dom": "18.2.0"
70
70
  },
@@ -74,5 +74,5 @@
74
74
  "publishConfig": {
75
75
  "access": "public"
76
76
  },
77
- "gitHead": "7127237a1e099d2a11fa8c06d49cb01cf16c0852"
77
+ "gitHead": "d06712d70880e665966897d71c92444ea1dea80e"
78
78
  }