From 3d377e6c69f78788a11a0db732f5fa82b97adccc Mon Sep 17 00:00:00 2001 From: emad-salah Date: Mon, 29 Nov 2021 14:19:53 +0100 Subject: [PATCH] Fixed TS errors and formatted with Prettier --- .../contact-api/streams/pubToLastSeenApp.js | 9 +-- services/gunDB/sockets/index.js | 10 ++-- services/gunDB/sockets/subscriptions.js | 14 ++--- utils/protectedRoutes.js | 57 ++++++++++++------- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/services/gunDB/contact-api/streams/pubToLastSeenApp.js b/services/gunDB/contact-api/streams/pubToLastSeenApp.js index 729f5e59..421b9f29 100644 --- a/services/gunDB/contact-api/streams/pubToLastSeenApp.js +++ b/services/gunDB/contact-api/streams/pubToLastSeenApp.js @@ -27,14 +27,15 @@ const on = (cb, pub) => { listeners.add(cb) cb(pubToLastSeenApp) if (pub && pubsWithListeners.add(pub)) { - pubToLastSeenApp[pub] = null; + pubToLastSeenApp[pub] = null notifyListeners() require('../../Mediator') .getGun() .user(pub) .get(Key.LAST_SEEN_APP) .on(timestamp => { - pubToLastSeenApp[pub] = typeof timestamp === 'number' ? timestamp : undefined + pubToLastSeenApp[pub] = + typeof timestamp === 'number' ? timestamp : undefined notifyListeners() }) } @@ -45,5 +46,5 @@ const on = (cb, pub) => { module.exports = { getPubToLastSeenApp, - on, -} \ No newline at end of file + on +} diff --git a/services/gunDB/sockets/index.js b/services/gunDB/sockets/index.js index 2295399e..9b52563b 100644 --- a/services/gunDB/sockets/index.js +++ b/services/gunDB/sockets/index.js @@ -179,10 +179,12 @@ const startSocket = socket => { } if (isAuthenticated()) { - socket.onAny(() => { - GunActions.setLastSeenApp().catch(e => - logger.info('error setting last seen app', e) - ) + socket.onAny(async () => { + try { + await GunActions.setLastSeenApp() + } catch (err) { + logger.info('error setting last seen app', err) + } }) } diff --git a/services/gunDB/sockets/subscriptions.js b/services/gunDB/sockets/subscriptions.js index 353c00f8..553a11d7 100644 --- a/services/gunDB/sockets/subscriptions.js +++ b/services/gunDB/sockets/subscriptions.js @@ -32,11 +32,7 @@ const add = ({ deviceId, subscriptionId, unsubscribe, metadata }) => { * @param {string} subscription.subscriptionId * @param {Unsubscribe} subscription.unsubscribe */ -const attachUnsubscribe = ({ - deviceId, - subscriptionId, - unsubscribe -}) => { +const attachUnsubscribe = ({ deviceId, subscriptionId, unsubscribe }) => { const deviceSubscriptions = userSubscriptions.get(deviceId) const subscriptions = deviceSubscriptions @@ -68,7 +64,7 @@ const remove = ({ deviceId, subscriptionId }) => { const deviceSubscriptions = userSubscriptions.get(deviceId) const subscriptions = deviceSubscriptions ?? new Map() - const subscription = subscriptions.get(subscriptionId); + const subscription = subscriptions.get(subscriptionId) if (subscription?.unsubscribe) { subscription.unsubscribe() @@ -84,7 +80,7 @@ const remove = ({ deviceId, subscriptionId }) => { * @param {string} subscription.deviceId */ const removeDevice = ({ deviceId }) => { - const deviceSubscriptions = userSubscriptions.get(deviceId); + const deviceSubscriptions = userSubscriptions.get(deviceId) if (!deviceSubscriptions) { return @@ -98,7 +94,7 @@ const removeDevice = ({ deviceId }) => { return subscription }) - userSubscriptions.set(deviceId, new Map()); + userSubscriptions.set(deviceId, new Map()) } /** @@ -124,4 +120,4 @@ module.exports = { get, remove, removeDevice -} \ No newline at end of file +} diff --git a/utils/protectedRoutes.js b/utils/protectedRoutes.js index 35e52ea4..0396dde5 100644 --- a/utils/protectedRoutes.js +++ b/utils/protectedRoutes.js @@ -1,28 +1,28 @@ module.exports = { unprotectedRoutes: { GET: { - "/healthz": true, - "/ping": true, - "/tunnel/status": true, + '/healthz': true, + '/ping': true, + '/tunnel/status': true, // Errors out when viewing an API page from the browser - "/favicon.ico": true, - "/api/lnd/connect": true, - "/api/lnd/wallet/status": true, - "/api/lnd/auth": true, + '/favicon.ico': true, + '/api/lnd/connect': true, + '/api/lnd/wallet/status': true, + '/api/lnd/auth': true, // - "/api/gun/auth": true, - "/api/subscribeStream":true, - "/":true, - "/api/accessInfo":true, - "/qrCodeGenerator":true, + '/api/gun/auth': true, + '/api/subscribeStream': true, + '/': true, + '/api/accessInfo': true, + '/qrCodeGenerator': true }, POST: { - "/api/lnd/connect": true, - "/api/lnd/wallet": true, - "/api/lnd/wallet/existing": true, - "/api/lnd/auth": true, - "/api/security/exchangeKeys": true, - "/api/encryption/exchange": true + '/api/lnd/connect': true, + '/api/lnd/wallet': true, + '/api/lnd/wallet/existing': true, + '/api/lnd/auth': true, + '/api/security/exchangeKeys': true, + '/api/encryption/exchange': true }, PUT: {}, DELETE: {}, @@ -39,11 +39,24 @@ module.exports = { sensitiveRoutes: { GET: {}, POST: { - "/api/lnd/connect": true, - "/api/lnd/wallet": true + '/api/lnd/connect': true, + '/api/lnd/wallet': true }, PUT: {}, DELETE: {} }, - nonEncryptedRoutes: ['/api/security/exchangeKeys', "/api/encryption/exchange", '/healthz', '/ping', '/tunnel/status', '/api/lnd/wallet/status', '/api/gun/auth',"/api/subscribeStream", "/", "/api/accessInfo","/qrCodeGenerator"] -} \ No newline at end of file + nonEncryptedRoutes: [ + '/api/security/exchangeKeys', + '/api/encryption/exchange', + '/healthz', + '/ping', + '/tunnel/status', + '/api/lnd/wallet/status', + '/api/gun/auth', + '/api/subscribeStream', + '/', + '/api/accessInfo', + '/qrCodeGenerator', + '/gun' + ] +}