From 9a1ab1345455f401ddc09dc6870a3c2724477fed Mon Sep 17 00:00:00 2001 From: anotherminh Date: Thu, 2 Nov 2023 13:56:35 -0400 Subject: [PATCH 1/2] Support nullable TrackingConsentDetails --- package.json | 4 +-- src/core.ts | 72 +++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 225c109..fa2c314 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", @@ -47,4 +47,4 @@ "typescript": "^4.5.5" }, "packageManager": "yarn@3.2.0" -} +} \ No newline at end of file diff --git a/src/core.ts b/src/core.ts index f19854f..858213e 100644 --- a/src/core.ts +++ b/src/core.ts @@ -82,9 +82,9 @@ export type Logger = { */ tag(logTag: string, callback?: () => any): void; // eslint-disable-line @typescript-eslint/no-explicit-any } & { - /** Log emitter (e.g. `logger.log()`) */ - [method in LogLevel]: LogEmitter; -}; + /** Log emitter (e.g. `logger.log()`) */ + [method in LogLevel]: LogEmitter; + }; /** AirgapAuth auth options */ export type AirgapAuthMap = { @@ -234,8 +234,8 @@ export type Removable = { export type Stringifiable = | string | (string & { - toString(): string; - }); + toString(): string; + }); /** Special `defaultConsent` automatic opt-out value for any potential reason */ export const AutoOptOut = t.literal('Auto'); @@ -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,36 @@ export const TrackingConsentDetails = t.intersection([ }), ]); +/** Type override */ +export type CoreTrackingConsentDetails = t.TypeOf; + +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 +435,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, From 7387307592e05384e8572ceec20d62d77fc8bd8a Mon Sep 17 00:00:00 2001 From: anotherminh Date: Thu, 2 Nov 2023 13:58:42 -0400 Subject: [PATCH 2/2] fix --- package.json | 2 +- src/core.ts | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index fa2c314..1b9b0ae 100644 --- a/package.json +++ b/package.json @@ -47,4 +47,4 @@ "typescript": "^4.5.5" }, "packageManager": "yarn@3.2.0" -} \ No newline at end of file +} diff --git a/src/core.ts b/src/core.ts index 858213e..4d1c331 100644 --- a/src/core.ts +++ b/src/core.ts @@ -82,9 +82,9 @@ export type Logger = { */ tag(logTag: string, callback?: () => any): void; // eslint-disable-line @typescript-eslint/no-explicit-any } & { - /** Log emitter (e.g. `logger.log()`) */ - [method in LogLevel]: LogEmitter; - }; + /** Log emitter (e.g. `logger.log()`) */ + [method in LogLevel]: LogEmitter; +}; /** AirgapAuth auth options */ export type AirgapAuthMap = { @@ -234,8 +234,8 @@ export type Removable = { export type Stringifiable = | string | (string & { - toString(): string; - }); + toString(): string; + }); /** Special `defaultConsent` automatic opt-out value for any potential reason */ export const AutoOptOut = t.literal('Auto'); @@ -371,7 +371,7 @@ export type TrackingConsent = t.TypeOf; export const TrackingConsentWithNulls = t.record( t.string, - t.union([t.boolean, t.undefined, t.null]) + t.union([t.boolean, t.undefined, t.null]), ); /** Type override */ export type TrackingConsentWithNulls = t.TypeOf; @@ -399,7 +399,9 @@ const CoreTrackingConsentDetails = t.intersection([ ]); /** Type override */ -export type CoreTrackingConsentDetails = t.TypeOf; +export type CoreTrackingConsentDetails = t.TypeOf< + typeof CoreTrackingConsentDetails +>; export const TrackingConsentDetails = t.intersection([ CoreTrackingConsentDetails, @@ -427,7 +429,7 @@ export const TrackingConsentOptionalData = t.partial({ export const FullTrackingConsentDetails = t.intersection([ TrackingConsentDetails, - TrackingConsentOptionalData + TrackingConsentOptionalData, ]); /** Override types. */