@sitecore-jss/sitecore-jss-nextjs 21.1.0-canary.98 → 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.
- package/LICENSE.txt +202 -202
- package/README.md +10 -10
- 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,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
|
|
@@ -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
|
+
}
|