-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
334 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@guardian/libs': minor | ||
--- | ||
|
||
Test for Consent or Pay |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
libs/@guardian/libs/src/consent-management-platform/isConsentOrPay.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { CountryCode } from '../index.test'; | ||
|
||
export const isConsentOrPay = (countryCode: CountryCode) => { | ||
const consentOrPayCountries = ['GB']; | ||
|
||
return consentOrPayCountries.includes(countryCode); | ||
}; |
23 changes: 23 additions & 0 deletions
23
libs/@guardian/libs/src/consent-management-platform/lib/participants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { isObject } from '../../isObject/isObject'; | ||
import { isString } from '../../isString/isString'; | ||
import { storage } from '../../storage/storage'; | ||
|
||
export type Participations = Record<string, { variant: string }>; | ||
|
||
const participationsKey = 'gu.ab.participations'; | ||
export const getParticipationsFromLocalStorage = (): Participations => { | ||
const participations = storage.local.get(participationsKey); | ||
return isParticipations(participations) ? participations : {}; | ||
}; | ||
|
||
const isParticipations = ( | ||
participations: unknown, | ||
): participations is Participations => { | ||
return ( | ||
isObject(participations) && | ||
Object.values(participations).every( | ||
(participation) => | ||
isObject(participation) && isString(participation.variant), | ||
) | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
libs/@guardian/libs/src/consent-management-platform/mergeUserConsent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { getCookie } from '../cookies/getCookie'; | ||
import { PROPERTY_ID_MAIN, PROPERTY_ID_SUPPORT } from './lib/sourcepointConfig'; | ||
import type { SPUserConsent } from './types/tcfv2'; | ||
|
||
// https://sourcepoint-public-api.readme.io/reference/post_consent-v3-siteid-tcstring | ||
|
||
export const mergeUserConsent = () => { | ||
const consentUUID = getCookie({ name: 'consentUUID' }); | ||
const url = `https://cdn.privacy-mgmt.com/consent/tcfv2/consent/v3/${PROPERTY_ID_SUPPORT}/tcstring?consentUUID=${consentUUID}`; | ||
const spUserConsentString = localStorage.getItem( | ||
`_sp_user_consent_${PROPERTY_ID_MAIN}`, | ||
); | ||
const userConsent = JSON.parse(spUserConsentString ?? '{}') as SPUserConsent; | ||
|
||
fetch(url, { | ||
method: 'POST', | ||
headers: { | ||
Accept: 'application/json', | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
euconsent: userConsent.gdpr?.euconsent, | ||
}), | ||
}).catch((error) => { | ||
console.error('Error:', error); | ||
}); | ||
}; |
22 changes: 22 additions & 0 deletions
22
libs/@guardian/libs/src/consent-management-platform/rejectAll.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getCurrentFramework } from './getCurrentFramework'; | ||
import { invokeCallbacks } from './onConsentChange'; | ||
import { rejectAllForUser } from './tcfv2/api'; | ||
|
||
const rejectAll = (): Promise<void> => | ||
// Consider jurisdiction/framework and countries. | ||
new Promise<void>((resolve, reject) => { | ||
console.log('Rejecting all'); | ||
if (getCurrentFramework() === 'tcfv2') { | ||
rejectAllForUser() | ||
.then(() => { | ||
invokeCallbacks(); | ||
resolve(); | ||
}) | ||
.catch(() => { | ||
reject(new Error('Unable to reject all')); | ||
}); | ||
} else { | ||
reject(new Error('Framework not supported')); | ||
} | ||
}); | ||
export { rejectAll }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.