Skip to content

Commit

Permalink
feat: complex configuration can be supplied as yaml (#1133)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhhyi authored Jul 22, 2022
1 parent d5155d3 commit 4a71df7
Show file tree
Hide file tree
Showing 11 changed files with 313 additions and 126 deletions.
20 changes: 13 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,19 @@ services:
# activeThemes: b2b
# activeThemes: b2c
environment:
- LOGGING=on
- SOURCE_MAPS=on
- ICM_BASE_URL
# - PROXY_ICM=true
- TRUST_ICM=true
# - PROMETHEUS=on
# - MULTI_SITE_LOCALE_MAP={"en_US":"/en","de_DE":"/de","fr_FR":"/fr"}
LOGGING: 'true'
SOURCE_MAPS: 'true'
ICM_BASE_URL:
# PROXY_ICM: 'true'
TRUST_ICM: 'true'
# PROMETHEUS: 'true'
# MULTI_SITE_LOCALE_MAP: |
# en_US: /en
# de_DE: /de
# fr_FR: /fr
# FEATURES: |
# - compare
# - rating

# <CDN-Example>
# add 127.0.0.1 mypwa.net to your hosts file and
Expand Down
136 changes: 44 additions & 92 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"express-http-proxy": "^1.6.3",
"express-robots-txt": "1.0.0",
"file-replace-loader": "^1.4.0",
"js-yaml": "^4.1.0",
"lodash-es": "^4.17.21",
"morgan": "^1.10.0",
"ng-recaptcha": "^10.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { payload } from 'ish-core/utils/ngrx-creators';

import { ConfigurationState } from './configuration.reducer';

type ConfigurationType = Partial<ConfigurationState>;
export type ConfigurationType = Partial<ConfigurationState>;

export const applyConfiguration = createAction('[Configuration] Apply Configuration', payload<ConfigurationType>());

Expand Down
23 changes: 9 additions & 14 deletions src/app/core/store/core/configuration/configuration.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { StatePropertiesService } from 'ish-core/utils/state-transfer/state-prop

import {
applyConfiguration,
ConfigurationType,
loadSingleServerTranslation,
loadSingleServerTranslationSuccess,
} from './configuration.actions';
Expand Down Expand Up @@ -73,20 +74,14 @@ export class ConfigurationEffects {
this.stateProperties
.getStateOrEnvOrDefault<string>('ICM_IDENTITY_PROVIDER', 'identityProvider')
.pipe(map(x => x || 'ICM')),
this.stateProperties
.getStateOrEnvOrDefault<string | object>('IDENTITY_PROVIDERS', 'identityProviders')
.pipe(map(config => (typeof config === 'string' ? JSON.parse(config) : config))),
this.stateProperties
.getStateOrEnvOrDefault<Record<string, unknown> | string | false>(
'MULTI_SITE_LOCALE_MAP',
'multiSiteLocaleMap'
)
.pipe(
map(multiSiteLocaleMap => (multiSiteLocaleMap === false ? undefined : multiSiteLocaleMap)),
map(multiSiteLocaleMap =>
typeof multiSiteLocaleMap === 'string' ? JSON.parse(multiSiteLocaleMap) : multiSiteLocaleMap
)
)
this.stateProperties.getStateOrEnvOrDefault<ConfigurationType['identityProviders']>(
'IDENTITY_PROVIDERS',
'identityProviders'
),
this.stateProperties.getStateOrEnvOrDefault<ConfigurationType['multiSiteLocaleMap']>(
'MULTI_SITE_LOCALE_MAP',
'multiSiteLocaleMap'
)
),
map(
([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const initialState: ConfigurationState = {
lang: undefined,
currency: undefined,
serverTranslations: {},
multiSiteLocaleMap: {},
multiSiteLocaleMap: undefined,
_deviceType: environment.defaultDeviceType,
};

Expand Down
54 changes: 54 additions & 0 deletions src/app/core/utils/functions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,60 @@ describe('Functions', () => {
}
`);
});

it('should handle empty source objects', () => {
expect(mergeDeep({ a: 1, b: { c: 2 }, d: 11 }, {})).toMatchInlineSnapshot(`
Object {
"a": 1,
"b": Object {
"c": 2,
},
"d": 11,
}
`);
});

it('should handle undefined source objects', () => {
expect(mergeDeep({ a: 1, b: { c: 2 }, d: 11 }, undefined)).toMatchInlineSnapshot(`
Object {
"a": 1,
"b": Object {
"c": 2,
},
"d": 11,
}
`);
});

it('should handle empty target objects', () => {
expect(mergeDeep({}, { a: 4, b: { c: 5 } })).toMatchInlineSnapshot(`
Object {
"a": 4,
"b": Object {
"c": 5,
},
}
`);
});

it('should handle undefined target objects', () => {
expect(mergeDeep(undefined, { a: 4, b: { c: 5 } })).toMatchInlineSnapshot(`
Object {
"a": 4,
"b": Object {
"c": 5,
},
}
`);
});

it('should handle empty target and source objects', () => {
expect(mergeDeep({}, {})).toMatchInlineSnapshot(`Object {}`);
});

it('should handle undefined target and source objects', () => {
expect(mergeDeep(undefined, undefined)).toBeUndefined();
});
});

describe('omit', () => {
Expand Down
Loading

0 comments on commit 4a71df7

Please sign in to comment.