backend-manager 2.3.13 → 2.3.16

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/david/itw-creative-works/backend-manager.svg">
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.13",
3
+ "version": "2.3.16",
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.66",
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.14",
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",
@@ -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 online = self.libraries.admin.database().ref(`gatherings/online`);
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.total', r)
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 online
120
+ await gatheringOnline
120
121
  .once('value')
121
122
  .then((snap) => {
122
- let data = snap.val() || {};
123
- let keys = Object.keys(data);
124
- _.set(update, 'users.online', keys.length)
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
- let count = 0;
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
- if (!['', 'basic', 'free'].includes(planId)) {
184
- count++;
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(count);
227
+ return resolve(stats);
189
228
  })
190
229
  .catch(function(e) {
191
230
  return reject(e)
@@ -16,6 +16,7 @@ Module.prototype.main = function () {
16
16
 
17
17
  let uid = payload.data.payload.uid;
18
18
  const app = payload.data.payload.appId || payload.data.payload.app || Manager.config.app.id;
19
+ let config = payload.data.payload.config || {};
19
20
 
20
21
  let uuid = null;
21
22
  let error;
@@ -62,6 +63,12 @@ Module.prototype.main = function () {
62
63
  return reject(error)
63
64
  }
64
65
 
66
+ if (config.backendManagerKey === Manager.config.backend_manager.key && Manager.config.backend_manager.key) {
67
+ assistant.log('Validated config', config, {environment: 'production'})
68
+ } else {
69
+ config = {};
70
+ }
71
+
65
72
  // Fetch app details
66
73
  await fetch('https://us-central1-itw-creative-works.cloudfunctions.net/getApp', {
67
74
  method: 'post',
@@ -81,6 +88,7 @@ Module.prototype.main = function () {
81
88
  ip: assistant.request.ip,
82
89
  country: assistant.request.country,
83
90
  app: result,
91
+ config: config,
84
92
  }
85
93
  });
86
94
  })