@sitecore-jss/sitecore-jss-nextjs 22.2.0-canary.80 → 22.2.0-canary.83
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 +2 -8
- package/dist/cjs/editing/constants.js +6 -1
- package/dist/cjs/editing/editing-config-middleware.js +3 -3
- package/dist/cjs/editing/editing-data-middleware.js +3 -3
- package/dist/cjs/editing/editing-data-service.js +2 -2
- package/dist/cjs/editing/editing-render-middleware.js +4 -4
- package/dist/cjs/editing/feaas-render-middleware.js +3 -3
- package/dist/cjs/index.js +2 -4
- package/dist/cjs/middleware/personalize-middleware.js +7 -4
- package/dist/esm/components/Link.js +2 -8
- package/dist/esm/editing/constants.js +5 -0
- package/dist/esm/editing/editing-config-middleware.js +1 -1
- package/dist/esm/editing/editing-data-middleware.js +1 -1
- package/dist/esm/editing/editing-data-service.js +1 -1
- package/dist/esm/editing/editing-render-middleware.js +1 -1
- package/dist/esm/editing/feaas-render-middleware.js +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/middleware/personalize-middleware.js +6 -3
- package/package.json +9 -8
- package/types/editing/constants.d.ts +5 -0
- package/types/editing/editing-render-middleware.d.ts +17 -2
- package/types/index.d.ts +0 -1
- 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
|
@@ -42,10 +42,6 @@ const react_1 = __importStar(require("react"));
|
|
|
42
42
|
const prop_types_1 = __importDefault(require("prop-types"));
|
|
43
43
|
const link_1 = __importDefault(require("next/link"));
|
|
44
44
|
const sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
45
|
-
/**
|
|
46
|
-
* Matches relative URLs that end with a file extension.
|
|
47
|
-
*/
|
|
48
|
-
const FILE_EXTENSION_MATCHER = /^\/.*\.\w+$/;
|
|
49
45
|
exports.Link = (0, react_1.forwardRef)((props, ref) => {
|
|
50
46
|
const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
51
47
|
if (!field ||
|
|
@@ -63,10 +59,8 @@ exports.Link = (0, react_1.forwardRef)((props, ref) => {
|
|
|
63
59
|
const isEditing = editable && (field.editable || field.metadata);
|
|
64
60
|
if (href && !isEditing) {
|
|
65
61
|
const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
// determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
|
|
69
|
-
if (isMatching && !isFileUrl) {
|
|
62
|
+
// determine if a link is a route or not.
|
|
63
|
+
if (internalLinkMatcher.test(href)) {
|
|
70
64
|
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 }),
|
|
71
65
|
text,
|
|
72
66
|
children));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EDITING_PASS_THROUGH_HEADERS = exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = exports.QUERY_PARAM_VERCEL_PROTECTION_BYPASS = void 0;
|
|
3
|
+
exports.EDITING_ALLOWED_ORIGINS = exports.EDITING_PASS_THROUGH_HEADERS = exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = exports.QUERY_PARAM_VERCEL_PROTECTION_BYPASS = exports.QUERY_PARAM_EDITING_SECRET = void 0;
|
|
4
|
+
exports.QUERY_PARAM_EDITING_SECRET = 'secret';
|
|
4
5
|
exports.QUERY_PARAM_VERCEL_PROTECTION_BYPASS = 'x-vercel-protection-bypass';
|
|
5
6
|
exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
|
|
6
7
|
/**
|
|
@@ -8,3 +9,7 @@ exports.QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
|
|
|
8
9
|
* Note these are in lowercase format to match expected `IncomingHttpHeaders`.
|
|
9
10
|
*/
|
|
10
11
|
exports.EDITING_PASS_THROUGH_HEADERS = ['authorization', 'cookie'];
|
|
12
|
+
/**
|
|
13
|
+
* Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
|
|
14
|
+
*/
|
|
15
|
+
exports.EDITING_ALLOWED_ORIGINS = ['https://pages.sitecorecloud.io'];
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.EditingConfigMiddleware = void 0;
|
|
13
|
-
const
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
14
|
const utils_1 = require("../utils/utils");
|
|
15
15
|
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
16
16
|
const layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
@@ -26,8 +26,8 @@ class EditingConfigMiddleware {
|
|
|
26
26
|
constructor(config) {
|
|
27
27
|
this.config = config;
|
|
28
28
|
this.handler = (_req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const secret = _req.query[
|
|
30
|
-
if (!(0, utils_2.enforceCors)(_req, res,
|
|
29
|
+
const secret = _req.query[constants_1.QUERY_PARAM_EDITING_SECRET];
|
|
30
|
+
if (!(0, utils_2.enforceCors)(_req, res, constants_1.EDITING_ALLOWED_ORIGINS)) {
|
|
31
31
|
sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
|
|
32
32
|
return res.status(401).json({ message: 'Invalid origin' });
|
|
33
33
|
}
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.EditingDataMiddleware = void 0;
|
|
13
13
|
const editing_data_cache_1 = require("./editing-data-cache");
|
|
14
14
|
const editing_data_1 = require("./editing-data");
|
|
15
|
-
const
|
|
15
|
+
const constants_1 = require("./constants");
|
|
16
16
|
const utils_1 = require("../utils/utils");
|
|
17
17
|
const utils_2 = require("@sitecore-jss/sitecore-jss/utils");
|
|
18
18
|
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
@@ -28,9 +28,9 @@ class EditingDataMiddleware {
|
|
|
28
28
|
var _a, _b;
|
|
29
29
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
30
30
|
const { method, query, body } = req;
|
|
31
|
-
const secret = query[
|
|
31
|
+
const secret = query[constants_1.QUERY_PARAM_EDITING_SECRET];
|
|
32
32
|
const key = query[this.queryParamKey];
|
|
33
|
-
if (!(0, utils_2.enforceCors)(req, res,
|
|
33
|
+
if (!(0, utils_2.enforceCors)(req, res, constants_1.EDITING_ALLOWED_ORIGINS)) {
|
|
34
34
|
sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
|
|
35
35
|
return res.status(401).json({ message: 'Invalid origin' });
|
|
36
36
|
}
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.editingDataService = exports.ServerlessEditingDataService = exports.BasicEditingDataService = exports.generateKey = void 0;
|
|
13
|
-
const
|
|
13
|
+
const constants_1 = require("./constants");
|
|
14
14
|
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
15
15
|
const editing_data_cache_1 = require("./editing-data-cache");
|
|
16
16
|
const utils_1 = require("../utils/utils");
|
|
@@ -137,7 +137,7 @@ class ServerlessEditingDataService {
|
|
|
137
137
|
// http://localhost:3000/api/editing/data/52961eea-bafd-5287-a532-a72e36bd8a36-qkb4e3fv5x?secret=1234secret
|
|
138
138
|
const apiRoute = (_a = this.apiRoute) === null || _a === void 0 ? void 0 : _a.replace('[key]', key);
|
|
139
139
|
const url = new URL(apiRoute, serverUrl);
|
|
140
|
-
url.searchParams.append(
|
|
140
|
+
url.searchParams.append(constants_1.QUERY_PARAM_EDITING_SECRET, (0, utils_1.getJssEditingSecret)());
|
|
141
141
|
if (params) {
|
|
142
142
|
for (const key in params) {
|
|
143
143
|
if ({}.hasOwnProperty.call(params, key)) {
|
|
@@ -13,8 +13,8 @@ exports.EditingRenderMiddleware = exports.MetadataHandler = exports.isEditingMet
|
|
|
13
13
|
const constants_1 = require("next/constants");
|
|
14
14
|
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
15
15
|
const layout_1 = require("@sitecore-jss/sitecore-jss/layout");
|
|
16
|
-
const editing_1 = require("@sitecore-jss/sitecore-jss/editing");
|
|
17
16
|
const editing_data_service_1 = require("./editing-data-service");
|
|
17
|
+
const constants_2 = require("./constants");
|
|
18
18
|
const utils_1 = require("../utils/utils");
|
|
19
19
|
const render_middleware_1 = require("./render-middleware");
|
|
20
20
|
const utils_2 = require("@sitecore-jss/sitecore-jss/utils");
|
|
@@ -265,7 +265,7 @@ class MetadataHandler {
|
|
|
265
265
|
* @returns Content-Security-Policy header value
|
|
266
266
|
*/
|
|
267
267
|
getSCPHeader() {
|
|
268
|
-
return `frame-ancestors 'self' ${[(0, utils_2.getAllowedOriginsFromEnv)(), ...
|
|
268
|
+
return `frame-ancestors 'self' ${[(0, utils_2.getAllowedOriginsFromEnv)(), ...constants_2.EDITING_ALLOWED_ORIGINS].join(' ')}`;
|
|
269
269
|
}
|
|
270
270
|
}
|
|
271
271
|
exports.MetadataHandler = MetadataHandler;
|
|
@@ -289,14 +289,14 @@ class EditingRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
289
289
|
headers,
|
|
290
290
|
body,
|
|
291
291
|
});
|
|
292
|
-
if (!(0, utils_2.enforceCors)(req, res,
|
|
292
|
+
if (!(0, utils_2.enforceCors)(req, res, constants_2.EDITING_ALLOWED_ORIGINS)) {
|
|
293
293
|
sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
|
|
294
294
|
return res.status(401).json({
|
|
295
295
|
html: `<html><body>Requests from origin ${(_a = req.headers) === null || _a === void 0 ? void 0 : _a.origin} not allowed</body></html>`,
|
|
296
296
|
});
|
|
297
297
|
}
|
|
298
298
|
// Validate secret
|
|
299
|
-
const secret = (_b = query[
|
|
299
|
+
const secret = (_b = query[constants_2.QUERY_PARAM_EDITING_SECRET]) !== null && _b !== void 0 ? _b : body === null || body === void 0 ? void 0 : body.jssEditingSecret;
|
|
300
300
|
if (secret !== (0, utils_1.getJssEditingSecret)()) {
|
|
301
301
|
sitecore_jss_1.debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, (0, utils_1.getJssEditingSecret)());
|
|
302
302
|
return res.status(401).json({
|
|
@@ -11,7 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.FEAASRenderMiddleware = void 0;
|
|
13
13
|
const sitecore_jss_1 = require("@sitecore-jss/sitecore-jss");
|
|
14
|
-
const
|
|
14
|
+
const constants_1 = require("./constants");
|
|
15
15
|
const utils_1 = require("../utils/utils");
|
|
16
16
|
const render_middleware_1 = require("./render-middleware");
|
|
17
17
|
const utils_2 = require("@sitecore-jss/sitecore-jss/utils");
|
|
@@ -37,7 +37,7 @@ class FEAASRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
37
37
|
query,
|
|
38
38
|
headers,
|
|
39
39
|
});
|
|
40
|
-
if (!(0, utils_2.enforceCors)(req, res,
|
|
40
|
+
if (!(0, utils_2.enforceCors)(req, res, constants_1.EDITING_ALLOWED_ORIGINS)) {
|
|
41
41
|
sitecore_jss_1.debug.editing('invalid origin host - set allowed origins in JSS_ALLOWED_ORIGINS environment variable');
|
|
42
42
|
return res
|
|
43
43
|
.status(401)
|
|
@@ -49,7 +49,7 @@ class FEAASRenderMiddleware extends render_middleware_1.RenderMiddlewareBase {
|
|
|
49
49
|
return res.status(405).send(`<html><body>Invalid request method '${method}'</body></html>`);
|
|
50
50
|
}
|
|
51
51
|
// Validate secret
|
|
52
|
-
const secret = query[
|
|
52
|
+
const secret = query[constants_1.QUERY_PARAM_EDITING_SECRET];
|
|
53
53
|
if (secret !== (0, utils_1.getJssEditingSecret)()) {
|
|
54
54
|
sitecore_jss_1.debug.editing('invalid editing secret - sent "%s" expected "%s"', secret, (0, utils_1.getJssEditingSecret)());
|
|
55
55
|
return res.status(401).send('<html><body>Missing or invalid secret</body></html>');
|
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.
|
|
27
|
-
exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.DefaultEmptyFieldEditingComponentText = exports.DefaultEmptyFieldEditingComponentImage = exports.File = exports.getComponentLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps =
|
|
26
|
+
exports.FEaaSComponent = exports.EditFrame = exports.DateField = exports.Text = exports.Image = exports.ComponentBuilder = exports.BYOCWrapper = exports.FEaaSWrapper = exports.NextImage = 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.getGroomedVariantIds = exports.getPersonalizedRewriteData = exports.getPersonalizedRewrite = exports.personalizeLayout = exports.RestDictionaryService = exports.GraphQLDictionaryService = exports.trackingApi = exports.mediaApi = exports.EditMode = exports.getContentStylesheetLink = exports.getFieldValue = exports.getChildPlaceholder = exports.RestLayoutService = exports.GraphQLLayoutService = exports.LayoutServicePageState = exports.MemoryCacheClient = exports.debug = exports.enableDebug = exports.NativeDataFetcher = exports.AxiosDataFetcher = exports.constants = void 0;
|
|
27
|
+
exports.EditingScripts = exports.withEmptyFieldEditingComponent = exports.withFieldMetadata = exports.withDatasourceCheck = exports.withPlaceholder = exports.withEditorChromes = exports.useSitecoreContext = exports.withSitecoreContext = exports.SitecoreContextReactContext = exports.SitecoreContext = exports.VisitorIdentification = exports.DefaultEmptyFieldEditingComponentText = exports.DefaultEmptyFieldEditingComponentImage = exports.File = exports.getComponentLibraryStylesheetLinks = exports.BYOCComponent = exports.fetchFEaaSComponentServerProps = 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; } });
|
|
@@ -89,8 +89,6 @@ const BYOCWrapper = __importStar(require("./components/BYOCWrapper"));
|
|
|
89
89
|
exports.BYOCWrapper = BYOCWrapper;
|
|
90
90
|
var ComponentBuilder_1 = require("./ComponentBuilder");
|
|
91
91
|
Object.defineProperty(exports, "ComponentBuilder", { enumerable: true, get: function () { return ComponentBuilder_1.ComponentBuilder; } });
|
|
92
|
-
var context_1 = require("./context");
|
|
93
|
-
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } });
|
|
94
92
|
var sitecore_jss_react_1 = require("@sitecore-jss/sitecore-jss-react");
|
|
95
93
|
Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return sitecore_jss_react_1.Image; } });
|
|
96
94
|
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
|
*/
|
|
@@ -136,20 +137,22 @@ class PersonalizeMiddleware extends middleware_1.MiddlewareBase {
|
|
|
136
137
|
}
|
|
137
138
|
initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
138
139
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
yield (0, server_2.
|
|
140
|
+
yield (0, server_2.CloudSDK)(request, response, {
|
|
140
141
|
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
141
142
|
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
142
143
|
siteName,
|
|
143
144
|
cookieDomain: hostname,
|
|
144
145
|
enableServerCookie: true,
|
|
145
|
-
})
|
|
146
|
+
})
|
|
147
|
+
.addPersonalize()
|
|
148
|
+
.initialize();
|
|
146
149
|
});
|
|
147
150
|
}
|
|
148
151
|
personalize({ params, friendlyId, language, timeout, variantIds, }, request) {
|
|
149
152
|
var _a;
|
|
150
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
154
|
sitecore_jss_1.debug.personalize('executing experience for %s %o', friendlyId, params);
|
|
152
|
-
return (yield (0,
|
|
155
|
+
return (yield (0, server_3.personalize)(request, {
|
|
153
156
|
channel: this.config.cdpConfig.channel || 'WEB',
|
|
154
157
|
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USD',
|
|
155
158
|
friendlyId,
|
|
@@ -13,10 +13,6 @@ import React, { forwardRef } from 'react';
|
|
|
13
13
|
import PropTypes from 'prop-types';
|
|
14
14
|
import NextLink from 'next/link';
|
|
15
15
|
import { Link as ReactLink, LinkPropTypes, } from '@sitecore-jss/sitecore-jss-react';
|
|
16
|
-
/**
|
|
17
|
-
* Matches relative URLs that end with a file extension.
|
|
18
|
-
*/
|
|
19
|
-
const FILE_EXTENSION_MATCHER = /^\/.*\.\w+$/;
|
|
20
16
|
export const Link = forwardRef((props, ref) => {
|
|
21
17
|
const { field, editable = true, children, internalLinkMatcher = /^\//g, showLinkTextWithChildrenPresent } = props, htmlLinkProps = __rest(props, ["field", "editable", "children", "internalLinkMatcher", "showLinkTextWithChildrenPresent"]);
|
|
22
18
|
if (!field ||
|
|
@@ -34,10 +30,8 @@ export const Link = forwardRef((props, ref) => {
|
|
|
34
30
|
const isEditing = editable && (field.editable || field.metadata);
|
|
35
31
|
if (href && !isEditing) {
|
|
36
32
|
const text = showLinkTextWithChildrenPresent || !children ? value.text || value.href : null;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// determine if a link is a route or not. File extensions are not routes and should not be pre-fetched.
|
|
40
|
-
if (isMatching && !isFileUrl) {
|
|
33
|
+
// determine if a link is a route or not.
|
|
34
|
+
if (internalLinkMatcher.test(href)) {
|
|
41
35
|
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 }),
|
|
42
36
|
text,
|
|
43
37
|
children));
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export const QUERY_PARAM_EDITING_SECRET = 'secret';
|
|
1
2
|
export const QUERY_PARAM_VERCEL_PROTECTION_BYPASS = 'x-vercel-protection-bypass';
|
|
2
3
|
export const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie';
|
|
3
4
|
/**
|
|
@@ -5,3 +6,7 @@ export const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = 'x-vercel-set-bypass-cookie'
|
|
|
5
6
|
* Note these are in lowercase format to match expected `IncomingHttpHeaders`.
|
|
6
7
|
*/
|
|
7
8
|
export const EDITING_PASS_THROUGH_HEADERS = ['authorization', 'cookie'];
|
|
9
|
+
/**
|
|
10
|
+
* Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
|
|
11
|
+
*/
|
|
12
|
+
export const EDITING_ALLOWED_ORIGINS = ['https://pages.sitecorecloud.io'];
|
|
@@ -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 { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET
|
|
10
|
+
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET } from './constants';
|
|
11
11
|
import { getJssEditingSecret } from '../utils/utils';
|
|
12
12
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
13
13
|
import { EditMode } from '@sitecore-jss/sitecore-jss/layout';
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { editingDataDiskCache } from './editing-data-cache';
|
|
11
11
|
import { isEditingData } from './editing-data';
|
|
12
|
-
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET
|
|
12
|
+
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET } from './constants';
|
|
13
13
|
import { getJssEditingSecret } from '../utils/utils';
|
|
14
14
|
import { enforceCors } from '@sitecore-jss/sitecore-jss/utils';
|
|
15
15
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
@@ -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 { QUERY_PARAM_EDITING_SECRET } from '
|
|
10
|
+
import { QUERY_PARAM_EDITING_SECRET } from './constants';
|
|
11
11
|
import { AxiosDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
|
|
12
12
|
import { editingDataDiskCache } from './editing-data-cache';
|
|
13
13
|
import { getJssEditingSecret } from '../utils/utils';
|
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
import { STATIC_PROPS_ID, SERVER_PROPS_ID } from 'next/constants';
|
|
11
11
|
import { AxiosDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
|
|
12
12
|
import { EditMode } from '@sitecore-jss/sitecore-jss/layout';
|
|
13
|
-
import { QUERY_PARAM_EDITING_SECRET, EDITING_ALLOWED_ORIGINS, } from '@sitecore-jss/sitecore-jss/editing';
|
|
14
13
|
import { editingDataService } from './editing-data-service';
|
|
14
|
+
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET } from './constants';
|
|
15
15
|
import { getJssEditingSecret } from '../utils/utils';
|
|
16
16
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
17
17
|
import { enforceCors, getAllowedOriginsFromEnv } from '@sitecore-jss/sitecore-jss/utils';
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
11
|
-
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET
|
|
11
|
+
import { EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET } from './constants';
|
|
12
12
|
import { getJssEditingSecret } from '../utils/utils';
|
|
13
13
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
14
14
|
import { enforceCors } from '@sitecore-jss/sitecore-jss/utils';
|
package/dist/esm/index.js
CHANGED
|
@@ -19,5 +19,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
19
19
|
export { FEaaSWrapper };
|
|
20
20
|
export { BYOCWrapper };
|
|
21
21
|
export { ComponentBuilder } from './ComponentBuilder';
|
|
22
|
-
export { Context } from './context';
|
|
23
22
|
export { Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, BYOCComponent, getComponentLibraryStylesheetLinks, File, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -11,7 +11,8 @@ import { NextResponse } from 'next/server';
|
|
|
11
11
|
import { GraphQLPersonalizeService, getPersonalizedRewrite, CdpHelper, DEFAULT_VARIANT, } 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
|
*/
|
|
@@ -133,13 +134,15 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
133
134
|
}
|
|
134
135
|
initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
135
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
yield
|
|
137
|
+
yield CloudSDK(request, response, {
|
|
137
138
|
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
138
139
|
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
139
140
|
siteName,
|
|
140
141
|
cookieDomain: hostname,
|
|
141
142
|
enableServerCookie: true,
|
|
142
|
-
})
|
|
143
|
+
})
|
|
144
|
+
.addPersonalize()
|
|
145
|
+
.initialize();
|
|
143
146
|
});
|
|
144
147
|
}
|
|
145
148
|
personalize({ params, friendlyId, language, timeout, variantIds, }, request) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "22.2.0-canary.
|
|
3
|
+
"version": "22.2.0-canary.83",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"url": "https://github.com/sitecore/jss/issues"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@sitecore-cloudsdk/
|
|
32
|
+
"@sitecore-cloudsdk/core": "^0.4.0",
|
|
33
|
+
"@sitecore-cloudsdk/personalize": "^0.4.0",
|
|
33
34
|
"@types/chai": "^4.3.4",
|
|
34
35
|
"@types/chai-as-promised": "^7.1.5",
|
|
35
36
|
"@types/chai-string": "^1.4.2",
|
|
@@ -65,16 +66,16 @@
|
|
|
65
66
|
"typescript": "~4.9.4"
|
|
66
67
|
},
|
|
67
68
|
"peerDependencies": {
|
|
68
|
-
"@sitecore-cloudsdk/
|
|
69
|
-
"@sitecore-cloudsdk/personalize": "^0.
|
|
69
|
+
"@sitecore-cloudsdk/core": "^0.4.0",
|
|
70
|
+
"@sitecore-cloudsdk/personalize": "^0.4.0",
|
|
70
71
|
"next": "^14.2.7",
|
|
71
72
|
"react": "^18.2.0",
|
|
72
73
|
"react-dom": "^18.2.0"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
75
|
-
"@sitecore-jss/sitecore-jss": "^22.2.0-canary.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^22.2.0-canary.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^22.2.0-canary.
|
|
76
|
+
"@sitecore-jss/sitecore-jss": "^22.2.0-canary.83",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^22.2.0-canary.83",
|
|
78
|
+
"@sitecore-jss/sitecore-jss-react": "^22.2.0-canary.83",
|
|
78
79
|
"@vercel/kv": "^0.2.1",
|
|
79
80
|
"prop-types": "^15.8.1",
|
|
80
81
|
"regex-parser": "^2.2.11",
|
|
@@ -82,7 +83,7 @@
|
|
|
82
83
|
},
|
|
83
84
|
"description": "",
|
|
84
85
|
"types": "types/index.d.ts",
|
|
85
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "d56b18ae5aabcf3095dac9d45b9f28959bf10b64",
|
|
86
87
|
"files": [
|
|
87
88
|
"dist",
|
|
88
89
|
"types",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export declare const QUERY_PARAM_EDITING_SECRET = "secret";
|
|
1
2
|
export declare const QUERY_PARAM_VERCEL_PROTECTION_BYPASS = "x-vercel-protection-bypass";
|
|
2
3
|
export declare const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = "x-vercel-set-bypass-cookie";
|
|
3
4
|
/**
|
|
@@ -5,3 +6,7 @@ export declare const QUERY_PARAM_VERCEL_SET_BYPASS_COOKIE = "x-vercel-set-bypass
|
|
|
5
6
|
* Note these are in lowercase format to match expected `IncomingHttpHeaders`.
|
|
6
7
|
*/
|
|
7
8
|
export declare const EDITING_PASS_THROUGH_HEADERS: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
|
|
11
|
+
*/
|
|
12
|
+
export declare const EDITING_ALLOWED_ORIGINS: string[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextApiRequest, NextApiResponse } from 'next';
|
|
2
2
|
import { AxiosDataFetcher } from '@sitecore-jss/sitecore-jss';
|
|
3
3
|
import { EditMode, LayoutServicePageState } from '@sitecore-jss/sitecore-jss/layout';
|
|
4
|
-
import {
|
|
4
|
+
import { LayoutKind } from '@sitecore-jss/sitecore-jss/editing';
|
|
5
5
|
import { EditingDataService } from './editing-data-service';
|
|
6
6
|
import { RenderMiddlewareBase } from './render-middleware';
|
|
7
7
|
/**
|
|
@@ -96,11 +96,26 @@ export declare class ChromesHandler extends RenderMiddlewareBase {
|
|
|
96
96
|
* Configuration for the Editing Metadata Handler.
|
|
97
97
|
*/
|
|
98
98
|
export type EditingRenderMiddlewareMetadataConfig = Pick<EditingRenderMiddlewareConfig, 'resolvePageUrl'>;
|
|
99
|
+
/**
|
|
100
|
+
* Query parameters appended to the page route URL
|
|
101
|
+
* Appended when XMCloud Pages preview (editing) Metadata Edit Mode is used
|
|
102
|
+
*/
|
|
103
|
+
export type MetadataQueryParams = {
|
|
104
|
+
secret: string;
|
|
105
|
+
sc_lang: string;
|
|
106
|
+
sc_itemid: string;
|
|
107
|
+
sc_site: string;
|
|
108
|
+
route: string;
|
|
109
|
+
mode: Exclude<LayoutServicePageState, 'normal'>;
|
|
110
|
+
sc_variant?: string;
|
|
111
|
+
sc_version?: string;
|
|
112
|
+
sc_layoutKind?: LayoutKind;
|
|
113
|
+
};
|
|
99
114
|
/**
|
|
100
115
|
* Next.js API request with Metadata query parameters.
|
|
101
116
|
*/
|
|
102
117
|
type MetadataNextApiRequest = NextApiRequest & {
|
|
103
|
-
query:
|
|
118
|
+
query: MetadataQueryParams;
|
|
104
119
|
};
|
|
105
120
|
/**
|
|
106
121
|
* Data for Next.js Preview (Editing) Metadata Edit Mode.
|
package/types/index.d.ts
CHANGED
|
@@ -22,5 +22,4 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
22
22
|
export { FEaaSWrapper };
|
|
23
23
|
export { BYOCWrapper };
|
|
24
24
|
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
|
25
|
-
export { Context, ContextConfig, SDK } from './context';
|
|
26
25
|
export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getComponentLibraryStylesheetLinks, File, FileField, RichTextField, DefaultEmptyFieldEditingComponentImage, DefaultEmptyFieldEditingComponentText, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, WithSitecoreContextOptions, WithSitecoreContextProps, WithSitecoreContextHocProps, withFieldMetadata, withEmptyFieldEditingComponent, EditingScripts, } from '@sitecore-jss/sitecore-jss-react';
|
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';
|