Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,14 @@ export interface FeatureTogglesInterface {
* Affects: `ReturnOrderComponent`
*/
enableReturnOrderReturnableQuantityConsigmentFallback?: boolean;
/**
* When enabled, all cross-site requests will include credentials (cookies, HTTP authentication entries, and client-side SSL certificates).
* This is needed to support scenarios where the backend services are hosted on a different domain than the Spartacus storefront,
* and the authentication cookies need to be sent with the requests to maintain the user session.
*
* Affects: `WithCredentialsInterceptor`
*/
enableWithCredentialsByDefault?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick]
This change affects only calls to OCC.
let's reflect it in the toggle name, e.g.:
occWithCredentialsByDefault

PS. I was never a fan of using the word enable in the toggles names. They should describe the change in behavior and that's it. By setting it to true, we just enable it 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, fully agreed with this suggestion, thanks 👍🏼

}

export const defaultFeatureToggles: Required<FeatureTogglesInterface> = {
Expand Down Expand Up @@ -759,4 +767,5 @@ export const defaultFeatureToggles: Required<FeatureTogglesInterface> = {
navigationMenuCloseOnSameLinkClick: false,
enableQuotePurchaseOrderNumber: false,
enableReturnOrderReturnableQuantityConsigmentFallback: false,
enableWithCredentialsByDefault: true,
};
54 changes: 54 additions & 0 deletions projects/core/src/occ/config/default-occ-config-factory.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { TestBed } from '@angular/core/testing';
import { provideFeatureToggles } from '@spartacus/core';
import { defaultOccConfig } from './default-occ-config';
import { defaultOccConfigFactory } from './default-occ-config-factory';

describe('defaultOccConfigFactory', () => {
it('should not modify useWithCredentials when no feature toggle is provided', () => {
TestBed.configureTestingModule({
providers: [],
});

const result = TestBed.runInInjectionContext(defaultOccConfigFactory);

expect(result).toEqual(defaultOccConfig);
expect(result.backend?.occ?.useWithCredentials).toBeUndefined();
});

it('should not modify useWithCredentials when feature toggle is disabled', () => {
TestBed.configureTestingModule({
providers: [
provideFeatureToggles({ enableWithCredentialsByDefault: false }),
],
});

const result = TestBed.runInInjectionContext(defaultOccConfigFactory);

expect(result).toEqual(defaultOccConfig);
expect(result.backend?.occ?.useWithCredentials).toBeUndefined();
});

it('should set useWithCredentials to true when feature toggle is enabled', () => {
TestBed.configureTestingModule({
providers: [
provideFeatureToggles({ enableWithCredentialsByDefault: true }),
],
});

const result = TestBed.runInInjectionContext(defaultOccConfigFactory);

const expectedConfig = {
...defaultOccConfig,
backend: {
...defaultOccConfig.backend,
occ: {
...defaultOccConfig.backend?.occ,
useWithCredentials: true,
},
},
};

expect(result).toEqual(expectedConfig);
expect(result.backend?.occ?.useWithCredentials).toBe(true);
});
});
22 changes: 22 additions & 0 deletions projects/core/src/occ/config/default-occ-config-factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* SPDX-FileCopyrightText: 2025 SAP Spartacus team <[email protected]>
*
* SPDX-License-Identifier: Apache-2.0
*/

import { inject } from '@angular/core';
import { FeatureToggles } from '@spartacus/core';
import { defaultOccConfig } from './default-occ-config';
import { OccConfig } from './occ-config';

export function defaultOccConfigFactory(): OccConfig {
const featureToggles = inject(FeatureToggles);
const config = { ...defaultOccConfig };

if (featureToggles.enableWithCredentialsByDefault) {
if (config.backend && config.backend.occ) {
config.backend.occ.useWithCredentials = true;
}
}
return config;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
mediaConfig,
PWAModuleConfig,
} from '@spartacus/storefront';
import { defaultOccConfigFactory } from 'projects/core/src/occ/config/default-occ-config-factory';
import { environment } from '../../environments/environment';

let baseSite = ['powertools-spa', 'powertools-standalone'];
Expand Down Expand Up @@ -47,6 +48,7 @@ if (environment.epdVisualization) {
addToHomeScreen: true,
},
}),
provideConfigFactory(defaultOccConfigFactory),
],
})
export class SpartacusB2bConfigurationModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
mediaConfig,
PWAModuleConfig,
} from '@spartacus/storefront';
import { defaultOccConfigFactory } from 'projects/core/src/occ/config/default-occ-config-factory';
import { environment } from '../../environments/environment';

const defaultBaseSite = [
Expand Down Expand Up @@ -57,6 +58,7 @@ const baseSite = environment.epdVisualization
},
},
}),
provideConfigFactory(defaultOccConfigFactory),
],
})
export class SpartacusB2cConfigurationModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ if (environment.cpq) {
navigationMenuCloseOnSameLinkClick: true,
enableQuotePurchaseOrderNumber: false,
enableReturnOrderReturnableQuantityConsigmentFallback: true,
enableWithCredentialsByDefault: true,
};
return appFeatureToggles;
}),
Expand Down
Loading