@sitecore-content-sdk/nextjs 0.1.0-beta.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/LICENSE.txt +202 -0
- package/README.md +10 -0
- package/dist/cjs/ComponentBuilder.js +63 -0
- package/dist/cjs/components/BYOCWrapper.js +41 -0
- package/dist/cjs/components/ComponentPropsContext.js +57 -0
- package/dist/cjs/components/FEaaSWrapper.js +43 -0
- package/dist/cjs/components/Link.js +87 -0
- package/dist/cjs/components/NextImage.js +82 -0
- package/dist/cjs/components/Placeholder.js +49 -0
- package/dist/cjs/components/RichText.js +95 -0
- package/dist/cjs/editing/constants.js +10 -0
- package/dist/cjs/editing/editing-config-middleware.js +62 -0
- package/dist/cjs/editing/editing-render-middleware.js +182 -0
- package/dist/cjs/editing/feaas-render-middleware.js +101 -0
- package/dist/cjs/editing/index.js +16 -0
- package/dist/cjs/editing/render-middleware.js +43 -0
- package/dist/cjs/graphql/index.js +7 -0
- package/dist/cjs/index.js +119 -0
- package/dist/cjs/middleware/index.js +13 -0
- package/dist/cjs/middleware/middleware.js +97 -0
- package/dist/cjs/middleware/multisite-middleware.js +93 -0
- package/dist/cjs/middleware/personalize-middleware.js +231 -0
- package/dist/cjs/middleware/redirects-middleware.js +264 -0
- package/dist/cjs/monitoring/healthcheck-middleware.js +30 -0
- package/dist/cjs/monitoring/index.js +5 -0
- package/dist/cjs/services/base-graphql-sitemap-service.js +206 -0
- package/dist/cjs/services/component-props-service.js +167 -0
- package/dist/cjs/services/graphql-sitemap-service.js +64 -0
- package/dist/cjs/services/mutisite-graphql-sitemap-service.js +81 -0
- package/dist/cjs/sharedTypes/component-props.js +2 -0
- package/dist/cjs/sharedTypes/module-factory.js +2 -0
- package/dist/cjs/site/index.js +5 -0
- package/dist/cjs/utils/index.js +11 -0
- package/dist/cjs/utils/utils.js +42 -0
- package/dist/esm/ComponentBuilder.js +59 -0
- package/dist/esm/components/BYOCWrapper.js +36 -0
- package/dist/esm/components/ComponentPropsContext.js +19 -0
- package/dist/esm/components/FEaaSWrapper.js +38 -0
- package/dist/esm/components/Link.js +48 -0
- package/dist/esm/components/NextImage.js +76 -0
- package/dist/esm/components/Placeholder.js +12 -0
- package/dist/esm/components/RichText.js +55 -0
- package/dist/esm/editing/constants.js +7 -0
- package/dist/esm/editing/editing-config-middleware.js +58 -0
- package/dist/esm/editing/editing-render-middleware.js +177 -0
- package/dist/esm/editing/feaas-render-middleware.js +97 -0
- package/dist/esm/editing/index.js +5 -0
- package/dist/esm/editing/render-middleware.js +39 -0
- package/dist/esm/graphql/index.js +1 -0
- package/dist/esm/index.js +23 -0
- package/dist/esm/middleware/index.js +5 -0
- package/dist/esm/middleware/middleware.js +93 -0
- package/dist/esm/middleware/multisite-middleware.js +89 -0
- package/dist/esm/middleware/personalize-middleware.js +227 -0
- package/dist/esm/middleware/redirects-middleware.js +257 -0
- package/dist/esm/monitoring/healthcheck-middleware.js +26 -0
- package/dist/esm/monitoring/index.js +1 -0
- package/dist/esm/services/base-graphql-sitemap-service.js +201 -0
- package/dist/esm/services/component-props-service.js +160 -0
- package/dist/esm/services/graphql-sitemap-service.js +59 -0
- package/dist/esm/services/mutisite-graphql-sitemap-service.js +77 -0
- package/dist/esm/sharedTypes/component-props.js +1 -0
- package/dist/esm/sharedTypes/module-factory.js +1 -0
- package/dist/esm/site/index.js +1 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/utils.js +37 -0
- package/editing.d.ts +1 -0
- package/editing.js +1 -0
- package/global.d.ts +21 -0
- package/graphql.d.ts +1 -0
- package/graphql.js +1 -0
- package/middleware.d.ts +1 -0
- package/middleware.js +1 -0
- package/monitoring.d.ts +1 -0
- package/monitoring.js +1 -0
- package/package.json +92 -0
- package/site.d.ts +1 -0
- package/site.js +1 -0
- package/types/ComponentBuilder.d.ts +59 -0
- package/types/components/BYOCWrapper.d.ts +20 -0
- package/types/components/ComponentPropsContext.d.ts +18 -0
- package/types/components/FEaaSWrapper.d.ts +22 -0
- package/types/components/Link.d.ts +10 -0
- package/types/components/NextImage.d.ts +6 -0
- package/types/components/Placeholder.d.ts +8 -0
- package/types/components/RichText.d.ts +32 -0
- package/types/editing/constants.d.ts +7 -0
- package/types/editing/editing-config-middleware.d.ts +29 -0
- package/types/editing/editing-render-middleware.d.ts +79 -0
- package/types/editing/feaas-render-middleware.d.ts +32 -0
- package/types/editing/index.d.ts +5 -0
- package/types/editing/render-middleware.d.ts +24 -0
- package/types/graphql/index.d.ts +1 -0
- package/types/index.d.ts +24 -0
- package/types/middleware/index.d.ts +5 -0
- package/types/middleware/middleware.d.ts +82 -0
- package/types/middleware/multisite-middleware.d.ts +39 -0
- package/types/middleware/personalize-middleware.d.ts +102 -0
- package/types/middleware/redirects-middleware.d.ts +57 -0
- package/types/monitoring/healthcheck-middleware.d.ts +12 -0
- package/types/monitoring/index.d.ts +1 -0
- package/types/services/base-graphql-sitemap-service.d.ts +148 -0
- package/types/services/component-props-service.d.ts +81 -0
- package/types/services/graphql-sitemap-service.d.ts +51 -0
- package/types/services/mutisite-graphql-sitemap-service.d.ts +42 -0
- package/types/sharedTypes/component-props.d.ts +26 -0
- package/types/sharedTypes/module-factory.d.ts +32 -0
- package/types/site/index.d.ts +1 -0
- package/types/utils/index.d.ts +3 -0
- package/types/utils/utils.d.ts +8 -0
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
+
import { GraphQLPersonalizeServiceConfig, PersonalizeInfo } from '@sitecore-content-sdk/core/personalize';
|
|
3
|
+
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
4
|
+
export type CdpServiceConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* Your Sitecore Edge Platform endpoint
|
|
7
|
+
* Default is https://edge-platform.sitecorecloud.io
|
|
8
|
+
*/
|
|
9
|
+
sitecoreEdgeUrl?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Your unified Sitecore Edge Context Id
|
|
12
|
+
*/
|
|
13
|
+
sitecoreEdgeContextId: string;
|
|
14
|
+
/**
|
|
15
|
+
* The Sitecore CDP channel to use for events. Uses 'WEB' by default.
|
|
16
|
+
*/
|
|
17
|
+
channel?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Currency for CDP request. Uses 'USA' as default.
|
|
20
|
+
*/
|
|
21
|
+
currency?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Timeout (ms) for CDP request. Default is 400.
|
|
24
|
+
*/
|
|
25
|
+
timeout?: number;
|
|
26
|
+
};
|
|
27
|
+
export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for your Sitecore Experience Edge endpoint
|
|
30
|
+
*/
|
|
31
|
+
edgeConfig: Omit<GraphQLPersonalizeServiceConfig, 'fetch'>;
|
|
32
|
+
/**
|
|
33
|
+
* Configuration for your Sitecore CDP endpoint
|
|
34
|
+
*/
|
|
35
|
+
cdpConfig: CdpServiceConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Optional Sitecore Personalize scope identifier allowing you to isolate your personalization data between XM Cloud environments
|
|
38
|
+
*/
|
|
39
|
+
scope?: string;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Object model of Experience Context data
|
|
43
|
+
*/
|
|
44
|
+
export type ExperienceParams = {
|
|
45
|
+
referrer: string;
|
|
46
|
+
utm: {
|
|
47
|
+
[key: string]: string | undefined;
|
|
48
|
+
campaign: string | undefined;
|
|
49
|
+
source: string | undefined;
|
|
50
|
+
medium: string | undefined;
|
|
51
|
+
content: string | undefined;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Object model of personalize execution data
|
|
56
|
+
*/
|
|
57
|
+
type PersonalizeExecution = {
|
|
58
|
+
friendlyId: string;
|
|
59
|
+
variantIds: string[];
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Middleware / handler to support Sitecore Personalize
|
|
63
|
+
*/
|
|
64
|
+
export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
65
|
+
protected config: PersonalizeMiddlewareConfig;
|
|
66
|
+
private personalizeService;
|
|
67
|
+
/**
|
|
68
|
+
* @param {PersonalizeMiddlewareConfig} [config] Personalize middleware config
|
|
69
|
+
*/
|
|
70
|
+
constructor(config: PersonalizeMiddlewareConfig);
|
|
71
|
+
/**
|
|
72
|
+
* Gets the Next.js middleware handler with error handling
|
|
73
|
+
* @returns middleware handler
|
|
74
|
+
*/
|
|
75
|
+
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
76
|
+
protected initPersonalizeServer({ hostname, siteName, request, response, }: {
|
|
77
|
+
hostname: string;
|
|
78
|
+
siteName: string;
|
|
79
|
+
request: NextRequest;
|
|
80
|
+
response: NextResponse;
|
|
81
|
+
}): Promise<void>;
|
|
82
|
+
protected personalize({ params, friendlyId, language, timeout, variantIds, }: {
|
|
83
|
+
params: ExperienceParams;
|
|
84
|
+
friendlyId: string;
|
|
85
|
+
language: string;
|
|
86
|
+
timeout?: number;
|
|
87
|
+
variantIds?: string[];
|
|
88
|
+
}, request: NextRequest): Promise<{
|
|
89
|
+
variantId: string;
|
|
90
|
+
}>;
|
|
91
|
+
protected getExperienceParams(req: NextRequest): ExperienceParams;
|
|
92
|
+
protected excludeRoute(pathname: string): boolean | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Aggregates personalize executions based on the provided route personalize information and language
|
|
95
|
+
* @param {PersonalizeInfo} personalizeInfo the route personalize information
|
|
96
|
+
* @param {string} language the language
|
|
97
|
+
* @returns An array of personalize executions
|
|
98
|
+
*/
|
|
99
|
+
protected getPersonalizeExecutions(personalizeInfo: PersonalizeInfo, language: string): PersonalizeExecution[];
|
|
100
|
+
private handler;
|
|
101
|
+
}
|
|
102
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { GraphQLRedirectsServiceConfig } from '@sitecore-content-sdk/core/site';
|
|
2
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
3
|
+
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
4
|
+
/**
|
|
5
|
+
* extended RedirectsMiddlewareConfig config type for RedirectsMiddleware
|
|
6
|
+
*/
|
|
7
|
+
export type RedirectsMiddlewareConfig = Omit<GraphQLRedirectsServiceConfig, 'fetch'> & MiddlewareBaseConfig & {
|
|
8
|
+
/**
|
|
9
|
+
* These are all the locales you support in your application.
|
|
10
|
+
* These should match those in your next.config.js (i18n.locales).
|
|
11
|
+
*/
|
|
12
|
+
locales: string[];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Middleware / handler fetches all redirects from Sitecore instance by grapqhl service
|
|
16
|
+
* compares with current url and redirects to target url
|
|
17
|
+
*/
|
|
18
|
+
export declare class RedirectsMiddleware extends MiddlewareBase {
|
|
19
|
+
protected config: RedirectsMiddlewareConfig;
|
|
20
|
+
private redirectsService;
|
|
21
|
+
private locales;
|
|
22
|
+
/**
|
|
23
|
+
* @param {RedirectsMiddlewareConfig} [config] redirects middleware config
|
|
24
|
+
*/
|
|
25
|
+
constructor(config: RedirectsMiddlewareConfig);
|
|
26
|
+
/**
|
|
27
|
+
* Gets the Next.js middleware handler with error handling
|
|
28
|
+
* @returns route handler
|
|
29
|
+
*/
|
|
30
|
+
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
31
|
+
private handler;
|
|
32
|
+
/**
|
|
33
|
+
* Method returns RedirectInfo when matches
|
|
34
|
+
* @param {NextRequest} req request
|
|
35
|
+
* @param {string} siteName site name
|
|
36
|
+
* @returns Promise<RedirectInfo | undefined>
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
private getExistsRedirect;
|
|
40
|
+
/**
|
|
41
|
+
* When a user clicks on a link generated by the Link component from next/link,
|
|
42
|
+
* Next.js adds special parameters in the route called path.
|
|
43
|
+
* This method removes these special parameters.
|
|
44
|
+
* @param {NextURL} url
|
|
45
|
+
* @returns {string} normalize url
|
|
46
|
+
*/
|
|
47
|
+
private normalizeUrl;
|
|
48
|
+
/**
|
|
49
|
+
* Helper function to create a redirect response and remove the x-middleware-next header.
|
|
50
|
+
* @param {NextURL} url The URL to redirect to.
|
|
51
|
+
* @param {Response} res The response object.
|
|
52
|
+
* @param {number} status The HTTP status code of the redirect.
|
|
53
|
+
* @param {string} statusText The status text of the redirect.
|
|
54
|
+
* @returns {NextResponse<unknown>} The redirect response.
|
|
55
|
+
*/
|
|
56
|
+
private createRedirectResponse;
|
|
57
|
+
}
|
|
@@ -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';
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { GraphQLClient, GraphQLRequestClientFactory, PageInfo } from '@sitecore-content-sdk/core/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
|
+
/**
|
|
31
|
+
* common variable for all GraphQL queries
|
|
32
|
+
* it will be used for every type of query to regulate result batch size
|
|
33
|
+
* Optional. How many result items to fetch in each GraphQL call. This is needed for pagination.
|
|
34
|
+
* @default 100
|
|
35
|
+
*/
|
|
36
|
+
pageSize?: number;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Schema of data returned in response to a "site" query request
|
|
40
|
+
* @template T The type of objects being requested.
|
|
41
|
+
*/
|
|
42
|
+
export interface SiteRouteQueryResult<T> {
|
|
43
|
+
site: {
|
|
44
|
+
siteInfo: {
|
|
45
|
+
routes: {
|
|
46
|
+
/**
|
|
47
|
+
* Data needed to paginate the site results
|
|
48
|
+
*/
|
|
49
|
+
pageInfo: PageInfo;
|
|
50
|
+
results: T[];
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The schema of data returned in response to a routes list query request
|
|
57
|
+
*/
|
|
58
|
+
export type RouteListQueryResult = {
|
|
59
|
+
path: string;
|
|
60
|
+
route?: {
|
|
61
|
+
personalization?: {
|
|
62
|
+
variantIds: string[];
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Configuration options for @see GraphQLSitemapService instances
|
|
68
|
+
*/
|
|
69
|
+
export interface BaseGraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariables, 'language' | 'siteName'> {
|
|
70
|
+
/**
|
|
71
|
+
* A flag for whether to include personalized routes in service output.
|
|
72
|
+
* Only works on XM Cloud for pages using Embedded Personalization (not Component A/B testing).
|
|
73
|
+
* Turned off by default.
|
|
74
|
+
*/
|
|
75
|
+
includePersonalizedRoutes?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
78
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
79
|
+
*/
|
|
80
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Object model of a site page item.
|
|
84
|
+
*/
|
|
85
|
+
export type StaticPath = {
|
|
86
|
+
params: {
|
|
87
|
+
path: string[];
|
|
88
|
+
};
|
|
89
|
+
locale?: string;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
93
|
+
* Used to handle a single site
|
|
94
|
+
* This list is used for SSG and Export functionality.
|
|
95
|
+
* @mixes SearchQueryService<PageListQueryResult>
|
|
96
|
+
*/
|
|
97
|
+
export declare abstract class BaseGraphQLSitemapService {
|
|
98
|
+
options: BaseGraphQLSitemapServiceConfig;
|
|
99
|
+
private _graphQLClient;
|
|
100
|
+
/**
|
|
101
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
102
|
+
* @param {GraphQLSitemapServiceConfig} options instance
|
|
103
|
+
*/
|
|
104
|
+
constructor(options: BaseGraphQLSitemapServiceConfig);
|
|
105
|
+
/**
|
|
106
|
+
* GraphQL client accessible by descendant classes when needed
|
|
107
|
+
*/
|
|
108
|
+
protected get graphQLClient(): GraphQLClient;
|
|
109
|
+
/**
|
|
110
|
+
* Gets the default query used for fetching the list of site pages
|
|
111
|
+
*/
|
|
112
|
+
protected get query(): string;
|
|
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
|
+
protected getTranformedPaths(siteName: string, languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
128
|
+
protected transformLanguageSitePaths(sitePaths: RouteListQueryResult[], formatStaticPath: (path: string[], language: string) => StaticPath, language: string): Promise<StaticPath[]>;
|
|
129
|
+
protected fetchLanguageSitePaths(language: string, siteName: string): Promise<RouteListQueryResult[]>;
|
|
130
|
+
/**
|
|
131
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
132
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
133
|
+
* want to use something else.
|
|
134
|
+
* @returns {GraphQLClient} implementation
|
|
135
|
+
*/
|
|
136
|
+
protected getGraphQLClient(): GraphQLClient;
|
|
137
|
+
/**
|
|
138
|
+
* Fetch a flat list of all pages that belong to the specificed site and have a
|
|
139
|
+
* version in the specified language(s).
|
|
140
|
+
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
141
|
+
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
142
|
+
* @returns list of pages
|
|
143
|
+
* @throws {RangeError} if the list of languages is empty.
|
|
144
|
+
* @throws {RangeError} if the any of the languages is an empty string.
|
|
145
|
+
*/
|
|
146
|
+
protected abstract fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
147
|
+
}
|
|
148
|
+
export {};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
|
|
2
|
+
import { LayoutServiceData, ComponentRendering, PlaceholdersData } from '@sitecore-content-sdk/core/layout';
|
|
3
|
+
import { ComponentPropsCollection, ComponentPropsFetchFunction } from '../sharedTypes/component-props';
|
|
4
|
+
import { ModuleFactory } from '../sharedTypes/module-factory';
|
|
5
|
+
export type FetchComponentPropsArguments<NextContext> = {
|
|
6
|
+
layoutData: LayoutServiceData;
|
|
7
|
+
context: NextContext;
|
|
8
|
+
moduleFactory: ModuleFactory;
|
|
9
|
+
};
|
|
10
|
+
export type ComponentPropsRequest<NextContext> = {
|
|
11
|
+
fetch: ComponentPropsFetchFunction<NextContext>;
|
|
12
|
+
layoutData: LayoutServiceData;
|
|
13
|
+
rendering: ComponentRendering;
|
|
14
|
+
context: NextContext;
|
|
15
|
+
};
|
|
16
|
+
type FetchFunctionFactory<NextContext> = (componentName: string) => Promise<ComponentPropsFetchFunction<NextContext> | undefined>;
|
|
17
|
+
export declare class ComponentPropsService {
|
|
18
|
+
/**
|
|
19
|
+
* SSR mode
|
|
20
|
+
* Fetch component props using getServerSideProps function
|
|
21
|
+
* @param {FetchComponentPropsArguments<GetServerSidePropsContext>} params fetch params
|
|
22
|
+
* @returns {Promise<ComponentPropsCollection>} props
|
|
23
|
+
*/
|
|
24
|
+
fetchServerSideComponentProps(params: FetchComponentPropsArguments<GetServerSidePropsContext>): Promise<ComponentPropsCollection>;
|
|
25
|
+
/**
|
|
26
|
+
* SSG mode
|
|
27
|
+
* Fetch component props using getStaticProps function
|
|
28
|
+
* @param {FetchComponentPropsArguments<GetStaticPropsContext>} params fetch arguments
|
|
29
|
+
* @returns {Promise<ComponentPropsCollection>} props
|
|
30
|
+
*/
|
|
31
|
+
fetchStaticComponentProps(params: FetchComponentPropsArguments<GetStaticPropsContext>): Promise<ComponentPropsCollection>;
|
|
32
|
+
/**
|
|
33
|
+
* Traverse Layout Service data tree and call side effects on component level.
|
|
34
|
+
* Side effect function can be: getStaticProps (SSG) or getServerSideProps (SSR)
|
|
35
|
+
* @param {FetchFunctionFactory<NextContext>} fetchFunctionFactory fetch function factory
|
|
36
|
+
* @param {LayoutServiceData} layoutData layout data
|
|
37
|
+
* @param {NextContext} context next context
|
|
38
|
+
* @returns {Promise<ComponentPropsCollection>} component props
|
|
39
|
+
*/
|
|
40
|
+
protected fetchComponentProps<NextContext>(fetchFunctionFactory: FetchFunctionFactory<NextContext>, layoutData: LayoutServiceData, context: NextContext): Promise<ComponentPropsCollection>;
|
|
41
|
+
/**
|
|
42
|
+
* Go through layout service data, check all renderings using displayName, which should make some side effects.
|
|
43
|
+
* Write result in requests variable
|
|
44
|
+
* @param {object} params params
|
|
45
|
+
* @param {PlaceholdersData} [params.placeholders]
|
|
46
|
+
* @param {FetchFunctionFactory<NextContext>} params.fetchFunctionFactory
|
|
47
|
+
* @param {LayoutServiceData} params.layoutData
|
|
48
|
+
* @param {NextContext} params.context
|
|
49
|
+
* @param {ComponentPropsRequest<NextContext>[]} params.requests
|
|
50
|
+
* @returns {ComponentPropsRequest<NextContext>[]} array of requests
|
|
51
|
+
*/
|
|
52
|
+
protected collectRequests<NextContext>(params: {
|
|
53
|
+
placeholders?: PlaceholdersData;
|
|
54
|
+
fetchFunctionFactory: FetchFunctionFactory<NextContext>;
|
|
55
|
+
layoutData: LayoutServiceData;
|
|
56
|
+
context: NextContext;
|
|
57
|
+
requests?: ComponentPropsRequest<NextContext>[];
|
|
58
|
+
}): Promise<ComponentPropsRequest<NextContext>[]>;
|
|
59
|
+
/**
|
|
60
|
+
* Execute request for component props
|
|
61
|
+
* @param {ComponentPropsRequest<NextContext>[]} requests requests
|
|
62
|
+
* @returns {Promise<ComponentPropsCollection>} requests result
|
|
63
|
+
*/
|
|
64
|
+
protected execRequests<NextContext>(requests: ComponentPropsRequest<NextContext>[]): Promise<ComponentPropsCollection>;
|
|
65
|
+
/**
|
|
66
|
+
* Take renderings from all placeholders and returns a flat array of renderings.
|
|
67
|
+
* @example
|
|
68
|
+
* const placeholders = {
|
|
69
|
+
* x1: [{ uid: 1 }, { uid: 2 }],
|
|
70
|
+
* x2: [{ uid: 11 }, { uid: 22 }]
|
|
71
|
+
* }
|
|
72
|
+
*
|
|
73
|
+
* flatRenderings(placeholders);
|
|
74
|
+
*
|
|
75
|
+
* RESULT: [{ uid: 1 }, { uid: 2 }, { uid: 11 }, { uid: 22 }]
|
|
76
|
+
* @param {PlaceholdersData} placeholders placeholders
|
|
77
|
+
* @returns {ComponentRendering[]} renderings
|
|
78
|
+
*/
|
|
79
|
+
protected flatRenderings(placeholders: PlaceholdersData): ComponentRendering[];
|
|
80
|
+
}
|
|
81
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BaseGraphQLSitemapService, BaseGraphQLSitemapServiceConfig } from './base-graphql-sitemap-service';
|
|
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
|
+
* Configuration options for @see GraphQLSitemapService instances
|
|
12
|
+
*/
|
|
13
|
+
export interface GraphQLSitemapServiceConfig extends BaseGraphQLSitemapServiceConfig {
|
|
14
|
+
/**
|
|
15
|
+
* Name of the site to retrieve site paths for
|
|
16
|
+
*/
|
|
17
|
+
siteName: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Object model of a site page item.
|
|
21
|
+
*/
|
|
22
|
+
export type StaticPath = {
|
|
23
|
+
params: {
|
|
24
|
+
path: string[];
|
|
25
|
+
};
|
|
26
|
+
locale?: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Service that fetches the list of site pages using Sitecore's GraphQL API.
|
|
30
|
+
* Used to handle a single site
|
|
31
|
+
* This list is used for SSG and Export functionality.
|
|
32
|
+
* @mixes SearchQueryService<PageListQueryResult>
|
|
33
|
+
*/
|
|
34
|
+
export declare class GraphQLSitemapService extends BaseGraphQLSitemapService {
|
|
35
|
+
options: GraphQLSitemapServiceConfig;
|
|
36
|
+
/**
|
|
37
|
+
* Creates an instance of graphQL sitemap service with the provided options
|
|
38
|
+
* @param {GraphQLSitemapServiceConfig} options instance
|
|
39
|
+
*/
|
|
40
|
+
constructor(options: GraphQLSitemapServiceConfig);
|
|
41
|
+
/**
|
|
42
|
+
* Fetch a flat list of all pages that belong to the specificed site and have a
|
|
43
|
+
* version in the specified language(s).
|
|
44
|
+
* @param {string[]} languages Fetch pages that have versions in this language(s).
|
|
45
|
+
* @param {Function} formatStaticPath Function for transforming the raw search results into (@see StaticPath) types.
|
|
46
|
+
* @returns list of pages
|
|
47
|
+
* @throws {RangeError} if the list of languages is empty.
|
|
48
|
+
* @throws {RangeError} if the any of the languages is an empty string.
|
|
49
|
+
*/
|
|
50
|
+
protected fetchSitemap(languages: string[], formatStaticPath: (path: string[], language: string) => StaticPath): Promise<StaticPath[]>;
|
|
51
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GetServerSidePropsContext, GetStaticPropsContext } from 'next';
|
|
2
|
+
import { ComponentRendering, LayoutServiceData } from '@sitecore-content-sdk/core/layout';
|
|
3
|
+
export type ComponentPropsError = {
|
|
4
|
+
error: string;
|
|
5
|
+
componentName: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Shape of component props storage
|
|
9
|
+
*/
|
|
10
|
+
export type ComponentPropsCollection = {
|
|
11
|
+
[componentUid: string]: unknown | ComponentPropsError;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Type of side effect function which could be invoked on component level (getStaticProps/getServerSideProps)
|
|
15
|
+
*/
|
|
16
|
+
export type ComponentPropsFetchFunction<NextContext, FetchedProps = unknown> = {
|
|
17
|
+
(rendering: ComponentRendering, layoutData: LayoutServiceData, context: NextContext): Promise<FetchedProps>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Shape of getServerSideProps function on component level
|
|
21
|
+
*/
|
|
22
|
+
export type GetServerSideComponentProps = ComponentPropsFetchFunction<GetServerSidePropsContext>;
|
|
23
|
+
/**
|
|
24
|
+
* Shape of getStaticProps function on component level
|
|
25
|
+
*/
|
|
26
|
+
export type GetStaticComponentProps = ComponentPropsFetchFunction<GetStaticPropsContext>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ComponentType } from 'react';
|
|
2
|
+
import { GetServerSideComponentProps, GetStaticComponentProps } from './component-props';
|
|
3
|
+
/**
|
|
4
|
+
* Represents a module (file)
|
|
5
|
+
*/
|
|
6
|
+
export type Module = {
|
|
7
|
+
/**
|
|
8
|
+
* Default SXA export
|
|
9
|
+
*/
|
|
10
|
+
Default?: ComponentType;
|
|
11
|
+
/**
|
|
12
|
+
* Default Next.js export
|
|
13
|
+
*/
|
|
14
|
+
default?: ComponentType;
|
|
15
|
+
/**
|
|
16
|
+
* function for component level data fetching in SSR mode
|
|
17
|
+
*/
|
|
18
|
+
getServerSideProps?: GetServerSideComponentProps;
|
|
19
|
+
/**
|
|
20
|
+
* function for component level data fetching in SSG mode
|
|
21
|
+
*/
|
|
22
|
+
getStaticProps?: GetStaticComponentProps;
|
|
23
|
+
} & {
|
|
24
|
+
/**
|
|
25
|
+
* Custom exports
|
|
26
|
+
*/
|
|
27
|
+
[key: string]: ComponentType;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Represents a module factory
|
|
31
|
+
*/
|
|
32
|
+
export type ModuleFactory = (componentName: string) => Module | Promise<Module> | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SiteResolver, SiteInfo } from '@sitecore-content-sdk/core/site';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Since Sitecore editors do not support Fast Refresh:
|
|
3
|
+
* 1. Subscribe on events provided by webpack.
|
|
4
|
+
* 2. Reset editor chromes when build is finished
|
|
5
|
+
* @param {boolean} [forceReload] force page reload instead of reset chromes
|
|
6
|
+
*/
|
|
7
|
+
export declare const handleEditorFastRefresh: (forceReload?: boolean) => void;
|
|
8
|
+
export declare const getJssEditingSecret: () => string;
|
package/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/utils/index';
|
package/utils.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/utils/index');
|