-
Notifications
You must be signed in to change notification settings - Fork 11
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 skipVerifyApp param to trackVerified() and startTrackingVerified() #185
Changes from 2 commits
0e13edd
6650ead
f14698b
406f73a
bfd792c
007527d
cd4fc9e
e417313
32c6198
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,9 @@ import Http from '../http'; | |
import Logger from '../logger'; | ||
import Session from '../session'; | ||
import Storage from '../storage'; | ||
import TrackAPI from './track'; | ||
|
||
import type { RadarStartTrackingVerifiedParams, RadarTrackParams, RadarTrackVerifiedResponse } from '../types'; | ||
import type { RadarStartTrackingVerifiedParams, RadarTrackVerifiedParams, RadarTrackVerifiedResponse } from '../types'; | ||
|
||
let tokenTimeoutId: any | null = null; | ||
let tokenCallback: ((token: RadarTrackVerifiedResponse) => void) | null = null; | ||
|
@@ -16,13 +17,15 @@ let expectedCountryCode: string | null = null; | |
let expectedStateCode: string | null = null; | ||
|
||
class VerifyAPI { | ||
static async trackVerified(params: RadarTrackParams, encrypted: Boolean = false) { | ||
static async trackVerified(params: RadarTrackVerifiedParams, encrypted: Boolean = false) { | ||
const options = Config.get(); | ||
|
||
const { skipVerifyApp } = params; | ||
|
||
// user indentification fields | ||
const userId = params.userId || Storage.getItem(Storage.USER_ID); | ||
const deviceId = params.deviceId || Device.getDeviceId(); | ||
const installId = params.installId || Device.getInstallId(); | ||
const deviceId = Device.getDeviceId(); | ||
const installId = Device.getInstallId(); | ||
const sessionId = Session.getSessionId(); | ||
const description = params.description || Storage.getItem(Storage.DESCRIPTION); | ||
|
||
|
@@ -36,59 +39,69 @@ class VerifyAPI { | |
// other info | ||
const metadata = params.metadata || Storage.getJSON(Storage.METADATA); | ||
|
||
const body = { | ||
...params, | ||
description, | ||
deviceId, | ||
foreground: true, | ||
installId, | ||
sessionId, | ||
metadata, | ||
sdkVersion: SDK_VERSION, | ||
stopped: true, | ||
userId, | ||
encrypted, | ||
expectedCountryCode, | ||
expectedStateCode, | ||
}; | ||
|
||
let userAgent = navigator.userAgent; | ||
const apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad')); | ||
|
||
const response: any = await Http.request({ | ||
method: 'GET', | ||
path: 'verify', | ||
data: body, | ||
host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516', | ||
}); | ||
|
||
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response; | ||
let location; | ||
if (user && user.location && user.location.coordinates && user.locationAccuracy) { | ||
location = { | ||
latitude: user.location.coordinates[1], | ||
longitude: user.location.coordinates[0], | ||
accuracy: user.locationAccuracy, | ||
let trackRes: RadarTrackVerifiedResponse; | ||
if (skipVerifyApp) { | ||
trackRes = await TrackAPI.trackOnce({ | ||
userId: userId ?? undefined, | ||
description: description ?? undefined, | ||
metadata: metadata, | ||
fraud: true, | ||
}); | ||
} else { | ||
const body = { | ||
...params, | ||
description, | ||
deviceId, | ||
foreground: true, | ||
installId, | ||
sessionId, | ||
metadata, | ||
sdkVersion: SDK_VERSION, | ||
stopped: true, | ||
userId, | ||
encrypted, | ||
expectedCountryCode, | ||
expectedStateCode, | ||
}; | ||
} | ||
if (expiresAt) { | ||
expiresAt = new Date(expiresAt); | ||
} | ||
|
||
const trackRes = { | ||
user, | ||
events, | ||
location, | ||
token, | ||
expiresAt, | ||
expiresIn, | ||
passed, | ||
failureReasons, | ||
_id, | ||
} as RadarTrackVerifiedResponse; | ||
|
||
if (options.debug) { | ||
trackRes.response = response; | ||
|
||
let userAgent = navigator.userAgent; | ||
const apple = userAgent && (userAgent.toLowerCase().includes('mac') || userAgent.toLowerCase().includes('iphone') || userAgent.toLowerCase().includes('ipod') || userAgent.toLowerCase().includes('ipad')); | ||
|
||
const response: any = await Http.request({ | ||
method: 'GET', | ||
path: 'verify', | ||
data: body, | ||
host: apple ? 'https://radar-verify.com:52516' : 'http://localhost:52516', | ||
}); | ||
|
||
let { user, events, token, expiresAt, expiresIn, passed, failureReasons, _id } = response; | ||
let location; | ||
if (user && user.location && user.location.coordinates && user.locationAccuracy) { | ||
location = { | ||
latitude: user.location.coordinates[1], | ||
longitude: user.location.coordinates[0], | ||
accuracy: user.locationAccuracy, | ||
}; | ||
} | ||
if (expiresAt) { | ||
expiresAt = new Date(expiresAt); | ||
} | ||
|
||
trackRes = { | ||
user, | ||
events, | ||
location, | ||
token, | ||
expiresAt, | ||
expiresIn, | ||
passed, | ||
failureReasons, | ||
_id, | ||
} as RadarTrackVerifiedResponse; | ||
|
||
if (options.debug) { | ||
trackRes.response = response; | ||
} | ||
} | ||
|
||
lastToken = trackRes; | ||
|
@@ -103,7 +116,9 @@ class VerifyAPI { | |
|
||
static async startTrackingVerified(params: RadarStartTrackingVerifiedParams) { | ||
const doTrackVerified = async () => { | ||
const trackRes = await this.trackVerified({}); | ||
const trackRes = await this.trackVerified({ | ||
...params, | ||
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. nit: can probably just pass 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. Good call, updated |
||
}); | ||
|
||
const { interval } = params; | ||
|
||
|
@@ -143,7 +158,7 @@ class VerifyAPI { | |
} | ||
} | ||
|
||
static async getVerifiedLocationToken() { | ||
static async getVerifiedLocationToken(params: RadarTrackVerifiedParams) { | ||
const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000; | ||
|
||
if (lastToken) { | ||
|
@@ -152,7 +167,7 @@ class VerifyAPI { | |
} | ||
} | ||
|
||
return this.trackVerified({}); | ||
return this.trackVerified(params); | ||
} | ||
|
||
static setExpectedJurisdiction(countryCode?: string, stateCode?: string) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default '4.4.3'; | ||
export default '4.4.4'; |
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.
Why the change to get rid of setting these via params? This might be how we override the values int the simulator.
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.
I don't really want to give developers control of these for fraud / geo-compliance use cases. For implementations using the Mac and Windows app, those apps override these anyway (with more stable hardware device IDs)