backend-manager 2.3.6 → 2.3.9

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.6",
3
+ "version": "2.3.9",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -58,7 +58,7 @@
58
58
  "ultimate-jekyll-poster": "^0.0.13",
59
59
  "universal-analytics": "^0.5.3",
60
60
  "uuid": "^8.3.2",
61
- "wonderful-fetch": "^0.0.12",
61
+ "wonderful-fetch": "^0.0.14",
62
62
  "yargs": "^17.5.1"
63
63
  },
64
64
  "files": [
@@ -0,0 +1,44 @@
1
+ const _ = require('lodash')
2
+
3
+ function Module() {
4
+
5
+ }
6
+
7
+ Module.prototype.main = function () {
8
+ const self = this;
9
+ const Manager = self.Manager;
10
+ const Api = self.Api;
11
+ const assistant = self.assistant;
12
+ const payload = self.payload;
13
+
14
+ return new Promise(async function(resolve, reject) {
15
+
16
+ self.Api.resolveUser({adminRequired: true})
17
+ .then(async (user) => {
18
+ const uid = _.get(user, 'auth.uid', null);
19
+ const id = _.get(payload.data.payload, 'id', 'sessions/app');
20
+
21
+ assistant.log(`Getting 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
+ return resolve({data: data});
30
+ })
31
+ .catch(e => {
32
+ return reject(assistant.errorManager(`Session query error: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
33
+ })
34
+
35
+ })
36
+ .catch(e => {
37
+ return reject(e);
38
+ })
39
+ });
40
+
41
+ };
42
+
43
+
44
+ module.exports = Module;
@@ -16,24 +16,27 @@ 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
20
 
20
- await self.libraries.admin.database().ref(`gatherings/online`)
21
+ assistant.log(`Signing out of all active sessions for ${uid} @ ${id}`, {environment: 'production'})
22
+
23
+ await self.libraries.admin.database().ref(id)
21
24
  .orderByChild('uid')
22
25
  .equalTo(uid)
23
26
  .once('value')
24
- .then(async snap => {
27
+ .then(async (snap) => {
25
28
  const data = snap.val();
26
29
  const keys = Object.keys(data || {});
27
30
  for (var i = 0; i < keys.length; i++) {
28
31
  const key = keys[i];
29
32
  self.assistant.log(`Signing out: ${key}`, {environment: 'production'});
30
- await self.libraries.admin.database().ref(`gatherings/online/${key}/command`).set('signout').catch(e => self.assistant.error(`Failed to signout ${key}`, e))
33
+ await self.libraries.admin.database().ref(`${id}/${key}/command`).set('signout').catch(e => self.assistant.error(`Failed to signout ${key}`, e))
31
34
  await powertools.wait(3000);
32
- await self.libraries.admin.database().ref(`gatherings/online/${key}`).remove().catch(e => self.assistant.error(`Failed to delete ${key}`, e))
35
+ await self.libraries.admin.database().ref(`${id}/${key}`).remove().catch(e => self.assistant.error(`Failed to delete ${key}`, e))
33
36
  }
34
37
  })
35
38
  .catch(e => {
36
- console.error('Gathering query error', e);
39
+ console.error('Session query error', e);
37
40
  })
38
41
 
39
42
  await self.libraries.admin