From 0dcb0cc58d27aa3ce4df3ca11e8f3721e0c87f37 Mon Sep 17 00:00:00 2001 From: Christiaan Scheermeijer Date: Tue, 22 Jun 2021 09:15:13 +0200 Subject: [PATCH] fix(project): inherit all options from the description json --- src/services/config.service.ts | 41 +++++++++++++++++----------------- types/Config.d.ts | 4 ++-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/services/config.service.ts b/src/services/config.service.ts index 9b503f2ab..9fe049b66 100644 --- a/src/services/config.service.ts +++ b/src/services/config.service.ts @@ -38,8 +38,8 @@ const configSchema: SchemaOf = 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(), @@ -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 => { diff --git a/types/Config.d.ts b/types/Config.d.ts index e1a766fba..76446a2da 100644 --- a/types/Config.d.ts +++ b/types/Config.d.ts @@ -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[];