@sitecore-jss/sitecore-jss-nextjs 21.1.0-canary.8 → 21.1.0-canary.80
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/ComponentPropsContext.js +7 -3
- package/dist/cjs/components/EditingComponentPlaceholder.js +12 -0
- package/dist/cjs/components/Link.js +8 -4
- package/dist/cjs/components/NextImage.js +1 -1
- package/dist/cjs/components/Placeholder.js +6 -2
- package/dist/cjs/components/RichText.js +8 -4
- package/dist/cjs/editing/editing-data-cache.js +15 -10
- package/dist/cjs/editing/editing-data-middleware.js +4 -4
- package/dist/cjs/editing/editing-data-service.js +3 -3
- package/dist/cjs/editing/editing-render-middleware.js +13 -4
- package/dist/cjs/index.js +16 -6
- package/dist/cjs/middleware/index.js +5 -1
- package/dist/cjs/middleware/multisite-middleware.js +104 -0
- package/dist/cjs/middleware/personalize-middleware.js +19 -4
- package/dist/cjs/middleware/redirects-middleware.js +75 -42
- package/dist/cjs/monitoring/healthcheck-middleware.js +30 -0
- package/dist/cjs/monitoring/index.js +5 -0
- package/dist/cjs/services/graphql-sitemap-service.js +48 -25
- package/dist/cjs/utils.js +3 -3
- package/dist/esm/components/EditingComponentPlaceholder.js +5 -0
- package/dist/esm/components/Link.js +2 -2
- package/dist/esm/editing/editing-data-cache.js +15 -10
- package/dist/esm/editing/editing-data-middleware.js +2 -2
- package/dist/esm/editing/editing-data-service.js +2 -2
- package/dist/esm/editing/editing-render-middleware.js +11 -2
- package/dist/esm/index.js +3 -3
- package/dist/esm/middleware/index.js +2 -0
- package/dist/esm/middleware/multisite-middleware.js +100 -0
- package/dist/esm/middleware/personalize-middleware.js +18 -3
- package/dist/esm/middleware/redirects-middleware.js +75 -42
- package/dist/esm/monitoring/healthcheck-middleware.js +26 -0
- package/dist/esm/monitoring/index.js +1 -0
- package/dist/esm/services/graphql-sitemap-service.js +47 -24
- package/monitoring.d.ts +1 -0
- package/monitoring.js +1 -0
- package/package.json +34 -33
- package/types/components/ComponentPropsContext.d.ts +1 -1
- package/types/components/EditingComponentPlaceholder.d.ts +4 -0
- package/types/components/Link.d.ts +1 -1
- package/types/components/NextImage.d.ts +1 -1
- package/types/components/RichText.d.ts +1 -1
- package/types/editing/editing-data-cache.d.ts +4 -4
- package/types/editing/editing-data.d.ts +1 -1
- package/types/index.d.ts +4 -4
- package/types/middleware/index.d.ts +2 -0
- package/types/middleware/multisite-middleware.d.ts +46 -0
- package/types/middleware/personalize-middleware.d.ts +12 -1
- package/types/middleware/redirects-middleware.d.ts +33 -4
- package/types/monitoring/healthcheck-middleware.d.ts +12 -0
- package/types/monitoring/index.d.ts +1 -0
- package/types/services/component-props-service.d.ts +3 -3
- package/types/services/graphql-sitemap-service.d.ts +10 -5
- package/types/sharedTypes/component-module.d.ts +2 -2
- package/types/sharedTypes/component-props.d.ts +4 -4
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
+
import { SiteInfo } from '@sitecore-jss/sitecore-jss/site';
|
|
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;
|
|
21
|
+
/**
|
|
22
|
+
* Function used to determine if site should be resolved from sc_site cookie when present
|
|
23
|
+
*/
|
|
24
|
+
useCookieResolution?: (req: NextRequest) => boolean;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Middleware / handler for multisite support
|
|
28
|
+
*/
|
|
29
|
+
export declare class MultisiteMiddleware {
|
|
30
|
+
protected config: MultisiteMiddlewareConfig;
|
|
31
|
+
private defaultHostname;
|
|
32
|
+
/**
|
|
33
|
+
* @param {MultisiteMiddlewareConfig} [config] Multisite middleware config
|
|
34
|
+
*/
|
|
35
|
+
constructor(config: MultisiteMiddlewareConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Gets the Next.js middleware handler with error handling
|
|
38
|
+
* @returns middleware handler
|
|
39
|
+
*/
|
|
40
|
+
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
41
|
+
protected excludeRoute(pathname: string): boolean;
|
|
42
|
+
protected extractDebugHeaders(incomingHeaders: Headers): {
|
|
43
|
+
[key: string]: string;
|
|
44
|
+
};
|
|
45
|
+
private handler;
|
|
46
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
2
|
import { GraphQLPersonalizeServiceConfig, CdpServiceConfig, ExperienceParams } from '@sitecore-jss/sitecore-jss/personalize';
|
|
3
|
-
|
|
3
|
+
import { SiteInfo } from '@sitecore-jss/sitecore-jss/site';
|
|
4
|
+
export type PersonalizeMiddlewareConfig = {
|
|
4
5
|
/**
|
|
5
6
|
* Function used to determine if route should be excluded from personalization.
|
|
6
7
|
* By default, files (pathname.includes('.')), Next.js API routes (pathname.startsWith('/api/')), and Sitecore API routes (pathname.startsWith('/sitecore/')) are ignored.
|
|
@@ -29,6 +30,15 @@ export declare type PersonalizeMiddlewareConfig = {
|
|
|
29
30
|
* @returns {boolean} false by default
|
|
30
31
|
*/
|
|
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
|
|
40
|
+
*/
|
|
41
|
+
defaultHostname?: string;
|
|
32
42
|
};
|
|
33
43
|
/**
|
|
34
44
|
* Middleware / handler to support Sitecore Personalize
|
|
@@ -37,6 +47,7 @@ export declare class PersonalizeMiddleware {
|
|
|
37
47
|
protected config: PersonalizeMiddlewareConfig;
|
|
38
48
|
private personalizeService;
|
|
39
49
|
private cdpService;
|
|
50
|
+
private defaultHostname;
|
|
40
51
|
/**
|
|
41
52
|
* @param {PersonalizeMiddlewareConfig} [config] Personalize middleware config
|
|
42
53
|
*/
|
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import { GraphQLRedirectsServiceConfig } from '@sitecore-jss/sitecore-jss/site';
|
|
2
|
+
import { GraphQLRedirectsServiceConfig, SiteInfo } from '@sitecore-jss/sitecore-jss/site';
|
|
3
3
|
/**
|
|
4
4
|
* extended RedirectsMiddlewareConfig config type for RedirectsMiddleware
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type RedirectsMiddlewareConfig = Omit<GraphQLRedirectsServiceConfig, 'fetch'> & {
|
|
7
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;
|
|
27
|
+
/**
|
|
28
|
+
* fallback hostname in case `host` header is not present
|
|
29
|
+
* @default localhost
|
|
30
|
+
*/
|
|
31
|
+
defaultHostname?: string;
|
|
8
32
|
};
|
|
9
33
|
/**
|
|
10
34
|
* Middleware / handler fetches all redirects from Sitecore instance by grapqhl service
|
|
11
35
|
* compares with current url and redirects to target url
|
|
12
36
|
*/
|
|
13
37
|
export declare class RedirectsMiddleware {
|
|
38
|
+
protected config: RedirectsMiddlewareConfig;
|
|
14
39
|
private redirectsService;
|
|
15
40
|
private locales;
|
|
41
|
+
private defaultHostname;
|
|
16
42
|
/**
|
|
17
43
|
* @param {RedirectsMiddlewareConfig} [config] redirects middleware config
|
|
18
44
|
*/
|
|
@@ -21,11 +47,14 @@ export declare class RedirectsMiddleware {
|
|
|
21
47
|
* Gets the Next.js API route handler
|
|
22
48
|
* @returns route handler
|
|
23
49
|
*/
|
|
24
|
-
getHandler(): (req: NextRequest) => Promise<NextResponse>;
|
|
50
|
+
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
51
|
+
protected excludeRoute(pathname: string): boolean;
|
|
52
|
+
protected getHostname(req: NextRequest): string;
|
|
25
53
|
private handler;
|
|
26
54
|
/**
|
|
27
55
|
* Method returns RedirectInfo when matches
|
|
28
|
-
* @param {NextRequest} req
|
|
56
|
+
* @param {NextRequest} req request
|
|
57
|
+
* @param {string} siteName site name
|
|
29
58
|
* @returns Promise<RedirectInfo | undefined>
|
|
30
59
|
* @private
|
|
31
60
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NextApiResponse, NextApiRequest } from 'next';
|
|
2
|
+
/**
|
|
3
|
+
* Middleware / handler for use in healthcheck Next.js API route (e.g. '/api/healthz').
|
|
4
|
+
*/
|
|
5
|
+
export declare class HealthcheckMiddleware {
|
|
6
|
+
/**
|
|
7
|
+
* Gets the Next.js API route handler
|
|
8
|
+
* @returns route handler
|
|
9
|
+
*/
|
|
10
|
+
getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
11
|
+
private handler;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HealthcheckMiddleware } from './healthcheck-middleware';
|
|
@@ -2,18 +2,18 @@ import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
|
|
|
2
2
|
import { LayoutServiceData, ComponentRendering, PlaceholdersData } from '@sitecore-jss/sitecore-jss/layout';
|
|
3
3
|
import { ComponentPropsCollection, ComponentPropsFetchFunction } from '../sharedTypes/component-props';
|
|
4
4
|
import { ComponentModule } from '../sharedTypes/component-module';
|
|
5
|
-
export
|
|
5
|
+
export type FetchComponentPropsArguments<NextContext> = {
|
|
6
6
|
layoutData: LayoutServiceData;
|
|
7
7
|
context: NextContext;
|
|
8
8
|
componentModule: ComponentModule;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type ComponentPropsRequest<NextContext> = {
|
|
11
11
|
fetch: ComponentPropsFetchFunction<NextContext>;
|
|
12
12
|
layoutData: LayoutServiceData;
|
|
13
13
|
rendering: ComponentRendering;
|
|
14
14
|
context: NextContext;
|
|
15
15
|
};
|
|
16
|
-
|
|
16
|
+
type FetchFunctionFactory<NextContext> = (componentName: string) => Promise<ComponentPropsFetchFunction<NextContext> | undefined>;
|
|
17
17
|
export declare class ComponentPropsService {
|
|
18
18
|
/**
|
|
19
19
|
* SSR mode
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GraphQLClient, PageInfo } from '@sitecore-jss/sitecore-jss/graphql';
|
|
2
2
|
/** @private */
|
|
3
3
|
export declare const languageError = "The list of languages cannot be empty";
|
|
4
|
+
export declare const sitesError = "The list of sites cannot be empty";
|
|
4
5
|
/**
|
|
5
6
|
* @param {string} siteName to inject into error text
|
|
6
7
|
* @private
|
|
@@ -53,7 +54,7 @@ export interface SiteRouteQueryResult<T> {
|
|
|
53
54
|
/**
|
|
54
55
|
* The schema of data returned in response to a routes list query request
|
|
55
56
|
*/
|
|
56
|
-
export
|
|
57
|
+
export type RouteListQueryResult = {
|
|
57
58
|
path: string;
|
|
58
59
|
route?: {
|
|
59
60
|
personalization?: {
|
|
@@ -64,7 +65,7 @@ export declare type RouteListQueryResult = {
|
|
|
64
65
|
/**
|
|
65
66
|
* Configuration options for @see GraphQLSitemapService instances
|
|
66
67
|
*/
|
|
67
|
-
export interface GraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariables, 'language'> {
|
|
68
|
+
export interface GraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariables, 'language' | 'siteName'> {
|
|
68
69
|
/**
|
|
69
70
|
* Your Graphql endpoint
|
|
70
71
|
*/
|
|
@@ -73,6 +74,10 @@ export interface GraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariable
|
|
|
73
74
|
* The API key to use for authentication.
|
|
74
75
|
*/
|
|
75
76
|
apiKey: string;
|
|
77
|
+
/**
|
|
78
|
+
* Names of the configured sites
|
|
79
|
+
*/
|
|
80
|
+
sites: string[];
|
|
76
81
|
/**
|
|
77
82
|
* A flag for whether to include personalized routes in service output - only works on XM Cloud
|
|
78
83
|
* turned off by default
|
|
@@ -82,7 +87,7 @@ export interface GraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariable
|
|
|
82
87
|
/**
|
|
83
88
|
* Object model of a site page item.
|
|
84
89
|
*/
|
|
85
|
-
export
|
|
90
|
+
export type StaticPath = {
|
|
86
91
|
params: {
|
|
87
92
|
path: string[];
|
|
88
93
|
};
|
|
@@ -129,8 +134,8 @@ export declare class GraphQLSitemapService {
|
|
|
129
134
|
* @throws {RangeError} if the any of the languages is an empty string.
|
|
130
135
|
*/
|
|
131
136
|
protected fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
132
|
-
protected transformLanguageSitePaths(sitePaths: RouteListQueryResult[], formatStaticPath: (path: string[], language: string) => StaticPath, language: string): Promise<StaticPath[]>;
|
|
133
|
-
protected fetchLanguageSitePaths(language: string): Promise<RouteListQueryResult[]>;
|
|
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[]>;
|
|
134
139
|
/**
|
|
135
140
|
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
136
141
|
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { GetServerSideComponentProps, GetStaticComponentProps } from './component-props';
|
|
3
|
-
export
|
|
3
|
+
export type Module = {
|
|
4
4
|
default: React.Component;
|
|
5
5
|
getServerSideProps?: GetServerSideComponentProps;
|
|
6
6
|
getStaticProps?: GetStaticComponentProps;
|
|
@@ -10,4 +10,4 @@ export declare type Module = {
|
|
|
10
10
|
* @returns `Module` regular module
|
|
11
11
|
* @returns `Promise<Module>` when module should be lazy loaded
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
13
|
+
export type ComponentModule = (componentName: string) => Module | Promise<Module> | undefined;
|
|
@@ -3,20 +3,20 @@ import { ComponentRendering, LayoutServiceData } from '@sitecore-jss/sitecore-js
|
|
|
3
3
|
/**
|
|
4
4
|
* Shape of component props storage
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type ComponentPropsCollection = {
|
|
7
7
|
[componentUid: string]: unknown;
|
|
8
8
|
};
|
|
9
9
|
/**
|
|
10
10
|
* Type of side effect function which could be invoked on component level (getStaticProps/getServerSideProps)
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export type ComponentPropsFetchFunction<NextContext, FetchedProps = unknown> = {
|
|
13
13
|
(rendering: ComponentRendering, layoutData: LayoutServiceData, context: NextContext): Promise<FetchedProps>;
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
16
|
* Shape of getServerSideProps function on component level
|
|
17
17
|
*/
|
|
18
|
-
export
|
|
18
|
+
export type GetServerSideComponentProps = ComponentPropsFetchFunction<GetServerSidePropsContext>;
|
|
19
19
|
/**
|
|
20
20
|
* Shape of getStaticProps function on component level
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export type GetStaticComponentProps = ComponentPropsFetchFunction<GetStaticPropsContext>;
|