Skip to content
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

Support new expiresAt/expiresIn/token/passed fields with trackOnce({ fraud: true }) and trackVerified() #159

Merged
merged 17 commits into from
May 6, 2024

Conversation

nickpatrick
Copy link
Contributor

@nickpatrick nickpatrick commented May 6, 2024

  • When calling trackOnce({ fraud: true }), return new token/expiresAt/expiresIn/passed fields. @tderouin right now we're calculating expiresIn and passed on the client, but cleaner to calculate them on the server. Could be a fast follow
  • Consolidates trackVerified() and trackVerifiedToken(). Now just a single function which returns all of user/events/location/token/expiresAt/expiresIn/passed. No desktop app changes required
  • Renames error codes to match mobile SDKs for consistency. RadarTimeoutError --> RadarNetworkError, RadarLocationPermissionsError --> RadarPermissionsError. Also renames RadarDesktopAppError to RadarVerifyAppError given the addition of the Radar Verify mobile apps
  • Fixes long-standing issue where we return RadarLocationPermissionsError for any location error, including location timeouts. Now we only return RadarPermissionsError for true permissions errors (code 1) and RadarLocationError for location timeouts or unable to determine location (codes 2 and 3)

@@ -212,8 +213,11 @@ export interface RadarTrackResponse extends RadarResponse {
events?: RadarEvent[];
}

export interface RadarTrackTokenResponse extends RadarResponse {
export interface RadarTrackVerifiedResponse extends RadarTrackResponse {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be a separate interface instead of extending RadarTrackResponse

constructor(message: string) {
super(message);
this.name = 'RadarLocationPermissionsError';
this.name = 'RadarPermissionsError';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match mobile SDKs

this.name = 'RadarDesktopAppError';
this.status = 'ERROR_DESKTOP_APP';
super('Radar Verify app not running.');
this.name = 'RadarVerifyAppError';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To account for Radar Verify desktop AND mobile apps

constructor() {
super('Request timed out.');
this.name = 'RadarTimeoutError';
this.status = 'ERROR_TIMED_OUT';
this.name = 'RadarNetworkError';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To match mobile SDKs

kochis
kochis previously approved these changes May 6, 2024
package.json Outdated
@@ -1,6 +1,6 @@
{
"name": "radar-sdk-js",
"version": "4.1.18",
"version": "4.2.0-beta.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we shipping these changes as 4.2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing trackVerifiedToken() and renaming the error codes are breaking changes, so should prob be 4.2.x instead of 4.1.x

src/api/track.ts Outdated
if (expiresAt) {
expiresAt = new Date(expiresAt);
passed = user?.fraud?.passed && user?.country?.passed && user?.state?.passed;
expiresIn = expiresAt ? (expiresAt.getTime() - new Date().getTime()) / 1000 : null;
Copy link
Collaborator

@kochis kochis May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It looks like expiresAt will also always be present here.

nit: You can also do Date.now() instead of new Date().getTime()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. @tderouin if we can expose expiresIn (in seconds, expiresAt - now) in the API response, I can also just remove this, along with passed

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -148,10 +148,6 @@ class Radar {
return VerifyAPI.trackVerified(params);
}

public static trackVerifiedToken(params: RadarTrackParams = {}) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't want this to be a breaking change, could we potentially pass the params here to track width { fraud: true }?

Could also include a deprecation notice:

Logger.warn('DEPRECATED - trackVerifiedToken will be removed in a future release.');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nobody uses this in prod yet (except for our demo page), so I think we're fine to skip this

kochis
kochis previously approved these changes May 6, 2024
if (expiresAt) {
expiresAt = new Date(expiresAt);
passed = user?.fraud?.passed && user?.country?.passed && user?.state?.passed;
expiresIn = (expiresAt.getTime() - Date.now()) / 1000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the name be expiresInSeconds to be explicit? No strong opinion here because jwt uses expiresIn as well and just has the docs saying it is in seconds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't really include units in the field name anywhere else in our APIs, so prefer to keep it expiresIn (if I could go back in a time machine to 2017 I might have used this pattern, but too late now, rather optimize for consistency and brevity)

@nickpatrick nickpatrick merged commit 0c2f659 into master May 6, 2024
3 checks passed
@nickpatrick nickpatrick deleted the track-once-fraud-callback branch May 6, 2024 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants