Skip to content

Commit

Permalink
Move rejectAll to cmp object
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsola-guardian committed Dec 9, 2024
1 parent eb85496 commit 334c67d
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apps/github-pages/src/components/CmpTest.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
// this maps to the version in libs/@guardian/libs
import { cmp, onConsentChange, log, rejectAll } from '@guardian/libs';
import { cmp, onConsentChange, log } from '@guardian/libs';
import { onMount } from 'svelte';
Expand Down Expand Up @@ -42,7 +42,7 @@
}
let rejectAllFunc = () => {
rejectAll().then(() => {
cmp.rejectAll().then(() => {
logEvent({ title: 'rejectAll'});
// window.location.reload();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe('hotfix cmp.init', () => {
willShowPrivacyMessage: () => new Promise(() => true),
willShowPrivacyMessageSync: () => true,
hasInitialised: () => true,
rejectAll: () => new Promise(() => undefined),
showPrivacyManager: () => {
console.warn('This is a dummy for showPrivacyManager');
},
Expand Down
9 changes: 5 additions & 4 deletions libs/@guardian/libs/src/consent-management-platform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const showPrivacyManager = () => {
void initialised.then(UnifiedCMP.showPrivacyManager);
};

const rejectAll = isServerSide
? clientRejectAll
: (window.guCmpHotFix.rejectAll ??= clientRejectAll);

export const cmp: CMP = isServerSide
? serverCmp
: (window.guCmpHotFix.cmp ||= {
Expand All @@ -101,6 +105,7 @@ export const cmp: CMP = isServerSide
willShowPrivacyMessageSync,
hasInitialised,
showPrivacyManager,
rejectAll,
version: version,

// special helper methods for disabling CMP
Expand All @@ -109,10 +114,6 @@ export const cmp: CMP = isServerSide
__disable: disable,
});

export const rejectAll = isServerSide
? clientRejectAll
: (window.guCmpHotFix.rejectAll ??= clientRejectAll);

export const onConsent = isServerSide
? serverOnConsent
: (window.guCmpHotFix.onConsent ||= clientOnConsent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const cmp: CMP = {
version: 'n/a',
willShowPrivacyMessage: serverSideWarnAndReturn(Promise.resolve(false)),
willShowPrivacyMessageSync: serverSideWarnAndReturn(false),
rejectAll: serverSideWarnAndReturn(Promise.resolve()),
};

export const onConsent = (): ReturnType<typeof OnConsent> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type CMP = {
willShowPrivacyMessageSync: () => boolean;
hasInitialised: () => boolean;
showPrivacyManager: () => void;
rejectAll: () => Promise<void>;
version: string;
__isDisabled: () => boolean;
__disable: () => void;
Expand Down
1 change: 0 additions & 1 deletion libs/@guardian/libs/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ describe('The package', () => {
'log',
'onConsent',
'onConsentChange',
'rejectAll',
'removeCookie',
'setCookie',
'setSessionCookie',
Expand Down
1 change: 0 additions & 1 deletion libs/@guardian/libs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export {
getConsentFor,
onConsentChange,
onConsent,
rejectAll,
} from './consent-management-platform';

export { getCookie } from './cookies/getCookie';
Expand Down

0 comments on commit 334c67d

Please sign in to comment.