@sitecore-jss/sitecore-jss-nextjs 21.6.0-canary.8 → 21.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +202 -202
- package/README.md +9 -12
- 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/graphql/index.js +6 -0
- package/dist/cjs/index.js +11 -5
- package/dist/cjs/middleware/personalize-middleware.js +33 -32
- 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 +79 -0
- package/dist/esm/context/index.js +1 -0
- package/dist/esm/graphql/index.js +1 -0
- package/dist/esm/index.js +9 -3
- package/dist/esm/middleware/personalize-middleware.js +34 -33
- 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/context/context.d.ts +116 -0
- package/types/context/index.d.ts +1 -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/utils/utils.d.ts +1 -0
|
@@ -14,7 +14,7 @@ const server_1 = require("next/server");
|
|
|
14
14
|
const personalize_1 = require("@sitecore-jss/sitecore-jss/personalize");
|
|
15
15
|
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
16
16
|
const middleware_1 = require("./middleware");
|
|
17
|
-
const
|
|
17
|
+
const server_2 = require("@sitecore-cloudsdk/personalize/server");
|
|
18
18
|
/**
|
|
19
19
|
* Middleware / handler to support Sitecore Personalize
|
|
20
20
|
*/
|
|
@@ -26,7 +26,6 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
26
26
|
super(config);
|
|
27
27
|
this.config = config;
|
|
28
28
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
var _a;
|
|
30
29
|
const pathname = req.nextUrl.pathname;
|
|
31
30
|
const language = this.getLanguage(req);
|
|
32
31
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
@@ -62,30 +61,20 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
62
61
|
sitecore_jss_1.debug.personalize('skipped (no personalization configured)');
|
|
63
62
|
return response;
|
|
64
63
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
sitecore_jss_1.debug.personalize('skipped (browser id generation failed)');
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
64
|
+
yield this.initPersonalizeServer({
|
|
65
|
+
hostname,
|
|
66
|
+
siteName: site.name,
|
|
67
|
+
request: req,
|
|
68
|
+
response,
|
|
69
|
+
});
|
|
75
70
|
const params = this.getExperienceParams(req);
|
|
76
|
-
sitecore_jss_1.debug.personalize('executing experience for %s %
|
|
77
|
-
const personalizationData = {
|
|
78
|
-
channel: this.config.cdpConfig.channel || 'WEB',
|
|
79
|
-
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USA',
|
|
80
|
-
friendlyId: personalizeInfo.contentId,
|
|
81
|
-
params,
|
|
82
|
-
language,
|
|
83
|
-
};
|
|
71
|
+
sitecore_jss_1.debug.personalize('executing experience for %s %o', personalizeInfo.contentId, params);
|
|
84
72
|
let variantId;
|
|
85
|
-
// Execute targeted experience in
|
|
73
|
+
// Execute targeted experience in Personalize SDK
|
|
86
74
|
// eslint-disable-next-line no-useless-catch
|
|
87
75
|
try {
|
|
88
|
-
|
|
76
|
+
const personalization = yield this.personalize({ personalizeInfo, params, language, timeout }, req);
|
|
77
|
+
variantId = personalization.variantId;
|
|
89
78
|
}
|
|
90
79
|
catch (error) {
|
|
91
80
|
throw error;
|
|
@@ -146,17 +135,29 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
146
135
|
}
|
|
147
136
|
});
|
|
148
137
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
:
|
|
156
|
-
|
|
157
|
-
|
|
138
|
+
initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
139
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
140
|
+
yield (0, server_2.init)({
|
|
141
|
+
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
142
|
+
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
143
|
+
siteName,
|
|
144
|
+
cookieDomain: hostname,
|
|
145
|
+
enableServerCookie: true,
|
|
146
|
+
}, request, response);
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
personalize({ params, personalizeInfo, language, timeout, }, request) {
|
|
150
|
+
var _a;
|
|
151
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
+
const personalizationData = {
|
|
153
|
+
channel: this.config.cdpConfig.channel || 'WEB',
|
|
154
|
+
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USD',
|
|
155
|
+
friendlyId: personalizeInfo.contentId,
|
|
156
|
+
params,
|
|
157
|
+
language,
|
|
158
|
+
};
|
|
159
|
+
return (yield (0, server_2.personalize)(personalizationData, request, timeout));
|
|
158
160
|
});
|
|
159
|
-
return engageServer;
|
|
160
161
|
}
|
|
161
162
|
getExperienceParams(req) {
|
|
162
163
|
const utm = {
|
|
@@ -136,13 +136,16 @@ class RedirectsMiddleware extends middleware_1.MiddlewareBase {
|
|
|
136
136
|
const redirects = yield this.redirectsService.fetchRedirects(siteName);
|
|
137
137
|
const tragetURL = req.nextUrl.pathname;
|
|
138
138
|
const targetQS = req.nextUrl.search || '';
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const language = this.getLanguage(req);
|
|
140
|
+
const modifyRedirects = JSON.parse(JSON.stringify(redirects));
|
|
141
|
+
return modifyRedirects.length
|
|
142
|
+
? modifyRedirects.find((redirect) => {
|
|
143
|
+
redirect.pattern = redirect.pattern.replace(RegExp(`^[^]?/${language}/`, 'gi'), '');
|
|
141
144
|
redirect.pattern = `/^\/${redirect.pattern
|
|
142
145
|
.replace(/^\/|\/$/g, '')
|
|
143
146
|
.replace(/^\^\/|\/\$$/g, '')
|
|
144
147
|
.replace(/^\^|\$$/g, '')
|
|
145
|
-
.replace(/\$\/gi$/g, '')}
|
|
148
|
+
.replace(/\$\/gi$/g, '')}[\/]?$/gi`;
|
|
146
149
|
return (((0, regex_parser_1.default)(redirect.pattern).test(tragetURL) ||
|
|
147
150
|
(0, regex_parser_1.default)(redirect.pattern).test(`${tragetURL}${targetQS}`) ||
|
|
148
151
|
(0, regex_parser_1.default)(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) ||
|
|
@@ -195,6 +195,14 @@ class BaseGraphQLSitemapService {
|
|
|
195
195
|
* @returns {GraphQLClient} implementation
|
|
196
196
|
*/
|
|
197
197
|
getGraphQLClient() {
|
|
198
|
+
if (!this.options.endpoint) {
|
|
199
|
+
if (!this.options.clientFactory) {
|
|
200
|
+
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.');
|
|
201
|
+
}
|
|
202
|
+
return this.options.clientFactory({
|
|
203
|
+
debugger: sitecore_jss_1.debug.sitemap,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
198
206
|
return new graphql_1.GraphQLRequestClient(this.options.endpoint, {
|
|
199
207
|
apiKey: this.options.apiKey,
|
|
200
208
|
debugger: sitecore_jss_1.debug.sitemap,
|
package/dist/cjs/utils/utils.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getJssEditingSecret = exports.handleEditorFastRefresh = exports.getPublicUrl = void 0;
|
|
7
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
8
4
|
const utils_1 = require("@sitecore-jss/sitecore-jss/utils");
|
|
9
5
|
/**
|
|
10
6
|
* Get the publicUrl.
|
|
@@ -13,27 +9,19 @@ const utils_1 = require("@sitecore-jss/sitecore-jss/utils");
|
|
|
13
9
|
* VERCEL_URL is provided by Vercel in case if we are in Preview deployment (deployment based on the custom branch),
|
|
14
10
|
* preview deployment has unique url, we don't know exact url.
|
|
15
11
|
* Similarly, DEPLOY_URL is provided by Netlify and would give us the deploy URL
|
|
12
|
+
* In production non-editing environments it is desirable to use relative urls, so in that case set PUBLIC_URL = ''
|
|
16
13
|
*/
|
|
17
14
|
const getPublicUrl = () => {
|
|
18
|
-
if (process.env.NETLIFY && process.env.DEPLOY_URL)
|
|
19
|
-
return process.env.DEPLOY_URL;
|
|
20
|
-
if (process.env.VERCEL_URL)
|
|
21
|
-
return `https://${process.env.VERCEL_URL}`;
|
|
22
15
|
let url = process.env.PUBLIC_URL;
|
|
23
16
|
if (url === undefined) {
|
|
24
|
-
|
|
17
|
+
if (process.env.NETLIFY && process.env.DEPLOY_URL)
|
|
18
|
+
return process.env.DEPLOY_URL;
|
|
19
|
+
if (process.env.VERCEL_URL)
|
|
20
|
+
return `https://${process.env.VERCEL_URL}`;
|
|
25
21
|
url = 'http://localhost:3000';
|
|
26
22
|
}
|
|
27
|
-
else {
|
|
28
|
-
try {
|
|
29
|
-
new URL(url);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
throw new Error(`The PUBLIC_URL environment variable '${url}' is not a valid URL.`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
23
|
// Ensure no trailing slash
|
|
36
|
-
return url.
|
|
24
|
+
return url.replace(/\/$/, '');
|
|
37
25
|
};
|
|
38
26
|
exports.getPublicUrl = getPublicUrl;
|
|
39
27
|
/**
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { LayoutServicePageState } from '@sitecore-jss/sitecore-jss-react';
|
|
2
|
+
/**
|
|
3
|
+
* Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
|
|
4
|
+
*/
|
|
5
|
+
export class Context {
|
|
6
|
+
constructor(props) {
|
|
7
|
+
this.props = props;
|
|
8
|
+
/**
|
|
9
|
+
* Indicates whether the Context and SDK(s) have been initialized
|
|
10
|
+
*/
|
|
11
|
+
this.isInitialized = false;
|
|
12
|
+
/**
|
|
13
|
+
* Software Development Kits (SDKs) to be initialized
|
|
14
|
+
*/
|
|
15
|
+
this.sdks = {};
|
|
16
|
+
/**
|
|
17
|
+
* Promises for the SDKs
|
|
18
|
+
*/
|
|
19
|
+
this.sdkPromises = {};
|
|
20
|
+
this.sdkErrors = {};
|
|
21
|
+
/**
|
|
22
|
+
* Retrieves the Software Development Kit (SDK) instance, ensuring it is initialized before returning
|
|
23
|
+
*
|
|
24
|
+
* @param {string} name SDK name
|
|
25
|
+
* @returns initialized SDK
|
|
26
|
+
*/
|
|
27
|
+
this.getSDK = (name) => {
|
|
28
|
+
if (!this.sdkPromises[name]) {
|
|
29
|
+
return Promise.reject(`Unknown SDK '${String(name)}'`);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return this.sdkPromises[name].then((result) => {
|
|
33
|
+
return ((this.sdkErrors[name] && Promise.reject(this.sdkErrors[name])) || Promise.resolve(result));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
this.sitecoreEdgeUrl = props.sitecoreEdgeUrl;
|
|
38
|
+
this.sitecoreEdgeContextId = props.sitecoreEdgeContextId;
|
|
39
|
+
this.siteName = props.siteName;
|
|
40
|
+
this.pageState = LayoutServicePageState.Normal;
|
|
41
|
+
}
|
|
42
|
+
init(props = {}) {
|
|
43
|
+
// Context and SDKs are initialized only once
|
|
44
|
+
if (this.isInitialized)
|
|
45
|
+
return;
|
|
46
|
+
this.isInitialized = true;
|
|
47
|
+
if (props.siteName) {
|
|
48
|
+
this.siteName = props.siteName;
|
|
49
|
+
}
|
|
50
|
+
if (props.pageState) {
|
|
51
|
+
this.pageState = props.pageState;
|
|
52
|
+
}
|
|
53
|
+
// iterate over the SDKs and initialize them
|
|
54
|
+
for (const sdkName of Object.keys(this.props.sdks)) {
|
|
55
|
+
this.initSDK(sdkName);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Initializes the Software Development Kit (SDK)
|
|
60
|
+
*
|
|
61
|
+
* @param {T} name SDK name
|
|
62
|
+
* @returns {void}
|
|
63
|
+
*/
|
|
64
|
+
initSDK(name) {
|
|
65
|
+
this.sdkPromises[name] = new Promise((resolve) => {
|
|
66
|
+
this.props.sdks[name]
|
|
67
|
+
.init(this)
|
|
68
|
+
.then(() => {
|
|
69
|
+
this.sdks[name] = this.props.sdks[name].sdk;
|
|
70
|
+
resolve(this.sdks[name]);
|
|
71
|
+
})
|
|
72
|
+
.catch((e) => {
|
|
73
|
+
// if init rejects, we mark SDK as failed - so getSDK call would reject with a reason
|
|
74
|
+
this.sdkErrors[name] = e;
|
|
75
|
+
resolve(undefined);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Context } from './context';
|
|
@@ -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;
|
|
@@ -59,30 +58,20 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
59
58
|
debug.personalize('skipped (no personalization configured)');
|
|
60
59
|
return response;
|
|
61
60
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
debug.personalize('skipped (browser id generation failed)');
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
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;
|
|
@@ -143,17 +132,29 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
143
132
|
}
|
|
144
133
|
});
|
|
145
134
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
:
|
|
153
|
-
|
|
154
|
-
|
|
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));
|
|
155
157
|
});
|
|
156
|
-
return engageServer;
|
|
157
158
|
}
|
|
158
159
|
getExperienceParams(req) {
|
|
159
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
|
|
3
|
+
"version": "21.6.0",
|
|
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.3",
|
|
69
|
+
"@sitecore-cloudsdk/personalize": "^0.1.3",
|
|
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": "
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "21.6.0",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "21.6.0",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "21.6.0",
|
|
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": "208a2a7c5fc3a91ff31cc357443b30e3f8b0a543",
|
|
87
87
|
"files": [
|
|
88
88
|
"dist",
|
|
89
89
|
"types",
|