Skip to content

Commit 14147c6

Browse files
committed
Use a domain instead of full URL for cdp-cdp-service (consistent with SitecoreCloud Engage SDK)
1 parent 2f5aa3c commit 14147c6

File tree

3 files changed

+37
-36
lines changed

3 files changed

+37
-36
lines changed

packages/sitecore-jss-nextjs/src/middleware/personalize-middleware.test.ts

+28-28
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('PersonalizeMiddleware', () => {
6060
},
6161
cookies: {
6262
get(cookieName: string) {
63-
const cookies = { 'bid_cdp-client-key': 'browser-id', ...props.cookieValues };
63+
const cookies = { 'BID_cdp-client-key': 'browser-id', ...props.cookieValues };
6464

6565
return cookies[cookieName];
6666
},
@@ -119,7 +119,7 @@ describe('PersonalizeMiddleware', () => {
119119
) => {
120120
const cdpConfig = {
121121
clientKey: 'cdp-client-key',
122-
endpoint: 'http://cdp-endpoint',
122+
domain: 'cdp-endpoint',
123123
pointOfSale: 'cdp-pos',
124124
...(props?.cdpConfig || {}),
125125
};
@@ -191,7 +191,7 @@ describe('PersonalizeMiddleware', () => {
191191

192192
validateDebugLog('skipped (personalize middleware is disabled)');
193193

194-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
194+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
195195

196196
expect(finalRes).to.deep.equal(res);
197197

@@ -216,7 +216,7 @@ describe('PersonalizeMiddleware', () => {
216216

217217
validateDebugLog('skipped (%s)', 'redirected');
218218

219-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
219+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
220220

221221
expect(finalRes).to.deep.equal(res);
222222

@@ -246,7 +246,7 @@ describe('PersonalizeMiddleware', () => {
246246

247247
validateDebugLog('skipped (%s)', 'preview');
248248

249-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
249+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
250250
expect(getCookiesSpy.calledWith('__prerender_bypass')).to.be.true;
251251

252252
expect(finalRes).to.deep.equal(res);
@@ -276,7 +276,7 @@ describe('PersonalizeMiddleware', () => {
276276

277277
validateDebugLog('skipped (%s)', 'preview');
278278

279-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
279+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
280280
expect(getCookiesSpy.calledWith('__prerender_bypass')).to.be.true;
281281
expect(getCookiesSpy.calledWith('__next_preview_data')).to.be.true;
282282

@@ -307,7 +307,7 @@ describe('PersonalizeMiddleware', () => {
307307

308308
validateDebugLog('skipped (%s)', 'route excluded');
309309

310-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
310+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
311311

312312
expect(finalRes).to.deep.equal(res);
313313

@@ -355,7 +355,7 @@ describe('PersonalizeMiddleware', () => {
355355

356356
validateDebugLog('skipped (personalize info not found)');
357357

358-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
358+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
359359

360360
expect(finalRes).to.deep.equal(res);
361361

@@ -387,7 +387,7 @@ describe('PersonalizeMiddleware', () => {
387387

388388
validateDebugLog('skipped (no personalization configured)');
389389

390-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
390+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
391391

392392
expect(finalRes).to.deep.equal(res);
393393

@@ -396,7 +396,7 @@ describe('PersonalizeMiddleware', () => {
396396

397397
it('browser id generation failed', async () => {
398398
const req = createRequest({
399-
cookieValues: { 'bid_cdp-client-key': undefined },
399+
cookieValues: { 'BID_cdp-client-key': undefined },
400400
});
401401

402402
const res = createResponse();
@@ -420,7 +420,7 @@ describe('PersonalizeMiddleware', () => {
420420

421421
validateDebugLog('skipped (browser id generation failed)');
422422

423-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
423+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
424424

425425
expect(finalRes).to.deep.equal(res);
426426

@@ -451,7 +451,7 @@ describe('PersonalizeMiddleware', () => {
451451

452452
validateDebugLog('skipped (no variant identified)');
453453

454-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
454+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
455455

456456
expect(finalRes).to.deep.equal(res);
457457

@@ -482,7 +482,7 @@ describe('PersonalizeMiddleware', () => {
482482

483483
validateDebugLog('skipped (invalid variant)');
484484

485-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
485+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
486486

487487
expect(finalRes).to.deep.equal(res);
488488

@@ -494,7 +494,7 @@ describe('PersonalizeMiddleware', () => {
494494
it('browser id is present in cookies', async () => {
495495
const req = createRequest({
496496
cookieValues: {
497-
'bid_cdp-client-key': 'browser-id',
497+
'BID_cdp-client-key': 'browser-id',
498498
},
499499
});
500500

@@ -527,11 +527,11 @@ describe('PersonalizeMiddleware', () => {
527527
},
528528
});
529529

530-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
530+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
531531

532532
expect(finalRes).to.deep.equal(res);
533533

534-
expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
534+
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);
535535

536536
getCookiesSpy.restore();
537537
nextRewriteStub.restore();
@@ -540,7 +540,7 @@ describe('PersonalizeMiddleware', () => {
540540
it('browser id is not present in cookies', async () => {
541541
const req = createRequest({
542542
cookieValues: {
543-
'bid_cdp-client-key': undefined,
543+
'BID_cdp-client-key': undefined,
544544
},
545545
});
546546

@@ -581,11 +581,11 @@ describe('PersonalizeMiddleware', () => {
581581
},
582582
});
583583

584-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
584+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
585585

586586
expect(finalRes).to.deep.equal(res);
587587

588-
expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
588+
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);
589589

590590
getCookiesSpy.restore();
591591
nextRewriteStub.restore();
@@ -634,11 +634,11 @@ describe('PersonalizeMiddleware', () => {
634634
},
635635
});
636636

637-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
637+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
638638

639639
expect(finalRes).to.deep.equal(res);
640640

641-
expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
641+
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);
642642

643643
getCookiesSpy.restore();
644644
nextRewriteStub.restore();
@@ -681,11 +681,11 @@ describe('PersonalizeMiddleware', () => {
681681
},
682682
});
683683

684-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
684+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
685685

686686
expect(finalRes).to.deep.equal(res);
687687

688-
expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
688+
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);
689689

690690
getCookiesSpy.restore();
691691
nextRewriteStub.restore();
@@ -723,11 +723,11 @@ describe('PersonalizeMiddleware', () => {
723723
},
724724
});
725725

726-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
726+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
727727

728728
expect(finalRes).to.deep.equal(res);
729729

730-
expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
730+
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);
731731

732732
getCookiesSpy.restore();
733733
nextRewriteStub.restore();
@@ -777,11 +777,11 @@ describe('PersonalizeMiddleware', () => {
777777
},
778778
});
779779

780-
expect(getCookiesSpy.calledWith('bid_cdp-client-key')).to.be.true;
780+
expect(getCookiesSpy.calledWith('BID_cdp-client-key')).to.be.true;
781781

782782
expect(finalRes).to.deep.equal(res);
783783

784-
expect(finalRes.cookies['bid_cdp-client-key']).to.equal(browserId);
784+
expect(finalRes.cookies['BID_cdp-client-key']).to.equal(browserId);
785785

786786
getCookiesSpy.restore();
787787
nextRewriteStub.restore();
@@ -826,7 +826,7 @@ describe('PersonalizeMiddleware', () => {
826826
it('should log error when generateBrowserId throws', async () => {
827827
const error = new Error('CDP generateBrowserId fails');
828828
const req = createRequest({
829-
cookieValues: { 'bid_cdp-client-key': undefined },
829+
cookieValues: { 'BID_cdp-client-key': undefined },
830830
});
831831

832832
const generateBrowserIdWithError = sinon.stub().throws(error);

packages/sitecore-jss/src/personalize/cdp-service.test.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { AxiosDataFetcher } from '../axios-fetcher';
88
use(spies);
99

1010
describe('CdpService', () => {
11-
const endpoint = 'http://sctest';
11+
const domain = 'sctest.com';
12+
const endpoint = `https://${domain}`;
1213
const clientKey = 'client-key';
1314
const contentId = 'content-id';
1415
const variantId = 'variant-1';
@@ -29,7 +30,7 @@ describe('CdpService', () => {
2930
} as ExperienceParams;
3031

3132
const config = {
32-
endpoint,
33+
domain,
3334
clientKey,
3435
pointOfSale,
3536
};
@@ -127,7 +128,7 @@ describe('CdpService', () => {
127128

128129
expect(actualVariantId).to.deep.equal(variantId);
129130
expect(fetcherSpy).to.be.called.once;
130-
expect(fetcherSpy).to.be.called.with('http://sctest/v2/callFlows');
131+
expect(fetcherSpy).to.be.called.with('https://sctest.com/v2/callFlows');
131132
});
132133

133134
it('should use custom fetcher resolver and return undefined id when timeout is exceeded', async () => {
@@ -220,7 +221,7 @@ describe('CdpService', () => {
220221
expect(actualRef).to.deep.equal(ref);
221222
expect(fetcherSpy).to.be.called.once;
222223
expect(fetcherSpy).to.be.called.with(
223-
`http://sctest/v1.2/browser/create.json?client_key=${clientKey}&message={}`
224+
`https://sctest.com/v1.2/browser/create.json?client_key=${clientKey}&message={}`
224225
);
225226
});
226227

packages/sitecore-jss/src/personalize/cdp-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export type GenerateBrowserIdResult = {
2424

2525
export type CdpServiceConfig = {
2626
/**
27-
* Your Sitecore CDP API endpoint
27+
* Your Sitecore CDP API domain
2828
*/
29-
endpoint: string;
29+
domain: string;
3030
/**
3131
* The client key to use for authentication
3232
*/
@@ -158,15 +158,15 @@ export class CdpService {
158158
* @returns {string} formatted URL
159159
*/
160160
protected getGenerateBrowserIdUrl() {
161-
return `${this.config.endpoint}/v1.2/browser/create.json?client_key=${this.config.clientKey}&message={}`;
161+
return `https://${this.config.domain}/v1.2/browser/create.json?client_key=${this.config.clientKey}&message={}`;
162162
}
163163

164164
/**
165165
* Get formatted URL for executeExperience call
166166
* @returns {string} formatted URL
167167
*/
168168
protected getExecuteExperienceUrl() {
169-
return `${this.config.endpoint}/v2/callFlows`;
169+
return `https://${this.config.domain}/v2/callFlows`;
170170
}
171171

172172
/**

0 commit comments

Comments
 (0)