@sitecore-jss/sitecore-jss-nextjs 21.9.0 → 21.10.0-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +202 -202
- package/README.md +9 -9
- 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
|
@@ -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.
|
|
3
|
+
"version": "21.10.0-canary.2",
|
|
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.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "21.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "21.
|
|
72
|
+
"@sitecore-jss/sitecore-jss": "^21.10.0-canary.2",
|
|
73
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^21.10.0-canary.2",
|
|
74
|
+
"@sitecore-jss/sitecore-jss-react": "^21.10.0-canary.2",
|
|
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": "bbfadfc2b3b14c3d0561019f70c93a29ffeb6497",
|
|
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';
|