@transcend-io/consent-manager-ui
Advanced tools
Comparing version 4.21.1 to 4.21.2
{ | ||
"name": "eslint", | ||
"version": "8.10.0-sdk", | ||
"version": "8.57.0-sdk", | ||
"main": "./lib/api.js", | ||
"type": "commonjs" | ||
} |
{ | ||
"name": "prettier", | ||
"version": "2.7.1-sdk", | ||
"main": "./index.js", | ||
"version": "3.3.3-sdk", | ||
"main": "./index.cjs", | ||
"type": "commonjs" | ||
} |
{ | ||
"name": "typescript", | ||
"version": "4.9.4-sdk", | ||
"version": "4.9.5-sdk", | ||
"main": "./lib/typescript.js", | ||
"type": "commonjs" | ||
} |
@@ -10,3 +10,3 @@ { | ||
"homepage": "https://github.com/transcend-io/consent-manager-ui", | ||
"version": "4.21.1", | ||
"version": "4.21.2", | ||
"license": "MIT", | ||
@@ -34,3 +34,3 @@ "main": "build/ui", | ||
"scripts": { | ||
"update:sdks": "yarn set version from sources && yarn sdks base", | ||
"update:sdks": "yarn sdks base", | ||
"update:deps": "yarn upgrade-interactive && yarn update:sdks", | ||
@@ -88,3 +88,3 @@ "build": "ts-node --transpile-only ./build.ts && cp -r ./src/translations ./build/translations && cp ./src/cm.css ./build/", | ||
}, | ||
"packageManager": "yarn@3.4.1" | ||
"packageManager": "yarn@4.5.1" | ||
} |
import { useCallback, useEffect, useState } from 'preact/hooks'; | ||
import { | ||
ConsentManagerLanguageKey, | ||
LanguageKey, | ||
TranslatedMessages, | ||
@@ -9,2 +10,3 @@ Translations, | ||
import { substituteHtml } from '../utils/substitute-html'; | ||
import { invertSafe } from '@transcend-io/type-utils'; | ||
@@ -14,2 +16,86 @@ export const loadedTranslations: Translations = Object.create(null); | ||
/** | ||
* Mapping of browser locale to AWS base translation key | ||
* | ||
* TODO: https://transcend.height.app/T-39777 | ||
* This is here for a quick fix of our CM UI translation logic. Copied from the monorepo's extract_intl.ts | ||
* This should be removed ASAP (it should be in the intl repo and imported, not in here or extract_intl.ts) | ||
*/ | ||
export const TRANSLATE_LOCALE = { | ||
[LanguageKey.EsEs]: 'es', | ||
[LanguageKey.NlNl]: 'nl', | ||
[LanguageKey.NlBe]: 'nl', | ||
[LanguageKey.Es419]: 'es-MX', | ||
// This is a hack to fix the fact that we don't have a LanguageKey -> BrowserLanguageKey mapping | ||
'es-MX': 'es-MX', | ||
[LanguageKey.ZhHk]: 'zh-TW', | ||
[LanguageKey.AfZz]: 'af', | ||
[LanguageKey.Ar]: 'ar', | ||
[LanguageKey.En]: 'en', | ||
[LanguageKey.Fr]: 'fr', | ||
[LanguageKey.Es]: 'es', | ||
[LanguageKey.De]: 'de', | ||
[LanguageKey.It]: 'it', | ||
[LanguageKey.Ja]: 'ja', | ||
[LanguageKey.Ru]: 'ru', | ||
[LanguageKey.ArAe]: 'ar', | ||
[LanguageKey.FrFr]: 'fr', | ||
[LanguageKey.DeDe]: 'de', | ||
[LanguageKey.ItIt]: 'it', | ||
[LanguageKey.BgBg]: 'bg', | ||
[LanguageKey.ZhCn]: 'zh', | ||
[LanguageKey.HrHr]: 'hr', | ||
[LanguageKey.CsCz]: 'cs', | ||
[LanguageKey.DaDk]: 'da', | ||
[LanguageKey.EnGb]: 'en', | ||
[LanguageKey.FiFi]: 'fi', | ||
[LanguageKey.ElGr]: 'el', | ||
[LanguageKey.HiIn]: 'hi', | ||
[LanguageKey.HuHu]: 'hu', | ||
[LanguageKey.IdId]: 'id', | ||
[LanguageKey.JaJp]: 'ja', | ||
[LanguageKey.KoKr]: 'ko', | ||
[LanguageKey.LtLt]: 'lt', | ||
[LanguageKey.MsMy]: 'ms', | ||
[LanguageKey.NbNi]: 'no', | ||
[LanguageKey.PlPl]: 'pl', | ||
[LanguageKey.PtBr]: 'pt', | ||
[LanguageKey.PtPt]: 'pt', | ||
[LanguageKey.RoRo]: 'ro', | ||
[LanguageKey.RuRu]: 'ru', | ||
[LanguageKey.SrLatnRs]: 'sr', | ||
[LanguageKey.SvSe]: 'sv', | ||
[LanguageKey.TaIn]: 'ta', | ||
[LanguageKey.ThTh]: 'th', | ||
[LanguageKey.TrTr]: 'tr', | ||
[LanguageKey.UkUa]: 'uk', | ||
[LanguageKey.ViVn]: 'vi', | ||
[LanguageKey.EnUS]: 'en', | ||
[LanguageKey.EnAu]: 'en', | ||
[LanguageKey.FrBe]: 'fr', | ||
[LanguageKey.EnIe]: 'en', | ||
[LanguageKey.EnCa]: 'en', | ||
[LanguageKey.EnAe]: 'en', | ||
[LanguageKey.DeAt]: 'de', | ||
[LanguageKey.DeCh]: 'de', | ||
[LanguageKey.ItCh]: 'it', | ||
[LanguageKey.FrCh]: 'fr', | ||
[LanguageKey.HeIl]: 'he', | ||
[LanguageKey.EnNz]: 'en', | ||
[LanguageKey.EtEe]: 'et', | ||
[LanguageKey.IsIs]: 'is', | ||
[LanguageKey.LvLv]: 'lv', | ||
[LanguageKey.MtMt]: 'mt', | ||
[LanguageKey.SkSk]: 'sk', | ||
[LanguageKey.SlSl]: 'sl', | ||
[LanguageKey.MrIn]: 'mr', | ||
[LanguageKey.ZuZa]: 'en', | ||
} as unknown as { [k in LanguageKey]: string }; | ||
/** Mapping of AWS base translation keys to list of browser locales that should use them */ | ||
export const INVERTED_TRANSLATE_LOCALE = invertSafe(TRANSLATE_LOCALE); | ||
const getDuplicativeLocalizations = (lang: LanguageKey): LanguageKey[] => | ||
INVERTED_TRANSLATE_LOCALE[TRANSLATE_LOCALE[lang]]; | ||
/** | ||
* Detect user-preferred languages from the user agent | ||
@@ -119,8 +205,22 @@ * | ||
const preferredLanguages = getUserLanguages(); | ||
return ( | ||
/* We should refactor this ASAP TODO: https://transcend.height.app/T-39777 | ||
* Extend supportedLanguages to include locales that we consider equivalent | ||
* e.g. instead of just having en, include en-US, en-GB, en-AU, etc | ||
*/ | ||
const extendedSupportedLanguages = supportedLanguages | ||
.map((lang: ConsentManagerLanguageKey) => getDuplicativeLocalizations(lang)) | ||
.flat() as ConsentManagerLanguageKey[]; | ||
const nearestExtendedLanguage = | ||
getNearestSupportedLanguage( | ||
preferredLanguages, | ||
sortSupportedLanguagesByPreference(supportedLanguages), | ||
) || ConsentManagerLanguageKey.En | ||
); | ||
sortSupportedLanguagesByPreference(extendedSupportedLanguages), | ||
) || ConsentManagerLanguageKey.En; | ||
let nearestTranslation = nearestExtendedLanguage; | ||
if (!supportedLanguages.includes(nearestTranslation)) { | ||
nearestTranslation = getDuplicativeLocalizations(nearestTranslation).find( | ||
(lang) => supportedLanguages.includes(lang as ConsentManagerLanguageKey), | ||
) as ConsentManagerLanguageKey; | ||
} | ||
return nearestTranslation; | ||
} | ||
@@ -127,0 +227,0 @@ |
@@ -5,3 +5,3 @@ import { | ||
TrackingConsentDetails, | ||
TrackingPurposesTypes | ||
TrackingPurposesTypes, | ||
} from '@transcend-io/airgap.js-types'; | ||
@@ -16,20 +16,32 @@ import { testWindow } from './render'; | ||
purposes: Object.fromEntries( | ||
Object.entries(purposeTypes) | ||
.map(([key, purpose]) => ([key, purpose.defaultConsent])) | ||
) as TrackingConsent | ||
} | ||
let consentCache: TrackingConsentDetails = JSON.parse(JSON.stringify(DEFAULT_CONSENT)); | ||
Object.entries(purposeTypes).map(([key, purpose]) => [ | ||
key, | ||
purpose.defaultConsent, | ||
]), | ||
) as TrackingConsent, | ||
}; | ||
let consentCache: TrackingConsentDetails = JSON.parse( | ||
JSON.stringify(DEFAULT_CONSENT), | ||
); | ||
const getPurposeTypes = (): TrackingPurposesTypes => purposeTypes; | ||
const optIn = (): void => { | ||
const optedInEntries = Object.entries(consentCache.purposes).map(([key]) => ([key, true])); | ||
const optedInEntries = Object.entries(consentCache.purposes).map( | ||
([key]) => [key, true], | ||
); | ||
consentCache.purposes = Object.fromEntries(optedInEntries); | ||
consentCache.confirmed = true; | ||
} | ||
}; | ||
const optOut = (): void => { | ||
const optedOutEntries = Object.entries(consentCache.purposes).map(([key]) => ([key, false])); | ||
const optedOutEntries = Object.entries(consentCache.purposes).map( | ||
([key]) => [key, false], | ||
); | ||
consentCache.purposes = Object.fromEntries(optedOutEntries); | ||
consentCache.confirmed = true; | ||
} | ||
const setConsent = (event: Event, purposes: TrackingConsent, options: ConsentOptions): void => { | ||
}; | ||
const setConsent = ( | ||
event: Event, | ||
purposes: TrackingConsent, | ||
options: ConsentOptions, | ||
): void => { | ||
consentCache = { | ||
@@ -41,13 +53,16 @@ ...consentCache, | ||
...consentCache.purposes, | ||
...purposes | ||
} | ||
} as TrackingConsentDetails | ||
} | ||
...purposes, | ||
}, | ||
} as TrackingConsentDetails; | ||
}; | ||
const getConsent = (): TrackingConsentDetails => ({ | ||
...consentCache, | ||
purposes: { ...consentCache.purposes } | ||
}); | ||
const getPrivacySignals = (): Set<"DNT" | "GPC"> => new Set() | ||
const getRegimePurposes = (): Set<string> => new Set(Object.keys(purposeTypes)); | ||
const reset = (): void => { consentCache = JSON.parse(JSON.stringify(DEFAULT_CONSENT)) }; | ||
...consentCache, | ||
purposes: { ...consentCache.purposes }, | ||
}); | ||
const getPrivacySignals = (): Set<'DNT' | 'GPC'> => new Set(); | ||
const getRegimePurposes = (): Set<string> => | ||
new Set(Object.keys(purposeTypes)); | ||
const reset = (): void => { | ||
consentCache = JSON.parse(JSON.stringify(DEFAULT_CONSENT)); | ||
}; | ||
@@ -63,3 +78,3 @@ testWindow.airgap = { | ||
reset, | ||
} | ||
} | ||
}; | ||
}; |
@@ -5,3 +5,3 @@ import { | ||
TrackingConsentDetails, | ||
TrackingPurposesTypes | ||
TrackingPurposesTypes, | ||
} from '@transcend-io/airgap.js-types'; | ||
@@ -14,3 +14,3 @@ import { TranslatedMessages } from '@transcend-io/internationalization'; | ||
/** Cached english messages read from en.json */ | ||
messages: TranslatedMessages | ||
messages: TranslatedMessages; | ||
} & Record<string, unknown>; | ||
@@ -24,18 +24,22 @@ } | ||
/** mock getPurposeTypes fxn */ | ||
getPurposeTypes: () => TrackingPurposesTypes | ||
getPurposeTypes: () => TrackingPurposesTypes; | ||
/** mock optIn fxn */ | ||
optIn: () => void | ||
optIn: () => void; | ||
/** mock optOut fxn */ | ||
optOut: () => void | ||
optOut: () => void; | ||
/** mock setConsent fxn */ | ||
setConsent: (event: Event, purposes: TrackingConsent, options: ConsentOptions) => void | ||
setConsent: ( | ||
event: Event, | ||
purposes: TrackingConsent, | ||
options: ConsentOptions, | ||
) => void; | ||
/** mock getConsent fxn */ | ||
getConsent: () => TrackingConsentDetails | ||
getConsent: () => TrackingConsentDetails; | ||
/** mock getPrivacySignals fxn */ | ||
getPrivacySignals: () => Set<"DNT" | "GPC"> | ||
getPrivacySignals: () => Set<'DNT' | 'GPC'>; | ||
/** mock getRegimePurposes fxn */ | ||
getRegimePurposes: () => Set<string> | ||
getRegimePurposes: () => Set<string>; | ||
/** mock reset fxn */ | ||
reset: () => void | ||
} | ||
} | ||
reset: () => void; | ||
}; | ||
}; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1795711
19863