@sitecore-jss/sitecore-jss-nextjs 21.10.0-canary.1 → 21.10.0-canary.3
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/dist/cjs/components/Link.js +3 -8
- package/dist/cjs/components/NextImage.js +0 -18
- package/dist/cjs/components/RichText.js +3 -12
- package/dist/cjs/index.js +1 -3
- package/dist/cjs/middleware/personalize-middleware.js +13 -9
- package/dist/esm/components/Link.js +4 -9
- package/dist/esm/components/NextImage.js +0 -18
- package/dist/esm/components/RichText.js +4 -10
- package/dist/esm/index.js +0 -1
- package/dist/esm/middleware/personalize-middleware.js +13 -9
- package/package.json +19 -23
- package/types/components/ComponentPropsContext.d.ts +1 -1
- package/types/components/EditingComponentPlaceholder.d.ts +1 -0
- package/types/components/RichText.d.ts +1 -14
- package/types/index.d.ts +0 -1
- package/types/middleware/personalize-middleware.d.ts +20 -2
- package/context.d.ts +0 -1
- package/context.js +0 -1
- package/dist/cjs/context/context.js +0 -83
- package/dist/cjs/context/index.js +0 -5
- package/dist/esm/context/context.js +0 -79
- package/dist/esm/context/index.js +0 -1
- package/types/context/context.d.ts +0 -116
- package/types/context/index.d.ts +0 -1
|
@@ -39,11 +39,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
40
|
exports.Link = void 0;
|
|
41
41
|
const react_1 = __importStar(require("react"));
|
|
42
|
-
const prop_types_1 = __importDefault(require("prop-types"));
|
|
43
42
|
const link_1 = __importDefault(require("next/link"));
|
|
44
43
|
const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
45
44
|
exports.Link = (0, react_1.forwardRef)((props, ref) => {
|
|
46
|
-
const { field, editable, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
45
|
+
const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
47
46
|
if (!field ||
|
|
48
47
|
(!field.editable && !field.value && !field.href)) {
|
|
49
48
|
return null;
|
|
@@ -57,7 +56,7 @@ exports.Link = (0, react_1.forwardRef)((props, ref) => {
|
|
|
57
56
|
const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
|
|
58
57
|
// determine if a link is a route or not.
|
|
59
58
|
if (internalLinkMatcher.test(href)) {
|
|
60
|
-
return (react_1.default.createElement(link_1.default, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", locale: false, title: value.title, target: value.target, className: value.class }, htmlLinkProps, { ref: ref }),
|
|
59
|
+
return (react_1.default.createElement(link_1.default, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", locale: false, title: value.title, target: value.target, className: value.class }, htmlLinkProps, { ref: ref }, (process.env.TEST ? { 'data-nextjs-link': true } : {})),
|
|
61
60
|
text,
|
|
62
61
|
children));
|
|
63
62
|
}
|
|
@@ -65,10 +64,6 @@ exports.Link = (0, react_1.forwardRef)((props, ref) => {
|
|
|
65
64
|
// prevent passing internalLinkMatcher as it is an invalid DOM element prop
|
|
66
65
|
const reactLinkProps = Object.assign({}, props);
|
|
67
66
|
delete reactLinkProps.internalLinkMatcher;
|
|
68
|
-
return react_1.default.createElement(sitecore_jss_react_1.Link, Object.assign({}, reactLinkProps, { ref: ref }));
|
|
67
|
+
return (react_1.default.createElement(sitecore_jss_react_1.Link, Object.assign({}, reactLinkProps, { ref: ref }, (process.env.TEST ? { 'data-react-link': true } : {}))));
|
|
69
68
|
});
|
|
70
|
-
exports.Link.defaultProps = {
|
|
71
|
-
editable: true,
|
|
72
|
-
};
|
|
73
69
|
exports.Link.displayName = 'NextLink';
|
|
74
|
-
exports.Link.propTypes = Object.assign({ internalLinkMatcher: prop_types_1.default.instanceOf(RegExp) }, sitecore_jss_react_1.LinkPropTypes);
|
|
@@ -16,7 +16,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.NextImage = void 0;
|
|
18
18
|
const media_1 = require("@sitecore-jss/sitecore-jss/media");
|
|
19
|
-
const prop_types_1 = __importDefault(require("prop-types"));
|
|
20
19
|
const react_1 = __importDefault(require("react"));
|
|
21
20
|
const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
22
21
|
const image_1 = __importDefault(require("next/image"));
|
|
@@ -61,21 +60,4 @@ const NextImage = (_a) => {
|
|
|
61
60
|
return null; // we can't handle the truth
|
|
62
61
|
};
|
|
63
62
|
exports.NextImage = NextImage;
|
|
64
|
-
exports.NextImage.propTypes = {
|
|
65
|
-
field: prop_types_1.default.oneOfType([
|
|
66
|
-
prop_types_1.default.shape({
|
|
67
|
-
src: prop_types_1.default.string.isRequired,
|
|
68
|
-
}),
|
|
69
|
-
prop_types_1.default.shape({
|
|
70
|
-
value: prop_types_1.default.object,
|
|
71
|
-
editable: prop_types_1.default.string,
|
|
72
|
-
}),
|
|
73
|
-
]),
|
|
74
|
-
editable: prop_types_1.default.bool,
|
|
75
|
-
mediaUrlPrefix: prop_types_1.default.instanceOf(RegExp),
|
|
76
|
-
imageParams: prop_types_1.default.objectOf(prop_types_1.default.oneOfType([prop_types_1.default.number.isRequired, prop_types_1.default.string.isRequired]).isRequired),
|
|
77
|
-
};
|
|
78
|
-
exports.NextImage.defaultProps = {
|
|
79
|
-
editable: true,
|
|
80
|
-
};
|
|
81
63
|
exports.NextImage.displayName = 'NextImage';
|
|
@@ -33,20 +33,16 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
33
33
|
}
|
|
34
34
|
return t;
|
|
35
35
|
};
|
|
36
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
-
};
|
|
39
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
37
|
exports.RichText = void 0;
|
|
41
38
|
const react_1 = __importStar(require("react"));
|
|
42
|
-
const prop_types_1 = __importDefault(require("prop-types"));
|
|
43
39
|
const router_1 = require("next/router");
|
|
44
40
|
const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
45
41
|
const prefetched = {};
|
|
46
42
|
const RichText = (props) => {
|
|
47
|
-
const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks"]);
|
|
43
|
+
const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true, editable = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks", "editable"]);
|
|
48
44
|
const hasText = props.field && props.field.value;
|
|
49
|
-
const isEditing =
|
|
45
|
+
const isEditing = editable && props.field && props.field.editable;
|
|
50
46
|
const router = (0, router_1.useRouter)();
|
|
51
47
|
const richTextRef = (0, react_1.useRef)(null);
|
|
52
48
|
(0, react_1.useEffect)(() => {
|
|
@@ -78,12 +74,7 @@ const RichText = (props) => {
|
|
|
78
74
|
link.addEventListener('click', routeHandler, false);
|
|
79
75
|
});
|
|
80
76
|
};
|
|
81
|
-
return react_1.default.createElement(sitecore_jss_react_1.RichText, Object.assign({ ref: richTextRef }, rest));
|
|
77
|
+
return react_1.default.createElement(sitecore_jss_react_1.RichText, Object.assign({ ref: richTextRef, editable: editable }, rest));
|
|
82
78
|
};
|
|
83
79
|
exports.RichText = RichText;
|
|
84
|
-
exports.RichText.propTypes = Object.assign({ internalLinksSelector: prop_types_1.default.string }, sitecore_jss_react_1.RichTextPropTypes);
|
|
85
|
-
exports.RichText.defaultProps = {
|
|
86
|
-
tag: 'div',
|
|
87
|
-
editable: true,
|
|
88
|
-
};
|
|
89
80
|
exports.RichText.displayName = 'NextRichText';
|
package/dist/cjs/index.js
CHANGED
|
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
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.ClientError = 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.getComponentLibraryStylesheetLinks = exports.getFEAASLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.
|
|
27
|
+
exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.File = exports.getComponentLibraryStylesheetLinks = exports.getFEAASLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = exports.NextImage = 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; } });
|
|
@@ -118,8 +118,6 @@ const BYOCWrapper = __importStar(require("./components/BYOCWrapper"));
|
|
|
118
118
|
exports.BYOCWrapper = BYOCWrapper;
|
|
119
119
|
var ComponentBuilder_1 = require("./ComponentBuilder");
|
|
120
120
|
Object.defineProperty(exports, "ComponentBuilder", { enumerable: true, get: function () { return ComponentBuilder_1.ComponentBuilder; } });
|
|
121
|
-
var context_1 = require("./context");
|
|
122
|
-
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
|
|
123
121
|
var sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
124
122
|
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return sitecore_jss_react_1.Image; } });
|
|
125
123
|
Object.defineProperty(exports, "Text", { enumerable: true, get: function () { return sitecore_jss_react_1.Text; } });
|
|
@@ -14,7 +14,8 @@ 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 server_2 = require("@sitecore-cloudsdk/
|
|
17
|
+
const server_2 = require("@sitecore-cloudsdk/core/server");
|
|
18
|
+
const server_3 = require("@sitecore-cloudsdk/personalize/server");
|
|
18
19
|
/**
|
|
19
20
|
* Middleware / handler to support Sitecore Personalize
|
|
20
21
|
*/
|
|
@@ -25,7 +26,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
25
26
|
constructor(config) {
|
|
26
27
|
super(config);
|
|
27
28
|
this.config = config;
|
|
28
|
-
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
this.handler = (req, res, options) => __awaiter(this, void 0, void 0, function* () {
|
|
29
30
|
const pathname = req.nextUrl.pathname;
|
|
30
31
|
const language = this.getLanguage(req);
|
|
31
32
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
@@ -73,7 +74,7 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
73
74
|
// Execute targeted experience in Personalize SDK
|
|
74
75
|
// eslint-disable-next-line no-useless-catch
|
|
75
76
|
try {
|
|
76
|
-
const personalization = yield this.personalize({ personalizeInfo, params, language, timeout }, req);
|
|
77
|
+
const personalization = yield this.personalize({ personalizeInfo, params, language, timeout, options }, req);
|
|
77
78
|
variantId = personalization.variantId;
|
|
78
79
|
}
|
|
79
80
|
catch (error) {
|
|
@@ -110,9 +111,9 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
110
111
|
* @returns middleware handler
|
|
111
112
|
*/
|
|
112
113
|
getHandler() {
|
|
113
|
-
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
return (req, res, options) => __awaiter(this, void 0, void 0, function* () {
|
|
114
115
|
try {
|
|
115
|
-
return yield this.handler(req, res);
|
|
116
|
+
return yield this.handler(req, res, options);
|
|
116
117
|
}
|
|
117
118
|
catch (error) {
|
|
118
119
|
console.log('Personalize middleware failed:');
|
|
@@ -123,16 +124,18 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
123
124
|
}
|
|
124
125
|
initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
125
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
126
|
-
yield (0, server_2.
|
|
127
|
+
yield (0, server_2.CloudSDK)(request, response, {
|
|
127
128
|
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
128
129
|
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
129
130
|
siteName,
|
|
130
131
|
cookieDomain: hostname,
|
|
131
132
|
enableServerCookie: true,
|
|
132
|
-
}
|
|
133
|
+
})
|
|
134
|
+
.addPersonalize({ enablePersonalizeCookie: true })
|
|
135
|
+
.initialize();
|
|
133
136
|
});
|
|
134
137
|
}
|
|
135
|
-
personalize({ params, personalizeInfo, language, timeout, }, request) {
|
|
138
|
+
personalize({ params, personalizeInfo, language, timeout, options, }, request) {
|
|
136
139
|
var _a;
|
|
137
140
|
return __awaiter(this, void 0, void 0, function* () {
|
|
138
141
|
const personalizationData = {
|
|
@@ -141,8 +144,9 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
141
144
|
friendlyId: personalizeInfo.contentId,
|
|
142
145
|
params,
|
|
143
146
|
language,
|
|
147
|
+
geo: options === null || options === void 0 ? void 0 : options.geo,
|
|
144
148
|
};
|
|
145
|
-
return (yield (0,
|
|
149
|
+
return (yield (0, server_3.personalize)(request, personalizationData, { timeout }));
|
|
146
150
|
});
|
|
147
151
|
}
|
|
148
152
|
getExperienceParams(req) {
|
|
@@ -10,11 +10,10 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import React, { forwardRef } from 'react';
|
|
13
|
-
import PropTypes from 'prop-types';
|
|
14
13
|
import NextLink from 'next/link';
|
|
15
|
-
import { Link as ReactLink,
|
|
14
|
+
import { Link as ReactLink, } from '@sitecore-jss/sitecore-jss-react';
|
|
16
15
|
export const Link = forwardRef((props, ref) => {
|
|
17
|
-
const { field, editable, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
16
|
+
const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
18
17
|
if (!field ||
|
|
19
18
|
(!field.editable && !field.value && !field.href)) {
|
|
20
19
|
return null;
|
|
@@ -28,7 +27,7 @@ export const Link = forwardRef((props, ref) => {
|
|
|
28
27
|
const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
|
|
29
28
|
// determine if a link is a route or not.
|
|
30
29
|
if (internalLinkMatcher.test(href)) {
|
|
31
|
-
return (React.createElement(NextLink, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", locale: false, title: value.title, target: value.target, className: value.class }, htmlLinkProps, { ref: ref }),
|
|
30
|
+
return (React.createElement(NextLink, Object.assign({ href: { pathname: href, query: querystring, hash: anchor }, key: "link", locale: false, title: value.title, target: value.target, className: value.class }, htmlLinkProps, { ref: ref }, (process.env.TEST ? { 'data-nextjs-link': true } : {})),
|
|
32
31
|
text,
|
|
33
32
|
children));
|
|
34
33
|
}
|
|
@@ -36,10 +35,6 @@ export const Link = forwardRef((props, ref) => {
|
|
|
36
35
|
// prevent passing internalLinkMatcher as it is an invalid DOM element prop
|
|
37
36
|
const reactLinkProps = Object.assign({}, props);
|
|
38
37
|
delete reactLinkProps.internalLinkMatcher;
|
|
39
|
-
return React.createElement(ReactLink, Object.assign({}, reactLinkProps, { ref: ref }));
|
|
38
|
+
return (React.createElement(ReactLink, Object.assign({}, reactLinkProps, { ref: ref }, (process.env.TEST ? { 'data-react-link': true } : {}))));
|
|
40
39
|
});
|
|
41
|
-
Link.defaultProps = {
|
|
42
|
-
editable: true,
|
|
43
|
-
};
|
|
44
40
|
Link.displayName = 'NextLink';
|
|
45
|
-
Link.propTypes = Object.assign({ internalLinkMatcher: PropTypes.instanceOf(RegExp) }, LinkPropTypes);
|
|
@@ -10,7 +10,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
13
|
-
import PropTypes from 'prop-types';
|
|
14
13
|
import React from 'react';
|
|
15
14
|
import { getEEMarkup, } from '@sitecore-jss/sitecore-jss-react';
|
|
16
15
|
import Image from 'next/image';
|
|
@@ -54,21 +53,4 @@ export const NextImage = (_a) => {
|
|
|
54
53
|
}
|
|
55
54
|
return null; // we can't handle the truth
|
|
56
55
|
};
|
|
57
|
-
NextImage.propTypes = {
|
|
58
|
-
field: PropTypes.oneOfType([
|
|
59
|
-
PropTypes.shape({
|
|
60
|
-
src: PropTypes.string.isRequired,
|
|
61
|
-
}),
|
|
62
|
-
PropTypes.shape({
|
|
63
|
-
value: PropTypes.object,
|
|
64
|
-
editable: PropTypes.string,
|
|
65
|
-
}),
|
|
66
|
-
]),
|
|
67
|
-
editable: PropTypes.bool,
|
|
68
|
-
mediaUrlPrefix: PropTypes.instanceOf(RegExp),
|
|
69
|
-
imageParams: PropTypes.objectOf(PropTypes.oneOfType([PropTypes.number.isRequired, PropTypes.string.isRequired]).isRequired),
|
|
70
|
-
};
|
|
71
|
-
NextImage.defaultProps = {
|
|
72
|
-
editable: true,
|
|
73
|
-
};
|
|
74
56
|
NextImage.displayName = 'NextImage';
|
|
@@ -10,14 +10,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import React, { useEffect, useRef } from 'react';
|
|
13
|
-
import PropTypes from 'prop-types';
|
|
14
13
|
import { useRouter } from 'next/router';
|
|
15
|
-
import { RichText as ReactRichText,
|
|
14
|
+
import { RichText as ReactRichText, } from '@sitecore-jss/sitecore-jss-react';
|
|
16
15
|
const prefetched = {};
|
|
17
16
|
export const RichText = (props) => {
|
|
18
|
-
const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks"]);
|
|
17
|
+
const { internalLinksSelector = 'a[href^="/"]', prefetchLinks = true, editable = true } = props, rest = __rest(props, ["internalLinksSelector", "prefetchLinks", "editable"]);
|
|
19
18
|
const hasText = props.field && props.field.value;
|
|
20
|
-
const isEditing =
|
|
19
|
+
const isEditing = editable && props.field && props.field.editable;
|
|
21
20
|
const router = useRouter();
|
|
22
21
|
const richTextRef = useRef(null);
|
|
23
22
|
useEffect(() => {
|
|
@@ -49,11 +48,6 @@ export const RichText = (props) => {
|
|
|
49
48
|
link.addEventListener('click', routeHandler, false);
|
|
50
49
|
});
|
|
51
50
|
};
|
|
52
|
-
return React.createElement(ReactRichText, Object.assign({ ref: richTextRef }, rest));
|
|
53
|
-
};
|
|
54
|
-
RichText.propTypes = Object.assign({ internalLinksSelector: PropTypes.string }, RichTextPropTypes);
|
|
55
|
-
RichText.defaultProps = {
|
|
56
|
-
tag: 'div',
|
|
57
|
-
editable: true,
|
|
51
|
+
return React.createElement(ReactRichText, Object.assign({ ref: richTextRef, editable: editable }, rest));
|
|
58
52
|
};
|
|
59
53
|
RichText.displayName = 'NextRichText';
|
package/dist/esm/index.js
CHANGED
|
@@ -43,5 +43,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
43
43
|
export { FEaaSWrapper };
|
|
44
44
|
export { BYOCWrapper };
|
|
45
45
|
export { ComponentBuilder } from './ComponentBuilder';
|
|
46
|
-
export { Context } from './context';
|
|
47
46
|
export { Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, BYOCComponent, getFEAASLibraryStylesheetLinks, getComponentLibraryStylesheetLinks, File, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -11,7 +11,8 @@ import { NextResponse } from 'next/server';
|
|
|
11
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 { CloudSDK } from '@sitecore-cloudsdk/core/server';
|
|
15
|
+
import { personalize } from '@sitecore-cloudsdk/personalize/server';
|
|
15
16
|
/**
|
|
16
17
|
* Middleware / handler to support Sitecore Personalize
|
|
17
18
|
*/
|
|
@@ -22,7 +23,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
22
23
|
constructor(config) {
|
|
23
24
|
super(config);
|
|
24
25
|
this.config = config;
|
|
25
|
-
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
this.handler = (req, res, options) => __awaiter(this, void 0, void 0, function* () {
|
|
26
27
|
const pathname = req.nextUrl.pathname;
|
|
27
28
|
const language = this.getLanguage(req);
|
|
28
29
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
@@ -70,7 +71,7 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
70
71
|
// Execute targeted experience in Personalize SDK
|
|
71
72
|
// eslint-disable-next-line no-useless-catch
|
|
72
73
|
try {
|
|
73
|
-
const personalization = yield this.personalize({ personalizeInfo, params, language, timeout }, req);
|
|
74
|
+
const personalization = yield this.personalize({ personalizeInfo, params, language, timeout, options }, req);
|
|
74
75
|
variantId = personalization.variantId;
|
|
75
76
|
}
|
|
76
77
|
catch (error) {
|
|
@@ -107,9 +108,9 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
107
108
|
* @returns middleware handler
|
|
108
109
|
*/
|
|
109
110
|
getHandler() {
|
|
110
|
-
return (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
return (req, res, options) => __awaiter(this, void 0, void 0, function* () {
|
|
111
112
|
try {
|
|
112
|
-
return yield this.handler(req, res);
|
|
113
|
+
return yield this.handler(req, res, options);
|
|
113
114
|
}
|
|
114
115
|
catch (error) {
|
|
115
116
|
console.log('Personalize middleware failed:');
|
|
@@ -120,16 +121,18 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
120
121
|
}
|
|
121
122
|
initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
122
123
|
return __awaiter(this, void 0, void 0, function* () {
|
|
123
|
-
yield
|
|
124
|
+
yield CloudSDK(request, response, {
|
|
124
125
|
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
125
126
|
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
126
127
|
siteName,
|
|
127
128
|
cookieDomain: hostname,
|
|
128
129
|
enableServerCookie: true,
|
|
129
|
-
}
|
|
130
|
+
})
|
|
131
|
+
.addPersonalize({ enablePersonalizeCookie: true })
|
|
132
|
+
.initialize();
|
|
130
133
|
});
|
|
131
134
|
}
|
|
132
|
-
personalize({ params, personalizeInfo, language, timeout, }, request) {
|
|
135
|
+
personalize({ params, personalizeInfo, language, timeout, options, }, request) {
|
|
133
136
|
var _a;
|
|
134
137
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
138
|
const personalizationData = {
|
|
@@ -138,8 +141,9 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
138
141
|
friendlyId: personalizeInfo.contentId,
|
|
139
142
|
params,
|
|
140
143
|
language,
|
|
144
|
+
geo: options === null || options === void 0 ? void 0 : options.geo,
|
|
141
145
|
};
|
|
142
|
-
return (yield personalize(
|
|
146
|
+
return (yield personalize(request, personalizationData, { timeout }));
|
|
143
147
|
});
|
|
144
148
|
}
|
|
145
149
|
getExperienceParams(req) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "21.10.0-canary.
|
|
3
|
+
"version": "21.10.0-canary.3",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,61 +29,57 @@
|
|
|
29
29
|
"url": "https://github.com/sitecore/jss/issues"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@sitecore-cloudsdk/personalize": "^0.
|
|
32
|
+
"@sitecore-cloudsdk/personalize": "^0.5.1",
|
|
33
|
+
"@testing-library/dom": "^10.4.0",
|
|
34
|
+
"@testing-library/react": "^16.3.0",
|
|
33
35
|
"@types/chai": "^4.3.4",
|
|
34
36
|
"@types/chai-as-promised": "^7.1.5",
|
|
35
37
|
"@types/chai-string": "^1.4.2",
|
|
36
|
-
"@types/enzyme": "^3.10.12",
|
|
37
38
|
"@types/mocha": "^10.0.1",
|
|
38
39
|
"@types/node": "~18.11.18",
|
|
39
|
-
"@types/
|
|
40
|
-
"@types/react": "^
|
|
41
|
-
"@types/react-dom": "^18.0.10",
|
|
40
|
+
"@types/react": "^19.1.2",
|
|
41
|
+
"@types/react-dom": "^19.1.3",
|
|
42
42
|
"@types/sinon": "^10.0.13",
|
|
43
43
|
"@types/sinon-chai": "^3.2.9",
|
|
44
|
-
"@wojtekmaj/enzyme-adapter-react-17": "^0.8.0",
|
|
45
44
|
"chai": "^4.3.7",
|
|
46
45
|
"chai-as-promised": "^7.1.1",
|
|
47
46
|
"chai-string": "^1.5.0",
|
|
48
47
|
"chalk": "^4.1.2",
|
|
49
|
-
"cheerio": "1.0.0-rc.12",
|
|
50
48
|
"cross-fetch": "^3.1.5",
|
|
51
49
|
"del-cli": "^5.0.0",
|
|
52
|
-
"enzyme": "^3.11.0",
|
|
53
50
|
"eslint": "^8.32.0",
|
|
54
|
-
"eslint-plugin-react": "^7.
|
|
51
|
+
"eslint-plugin-react": "^7.37.5",
|
|
55
52
|
"jsdom": "^21.1.0",
|
|
56
53
|
"mocha": "^10.2.0",
|
|
57
|
-
"next": "^
|
|
54
|
+
"next": "^15.3.1",
|
|
58
55
|
"nock": "^13.3.0",
|
|
59
56
|
"nyc": "^15.1.0",
|
|
60
|
-
"react": "^
|
|
61
|
-
"react-dom": "^
|
|
57
|
+
"react": "^19.1.0",
|
|
58
|
+
"react-dom": "^19.1.0",
|
|
62
59
|
"sinon": "^15.0.1",
|
|
63
60
|
"sinon-chai": "^3.7.0",
|
|
64
61
|
"ts-node": "^10.9.1",
|
|
65
62
|
"typescript": "~4.9.4"
|
|
66
63
|
},
|
|
67
64
|
"peerDependencies": {
|
|
68
|
-
"@sitecore-cloudsdk/events": "^0.
|
|
69
|
-
"@sitecore-cloudsdk/personalize": "^0.
|
|
70
|
-
"next": "^
|
|
71
|
-
"react": "^
|
|
72
|
-
"react-dom": "^
|
|
65
|
+
"@sitecore-cloudsdk/events": "^0.5.1",
|
|
66
|
+
"@sitecore-cloudsdk/personalize": "^0.5.1",
|
|
67
|
+
"next": "^15.3.1",
|
|
68
|
+
"react": "^19.1.0",
|
|
69
|
+
"react-dom": "^19.1.0"
|
|
73
70
|
},
|
|
74
71
|
"dependencies": {
|
|
75
|
-
"@sitecore-jss/sitecore-jss": "^21.10.0-canary.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^21.10.0-canary.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^21.10.0-canary.
|
|
72
|
+
"@sitecore-jss/sitecore-jss": "^21.10.0-canary.3",
|
|
73
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^21.10.0-canary.3",
|
|
74
|
+
"@sitecore-jss/sitecore-jss-react": "^21.10.0-canary.3",
|
|
78
75
|
"@vercel/kv": "^0.2.1",
|
|
79
76
|
"node-html-parser": "^6.1.4",
|
|
80
|
-
"prop-types": "^15.8.1",
|
|
81
77
|
"regex-parser": "^2.2.11",
|
|
82
78
|
"sync-disk-cache": "^2.1.0"
|
|
83
79
|
},
|
|
84
80
|
"description": "",
|
|
85
81
|
"types": "types/index.d.ts",
|
|
86
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "11f94148ea2ed999d14c9b4b0e353a089ebea1a3",
|
|
87
83
|
"files": [
|
|
88
84
|
"dist",
|
|
89
85
|
"types",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="@types/react" />
|
|
2
|
-
import React, { ReactNode } from 'react';
|
|
2
|
+
import React, { ReactNode, JSX } from 'react';
|
|
3
3
|
import { ComponentPropsCollection } from '../sharedTypes/component-props';
|
|
4
4
|
/**
|
|
5
5
|
* Component props context which we are using in order to store data fetched on components level (getStaticProps/getServerSideProps)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { JSX } from 'react';
|
|
2
2
|
import { RichTextProps as ReactRichTextProps } from '@sitecore-jss/sitecore-jss-react';
|
|
3
3
|
export type RichTextProps = ReactRichTextProps & {
|
|
4
4
|
/**
|
|
@@ -15,18 +15,5 @@ export type RichTextProps = ReactRichTextProps & {
|
|
|
15
15
|
};
|
|
16
16
|
export declare const RichText: {
|
|
17
17
|
(props: RichTextProps): JSX.Element;
|
|
18
|
-
propTypes: {
|
|
19
|
-
field: PropTypes.Requireable<PropTypes.InferProps<{
|
|
20
|
-
value: PropTypes.Requireable<string>;
|
|
21
|
-
editable: PropTypes.Requireable<string>;
|
|
22
|
-
}>>;
|
|
23
|
-
tag: PropTypes.Requireable<string>;
|
|
24
|
-
editable: PropTypes.Requireable<boolean>;
|
|
25
|
-
internalLinksSelector: PropTypes.Requireable<string>;
|
|
26
|
-
};
|
|
27
|
-
defaultProps: {
|
|
28
|
-
tag: string;
|
|
29
|
-
editable: boolean;
|
|
30
|
-
};
|
|
31
18
|
displayName: string;
|
|
32
19
|
};
|
package/types/index.d.ts
CHANGED
|
@@ -34,5 +34,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
34
34
|
export { FEaaSWrapper };
|
|
35
35
|
export { BYOCWrapper };
|
|
36
36
|
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
|
37
|
-
export { Context, ContextConfig, SDK } from './context';
|
|
38
37
|
export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getFEAASLibraryStylesheetLinks, getComponentLibraryStylesheetLinks, File, FileField, RichTextField, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -34,6 +34,23 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
|
34
34
|
*/
|
|
35
35
|
cdpConfig: CdpServiceConfig;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* Personalization options
|
|
39
|
+
*/
|
|
40
|
+
export type PersonalizeOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* Geolocation data used for personalization
|
|
43
|
+
*/
|
|
44
|
+
geo?: PersonalizeGeoData;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Represents the geolocation data used for personalization
|
|
48
|
+
*/
|
|
49
|
+
export type PersonalizeGeoData = {
|
|
50
|
+
city?: string;
|
|
51
|
+
country?: string;
|
|
52
|
+
region?: string;
|
|
53
|
+
};
|
|
37
54
|
/**
|
|
38
55
|
* Object model of Experience Context data
|
|
39
56
|
*/
|
|
@@ -61,18 +78,19 @@ export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
61
78
|
* Gets the Next.js middleware handler with error handling
|
|
62
79
|
* @returns middleware handler
|
|
63
80
|
*/
|
|
64
|
-
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
81
|
+
getHandler(): (req: NextRequest, res?: NextResponse, options?: PersonalizeOptions) => Promise<NextResponse>;
|
|
65
82
|
protected initPersonalizeServer({ hostname, siteName, request, response, }: {
|
|
66
83
|
hostname: string;
|
|
67
84
|
siteName: string;
|
|
68
85
|
request: NextRequest;
|
|
69
86
|
response: NextResponse;
|
|
70
87
|
}): Promise<void>;
|
|
71
|
-
protected personalize({ params, personalizeInfo, language, timeout, }: {
|
|
88
|
+
protected personalize({ params, personalizeInfo, language, timeout, options, }: {
|
|
72
89
|
personalizeInfo: PersonalizeInfo;
|
|
73
90
|
params: ExperienceParams;
|
|
74
91
|
language: string;
|
|
75
92
|
timeout?: number;
|
|
93
|
+
options?: PersonalizeOptions;
|
|
76
94
|
}, request: NextRequest): Promise<{
|
|
77
95
|
variantId: string;
|
|
78
96
|
}>;
|
package/context.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './types/context/index';
|
package/context.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require('./dist/cjs/context/index');
|
|
@@ -1,83 +0,0 @@
|
|
|
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;
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Context } from './context';
|
|
@@ -1,116 +0,0 @@
|
|
|
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 {};
|
package/types/context/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Context, ContextConfig, SDK } from './context';
|