backend-manager 2.3.12 → 2.3.15
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/README.md
CHANGED
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<img src="https://img.shields.io/github/package-json/v/itw-creative-works/backend-manager.svg">
|
|
9
9
|
<br>
|
|
10
|
-
<img src="https://img.shields.io/
|
|
11
|
-
<img src="https://img.shields.io/david/dev/itw-creative-works/backend-manager.svg">
|
|
10
|
+
<img src="https://img.shields.io/librariesio/release/npm/backend-manager.svg">
|
|
12
11
|
<img src="https://img.shields.io/bundlephobia/min/backend-manager.svg">
|
|
13
12
|
<img src="https://img.shields.io/codeclimate/maintainability-percentage/itw-creative-works/backend-manager.svg">
|
|
14
13
|
<img src="https://img.shields.io/npm/dm/backend-manager.svg">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backend-manager",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.15",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@google-cloud/storage": "^5.20.5",
|
|
32
32
|
"@sendgrid/mail": "^7.7.0",
|
|
33
33
|
"@sentry/node": "^6.19.7",
|
|
34
|
-
"backend-assistant": "^0.0.
|
|
34
|
+
"backend-assistant": "^0.0.67",
|
|
35
35
|
"busboy": "^1.6.0",
|
|
36
36
|
"chalk": "^4.1.2",
|
|
37
37
|
"cors": "^2.8.5",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"mocha": "^9.2.2",
|
|
49
49
|
"moment": "^2.29.4",
|
|
50
50
|
"node-fetch": "^2.6.7",
|
|
51
|
-
"node-powertools": "^0.0.
|
|
51
|
+
"node-powertools": "^0.0.18",
|
|
52
52
|
"npm-api": "^1.0.1",
|
|
53
53
|
"paypal-server-api": "^0.0.7",
|
|
54
54
|
"pushid": "^1.0.0",
|
|
@@ -66,4 +66,4 @@
|
|
|
66
66
|
"src/",
|
|
67
67
|
"templates/"
|
|
68
68
|
]
|
|
69
|
-
}
|
|
69
|
+
}
|
|
@@ -75,7 +75,8 @@ Module.prototype.updateStats = function (existingData) {
|
|
|
75
75
|
|
|
76
76
|
return new Promise(async function(resolve, reject) {
|
|
77
77
|
const stats = self.libraries.admin.firestore().doc(`meta/stats`);
|
|
78
|
-
const
|
|
78
|
+
const gatheringOnline = self.libraries.admin.database().ref(`gatherings/online`);
|
|
79
|
+
const sessionsApp = self.libraries.admin.database().ref(`sessions/app`);
|
|
79
80
|
|
|
80
81
|
let error = null;
|
|
81
82
|
let update = {};
|
|
@@ -106,7 +107,7 @@ Module.prototype.updateStats = function (existingData) {
|
|
|
106
107
|
|
|
107
108
|
await self.getAllSubscriptions()
|
|
108
109
|
.then(r => {
|
|
109
|
-
_.set(update, 'subscriptions
|
|
110
|
+
_.set(update, 'subscriptions', r)
|
|
110
111
|
})
|
|
111
112
|
.catch(e => {
|
|
112
113
|
error = new Error(`Failed getting subscriptions: ${e}`);
|
|
@@ -116,12 +117,25 @@ Module.prototype.updateStats = function (existingData) {
|
|
|
116
117
|
return reject(error);
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
await
|
|
120
|
+
await gatheringOnline
|
|
120
121
|
.once('value')
|
|
121
122
|
.then((snap) => {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
_.
|
|
123
|
+
const data = snap.val() || {};
|
|
124
|
+
const keys = Object.keys(data);
|
|
125
|
+
const existing = _.get(update, 'users.online', 0)
|
|
126
|
+
_.set(update, 'users.online', existing + keys.length)
|
|
127
|
+
})
|
|
128
|
+
.catch(e => {
|
|
129
|
+
error = new Error(`Failed getting online users: ${e}`);
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
await sessionsApp
|
|
133
|
+
.once('value')
|
|
134
|
+
.then((snap) => {
|
|
135
|
+
const data = snap.val() || {};
|
|
136
|
+
const keys = Object.keys(data);
|
|
137
|
+
const existing = _.get(update, 'users.online', 0)
|
|
138
|
+
_.set(update, 'users.online', existing + keys.length)
|
|
125
139
|
})
|
|
126
140
|
.catch(e => {
|
|
127
141
|
error = new Error(`Failed getting online users: ${e}`);
|
|
@@ -174,18 +188,43 @@ Module.prototype.getAllSubscriptions = function () {
|
|
|
174
188
|
.where('plan.expires.timestampUNIX', '>=', new Date().getTime() / 1000)
|
|
175
189
|
.get()
|
|
176
190
|
.then(function(snapshot) {
|
|
177
|
-
|
|
191
|
+
const stats = {
|
|
192
|
+
totals: {
|
|
193
|
+
total: 0,
|
|
194
|
+
exempt: 0,
|
|
195
|
+
},
|
|
196
|
+
plans: {}
|
|
197
|
+
};
|
|
178
198
|
|
|
179
199
|
snapshot
|
|
180
200
|
.forEach((doc, i) => {
|
|
181
201
|
const data = doc.data();
|
|
182
202
|
const planId = _.get(data, 'plan.id', 'basic');
|
|
183
|
-
|
|
184
|
-
|
|
203
|
+
const frequency = _.get(data, 'plan.payment.frequency', 'unknown');
|
|
204
|
+
const isAdmin = _.get(data, 'roles.admin', false);
|
|
205
|
+
const isVip = _.get(data, 'roles.vip', false);
|
|
206
|
+
|
|
207
|
+
if (!stats.plans[planId]) {
|
|
208
|
+
stats.plans[planId] = {
|
|
209
|
+
total: 0,
|
|
210
|
+
monthly: 0,
|
|
211
|
+
annually: 0,
|
|
212
|
+
exempt: 0,
|
|
213
|
+
}
|
|
185
214
|
}
|
|
215
|
+
|
|
216
|
+
if (isAdmin || isVip) {
|
|
217
|
+
stats.totals.exempt++;
|
|
218
|
+
stats.plans[planId].exempt++;
|
|
219
|
+
return
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
stats.totals.total++;
|
|
223
|
+
stats.plans[planId].total++;
|
|
224
|
+
stats.plans[planId][frequency] = (stats.plans[planId][frequency] || 0) + 1
|
|
186
225
|
});
|
|
187
226
|
|
|
188
|
-
return resolve(
|
|
227
|
+
return resolve(stats);
|
|
189
228
|
})
|
|
190
229
|
.catch(function(e) {
|
|
191
230
|
return reject(e)
|
|
@@ -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', '
|
|
19
|
+
const id = _.get(payload.data.payload, 'id', 'app');
|
|
20
|
+
const session = `sessions/${id}`;
|
|
20
21
|
|
|
21
|
-
assistant.log(`Getting active sessions for ${uid} @ ${
|
|
22
|
+
assistant.log(`Getting active sessions for ${uid} @ ${session}`, {environment: 'production'})
|
|
22
23
|
|
|
23
|
-
await self.libraries.admin.database().ref(
|
|
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 =
|
|
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', '
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
.
|
|
25
|
-
|
|
26
|
-
.
|
|
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;
|