From c496627257167801916c88e11cda3ebdf0792430 Mon Sep 17 00:00:00 2001 From: Ravi <7014230+arelra@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:01:45 +0000 Subject: [PATCH 1/6] Fix usnat supported api lookup --- .../usnat/getConsentState.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) 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..d2cd8e3e0 100644 --- a/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts +++ b/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts @@ -1,18 +1,29 @@ import { type USNATConsentState } from '../types/usnat'; import { getGPPData } from './api'; +const getSupportedAPIv1 = ( + supportedAPI: string | undefined, +): string | undefined => { + if (supportedAPI?.includes('usnat')) { + return supportedAPI.includes('v1') ? supportedAPI : `${supportedAPI}'v1'`; + } + return supportedAPI; +}; + export const getConsentState: () => Promise = async () => { let doNotSell = false; // Opt-Out const gppData = await getGPPData(); - const supportedAPIs = gppData.supportedAPIs[0]?.split(':')[1]; // E.G: '7:usnatv1', '8:uscav1' + const supportedAPI = gppData.supportedAPIs[0]?.split(':')[1]; // E.G: '7:usnatv1', '8:uscav1' + // Temporary fix 21/11/2024 + const supportedAPIv1 = getSupportedAPIv1(supportedAPI); - 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 (supportedAPIv1) { // 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 = + gppData.parsedSections[supportedAPIv1]?.SaleOptOut !== 2 || + gppData.parsedSections[supportedAPIv1].Gpc; } return { From cead3993a9c03d55802fc3f60d1b69a4c3e44ad7 Mon Sep 17 00:00:00 2001 From: Ravi <7014230+arelra@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:45:12 +0000 Subject: [PATCH 2/6] Changeset --- .changeset/silver-taxis-learn.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/silver-taxis-learn.md 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 From 2eb08b264adfa9d0d46ce76085ee1c629669e603 Mon Sep 17 00:00:00 2001 From: Ravi <7014230+arelra@users.noreply.github.com> Date: Thu, 21 Nov 2024 12:54:19 +0000 Subject: [PATCH 3/6] Fix quotes --- .../src/consent-management-platform/usnat/getConsentState.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d2cd8e3e0..3a637b19e 100644 --- a/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts +++ b/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts @@ -5,7 +5,7 @@ const getSupportedAPIv1 = ( supportedAPI: string | undefined, ): string | undefined => { if (supportedAPI?.includes('usnat')) { - return supportedAPI.includes('v1') ? supportedAPI : `${supportedAPI}'v1'`; + return supportedAPI.includes('v1') ? supportedAPI : `${supportedAPI}v1`; } return supportedAPI; }; From db841fbc29306f625738ad8d39a1c4411105881d Mon Sep 17 00:00:00 2001 From: Ravi <7014230+arelra@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:18:29 +0000 Subject: [PATCH 4/6] Check for all usnat states --- .../src/consent-management-platform/usnat/getConsentState.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 3a637b19e..e46798928 100644 --- a/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts +++ b/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts @@ -1,10 +1,12 @@ import { type USNATConsentState } from '../types/usnat'; import { getGPPData } from './api'; +const usnatStates = ['usnat', 'usca', 'usva', 'usco', 'usut', 'usct']; + const getSupportedAPIv1 = ( supportedAPI: string | undefined, ): string | undefined => { - if (supportedAPI?.includes('usnat')) { + if (supportedAPI && usnatStates.includes(supportedAPI)) { return supportedAPI.includes('v1') ? supportedAPI : `${supportedAPI}v1`; } return supportedAPI; From ed6da121f436fc3a27f56dc7584afad3adde7380 Mon Sep 17 00:00:00 2001 From: Ravi <7014230+arelra@users.noreply.github.com> Date: Thu, 21 Nov 2024 13:32:51 +0000 Subject: [PATCH 5/6] Read gppData.parsedSection[0] directly to set the doNotSell signal Co-authored-by: Ashish Puliyel --- .../usnat/getConsentState.ts | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) 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 e46798928..96b63eee4 100644 --- a/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts +++ b/libs/@guardian/libs/src/consent-management-platform/usnat/getConsentState.ts @@ -1,31 +1,15 @@ import { type USNATConsentState } from '../types/usnat'; import { getGPPData } from './api'; -const usnatStates = ['usnat', 'usca', 'usva', 'usco', 'usut', 'usct']; - -const getSupportedAPIv1 = ( - supportedAPI: string | undefined, -): string | undefined => { - if (supportedAPI && usnatStates.includes(supportedAPI)) { - return supportedAPI.includes('v1') ? supportedAPI : `${supportedAPI}v1`; - } - return supportedAPI; -}; - export const getConsentState: () => Promise = async () => { let doNotSell = false; // Opt-Out const gppData = await getGPPData(); + const supportedAPI = gppData.parsedSections[0]; - const supportedAPI = gppData.supportedAPIs[0]?.split(':')[1]; // E.G: '7:usnatv1', '8:uscav1' - // Temporary fix 21/11/2024 - const supportedAPIv1 = getSupportedAPIv1(supportedAPI); - - if (supportedAPIv1) { + 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 = - gppData.parsedSections[supportedAPIv1]?.SaleOptOut !== 2 || - gppData.parsedSections[supportedAPIv1].Gpc; + doNotSell = supportedAPI.SaleOptOut !== 2 || supportedAPI.Gpc; } return { From fa2491c2accef7b1016c68c1561f3338d9ec94aa Mon Sep 17 00:00:00 2001 From: Ravi <7014230+arelra@users.noreply.github.com> Date: Thu, 21 Nov 2024 14:53:23 +0000 Subject: [PATCH 6/6] Get first value of gppData.parsedSections --- .../consent-management-platform/usnat/getConsentState.test.js | 3 +++ .../src/consent-management-platform/usnat/getConsentState.ts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) 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 96b63eee4..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,7 +4,7 @@ import { getGPPData } from './api'; export const getConsentState: () => Promise = async () => { let doNotSell = false; // Opt-Out const gppData = await getGPPData(); - const supportedAPI = gppData.parsedSections[0]; + const supportedAPI = Object.values(gppData.parsedSections)[0]; if (supportedAPI) { // https://github.com/InteractiveAdvertisingBureau/Global-Privacy-Platform/blob/main/Sections/US-National/IAB%20Privacy%E2%80%99s%20National%20Privacy%20Technical%20Specification.md