@sitecore-jss/sitecore-jss-nextjs 22.3.1 → 22.4.0-canary.10
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/LICENSE.txt +202 -202
- package/README.md +11 -11
- package/dist/cjs/editing/editing-data-service.js +1 -1
- package/dist/cjs/editing/editing-render-middleware.js +57 -22
- package/dist/cjs/editing/index.js +6 -1
- package/dist/cjs/editing/render-middleware.js +8 -6
- package/dist/cjs/index.js +5 -3
- package/dist/cjs/middleware/redirects-middleware.js +53 -81
- package/dist/esm/editing/editing-data-service.js +2 -2
- package/dist/esm/editing/editing-render-middleware.js +57 -23
- package/dist/esm/editing/index.js +2 -1
- package/dist/esm/editing/render-middleware.js +8 -6
- package/dist/esm/index.js +3 -2
- package/dist/esm/middleware/redirects-middleware.js +54 -82
- package/package.json +5 -5
- package/types/editing/editing-data-service.d.ts +5 -5
- package/types/editing/editing-render-middleware.d.ts +28 -7
- package/types/editing/index.d.ts +2 -1
- package/types/editing/render-middleware.d.ts +1 -1
- package/types/index.d.ts +3 -2
- package/types/middleware/redirects-middleware.d.ts +0 -11
package/dist/cjs/index.js
CHANGED
|
@@ -23,11 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = exports.NextImage = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getGroomedVariantIds = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.EditMode = exports.getContentStylesheetLink = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.MemoryCacheClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.
|
|
27
|
-
exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.DefaultEmptyFieldEditingComponentText = exports.DefaultEmptyFieldEditingComponentImage = exports.File = exports.getComponentLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = void 0;
|
|
26
|
+
exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = exports.NextImage = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getGroomedVariantIds = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.RestComponentLayoutService = exports.EditMode = exports.getContentStylesheetLink = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.MemoryCacheClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.constants = void 0;
|
|
27
|
+
exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.DefaultEmptyFieldEditingComponentText = exports.DefaultEmptyFieldEditingComponentImage = exports.ComponentLibraryLayout = exports.File = exports.getComponentLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = void 0;
|
|
28
28
|
var sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
29
29
|
Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return sitecore_jss_1.constants; } });
|
|
30
|
-
Object.defineProperty(exports, "AxiosDataFetcher", { enumerable: true, get: function () { return sitecore_jss_1.AxiosDataFetcher; } });
|
|
31
30
|
Object.defineProperty(exports, "NativeDataFetcher", { enumerable: true, get: function () { return sitecore_jss_1.NativeDataFetcher; } });
|
|
32
31
|
Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return sitecore_jss_1.enableDebug; } });
|
|
33
32
|
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return sitecore_jss_1.debug; } });
|
|
@@ -40,6 +39,8 @@ Object.defineProperty(exports, "getChildPlaceholder", { enumerable: true, get: f
|
|
|
40
39
|
Object.defineProperty(exports, "getFieldValue", { enumerable: true, get: function () { return layout_1.getFieldValue; } });
|
|
41
40
|
Object.defineProperty(exports, "getContentStylesheetLink", { enumerable: true, get: function () { return layout_1.getContentStylesheetLink; } });
|
|
42
41
|
Object.defineProperty(exports, "EditMode", { enumerable: true, get: function () { return layout_1.EditMode; } });
|
|
42
|
+
var editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
43
|
+
Object.defineProperty(exports, "RestComponentLayoutService", { enumerable: true, get: function () { return editing_1.RestComponentLayoutService; } });
|
|
43
44
|
var media_1 = require("@sitecore-jss/sitecore-jss/media");
|
|
44
45
|
Object.defineProperty(exports, "mediaApi", { enumerable: true, get: function () { return media_1.mediaApi; } });
|
|
45
46
|
var tracking_1 = require("@sitecore-jss/sitecore-jss/tracking");
|
|
@@ -99,6 +100,7 @@ Object.defineProperty(exports, "fetchFEaaSComponentServerProps", { enumerable: t
|
|
|
99
100
|
Object.defineProperty(exports, "BYOCComponent", { enumerable: true, get: function () { return sitecore_jss_react_1.BYOCComponent; } });
|
|
100
101
|
Object.defineProperty(exports, "getComponentLibraryStylesheetLinks", { enumerable: true, get: function () { return sitecore_jss_react_1.getComponentLibraryStylesheetLinks; } });
|
|
101
102
|
Object.defineProperty(exports, "File", { enumerable: true, get: function () { return sitecore_jss_react_1.File; } });
|
|
103
|
+
Object.defineProperty(exports, "ComponentLibraryLayout", { enumerable: true, get: function () { return sitecore_jss_react_1.ComponentLibraryLayout; } });
|
|
102
104
|
Object.defineProperty(exports, "DefaultEmptyFieldEditingComponentImage", { enumerable: true, get: function () { return sitecore_jss_react_1.DefaultEmptyFieldEditingComponentImage; } });
|
|
103
105
|
Object.defineProperty(exports, "DefaultEmptyFieldEditingComponentText", { enumerable: true, get: function () { return sitecore_jss_react_1.DefaultEmptyFieldEditingComponentText; } });
|
|
104
106
|
Object.defineProperty(exports, "VisitorIdentification", { enumerable: true, get: function () { return sitecore_jss_react_1.VisitorIdentification; } });
|
|
@@ -45,20 +45,28 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
45
45
|
});
|
|
46
46
|
const createResponse = () => __awaiter(this, void 0, void 0, function* () {
|
|
47
47
|
var _a;
|
|
48
|
+
const response = res || server_1.NextResponse.next();
|
|
48
49
|
if (this.config.disabled && this.config.disabled(req, res || server_1.NextResponse.next())) {
|
|
49
50
|
sitecore_jss_1.debug.redirects('skipped (redirects middleware is disabled)');
|
|
50
|
-
return
|
|
51
|
+
return response;
|
|
51
52
|
}
|
|
52
53
|
if (this.isPreview(req) || this.excludeRoute(pathname)) {
|
|
53
54
|
sitecore_jss_1.debug.redirects('skipped (%s)', this.isPreview(req) ? 'preview' : 'route excluded');
|
|
54
|
-
return
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
// Skip prefetch requests from Next.js, which are not original client requests
|
|
58
|
+
// as they load unnecessary requests that burden the redirects middleware with meaningless traffic
|
|
59
|
+
if (this.isPrefetch(req)) {
|
|
60
|
+
sitecore_jss_1.debug.redirects('skipped (prefetch)');
|
|
61
|
+
response.headers.set('x-middleware-cache', 'no-cache');
|
|
62
|
+
return response;
|
|
55
63
|
}
|
|
56
64
|
site = this.getSite(req, res);
|
|
57
65
|
// Find the redirect from result of RedirectService
|
|
58
66
|
const existsRedirect = yield this.getExistsRedirect(req, site.name);
|
|
59
67
|
if (!existsRedirect) {
|
|
60
68
|
sitecore_jss_1.debug.redirects('skipped (redirect does not exist)');
|
|
61
|
-
return
|
|
69
|
+
return response;
|
|
62
70
|
}
|
|
63
71
|
// Find context site language and replace token
|
|
64
72
|
if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
|
|
@@ -72,27 +80,26 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
72
80
|
url.href = existsRedirect.target;
|
|
73
81
|
}
|
|
74
82
|
else {
|
|
75
|
-
const
|
|
76
|
-
const
|
|
83
|
+
const isUrl = (0, utils_1.isRegexOrUrl)(existsRedirect.pattern) === 'url';
|
|
84
|
+
const targetParts = existsRedirect.target.split('/');
|
|
85
|
+
const urlFirstPart = targetParts[1];
|
|
77
86
|
if (this.locales.includes(urlFirstPart)) {
|
|
78
87
|
req.nextUrl.locale = urlFirstPart;
|
|
79
88
|
existsRedirect.target = existsRedirect.target.replace(`/${urlFirstPart}`, '');
|
|
80
89
|
}
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
.replace(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);
|
|
90
|
+
const targetSegments = isUrl
|
|
91
|
+
? existsRedirect.target.split('?')
|
|
92
|
+
: url.pathname.replace(/\/*$/gi, '') + existsRedirect.matchedQueryString;
|
|
93
|
+
const [targetPath, targetQueryString] = isUrl
|
|
94
|
+
? targetSegments
|
|
95
|
+
: targetSegments
|
|
96
|
+
.replace((0, regex_parser_1.default)(existsRedirect.pattern), existsRedirect.target)
|
|
97
|
+
.replace(/^\/\//, '/')
|
|
98
|
+
.split('?');
|
|
99
|
+
const mergedQueryString = existsRedirect.isQueryStringPreserved
|
|
100
|
+
? (0, utils_1.mergeURLSearchParams)(new URLSearchParams((_a = url.search) !== null && _a !== void 0 ? _a : ''), new URLSearchParams(targetQueryString || ''))
|
|
101
|
+
: targetQueryString || '';
|
|
102
|
+
const prepareNewURL = new URL(`${targetPath}${mergedQueryString ? '?' + mergedQueryString : ''}`, url.origin);
|
|
96
103
|
url.href = prepareNewURL.href;
|
|
97
104
|
url.pathname = prepareNewURL.pathname;
|
|
98
105
|
url.search = prepareNewURL.search;
|
|
@@ -101,16 +108,16 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
101
108
|
/** return Response redirect with http code of redirect type */
|
|
102
109
|
switch (existsRedirect.redirectType) {
|
|
103
110
|
case site_1.REDIRECT_TYPE_301: {
|
|
104
|
-
return this.createRedirectResponse(url,
|
|
111
|
+
return this.createRedirectResponse(url, response, 301, 'Moved Permanently');
|
|
105
112
|
}
|
|
106
113
|
case site_1.REDIRECT_TYPE_302: {
|
|
107
|
-
return this.createRedirectResponse(url,
|
|
114
|
+
return this.createRedirectResponse(url, response, 302, 'Found');
|
|
108
115
|
}
|
|
109
116
|
case site_1.REDIRECT_TYPE_SERVER_TRANSFER: {
|
|
110
|
-
return this.rewrite(url.href, req,
|
|
117
|
+
return this.rewrite(url.href, req, response);
|
|
111
118
|
}
|
|
112
119
|
default:
|
|
113
|
-
return
|
|
120
|
+
return response;
|
|
114
121
|
}
|
|
115
122
|
});
|
|
116
123
|
const response = yield createResponse();
|
|
@@ -152,59 +159,43 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
152
159
|
*/
|
|
153
160
|
getExistsRedirect(req, siteName) {
|
|
154
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
156
162
|
const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
|
|
163
|
+
const normalizedPath = targetURL.replace(/\/*$/gi, '');
|
|
164
|
+
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
157
165
|
const language = this.getLanguage(req);
|
|
158
166
|
const modifyRedirects = structuredClone(redirects);
|
|
167
|
+
let matchedQueryString;
|
|
159
168
|
return modifyRedirects.length
|
|
160
169
|
? modifyRedirects.find((redirect) => {
|
|
170
|
+
var _a;
|
|
171
|
+
if ((0, utils_1.isRegexOrUrl)(redirect.pattern) === 'url') {
|
|
172
|
+
const parseUrlPattern = redirect.pattern.endsWith('/')
|
|
173
|
+
? redirect.pattern.slice(0, -1).split('?')
|
|
174
|
+
: redirect.pattern.split('?');
|
|
175
|
+
return ((parseUrlPattern[0] === normalizedPath ||
|
|
176
|
+
parseUrlPattern[0] === `/${locale}${normalizedPath}`) &&
|
|
177
|
+
(0, utils_1.areURLSearchParamsEqual)(new URLSearchParams((_a = parseUrlPattern[1]) !== null && _a !== void 0 ? _a : ''), new URLSearchParams(targetQS)));
|
|
178
|
+
}
|
|
161
179
|
// Modify the redirect pattern to ignore the language prefix in the path
|
|
162
|
-
|
|
180
|
+
// And escapes non-special "?" characters in a string or regex.
|
|
181
|
+
redirect.pattern = (0, utils_1.escapeNonSpecialQuestionMarks)(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
|
|
163
182
|
// Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
|
|
164
183
|
redirect.pattern = `/^\/${redirect.pattern
|
|
165
184
|
.replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
|
|
166
185
|
.replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
|
|
167
186
|
.replace(/^\^|\$$/g, '') // Further cleans up anchors
|
|
168
|
-
.replace(/(?<!\\)\?/g, '\\?') // Escapes question marks in the pattern
|
|
169
187
|
.replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
* To account for this, the method `isPermutedQueryMatch` generates all possible permutations
|
|
177
|
-
* of the query parameters and checks if any of those permutations match the regex pattern for the redirect.
|
|
178
|
-
*
|
|
179
|
-
* NOTE: This fix is specifically implemented for Netlify, where query parameters are sometimes
|
|
180
|
-
* automatically sorted, which can cause issues with matching redirects if the order of query
|
|
181
|
-
* parameters is important. By checking every possible permutation, we ensure that redirects
|
|
182
|
-
* work correctly on Netlify despite this behavior.
|
|
183
|
-
*
|
|
184
|
-
* It passes several pieces of information to the function:
|
|
185
|
-
* 1. `pathname`: The normalized URL path without query parameters (e.g., '/about').
|
|
186
|
-
* 2. `queryString`: The current query string from the URL, which will be permuted and matched (e.g., '?key1=value1&key2=value2').
|
|
187
|
-
* 3. `pattern`: The regex pattern for the redirect that we are trying to match against the URL (e.g., '/about?key1=value1').
|
|
188
|
-
* 4. `locale`: The locale part of the URL (if any), which helps support multilingual URLs.
|
|
189
|
-
*
|
|
190
|
-
* If one of the permutations of the query string matches the redirect pattern, the function
|
|
191
|
-
* returns the matched query string, which is stored in `matchedQueryString`. If no match is found,
|
|
192
|
-
* it returns `undefined`. The `matchedQueryString` is later used to indicate whether the query
|
|
193
|
-
* string contributed to a successful redirect match.
|
|
194
|
-
*/
|
|
195
|
-
const matchedQueryString = this.isPermutedQueryMatch({
|
|
196
|
-
pathname: targetURL,
|
|
197
|
-
queryString: targetQS,
|
|
198
|
-
pattern: redirect.pattern,
|
|
199
|
-
locale,
|
|
200
|
-
});
|
|
188
|
+
matchedQueryString = [
|
|
189
|
+
(0, regex_parser_1.default)(redirect.pattern).test(`${normalizedPath}${targetQS}`),
|
|
190
|
+
(0, regex_parser_1.default)(redirect.pattern).test(`/${locale}${normalizedPath}${targetQS}`),
|
|
191
|
+
].some(Boolean)
|
|
192
|
+
? targetQS
|
|
193
|
+
: undefined;
|
|
201
194
|
// Save the matched query string (if found) into the redirect object
|
|
202
195
|
redirect.matchedQueryString = matchedQueryString || '';
|
|
203
|
-
|
|
204
|
-
return (((0, regex_parser_1.default)(redirect.pattern).test(targetURL) ||
|
|
196
|
+
return (!!((0, regex_parser_1.default)(redirect.pattern).test(targetURL) ||
|
|
205
197
|
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
|
|
206
|
-
matchedQueryString) &&
|
|
207
|
-
(redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
198
|
+
matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
208
199
|
})
|
|
209
200
|
: undefined;
|
|
210
201
|
});
|
|
@@ -269,24 +260,5 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
269
260
|
}
|
|
270
261
|
return redirect;
|
|
271
262
|
}
|
|
272
|
-
/**
|
|
273
|
-
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
274
|
-
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
275
|
-
* @param {object} params - The parameters for the URL match.
|
|
276
|
-
* @param {string} params.pathname - The current URL pathname.
|
|
277
|
-
* @param {string} params.queryString - The current URL query string.
|
|
278
|
-
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
279
|
-
* @param {string} [params.locale] - The locale prefix to include in the URL if present.
|
|
280
|
-
* @returns {string | undefined} - return query string if any of the query permutations match the provided pattern, undefined otherwise.
|
|
281
|
-
*/
|
|
282
|
-
isPermutedQueryMatch({ pathname, queryString, pattern, locale, }) {
|
|
283
|
-
const paramsArray = Array.from(new URLSearchParams(queryString).entries());
|
|
284
|
-
const listOfPermuted = (0, utils_1.getPermutations)(paramsArray).map((permutation) => '?' + permutation.map(([key, value]) => `${key}=${value}`).join('&'));
|
|
285
|
-
const normalizedPath = pathname.replace(/\/*$/gi, '');
|
|
286
|
-
return listOfPermuted.find((query) => [
|
|
287
|
-
(0, regex_parser_1.default)(pattern).test(`${normalizedPath}${query}`),
|
|
288
|
-
(0, regex_parser_1.default)(pattern).test(`/${locale}${normalizedPath}${query}`),
|
|
289
|
-
].some(Boolean));
|
|
290
|
-
}
|
|
291
263
|
}
|
|
292
264
|
exports.RedirectsMiddleware = RedirectsMiddleware;
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { QUERY_PARAM_EDITING_SECRET } from '@sitecore-jss/sitecore-jss/editing';
|
|
11
|
-
import {
|
|
11
|
+
import { NativeDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
|
|
12
12
|
import { editingDataDiskCache } from './editing-data-cache';
|
|
13
13
|
import { getJssEditingSecret } from '../utils/utils';
|
|
14
14
|
/**
|
|
@@ -85,7 +85,7 @@ export class ServerlessEditingDataService {
|
|
|
85
85
|
if (!this.apiRoute.includes('[key]')) {
|
|
86
86
|
throw new Error(`The specified apiRoute '${this.apiRoute}' is missing '[key]'.`);
|
|
87
87
|
}
|
|
88
|
-
this.dataFetcher = (_b = config === null || config === void 0 ? void 0 : config.dataFetcher) !== null && _b !== void 0 ? _b : new
|
|
88
|
+
this.dataFetcher = (_b = config === null || config === void 0 ? void 0 : config.dataFetcher) !== null && _b !== void 0 ? _b : new NativeDataFetcher({ debugger: debug.editing });
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* Stores Sitecore editor payload data for later retrieval by key
|
|
@@ -8,8 +8,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { STATIC_PROPS_ID, SERVER_PROPS_ID } from 'next/constants';
|
|
11
|
-
import {
|
|
12
|
-
import { EditMode } from '@sitecore-jss/sitecore-jss/layout';
|
|
11
|
+
import { NativeDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
|
|
12
|
+
import { EditMode, LayoutServicePageState } from '@sitecore-jss/sitecore-jss/layout';
|
|
13
13
|
import { QUERY_PARAM_EDITING_SECRET, EDITING_ALLOWED_ORIGINS, } from '@sitecore-jss/sitecore-jss/editing';
|
|
14
14
|
import { editingDataService } from './editing-data-service';
|
|
15
15
|
import { getJssEditingSecret } from '../utils/utils';
|
|
@@ -49,7 +49,7 @@ export class ChromesHandler extends RenderMiddlewareBase {
|
|
|
49
49
|
return `${process.env.VERCEL ? 'https' : 'http'}://${req.headers.host}`;
|
|
50
50
|
};
|
|
51
51
|
this.editingDataService = (_a = config === null || config === void 0 ? void 0 : config.editingDataService) !== null && _a !== void 0 ? _a : editingDataService;
|
|
52
|
-
this.dataFetcher = (_b = config === null || config === void 0 ? void 0 : config.dataFetcher) !== null && _b !== void 0 ? _b : new
|
|
52
|
+
this.dataFetcher = (_b = config === null || config === void 0 ? void 0 : config.dataFetcher) !== null && _b !== void 0 ? _b : new NativeDataFetcher({ debugger: debug.editing });
|
|
53
53
|
this.resolvePageUrl = (_c = config === null || config === void 0 ? void 0 : config.resolvePageUrl) !== null && _c !== void 0 ? _c : this.defaultResolvePageUrl;
|
|
54
54
|
this.resolveServerUrl = (_d = config === null || config === void 0 ? void 0 : config.resolveServerUrl) !== null && _d !== void 0 ? _d : this.defaultResolveServerUrl;
|
|
55
55
|
}
|
|
@@ -76,7 +76,7 @@ export class ChromesHandler extends RenderMiddlewareBase {
|
|
|
76
76
|
const cookies = res.getHeader('Set-Cookie');
|
|
77
77
|
headers.cookie = `${headers.cookie ? headers.cookie + ';' : ''}${cookies.join(';')}`;
|
|
78
78
|
// Make actual render request for page route, passing on preview cookies as well as any approved query string parameters.
|
|
79
|
-
// Note timestamp effectively disables caching the request
|
|
79
|
+
// Note timestamp effectively disables caching the request (no amount of cache headers seemed to do it)
|
|
80
80
|
debug.editing('fetching page route for %s', editingData.path);
|
|
81
81
|
const requestUrl = new URL(this.resolvePageUrl({ serverUrl, itemPath: editingData.path }));
|
|
82
82
|
for (const key in params) {
|
|
@@ -122,8 +122,7 @@ export class ChromesHandler extends RenderMiddlewareBase {
|
|
|
122
122
|
catch (err) {
|
|
123
123
|
const error = err;
|
|
124
124
|
console.error(error);
|
|
125
|
-
if (error.response
|
|
126
|
-
// Axios error, which could mean the server or page URL isn't quite right, so provide a more helpful hint
|
|
125
|
+
if (error.response) {
|
|
127
126
|
console.info(
|
|
128
127
|
// eslint-disable-next-line quotes
|
|
129
128
|
"Hint: for non-standard server or Next.js route configurations, you may need to override the 'resolveServerUrl' or 'resolvePageUrl' available on the 'EditingRenderMiddleware' config.");
|
|
@@ -179,6 +178,18 @@ export const isEditingMetadataPreviewData = (data) => {
|
|
|
179
178
|
'editMode' in data &&
|
|
180
179
|
data.editMode === EditMode.Metadata);
|
|
181
180
|
};
|
|
181
|
+
/**
|
|
182
|
+
* Type guard for Component Library mode
|
|
183
|
+
* @param {object} data preview data to check
|
|
184
|
+
* @returns true if the data is EditingMetadataPreviewData
|
|
185
|
+
* @see EditingMetadataPreviewData
|
|
186
|
+
*/
|
|
187
|
+
export const isComponentLibraryPreviewData = (data) => {
|
|
188
|
+
return (typeof data === 'object' &&
|
|
189
|
+
data !== null &&
|
|
190
|
+
'mode' in data &&
|
|
191
|
+
data.mode === 'library');
|
|
192
|
+
};
|
|
182
193
|
/**
|
|
183
194
|
* Handler for the Editing Metadata GET requests.
|
|
184
195
|
* This handler is responsible for redirecting the request to the page route.
|
|
@@ -192,13 +203,17 @@ export class MetadataHandler {
|
|
|
192
203
|
var _a, _b, _c;
|
|
193
204
|
const { query } = req;
|
|
194
205
|
const startTimestamp = Date.now();
|
|
195
|
-
const
|
|
206
|
+
const mode = query.mode;
|
|
207
|
+
const metadataDefaultRequiredParams = ['sc_site', 'sc_itemid', 'sc_lang', 'route', 'mode'];
|
|
208
|
+
const metadataComponentRequiredParams = [
|
|
196
209
|
'sc_site',
|
|
197
210
|
'sc_itemid',
|
|
211
|
+
'sc_renderingId',
|
|
212
|
+
'sc_uid',
|
|
198
213
|
'sc_lang',
|
|
199
|
-
'route',
|
|
200
214
|
'mode',
|
|
201
215
|
];
|
|
216
|
+
const requiredQueryParams = mode === 'library' ? metadataComponentRequiredParams : metadataDefaultRequiredParams;
|
|
202
217
|
const missingQueryParams = requiredQueryParams.filter((param) => !query[param]);
|
|
203
218
|
// Validate query parameters
|
|
204
219
|
if (missingQueryParams.length) {
|
|
@@ -207,21 +222,40 @@ export class MetadataHandler {
|
|
|
207
222
|
html: `<html><body>Missing required query parameters: ${missingQueryParams.join(', ')}</body></html>`,
|
|
208
223
|
});
|
|
209
224
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
if (mode === 'library') {
|
|
226
|
+
// dedicated route and layout to SSR component library
|
|
227
|
+
query.route = '/component-library/render';
|
|
228
|
+
res.setPreviewData({
|
|
229
|
+
itemId: query.sc_itemid,
|
|
230
|
+
componentUid: query.sc_uid,
|
|
231
|
+
renderingId: query.sc_renderingId,
|
|
232
|
+
language: query.sc_lang,
|
|
233
|
+
site: query.sc_site,
|
|
234
|
+
pageState: LayoutServicePageState.Normal,
|
|
235
|
+
mode: 'library',
|
|
236
|
+
dataSourceId: query.sc_datasourceId,
|
|
237
|
+
version: query.sc_version,
|
|
238
|
+
}, {
|
|
239
|
+
maxAge: 3,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
res.setPreviewData({
|
|
244
|
+
site: query.sc_site,
|
|
245
|
+
itemId: query.sc_itemid,
|
|
246
|
+
language: query.sc_lang,
|
|
247
|
+
// for sc_variantId we may employ multiple variants (page-layout + component level)
|
|
248
|
+
variantIds: ((_a = query.sc_variant) === null || _a === void 0 ? void 0 : _a.split(',')) || [DEFAULT_VARIANT],
|
|
249
|
+
version: query.sc_version,
|
|
250
|
+
editMode: EditMode.Metadata,
|
|
251
|
+
pageState: query.mode,
|
|
252
|
+
layoutKind: query.sc_layoutKind,
|
|
253
|
+
},
|
|
254
|
+
// Cache the preview data for 3 seconds to ensure the page is rendered with the correct preview data not the cached one
|
|
255
|
+
{
|
|
256
|
+
maxAge: 3,
|
|
257
|
+
});
|
|
258
|
+
}
|
|
225
259
|
// Cookies with the SameSite=Lax policy set by Next.js setPreviewData function causes CORS issue
|
|
226
260
|
// when Next.js preview mode is activated, resulting the page to render in normal mode instead.
|
|
227
261
|
// By replacing it with "SameSite=None; Secure", we ensure cookies are correctly sent with
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { GraphQLEditingService } from '@sitecore-jss/sitecore-jss/editing';
|
|
2
2
|
export { EditingDataDiskCache } from './editing-data-cache';
|
|
3
3
|
export { EditingDataMiddleware } from './editing-data-middleware';
|
|
4
|
-
export { EditingRenderMiddleware, isEditingMetadataPreviewData, } from './editing-render-middleware';
|
|
4
|
+
export { EditingRenderMiddleware, isEditingMetadataPreviewData, isComponentLibraryPreviewData, } from './editing-render-middleware';
|
|
5
5
|
export { BasicEditingDataService, ServerlessEditingDataService, editingDataService, } from './editing-data-service';
|
|
6
6
|
export { VercelEditingDataCache } from './vercel-editing-data-cache';
|
|
7
7
|
export { FEAASRenderMiddleware } from './feaas-render-middleware';
|
|
8
8
|
export { EditingConfigMiddleware, } from './editing-config-middleware';
|
|
9
|
+
export { RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-jss/sitecore-jss/layout';
|
|
@@ -25,13 +25,15 @@ export class RenderMiddlewareBase {
|
|
|
25
25
|
* @returns Object of approved headers
|
|
26
26
|
*/
|
|
27
27
|
this.getHeadersForPropagation = (headers) => {
|
|
28
|
-
|
|
29
|
-
EDITING_PASS_THROUGH_HEADERS.
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
// Filter and normalize headers
|
|
29
|
+
const filteredHeaders = EDITING_PASS_THROUGH_HEADERS.reduce((acc, header) => {
|
|
30
|
+
const value = headers[header];
|
|
31
|
+
if (value) {
|
|
32
|
+
acc[header] = Array.isArray(value) ? value.join(', ') : value;
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
|
+
return filteredHeaders;
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { constants,
|
|
1
|
+
export { constants, NativeDataFetcher, enableDebug, debug, MemoryCacheClient, } from '@sitecore-jss/sitecore-jss';
|
|
2
2
|
export { LayoutServicePageState, GraphQLLayoutService, RestLayoutService, getChildPlaceholder, getFieldValue, getContentStylesheetLink, EditMode, } from '@sitecore-jss/sitecore-jss/layout';
|
|
3
|
+
export { RestComponentLayoutService } from '@sitecore-jss/sitecore-jss/editing';
|
|
3
4
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
4
5
|
export { trackingApi, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
5
6
|
export { GraphQLDictionaryService, RestDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
@@ -19,4 +20,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
19
20
|
export { FEaaSWrapper };
|
|
20
21
|
export { BYOCWrapper };
|
|
21
22
|
export { ComponentBuilder } from './ComponentBuilder';
|
|
22
|
-
export { Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, BYOCComponent, getComponentLibraryStylesheetLinks, File, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
|
|
23
|
+
export { Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, BYOCComponent, getComponentLibraryStylesheetLinks, File, ComponentLibraryLayout, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
|