Skip to content

Commit f95bbbc

Browse files
move phone number function to sdkbase
1 parent e862d48 commit f95bbbc

File tree

2 files changed

+24
-29
lines changed

2 files changed

+24
-29
lines changed

src/sdkBase.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ClientSideIdentityOptions,
1010
isClientSideIdentityOptionsOrThrow,
1111
} from './clientSideIdentityOptions';
12-
import { normalizeEmail } from './diiNormalization';
12+
import { isNormalizedPhone, normalizeEmail } from './diiNormalization';
1313
import { isBase64Hash } from './hashedDii';
1414
import { PromiseHandler } from './promiseHandler';
1515
import { StorageManager } from './storageManager';
@@ -108,6 +108,29 @@ export abstract class SdkBase {
108108
await this.callCstgAndSetIdentity({ emailHash: emailHash }, opts);
109109
}
110110

111+
public async setIdentityFromPhone(phone: string, opts: ClientSideIdentityOptions) {
112+
this.throwIfInitNotComplete('Cannot set identity before calling init.');
113+
isClientSideIdentityOptionsOrThrow(opts, this._product.name);
114+
115+
if (!isNormalizedPhone(phone)) {
116+
throw new Error('Invalid phone number');
117+
}
118+
119+
const phoneHash = await hashAndEncodeIdentifier(phone);
120+
await this.callCstgAndSetIdentity({ phoneHash: phoneHash }, opts);
121+
}
122+
123+
public async setIdentityFromPhoneHash(phoneHash: string, opts: ClientSideIdentityOptions) {
124+
this.throwIfInitNotComplete('Cannot set identity before calling init.');
125+
isClientSideIdentityOptionsOrThrow(opts, this._product.name);
126+
127+
if (!isBase64Hash(phoneHash)) {
128+
throw new Error('Invalid hash');
129+
}
130+
131+
await this.callCstgAndSetIdentity({ phoneHash: phoneHash }, opts);
132+
}
133+
111134
public setIdentity(identity: Identity | OptoutIdentity) {
112135
if (this._apiClient) this._apiClient.abortActiveRequests();
113136
const validatedIdentity = this.validateAndSetIdentity(identity);

src/uid2Sdk.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { EventType, CallbackHandler } from './callbackManager';
2-
import {
3-
ClientSideIdentityOptions,
4-
isClientSideIdentityOptionsOrThrow,
5-
} from './clientSideIdentityOptions';
62
import { isNormalizedPhone, normalizeEmail } from './diiNormalization';
7-
import { isBase64Hash } from './hashedDii';
83
import { hashAndEncodeIdentifier, hashIdentifier } from './encoding/hash';
94
import { CallbackContainer, sdkAssertErrorText, SdkBase, SDKSetup } from './sdkBase';
105
import { ProductDetails } from './product';
@@ -75,29 +70,6 @@ export class UID2 extends SdkBase {
7570
callbackContainer.callback = runCallbacks;
7671
}
7772
}
78-
79-
public async setIdentityFromPhone(phone: string, opts: ClientSideIdentityOptions) {
80-
this.throwIfInitNotComplete('Cannot set identity before calling init.');
81-
isClientSideIdentityOptionsOrThrow(opts, this._product.name);
82-
83-
if (!isNormalizedPhone(phone)) {
84-
throw new Error('Invalid phone number');
85-
}
86-
87-
const phoneHash = await hashAndEncodeIdentifier(phone);
88-
await this.callCstgAndSetIdentity({ phoneHash: phoneHash }, opts);
89-
}
90-
91-
public async setIdentityFromPhoneHash(phoneHash: string, opts: ClientSideIdentityOptions) {
92-
this.throwIfInitNotComplete('Cannot set identity before calling init.');
93-
isClientSideIdentityOptionsOrThrow(opts, this._product.name);
94-
95-
if (!isBase64Hash(phoneHash)) {
96-
throw new Error('Invalid hash');
97-
}
98-
99-
await this.callCstgAndSetIdentity({ phoneHash: phoneHash }, opts);
100-
}
10173
}
10274

10375
declare global {

0 commit comments

Comments
 (0)