Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CXCDS-13558: Change implementation for Spartacus CAS support #19869

Merged
merged 19 commits into from
Jan 21, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0cee600
CXEC-45758: add possibility to enable SCI for CAS.
johannathalmann-SAP Jan 14, 2025
35e478e
CXCDS-13558: add possibility to enable SCI for CAS, fix tests and style.
johannathalmann-SAP Jan 15, 2025
13f2b52
Add license header
github-actions[bot] Jan 15, 2025
a214f48
CXCDS-13558: default should be false.
johannathalmann-SAP Jan 15, 2025
dfa6a76
CXCDS-13558: remove not needed code.
johannathalmann-SAP Jan 15, 2025
9850516
Merge branch 'feature/CXCDS-13558' of https://github.com/SAP/spartacu…
johannathalmann-SAP Jan 15, 2025
d6ec51a
CXCDS-13558: move evaluation of sciEnabled to cds-feature.module
johannathalmann-SAP Jan 16, 2025
300dbd7
CXCDS-13558: remove accidentally added header line.
johannathalmann-SAP Jan 16, 2025
79b1166
CXCDS-13558: add switch for configurl.
johannathalmann-SAP Jan 17, 2025
5c48f34
CXEC-45758: add possibility to enable SCI for CAS.
johannathalmann-SAP Jan 14, 2025
8e3bc5e
CXCDS-13558: add possibility to enable SCI for CAS, fix tests and style.
johannathalmann-SAP Jan 15, 2025
0fbe4ea
CXCDS-13558: default should be false.
johannathalmann-SAP Jan 15, 2025
62f7606
CXCDS-13558: remove not needed code.
johannathalmann-SAP Jan 15, 2025
e1acbe9
Add license header
github-actions[bot] Jan 15, 2025
c637b6f
CXCDS-13558: move evaluation of sciEnabled to cds-feature.module
johannathalmann-SAP Jan 16, 2025
4356428
CXCDS-13558: remove accidentally added header line.
johannathalmann-SAP Jan 16, 2025
8f5c540
CXCDS-13558: add switch for configurl.
johannathalmann-SAP Jan 17, 2025
8e1c463
Merge branch 'feature/CXCDS-13558' of https://github.com/SAP/spartacu…
johannathalmann-SAP Jan 20, 2025
361a08a
Merge branch 'develop' into feature/CXCDS-13558
johannathalmann-SAP Jan 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env-cmdrc
Original file line number Diff line number Diff line change
@@ -15,7 +15,8 @@
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-p1-public.model-t.myhybris.cloud"
},
"cds": {
"CX_CDS": "true"
"CX_CDS": "true",
"CX_SCI": "false"
},
"lighthouse": {
"CX_BASE_URL": "https://api.spartacus.rocks"
15 changes: 11 additions & 4 deletions integration-libs/cds/src/cds.module.ts
Original file line number Diff line number Diff line change
@@ -5,8 +5,16 @@
*/

import { ModuleWithProviders, NgModule } from '@angular/core';
import { provideConfigValidator, provideDefaultConfig } from '@spartacus/core';
import { CdsConfig, cdsConfigValidator, DEFAULT_CDS_CONFIG } from './config';
import {
provideConfigValidator,
provideDefaultConfig,
provideDefaultConfigFactory,
} from '@spartacus/core';
import {
CdsConfig,
cdsConfigValidator,
defaultCdsConfigFactory,
} from './config';
import { MerchandisingModule } from './merchandising';
import {
ProfileTagModule,
@@ -15,7 +23,6 @@ import {
} from './profiletag';
import { RecentSearchesModule } from './recent-searches/recent-searches.module';
import { TrendingSearchesModule } from './trending-searches/trending-searches.module';

@NgModule({
imports: [
ProfileTagModule,
@@ -30,7 +37,7 @@ export class CdsModule {
return {
ngModule: CdsModule,
providers: [
provideDefaultConfig(DEFAULT_CDS_CONFIG),
provideDefaultConfigFactory(defaultCdsConfigFactory),
provideDefaultConfig(config),
provideConfigValidator(cdsConfigValidator),
ProfileTagPushEventsService,
1 change: 1 addition & 0 deletions integration-libs/cds/src/config/cds-config.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ export abstract class CdsConfig {
endpoints?: CdsEndpoints;
merchandising?: MerchandisingConfig;
profileTag?: ProfileTagConfig;
sciEnabled?: boolean;
};
}

31 changes: 14 additions & 17 deletions integration-libs/cds/src/config/default-cds-config.ts
Original file line number Diff line number Diff line change
@@ -6,21 +6,18 @@

import { CdsConfig } from './cds-config';

export const DEFAULT_CDS_CONFIG: CdsConfig = {
cds: {
tenant: '',
baseUrl: '',
endpoints: {
strategyProducts: '/strategy/${tenant}/strategies/${strategyId}/products',
searchIntelligence:
'/search-intelligence/v1/sites/${cdsSiteId}/trendingSearches',
export function defaultCdsConfigFactory(): CdsConfig {
return {
cds: {
tenant: '',
baseUrl: '',
merchandising: {
defaultCarouselViewportThreshold: 80,
},
consentTemplateId: 'PROFILE',
profileTag: {
allowInsecureCookies: false,
},
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
consentTemplateId: 'PROFILE',
profileTag: {
allowInsecureCookies: false,
},
},
};
};
}
1 change: 1 addition & 0 deletions integration-libs/cds/src/config/profile-tag.config.ts
Original file line number Diff line number Diff line change
@@ -9,4 +9,5 @@ export interface ProfileTagConfig {
configUrl?: string;
allowInsecureCookies?: boolean;
gtmId?: string;
sciEnabled?: boolean;
}
Original file line number Diff line number Diff line change
@@ -7,10 +7,17 @@ import { CdsEndpointsService } from '../../../services/cds-endpoints.service';
import { StrategyProducts } from '../../model/strategy-products.model';
import { CdsMerchandisingStrategyAdapter } from './cds-merchandising-strategy.adapter';
import createSpy = jasmine.createSpy;
import { BaseSiteService } from '@spartacus/core';
import { of } from 'rxjs';

const STRATEGY_ID = 'test-strategy-id';
const STRATEGY_PRODUCTS_ENDPOINT_KEY = 'strategyProducts';
const strategyIdObject = { strategyId: STRATEGY_ID };
const TEST_BASE_SITE = 'testBaseSite';

const TEST_URL_PARAMS = {
baseSite: TEST_BASE_SITE,
strategyId: STRATEGY_ID,
};

const expectedProductsFromStrategy: StrategyProducts = {
resultCount: 1,
@@ -46,7 +53,13 @@ const strategyRequestUndefinedConsentReference = {

class MockCdsEndpointsService {
getUrl = createSpy('MockCdsEndpointsService.getUrl').and.callFake(
(endpoint) => endpoint
(endpoint: string) => endpoint
);
}

class MockBaseSiteService {
getActive = createSpy('MockBaseSiteService.getActive').and.callFake(() =>
of(TEST_BASE_SITE)
);
}

@@ -63,6 +76,10 @@ describe('MerchandisingStrategyAdapter', () => {
provide: CdsEndpointsService,
useClass: MockCdsEndpointsService,
},
{
provide: BaseSiteService,
useClass: MockBaseSiteService,
},
CdsMerchandisingStrategyAdapter,
],
});
@@ -123,7 +140,7 @@ describe('MerchandisingStrategyAdapter', () => {

expect(cdsEndpointsService.getUrl).toHaveBeenCalledWith(
STRATEGY_PRODUCTS_ENDPOINT_KEY,
strategyIdObject,
TEST_URL_PARAMS,
strategyRequest.queryParams
);

@@ -156,7 +173,7 @@ describe('MerchandisingStrategyAdapter', () => {

expect(cdsEndpointsService.getUrl).toHaveBeenCalledWith(
STRATEGY_PRODUCTS_ENDPOINT_KEY,
strategyIdObject,
TEST_URL_PARAMS,
strategyRequest.queryParams
);

Original file line number Diff line number Diff line change
@@ -6,11 +6,12 @@

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Observable, switchMap, take } from 'rxjs';
import { CdsEndpointsService } from '../../../services/cds-endpoints.service';
import { MerchandisingStrategyAdapter } from '../../connectors/strategy/merchandising-strategy.adapter';
import { StrategyProducts } from '../../model/strategy-products.model';
import { StrategyRequest } from './../../../cds-models/cds-strategy-request.model';
import { BaseSiteService } from '@spartacus/core';

const STRATEGY_PRODUCTS_ENDPOINT_KEY = 'strategyProducts';

@@ -20,6 +21,7 @@ export class CdsMerchandisingStrategyAdapter
{
constructor(
private cdsEndpointsService: CdsEndpointsService,
private baseSiteService: BaseSiteService,
protected http: HttpClient
) {}

@@ -34,15 +36,21 @@ export class CdsMerchandisingStrategyAdapter
strategyRequest.headers.consentReference
);
}
return this.http.get(
this.cdsEndpointsService.getUrl(
STRATEGY_PRODUCTS_ENDPOINT_KEY,
{
strategyId,
},
strategyRequest.queryParams
),
{ headers }
return this.baseSiteService.getActive().pipe(
take(1),
switchMap((baseSite) =>
this.http.get(
this.cdsEndpointsService.getUrl(
STRATEGY_PRODUCTS_ENDPOINT_KEY,
{
baseSite,
strategyId,
},
strategyRequest.queryParams
),
{ headers }
)
)
);
}
}
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ export interface ProfileTagJsConfig {
configUrl?: string;
allowInsecureCookies?: boolean;
gtmId?: string;
sciEnabled?: boolean;
}

export interface ConsentReferenceEvent extends CustomEvent {
@@ -53,14 +54,14 @@ export interface ProfileTagPushEvent {
export class NavigatedPushEvent implements ProfileTagPushEvent {
name = 'Navigated';
data: any;
constructor(data?) {
constructor(data?: any) {
this.data = data;
}
}

export class ConsentChangedPushEvent implements ProfileTagPushEvent {
name = 'ConsentChanged';
data: { granted: boolean } = { granted: undefined };
data: { granted?: boolean } = { granted: undefined };
constructor(granted: boolean) {
this.data.granted = granted;
}
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ const mockCDSConfig: CdsConfig = {
configUrl: 'https:tag.static.us.context.cloud.sap',
allowInsecureCookies: false,
gtmId: 'test-id-1234567',
sciEnabled: false,
},
},
};
Original file line number Diff line number Diff line change
@@ -144,6 +144,6 @@ describe('RecentSearchesComponent', () => {

expect(() => {
component.shareEvent(ev);
}).toThrowError();
}).toThrow();
});
});
Original file line number Diff line number Diff line change
@@ -21,9 +21,6 @@ import { I18nConfig, provideConfig } from "@spartacus/core";
cds: {
tenant: 'my-tenant',
baseUrl: 'my-base-url.com',
endpoints: {
strategyProducts: '/strategy/\${tenant}/strategies/\${strategyId}/products',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
@@ -67,9 +64,6 @@ import { I18nConfig, provideConfig } from "@spartacus/core";
cds: {
tenant: 'my-tenant',
baseUrl: 'my-base-url.com',
endpoints: {
strategyProducts: '/strategy/\${tenant}/strategies/\${strategyId}/products',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
Original file line number Diff line number Diff line change
@@ -68,9 +68,6 @@ function buildCdsConfig(
cds: {
tenant: '${options.tenant || 'TENANT_PLACEHOLDER'}',
baseUrl: '${options.baseUrl || 'BASE_URL_PLACEHOLDER'}',
endpoints: {
strategyProducts: '/strategy/\${tenant}/strategies/\${strategyId}/products',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
Original file line number Diff line number Diff line change
@@ -16,31 +16,48 @@ import {
cdsTranslationChunksConfig,
cdsTranslations,
} from '@spartacus/cds/assets';
import { environment } from '../../../../environments/environment';

/**
* Only differences to the default cds config, they are merged together.
*
* @see defaultCdsConfigFactory
* @see CdsModule.forRoot
*/

const sciEnabled = environment.sciEnabled;

const cds1: CdsConfig = {
cds: {
baseSite: ['electronics-spa', 'electronics', 'electronics-standalone'],
tenant: 'argotest',
baseUrl: 'https://api.stage.context.cloud.sap',
endpoints: {
strategyProducts: '/strategy/${tenant}/strategies/${strategyId}/products',
strategyProducts: sciEnabled
? '/strategy/v1/sites/${baseSite}/strategies/${strategyId}/products'
: '/strategy/${tenant}/strategies/${strategyId}/products',
searchIntelligence:
'/search-intelligence/v1/sites/${cdsSiteId}/trendingSearches',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
profileTag: {
javascriptUrl:
'https://tag.static.stage.context.cloud.sap/js/profile-tag.js',
configUrl:
'https://tag.static.stage.context.cloud.sap/config/mytenant-main-default',
configUrl: sciEnabled
? 'https://tag.static.stage.context.cloud.sap/config/profiletag-default-config'
: 'https://tag.static.stage.context.cloud.sap/config/mytenant-main-default',
allowInsecureCookies: true,
sciEnabled: sciEnabled,
},
},
};

const cds2 = {
/**
* Only differences to the default cds config, they are merged together.
*
* @see defaultCdsConfigFactory
* @see CdsModule.forRoot
*/
const cds2: CdsConfig = {
cds: {
baseSite: [
'apparel-de',
@@ -51,24 +68,26 @@ const cds2 = {
tenant: 'A_CDS_TENANT',
baseUrl: 'A_CDS_BASE_URL',
endpoints: {
strategyProducts: '/strategy/${tenant}/strategies/${strategyId}/products',
strategyProducts: sciEnabled
? '/strategy/v1/sites/${baseSite}/strategies/${strategyId}/products'
: '/strategy/${tenant}/strategies/${strategyId}/products',
searchIntelligence:
'/search-intelligence/v1/sites/${cdsSiteId}/trendingSearches',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
profileTag: {
javascriptUrl: 'A_CDS_PROFILE_TAG_LOAD_URL',
configUrl: 'A_CDS_PROFILE_TAG_CONFIG_URL',
configUrl: sciEnabled
? 'https://tag.static.stage.context.cloud.sap/config/profiletag-default-config'
: 'A_CDS_PROFILE_TAG_CONFIG_URL',
allowInsecureCookies: true,
sciEnabled: sciEnabled,
},
},
};

const cdsConfigArray = [cds1, cds2];
function cdsConfigFactory(windowRef: WindowRef): CdsConfig {
const cdsConfigArray = [cds1, cds2];

const cdsConfig = (windowRef: WindowRef): CdsConfig => {
if (!windowRef.isBrowser()) {
return cds1;
}
@@ -78,7 +97,7 @@ const cdsConfig = (windowRef: WindowRef): CdsConfig => {
);
});
return cds ?? cds1;
};
}

@NgModule({
imports: [CdsModule.forRoot()],
@@ -90,7 +109,7 @@ const cdsConfig = (windowRef: WindowRef): CdsConfig => {
fallbackLang: 'en',
},
}),
provideConfigFactory(cdsConfig, [WindowRef]),
provideConfigFactory(cdsConfigFactory, [WindowRef]),
],
})
export class CdsFeatureModule {}
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ export const environment: Environment = {
occBaseUrl: buildProcess.env.CX_BASE_URL,
occApiPrefix: '/occ/v2/',
cds: buildProcess.env.CX_CDS,
sciEnabled: buildProcess.env.CX_SCI,
b2b: buildProcess.env.CX_B2B,
cdc: buildProcess.env.CX_CDC,
cdp: buildProcess.env.CX_CDP,
Loading