backend-manager 3.0.4 → 3.0.7

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": "3.0.4",
3
+ "version": "3.0.7",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -69,4 +69,4 @@
69
69
  "wonderful-log": "^1.0.5",
70
70
  "yargs": "^17.7.2"
71
71
  }
72
- }
72
+ }
@@ -36,7 +36,7 @@ Module.prototype.main = function () {
36
36
  const oneHour = 60 * 60 * 1000; // One hour in milliseconds
37
37
 
38
38
  // Get current rate-limiting data
39
- const rateLimitingData = storage.get(`ipRateLimits.${ipAddress}`);
39
+ const rateLimitingData = storage.get(`ipRateLimits.${ipAddress}`).value();
40
40
  const count = get(rateLimitingData, 'count', 0);
41
41
  const lastTime = get(rateLimitingData, 'lastTime', 0);
42
42
 
@@ -49,7 +49,7 @@ Module.prototype.main = function () {
49
49
  }
50
50
 
51
51
  // Update rate-limiting data
52
- storage.set(`ipRateLimits.${ipAddress}`, { count: count + 1, lastTime: currentTime });
52
+ storage.set(`ipRateLimits.${ipAddress}`, { count: count + 1, lastTime: currentTime }).write();
53
53
 
54
54
  const existingAccount = await admin.firestore().doc(`users/${user.uid}`)
55
55
  .get()
@@ -4,7 +4,7 @@ function Utilities(Manager) {
4
4
  const self = this;
5
5
 
6
6
  self.cache = null;
7
-
7
+
8
8
  self.Manager = Manager;
9
9
  }
10
10
 
@@ -56,7 +56,7 @@ Utilities.prototype.iterateCollection = function (callback, options) {
56
56
 
57
57
  if (options.log) {
58
58
  console.log('Processing batch:', batch);
59
- }
59
+ }
60
60
 
61
61
  callback({
62
62
  snap: snap, docs: snap.docs.map(x => x)
@@ -81,14 +81,14 @@ Utilities.prototype.iterateCollection = function (callback, options) {
81
81
  });
82
82
  }
83
83
 
84
- listAllDocuments();
84
+ listAllDocuments();
85
85
  });
86
86
  };
87
87
 
88
88
  Utilities.prototype.iterateUsers = function (callback, options) {
89
89
  const self = this;
90
90
  const Manager = self.Manager;
91
- const admin = Manager.libraries.admin;
91
+ const admin = Manager.libraries.admin;
92
92
 
93
93
  return new Promise(function(resolve, reject) {
94
94
  let batch = -1;
@@ -97,13 +97,13 @@ Utilities.prototype.iterateUsers = function (callback, options) {
97
97
  options.batchSize = options.batchSize || 1000;
98
98
  options.log = options.log;
99
99
  options.pageToken = options.pageToken;
100
-
100
+
101
101
  function listAllUsers(nextPageToken) {
102
102
  // List batch of users, 1000 at a time.
103
103
  admin.auth()
104
104
  .listUsers(options.batchSize, nextPageToken)
105
105
  .then(async (listUsersResult) => {
106
-
106
+
107
107
  batch++;
108
108
 
109
109
  if (options.log) {
@@ -111,8 +111,8 @@ Utilities.prototype.iterateUsers = function (callback, options) {
111
111
  }
112
112
 
113
113
  callback({
114
- snap: listUsersResult,
115
- users: listUsersResult.users,
114
+ snap: listUsersResult,
115
+ users: listUsersResult.users,
116
116
  pageToken: listUsersResult.pageToken,
117
117
  }, batch)
118
118
  .then(r => {
@@ -125,16 +125,16 @@ Utilities.prototype.iterateUsers = function (callback, options) {
125
125
  .catch((e) => {
126
126
  console.error('Callback failed', e);
127
127
  return reject(e)
128
- });
129
-
128
+ });
129
+
130
130
  })
131
131
  .catch((e) => {
132
132
  console.error('Query failed', e);
133
133
  return reject(e)
134
- });
134
+ });
135
135
  }
136
-
137
- listAllUsers(options.pageToken);
136
+
137
+ listAllUsers(options.pageToken);
138
138
  });
139
139
  };
140
140
 
@@ -148,7 +148,7 @@ Utilities.prototype.randomId = function (options) {
148
148
  nanoId = require('nanoid');
149
149
 
150
150
  nanoId = nanoId.customAlphabet(
151
- nanoId.urlAlphabet.replace(/_|-/g, ''),
151
+ nanoId.urlAlphabet.replace(/_|-/g, ''),
152
152
  options.size,
153
153
  )
154
154
  }
@@ -177,18 +177,17 @@ Utilities.prototype.get = function (docPath, options) {
177
177
  .then(async (doc) => {
178
178
  const data = doc.data();
179
179
 
180
- if (!data) {
181
- throw new Error(`Document with ID ${doc} not found`);
180
+ if (data) {
181
+ self.cache.set(docPath, {
182
+ doc: doc,
183
+ time: Date.now(),
184
+ })
185
+ .write();
182
186
  }
183
187
 
184
- self.cache.set(docPath, {
185
- doc: doc,
186
- time: Date.now(),
187
- })
188
- .write();
189
-
190
188
  return resolve(doc);
191
189
  })
190
+ .catch(e => reject(e));
192
191
  }
193
192
  });
194
193
  };