backend-manager 2.3.8 → 2.3.11

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.8",
3
+ "version": "2.3.11",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -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() || []).filter(i => i);
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
@@ -3,7 +3,44 @@
3
3
  ///---backend-manager---///
4
4
  ///---version=0.0.0---///
5
5
 
6
- // Gathering rules
6
+ // Sessions rules
7
+ "sessions": {
8
+ ".read": false,
9
+ ".write": false,
10
+ "$room": {
11
+ ".read": "
12
+ (auth.uid != null && query.equalTo == auth.uid)
13
+ ",
14
+ ".write": false,
15
+ ".indexOn": ["uid"],
16
+ "$id": {
17
+ ".read": "
18
+ // Allowed if user is authenticated AND is the owner of the doc
19
+ (auth != null && auth.uid == data.child('uid').val())
20
+ // Allowed if uid is equal to the doc id [LEGACY FOR SOMIIBO]
21
+ || (auth != null && auth.uid == $id)
22
+ // Allowed if user is not authenticated AND is the doc has no owner
23
+ || (auth == null && (data.child('uid').val() == ''))
24
+ ",
25
+ ".write": "
26
+ // Allowed if the user is authenticated AND is the owner of the existing doc
27
+ (auth != null && auth.uid == data.child('uid').val())
28
+ // Allowed if the user is authenticated AND is the owner of the new doc
29
+ || (auth != null && auth.uid == newData.child('uid').val())
30
+ // Allowed if the user is authenticated AND is the owner of the existing doc
31
+ || (auth != null && auth.uid == data.child('uid').val())
32
+ // Allowed if uid is equal to the doc id [LEGACY FOR SOMIIBO]
33
+ || (auth != null && auth.uid == $id)
34
+ // Allowed if the existing doc has no owner
35
+ || (data.child('uid').val() == '')
36
+ // Allowed if the new doc has no owner
37
+ || (newData.child('uid').val() == '')
38
+ // Allowed if it's a delete
39
+ || (!newData.exists())
40
+ ",
41
+ }
42
+ }
43
+ },
7
44
  "gatherings": {
8
45
  ".read": false,
9
46
  ".write": false,