-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new no identity available event #184
Merged
ashleysmithTTD
merged 28 commits into
main
from
ans-UID2-2295-no-identity-available-event
Feb 25, 2025
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
a34660a
first examples of no identity available
ashleysmithTTD 8460640
added more tests where identity could be unavailable
ashleysmithTTD bacfbf6
no identity available on set identity
ashleysmithTTD 59856db
more set identity examples
ashleysmithTTD f8b39dd
no identity available new event
ashleysmithTTD d9b53b0
callback changes no need to init
ashleysmithTTD d549c07
Merge branch 'main' into ans-UID2-2295-no-identity-available-event
ashleysmithTTD d8cc05d
not needed from prev branch
ashleysmithTTD 75b4952
wrote separate identity function for callback instead
ashleysmithTTD ea6f0e4
added tests for cstg and refresh timer
ashleysmithTTD 1879ddc
added test for local storage
ashleysmithTTD f0d0bed
added test without init
ashleysmithTTD b991a98
identity should always be null
ashleysmithTTD 7aa9c23
organizing tests
ashleysmithTTD dc38026
added cookie example also
ashleysmithTTD 2a7f821
cleaned up valid identity test
ashleysmithTTD 50d0cea
added sdk loaded check in run callbacks
ashleysmithTTD 3c0a13a
removed identity forced to be null
ashleysmithTTD ccd68ae
fixed tests to expect expired identity sometimes
ashleysmithTTD 6fcb0d3
cleaned up get identity to be more consistent with isvalididentity fu…
ashleysmithTTD 6bea2a5
the check iwll already happen in islogin required
ashleysmithTTD c16234b
unavailable check still needed
ashleysmithTTD f1d89c5
removed any no identity available event reference
ashleysmithTTD 12ae483
dont need separate get identity functions anymore
ashleysmithTTD 1c4167c
no need to call is identity available everywhere
ashleysmithTTD 4053cb7
clean up get identity
ashleysmithTTD c4061fe
get identity return
ashleysmithTTD 86501e8
fixed is identity available
ashleysmithTTD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { version } from '../package.json'; | ||
import { OptoutIdentity, Identity, isOptoutIdentity } from './Identity'; | ||
import { OptoutIdentity, Identity, isOptoutIdentity, isValidIdentity } from './Identity'; | ||
import { IdentityStatus, InitCallbackManager } from './initCallbacks'; | ||
import { SdkOptions, isSDKOptionsOrThrow } from './sdkOptions'; | ||
import { Logger, MakeLogger } from './sdk/logger'; | ||
|
@@ -163,9 +163,8 @@ export abstract class SdkBase { | |
|
||
public getIdentity(): Identity | null { | ||
const identity = this._identity ?? this.getIdentityNoInit(); | ||
return identity && !this.temporarilyUnavailable(identity) && !isOptoutIdentity(identity) | ||
? identity | ||
: null; | ||
// if identity is valid (includes not opted out) and available, return it | ||
return isValidIdentity(identity) && !this.temporarilyUnavailable(identity) ? identity : null; | ||
} | ||
|
||
// When the SDK has been initialized, this function should return the token | ||
|
@@ -181,11 +180,23 @@ export abstract class SdkBase { | |
} | ||
|
||
public isLoginRequired() { | ||
const identity = this._identity ?? this.getIdentityNoInit(); | ||
// if identity temporarily unavailable, login is not required | ||
if (this.temporarilyUnavailable(identity)) { | ||
return false; | ||
} | ||
return !this.isIdentityAvailable(); | ||
} | ||
|
||
public isIdentityAvailable() { | ||
return this.isIdentityValid() || this._apiClient?.hasActiveRequests(); | ||
const identity = this._identity ?? this.getIdentityNoInit(); | ||
// available if identity exists and has not expired or if there active requests | ||
return ( | ||
(identity && | ||
!hasExpired(identity.refresh_expires) && | ||
!this.temporarilyUnavailable(identity)) || | ||
this._apiClient?.hasActiveRequests() | ||
); | ||
} | ||
|
||
public hasOptedOut() { | ||
|
@@ -230,10 +241,14 @@ export abstract class SdkBase { | |
this._initCallbackManager?.addInitCallback(opts.callback); | ||
} | ||
|
||
const useNewIdentity = | ||
opts.identity && | ||
(!previousOpts.identity || | ||
opts.identity.identity_expires > previousOpts.identity.identity_expires); | ||
let useNewIdentity; | ||
if (!opts.identity) useNewIdentity = true; | ||
else { | ||
useNewIdentity = | ||
!previousOpts.identity || | ||
opts.identity.identity_expires > previousOpts.identity.identity_expires; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. found in testing that we didnt have the possibility that opts.identity just doesn't exist, which would automatically make |
||
if (useNewIdentity || opts.callback) { | ||
let identity = useNewIdentity ? opts.identity : previousOpts.identity ?? null; | ||
if (identity) { | ||
|
@@ -280,11 +295,6 @@ export abstract class SdkBase { | |
if (this.hasOptedOut()) this._callbackManager.runCallbacks(EventType.OptoutReceived, {}); | ||
} | ||
|
||
private isIdentityValid() { | ||
const identity = this._identity ?? this.getIdentityNoInit(); | ||
return identity && !hasExpired(identity.refresh_expires); | ||
} | ||
|
||
private temporarilyUnavailable(identity: Identity | OptoutIdentity | null | undefined) { | ||
if (!identity && this._apiClient?.hasActiveRequests()) return true; | ||
// returns true if identity is expired but refreshable | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With everything that can be done without init, I dont think it makes sense anymore to not run callbacks if init is not complete