diff --git a/.changeset/silver-taxis-learn.md b/.changeset/silver-taxis-learn.md new file mode 100644 index 000000000..2ee7b5877 --- /dev/null +++ b/.changeset/silver-taxis-learn.md @@ -0,0 +1,5 @@ +--- +'@guardian/libs': patch +--- + +Fix cmp usnat supported api lookup diff --git a/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.test.js b/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.test.js index 7fb914083..a3bca6514 100644 --- a/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.test.js +++ b/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.test.js @@ -7,6 +7,9 @@ import { getConsentState } from './getConsentState.ts'; jest.mock('./api'); describe('getConsentState', () => { + beforeEach(() => { + jest.clearAllMocks(); + }); it('gets the gpp consent state correctly - doNotSell is false', async () => { getGPPData.mockResolvedValue(gppDataCanSell); diff --git a/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts b/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts index fc1785957..899b72396 100644 --- a/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts +++ b/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts @@ -4,15 +4,12 @@ import { getGPPData } from './api'; export const getConsentState: () => Promise = async () => { let doNotSell = false; // Opt-Out const gppData = await getGPPData(); + const supportedAPI = Object.values(gppData.parsedSections)[0]; - const supportedAPIs = gppData.supportedAPIs[0]?.split(':')[1]; // E.G: '7:usnatv1', '8:uscav1' - - if (supportedAPIs) { - //0 Not Applicable. SharingOptOutNotice value was not applicable or no notice was provided, 1 Opted Out, 2 Did Not Opt Out - doNotSell = - gppData.parsedSections[supportedAPIs]?.SaleOptOut !== 2 || - gppData.parsedSections[supportedAPIs].Gpc; + if (supportedAPI) { // https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform/blob/main/Sections/US-National/IAB%20Privacy%E2%80%99s%20National%20Privacy%20Technical%20Specification.md + // 0 Not Applicable. SharingOptOutNotice value was not applicable or no notice was provided, 1 Opted Out, 2 Did Not Opt Out + doNotSell = supportedAPI.SaleOptOut !== 2 || supportedAPI.Gpc; } return {