@sitecore-jss/sitecore-jss-nextjs 22.2.0-canary.9 → 22.3.0-canary.2
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/components/Link.js +8 -2
- package/dist/cjs/components/NextImage.js +6 -1
- package/dist/cjs/editing/constants.js +1 -6
- package/dist/cjs/editing/editing-config-middleware.js +3 -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 +5 -5
- package/dist/cjs/editing/feaas-render-middleware.js +3 -3
- package/dist/cjs/index.js +2 -3
- package/dist/cjs/middleware/index.js +3 -1
- package/dist/cjs/middleware/personalize-middleware.js +7 -4
- package/dist/cjs/middleware/redirects-middleware.js +157 -42
- package/dist/esm/components/Link.js +8 -2
- package/dist/esm/components/NextImage.js +8 -3
- package/dist/esm/editing/constants.js +0 -5
- package/dist/esm/editing/editing-config-middleware.js +1 -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 +2 -2
- package/dist/esm/editing/feaas-render-middleware.js +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/middleware/index.js +1 -0
- package/dist/esm/middleware/personalize-middleware.js +6 -3
- package/dist/esm/middleware/redirects-middleware.js +157 -42
- package/package.json +11 -10
- package/types/editing/constants.d.ts +0 -5
- package/types/editing/editing-render-middleware.d.ts +3 -15
- package/types/index.d.ts +1 -2
- package/types/middleware/index.d.ts +1 -0
- package/types/middleware/redirects-middleware.d.ts +29 -1
- package/context.d.ts +0 -1
- package/context.js +0 -1
- package/dist/cjs/context/context.js +0 -83
- package/dist/cjs/context/index.js +0 -5
- package/dist/esm/context/context.js +0 -79
- package/dist/esm/context/index.js +0 -1
- package/types/context/context.d.ts +0 -116
- package/types/context/index.d.ts +0 -1
|
@@ -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';
|
|
@@ -216,10 +216,10 @@ export class MetadataHandler {
|
|
|
216
216
|
version: query.sc_version,
|
|
217
217
|
editMode: EditMode.Metadata,
|
|
218
218
|
pageState: query.mode,
|
|
219
|
+
layoutKind: query.sc_layoutKind,
|
|
219
220
|
},
|
|
220
221
|
// Cache the preview data for 3 seconds to ensure the page is rendered with the correct preview data not the cached one
|
|
221
222
|
{
|
|
222
|
-
path: query.route,
|
|
223
223
|
maxAge: 3,
|
|
224
224
|
});
|
|
225
225
|
// Cookies with the SameSite=Lax policy set by Next.js setPreviewData function causes CORS issue
|
|
@@ -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';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { constants, AxiosDataFetcher, NativeDataFetcher, enableDebug, debug, } from '@sitecore-jss/sitecore-jss';
|
|
1
|
+
export { constants, AxiosDataFetcher, 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
3
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
4
4
|
export { trackingApi, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
@@ -19,5 +19,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
19
19
|
export { FEaaSWrapper };
|
|
20
20
|
export { BYOCWrapper };
|
|
21
21
|
export { ComponentBuilder } from './ComponentBuilder';
|
|
22
|
-
export { Context } from './context';
|
|
23
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';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { debug } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
export { MiddlewareBase } from './middleware';
|
|
2
3
|
export { RedirectsMiddleware } from './redirects-middleware';
|
|
3
4
|
export { PersonalizeMiddleware } from './personalize-middleware';
|
|
4
5
|
export { MultisiteMiddleware } from './multisite-middleware';
|
|
@@ -11,7 +11,8 @@ import { NextResponse } from 'next/server';
|
|
|
11
11
|
import { GraphQLPersonalizeService, getPersonalizedRewrite, CdpHelper, DEFAULT_VARIANT, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
12
12
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
13
13
|
import { MiddlewareBase } from './middleware';
|
|
14
|
-
import {
|
|
14
|
+
import { CloudSDK } from '@sitecore-cloudsdk/core/server';
|
|
15
|
+
import { personalize } from '@sitecore-cloudsdk/personalize/server';
|
|
15
16
|
/**
|
|
16
17
|
* Middleware / handler to support Sitecore Personalize
|
|
17
18
|
*/
|
|
@@ -133,13 +134,15 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
133
134
|
}
|
|
134
135
|
initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
135
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
yield
|
|
137
|
+
yield CloudSDK(request, response, {
|
|
137
138
|
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
138
139
|
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
139
140
|
siteName,
|
|
140
141
|
cookieDomain: hostname,
|
|
141
142
|
enableServerCookie: true,
|
|
142
|
-
})
|
|
143
|
+
})
|
|
144
|
+
.addPersonalize()
|
|
145
|
+
.initialize();
|
|
143
146
|
});
|
|
144
147
|
}
|
|
145
148
|
personalize({ params, friendlyId, language, timeout, variantIds, }, request) {
|
|
@@ -7,10 +7,11 @@ 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 regexParser from 'regex-parser';
|
|
11
|
-
import { NextResponse } from 'next/server';
|
|
12
|
-
import { GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, } from '@sitecore-jss/sitecore-jss/site';
|
|
13
10
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
11
|
+
import { GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, } from '@sitecore-jss/sitecore-jss/site';
|
|
12
|
+
import { getPermutations } from '@sitecore-jss/sitecore-jss/utils';
|
|
13
|
+
import { NextResponse } from 'next/server';
|
|
14
|
+
import regexParser from 'regex-parser';
|
|
14
15
|
import { MiddlewareBase } from './middleware';
|
|
15
16
|
const REGEXP_CONTEXT_SITE_LANG = new RegExp(/\$siteLang/, 'i');
|
|
16
17
|
const REGEXP_ABSOLUTE_URL = new RegExp('^(?:[a-z]+:)?//', 'i');
|
|
@@ -37,6 +38,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
37
38
|
hostname,
|
|
38
39
|
});
|
|
39
40
|
const createResponse = () => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
var _a;
|
|
40
42
|
if (this.config.disabled && this.config.disabled(req, res || NextResponse.next())) {
|
|
41
43
|
debug.redirects('skipped (redirects middleware is disabled)');
|
|
42
44
|
return res || NextResponse.next();
|
|
@@ -57,48 +59,50 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
57
59
|
!(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
|
|
58
60
|
existsRedirect.target.includes(hostname))) {
|
|
59
61
|
existsRedirect.target = existsRedirect.target.replace(REGEXP_CONTEXT_SITE_LANG, site.language);
|
|
62
|
+
req.nextUrl.locale = site.language;
|
|
60
63
|
}
|
|
61
|
-
const url = req.nextUrl.clone();
|
|
64
|
+
const url = this.normalizeUrl(req.nextUrl.clone());
|
|
62
65
|
if (REGEXP_ABSOLUTE_URL.test(existsRedirect.target)) {
|
|
63
66
|
url.href = existsRedirect.target;
|
|
64
67
|
}
|
|
65
68
|
else {
|
|
66
|
-
const source = `${url.pathname}${
|
|
67
|
-
url.search = existsRedirect.isQueryStringPreserved ? url.search : '';
|
|
69
|
+
const source = `${url.pathname.replace(/\/*$/gi, '')}${existsRedirect.matchedQueryString}`;
|
|
68
70
|
const urlFirstPart = existsRedirect.target.split('/')[1];
|
|
69
71
|
if (this.locales.includes(urlFirstPart)) {
|
|
70
|
-
|
|
72
|
+
req.nextUrl.locale = urlFirstPart;
|
|
71
73
|
existsRedirect.target = existsRedirect.target.replace(`/${urlFirstPart}`, '');
|
|
72
74
|
}
|
|
73
75
|
const target = source
|
|
74
76
|
.replace(regexParser(existsRedirect.pattern), existsRedirect.target)
|
|
75
77
|
.replace(/^\/\//, '/')
|
|
76
78
|
.split('?');
|
|
77
|
-
url.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
for (const [key, val] of newParams.entries()) {
|
|
81
|
-
url.searchParams.append(key, val);
|
|
82
|
-
}
|
|
79
|
+
if (url.search && existsRedirect.isQueryStringPreserved) {
|
|
80
|
+
const targetQueryString = (_a = target[1]) !== null && _a !== void 0 ? _a : '';
|
|
81
|
+
url.search = '?' + new URLSearchParams(`${url.search}&${targetQueryString}`).toString();
|
|
83
82
|
}
|
|
83
|
+
else if (target[1]) {
|
|
84
|
+
url.search = '?' + target[1];
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
url.search = '';
|
|
88
|
+
}
|
|
89
|
+
const prepareNewURL = new URL(`${target[0]}${url.search}`, url.origin);
|
|
90
|
+
url.href = prepareNewURL.href;
|
|
91
|
+
url.pathname = prepareNewURL.pathname;
|
|
92
|
+
url.search = prepareNewURL.search;
|
|
93
|
+
url.locale = req.nextUrl.locale;
|
|
84
94
|
}
|
|
85
|
-
const redirectUrl = decodeURIComponent(url.href);
|
|
86
95
|
/** return Response redirect with http code of redirect type **/
|
|
87
96
|
switch (existsRedirect.redirectType) {
|
|
88
|
-
case REDIRECT_TYPE_301:
|
|
89
|
-
return
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
case
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
statusText: 'Found',
|
|
98
|
-
headers: res === null || res === void 0 ? void 0 : res.headers,
|
|
99
|
-
});
|
|
100
|
-
case REDIRECT_TYPE_SERVER_TRANSFER:
|
|
101
|
-
return NextResponse.rewrite(redirectUrl, res);
|
|
97
|
+
case REDIRECT_TYPE_301: {
|
|
98
|
+
return this.createRedirectResponse(url, res, 301, 'Moved Permanently');
|
|
99
|
+
}
|
|
100
|
+
case REDIRECT_TYPE_302: {
|
|
101
|
+
return this.createRedirectResponse(url, res, 302, 'Found');
|
|
102
|
+
}
|
|
103
|
+
case REDIRECT_TYPE_SERVER_TRANSFER: {
|
|
104
|
+
return this.rewrite(url.href, req, res || NextResponse.next());
|
|
105
|
+
}
|
|
102
106
|
default:
|
|
103
107
|
return res || NextResponse.next();
|
|
104
108
|
}
|
|
@@ -143,28 +147,139 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
143
147
|
getExistsRedirect(req, siteName) {
|
|
144
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
145
149
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
146
|
-
const
|
|
147
|
-
const targetQS = req.nextUrl.search || '';
|
|
150
|
+
const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
|
|
148
151
|
const language = this.getLanguage(req);
|
|
149
152
|
const modifyRedirects = structuredClone(redirects);
|
|
150
153
|
return modifyRedirects.length
|
|
151
154
|
? modifyRedirects.find((redirect) => {
|
|
155
|
+
// Modify the redirect pattern to ignore the language prefix in the path
|
|
152
156
|
redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
|
|
157
|
+
// Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
|
|
153
158
|
redirect.pattern = `/^\/${redirect.pattern
|
|
154
|
-
.replace(/^\/|\/$/g, '')
|
|
155
|
-
.replace(/^\^\/|\/\$$/g, '')
|
|
156
|
-
.replace(/^\^|\$$/g, '')
|
|
157
|
-
.replace(/(?<!\\)\?/g, '\\?')
|
|
158
|
-
.replace(/\$\/gi$/g, '')}[\/]?$/
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
.replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
|
|
160
|
+
.replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
|
|
161
|
+
.replace(/^\^|\$$/g, '') // Further cleans up anchors
|
|
162
|
+
.replace(/(?<!\\)\?/g, '\\?') // Escapes question marks in the pattern
|
|
163
|
+
.replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
|
|
164
|
+
/**
|
|
165
|
+
* This line checks whether the current URL query string (and all its possible permutations)
|
|
166
|
+
* matches the redirect pattern.
|
|
167
|
+
*
|
|
168
|
+
* Query parameters in URLs can come in different orders, but logically they represent the
|
|
169
|
+
* same information (e.g., "key1=value1&key2=value2" is the same as "key2=value2&key1=value1").
|
|
170
|
+
* To account for this, the method `isPermutedQueryMatch` generates all possible permutations
|
|
171
|
+
* of the query parameters and checks if any of those permutations match the regex pattern for the redirect.
|
|
172
|
+
*
|
|
173
|
+
* NOTE: This fix is specifically implemented for Netlify, where query parameters are sometimes
|
|
174
|
+
* automatically sorted, which can cause issues with matching redirects if the order of query
|
|
175
|
+
* parameters is important. By checking every possible permutation, we ensure that redirects
|
|
176
|
+
* work correctly on Netlify despite this behavior.
|
|
177
|
+
*
|
|
178
|
+
* It passes several pieces of information to the function:
|
|
179
|
+
* 1. `pathname`: The normalized URL path without query parameters (e.g., '/about').
|
|
180
|
+
* 2. `queryString`: The current query string from the URL, which will be permuted and matched (e.g., '?key1=value1&key2=value2').
|
|
181
|
+
* 3. `pattern`: The regex pattern for the redirect that we are trying to match against the URL (e.g., '/about?key1=value1').
|
|
182
|
+
* 4. `locale`: The locale part of the URL (if any), which helps support multilingual URLs.
|
|
183
|
+
*
|
|
184
|
+
* If one of the permutations of the query string matches the redirect pattern, the function
|
|
185
|
+
* returns the matched query string, which is stored in `matchedQueryString`. If no match is found,
|
|
186
|
+
* it returns `undefined`. The `matchedQueryString` is later used to indicate whether the query
|
|
187
|
+
* string contributed to a successful redirect match.
|
|
188
|
+
*/
|
|
189
|
+
const matchedQueryString = this.isPermutedQueryMatch({
|
|
190
|
+
pathname: targetURL,
|
|
191
|
+
queryString: targetQS,
|
|
192
|
+
pattern: redirect.pattern,
|
|
193
|
+
locale,
|
|
194
|
+
});
|
|
195
|
+
// Save the matched query string (if found) into the redirect object
|
|
196
|
+
redirect.matchedQueryString = matchedQueryString || '';
|
|
197
|
+
// Return the redirect if the URL path or any query string permutation matches the pattern
|
|
198
|
+
return ((regexParser(redirect.pattern).test(targetURL) ||
|
|
199
|
+
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
|
|
200
|
+
matchedQueryString) &&
|
|
201
|
+
(redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
|
|
166
202
|
})
|
|
167
203
|
: undefined;
|
|
168
204
|
});
|
|
169
205
|
}
|
|
206
|
+
/**
|
|
207
|
+
* When a user clicks on a link generated by the Link component from next/link,
|
|
208
|
+
* Next.js adds special parameters in the route called path.
|
|
209
|
+
* This method removes these special parameters.
|
|
210
|
+
* @param {NextURL} url
|
|
211
|
+
* @returns {string} normalize url
|
|
212
|
+
*/
|
|
213
|
+
normalizeUrl(url) {
|
|
214
|
+
if (!url.search) {
|
|
215
|
+
return url;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Prepare special parameters for exclusion.
|
|
219
|
+
*/
|
|
220
|
+
const splittedPathname = url.pathname
|
|
221
|
+
.split('/')
|
|
222
|
+
.filter((route) => route)
|
|
223
|
+
.map((route) => `path=${route}`);
|
|
224
|
+
/**
|
|
225
|
+
* Remove special parameters(Next.JS)
|
|
226
|
+
* Example: /about/contact/us
|
|
227
|
+
* When a user clicks on this link, Next.js should generate a link for the middleware, formatted like this:
|
|
228
|
+
* http://host/about/contact/us?path=about&path=contact&path=us
|
|
229
|
+
*/
|
|
230
|
+
const newQueryString = url.search
|
|
231
|
+
.replace(/^\?/, '')
|
|
232
|
+
.split('&')
|
|
233
|
+
.filter((param) => {
|
|
234
|
+
if (!splittedPathname.includes(param)) {
|
|
235
|
+
return param;
|
|
236
|
+
}
|
|
237
|
+
return false;
|
|
238
|
+
})
|
|
239
|
+
.join('&');
|
|
240
|
+
const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
|
|
241
|
+
url.search = newUrl.search;
|
|
242
|
+
url.pathname = newUrl.pathname;
|
|
243
|
+
url.href = newUrl.href;
|
|
244
|
+
return url;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
248
|
+
* @param {NextURL} url The URL to redirect to.
|
|
249
|
+
* @param {Response} res The response object.
|
|
250
|
+
* @param {number} status The HTTP status code of the redirect.
|
|
251
|
+
* @param {string} statusText The status text of the redirect.
|
|
252
|
+
* @returns {NextResponse<unknown>} The redirect response.
|
|
253
|
+
*/
|
|
254
|
+
createRedirectResponse(url, res, status, statusText) {
|
|
255
|
+
const redirect = NextResponse.redirect(url, {
|
|
256
|
+
status,
|
|
257
|
+
statusText,
|
|
258
|
+
headers: res === null || res === void 0 ? void 0 : res.headers,
|
|
259
|
+
});
|
|
260
|
+
if (res === null || res === void 0 ? void 0 : res.headers) {
|
|
261
|
+
redirect.headers.delete('x-middleware-next');
|
|
262
|
+
redirect.headers.delete('x-middleware-rewrite');
|
|
263
|
+
}
|
|
264
|
+
return redirect;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
268
|
+
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
269
|
+
* @param {Object} params - The parameters for the URL match.
|
|
270
|
+
* @param {string} params.pathname - The current URL pathname.
|
|
271
|
+
* @param {string} params.queryString - The current URL query string.
|
|
272
|
+
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
273
|
+
* @param {string} [params.locale] - The locale prefix to include in the URL if present.
|
|
274
|
+
* @returns {string | undefined} - return query string if any of the query permutations match the provided pattern, undefined otherwise.
|
|
275
|
+
*/
|
|
276
|
+
isPermutedQueryMatch({ pathname, queryString, pattern, locale, }) {
|
|
277
|
+
const paramsArray = Array.from(new URLSearchParams(queryString).entries());
|
|
278
|
+
const listOfPermuted = getPermutations(paramsArray).map((permutation) => '?' + permutation.map(([key, value]) => `${key}=${value}`).join('&'));
|
|
279
|
+
const normalizedPath = pathname.replace(/\/*$/gi, '');
|
|
280
|
+
return listOfPermuted.find((query) => [
|
|
281
|
+
regexParser(pattern).test(`${normalizedPath}${query}`),
|
|
282
|
+
regexParser(pattern).test(`/${locale}${normalizedPath}${query}`),
|
|
283
|
+
].some(Boolean));
|
|
284
|
+
}
|
|
170
285
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.3.0-canary.2",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"url": "https://github.com/sitecore/jss/issues"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@sitecore-cloudsdk/
|
|
32
|
+
"@sitecore-cloudsdk/core": "^0.4.0",
|
|
33
|
+
"@sitecore-cloudsdk/personalize": "^0.4.0",
|
|
33
34
|
"@types/chai": "^4.3.4",
|
|
34
35
|
"@types/chai-as-promised": "^7.1.5",
|
|
35
36
|
"@types/chai-string": "^1.4.2",
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"eslint-plugin-react": "^7.32.1",
|
|
55
56
|
"jsdom": "^21.1.0",
|
|
56
57
|
"mocha": "^10.2.0",
|
|
57
|
-
"next": "^14.
|
|
58
|
+
"next": "^14.2.7",
|
|
58
59
|
"nock": "^13.3.0",
|
|
59
60
|
"nyc": "^15.1.0",
|
|
60
61
|
"react": "^18.2.0",
|
|
@@ -65,16 +66,16 @@
|
|
|
65
66
|
"typescript": "~4.9.4"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
|
-
"@sitecore-cloudsdk/
|
|
69
|
-
"@sitecore-cloudsdk/personalize": "^0.
|
|
70
|
-
"next": "^14.
|
|
69
|
+
"@sitecore-cloudsdk/core": "^0.4.0",
|
|
70
|
+
"@sitecore-cloudsdk/personalize": "^0.4.0",
|
|
71
|
+
"next": "^14.2.7",
|
|
71
72
|
"react": "^18.2.0",
|
|
72
73
|
"react-dom": "^18.2.0"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
75
|
-
"@sitecore-jss/sitecore-jss": "^22.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^22.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^22.
|
|
76
|
+
"@sitecore-jss/sitecore-jss": "^22.3.0-canary.2",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^22.3.0-canary.2",
|
|
78
|
+
"@sitecore-jss/sitecore-jss-react": "^22.3.0-canary.2",
|
|
78
79
|
"@vercel/kv": "^0.2.1",
|
|
79
80
|
"prop-types": "^15.8.1",
|
|
80
81
|
"regex-parser": "^2.2.11",
|
|
@@ -82,7 +83,7 @@
|
|
|
82
83
|
},
|
|
83
84
|
"description": "",
|
|
84
85
|
"types": "types/index.d.ts",
|
|
85
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "0065e93738024c2357c0e9b3fd1b1613f3bc3153",
|
|
86
87
|
"files": [
|
|
87
88
|
"dist",
|
|
88
89
|
"types",
|
|
@@ -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,6 +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
5
|
import { EditingDataService } from './editing-data-service';
|
|
5
6
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
6
7
|
/**
|
|
@@ -95,25 +96,11 @@ export declare class ChromesHandler extends RenderMiddlewareBase {
|
|
|
95
96
|
* Configuration for the Editing Metadata Handler.
|
|
96
97
|
*/
|
|
97
98
|
export type EditingRenderMiddlewareMetadataConfig = Pick<EditingRenderMiddlewareConfig, 'resolvePageUrl'>;
|
|
98
|
-
/**
|
|
99
|
-
* Query parameters appended to the page route URL
|
|
100
|
-
* Appended when XMCloud Pages preview (editing) Metadata Edit Mode is used
|
|
101
|
-
*/
|
|
102
|
-
export type MetadataQueryParams = {
|
|
103
|
-
secret: string;
|
|
104
|
-
sc_lang: string;
|
|
105
|
-
sc_itemid: string;
|
|
106
|
-
sc_site: string;
|
|
107
|
-
route: string;
|
|
108
|
-
mode: Exclude<LayoutServicePageState, 'normal'>;
|
|
109
|
-
sc_variant?: string;
|
|
110
|
-
sc_version?: string;
|
|
111
|
-
};
|
|
112
99
|
/**
|
|
113
100
|
* Next.js API request with Metadata query parameters.
|
|
114
101
|
*/
|
|
115
102
|
type MetadataNextApiRequest = NextApiRequest & {
|
|
116
|
-
query:
|
|
103
|
+
query: RenderMetadataQueryParams;
|
|
117
104
|
};
|
|
118
105
|
/**
|
|
119
106
|
* Data for Next.js Preview (Editing) Metadata Edit Mode.
|
|
@@ -126,6 +113,7 @@ export type EditingMetadataPreviewData = {
|
|
|
126
113
|
pageState: Exclude<LayoutServicePageState, 'Normal'>;
|
|
127
114
|
variantIds: string[];
|
|
128
115
|
version?: string;
|
|
116
|
+
layoutKind?: LayoutKind;
|
|
129
117
|
};
|
|
130
118
|
/**
|
|
131
119
|
* Type guard for EditingMetadataPreviewData
|
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { constants, HttpDataFetcher, HttpResponse, AxiosResponse, AxiosDataFetcher, AxiosDataFetcherConfig, NativeDataFetcher, NativeDataFetcherConfig, HTMLLink, enableDebug, debug, } from '@sitecore-jss/sitecore-jss';
|
|
1
|
+
export { constants, HttpDataFetcher, HttpResponse, AxiosResponse, AxiosDataFetcher, AxiosDataFetcherConfig, NativeDataFetcher, NativeDataFetcherConfig, HTMLLink, enableDebug, debug, CacheClient, CacheOptions, MemoryCacheClient, } from '@sitecore-jss/sitecore-jss';
|
|
2
2
|
export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, RestLayoutService, RestLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, getContentStylesheetLink, EditMode, } from '@sitecore-jss/sitecore-jss/layout';
|
|
3
3
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
4
4
|
export { trackingApi, TrackingRequestOptions, CampaignInstance, GoalInstance, OutcomeInstance, EventInstance, PageViewInstance, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
@@ -22,5 +22,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
22
22
|
export { FEaaSWrapper };
|
|
23
23
|
export { BYOCWrapper };
|
|
24
24
|
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
|
25
|
-
export { Context, ContextConfig, SDK } from './context';
|
|
26
25
|
export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getComponentLibraryStylesheetLinks, File, FileField, RichTextField, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, WithSitecoreContextOptions, WithSitecoreContextProps, WithSitecoreContextHocProps, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { debug } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
export { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
2
3
|
export { RedirectsMiddleware, RedirectsMiddlewareConfig } from './redirects-middleware';
|
|
3
4
|
export { PersonalizeMiddleware, PersonalizeMiddlewareConfig } from './personalize-middleware';
|
|
4
5
|
export { MultisiteMiddleware, MultisiteMiddlewareConfig } from './multisite-middleware';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NextResponse, NextRequest } from 'next/server';
|
|
2
1
|
import { GraphQLRedirectsServiceConfig } from '@sitecore-jss/sitecore-jss/site';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
4
4
|
/**
|
|
5
5
|
* extended RedirectsMiddlewareConfig config type for RedirectsMiddleware
|
|
@@ -37,4 +37,32 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
|
37
37
|
* @private
|
|
38
38
|
*/
|
|
39
39
|
private getExistsRedirect;
|
|
40
|
+
/**
|
|
41
|
+
* When a user clicks on a link generated by the Link component from next/link,
|
|
42
|
+
* Next.js adds special parameters in the route called path.
|
|
43
|
+
* This method removes these special parameters.
|
|
44
|
+
* @param {NextURL} url
|
|
45
|
+
* @returns {string} normalize url
|
|
46
|
+
*/
|
|
47
|
+
private normalizeUrl;
|
|
48
|
+
/**
|
|
49
|
+
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
50
|
+
* @param {NextURL} url The URL to redirect to.
|
|
51
|
+
* @param {Response} res The response object.
|
|
52
|
+
* @param {number} status The HTTP status code of the redirect.
|
|
53
|
+
* @param {string} statusText The status text of the redirect.
|
|
54
|
+
* @returns {NextResponse<unknown>} The redirect response.
|
|
55
|
+
*/
|
|
56
|
+
private createRedirectResponse;
|
|
57
|
+
/**
|
|
58
|
+
* Checks if the current URL query matches the provided pattern, considering all permutations of query parameters.
|
|
59
|
+
* It constructs all possible query parameter permutations and tests them against the pattern.
|
|
60
|
+
* @param {Object} params - The parameters for the URL match.
|
|
61
|
+
* @param {string} params.pathname - The current URL pathname.
|
|
62
|
+
* @param {string} params.queryString - The current URL query string.
|
|
63
|
+
* @param {string} params.pattern - The regex pattern to test the constructed URLs against.
|
|
64
|
+
* @param {string} [params.locale] - The locale prefix to include in the URL if present.
|
|
65
|
+
* @returns {string | undefined} - return query string if any of the query permutations match the provided pattern, undefined otherwise.
|
|
66
|
+
*/
|
|
67
|
+
private isPermutedQueryMatch;
|
|
40
68
|
}
|
package/context.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './types/context/index';
|
package/context.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/cjs/context/index');
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Context = void 0;
|
|
4
|
-
const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
5
|
-
/**
|
|
6
|
-
* Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
|
|
7
|
-
*/
|
|
8
|
-
class Context {
|
|
9
|
-
constructor(props) {
|
|
10
|
-
this.props = props;
|
|
11
|
-
/**
|
|
12
|
-
* Indicates whether the Context and SDK(s) have been initialized
|
|
13
|
-
*/
|
|
14
|
-
this.isInitialized = false;
|
|
15
|
-
/**
|
|
16
|
-
* Software Development Kits (SDKs) to be initialized
|
|
17
|
-
*/
|
|
18
|
-
this.sdks = {};
|
|
19
|
-
/**
|
|
20
|
-
* Promises for the SDKs
|
|
21
|
-
*/
|
|
22
|
-
this.sdkPromises = {};
|
|
23
|
-
this.sdkErrors = {};
|
|
24
|
-
/**
|
|
25
|
-
* Retrieves the Software Development Kit (SDK) instance, ensuring it is initialized before returning
|
|
26
|
-
*
|
|
27
|
-
* @param {string} name SDK name
|
|
28
|
-
* @returns initialized SDK
|
|
29
|
-
*/
|
|
30
|
-
this.getSDK = (name) => {
|
|
31
|
-
if (!this.sdkPromises[name]) {
|
|
32
|
-
return Promise.reject(`Unknown SDK '${String(name)}'`);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return this.sdkPromises[name].then((result) => {
|
|
36
|
-
return ((this.sdkErrors[name] && Promise.reject(this.sdkErrors[name])) || Promise.resolve(result));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
this.sitecoreEdgeUrl = props.sitecoreEdgeUrl;
|
|
41
|
-
this.sitecoreEdgeContextId = props.sitecoreEdgeContextId;
|
|
42
|
-
this.siteName = props.siteName;
|
|
43
|
-
this.pageState = sitecore_jss_react_1.LayoutServicePageState.Normal;
|
|
44
|
-
}
|
|
45
|
-
init(props = {}) {
|
|
46
|
-
// Context and SDKs are initialized only once
|
|
47
|
-
if (this.isInitialized)
|
|
48
|
-
return;
|
|
49
|
-
this.isInitialized = true;
|
|
50
|
-
if (props.siteName) {
|
|
51
|
-
this.siteName = props.siteName;
|
|
52
|
-
}
|
|
53
|
-
if (props.pageState) {
|
|
54
|
-
this.pageState = props.pageState;
|
|
55
|
-
}
|
|
56
|
-
// iterate over the SDKs and initialize them
|
|
57
|
-
for (const sdkName of Object.keys(this.props.sdks)) {
|
|
58
|
-
this.initSDK(sdkName);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Initializes the Software Development Kit (SDK)
|
|
63
|
-
*
|
|
64
|
-
* @param {T} name SDK name
|
|
65
|
-
* @returns {void}
|
|
66
|
-
*/
|
|
67
|
-
initSDK(name) {
|
|
68
|
-
this.sdkPromises[name] = new Promise((resolve) => {
|
|
69
|
-
this.props.sdks[name]
|
|
70
|
-
.init(this)
|
|
71
|
-
.then(() => {
|
|
72
|
-
this.sdks[name] = this.props.sdks[name].sdk;
|
|
73
|
-
resolve(this.sdks[name]);
|
|
74
|
-
})
|
|
75
|
-
.catch((e) => {
|
|
76
|
-
// if init rejects, we mark SDK as failed - so getSDK call would reject with a reason
|
|
77
|
-
this.sdkErrors[name] = e;
|
|
78
|
-
resolve(undefined);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.Context = Context;
|