@sitecore-jss/sitecore-jss-nextjs 21.6.0-canary.9 → 21.6.1-canary.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/README.md +1 -4
- 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
package/README.md
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains Next.js components and integration for JSS.
|
|
4
4
|
|
|
5
|
-
<!---
|
|
6
|
-
@TODO: Update to next version docs before release
|
|
7
|
-
-->
|
|
8
5
|
[Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/21/sitecore-headless-development/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
9
6
|
|
|
10
7
|
[Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdk--jss--for-next-js.html)
|
|
11
8
|
|
|
12
|
-
[API reference documentation](/ref-docs/sitecore-jss-nextjs/)
|
|
9
|
+
[API reference documentation](/ref-docs/sitecore-jss-nextjs/)
|
package/context.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/context/index';
|
package/context.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/context/index');
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Context = void 0;
|
|
4
|
+
const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
5
|
+
/**
|
|
6
|
+
* Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
|
|
7
|
+
*/
|
|
8
|
+
class Context {
|
|
9
|
+
constructor(props) {
|
|
10
|
+
this.props = props;
|
|
11
|
+
/**
|
|
12
|
+
* Indicates whether the Context and SDK(s) have been initialized
|
|
13
|
+
*/
|
|
14
|
+
this.isInitialized = false;
|
|
15
|
+
/**
|
|
16
|
+
* Software Development Kits (SDKs) to be initialized
|
|
17
|
+
*/
|
|
18
|
+
this.sdks = {};
|
|
19
|
+
/**
|
|
20
|
+
* Promises for the SDKs
|
|
21
|
+
*/
|
|
22
|
+
this.sdkPromises = {};
|
|
23
|
+
this.sdkErrors = {};
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the Software Development Kit (SDK) instance, ensuring it is initialized before returning
|
|
26
|
+
*
|
|
27
|
+
* @param {string} name SDK name
|
|
28
|
+
* @returns initialized SDK
|
|
29
|
+
*/
|
|
30
|
+
this.getSDK = (name) => {
|
|
31
|
+
if (!this.sdkPromises[name]) {
|
|
32
|
+
return Promise.reject(`Unknown SDK '${String(name)}'`);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return this.sdkPromises[name].then((result) => {
|
|
36
|
+
return ((this.sdkErrors[name] && Promise.reject(this.sdkErrors[name])) || Promise.resolve(result));
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
this.sitecoreEdgeUrl = props.sitecoreEdgeUrl;
|
|
41
|
+
this.sitecoreEdgeContextId = props.sitecoreEdgeContextId;
|
|
42
|
+
this.siteName = props.siteName;
|
|
43
|
+
this.pageState = sitecore_jss_react_1.LayoutServicePageState.Normal;
|
|
44
|
+
}
|
|
45
|
+
init(props = {}) {
|
|
46
|
+
// Context and SDKs are initialized only once
|
|
47
|
+
if (this.isInitialized)
|
|
48
|
+
return;
|
|
49
|
+
this.isInitialized = true;
|
|
50
|
+
if (props.siteName) {
|
|
51
|
+
this.siteName = props.siteName;
|
|
52
|
+
}
|
|
53
|
+
if (props.pageState) {
|
|
54
|
+
this.pageState = props.pageState;
|
|
55
|
+
}
|
|
56
|
+
// iterate over the SDKs and initialize them
|
|
57
|
+
for (const sdkName of Object.keys(this.props.sdks)) {
|
|
58
|
+
this.initSDK(sdkName);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Initializes the Software Development Kit (SDK)
|
|
63
|
+
*
|
|
64
|
+
* @param {T} name SDK name
|
|
65
|
+
* @returns {void}
|
|
66
|
+
*/
|
|
67
|
+
initSDK(name) {
|
|
68
|
+
this.sdkPromises[name] = new Promise((resolve) => {
|
|
69
|
+
this.props.sdks[name]
|
|
70
|
+
.init(this)
|
|
71
|
+
.then(() => {
|
|
72
|
+
this.sdks[name] = this.props.sdks[name].sdk;
|
|
73
|
+
resolve(this.sdks[name]);
|
|
74
|
+
})
|
|
75
|
+
.catch((e) => {
|
|
76
|
+
// if init rejects, we mark SDK as failed - so getSDK call would reject with a reason
|
|
77
|
+
this.sdkErrors[name] = e;
|
|
78
|
+
resolve(undefined);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.Context = Context;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEdgeProxyContentUrl = exports.GraphQLRequestClient = void 0;
|
|
4
|
+
var graphql_1 = require("@sitecore-jss/sitecore-jss/graphql");
|
|
5
|
+
Object.defineProperty(exports, "GraphQLRequestClient", { enumerable: true, get: function () { return graphql_1.GraphQLRequestClient; } });
|
|
6
|
+
Object.defineProperty(exports, "getEdgeProxyContentUrl", { enumerable: true, get: function () { return graphql_1.getEdgeProxyContentUrl; } });
|
package/dist/cjs/index.js
CHANGED
|
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.NextImage = exports.EditingComponentPlaceholder = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.
|
|
27
|
-
exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.getFEAASLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = void 0;
|
|
26
|
+
exports.NextImage = exports.EditingComponentPlaceholder = exports.Placeholder = exports.RichText = exports.Link = exports.useComponentProps = exports.ComponentPropsContext = exports.ComponentPropsReactContext = exports.normalizeSiteRewrite = exports.getSiteRewriteData = exports.getSiteRewrite = exports.GraphQLSiteInfoService = exports.SiteResolver = exports.GraphQLRobotsService = exports.GraphQLErrorPagesService = exports.GraphQLSitemapXmlService = exports.MultisiteGraphQLSitemapService = exports.GraphQLSitemapService = exports.DisconnectedSitemapService = exports.ComponentPropsService = exports.CdpHelper = exports.normalizePersonalizedRewrite = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.getContentStylesheetLink = exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.tryParseEnvValue = exports.resolveUrl = exports.resetEditorChromes = exports.isEditorActive = exports.getPublicUrl = exports.handleEditorFastRefresh = exports.GraphQLRequestClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.AxiosDataFetcher = exports.constants = void 0;
|
|
27
|
+
exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.getFEAASLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.Context = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = void 0;
|
|
28
28
|
var sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
29
29
|
Object.defineProperty(exports, "constants", { enumerable: true, get: function () { return sitecore_jss_1.constants; } });
|
|
30
30
|
Object.defineProperty(exports, "AxiosDataFetcher", { enumerable: true, get: function () { return sitecore_jss_1.AxiosDataFetcher; } });
|
|
@@ -33,6 +33,7 @@ Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function
|
|
|
33
33
|
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return sitecore_jss_1.debug; } });
|
|
34
34
|
// we will remove the root exports for these later
|
|
35
35
|
// we cannot mark exports as deprected directly, so we're using this hack instead
|
|
36
|
+
const graphql_1 = require("./graphql");
|
|
36
37
|
const utils_1 = require("@sitecore-jss/sitecore-jss/utils");
|
|
37
38
|
const utils_2 = require("./utils");
|
|
38
39
|
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/utils' instead */
|
|
@@ -50,6 +51,11 @@ exports.resolveUrl = resolveUrl;
|
|
|
50
51
|
exports.tryParseEnvValue = tryParseEnvValue;
|
|
51
52
|
exports.handleEditorFastRefresh = handleEditorFastRefresh;
|
|
52
53
|
exports.getPublicUrl = getPublicUrl;
|
|
54
|
+
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/graphql' instead */
|
|
55
|
+
const { GraphQLRequestClientDep: GraphQLRequestClient } = {
|
|
56
|
+
GraphQLRequestClientDep: graphql_1.GraphQLRequestClient,
|
|
57
|
+
};
|
|
58
|
+
exports.GraphQLRequestClient = GraphQLRequestClient;
|
|
53
59
|
var layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
54
60
|
Object.defineProperty(exports, "LayoutServicePageState", { enumerable: true, get: function () { return layout_1.LayoutServicePageState; } });
|
|
55
61
|
Object.defineProperty(exports, "GraphQLLayoutService", { enumerable: true, get: function () { return layout_1.GraphQLLayoutService; } });
|
|
@@ -59,6 +65,7 @@ Object.defineProperty(exports, "getFieldValue", { enumerable: true, get: functio
|
|
|
59
65
|
Object.defineProperty(exports, "RenderingType", { enumerable: true, get: function () { return layout_1.RenderingType; } });
|
|
60
66
|
Object.defineProperty(exports, "EDITING_COMPONENT_PLACEHOLDER", { enumerable: true, get: function () { return layout_1.EDITING_COMPONENT_PLACEHOLDER; } });
|
|
61
67
|
Object.defineProperty(exports, "EDITING_COMPONENT_ID", { enumerable: true, get: function () { return layout_1.EDITING_COMPONENT_ID; } });
|
|
68
|
+
Object.defineProperty(exports, "getContentStylesheetLink", { enumerable: true, get: function () { return layout_1.getContentStylesheetLink; } });
|
|
62
69
|
var media_1 = require("@sitecore-jss/sitecore-jss/media");
|
|
63
70
|
Object.defineProperty(exports, "mediaApi", { enumerable: true, get: function () { return media_1.mediaApi; } });
|
|
64
71
|
var tracking_1 = require("@sitecore-jss/sitecore-jss/tracking");
|
|
@@ -72,9 +79,6 @@ Object.defineProperty(exports, "getPersonalizedRewrite", { enumerable: true, get
|
|
|
72
79
|
Object.defineProperty(exports, "getPersonalizedRewriteData", { enumerable: true, get: function () { return personalize_1.getPersonalizedRewriteData; } });
|
|
73
80
|
Object.defineProperty(exports, "normalizePersonalizedRewrite", { enumerable: true, get: function () { return personalize_1.normalizePersonalizedRewrite; } });
|
|
74
81
|
Object.defineProperty(exports, "CdpHelper", { enumerable: true, get: function () { return personalize_1.CdpHelper; } });
|
|
75
|
-
Object.defineProperty(exports, "PosResolver", { enumerable: true, get: function () { return personalize_1.PosResolver; } });
|
|
76
|
-
var sitecore_jss_2 = require("@sitecore-jss/sitecore-jss");
|
|
77
|
-
Object.defineProperty(exports, "GraphQLRequestClient", { enumerable: true, get: function () { return sitecore_jss_2.GraphQLRequestClient; } });
|
|
78
82
|
var component_props_service_1 = require("./services/component-props-service");
|
|
79
83
|
Object.defineProperty(exports, "ComponentPropsService", { enumerable: true, get: function () { return component_props_service_1.ComponentPropsService; } });
|
|
80
84
|
var disconnected_sitemap_service_1 = require("./services/disconnected-sitemap-service");
|
|
@@ -112,6 +116,8 @@ const BYOCWrapper = __importStar(require("./components/BYOCWrapper"));
|
|
|
112
116
|
exports.BYOCWrapper = BYOCWrapper;
|
|
113
117
|
var ComponentBuilder_1 = require("./ComponentBuilder");
|
|
114
118
|
Object.defineProperty(exports, "ComponentBuilder", { enumerable: true, get: function () { return ComponentBuilder_1.ComponentBuilder; } });
|
|
119
|
+
var context_1 = require("./context");
|
|
120
|
+
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
|
|
115
121
|
var sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
116
122
|
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return sitecore_jss_react_1.Image; } });
|
|
117
123
|
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return sitecore_jss_react_1.Text; } });
|
|
@@ -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.
|
|
3
|
+
"version": "21.6.1-canary.1",
|
|
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": "^21.6.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^21.6.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^21.6.
|
|
75
|
+
"@sitecore-jss/sitecore-jss": "^21.6.1-canary.1",
|
|
76
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^21.6.1-canary.1",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-react": "^21.6.1-canary.1",
|
|
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": "40f87d01fb0007aa6004a7dcc72ec8bf135538a1",
|
|
87
87
|
"files": [
|
|
88
88
|
"dist",
|
|
89
89
|
"types",
|
|
@@ -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';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GraphQLRequestClient, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, getEdgeProxyContentUrl, } from '@sitecore-jss/sitecore-jss/graphql';
|
package/types/index.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
export { constants, HttpDataFetcher, HttpResponse, AxiosResponse, AxiosDataFetcher, AxiosDataFetcherConfig, NativeDataFetcher, NativeDataFetcherConfig, HTMLLink, enableDebug, debug, } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
import { GraphQLRequestClient as GraphQLRequestClientDep } from './graphql';
|
|
2
3
|
import { resolveUrl as resolveUrlDep } from '@sitecore-jss/sitecore-jss/utils';
|
|
3
4
|
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/utils' instead */
|
|
4
5
|
declare const isEditorActive: () => boolean, resetEditorChromes: () => void, resolveUrl: typeof resolveUrlDep, tryParseEnvValue: <T>(envValue: string | undefined, defaultValue: T) => T, handleEditorFastRefresh: (forceReload?: boolean) => void, getPublicUrl: () => string;
|
|
6
|
+
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/graphql' instead */
|
|
7
|
+
declare const GraphQLRequestClient: typeof GraphQLRequestClientDep;
|
|
8
|
+
export { GraphQLRequestClient };
|
|
5
9
|
export { handleEditorFastRefresh, getPublicUrl };
|
|
6
10
|
export { isEditorActive, resetEditorChromes, resolveUrl, tryParseEnvValue };
|
|
7
|
-
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';
|
|
8
12
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
9
13
|
export { trackingApi, TrackingRequestOptions, CampaignInstance, GoalInstance, OutcomeInstance, EventInstance, PageViewInstance, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
10
14
|
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQLDictionaryServiceConfig, RestDictionaryService, RestDictionaryServiceConfig, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
11
|
-
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper,
|
|
12
|
-
export { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss';
|
|
15
|
+
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
13
16
|
export { ComponentPropsCollection, ComponentPropsError, GetStaticComponentProps, GetServerSideComponentProps, } from './sharedTypes/component-props';
|
|
14
17
|
export { ModuleFactory, Module } from './sharedTypes/module-factory';
|
|
15
18
|
export { ComponentPropsService } from './services/component-props-service';
|
|
@@ -29,4 +32,5 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
29
32
|
export { FEaaSWrapper };
|
|
30
33
|
export { BYOCWrapper };
|
|
31
34
|
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
|
35
|
+
export { Context, ContextConfig, SDK } from './context';
|
|
32
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';
|
|
@@ -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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLClient, PageInfo } from '@sitecore-jss/sitecore-jss/graphql';
|
|
1
|
+
import { GraphQLClient, GraphQLRequestClientFactory, PageInfo } from '@sitecore-jss/sitecore-jss/graphql';
|
|
2
2
|
/** @private */
|
|
3
3
|
export declare const languageError = "The list of languages cannot be empty";
|
|
4
4
|
export declare const siteError = "The service needs a site name";
|
|
@@ -68,17 +68,24 @@ export type RouteListQueryResult = {
|
|
|
68
68
|
export interface BaseGraphQLSitemapServiceConfig extends Omit<SiteRouteQueryVariables, 'language' | 'siteName'> {
|
|
69
69
|
/**
|
|
70
70
|
* Your Graphql endpoint
|
|
71
|
+
* @deprecated use @param clientFactory property instead
|
|
71
72
|
*/
|
|
72
|
-
endpoint
|
|
73
|
+
endpoint?: string;
|
|
73
74
|
/**
|
|
74
75
|
* The API key to use for authentication.
|
|
76
|
+
* @deprecated use @param clientFactory property instead
|
|
75
77
|
*/
|
|
76
|
-
apiKey
|
|
78
|
+
apiKey?: string;
|
|
77
79
|
/**
|
|
78
80
|
* A flag for whether to include personalized routes in service output - only works on XM Cloud
|
|
79
81
|
* turned off by default
|
|
80
82
|
*/
|
|
81
83
|
includePersonalizedRoutes?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* A GraphQL Request Client Factory is a function that accepts configuration and returns an instance of a GraphQLRequestClient.
|
|
86
|
+
* This factory function is used to create and configure GraphQL clients for making GraphQL API requests.
|
|
87
|
+
*/
|
|
88
|
+
clientFactory?: GraphQLRequestClientFactory;
|
|
82
89
|
}
|
|
83
90
|
/**
|
|
84
91
|
* Object model of a site page item.
|
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
|
/**
|