@sitecore-jss/sitecore-jss-nextjs 21.7.0-canary.5 → 21.7.0-canary.50
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/context.d.ts +1 -0
- package/context.js +1 -0
- package/dist/cjs/context/context.js +83 -0
- package/dist/cjs/context/index.js +5 -0
- package/dist/cjs/editing/editing-render-middleware.js +1 -1
- package/dist/cjs/index.js +5 -3
- package/dist/cjs/middleware/middleware.js +17 -0
- package/dist/cjs/middleware/multisite-middleware.js +1 -6
- package/dist/cjs/middleware/personalize-middleware.js +34 -47
- package/dist/cjs/middleware/redirects-middleware.js +31 -13
- package/dist/cjs/revalidate/index.js +5 -0
- package/dist/cjs/revalidate/revalidate-middleware.js +216 -0
- package/dist/cjs/utils/utils.js +6 -18
- package/dist/esm/context/context.js +79 -0
- package/dist/esm/context/index.js +1 -0
- package/dist/esm/editing/editing-render-middleware.js +1 -1
- package/dist/esm/index.js +3 -2
- package/dist/esm/middleware/middleware.js +17 -0
- package/dist/esm/middleware/multisite-middleware.js +1 -6
- package/dist/esm/middleware/personalize-middleware.js +35 -48
- package/dist/esm/middleware/redirects-middleware.js +31 -13
- package/dist/esm/revalidate/index.js +1 -0
- package/dist/esm/revalidate/revalidate-middleware.js +212 -0
- package/dist/esm/utils/utils.js +6 -15
- package/package.json +11 -11
- package/revalidate.d.ts +1 -0
- package/revalidate.js +1 -0
- package/types/context/context.d.ts +116 -0
- package/types/context/index.d.ts +1 -0
- package/types/editing/editing-render-middleware.d.ts +1 -1
- package/types/index.d.ts +3 -2
- package/types/middleware/middleware.d.ts +8 -0
- package/types/middleware/personalize-middleware.d.ts +20 -15
- package/types/revalidate/index.d.ts +1 -0
- package/types/revalidate/revalidate-middleware.d.ts +115 -0
- package/types/utils/utils.d.ts +1 -0
package/dist/esm/utils/utils.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
1
|
import { isEditorActive, resetEditorChromes } from '@sitecore-jss/sitecore-jss/utils';
|
|
3
2
|
/**
|
|
4
3
|
* Get the publicUrl.
|
|
@@ -7,27 +6,19 @@ import { isEditorActive, resetEditorChromes } from '@sitecore-jss/sitecore-jss/u
|
|
|
7
6
|
* VERCEL_URL is provided by Vercel in case if we are in Preview deployment (deployment based on the custom branch),
|
|
8
7
|
* preview deployment has unique url, we don't know exact url.
|
|
9
8
|
* Similarly, DEPLOY_URL is provided by Netlify and would give us the deploy URL
|
|
9
|
+
* In production non-editing environments it is desirable to use relative urls, so in that case set PUBLIC_URL = ''
|
|
10
10
|
*/
|
|
11
11
|
export const getPublicUrl = () => {
|
|
12
|
-
if (process.env.NETLIFY && process.env.DEPLOY_URL)
|
|
13
|
-
return process.env.DEPLOY_URL;
|
|
14
|
-
if (process.env.VERCEL_URL)
|
|
15
|
-
return `https://${process.env.VERCEL_URL}`;
|
|
16
12
|
let url = process.env.PUBLIC_URL;
|
|
17
13
|
if (url === undefined) {
|
|
18
|
-
|
|
14
|
+
if (process.env.NETLIFY && process.env.DEPLOY_URL)
|
|
15
|
+
return process.env.DEPLOY_URL;
|
|
16
|
+
if (process.env.VERCEL_URL)
|
|
17
|
+
return `https://${process.env.VERCEL_URL}`;
|
|
19
18
|
url = 'http://localhost:3000';
|
|
20
19
|
}
|
|
21
|
-
else {
|
|
22
|
-
try {
|
|
23
|
-
new URL(url);
|
|
24
|
-
}
|
|
25
|
-
catch (error) {
|
|
26
|
-
throw new Error(`The PUBLIC_URL environment variable '${url}' is not a valid URL.`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
20
|
// Ensure no trailing slash
|
|
30
|
-
return url.
|
|
21
|
+
return url.replace(/\/$/, '');
|
|
31
22
|
};
|
|
32
23
|
/**
|
|
33
24
|
* Since Sitecore editors do not support Fast Refresh:
|
package/package.json
CHANGED
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "21.7.0-canary.
|
|
3
|
+
"version": "21.7.0-canary.50",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig-esm.json",
|
|
9
9
|
"clean": "del-cli dist types",
|
|
10
|
-
"lint": "eslint ./src/**/*.tsx ./src/**/*.ts",
|
|
10
|
+
"lint": "eslint \"./src/**/*.tsx\" \"./src/**/*.ts\"",
|
|
11
11
|
"test": "mocha --require ./test/setup.js \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
13
|
"coverage": "nyc npm test",
|
|
14
|
-
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --githubPages false"
|
|
14
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --entryPoints src/context/index.ts --entryPoints src/utils/index.ts --entryPoints src/site/index.ts --entryPoints src/graphql/index.ts --entryPoints src/revalidate/index.ts --githubPages false"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
|
-
"node": ">=
|
|
18
|
-
"npm": ">=6"
|
|
17
|
+
"node": ">=18"
|
|
19
18
|
},
|
|
20
19
|
"author": {
|
|
21
20
|
"name": "Sitecore Corporation",
|
|
@@ -30,7 +29,7 @@
|
|
|
30
29
|
"url": "https://github.com/sitecore/jss/issues"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@sitecore/
|
|
32
|
+
"@sitecore-cloudsdk/personalize": "^0.1.1",
|
|
34
33
|
"@types/chai": "^4.3.4",
|
|
35
34
|
"@types/chai-as-promised": "^7.1.5",
|
|
36
35
|
"@types/chai-string": "^1.4.2",
|
|
@@ -66,15 +65,16 @@
|
|
|
66
65
|
"typescript": "~4.9.4"
|
|
67
66
|
},
|
|
68
67
|
"peerDependencies": {
|
|
69
|
-
"@sitecore/
|
|
68
|
+
"@sitecore-cloudsdk/events": "^0.1.1",
|
|
69
|
+
"@sitecore-cloudsdk/personalize": "^0.1.1",
|
|
70
70
|
"next": "^13.4.16",
|
|
71
71
|
"react": "^18.2.0",
|
|
72
72
|
"react-dom": "^18.2.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@sitecore-jss/sitecore-jss": "^21.7.0-canary.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^21.7.0-canary.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^21.7.0-canary.
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "^21.7.0-canary.50",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^21.7.0-canary.50",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "^21.7.0-canary.50",
|
|
78
78
|
"@vercel/kv": "^0.2.1",
|
|
79
79
|
"node-html-parser": "^6.1.4",
|
|
80
80
|
"prop-types": "^15.8.1",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
},
|
|
84
84
|
"description": "",
|
|
85
85
|
"types": "types/index.d.ts",
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "2280864898b84d0472c54175075a1628e63a29b0",
|
|
87
87
|
"files": [
|
|
88
88
|
"dist",
|
|
89
89
|
"types",
|
package/revalidate.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/revalidate/index';
|
package/revalidate.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/revalidate/index');
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { LayoutServicePageState } from '@sitecore-jss/sitecore-jss-react';
|
|
2
|
+
/**
|
|
3
|
+
* Software Development Kit (SDK) instance
|
|
4
|
+
*/
|
|
5
|
+
export type SDK<SDKType = unknown> = {
|
|
6
|
+
/**
|
|
7
|
+
* The Software Development Kit (SDK) library instance
|
|
8
|
+
*/
|
|
9
|
+
sdk: SDKType;
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the Software Development Kit (SDK)
|
|
12
|
+
*/
|
|
13
|
+
init: (props: InitSDKProps) => Promise<void>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Software Development Kits (SDKs) to be initialized
|
|
17
|
+
*/
|
|
18
|
+
type SDKModulesType = Record<string, SDK>;
|
|
19
|
+
/**
|
|
20
|
+
* Properties that are passed to the Context.
|
|
21
|
+
*/
|
|
22
|
+
export interface ContextInitProps {
|
|
23
|
+
/**
|
|
24
|
+
* Your Sitecore site name
|
|
25
|
+
*/
|
|
26
|
+
siteName?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Sitecore page state (normal, preview, edit)
|
|
29
|
+
*/
|
|
30
|
+
pageState?: LayoutServicePageState;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Configuration that is passed to the Context.
|
|
34
|
+
*/
|
|
35
|
+
export interface ContextConfig<SDKModules extends SDKModulesType> {
|
|
36
|
+
/**
|
|
37
|
+
* Your Sitecore Edge URL
|
|
38
|
+
*/
|
|
39
|
+
sitecoreEdgeUrl: string;
|
|
40
|
+
/**
|
|
41
|
+
* Your Sitecore Edge Context ID
|
|
42
|
+
*/
|
|
43
|
+
sitecoreEdgeContextId: string;
|
|
44
|
+
/**
|
|
45
|
+
* Your Sitecore site name
|
|
46
|
+
*/
|
|
47
|
+
siteName: string;
|
|
48
|
+
/**
|
|
49
|
+
* Software Development Kits (SDKs) to be initialized
|
|
50
|
+
*/
|
|
51
|
+
sdks: {
|
|
52
|
+
[module in keyof SDKModules]: SDKModules[module];
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Properties that are passed to the Software Development Kit (SDK) initialization function.
|
|
57
|
+
*/
|
|
58
|
+
type InitSDKProps = Omit<ContextConfig<SDKModulesType>, 'sdks'>;
|
|
59
|
+
/**
|
|
60
|
+
* Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
|
|
61
|
+
*/
|
|
62
|
+
export declare class Context<SDKModules extends SDKModulesType> {
|
|
63
|
+
protected props: ContextConfig<SDKModules>;
|
|
64
|
+
/**
|
|
65
|
+
* Indicates whether the Context and SDK(s) have been initialized
|
|
66
|
+
*/
|
|
67
|
+
isInitialized: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* The Sitecore Edge URL
|
|
70
|
+
*/
|
|
71
|
+
readonly sitecoreEdgeUrl: string;
|
|
72
|
+
/**
|
|
73
|
+
* The Sitecore Edge Context ID
|
|
74
|
+
*/
|
|
75
|
+
readonly sitecoreEdgeContextId: string;
|
|
76
|
+
/**
|
|
77
|
+
* The Sitecore site name
|
|
78
|
+
*/
|
|
79
|
+
siteName: string;
|
|
80
|
+
/**
|
|
81
|
+
* Sitecore page state (normal, preview, edit)
|
|
82
|
+
*/
|
|
83
|
+
pageState: LayoutServicePageState;
|
|
84
|
+
/**
|
|
85
|
+
* Software Development Kits (SDKs) to be initialized
|
|
86
|
+
*/
|
|
87
|
+
readonly sdks: {
|
|
88
|
+
[module in keyof SDKModules]?: SDKModules[module]['sdk'];
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Promises for the SDKs
|
|
92
|
+
*/
|
|
93
|
+
protected sdkPromises: {
|
|
94
|
+
[module in keyof SDKModules]?: Promise<SDKModules[module]['sdk']>;
|
|
95
|
+
};
|
|
96
|
+
protected sdkErrors: {
|
|
97
|
+
[module in keyof SDKModules]?: string;
|
|
98
|
+
};
|
|
99
|
+
constructor(props: ContextConfig<SDKModules>);
|
|
100
|
+
init(props?: ContextInitProps): void;
|
|
101
|
+
/**
|
|
102
|
+
* Retrieves the Software Development Kit (SDK) instance, ensuring it is initialized before returning
|
|
103
|
+
*
|
|
104
|
+
* @param {string} name SDK name
|
|
105
|
+
* @returns initialized SDK
|
|
106
|
+
*/
|
|
107
|
+
getSDK: <T extends keyof SDKModules>(name: T) => Promise<SDKModules[T]["sdk"]>;
|
|
108
|
+
/**
|
|
109
|
+
* Initializes the Software Development Kit (SDK)
|
|
110
|
+
*
|
|
111
|
+
* @param {T} name SDK name
|
|
112
|
+
* @returns {void}
|
|
113
|
+
*/
|
|
114
|
+
protected initSDK<T extends keyof SDKModules>(name: T): void;
|
|
115
|
+
}
|
|
116
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Context, ContextConfig, SDK } from './context';
|
|
@@ -57,7 +57,7 @@ export declare class EditingRenderMiddleware {
|
|
|
57
57
|
getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
58
58
|
/**
|
|
59
59
|
* Gets query parameters that should be passed along to subsequent requests
|
|
60
|
-
* @param query Object of query parameters from incoming URL
|
|
60
|
+
* @param {Object} query Object of query parameters from incoming URL
|
|
61
61
|
* @returns Object of approved query parameters
|
|
62
62
|
*/
|
|
63
63
|
protected getQueryParamsForPropagation: (query: Partial<{
|
package/types/index.d.ts
CHANGED
|
@@ -8,11 +8,11 @@ declare const GraphQLRequestClient: typeof GraphQLRequestClientDep;
|
|
|
8
8
|
export { GraphQLRequestClient };
|
|
9
9
|
export { handleEditorFastRefresh, getPublicUrl };
|
|
10
10
|
export { isEditorActive, resetEditorChromes, resolveUrl, tryParseEnvValue };
|
|
11
|
-
export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, RestLayoutService, RestLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-jss/sitecore-jss/layout';
|
|
11
|
+
export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, RestLayoutService, RestLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, getContentStylesheetLink, } from '@sitecore-jss/sitecore-jss/layout';
|
|
12
12
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
13
13
|
export { trackingApi, TrackingRequestOptions, CampaignInstance, GoalInstance, OutcomeInstance, EventInstance, PageViewInstance, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
14
14
|
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQLDictionaryServiceConfig, RestDictionaryService, RestDictionaryServiceConfig, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
15
|
-
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper,
|
|
15
|
+
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
16
16
|
export { ComponentPropsCollection, ComponentPropsError, GetStaticComponentProps, GetServerSideComponentProps, } from './sharedTypes/component-props';
|
|
17
17
|
export { ModuleFactory, Module } from './sharedTypes/module-factory';
|
|
18
18
|
export { ComponentPropsService } from './services/component-props-service';
|
|
@@ -32,4 +32,5 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
32
32
|
export { FEaaSWrapper };
|
|
33
33
|
export { BYOCWrapper };
|
|
34
34
|
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
|
35
|
+
export { Context, ContextConfig, SDK } from './context';
|
|
35
36
|
export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getFEAASLibraryStylesheetLinks, File, FileField, RichTextField, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -28,6 +28,7 @@ export type MiddlewareBaseConfig = {
|
|
|
28
28
|
export declare abstract class MiddlewareBase {
|
|
29
29
|
protected config: MiddlewareBaseConfig;
|
|
30
30
|
protected SITE_SYMBOL: string;
|
|
31
|
+
protected REWRITE_HEADER_NAME: string;
|
|
31
32
|
protected defaultHostname: string;
|
|
32
33
|
constructor(config: MiddlewareBaseConfig);
|
|
33
34
|
/**
|
|
@@ -65,4 +66,11 @@ export declare abstract class MiddlewareBase {
|
|
|
65
66
|
* @returns {SiteInfo} site information
|
|
66
67
|
*/
|
|
67
68
|
protected getSite(req: NextRequest, res?: NextResponse): SiteInfo;
|
|
69
|
+
/**
|
|
70
|
+
* Create a rewrite response
|
|
71
|
+
* @param {string} rewritePath the destionation path
|
|
72
|
+
* @param {NextRequest} req the current request
|
|
73
|
+
* @param {NextResponse} res the current response
|
|
74
|
+
*/
|
|
75
|
+
protected rewrite(rewritePath: string, req: NextRequest, res: NextResponse): NextResponse;
|
|
68
76
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import { GraphQLPersonalizeServiceConfig } from '@sitecore-jss/sitecore-jss/personalize';
|
|
3
|
-
import { SiteInfo } from '@sitecore-jss/sitecore-jss/site';
|
|
2
|
+
import { GraphQLPersonalizeServiceConfig, PersonalizeInfo } from '@sitecore-jss/sitecore-jss/personalize';
|
|
4
3
|
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
5
|
-
import { EngageServer } from '@sitecore/engage';
|
|
6
4
|
export type CdpServiceConfig = {
|
|
7
5
|
/**
|
|
8
|
-
* Your Sitecore
|
|
6
|
+
* Your Sitecore Edge Platform endpoint
|
|
7
|
+
* Default is https://edge-platform.sitecorecloud.io
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
sitecoreEdgeUrl?: string;
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
11
|
+
* Your unified Sitecore Edge Context Id
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
sitecoreEdgeContextId: string;
|
|
15
14
|
/**
|
|
16
15
|
* The Sitecore CDP channel to use for events. Uses 'WEB' by default.
|
|
17
16
|
*/
|
|
@@ -34,13 +33,6 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
|
34
33
|
* Configuration for your Sitecore CDP endpoint
|
|
35
34
|
*/
|
|
36
35
|
cdpConfig: CdpServiceConfig;
|
|
37
|
-
/**
|
|
38
|
-
* function to resolve point of sale for a site
|
|
39
|
-
* @param {Siteinfo} site to get info from
|
|
40
|
-
* @param {string} language to get info for
|
|
41
|
-
* @returns point of sale value for site/language combination
|
|
42
|
-
*/
|
|
43
|
-
getPointOfSale?: (site: SiteInfo, language: string) => string;
|
|
44
36
|
};
|
|
45
37
|
/**
|
|
46
38
|
* Object model of Experience Context data
|
|
@@ -70,7 +62,20 @@ export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
70
62
|
* @returns middleware handler
|
|
71
63
|
*/
|
|
72
64
|
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
73
|
-
protected
|
|
65
|
+
protected initPersonalizeServer({ hostname, siteName, request, response, }: {
|
|
66
|
+
hostname: string;
|
|
67
|
+
siteName: string;
|
|
68
|
+
request: NextRequest;
|
|
69
|
+
response: NextResponse;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
protected personalize({ params, personalizeInfo, language, timeout, }: {
|
|
72
|
+
personalizeInfo: PersonalizeInfo;
|
|
73
|
+
params: ExperienceParams;
|
|
74
|
+
language: string;
|
|
75
|
+
timeout?: number;
|
|
76
|
+
}, request: NextRequest): Promise<{
|
|
77
|
+
variantId: string;
|
|
78
|
+
}>;
|
|
74
79
|
protected getExperienceParams(req: NextRequest): ExperienceParams;
|
|
75
80
|
protected excludeRoute(pathname: string): boolean | undefined;
|
|
76
81
|
private handler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { RevalidateMiddleware } from './revalidate-middleware';
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { NextApiResponse, NextApiRequest } from 'next';
|
|
2
|
+
import { GraphQLRequestClientFactory } from '@sitecore-jss/sitecore-jss/graphql';
|
|
3
|
+
declare enum EntityDefinition {
|
|
4
|
+
LayoutData = "LayoutData",
|
|
5
|
+
Item = "Item"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Object model of each updated entity returned from the webhook payload
|
|
9
|
+
*/
|
|
10
|
+
export type Entity = {
|
|
11
|
+
identifier: string;
|
|
12
|
+
entity_definition: EntityDefinition;
|
|
13
|
+
operation: string;
|
|
14
|
+
entity_culture: string;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Object model for updated paths returned from the webhook payload
|
|
18
|
+
*/
|
|
19
|
+
export type UpdatedPaths = {
|
|
20
|
+
path: string;
|
|
21
|
+
language: string;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Object model for personalized results from GraphqlPersonalizeService
|
|
25
|
+
*/
|
|
26
|
+
export type PersonalizedResult = {
|
|
27
|
+
path: string;
|
|
28
|
+
variantId: string;
|
|
29
|
+
};
|
|
30
|
+
export type RevalidateConfig = {
|
|
31
|
+
/**
|
|
32
|
+
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
33
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
34
|
+
*/
|
|
35
|
+
clientFactory: GraphQLRequestClientFactory;
|
|
36
|
+
/**
|
|
37
|
+
* Indicates whether multisite functionality is enabled.
|
|
38
|
+
* Default is false
|
|
39
|
+
*/
|
|
40
|
+
multiSite?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Indicates whether personalization is enabled.
|
|
43
|
+
* Default is false
|
|
44
|
+
*/
|
|
45
|
+
personalize?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Function to handle language prefixes for different locales.
|
|
48
|
+
* @param language - The language to generate the prefix for.
|
|
49
|
+
* @returns The language prefix or null.
|
|
50
|
+
*/
|
|
51
|
+
localePrefix?: (language: string) => string | null;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Middleware / handler for on-demand ISR (e.g. '/api/revalidate').
|
|
55
|
+
*/
|
|
56
|
+
export declare class RevalidateMiddleware {
|
|
57
|
+
protected config: RevalidateConfig;
|
|
58
|
+
private personalizeService;
|
|
59
|
+
constructor(config: RevalidateConfig);
|
|
60
|
+
/**
|
|
61
|
+
* Generates a Next.js API route handler that executes a revalidation process.
|
|
62
|
+
* @returns The route handler function for handling Next.js API requests.
|
|
63
|
+
*/
|
|
64
|
+
getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Gets personalized results for the updated paths
|
|
67
|
+
* @param {UpdatedPaths[]} filteredUpdates Updated paths
|
|
68
|
+
*/
|
|
69
|
+
getPersonalizedResults(filteredUpdates: UpdatedPaths[]): Promise<{
|
|
70
|
+
personalized: PersonalizedResult[];
|
|
71
|
+
nonPersonalized: {
|
|
72
|
+
path: string;
|
|
73
|
+
}[];
|
|
74
|
+
}>;
|
|
75
|
+
protected isEmpty(data: UpdatedPaths[]): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Extracts the paths from the updated paths
|
|
78
|
+
* @param {UpdatedPaths[]} filteredUpdates Updated paths
|
|
79
|
+
* @returns {string[]} paths
|
|
80
|
+
*/
|
|
81
|
+
protected extractPaths(filteredUpdates: UpdatedPaths[]): string[];
|
|
82
|
+
/**
|
|
83
|
+
* Gets the site name from the path name
|
|
84
|
+
* @param {string} pathname Path name
|
|
85
|
+
* @returns {string} site name
|
|
86
|
+
*/
|
|
87
|
+
protected getSiteName(pathname: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Gets the path name from the full path
|
|
90
|
+
* @param {string} fullPath Full path
|
|
91
|
+
* @returns {string} path name
|
|
92
|
+
*/
|
|
93
|
+
protected getPathName(fullPath: string): string;
|
|
94
|
+
protected extractSiteName(path: string): string;
|
|
95
|
+
/**
|
|
96
|
+
* Filters out the updated paths and language from the request body
|
|
97
|
+
* @param {NextApiRequest} req Next.js API request
|
|
98
|
+
* @returns {UpdatedPaths[]} updated paths
|
|
99
|
+
*/
|
|
100
|
+
protected getFilteredUpdates(req: NextApiRequest): UpdatedPaths[];
|
|
101
|
+
protected handleMultiSitePersonalization(personalizeInfo: {
|
|
102
|
+
personalized: PersonalizedResult[];
|
|
103
|
+
nonPersonalized: {
|
|
104
|
+
path: string;
|
|
105
|
+
}[];
|
|
106
|
+
}, pathsToRevalidate: string[], getPathName: (x: string) => string, getSiteName: (x: string) => string): void;
|
|
107
|
+
protected handleNonMultiSitePersonalization(personalizeInfo: {
|
|
108
|
+
personalized: PersonalizedResult[];
|
|
109
|
+
nonPersonalized: {
|
|
110
|
+
path: string;
|
|
111
|
+
}[];
|
|
112
|
+
}, pathsToRevalidate: string[], getPathName: (x: string) => string): void;
|
|
113
|
+
private handler;
|
|
114
|
+
}
|
|
115
|
+
export {};
|
package/types/utils/utils.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* VERCEL_URL is provided by Vercel in case if we are in Preview deployment (deployment based on the custom branch),
|
|
6
6
|
* preview deployment has unique url, we don't know exact url.
|
|
7
7
|
* Similarly, DEPLOY_URL is provided by Netlify and would give us the deploy URL
|
|
8
|
+
* In production non-editing environments it is desirable to use relative urls, so in that case set PUBLIC_URL = ''
|
|
8
9
|
*/
|
|
9
10
|
export declare const getPublicUrl: () => string;
|
|
10
11
|
/**
|