Skip to content

Commit 75b4952

Browse files
wrote separate identity function for callback instead
1 parent d8cc05d commit 75b4952

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/callbackManager.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ export type PayloadWithIdentity = {
1919
};
2020

2121
export class CallbackManager {
22-
private _getIdentity: (isForCallback: boolean) => Identity | null | undefined;
22+
private _getIdentity: () => Identity | null | undefined;
2323
private _logger: Logger;
2424
private _sdk: SdkBase;
2525
private _productName: string;
2626
constructor(
2727
sdk: SdkBase,
2828
productName: string,
29-
getIdentity: (isForCallback: boolean) => Identity | null | undefined,
29+
getIdentity: () => Identity | null | undefined,
3030
logger: Logger
3131
) {
3232
this._productName = productName;
@@ -44,7 +44,7 @@ export class CallbackManager {
4444
this.safeRunCallback(c, EventType.SdkLoaded, {});
4545
if (this._sentInit)
4646
this.safeRunCallback(c, EventType.InitCompleted, {
47-
identity: this._getIdentity(true) ?? null,
47+
identity: this._getIdentity() ?? null,
4848
});
4949
}
5050
return Array.prototype.push.apply(this._sdk.callbacks, args);
@@ -56,7 +56,7 @@ export class CallbackManager {
5656

5757
const enrichedPayload = {
5858
...payload,
59-
identity: this._getIdentity(true) ?? null,
59+
identity: this._getIdentity() ?? null,
6060
};
6161
for (const callback of this._sdk.callbacks) {
6262
this.safeRunCallback(callback, event, enrichedPayload);

src/sdkBase.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export abstract class SdkBase {
8484
this._callbackManager = new CallbackManager(
8585
this,
8686
this._product.name,
87-
() => this.getIdentity(true),
87+
() => this.getIdentityForCallback(),
8888
this._logger
8989
);
9090
}
@@ -161,20 +161,25 @@ export abstract class SdkBase {
161161
this.isIdentityAvailable();
162162
}
163163

164-
public getIdentity(isForCallback?: boolean): Identity | null {
164+
public getIdentity(): Identity | null {
165165
const identity = this._identity ?? this.getIdentityNoInit();
166166
const isValid =
167167
identity && !this.temporarilyUnavailable(identity) && !isOptoutIdentity(identity);
168168
if (!isValid) {
169-
if (!isForCallback) {
170-
this._callbackManager.runCallbacks(EventType.NoIdentityAvailable, {});
171-
}
169+
this._callbackManager.runCallbacks(EventType.NoIdentityAvailable, {});
172170
return null;
173171
} else {
174172
return identity;
175173
}
176174
}
177175

176+
private getIdentityForCallback(): Identity | null {
177+
const identity = this._identity ?? this.getIdentityNoInit();
178+
return identity && !this.temporarilyUnavailable(identity) && !isOptoutIdentity(identity)
179+
? identity
180+
: null;
181+
}
182+
178183
// When the SDK has been initialized, this function should return the token
179184
// from the most recent refresh request, if there is a request, wait for the
180185
// new token. Otherwise, returns a promise which will be resolved after init.

0 commit comments

Comments
 (0)