@sitecore-jss/sitecore-jss-nextjs 21.6.0-canary.3 → 21.6.0-canary.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -4
- package/context.d.ts +1 -0
- package/context.js +1 -0
- package/dist/cjs/context/context.js +63 -0
- package/dist/cjs/context/index.js +5 -0
- package/dist/cjs/editing/constants.js +6 -0
- package/dist/cjs/editing/editing-data-middleware.js +2 -2
- package/dist/cjs/editing/editing-data-service.js +15 -7
- package/dist/cjs/editing/editing-render-middleware.js +31 -8
- package/dist/cjs/graphql/index.js +6 -0
- package/dist/cjs/index.js +10 -5
- package/dist/cjs/middleware/personalize-middleware.js +41 -32
- package/dist/cjs/services/base-graphql-sitemap-service.js +8 -0
- package/dist/esm/context/context.js +59 -0
- package/dist/esm/context/index.js +1 -0
- package/dist/esm/editing/constants.js +3 -0
- package/dist/esm/editing/editing-data-middleware.js +1 -1
- package/dist/esm/editing/editing-data-service.js +13 -5
- package/dist/esm/editing/editing-render-middleware.js +31 -8
- package/dist/esm/graphql/index.js +1 -0
- package/dist/esm/index.js +8 -2
- package/dist/esm/middleware/personalize-middleware.js +42 -33
- package/dist/esm/services/base-graphql-sitemap-service.js +9 -1
- package/graphql.d.ts +1 -0
- package/graphql.js +1 -0
- package/package.json +9 -8
- package/types/ComponentBuilder.d.ts +1 -0
- package/types/components/ComponentPropsContext.d.ts +1 -0
- package/types/components/Link.d.ts +1 -0
- package/types/components/NextImage.d.ts +1 -0
- package/types/components/Placeholder.d.ts +1 -0
- package/types/context/context.d.ts +104 -0
- package/types/context/index.d.ts +1 -0
- package/types/editing/constants.d.ts +3 -0
- package/types/editing/editing-data-service.d.ts +12 -4
- package/types/editing/editing-render-middleware.d.ts +10 -0
- package/types/graphql/index.d.ts +1 -0
- package/types/index.d.ts +6 -2
- package/types/middleware/personalize-middleware.d.ts +20 -15
- package/types/services/base-graphql-sitemap-service.d.ts +10 -3
- package/types/sharedTypes/module-factory.d.ts +1 -0
|
@@ -11,7 +11,8 @@ import { STATIC_PROPS_ID, SERVER_PROPS_ID } from 'next/constants';
|
|
|
11
11
|
import { AxiosDataFetcher, debug } from '@sitecore-jss/sitecore-jss';
|
|
12
12
|
import { EDITING_COMPONENT_ID, RenderingType } from '@sitecore-jss/sitecore-jss/layout';
|
|
13
13
|
import { parse } from 'node-html-parser';
|
|
14
|
-
import { editingDataService
|
|
14
|
+
import { editingDataService } from './editing-data-service';
|
|
15
|
+
import { QUERY_PARAM_EDITING_SECRET, QUERY_PARAM_PROTECTION_BYPASS_SITECORE, QUERY_PARAM_PROTECTION_BYPASS_VERCEL, } from './constants';
|
|
15
16
|
import { getJssEditingSecret } from '../utils/utils';
|
|
16
17
|
/**
|
|
17
18
|
* Middleware / handler for use in the editing render Next.js API route (e.g. '/api/editing/render')
|
|
@@ -23,6 +24,21 @@ export class EditingRenderMiddleware {
|
|
|
23
24
|
*/
|
|
24
25
|
constructor(config) {
|
|
25
26
|
var _a, _b, _c, _d;
|
|
27
|
+
/**
|
|
28
|
+
* Gets query parameters that should be passed along to subsequent requests
|
|
29
|
+
* @param query Object of query parameters from incoming URL
|
|
30
|
+
* @returns Object of approved query parameters
|
|
31
|
+
*/
|
|
32
|
+
this.getQueryParamsForPropagation = (query) => {
|
|
33
|
+
const params = {};
|
|
34
|
+
if (query[QUERY_PARAM_PROTECTION_BYPASS_SITECORE]) {
|
|
35
|
+
params[QUERY_PARAM_PROTECTION_BYPASS_SITECORE] = query[QUERY_PARAM_PROTECTION_BYPASS_SITECORE];
|
|
36
|
+
}
|
|
37
|
+
if (query[QUERY_PARAM_PROTECTION_BYPASS_VERCEL]) {
|
|
38
|
+
params[QUERY_PARAM_PROTECTION_BYPASS_VERCEL] = query[QUERY_PARAM_PROTECTION_BYPASS_VERCEL];
|
|
39
|
+
}
|
|
40
|
+
return params;
|
|
41
|
+
};
|
|
26
42
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
27
43
|
var _e, _f;
|
|
28
44
|
const { method, query, body, headers } = req;
|
|
@@ -53,21 +69,28 @@ export class EditingRenderMiddleware {
|
|
|
53
69
|
const editingData = extractEditingData(req);
|
|
54
70
|
// Resolve server URL
|
|
55
71
|
const serverUrl = this.resolveServerUrl(req);
|
|
72
|
+
// Get query string parameters to propagate on subsequent requests (e.g. for deployment protection bypass)
|
|
73
|
+
const params = this.getQueryParamsForPropagation(query);
|
|
56
74
|
// Stash for use later on (i.e. within getStatic/ServerSideProps).
|
|
57
75
|
// Note we can't set this directly in setPreviewData since it's stored as a cookie (2KB limit)
|
|
58
76
|
// https://nextjs.org/docs/advanced-features/preview-mode#previewdata-size-limits)
|
|
59
|
-
const previewData = yield this.editingDataService.setEditingData(editingData, serverUrl);
|
|
77
|
+
const previewData = yield this.editingDataService.setEditingData(editingData, serverUrl, params);
|
|
60
78
|
// Enable Next.js Preview Mode, passing our preview data (i.e. editingData cache key)
|
|
61
79
|
res.setPreviewData(previewData);
|
|
62
80
|
// Grab the Next.js preview cookies to send on to the render request
|
|
63
81
|
const cookies = res.getHeader('Set-Cookie');
|
|
64
|
-
// Make actual render request for page route, passing on preview cookies.
|
|
82
|
+
// Make actual render request for page route, passing on preview cookies as well as any approved query string parameters.
|
|
65
83
|
// Note timestamp effectively disables caching the request in Axios (no amount of cache headers seemed to do it)
|
|
66
|
-
const requestUrl = this.resolvePageUrl(serverUrl, editingData.path);
|
|
67
84
|
debug.editing('fetching page route for %s', editingData.path);
|
|
68
|
-
const
|
|
85
|
+
const requestUrl = new URL(this.resolvePageUrl(serverUrl, editingData.path));
|
|
86
|
+
for (const key in params) {
|
|
87
|
+
if ({}.hasOwnProperty.call(params, key)) {
|
|
88
|
+
requestUrl.searchParams.append(key, params[key]);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
requestUrl.searchParams.append('timestamp', Date.now().toString());
|
|
69
92
|
const pageRes = yield this.dataFetcher
|
|
70
|
-
.get(
|
|
93
|
+
.get(requestUrl.toString(), {
|
|
71
94
|
headers: {
|
|
72
95
|
Cookie: cookies.join(';'),
|
|
73
96
|
},
|
|
@@ -82,7 +105,7 @@ export class EditingRenderMiddleware {
|
|
|
82
105
|
});
|
|
83
106
|
let html = pageRes.data;
|
|
84
107
|
if (!html || html.length === 0) {
|
|
85
|
-
throw new Error(`Failed to render html for ${
|
|
108
|
+
throw new Error(`Failed to render html for ${editingData.path}`);
|
|
86
109
|
}
|
|
87
110
|
// replace phkey attribute with key attribute so that newly added renderings
|
|
88
111
|
// show correct placeholders, so save and refresh won't be needed after adding each rendering
|
|
@@ -98,7 +121,7 @@ export class EditingRenderMiddleware {
|
|
|
98
121
|
// Handle component rendering. Extract component markup only
|
|
99
122
|
html = (_f = parse(html).getElementById(EDITING_COMPONENT_ID)) === null || _f === void 0 ? void 0 : _f.innerHTML;
|
|
100
123
|
if (!html)
|
|
101
|
-
throw new Error(`Failed to render component for ${
|
|
124
|
+
throw new Error(`Failed to render component for ${editingData.path}`);
|
|
102
125
|
}
|
|
103
126
|
const body = { html };
|
|
104
127
|
// Return expected JSON result
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GraphQLRequestClient, getEdgeProxyContentUrl, } from '@sitecore-jss/sitecore-jss/graphql';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { constants, AxiosDataFetcher, NativeDataFetcher, enableDebug, debug, } from '@sitecore-jss/sitecore-jss';
|
|
2
2
|
// we will remove the root exports for these later
|
|
3
3
|
// we cannot mark exports as deprected directly, so we're using this hack instead
|
|
4
|
+
import { GraphQLRequestClient as GraphQLRequestClientDep } from './graphql';
|
|
4
5
|
import { isEditorActive as isEditorActiveDep, resetEditorChromes as resetEditorChromesDep, resolveUrl as resolveUrlDep, tryParseEnvValue as tryParseEnvValueDep, } from '@sitecore-jss/sitecore-jss/utils';
|
|
5
6
|
import { handleEditorFastRefresh as handleEditorFastRefreshDep, getPublicUrl as getPublicUrlDep, } from './utils';
|
|
6
7
|
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/utils' instead */
|
|
@@ -12,14 +13,18 @@ const { isEditorActiveDep: isEditorActive, resetEditorChromesDep: resetEditorChr
|
|
|
12
13
|
handleEditorFastRefreshDep,
|
|
13
14
|
getPublicUrlDep,
|
|
14
15
|
};
|
|
16
|
+
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/graphql' instead */
|
|
17
|
+
const { GraphQLRequestClientDep: GraphQLRequestClient } = {
|
|
18
|
+
GraphQLRequestClientDep,
|
|
19
|
+
};
|
|
20
|
+
export { GraphQLRequestClient };
|
|
15
21
|
export { handleEditorFastRefresh, getPublicUrl };
|
|
16
22
|
export { isEditorActive, resetEditorChromes, resolveUrl, tryParseEnvValue };
|
|
17
23
|
export { LayoutServicePageState, GraphQLLayoutService, RestLayoutService, getChildPlaceholder, getFieldValue, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-jss/sitecore-jss/layout';
|
|
18
24
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
19
25
|
export { trackingApi, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
20
26
|
export { GraphQLDictionaryService, RestDictionaryService, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
21
|
-
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper,
|
|
22
|
-
export { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss';
|
|
27
|
+
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
23
28
|
export { ComponentPropsService } from './services/component-props-service';
|
|
24
29
|
export { DisconnectedSitemapService } from './services/disconnected-sitemap-service';
|
|
25
30
|
export { GraphQLSitemapService, } from './services/graphql-sitemap-service';
|
|
@@ -36,4 +41,5 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
36
41
|
export { FEaaSWrapper };
|
|
37
42
|
export { BYOCWrapper };
|
|
38
43
|
export { ComponentBuilder } from './ComponentBuilder';
|
|
44
|
+
export { Context } from './context';
|
|
39
45
|
export { Image, Text, DateField, EditFrame, FEaaSComponent, fetchFEaaSComponentServerProps, BYOCComponent, getFEAASLibraryStylesheetLinks, File, VisitorIdentification, SitecoreContext, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -8,10 +8,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { NextResponse } from 'next/server';
|
|
11
|
-
import { GraphQLPersonalizeService, getPersonalizedRewrite,
|
|
11
|
+
import { GraphQLPersonalizeService, getPersonalizedRewrite, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
12
12
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
13
13
|
import { MiddlewareBase } from './middleware';
|
|
14
|
-
import {
|
|
14
|
+
import { init, personalize } from '@sitecore-cloudsdk/personalize/server';
|
|
15
15
|
/**
|
|
16
16
|
* Middleware / handler to support Sitecore Personalize
|
|
17
17
|
*/
|
|
@@ -23,7 +23,6 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
23
23
|
super(config);
|
|
24
24
|
this.config = config;
|
|
25
25
|
this.handler = (req, res) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
var _a;
|
|
27
26
|
const pathname = req.nextUrl.pathname;
|
|
28
27
|
const language = this.getLanguage(req);
|
|
29
28
|
const hostname = this.getHostHeader(req) || this.defaultHostname;
|
|
@@ -48,16 +47,6 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
48
47
|
return response;
|
|
49
48
|
}
|
|
50
49
|
const site = this.getSite(req, response);
|
|
51
|
-
const engageServer = this.initializeEngageServer(site, language);
|
|
52
|
-
// creates the browser ID cookie on the server side
|
|
53
|
-
// and includes the cookie in the response header
|
|
54
|
-
try {
|
|
55
|
-
yield engageServer.handleCookie(req, response, timeout);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
debug.personalize('skipped (browser id generation failed)');
|
|
59
|
-
throw error;
|
|
60
|
-
}
|
|
61
50
|
// Get personalization info from Experience Edge
|
|
62
51
|
const personalizeInfo = yield this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
|
|
63
52
|
if (!personalizeInfo) {
|
|
@@ -69,20 +58,20 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
69
58
|
debug.personalize('skipped (no personalization configured)');
|
|
70
59
|
return response;
|
|
71
60
|
}
|
|
61
|
+
yield this.initPersonalizeServer({
|
|
62
|
+
hostname,
|
|
63
|
+
siteName: site.name,
|
|
64
|
+
request: req,
|
|
65
|
+
response,
|
|
66
|
+
});
|
|
72
67
|
const params = this.getExperienceParams(req);
|
|
73
68
|
debug.personalize('executing experience for %s %s %o', personalizeInfo.contentId, params);
|
|
74
|
-
const personalizationData = {
|
|
75
|
-
channel: this.config.cdpConfig.channel || 'WEB',
|
|
76
|
-
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USA',
|
|
77
|
-
friendlyId: personalizeInfo.contentId,
|
|
78
|
-
params,
|
|
79
|
-
language,
|
|
80
|
-
};
|
|
81
69
|
let variantId;
|
|
82
|
-
// Execute targeted experience in
|
|
70
|
+
// Execute targeted experience in Personalize SDK
|
|
83
71
|
// eslint-disable-next-line no-useless-catch
|
|
84
72
|
try {
|
|
85
|
-
|
|
73
|
+
const personalization = yield this.personalize({ personalizeInfo, params, language, timeout }, req);
|
|
74
|
+
variantId = personalization.variantId;
|
|
86
75
|
}
|
|
87
76
|
catch (error) {
|
|
88
77
|
throw error;
|
|
@@ -101,15 +90,22 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
101
90
|
const rewritePath = getPersonalizedRewrite(basePath, { variantId });
|
|
102
91
|
// Note an absolute URL is required: https://nextjs.org/docs/messages/middleware-relative-urls
|
|
103
92
|
const rewriteUrl = req.nextUrl.clone();
|
|
93
|
+
// Preserve cookies from previous response
|
|
94
|
+
const cookies = response.cookies.getAll();
|
|
104
95
|
rewriteUrl.pathname = rewritePath;
|
|
105
|
-
response = NextResponse.rewrite(rewriteUrl);
|
|
96
|
+
response = NextResponse.rewrite(rewriteUrl, response);
|
|
106
97
|
// Disable preflight caching to force revalidation on client-side navigation (personalization may be influenced)
|
|
107
98
|
// See https://github.com/vercel/next.js/issues/32727
|
|
108
99
|
response.headers.set('x-middleware-cache', 'no-cache');
|
|
109
|
-
// Share rewrite path with following executed
|
|
100
|
+
// Share rewrite path with following executed middleware
|
|
110
101
|
response.headers.set('x-sc-rewrite', rewritePath);
|
|
111
102
|
// Share site name with the following executed middlewares
|
|
112
103
|
response.cookies.set(this.SITE_SYMBOL, site.name);
|
|
104
|
+
// Restore cookies from previous response since
|
|
105
|
+
// browserId cookie gets omitted after rewrite
|
|
106
|
+
cookies.forEach((cookie) => {
|
|
107
|
+
response.cookies.set(cookie);
|
|
108
|
+
});
|
|
113
109
|
debug.personalize('personalize middleware end in %dms: %o', Date.now() - startTimestamp, {
|
|
114
110
|
rewritePath,
|
|
115
111
|
headers: this.extractDebugHeaders(response.headers),
|
|
@@ -136,16 +132,29 @@ export class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
136
132
|
}
|
|
137
133
|
});
|
|
138
134
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
:
|
|
146
|
-
|
|
135
|
+
initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
136
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
137
|
+
yield init({
|
|
138
|
+
sitecoreEdgeUrl: this.config.cdpConfig.sitecoreEdgeUrl,
|
|
139
|
+
sitecoreEdgeContextId: this.config.cdpConfig.sitecoreEdgeContextId,
|
|
140
|
+
siteName,
|
|
141
|
+
cookieDomain: hostname,
|
|
142
|
+
enableServerCookie: true,
|
|
143
|
+
}, request, response);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
personalize({ params, personalizeInfo, language, timeout, }, request) {
|
|
147
|
+
var _a;
|
|
148
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const personalizationData = {
|
|
150
|
+
channel: this.config.cdpConfig.channel || 'WEB',
|
|
151
|
+
currency: (_a = this.config.cdpConfig.currency) !== null && _a !== void 0 ? _a : 'USD',
|
|
152
|
+
friendlyId: personalizeInfo.contentId,
|
|
153
|
+
params,
|
|
154
|
+
language,
|
|
155
|
+
};
|
|
156
|
+
return (yield personalize(personalizationData, request, timeout));
|
|
147
157
|
});
|
|
148
|
-
return engageServer;
|
|
149
158
|
}
|
|
150
159
|
getExperienceParams(req) {
|
|
151
160
|
const utm = {
|
|
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss/graphql';
|
|
10
|
+
import { GraphQLRequestClient, } from '@sitecore-jss/sitecore-jss/graphql';
|
|
11
11
|
import { debug } from '@sitecore-jss/sitecore-jss';
|
|
12
12
|
import { getPersonalizedRewrite } from '@sitecore-jss/sitecore-jss/personalize';
|
|
13
13
|
/** @private */
|
|
@@ -191,6 +191,14 @@ export class BaseGraphQLSitemapService {
|
|
|
191
191
|
* @returns {GraphQLClient} implementation
|
|
192
192
|
*/
|
|
193
193
|
getGraphQLClient() {
|
|
194
|
+
if (!this.options.endpoint) {
|
|
195
|
+
if (!this.options.clientFactory) {
|
|
196
|
+
throw new Error('You should provide either an endpoint and apiKey, or a clientFactory.');
|
|
197
|
+
}
|
|
198
|
+
return this.options.clientFactory({
|
|
199
|
+
debugger: debug.sitemap,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
194
202
|
return new GraphQLRequestClient(this.options.endpoint, {
|
|
195
203
|
apiKey: this.options.apiKey,
|
|
196
204
|
debugger: debug.sitemap,
|
package/graphql.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types/graphql/index';
|
package/graphql.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/cjs/graphql/index');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sitecore-jss/sitecore-jss-nextjs",
|
|
3
|
-
"version": "21.6.0-canary.
|
|
3
|
+
"version": "21.6.0-canary.31",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"test": "mocha --require ./test/setup.js \"./src/**/*.test.ts\" \"./src/**/*.test.tsx\" --exit",
|
|
12
12
|
"prepublishOnly": "npm run build",
|
|
13
13
|
"coverage": "nyc npm test",
|
|
14
|
-
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --githubPages false"
|
|
14
|
+
"generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --readme none --out ../../ref-docs/sitecore-jss-nextjs --entryPoints src/index.ts --entryPoints src/monitoring/index.ts --entryPoints src/editing/index.ts --entryPoints src/middleware/index.ts --entryPoints src/context/index.ts --entryPoints src/utils/index.ts --entryPoints src/site/index.ts --entryPoints src/graphql/index.ts --githubPages false"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=12",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"url": "https://github.com/sitecore/jss/issues"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@sitecore/
|
|
33
|
+
"@sitecore-cloudsdk/personalize": "^0.1.1",
|
|
34
34
|
"@types/chai": "^4.3.4",
|
|
35
35
|
"@types/chai-as-promised": "^7.1.5",
|
|
36
36
|
"@types/chai-string": "^1.4.2",
|
|
@@ -66,15 +66,16 @@
|
|
|
66
66
|
"typescript": "~4.9.4"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@sitecore/
|
|
69
|
+
"@sitecore-cloudsdk/events": "^0.1.1",
|
|
70
|
+
"@sitecore-cloudsdk/personalize": "^0.1.1",
|
|
70
71
|
"next": "^13.4.16",
|
|
71
72
|
"react": "^18.2.0",
|
|
72
73
|
"react-dom": "^18.2.0"
|
|
73
74
|
},
|
|
74
75
|
"dependencies": {
|
|
75
|
-
"@sitecore-jss/sitecore-jss": "^21.6.0-canary.
|
|
76
|
-
"@sitecore-jss/sitecore-jss-dev-tools": "^21.6.0-canary.
|
|
77
|
-
"@sitecore-jss/sitecore-jss-react": "^21.6.0-canary.
|
|
76
|
+
"@sitecore-jss/sitecore-jss": "^21.6.0-canary.31",
|
|
77
|
+
"@sitecore-jss/sitecore-jss-dev-tools": "^21.6.0-canary.31",
|
|
78
|
+
"@sitecore-jss/sitecore-jss-react": "^21.6.0-canary.31",
|
|
78
79
|
"@vercel/kv": "^0.2.1",
|
|
79
80
|
"node-html-parser": "^6.1.4",
|
|
80
81
|
"prop-types": "^15.8.1",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
},
|
|
84
85
|
"description": "",
|
|
85
86
|
"types": "types/index.d.ts",
|
|
86
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "db032a6fdbcba3627412f55865ab660bb7aa5900",
|
|
87
88
|
"files": [
|
|
88
89
|
"dist",
|
|
89
90
|
"types",
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Software Development Kit (SDK) instance
|
|
3
|
+
*/
|
|
4
|
+
export type SDK<SDKType = unknown> = {
|
|
5
|
+
/**
|
|
6
|
+
* The Software Development Kit (SDK) library instance
|
|
7
|
+
*/
|
|
8
|
+
sdk: SDKType;
|
|
9
|
+
/**
|
|
10
|
+
* Initializes the Software Development Kit (SDK)
|
|
11
|
+
*/
|
|
12
|
+
init: (props: InitSDKProps) => Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Software Development Kits (SDKs) to be initialized
|
|
16
|
+
*/
|
|
17
|
+
type SDKModulesType = Record<string, SDK>;
|
|
18
|
+
/**
|
|
19
|
+
* Properties that are passed to the Context.
|
|
20
|
+
*/
|
|
21
|
+
export interface ContextInitProps {
|
|
22
|
+
/**
|
|
23
|
+
* Your Sitecore site name
|
|
24
|
+
*/
|
|
25
|
+
siteName?: string;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Configuration that is passed to the Context.
|
|
29
|
+
*/
|
|
30
|
+
export interface ContextConfig<SDKModules extends SDKModulesType> {
|
|
31
|
+
/**
|
|
32
|
+
* Your Sitecore Edge URL
|
|
33
|
+
*/
|
|
34
|
+
sitecoreEdgeUrl: string;
|
|
35
|
+
/**
|
|
36
|
+
* Your Sitecore Edge Context ID
|
|
37
|
+
*/
|
|
38
|
+
sitecoreEdgeContextId: string;
|
|
39
|
+
/**
|
|
40
|
+
* Your Sitecore site name
|
|
41
|
+
*/
|
|
42
|
+
siteName: string;
|
|
43
|
+
/**
|
|
44
|
+
* Software Development Kits (SDKs) to be initialized
|
|
45
|
+
*/
|
|
46
|
+
sdks: {
|
|
47
|
+
[module in keyof SDKModules]: SDKModules[module];
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Properties that are passed to the Software Development Kit (SDK) initialization function.
|
|
52
|
+
*/
|
|
53
|
+
type InitSDKProps = Omit<ContextConfig<SDKModulesType>, 'sdks'>;
|
|
54
|
+
/**
|
|
55
|
+
* Context instance that is used to initialize the application Context and associated Software Development Kits (SDKs).
|
|
56
|
+
*/
|
|
57
|
+
export declare class Context<SDKModules extends SDKModulesType> {
|
|
58
|
+
protected props: ContextConfig<SDKModules>;
|
|
59
|
+
/**
|
|
60
|
+
* Indicates whether the Context and SDK(s) have been initialized
|
|
61
|
+
*/
|
|
62
|
+
isInitialized: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* The Sitecore Edge URL
|
|
65
|
+
*/
|
|
66
|
+
readonly sitecoreEdgeUrl: string;
|
|
67
|
+
/**
|
|
68
|
+
* The Sitecore Edge Context ID
|
|
69
|
+
*/
|
|
70
|
+
readonly sitecoreEdgeContextId: string;
|
|
71
|
+
/**
|
|
72
|
+
* The Sitecore site name
|
|
73
|
+
*/
|
|
74
|
+
siteName: string;
|
|
75
|
+
/**
|
|
76
|
+
* Software Development Kits (SDKs) to be initialized
|
|
77
|
+
*/
|
|
78
|
+
readonly sdks: {
|
|
79
|
+
[module in keyof SDKModules]?: SDKModules[module]['sdk'];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Promises for the SDKs
|
|
83
|
+
*/
|
|
84
|
+
protected sdkPromises: {
|
|
85
|
+
[module in keyof SDKModules]?: Promise<SDKModules[module]['sdk']>;
|
|
86
|
+
};
|
|
87
|
+
constructor(props: ContextConfig<SDKModules>);
|
|
88
|
+
init(props?: ContextInitProps): void;
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves the Software Development Kit (SDK) instance, ensuring it is initialized before returning
|
|
91
|
+
*
|
|
92
|
+
* @param {string} name SDK name
|
|
93
|
+
* @returns initialized SDK
|
|
94
|
+
*/
|
|
95
|
+
getSDK<T extends keyof SDKModules>(name: T): Promise<SDKModules[T]['sdk']> | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Initializes the Software Development Kit (SDK)
|
|
98
|
+
*
|
|
99
|
+
* @param {T} name SDK name
|
|
100
|
+
* @returns {void}
|
|
101
|
+
*/
|
|
102
|
+
protected initSDK<T extends keyof SDKModules>(name: T): void;
|
|
103
|
+
}
|
|
104
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Context, ContextConfig, SDK } from './context';
|
|
@@ -2,13 +2,15 @@ import { AxiosDataFetcher } from '@sitecore-jss/sitecore-jss';
|
|
|
2
2
|
import { EditingData } from './editing-data';
|
|
3
3
|
import { EditingDataCache } from './editing-data-cache';
|
|
4
4
|
import { PreviewData } from 'next';
|
|
5
|
-
export declare const QUERY_PARAM_EDITING_SECRET = "secret";
|
|
6
5
|
/**
|
|
7
6
|
* Data for Next.js Preview (Editing) mode
|
|
8
7
|
*/
|
|
9
8
|
export interface EditingPreviewData {
|
|
10
9
|
key: string;
|
|
11
10
|
serverUrl?: string;
|
|
11
|
+
params?: {
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
};
|
|
12
14
|
}
|
|
13
15
|
/**
|
|
14
16
|
* Defines an editing data service implementation
|
|
@@ -20,7 +22,9 @@ export interface EditingDataService {
|
|
|
20
22
|
* @param {string} serverUrl The server url e.g. which can be used for further API requests
|
|
21
23
|
* @returns The {@link EditingPreviewData} containing the information to use for retrieval
|
|
22
24
|
*/
|
|
23
|
-
setEditingData(data: EditingData, serverUrl: string
|
|
25
|
+
setEditingData(data: EditingData, serverUrl: string, params?: {
|
|
26
|
+
[key: string]: string;
|
|
27
|
+
}): Promise<EditingPreviewData>;
|
|
24
28
|
/**
|
|
25
29
|
* Retrieves Sitecore editor payload data
|
|
26
30
|
* @param {PreviewData} previewData Editing preview data containing the information to use for retrieval
|
|
@@ -107,14 +111,18 @@ export declare class ServerlessEditingDataService implements EditingDataService
|
|
|
107
111
|
* @param {string} serverUrl The server url to use for subsequent data API requests
|
|
108
112
|
* @returns {Promise} The {@link EditingPreviewData} containing the generated key and serverUrl to use for retrieval
|
|
109
113
|
*/
|
|
110
|
-
setEditingData(data: EditingData, serverUrl: string
|
|
114
|
+
setEditingData(data: EditingData, serverUrl: string, params?: {
|
|
115
|
+
[key: string]: string;
|
|
116
|
+
}): Promise<EditingPreviewData>;
|
|
111
117
|
/**
|
|
112
118
|
* Retrieves Sitecore editor payload data by key
|
|
113
119
|
* @param {PreviewData} previewData Editing preview data containing the key and serverUrl to use for retrieval
|
|
114
120
|
* @returns {Promise} The {@link EditingData}
|
|
115
121
|
*/
|
|
116
122
|
getEditingData(previewData: PreviewData): Promise<EditingData | undefined>;
|
|
117
|
-
protected getUrl(serverUrl: string, key: string
|
|
123
|
+
protected getUrl(serverUrl: string, key: string, params?: {
|
|
124
|
+
[key: string]: string;
|
|
125
|
+
}): string;
|
|
118
126
|
}
|
|
119
127
|
/**
|
|
120
128
|
* The `EditingDataService` default instance.
|
|
@@ -55,6 +55,16 @@ export declare class EditingRenderMiddleware {
|
|
|
55
55
|
* @returns route handler
|
|
56
56
|
*/
|
|
57
57
|
getHandler(): (req: NextApiRequest, res: NextApiResponse) => Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Gets query parameters that should be passed along to subsequent requests
|
|
60
|
+
* @param query Object of query parameters from incoming URL
|
|
61
|
+
* @returns Object of approved query parameters
|
|
62
|
+
*/
|
|
63
|
+
protected getQueryParamsForPropagation: (query: Partial<{
|
|
64
|
+
[key: string]: string | string[];
|
|
65
|
+
}>) => {
|
|
66
|
+
[key: string]: string;
|
|
67
|
+
};
|
|
58
68
|
private handler;
|
|
59
69
|
/**
|
|
60
70
|
* Default page URL resolution.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { GraphQLRequestClient, GraphQLRequestClientFactory, GraphQLRequestClientFactoryConfig, getEdgeProxyContentUrl, } from '@sitecore-jss/sitecore-jss/graphql';
|
package/types/index.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
export { constants, HttpDataFetcher, HttpResponse, AxiosResponse, AxiosDataFetcher, AxiosDataFetcherConfig, NativeDataFetcher, NativeDataFetcherConfig, HTMLLink, enableDebug, debug, } from '@sitecore-jss/sitecore-jss';
|
|
2
|
+
import { GraphQLRequestClient as GraphQLRequestClientDep } from './graphql';
|
|
2
3
|
import { resolveUrl as resolveUrlDep } from '@sitecore-jss/sitecore-jss/utils';
|
|
3
4
|
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/utils' instead */
|
|
4
5
|
declare const isEditorActive: () => boolean, resetEditorChromes: () => void, resolveUrl: typeof resolveUrlDep, tryParseEnvValue: <T>(envValue: string | undefined, defaultValue: T) => T, handleEditorFastRefresh: (forceReload?: boolean) => void, getPublicUrl: () => string;
|
|
6
|
+
/** @deprecated use import from '@sitecore-jss/sitecore-jss-nextjs/graphql' instead */
|
|
7
|
+
declare const GraphQLRequestClient: typeof GraphQLRequestClientDep;
|
|
8
|
+
export { GraphQLRequestClient };
|
|
5
9
|
export { handleEditorFastRefresh, getPublicUrl };
|
|
6
10
|
export { isEditorActive, resetEditorChromes, resolveUrl, tryParseEnvValue };
|
|
7
11
|
export { LayoutService, LayoutServiceData, LayoutServicePageState, LayoutServiceContext, LayoutServiceContextData, GraphQLLayoutService, GraphQLLayoutServiceConfig, RestLayoutService, RestLayoutServiceConfig, PlaceholderData, PlaceholdersData, RouteData, Field, Item, HtmlElementRendering, getChildPlaceholder, getFieldValue, ComponentRendering, ComponentFields, ComponentParams, RenderingType, EDITING_COMPONENT_PLACEHOLDER, EDITING_COMPONENT_ID, } from '@sitecore-jss/sitecore-jss/layout';
|
|
8
12
|
export { mediaApi } from '@sitecore-jss/sitecore-jss/media';
|
|
9
13
|
export { trackingApi, TrackingRequestOptions, CampaignInstance, GoalInstance, OutcomeInstance, EventInstance, PageViewInstance, } from '@sitecore-jss/sitecore-jss/tracking';
|
|
10
14
|
export { DictionaryPhrases, DictionaryService, GraphQLDictionaryService, GraphQLDictionaryServiceConfig, RestDictionaryService, RestDictionaryServiceConfig, } from '@sitecore-jss/sitecore-jss/i18n';
|
|
11
|
-
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper,
|
|
12
|
-
export { GraphQLRequestClient } from '@sitecore-jss/sitecore-jss';
|
|
15
|
+
export { personalizeLayout, getPersonalizedRewrite, getPersonalizedRewriteData, normalizePersonalizedRewrite, CdpHelper, } from '@sitecore-jss/sitecore-jss/personalize';
|
|
13
16
|
export { ComponentPropsCollection, ComponentPropsError, GetStaticComponentProps, GetServerSideComponentProps, } from './sharedTypes/component-props';
|
|
14
17
|
export { ModuleFactory, Module } from './sharedTypes/module-factory';
|
|
15
18
|
export { ComponentPropsService } from './services/component-props-service';
|
|
@@ -29,4 +32,5 @@ import * as BYOCWrapper from './components/BYOCWrapper';
|
|
|
29
32
|
export { FEaaSWrapper };
|
|
30
33
|
export { BYOCWrapper };
|
|
31
34
|
export { ComponentBuilder, ComponentBuilderConfig } from './ComponentBuilder';
|
|
35
|
+
export { Context, ContextConfig, SDK } from './context';
|
|
32
36
|
export { ComponentFactory, Image, ImageField, ImageFieldValue, ImageProps, LinkField, LinkFieldValue, Text, TextField, DateField, EditFrame, FEaaSComponent, FEaaSComponentProps, FEaaSComponentParams, fetchFEaaSComponentServerProps, BYOCComponentParams, BYOCComponent, BYOCComponentProps, getFEAASLibraryStylesheetLinks, File, FileField, RichTextField, VisitorIdentification, PlaceholderComponentProps, SitecoreContext, SitecoreContextState, SitecoreContextValue, SitecoreContextReactContext, withSitecoreContext, useSitecoreContext, withEditorChromes, withPlaceholder, withDatasourceCheck, ImageSizeParameters, ComponentConsumerProps, WithSitecoreContextOptions, WithSitecoreContextProps, } from '@sitecore-jss/sitecore-jss-react';
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { NextResponse, NextRequest } from 'next/server';
|
|
2
|
-
import { GraphQLPersonalizeServiceConfig } from '@sitecore-jss/sitecore-jss/personalize';
|
|
3
|
-
import { SiteInfo } from '@sitecore-jss/sitecore-jss/site';
|
|
2
|
+
import { GraphQLPersonalizeServiceConfig, PersonalizeInfo } from '@sitecore-jss/sitecore-jss/personalize';
|
|
4
3
|
import { MiddlewareBase, MiddlewareBaseConfig } from './middleware';
|
|
5
|
-
import { EngageServer } from '@sitecore/engage';
|
|
6
4
|
export type CdpServiceConfig = {
|
|
7
5
|
/**
|
|
8
|
-
* Your Sitecore
|
|
6
|
+
* Your Sitecore Edge Platform endpoint
|
|
7
|
+
* Default is https://edge-platform.sitecorecloud.io
|
|
9
8
|
*/
|
|
10
|
-
|
|
9
|
+
sitecoreEdgeUrl?: string;
|
|
11
10
|
/**
|
|
12
|
-
*
|
|
11
|
+
* Your unified Sitecore Edge Context Id
|
|
13
12
|
*/
|
|
14
|
-
|
|
13
|
+
sitecoreEdgeContextId: string;
|
|
15
14
|
/**
|
|
16
15
|
* The Sitecore CDP channel to use for events. Uses 'WEB' by default.
|
|
17
16
|
*/
|
|
@@ -34,13 +33,6 @@ export type PersonalizeMiddlewareConfig = MiddlewareBaseConfig & {
|
|
|
34
33
|
* Configuration for your Sitecore CDP endpoint
|
|
35
34
|
*/
|
|
36
35
|
cdpConfig: CdpServiceConfig;
|
|
37
|
-
/**
|
|
38
|
-
* function to resolve point of sale for a site
|
|
39
|
-
* @param {Siteinfo} site to get info from
|
|
40
|
-
* @param {string} language to get info for
|
|
41
|
-
* @returns point of sale value for site/language combination
|
|
42
|
-
*/
|
|
43
|
-
getPointOfSale?: (site: SiteInfo, language: string) => string;
|
|
44
36
|
};
|
|
45
37
|
/**
|
|
46
38
|
* Object model of Experience Context data
|
|
@@ -70,7 +62,20 @@ export declare class PersonalizeMiddleware extends MiddlewareBase {
|
|
|
70
62
|
* @returns middleware handler
|
|
71
63
|
*/
|
|
72
64
|
getHandler(): (req: NextRequest, res?: NextResponse) => Promise<NextResponse>;
|
|
73
|
-
protected
|
|
65
|
+
protected initPersonalizeServer({ hostname, siteName, request, response, }: {
|
|
66
|
+
hostname: string;
|
|
67
|
+
siteName: string;
|
|
68
|
+
request: NextRequest;
|
|
69
|
+
response: NextResponse;
|
|
70
|
+
}): Promise<void>;
|
|
71
|
+
protected personalize({ params, personalizeInfo, language, timeout, }: {
|
|
72
|
+
personalizeInfo: PersonalizeInfo;
|
|
73
|
+
params: ExperienceParams;
|
|
74
|
+
language: string;
|
|
75
|
+
timeout?: number;
|
|
76
|
+
}, request: NextRequest): Promise<{
|
|
77
|
+
variantId: string;
|
|
78
|
+
}>;
|
|
74
79
|
protected getExperienceParams(req: NextRequest): ExperienceParams;
|
|
75
80
|
protected excludeRoute(pathname: string): boolean | undefined;
|
|
76
81
|
private handler;
|