@sitecore-cloudsdk/personalize
Advanced tools
Comparing version 0.4.4 to 0.5.0-rc.0
{ | ||
"name": "@sitecore-cloudsdk/personalize", | ||
"version": "0.4.4", | ||
"version": "0.5.0-rc.0", | ||
"license": "Apache-2.0", | ||
@@ -19,5 +19,5 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html", | ||
"dependencies": { | ||
"@sitecore-cloudsdk/core": "^0.4.4", | ||
"@sitecore-cloudsdk/events": "^0.4.4", | ||
"@sitecore-cloudsdk/utils": "^0.4.4" | ||
"@sitecore-cloudsdk/core": "^0.5.0-rc.0", | ||
"@sitecore-cloudsdk/events": "^0.5.0-rc.0", | ||
"@sitecore-cloudsdk/utils": "^0.5.0-rc.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
@@ -1,2 +0,1 @@ | ||
export { init } from './lib/init/client/initializer'; | ||
export { personalize } from './lib/personalization/personalize'; | ||
@@ -3,0 +2,0 @@ export { PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from './lib/consts'; |
"use strict"; | ||
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PERSONALIZE_NAMESPACE = exports.PACKAGE_VERSION = exports.personalize = exports.init = void 0; | ||
var initializer_1 = require("./lib/init/client/initializer"); | ||
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return initializer_1.init; } }); | ||
exports.PERSONALIZE_NAMESPACE = exports.PACKAGE_VERSION = exports.personalize = void 0; | ||
var personalize_1 = require("./lib/personalization/personalize"); | ||
@@ -8,0 +6,0 @@ Object.defineProperty(exports, "personalize", { enumerable: true, get: function () { return personalize_1.personalize; } }); |
@@ -7,5 +7,2 @@ export declare const PERSONALIZE_NAMESPACE: "sitecore-cloudsdk:personalize"; | ||
IE_0001 = "[IE-0001] You are trying to run a browser-side function on the server side. On the server side, run the server-side equivalent of the function, available in \"server\" modules.", | ||
IE_0006 = "[IE-0006] You must first initialize the \"personalize/browser\" module. Run the \"init\" function.", | ||
IE_0007 = "[IE-0007] You must first initialize the \"personalize/server\" module. Run the \"init\" function.", | ||
IE_0008 = "[IE-0008] You must first initialize the \"core\" package. Run the \"init\" function.", | ||
IE_0016 = "[IE-0016] You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/browser\" and import \"@sitecore-cloudsdk/personalize/browser\". Then, run \"CloudSDK().addPersonalize().initialize()\".", | ||
@@ -12,0 +9,0 @@ IE_0017 = "[IE-0017] You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/server\", and import \"@sitecore-cloudsdk/personalize/server\". Then, run \"await CloudSDK().addPersonalize().initialize()\".", |
@@ -18,5 +18,2 @@ "use strict"; | ||
ErrorMessages["IE_0001"] = "[IE-0001] You are trying to run a browser-side function on the server side. On the server side, run the server-side equivalent of the function, available in \"server\" modules."; | ||
ErrorMessages["IE_0006"] = "[IE-0006] You must first initialize the \"personalize/browser\" module. Run the \"init\" function."; | ||
ErrorMessages["IE_0007"] = "[IE-0007] You must first initialize the \"personalize/server\" module. Run the \"init\" function."; | ||
ErrorMessages["IE_0008"] = "[IE-0008] You must first initialize the \"core\" package. Run the \"init\" function."; | ||
// eslint-disable-next-line max-len | ||
@@ -23,0 +20,0 @@ ErrorMessages["IE_0016"] = "[IE-0016] You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/browser\" and import \"@sitecore-cloudsdk/personalize/browser\". Then, run \"CloudSDK().addPersonalize().initialize()\"."; |
@@ -1,3 +0,3 @@ | ||
import type { Settings } from '@sitecore-cloudsdk/core/browser'; | ||
import { type Settings } from '@sitecore-cloudsdk/core/browser'; | ||
import type { PersonalizeSettings } from './interfaces'; | ||
export declare function createPersonalizeCookie(personalizeSettings: PersonalizeSettings, cloudSDKSettings: Settings): Promise<void | boolean>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createPersonalizeCookie = void 0; | ||
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
const browser_1 = require("@sitecore-cloudsdk/core/browser"); | ||
const internal_1 = require("@sitecore-cloudsdk/core/internal"); | ||
@@ -16,3 +18,3 @@ const utils_1 = require("@sitecore-cloudsdk/utils"); | ||
else if (browserIdCookieValue) { | ||
const guestIdCookieValue = await (0, internal_1.getGuestId)(browserIdCookieValue, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl); | ||
const guestIdCookieValue = await (0, browser_1.getGuestId)(); | ||
document.cookie = (0, utils_1.createCookieString)(personalizeSettings.cookieSettings.name.guestId, guestIdCookieValue, attributes); | ||
@@ -19,0 +21,0 @@ } |
@@ -26,1 +26,5 @@ import { CloudSDKBrowserInitializer } from '@sitecore-cloudsdk/core/browser'; | ||
} | ||
/** | ||
* A function that handles the async browser init logic. Throws an error or awaits the promise. | ||
*/ | ||
export declare function awaitInit(): Promise<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addPersonalize = exports.sideEffects = void 0; | ||
exports.awaitInit = exports.addPersonalize = exports.sideEffects = void 0; | ||
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
@@ -66,1 +66,11 @@ const browser_1 = require("@sitecore-cloudsdk/core/browser"); | ||
browser_1.CloudSDKBrowserInitializer.prototype.addPersonalize = addPersonalize; | ||
/** | ||
* A function that handles the async browser init logic. Throws an error or awaits the promise. | ||
*/ | ||
async function awaitInit() { | ||
const initState = (0, internal_1.getEnabledPackageBrowser)(consts_1.PACKAGE_NAME)?.initState; | ||
if (!initState) | ||
throw new Error(consts_1.ErrorMessages.IE_0016); | ||
await initState; | ||
} | ||
exports.awaitInit = awaitInit; |
@@ -20,3 +20,3 @@ "use strict"; | ||
else if (browserIdCookie) { | ||
const guestIdCookieValueFromEdgeProxy = await (0, internal_1.getGuestId)(browserIdCookie.value, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl); | ||
const guestIdCookieValueFromEdgeProxy = await (0, internal_1.getGuestIdServer)(browserIdCookie.value); | ||
guestIdCookieString = (0, utils_1.createCookieString)(settings.cookieSettings.name.guestId, guestIdCookieValueFromEdgeProxy, defaultCookieAttributes); | ||
@@ -23,0 +23,0 @@ } |
@@ -19,3 +19,3 @@ "use strict"; | ||
else if (browserIdCookieValue) { | ||
const guestIdCookieValueFromEdgeProxy = await (0, internal_1.getGuestId)(browserIdCookieValue, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl); | ||
const guestIdCookieValueFromEdgeProxy = await (0, internal_1.getGuestIdServer)(browserIdCookieValue); | ||
guestIdValue = guestIdCookieValueFromEdgeProxy; | ||
@@ -22,0 +22,0 @@ } |
@@ -16,1 +16,2 @@ import { CloudSDKServerInitializer } from '@sitecore-cloudsdk/core/server'; | ||
} | ||
export declare function verifyPersonalizePackageExistence(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.addPersonalize = exports.sideEffects = void 0; | ||
exports.verifyPersonalizePackageExistence = exports.addPersonalize = exports.sideEffects = void 0; | ||
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
@@ -39,1 +39,6 @@ const internal_1 = require("@sitecore-cloudsdk/core/internal"); | ||
server_1.CloudSDKServerInitializer.prototype.addPersonalize = addPersonalize; | ||
function verifyPersonalizePackageExistence() { | ||
if (!(0, internal_1.getEnabledPackageServer)(consts_1.PACKAGE_NAME)) | ||
throw Error(consts_1.ErrorMessages.IE_0017); | ||
} | ||
exports.verifyPersonalizePackageExistence = verifyPersonalizePackageExistence; |
@@ -8,3 +8,3 @@ "use strict"; | ||
const consts_1 = require("../consts"); | ||
const initializer_1 = require("../init/client/initializer"); | ||
const initializer_1 = require("../initializer/browser/initializer"); | ||
const personalizer_1 = require("./personalizer"); | ||
@@ -19,20 +19,10 @@ /** | ||
await (0, initializer_1.awaitInit)(); | ||
if ((0, internal_1.getEnabledPackageBrowser)(consts_1.PACKAGE_NAME)?.initState) { | ||
const cloudSDKSettings = (0, internal_1.getCloudSDKSettingsBrowser)(); | ||
const personalizeSettings = (0, internal_1.getEnabledPackageBrowser)(consts_1.PACKAGE_NAME)?.settings; | ||
const browserId = (0, utils_1.getCookieValueClientSide)(cloudSDKSettings.cookieSettings.name.browserId); | ||
const guestId = (0, utils_1.getCookieValueClientSide)(personalizeSettings.cookieSettings.name.guestId); | ||
return new personalizer_1.Personalizer(browserId, guestId).getInteractiveExperienceData(personalizeData, cloudSDKSettings, window.location.search, { | ||
timeout: opts?.timeout | ||
}); | ||
} | ||
else { | ||
const settings = (0, internal_1.handleGetSettingsError)(internal_1.getSettings, consts_1.ErrorMessages.IE_0016); | ||
const browserId = (0, internal_1.getBrowserId)(); | ||
const guestId = (0, utils_1.getCookieValueClientSide)(settings.cookieSettings.cookieNames.guestId); | ||
return new personalizer_1.Personalizer(browserId, guestId).getInteractiveExperienceData(personalizeData, settings, window.location.search, { | ||
timeout: opts?.timeout | ||
}); | ||
} | ||
const cloudSDKSettings = (0, internal_1.getCloudSDKSettingsBrowser)(); | ||
const personalizeSettings = (0, internal_1.getEnabledPackageBrowser)(consts_1.PACKAGE_NAME)?.settings; | ||
const browserId = (0, utils_1.getCookieValueClientSide)(cloudSDKSettings.cookieSettings.name.browserId); | ||
const guestId = (0, utils_1.getCookieValueClientSide)(personalizeSettings.cookieSettings.name.guestId); | ||
return new personalizer_1.Personalizer(browserId, guestId).getInteractiveExperienceData(personalizeData, cloudSDKSettings, window.location.search, { | ||
timeout: opts?.timeout | ||
}); | ||
} | ||
exports.personalize = personalize; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const consts_1 = require("../consts"); | ||
const initializer_1 = require("../initializer/server/initializer"); | ||
const personalizer_1 = require("./personalizer"); | ||
@@ -19,2 +20,3 @@ /** | ||
function personalizeServer(request, personalizeData, opts) { | ||
(0, initializer_1.verifyPersonalizePackageExistence)(); | ||
const requestUrl = new URL(request.url, `https://localhost`); | ||
@@ -26,17 +28,7 @@ const userAgent = (0, utils_1.isNextJsMiddlewareRequest)(request) | ||
personalizeData.geo = request.geo; | ||
let settings, id, guestId; | ||
const settings = (0, internal_1.getCloudSDKSettingsServer)(); | ||
const personalizeSettings = (0, internal_1.getEnabledPackageServer)(consts_1.PACKAGE_NAME)?.settings; | ||
if (internal_1.builderInstanceServer) { | ||
if (!(0, internal_1.getEnabledPackageServer)(consts_1.PACKAGE_NAME)) | ||
throw new Error(consts_1.ErrorMessages.IE_0017); | ||
settings = (0, internal_1.getCloudSDKSettingsServer)(); | ||
id = (0, internal_1.getCookieValueFromRequest)(request, settings.cookieSettings.name.browserId); | ||
guestId = (0, internal_1.getCookieValueFromRequest)(request, personalizeSettings.cookieSettings.name.guestId); | ||
} | ||
else { | ||
settings = (0, internal_1.handleGetSettingsError)(internal_1.getSettingsServer, consts_1.ErrorMessages.IE_0017); | ||
id = (0, internal_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.browserId); | ||
guestId = (0, internal_1.getCookieValueFromRequest)(request, settings.cookieSettings.cookieNames.guestId); | ||
} | ||
return new personalizer_1.Personalizer(id, guestId).getInteractiveExperienceData(personalizeData, settings, requestUrl.search, { | ||
const browserId = (0, internal_1.getCookieValueFromRequest)(request, settings.cookieSettings.name.browserId); | ||
const guestId = (0, internal_1.getCookieValueFromRequest)(request, personalizeSettings.cookieSettings.name.guestId); | ||
return new personalizer_1.Personalizer(browserId, guestId).getInteractiveExperienceData(personalizeData, settings, requestUrl.search, { | ||
timeout: opts?.timeout, | ||
@@ -43,0 +35,0 @@ userAgent |
@@ -1,2 +0,1 @@ | ||
export { initServer as init } from './lib/init/server/initializer'; | ||
export { personalizeServer as personalize } from './lib/personalization/personalizeServer'; | ||
@@ -3,0 +2,0 @@ export { PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from './lib/consts'; |
"use strict"; | ||
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.PERSONALIZE_NAMESPACE = exports.PACKAGE_VERSION = exports.personalize = exports.init = void 0; | ||
var initializer_1 = require("./lib/init/server/initializer"); | ||
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return initializer_1.initServer; } }); | ||
exports.PERSONALIZE_NAMESPACE = exports.PACKAGE_VERSION = exports.personalize = void 0; | ||
var personalizeServer_1 = require("./lib/personalization/personalizeServer"); | ||
@@ -8,0 +6,0 @@ Object.defineProperty(exports, "personalize", { enumerable: true, get: function () { return personalizeServer_1.personalizeServer; } }); |
{ | ||
"name": "@sitecore-cloudsdk/personalize", | ||
"version": "0.4.4", | ||
"version": "0.5.0-rc.0", | ||
"license": "Apache-2.0", | ||
@@ -19,5 +19,5 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html", | ||
"dependencies": { | ||
"@sitecore-cloudsdk/core": "^0.4.4", | ||
"@sitecore-cloudsdk/events": "^0.4.4", | ||
"@sitecore-cloudsdk/utils": "^0.4.4" | ||
"@sitecore-cloudsdk/core": "^0.5.0-rc.0", | ||
"@sitecore-cloudsdk/events": "^0.5.0-rc.0", | ||
"@sitecore-cloudsdk/utils": "^0.5.0-rc.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
@@ -1,2 +0,1 @@ | ||
export { init } from './lib/init/client/initializer'; | ||
export { personalize } from './lib/personalization/personalize'; | ||
@@ -3,0 +2,0 @@ export { PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from './lib/consts'; |
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
export { init } from './lib/init/client/initializer'; | ||
export { personalize } from './lib/personalization/personalize'; | ||
export { PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from './lib/consts'; | ||
import './lib/initializer/browser/initializer'; |
@@ -7,5 +7,2 @@ export declare const PERSONALIZE_NAMESPACE: "sitecore-cloudsdk:personalize"; | ||
IE_0001 = "[IE-0001] You are trying to run a browser-side function on the server side. On the server side, run the server-side equivalent of the function, available in \"server\" modules.", | ||
IE_0006 = "[IE-0006] You must first initialize the \"personalize/browser\" module. Run the \"init\" function.", | ||
IE_0007 = "[IE-0007] You must first initialize the \"personalize/server\" module. Run the \"init\" function.", | ||
IE_0008 = "[IE-0008] You must first initialize the \"core\" package. Run the \"init\" function.", | ||
IE_0016 = "[IE-0016] You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/browser\" and import \"@sitecore-cloudsdk/personalize/browser\". Then, run \"CloudSDK().addPersonalize().initialize()\".", | ||
@@ -12,0 +9,0 @@ IE_0017 = "[IE-0017] You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/server\", and import \"@sitecore-cloudsdk/personalize/server\". Then, run \"await CloudSDK().addPersonalize().initialize()\".", |
@@ -12,5 +12,2 @@ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
ErrorMessages["IE_0001"] = "[IE-0001] You are trying to run a browser-side function on the server side. On the server side, run the server-side equivalent of the function, available in \"server\" modules."; | ||
ErrorMessages["IE_0006"] = "[IE-0006] You must first initialize the \"personalize/browser\" module. Run the \"init\" function."; | ||
ErrorMessages["IE_0007"] = "[IE-0007] You must first initialize the \"personalize/server\" module. Run the \"init\" function."; | ||
ErrorMessages["IE_0008"] = "[IE-0008] You must first initialize the \"core\" package. Run the \"init\" function."; | ||
// eslint-disable-next-line max-len | ||
@@ -17,0 +14,0 @@ ErrorMessages["IE_0016"] = "[IE-0016] You must first initialize the Cloud SDK and the \"personalize\" package. First, import \"CloudSDK\" from \"@sitecore-cloudsdk/core/browser\" and import \"@sitecore-cloudsdk/personalize/browser\". Then, run \"CloudSDK().addPersonalize().initialize()\"."; |
@@ -1,3 +0,3 @@ | ||
import type { Settings } from '@sitecore-cloudsdk/core/browser'; | ||
import { type Settings } from '@sitecore-cloudsdk/core/browser'; | ||
import type { PersonalizeSettings } from './interfaces'; | ||
export declare function createPersonalizeCookie(personalizeSettings: PersonalizeSettings, cloudSDKSettings: Settings): Promise<void | boolean>; |
@@ -1,2 +0,4 @@ | ||
import { getCookiesValuesFromEdgeBrowser, getDefaultCookieAttributes, getGuestId } from '@sitecore-cloudsdk/core/internal'; | ||
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
import { getGuestId } from '@sitecore-cloudsdk/core/browser'; | ||
import { getCookiesValuesFromEdgeBrowser, getDefaultCookieAttributes } from '@sitecore-cloudsdk/core/internal'; | ||
import { createCookieString, getCookieValueClientSide } from '@sitecore-cloudsdk/utils'; | ||
@@ -13,5 +15,5 @@ export async function createPersonalizeCookie(personalizeSettings, cloudSDKSettings) { | ||
else if (browserIdCookieValue) { | ||
const guestIdCookieValue = await getGuestId(browserIdCookieValue, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl); | ||
const guestIdCookieValue = await getGuestId(); | ||
document.cookie = createCookieString(personalizeSettings.cookieSettings.name.guestId, guestIdCookieValue, attributes); | ||
} | ||
} |
@@ -26,1 +26,5 @@ import { CloudSDKBrowserInitializer } from '@sitecore-cloudsdk/core/browser'; | ||
} | ||
/** | ||
* A function that handles the async browser init logic. Throws an error or awaits the promise. | ||
*/ | ||
export declare function awaitInit(): Promise<void>; |
@@ -6,3 +6,3 @@ // © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
import { appendScriptWithAttributes } from '@sitecore-cloudsdk/utils'; | ||
import { PACKAGE_NAME, PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from '../../consts'; | ||
import { ErrorMessages, PACKAGE_NAME, PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from '../../consts'; | ||
import { personalize } from '../../personalization/personalize'; | ||
@@ -62,1 +62,10 @@ import { getCdnUrl } from '../../web-personalization/get-cdn-url'; | ||
CloudSDKBrowserInitializer.prototype.addPersonalize = addPersonalize; | ||
/** | ||
* A function that handles the async browser init logic. Throws an error or awaits the promise. | ||
*/ | ||
export async function awaitInit() { | ||
const initState = getEnabledPackageBrowser(PACKAGE_NAME)?.initState; | ||
if (!initState) | ||
throw new Error(ErrorMessages.IE_0016); | ||
await initState; | ||
} |
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
import { getCookiesValuesFromEdgeServer, getDefaultCookieAttributes, getGuestId } from '@sitecore-cloudsdk/core/internal'; | ||
import { getCookiesValuesFromEdgeServer, getDefaultCookieAttributes, getGuestIdServer } from '@sitecore-cloudsdk/core/internal'; | ||
import { createCookieString, getCookieServerSide } from '@sitecore-cloudsdk/utils'; | ||
@@ -17,3 +17,3 @@ export async function handleHttpCookie(request, response, settings, cloudSDKSettings) { | ||
else if (browserIdCookie) { | ||
const guestIdCookieValueFromEdgeProxy = await getGuestId(browserIdCookie.value, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl); | ||
const guestIdCookieValueFromEdgeProxy = await getGuestIdServer(browserIdCookie.value); | ||
guestIdCookieString = createCookieString(settings.cookieSettings.name.guestId, guestIdCookieValueFromEdgeProxy, defaultCookieAttributes); | ||
@@ -20,0 +20,0 @@ } |
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
import { getCookiesValuesFromEdgeServer, getCookieValueFromMiddlewareRequest, getDefaultCookieAttributes, getGuestId } from '@sitecore-cloudsdk/core/internal'; | ||
import { getCookiesValuesFromEdgeServer, getCookieValueFromMiddlewareRequest, getDefaultCookieAttributes, getGuestIdServer } from '@sitecore-cloudsdk/core/internal'; | ||
export async function handleNextJsMiddlewareCookie(request, response, settings, cloudSDKSettings) { | ||
@@ -16,3 +16,3 @@ const middlewareRequest = request; | ||
else if (browserIdCookieValue) { | ||
const guestIdCookieValueFromEdgeProxy = await getGuestId(browserIdCookieValue, cloudSDKSettings.sitecoreEdgeContextId, cloudSDKSettings.sitecoreEdgeUrl); | ||
const guestIdCookieValueFromEdgeProxy = await getGuestIdServer(browserIdCookieValue); | ||
guestIdValue = guestIdCookieValueFromEdgeProxy; | ||
@@ -19,0 +19,0 @@ } |
@@ -16,1 +16,2 @@ import { CloudSDKServerInitializer } from '@sitecore-cloudsdk/core/server'; | ||
} | ||
export declare function verifyPersonalizePackageExistence(): void; |
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
import { COOKIE_NAME_PREFIX, debug, enabledPackagesServer as enabledPackages, getCloudSDKRequest, getCloudSDKResponse, getCloudSDKSettingsServer, getEnabledPackageServer, PackageInitializerServer } from '@sitecore-cloudsdk/core/internal'; | ||
import { CloudSDKServerInitializer } from '@sitecore-cloudsdk/core/server'; | ||
import { PACKAGE_NAME, PERSONALIZE_NAMESPACE } from '../../consts'; | ||
import { ErrorMessages, PACKAGE_NAME, PERSONALIZE_NAMESPACE } from '../../consts'; | ||
import { createPersonalizeCookie } from './createPersonalizeCookie'; | ||
@@ -34,1 +34,5 @@ export async function sideEffects() { | ||
CloudSDKServerInitializer.prototype.addPersonalize = addPersonalize; | ||
export function verifyPersonalizePackageExistence() { | ||
if (!getEnabledPackageServer(PACKAGE_NAME)) | ||
throw Error(ErrorMessages.IE_0017); | ||
} |
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
import { getBrowserId, getCloudSDKSettingsBrowser as getCloudSDKSettings, getEnabledPackageBrowser as getEnabledPackage, getSettings, handleGetSettingsError } from '@sitecore-cloudsdk/core/internal'; | ||
import { getCloudSDKSettingsBrowser as getCloudSDKSettings, getEnabledPackageBrowser as getEnabledPackage } from '@sitecore-cloudsdk/core/internal'; | ||
import { getCookieValueClientSide } from '@sitecore-cloudsdk/utils'; | ||
import { ErrorMessages, PACKAGE_NAME } from '../consts'; | ||
import { awaitInit } from '../init/client/initializer'; | ||
import { PACKAGE_NAME } from '../consts'; | ||
import { awaitInit } from '../initializer/browser/initializer'; | ||
import { Personalizer } from './personalizer'; | ||
@@ -15,19 +15,9 @@ /** | ||
await awaitInit(); | ||
if (getEnabledPackage(PACKAGE_NAME)?.initState) { | ||
const cloudSDKSettings = getCloudSDKSettings(); | ||
const personalizeSettings = getEnabledPackage(PACKAGE_NAME)?.settings; | ||
const browserId = getCookieValueClientSide(cloudSDKSettings.cookieSettings.name.browserId); | ||
const guestId = getCookieValueClientSide(personalizeSettings.cookieSettings.name.guestId); | ||
return new Personalizer(browserId, guestId).getInteractiveExperienceData(personalizeData, cloudSDKSettings, window.location.search, { | ||
timeout: opts?.timeout | ||
}); | ||
} | ||
else { | ||
const settings = handleGetSettingsError(getSettings, ErrorMessages.IE_0016); | ||
const browserId = getBrowserId(); | ||
const guestId = getCookieValueClientSide(settings.cookieSettings.cookieNames.guestId); | ||
return new Personalizer(browserId, guestId).getInteractiveExperienceData(personalizeData, settings, window.location.search, { | ||
timeout: opts?.timeout | ||
}); | ||
} | ||
const cloudSDKSettings = getCloudSDKSettings(); | ||
const personalizeSettings = getEnabledPackage(PACKAGE_NAME)?.settings; | ||
const browserId = getCookieValueClientSide(cloudSDKSettings.cookieSettings.name.browserId); | ||
const guestId = getCookieValueClientSide(personalizeSettings.cookieSettings.name.guestId); | ||
return new Personalizer(browserId, guestId).getInteractiveExperienceData(personalizeData, cloudSDKSettings, window.location.search, { | ||
timeout: opts?.timeout | ||
}); | ||
} |
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
import { builderInstanceServer, getCloudSDKSettingsServer, getCookieValueFromRequest, getEnabledPackageServer, getSettingsServer, handleGetSettingsError } from '@sitecore-cloudsdk/core/internal'; | ||
import { getCloudSDKSettingsServer, getCookieValueFromRequest, getEnabledPackageServer } from '@sitecore-cloudsdk/core/internal'; | ||
import { isNextJsMiddlewareRequest } from '@sitecore-cloudsdk/utils'; | ||
import { ErrorMessages, PACKAGE_NAME } from '../consts'; | ||
import { PACKAGE_NAME } from '../consts'; | ||
import { verifyPersonalizePackageExistence } from '../initializer/server/initializer'; | ||
import { Personalizer } from './personalizer'; | ||
@@ -15,2 +16,3 @@ /** | ||
export function personalizeServer(request, personalizeData, opts) { | ||
verifyPersonalizePackageExistence(); | ||
const requestUrl = new URL(request.url, `https://localhost`); | ||
@@ -22,17 +24,7 @@ const userAgent = isNextJsMiddlewareRequest(request) | ||
personalizeData.geo = request.geo; | ||
let settings, id, guestId; | ||
const settings = getCloudSDKSettingsServer(); | ||
const personalizeSettings = getEnabledPackageServer(PACKAGE_NAME)?.settings; | ||
if (builderInstanceServer) { | ||
if (!getEnabledPackageServer(PACKAGE_NAME)) | ||
throw new Error(ErrorMessages.IE_0017); | ||
settings = getCloudSDKSettingsServer(); | ||
id = getCookieValueFromRequest(request, settings.cookieSettings.name.browserId); | ||
guestId = getCookieValueFromRequest(request, personalizeSettings.cookieSettings.name.guestId); | ||
} | ||
else { | ||
settings = handleGetSettingsError(getSettingsServer, ErrorMessages.IE_0017); | ||
id = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.browserId); | ||
guestId = getCookieValueFromRequest(request, settings.cookieSettings.cookieNames.guestId); | ||
} | ||
return new Personalizer(id, guestId).getInteractiveExperienceData(personalizeData, settings, requestUrl.search, { | ||
const browserId = getCookieValueFromRequest(request, settings.cookieSettings.name.browserId); | ||
const guestId = getCookieValueFromRequest(request, personalizeSettings.cookieSettings.name.guestId); | ||
return new Personalizer(browserId, guestId).getInteractiveExperienceData(personalizeData, settings, requestUrl.search, { | ||
timeout: opts?.timeout, | ||
@@ -39,0 +31,0 @@ userAgent |
@@ -1,2 +0,1 @@ | ||
export { initServer as init } from './lib/init/server/initializer'; | ||
export { personalizeServer as personalize } from './lib/personalization/personalizeServer'; | ||
@@ -3,0 +2,0 @@ export { PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from './lib/consts'; |
// © Sitecore Corporation A/S. All rights reserved. Sitecore® is a registered trademark of Sitecore Corporation A/S. | ||
export { initServer as init } from './lib/init/server/initializer'; | ||
export { personalizeServer as personalize } from './lib/personalization/personalizeServer'; | ||
export { PACKAGE_VERSION, PERSONALIZE_NAMESPACE } from './lib/consts'; | ||
import './lib/initializer/server/initializer'; |
{ | ||
"name": "@sitecore-cloudsdk/personalize", | ||
"version": "0.4.4", | ||
"version": "0.5.0-rc.0", | ||
"license": "Apache-2.0", | ||
@@ -19,5 +19,5 @@ "homepage": "https://doc.sitecore.com/xmc/en/developers/sdk/latest/cloud-sdk/index.html", | ||
"dependencies": { | ||
"@sitecore-cloudsdk/core": "^0.4.4", | ||
"@sitecore-cloudsdk/events": "^0.4.4", | ||
"@sitecore-cloudsdk/utils": "^0.4.4" | ||
"@sitecore-cloudsdk/core": "^0.5.0-rc.0", | ||
"@sitecore-cloudsdk/events": "^0.5.0-rc.0", | ||
"@sitecore-cloudsdk/utils": "^0.5.0-rc.0" | ||
}, | ||
@@ -24,0 +24,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
151079
76
1506
+ Added@sitecore-cloudsdk/core@0.5.0(transitive)
+ Added@sitecore-cloudsdk/events@0.5.0(transitive)
+ Added@sitecore-cloudsdk/utils@0.5.0(transitive)
- Removed@sitecore-cloudsdk/core@0.4.4(transitive)
- Removed@sitecore-cloudsdk/events@0.4.4(transitive)
- Removed@sitecore-cloudsdk/utils@0.4.4(transitive)