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

Add startTrackingVerified(), getVerifiedLocationToken(), and onTokenUpdated() #178

Merged
merged 12 commits into from
Aug 14, 2024

Conversation

nickpatrick
Copy link
Contributor

No description provided.

@@ -78,14 +83,86 @@ class VerifyAPI {
expiresAt,
expiresIn,
passed,
failureReasons,
_id,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What _id is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

location._id

} as RadarTrackVerifiedResponse;

if (options.debug) {
trackRes.response = response;
}

lastToken = trackRes;
Copy link
Collaborator

Choose a reason for hiding this comment

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

token is the entire response?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Deserialized to RadarVerifiedLocationToken in mobile SDKs

import type { RadarTrackParams, RadarTrackVerifiedResponse } from '../types';
import type { RadarStartTrackingVerifiedParams, RadarTrackParams, RadarTrackVerifiedResponse } from '../types';

let tokenTimeoutId: any | null = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we namespace these as verified instead of token?

Copy link
Collaborator

@kochis kochis Aug 12, 2024

Choose a reason for hiding this comment

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

Also, it's probably preferable to mark things as optional instead of null

let tokenTimeoutId?: any;
let tokenCallback?: (token: RadarTrackVerifiedResponse) => void;

Otherwise it needs to be explicitly set to null

} as RadarTrackVerifiedResponse;

if (options.debug) {
trackRes.response = response;
}

lastToken = trackRes;
lastTokenNow = performance.now();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should use Date.now() unless there's a need for nano-second measurement (this is really only intended for perf measurement)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem with Date.now() is that you can manipulate it by changing your system clock time, whereas performance.now() is based off of time since page load and harder to tamper with

Copy link
Contributor Author

@nickpatrick nickpatrick Aug 12, 2024

Choose a reason for hiding this comment

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

We do something similar on the mobile SDKs (SystemClock.elapsedRealTimeNanos on Android) for the same reason

}

static setExpectedJurisdiction(countryCode?: string, stateCode?: string) {
expectedCountryCode = countryCode || null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

If these are marked as optional in the definition, we wont need the || null here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting errors because expectedCountryCode is defined as | null instead of | undefined. https://app.circleci.com/pipelines/github/radarlabs/radar-sdk-js/1241/workflows/a23a44d8-bbed-4f3d-a059-163a7b4407c0/jobs/1016

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting errors because expectedCountryCode is defined as | null instead of | undefined. https://app.circleci.com/pipelines/github/radarlabs/radar-sdk-js/1241/workflows/a23a44d8-bbed-4f3d-a059-163a7b4407c0/jobs/1016

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, I think you can just define them as:

let expectedCountryCode?: string;

Comment on lines +12 to +16
let tokenCallback: ((token: RadarTrackVerifiedResponse) => void) | null = null;
let lastToken: RadarTrackVerifiedResponse | null = null;
let lastTokenNow: number = 0;
let expectedCountryCode: string | null = null;
let expectedStateCode: string | null = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is probably fine to define the scoped variables like this, but there are a couple issues:

  1. These wont persist across a page reload
  2. Can run into issues if there are multiple callers (though I think for track we expect a singleton pattern)

If we need to track the last call time across the page-load, probably need to put it in localstorage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't need this to work across page load like userId, so should be good. I could move it inside the class if that's important

Copy link
Collaborator

Choose a reason for hiding this comment

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

If these aren't sensitive it's probably fine. Maybe the user-provided ones should be static variables (callback and expected codes)

Comment on lines +120 to +127
// re-request early to maximize the likelihood that a cached token is available
if (minInterval > 20) {
minInterval = minInterval - 10;
}

// min interval is 10 seconds
if (minInterval < 10) {
minInterval = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

so if I give the interval param as 21 then it is effectively 11 but if I give 15 it is effectively 15?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. I think that's an edge case, but if it bothers us, I can update

@nickpatrick
Copy link
Contributor Author

@david-goodfellow @kochis lmk if any must-fix feedback before 👍

Would love to ship this tonight

kochis
kochis previously approved these changes Aug 13, 2024
@nickpatrick nickpatrick merged commit 33a68b4 into master Aug 14, 2024
3 checks passed
@nickpatrick nickpatrick deleted the start-tracking-verified branch August 14, 2024 15:20
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.

3 participants