Skip to content

Commit

Permalink
fix: parameters ;loc and ;cur may overlook server configuration
Browse files Browse the repository at this point in the history
When the first page of the site is displayed, requests can be sent to the icm before the redux
ServerConfiguration store is initialized. This can be problematic in the case of localized URLs such
as content retrieval, as the icm channel configuration can influence the value of the ;loc and ;cur
parameters.
  • Loading branch information
tbouliere-datasolution authored and Eisie96 committed Jun 13, 2023
1 parent 7d0cd7e commit ff102e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/app/core/services/api/api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from 'ish-core/store/core/configuration';
import { CoreStoreModule } from 'ish-core/store/core/core-store.module';
import { serverError } from 'ish-core/store/core/error';
import { loadServerConfigSuccess } from 'ish-core/store/core/server-config';
import { isServerConfigurationLoaded, loadServerConfigSuccess } from 'ish-core/store/core/server-config';
import { getPGID } from 'ish-core/store/customer/user';

import { ApiService, unpackEnvelope } from './api.service';
Expand All @@ -39,6 +39,7 @@ describe('Api Service', () => {
providers: [
provideMockStore({
selectors: [
{ selector: isServerConfigurationLoaded, value: true },
{ selector: getRestEndpoint, value: 'http://www.example.org/WFS/site/-' },
{ selector: getICMServerURL, value: undefined },
{ selector: getCurrentCurrency, value: 'USD' },
Expand Down Expand Up @@ -198,6 +199,7 @@ describe('Api Service', () => {
providers: [
provideMockStore({
selectors: [
{ selector: isServerConfigurationLoaded, value: true },
{ selector: getRestEndpoint, value: 'http://www.example.org/WFS/site/-' },
{ selector: getICMServerURL, value: 'http://www.example.org/WFS' },
{ selector: getCurrentCurrency, value: 'USD' },
Expand Down Expand Up @@ -402,6 +404,7 @@ describe('Api Service', () => {
providers: [
provideMockStore({
selectors: [
{ selector: isServerConfigurationLoaded, value: true },
{ selector: getRestEndpoint, value: 'http://www.example.org/WFS/site/-' },
{ selector: getICMServerURL, value: undefined },
{ selector: getCurrentLocale, value: undefined },
Expand Down Expand Up @@ -679,6 +682,7 @@ describe('Api Service', () => {
providers: [
provideMockStore({
selectors: [
{ selector: isServerConfigurationLoaded, value: true },
{ selector: getICMServerURL, value: undefined },
{ selector: getRestEndpoint, value: 'http://www.example.org' },
{ selector: getCurrentLocale, value: 'en' },
Expand Down
23 changes: 18 additions & 5 deletions src/app/core/services/api/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
of,
throwError,
} from 'rxjs';
import { catchError, concatMap, filter, first, map, take, withLatestFrom } from 'rxjs/operators';
import { catchError, concatMap, filter, first, map, switchMap, take, withLatestFrom } from 'rxjs/operators';

import { Captcha } from 'ish-core/models/captcha/captcha.model';
import { Link } from 'ish-core/models/link/link.model';
Expand All @@ -25,6 +25,7 @@ import {
getRestEndpoint,
} from 'ish-core/store/core/configuration';
import { communicationTimeoutError, serverError } from 'ish-core/store/core/error';
import { isServerConfigurationLoaded } from 'ish-core/store/core/server-config';
import { getLoggedInCustomer, getLoggedInUser, getPGID } from 'ish-core/store/customer/user';
import { whenTruthy } from 'ish-core/utils/operators';
import { encodeResourceID } from 'ish-core/utils/url-resource-ids';
Expand Down Expand Up @@ -152,19 +153,31 @@ export class ApiService {
private getLocale$(options: AvailableOptions): Observable<string> {
return options?.sendLocale === undefined || options.sendLocale
? this.store.pipe(
select(getCurrentLocale),
select(isServerConfigurationLoaded),
whenTruthy(),
map(l => `;loc=${l}`)
switchMap(() =>
this.store.pipe(
select(getCurrentLocale),
whenTruthy(),
map(l => `;loc=${l}`)
)
)
)
: of('');
}

private getCurrency$(options: AvailableOptions): Observable<string> {
return options?.sendCurrency === undefined || options.sendCurrency
? this.store.pipe(
select(getCurrentCurrency),
select(isServerConfigurationLoaded),
whenTruthy(),
map(l => `;cur=${l}`)
switchMap(() =>
this.store.pipe(
select(getCurrentCurrency),
whenTruthy(),
map(l => `;cur=${l}`)
)
)
)
: of('');
}
Expand Down

0 comments on commit ff102e3

Please sign in to comment.