-
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
trackVerified() behavior by platform #121
Changes from all commits
4cae05e
91939eb
1e1f2b0
ccdbdf6
6744b14
6689d13
848c4ca
e900ce9
ceb102e
1c4261c
05afcb1
002f7ee
6a62840
5710756
c91f046
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 |
---|---|---|
|
@@ -9,7 +9,7 @@ import Storage from '../storage'; | |
import type { RadarTrackParams, RadarTrackResponse, RadarTrackTokenResponse } from '../types'; | ||
|
||
class VerifyAPI { | ||
static async trackVerified(params: RadarTrackParams, encrypted: Boolean = false) { | ||
static async trackVerified(params: RadarTrackParams, encrypted: Boolean = false, host: string = 'http://localhost:52516') { | ||
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. Same as above, lets just make |
||
const options = Config.get(); | ||
|
||
// user indentification fields | ||
|
@@ -47,7 +47,7 @@ class VerifyAPI { | |
method: 'GET', | ||
path: 'verify', | ||
data: body, | ||
host: 'https://radar-verify.com:52516', | ||
host, | ||
}); | ||
|
||
const { user, events, token } = response; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Config from './config'; | ||
import Storage from './storage'; | ||
|
||
const generateUUID = (): string => { | ||
|
@@ -11,6 +12,23 @@ const generateUUID = (): string => { | |
}; | ||
|
||
class Device { | ||
static getPlatform(): string { | ||
let userAgent = navigator.userAgent; | ||
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. Any idea how reliable this is? UserAgent parsing can have a lot of edge cases 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. I think it's the best option for this use case. There's also |
||
if (userAgent) { | ||
userAgent = userAgent.toLowerCase(); | ||
if (userAgent.includes('macintosh')) { | ||
return 'DESKTOP_MAC'; | ||
} else if (userAgent.includes('windows')) { | ||
return 'DESKTOP_WINDOWS'; | ||
} else if (userAgent.includes('iphone') || userAgent.includes('ipad') || userAgent.includes('ipod')) { | ||
return 'MOBILE_IOS'; | ||
} else if (userAgent.includes('android')) { | ||
return 'MOBILE_ANDROID'; | ||
} | ||
} | ||
return 'OTHER'; | ||
} | ||
|
||
static getDeviceId(): string { | ||
// use existing deviceId if present | ||
const deviceId = Storage.getItem(Storage.DEVICE_ID); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ import { | |
RadarBadRequestError, | ||
RadarDesktopAppError, | ||
RadarForbiddenError, | ||
RadarLocationError, | ||
RadarLocationPermissionsError, | ||
RadarNotFoundError, | ||
RadarPaymentRequiredError, | ||
RadarPublishableKeyError, | ||
|
@@ -96,6 +98,13 @@ class Http { | |
return reject(new RadarServerError(response)); | ||
} | ||
|
||
const error = response?.meta?.error; | ||
if (error === 'ERROR_PERMISSIONS') { | ||
return reject(new RadarLocationPermissionsError('Location permissions not granted')); | ||
} else if (error === 'ERROR_LOCATION') { | ||
return reject(new RadarLocationError('Could not determine location')); | ||
} | ||
|
||
if (xhr.status == 200) { | ||
return resolve(response); | ||
} | ||
|
@@ -132,7 +141,7 @@ class Http { | |
} | ||
|
||
xhr.onerror = function() { | ||
if (host && host === 'https://radar-verify.com:52516') { | ||
if (host && (host === 'https://radar-verify.com:52516' || host === 'http://localhost:52516')) { | ||
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. if (host && host.includes('localhost:52516')) { |
||
reject(new RadarDesktopAppError()); | ||
} else { | ||
reject(new RadarServerError()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import Config from './config'; | ||
import Device from './device'; | ||
import Logger from './logger'; | ||
import Storage from './storage'; | ||
import Navigator from './navigator'; | ||
|
@@ -33,6 +34,8 @@ import type { | |
RadarSearchGeofencesParams, | ||
RadarSearchPlacesParams, | ||
RadarTrackParams, | ||
RadarTrackResponse, | ||
RadarTrackTokenResponse, | ||
RadarTripOptions, | ||
RadarValidateAddressParams, | ||
} from './types'; | ||
|
@@ -136,20 +139,42 @@ class Radar { | |
return Navigator.getCurrentPosition(); | ||
} | ||
|
||
public static trackOnce(params: RadarTrackParams = {}) { | ||
public static trackOnce(params: RadarTrackParams = {}): Promise<RadarTrackResponse> { | ||
try { | ||
return TrackAPI.trackOnce(params); | ||
} finally { | ||
ConfigAPI.getConfig(params); // call with updated permissions | ||
} | ||
} | ||
|
||
public static trackVerified(params: RadarTrackParams = {}) { | ||
return VerifyAPI.trackVerified(params); | ||
public static trackVerified(params: RadarTrackParams = {}): Promise<RadarTrackResponse> { | ||
const platform = Device.getPlatform(); | ||
if (platform === 'DESKTOP_MAC') { // use Mac app | ||
return VerifyAPI.trackVerified(params, false, 'https://radar-verify.com:52516'); | ||
} else if (platform === 'DESKTOP_WINDOWS') { // use Windows app | ||
return VerifyAPI.trackVerified(params, false, 'http://localhost:52516'); | ||
} else { // bypass desktop app | ||
try { | ||
return TrackAPI.trackOnce(params, true, false, 'https://api-verified.radar.io'); | ||
} finally { | ||
ConfigAPI.getConfig(params); // call with updated permissions | ||
} | ||
} | ||
Comment on lines
+152
to
+162
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. Small nit, if each branch returns technically these don't need to be if (platform === 'DESKTOP_MAC') { // use Mac app
return VerifyAPI.trackVerified(params, false, 'https://radar-verify.com:52516');
}
if (platform === 'DESKTOP_WINDOWS') { // use Windows app
return VerifyAPI.trackVerified(params, false, 'http://localhost:52516');
}
// bypass desktop app
try {
return TrackAPI.trackOnce(params, true, false, 'https://api-verified.radar.io');
} finally {
ConfigAPI.getConfig(params); // call with updated permissions
} 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. Can update |
||
} | ||
|
||
public static trackVerifiedToken(params: RadarTrackParams = {}) { | ||
return VerifyAPI.trackVerified(params, true); | ||
public static trackVerifiedToken(params: RadarTrackParams = {}): Promise<RadarTrackTokenResponse> { | ||
const platform = Device.getPlatform(); | ||
if (platform === 'DESKTOP_MAC') { // use Mac app | ||
return VerifyAPI.trackVerified(params, true, 'https://radar-verify.com:52516'); | ||
} else if (platform === 'DESKTOP_WINDOWS') { // use Windows app | ||
return VerifyAPI.trackVerified(params, true, 'http://localhost:52516'); | ||
} else { // bypass desktop app | ||
try { | ||
return TrackAPI.trackOnce(params, true, true, 'https://api-verified.radar.io'); | ||
} finally { | ||
ConfigAPI.getConfig(params); // call with updated permissions | ||
} | ||
} | ||
} | ||
|
||
public static getContext(params: Location) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export default '4.1.5'; | ||
export default '4.1.6-beta.1'; |
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.
Lets just roll these into
RadarTrackParams
(maybe except forhost
since it's not send in the track request)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.
Or add another object that is like
verifiedOptions
or somethingThere 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 thought about adding it to
RadarTrackParams
, but we don't want to allow developers to pass it explicitly. More an internal implementation detail. Whether we passencrypted = true
(which we will prob rename or remove, btw) is implicit in whether the developer is callingtrackVerified()
or `trackVerifiedToken()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.
We should still wrap it in an optional object. Otherwise it's hard to tell what the arguments are at the callsite:
As opposed to: