@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
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { GraphQLClient, PageInfo } from '@sitecore-jss/sitecore-jss/graphql';
|
|
2
|
+
/** @private */
|
|
3
|
+
export declare const languageError = "The list of languages cannot be empty";
|
|
4
|
+
export declare const siteError = "The service needs a site name";
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} siteName to inject into error text
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare function getSiteEmptyError(siteName: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* type for input variables for the site routes query
|
|
12
|
+
*/
|
|
13
|
+
interface SiteRouteQueryVariables {
|
|
14
|
+
/**
|
|
15
|
+
* Required. The name of the site being queried.
|
|
16
|
+
*/
|
|
17
|
+
siteName: string;
|
|
18
|
+
/**
|
|
19
|
+
* Required. The language to return routes/pages for.
|
|
20
|
+
*/
|
|
21
|
+
language: string;
|
|
22
|
+
/**
|
|
23
|
+
* Optional. Only paths starting with these provided prefixes will be returned.
|
|
24
|
+
*/
|
|
25
|
+
includedPaths?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* Optional. Paths starting with these provided prefixes will be excluded from returned results.
|
|
28
|
+
*/
|
|
29
|
+
excludedPaths?: string[];
|
|
30
|
+
/** common variable for all GraphQL queries
|
|
31
|
+
* it will be used for every type of query to regulate result batch size
|
|
32
|
+
* Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
|
|
33
|
+
* @default 10
|
|
34
|
+
*/
|
|
35
|
+
pageSize?: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Schema of data returned in response to a "site" query request
|
|
39
|
+
* @template T The type of objects being requested.
|
|
40
|
+
*/
|
|
41
|
+
export interface SiteRouteQueryResult<T> {
|
|
42
|
+
site: {
|
|
43
|
+
siteInfo: {
|
|
44
|
+
routes: {
|
|
45
|
+
/**
|
|
46
|
+
* Data needed to paginate the site results
|
|
47
|
+
*/
|
|
48
|
+
pageInfo: PageInfo;
|
|
49
|
+
results: T[];
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The schema of data returned in response to a routes list query request
|
|
56
|
+
*/
|
|
57
|
+
export type RouteListQueryResult = {
|
|
58
|
+
path: string;
|
|
59
|
+
route?: {
|
|
60
|
+
personalization?: {
|
|
61
|
+
variantIds: string[];
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Configuration options for @see GraphQLSitemapService instances
|
|
67
|
+
*/
|
|
68
|
+
export interface BaseGraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariables, 'language' | 'siteName'> {
|
|
69
|
+
/**
|
|
70
|
+
* Your Graphql endpoint
|
|
71
|
+
*/
|
|
72
|
+
endpoint: string;
|
|
73
|
+
/**
|
|
74
|
+
* The API key to use for authentication.
|
|
75
|
+
*/
|
|
76
|
+
apiKey: string;
|
|
77
|
+
/**
|
|
78
|
+
* A flag for whether to include personalized routes in service output - only works on XM Cloud
|
|
79
|
+
* turned off by default
|
|
80
|
+
*/
|
|
81
|
+
includePersonalizedRoutes?: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Object model of a site page item.
|
|
85
|
+
*/
|
|
86
|
+
export type StaticPath = {
|
|
87
|
+
params: {
|
|
88
|
+
path: string[];
|
|
89
|
+
};
|
|
90
|
+
locale?: string;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
94
|
+
* Used to handle a single site
|
|
95
|
+
* This list is used for SSG and Export functionality.
|
|
96
|
+
* @mixes SearchQueryService<PageListQueryResult>
|
|
97
|
+
*/
|
|
98
|
+
export declare abstract class BaseGraphQLSitemapService {
|
|
99
|
+
options: BaseGraphQLSitemapServiceConfig;
|
|
100
|
+
private _graphQLClient;
|
|
101
|
+
/**
|
|
102
|
+
* GraphQL client accessible by descendant classes when needed
|
|
103
|
+
*/
|
|
104
|
+
protected get graphQLClient(): GraphQLClient;
|
|
105
|
+
/**
|
|
106
|
+
* Gets the default query used for fetching the list of site pages
|
|
107
|
+
*/
|
|
108
|
+
protected get query(): string;
|
|
109
|
+
/**
|
|
110
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
111
|
+
* @param {GraphQLSitemapServiceConfig} options instance
|
|
112
|
+
*/
|
|
113
|
+
constructor(options: BaseGraphQLSitemapServiceConfig);
|
|
114
|
+
/**
|
|
115
|
+
* Fetch sitemap which could be used for generation of static pages during `next export`.
|
|
116
|
+
* The `locale` parameter will be used in the item query, but since i18n is not supported,
|
|
117
|
+
* the output paths will not include a `language` property.
|
|
118
|
+
* @param {string} locale which application supports
|
|
119
|
+
* @returns an array of @see StaticPath objects
|
|
120
|
+
*/
|
|
121
|
+
fetchExportSitemap(locale: string): Promise<StaticPath[]>;
|
|
122
|
+
/**
|
|
123
|
+
* Fetch sitemap which could be used for generation of static pages using SSG mode
|
|
124
|
+
* @param {string[]} locales locales which application supports
|
|
125
|
+
* @returns an array of @see StaticPath objects
|
|
126
|
+
*/
|
|
127
|
+
fetchSSGSitemap(locales: string[]): Promise<StaticPath[]>;
|
|
128
|
+
protected getTranformedPaths(siteName: string, languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
129
|
+
protected transformLanguageSitePaths(sitePaths: RouteListQueryResult[], formatStaticPath: (path: string[], language: string) => StaticPath, language: string): Promise<StaticPath[]>;
|
|
130
|
+
protected fetchLanguageSitePaths(language: string, siteName: string): Promise<RouteListQueryResult[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
133
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
134
|
+
* want to use something else.
|
|
135
|
+
* @returns {GraphQLClient} implementation
|
|
136
|
+
*/
|
|
137
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
138
|
+
/**
|
|
139
|
+
* Fetch a flat list of all pages that belong to the specificed site and have a
|
|
140
|
+
* version in the specified language(s).
|
|
141
|
+
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
142
|
+
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
143
|
+
* @returns list of pages
|
|
144
|
+
* @throws {RangeError} if the list of languages is empty.
|
|
145
|
+
* @throws {RangeError} if the any of the languages is an empty string.
|
|
146
|
+
*/
|
|
147
|
+
protected abstract fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
148
|
+
}
|
|
149
|
+
export {};
|
|
@@ -1,88 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseGraphQLSitemapService, BaseGraphQLSitemapServiceConfig } from './base-graphql-sitemap-service';
|
|
2
2
|
/** @private */
|
|
3
3
|
export declare const languageError = "The list of languages cannot be empty";
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const siteError = "The service needs a site name";
|
|
5
5
|
/**
|
|
6
6
|
* @param {string} siteName to inject into error text
|
|
7
7
|
* @private
|
|
8
8
|
*/
|
|
9
9
|
export declare function getSiteEmptyError(siteName: string): string;
|
|
10
|
-
/**
|
|
11
|
-
* type for input variables for the site routes query
|
|
12
|
-
*/
|
|
13
|
-
interface SiteRouteQueryVariables {
|
|
14
|
-
/**
|
|
15
|
-
* Required. The name of the site being queried.
|
|
16
|
-
*/
|
|
17
|
-
siteName: string;
|
|
18
|
-
/**
|
|
19
|
-
* Required. The language to return routes/pages for.
|
|
20
|
-
*/
|
|
21
|
-
language: string;
|
|
22
|
-
/**
|
|
23
|
-
* Optional. Only paths starting with these provided prefixes will be returned.
|
|
24
|
-
*/
|
|
25
|
-
includedPaths?: string[];
|
|
26
|
-
/**
|
|
27
|
-
* Optional. Paths starting with these provided prefixes will be excluded from returned results.
|
|
28
|
-
*/
|
|
29
|
-
excludedPaths?: string[];
|
|
30
|
-
/** common variable for all GraphQL queries
|
|
31
|
-
* it will be used for every type of query to regulate result batch size
|
|
32
|
-
* Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
|
|
33
|
-
* @default 10
|
|
34
|
-
*/
|
|
35
|
-
pageSize?: number;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Schema of data returned in response to a "site" query request
|
|
39
|
-
* @template T The type of objects being requested.
|
|
40
|
-
*/
|
|
41
|
-
export interface SiteRouteQueryResult<T> {
|
|
42
|
-
site: {
|
|
43
|
-
siteInfo: {
|
|
44
|
-
routes: {
|
|
45
|
-
/**
|
|
46
|
-
* Data needed to paginate the site results
|
|
47
|
-
*/
|
|
48
|
-
pageInfo: PageInfo;
|
|
49
|
-
results: T[];
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* The schema of data returned in response to a routes list query request
|
|
56
|
-
*/
|
|
57
|
-
export type RouteListQueryResult = {
|
|
58
|
-
path: string;
|
|
59
|
-
route?: {
|
|
60
|
-
personalization?: {
|
|
61
|
-
variantIds: string[];
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
10
|
/**
|
|
66
11
|
* Configuration options for @see GraphQLSitemapService instances
|
|
67
12
|
*/
|
|
68
|
-
export interface GraphQLSitemapServiceConfig extends
|
|
69
|
-
/**
|
|
70
|
-
* Your Graphql endpoint
|
|
71
|
-
*/
|
|
72
|
-
endpoint: string;
|
|
73
|
-
/**
|
|
74
|
-
* The API key to use for authentication.
|
|
75
|
-
*/
|
|
76
|
-
apiKey: string;
|
|
77
|
-
/**
|
|
78
|
-
* Names of the configured sites
|
|
79
|
-
*/
|
|
80
|
-
sites: string[];
|
|
13
|
+
export interface GraphQLSitemapServiceConfig extends BaseGraphQLSitemapServiceConfig {
|
|
81
14
|
/**
|
|
82
|
-
*
|
|
83
|
-
* turned off by default
|
|
15
|
+
* Name of the site to retrieve site paths for
|
|
84
16
|
*/
|
|
85
|
-
|
|
17
|
+
siteName: string;
|
|
86
18
|
}
|
|
87
19
|
/**
|
|
88
20
|
* Object model of a site page item.
|
|
@@ -95,35 +27,17 @@ export type StaticPath = {
|
|
|
95
27
|
};
|
|
96
28
|
/**
|
|
97
29
|
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
30
|
+
* Used to handle a single site
|
|
98
31
|
* This list is used for SSG and Export functionality.
|
|
99
32
|
* @mixes SearchQueryService<PageListQueryResult>
|
|
100
33
|
*/
|
|
101
|
-
export declare class GraphQLSitemapService {
|
|
34
|
+
export declare class GraphQLSitemapService extends BaseGraphQLSitemapService {
|
|
102
35
|
options: GraphQLSitemapServiceConfig;
|
|
103
|
-
private graphQLClient;
|
|
104
|
-
/**
|
|
105
|
-
* Gets the default query used for fetching the list of site pages
|
|
106
|
-
*/
|
|
107
|
-
protected get query(): string;
|
|
108
36
|
/**
|
|
109
37
|
* Creates an instance of graphQL sitemap service with the provided options
|
|
110
38
|
* @param {GraphQLSitemapServiceConfig} options instance
|
|
111
39
|
*/
|
|
112
40
|
constructor(options: GraphQLSitemapServiceConfig);
|
|
113
|
-
/**
|
|
114
|
-
* Fetch sitemap which could be used for generation of static pages during `next export`.
|
|
115
|
-
* The `locale` parameter will be used in the item query, but since i18n is not supported,
|
|
116
|
-
* the output paths will not include a `language` property.
|
|
117
|
-
* @param {string} locale which application supports
|
|
118
|
-
* @returns an array of @see StaticPath objects
|
|
119
|
-
*/
|
|
120
|
-
fetchExportSitemap(locale: string): Promise<StaticPath[]>;
|
|
121
|
-
/**
|
|
122
|
-
* Fetch sitemap which could be used for generation of static pages using SSG mode
|
|
123
|
-
* @param {string[]} locales locales which application supports
|
|
124
|
-
* @returns an array of @see StaticPath objects
|
|
125
|
-
*/
|
|
126
|
-
fetchSSGSitemap(locales: string[]): Promise<StaticPath[]>;
|
|
127
41
|
/**
|
|
128
42
|
* Fetch a flat list of all pages that belong to the specificed site and have a
|
|
129
43
|
* version in the specified language(s).
|
|
@@ -134,14 +48,4 @@ export declare class GraphQLSitemapService {
|
|
|
134
48
|
* @throws {RangeError} if the any of the languages is an empty string.
|
|
135
49
|
*/
|
|
136
50
|
protected fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
137
|
-
protected transformLanguageSitePaths(sitePaths: RouteListQueryResult[], formatStaticPath: (path: string[], language: string) => StaticPath, language: string, multiSiteName?: string): Promise<StaticPath[]>;
|
|
138
|
-
protected fetchLanguageSitePaths(language: string, siteName: string): Promise<RouteListQueryResult[]>;
|
|
139
|
-
/**
|
|
140
|
-
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
141
|
-
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
142
|
-
* want to use something else.
|
|
143
|
-
* @returns {GraphQLClient} implementation
|
|
144
|
-
*/
|
|
145
|
-
protected getGraphQLClient(): GraphQLClient;
|
|
146
51
|
}
|
|
147
|
-
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseGraphQLSitemapService, BaseGraphQLSitemapServiceConfig, RouteListQueryResult, StaticPath } from './base-graphql-sitemap-service';
|
|
2
|
+
export declare const sitesError = "The list of sites cannot be empty";
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for @see GraphQLSitemapService instances
|
|
5
|
+
*/
|
|
6
|
+
export interface MultisiteGraphQLSitemapServiceConfig extends BaseGraphQLSitemapServiceConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Names of the configured sites
|
|
9
|
+
*/
|
|
10
|
+
sites: string[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
14
|
+
* Used to handle multiple sites
|
|
15
|
+
* This list is used for SSG and Export functionality.
|
|
16
|
+
* @mixes SearchQueryService<PageListQueryResult>
|
|
17
|
+
*/
|
|
18
|
+
export declare class MultisiteGraphQLSitemapService extends BaseGraphQLSitemapService {
|
|
19
|
+
options: MultisiteGraphQLSitemapServiceConfig;
|
|
20
|
+
/**
|
|
21
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
22
|
+
* @param {MultisiteGraphQLSitemapServiceConfig} options instance
|
|
23
|
+
*/
|
|
24
|
+
constructor(options: MultisiteGraphQLSitemapServiceConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Fetch a flat list of all pages that belong to all the requested sites and have a
|
|
27
|
+
* version in the specified language(s).
|
|
28
|
+
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
29
|
+
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
30
|
+
* @returns list of pages
|
|
31
|
+
* @throws {RangeError} if the list of languages is empty.
|
|
32
|
+
* @throws {RangeError} if the any of the languages is an empty string.
|
|
33
|
+
*/
|
|
34
|
+
protected fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
35
|
+
/**
|
|
36
|
+
* Fetch and return site paths for multisite implementation, with prefixes included
|
|
37
|
+
* @param {string} language path language
|
|
38
|
+
* @param {string} siteName site name
|
|
39
|
+
* @returns modified paths
|
|
40
|
+
*/
|
|
41
|
+
protected fetchLanguageSitePaths(language: string, siteName: string): Promise<RouteListQueryResult[]>;
|
|
42
|
+
}
|