@sitecore-jss/sitecore-jss-nextjs 22.2.0-canary.81 → 22.2.0-canary.83

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.
@@ -42,10 +42,6 @@ const react_1 = __importStar(require("react"));
42
42
  const prop_types_1 = __importDefault(require("prop-types"));
43
43
  const link_1 = __importDefault(require("next/link"));
44
44
  const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
45
- /**
46
- * Matches relative URLs that end with a file extension.
47
- */
48
- const FILE_EXTENSION_MATCHER = /^\/.*\.\w+$/;
49
45
  exports.Link = (0, react_1.forwardRef)((props, ref) => {
50
46
  const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
51
47
  if (!field ||
@@ -63,10 +59,8 @@ exports.Link = (0, react_1.forwardRef)((props, ref) => {
63
59
  const isEditing = editable && (field.editable || field.metadata);
64
60
  if (href && !isEditing) {
65
61
  const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
66
- const isMatching = internalLinkMatcher.test(href);
67
- const isFileUrl = FILE_EXTENSION_MATCHER.test(href);
68
- // determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
69
- if (isMatching && !isFileUrl) {
62
+ // determine if a link is a route or not.
63
+ if (internalLinkMatcher.test(href)) {
70
64
  return (react_1.default.createElement(link_1.default, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", locale: false, title: value.title, target: value.target, className: value.class }, htmlLinkProps, { ref: ref }),
71
65
  text,
72
66
  children));
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EDITING_PASS_THROUGH_HEADERS = exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = exports.QUERY_PARAM_VERCEL_PROTECTION_BYPASS = void 0;
3
+ exports.EDITING_ALLOWED_ORIGINS = exports.EDITING_PASS_THROUGH_HEADERS = exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = exports.QUERY_PARAM_VERCEL_PROTECTION_BYPASS = exports.QUERY_PARAM_EDITING_SECRET = void 0;
4
+ exports.QUERY_PARAM_EDITING_SECRET = 'secret';
4
5
  exports.QUERY_PARAM_VERCEL_PROTECTION_BYPASS = 'x-vercel-protection-bypass';
5
6
  exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
6
7
  /**
@@ -8,3 +9,7 @@ exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
8
9
  * Note these are in lowercase format to match expected `IncomingHttpHeaders`.
9
10
  */
10
11
  exports.EDITING_PASS_THROUGH_HEADERS = ['authorization', 'cookie'];
12
+ /**
13
+ * Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
14
+ */
15
+ exports.EDITING_ALLOWED_ORIGINS = ['https://pages.sitecorecloud.io'];
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EditingConfigMiddleware = void 0;
13
- const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
13
+ const constants_1 = require("./constants");
14
14
  const utils_1 = require("../utils/utils");
15
15
  const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
16
16
  const layout_1 = require("@sitecore-jss/sitecore-jss/layout");
@@ -26,8 +26,8 @@ class EditingConfigMiddleware {
26
26
  constructor(config) {
27
27
  this.config = config;
28
28
  this.handler = (_req, res) => __awaiter(this, void 0, void 0, function* () {
29
- const secret = _req.query[editing_1.QUERY_PARAM_EDITING_SECRET];
30
- if (!(0, utils_2.enforceCors)(_req, res, editing_1.EDITING_ALLOWED_ORIGINS)) {
29
+ const secret = _req.query[constants_1.QUERY_PARAM_EDITING_SECRET];
30
+ if (!(0, utils_2.enforceCors)(_req, res, constants_1.EDITING_ALLOWED_ORIGINS)) {
31
31
  sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
32
32
  return res.status(401).json({ message: 'Invalid origin' });
33
33
  }
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.EditingDataMiddleware = void 0;
13
13
  const editing_data_cache_1 = require("./editing-data-cache");
14
14
  const editing_data_1 = require("./editing-data");
15
- const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
15
+ const constants_1 = require("./constants");
16
16
  const utils_1 = require("../utils/utils");
17
17
  const utils_2 = require("@sitecore-jss/sitecore-jss/utils");
18
18
  const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
@@ -28,9 +28,9 @@ class EditingDataMiddleware {
28
28
  var _a, _b;
29
29
  this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
30
30
  const { method, query, body } = req;
31
- const secret = query[editing_1.QUERY_PARAM_EDITING_SECRET];
31
+ const secret = query[constants_1.QUERY_PARAM_EDITING_SECRET];
32
32
  const key = query[this.queryParamKey];
33
- if (!(0, utils_2.enforceCors)(req, res, editing_1.EDITING_ALLOWED_ORIGINS)) {
33
+ if (!(0, utils_2.enforceCors)(req, res, constants_1.EDITING_ALLOWED_ORIGINS)) {
34
34
  sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
35
35
  return res.status(401).json({ message: 'Invalid origin' });
36
36
  }
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.editingDataService = exports.ServerlessEditingDataService = exports.BasicEditingDataService = exports.generateKey = void 0;
13
- const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
13
+ const constants_1 = require("./constants");
14
14
  const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
15
15
  const editing_data_cache_1 = require("./editing-data-cache");
16
16
  const utils_1 = require("../utils/utils");
@@ -137,7 +137,7 @@ class ServerlessEditingDataService {
137
137
  // http://localhost:3000/api/editing/data/52961eea-bafd-5287-a532-a72e36bd8a36-qkb4e3fv5x?secret=1234secret
138
138
  const apiRoute = (_a = this.apiRoute) === null || _a === void 0 ? void 0 : _a.replace('[key]', key);
139
139
  const url = new URL(apiRoute, serverUrl);
140
- url.searchParams.append(editing_1.QUERY_PARAM_EDITING_SECRET, (0, utils_1.getJssEditingSecret)());
140
+ url.searchParams.append(constants_1.QUERY_PARAM_EDITING_SECRET, (0, utils_1.getJssEditingSecret)());
141
141
  if (params) {
142
142
  for (const key in params) {
143
143
  if ({}.hasOwnProperty.call(params, key)) {
@@ -13,8 +13,8 @@ exports.EditingRenderMiddleware = exports.MetadataHandler = exports.isEditingMet
13
13
  const constants_1 = require("next/constants");
14
14
  const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
15
15
  const layout_1 = require("@sitecore-jss/sitecore-jss/layout");
16
- const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
17
16
  const editing_data_service_1 = require("./editing-data-service");
17
+ const constants_2 = require("./constants");
18
18
  const utils_1 = require("../utils/utils");
19
19
  const render_middleware_1 = require("./render-middleware");
20
20
  const utils_2 = require("@sitecore-jss/sitecore-jss/utils");
@@ -265,7 +265,7 @@ class MetadataHandler {
265
265
  * @returns Content-Security-Policy header value
266
266
  */
267
267
  getSCPHeader() {
268
- return `frame-ancestors 'self' ${[(0, utils_2.getAllowedOriginsFromEnv)(), ...editing_1.EDITING_ALLOWED_ORIGINS].join(' ')}`;
268
+ return `frame-ancestors 'self' ${[(0, utils_2.getAllowedOriginsFromEnv)(), ...constants_2.EDITING_ALLOWED_ORIGINS].join(' ')}`;
269
269
  }
270
270
  }
271
271
  exports.MetadataHandler = MetadataHandler;
@@ -289,14 +289,14 @@ class EditingRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
289
289
  headers,
290
290
  body,
291
291
  });
292
- if (!(0, utils_2.enforceCors)(req, res, editing_1.EDITING_ALLOWED_ORIGINS)) {
292
+ if (!(0, utils_2.enforceCors)(req, res, constants_2.EDITING_ALLOWED_ORIGINS)) {
293
293
  sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
294
294
  return res.status(401).json({
295
295
  html: `<html><body>Requests from origin ${(_a = req.headers) === null || _a === void 0 ? void 0 : _a.origin} not allowed</body></html>`,
296
296
  });
297
297
  }
298
298
  // Validate secret
299
- const secret = (_b = query[editing_1.QUERY_PARAM_EDITING_SECRET]) !== null && _b !== void 0 ? _b : body === null || body === void 0 ? void 0 : body.jssEditingSecret;
299
+ const secret = (_b = query[constants_2.QUERY_PARAM_EDITING_SECRET]) !== null && _b !== void 0 ? _b : body === null || body === void 0 ? void 0 : body.jssEditingSecret;
300
300
  if (secret !== (0, utils_1.getJssEditingSecret)()) {
301
301
  sitecore_jss_1.debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, (0, utils_1.getJssEditingSecret)());
302
302
  return res.status(401).json({
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FEAASRenderMiddleware = void 0;
13
13
  const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
14
- const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
14
+ const constants_1 = require("./constants");
15
15
  const utils_1 = require("../utils/utils");
16
16
  const render_middleware_1 = require("./render-middleware");
17
17
  const utils_2 = require("@sitecore-jss/sitecore-jss/utils");
@@ -37,7 +37,7 @@ class FEAASRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
37
37
  query,
38
38
  headers,
39
39
  });
40
- if (!(0, utils_2.enforceCors)(req, res, editing_1.EDITING_ALLOWED_ORIGINS)) {
40
+ if (!(0, utils_2.enforceCors)(req, res, constants_1.EDITING_ALLOWED_ORIGINS)) {
41
41
  sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
42
42
  return res
43
43
  .status(401)
@@ -49,7 +49,7 @@ class FEAASRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
49
49
  return res.status(405).send(`<html><body>Invalid request method '${method}'</body></html>`);
50
50
  }
51
51
  // Validate secret
52
- const secret = query[editing_1.QUERY_PARAM_EDITING_SECRET];
52
+ const secret = query[constants_1.QUERY_PARAM_EDITING_SECRET];
53
53
  if (secret !== (0, utils_1.getJssEditingSecret)()) {
54
54
  sitecore_jss_1.debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, (0, utils_1.getJssEditingSecret)());
55
55
  return res.status(401).send('<html><body>Missing or invalid secret</body></html>');
@@ -13,10 +13,6 @@ import React, { forwardRef } from 'react';
13
13
  import PropTypes from 'prop-types';
14
14
  import NextLink from 'next/link';
15
15
  import { Link as ReactLink, LinkPropTypes, } from '@sitecore-jss/sitecore-jss-react';
16
- /**
17
- * Matches relative URLs that end with a file extension.
18
- */
19
- const FILE_EXTENSION_MATCHER = /^\/.*\.\w+$/;
20
16
  export const Link = forwardRef((props, ref) => {
21
17
  const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
22
18
  if (!field ||
@@ -34,10 +30,8 @@ export const Link = forwardRef((props, ref) => {
34
30
  const isEditing = editable && (field.editable || field.metadata);
35
31
  if (href && !isEditing) {
36
32
  const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
37
- const isMatching = internalLinkMatcher.test(href);
38
- const isFileUrl = FILE_EXTENSION_MATCHER.test(href);
39
- // determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
40
- if (isMatching && !isFileUrl) {
33
+ // determine if a link is a route or not.
34
+ if (internalLinkMatcher.test(href)) {
41
35
  return (React.createElement(NextLink, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", locale: false, title: value.title, target: value.target, className: value.class }, htmlLinkProps, { ref: ref }),
42
36
  text,
43
37
  children));
@@ -1,3 +1,4 @@
1
+ export const QUERY_PARAM_EDITING_SECRET = 'secret';
1
2
  export const QUERY_PARAM_VERCEL_PROTECTION_BYPASS = 'x-vercel-protection-bypass';
2
3
  export const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
3
4
  /**
@@ -5,3 +6,7 @@ export const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie'
5
6
  * Note these are in lowercase format to match expected `IncomingHttpHeaders`.
6
7
  */
7
8
  export const EDITING_PASS_THROUGH_HEADERS = ['authorization', 'cookie'];
9
+ /**
10
+ * Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
11
+ */
12
+ export const EDITING_ALLOWED_ORIGINS = ['https://pages.sitecorecloud.io'];
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, } from '@sitecore-jss/sitecore-jss/editing';
10
+ import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET } from './constants';
11
11
  import { getJssEditingSecret } from '../utils/utils';
12
12
  import { debug } from '@sitecore-jss/sitecore-jss';
13
13
  import { EditMode } from '@sitecore-jss/sitecore-jss/layout';
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { editingDataDiskCache } from './editing-data-cache';
11
11
  import { isEditingData } from './editing-data';
12
- import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, } from '@sitecore-jss/sitecore-jss/editing';
12
+ import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET } from './constants';
13
13
  import { getJssEditingSecret } from '../utils/utils';
14
14
  import { enforceCors } from '@sitecore-jss/sitecore-jss/utils';
15
15
  import { debug } from '@sitecore-jss/sitecore-jss';
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { QUERY_PARAM_EDITING_SECRET } from '@sitecore-jss/sitecore-jss/editing';
10
+ import { QUERY_PARAM_EDITING_SECRET } from './constants';
11
11
  import { AxiosDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
12
12
  import { editingDataDiskCache } from './editing-data-cache';
13
13
  import { getJssEditingSecret } from '../utils/utils';
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { STATIC_PROPS_ID, SERVER_PROPS_ID } from 'next/constants';
11
11
  import { AxiosDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
12
12
  import { EditMode } from '@sitecore-jss/sitecore-jss/layout';
13
- import { QUERY_PARAM_EDITING_SECRET, EDITING_ALLOWED_ORIGINS, } from '@sitecore-jss/sitecore-jss/editing';
14
13
  import { editingDataService } from './editing-data-service';
14
+ import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET } from './constants';
15
15
  import { getJssEditingSecret } from '../utils/utils';
16
16
  import { RenderMiddlewareBase } from './render-middleware';
17
17
  import { enforceCors, getAllowedOriginsFromEnv } from '@sitecore-jss/sitecore-jss/utils';
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { debug } from '@sitecore-jss/sitecore-jss';
11
- import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, } from '@sitecore-jss/sitecore-jss/editing';
11
+ import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET } from './constants';
12
12
  import { getJssEditingSecret } from '../utils/utils';
13
13
  import { RenderMiddlewareBase } from './render-middleware';
14
14
  import { enforceCors } from '@sitecore-jss/sitecore-jss/utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-nextjs",
3
- "version": "22.2.0-canary.81",
3
+ "version": "22.2.0-canary.83",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -73,9 +73,9 @@
73
73
  "react-dom": "^18.2.0"
74
74
  },
75
75
  "dependencies": {
76
- "@sitecore-jss/sitecore-jss": "^22.2.0-canary.81",
77
- "@sitecore-jss/sitecore-jss-dev-tools": "^22.2.0-canary.81",
78
- "@sitecore-jss/sitecore-jss-react": "^22.2.0-canary.81",
76
+ "@sitecore-jss/sitecore-jss": "^22.2.0-canary.83",
77
+ "@sitecore-jss/sitecore-jss-dev-tools": "^22.2.0-canary.83",
78
+ "@sitecore-jss/sitecore-jss-react": "^22.2.0-canary.83",
79
79
  "@vercel/kv": "^0.2.1",
80
80
  "prop-types": "^15.8.1",
81
81
  "regex-parser": "^2.2.11",
@@ -83,7 +83,7 @@
83
83
  },
84
84
  "description": "",
85
85
  "types": "types/index.d.ts",
86
- "gitHead": "8b710877973ac2dedbf09cb4dffc62bb85bbc6dd",
86
+ "gitHead": "d56b18ae5aabcf3095dac9d45b9f28959bf10b64",
87
87
  "files": [
88
88
  "dist",
89
89
  "types",
@@ -1,3 +1,4 @@
1
+ export declare const QUERY_PARAM_EDITING_SECRET = "secret";
1
2
  export declare const QUERY_PARAM_VERCEL_PROTECTION_BYPASS = "x-vercel-protection-bypass";
2
3
  export declare const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = "x-vercel-set-bypass-cookie";
3
4
  /**
@@ -5,3 +6,7 @@ export declare const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = "x-vercel-set-bypass
5
6
  * Note these are in lowercase format to match expected `IncomingHttpHeaders`.
6
7
  */
7
8
  export declare const EDITING_PASS_THROUGH_HEADERS: string[];
9
+ /**
10
+ * Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
11
+ */
12
+ export declare const EDITING_ALLOWED_ORIGINS: string[];
@@ -1,7 +1,7 @@
1
1
  import { NextApiRequest, NextApiResponse } from 'next';
2
2
  import { AxiosDataFetcher } from '@sitecore-jss/sitecore-jss';
3
3
  import { EditMode, LayoutServicePageState } from '@sitecore-jss/sitecore-jss/layout';
4
- import { RenderMetadataQueryParams, LayoutKind } from '@sitecore-jss/sitecore-jss/editing';
4
+ import { LayoutKind } from '@sitecore-jss/sitecore-jss/editing';
5
5
  import { EditingDataService } from './editing-data-service';
6
6
  import { RenderMiddlewareBase } from './render-middleware';
7
7
  /**
@@ -96,11 +96,26 @@ export declare class ChromesHandler extends RenderMiddlewareBase {
96
96
  * Configuration for the Editing Metadata Handler.
97
97
  */
98
98
  export type EditingRenderMiddlewareMetadataConfig = Pick<EditingRenderMiddlewareConfig, 'resolvePageUrl'>;
99
+ /**
100
+ * Query parameters appended to the page route URL
101
+ * Appended when XMCloud Pages preview (editing) Metadata Edit Mode is used
102
+ */
103
+ export type MetadataQueryParams = {
104
+ secret: string;
105
+ sc_lang: string;
106
+ sc_itemid: string;
107
+ sc_site: string;
108
+ route: string;
109
+ mode: Exclude<LayoutServicePageState, 'normal'>;
110
+ sc_variant?: string;
111
+ sc_version?: string;
112
+ sc_layoutKind?: LayoutKind;
113
+ };
99
114
  /**
100
115
  * Next.js API request with Metadata query parameters.
101
116
  */
102
117
  type MetadataNextApiRequest = NextApiRequest & {
103
- query: RenderMetadataQueryParams;
118
+ query: MetadataQueryParams;
104
119
  };
105
120
  /**
106
121
  * Data for Next.js Preview (Editing) Metadata Edit Mode.