@sitecore-content-sdk/nextjs 2.0.0-canary.8 → 2.0.0
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/dist/cjs/cache/page-params.js +30 -0
- package/dist/cjs/client/sitecore-nextjs-client.js +57 -94
- package/dist/cjs/components/BYOCWrapper.js +3 -12
- package/dist/cjs/components/DesignLibrary/DesignLibraryApp.js +31 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryClientEvents.js +139 -0
- package/dist/cjs/components/DesignLibrary/DesignLibraryServer.js +221 -0
- package/dist/cjs/components/DesignLibrary/index.js +5 -0
- package/dist/cjs/components/DesignLibrary/models.js +2 -0
- package/dist/cjs/components/FEaaSWrapper.js +3 -12
- package/dist/cjs/editing/editing-config-middleware.js +2 -11
- package/dist/cjs/editing/editing-render-middleware.js +3 -12
- package/dist/cjs/editing/feaas-render-middleware.js +2 -11
- package/dist/cjs/editing/utils.js +3 -12
- package/dist/cjs/index.js +12 -2
- package/dist/cjs/initialization/proxy/analytics-adapter.js +71 -0
- package/dist/cjs/initialization/proxy/personalize-adapter.js +72 -0
- package/dist/cjs/middleware/robots-middleware.js +16 -25
- package/dist/cjs/middleware/sitemap-middleware.js +19 -28
- package/dist/cjs/monitoring/healthcheck-middleware.js +2 -11
- package/dist/cjs/proxy/locale-proxy.js +2 -11
- package/dist/cjs/proxy/multisite-proxy.js +2 -11
- package/dist/cjs/proxy/personalize-proxy.js +40 -36
- package/dist/cjs/proxy/proxy.js +3 -12
- package/dist/cjs/proxy/redirects-proxy.js +58 -69
- package/dist/cjs/route-handler/editing-config-route-handler.js +4 -13
- package/dist/cjs/route-handler/editing-render-route-handler.js +17 -28
- package/dist/cjs/route-handler/robots-route-handler.js +5 -14
- package/dist/cjs/route-handler/sitemap-route-handler.js +5 -14
- package/dist/cjs/server-actions/update-server-component-action.js +56 -0
- package/dist/cjs/services/component-props-service.js +63 -80
- package/dist/esm/cache/page-params.js +25 -0
- package/dist/esm/client/sitecore-nextjs-client.js +57 -94
- package/dist/esm/components/BYOCWrapper.js +3 -12
- package/dist/esm/components/DesignLibrary/DesignLibraryApp.js +24 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryClientEvents.js +100 -0
- package/dist/esm/components/DesignLibrary/DesignLibraryServer.js +178 -0
- package/dist/esm/components/DesignLibrary/index.js +1 -0
- package/dist/esm/components/DesignLibrary/models.js +1 -0
- package/dist/esm/components/FEaaSWrapper.js +3 -12
- package/dist/esm/editing/editing-config-middleware.js +2 -11
- package/dist/esm/editing/editing-render-middleware.js +3 -12
- package/dist/esm/editing/feaas-render-middleware.js +2 -11
- package/dist/esm/editing/utils.js +3 -12
- package/dist/esm/index.js +6 -1
- package/dist/esm/initialization/proxy/analytics-adapter.js +66 -0
- package/dist/esm/initialization/proxy/personalize-adapter.js +69 -0
- package/dist/esm/middleware/robots-middleware.js +16 -25
- package/dist/esm/middleware/sitemap-middleware.js +19 -28
- package/dist/esm/monitoring/healthcheck-middleware.js +2 -11
- package/dist/esm/proxy/locale-proxy.js +2 -11
- package/dist/esm/proxy/multisite-proxy.js +2 -11
- package/dist/esm/proxy/personalize-proxy.js +40 -36
- package/dist/esm/proxy/proxy.js +3 -12
- package/dist/esm/proxy/redirects-proxy.js +58 -69
- package/dist/esm/route-handler/editing-config-route-handler.js +4 -13
- package/dist/esm/route-handler/editing-render-route-handler.js +17 -28
- package/dist/esm/route-handler/robots-route-handler.js +5 -14
- package/dist/esm/route-handler/sitemap-route-handler.js +5 -14
- package/dist/esm/server-actions/update-server-component-action.js +52 -0
- package/dist/esm/services/component-props-service.js +63 -80
- package/package.json +10 -10
- package/types/cache/page-params.d.ts +30 -0
- package/types/cache/page-params.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts +14 -0
- package/types/components/DesignLibrary/DesignLibraryApp.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts +21 -0
- package/types/components/DesignLibrary/DesignLibraryClientEvents.d.ts.map +1 -0
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts +38 -0
- package/types/components/DesignLibrary/DesignLibraryServer.d.ts.map +1 -0
- package/types/components/DesignLibrary/index.d.ts +2 -0
- package/types/components/DesignLibrary/index.d.ts.map +1 -0
- package/types/components/DesignLibrary/models.d.ts +60 -0
- package/types/components/DesignLibrary/models.d.ts.map +1 -0
- package/types/index.d.ts +9 -1
- package/types/index.d.ts.map +1 -1
- package/types/initialization/proxy/analytics-adapter.d.ts +30 -0
- package/types/initialization/proxy/analytics-adapter.d.ts.map +1 -0
- package/types/initialization/proxy/personalize-adapter.d.ts +23 -0
- package/types/initialization/proxy/personalize-adapter.d.ts.map +1 -0
- package/types/middleware/robots-middleware.d.ts.map +1 -1
- package/types/middleware/sitemap-middleware.d.ts.map +1 -1
- package/types/proxy/personalize-proxy.d.ts +2 -1
- package/types/proxy/personalize-proxy.d.ts.map +1 -1
- package/types/server-actions/update-server-component-action.d.ts +63 -0
- package/types/server-actions/update-server-component-action.d.ts.map +1 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClientId = void 0;
|
|
4
|
+
exports.analyticsProxyAdapter = analyticsProxyAdapter;
|
|
5
|
+
const internal_1 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
6
|
+
const internal_2 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
7
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
|
+
/**
|
|
9
|
+
* Creates a proxy-based analytics adapter that reads and writes the visitor ID
|
|
10
|
+
* using cookies and can resolve a new client ID from the Edge proxy when needed.
|
|
11
|
+
* The adapter also provides access to the current URL search parameters.
|
|
12
|
+
* @param {NextRequest} request - The Next.js request object.
|
|
13
|
+
* @param {NextResponse} response - The Next.js response object.
|
|
14
|
+
* @returns {AnalyticsProxyAdapter} The analytics proxy adapter.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
function analyticsProxyAdapter(request, response) {
|
|
18
|
+
return {
|
|
19
|
+
type: 'proxy',
|
|
20
|
+
getClientId: () => {
|
|
21
|
+
return (0, exports.getClientId)(request);
|
|
22
|
+
},
|
|
23
|
+
setClientId: async () => {
|
|
24
|
+
var _a;
|
|
25
|
+
const coreConfig = (0, core_1.getCoreContext)().config;
|
|
26
|
+
const analyticsOptions = (0, internal_2.getAnalyticsPlugin)().options;
|
|
27
|
+
const cookieOptions = analyticsOptions.cookies;
|
|
28
|
+
const clientIdCookieName = cookieOptions.name;
|
|
29
|
+
const legacyClientIdCookieName = `${internal_1.COOKIE_NAME_PREFIX}${coreConfig.contextId}`;
|
|
30
|
+
const cookieAttributes = (0, internal_1.getDefaultCookieAttributes)(cookieOptions.expiryDays, cookieOptions.domain);
|
|
31
|
+
const legacyClientIdCookie = (_a = request.cookies.get(legacyClientIdCookieName)) === null || _a === void 0 ? void 0 : _a.value;
|
|
32
|
+
if (legacyClientIdCookie) {
|
|
33
|
+
request.cookies.set(clientIdCookieName, legacyClientIdCookie);
|
|
34
|
+
response.cookies.set(clientIdCookieName, legacyClientIdCookie, Object.assign(Object.assign({}, cookieAttributes), { sameSite: 'none' }));
|
|
35
|
+
request.cookies.delete(legacyClientIdCookieName);
|
|
36
|
+
response.cookies.delete(legacyClientIdCookieName);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const clientIdCookie = (0, exports.getClientId)(request);
|
|
40
|
+
let newClientIdCookieValue;
|
|
41
|
+
if (!clientIdCookie) {
|
|
42
|
+
const cookieValues = await (0, internal_1.fetchClientIdFromEdgeProxy)(coreConfig.edgeUrl, coreConfig.contextId, analyticsOptions.timeout);
|
|
43
|
+
newClientIdCookieValue = cookieValues.clientId;
|
|
44
|
+
analyticsOptions.visitorIds = cookieValues;
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
newClientIdCookieValue = clientIdCookie;
|
|
48
|
+
if (!clientIdCookie)
|
|
49
|
+
request.cookies.set(clientIdCookieName, newClientIdCookieValue);
|
|
50
|
+
const attributes = (0, internal_1.getDefaultCookieAttributes)(cookieOptions.expiryDays, cookieOptions.domain);
|
|
51
|
+
response.cookies.set(clientIdCookieName, newClientIdCookieValue, Object.assign(Object.assign({}, attributes), { sameSite: 'none' }));
|
|
52
|
+
},
|
|
53
|
+
location: {
|
|
54
|
+
getSearchParams: () => {
|
|
55
|
+
return request.nextUrl.searchParams.toString();
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the client ID from the request cookies.
|
|
62
|
+
* @param {NextRequest} request
|
|
63
|
+
* @returns {string | null} The client ID or null if not found.
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
const getClientId = (request) => {
|
|
67
|
+
var _a;
|
|
68
|
+
const clientIdCookieName = (0, internal_2.getAnalyticsPlugin)().options.cookies.name;
|
|
69
|
+
return ((_a = request.cookies.get(clientIdCookieName)) === null || _a === void 0 ? void 0 : _a.value) || null;
|
|
70
|
+
};
|
|
71
|
+
exports.getClientId = getClientId;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.personalizeProxyAdapter = personalizeProxyAdapter;
|
|
4
|
+
const internal_1 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
5
|
+
const internal_2 = require("@sitecore-content-sdk/analytics-core/internal");
|
|
6
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
7
|
+
const internal_3 = require("@sitecore-content-sdk/personalize/internal");
|
|
8
|
+
const analytics_adapter_1 = require("./analytics-adapter");
|
|
9
|
+
/**
|
|
10
|
+
* Creates a proxy-based personalize adapter that reads and writes the profile ID
|
|
11
|
+
* using cookies and can resolve a new profile ID from the Edge proxy when needed.
|
|
12
|
+
* The adapter also provides access user agent from the request headers.
|
|
13
|
+
* @param {NextRequest} request - The HTTP request object.
|
|
14
|
+
* @param {NextResponse} response - The HTTP response object.
|
|
15
|
+
* @returns {PersonalizeProxyAdapter} The personalize proxy adapter.
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
function personalizeProxyAdapter(request, response) {
|
|
19
|
+
return {
|
|
20
|
+
type: 'proxy',
|
|
21
|
+
getUserAgent: () => request.headers.get('user-agent') || undefined,
|
|
22
|
+
getProfileId: () => {
|
|
23
|
+
return getProfileId(request);
|
|
24
|
+
},
|
|
25
|
+
setProfileId: async () => {
|
|
26
|
+
var _a;
|
|
27
|
+
const coreConfig = (0, core_1.getCoreContext)().config;
|
|
28
|
+
const cookieOptions = (0, internal_2.getAnalyticsPlugin)().options.cookies;
|
|
29
|
+
const personalizePlugin = (0, internal_3.getPersonalizePlugin)();
|
|
30
|
+
const profileIdCookieName = personalizePlugin.options.cookies.name;
|
|
31
|
+
const cookieAttributes = (0, internal_1.getDefaultCookieAttributes)(cookieOptions.expiryDays, cookieOptions.domain);
|
|
32
|
+
const legacyProfileIdCookieName = `${internal_1.COOKIE_NAME_PREFIX}${coreConfig.contextId}_personalize`;
|
|
33
|
+
const legacyProfileIdCookie = (_a = request.cookies.get(legacyProfileIdCookieName)) === null || _a === void 0 ? void 0 : _a.value;
|
|
34
|
+
if (legacyProfileIdCookie) {
|
|
35
|
+
request.cookies.set(profileIdCookieName, legacyProfileIdCookie);
|
|
36
|
+
response.cookies.set(profileIdCookieName, legacyProfileIdCookie, Object.assign(Object.assign({}, cookieAttributes), { sameSite: 'none' }));
|
|
37
|
+
request.cookies.delete(legacyProfileIdCookieName);
|
|
38
|
+
response.cookies.delete(legacyProfileIdCookieName);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const cookiesValuesFromEdgeServer = (0, internal_2.getAnalyticsPlugin)().options.visitorIds;
|
|
42
|
+
const profileIdCookie = getProfileId(request);
|
|
43
|
+
const clientIdCookie = (0, analytics_adapter_1.getClientId)(request);
|
|
44
|
+
let newProfileIdCookieValue;
|
|
45
|
+
if (profileIdCookie)
|
|
46
|
+
newProfileIdCookieValue = profileIdCookie;
|
|
47
|
+
else if (cookiesValuesFromEdgeServer === null || cookiesValuesFromEdgeServer === void 0 ? void 0 : cookiesValuesFromEdgeServer.profileId)
|
|
48
|
+
newProfileIdCookieValue = cookiesValuesFromEdgeServer.profileId;
|
|
49
|
+
else if (clientIdCookie) {
|
|
50
|
+
const profileIdCookieValueFromEdgeProxy = await (0, internal_3.fetchProfileIdFromEdgeProxy)(clientIdCookie, coreConfig.contextId, coreConfig.edgeUrl);
|
|
51
|
+
newProfileIdCookieValue = profileIdCookieValueFromEdgeProxy;
|
|
52
|
+
}
|
|
53
|
+
else
|
|
54
|
+
return;
|
|
55
|
+
if (!profileIdCookie)
|
|
56
|
+
request.cookies.set(profileIdCookieName, newProfileIdCookieValue);
|
|
57
|
+
const attributes = (0, internal_1.getDefaultCookieAttributes)(cookieOptions.expiryDays, cookieOptions.domain);
|
|
58
|
+
response.cookies.set(profileIdCookieName, newProfileIdCookieValue, Object.assign(Object.assign({}, attributes), { sameSite: 'none' }));
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Retrieves the profile ID from request cookies.
|
|
64
|
+
* @param {NextRequest} request
|
|
65
|
+
* @returns {string | null} The profile ID or null if not found.
|
|
66
|
+
* @internal
|
|
67
|
+
*/
|
|
68
|
+
function getProfileId(request) {
|
|
69
|
+
var _a;
|
|
70
|
+
const profileIdCookieName = (0, internal_3.getPersonalizePlugin)().options.cookies.name;
|
|
71
|
+
return ((_a = request.cookies.get(profileIdCookieName)) === null || _a === void 0 ? void 0 : _a.value) || null;
|
|
72
|
+
}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.RobotsMiddleware = void 0;
|
|
4
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
13
5
|
const site_1 = require("../site");
|
|
6
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
14
7
|
/**
|
|
15
8
|
* Middleware for handling robots.txt requests in a Next.js application.
|
|
16
9
|
* @public
|
|
@@ -23,23 +16,21 @@ class RobotsMiddleware {
|
|
|
23
16
|
getHandler() {
|
|
24
17
|
return this.handler.bind(this);
|
|
25
18
|
}
|
|
26
|
-
handler(req, res) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return res.status(404).send('User-agent: *\nDisallow: /');
|
|
36
|
-
}
|
|
37
|
-
res.status(200).send(robotsContent);
|
|
19
|
+
async handler(req, res) {
|
|
20
|
+
var _a;
|
|
21
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
22
|
+
const hostName = req.headers['x-forwarded-host'] || ((_a = req.headers.host) === null || _a === void 0 ? void 0 : _a.split(':')[0]) || 'localhost';
|
|
23
|
+
const site = this.siteResolver.getByHost(hostName);
|
|
24
|
+
try {
|
|
25
|
+
const robotsContent = await this.client.getRobots(site.name);
|
|
26
|
+
if (!robotsContent) {
|
|
27
|
+
return res.status(404).send('User-agent: *\nDisallow: /');
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
res.status(200).send(robotsContent);
|
|
30
|
+
}
|
|
31
|
+
catch (_b) {
|
|
32
|
+
res.status(500).send(`Internal Server Error. ${ERROR_MESSAGES.CONTACT_SUPPORT}`);
|
|
33
|
+
}
|
|
43
34
|
}
|
|
44
35
|
}
|
|
45
36
|
exports.RobotsMiddleware = RobotsMiddleware;
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SitemapMiddleware = void 0;
|
|
4
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
13
5
|
const site_1 = require("../site");
|
|
6
|
+
const { ERROR_MESSAGES } = core_1.constants;
|
|
14
7
|
/**
|
|
15
8
|
* Middleware for handling sitemap requests in a Next.js application.
|
|
16
9
|
* Encapsulates all HTTP-related logic for sitemap generation and delivery.
|
|
@@ -24,27 +17,25 @@ class SitemapMiddleware {
|
|
|
24
17
|
getHandler() {
|
|
25
18
|
return this.handler.bind(this);
|
|
26
19
|
}
|
|
27
|
-
handler(req, res) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
20
|
+
async handler(req, res) {
|
|
21
|
+
const id = Array.isArray(req.query.id) ? req.query.id[0] : req.query.id;
|
|
22
|
+
const reqHost = req.headers['x-forwarded-host'] || req.headers.host || '';
|
|
23
|
+
const reqProtocol = req.headers['x-forwarded-proto'] || 'https';
|
|
24
|
+
const site = this.siteResolver.getByHost(reqHost);
|
|
25
|
+
const options = { reqHost, reqProtocol, id, siteName: site.name };
|
|
26
|
+
try {
|
|
27
|
+
const xmlContent = await this.client.getSiteMap(options);
|
|
28
|
+
res.setHeader('Content-Type', 'text/xml;charset=utf-8');
|
|
29
|
+
res.send(xmlContent);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
if (error instanceof Error && error.message === 'REDIRECT_404') {
|
|
33
|
+
res.redirect('/404');
|
|
38
34
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
res.redirect('/404');
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
res.status(500).send('Internal Server Error');
|
|
45
|
-
}
|
|
35
|
+
else {
|
|
36
|
+
res.status(500).send(`Internal Server Error. ${ERROR_MESSAGES.CONTACT_SUPPORT}`);
|
|
46
37
|
}
|
|
47
|
-
}
|
|
38
|
+
}
|
|
48
39
|
}
|
|
49
40
|
}
|
|
50
41
|
exports.SitemapMiddleware = SitemapMiddleware;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.HealthcheckMiddleware = void 0;
|
|
13
4
|
/**
|
|
@@ -16,9 +7,9 @@ exports.HealthcheckMiddleware = void 0;
|
|
|
16
7
|
*/
|
|
17
8
|
class HealthcheckMiddleware {
|
|
18
9
|
constructor() {
|
|
19
|
-
this.handler = (_req, res) =>
|
|
10
|
+
this.handler = async (_req, res) => {
|
|
20
11
|
res.status(200).send('Healthy');
|
|
21
|
-
}
|
|
12
|
+
};
|
|
22
13
|
}
|
|
23
14
|
/**
|
|
24
15
|
* Gets the Next.js API route handler
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
5
|
};
|
|
@@ -30,7 +21,7 @@ class LocaleProxy extends proxy_1.ProxyBase {
|
|
|
30
21
|
constructor(config) {
|
|
31
22
|
super(config);
|
|
32
23
|
this.config = config;
|
|
33
|
-
this.handle = (req, res) =>
|
|
24
|
+
this.handle = async (req, res) => {
|
|
34
25
|
try {
|
|
35
26
|
const { pathname } = req.nextUrl;
|
|
36
27
|
const localeFromPath = this.getLocaleFromPath(pathname);
|
|
@@ -67,7 +58,7 @@ class LocaleProxy extends proxy_1.ProxyBase {
|
|
|
67
58
|
console.log(error);
|
|
68
59
|
return res;
|
|
69
60
|
}
|
|
70
|
-
}
|
|
61
|
+
};
|
|
71
62
|
}
|
|
72
63
|
disabled(req, res) {
|
|
73
64
|
// ignore files
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
13
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
5
|
};
|
|
@@ -29,7 +20,7 @@ class MultisiteProxy extends proxy_1.ProxyBase {
|
|
|
29
20
|
constructor(config) {
|
|
30
21
|
super(config);
|
|
31
22
|
this.config = config;
|
|
32
|
-
this.handle = (req, res) =>
|
|
23
|
+
this.handle = async (req, res) => {
|
|
33
24
|
var _a, _b, _c;
|
|
34
25
|
try {
|
|
35
26
|
// Path can be rewritten by previously executed proxy
|
|
@@ -107,7 +98,7 @@ class MultisiteProxy extends proxy_1.ProxyBase {
|
|
|
107
98
|
console.log(error);
|
|
108
99
|
return res;
|
|
109
100
|
}
|
|
110
|
-
}
|
|
101
|
+
};
|
|
111
102
|
}
|
|
112
103
|
disabled(req, res) {
|
|
113
104
|
// ignore files
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -15,9 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
6
|
exports.PersonalizeProxy = void 0;
|
|
16
7
|
const personalize_1 = require("@sitecore-content-sdk/content/personalize");
|
|
17
8
|
const proxy_1 = require("./proxy");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
9
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
10
|
+
const personalize_2 = require("@sitecore-content-sdk/personalize");
|
|
20
11
|
const debug_1 = __importDefault(require("../debug"));
|
|
12
|
+
const analytics_core_1 = require("@sitecore-content-sdk/analytics-core");
|
|
13
|
+
const analytics_adapter_1 = require("../initialization/proxy/analytics-adapter");
|
|
14
|
+
const personalize_3 = require("@sitecore-content-sdk/personalize");
|
|
15
|
+
const personalize_adapter_1 = require("../initialization/proxy/personalize-adapter");
|
|
21
16
|
/**
|
|
22
17
|
* Proxy / handler to support Sitecore Personalize
|
|
23
18
|
* @public
|
|
@@ -30,7 +25,7 @@ class PersonalizeProxy extends proxy_1.ProxyBase {
|
|
|
30
25
|
var _a;
|
|
31
26
|
super(config);
|
|
32
27
|
this.config = config;
|
|
33
|
-
this.handle = (req, res) =>
|
|
28
|
+
this.handle = async (req, res) => {
|
|
34
29
|
if (!this.config.enabled) {
|
|
35
30
|
debug_1.default.personalize('skipped (personalize proxy is disabled globally)');
|
|
36
31
|
return res;
|
|
@@ -42,7 +37,7 @@ class PersonalizeProxy extends proxy_1.ProxyBase {
|
|
|
42
37
|
const startTimestamp = Date.now();
|
|
43
38
|
const cdpTimeout = this.config.cdpTimeout;
|
|
44
39
|
const geo = this.config.extractGeoDataCb
|
|
45
|
-
?
|
|
40
|
+
? await this.config.extractGeoDataCb(req)
|
|
46
41
|
: undefined;
|
|
47
42
|
debug_1.default.personalize('personalize proxy start: %o', Object.assign(Object.assign({ pathname,
|
|
48
43
|
language,
|
|
@@ -63,7 +58,7 @@ class PersonalizeProxy extends proxy_1.ProxyBase {
|
|
|
63
58
|
if (!this.personalizeService) {
|
|
64
59
|
return res;
|
|
65
60
|
}
|
|
66
|
-
const personalizeInfo =
|
|
61
|
+
const personalizeInfo = await this.personalizeService.getPersonalizeInfo(pathname, language, site.name);
|
|
67
62
|
if (!personalizeInfo) {
|
|
68
63
|
// Likely an invalid route / language
|
|
69
64
|
debug_1.default.personalize('skipped (personalize info not found)');
|
|
@@ -83,7 +78,7 @@ class PersonalizeProxy extends proxy_1.ProxyBase {
|
|
|
83
78
|
res.headers.set('Cache-Control', 'no-store, must-revalidate');
|
|
84
79
|
return res;
|
|
85
80
|
}
|
|
86
|
-
|
|
81
|
+
await this.initPersonalizeServer({
|
|
87
82
|
hostname,
|
|
88
83
|
siteName: site.name,
|
|
89
84
|
request: req,
|
|
@@ -92,8 +87,8 @@ class PersonalizeProxy extends proxy_1.ProxyBase {
|
|
|
92
87
|
const params = this.getExperienceParams(req);
|
|
93
88
|
const executions = this.getPersonalizeExecutions(personalizeInfo, language);
|
|
94
89
|
const identifiedVariantIds = [];
|
|
95
|
-
|
|
96
|
-
language, timeout: cdpTimeout }, (geo && { geo }))
|
|
90
|
+
await Promise.all(executions.map((execution) => this.personalize(Object.assign({ friendlyId: execution.friendlyId, variantIds: execution.variantIds, params,
|
|
91
|
+
language, timeout: cdpTimeout }, (geo && { geo }))).then((personalization) => {
|
|
97
92
|
const variantId = personalization.variantId;
|
|
98
93
|
if (variantId) {
|
|
99
94
|
if (!execution.variantIds.includes(variantId)) {
|
|
@@ -127,7 +122,7 @@ class PersonalizeProxy extends proxy_1.ProxyBase {
|
|
|
127
122
|
console.log(error);
|
|
128
123
|
return res;
|
|
129
124
|
}
|
|
130
|
-
}
|
|
125
|
+
};
|
|
131
126
|
// Validate edge config is present - personalize requires Edge platform
|
|
132
127
|
if (!this.config.contextId && !this.config.clientContextId) {
|
|
133
128
|
console.warn('[PersonalizeProxy] Personalize proxy requires Edge configuration (contextId/clientContextId). ' +
|
|
@@ -175,27 +170,36 @@ class PersonalizeProxy extends proxy_1.ProxyBase {
|
|
|
175
170
|
utm,
|
|
176
171
|
};
|
|
177
172
|
}
|
|
178
|
-
initPersonalizeServer(
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
173
|
+
async initPersonalizeServer({ hostname, siteName, request, response, }) {
|
|
174
|
+
await (0, core_1.initContentSdk)({
|
|
175
|
+
config: {
|
|
176
|
+
contextId: this.config.contextId,
|
|
177
|
+
edgeUrl: this.config.edgeUrl,
|
|
183
178
|
siteName,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
179
|
+
},
|
|
180
|
+
plugins: [
|
|
181
|
+
(0, analytics_core_1.analyticsPlugin)({
|
|
182
|
+
options: {
|
|
183
|
+
enableCookie: true,
|
|
184
|
+
cookieDomain: hostname,
|
|
185
|
+
},
|
|
186
|
+
adapter: (0, analytics_adapter_1.analyticsProxyAdapter)(request, response),
|
|
187
|
+
}),
|
|
188
|
+
(0, personalize_3.personalizeServerPlugin)({
|
|
189
|
+
options: {
|
|
190
|
+
enablePersonalizeCookie: true,
|
|
191
|
+
},
|
|
192
|
+
adapter: (0, personalize_adapter_1.personalizeProxyAdapter)(request, response),
|
|
193
|
+
}),
|
|
194
|
+
],
|
|
189
195
|
});
|
|
190
196
|
}
|
|
191
|
-
personalize(
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
language, pageVariantIds: variantIds }, (geo && { geo })), { timeout }));
|
|
198
|
-
});
|
|
197
|
+
async personalize({ params, friendlyId, language, timeout, variantIds, geo, }) {
|
|
198
|
+
var _a;
|
|
199
|
+
debug_1.default.personalize('executing experience for %s %o', friendlyId, params);
|
|
200
|
+
return (await (0, personalize_2.personalize)(Object.assign({ channel: this.config.channel || 'WEB', currency: (_a = this.config.currency) !== null && _a !== void 0 ? _a : 'USD', friendlyId,
|
|
201
|
+
params,
|
|
202
|
+
language, pageVariantIds: variantIds }, (geo && { geo })), { timeout }));
|
|
199
203
|
}
|
|
200
204
|
/**
|
|
201
205
|
* Aggregates personalize executions based on the provided route personalize information and language
|
package/dist/cjs/proxy/proxy.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -185,14 +176,14 @@ const defineProxy = (...proxies) => {
|
|
|
185
176
|
* @param {NextRequest} req request
|
|
186
177
|
* @param {NextResponse} [res] response
|
|
187
178
|
*/
|
|
188
|
-
exec: (req, res) =>
|
|
179
|
+
exec: async (req, res) => {
|
|
189
180
|
const response = res || server_1.NextResponse.next();
|
|
190
181
|
debug_1.default.common('proxy start');
|
|
191
182
|
const start = Date.now();
|
|
192
|
-
const proxyResponse =
|
|
183
|
+
const proxyResponse = await proxies.reduce((p, proxy) => p.then((res) => proxy.handle(req, res)), Promise.resolve(response));
|
|
193
184
|
debug_1.default.common('proxy end in %dms', Date.now() - start);
|
|
194
185
|
return proxyResponse;
|
|
195
|
-
}
|
|
186
|
+
},
|
|
196
187
|
};
|
|
197
188
|
};
|
|
198
189
|
exports.defineProxy = defineProxy;
|