Skip to content

Commit

Permalink
Support nullable TrackingConsentDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
anotherminh committed Nov 2, 2023
1 parent 56bf738 commit 9a1ab13
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -47,4 +47,4 @@
"typescript": "^4.5.5"
},
"packageManager": "[email protected]"
}
}
72 changes: 52 additions & 20 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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');
Expand Down 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,57 @@ 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 9a1ab13

Please sign in to comment.