diff --git a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.test.ts b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.test.ts index ebb6eac19e..18d74bcfd7 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.test.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.test.ts @@ -60,7 +60,7 @@ describe('PersonalizeMiddleware', () => { }, cookies: { get(cookieName: string) { - const cookies = { 'bid_cdp-client-key': 'browser-id', ...props.cookieValues }; + const cookies = { 'BID_cdp-client-key': 'browser-id', ...props.cookieValues }; return cookies[cookieName]; }, @@ -119,7 +119,7 @@ describe('PersonalizeMiddleware', () => { ) => { const cdpConfig = { clientKey: 'cdp-client-key', - endpoint: 'http://cdp-endpoint', + domain: 'cdp-endpoint', pointOfSale: 'cdp-pos', ...(props?.cdpConfig || {}), }; @@ -191,7 +191,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (personalize middleware is disabled)'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -216,7 +216,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (%s)', 'redirected'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -246,7 +246,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (%s)', 'preview'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(getCookiesSpy.calledWith('__prerender_bypass')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -276,7 +276,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (%s)', 'preview'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(getCookiesSpy.calledWith('__prerender_bypass')).to.be.true; expect(getCookiesSpy.calledWith('__next_preview_data')).to.be.true; @@ -307,7 +307,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (%s)', 'route excluded'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -355,7 +355,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (personalize info not found)'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -387,7 +387,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (no personalization configured)'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -396,7 +396,7 @@ describe('PersonalizeMiddleware', () => { it('browser id generation failed', async () => { const req = createRequest({ - cookieValues: { 'bid_cdp-client-key': undefined }, + cookieValues: { 'BID_cdp-client-key': undefined }, }); const res = createResponse(); @@ -420,7 +420,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (browser id generation failed)'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -451,7 +451,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (no variant identified)'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -482,7 +482,7 @@ describe('PersonalizeMiddleware', () => { validateDebugLog('skipped (invalid variant)'); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); @@ -494,7 +494,7 @@ describe('PersonalizeMiddleware', () => { it('browser id is present in cookies', async () => { const req = createRequest({ cookieValues: { - 'bid_cdp-client-key': 'browser-id', + 'BID_cdp-client-key': 'browser-id', }, }); @@ -527,11 +527,11 @@ describe('PersonalizeMiddleware', () => { }, }); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); - expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId); + expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId); getCookiesSpy.restore(); nextRewriteStub.restore(); @@ -540,7 +540,7 @@ describe('PersonalizeMiddleware', () => { it('browser id is not present in cookies', async () => { const req = createRequest({ cookieValues: { - 'bid_cdp-client-key': undefined, + 'BID_cdp-client-key': undefined, }, }); @@ -581,11 +581,11 @@ describe('PersonalizeMiddleware', () => { }, }); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); - expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId); + expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId); getCookiesSpy.restore(); nextRewriteStub.restore(); @@ -634,11 +634,11 @@ describe('PersonalizeMiddleware', () => { }, }); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); - expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId); + expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId); getCookiesSpy.restore(); nextRewriteStub.restore(); @@ -681,11 +681,11 @@ describe('PersonalizeMiddleware', () => { }, }); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); - expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId); + expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId); getCookiesSpy.restore(); nextRewriteStub.restore(); @@ -723,11 +723,11 @@ describe('PersonalizeMiddleware', () => { }, }); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); - expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId); + expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId); getCookiesSpy.restore(); nextRewriteStub.restore(); @@ -777,11 +777,11 @@ describe('PersonalizeMiddleware', () => { }, }); - expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true; + expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true; expect(finalRes).to.deep.equal(res); - expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId); + expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId); getCookiesSpy.restore(); nextRewriteStub.restore(); @@ -826,7 +826,7 @@ describe('PersonalizeMiddleware', () => { it('should log error when generateBrowserId throws', async () => { const error = new Error('CDP generateBrowserId fails'); const req = createRequest({ - cookieValues: { 'bid_cdp-client-key': undefined }, + cookieValues: { 'BID_cdp-client-key': undefined }, }); const generateBrowserIdWithError = sinon.stub().throws(error); diff --git a/packages/sitecore-jss/src/personalize/cdp-service.test.ts b/packages/sitecore-jss/src/personalize/cdp-service.test.ts index 43afc5094e..4cfbbae8aa 100644 --- a/packages/sitecore-jss/src/personalize/cdp-service.test.ts +++ b/packages/sitecore-jss/src/personalize/cdp-service.test.ts @@ -8,7 +8,8 @@ import { AxiosDataFetcher } from '../axios-fetcher'; use(spies); describe('CdpService', () => { - const endpoint = 'http://sctest'; + const domain = 'sctest.com'; + const endpoint = `https://${domain}`; const clientKey = 'client-key'; const contentId = 'content-id'; const variantId = 'variant-1'; @@ -29,7 +30,7 @@ describe('CdpService', () => { } as ExperienceParams; const config = { - endpoint, + domain, clientKey, pointOfSale, }; @@ -127,7 +128,7 @@ describe('CdpService', () => { expect(actualVariantId).to.deep.equal(variantId); expect(fetcherSpy).to.be.called.once; - expect(fetcherSpy).to.be.called.with('http://sctest/v2/callFlows'); + expect(fetcherSpy).to.be.called.with('https://sctest.com/v2/callFlows'); }); it('should use custom fetcher resolver and return undefined id when timeout is exceeded', async () => { @@ -220,7 +221,7 @@ describe('CdpService', () => { expect(actualRef).to.deep.equal(ref); expect(fetcherSpy).to.be.called.once; expect(fetcherSpy).to.be.called.with( - `http://sctest/v1.2/browser/create.json?client_key=${clientKey}&message={}` + `https://sctest.com/v1.2/browser/create.json?client_key=${clientKey}&message={}` ); }); diff --git a/packages/sitecore-jss/src/personalize/cdp-service.ts b/packages/sitecore-jss/src/personalize/cdp-service.ts index b43dffb02e..ad4a6a027f 100644 --- a/packages/sitecore-jss/src/personalize/cdp-service.ts +++ b/packages/sitecore-jss/src/personalize/cdp-service.ts @@ -24,9 +24,9 @@ export type GenerateBrowserIdResult = { export type CdpServiceConfig = { /** - * Your Sitecore CDP API endpoint + * Your Sitecore CDP API domain */ - endpoint: string; + domain: string; /** * The client key to use for authentication */ @@ -158,7 +158,7 @@ export class CdpService { * @returns {string} formatted URL */ protected getGenerateBrowserIdUrl() { - return `${this.config.endpoint}/v1.2/browser/create.json?client_key=${this.config.clientKey}&message={}`; + return `https://${this.config.domain}/v1.2/browser/create.json?client_key=${this.config.clientKey}&message={}`; } /** @@ -166,7 +166,7 @@ export class CdpService { * @returns {string} formatted URL */ protected getExecuteExperienceUrl() { - return `${this.config.endpoint}/v2/callFlows`; + return `https://${this.config.domain}/v2/callFlows`; } /**