@sitecore-content-sdk/nextjs 0.1.0-beta.7 → 0.1.0-beta.8
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/config.d.ts +1 -0
- package/config.js +1 -0
- package/dist/cjs/config/index.js +5 -0
- package/dist/cjs/middleware/middleware.js +4 -2
- package/dist/cjs/middleware/multisite-middleware.js +5 -1
- package/dist/cjs/middleware/personalize-middleware.js +17 -8
- package/dist/cjs/middleware/redirects-middleware.js +8 -4
- package/dist/esm/config/index.js +1 -0
- package/dist/esm/middleware/middleware.js +4 -2
- package/dist/esm/middleware/multisite-middleware.js +5 -1
- package/dist/esm/middleware/personalize-middleware.js +17 -8
- package/dist/esm/middleware/redirects-middleware.js +8 -4
- package/package.json +5 -5
- package/types/config/index.d.ts +1 -0
- package/types/middleware/middleware.d.ts +2 -1
- package/types/middleware/multisite-middleware.d.ts +2 -6
- package/types/middleware/personalize-middleware.d.ts +5 -14
- package/types/middleware/redirects-middleware.d.ts +2 -7
package/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/config/index';
|
package/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/config/index');
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineConfig = void 0;
|
|
4
|
+
var config_1 = require("@sitecore-content-sdk/core/config");
|
|
5
|
+
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return config_1.defineConfig; } });
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.defineMiddleware = exports.MiddlewareBase = exports.Middleware = void 0;
|
|
13
|
+
const site_1 = require("@sitecore-content-sdk/core/site");
|
|
13
14
|
const core_1 = require("@sitecore-content-sdk/core");
|
|
14
15
|
const server_1 = require("next/server");
|
|
15
16
|
/**
|
|
@@ -27,6 +28,7 @@ class MiddlewareBase extends Middleware {
|
|
|
27
28
|
this.config = config;
|
|
28
29
|
this.SITE_SYMBOL = 'sc_site';
|
|
29
30
|
this.REWRITE_HEADER_NAME = 'x-sc-rewrite';
|
|
31
|
+
this.siteResolver = new site_1.SiteResolver(config.sites);
|
|
30
32
|
this.defaultHostname = config.defaultHostname || 'localhost';
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
@@ -94,9 +96,9 @@ class MiddlewareBase extends Middleware {
|
|
|
94
96
|
var _a;
|
|
95
97
|
const siteNameCookie = (_a = res === null || res === void 0 ? void 0 : res.cookies.get(this.SITE_SYMBOL)) === null || _a === void 0 ? void 0 : _a.value;
|
|
96
98
|
if (siteNameCookie)
|
|
97
|
-
return this.
|
|
99
|
+
return this.siteResolver.getByName(siteNameCookie);
|
|
98
100
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
99
|
-
return this.
|
|
101
|
+
return this.siteResolver.getByHost(hostname);
|
|
100
102
|
}
|
|
101
103
|
/**
|
|
102
104
|
* Create a rewrite response
|
|
@@ -25,6 +25,10 @@ class MultisiteMiddleware extends middleware_1.MiddlewareBase {
|
|
|
25
25
|
this.config = config;
|
|
26
26
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
27
27
|
var _a;
|
|
28
|
+
if (!this.config.enabled) {
|
|
29
|
+
core_1.debug.multisite('skipped (multisite middleware is disabled globally)');
|
|
30
|
+
return res;
|
|
31
|
+
}
|
|
28
32
|
try {
|
|
29
33
|
const pathname = req.nextUrl.pathname;
|
|
30
34
|
const language = this.getLanguage(req);
|
|
@@ -48,7 +52,7 @@ class MultisiteMiddleware extends middleware_1.MiddlewareBase {
|
|
|
48
52
|
(this.config.useCookieResolution &&
|
|
49
53
|
this.config.useCookieResolution(req) &&
|
|
50
54
|
((_a = req.cookies.get(this.SITE_SYMBOL)) === null || _a === void 0 ? void 0 : _a.value)) ||
|
|
51
|
-
this.
|
|
55
|
+
this.siteResolver.getByHost(hostname).name;
|
|
52
56
|
// Rewrite to site specific path
|
|
53
57
|
const rewritePath = (0, site_1.getSiteRewrite)(pathname, {
|
|
54
58
|
siteName,
|
|
@@ -26,12 +26,16 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
26
26
|
super(config);
|
|
27
27
|
this.config = config;
|
|
28
28
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
if (!this.config.enabled) {
|
|
30
|
+
core_1.debug.personalize('skipped (personalize middleware is disabled globally)');
|
|
31
|
+
return res;
|
|
32
|
+
}
|
|
29
33
|
try {
|
|
30
34
|
const pathname = req.nextUrl.pathname;
|
|
31
35
|
const language = this.getLanguage(req);
|
|
32
36
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
33
37
|
const startTimestamp = Date.now();
|
|
34
|
-
const timeout = this.config.
|
|
38
|
+
const timeout = this.config.cdpTimeout;
|
|
35
39
|
core_1.debug.personalize('personalize middleware start: %o', {
|
|
36
40
|
pathname,
|
|
37
41
|
language,
|
|
@@ -121,13 +125,18 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
121
125
|
});
|
|
122
126
|
// NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
|
|
123
127
|
// (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
|
|
124
|
-
this.personalizeService = new personalize_1.GraphQLPersonalizeService(
|
|
128
|
+
this.personalizeService = new personalize_1.GraphQLPersonalizeService({
|
|
129
|
+
clientFactory: this.config.clientFactory,
|
|
130
|
+
timeout: this.config.edgeTimeout,
|
|
131
|
+
scope: this.config.scope,
|
|
132
|
+
fetch: fetch,
|
|
133
|
+
});
|
|
125
134
|
}
|
|
126
135
|
initPersonalizeServer(_a) {
|
|
127
136
|
return __awaiter(this, arguments, void 0, function* ({ hostname, siteName, request, response, }) {
|
|
128
137
|
yield (0, server_1.CloudSDK)(request, response, {
|
|
129
|
-
sitecoreEdgeUrl: this.config.
|
|
130
|
-
sitecoreEdgeContextId: this.config.
|
|
138
|
+
sitecoreEdgeUrl: this.config.edgeUrl,
|
|
139
|
+
sitecoreEdgeContextId: this.config.contextId,
|
|
131
140
|
siteName,
|
|
132
141
|
cookieDomain: hostname,
|
|
133
142
|
enableServerCookie: true,
|
|
@@ -141,8 +150,8 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
141
150
|
var _b;
|
|
142
151
|
core_1.debug.personalize('executing experience for %s %o', friendlyId, params);
|
|
143
152
|
return (yield (0, server_2.personalize)(request, {
|
|
144
|
-
channel: this.config.
|
|
145
|
-
currency: (_b = this.config.
|
|
153
|
+
channel: this.config.channel || 'WEB',
|
|
154
|
+
currency: (_b = this.config.currency) !== null && _b !== void 0 ? _b : 'USD',
|
|
146
155
|
friendlyId,
|
|
147
156
|
params,
|
|
148
157
|
language,
|
|
@@ -184,7 +193,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
184
193
|
if (variantId.includes('_')) {
|
|
185
194
|
// Component-level personalization in format "<ComponentID>_<VariantID>"
|
|
186
195
|
const componentId = variantId.split('_')[0];
|
|
187
|
-
const friendlyId = personalize_1.CdpHelper.getComponentFriendlyId(personalizeInfo.pageId, componentId, language, this.config.scope
|
|
196
|
+
const friendlyId = personalize_1.CdpHelper.getComponentFriendlyId(personalizeInfo.pageId, componentId, language, this.config.scope);
|
|
188
197
|
const execution = results.find((x) => x.friendlyId === friendlyId);
|
|
189
198
|
if (execution) {
|
|
190
199
|
execution.variantIds.push(variantId);
|
|
@@ -200,7 +209,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
200
209
|
}
|
|
201
210
|
else {
|
|
202
211
|
// Embedded (page-level) personalization in format "<VariantID>"
|
|
203
|
-
const friendlyId = personalize_1.CdpHelper.getPageFriendlyId(personalizeInfo.pageId, language, this.config.scope
|
|
212
|
+
const friendlyId = personalize_1.CdpHelper.getPageFriendlyId(personalizeInfo.pageId, language, this.config.scope);
|
|
204
213
|
const execution = results.find((x) => x.friendlyId === friendlyId);
|
|
205
214
|
if (execution) {
|
|
206
215
|
execution.variantIds.push(variantId);
|
|
@@ -33,6 +33,10 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
33
33
|
super(config);
|
|
34
34
|
this.config = config;
|
|
35
35
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
if (!this.config.enabled) {
|
|
37
|
+
core_1.debug.redirects('skipped (redirects middleware is disabled globally)');
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
36
40
|
try {
|
|
37
41
|
const pathname = req.nextUrl.pathname;
|
|
38
42
|
const language = this.getLanguage(req);
|
|
@@ -44,12 +48,12 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
44
48
|
language,
|
|
45
49
|
hostname,
|
|
46
50
|
});
|
|
51
|
+
if (this.disabled(req, res)) {
|
|
52
|
+
core_1.debug.redirects('skipped (redirects middleware is disabled)');
|
|
53
|
+
return res;
|
|
54
|
+
}
|
|
47
55
|
const createResponse = () => __awaiter(this, void 0, void 0, function* () {
|
|
48
56
|
var _a;
|
|
49
|
-
if (this.disabled(req, res)) {
|
|
50
|
-
core_1.debug.redirects('skipped (redirects middleware is disabled)');
|
|
51
|
-
return res;
|
|
52
|
-
}
|
|
53
57
|
if (this.isPreview(req)) {
|
|
54
58
|
core_1.debug.redirects('skipped (preview)');
|
|
55
59
|
return res;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineConfig, } from '@sitecore-content-sdk/core/config';
|
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { SiteResolver } from '@sitecore-content-sdk/core/site';
|
|
10
11
|
import { debug } from '@sitecore-content-sdk/core';
|
|
11
12
|
import { NextResponse } from 'next/server';
|
|
12
13
|
/**
|
|
@@ -23,6 +24,7 @@ export class MiddlewareBase extends Middleware {
|
|
|
23
24
|
this.config = config;
|
|
24
25
|
this.SITE_SYMBOL = 'sc_site';
|
|
25
26
|
this.REWRITE_HEADER_NAME = 'x-sc-rewrite';
|
|
27
|
+
this.siteResolver = new SiteResolver(config.sites);
|
|
26
28
|
this.defaultHostname = config.defaultHostname || 'localhost';
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
@@ -90,9 +92,9 @@ export class MiddlewareBase extends Middleware {
|
|
|
90
92
|
var _a;
|
|
91
93
|
const siteNameCookie = (_a = res === null || res === void 0 ? void 0 : res.cookies.get(this.SITE_SYMBOL)) === null || _a === void 0 ? void 0 : _a.value;
|
|
92
94
|
if (siteNameCookie)
|
|
93
|
-
return this.
|
|
95
|
+
return this.siteResolver.getByName(siteNameCookie);
|
|
94
96
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
95
|
-
return this.
|
|
97
|
+
return this.siteResolver.getByHost(hostname);
|
|
96
98
|
}
|
|
97
99
|
/**
|
|
98
100
|
* Create a rewrite response
|
|
@@ -22,6 +22,10 @@ export class MultisiteMiddleware extends MiddlewareBase {
|
|
|
22
22
|
this.config = config;
|
|
23
23
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
24
24
|
var _a;
|
|
25
|
+
if (!this.config.enabled) {
|
|
26
|
+
debug.multisite('skipped (multisite middleware is disabled globally)');
|
|
27
|
+
return res;
|
|
28
|
+
}
|
|
25
29
|
try {
|
|
26
30
|
const pathname = req.nextUrl.pathname;
|
|
27
31
|
const language = this.getLanguage(req);
|
|
@@ -45,7 +49,7 @@ export class MultisiteMiddleware extends MiddlewareBase {
|
|
|
45
49
|
(this.config.useCookieResolution &&
|
|
46
50
|
this.config.useCookieResolution(req) &&
|
|
47
51
|
((_a = req.cookies.get(this.SITE_SYMBOL)) === null || _a === void 0 ? void 0 : _a.value)) ||
|
|
48
|
-
this.
|
|
52
|
+
this.siteResolver.getByHost(hostname).name;
|
|
49
53
|
// Rewrite to site specific path
|
|
50
54
|
const rewritePath = getSiteRewrite(pathname, {
|
|
51
55
|
siteName,
|
|
@@ -23,12 +23,16 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
23
23
|
super(config);
|
|
24
24
|
this.config = config;
|
|
25
25
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (!this.config.enabled) {
|
|
27
|
+
debug.personalize('skipped (personalize middleware is disabled globally)');
|
|
28
|
+
return res;
|
|
29
|
+
}
|
|
26
30
|
try {
|
|
27
31
|
const pathname = req.nextUrl.pathname;
|
|
28
32
|
const language = this.getLanguage(req);
|
|
29
33
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
30
34
|
const startTimestamp = Date.now();
|
|
31
|
-
const timeout = this.config.
|
|
35
|
+
const timeout = this.config.cdpTimeout;
|
|
32
36
|
debug.personalize('personalize middleware start: %o', {
|
|
33
37
|
pathname,
|
|
34
38
|
language,
|
|
@@ -118,13 +122,18 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
118
122
|
});
|
|
119
123
|
// NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
|
|
120
124
|
// (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
|
|
121
|
-
this.personalizeService = new GraphQLPersonalizeService(
|
|
125
|
+
this.personalizeService = new GraphQLPersonalizeService({
|
|
126
|
+
clientFactory: this.config.clientFactory,
|
|
127
|
+
timeout: this.config.edgeTimeout,
|
|
128
|
+
scope: this.config.scope,
|
|
129
|
+
fetch: fetch,
|
|
130
|
+
});
|
|
122
131
|
}
|
|
123
132
|
initPersonalizeServer(_a) {
|
|
124
133
|
return __awaiter(this, arguments, void 0, function* ({ hostname, siteName, request, response, }) {
|
|
125
134
|
yield CloudSDK(request, response, {
|
|
126
|
-
sitecoreEdgeUrl: this.config.
|
|
127
|
-
sitecoreEdgeContextId: this.config.
|
|
135
|
+
sitecoreEdgeUrl: this.config.edgeUrl,
|
|
136
|
+
sitecoreEdgeContextId: this.config.contextId,
|
|
128
137
|
siteName,
|
|
129
138
|
cookieDomain: hostname,
|
|
130
139
|
enableServerCookie: true,
|
|
@@ -138,8 +147,8 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
138
147
|
var _b;
|
|
139
148
|
debug.personalize('executing experience for %s %o', friendlyId, params);
|
|
140
149
|
return (yield personalize(request, {
|
|
141
|
-
channel: this.config.
|
|
142
|
-
currency: (_b = this.config.
|
|
150
|
+
channel: this.config.channel || 'WEB',
|
|
151
|
+
currency: (_b = this.config.currency) !== null && _b !== void 0 ? _b : 'USD',
|
|
143
152
|
friendlyId,
|
|
144
153
|
params,
|
|
145
154
|
language,
|
|
@@ -181,7 +190,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
181
190
|
if (variantId.includes('_')) {
|
|
182
191
|
// Component-level personalization in format "<ComponentID>_<VariantID>"
|
|
183
192
|
const componentId = variantId.split('_')[0];
|
|
184
|
-
const friendlyId = CdpHelper.getComponentFriendlyId(personalizeInfo.pageId, componentId, language, this.config.scope
|
|
193
|
+
const friendlyId = CdpHelper.getComponentFriendlyId(personalizeInfo.pageId, componentId, language, this.config.scope);
|
|
185
194
|
const execution = results.find((x) => x.friendlyId === friendlyId);
|
|
186
195
|
if (execution) {
|
|
187
196
|
execution.variantIds.push(variantId);
|
|
@@ -197,7 +206,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
197
206
|
}
|
|
198
207
|
else {
|
|
199
208
|
// Embedded (page-level) personalization in format "<VariantID>"
|
|
200
|
-
const friendlyId = CdpHelper.getPageFriendlyId(personalizeInfo.pageId, language, this.config.scope
|
|
209
|
+
const friendlyId = CdpHelper.getPageFriendlyId(personalizeInfo.pageId, language, this.config.scope);
|
|
201
210
|
const execution = results.find((x) => x.friendlyId === friendlyId);
|
|
202
211
|
if (execution) {
|
|
203
212
|
execution.variantIds.push(variantId);
|
|
@@ -27,6 +27,10 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
27
27
|
super(config);
|
|
28
28
|
this.config = config;
|
|
29
29
|
this.handle = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (!this.config.enabled) {
|
|
31
|
+
debug.redirects('skipped (redirects middleware is disabled globally)');
|
|
32
|
+
return res;
|
|
33
|
+
}
|
|
30
34
|
try {
|
|
31
35
|
const pathname = req.nextUrl.pathname;
|
|
32
36
|
const language = this.getLanguage(req);
|
|
@@ -38,12 +42,12 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
38
42
|
language,
|
|
39
43
|
hostname,
|
|
40
44
|
});
|
|
45
|
+
if (this.disabled(req, res)) {
|
|
46
|
+
debug.redirects('skipped (redirects middleware is disabled)');
|
|
47
|
+
return res;
|
|
48
|
+
}
|
|
41
49
|
const createResponse = () => __awaiter(this, void 0, void 0, function* () {
|
|
42
50
|
var _a;
|
|
43
|
-
if (this.disabled(req, res)) {
|
|
44
|
-
debug.redirects('skipped (redirects middleware is disabled)');
|
|
45
|
-
return res;
|
|
46
|
-
}
|
|
47
51
|
if (this.isPreview(req)) {
|
|
48
52
|
debug.redirects('skipped (preview)');
|
|
49
53
|
return res;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-content-sdk/nextjs",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.8",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -72,9 +72,9 @@
|
|
|
72
72
|
"react-dom": "^18.2.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@sitecore-content-sdk/core": "0.1.0-beta.
|
|
76
|
-
"@sitecore-content-sdk/dev-tools": "0.1.0-beta.
|
|
77
|
-
"@sitecore-content-sdk/react": "0.1.0-beta.
|
|
75
|
+
"@sitecore-content-sdk/core": "0.1.0-beta.8",
|
|
76
|
+
"@sitecore-content-sdk/dev-tools": "0.1.0-beta.8",
|
|
77
|
+
"@sitecore-content-sdk/react": "0.1.0-beta.8",
|
|
78
78
|
"@vercel/kv": "^3.0.0",
|
|
79
79
|
"prop-types": "^15.8.1",
|
|
80
80
|
"regex-parser": "^2.3.0",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
},
|
|
83
83
|
"description": "",
|
|
84
84
|
"types": "types/index.d.ts",
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "53fbb6772abec34c970f67e623e28cba99628d7c",
|
|
86
86
|
"files": [
|
|
87
87
|
"dist",
|
|
88
88
|
"types",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineConfig, SitecoreConfigInput, SitecoreConfig, } from '@sitecore-content-sdk/core/config';
|
|
@@ -15,7 +15,7 @@ export type MiddlewareBaseConfig = {
|
|
|
15
15
|
/**
|
|
16
16
|
* Site resolution implementation by name/hostname
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
sites: SiteInfo[];
|
|
19
19
|
};
|
|
20
20
|
/**
|
|
21
21
|
* Middleware class to be extended by all middleware implementations
|
|
@@ -37,6 +37,7 @@ export declare abstract class MiddlewareBase extends Middleware {
|
|
|
37
37
|
protected SITE_SYMBOL: string;
|
|
38
38
|
protected REWRITE_HEADER_NAME: string;
|
|
39
39
|
protected defaultHostname: string;
|
|
40
|
+
protected siteResolver: SiteResolver;
|
|
40
41
|
constructor(config: MiddlewareBaseConfig);
|
|
41
42
|
/**
|
|
42
43
|
* Determines if mode is preview
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
2
|
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
3
|
+
import { SitecoreConfig } from '../config';
|
|
3
4
|
export type CookieAttributes = {
|
|
4
5
|
/**
|
|
5
6
|
* the Secure attribute of the site cookie
|
|
@@ -14,12 +15,7 @@ export type CookieAttributes = {
|
|
|
14
15
|
*/
|
|
15
16
|
sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined;
|
|
16
17
|
};
|
|
17
|
-
export type MultisiteMiddlewareConfig = MiddlewareBaseConfig &
|
|
18
|
-
/**
|
|
19
|
-
* Function used to determine if site should be resolved from sc_site cookie when present
|
|
20
|
-
*/
|
|
21
|
-
useCookieResolution?: (req: NextRequest) => boolean;
|
|
22
|
-
};
|
|
18
|
+
export type MultisiteMiddlewareConfig = MiddlewareBaseConfig & SitecoreConfig['multisite'];
|
|
23
19
|
/**
|
|
24
20
|
* Middleware / handler for multisite support
|
|
25
21
|
*/
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import {
|
|
2
|
+
import { PersonalizeInfo } from '@sitecore-content-sdk/core/personalize';
|
|
3
|
+
import { GraphQLRequestClientFactory } from '@sitecore-content-sdk/core';
|
|
3
4
|
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
5
|
+
import { SitecoreConfig } from '../config';
|
|
4
6
|
export type CdpServiceConfig = {
|
|
5
7
|
/**
|
|
6
8
|
* Your Sitecore Edge Platform endpoint
|
|
@@ -24,19 +26,8 @@ export type CdpServiceConfig = {
|
|
|
24
26
|
*/
|
|
25
27
|
timeout?: number;
|
|
26
28
|
};
|
|
27
|
-
export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
28
|
-
|
|
29
|
-
* Configuration for your Sitecore Experience Edge endpoint
|
|
30
|
-
*/
|
|
31
|
-
edgeConfig: Omit<GraphQLPersonalizeServiceConfig, 'fetch'>;
|
|
32
|
-
/**
|
|
33
|
-
* Configuration for your Sitecore CDP endpoint
|
|
34
|
-
*/
|
|
35
|
-
cdpConfig: CdpServiceConfig;
|
|
36
|
-
/**
|
|
37
|
-
* Optional Sitecore Personalize scope identifier allowing you to isolate your personalization data between XM Cloud environments
|
|
38
|
-
*/
|
|
39
|
-
scope?: string;
|
|
29
|
+
export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & SitecoreConfig['api']['edge'] & SitecoreConfig['personalize'] & {
|
|
30
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
40
31
|
};
|
|
41
32
|
/**
|
|
42
33
|
* Object model of Experience Context data
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
import { GraphQLRedirectsServiceConfig } from '@sitecore-content-sdk/core/site';
|
|
2
2
|
import { NextRequest, NextResponse } from 'next/server';
|
|
3
3
|
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
4
|
+
import { SitecoreConfig } from '../config';
|
|
4
5
|
/**
|
|
5
6
|
* extended RedirectsMiddlewareConfig config type for RedirectsMiddleware
|
|
6
7
|
*/
|
|
7
|
-
export type RedirectsMiddlewareConfig = Omit<GraphQLRedirectsServiceConfig, 'fetch'> & MiddlewareBaseConfig &
|
|
8
|
-
/**
|
|
9
|
-
* These are all the locales you support in your application.
|
|
10
|
-
* These should match those in your next.config.js (i18n.locales).
|
|
11
|
-
*/
|
|
12
|
-
locales: string[];
|
|
13
|
-
};
|
|
8
|
+
export type RedirectsMiddlewareConfig = Omit<GraphQLRedirectsServiceConfig, 'fetch'> & MiddlewareBaseConfig & SitecoreConfig['redirects'];
|
|
14
9
|
/**
|
|
15
10
|
* Middleware / handler fetches all redirects from Sitecore instance by grapqhl service
|
|
16
11
|
* compares with current url and redirects to target url
|