backend-manager 2.5.101 → 2.5.102

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.5.101",
3
+ "version": "2.5.102",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -60,8 +60,6 @@ Module.prototype.signOutOfSession = function (uid, session) {
60
60
  return new Promise(async function(resolve, reject) {
61
61
  let count = 0;
62
62
 
63
- assistant.log(`Signing out of all active sessions for ${uid} @ ${session}`, {environment: 'production'})
64
-
65
63
  await self.libraries.admin.database().ref(session)
66
64
  .orderByChild('uid')
67
65
  .equalTo(uid)
@@ -70,35 +68,49 @@ Module.prototype.signOutOfSession = function (uid, session) {
70
68
  const data = snap.val() || {};
71
69
  const keys = Object.keys(data);
72
70
 
71
+ const promises = [];
72
+
73
+ assistant.log(`Signing out of ${keys.length} active sessions for ${uid} @ ${session}`, {environment: 'production'})
74
+
73
75
  for (var i = 0; i < keys.length; i++) {
74
- const key = keys[i];
76
+ promises.push((async () => {
77
+ const key = keys[i];
75
78
 
76
- assistant.log(`Signing out ${session}/${key}...`, {environment: 'production'});
77
-
78
- // Send signout command
79
- await self.libraries.admin.database().ref(`${session}/${key}/command`)
80
- .set('signout')
81
- .catch(e => assistant.error(`Failed to signout of session ${key}`, e, {environment: 'production'}))
79
+ assistant.log(`Signing out ${session}/${key}...`, {environment: 'production'});
80
+
81
+ // Send signout command
82
+ await self.libraries.admin.database().ref(`${session}/${key}/command`)
83
+ .set('signout')
84
+ .catch(e => assistant.error(`Failed to signout of session ${key}`, e, {environment: 'production'}))
82
85
 
83
- // Delay so the client has time to react to the command
84
- await powertools.wait(5000);
86
+ // Delay so the client has time to react to the command
87
+ await powertools.wait(5000);
85
88
 
86
- // Delete session
87
- await self.libraries.admin.database().ref(`${session}/${key}`)
88
- .remove()
89
- .catch(e => assistant.error(`Failed to delete session ${key}`, e, {environment: 'production'}))
89
+ // Delete session
90
+ await self.libraries.admin.database().ref(`${session}/${key}`)
91
+ .remove()
92
+ .catch(e => assistant.error(`Failed to delete session ${key}`, e, {environment: 'production'}))
90
93
 
91
- assistant.log(`Signed out successfully: ${key}`, {environment: 'production'});
94
+ assistant.log(`Signed out successfully: ${key}`, {environment: 'production'});
92
95
 
93
- count++;
96
+ count++;
97
+ })())
94
98
  }
95
99
 
96
- return resolve(count);
100
+ // Run all promises
101
+ await Promise.all(promises)
102
+ .then(() => {
103
+ return resolve(count);
104
+ })
105
+ .catch((e) => {
106
+ return reject(e);
107
+ })
108
+
97
109
  })
98
110
  .catch(e => {
99
111
  assistant.errorManager(`Session query error for session ${session}: ${e}`, {code: 500, sentry: true, send: false, log: true})
100
112
 
101
- return reject(e)
113
+ return reject(e);
102
114
  })
103
115
  });
104
116
  }