From dbcc101f49f407b4adc0c55eb35c237954021da3 Mon Sep 17 00:00:00 2001 From: Craig Kochis Date: Wed, 2 Aug 2023 16:34:07 -0400 Subject: [PATCH] truncate session and send location authorization in track requests --- src/api/track.ts | 9 +++++++++ src/session.ts | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/api/track.ts b/src/api/track.ts index fccde1ce..c3202bc8 100644 --- a/src/api/track.ts +++ b/src/api/track.ts @@ -26,6 +26,14 @@ class TrackAPI { accuracy = deviceLocation.accuracy; } + // location authorization + let locationAuthorization; + try { + locationAuthorization = await Navigator.getPermissionStatus(); + } catch (err: any) { + Logger.warn(`Location authorization error: ${err.message}`); + } + // user indentification fields const userId = params.userId || Storage.getItem(Storage.USER_ID); const deviceId = params.deviceId || Device.getDeviceId(); @@ -52,6 +60,7 @@ class TrackAPI { const body = { ...params, + locationAuthorization, accuracy, description, deviceId, diff --git a/src/session.ts b/src/session.ts index 5dc464e2..876e1627 100644 --- a/src/session.ts +++ b/src/session.ts @@ -3,7 +3,7 @@ import Storage from './storage'; const SESSION_TIMEOUT_SECS = 300; // 5 mins const isValid = (sessionId: string): boolean => { - const now = Date.now() / 1000; + const now = Math.trunc(Date.now() / 1000); const session = Number.parseInt(sessionId); const diff = Math.abs(now - session); return diff < SESSION_TIMEOUT_SECS; @@ -19,7 +19,7 @@ class Session { } // create new session if does not already exist or expired - const newSessionId = (Date.now() / 1000).toString(); // unix ts in seconds + const newSessionId = Math.trunc(Date.now() / 1000).toString(); // unix ts in seconds Storage.setItem(Storage.SESSION_ID, newSessionId); return newSessionId; }