Skip to content

Commit

Permalink
CXCDS-14100: move SCI configuration from .env to schematics-config (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
johannathalmann-SAP authored Feb 7, 2025
1 parent b0d19eb commit 944b991
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 38 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
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
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 @@ -22,7 +22,6 @@ export interface ProfileTagJsConfig {
configUrl?: string;
allowInsecureCookies?: boolean;
gtmId?: string;
sciEnabled?: boolean;
}

export interface ConsentReferenceEvent extends CustomEvent {
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 @@ -21,6 +21,59 @@ import { I18nConfig, provideConfig } from "@spartacus/core";
cds: {
tenant: 'my-tenant',
baseUrl: 'my-base-url.com',
endpoints: {
strategyProducts: '/strategy/\${tenant}/strategies/\${strategyId}/products',
searchIntelligence:
'/search-intelligence/v1/sites/\${cdsSiteId}/trendingSearches',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
},
}),
provideConfig(<CdsConfig>{
cds: {
profileTag: {
javascriptUrl:
'profile-tag-load-url.com',
configUrl:
'profile-tag-config-url.com',
allowInsecureCookies: true
},
},
})
]
})
export class CdsFeatureModule { }
"
`;
exports[`Spartacus CDS schematics: ng-add CDS feature with sciEnabled option set to true general setup should create the feature module 1`] = `
"import { NgModule } from '@angular/core';
import { CdsConfig, CdsModule } from "@spartacus/cds";
import { cdsTranslationChunksConfig, cdsTranslationsEn } from "@spartacus/cds/assets";
import { I18nConfig, provideConfig } from "@spartacus/core";
@NgModule({
declarations: [],
imports: [
CdsModule.forRoot()
],
providers: [provideConfig(<I18nConfig>{
i18n: {
resources: { en: cdsTranslationsEn },
chunks: cdsTranslationChunksConfig,
},
}),
provideConfig(<CdsConfig>{
cds: {
tenant: 'my-tenant',
baseUrl: 'my-base-url.com',
endpoints: {
strategyProducts: '/strategy/v1/sites/\${baseSite}/strategies/\${strategyId}/products',
searchIntelligence:
'/search-intelligence/v1/sites/\${cdsSiteId}/trendingSearches',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
Expand All @@ -33,7 +86,7 @@ import { I18nConfig, provideConfig } from "@spartacus/core";
'profile-tag-load-url.com',
configUrl:
'profile-tag-config-url.com',
allowInsecureCookies: true,
allowInsecureCookies: true
},
},
})
Expand Down Expand Up @@ -64,6 +117,11 @@ import { I18nConfig, provideConfig } from "@spartacus/core";
cds: {
tenant: 'my-tenant',
baseUrl: 'my-base-url.com',
endpoints: {
strategyProducts: '/strategy/\${tenant}/strategies/\${strategyId}/products',
searchIntelligence:
'/search-intelligence/v1/sites/\${cdsSiteId}/trendingSearches',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
Expand All @@ -76,7 +134,7 @@ import { I18nConfig, provideConfig } from "@spartacus/core";
'PROFILE_TAG_LOAD_URL_PLACEHOLDER',
configUrl:
'PROFILE_TAG_CONFIG_URL_PLACEHOLDER',
allowInsecureCookies: true,
allowInsecureCookies: true
},
},
})
Expand Down
33 changes: 33 additions & 0 deletions integration-libs/cds/src/schematics/add-cds/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,38 @@ describe('Spartacus CDS schematics: ng-add', () => {
});
});
});

describe('with sciEnabled option set to true', () => {
beforeAll(async () => {
appTree = await generateDefaultWorkspace(schematicRunner, appTree);
appTree = await schematicRunner.runSchematic(
'ng-add',
{
...cdsFeatureOptions,
profileTagConfigUrl: 'profile-tag-config-url.com',
profileTagLoadUrl: 'profile-tag-load-url.com',
sciEnabled: true,
},
appTree
);
});

describe('general setup', () => {
it('should create the feature module', async () => {
const module = appTree.readContent(cdsFeatureModulePath);
expect(module).toMatchSnapshot();
});

it('should NOT install the required feature dependencies', async () => {
const userFeatureModule = appTree.readContent(userFeatureModulePath);
expect(userFeatureModule).toBeFalsy();

const trackingPersonalizationFeatureModule = appTree.readContent(
trackingPersonalizationFeatureModulePath
);
expect(trackingPersonalizationFeatureModule).toBeFalsy();
});
});
});
});
});
6 changes: 6 additions & 0 deletions integration-libs/cds/src/schematics/add-cds/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@
"type": "string",
"description": "Configuration URL for ProfileTag. (e.g. https://tag.static.stage.context.cloud.sap/config/my-config123)",
"x-prompt": "[CDS] What is the ProfileTag configuration URL?"
},
"sciEnabled": {
"type": "boolean",
"description": "CDS/ISS is integrated into the SAP Cloud Identity Service (SCI). The downstream services use different domains and URL formats. To enable SCI, enable this parameter and make sure to use the proper profile tag urls (see documentation).",
"default": false,
"x-prompt": "[CDS] Do you want to enable SCI?"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface SpartacusCdsOptions extends LibraryOptions {
baseUrl?: string;
profileTagLoadUrl?: string;
profileTagConfigUrl?: string;
sciEnabled?: boolean;
}

export const CDS_FOLDER_NAME = 'cds';
Expand Down Expand Up @@ -68,6 +69,15 @@ function buildCdsConfig(
cds: {
tenant: '${options.tenant || 'TENANT_PLACEHOLDER'}',
baseUrl: '${options.baseUrl || 'BASE_URL_PLACEHOLDER'}',
endpoints: {
strategyProducts: '${
options.sciEnabled
? '/strategy/v1/sites/${baseSite}/strategies/${strategyId}/products'
: '/strategy/${tenant}/strategies/${strategyId}/products'
}',
searchIntelligence:
'/search-intelligence/v1/sites/\${cdsSiteId}/trendingSearches',
},
merchandising: {
defaultCarouselViewportThreshold: 80,
},
Expand Down Expand Up @@ -96,7 +106,7 @@ function buildCdsConfig(
options.profileTagConfigUrl ||
'PROFILE_TAG_CONFIG_URL_PLACEHOLDER'
}',
allowInsecureCookies: true,
allowInsecureCookies: true
},
},
}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
cdsTranslationsDe,
cdsTranslationsZh,
} from '@spartacus/cds/assets';
import { environment } from '../../../../environments/environment';

/**
* Only differences to the default cds config, they are merged together.
Expand All @@ -28,28 +27,17 @@ import { environment } from '../../../../environments/environment';
* @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',
searchIntelligence:
'/search-intelligence/v1/sites/${cdsSiteId}/trendingSearches',
},
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,
},
},
};
Expand All @@ -70,20 +58,10 @@ 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',
searchIntelligence:
'/search-intelligence/v1/sites/${cdsSiteId}/trendingSearches',
},
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,
},
},
};
Expand Down
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
1 change: 0 additions & 1 deletion projects/storefrontapp/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const environment: Environment = {
occBaseUrl: buildProcess.env.CX_BASE_URL,
occApiPrefix: '/occ/v2/',
cds: buildProcess.env.CX_CDS ?? false,
sciEnabled: buildProcess.env.CX_SCI ?? false,
b2b: buildProcess.env.CX_B2B ?? false,
cdc: buildProcess.env.CX_CDC ?? false,
cdp: buildProcess.env.CX_CDP ?? false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface BuildProcess {
interface Env {
CX_BASE_URL: string;
CX_CDS: boolean;
CX_SCI: boolean;
CX_CDC: boolean;
CX_CDP: boolean;
CX_B2B: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export interface Environment {
occApiPrefix: string;
b2b: boolean;
cds: boolean;
sciEnabled: boolean;
cdc: boolean;
cdp: boolean;
cpq: boolean;
Expand Down

0 comments on commit 944b991

Please sign in to comment.