From 06a2cc779a5e21621ee4f89f77927dbf625ea63a Mon Sep 17 00:00:00 2001 From: linh-transcend Date: Thu, 8 Feb 2024 10:22:53 -0500 Subject: [PATCH] add error for invalid view states --- src/api.ts | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/api.ts b/src/api.ts index 8f310874..f8b45704 100644 --- a/src/api.ts +++ b/src/api.ts @@ -65,13 +65,28 @@ export function makeConsentManagerAPI({ ), // eslint-disable-next-line require-await showConsentManager: async (options) => { - if (options?.viewState !== ViewState.TCF_EU) { - handleSetViewState(options?.viewState || 'open', undefined, true); + if (options?.viewState === ViewState.TCF_EU) { + logger.warn( + 'TCF_EU view state is not valid. Please configure your regime to use this view state.', + ); return; } - logger.warn( - 'TCF_EU view state is not valid. Please configure your regime to use this view state.', - ); + if ( + options?.viewState && + !Object.values(ViewState).includes(options.viewState) + ) { + logger.warn( + `${ + options.viewState + } is not a valid view state. Valid view states include ${Object.values( + ViewState, + ) + .filter((viewState) => viewState !== ViewState.TCF_EU) + .join(', ')}`, + ); + return; + } + handleSetViewState(options?.viewState || 'open', undefined, true); }, hideConsentManager: () => Promise.resolve(handleSetViewState('close')), toggleConsentManager: () =>