@sitecore-jss/sitecore-jss-nextjs 21.1.0-canary.99 → 21.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/LICENSE.txt +202 -202
  2. package/README.md +10 -10
  3. package/dist/cjs/components/NextImage.js +8 -2
  4. package/dist/cjs/index.js +7 -2
  5. package/dist/cjs/middleware/index.js +3 -1
  6. package/dist/cjs/middleware/middleware.js +70 -0
  7. package/dist/cjs/middleware/multisite-middleware.js +13 -30
  8. package/dist/cjs/middleware/personalize-middleware.js +14 -40
  9. package/dist/cjs/middleware/redirects-middleware.js +30 -25
  10. package/dist/cjs/services/base-graphql-sitemap-service.js +204 -0
  11. package/dist/cjs/services/graphql-sitemap-service.js +10 -176
  12. package/dist/cjs/services/mutisite-graphql-sitemap-service.js +81 -0
  13. package/dist/esm/components/NextImage.js +8 -2
  14. package/dist/esm/index.js +4 -3
  15. package/dist/esm/middleware/index.js +1 -0
  16. package/dist/esm/middleware/middleware.js +66 -0
  17. package/dist/esm/middleware/multisite-middleware.js +13 -30
  18. package/dist/esm/middleware/personalize-middleware.js +15 -41
  19. package/dist/esm/middleware/redirects-middleware.js +30 -25
  20. package/dist/esm/services/base-graphql-sitemap-service.js +199 -0
  21. package/dist/esm/services/graphql-sitemap-service.js +9 -175
  22. package/dist/esm/services/mutisite-graphql-sitemap-service.js +77 -0
  23. package/package.json +5 -5
  24. package/types/index.d.ts +4 -3
  25. package/types/middleware/index.d.ts +1 -0
  26. package/types/middleware/middleware.d.ts +68 -0
  27. package/types/middleware/multisite-middleware.d.ts +3 -25
  28. package/types/middleware/personalize-middleware.d.ts +8 -41
  29. package/types/middleware/redirects-middleware.d.ts +7 -29
  30. package/types/services/base-graphql-sitemap-service.d.ts +149 -0
  31. package/types/services/graphql-sitemap-service.d.ts +7 -103
  32. package/types/services/mutisite-graphql-sitemap-service.d.ts +42 -0
@@ -10,29 +10,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import regexParser from 'regex-parser';
11
11
  import { NextResponse } from 'next/server';
12
12
  import { GraphQLRedirectsService, REDIRECT_TYPE_301, REDIRECT_TYPE_302, REDIRECT_TYPE_SERVER_TRANSFER, } from '@sitecore-jss/sitecore-jss/site';
13
+ import { debug } from '@sitecore-jss/sitecore-jss';
14
+ import { MiddlewareBase } from './middleware';
13
15
  /**
14
16
  * Middleware / handler fetches all redirects from Sitecore instance by grapqhl service
15
17
  * compares with current url and redirects to target url
16
18
  */
17
- export class RedirectsMiddleware {
19
+ export class RedirectsMiddleware extends MiddlewareBase {
18
20
  /**
19
21
  * @param {RedirectsMiddlewareConfig} [config] redirects middleware config
20
22
  */
21
23
  constructor(config) {
24
+ super(config);
22
25
  this.config = config;
23
26
  this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
24
- var _a;
25
- const hostname = this.getHostname(req);
26
- const siteName = ((_a = res === null || res === void 0 ? void 0 : res.cookies.get('sc_site')) === null || _a === void 0 ? void 0 : _a.value) || this.config.getSite(hostname).name;
27
+ const pathname = req.nextUrl.pathname;
28
+ const language = this.getLanguage(req);
29
+ const hostname = this.getHostHeader(req) || this.defaultHostname;
30
+ let site;
31
+ debug.redirects('redirects middleware start: %o', {
32
+ pathname,
33
+ language,
34
+ hostname,
35
+ });
27
36
  const createResponse = () => __awaiter(this, void 0, void 0, function* () {
28
- if ((this.config.disabled && this.config.disabled(req, NextResponse.next())) ||
29
- this.excludeRoute(req.nextUrl.pathname) ||
30
- (this.config.excludeRoute && this.config.excludeRoute(req.nextUrl.pathname))) {
37
+ if (this.config.disabled && this.config.disabled(req, NextResponse.next())) {
38
+ debug.redirects('skipped (redirects middleware is disabled)');
39
+ return res || NextResponse.next();
40
+ }
41
+ if (this.isPreview(req) || this.excludeRoute(pathname)) {
42
+ debug.redirects('skipped (%s)', this.isPreview(req) ? 'preview' : 'route excluded');
31
43
  return res || NextResponse.next();
32
44
  }
45
+ site = this.getSite(req, res);
33
46
  // Find the redirect from result of RedirectService
34
- const existsRedirect = yield this.getExistsRedirect(req, siteName);
47
+ const existsRedirect = yield this.getExistsRedirect(req, site.name);
35
48
  if (!existsRedirect) {
49
+ debug.redirects('skipped (redirect does not exist)');
36
50
  return res || NextResponse.next();
37
51
  }
38
52
  const url = req.nextUrl.clone();
@@ -67,14 +81,20 @@ export class RedirectsMiddleware {
67
81
  });
68
82
  const response = yield createResponse();
69
83
  // Share site name with the following executed middlewares
70
- response.cookies.set('sc_site', siteName);
84
+ // Don't need to set when middleware is disabled
85
+ site && response.cookies.set(this.SITE_SYMBOL, site.name);
86
+ debug.redirects('redirects middleware end: %o', {
87
+ redirected: response.redirected,
88
+ status: response.status,
89
+ url: response.url,
90
+ headers: this.extractDebugHeaders(response.headers),
91
+ });
71
92
  return response;
72
93
  });
73
94
  // NOTE: we provide native fetch for compatibility on Next.js Edge Runtime
74
95
  // (underlying default 'cross-fetch' is not currently compatible: https://github.com/lquixada/cross-fetch/issues/78)
75
96
  this.redirectsService = new GraphQLRedirectsService(Object.assign(Object.assign({}, config), { fetch: fetch }));
76
97
  this.locales = config.locales;
77
- this.defaultHostname = config.defaultHostname || 'localhost';
78
98
  }
79
99
  /**
80
100
  * Gets the Next.js API route handler
@@ -83,21 +103,6 @@ export class RedirectsMiddleware {
83
103
  getHandler() {
84
104
  return this.handler;
85
105
  }
86
- excludeRoute(pathname) {
87
- if (pathname.includes('.') || // Ignore files
88
- pathname.startsWith('/api/') || // Ignore Next.js API calls
89
- pathname.startsWith('/sitecore/') || // Ignore Sitecore API calls
90
- pathname.startsWith('/_next') // Ignore next service calls
91
- ) {
92
- return true;
93
- }
94
- return false;
95
- }
96
- getHostname(req) {
97
- var _a;
98
- const hostHeader = (_a = req.headers.get('host')) === null || _a === void 0 ? void 0 : _a.split(':')[0];
99
- return hostHeader || this.defaultHostname;
100
- }
101
106
  /**
102
107
  * Method returns RedirectInfo when matches
103
108
  * @param {NextRequest} req request
@@ -0,0 +1,199 @@
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 { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss/graphql';
11
+ import { debug } from '@sitecore-jss/sitecore-jss';
12
+ import { getPersonalizedRewrite } from '@sitecore-jss/sitecore-jss/personalize';
13
+ /** @private */
14
+ export const languageError = 'The list of languages cannot be empty';
15
+ export const siteError = 'The service needs a site name';
16
+ /**
17
+ * @param {string} siteName to inject into error text
18
+ * @private
19
+ */
20
+ export function getSiteEmptyError(siteName) {
21
+ return `Site "${siteName}" does not exist or site item tree is missing`;
22
+ }
23
+ const languageEmptyError = 'The language must be a non-empty string';
24
+ /**
25
+ * GQL query made dynamic based on schema differences between SXP and XM Cloud
26
+ * @param {boolean} usesPersonalize flag to detrmine which variation of a query to run
27
+ * @returns GraphQL query to fetch site paths with
28
+ */
29
+ const defaultQuery = (usesPersonalize) => /* GraphQL */ `
30
+ query ${usesPersonalize ? 'PersonalizeSitemapQuery' : 'DefaultSitemapQuery'}(
31
+ $siteName: String!
32
+ $language: String!
33
+ $includedPaths: [String]
34
+ $excludedPaths: [String]
35
+ $pageSize: Int = 10
36
+ $after: String
37
+ ) {
38
+ site {
39
+ siteInfo(site: $siteName) {
40
+ routes(
41
+ language: $language
42
+ includedPaths: $includedPaths
43
+ excludedPaths: $excludedPaths
44
+ first: $pageSize
45
+ after: $after
46
+ ){
47
+ total
48
+ pageInfo {
49
+ endCursor
50
+ hasNext
51
+ }
52
+ results {
53
+ path: routePath
54
+ ${usesPersonalize
55
+ ? `
56
+ route {
57
+ personalization {
58
+ variantIds
59
+ }
60
+ }`
61
+ : ''}
62
+ }
63
+ }
64
+ }
65
+ }
66
+ }
67
+ `;
68
+ /**
69
+ * Service that fetches the list of site pages using Sitecore's GraphQL API.
70
+ * Used to handle a single site
71
+ * This list is used for SSG and Export functionality.
72
+ * @mixes SearchQueryService<PageListQueryResult>
73
+ */
74
+ export class BaseGraphQLSitemapService {
75
+ /**
76
+ * GraphQL client accessible by descendant classes when needed
77
+ */
78
+ get graphQLClient() {
79
+ return this._graphQLClient;
80
+ }
81
+ /**
82
+ * Gets the default query used for fetching the list of site pages
83
+ */
84
+ get query() {
85
+ return defaultQuery(this.options.includePersonalizedRoutes);
86
+ }
87
+ /**
88
+ * Creates an instance of graphQL sitemap service with the provided options
89
+ * @param {GraphQLSitemapServiceConfig} options instance
90
+ */
91
+ constructor(options) {
92
+ this.options = options;
93
+ this._graphQLClient = this.getGraphQLClient();
94
+ }
95
+ /**
96
+ * Fetch sitemap which could be used for generation of static pages during `next export`.
97
+ * The `locale` parameter will be used in the item query, but since i18n is not supported,
98
+ * the output paths will not include a `language` property.
99
+ * @param {string} locale which application supports
100
+ * @returns an array of @see StaticPath objects
101
+ */
102
+ fetchExportSitemap(locale) {
103
+ return __awaiter(this, void 0, void 0, function* () {
104
+ const formatPath = (path) => ({
105
+ params: {
106
+ path,
107
+ },
108
+ });
109
+ return this.fetchSitemap([locale], formatPath);
110
+ });
111
+ }
112
+ /**
113
+ * Fetch sitemap which could be used for generation of static pages using SSG mode
114
+ * @param {string[]} locales locales which application supports
115
+ * @returns an array of @see StaticPath objects
116
+ */
117
+ fetchSSGSitemap(locales) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ const formatPath = (path, locale) => ({
120
+ params: {
121
+ path,
122
+ },
123
+ locale,
124
+ });
125
+ return this.fetchSitemap(locales, formatPath);
126
+ });
127
+ }
128
+ getTranformedPaths(siteName, languages, formatStaticPath) {
129
+ return __awaiter(this, void 0, void 0, function* () {
130
+ const paths = new Array();
131
+ yield Promise.all(languages.map((language) => __awaiter(this, void 0, void 0, function* () {
132
+ if (language === '') {
133
+ throw new RangeError(languageEmptyError);
134
+ }
135
+ debug.sitemap('fetching sitemap data for %s %s', language, siteName);
136
+ const results = yield this.fetchLanguageSitePaths(language, siteName);
137
+ const transformedPaths = yield this.transformLanguageSitePaths(results, formatStaticPath, language);
138
+ paths.push(...transformedPaths);
139
+ })));
140
+ return paths;
141
+ });
142
+ }
143
+ transformLanguageSitePaths(sitePaths, formatStaticPath, language) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ const formatPath = (path) => formatStaticPath(path.replace(/^\/|\/$/g, '').split('/'), language);
146
+ const aggregatedPaths = [];
147
+ sitePaths.forEach((item) => {
148
+ var _a, _b, _c, _d;
149
+ if (!item)
150
+ return;
151
+ aggregatedPaths.push(formatPath(item.path));
152
+ // check for type safety's sake - personalize may be empty depending on query type
153
+ if ((_b = (_a = item.route) === null || _a === void 0 ? void 0 : _a.personalization) === null || _b === void 0 ? void 0 : _b.variantIds.length) {
154
+ 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(item.path, { variantId: varId })))) || {}));
155
+ }
156
+ });
157
+ return aggregatedPaths;
158
+ });
159
+ }
160
+ fetchLanguageSitePaths(language, siteName) {
161
+ var _a, _b, _c, _d;
162
+ return __awaiter(this, void 0, void 0, function* () {
163
+ const args = {
164
+ siteName: siteName,
165
+ language: language,
166
+ pageSize: this.options.pageSize,
167
+ includedPaths: this.options.includedPaths,
168
+ excludedPaths: this.options.excludedPaths,
169
+ };
170
+ let results = [];
171
+ let hasNext = true;
172
+ let after = '';
173
+ while (hasNext) {
174
+ const fetchResponse = yield this.graphQLClient.request(this.query, Object.assign(Object.assign({}, args), { after }));
175
+ if (!((_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.site) === null || _a === void 0 ? void 0 : _a.siteInfo)) {
176
+ throw new RangeError(getSiteEmptyError(siteName));
177
+ }
178
+ else {
179
+ results = results.concat((_b = fetchResponse.site.siteInfo.routes) === null || _b === void 0 ? void 0 : _b.results);
180
+ hasNext = (_c = fetchResponse.site.siteInfo.routes) === null || _c === void 0 ? void 0 : _c.pageInfo.hasNext;
181
+ after = (_d = fetchResponse.site.siteInfo.routes) === null || _d === void 0 ? void 0 : _d.pageInfo.endCursor;
182
+ }
183
+ }
184
+ return results;
185
+ });
186
+ }
187
+ /**
188
+ * Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
189
+ * library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
190
+ * want to use something else.
191
+ * @returns {GraphQLClient} implementation
192
+ */
193
+ getGraphQLClient() {
194
+ return new GraphQLRequestClient(this.options.endpoint, {
195
+ apiKey: this.options.apiKey,
196
+ debugger: debug.sitemap,
197
+ });
198
+ }
199
+ }
@@ -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 { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss/graphql';
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 sitesError = 'The list of sites cannot be empty';
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
- // Get all sites
138
- const sites = this.options.sites;
139
- if (!sites || !sites.length) {
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": "21.1.0-canary.99",
3
+ "version": "21.1.0",
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": "^21.1.0-canary.99",
74
- "@sitecore-jss/sitecore-jss-dev-tools": "^21.1.0-canary.99",
75
- "@sitecore-jss/sitecore-jss-react": "^21.1.0-canary.99",
73
+ "@sitecore-jss/sitecore-jss": "^21.1.0",
74
+ "@sitecore-jss/sitecore-jss-dev-tools": "^21.1.0",
75
+ "@sitecore-jss/sitecore-jss-react": "^21.1.0",
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": "5b1755d4be55645818169d278dd204543d1351d8",
83
+ "gitHead": "b3e19b20d4ab6157e358c84dc78d16784b086858",
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';