Skip to content

Commit

Permalink
Support nullable TrackingConsentDetails (#102)
Browse files Browse the repository at this point in the history
* Support nullable TrackingConsentDetails

* fix
  • Loading branch information
anotherminh authored Nov 2, 2023
1 parent 56bf738 commit f1cb403
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
64 changes: 49 additions & 15 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,15 @@ export const TrackingConsent = t.intersection([
*/
export type TrackingConsent = t.TypeOf<typeof TrackingConsent>;

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<typeof TrackingConsent>;

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
Expand All @@ -393,30 +398,59 @@ 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<typeof TrackingConsentDetails>;

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. */
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,
Expand Down

0 comments on commit f1cb403

Please sign in to comment.