@sitecore-jss/sitecore-jss-nextjs 22.3.0 → 22.3.1-canary.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.
- package/dist/cjs/ComponentBuilder.js +1 -1
- package/dist/cjs/components/Link.js +8 -2
- package/dist/cjs/editing/constants.js +1 -6
- package/dist/cjs/editing/editing-config-middleware.js +9 -3
- package/dist/cjs/editing/editing-data-middleware.js +3 -3
- package/dist/cjs/editing/editing-data-service.js +2 -2
- package/dist/cjs/editing/editing-render-middleware.js +14 -6
- package/dist/cjs/editing/feaas-render-middleware.js +12 -6
- package/dist/cjs/editing/render-middleware.js +1 -1
- package/dist/cjs/middleware/personalize-middleware.js +6 -6
- package/dist/cjs/middleware/redirects-middleware.js +2 -2
- package/dist/cjs/services/base-graphql-sitemap-service.js +9 -9
- package/dist/cjs/services/component-props-service.js +2 -3
- package/dist/cjs/utils/utils.js +0 -1
- package/dist/esm/ComponentBuilder.js +1 -1
- package/dist/esm/components/Link.js +8 -2
- package/dist/esm/editing/constants.js +0 -5
- package/dist/esm/editing/editing-config-middleware.js +7 -1
- package/dist/esm/editing/editing-data-middleware.js +1 -1
- package/dist/esm/editing/editing-data-service.js +1 -1
- package/dist/esm/editing/editing-render-middleware.js +12 -4
- package/dist/esm/editing/feaas-render-middleware.js +10 -4
- package/dist/esm/editing/render-middleware.js +1 -1
- package/dist/esm/middleware/personalize-middleware.js +6 -6
- package/dist/esm/middleware/redirects-middleware.js +2 -2
- package/dist/esm/services/base-graphql-sitemap-service.js +9 -9
- package/dist/esm/services/component-props-service.js +2 -3
- package/dist/esm/utils/utils.js +0 -1
- package/package.json +17 -17
- package/types/ComponentBuilder.d.ts +1 -1
- package/types/editing/constants.d.ts +0 -5
- package/types/editing/editing-render-middleware.d.ts +5 -20
- package/types/editing/render-middleware.d.ts +2 -1
- package/types/middleware/redirects-middleware.d.ts +1 -1
- package/types/services/base-graphql-sitemap-service.d.ts +7 -6
- package/types/services/component-props-service.d.ts +1 -2
- package/types/utils/utils.d.ts +0 -1
|
@@ -34,7 +34,7 @@ class ComponentBuilder {
|
|
|
34
34
|
/**
|
|
35
35
|
* Creates a new instance of component factory
|
|
36
36
|
* Component can be imported dynamically or statically.
|
|
37
|
-
* @param {
|
|
37
|
+
* @param {object} [config] Component factory configuration
|
|
38
38
|
* @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
|
|
39
39
|
* @returns {ComponentFactory} Component factory implementation
|
|
40
40
|
*/
|
|
@@ -42,6 +42,10 @@ 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+$/;
|
|
45
49
|
exports.Link = (0, react_1.forwardRef)((props, ref) => {
|
|
46
50
|
const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
47
51
|
if (!field ||
|
|
@@ -59,8 +63,10 @@ exports.Link = (0, react_1.forwardRef)((props, ref) => {
|
|
|
59
63
|
const isEditing = editable && (field.editable || field.metadata);
|
|
60
64
|
if (href && !isEditing) {
|
|
61
65
|
const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
|
|
62
|
-
|
|
63
|
-
|
|
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) {
|
|
64
70
|
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 }),
|
|
65
71
|
text,
|
|
66
72
|
children));
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.QUERY_PARAM_EDITING_SECRET = 'secret';
|
|
3
|
+
exports.EDITING_PASS_THROUGH_HEADERS = exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = exports.QUERY_PARAM_VERCEL_PROTECTION_BYPASS = void 0;
|
|
5
4
|
exports.QUERY_PARAM_VERCEL_PROTECTION_BYPASS = 'x-vercel-protection-bypass';
|
|
6
5
|
exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
|
|
7
6
|
/**
|
|
@@ -9,7 +8,3 @@ exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
|
|
|
9
8
|
* Note these are in lowercase format to match expected `IncomingHttpHeaders`.
|
|
10
9
|
*/
|
|
11
10
|
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
|
|
13
|
+
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
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[
|
|
30
|
-
if (!(0, utils_2.enforceCors)(_req, res,
|
|
29
|
+
const secret = _req.query[editing_1.QUERY_PARAM_EDITING_SECRET];
|
|
30
|
+
if (!(0, utils_2.enforceCors)(_req, res, editing_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
|
}
|
|
@@ -35,6 +35,12 @@ class EditingConfigMiddleware {
|
|
|
35
35
|
sitecore_jss_1.debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, (0, utils_1.getJssEditingSecret)());
|
|
36
36
|
return res.status(401).json({ message: 'Missing or invalid editing secret' });
|
|
37
37
|
}
|
|
38
|
+
// Handle preflight request
|
|
39
|
+
if (_req.method === 'OPTIONS') {
|
|
40
|
+
sitecore_jss_1.debug.editing('preflight request');
|
|
41
|
+
// CORS headers are set by enforceCors
|
|
42
|
+
return res.status(204).send(null);
|
|
43
|
+
}
|
|
38
44
|
const components = Array.isArray(this.config.components)
|
|
39
45
|
? this.config.components
|
|
40
46
|
: Array.from(this.config.components.keys());
|
|
@@ -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
|
|
15
|
+
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
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[
|
|
31
|
+
const secret = query[editing_1.QUERY_PARAM_EDITING_SECRET];
|
|
32
32
|
const key = query[this.queryParamKey];
|
|
33
|
-
if (!(0, utils_2.enforceCors)(req, res,
|
|
33
|
+
if (!(0, utils_2.enforceCors)(req, res, editing_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
|
|
13
|
+
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
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(
|
|
140
|
+
url.searchParams.append(editing_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");
|
|
16
17
|
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");
|
|
@@ -30,7 +30,7 @@ class ChromesHandler extends render_middleware_1.RenderMiddlewareBase {
|
|
|
30
30
|
this.config = config;
|
|
31
31
|
/**
|
|
32
32
|
* Default page URL resolution.
|
|
33
|
-
* @param {
|
|
33
|
+
* @param {object} args Arguments for resolving the page URL
|
|
34
34
|
* @param {string} args.serverUrl The root server URL e.g. 'http://localhost:3000'
|
|
35
35
|
* @param {string} args.itemPath The Sitecore relative item path e.g. '/styleguide'
|
|
36
36
|
* @returns {string} The URL to render
|
|
@@ -173,7 +173,7 @@ class ChromesHandler extends render_middleware_1.RenderMiddlewareBase {
|
|
|
173
173
|
exports.ChromesHandler = ChromesHandler;
|
|
174
174
|
/**
|
|
175
175
|
* Type guard for EditingMetadataPreviewData
|
|
176
|
-
* @param {
|
|
176
|
+
* @param {object} data preview data to check
|
|
177
177
|
* @returns true if the data is EditingMetadataPreviewData
|
|
178
178
|
* @see EditingMetadataPreviewData
|
|
179
179
|
*/
|
|
@@ -265,7 +265,10 @@ class MetadataHandler {
|
|
|
265
265
|
* @returns Content-Security-Policy header value
|
|
266
266
|
*/
|
|
267
267
|
getSCPHeader() {
|
|
268
|
-
return `frame-ancestors 'self' ${[
|
|
268
|
+
return `frame-ancestors 'self' ${[
|
|
269
|
+
...(0, utils_2.getAllowedOriginsFromEnv)(),
|
|
270
|
+
...editing_1.EDITING_ALLOWED_ORIGINS,
|
|
271
|
+
].join(' ')}`;
|
|
269
272
|
}
|
|
270
273
|
}
|
|
271
274
|
exports.MetadataHandler = MetadataHandler;
|
|
@@ -289,14 +292,14 @@ class EditingRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
289
292
|
headers,
|
|
290
293
|
body,
|
|
291
294
|
});
|
|
292
|
-
if (!(0, utils_2.enforceCors)(req, res,
|
|
295
|
+
if (!(0, utils_2.enforceCors)(req, res, editing_1.EDITING_ALLOWED_ORIGINS)) {
|
|
293
296
|
sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
|
|
294
297
|
return res.status(401).json({
|
|
295
298
|
html: `<html><body>Requests from origin ${(_a = req.headers) === null || _a === void 0 ? void 0 : _a.origin} not allowed</body></html>`,
|
|
296
299
|
});
|
|
297
300
|
}
|
|
298
301
|
// Validate secret
|
|
299
|
-
const secret = (_b = query[
|
|
302
|
+
const secret = (_b = query[editing_1.QUERY_PARAM_EDITING_SECRET]) !== null && _b !== void 0 ? _b : body === null || body === void 0 ? void 0 : body.jssEditingSecret;
|
|
300
303
|
if (secret !== (0, utils_1.getJssEditingSecret)()) {
|
|
301
304
|
sitecore_jss_1.debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, (0, utils_1.getJssEditingSecret)());
|
|
302
305
|
return res.status(401).json({
|
|
@@ -314,6 +317,11 @@ class EditingRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
314
317
|
yield handler.render(req, res);
|
|
315
318
|
break;
|
|
316
319
|
}
|
|
320
|
+
case 'OPTIONS': {
|
|
321
|
+
sitecore_jss_1.debug.editing('preflight request');
|
|
322
|
+
// CORS headers are set by enforceCors
|
|
323
|
+
return res.status(204).send(null);
|
|
324
|
+
}
|
|
317
325
|
default:
|
|
318
326
|
sitecore_jss_1.debug.editing('invalid method - sent %s expected GET/POST', req.method);
|
|
319
327
|
res.setHeader('Allow', 'GET, POST');
|
|
@@ -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
|
|
14
|
+
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
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,23 +37,29 @@ class FEAASRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
37
37
|
query,
|
|
38
38
|
headers,
|
|
39
39
|
});
|
|
40
|
-
if (!(0, utils_2.enforceCors)(req, res,
|
|
40
|
+
if (!(0, utils_2.enforceCors)(req, res, editing_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)
|
|
44
44
|
.send(`<html><body>Requests from origin ${(_b = req.headers) === null || _b === void 0 ? void 0 : _b.origin} are not allowed</body></html>`);
|
|
45
45
|
}
|
|
46
|
-
if (method
|
|
47
|
-
sitecore_jss_1.debug.editing('invalid method - sent %s expected GET', method);
|
|
48
|
-
res.setHeader('Allow', 'GET');
|
|
46
|
+
if (!method || !['GET', 'OPTIONS'].includes(method)) {
|
|
47
|
+
sitecore_jss_1.debug.editing('invalid method - sent %s expected GET,OPTIONS', method);
|
|
48
|
+
res.setHeader('Allow', 'GET, OPTIONS');
|
|
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[
|
|
52
|
+
const secret = query[editing_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>');
|
|
56
56
|
}
|
|
57
|
+
// Handle preflight request
|
|
58
|
+
if (method === 'OPTIONS') {
|
|
59
|
+
sitecore_jss_1.debug.editing('preflight request');
|
|
60
|
+
// CORS headers are set by enforceCors
|
|
61
|
+
return res.status(204).send(null);
|
|
62
|
+
}
|
|
57
63
|
try {
|
|
58
64
|
// Get query string parameters to propagate on subsequent requests (e.g. for deployment protection bypass)
|
|
59
65
|
const params = this.getQueryParamsForPropagation(query);
|
|
@@ -9,7 +9,7 @@ class RenderMiddlewareBase {
|
|
|
9
9
|
constructor() {
|
|
10
10
|
/**
|
|
11
11
|
* Gets query parameters that should be passed along to subsequent requests (e.g. for deployment protection bypass)
|
|
12
|
-
* @param {
|
|
12
|
+
* @param {object} query Object of query parameters from incoming URL
|
|
13
13
|
* @returns Object of approved query parameters
|
|
14
14
|
*/
|
|
15
15
|
this.getQueryParamsForPropagation = (query) => {
|
|
@@ -135,8 +135,8 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
initPersonalizeServer(
|
|
139
|
-
return __awaiter(this,
|
|
138
|
+
initPersonalizeServer(_a) {
|
|
139
|
+
return __awaiter(this, arguments, void 0, function* ({ hostname, siteName, request, response, }) {
|
|
140
140
|
yield (0, server_2.CloudSDK)(request, response, {
|
|
141
141
|
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
142
142
|
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
@@ -148,13 +148,13 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
148
148
|
.initialize();
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
-
personalize(
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
personalize(_a, request_1) {
|
|
152
|
+
return __awaiter(this, arguments, void 0, function* ({ params, friendlyId, language, timeout, variantIds, }, request) {
|
|
153
|
+
var _b;
|
|
154
154
|
sitecore_jss_1.debug.personalize('executing experience for %s %o', friendlyId, params);
|
|
155
155
|
return (yield (0, server_3.personalize)(request, {
|
|
156
156
|
channel: this.config.cdpConfig.channel || 'WEB',
|
|
157
|
-
currency: (
|
|
157
|
+
currency: (_b = this.config.cdpConfig.currency) !== null && _b !== void 0 ? _b : 'USD',
|
|
158
158
|
friendlyId,
|
|
159
159
|
params,
|
|
160
160
|
language,
|
|
@@ -98,7 +98,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
98
98
|
url.search = prepareNewURL.search;
|
|
99
99
|
url.locale = req.nextUrl.locale;
|
|
100
100
|
}
|
|
101
|
-
/** return Response redirect with http code of redirect type
|
|
101
|
+
/** return Response redirect with http code of redirect type */
|
|
102
102
|
switch (existsRedirect.redirectType) {
|
|
103
103
|
case site_1.REDIRECT_TYPE_301: {
|
|
104
104
|
return this.createRedirectResponse(url, res, 301, 'Moved Permanently');
|
|
@@ -272,7 +272,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
272
272
|
/**
|
|
273
273
|
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
274
274
|
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
275
|
-
* @param {
|
|
275
|
+
* @param {object} params - The parameters for the URL match.
|
|
276
276
|
* @param {string} params.pathname - The current URL pathname.
|
|
277
277
|
* @param {string} params.queryString - The current URL query string.
|
|
278
278
|
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
@@ -75,6 +75,14 @@ query ${usesPersonalize ? 'PersonalizeSitemapQuery' : 'DefaultSitemapQuery'}(
|
|
|
75
75
|
* @mixes SearchQueryService<PageListQueryResult>
|
|
76
76
|
*/
|
|
77
77
|
class BaseGraphQLSitemapService {
|
|
78
|
+
/**
|
|
79
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
80
|
+
* @param {GraphQLSitemapServiceConfig} options instance
|
|
81
|
+
*/
|
|
82
|
+
constructor(options) {
|
|
83
|
+
this.options = options;
|
|
84
|
+
this._graphQLClient = this.getGraphQLClient();
|
|
85
|
+
}
|
|
78
86
|
/**
|
|
79
87
|
* GraphQL client accessible by descendant classes when needed
|
|
80
88
|
*/
|
|
@@ -87,14 +95,6 @@ class BaseGraphQLSitemapService {
|
|
|
87
95
|
get query() {
|
|
88
96
|
return defaultQuery(this.options.includePersonalizedRoutes);
|
|
89
97
|
}
|
|
90
|
-
/**
|
|
91
|
-
* Creates an instance of graphQL sitemap service with the provided options
|
|
92
|
-
* @param {GraphQLSitemapServiceConfig} options instance
|
|
93
|
-
*/
|
|
94
|
-
constructor(options) {
|
|
95
|
-
this.options = options;
|
|
96
|
-
this._graphQLClient = this.getGraphQLClient();
|
|
97
|
-
}
|
|
98
98
|
/**
|
|
99
99
|
* Fetch sitemap which could be used for generation of static pages during `next export`.
|
|
100
100
|
* The `locale` parameter will be used in the item query, but since i18n is not supported,
|
|
@@ -162,8 +162,8 @@ class BaseGraphQLSitemapService {
|
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
fetchLanguageSitePaths(language, siteName) {
|
|
165
|
-
var _a, _b, _c, _d;
|
|
166
165
|
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
var _a, _b, _c, _d;
|
|
167
167
|
const args = {
|
|
168
168
|
siteName: siteName,
|
|
169
169
|
language: language,
|
|
@@ -56,8 +56,8 @@ class ComponentPropsService {
|
|
|
56
56
|
* @returns {Promise<ComponentPropsCollection>} component props
|
|
57
57
|
*/
|
|
58
58
|
fetchComponentProps(fetchFunctionFactory, layoutData, context) {
|
|
59
|
-
var _a;
|
|
60
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
+
var _a;
|
|
61
61
|
// Array of side effect functions
|
|
62
62
|
const requests = yield this.collectRequests({
|
|
63
63
|
placeholders: (_a = layoutData.sitecore.route) === null || _a === void 0 ? void 0 : _a.placeholders,
|
|
@@ -71,7 +71,7 @@ class ComponentPropsService {
|
|
|
71
71
|
/**
|
|
72
72
|
* Go through layout service data, check all renderings using displayName, which should make some side effects.
|
|
73
73
|
* Write result in requests variable
|
|
74
|
-
* @param {
|
|
74
|
+
* @param {object} params params
|
|
75
75
|
* @param {PlaceholdersData} [params.placeholders]
|
|
76
76
|
* @param {FetchFunctionFactory<NextContext>} params.fetchFunctionFactory
|
|
77
77
|
* @param {LayoutServiceData} params.layoutData
|
|
@@ -151,7 +151,6 @@ class ComponentPropsService {
|
|
|
151
151
|
* flatRenderings(placeholders);
|
|
152
152
|
*
|
|
153
153
|
* RESULT: [{ uid: 1 }, { uid: 2 }, { uid: 11 }, { uid: 22 }]
|
|
154
|
-
*
|
|
155
154
|
* @param {PlaceholdersData} placeholders placeholders
|
|
156
155
|
* @returns {ComponentRendering[]} renderings
|
|
157
156
|
*/
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -29,7 +29,6 @@ exports.getPublicUrl = getPublicUrl;
|
|
|
29
29
|
* 1. Subscribe on events provided by webpack.
|
|
30
30
|
* 2. Reset editor chromes when build is finished
|
|
31
31
|
* @param {boolean} [forceReload] force page reload instead of reset chromes
|
|
32
|
-
* @default forceReload false
|
|
33
32
|
*/
|
|
34
33
|
const handleEditorFastRefresh = (forceReload = false) => {
|
|
35
34
|
if (process.env.NODE_ENV !== 'development' || !(0, editing_1.isEditorActive)()) {
|
|
@@ -31,7 +31,7 @@ export class ComponentBuilder {
|
|
|
31
31
|
/**
|
|
32
32
|
* Creates a new instance of component factory
|
|
33
33
|
* Component can be imported dynamically or statically.
|
|
34
|
-
* @param {
|
|
34
|
+
* @param {object} [config] Component factory configuration
|
|
35
35
|
* @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
|
|
36
36
|
* @returns {ComponentFactory} Component factory implementation
|
|
37
37
|
*/
|
|
@@ -13,6 +13,10 @@ 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+$/;
|
|
16
20
|
export const Link = forwardRef((props, ref) => {
|
|
17
21
|
const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
18
22
|
if (!field ||
|
|
@@ -30,8 +34,10 @@ export const Link = forwardRef((props, ref) => {
|
|
|
30
34
|
const isEditing = editable && (field.editable || field.metadata);
|
|
31
35
|
if (href && !isEditing) {
|
|
32
36
|
const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
|
|
33
|
-
|
|
34
|
-
|
|
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) {
|
|
35
41
|
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 }),
|
|
36
42
|
text,
|
|
37
43
|
children));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export const QUERY_PARAM_EDITING_SECRET = 'secret';
|
|
2
1
|
export const QUERY_PARAM_VERCEL_PROTECTION_BYPASS = 'x-vercel-protection-bypass';
|
|
3
2
|
export const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
|
|
4
3
|
/**
|
|
@@ -6,7 +5,3 @@ export const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie'
|
|
|
6
5
|
* Note these are in lowercase format to match expected `IncomingHttpHeaders`.
|
|
7
6
|
*/
|
|
8
7
|
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 '
|
|
10
|
+
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, } from '@sitecore-jss/sitecore-jss/editing';
|
|
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';
|
|
@@ -32,6 +32,12 @@ export class EditingConfigMiddleware {
|
|
|
32
32
|
debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, getJssEditingSecret());
|
|
33
33
|
return res.status(401).json({ message: 'Missing or invalid editing secret' });
|
|
34
34
|
}
|
|
35
|
+
// Handle preflight request
|
|
36
|
+
if (_req.method === 'OPTIONS') {
|
|
37
|
+
debug.editing('preflight request');
|
|
38
|
+
// CORS headers are set by enforceCors
|
|
39
|
+
return res.status(204).send(null);
|
|
40
|
+
}
|
|
35
41
|
const components = Array.isArray(this.config.components)
|
|
36
42
|
? this.config.components
|
|
37
43
|
: Array.from(this.config.components.keys());
|
|
@@ -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 '
|
|
12
|
+
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, } from '@sitecore-jss/sitecore-jss/editing';
|
|
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 '
|
|
10
|
+
import { QUERY_PARAM_EDITING_SECRET } from '@sitecore-jss/sitecore-jss/editing';
|
|
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';
|
|
13
14
|
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';
|
|
@@ -27,7 +27,7 @@ export class ChromesHandler extends RenderMiddlewareBase {
|
|
|
27
27
|
this.config = config;
|
|
28
28
|
/**
|
|
29
29
|
* Default page URL resolution.
|
|
30
|
-
* @param {
|
|
30
|
+
* @param {object} args Arguments for resolving the page URL
|
|
31
31
|
* @param {string} args.serverUrl The root server URL e.g. 'http://localhost:3000'
|
|
32
32
|
* @param {string} args.itemPath The Sitecore relative item path e.g. '/styleguide'
|
|
33
33
|
* @returns {string} The URL to render
|
|
@@ -169,7 +169,7 @@ export class ChromesHandler extends RenderMiddlewareBase {
|
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
171
|
* Type guard for EditingMetadataPreviewData
|
|
172
|
-
* @param {
|
|
172
|
+
* @param {object} data preview data to check
|
|
173
173
|
* @returns true if the data is EditingMetadataPreviewData
|
|
174
174
|
* @see EditingMetadataPreviewData
|
|
175
175
|
*/
|
|
@@ -260,7 +260,10 @@ export class MetadataHandler {
|
|
|
260
260
|
* @returns Content-Security-Policy header value
|
|
261
261
|
*/
|
|
262
262
|
getSCPHeader() {
|
|
263
|
-
return `frame-ancestors 'self' ${[
|
|
263
|
+
return `frame-ancestors 'self' ${[
|
|
264
|
+
...getAllowedOriginsFromEnv(),
|
|
265
|
+
...EDITING_ALLOWED_ORIGINS,
|
|
266
|
+
].join(' ')}`;
|
|
264
267
|
}
|
|
265
268
|
}
|
|
266
269
|
/**
|
|
@@ -308,6 +311,11 @@ export class EditingRenderMiddleware extends RenderMiddlewareBase {
|
|
|
308
311
|
yield handler.render(req, res);
|
|
309
312
|
break;
|
|
310
313
|
}
|
|
314
|
+
case 'OPTIONS': {
|
|
315
|
+
debug.editing('preflight request');
|
|
316
|
+
// CORS headers are set by enforceCors
|
|
317
|
+
return res.status(204).send(null);
|
|
318
|
+
}
|
|
311
319
|
default:
|
|
312
320
|
debug.editing('invalid method - sent %s expected GET/POST', req.method);
|
|
313
321
|
res.setHeader('Allow', 'GET, POST');
|
|
@@ -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 '
|
|
11
|
+
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, } from '@sitecore-jss/sitecore-jss/editing';
|
|
12
12
|
import { getJssEditingSecret } from '../utils/utils';
|
|
13
13
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
14
14
|
import { enforceCors } from '@sitecore-jss/sitecore-jss/utils';
|
|
@@ -40,9 +40,9 @@ export class FEAASRenderMiddleware extends RenderMiddlewareBase {
|
|
|
40
40
|
.status(401)
|
|
41
41
|
.send(`<html><body>Requests from origin ${(_b = req.headers) === null || _b === void 0 ? void 0 : _b.origin} are not allowed</body></html>`);
|
|
42
42
|
}
|
|
43
|
-
if (method
|
|
44
|
-
debug.editing('invalid method - sent %s expected GET', method);
|
|
45
|
-
res.setHeader('Allow', 'GET');
|
|
43
|
+
if (!method || !['GET', 'OPTIONS'].includes(method)) {
|
|
44
|
+
debug.editing('invalid method - sent %s expected GET,OPTIONS', method);
|
|
45
|
+
res.setHeader('Allow', 'GET, OPTIONS');
|
|
46
46
|
return res.status(405).send(`<html><body>Invalid request method '${method}'</body></html>`);
|
|
47
47
|
}
|
|
48
48
|
// Validate secret
|
|
@@ -51,6 +51,12 @@ export class FEAASRenderMiddleware extends RenderMiddlewareBase {
|
|
|
51
51
|
debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, getJssEditingSecret());
|
|
52
52
|
return res.status(401).send('<html><body>Missing or invalid secret</body></html>');
|
|
53
53
|
}
|
|
54
|
+
// Handle preflight request
|
|
55
|
+
if (method === 'OPTIONS') {
|
|
56
|
+
debug.editing('preflight request');
|
|
57
|
+
// CORS headers are set by enforceCors
|
|
58
|
+
return res.status(204).send(null);
|
|
59
|
+
}
|
|
54
60
|
try {
|
|
55
61
|
// Get query string parameters to propagate on subsequent requests (e.g. for deployment protection bypass)
|
|
56
62
|
const params = this.getQueryParamsForPropagation(query);
|
|
@@ -6,7 +6,7 @@ export class RenderMiddlewareBase {
|
|
|
6
6
|
constructor() {
|
|
7
7
|
/**
|
|
8
8
|
* Gets query parameters that should be passed along to subsequent requests (e.g. for deployment protection bypass)
|
|
9
|
-
* @param {
|
|
9
|
+
* @param {object} query Object of query parameters from incoming URL
|
|
10
10
|
* @returns Object of approved query parameters
|
|
11
11
|
*/
|
|
12
12
|
this.getQueryParamsForPropagation = (query) => {
|
|
@@ -132,8 +132,8 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
132
132
|
}
|
|
133
133
|
});
|
|
134
134
|
}
|
|
135
|
-
initPersonalizeServer(
|
|
136
|
-
return __awaiter(this,
|
|
135
|
+
initPersonalizeServer(_a) {
|
|
136
|
+
return __awaiter(this, arguments, void 0, function* ({ hostname, siteName, request, response, }) {
|
|
137
137
|
yield CloudSDK(request, response, {
|
|
138
138
|
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
139
139
|
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
@@ -145,13 +145,13 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
145
145
|
.initialize();
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
|
-
personalize(
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
personalize(_a, request_1) {
|
|
149
|
+
return __awaiter(this, arguments, void 0, function* ({ params, friendlyId, language, timeout, variantIds, }, request) {
|
|
150
|
+
var _b;
|
|
151
151
|
debug.personalize('executing experience for %s %o', friendlyId, params);
|
|
152
152
|
return (yield personalize(request, {
|
|
153
153
|
channel: this.config.cdpConfig.channel || 'WEB',
|
|
154
|
-
currency: (
|
|
154
|
+
currency: (_b = this.config.cdpConfig.currency) !== null && _b !== void 0 ? _b : 'USD',
|
|
155
155
|
friendlyId,
|
|
156
156
|
params,
|
|
157
157
|
language,
|
|
@@ -92,7 +92,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
92
92
|
url.search = prepareNewURL.search;
|
|
93
93
|
url.locale = req.nextUrl.locale;
|
|
94
94
|
}
|
|
95
|
-
/** return Response redirect with http code of redirect type
|
|
95
|
+
/** return Response redirect with http code of redirect type */
|
|
96
96
|
switch (existsRedirect.redirectType) {
|
|
97
97
|
case REDIRECT_TYPE_301: {
|
|
98
98
|
return this.createRedirectResponse(url, res, 301, 'Moved Permanently');
|
|
@@ -266,7 +266,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
266
266
|
/**
|
|
267
267
|
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
268
268
|
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
269
|
-
* @param {
|
|
269
|
+
* @param {object} params - The parameters for the URL match.
|
|
270
270
|
* @param {string} params.pathname - The current URL pathname.
|
|
271
271
|
* @param {string} params.queryString - The current URL query string.
|
|
272
272
|
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
@@ -71,6 +71,14 @@ query ${usesPersonalize ? 'PersonalizeSitemapQuery' : 'DefaultSitemapQuery'}(
|
|
|
71
71
|
* @mixes SearchQueryService<PageListQueryResult>
|
|
72
72
|
*/
|
|
73
73
|
export class BaseGraphQLSitemapService {
|
|
74
|
+
/**
|
|
75
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
76
|
+
* @param {GraphQLSitemapServiceConfig} options instance
|
|
77
|
+
*/
|
|
78
|
+
constructor(options) {
|
|
79
|
+
this.options = options;
|
|
80
|
+
this._graphQLClient = this.getGraphQLClient();
|
|
81
|
+
}
|
|
74
82
|
/**
|
|
75
83
|
* GraphQL client accessible by descendant classes when needed
|
|
76
84
|
*/
|
|
@@ -83,14 +91,6 @@ export class BaseGraphQLSitemapService {
|
|
|
83
91
|
get query() {
|
|
84
92
|
return defaultQuery(this.options.includePersonalizedRoutes);
|
|
85
93
|
}
|
|
86
|
-
/**
|
|
87
|
-
* Creates an instance of graphQL sitemap service with the provided options
|
|
88
|
-
* @param {GraphQLSitemapServiceConfig} options instance
|
|
89
|
-
*/
|
|
90
|
-
constructor(options) {
|
|
91
|
-
this.options = options;
|
|
92
|
-
this._graphQLClient = this.getGraphQLClient();
|
|
93
|
-
}
|
|
94
94
|
/**
|
|
95
95
|
* Fetch sitemap which could be used for generation of static pages during `next export`.
|
|
96
96
|
* The `locale` parameter will be used in the item query, but since i18n is not supported,
|
|
@@ -158,8 +158,8 @@ export class BaseGraphQLSitemapService {
|
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
160
|
fetchLanguageSitePaths(language, siteName) {
|
|
161
|
-
var _a, _b, _c, _d;
|
|
162
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
var _a, _b, _c, _d;
|
|
163
163
|
const args = {
|
|
164
164
|
siteName: siteName,
|
|
165
165
|
language: language,
|
|
@@ -50,8 +50,8 @@ export class ComponentPropsService {
|
|
|
50
50
|
* @returns {Promise<ComponentPropsCollection>} component props
|
|
51
51
|
*/
|
|
52
52
|
fetchComponentProps(fetchFunctionFactory, layoutData, context) {
|
|
53
|
-
var _a;
|
|
54
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
var _a;
|
|
55
55
|
// Array of side effect functions
|
|
56
56
|
const requests = yield this.collectRequests({
|
|
57
57
|
placeholders: (_a = layoutData.sitecore.route) === null || _a === void 0 ? void 0 : _a.placeholders,
|
|
@@ -65,7 +65,7 @@ export class ComponentPropsService {
|
|
|
65
65
|
/**
|
|
66
66
|
* Go through layout service data, check all renderings using displayName, which should make some side effects.
|
|
67
67
|
* Write result in requests variable
|
|
68
|
-
* @param {
|
|
68
|
+
* @param {object} params params
|
|
69
69
|
* @param {PlaceholdersData} [params.placeholders]
|
|
70
70
|
* @param {FetchFunctionFactory<NextContext>} params.fetchFunctionFactory
|
|
71
71
|
* @param {LayoutServiceData} params.layoutData
|
|
@@ -145,7 +145,6 @@ export class ComponentPropsService {
|
|
|
145
145
|
* flatRenderings(placeholders);
|
|
146
146
|
*
|
|
147
147
|
* RESULT: [{ uid: 1 }, { uid: 2 }, { uid: 11 }, { uid: 22 }]
|
|
148
|
-
*
|
|
149
148
|
* @param {PlaceholdersData} placeholders placeholders
|
|
150
149
|
* @returns {ComponentRendering[]} renderings
|
|
151
150
|
*/
|
package/dist/esm/utils/utils.js
CHANGED
|
@@ -25,7 +25,6 @@ export const getPublicUrl = () => {
|
|
|
25
25
|
* 1. Subscribe on events provided by webpack.
|
|
26
26
|
* 2. Reset editor chromes when build is finished
|
|
27
27
|
* @param {boolean} [forceReload] force page reload instead of reset chromes
|
|
28
|
-
* @default forceReload false
|
|
29
28
|
*/
|
|
30
29
|
export const handleEditorFastRefresh = (forceReload = false) => {
|
|
31
30
|
if (process.env.NODE_ENV !== 'development' || !isEditorActive()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.3.
|
|
3
|
+
"version": "22.3.1-canary.11",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,10 +11,10 @@
|
|
|
11
11
|
"test": "mocha --require ./test/setup.js \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
13
|
"coverage": "nyc npm test",
|
|
14
|
-
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --entryPoints src/context/index.ts --entryPoints src/utils/index.ts --entryPoints src/site/index.ts --entryPoints src/graphql/index.ts --githubPages false"
|
|
14
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/sitecore-jss-nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --entryPoints src/context/index.ts --entryPoints src/utils/index.ts --entryPoints src/site/index.ts --entryPoints src/graphql/index.ts --githubPages false"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
17
|
+
"node": ">=22"
|
|
18
18
|
},
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Sitecore Corporation",
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"url": "https://github.com/sitecore/jss/issues"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@sitecore-cloudsdk/core": "^0.4.
|
|
33
|
-
"@sitecore-cloudsdk/personalize": "^0.4.
|
|
32
|
+
"@sitecore-cloudsdk/core": "^0.4.2",
|
|
33
|
+
"@sitecore-cloudsdk/personalize": "^0.4.2",
|
|
34
34
|
"@types/chai": "^4.3.4",
|
|
35
35
|
"@types/chai-as-promised": "^7.1.5",
|
|
36
36
|
"@types/chai-string": "^1.4.2",
|
|
37
37
|
"@types/enzyme": "^3.10.12",
|
|
38
38
|
"@types/mocha": "^10.0.1",
|
|
39
|
-
"@types/node": "~
|
|
39
|
+
"@types/node": "~22.9.0",
|
|
40
40
|
"@types/prop-types": "^15.7.5",
|
|
41
|
-
"@types/react": "^18.2.
|
|
41
|
+
"@types/react": "^18.2.45",
|
|
42
42
|
"@types/react-dom": "^18.0.10",
|
|
43
43
|
"@types/sinon": "^10.0.13",
|
|
44
44
|
"@types/sinon-chai": "^3.2.9",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"cross-fetch": "^3.1.5",
|
|
52
52
|
"del-cli": "^5.0.0",
|
|
53
53
|
"enzyme": "^3.11.0",
|
|
54
|
-
"eslint": "^8.
|
|
54
|
+
"eslint": "^8.56.0",
|
|
55
55
|
"eslint-plugin-react": "^7.32.1",
|
|
56
56
|
"jsdom": "^21.1.0",
|
|
57
57
|
"mocha": "^10.2.0",
|
|
58
|
-
"next": "^14.2.
|
|
58
|
+
"next": "^14.2.18",
|
|
59
59
|
"nock": "^13.3.0",
|
|
60
60
|
"nyc": "^15.1.0",
|
|
61
61
|
"react": "^18.2.0",
|
|
@@ -63,19 +63,19 @@
|
|
|
63
63
|
"sinon": "^15.0.1",
|
|
64
64
|
"sinon-chai": "^3.7.0",
|
|
65
65
|
"ts-node": "^10.9.1",
|
|
66
|
-
"typescript": "~4.
|
|
66
|
+
"typescript": "~5.4.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@sitecore-cloudsdk/core": "^0.4.
|
|
70
|
-
"@sitecore-cloudsdk/personalize": "^0.4.
|
|
71
|
-
"next": "^14.2.
|
|
69
|
+
"@sitecore-cloudsdk/core": "^0.4.2",
|
|
70
|
+
"@sitecore-cloudsdk/personalize": "^0.4.2",
|
|
71
|
+
"next": "^14.2.18",
|
|
72
72
|
"react": "^18.2.0",
|
|
73
73
|
"react-dom": "^18.2.0"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@sitecore-jss/sitecore-jss": "22.3.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "22.3.
|
|
78
|
-
"@sitecore-jss/sitecore-jss-react": "22.3.
|
|
76
|
+
"@sitecore-jss/sitecore-jss": "^22.3.1-canary.11",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^22.3.1-canary.11",
|
|
78
|
+
"@sitecore-jss/sitecore-jss-react": "^22.3.1-canary.11",
|
|
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": "
|
|
86
|
+
"gitHead": "e0fc3cbbe09cd16d73934faa4807de2867cd3126",
|
|
87
87
|
"files": [
|
|
88
88
|
"dist",
|
|
89
89
|
"types",
|
|
@@ -50,7 +50,7 @@ export declare class ComponentBuilder {
|
|
|
50
50
|
/**
|
|
51
51
|
* Creates a new instance of component factory
|
|
52
52
|
* Component can be imported dynamically or statically.
|
|
53
|
-
* @param {
|
|
53
|
+
* @param {object} [config] Component factory configuration
|
|
54
54
|
* @param {boolean} [config.isEditing] Indicates if component factory is used in editing mode
|
|
55
55
|
* @returns {ComponentFactory} Component factory implementation
|
|
56
56
|
*/
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export declare const QUERY_PARAM_EDITING_SECRET = "secret";
|
|
2
1
|
export declare const QUERY_PARAM_VERCEL_PROTECTION_BYPASS = "x-vercel-protection-bypass";
|
|
3
2
|
export declare const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = "x-vercel-set-bypass-cookie";
|
|
4
3
|
/**
|
|
@@ -6,7 +5,3 @@ export declare const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = "x-vercel-set-bypass
|
|
|
6
5
|
* Note these are in lowercase format to match expected `IncomingHttpHeaders`.
|
|
7
6
|
*/
|
|
8
7
|
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 { LayoutKind } from '@sitecore-jss/sitecore-jss/editing';
|
|
4
|
+
import { RenderMetadataQueryParams, LayoutKind } from '@sitecore-jss/sitecore-jss/editing';
|
|
5
5
|
import { EditingDataService } from './editing-data-service';
|
|
6
6
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
7
7
|
/**
|
|
@@ -32,7 +32,7 @@ export type EditingRenderMiddlewareConfig = {
|
|
|
32
32
|
*
|
|
33
33
|
* Function used to determine route/page URL to render.
|
|
34
34
|
* This may be necessary for certain custom Next.js routing configurations.
|
|
35
|
-
* @param {
|
|
35
|
+
* @param {object} args Arguments for resolving the page URL
|
|
36
36
|
* @param {string} args.serverUrl The root server URL e.g. 'http://localhost:3000'. Available in Chromes Edit Mode only.
|
|
37
37
|
* @param {string} itemPath The Sitecore relative item path e.g. '/styleguide'
|
|
38
38
|
* @returns {string} The URL to render
|
|
@@ -73,7 +73,7 @@ export declare class ChromesHandler extends RenderMiddlewareBase {
|
|
|
73
73
|
render(req: NextApiRequest, res: NextApiResponse): Promise<void>;
|
|
74
74
|
/**
|
|
75
75
|
* Default page URL resolution.
|
|
76
|
-
* @param {
|
|
76
|
+
* @param {object} args Arguments for resolving the page URL
|
|
77
77
|
* @param {string} args.serverUrl The root server URL e.g. 'http://localhost:3000'
|
|
78
78
|
* @param {string} args.itemPath The Sitecore relative item path e.g. '/styleguide'
|
|
79
79
|
* @returns {string} The URL to render
|
|
@@ -96,26 +96,11 @@ 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
|
-
};
|
|
114
99
|
/**
|
|
115
100
|
* Next.js API request with Metadata query parameters.
|
|
116
101
|
*/
|
|
117
102
|
type MetadataNextApiRequest = NextApiRequest & {
|
|
118
|
-
query:
|
|
103
|
+
query: RenderMetadataQueryParams;
|
|
119
104
|
};
|
|
120
105
|
/**
|
|
121
106
|
* Data for Next.js Preview (Editing) Metadata Edit Mode.
|
|
@@ -132,7 +117,7 @@ export type EditingMetadataPreviewData = {
|
|
|
132
117
|
};
|
|
133
118
|
/**
|
|
134
119
|
* Type guard for EditingMetadataPreviewData
|
|
135
|
-
* @param {
|
|
120
|
+
* @param {object} data preview data to check
|
|
136
121
|
* @returns true if the data is EditingMetadataPreviewData
|
|
137
122
|
* @see EditingMetadataPreviewData
|
|
138
123
|
*/
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { IncomingHttpHeaders } from 'http';
|
|
2
3
|
/**
|
|
3
4
|
* Base class for middleware that handles pages and components rendering in Sitecore Editors.
|
|
@@ -5,7 +6,7 @@ import { IncomingHttpHeaders } from 'http';
|
|
|
5
6
|
export declare abstract class RenderMiddlewareBase {
|
|
6
7
|
/**
|
|
7
8
|
* Gets query parameters that should be passed along to subsequent requests (e.g. for deployment protection bypass)
|
|
8
|
-
* @param {
|
|
9
|
+
* @param {object} query Object of query parameters from incoming URL
|
|
9
10
|
* @returns Object of approved query parameters
|
|
10
11
|
*/
|
|
11
12
|
protected getQueryParamsForPropagation: (query: Partial<{
|
|
@@ -57,7 +57,7 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
|
57
57
|
/**
|
|
58
58
|
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
59
59
|
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
60
|
-
* @param {
|
|
60
|
+
* @param {object} params - The parameters for the URL match.
|
|
61
61
|
* @param {string} params.pathname - The current URL pathname.
|
|
62
62
|
* @param {string} params.queryString - The current URL query string.
|
|
63
63
|
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
@@ -27,7 +27,8 @@ interface SiteRouteQueryVariables {
|
|
|
27
27
|
* Optional. Paths starting with these provided prefixes will be excluded from returned results.
|
|
28
28
|
*/
|
|
29
29
|
excludedPaths?: string[];
|
|
30
|
-
/**
|
|
30
|
+
/**
|
|
31
|
+
* common variable for all GraphQL queries
|
|
31
32
|
* it will be used for every type of query to regulate result batch size
|
|
32
33
|
* Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
|
|
33
34
|
* @default 100
|
|
@@ -96,6 +97,11 @@ export type StaticPath = {
|
|
|
96
97
|
export declare abstract class BaseGraphQLSitemapService {
|
|
97
98
|
options: BaseGraphQLSitemapServiceConfig;
|
|
98
99
|
private _graphQLClient;
|
|
100
|
+
/**
|
|
101
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
102
|
+
* @param {GraphQLSitemapServiceConfig} options instance
|
|
103
|
+
*/
|
|
104
|
+
constructor(options: BaseGraphQLSitemapServiceConfig);
|
|
99
105
|
/**
|
|
100
106
|
* GraphQL client accessible by descendant classes when needed
|
|
101
107
|
*/
|
|
@@ -104,11 +110,6 @@ export declare abstract class BaseGraphQLSitemapService {
|
|
|
104
110
|
* Gets the default query used for fetching the list of site pages
|
|
105
111
|
*/
|
|
106
112
|
protected get query(): string;
|
|
107
|
-
/**
|
|
108
|
-
* Creates an instance of graphQL sitemap service with the provided options
|
|
109
|
-
* @param {GraphQLSitemapServiceConfig} options instance
|
|
110
|
-
*/
|
|
111
|
-
constructor(options: BaseGraphQLSitemapServiceConfig);
|
|
112
113
|
/**
|
|
113
114
|
* Fetch sitemap which could be used for generation of static pages during `next export`.
|
|
114
115
|
* The `locale` parameter will be used in the item query, but since i18n is not supported,
|
|
@@ -41,7 +41,7 @@ export declare class ComponentPropsService {
|
|
|
41
41
|
/**
|
|
42
42
|
* Go through layout service data, check all renderings using displayName, which should make some side effects.
|
|
43
43
|
* Write result in requests variable
|
|
44
|
-
* @param {
|
|
44
|
+
* @param {object} params params
|
|
45
45
|
* @param {PlaceholdersData} [params.placeholders]
|
|
46
46
|
* @param {FetchFunctionFactory<NextContext>} params.fetchFunctionFactory
|
|
47
47
|
* @param {LayoutServiceData} params.layoutData
|
|
@@ -73,7 +73,6 @@ export declare class ComponentPropsService {
|
|
|
73
73
|
* flatRenderings(placeholders);
|
|
74
74
|
*
|
|
75
75
|
* RESULT: [{ uid: 1 }, { uid: 2 }, { uid: 11 }, { uid: 22 }]
|
|
76
|
-
*
|
|
77
76
|
* @param {PlaceholdersData} placeholders placeholders
|
|
78
77
|
* @returns {ComponentRendering[]} renderings
|
|
79
78
|
*/
|
package/types/utils/utils.d.ts
CHANGED
|
@@ -13,7 +13,6 @@ export declare const getPublicUrl: () => string;
|
|
|
13
13
|
* 1. Subscribe on events provided by webpack.
|
|
14
14
|
* 2. Reset editor chromes when build is finished
|
|
15
15
|
* @param {boolean} [forceReload] force page reload instead of reset chromes
|
|
16
|
-
* @default forceReload false
|
|
17
16
|
*/
|
|
18
17
|
export declare const handleEditorFastRefresh: (forceReload?: boolean) => void;
|
|
19
18
|
export declare const getJssEditingSecret: () => string;
|