@sitecore-jss/sitecore-jss-nextjs 21.6.0-canary.4 → 21.6.0-canary.41
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/README.md +1 -4
- package/context.d.ts +1 -0
- package/context.js +1 -0
- package/dist/cjs/context/context.js +68 -0
- package/dist/cjs/context/index.js +5 -0
- package/dist/cjs/editing/constants.js +6 -0
- package/dist/cjs/editing/editing-data-middleware.js +2 -2
- package/dist/cjs/editing/editing-data-service.js +15 -7
- package/dist/cjs/editing/editing-render-middleware.js +31 -8
- package/dist/cjs/graphql/index.js +6 -0
- package/dist/cjs/index.js +11 -5
- package/dist/cjs/middleware/personalize-middleware.js +42 -33
- package/dist/cjs/middleware/redirects-middleware.js +6 -3
- package/dist/cjs/services/base-graphql-sitemap-service.js +8 -0
- package/dist/cjs/utils/utils.js +6 -18
- package/dist/esm/context/context.js +64 -0
- package/dist/esm/context/index.js +1 -0
- package/dist/esm/editing/constants.js +3 -0
- package/dist/esm/editing/editing-data-middleware.js +1 -1
- package/dist/esm/editing/editing-data-service.js +13 -5
- package/dist/esm/editing/editing-render-middleware.js +31 -8
- package/dist/esm/graphql/index.js +1 -0
- package/dist/esm/index.js +9 -3
- package/dist/esm/middleware/personalize-middleware.js +43 -34
- package/dist/esm/middleware/redirects-middleware.js +6 -3
- package/dist/esm/services/base-graphql-sitemap-service.js +9 -1
- package/dist/esm/utils/utils.js +6 -15
- package/graphql.d.ts +1 -0
- package/graphql.js +1 -0
- package/package.json +10 -10
- package/types/ComponentBuilder.d.ts +1 -0
- package/types/components/ComponentPropsContext.d.ts +1 -0
- package/types/components/Link.d.ts +1 -0
- package/types/components/NextImage.d.ts +1 -0
- package/types/components/Placeholder.d.ts +1 -0
- package/types/context/context.d.ts +113 -0
- package/types/context/index.d.ts +1 -0
- package/types/editing/constants.d.ts +3 -0
- package/types/editing/editing-data-service.d.ts +12 -4
- package/types/editing/editing-render-middleware.d.ts +10 -0
- package/types/graphql/index.d.ts +1 -0
- package/types/index.d.ts +7 -3
- package/types/middleware/personalize-middleware.d.ts +20 -15
- package/types/services/base-graphql-sitemap-service.d.ts +10 -3
- package/types/sharedTypes/module-factory.d.ts +1 -0
- package/types/utils/utils.d.ts +1 -0
|
@@ -7,10 +7,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { QUERY_PARAM_EDITING_SECRET } from './constants';
|
|
10
11
|
import { AxiosDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
|
|
11
12
|
import { editingDataDiskCache } from './editing-data-cache';
|
|
12
13
|
import { getJssEditingSecret } from '../utils/utils';
|
|
13
|
-
export const QUERY_PARAM_EDITING_SECRET = 'secret';
|
|
14
14
|
/**
|
|
15
15
|
* Unique key generator.
|
|
16
16
|
* Need more than just the item GUID since requests are made "live" during editing in EE.
|
|
@@ -93,13 +93,14 @@ export class ServerlessEditingDataService {
|
|
|
93
93
|
* @param {string} serverUrl The server url to use for subsequent data API requests
|
|
94
94
|
* @returns {Promise} The {@link EditingPreviewData} containing the generated key and serverUrl to use for retrieval
|
|
95
95
|
*/
|
|
96
|
-
setEditingData(data, serverUrl) {
|
|
96
|
+
setEditingData(data, serverUrl, params) {
|
|
97
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
98
|
const key = this.generateKey(data);
|
|
99
|
-
const url = this.getUrl(serverUrl, key);
|
|
99
|
+
const url = this.getUrl(serverUrl, key, params);
|
|
100
100
|
const previewData = {
|
|
101
101
|
key,
|
|
102
102
|
serverUrl,
|
|
103
|
+
params,
|
|
103
104
|
};
|
|
104
105
|
debug.editing('storing editing data for %o: %o', previewData, data);
|
|
105
106
|
return this.dataFetcher.put(url, data).then(() => {
|
|
@@ -118,20 +119,27 @@ export class ServerlessEditingDataService {
|
|
|
118
119
|
if (!(editingPreviewData === null || editingPreviewData === void 0 ? void 0 : editingPreviewData.serverUrl)) {
|
|
119
120
|
return undefined;
|
|
120
121
|
}
|
|
121
|
-
const url = this.getUrl(editingPreviewData.serverUrl, editingPreviewData.key);
|
|
122
|
+
const url = this.getUrl(editingPreviewData.serverUrl, editingPreviewData.key, editingPreviewData.params);
|
|
122
123
|
debug.editing('retrieving editing data for %o', previewData);
|
|
123
124
|
return this.dataFetcher.get(url).then((response) => {
|
|
124
125
|
return response.data;
|
|
125
126
|
});
|
|
126
127
|
});
|
|
127
128
|
}
|
|
128
|
-
getUrl(serverUrl, key) {
|
|
129
|
+
getUrl(serverUrl, key, params) {
|
|
129
130
|
var _a;
|
|
130
131
|
// Example URL format:
|
|
131
132
|
// http://localhost:3000/api/editing/data/52961eea-bafd-5287-a532-a72e36bd8a36-qkb4e3fv5x?secret=1234secret
|
|
132
133
|
const apiRoute = (_a = this.apiRoute) === null || _a === void 0 ? void 0 : _a.replace('[key]', key);
|
|
133
134
|
const url = new URL(apiRoute, serverUrl);
|
|
134
135
|
url.searchParams.append(QUERY_PARAM_EDITING_SECRET, getJssEditingSecret());
|
|
136
|
+
if (params) {
|
|
137
|
+
for (const key in params) {
|
|
138
|
+
if ({}.hasOwnProperty.call(params, key)) {
|
|
139
|
+
url.searchParams.append(key, params[key]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
135
143
|
return url.toString();
|
|
136
144
|
}
|
|
137
145
|
}
|
|
@@ -11,7 +11,8 @@ import { STATIC_PROPS_ID, SERVER_PROPS_ID } from 'next/constants';
|
|
|
11
11
|
import { AxiosDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
|
|
12
12
|
import { EDITING_COMPONENT_ID, RenderingType } from '@sitecore-jss/sitecore-jss/layout';
|
|
13
13
|
import { parse } from 'node-html-parser';
|
|
14
|
-
import { editingDataService
|
|
14
|
+
import { editingDataService } from './editing-data-service';
|
|
15
|
+
import { QUERY_PARAM_EDITING_SECRET, QUERY_PARAM_PROTECTION_BYPASS_SITECORE, QUERY_PARAM_PROTECTION_BYPASS_VERCEL, } from './constants';
|
|
15
16
|
import { getJssEditingSecret } from '../utils/utils';
|
|
16
17
|
/**
|
|
17
18
|
* Middleware / handler for use in the editing render Next.js API route (e.g. '/api/editing/render')
|
|
@@ -23,6 +24,21 @@ export class EditingRenderMiddleware {
|
|
|
23
24
|
*/
|
|
24
25
|
constructor(config) {
|
|
25
26
|
var _a, _b, _c, _d;
|
|
27
|
+
/**
|
|
28
|
+
* Gets query parameters that should be passed along to subsequent requests
|
|
29
|
+
* @param query Object of query parameters from incoming URL
|
|
30
|
+
* @returns Object of approved query parameters
|
|
31
|
+
*/
|
|
32
|
+
this.getQueryParamsForPropagation = (query) => {
|
|
33
|
+
const params = {};
|
|
34
|
+
if (query[QUERY_PARAM_PROTECTION_BYPASS_SITECORE]) {
|
|
35
|
+
params[QUERY_PARAM_PROTECTION_BYPASS_SITECORE] = query[QUERY_PARAM_PROTECTION_BYPASS_SITECORE];
|
|
36
|
+
}
|
|
37
|
+
if (query[QUERY_PARAM_PROTECTION_BYPASS_VERCEL]) {
|
|
38
|
+
params[QUERY_PARAM_PROTECTION_BYPASS_VERCEL] = query[QUERY_PARAM_PROTECTION_BYPASS_VERCEL];
|
|
39
|
+
}
|
|
40
|
+
return params;
|
|
41
|
+
};
|
|
26
42
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
27
43
|
var _e, _f;
|
|
28
44
|
const { method, query, body, headers } = req;
|
|
@@ -53,21 +69,28 @@ export class EditingRenderMiddleware {
|
|
|
53
69
|
const editingData = extractEditingData(req);
|
|
54
70
|
// Resolve server URL
|
|
55
71
|
const serverUrl = this.resolveServerUrl(req);
|
|
72
|
+
// Get query string parameters to propagate on subsequent requests (e.g. for deployment protection bypass)
|
|
73
|
+
const params = this.getQueryParamsForPropagation(query);
|
|
56
74
|
// Stash for use later on (i.e. within getStatic/ServerSideProps).
|
|
57
75
|
// Note we can't set this directly in setPreviewData since it's stored as a cookie (2KB limit)
|
|
58
76
|
// https://nextjs.org/docs/advanced-features/preview-mode#previewdata-size-limits)
|
|
59
|
-
const previewData = yield this.editingDataService.setEditingData(editingData, serverUrl);
|
|
77
|
+
const previewData = yield this.editingDataService.setEditingData(editingData, serverUrl, params);
|
|
60
78
|
// Enable Next.js Preview Mode, passing our preview data (i.e. editingData cache key)
|
|
61
79
|
res.setPreviewData(previewData);
|
|
62
80
|
// Grab the Next.js preview cookies to send on to the render request
|
|
63
81
|
const cookies = res.getHeader('Set-Cookie');
|
|
64
|
-
// Make actual render request for page route, passing on preview cookies.
|
|
82
|
+
// Make actual render request for page route, passing on preview cookies as well as any approved query string parameters.
|
|
65
83
|
// Note timestamp effectively disables caching the request in Axios (no amount of cache headers seemed to do it)
|
|
66
|
-
const requestUrl = this.resolvePageUrl(serverUrl, editingData.path);
|
|
67
84
|
debug.editing('fetching page route for %s', editingData.path);
|
|
68
|
-
const
|
|
85
|
+
const requestUrl = new URL(this.resolvePageUrl(serverUrl, editingData.path));
|
|
86
|
+
for (const key in params) {
|
|
87
|
+
if ({}.hasOwnProperty.call(params, key)) {
|
|
88
|
+
requestUrl.searchParams.append(key, params[key]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
requestUrl.searchParams.append('timestamp', Date.now().toString());
|
|
69
92
|
const pageRes = yield this.dataFetcher
|
|
70
|
-
.get(
|
|
93
|
+
.get(requestUrl.toString(), {
|
|
71
94
|
headers: {
|
|
72
95
|
Cookie: cookies.join(';'),
|
|
73
96
|
},
|
|
@@ -82,7 +105,7 @@ export class EditingRenderMiddleware {
|
|
|
82
105
|
});
|
|
83
106
|
let html = pageRes.data;
|
|
84
107
|
if (!html || html.length === 0) {
|
|
85
|
-
throw new Error(`Failed to render html for ${
|
|
108
|
+
throw new Error(`Failed to render html for ${editingData.path}`);
|
|
86
109
|
}
|
|
87
110
|
// replace phkey attribute with key attribute so that newly added renderings
|
|
88
111
|
// show correct placeholders, so save and refresh won't be needed after adding each rendering
|
|
@@ -98,7 +121,7 @@ export class EditingRenderMiddleware {
|
|
|
98
121
|
// Handle component rendering. Extract component markup only
|
|
99
122
|
html = (_f = parse(html).getElementById(EDITING_COMPONENT_ID)) === null || _f === void 0 ? void 0 : _f.innerHTML;
|
|
100
123
|
if (!html)
|
|
101
|
-
throw new Error(`Failed to render component for ${
|
|
124
|
+
throw new Error(`Failed to render component for ${editingData.path}`);
|
|
102
125
|
}
|
|
103
126
|
const body = { html };
|
|
104
127
|
// Return expected JSON result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GraphQLRequestClient, getEdgeProxyContentUrl, } from '@sitecore-jss/sitecore-jss/graphql';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { constants, AxiosDataFetcher, NativeDataFetcher, enableDebug, debug, } from '@sitecore-jss/sitecore-jss';
|
|
2
2
|
// we will remove the root exports for these later
|
|
3
3
|
// we cannot mark exports as deprected directly, so we're using this hack instead
|
|
4
|
+
import { GraphQLRequestClient as GraphQLRequestClientDep } from './graphql';
|
|
4
5
|
import { isEditorActive as isEditorActiveDep, resetEditorChromes as resetEditorChromesDep, resolveUrl as resolveUrlDep, tryParseEnvValue as tryParseEnvValueDep, } from '@sitecore-jss/sitecore-jss/utils';
|
|
5
6
|
import { handleEditorFastRefresh as handleEditorFastRefreshDep, getPublicUrl as getPublicUrlDep, } from './utils';
|
|
6
7
|
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/utils' instead */
|
|
@@ -12,14 +13,18 @@ const { isEditorActiveDep: isEditorActive, resetEditorChromesDep: resetEditorChr
|
|
|
12
13
|
handleEditorFastRefreshDep,
|
|
13
14
|
getPublicUrlDep,
|
|
14
15
|
};
|
|
16
|
+
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/graphql' instead */
|
|
17
|
+
const { GraphQLRequestClientDep: GraphQLRequestClient } = {
|
|
18
|
+
GraphQLRequestClientDep,
|
|
19
|
+
};
|
|
20
|
+
export { GraphQLRequestClient };
|
|
15
21
|
export { handleEditorFastRefresh, getPublicUrl };
|
|
16
22
|
export { isEditorActive, resetEditorChromes, resolveUrl, tryParseEnvValue };
|
|
17
|
-
export { LayoutServicePageState, GraphQLLayoutService, RestLayoutService, getChildPlaceholder, getFieldValue, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-jss/sitecore-jss/layout';
|
|
23
|
+
export { LayoutServicePageState, GraphQLLayoutService, RestLayoutService, getChildPlaceholder, getFieldValue, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, getContentStylesheetLink, } from '@sitecore-jss/sitecore-jss/layout';
|
|
18
24
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
19
25
|
export { trackingApi, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
20
26
|
export { GraphQLDictionaryService, RestDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
21
|
-
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper,
|
|
22
|
-
export { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss';
|
|
27
|
+
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
23
28
|
export { ComponentPropsService } from './services/component-props-service';
|
|
24
29
|
export { DisconnectedSitemapService } from './services/disconnected-sitemap-service';
|
|
25
30
|
export { GraphQLSitemapService, } from './services/graphql-sitemap-service';
|
|
@@ -36,4 +41,5 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
36
41
|
export { FEaaSWrapper };
|
|
37
42
|
export { BYOCWrapper };
|
|
38
43
|
export { ComponentBuilder } from './ComponentBuilder';
|
|
44
|
+
export { Context } from './context';
|
|
39
45
|
export { Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, BYOCComponent, getFEAASLibraryStylesheetLinks, File, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -8,10 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { NextResponse } from 'next/server';
|
|
11
|
-
import { GraphQLPersonalizeService, getPersonalizedRewrite,
|
|
11
|
+
import { GraphQLPersonalizeService, getPersonalizedRewrite, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
12
12
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
13
13
|
import { MiddlewareBase } from './middleware';
|
|
14
|
-
import {
|
|
14
|
+
import { init, personalize } from '@sitecore-cloudsdk/personalize/server';
|
|
15
15
|
/**
|
|
16
16
|
* Middleware / handler to support Sitecore Personalize
|
|
17
17
|
*/
|
|
@@ -23,7 +23,6 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
23
23
|
super(config);
|
|
24
24
|
this.config = config;
|
|
25
25
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
var _a;
|
|
27
26
|
const pathname = req.nextUrl.pathname;
|
|
28
27
|
const language = this.getLanguage(req);
|
|
29
28
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
@@ -48,16 +47,6 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
48
47
|
return response;
|
|
49
48
|
}
|
|
50
49
|
const site = this.getSite(req, response);
|
|
51
|
-
const engageServer = this.initializeEngageServer(site, language);
|
|
52
|
-
// creates the browser ID cookie on the server side
|
|
53
|
-
// and includes the cookie in the response header
|
|
54
|
-
try {
|
|
55
|
-
yield engageServer.handleCookie(req, response, timeout);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
debug.personalize('skipped (browser id generation failed)');
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
50
|
// Get personalization info from Experience Edge
|
|
62
51
|
const personalizeInfo = yield this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
|
|
63
52
|
if (!personalizeInfo) {
|
|
@@ -69,20 +58,20 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
69
58
|
debug.personalize('skipped (no personalization configured)');
|
|
70
59
|
return response;
|
|
71
60
|
}
|
|
61
|
+
yield this.initPersonalizeServer({
|
|
62
|
+
hostname,
|
|
63
|
+
siteName: site.name,
|
|
64
|
+
request: req,
|
|
65
|
+
response,
|
|
66
|
+
});
|
|
72
67
|
const params = this.getExperienceParams(req);
|
|
73
|
-
debug.personalize('executing experience for %s %
|
|
74
|
-
const personalizationData = {
|
|
75
|
-
channel: this.config.cdpConfig.channel || 'WEB',
|
|
76
|
-
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USA',
|
|
77
|
-
friendlyId: personalizeInfo.contentId,
|
|
78
|
-
params,
|
|
79
|
-
language,
|
|
80
|
-
};
|
|
68
|
+
debug.personalize('executing experience for %s %o', personalizeInfo.contentId, params);
|
|
81
69
|
let variantId;
|
|
82
|
-
// Execute targeted experience in
|
|
70
|
+
// Execute targeted experience in Personalize SDK
|
|
83
71
|
// eslint-disable-next-line no-useless-catch
|
|
84
72
|
try {
|
|
85
|
-
|
|
73
|
+
const personalization = yield this.personalize({ personalizeInfo, params, language, timeout }, req);
|
|
74
|
+
variantId = personalization.variantId;
|
|
86
75
|
}
|
|
87
76
|
catch (error) {
|
|
88
77
|
throw error;
|
|
@@ -101,15 +90,22 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
101
90
|
const rewritePath = getPersonalizedRewrite(basePath, { variantId });
|
|
102
91
|
// Note an absolute URL is required: https://nextjs.org/docs/messages/middleware-relative-urls
|
|
103
92
|
const rewriteUrl = req.nextUrl.clone();
|
|
93
|
+
// Preserve cookies from previous response
|
|
94
|
+
const cookies = response.cookies.getAll();
|
|
104
95
|
rewriteUrl.pathname = rewritePath;
|
|
105
|
-
response = NextResponse.rewrite(rewriteUrl);
|
|
96
|
+
response = NextResponse.rewrite(rewriteUrl, response);
|
|
106
97
|
// Disable preflight caching to force revalidation on client-side navigation (personalization may be influenced)
|
|
107
98
|
// See https://github.com/vercel/next.js/issues/32727
|
|
108
99
|
response.headers.set('x-middleware-cache', 'no-cache');
|
|
109
|
-
// Share rewrite path with following executed
|
|
100
|
+
// Share rewrite path with following executed middleware
|
|
110
101
|
response.headers.set('x-sc-rewrite', rewritePath);
|
|
111
102
|
// Share site name with the following executed middlewares
|
|
112
103
|
response.cookies.set(this.SITE_SYMBOL, site.name);
|
|
104
|
+
// Restore cookies from previous response since
|
|
105
|
+
// browserId cookie gets omitted after rewrite
|
|
106
|
+
cookies.forEach((cookie) => {
|
|
107
|
+
response.cookies.set(cookie);
|
|
108
|
+
});
|
|
113
109
|
debug.personalize('personalize middleware end in %dms: %o', Date.now() - startTimestamp, {
|
|
114
110
|
rewritePath,
|
|
115
111
|
headers: this.extractDebugHeaders(response.headers),
|
|
@@ -136,16 +132,29 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
136
132
|
}
|
|
137
133
|
});
|
|
138
134
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
:
|
|
146
|
-
|
|
135
|
+
initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
yield init({
|
|
138
|
+
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
139
|
+
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
140
|
+
siteName,
|
|
141
|
+
cookieDomain: hostname,
|
|
142
|
+
enableServerCookie: true,
|
|
143
|
+
}, request, response);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
personalize({ params, personalizeInfo, language, timeout, }, request) {
|
|
147
|
+
var _a;
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const personalizationData = {
|
|
150
|
+
channel: this.config.cdpConfig.channel || 'WEB',
|
|
151
|
+
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USD',
|
|
152
|
+
friendlyId: personalizeInfo.contentId,
|
|
153
|
+
params,
|
|
154
|
+
language,
|
|
155
|
+
};
|
|
156
|
+
return (yield personalize(personalizationData, request, timeout));
|
|
147
157
|
});
|
|
148
|
-
return engageServer;
|
|
149
158
|
}
|
|
150
159
|
getExperienceParams(req) {
|
|
151
160
|
const utm = {
|
|
@@ -130,13 +130,16 @@ export class RedirectsMiddleware extends MiddlewareBase {
|
|
|
130
130
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
131
131
|
const tragetURL = req.nextUrl.pathname;
|
|
132
132
|
const targetQS = req.nextUrl.search || '';
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
const language = this.getLanguage(req);
|
|
134
|
+
const modifyRedirects = JSON.parse(JSON.stringify(redirects));
|
|
135
|
+
return modifyRedirects.length
|
|
136
|
+
? modifyRedirects.find((redirect) => {
|
|
137
|
+
redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
|
|
135
138
|
redirect.pattern = `/^\/${redirect.pattern
|
|
136
139
|
.replace(/^\/|\/$/g, '')
|
|
137
140
|
.replace(/^\^\/|\/\$$/g, '')
|
|
138
141
|
.replace(/^\^|\$$/g, '')
|
|
139
|
-
.replace(/\$\/gi$/g, '')}
|
|
142
|
+
.replace(/\$\/gi$/g, '')}[\/]?$/gi`;
|
|
140
143
|
return ((regexParser(redirect.pattern).test(tragetURL) ||
|
|
141
144
|
regexParser(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
|
|
142
145
|
regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss/graphql';
|
|
10
|
+
import { GraphQLRequestClient, } from '@sitecore-jss/sitecore-jss/graphql';
|
|
11
11
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
12
12
|
import { getPersonalizedRewrite } from '@sitecore-jss/sitecore-jss/personalize';
|
|
13
13
|
/** @private */
|
|
@@ -191,6 +191,14 @@ export class BaseGraphQLSitemapService {
|
|
|
191
191
|
* @returns {GraphQLClient} implementation
|
|
192
192
|
*/
|
|
193
193
|
getGraphQLClient() {
|
|
194
|
+
if (!this.options.endpoint) {
|
|
195
|
+
if (!this.options.clientFactory) {
|
|
196
|
+
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.');
|
|
197
|
+
}
|
|
198
|
+
return this.options.clientFactory({
|
|
199
|
+
debugger: debug.sitemap,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
194
202
|
return new GraphQLRequestClient(this.options.endpoint, {
|
|
195
203
|
apiKey: this.options.apiKey,
|
|
196
204
|
debugger: debug.sitemap,
|
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/graphql.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/graphql/index';
|
package/graphql.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/graphql/index');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "21.6.0-canary.
|
|
3
|
+
"version": "21.6.0-canary.41",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,11 +11,10 @@
|
|
|
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 --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.6.0-canary.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^21.6.0-canary.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^21.6.0-canary.
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "^21.6.0-canary.41",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^21.6.0-canary.41",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "^21.6.0-canary.41",
|
|
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": "4644ae722d341b1a12639a69c8d02adaa973c3ad",
|
|
87
87
|
"files": [
|
|
88
88
|
"dist",
|
|
89
89
|
"types",
|
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
constructor(props: ContextConfig<SDKModules>);
|
|
97
|
+
init(props?: ContextInitProps): void;
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves the Software Development Kit (SDK) instance, ensuring it is initialized before returning
|
|
100
|
+
*
|
|
101
|
+
* @param {string} name SDK name
|
|
102
|
+
* @returns initialized SDK
|
|
103
|
+
*/
|
|
104
|
+
getSDK: <T extends keyof SDKModules>(name: T) => Promise<SDKModules[T]["sdk"]>;
|
|
105
|
+
/**
|
|
106
|
+
* Initializes the Software Development Kit (SDK)
|
|
107
|
+
*
|
|
108
|
+
* @param {T} name SDK name
|
|
109
|
+
* @returns {void}
|
|
110
|
+
*/
|
|
111
|
+
protected initSDK<T extends keyof SDKModules>(name: T): void;
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Context, ContextConfig, SDK } from './context';
|