Skip to content

Commit

Permalink
CXCDS-13546 - Remove Spartacus Feature Toggle Code from December rele…
Browse files Browse the repository at this point in the history
…ase (SAP#19664)
  • Loading branch information
SebastianHamilton authored Nov 29, 2024
1 parent 6e16fc3 commit 392ecd6
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 107 deletions.
14 changes: 3 additions & 11 deletions integration-libs/cds/src/cds.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@
*/

import { ModuleWithProviders, NgModule } from '@angular/core';
import {
provideConfigValidator,
provideDefaultConfig,
provideDefaultConfigFactory,
} from '@spartacus/core';
import {
CdsConfig,
cdsConfigValidator,
defaultCdsConfigFactory,
} from './config';
import { provideConfigValidator, provideDefaultConfig } from '@spartacus/core';
import { CdsConfig, cdsConfigValidator, DEFAULT_CDS_CONFIG } from './config';
import { MerchandisingModule } from './merchandising';
import {
ProfileTagModule,
Expand All @@ -38,7 +30,7 @@ export class CdsModule {
return {
ngModule: CdsModule,
providers: [
provideDefaultConfigFactory(defaultCdsConfigFactory),
provideDefaultConfig(DEFAULT_CDS_CONFIG),
provideDefaultConfig(config),
provideConfigValidator(cdsConfigValidator),
ProfileTagPushEventsService,
Expand Down
43 changes: 17 additions & 26 deletions integration-libs/cds/src/config/default-cds-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,23 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { inject } from '@angular/core';
import { CdsConfig } from './cds-config';
import { FeatureToggles } from '@spartacus/core';

export function defaultCdsConfigFactory(): CdsConfig {
const featureToggles = inject(FeatureToggles);
const sciEnabled = featureToggles.sciEnabled;
return {
cds: {
tenant: '',
baseUrl: '',
endpoints: {
strategyProducts: sciEnabled
? '/strategy/v1/sites/${baseSite}/strategies/${strategyId}/products'
: '/strategy/${tenant}/strategies/${strategyId}/products',
searchIntelligence:
'/search-intelligence/v1/sites/${cdsSiteId}/trendingSearches',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
consentTemplateId: 'PROFILE',
profileTag: {
allowInsecureCookies: false,
sciEnabled: sciEnabled,
},
export const DEFAULT_CDS_CONFIG: CdsConfig = {
cds: {
tenant: '',
baseUrl: '',
endpoints: {
strategyProducts: '/strategy/${tenant}/strategies/${strategyId}/products',
searchIntelligence:
'/search-intelligence/v1/sites/${cdsSiteId}/trendingSearches',
},
};
}
merchandising: {
defaultCarouselViewportThreshold: 80,
},
consentTemplateId: 'PROFILE',
profileTag: {
allowInsecureCookies: false,
},
},
};
1 change: 0 additions & 1 deletion integration-libs/cds/src/config/profile-tag.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ export interface ProfileTagConfig {
configUrl?: string;
allowInsecureCookies?: boolean;
gtmId?: string;
sciEnabled?: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,10 @@ 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 TEST_BASE_SITE = 'testBaseSite';

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

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

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

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

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

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

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

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

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

import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable, switchMap, take } from 'rxjs';
import { Observable } 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';

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

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

export interface ConsentReferenceEvent extends CustomEvent {
Expand Down Expand Up @@ -54,14 +53,14 @@ export interface ProfileTagPushEvent {
export class NavigatedPushEvent implements ProfileTagPushEvent {
name = 'Navigated';
data: any;
constructor(data?: any) {
constructor(data?) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const mockCDSConfig: CdsConfig = {
configUrl: 'https:tag.static.us.context.cloud.sap',
allowInsecureCookies: false,
gtmId: 'test-id-1234567',
sciEnabled: false,
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,6 @@ describe('RecentSearchesComponent', () => {

expect(() => {
component.shareEvent(ev);
}).toThrow();
}).toThrowError();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ 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,
},
Expand Down Expand Up @@ -64,6 +67,9 @@ 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,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -788,12 +788,6 @@ export interface FeatureTogglesInterface {
*/
a11yPdpGridArrangement?: boolean;

/**
* CDS/ISS is integrated into the SAP Cloud Identity Service (SCI). The downstream services use different domains and URL formats.
* This feature toggle can be used to make the CDS module use these new URLs.
*/
sciEnabled?: boolean;

/**
* When enabled, allows to provide extended formats and media queries for <picture> element if used in MediaComponent.
*
Expand Down Expand Up @@ -962,7 +956,6 @@ export const defaultFeatureToggles: Required<FeatureTogglesInterface> = {
enablePasswordsCannotMatchInPasswordUpdateForm: false,
allPageMetaResolversEnabledInCsr: false,
a11yPdpGridArrangement: false,
sciEnabled: false,
useExtendedMediaComponentConfiguration: false,
showRealTimeStockInPDP: false,
enableSecurePasswordValidation: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ function buildCdsConfig(
cds: {
tenant: '${options.tenant || 'TENANT_PLACEHOLDER'}',
baseUrl: '${options.baseUrl || 'BASE_URL_PLACEHOLDER'}',
endpoints: {
strategyProducts: '/strategy/\${tenant}/strategies/\${strategyId}/products',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@ import {
cdsTranslations,
} from '@spartacus/cds/assets';

/**
* Only differences to the default cds config, they are merged together.
*
* @see defaultCdsConfigFactory
* @see CdsModule.forRoot
*/
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',
searchIntelligence:
'/search-intelligence/v1/sites/${cdsSiteId}/trendingSearches',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
profileTag: {
javascriptUrl:
'https://tag.static.stage.context.cloud.sap/js/profile-tag.js',
Expand All @@ -38,13 +40,7 @@ const cds1: CdsConfig = {
},
};

/**
* Only differences to the default cds config, they are merged together.
*
* @see defaultCdsConfigFactory
* @see CdsModule.forRoot
*/
const cds2: CdsConfig = {
const cds2 = {
cds: {
baseSite: [
'apparel-de',
Expand All @@ -54,6 +50,14 @@ const cds2: CdsConfig = {
],
tenant: 'A_CDS_TENANT',
baseUrl: 'A_CDS_BASE_URL',
endpoints: {
strategyProducts: '/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',
Expand All @@ -62,9 +66,9 @@ const cds2: CdsConfig = {
},
};

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

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

@NgModule({
imports: [CdsModule.forRoot()],
Expand All @@ -86,7 +90,7 @@ function cdsConfigFactory(windowRef: WindowRef): CdsConfig {
fallbackLang: 'en',
},
}),
provideConfigFactory(cdsConfigFactory, [WindowRef]),
provideConfigFactory(cdsConfig, [WindowRef]),
],
})
export class CdsFeatureModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,6 @@ if (environment.cpq) {
enablePasswordsCannotMatchInPasswordUpdateForm: true,
allPageMetaResolversEnabledInCsr: true,
a11yPdpGridArrangement: true,
sciEnabled: false,
useExtendedMediaComponentConfiguration: true,
showRealTimeStockInPDP: false,
a11yWrapReviewOrderInSection: true,
Expand Down

0 comments on commit 392ecd6

Please sign in to comment.