@sitecore-jss/sitecore-jss-nextjs 22.6.0-canary.4 → 22.6.0-canary.40

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.
@@ -67,14 +67,16 @@ exports.Link = (0, react_1.forwardRef)((props, ref) => {
67
67
  const isFileUrl = FILE_EXTENSION_MATCHER.test(href);
68
68
  // determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
69
69
  if (isMatching && !isFileUrl) {
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 }),
70
+ delete htmlLinkProps.emptyFieldEditingComponent;
71
+ 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, prefetch: props.prefetch }, htmlLinkProps, { ref: ref }),
71
72
  text,
72
73
  children));
73
74
  }
74
75
  }
75
- // prevent passing internalLinkMatcher as it is an invalid DOM element prop
76
+ // prevent passing internalLinkMatcher or prefetch as it is an invalid DOM element prop
76
77
  const reactLinkProps = Object.assign({}, props);
77
78
  delete reactLinkProps.internalLinkMatcher;
79
+ delete reactLinkProps.prefetch;
78
80
  return react_1.default.createElement(sitecore_jss_react_1.Link, Object.assign({}, reactLinkProps, { ref: ref }));
79
81
  });
80
82
  exports.Link.displayName = 'NextLink';
@@ -37,12 +37,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.RichText = void 0;
40
+ exports.RichText = exports.prefetched = void 0;
41
41
  const react_1 = __importStar(require("react"));
42
42
  const prop_types_1 = __importDefault(require("prop-types"));
43
43
  const router_1 = require("next/router");
44
44
  const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
45
- const prefetched = {};
45
+ exports.prefetched = {};
46
46
  const RichText = (props) => {
47
47
  const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true, editable = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks", "editable"]);
48
48
  const hasText = props.field && props.field.value;
@@ -50,7 +50,7 @@ const RichText = (props) => {
50
50
  const router = (0, router_1.useRouter)();
51
51
  const richTextRef = (0, react_1.useRef)(null);
52
52
  (0, react_1.useEffect)(() => {
53
- // NOT IN EXPERIENCE EDITOR
53
+ // NOT IN EDIT MODE
54
54
  if (hasText && !isEditing) {
55
55
  initializeLinks();
56
56
  }
@@ -71,9 +71,21 @@ const RichText = (props) => {
71
71
  internalLinks.forEach((link) => {
72
72
  if (link.target === '_blank')
73
73
  return;
74
- if (prefetchLinks && !prefetched[link.pathname]) {
74
+ const prefetch = () => {
75
75
  router.prefetch(link.pathname, undefined, { locale: false });
76
- prefetched[link.pathname] = true;
76
+ exports.prefetched[link.pathname] = true;
77
+ };
78
+ if (!exports.prefetched[link.pathname] && prefetchLinks !== false) {
79
+ if (prefetchLinks === true) {
80
+ prefetch();
81
+ }
82
+ if (prefetchLinks === 'hover') {
83
+ const mouseOverHandler = () => {
84
+ prefetch();
85
+ link.removeEventListener('mouseover', mouseOverHandler);
86
+ };
87
+ link.addEventListener('mouseover', mouseOverHandler, false);
88
+ }
77
89
  }
78
90
  link.addEventListener('click', routeHandler, false);
79
91
  });
@@ -108,7 +108,13 @@ class ServerlessEditingDataService {
108
108
  params,
109
109
  };
110
110
  sitecore_jss_1.debug.editing('storing editing data for %o: %o', previewData, data);
111
- return this.dataFetcher.put(url, data).then(() => {
111
+ return this.dataFetcher
112
+ .put(url, data, {
113
+ headers: {
114
+ 'Content-Type': 'application/json',
115
+ },
116
+ })
117
+ .then(() => {
112
118
  return previewData;
113
119
  });
114
120
  });
package/dist/cjs/index.js CHANGED
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.fetchFEaaSComponentServerProps = 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.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.File = exports.getComponentLibraryStylesheetLinks = exports.BYOCComponent = void 0;
26
+ exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.Form = 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.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.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
30
  Object.defineProperty(exports, "NativeDataFetcher", { enumerable: true, get: function () { return sitecore_jss_1.NativeDataFetcher; } });
@@ -89,6 +89,7 @@ exports.BYOCWrapper = BYOCWrapper;
89
89
  var ComponentBuilder_1 = require("./ComponentBuilder");
90
90
  Object.defineProperty(exports, "ComponentBuilder", { enumerable: true, get: function () { return ComponentBuilder_1.ComponentBuilder; } });
91
91
  var sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
92
+ Object.defineProperty(exports, "Form", { enumerable: true, get: function () { return sitecore_jss_react_1.Form; } });
92
93
  Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return sitecore_jss_react_1.Image; } });
93
94
  Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return sitecore_jss_react_1.Text; } });
94
95
  Object.defineProperty(exports, "DateField", { enumerable: true, get: function () { return sitecore_jss_react_1.DateField; } });
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MiddlewareBase = void 0;
3
+ exports.MiddlewareBase = exports.REWRITE_HEADER_NAME = void 0;
4
4
  const server_1 = require("next/server");
5
+ exports.REWRITE_HEADER_NAME = 'x-sc-rewrite';
5
6
  class MiddlewareBase {
6
7
  constructor(config) {
7
8
  this.config = config;
8
9
  this.SITE_SYMBOL = 'sc_site';
9
- this.REWRITE_HEADER_NAME = 'x-sc-rewrite';
10
10
  this.defaultHostname = config.defaultHostname || 'localhost';
11
11
  }
12
12
  /**
@@ -84,14 +84,17 @@ class MiddlewareBase {
84
84
  * @param {string} rewritePath the destionation path
85
85
  * @param {NextRequest} req the current request
86
86
  * @param {NextResponse} res the current response
87
+ * @param {boolean} [skipHeader] don't write 'x-sc-rewrite' header
87
88
  */
88
- rewrite(rewritePath, req, res) {
89
+ rewrite(rewritePath, req, res, skipHeader) {
89
90
  // Note an absolute URL is required: https://nextjs.org/docs/messages/middleware-relative-urls
90
91
  const rewriteUrl = req.nextUrl.clone();
91
92
  rewriteUrl.pathname = rewritePath;
92
93
  const response = server_1.NextResponse.rewrite(rewriteUrl, res);
93
94
  // Share rewrite path with following executed middlewares
94
- response.headers.set(this.REWRITE_HEADER_NAME, rewritePath);
95
+ if (!skipHeader) {
96
+ response.headers.set(exports.REWRITE_HEADER_NAME, rewritePath);
97
+ }
95
98
  return response;
96
99
  }
97
100
  }
@@ -102,7 +102,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
102
102
  return response;
103
103
  }
104
104
  // Path can be rewritten by previously executed middleware
105
- const basePath = (res === null || res === void 0 ? void 0 : res.headers.get('x-sc-rewrite')) || pathname;
105
+ const basePath = (res === null || res === void 0 ? void 0 : res.headers.get(middleware_1.REWRITE_HEADER_NAME)) || pathname;
106
106
  // Rewrite to persononalized path
107
107
  const rewritePath = (0, personalize_1.getPersonalizedRewrite)(basePath, identifiedVariantIds);
108
108
  response = this.rewrite(rewritePath, req, response);
@@ -32,7 +32,97 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
32
32
  constructor(config) {
33
33
  super(config);
34
34
  this.config = config;
35
- this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
35
+ // NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
36
+ // (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
37
+ this.redirectsService = new site_1.GraphQLRedirectsService(Object.assign(Object.assign({}, config), { fetch: fetch }));
38
+ this.locales = config.locales;
39
+ }
40
+ /**
41
+ * Gets the Next.js middleware handler with error handling
42
+ * @returns route handler
43
+ */
44
+ getHandler() {
45
+ return (req, res) => __awaiter(this, void 0, void 0, function* () {
46
+ try {
47
+ return this.processRedirectRequest(req, res);
48
+ }
49
+ catch (error) {
50
+ console.log('Redirect middleware failed:');
51
+ console.log(error);
52
+ return res || server_1.NextResponse.next();
53
+ }
54
+ });
55
+ }
56
+ /**
57
+ * Method returns RedirectInfo when matches
58
+ * @param {NextRequest} req request
59
+ * @param {string} siteName site name
60
+ * @returns Promise<RedirectInfo | undefined> The redirect info or undefined if no redirect is found
61
+ * @protected
62
+ */
63
+ getExistsRedirect(req, siteName) {
64
+ return __awaiter(this, void 0, void 0, function* () {
65
+ const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
66
+ const locale = this.getLanguage(req);
67
+ const normalizedPath = incomingURL.replace(/\/*$/gi, '');
68
+ const redirects = yield this.redirectsService.fetchRedirects(siteName);
69
+ const language = this.getLanguage(req);
70
+ const modifyRedirects = structuredClone(redirects);
71
+ let matchedQueryString;
72
+ const localePath = `/${locale.toLowerCase()}${normalizedPath}`;
73
+ return modifyRedirects.length
74
+ ? modifyRedirects.find((redirect) => {
75
+ // process static URL (non-regex) rules
76
+ if ((0, utils_1.isRegexOrUrl)(redirect.pattern) === 'url') {
77
+ const urlArray = redirect.pattern.endsWith('/')
78
+ ? redirect.pattern.slice(0, -1).split('?')
79
+ : redirect.pattern.split('?');
80
+ const patternQS = urlArray[1];
81
+ let patternPath = urlArray[0];
82
+ // nextjs routes are case-sensitive, but locales should be compared case-insensitively
83
+ const patternParts = patternPath.split('/');
84
+ const maybeLocale = patternParts[1].toLowerCase();
85
+ // case insensitive lookup of locales
86
+ if (new RegExp(this.locales.join('|'), 'i').test(maybeLocale)) {
87
+ patternPath = patternPath.replace(`/${patternParts[1]}`, `/${maybeLocale}`);
88
+ }
89
+ return ((patternPath === localePath || patternPath === normalizedPath) &&
90
+ (!patternQS ||
91
+ (0, utils_1.areURLSearchParamsEqual)(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
92
+ }
93
+ // process regex rules
94
+ // Modify the redirect pattern to ignore the language prefix in the path
95
+ // And escapes non-special "?" characters in a string or regex.
96
+ redirect.pattern = (0, utils_1.escapeNonSpecialQuestionMarks)(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
97
+ // Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
98
+ redirect.pattern = `/^\/${redirect.pattern
99
+ .replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
100
+ .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
101
+ .replace(/^\^|\$$/g, '') // Further cleans up anchors
102
+ .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
103
+ // Redirect pattern matches the full incoming URL with query string present
104
+ matchedQueryString = [
105
+ (0, regex_parser_1.default)(redirect.pattern).test(`${localePath}${incomingQS}`),
106
+ (0, regex_parser_1.default)(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
107
+ ].some(Boolean)
108
+ ? incomingQS
109
+ : undefined;
110
+ // Save the matched query string (if found) into the redirect object
111
+ redirect.matchedQueryString = matchedQueryString || '';
112
+ return (!!((0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
113
+ (0, regex_parser_1.default)(redirect.pattern).test(incomingURL) ||
114
+ matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
115
+ })
116
+ : undefined;
117
+ });
118
+ }
119
+ /**
120
+ * @param {NextRequest} req request
121
+ * @param {Response} res response
122
+ * @returns {Promise<NextResponse>} The redirect response.
123
+ */
124
+ processRedirectRequest(req, res) {
125
+ return __awaiter(this, void 0, void 0, function* () {
36
126
  const pathname = req.nextUrl.pathname;
37
127
  const language = this.getLanguage(req);
38
128
  const hostname = this.getHostHeader(req) || this.defaultHostname;
@@ -68,6 +158,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
68
158
  sitecore_jss_1.debug.redirects('skipped (redirect does not exist)');
69
159
  return response;
70
160
  }
161
+ sitecore_jss_1.debug.redirects('Matched redirect rule: %o', { existsRedirect });
71
162
  // Find context site language and replace token
72
163
  if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
73
164
  !(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
@@ -114,7 +205,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
114
205
  return this.createRedirectResponse(url, response, 302, 'Found');
115
206
  }
116
207
  case site_1.REDIRECT_TYPE_SERVER_TRANSFER: {
117
- return this.rewrite(url.href, req, response);
208
+ return this.rewrite(url.href, req, response, true);
118
209
  }
119
210
  default:
120
211
  return response;
@@ -129,76 +220,6 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
129
220
  });
130
221
  return response;
131
222
  });
132
- // NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
133
- // (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
134
- this.redirectsService = new site_1.GraphQLRedirectsService(Object.assign(Object.assign({}, config), { fetch: fetch }));
135
- this.locales = config.locales;
136
- }
137
- /**
138
- * Gets the Next.js middleware handler with error handling
139
- * @returns route handler
140
- */
141
- getHandler() {
142
- return (req, res) => __awaiter(this, void 0, void 0, function* () {
143
- try {
144
- return yield this.handler(req, res);
145
- }
146
- catch (error) {
147
- console.log('Redirect middleware failed:');
148
- console.log(error);
149
- return res || server_1.NextResponse.next();
150
- }
151
- });
152
- }
153
- /**
154
- * Method returns RedirectInfo when matches
155
- * @param {NextRequest} req request
156
- * @param {string} siteName site name
157
- * @returns Promise<RedirectInfo | undefined>
158
- * @private
159
- */
160
- getExistsRedirect(req, siteName) {
161
- return __awaiter(this, void 0, void 0, function* () {
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);
165
- const language = this.getLanguage(req);
166
- const modifyRedirects = structuredClone(redirects);
167
- let matchedQueryString;
168
- return modifyRedirects.length
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
- }
179
- // Modify the redirect pattern to ignore the language prefix in the path
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'), ''));
182
- // Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
183
- redirect.pattern = `/^\/${redirect.pattern
184
- .replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
185
- .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
186
- .replace(/^\^|\$$/g, '') // Further cleans up anchors
187
- .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
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;
194
- // Save the matched query string (if found) into the redirect object
195
- redirect.matchedQueryString = matchedQueryString || '';
196
- return (!!((0, regex_parser_1.default)(redirect.pattern).test(targetURL) ||
197
- (0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
198
- matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
199
- })
200
- : undefined;
201
- });
202
223
  }
203
224
  /**
204
225
  * When a user clicks on a link generated by the Link component from next/link,
@@ -234,9 +255,9 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
234
255
  return false;
235
256
  })
236
257
  .join('&');
237
- const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
258
+ const newUrl = new URL(`${url.pathname.toLowerCase()}?${newQueryString}`, url.origin);
238
259
  url.search = newUrl.search;
239
- url.pathname = newUrl.pathname;
260
+ url.pathname = newUrl.pathname.toLowerCase();
240
261
  url.href = newUrl.href;
241
262
  return url;
242
263
  }
@@ -257,6 +278,7 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
257
278
  if (res === null || res === void 0 ? void 0 : res.headers) {
258
279
  redirect.headers.delete('x-middleware-next');
259
280
  redirect.headers.delete('x-middleware-rewrite');
281
+ redirect.headers.delete(middleware_1.REWRITE_HEADER_NAME);
260
282
  }
261
283
  return redirect;
262
284
  }
@@ -38,14 +38,16 @@ export const Link = forwardRef((props, ref) => {
38
38
  const isFileUrl = FILE_EXTENSION_MATCHER.test(href);
39
39
  // determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
40
40
  if (isMatching && !isFileUrl) {
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 }),
41
+ delete htmlLinkProps.emptyFieldEditingComponent;
42
+ 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, prefetch: props.prefetch }, htmlLinkProps, { ref: ref }),
42
43
  text,
43
44
  children));
44
45
  }
45
46
  }
46
- // prevent passing internalLinkMatcher as it is an invalid DOM element prop
47
+ // prevent passing internalLinkMatcher or prefetch as it is an invalid DOM element prop
47
48
  const reactLinkProps = Object.assign({}, props);
48
49
  delete reactLinkProps.internalLinkMatcher;
50
+ delete reactLinkProps.prefetch;
49
51
  return React.createElement(ReactLink, Object.assign({}, reactLinkProps, { ref: ref }));
50
52
  });
51
53
  Link.displayName = 'NextLink';
@@ -13,7 +13,7 @@ import React, { useEffect, useRef } from 'react';
13
13
  import PropTypes from 'prop-types';
14
14
  import { useRouter } from 'next/router';
15
15
  import { RichText as ReactRichText, RichTextPropTypes, } from '@sitecore-jss/sitecore-jss-react';
16
- const prefetched = {};
16
+ export const prefetched = {};
17
17
  export const RichText = (props) => {
18
18
  const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true, editable = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks", "editable"]);
19
19
  const hasText = props.field && props.field.value;
@@ -21,7 +21,7 @@ export const RichText = (props) => {
21
21
  const router = useRouter();
22
22
  const richTextRef = useRef(null);
23
23
  useEffect(() => {
24
- // NOT IN EXPERIENCE EDITOR
24
+ // NOT IN EDIT MODE
25
25
  if (hasText && !isEditing) {
26
26
  initializeLinks();
27
27
  }
@@ -42,9 +42,21 @@ export const RichText = (props) => {
42
42
  internalLinks.forEach((link) => {
43
43
  if (link.target === '_blank')
44
44
  return;
45
- if (prefetchLinks && !prefetched[link.pathname]) {
45
+ const prefetch = () => {
46
46
  router.prefetch(link.pathname, undefined, { locale: false });
47
47
  prefetched[link.pathname] = true;
48
+ };
49
+ if (!prefetched[link.pathname] && prefetchLinks !== false) {
50
+ if (prefetchLinks === true) {
51
+ prefetch();
52
+ }
53
+ if (prefetchLinks === 'hover') {
54
+ const mouseOverHandler = () => {
55
+ prefetch();
56
+ link.removeEventListener('mouseover', mouseOverHandler);
57
+ };
58
+ link.addEventListener('mouseover', mouseOverHandler, false);
59
+ }
48
60
  }
49
61
  link.addEventListener('click', routeHandler, false);
50
62
  });
@@ -103,7 +103,13 @@ export class ServerlessEditingDataService {
103
103
  params,
104
104
  };
105
105
  debug.editing('storing editing data for %o: %o', previewData, data);
106
- return this.dataFetcher.put(url, data).then(() => {
106
+ return this.dataFetcher
107
+ .put(url, data, {
108
+ headers: {
109
+ 'Content-Type': 'application/json',
110
+ },
111
+ })
112
+ .then(() => {
107
113
  return previewData;
108
114
  });
109
115
  });
package/dist/esm/index.js CHANGED
@@ -19,4 +19,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
19
19
  export { FEaaSWrapper };
20
20
  export { BYOCWrapper };
21
21
  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';
22
+ export { Form, 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,9 +1,9 @@
1
1
  import { NextResponse } from 'next/server';
2
+ export const REWRITE_HEADER_NAME = 'x-sc-rewrite';
2
3
  export class MiddlewareBase {
3
4
  constructor(config) {
4
5
  this.config = config;
5
6
  this.SITE_SYMBOL = 'sc_site';
6
- this.REWRITE_HEADER_NAME = 'x-sc-rewrite';
7
7
  this.defaultHostname = config.defaultHostname || 'localhost';
8
8
  }
9
9
  /**
@@ -81,14 +81,17 @@ export class MiddlewareBase {
81
81
  * @param {string} rewritePath the destionation path
82
82
  * @param {NextRequest} req the current request
83
83
  * @param {NextResponse} res the current response
84
+ * @param {boolean} [skipHeader] don't write 'x-sc-rewrite' header
84
85
  */
85
- rewrite(rewritePath, req, res) {
86
+ rewrite(rewritePath, req, res, skipHeader) {
86
87
  // Note an absolute URL is required: https://nextjs.org/docs/messages/middleware-relative-urls
87
88
  const rewriteUrl = req.nextUrl.clone();
88
89
  rewriteUrl.pathname = rewritePath;
89
90
  const response = NextResponse.rewrite(rewriteUrl, res);
90
91
  // Share rewrite path with following executed middlewares
91
- response.headers.set(this.REWRITE_HEADER_NAME, rewritePath);
92
+ if (!skipHeader) {
93
+ response.headers.set(REWRITE_HEADER_NAME, rewritePath);
94
+ }
92
95
  return response;
93
96
  }
94
97
  }
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  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
- import { MiddlewareBase } from './middleware';
13
+ import { MiddlewareBase, REWRITE_HEADER_NAME } from './middleware';
14
14
  import { CloudSDK } from '@sitecore-cloudsdk/core/server';
15
15
  import { personalize } from '@sitecore-cloudsdk/personalize/server';
16
16
  /**
@@ -99,7 +99,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
99
99
  return response;
100
100
  }
101
101
  // Path can be rewritten by previously executed middleware
102
- const basePath = (res === null || res === void 0 ? void 0 : res.headers.get('x-sc-rewrite')) || pathname;
102
+ const basePath = (res === null || res === void 0 ? void 0 : res.headers.get(REWRITE_HEADER_NAME)) || pathname;
103
103
  // Rewrite to persononalized path
104
104
  const rewritePath = getPersonalizedRewrite(basePath, identifiedVariantIds);
105
105
  response = this.rewrite(rewritePath, req, response);
@@ -12,7 +12,7 @@ import { GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT
12
12
  import { areURLSearchParamsEqual, escapeNonSpecialQuestionMarks, isRegexOrUrl, mergeURLSearchParams, } from '@sitecore-jss/sitecore-jss/utils';
13
13
  import { NextResponse } from 'next/server';
14
14
  import regexParser from 'regex-parser';
15
- import { MiddlewareBase } from './middleware';
15
+ import { MiddlewareBase, REWRITE_HEADER_NAME } from './middleware';
16
16
  const REGEXP_CONTEXT_SITE_LANG = new RegExp(/\$siteLang/, 'i');
17
17
  const REGEXP_ABSOLUTE_URL = new RegExp('^(?:[a-z]+:)?//', 'i');
18
18
  /**
@@ -26,7 +26,97 @@ export class RedirectsMiddleware extends MiddlewareBase {
26
26
  constructor(config) {
27
27
  super(config);
28
28
  this.config = config;
29
- this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
29
+ // NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
30
+ // (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
31
+ this.redirectsService = new GraphQLRedirectsService(Object.assign(Object.assign({}, config), { fetch: fetch }));
32
+ this.locales = config.locales;
33
+ }
34
+ /**
35
+ * Gets the Next.js middleware handler with error handling
36
+ * @returns route handler
37
+ */
38
+ getHandler() {
39
+ return (req, res) => __awaiter(this, void 0, void 0, function* () {
40
+ try {
41
+ return this.processRedirectRequest(req, res);
42
+ }
43
+ catch (error) {
44
+ console.log('Redirect middleware failed:');
45
+ console.log(error);
46
+ return res || NextResponse.next();
47
+ }
48
+ });
49
+ }
50
+ /**
51
+ * Method returns RedirectInfo when matches
52
+ * @param {NextRequest} req request
53
+ * @param {string} siteName site name
54
+ * @returns Promise<RedirectInfo | undefined> The redirect info or undefined if no redirect is found
55
+ * @protected
56
+ */
57
+ getExistsRedirect(req, siteName) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
60
+ const locale = this.getLanguage(req);
61
+ const normalizedPath = incomingURL.replace(/\/*$/gi, '');
62
+ const redirects = yield this.redirectsService.fetchRedirects(siteName);
63
+ const language = this.getLanguage(req);
64
+ const modifyRedirects = structuredClone(redirects);
65
+ let matchedQueryString;
66
+ const localePath = `/${locale.toLowerCase()}${normalizedPath}`;
67
+ return modifyRedirects.length
68
+ ? modifyRedirects.find((redirect) => {
69
+ // process static URL (non-regex) rules
70
+ if (isRegexOrUrl(redirect.pattern) === 'url') {
71
+ const urlArray = redirect.pattern.endsWith('/')
72
+ ? redirect.pattern.slice(0, -1).split('?')
73
+ : redirect.pattern.split('?');
74
+ const patternQS = urlArray[1];
75
+ let patternPath = urlArray[0];
76
+ // nextjs routes are case-sensitive, but locales should be compared case-insensitively
77
+ const patternParts = patternPath.split('/');
78
+ const maybeLocale = patternParts[1].toLowerCase();
79
+ // case insensitive lookup of locales
80
+ if (new RegExp(this.locales.join('|'), 'i').test(maybeLocale)) {
81
+ patternPath = patternPath.replace(`/${patternParts[1]}`, `/${maybeLocale}`);
82
+ }
83
+ return ((patternPath === localePath || patternPath === normalizedPath) &&
84
+ (!patternQS ||
85
+ areURLSearchParamsEqual(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
86
+ }
87
+ // process regex rules
88
+ // Modify the redirect pattern to ignore the language prefix in the path
89
+ // And escapes non-special "?" characters in a string or regex.
90
+ redirect.pattern = escapeNonSpecialQuestionMarks(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
91
+ // Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
92
+ redirect.pattern = `/^\/${redirect.pattern
93
+ .replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
94
+ .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
95
+ .replace(/^\^|\$$/g, '') // Further cleans up anchors
96
+ .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
97
+ // Redirect pattern matches the full incoming URL with query string present
98
+ matchedQueryString = [
99
+ regexParser(redirect.pattern).test(`${localePath}${incomingQS}`),
100
+ regexParser(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
101
+ ].some(Boolean)
102
+ ? incomingQS
103
+ : undefined;
104
+ // Save the matched query string (if found) into the redirect object
105
+ redirect.matchedQueryString = matchedQueryString || '';
106
+ return (!!(regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
107
+ regexParser(redirect.pattern).test(incomingURL) ||
108
+ matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
109
+ })
110
+ : undefined;
111
+ });
112
+ }
113
+ /**
114
+ * @param {NextRequest} req request
115
+ * @param {Response} res response
116
+ * @returns {Promise<NextResponse>} The redirect response.
117
+ */
118
+ processRedirectRequest(req, res) {
119
+ return __awaiter(this, void 0, void 0, function* () {
30
120
  const pathname = req.nextUrl.pathname;
31
121
  const language = this.getLanguage(req);
32
122
  const hostname = this.getHostHeader(req) || this.defaultHostname;
@@ -62,6 +152,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
62
152
  debug.redirects('skipped (redirect does not exist)');
63
153
  return response;
64
154
  }
155
+ debug.redirects('Matched redirect rule: %o', { existsRedirect });
65
156
  // Find context site language and replace token
66
157
  if (REGEXP_CONTEXT_SITE_LANG.test(existsRedirect.target) &&
67
158
  !(REGEXP_ABSOLUTE_URL.test(existsRedirect.target) &&
@@ -108,7 +199,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
108
199
  return this.createRedirectResponse(url, response, 302, 'Found');
109
200
  }
110
201
  case REDIRECT_TYPE_SERVER_TRANSFER: {
111
- return this.rewrite(url.href, req, response);
202
+ return this.rewrite(url.href, req, response, true);
112
203
  }
113
204
  default:
114
205
  return response;
@@ -123,76 +214,6 @@ export class RedirectsMiddleware extends MiddlewareBase {
123
214
  });
124
215
  return response;
125
216
  });
126
- // NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
127
- // (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
128
- this.redirectsService = new GraphQLRedirectsService(Object.assign(Object.assign({}, config), { fetch: fetch }));
129
- this.locales = config.locales;
130
- }
131
- /**
132
- * Gets the Next.js middleware handler with error handling
133
- * @returns route handler
134
- */
135
- getHandler() {
136
- return (req, res) => __awaiter(this, void 0, void 0, function* () {
137
- try {
138
- return yield this.handler(req, res);
139
- }
140
- catch (error) {
141
- console.log('Redirect middleware failed:');
142
- console.log(error);
143
- return res || NextResponse.next();
144
- }
145
- });
146
- }
147
- /**
148
- * Method returns RedirectInfo when matches
149
- * @param {NextRequest} req request
150
- * @param {string} siteName site name
151
- * @returns Promise<RedirectInfo | undefined>
152
- * @private
153
- */
154
- getExistsRedirect(req, siteName) {
155
- return __awaiter(this, void 0, void 0, function* () {
156
- const { pathname: targetURL, search: targetQS = '', locale } = this.normalizeUrl(req.nextUrl.clone());
157
- const normalizedPath = targetURL.replace(/\/*$/gi, '');
158
- const redirects = yield this.redirectsService.fetchRedirects(siteName);
159
- const language = this.getLanguage(req);
160
- const modifyRedirects = structuredClone(redirects);
161
- let matchedQueryString;
162
- return modifyRedirects.length
163
- ? modifyRedirects.find((redirect) => {
164
- var _a;
165
- if (isRegexOrUrl(redirect.pattern) === 'url') {
166
- const parseUrlPattern = redirect.pattern.endsWith('/')
167
- ? redirect.pattern.slice(0, -1).split('?')
168
- : redirect.pattern.split('?');
169
- return ((parseUrlPattern[0] === normalizedPath ||
170
- parseUrlPattern[0] === `/${locale}${normalizedPath}`) &&
171
- areURLSearchParamsEqual(new URLSearchParams((_a = parseUrlPattern[1]) !== null && _a !== void 0 ? _a : ''), new URLSearchParams(targetQS)));
172
- }
173
- // Modify the redirect pattern to ignore the language prefix in the path
174
- // And escapes non-special "?" characters in a string or regex.
175
- redirect.pattern = escapeNonSpecialQuestionMarks(redirect.pattern.replace(new RegExp(`^[^]?/${language}/`, 'gi'), ''));
176
- // Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
177
- redirect.pattern = `/^\/${redirect.pattern
178
- .replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
179
- .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
180
- .replace(/^\^|\$$/g, '') // Further cleans up anchors
181
- .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
182
- matchedQueryString = [
183
- regexParser(redirect.pattern).test(`${normalizedPath}${targetQS}`),
184
- regexParser(redirect.pattern).test(`/${locale}${normalizedPath}${targetQS}`),
185
- ].some(Boolean)
186
- ? targetQS
187
- : undefined;
188
- // Save the matched query string (if found) into the redirect object
189
- redirect.matchedQueryString = matchedQueryString || '';
190
- return (!!(regexParser(redirect.pattern).test(targetURL) ||
191
- regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${targetURL}`) ||
192
- matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
193
- })
194
- : undefined;
195
- });
196
217
  }
197
218
  /**
198
219
  * When a user clicks on a link generated by the Link component from next/link,
@@ -228,9 +249,9 @@ export class RedirectsMiddleware extends MiddlewareBase {
228
249
  return false;
229
250
  })
230
251
  .join('&');
231
- const newUrl = new URL(`${url.pathname}?${newQueryString}`, url.origin);
252
+ const newUrl = new URL(`${url.pathname.toLowerCase()}?${newQueryString}`, url.origin);
232
253
  url.search = newUrl.search;
233
- url.pathname = newUrl.pathname;
254
+ url.pathname = newUrl.pathname.toLowerCase();
234
255
  url.href = newUrl.href;
235
256
  return url;
236
257
  }
@@ -251,6 +272,7 @@ export class RedirectsMiddleware extends MiddlewareBase {
251
272
  if (res === null || res === void 0 ? void 0 : res.headers) {
252
273
  redirect.headers.delete('x-middleware-next');
253
274
  redirect.headers.delete('x-middleware-rewrite');
275
+ redirect.headers.delete(REWRITE_HEADER_NAME);
254
276
  }
255
277
  return redirect;
256
278
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss-nextjs",
3
- "version": "22.6.0-canary.4",
3
+ "version": "22.6.0-canary.40",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -67,15 +67,16 @@
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@sitecore-cloudsdk/core": "^0.4.2",
70
+ "@sitecore-cloudsdk/events": "^0.4.2",
70
71
  "@sitecore-cloudsdk/personalize": "^0.4.2",
71
72
  "next": "^14.2.18",
72
73
  "react": "^18.2.0",
73
74
  "react-dom": "^18.2.0"
74
75
  },
75
76
  "dependencies": {
76
- "@sitecore-jss/sitecore-jss": "^22.6.0-canary.4",
77
- "@sitecore-jss/sitecore-jss-dev-tools": "^22.6.0-canary.4",
78
- "@sitecore-jss/sitecore-jss-react": "^22.6.0-canary.4",
77
+ "@sitecore-jss/sitecore-jss": "22.6.0-canary.40",
78
+ "@sitecore-jss/sitecore-jss-dev-tools": "22.6.0-canary.40",
79
+ "@sitecore-jss/sitecore-jss-react": "22.6.0-canary.40",
79
80
  "@vercel/kv": "^0.2.1",
80
81
  "prop-types": "^15.8.1",
81
82
  "regex-parser": "^2.2.11",
@@ -83,7 +84,7 @@
83
84
  },
84
85
  "description": "",
85
86
  "types": "types/index.d.ts",
86
- "gitHead": "acbeab9ccde8a7c55d835df164c4027a4b2786d3",
87
+ "gitHead": "2279a5d7360a43fa5d24b7b74d89043c5eb72c80",
87
88
  "files": [
88
89
  "dist",
89
90
  "types",
@@ -1,5 +1,6 @@
1
1
  /// <reference types="@types/react" />
2
2
  import React from 'react';
3
+ import { LinkProps as NextLinkProps } from 'next/link';
3
4
  import { LinkProps as ReactLinkProps } from '@sitecore-jss/sitecore-jss-react';
4
5
  export type LinkProps = ReactLinkProps & {
5
6
  /**
@@ -7,5 +8,9 @@ export type LinkProps = ReactLinkProps & {
7
8
  * @default /^\//g
8
9
  */
9
10
  internalLinkMatcher?: RegExp;
11
+ /**
12
+ * Next.js Link prefetch.
13
+ */
14
+ prefetch?: NextLinkProps['prefetch'];
10
15
  };
11
16
  export declare const Link: React.ForwardRefExoticComponent<Omit<LinkProps, "ref"> & React.RefAttributes<HTMLAnchorElement>>;
@@ -11,9 +11,15 @@ export type RichTextProps = ReactRichTextProps & {
11
11
  /**
12
12
  * Controls the prefetch of internal links. This can be beneficial if you have RichText fields
13
13
  * with large numbers of internal links in them.
14
+ * - `true` (default): The full route & its data will be prefetched.
15
+ * - `hover`: Prefetching will happen on hover.
16
+ * - `false`: Prefetching will not happen.
14
17
  * @default true
15
18
  */
16
- prefetchLinks?: boolean;
19
+ prefetchLinks?: boolean | 'hover';
20
+ };
21
+ export declare const prefetched: {
22
+ [cacheKey: string]: boolean;
17
23
  };
18
24
  export declare const RichText: {
19
25
  (props: RichTextProps): JSX.Element;
package/types/index.d.ts CHANGED
@@ -22,4 +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 { 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';
25
+ export { ComponentFactory, Form, 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,5 +1,6 @@
1
1
  import { SiteInfo, SiteResolver } from '@sitecore-jss/sitecore-jss/site';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
+ export declare const REWRITE_HEADER_NAME = "x-sc-rewrite";
3
4
  export type MiddlewareBaseConfig = {
4
5
  /**
5
6
  * function, determines if middleware should be turned off, based on cookie, header, or other considerations
@@ -28,7 +29,6 @@ export type MiddlewareBaseConfig = {
28
29
  export declare abstract class MiddlewareBase {
29
30
  protected config: MiddlewareBaseConfig;
30
31
  protected SITE_SYMBOL: string;
31
- protected REWRITE_HEADER_NAME: string;
32
32
  protected defaultHostname: string;
33
33
  constructor(config: MiddlewareBaseConfig);
34
34
  /**
@@ -77,6 +77,7 @@ export declare abstract class MiddlewareBase {
77
77
  * @param {string} rewritePath the destionation path
78
78
  * @param {NextRequest} req the current request
79
79
  * @param {NextResponse} res the current response
80
+ * @param {boolean} [skipHeader] don't write 'x-sc-rewrite' header
80
81
  */
81
- protected rewrite(rewritePath: string, req: NextRequest, res: NextResponse): NextResponse;
82
+ protected rewrite(rewritePath: string, req: NextRequest, res: NextResponse, skipHeader?: boolean): NextResponse;
82
83
  }
@@ -1,6 +1,9 @@
1
- import { GraphQLRedirectsServiceConfig } from '@sitecore-jss/sitecore-jss/site';
1
+ import { GraphQLRedirectsServiceConfig, RedirectInfo } from '@sitecore-jss/sitecore-jss/site';
2
2
  import { NextRequest, NextResponse } from 'next/server';
3
3
  import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
4
+ type RedirectResult = RedirectInfo & {
5
+ matchedQueryString?: string;
6
+ };
4
7
  /**
5
8
  * extended RedirectsMiddlewareConfig config type for RedirectsMiddleware
6
9
  */
@@ -28,15 +31,20 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
28
31
  * @returns route handler
29
32
  */
30
33
  getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
31
- private handler;
32
34
  /**
33
35
  * Method returns RedirectInfo when matches
34
36
  * @param {NextRequest} req request
35
37
  * @param {string} siteName site name
36
- * @returns Promise<RedirectInfo | undefined>
37
- * @private
38
+ * @returns Promise<RedirectInfo | undefined> The redirect info or undefined if no redirect is found
39
+ * @protected
40
+ */
41
+ protected getExistsRedirect(req: NextRequest, siteName: string): Promise<RedirectResult | undefined>;
42
+ /**
43
+ * @param {NextRequest} req request
44
+ * @param {Response} res response
45
+ * @returns {Promise<NextResponse>} The redirect response.
38
46
  */
39
- private getExistsRedirect;
47
+ protected processRedirectRequest(req: NextRequest, res?: NextResponse): Promise<NextResponse>;
40
48
  /**
41
49
  * When a user clicks on a link generated by the Link component from next/link,
42
50
  * Next.js adds special parameters in the route called path.
@@ -55,3 +63,4 @@ export declare class RedirectsMiddleware extends MiddlewareBase {
55
63
  */
56
64
  private createRedirectResponse;
57
65
  }
66
+ export {};