@sitecore-content-sdk/nextjs 2.0.0-canary.9 → 2.0.0

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.
Files changed (86) hide show
  1. package/LICENSE.txt +202 -202
  2. package/dist/cjs/cache/page-params.js +30 -0
  3. package/dist/cjs/client/sitecore-nextjs-client.js +57 -94
  4. package/dist/cjs/components/BYOCWrapper.js +3 -12
  5. package/dist/cjs/components/DesignLibrary/DesignLibraryApp.js +31 -0
  6. package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +139 -0
  7. package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +221 -0
  8. package/dist/cjs/components/DesignLibrary/index.js +5 -0
  9. package/dist/cjs/components/DesignLibrary/models.js +2 -0
  10. package/dist/cjs/components/FEaaSWrapper.js +3 -12
  11. package/dist/cjs/editing/editing-config-middleware.js +2 -11
  12. package/dist/cjs/editing/editing-render-middleware.js +3 -12
  13. package/dist/cjs/editing/feaas-render-middleware.js +2 -11
  14. package/dist/cjs/editing/utils.js +3 -12
  15. package/dist/cjs/index.js +12 -2
  16. package/dist/cjs/initialization/proxy/analytics-adapter.js +71 -0
  17. package/dist/cjs/initialization/proxy/personalize-adapter.js +72 -0
  18. package/dist/cjs/middleware/robots-middleware.js +16 -25
  19. package/dist/cjs/middleware/sitemap-middleware.js +19 -28
  20. package/dist/cjs/monitoring/healthcheck-middleware.js +2 -11
  21. package/dist/cjs/proxy/locale-proxy.js +2 -11
  22. package/dist/cjs/proxy/multisite-proxy.js +2 -11
  23. package/dist/cjs/proxy/personalize-proxy.js +40 -36
  24. package/dist/cjs/proxy/proxy.js +3 -12
  25. package/dist/cjs/proxy/redirects-proxy.js +58 -69
  26. package/dist/cjs/route-handler/editing-config-route-handler.js +4 -13
  27. package/dist/cjs/route-handler/editing-render-route-handler.js +17 -28
  28. package/dist/cjs/route-handler/robots-route-handler.js +5 -14
  29. package/dist/cjs/route-handler/sitemap-route-handler.js +5 -14
  30. package/dist/cjs/server-actions/update-server-component-action.js +56 -0
  31. package/dist/cjs/services/component-props-service.js +63 -80
  32. package/dist/esm/cache/page-params.js +25 -0
  33. package/dist/esm/client/sitecore-nextjs-client.js +57 -94
  34. package/dist/esm/components/BYOCWrapper.js +3 -12
  35. package/dist/esm/components/DesignLibrary/DesignLibraryApp.js +24 -0
  36. package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +100 -0
  37. package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +178 -0
  38. package/dist/esm/components/DesignLibrary/index.js +1 -0
  39. package/dist/esm/components/DesignLibrary/models.js +1 -0
  40. package/dist/esm/components/FEaaSWrapper.js +3 -12
  41. package/dist/esm/editing/editing-config-middleware.js +2 -11
  42. package/dist/esm/editing/editing-render-middleware.js +3 -12
  43. package/dist/esm/editing/feaas-render-middleware.js +2 -11
  44. package/dist/esm/editing/utils.js +3 -12
  45. package/dist/esm/index.js +6 -1
  46. package/dist/esm/initialization/proxy/analytics-adapter.js +66 -0
  47. package/dist/esm/initialization/proxy/personalize-adapter.js +69 -0
  48. package/dist/esm/middleware/robots-middleware.js +16 -25
  49. package/dist/esm/middleware/sitemap-middleware.js +19 -28
  50. package/dist/esm/monitoring/healthcheck-middleware.js +2 -11
  51. package/dist/esm/proxy/locale-proxy.js +2 -11
  52. package/dist/esm/proxy/multisite-proxy.js +2 -11
  53. package/dist/esm/proxy/personalize-proxy.js +40 -36
  54. package/dist/esm/proxy/proxy.js +3 -12
  55. package/dist/esm/proxy/redirects-proxy.js +58 -69
  56. package/dist/esm/route-handler/editing-config-route-handler.js +4 -13
  57. package/dist/esm/route-handler/editing-render-route-handler.js +17 -28
  58. package/dist/esm/route-handler/robots-route-handler.js +5 -14
  59. package/dist/esm/route-handler/sitemap-route-handler.js +5 -14
  60. package/dist/esm/server-actions/update-server-component-action.js +52 -0
  61. package/dist/esm/services/component-props-service.js +63 -80
  62. package/package.json +10 -10
  63. package/types/cache/page-params.d.ts +30 -0
  64. package/types/cache/page-params.d.ts.map +1 -0
  65. package/types/components/DesignLibrary/DesignLibraryApp.d.ts +14 -0
  66. package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +1 -0
  67. package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +21 -0
  68. package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +1 -0
  69. package/types/components/DesignLibrary/DesignLibraryServer.d.ts +38 -0
  70. package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +1 -0
  71. package/types/components/DesignLibrary/index.d.ts +2 -0
  72. package/types/components/DesignLibrary/index.d.ts.map +1 -0
  73. package/types/components/DesignLibrary/models.d.ts +60 -0
  74. package/types/components/DesignLibrary/models.d.ts.map +1 -0
  75. package/types/index.d.ts +9 -1
  76. package/types/index.d.ts.map +1 -1
  77. package/types/initialization/proxy/analytics-adapter.d.ts +30 -0
  78. package/types/initialization/proxy/analytics-adapter.d.ts.map +1 -0
  79. package/types/initialization/proxy/personalize-adapter.d.ts +23 -0
  80. package/types/initialization/proxy/personalize-adapter.d.ts.map +1 -0
  81. package/types/middleware/robots-middleware.d.ts.map +1 -1
  82. package/types/middleware/sitemap-middleware.d.ts.map +1 -1
  83. package/types/proxy/personalize-proxy.d.ts +2 -1
  84. package/types/proxy/personalize-proxy.d.ts.map +1 -1
  85. package/types/server-actions/update-server-component-action.d.ts +63 -0
  86. package/types/server-actions/update-server-component-action.d.ts.map +1 -0
@@ -1,13 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  import { getLocaleRewrite } from '@sitecore-content-sdk/content/i18n';
12
3
  import { ProxyBase, LOCALE_HEADER_NAME } from './proxy';
13
4
  import debug from '../debug';
@@ -24,7 +15,7 @@ export class LocaleProxy extends ProxyBase {
24
15
  constructor(config) {
25
16
  super(config);
26
17
  this.config = config;
27
- this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
18
+ this.handle = async (req, res) => {
28
19
  try {
29
20
  const { pathname } = req.nextUrl;
30
21
  const localeFromPath = this.getLocaleFromPath(pathname);
@@ -61,7 +52,7 @@ export class LocaleProxy extends ProxyBase {
61
52
  console.log(error);
62
53
  return res;
63
54
  }
64
- });
55
+ };
65
56
  }
66
57
  disabled(req, res) {
67
58
  // ignore files
@@ -1,13 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  import { getSiteRewrite, SITE_KEY } from '@sitecore-content-sdk/content/site';
12
3
  import { ProxyBase, REWRITE_HEADER_NAME } from './proxy';
13
4
  import { PREVIEW_KEY } from '@sitecore-content-sdk/content/editing';
@@ -23,7 +14,7 @@ export class MultisiteProxy extends ProxyBase {
23
14
  constructor(config) {
24
15
  super(config);
25
16
  this.config = config;
26
- this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
17
+ this.handle = async (req, res) => {
27
18
  var _a, _b, _c;
28
19
  try {
29
20
  // Path can be rewritten by previously executed proxy
@@ -101,7 +92,7 @@ export class MultisiteProxy extends ProxyBase {
101
92
  console.log(error);
102
93
  return res;
103
94
  }
104
- });
95
+ };
105
96
  }
106
97
  disabled(req, res) {
107
98
  // ignore files
@@ -1,17 +1,12 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { PersonalizeService, getPersonalizedRewrite, CdpHelper, DEFAULT_VARIANT, } from '@sitecore-content-sdk/content/personalize';
11
2
  import { ProxyBase, REWRITE_HEADER_NAME } from './proxy';
12
- import { CloudSDK } from '@sitecore-cloudsdk/core/server';
13
- import { personalize } from '@sitecore-cloudsdk/personalize/server';
3
+ import { initContentSdk } from '@sitecore-content-sdk/core';
4
+ import { personalize } from '@sitecore-content-sdk/personalize';
14
5
  import debug from '../debug';
6
+ import { analyticsPlugin } from '@sitecore-content-sdk/analytics-core';
7
+ import { analyticsProxyAdapter } from '../initialization/proxy/analytics-adapter';
8
+ import { personalizeServerPlugin } from '@sitecore-content-sdk/personalize';
9
+ import { personalizeProxyAdapter } from '../initialization/proxy/personalize-adapter';
15
10
  /**
16
11
  * Proxy / handler to support Sitecore Personalize
17
12
  * @public
@@ -24,7 +19,7 @@ export class PersonalizeProxy extends ProxyBase {
24
19
  var _a;
25
20
  super(config);
26
21
  this.config = config;
27
- this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
22
+ this.handle = async (req, res) => {
28
23
  if (!this.config.enabled) {
29
24
  debug.personalize('skipped (personalize proxy is disabled globally)');
30
25
  return res;
@@ -36,7 +31,7 @@ export class PersonalizeProxy extends ProxyBase {
36
31
  const startTimestamp = Date.now();
37
32
  const cdpTimeout = this.config.cdpTimeout;
38
33
  const geo = this.config.extractGeoDataCb
39
- ? yield this.config.extractGeoDataCb(req)
34
+ ? await this.config.extractGeoDataCb(req)
40
35
  : undefined;
41
36
  debug.personalize('personalize proxy start: %o', Object.assign(Object.assign({ pathname,
42
37
  language,
@@ -57,7 +52,7 @@ export class PersonalizeProxy extends ProxyBase {
57
52
  if (!this.personalizeService) {
58
53
  return res;
59
54
  }
60
- const personalizeInfo = yield this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
55
+ const personalizeInfo = await this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
61
56
  if (!personalizeInfo) {
62
57
  // Likely an invalid route / language
63
58
  debug.personalize('skipped (personalize info not found)');
@@ -77,7 +72,7 @@ export class PersonalizeProxy extends ProxyBase {
77
72
  res.headers.set('Cache-Control', 'no-store, must-revalidate');
78
73
  return res;
79
74
  }
80
- yield this.initPersonalizeServer({
75
+ await this.initPersonalizeServer({
81
76
  hostname,
82
77
  siteName: site.name,
83
78
  request: req,
@@ -86,8 +81,8 @@ export class PersonalizeProxy extends ProxyBase {
86
81
  const params = this.getExperienceParams(req);
87
82
  const executions = this.getPersonalizeExecutions(personalizeInfo, language);
88
83
  const identifiedVariantIds = [];
89
- yield Promise.all(executions.map((execution) => this.personalize(Object.assign({ friendlyId: execution.friendlyId, variantIds: execution.variantIds, params,
90
- language, timeout: cdpTimeout }, (geo && { geo })), req).then((personalization) => {
84
+ await Promise.all(executions.map((execution) => this.personalize(Object.assign({ friendlyId: execution.friendlyId, variantIds: execution.variantIds, params,
85
+ language, timeout: cdpTimeout }, (geo && { geo }))).then((personalization) => {
91
86
  const variantId = personalization.variantId;
92
87
  if (variantId) {
93
88
  if (!execution.variantIds.includes(variantId)) {
@@ -121,7 +116,7 @@ export class PersonalizeProxy extends ProxyBase {
121
116
  console.log(error);
122
117
  return res;
123
118
  }
124
- });
119
+ };
125
120
  // Validate edge config is present - personalize requires Edge platform
126
121
  if (!this.config.contextId && !this.config.clientContextId) {
127
122
  console.warn('[PersonalizeProxy] Personalize proxy requires Edge configuration (contextId/clientContextId). ' +
@@ -169,27 +164,36 @@ export class PersonalizeProxy extends ProxyBase {
169
164
  utm,
170
165
  };
171
166
  }
172
- initPersonalizeServer(_a) {
173
- return __awaiter(this, arguments, void 0, function* ({ hostname, siteName, request, response, }) {
174
- yield CloudSDK(request, response, {
175
- sitecoreEdgeUrl: this.config.edgeUrl,
176
- sitecoreEdgeContextId: this.config.contextId,
167
+ async initPersonalizeServer({ hostname, siteName, request, response, }) {
168
+ await initContentSdk({
169
+ config: {
170
+ contextId: this.config.contextId,
171
+ edgeUrl: this.config.edgeUrl,
177
172
  siteName,
178
- cookieDomain: hostname,
179
- enableServerCookie: true,
180
- })
181
- .addPersonalize({ enablePersonalizeCookie: true })
182
- .initialize();
173
+ },
174
+ plugins: [
175
+ analyticsPlugin({
176
+ options: {
177
+ enableCookie: true,
178
+ cookieDomain: hostname,
179
+ },
180
+ adapter: analyticsProxyAdapter(request, response),
181
+ }),
182
+ personalizeServerPlugin({
183
+ options: {
184
+ enablePersonalizeCookie: true,
185
+ },
186
+ adapter: personalizeProxyAdapter(request, response),
187
+ }),
188
+ ],
183
189
  });
184
190
  }
185
- personalize(_a, request_1) {
186
- return __awaiter(this, arguments, void 0, function* ({ params, friendlyId, language, timeout, variantIds, geo, }, request) {
187
- var _b;
188
- debug.personalize('executing experience for %s %o', friendlyId, params);
189
- return (yield personalize(request, Object.assign({ channel: this.config.channel || 'WEB', currency: (_b = this.config.currency) !== null && _b !== void 0 ? _b : 'USD', friendlyId,
190
- params,
191
- language, pageVariantIds: variantIds }, (geo && { geo })), { timeout }));
192
- });
191
+ async personalize({ params, friendlyId, language, timeout, variantIds, geo, }) {
192
+ var _a;
193
+ debug.personalize('executing experience for %s %o', friendlyId, params);
194
+ return (await personalize(Object.assign({ channel: this.config.channel || 'WEB', currency: (_a = this.config.currency) !== null && _a !== void 0 ? _a : 'USD', friendlyId,
195
+ params,
196
+ language, pageVariantIds: variantIds }, (geo && { geo })), { timeout }));
193
197
  }
194
198
  /**
195
199
  * Aggregates personalize executions based on the provided route personalize information and language
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { SITE_KEY, SiteResolver } from '@sitecore-content-sdk/content/site';
11
2
  import { NextResponse } from 'next/server';
12
3
  import { createGraphQLClientFactory, } from '@sitecore-content-sdk/content/client';
@@ -177,13 +168,13 @@ export const defineProxy = (...proxies) => {
177
168
  * @param {NextRequest} req request
178
169
  * @param {NextResponse} [res] response
179
170
  */
180
- exec: (req, res) => __awaiter(void 0, void 0, void 0, function* () {
171
+ exec: async (req, res) => {
181
172
  const response = res || NextResponse.next();
182
173
  debug.common('proxy start');
183
174
  const start = Date.now();
184
- const proxyResponse = yield proxies.reduce((p, proxy) => p.then((res) => proxy.handle(req, res)), Promise.resolve(response));
175
+ const proxyResponse = await proxies.reduce((p, proxy) => p.then((res) => proxy.handle(req, res)), Promise.resolve(response));
185
176
  debug.common('proxy end in %dms', Date.now() - start);
186
177
  return proxyResponse;
187
- }),
178
+ },
188
179
  };
189
180
  };
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { RedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, } from '@sitecore-content-sdk/content/site';
11
2
  import { areURLSearchParamsEqual, escapeNonSpecialQuestionMarks, isRegexOrUrl, mergeURLSearchParams, } from '@sitecore-content-sdk/core/tools';
12
3
  import { NextResponse } from 'next/server';
@@ -27,7 +18,7 @@ export class RedirectsProxy extends ProxyBase {
27
18
  constructor(config) {
28
19
  super(config);
29
20
  this.config = config;
30
- this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
21
+ this.handle = async (req, res) => {
31
22
  if (!this.config.enabled) {
32
23
  debug.redirects('skipped (redirects proxy is disabled globally)');
33
24
  return res;
@@ -68,7 +59,7 @@ export class RedirectsProxy extends ProxyBase {
68
59
  }
69
60
  site = this.getSite(req, res);
70
61
  // Find the redirect from result of RedirectService
71
- const existsRedirect = yield this.getExistsRedirect(req, site.name);
62
+ const existsRedirect = await this.getExistsRedirect(req, site.name);
72
63
  if (!existsRedirect) {
73
64
  debug.redirects('skipped (redirect does not exist)');
74
65
  return res;
@@ -153,7 +144,7 @@ export class RedirectsProxy extends ProxyBase {
153
144
  console.log(error);
154
145
  return res;
155
146
  }
156
- });
147
+ };
157
148
  this.locales = config.locales;
158
149
  // If redirectsService is provided directly (e.g., for testing), use it
159
150
  if (this.config.redirectsService) {
@@ -205,64 +196,62 @@ export class RedirectsProxy extends ProxyBase {
205
196
  * @returns Promise<RedirectInfo | undefined>
206
197
  * @private
207
198
  */
208
- getExistsRedirect(req, siteName) {
209
- return __awaiter(this, void 0, void 0, function* () {
210
- if (!this.redirectsService) {
211
- return undefined;
212
- }
213
- const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
214
- const locale = this.getLanguage(req);
215
- const normalizedPath = incomingURL.replace(/\/*$/gi, '').toLowerCase();
216
- const redirects = yield this.redirectsService.fetchRedirects(siteName);
217
- const modifyRedirects = structuredClone(redirects);
218
- let matchedQueryString;
219
- const localePath = `/${locale.toLowerCase()}${normalizedPath}`;
220
- return modifyRedirects.length
221
- ? modifyRedirects.find((redirect) => {
222
- // process static URL (non-regex) rules
223
- if (isRegexOrUrl(redirect.pattern) === 'url') {
224
- const urlArray = redirect.pattern.endsWith('/')
225
- ? redirect.pattern.slice(0, -1).split('?')
226
- : redirect.pattern.split('?');
227
- const patternQS = urlArray[1];
228
- let patternPath = urlArray[0].toLowerCase();
229
- // nextjs routes are case-sensitive, but locales should be compared case-insensitively
230
- const patternParts = patternPath.split('/');
231
- const maybeLocale = patternParts[1].toLowerCase();
232
- // case insensitive lookup of locales
233
- if (new RegExp(this.locales.join('|'), 'i').test(maybeLocale)) {
234
- patternPath = patternPath.replace(`/${patternParts[1]}`, `/${maybeLocale}`);
235
- }
236
- return ((patternPath === localePath || patternPath === normalizedPath) &&
237
- (!patternQS ||
238
- areURLSearchParamsEqual(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
199
+ async getExistsRedirect(req, siteName) {
200
+ if (!this.redirectsService) {
201
+ return undefined;
202
+ }
203
+ const { pathname: incomingURL, search: incomingQS = '' } = this.normalizeUrl(req.nextUrl.clone());
204
+ const locale = this.getLanguage(req);
205
+ const normalizedPath = incomingURL.replace(/\/*$/gi, '').toLowerCase();
206
+ const redirects = await this.redirectsService.fetchRedirects(siteName);
207
+ const modifyRedirects = structuredClone(redirects);
208
+ let matchedQueryString;
209
+ const localePath = `/${locale.toLowerCase()}${normalizedPath}`;
210
+ return modifyRedirects.length
211
+ ? modifyRedirects.find((redirect) => {
212
+ // process static URL (non-regex) rules
213
+ if (isRegexOrUrl(redirect.pattern) === 'url') {
214
+ const urlArray = redirect.pattern.endsWith('/')
215
+ ? redirect.pattern.slice(0, -1).split('?')
216
+ : redirect.pattern.split('?');
217
+ const patternQS = urlArray[1];
218
+ let patternPath = urlArray[0].toLowerCase();
219
+ // nextjs routes are case-sensitive, but locales should be compared case-insensitively
220
+ const patternParts = patternPath.split('/');
221
+ const maybeLocale = patternParts[1].toLowerCase();
222
+ // case insensitive lookup of locales
223
+ if (new RegExp(this.locales.join('|'), 'i').test(maybeLocale)) {
224
+ patternPath = patternPath.replace(`/${patternParts[1]}`, `/${maybeLocale}`);
239
225
  }
240
- // process regex rules
241
- // Modify the redirect pattern to ignore the language prefix in the path
242
- // And escapes non-special "?" characters in a string or regex.
243
- redirect.pattern = escapeNonSpecialQuestionMarks('^' + redirect.pattern.replace(new RegExp(`^[^]?/${locale}/`, 'gi'), '') // ensure function thinks input is regex
244
- );
245
- // Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
246
- redirect.pattern = `/^\/${redirect.pattern
247
- .replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
248
- .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
249
- .replace(/^\^|\$$/g, '') // Further cleans up anchors
250
- .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
251
- // Redirect pattern matches the full incoming URL with query string present
252
- matchedQueryString = [
253
- regexParser(redirect.pattern).test(`/${localePath}${incomingQS}`),
254
- regexParser(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
255
- ].some(Boolean)
256
- ? incomingQS
257
- : undefined;
258
- // Save the matched query string (if found) into the redirect object
259
- redirect.matchedQueryString = matchedQueryString || '';
260
- return (!!(regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
261
- regexParser(redirect.pattern).test(incomingURL) ||
262
- matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
263
- })
264
- : undefined;
265
- });
226
+ return ((patternPath === localePath || patternPath === normalizedPath) &&
227
+ (!patternQS ||
228
+ areURLSearchParamsEqual(new URLSearchParams(patternQS), new URLSearchParams(incomingQS))));
229
+ }
230
+ // process regex rules
231
+ // Modify the redirect pattern to ignore the language prefix in the path
232
+ // And escapes non-special "?" characters in a string or regex.
233
+ redirect.pattern = escapeNonSpecialQuestionMarks('^' + redirect.pattern.replace(new RegExp(`^[^]?/${locale}/`, 'gi'), '') // ensure function thinks input is regex
234
+ );
235
+ // Prepare the redirect pattern as a regular expression, making it more flexible for matching URLs
236
+ redirect.pattern = `/^\/${redirect.pattern
237
+ .replace(/^\/|\/$/g, '') // Removes leading and trailing slashes
238
+ .replace(/^\^\/|\/\$$/g, '') // Removes unnecessary start (^) and end ($) anchors
239
+ .replace(/^\^|\$$/g, '') // Further cleans up anchors
240
+ .replace(/\$\/gi$/g, '')}[\/]?$/i`; // Ensures the pattern allows an optional trailing slash
241
+ // Redirect pattern matches the full incoming URL with query string present
242
+ matchedQueryString = [
243
+ regexParser(redirect.pattern).test(`/${localePath}${incomingQS}`),
244
+ regexParser(redirect.pattern).test(`${normalizedPath}${incomingQS}`),
245
+ ].some(Boolean)
246
+ ? incomingQS
247
+ : undefined;
248
+ // Save the matched query string (if found) into the redirect object
249
+ redirect.matchedQueryString = matchedQueryString || '';
250
+ return (!!(regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${incomingURL}`) ||
251
+ regexParser(redirect.pattern).test(incomingURL) ||
252
+ matchedQueryString) && (redirect.locale ? redirect.locale.toLowerCase() === locale.toLowerCase() : true));
253
+ })
254
+ : undefined;
266
255
  }
267
256
  /**
268
257
  * When a user clicks on a link generated by the Link component from next/link,
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, } from '@sitecore-content-sdk/content/editing';
11
2
  import { getEnforcedCorsHeaders } from '@sitecore-content-sdk/core/tools';
12
3
  import { EditMode } from '@sitecore-content-sdk/content/layout';
@@ -31,7 +22,7 @@ export const createEditingConfigRouteHandler = (options) => {
31
22
  });
32
23
  return { secret, corsHeaders };
33
24
  };
34
- const GET = (req) => __awaiter(void 0, void 0, void 0, function* () {
25
+ const GET = async (req) => {
35
26
  try {
36
27
  const startTimestamp = Date.now();
37
28
  debug.editing('editing config route handler start');
@@ -74,8 +65,8 @@ export const createEditingConfigRouteHandler = (options) => {
74
65
  status: 500,
75
66
  });
76
67
  }
77
- });
78
- const OPTIONS = (req) => __awaiter(void 0, void 0, void 0, function* () {
68
+ };
69
+ const OPTIONS = async (req) => {
79
70
  try {
80
71
  debug.editing('preflight request');
81
72
  const { corsHeaders } = validateRequest(req);
@@ -101,6 +92,6 @@ export const createEditingConfigRouteHandler = (options) => {
101
92
  status: 500,
102
93
  });
103
94
  }
104
- });
95
+ };
105
96
  return { GET, OPTIONS };
106
97
  };
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { NativeDataFetcher } from '@sitecore-content-sdk/core';
11
2
  import { EDITING_ALLOWED_ORIGINS, PREVIEW_KEY, QUERY_PARAM_EDITING_SECRET, INVALID_SECRET_HTML_MESSAGE, } from '@sitecore-content-sdk/content/editing';
12
3
  import { getEnforcedCorsHeaders } from '@sitecore-content-sdk/core/tools';
@@ -20,14 +11,12 @@ import debug from '../debug';
20
11
  * Helper function to handle cookie operations - can be mocked for testing
21
12
  * @returns {Promise<NextCookies>} Next cookies
22
13
  */
23
- export function getNextCookies() {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- // In test environment, use mock cookie store only if specifically provided
26
- if (process.env.TEST === 'true' && global.__TEST_COOKIE_STORE__) {
27
- return global.__TEST_COOKIE_STORE__;
28
- }
29
- return yield nextCokies();
30
- });
14
+ export async function getNextCookies() {
15
+ // In test environment, use mock cookie store only if specifically provided
16
+ if (process.env.TEST === 'true' && global.__TEST_COOKIE_STORE__) {
17
+ return global.__TEST_COOKIE_STORE__;
18
+ }
19
+ return await nextCokies();
31
20
  }
32
21
  /**
33
22
  * Creates a route handler for the editing render API route (e.g. '/api/editing/render')
@@ -76,7 +65,7 @@ export const createEditingRenderRouteHandlers = (options) => {
76
65
  debug.editing('preflight request');
77
66
  return new Response(null, { status: 204, headers: expectedCorsHeaders });
78
67
  };
79
- const GET = (req) => __awaiter(void 0, void 0, void 0, function* () {
68
+ const GET = async (req) => {
80
69
  var _a, _b;
81
70
  const { method, headers } = req;
82
71
  // init query string values
@@ -103,7 +92,7 @@ export const createEditingRenderRouteHandlers = (options) => {
103
92
  }, { status: 401, headers: responseHeaders });
104
93
  }
105
94
  // enable preview
106
- const draft = yield draftMode();
95
+ const draft = await draftMode();
107
96
  draft.enable();
108
97
  const startTimestamp = Date.now();
109
98
  const mode = query.mode;
@@ -129,7 +118,7 @@ export const createEditingRenderRouteHandlers = (options) => {
129
118
  const requestUrl = new URL(route, base);
130
119
  // Restrict the page to be rendered only within the allowed origins
131
120
  responseHeaders['Content-Security-Policy'] = getCSPHeader();
132
- const cookieStore = yield getNextCookies();
121
+ const cookieStore = await getNextCookies();
133
122
  cookieStore.set("__prerender_bypass" /* PreviewCookies.PRERENDER_BYPASS */, ((_b = cookieStore.get("__prerender_bypass" /* PreviewCookies.PRERENDER_BYPASS */)) === null || _b === void 0 ? void 0 : _b.value) || '', {
134
123
  httpOnly: true,
135
124
  path: '/',
@@ -159,7 +148,7 @@ export const createEditingRenderRouteHandlers = (options) => {
159
148
  const propagatedQsParams = Object.assign(Object.assign(Object.assign({}, getQueryParamsForPropagation(query)), mapEditingParams(query)), allowedQueryParams);
160
149
  // Get headers to propagate on subsequent requests
161
150
  const propagatedHeaders = getHeadersForPropagation(headers);
162
- const html = yield getEditingRequestHtml(requestUrl, propagatedQsParams, propagatedHeaders, convertedCookies, dataFetcher);
151
+ const html = await getEditingRequestHtml(requestUrl, propagatedQsParams, propagatedHeaders, convertedCookies, dataFetcher);
163
152
  // remove nextjs preview cookies to not leak them to the browser
164
153
  const filteredCookies = cleanupNextPreviewCookies(convertedCookies);
165
154
  responseHeaders['Set-Cookie'] = (filteredCookies === null || filteredCookies === void 0 ? void 0 : filteredCookies.join('; ')) || '';
@@ -180,9 +169,9 @@ export const createEditingRenderRouteHandlers = (options) => {
180
169
  return Response.redirect(route);
181
170
  }
182
171
  finally {
183
- yield draft.disable();
172
+ await draft.disable();
184
173
  }
185
- });
174
+ };
186
175
  /**
187
176
  * This POST handler serves as proxy for server action call when Design Library is rendering server component.
188
177
  * When Design Library needs to dynamically update or render a generated variant of server component a server action {@link updateServerComponentAction} is called from the client side.
@@ -190,7 +179,7 @@ export const createEditingRenderRouteHandlers = (options) => {
190
179
  * However, in editing mode we are in an api route handler scenario so we need to proxy the POST request to be able to process the server action correctly.
191
180
  * @param {NextRequest} req - The incoming request
192
181
  */
193
- const POST = (req) => __awaiter(void 0, void 0, void 0, function* () {
182
+ const POST = async (req) => {
194
183
  var _a;
195
184
  const requestOrigin = req.headers.get('origin') || '';
196
185
  const originHost = new URL(requestOrigin).host;
@@ -225,10 +214,10 @@ export const createEditingRenderRouteHandlers = (options) => {
225
214
  }
226
215
  targetUrl.searchParams.append('timestamp', Date.now().toString());
227
216
  // enable draft mode in order to get prerender bypass cookie from request
228
- const draft = yield draftMode();
217
+ const draft = await draftMode();
229
218
  draft.enable();
230
219
  // add prerender bypass cookie to forwarded request in order to enable draft mode
231
- const cookieStore = yield getNextCookies();
220
+ const cookieStore = await getNextCookies();
232
221
  const reqCookie = req.headers.get('cookie') || '';
233
222
  const prerenderBypassCookie = `${"__prerender_bypass" /* PreviewCookies.PRERENDER_BYPASS */}=${((_a = cookieStore.get("__prerender_bypass" /* PreviewCookies.PRERENDER_BYPASS */)) === null || _a === void 0 ? void 0 : _a.value) || ''}`;
234
223
  const forwardCookie = reqCookie
@@ -236,7 +225,7 @@ export const createEditingRenderRouteHandlers = (options) => {
236
225
  : prerenderBypassCookie;
237
226
  const forwardHeaders = new Headers(req.headers);
238
227
  forwardHeaders.set('cookie', forwardCookie);
239
- const forwardedResponse = yield dataFetcher.fetch(targetUrl.toString(), {
228
+ const forwardedResponse = await dataFetcher.fetch(targetUrl.toString(), {
240
229
  method: req.method,
241
230
  headers: forwardHeaders,
242
231
  body: req.body,
@@ -268,6 +257,6 @@ export const createEditingRenderRouteHandlers = (options) => {
268
257
  statusText: forwardedResponse.statusText,
269
258
  headers: filteredHeaders,
270
259
  });
271
- });
260
+ };
272
261
  return { GET, POST, OPTIONS };
273
262
  };
@@ -1,12 +1,3 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
1
  import { SiteResolver } from '@sitecore-content-sdk/content/site';
11
2
  import { unstable_cache } from 'next/cache';
12
3
  import debug from '../debug';
@@ -19,13 +10,13 @@ import debug from '../debug';
19
10
  export const createRobotsRouteHandler = (options) => {
20
11
  const { client, sites, revalidate = 60 } = options;
21
12
  const siteResolver = new SiteResolver(sites);
22
- const getRobots = unstable_cache((site) => __awaiter(void 0, void 0, void 0, function* () {
13
+ const getRobots = unstable_cache(async (site) => {
23
14
  return client.getRobots(site);
24
- }), ['robots'], {
15
+ }, ['robots'], {
25
16
  revalidate,
26
17
  tags: ['robots'],
27
18
  });
28
- const GET = (req) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const GET = async (req) => {
29
20
  var _a;
30
21
  try {
31
22
  const hostName = req.headers.get('x-forwarded-host') ||
@@ -38,7 +29,7 @@ export const createRobotsRouteHandler = (options) => {
38
29
  hostName,
39
30
  siteName: site.name,
40
31
  });
41
- const robotsContent = yield getRobots(site.name);
32
+ const robotsContent = await getRobots(site.name);
42
33
  if (!robotsContent) {
43
34
  debug.robots('robots route handler end in %dms', Date.now() - startTimestamp);
44
35
  return new Response('User-agent: *\nDisallow: /', {
@@ -67,6 +58,6 @@ export const createRobotsRouteHandler = (options) => {
67
58
  status: 500,
68
59
  });
69
60
  }
70
- });
61
+ };
71
62
  return { GET };
72
63
  };