backend-manager 2.3.12 → 2.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "2.3.12",
3
+ "version": "2.3.13",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -16,16 +16,17 @@ Module.prototype.main = function () {
16
16
  self.Api.resolveUser({adminRequired: true})
17
17
  .then(async (user) => {
18
18
  const uid = _.get(user, 'auth.uid', null);
19
- const id = _.get(payload.data.payload, 'id', 'sessions/app');
19
+ const id = _.get(payload.data.payload, 'id', 'app');
20
+ const session = `sessions/${id}`;
20
21
 
21
- assistant.log(`Getting active sessions for ${uid} @ ${id}`, {environment: 'production'})
22
+ assistant.log(`Getting active sessions for ${uid} @ ${session}`, {environment: 'production'})
22
23
 
23
- await self.libraries.admin.database().ref(id)
24
+ await self.libraries.admin.database().ref(session)
24
25
  .orderByChild('uid')
25
26
  .equalTo(uid)
26
27
  .once('value')
27
28
  .then(async (snap) => {
28
- const data = (snap.val() || []).filter(i => i);
29
+ const data = snap.val() || {};
29
30
  return resolve({data: data});
30
31
  })
31
32
  .catch(e => {
@@ -16,34 +16,20 @@ Module.prototype.main = function () {
16
16
  self.Api.resolveUser({adminRequired: true})
17
17
  .then(async (user) => {
18
18
  const uid = _.get(user, 'auth.uid', null);
19
- const id = _.get(payload.data.payload, 'id', 'sessions/app');
20
-
21
- assistant.log(`Signing out of all active sessions for ${uid} @ ${id}`, {environment: 'production'})
22
-
23
- await self.libraries.admin.database().ref(id)
24
- .orderByChild('uid')
25
- .equalTo(uid)
26
- .once('value')
27
- .then(async (snap) => {
28
- const data = snap.val();
29
- const keys = Object.keys(data || {});
30
- for (var i = 0; i < keys.length; i++) {
31
- const key = keys[i];
32
- self.assistant.log(`Signing out: ${key}`, {environment: 'production'});
33
- await self.libraries.admin.database().ref(`${id}/${key}/command`).set('signout').catch(e => self.assistant.error(`Failed to signout ${key}`, e))
34
- await powertools.wait(3000);
35
- await self.libraries.admin.database().ref(`${id}/${key}`).remove().catch(e => self.assistant.error(`Failed to delete ${key}`, e))
36
- }
37
- })
38
- .catch(e => {
39
- console.error('Session query error', e);
40
- })
19
+ const id = _.get(payload.data.payload, 'id', 'app');
20
+ const session = `sessions/${id}`;
21
+
22
+ let count = 0;
23
+
24
+ await self.signOutOfSession(uid, session).then(r => count += r);
25
+ // Legacy for somiibo and old electron-manager
26
+ await self.signOutOfSession(uid, 'gatherings/online').then(r => count += r);
41
27
 
42
28
  await self.libraries.admin
43
29
  .auth()
44
30
  .revokeRefreshTokens(uid)
45
31
  .then(() => {
46
- return resolve({data: {message: `Successfully signed ${uid} out of all sessions`}});
32
+ return resolve({data: {sessions: count, message: `Successfully signed ${uid} out of all sessions`}});
47
33
  })
48
34
  .catch(e => {
49
35
  return reject(assistant.errorManager(`Failed to sign out of all sessions: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
@@ -56,5 +42,39 @@ Module.prototype.main = function () {
56
42
 
57
43
  };
58
44
 
45
+ Module.prototype.signOutOfSession = function (uid, session) {
46
+ const self = this;
47
+ const Manager = self.Manager;
48
+ const Api = self.Api;
49
+ const assistant = self.assistant;
50
+ const payload = self.payload;
51
+
52
+ return new Promise(async function(resolve, reject) {
53
+ assistant.log(`Signing out of all active sessions for ${uid} @ ${session}`, {environment: 'production'})
54
+ let count = 0;
55
+
56
+ await self.libraries.admin.database().ref(session)
57
+ .orderByChild('uid')
58
+ .equalTo(uid)
59
+ .once('value')
60
+ .then(async (snap) => {
61
+ const data = snap.val() || {};
62
+ const keys = Object.keys(data);
63
+ for (var i = 0; i < keys.length; i++) {
64
+ const key = keys[i];
65
+ self.assistant.log(`Signing out: ${key}`, {environment: 'production'});
66
+ await self.libraries.admin.database().ref(`${session}/${key}/command`).set('signout').catch(e => self.assistant.error(`Failed to signout ${key}`, e))
67
+ // await powertools.wait(3000);
68
+ // await self.libraries.admin.database().ref(`${session}/${key}`).remove().catch(e => self.assistant.error(`Failed to delete ${key}`, e))
69
+ count++;
70
+ }
71
+ return resolve(count);
72
+ })
73
+ .catch(e => {
74
+ assistant.errorManager(`Session query error for session ${session}: ${e}`, {code: 500, sentry: true, send: false, log: true})
75
+ return reject(count)
76
+ })
77
+ });
78
+ }
59
79
 
60
80
  module.exports = Module;