From bab52fdd85a42a0c00b972257073dcaf14f5f431 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 25 Nov 2024 12:06:00 -0700 Subject: [PATCH 1/3] moved uid2 helper to generalize and use for euid --- src/euidSdk.ts | 6 +++++- src/sdkBase.ts | 20 +++++++++++++++++++- src/uid2Sdk.ts | 26 +++----------------------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/euidSdk.ts b/src/euidSdk.ts index 8a1d413..7daa3af 100644 --- a/src/euidSdk.ts +++ b/src/euidSdk.ts @@ -1,5 +1,5 @@ import { EventType, CallbackHandler } from './callbackManager'; -import { CallbackContainer, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase'; +import { CallbackContainer, IdHelper, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase'; import { ProductDetails } from './product'; import { UidSecureSignalProviderType } from './secureSignal_types'; import { loadConfig } from './configManager'; @@ -13,6 +13,8 @@ const productDetails: ProductDetails = { cookieName: '__euid', }; +type EUIDHelper = IdHelper; + export class EUID extends SdkBase { private static cookieName = productDetails.cookieName; // Deprecated. Integrators should never access the cookie directly! @@ -55,6 +57,7 @@ export class EUID extends SdkBase { declare global { interface Window { __euid: EUID | SDKSetup | undefined; + __euidHelper: IdHelper | undefined; __euidSecureSignalProvider?: UidSecureSignalProviderType; } } @@ -80,6 +83,7 @@ export function __euidInternalHandleScriptLoad() { const callbacks = window?.__euid?.callbacks || []; const callbackContainer: CallbackContainer = {}; window.__euid = new EUID(callbacks, callbackContainer); + window.__euidHelper = new IdHelper(); if (callbackContainer.callback) callbackContainer.callback(); bootstrapInit(); } diff --git a/src/sdkBase.ts b/src/sdkBase.ts index a238d65..afb250c 100644 --- a/src/sdkBase.ts +++ b/src/sdkBase.ts @@ -13,7 +13,7 @@ import { isNormalizedPhone, normalizeEmail } from './diiNormalization'; import { isBase64Hash } from './hashedDii'; import { PromiseHandler } from './promiseHandler'; import { StorageManager } from './storageManager'; -import { hashAndEncodeIdentifier } from './encoding/hash'; +import { hashAndEncodeIdentifier, hashIdentifier } from './encoding/hash'; import { ProductDetails, ProductName } from './product'; import { storeConfig, updateConfig } from './configManager'; import { loadIdentityFromCookieNoLegacy } from './cookieManager'; @@ -27,6 +27,24 @@ export type SDKSetup = { }; export type CallbackContainer = { callback?: () => void }; +export class IdHelper { + public normalizeEmail(email: string) { + return normalizeEmail(email); + } + + public hashIdentifier(normalizedEmail: string) { + return hashIdentifier(normalizedEmail); + } + + public async hashAndEncodeIdentifier(normalizedEmail: string) { + return await hashAndEncodeIdentifier(normalizedEmail); + } + + public isNormalizedPhone(phone: string) { + return isNormalizedPhone(phone); + } +} + export abstract class SdkBase { static get VERSION() { return version; diff --git a/src/uid2Sdk.ts b/src/uid2Sdk.ts index 4f101b4..3230d29 100644 --- a/src/uid2Sdk.ts +++ b/src/uid2Sdk.ts @@ -1,31 +1,11 @@ import { EventType, CallbackHandler } from './callbackManager'; -import { isNormalizedPhone, normalizeEmail } from './diiNormalization'; -import { hashAndEncodeIdentifier, hashIdentifier } from './encoding/hash'; -import { CallbackContainer, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase'; +import { CallbackContainer, IdHelper, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase'; import { ProductDetails } from './product'; import { loadConfig } from './configManager'; import { UidSecureSignalProviderType } from './secureSignal_types'; export * from './exports'; -export class UID2Helper { - public normalizeEmail(email: string) { - return normalizeEmail(email); - } - - public hashIdentifier(normalizedEmail: string) { - return hashIdentifier(normalizedEmail); - } - - public async hashAndEncodeIdentifier(normalizedEmail: string) { - return await hashAndEncodeIdentifier(normalizedEmail); - } - - public isNormalizedPhone(phone: string) { - return isNormalizedPhone(phone); - } -} - const productDetails: ProductDetails = { name: 'UID2', defaultBaseUrl: 'https://prod.uidapi.com', @@ -75,7 +55,7 @@ export class UID2 extends SdkBase { declare global { interface Window { __uid2: UID2 | SDKSetup | undefined; - __uid2Helper: UID2Helper | undefined; + __uid2Helper: IdHelper | undefined; __uid2SecureSignalProvider?: UidSecureSignalProviderType; } } @@ -102,7 +82,7 @@ export function __uid2InternalHandleScriptLoad() { const callbacks = window?.__uid2?.callbacks || []; const callbackContainer: CallbackContainer = {}; window.__uid2 = new UID2(callbacks, callbackContainer); - window.__uid2Helper = new UID2Helper(); + window.__uid2Helper = new IdHelper(); if (callbackContainer.callback) callbackContainer.callback(); bootstrapInit(); } From 03195000476c3b1859325fe5df358149cc9709a8 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 25 Nov 2024 12:06:53 -0700 Subject: [PATCH 2/3] no need for type --- src/euidSdk.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/euidSdk.ts b/src/euidSdk.ts index 7daa3af..716eb39 100644 --- a/src/euidSdk.ts +++ b/src/euidSdk.ts @@ -13,8 +13,6 @@ const productDetails: ProductDetails = { cookieName: '__euid', }; -type EUIDHelper = IdHelper; - export class EUID extends SdkBase { private static cookieName = productDetails.cookieName; // Deprecated. Integrators should never access the cookie directly! From bd95942ac201e44b71d954bdbf612ffb778a36dc Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Tue, 26 Nov 2024 10:42:10 -0700 Subject: [PATCH 3/3] fixed naming to uid helper --- src/euidSdk.ts | 6 +++--- src/sdkBase.ts | 2 +- src/uid2Sdk.ts | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/euidSdk.ts b/src/euidSdk.ts index 716eb39..5fa7f45 100644 --- a/src/euidSdk.ts +++ b/src/euidSdk.ts @@ -1,5 +1,5 @@ import { EventType, CallbackHandler } from './callbackManager'; -import { CallbackContainer, IdHelper, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase'; +import { CallbackContainer, UIDHelper, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase'; import { ProductDetails } from './product'; import { UidSecureSignalProviderType } from './secureSignal_types'; import { loadConfig } from './configManager'; @@ -55,7 +55,7 @@ export class EUID extends SdkBase { declare global { interface Window { __euid: EUID | SDKSetup | undefined; - __euidHelper: IdHelper | undefined; + __euidHelper: UIDHelper | undefined; __euidSecureSignalProvider?: UidSecureSignalProviderType; } } @@ -81,7 +81,7 @@ export function __euidInternalHandleScriptLoad() { const callbacks = window?.__euid?.callbacks || []; const callbackContainer: CallbackContainer = {}; window.__euid = new EUID(callbacks, callbackContainer); - window.__euidHelper = new IdHelper(); + window.__euidHelper = new UIDHelper(); if (callbackContainer.callback) callbackContainer.callback(); bootstrapInit(); } diff --git a/src/sdkBase.ts b/src/sdkBase.ts index afb250c..b402916 100644 --- a/src/sdkBase.ts +++ b/src/sdkBase.ts @@ -27,7 +27,7 @@ export type SDKSetup = { }; export type CallbackContainer = { callback?: () => void }; -export class IdHelper { +export class UIDHelper { public normalizeEmail(email: string) { return normalizeEmail(email); } diff --git a/src/uid2Sdk.ts b/src/uid2Sdk.ts index 3230d29..0568aff 100644 --- a/src/uid2Sdk.ts +++ b/src/uid2Sdk.ts @@ -1,5 +1,5 @@ import { EventType, CallbackHandler } from './callbackManager'; -import { CallbackContainer, IdHelper, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase'; +import { CallbackContainer, UIDHelper, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase'; import { ProductDetails } from './product'; import { loadConfig } from './configManager'; import { UidSecureSignalProviderType } from './secureSignal_types'; @@ -55,7 +55,7 @@ export class UID2 extends SdkBase { declare global { interface Window { __uid2: UID2 | SDKSetup | undefined; - __uid2Helper: IdHelper | undefined; + __uid2Helper: UIDHelper | undefined; __uid2SecureSignalProvider?: UidSecureSignalProviderType; } } @@ -82,7 +82,7 @@ export function __uid2InternalHandleScriptLoad() { const callbacks = window?.__uid2?.callbacks || []; const callbackContainer: CallbackContainer = {}; window.__uid2 = new UID2(callbacks, callbackContainer); - window.__uid2Helper = new IdHelper(); + window.__uid2Helper = new UIDHelper(); if (callbackContainer.callback) callbackContainer.callback(); bootstrapInit(); }