diff --git a/README.md b/README.md index 2ec2eae..a332a9d 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ Radar.initialize('prj_test_pk_...', { /* options */ }); Add the following script in your `html` file ```html - + ``` Then initialize the Radar SDK @@ -73,8 +73,8 @@ To create a map, first initialize the Radar SDK with your publishable key. Then ```html - - + + @@ -98,8 +98,8 @@ To create an autocomplete input, first initialize the Radar SDK with your publis ```html - - + + @@ -130,8 +130,8 @@ To power [geofencing](https://radar.com/documentation/geofencing/overview) exper ```html - - + + diff --git a/package-lock.json b/package-lock.json index 02f3152..478e8f5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "radar-sdk-js", - "version": "4.4.4", + "version": "4.4.6-beta.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "radar-sdk-js", - "version": "4.4.4", + "version": "4.4.5", "license": "ISC", "dependencies": { "@types/geojson": "^7946.0.10" diff --git a/package.json b/package.json index 0198f30..bbfc48c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "radar-sdk-js", - "version": "4.4.4", + "version": "4.4.6-beta.1", "description": "Web Javascript SDK for Radar, location infrastructure for mobile and web apps.", "homepage": "https://radar.com", "type": "module", diff --git a/src/api.ts b/src/api.ts index dca330d..93e3dc6 100644 --- a/src/api.ts +++ b/src/api.ts @@ -31,6 +31,7 @@ import type { RadarSearchPlacesParams, RadarStartTrackingVerifiedParams, RadarTrackParams, + RadarTrackVerifiedParams, RadarTrackVerifiedResponse, RadarTripOptions, RadarValidateAddressParams, @@ -75,7 +76,7 @@ class Radar { Logger.info(`initialized with ${live ? 'live' : 'test'} publishableKey.`); if (options.debug) { - Logger.info(`using options: ${JSON.stringify(options)}`); + Logger.debug('using options', options); } // NOTE(jasonl): this allows us to run jest tests @@ -129,7 +130,7 @@ class Radar { } } - public static trackVerified(params: RadarTrackParams = {}) { + public static trackVerified(params: RadarTrackVerifiedParams = {}) { return VerifyAPI.trackVerified(params); } @@ -141,8 +142,8 @@ class Radar { return VerifyAPI.stopTrackingVerified(); } - public static getVerifiedLocationToken() { - return VerifyAPI.getVerifiedLocationToken(); + public static getVerifiedLocationToken(params: RadarTrackVerifiedParams = {}) { + return VerifyAPI.getVerifiedLocationToken(params); } public static setExpectedJurisdiction(countryCode?: string, stateCode?: string) { diff --git a/src/api/track.ts b/src/api/track.ts index 8548c2a..3862a44 100644 --- a/src/api/track.ts +++ b/src/api/track.ts @@ -111,6 +111,7 @@ class TrackAPI { let sclVal = -1; let cslVal = -1; + /* try { const [sclRes, csl] = await Promise.all([ Http.request({ @@ -126,6 +127,7 @@ class TrackAPI { } catch (err) { // do nothing, send scl = -1 and csl = -1 } + */ const payload = { payload: JSON.stringify({ diff --git a/src/api/verify.ts b/src/api/verify.ts index d7ef2f1..7c5cff9 100644 --- a/src/api/verify.ts +++ b/src/api/verify.ts @@ -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,7 @@ class VerifyAPI { static async startTrackingVerified(params: RadarStartTrackingVerifiedParams) { const doTrackVerified = async () => { - const trackRes = await this.trackVerified({}); + const trackRes = await this.trackVerified(params); const { interval } = params; @@ -143,16 +156,16 @@ class VerifyAPI { } } - static async getVerifiedLocationToken() { + static async getVerifiedLocationToken(params: RadarTrackVerifiedParams) { const lastTokenElapsed = (performance.now() - lastTokenNow) / 1000; - if (lastToken) { + if (lastToken && lastToken.passed) { if (lastTokenElapsed < (lastToken.expiresIn || 0)) { return lastToken; } } - return this.trackVerified({}); + return this.trackVerified(params); } static setExpectedJurisdiction(countryCode?: string, stateCode?: string) { diff --git a/src/logger.ts b/src/logger.ts index 71bf4da..21701ea 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -27,9 +27,9 @@ const getLevel = (): number => { } class Logger { - public static debug(message: string) { + public static debug(message: string, options?: any) { if (getLevel() === LOG_LEVELS.debug) { - console.log(`Radar SDK (debug): ${message.trim()}`); + console.log(`Radar SDK (debug): ${message.trim()}`, options); } } diff --git a/src/types.ts b/src/types.ts index 2dd2c1e..db0c145 100644 --- a/src/types.ts +++ b/src/types.ts @@ -76,8 +76,16 @@ export interface RadarTrackParams { fraud?: boolean; } +export interface RadarTrackVerifiedParams { + userId?: string; + description?: string; + metadata?: RadarMetadata; + skipVerifyApp?: boolean; +} + export interface RadarStartTrackingVerifiedParams { interval: number; + skipVerifyApp?: boolean; } export enum RadarEventConfidence { diff --git a/src/ui/RadarMap.ts b/src/ui/RadarMap.ts index 4ccfcbd..7d04429 100644 --- a/src/ui/RadarMap.ts +++ b/src/ui/RadarMap.ts @@ -96,7 +96,7 @@ class RadarMap extends maplibregl.Map { radarMapOptions, { style }, ); - Logger.debug(`initialize map with options: ${JSON.stringify(mapOptions)}`); + Logger.debug('map initailized with options', mapOptions); (mapOptions as maplibregl.MapOptions).transformRequest = (url, resourceType) => { // this handles when a style is switched diff --git a/src/ui/autocomplete.ts b/src/ui/autocomplete.ts index 3d25cac..79bf13b 100644 --- a/src/ui/autocomplete.ts +++ b/src/ui/autocomplete.ts @@ -186,7 +186,7 @@ class AutocompleteUI { this.inputField.addEventListener('blur', this.close.bind(this), true); } - Logger.debug(`AutocompleteUI iniailized with options: ${JSON.stringify(this.config)}`); + Logger.debug('AutocompleteUI initialized with options', this.config); } public handleInput() { diff --git a/src/version.ts b/src/version.ts index 6b04937..5e827c3 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1 +1 @@ -export default '4.4.4'; +export default '4.4.6-beta.1'; \ No newline at end of file