Skip to content

Commit

Permalink
Add error for showConsentManager when viewState is TCF_EU (#157)
Browse files Browse the repository at this point in the history
* add error if viewState input is TCF_EU

* bump version

* bump version

* rm accidently change

* add error for invalid view states

* error instead of warn

* copy update

* filter out closed view states

* rm languageOptions as valid view state

* update enum used

* rm accident change
  • Loading branch information
linh-transcend authored Feb 8, 2024
1 parent d1b5f83 commit 03918d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/transcend-io/consent-manager-ui.git"
},
"homepage": "https://github.com/transcend-io/consent-manager-ui",
"version": "4.13.1",
"version": "4.13.2",
"license": "MIT",
"main": "build/ui",
"files": [
Expand Down
36 changes: 32 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AirgapAPI,
ConsentManagerAPI,
ViewState,
InitialViewState,
} from '@transcend-io/airgap.js-types';
import { isViewStateClosed } from './hooks';
import { logger } from './logger';
Expand Down Expand Up @@ -63,10 +64,37 @@ export function makeConsentManagerAPI({
Promise.resolve(
handleSetViewState(options?.viewState || 'OptOutDisclosure', auth),
),
showConsentManager: (options) =>
Promise.resolve(
handleSetViewState(options?.viewState || 'open', undefined, true),
),
// eslint-disable-next-line require-await
showConsentManager: async (options) => {
if (options?.viewState === ViewState.TCF_EU) {
logger.error(
'TCF_EU view state is not valid for this user experience. ' +
'Please configure your Regional Experience to use this view state and try again.',
);
return;
}
const excludedViewStates: InitialViewState[] = [
InitialViewState.TCF_EU, // not valid without TCF experience
InitialViewState.Hidden, // not 'open'
];
const validViewStates = Object.values(InitialViewState).filter(
(state) => !excludedViewStates.includes(state),
);
if (
options?.viewState &&
!validViewStates.includes(options.viewState as InitialViewState)
) {
logger.error(
`${
options.viewState
} is not a valid view state. Valid view states include ${validViewStates.join(
', ',
)}`,
);
return;
}
handleSetViewState(options?.viewState || 'open', undefined, true);
},
hideConsentManager: () => Promise.resolve(handleSetViewState('close')),
toggleConsentManager: () =>
Promise.resolve(
Expand Down

0 comments on commit 03918d9

Please sign in to comment.