@sitecore-jss/sitecore-jss-nextjs 21.1.0-canary.99 → 22.0.0-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/NextImage.js +8 -2
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/middleware/index.js +3 -1
- package/dist/cjs/middleware/middleware.js +70 -0
- package/dist/cjs/middleware/multisite-middleware.js +13 -30
- package/dist/cjs/middleware/personalize-middleware.js +14 -40
- package/dist/cjs/middleware/redirects-middleware.js +30 -25
- package/dist/cjs/services/base-graphql-sitemap-service.js +204 -0
- package/dist/cjs/services/graphql-sitemap-service.js +10 -176
- package/dist/cjs/services/mutisite-graphql-sitemap-service.js +81 -0
- package/dist/esm/components/NextImage.js +8 -2
- package/dist/esm/index.js +4 -3
- package/dist/esm/middleware/index.js +1 -0
- package/dist/esm/middleware/middleware.js +66 -0
- package/dist/esm/middleware/multisite-middleware.js +13 -30
- package/dist/esm/middleware/personalize-middleware.js +15 -41
- package/dist/esm/middleware/redirects-middleware.js +30 -25
- package/dist/esm/services/base-graphql-sitemap-service.js +199 -0
- package/dist/esm/services/graphql-sitemap-service.js +9 -175
- package/dist/esm/services/mutisite-graphql-sitemap-service.js +77 -0
- package/package.json +5 -5
- package/types/index.d.ts +4 -3
- package/types/middleware/index.d.ts +1 -0
- package/types/middleware/middleware.d.ts +68 -0
- package/types/middleware/multisite-middleware.d.ts +3 -25
- package/types/middleware/personalize-middleware.d.ts +8 -41
- package/types/middleware/redirects-middleware.d.ts +7 -29
- package/types/services/base-graphql-sitemap-service.d.ts +149 -0
- package/types/services/graphql-sitemap-service.d.ts +7 -103
- package/types/services/mutisite-graphql-sitemap-service.d.ts +42 -0
|
@@ -7,13 +7,10 @@ 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 {
|
|
11
|
-
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
12
|
-
import { getPersonalizedRewrite } from '@sitecore-jss/sitecore-jss/personalize';
|
|
13
|
-
import { getSiteRewrite } from '@sitecore-jss/sitecore-jss/site';
|
|
10
|
+
import { BaseGraphQLSitemapService, } from './base-graphql-sitemap-service';
|
|
14
11
|
/** @private */
|
|
15
12
|
export const languageError = 'The list of languages cannot be empty';
|
|
16
|
-
export const
|
|
13
|
+
export const siteError = 'The service needs a site name';
|
|
17
14
|
/**
|
|
18
15
|
* @param {string} siteName to inject into error text
|
|
19
16
|
* @private
|
|
@@ -21,103 +18,20 @@ export const sitesError = 'The list of sites cannot be empty';
|
|
|
21
18
|
export function getSiteEmptyError(siteName) {
|
|
22
19
|
return `Site "${siteName}" does not exist or site item tree is missing`;
|
|
23
20
|
}
|
|
24
|
-
const languageEmptyError = 'The language must be a non-empty string';
|
|
25
|
-
/**
|
|
26
|
-
* GQL query made dynamic based on schema differences between SXP and XM Cloud
|
|
27
|
-
* @param {boolean} usesPersonalize flag to detrmine which variation of a query to run
|
|
28
|
-
* @returns GraphQL query to fetch site paths with
|
|
29
|
-
*/
|
|
30
|
-
const defaultQuery = (usesPersonalize) => /* GraphQL */ `
|
|
31
|
-
query ${usesPersonalize ? 'PersonalizeSitemapQuery' : 'DefaultSitemapQuery'}(
|
|
32
|
-
$siteName: String!
|
|
33
|
-
$language: String!
|
|
34
|
-
$includedPaths: [String]
|
|
35
|
-
$excludedPaths: [String]
|
|
36
|
-
$pageSize: Int = 10
|
|
37
|
-
$after: String
|
|
38
|
-
) {
|
|
39
|
-
site {
|
|
40
|
-
siteInfo(site: $siteName) {
|
|
41
|
-
routes(
|
|
42
|
-
language: $language
|
|
43
|
-
includedPaths: $includedPaths
|
|
44
|
-
excludedPaths: $excludedPaths
|
|
45
|
-
first: $pageSize
|
|
46
|
-
after: $after
|
|
47
|
-
){
|
|
48
|
-
total
|
|
49
|
-
pageInfo {
|
|
50
|
-
endCursor
|
|
51
|
-
hasNext
|
|
52
|
-
}
|
|
53
|
-
results {
|
|
54
|
-
path: routePath
|
|
55
|
-
${usesPersonalize
|
|
56
|
-
? `
|
|
57
|
-
route {
|
|
58
|
-
personalization {
|
|
59
|
-
variantIds
|
|
60
|
-
}
|
|
61
|
-
}`
|
|
62
|
-
: ''}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
69
21
|
/**
|
|
70
22
|
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
23
|
+
* Used to handle a single site
|
|
71
24
|
* This list is used for SSG and Export functionality.
|
|
72
25
|
* @mixes SearchQueryService<PageListQueryResult>
|
|
73
26
|
*/
|
|
74
|
-
export class GraphQLSitemapService {
|
|
75
|
-
/**
|
|
76
|
-
* Gets the default query used for fetching the list of site pages
|
|
77
|
-
*/
|
|
78
|
-
get query() {
|
|
79
|
-
return defaultQuery(this.options.includePersonalizedRoutes);
|
|
80
|
-
}
|
|
27
|
+
export class GraphQLSitemapService extends BaseGraphQLSitemapService {
|
|
81
28
|
/**
|
|
82
29
|
* Creates an instance of graphQL sitemap service with the provided options
|
|
83
30
|
* @param {GraphQLSitemapServiceConfig} options instance
|
|
84
31
|
*/
|
|
85
32
|
constructor(options) {
|
|
33
|
+
super(options);
|
|
86
34
|
this.options = options;
|
|
87
|
-
this.graphQLClient = this.getGraphQLClient();
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Fetch sitemap which could be used for generation of static pages during `next export`.
|
|
91
|
-
* The `locale` parameter will be used in the item query, but since i18n is not supported,
|
|
92
|
-
* the output paths will not include a `language` property.
|
|
93
|
-
* @param {string} locale which application supports
|
|
94
|
-
* @returns an array of @see StaticPath objects
|
|
95
|
-
*/
|
|
96
|
-
fetchExportSitemap(locale) {
|
|
97
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const formatPath = (path) => ({
|
|
99
|
-
params: {
|
|
100
|
-
path,
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
return this.fetchSitemap([locale], formatPath);
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Fetch sitemap which could be used for generation of static pages using SSG mode
|
|
108
|
-
* @param {string[]} locales locales which application supports
|
|
109
|
-
* @returns an array of @see StaticPath objects
|
|
110
|
-
*/
|
|
111
|
-
fetchSSGSitemap(locales) {
|
|
112
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
-
const formatPath = (path, locale) => ({
|
|
114
|
-
params: {
|
|
115
|
-
path,
|
|
116
|
-
},
|
|
117
|
-
locale,
|
|
118
|
-
});
|
|
119
|
-
return this.fetchSitemap(locales, formatPath);
|
|
120
|
-
});
|
|
121
35
|
}
|
|
122
36
|
/**
|
|
123
37
|
* Fetch a flat list of all pages that belong to the specificed site and have a
|
|
@@ -134,92 +48,12 @@ export class GraphQLSitemapService {
|
|
|
134
48
|
if (!languages.length) {
|
|
135
49
|
throw new RangeError(languageError);
|
|
136
50
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
throw new RangeError(sitesError);
|
|
141
|
-
}
|
|
142
|
-
// Fetch paths for each site
|
|
143
|
-
for (let i = 0; i < sites.length; i++) {
|
|
144
|
-
const siteName = sites[i];
|
|
145
|
-
const multiSiteName = sites.length > 1 ? siteName : undefined;
|
|
146
|
-
// Fetch paths using all locales
|
|
147
|
-
yield Promise.all(languages.map((language) => __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
if (language === '') {
|
|
149
|
-
throw new RangeError(languageEmptyError);
|
|
150
|
-
}
|
|
151
|
-
debug.sitemap('fetching sitemap data for %s %s', language, siteName);
|
|
152
|
-
const results = yield this.fetchLanguageSitePaths(language, siteName);
|
|
153
|
-
const transformedPaths = yield this.transformLanguageSitePaths(results, formatStaticPath, language, multiSiteName);
|
|
154
|
-
paths.push(...transformedPaths);
|
|
155
|
-
})));
|
|
51
|
+
const siteName = this.options.siteName;
|
|
52
|
+
if (!siteName) {
|
|
53
|
+
throw new RangeError(siteError);
|
|
156
54
|
}
|
|
55
|
+
paths.push(...(yield this.getTranformedPaths(siteName, languages, formatStaticPath)));
|
|
157
56
|
return [].concat(...paths);
|
|
158
57
|
});
|
|
159
58
|
}
|
|
160
|
-
transformLanguageSitePaths(sitePaths, formatStaticPath, language, multiSiteName) {
|
|
161
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
-
const formatPath = (path) => formatStaticPath(path.replace(/^\/|\/$/g, '').split('/'), language);
|
|
163
|
-
const aggregatedPaths = [];
|
|
164
|
-
sitePaths.forEach((item) => {
|
|
165
|
-
var _a, _b, _c, _d, _e, _f;
|
|
166
|
-
if (!item)
|
|
167
|
-
return;
|
|
168
|
-
if (!multiSiteName) {
|
|
169
|
-
aggregatedPaths.push(formatPath(item.path));
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
aggregatedPaths.push(formatPath(getSiteRewrite(item.path, { siteName: multiSiteName })));
|
|
173
|
-
}
|
|
174
|
-
// check for type safety's sake - personalize may be empty depending on query type
|
|
175
|
-
if ((_b = (_a = item.route) === null || _a === void 0 ? void 0 : _a.personalization) === null || _b === void 0 ? void 0 : _b.variantIds.length) {
|
|
176
|
-
multiSiteName
|
|
177
|
-
? aggregatedPaths.push(...(((_d = (_c = item.route) === null || _c === void 0 ? void 0 : _c.personalization) === null || _d === void 0 ? void 0 : _d.variantIds.map((varId) => formatPath(getPersonalizedRewrite(getSiteRewrite(item.path, { siteName: multiSiteName }), {
|
|
178
|
-
variantId: varId,
|
|
179
|
-
})))) || {}))
|
|
180
|
-
: aggregatedPaths.push(...(((_f = (_e = item.route) === null || _e === void 0 ? void 0 : _e.personalization) === null || _f === void 0 ? void 0 : _f.variantIds.map((varId) => formatPath(getPersonalizedRewrite(item.path, { variantId: varId })))) || {}));
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
return aggregatedPaths;
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
fetchLanguageSitePaths(language, siteName) {
|
|
187
|
-
var _a, _b, _c, _d;
|
|
188
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
-
const args = {
|
|
190
|
-
siteName: siteName,
|
|
191
|
-
language: language,
|
|
192
|
-
pageSize: this.options.pageSize,
|
|
193
|
-
includedPaths: this.options.includedPaths,
|
|
194
|
-
excludedPaths: this.options.excludedPaths,
|
|
195
|
-
};
|
|
196
|
-
let results = [];
|
|
197
|
-
let hasNext = true;
|
|
198
|
-
let after = '';
|
|
199
|
-
while (hasNext) {
|
|
200
|
-
const fetchResponse = yield this.graphQLClient.request(this.query, Object.assign(Object.assign({}, args), { after }));
|
|
201
|
-
if (!((_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.site) === null || _a === void 0 ? void 0 : _a.siteInfo)) {
|
|
202
|
-
throw new RangeError(getSiteEmptyError(siteName));
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
results = results.concat((_b = fetchResponse.site.siteInfo.routes) === null || _b === void 0 ? void 0 : _b.results);
|
|
206
|
-
hasNext = (_c = fetchResponse.site.siteInfo.routes) === null || _c === void 0 ? void 0 : _c.pageInfo.hasNext;
|
|
207
|
-
after = (_d = fetchResponse.site.siteInfo.routes) === null || _d === void 0 ? void 0 : _d.pageInfo.endCursor;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return results;
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
215
|
-
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
216
|
-
* want to use something else.
|
|
217
|
-
* @returns {GraphQLClient} implementation
|
|
218
|
-
*/
|
|
219
|
-
getGraphQLClient() {
|
|
220
|
-
return new GraphQLRequestClient(this.options.endpoint, {
|
|
221
|
-
apiKey: this.options.apiKey,
|
|
222
|
-
debugger: debug.sitemap,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
59
|
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
import { getSiteRewrite } from '@sitecore-jss/sitecore-jss/site';
|
|
11
|
+
import { BaseGraphQLSitemapService, languageError, } from './base-graphql-sitemap-service';
|
|
12
|
+
export const sitesError = 'The list of sites cannot be empty';
|
|
13
|
+
/**
|
|
14
|
+
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
15
|
+
* Used to handle multiple sites
|
|
16
|
+
* This list is used for SSG and Export functionality.
|
|
17
|
+
* @mixes SearchQueryService<PageListQueryResult>
|
|
18
|
+
*/
|
|
19
|
+
export class MultisiteGraphQLSitemapService extends BaseGraphQLSitemapService {
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
22
|
+
* @param {MultisiteGraphQLSitemapServiceConfig} options instance
|
|
23
|
+
*/
|
|
24
|
+
constructor(options) {
|
|
25
|
+
super(options);
|
|
26
|
+
this.options = options;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Fetch a flat list of all pages that belong to all the requested sites and have a
|
|
30
|
+
* version in the specified language(s).
|
|
31
|
+
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
32
|
+
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
33
|
+
* @returns list of pages
|
|
34
|
+
* @throws {RangeError} if the list of languages is empty.
|
|
35
|
+
* @throws {RangeError} if the any of the languages is an empty string.
|
|
36
|
+
*/
|
|
37
|
+
fetchSitemap(languages, formatStaticPath) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
const paths = new Array();
|
|
40
|
+
if (!languages.length) {
|
|
41
|
+
throw new RangeError(languageError);
|
|
42
|
+
}
|
|
43
|
+
// Get all sites
|
|
44
|
+
const sites = this.options.sites;
|
|
45
|
+
if (!sites || !sites.length) {
|
|
46
|
+
throw new RangeError(sitesError);
|
|
47
|
+
}
|
|
48
|
+
// Fetch paths for each site
|
|
49
|
+
for (let i = 0; i < sites.length; i++) {
|
|
50
|
+
const siteName = sites[i];
|
|
51
|
+
// Fetch paths using all locales
|
|
52
|
+
paths.push(...(yield this.getTranformedPaths(siteName, languages, formatStaticPath)));
|
|
53
|
+
}
|
|
54
|
+
return [].concat(...paths);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Fetch and return site paths for multisite implementation, with prefixes included
|
|
59
|
+
* @param {string} language path language
|
|
60
|
+
* @param {string} siteName site name
|
|
61
|
+
* @returns modified paths
|
|
62
|
+
*/
|
|
63
|
+
fetchLanguageSitePaths(language, siteName) {
|
|
64
|
+
const _super = Object.create(null, {
|
|
65
|
+
fetchLanguageSitePaths: { get: () => super.fetchLanguageSitePaths }
|
|
66
|
+
});
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const results = yield _super.fetchLanguageSitePaths.call(this, language, siteName);
|
|
69
|
+
results.forEach((item) => {
|
|
70
|
+
if (item) {
|
|
71
|
+
item.path = getSiteRewrite(item.path, { siteName: siteName });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
return results;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "22.0.0-canary.1",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"react-dom": "^18.2.0"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@sitecore-jss/sitecore-jss": "^
|
|
74
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^
|
|
75
|
-
"@sitecore-jss/sitecore-jss-react": "^
|
|
73
|
+
"@sitecore-jss/sitecore-jss": "^22.0.0-canary.1",
|
|
74
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^22.0.0-canary.1",
|
|
75
|
+
"@sitecore-jss/sitecore-jss-react": "^22.0.0-canary.1",
|
|
76
76
|
"node-html-parser": "^6.1.4",
|
|
77
77
|
"prop-types": "^15.8.1",
|
|
78
78
|
"regex-parser": "^2.2.11",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
},
|
|
81
81
|
"description": "",
|
|
82
82
|
"types": "types/index.d.ts",
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "8f7ef1bee3508c70baae3c3b583908395609be52",
|
|
84
84
|
"files": [
|
|
85
85
|
"dist",
|
|
86
86
|
"types",
|
package/types/index.d.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
export { constants, HttpDataFetcher, HttpResponse, AxiosResponse, AxiosDataFetcher, AxiosDataFetcherConfig, NativeDataFetcher, NativeDataFetcherConfig, enableDebug, } from '@sitecore-jss/sitecore-jss';
|
|
2
|
-
export { isEditorActive, resetEditorChromes, resolveUrl } from '@sitecore-jss/sitecore-jss/utils';
|
|
2
|
+
export { isEditorActive, resetEditorChromes, resolveUrl, tryParseEnvValue, } from '@sitecore-jss/sitecore-jss/utils';
|
|
3
3
|
export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, RestLayoutService, RestLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
4
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
5
5
|
export { trackingApi, TrackingRequestOptions, CampaignInstance, GoalInstance, OutcomeInstance, EventInstance, PageViewInstance, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
6
6
|
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQLDictionaryServiceConfig, RestDictionaryService, RestDictionaryServiceConfig, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
7
|
-
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
7
|
+
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, PosResolver, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
8
8
|
export { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss';
|
|
9
9
|
export { ComponentPropsCollection, GetStaticComponentProps, GetServerSideComponentProps, } from './sharedTypes/component-props';
|
|
10
10
|
export { ComponentModule } from './sharedTypes/component-module';
|
|
11
11
|
export { ComponentPropsService } from './services/component-props-service';
|
|
12
12
|
export { DisconnectedSitemapService } from './services/disconnected-sitemap-service';
|
|
13
13
|
export { GraphQLSitemapService, GraphQLSitemapServiceConfig, } from './services/graphql-sitemap-service';
|
|
14
|
+
export { MultisiteGraphQLSitemapService, MultisiteGraphQLSitemapServiceConfig, } from './services/mutisite-graphql-sitemap-service';
|
|
14
15
|
export { GraphQLSitemapXmlService, GraphQLSitemapXmlServiceConfig, GraphQLErrorPagesService, GraphQLErrorPagesServiceConfig, RobotsQueryResult, GraphQLRobotsService, GraphQLRobotsServiceConfig, ErrorPages, SiteInfo, SiteResolver, GraphQLSiteInfoService, GraphQLSiteInfoServiceConfig, getSiteRewrite, getSiteRewriteData, normalizeSiteRewrite, } from '@sitecore-jss/sitecore-jss/site';
|
|
15
16
|
export { StaticPath } from './services/graphql-sitemap-service';
|
|
16
17
|
export { ComponentPropsReactContext, ComponentPropsContextProps, ComponentPropsContext, useComponentProps, } from './components/ComponentPropsContext';
|
|
@@ -20,4 +21,4 @@ export { RichText, RichTextProps } from './components/RichText';
|
|
|
20
21
|
export { Placeholder } from './components/Placeholder';
|
|
21
22
|
export { EditingComponentPlaceholder } from './components/EditingComponentPlaceholder';
|
|
22
23
|
export { NextImage } from './components/NextImage';
|
|
23
|
-
export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, FEaaSComponent, FEaaSComponentProps, File, FileField, RichTextField, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, } from '@sitecore-jss/sitecore-jss-react';
|
|
24
|
+
export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, File, FileField, RichTextField, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -2,3 +2,4 @@ export { RedirectsMiddleware, RedirectsMiddlewareConfig } from './redirects-midd
|
|
|
2
2
|
export { PersonalizeMiddleware, PersonalizeMiddlewareConfig } from './personalize-middleware';
|
|
3
3
|
export { MultisiteMiddleware, MultisiteMiddlewareConfig } from './multisite-middleware';
|
|
4
4
|
export { SiteResolver, SiteInfo } from '@sitecore-jss/sitecore-jss/site';
|
|
5
|
+
export { tryParseEnvValue } from '@sitecore-jss/sitecore-jss/utils';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { SiteInfo, SiteResolver } from '@sitecore-jss/sitecore-jss/site';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
export type MiddlewareBaseConfig = {
|
|
4
|
+
/**
|
|
5
|
+
* function, determines if middleware should be turned off, based on cookie, header, or other considerations
|
|
6
|
+
* @param {NextRequest} [req] request object from middleware handler
|
|
7
|
+
* @param {NextResponse} [res] response object from middleware handler
|
|
8
|
+
*/
|
|
9
|
+
disabled?: (req?: NextRequest, res?: NextResponse) => boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Function used to determine if route should be excluded.
|
|
12
|
+
* By default, files (pathname.includes('.')), Next.js API routes (pathname.startsWith('/api/')), and Sitecore API routes (pathname.startsWith('/sitecore/')) are ignored.
|
|
13
|
+
* This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
14
|
+
* @param {string} pathname The pathname
|
|
15
|
+
* @returns {boolean} Whether to exclude the route
|
|
16
|
+
*/
|
|
17
|
+
excludeRoute?: (pathname: string) => boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Fallback hostname in case `host` header is not present
|
|
20
|
+
* @default localhost
|
|
21
|
+
*/
|
|
22
|
+
defaultHostname?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Site resolution implementation by name/hostname
|
|
25
|
+
*/
|
|
26
|
+
siteResolver: SiteResolver;
|
|
27
|
+
};
|
|
28
|
+
export declare abstract class MiddlewareBase {
|
|
29
|
+
protected config: MiddlewareBaseConfig;
|
|
30
|
+
protected SITE_SYMBOL: string;
|
|
31
|
+
protected defaultHostname: string;
|
|
32
|
+
constructor(config: MiddlewareBaseConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Determines if mode is preview
|
|
35
|
+
* @param {NextRequest} req request
|
|
36
|
+
* @returns {boolean} is preview
|
|
37
|
+
*/
|
|
38
|
+
protected isPreview(req: NextRequest): boolean;
|
|
39
|
+
protected excludeRoute(pathname: string): boolean | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Safely extract all headers for debug logging
|
|
42
|
+
* Necessary to avoid middleware issue https://github.com/vercel/next.js/issues/39765
|
|
43
|
+
* @param {Headers} incomingHeaders Incoming headers
|
|
44
|
+
* @returns Object with headers as key/value pairs
|
|
45
|
+
*/
|
|
46
|
+
protected extractDebugHeaders(incomingHeaders: Headers): {
|
|
47
|
+
[key: string]: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Provides used language
|
|
51
|
+
* @param {NextRequest} req request
|
|
52
|
+
* @returns {string} language
|
|
53
|
+
*/
|
|
54
|
+
protected getLanguage(req: NextRequest): string;
|
|
55
|
+
/**
|
|
56
|
+
* Extract 'host' header
|
|
57
|
+
* @param {NextRequest} req request
|
|
58
|
+
*/
|
|
59
|
+
protected getHostHeader(req: NextRequest): string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Get site information.
|
|
62
|
+
* Can not be used in **Preview** mode, since site will not be resolved
|
|
63
|
+
* @param {NextRequest} req request
|
|
64
|
+
* @param {NextResponse} [res] response
|
|
65
|
+
* @returns {SiteInfo} site information
|
|
66
|
+
*/
|
|
67
|
+
protected getSite(req: NextRequest, res?: NextResponse): SiteInfo;
|
|
68
|
+
}
|
|
@@ -1,23 +1,6 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import {
|
|
3
|
-
export type MultisiteMiddlewareConfig = {
|
|
4
|
-
/**
|
|
5
|
-
* Function used to determine if route should be excluded during execution.
|
|
6
|
-
* By default, files (pathname.includes('.')), Next.js API routes (pathname.startsWith('/api/')), and Sitecore API routes (pathname.startsWith('/sitecore/')) are ignored.
|
|
7
|
-
* This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
8
|
-
* @param {string} pathname The pathname
|
|
9
|
-
* @returns {boolean} Whether to exclude the route
|
|
10
|
-
*/
|
|
11
|
-
excludeRoute?: (pathname: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* Function used to resolve site for given hostname
|
|
14
|
-
*/
|
|
15
|
-
getSite: (hostname: string) => SiteInfo;
|
|
16
|
-
/**
|
|
17
|
-
* Fallback hostname in case `host` header is not present
|
|
18
|
-
* @default localhost
|
|
19
|
-
*/
|
|
20
|
-
defaultHostname?: string;
|
|
2
|
+
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
3
|
+
export type MultisiteMiddlewareConfig = Omit<MiddlewareBaseConfig, 'disabled'> & {
|
|
21
4
|
/**
|
|
22
5
|
* Function used to determine if site should be resolved from sc_site cookie when present
|
|
23
6
|
*/
|
|
@@ -26,9 +9,8 @@ export type MultisiteMiddlewareConfig = {
|
|
|
26
9
|
/**
|
|
27
10
|
* Middleware / handler for multisite support
|
|
28
11
|
*/
|
|
29
|
-
export declare class MultisiteMiddleware {
|
|
12
|
+
export declare class MultisiteMiddleware extends MiddlewareBase {
|
|
30
13
|
protected config: MultisiteMiddlewareConfig;
|
|
31
|
-
private defaultHostname;
|
|
32
14
|
/**
|
|
33
15
|
* @param {MultisiteMiddlewareConfig} [config] Multisite middleware config
|
|
34
16
|
*/
|
|
@@ -38,9 +20,5 @@ export declare class MultisiteMiddleware {
|
|
|
38
20
|
* @returns middleware handler
|
|
39
21
|
*/
|
|
40
22
|
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
41
|
-
protected excludeRoute(pathname: string): boolean;
|
|
42
|
-
protected extractDebugHeaders(incomingHeaders: Headers): {
|
|
43
|
-
[key: string]: string;
|
|
44
|
-
};
|
|
45
23
|
private handler;
|
|
46
24
|
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
2
|
import { GraphQLPersonalizeServiceConfig, CdpServiceConfig, ExperienceParams } from '@sitecore-jss/sitecore-jss/personalize';
|
|
3
|
+
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
3
4
|
import { SiteInfo } from '@sitecore-jss/sitecore-jss/site';
|
|
4
|
-
export type PersonalizeMiddlewareConfig = {
|
|
5
|
-
/**
|
|
6
|
-
* Function used to determine if route should be excluded from personalization.
|
|
7
|
-
* By default, files (pathname.includes('.')), Next.js API routes (pathname.startsWith('/api/')), and Sitecore API routes (pathname.startsWith('/sitecore/')) are ignored.
|
|
8
|
-
* This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
9
|
-
* @param {string} pathname The pathname
|
|
10
|
-
* @returns {boolean} Whether to exclude the route from personalization
|
|
11
|
-
*/
|
|
12
|
-
excludeRoute?: (pathname: string) => boolean;
|
|
5
|
+
export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
13
6
|
/**
|
|
14
7
|
* Configuration for your Sitecore Experience Edge endpoint
|
|
15
8
|
*/
|
|
@@ -19,35 +12,20 @@ export type PersonalizeMiddlewareConfig = {
|
|
|
19
12
|
*/
|
|
20
13
|
cdpConfig: Omit<CdpServiceConfig, 'dataFetcherResolver'>;
|
|
21
14
|
/**
|
|
22
|
-
* function
|
|
23
|
-
* @param {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* function, determines if middleware should be turned off, based on cookie, header, or other considerations
|
|
28
|
-
* @param {NextRequest} [req] optional: request object from middleware handler
|
|
29
|
-
* @param {NextResponse} [res] optional: response object from middleware handler
|
|
30
|
-
* @returns {boolean} false by default
|
|
31
|
-
*/
|
|
32
|
-
disabled?: (req?: NextRequest, res?: NextResponse) => boolean;
|
|
33
|
-
/**
|
|
34
|
-
* function used to resolve site for given hostname
|
|
35
|
-
*/
|
|
36
|
-
getSite: (hostname: string) => SiteInfo;
|
|
37
|
-
/**
|
|
38
|
-
* fallback hostname in case `host` header is not present
|
|
39
|
-
* @default localhost
|
|
15
|
+
* function to resolve point of sale for a site
|
|
16
|
+
* @param {Siteinfo} site to get info from
|
|
17
|
+
* @param {string} language to get info for
|
|
18
|
+
* @returns point of sale value for site/language combination
|
|
40
19
|
*/
|
|
41
|
-
|
|
20
|
+
getPointOfSale?: (site: SiteInfo, language: string) => string;
|
|
42
21
|
};
|
|
43
22
|
/**
|
|
44
23
|
* Middleware / handler to support Sitecore Personalize
|
|
45
24
|
*/
|
|
46
|
-
export declare class PersonalizeMiddleware {
|
|
25
|
+
export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
47
26
|
protected config: PersonalizeMiddlewareConfig;
|
|
48
27
|
private personalizeService;
|
|
49
28
|
private cdpService;
|
|
50
|
-
private defaultHostname;
|
|
51
29
|
/**
|
|
52
30
|
* @param {PersonalizeMiddlewareConfig} [config] Personalize middleware config
|
|
53
31
|
*/
|
|
@@ -61,16 +39,5 @@ export declare class PersonalizeMiddleware {
|
|
|
61
39
|
protected getBrowserId(req: NextRequest): string | undefined;
|
|
62
40
|
protected setBrowserId(res: NextResponse, browserId: string): void;
|
|
63
41
|
protected getExperienceParams(req: NextRequest): ExperienceParams;
|
|
64
|
-
protected excludeRoute(pathname: string): boolean;
|
|
65
|
-
protected isPreview(req: NextRequest): string | undefined;
|
|
66
|
-
/**
|
|
67
|
-
* Safely extract all headers for debug logging
|
|
68
|
-
* Necessary to avoid middleware issue https://github.com/vercel/next.js/issues/39765
|
|
69
|
-
* @param {Headers} incomingHeaders Incoming headers
|
|
70
|
-
* @returns Object with headers as key/value pairs
|
|
71
|
-
*/
|
|
72
|
-
protected extractDebugHeaders(incomingHeaders: Headers): {
|
|
73
|
-
[key: string]: string;
|
|
74
|
-
};
|
|
75
42
|
private handler;
|
|
76
43
|
}
|
|
@@ -1,44 +1,24 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import { GraphQLRedirectsServiceConfig
|
|
2
|
+
import { GraphQLRedirectsServiceConfig } from '@sitecore-jss/sitecore-jss/site';
|
|
3
|
+
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
3
4
|
/**
|
|
4
5
|
* extended RedirectsMiddlewareConfig config type for RedirectsMiddleware
|
|
5
6
|
*/
|
|
6
|
-
export type RedirectsMiddlewareConfig = Omit<GraphQLRedirectsServiceConfig, 'fetch'> & {
|
|
7
|
-
locales: string[];
|
|
8
|
-
/**
|
|
9
|
-
* Function used to determine if route should be excluded from RedirectsMiddleware.
|
|
10
|
-
* By default, files (pathname.includes('.')), Next.js API routes (pathname.startsWith('/api/')), and Sitecore API routes (pathname.startsWith('/sitecore/')) are ignored.
|
|
11
|
-
* This is an important performance consideration since Next.js Edge middleware runs on every request.
|
|
12
|
-
* @param {string} pathname The pathname
|
|
13
|
-
* @returns {boolean} Whether to exclude the route from RedirectsMiddleware
|
|
14
|
-
*/
|
|
15
|
-
excludeRoute?: (pathname: string) => boolean;
|
|
16
|
-
/**
|
|
17
|
-
* function, determines if middleware should be turned off, based on cookie, header, or other considerations
|
|
18
|
-
* @param {NextRequest} [req] optional: request object from middleware handler
|
|
19
|
-
* @param {NextResponse} [res] optional: response object from middleware handler
|
|
20
|
-
* @returns {boolean} false by default
|
|
21
|
-
*/
|
|
22
|
-
disabled?: (req?: NextRequest, res?: NextResponse) => boolean;
|
|
23
|
-
/**
|
|
24
|
-
* function used to resolve site for given hostname
|
|
25
|
-
*/
|
|
26
|
-
getSite: (hostname: string) => SiteInfo;
|
|
7
|
+
export type RedirectsMiddlewareConfig = Omit<GraphQLRedirectsServiceConfig, 'fetch'> & MiddlewareBaseConfig & {
|
|
27
8
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
9
|
+
* These are all the locales you support in your application.
|
|
10
|
+
* These should match those in your next.config.js (i18n.locales).
|
|
30
11
|
*/
|
|
31
|
-
|
|
12
|
+
locales: string[];
|
|
32
13
|
};
|
|
33
14
|
/**
|
|
34
15
|
* Middleware / handler fetches all redirects from Sitecore instance by grapqhl service
|
|
35
16
|
* compares with current url and redirects to target url
|
|
36
17
|
*/
|
|
37
|
-
export declare class RedirectsMiddleware {
|
|
18
|
+
export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
38
19
|
protected config: RedirectsMiddlewareConfig;
|
|
39
20
|
private redirectsService;
|
|
40
21
|
private locales;
|
|
41
|
-
private defaultHostname;
|
|
42
22
|
/**
|
|
43
23
|
* @param {RedirectsMiddlewareConfig} [config] redirects middleware config
|
|
44
24
|
*/
|
|
@@ -48,8 +28,6 @@ export declare class RedirectsMiddleware {
|
|
|
48
28
|
* @returns route handler
|
|
49
29
|
*/
|
|
50
30
|
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
51
|
-
protected excludeRoute(pathname: string): boolean;
|
|
52
|
-
protected getHostname(req: NextRequest): string;
|
|
53
31
|
private handler;
|
|
54
32
|
/**
|
|
55
33
|
* Method returns RedirectInfo when matches
|