From f1cb4035366d52dd2ae790a69ac64d7959ca37b8 Mon Sep 17 00:00:00 2001 From: anotherminh Date: Thu, 2 Nov 2023 14:13:38 -0400 Subject: [PATCH] Support nullable TrackingConsentDetails (#102) * Support nullable TrackingConsentDetails * fix --- package.json | 2 +- src/core.ts | 64 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 225c109..1b9b0ae 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "author": "Transcend Inc.", "name": "@transcend-io/airgap.js-types", "description": "TypeScript types for airgap.js interoperability with custom consent UIs", - "version": "10.7.0", + "version": "10.7.1", "homepage": "https://github.com/transcend-io/airgap.js-types", "repository": { "type": "git", diff --git a/src/core.ts b/src/core.ts index f19854f..4d1c331 100644 --- a/src/core.ts +++ b/src/core.ts @@ -369,10 +369,15 @@ export const TrackingConsent = t.intersection([ */ export type TrackingConsent = t.TypeOf; -export const TrackingConsentDetails = t.intersection([ +export const TrackingConsentWithNulls = t.record( + t.string, + t.union([t.boolean, t.undefined, t.null]), +); +/** Type override */ +export type TrackingConsentWithNulls = t.TypeOf; + +const CoreTrackingConsentDetails = t.intersection([ t.type({ - /** Tracking consent config */ - purposes: TrackingConsent, /** * Was tracking consent confirmed by the user? * If this is false, the consent was resolved from defaults & is not yet confirmed @@ -393,23 +398,38 @@ export const TrackingConsentDetails = t.intersection([ }), ]); +/** Type override */ +export type CoreTrackingConsentDetails = t.TypeOf< + typeof CoreTrackingConsentDetails +>; + +export const TrackingConsentDetails = t.intersection([ + CoreTrackingConsentDetails, + t.type({ + /** Tracking consent config */ + purposes: TrackingConsent, + }), +]); + /** Override types. */ export type TrackingConsentDetails = t.TypeOf; +export const TrackingConsentOptionalData = t.partial({ + /** Transparency Consent (TCF) String */ + tcf: t.string, + /** US Privacy (USP) String */ + usp: t.string, + /** Global Privacy Platform (GPP) String */ + gpp: t.string, + /** Consent Manager View State */ + viewState: valuesOf(ViewState), + /** Airgap Version */ + airgapVersion: t.string, +}); + export const FullTrackingConsentDetails = t.intersection([ TrackingConsentDetails, - t.partial({ - /** Transparency Consent (TCF) String */ - tcf: t.string, - /** US Privacy (USP) String */ - usp: t.string, - /** Global Privacy Platform (GPP) String */ - gpp: t.string, - /** Consent Manager View State */ - viewState: valuesOf(ViewState), - /** Airgap Version */ - airgapVersion: t.string, - }), + TrackingConsentOptionalData, ]); /** Override types. */ @@ -417,6 +437,20 @@ export type FullTrackingConsentDetails = t.TypeOf< typeof FullTrackingConsentDetails >; +export const FullTrackingConsentDetailsWithNulls = t.intersection([ + CoreTrackingConsentDetails, + TrackingConsentOptionalData, + t.type({ + /** Tracking consent config */ + purposes: TrackingConsentWithNulls, + }), +]); + +/** Override types. */ +export type FullTrackingConsentDetailsWithNulls = t.TypeOf< + typeof FullTrackingConsentDetailsWithNulls +>; + export const ConsentPreferencesBody = t.type({ /** token containing encrypted identifier */ token: t.string,