Skip to content

Commit

Permalink
Revert "CXCDS-13558: Change implementation for Spartacus CAS support (#…
Browse files Browse the repository at this point in the history
…19869)"

This reverts commit e20db8b.
  • Loading branch information
Radhep committed Jan 24, 2025
1 parent 62cf211 commit 90dd015
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 112 deletions.
3 changes: 1 addition & 2 deletions .env-cmdrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"CX_BASE_URL": "https://api.cg79x9wuu9-eccommerc1-p1-public.model-t.myhybris.cloud"
},
"cds": {
"CX_CDS": "true",
"CX_SCI": "false"
"CX_CDS": "true"
},
"lighthouse": {
"CX_BASE_URL": "https://api.spartacus.rocks"
Expand Down
15 changes: 4 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 @@ -23,6 +15,7 @@ import {
} from './profiletag';
import { RecentSearchesModule } from './recent-searches/recent-searches.module';
import { TrendingSearchesModule } from './trending-searches/trending-searches.module';

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

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

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

export function defaultCdsConfigFactory(): CdsConfig {
return {
cds: {
tenant: '',
baseUrl: '',
merchandising: {
defaultCarouselViewportThreshold: 80,
},
consentTemplateId: 'PROFILE',
profileTag: {
allowInsecureCookies: false,
},
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 @@ -11,17 +11,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 @@ -57,13 +50,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 @@ -80,10 +67,6 @@ describe('MerchandisingStrategyAdapter', () => {
provide: CdsEndpointsService,
useClass: MockCdsEndpointsService,
},
{
provide: BaseSiteService,
useClass: MockBaseSiteService,
},
CdsMerchandisingStrategyAdapter,
provideHttpClient(withInterceptorsFromDi()),
provideHttpClientTesting(),
Expand Down Expand Up @@ -146,7 +129,7 @@ describe('MerchandisingStrategyAdapter', () => {

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

Expand Down Expand Up @@ -179,7 +162,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 @@ -145,6 +145,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 @@ -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 @@ -19,48 +19,31 @@ import {
cdsTranslationsDe,
cdsTranslationsZh,
} 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: sciEnabled
? '/strategy/v1/sites/${baseSite}/strategies/${strategyId}/products'
: '/strategy/${tenant}/strategies/${strategyId}/products',
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',
configUrl: sciEnabled
? 'https://tag.static.stage.context.cloud.sap/config/profiletag-default-config'
: 'https://tag.static.stage.context.cloud.sap/config/mytenant-main-default',
configUrl:
'https://tag.static.stage.context.cloud.sap/config/mytenant-main-default',
allowInsecureCookies: true,
sciEnabled: sciEnabled,
},
},
};

/**
* 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 @@ -71,26 +54,24 @@ const cds2: CdsConfig = {
tenant: 'A_CDS_TENANT',
baseUrl: 'A_CDS_BASE_URL',
endpoints: {
strategyProducts: sciEnabled
? '/strategy/v1/sites/${baseSite}/strategies/${strategyId}/products'
: '/strategy/${tenant}/strategies/${strategyId}/products',
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: sciEnabled
? 'https://tag.static.stage.context.cloud.sap/config/profiletag-default-config'
: 'A_CDS_PROFILE_TAG_CONFIG_URL',
configUrl: 'A_CDS_PROFILE_TAG_CONFIG_URL',
allowInsecureCookies: true,
sciEnabled: sciEnabled,
},
},
};

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 @@ -100,7 +81,7 @@ function cdsConfigFactory(windowRef: WindowRef): CdsConfig {
);
});
return cds ?? cds1;
}
};

@NgModule({
imports: [CdsModule.forRoot()],
Expand All @@ -117,7 +98,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 @@ -11,7 +11,6 @@ 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,
Expand Down
Loading

0 comments on commit 90dd015

Please sign in to comment.