diff --git a/clients/fides-js/src/fides.ts b/clients/fides-js/src/fides.ts index 6d25d5089f..f9ff4ed80f 100644 --- a/clients/fides-js/src/fides.ts +++ b/clients/fides-js/src/fides.ts @@ -68,6 +68,7 @@ import { ConsentMethod, SaveConsentPreference, ConsentMechanism, + EmptyExperience, } from "./lib/consent-types"; import { constructFidesRegionString, @@ -231,7 +232,8 @@ const init = async ({ } let shouldInitOverlay: boolean = options.isOverlayEnabled; - let effectiveExperience: PrivacyExperience | undefined | {} = experience; + let effectiveExperience: PrivacyExperience | undefined | EmptyExperience = + experience; let fidesRegionString: string | null = null; if (shouldInitOverlay) { diff --git a/clients/fides-js/src/lib/consent-types.ts b/clients/fides-js/src/lib/consent-types.ts index 9f238b2434..2806dfd004 100644 --- a/clients/fides-js/src/lib/consent-types.ts +++ b/clients/fides-js/src/lib/consent-types.ts @@ -1,4 +1,4 @@ -export type EmptyExperience = {}; +export type EmptyExperience = Record; export interface FidesConfig { // Set the consent defaults from a "legacy" Privacy Center config.json. diff --git a/clients/fides-js/src/lib/consent-utils.ts b/clients/fides-js/src/lib/consent-utils.ts index 6c2a393431..c3e8952ee8 100644 --- a/clients/fides-js/src/lib/consent-utils.ts +++ b/clients/fides-js/src/lib/consent-utils.ts @@ -37,12 +37,11 @@ export const isEmptyExperience = (obj: unknown): obj is EmptyExperience => * Returns true if privacy experience has notices */ export const experienceHasNotices = ( - experience: PrivacyExperience | undefined | {} + experience: PrivacyExperience | undefined | EmptyExperience ): boolean => Boolean( experience && !isEmptyExperience(experience) && - // fixme: how to tell ts that privacy_notices exists on experience? experience.privacy_notices && experience.privacy_notices.length > 0 ); @@ -161,17 +160,16 @@ export const validateOptions = (options: FidesOptions): boolean => { * Determines whether experience is valid and relevant notices exist within the experience */ export const experienceIsValid = ( - effectiveExperience: PrivacyExperience | undefined | {}, + effectiveExperience: PrivacyExperience | undefined | EmptyExperience, options: FidesOptions ): boolean => { - if (!experienceHasNotices(effectiveExperience)) { + if (!effectiveExperience || !experienceHasNotices(effectiveExperience)) { debugLog( options.debug, `Privacy experience has no notices. Skipping overlay initialization.` ); return false; } - // @ts-ignore if (effectiveExperience.component !== ComponentType.OVERLAY) { debugLog( options.debug, @@ -179,7 +177,6 @@ export const experienceIsValid = ( ); return false; } - // @ts-ignore if (!effectiveExperience.experience_config) { debugLog( options.debug, diff --git a/clients/fides-js/src/services/fides/api.ts b/clients/fides-js/src/services/fides/api.ts index 86438d36cd..80a97b6250 100644 --- a/clients/fides-js/src/services/fides/api.ts +++ b/clients/fides-js/src/services/fides/api.ts @@ -1,5 +1,6 @@ import { ComponentType, + EmptyExperience, LastServedNoticeSchema, NoticesServedRequest, PrivacyExperience, @@ -22,7 +23,7 @@ export const fetchExperience = async ( fidesApiUrl: string, debug: boolean, fidesUserDeviceId?: string | null -): Promise => { +): Promise => { debugLog( debug, `Fetching experience for userId: ${fidesUserDeviceId} in location: ${userLocationString}`