Skip to content

Commit

Permalink
fix(project): inherit all options from the description json
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristiaanScheermeijer committed Jun 22, 2021
1 parent 2906043 commit 0dcb0cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
41 changes: 20 additions & 21 deletions src/services/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const configSchema: SchemaOf<Config> = object({
player: string().defined(),
recommendationsPlaylist: string().notRequired(),
searchPlaylist: string().notRequired(),
analyticsToken: string().notRequired(),
adSchedule: string().notRequired(),
analyticsToken: string().nullable(),
adSchedule: string().nullable(),
assets: object({
banner: string().notRequired(),
}).defined(),
Expand Down Expand Up @@ -98,27 +98,26 @@ const addPersonalShelves = (data: Config) => {
* @returns {Config}
*/
const parseDeprecatedConfig = (config: Config) => {
if (config.description.startsWith('{')) {
try {
const description = JSON.parse(config.description);
config.description = '';

return {
...config,
id: 'ID_PLACE_HOLDER',
menu: description.menu,
analyticsToken: description.analyticsToken,
options: {
dynamicBlur: description.dynamicBlur,
...config.options,
},
};
} catch (error: unknown) {
throw new Error('Failed to JSON parse the `description` property');
}
if (!config.description.startsWith('{')) {
return config;
}

return config;
try {
const { menu, id, analyticsToken, adSchedule, description, ...options } = JSON.parse(config.description);

const updatedConfig = {
menu: menu || [],
id: id || 'showcase-id',
analyticsToken: analyticsToken || null,
adSchedule: adSchedule || null,
description: description || '',
options: Object.assign(config.options, options),
};

return Object.assign(config, updatedConfig);
} catch (error: unknown) {
throw new Error('Failed to JSON parse the `description` property');
}
};

export const validateConfig = (config: Config): Promise<Config> => {
Expand Down
4 changes: 2 additions & 2 deletions types/Config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export type Config = {
player: string;
recommendationsPlaylist?: string;
searchPlaylist?: string;
analyticsToken?: string;
adSchedule?: string;
analyticsToken?: string | null;
adSchedule?: string | null;
assets: { banner?: string };
content: Content[];
menu: Menu[];
Expand Down

0 comments on commit 0dcb0cc

Please sign in to comment.