@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.
- package/LICENSE.txt +202 -202
- package/dist/cjs/cache/page-params.js +30 -0
- package/dist/cjs/client/sitecore-nextjs-client.js +57 -94
- package/dist/cjs/components/BYOCWrapper.js +3 -12
- package/dist/cjs/components/DesignLibrary/DesignLibraryApp.js +31 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +139 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +221 -0
- package/dist/cjs/components/DesignLibrary/index.js +5 -0
- package/dist/cjs/components/DesignLibrary/models.js +2 -0
- package/dist/cjs/components/FEaaSWrapper.js +3 -12
- package/dist/cjs/editing/editing-config-middleware.js +2 -11
- package/dist/cjs/editing/editing-render-middleware.js +3 -12
- package/dist/cjs/editing/feaas-render-middleware.js +2 -11
- package/dist/cjs/editing/utils.js +3 -12
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/initialization/proxy/analytics-adapter.js +71 -0
- package/dist/cjs/initialization/proxy/personalize-adapter.js +72 -0
- package/dist/cjs/middleware/robots-middleware.js +16 -25
- package/dist/cjs/middleware/sitemap-middleware.js +19 -28
- package/dist/cjs/monitoring/healthcheck-middleware.js +2 -11
- package/dist/cjs/proxy/locale-proxy.js +2 -11
- package/dist/cjs/proxy/multisite-proxy.js +2 -11
- package/dist/cjs/proxy/personalize-proxy.js +40 -36
- package/dist/cjs/proxy/proxy.js +3 -12
- package/dist/cjs/proxy/redirects-proxy.js +58 -69
- package/dist/cjs/route-handler/editing-config-route-handler.js +4 -13
- package/dist/cjs/route-handler/editing-render-route-handler.js +17 -28
- package/dist/cjs/route-handler/robots-route-handler.js +5 -14
- package/dist/cjs/route-handler/sitemap-route-handler.js +5 -14
- package/dist/cjs/server-actions/update-server-component-action.js +56 -0
- package/dist/cjs/services/component-props-service.js +63 -80
- package/dist/esm/cache/page-params.js +25 -0
- package/dist/esm/client/sitecore-nextjs-client.js +57 -94
- package/dist/esm/components/BYOCWrapper.js +3 -12
- package/dist/esm/components/DesignLibrary/DesignLibraryApp.js +24 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +100 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +178 -0
- package/dist/esm/components/DesignLibrary/index.js +1 -0
- package/dist/esm/components/DesignLibrary/models.js +1 -0
- package/dist/esm/components/FEaaSWrapper.js +3 -12
- package/dist/esm/editing/editing-config-middleware.js +2 -11
- package/dist/esm/editing/editing-render-middleware.js +3 -12
- package/dist/esm/editing/feaas-render-middleware.js +2 -11
- package/dist/esm/editing/utils.js +3 -12
- package/dist/esm/index.js +6 -1
- package/dist/esm/initialization/proxy/analytics-adapter.js +66 -0
- package/dist/esm/initialization/proxy/personalize-adapter.js +69 -0
- package/dist/esm/middleware/robots-middleware.js +16 -25
- package/dist/esm/middleware/sitemap-middleware.js +19 -28
- package/dist/esm/monitoring/healthcheck-middleware.js +2 -11
- package/dist/esm/proxy/locale-proxy.js +2 -11
- package/dist/esm/proxy/multisite-proxy.js +2 -11
- package/dist/esm/proxy/personalize-proxy.js +40 -36
- package/dist/esm/proxy/proxy.js +3 -12
- package/dist/esm/proxy/redirects-proxy.js +58 -69
- package/dist/esm/route-handler/editing-config-route-handler.js +4 -13
- package/dist/esm/route-handler/editing-render-route-handler.js +17 -28
- package/dist/esm/route-handler/robots-route-handler.js +5 -14
- package/dist/esm/route-handler/sitemap-route-handler.js +5 -14
- package/dist/esm/server-actions/update-server-component-action.js +52 -0
- package/dist/esm/services/component-props-service.js +63 -80
- package/package.json +10 -10
- package/types/cache/page-params.d.ts +30 -0
- package/types/cache/page-params.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts +14 -0
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +21 -0
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts +38 -0
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +1 -0
- package/types/components/DesignLibrary/index.d.ts +2 -0
- package/types/components/DesignLibrary/index.d.ts.map +1 -0
- package/types/components/DesignLibrary/models.d.ts +60 -0
- package/types/components/DesignLibrary/models.d.ts.map +1 -0
- package/types/index.d.ts +9 -1
- package/types/index.d.ts.map +1 -1
- package/types/initialization/proxy/analytics-adapter.d.ts +30 -0
- package/types/initialization/proxy/analytics-adapter.d.ts.map +1 -0
- package/types/initialization/proxy/personalize-adapter.d.ts +23 -0
- package/types/initialization/proxy/personalize-adapter.d.ts.map +1 -0
- package/types/middleware/robots-middleware.d.ts.map +1 -1
- package/types/middleware/sitemap-middleware.d.ts.map +1 -1
- package/types/proxy/personalize-proxy.d.ts +2 -1
- package/types/proxy/personalize-proxy.d.ts.map +1 -1
- package/types/server-actions/update-server-component-action.d.ts +63 -0
- 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) =>
|
|
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) =>
|
|
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 {
|
|
13
|
-
import { personalize } from '@sitecore-
|
|
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) =>
|
|
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
|
-
?
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
90
|
-
language, timeout: cdpTimeout }, (geo && { geo }))
|
|
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(
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
package/dist/esm/proxy/proxy.js
CHANGED
|
@@ -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) =>
|
|
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 =
|
|
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) =>
|
|
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 =
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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) =>
|
|
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) =>
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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) =>
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
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) =>
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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) =>
|
|
13
|
+
const getRobots = unstable_cache(async (site) => {
|
|
23
14
|
return client.getRobots(site);
|
|
24
|
-
}
|
|
15
|
+
}, ['robots'], {
|
|
25
16
|
revalidate,
|
|
26
17
|
tags: ['robots'],
|
|
27
18
|
});
|
|
28
|
-
const GET = (req) =>
|
|
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 =
|
|
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
|
};
|