backend-manager 3.0.39 → 3.0.41
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
|
@@ -341,7 +341,9 @@ BackendAssistant.prototype.errorManager = function(e, options) {
|
|
|
341
341
|
options.sentry = typeof options.sentry === 'undefined' ? true : options.sentry;
|
|
342
342
|
options.send = typeof options.send === 'undefined' ? true : options.send;
|
|
343
343
|
|
|
344
|
-
const newError = e instanceof Error
|
|
344
|
+
const newError = e instanceof Error
|
|
345
|
+
? e
|
|
346
|
+
: new Error(stringify(e));
|
|
345
347
|
|
|
346
348
|
// Attach properties
|
|
347
349
|
Object.keys(options)
|
|
@@ -370,6 +372,14 @@ BackendAssistant.prototype.errorManager = function(e, options) {
|
|
|
370
372
|
}
|
|
371
373
|
}
|
|
372
374
|
|
|
375
|
+
function stringify(e) {
|
|
376
|
+
if (typeof e === 'string') {
|
|
377
|
+
return e;
|
|
378
|
+
} else {
|
|
379
|
+
return JSON.stringify(e);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
373
383
|
|
|
374
384
|
BackendAssistant.prototype.authenticate = async function (options) {
|
|
375
385
|
const self = this;
|
|
@@ -105,9 +105,6 @@ Usage.prototype.init = function (assistant, options) {
|
|
|
105
105
|
self.log(`Usage.init(): Got app data`, self.app);
|
|
106
106
|
self.log(`Usage.init(): Got user`, self.user);
|
|
107
107
|
|
|
108
|
-
// Resolve with the user to get their current plan limits
|
|
109
|
-
// If there is no user, go forward with their IP and make them a basic plan user
|
|
110
|
-
|
|
111
108
|
// Set initialized to true
|
|
112
109
|
self.initialized = true;
|
|
113
110
|
|
|
@@ -127,8 +124,8 @@ Usage.prototype.validate = function (path, options) {
|
|
|
127
124
|
options.useCaptchaResponse = typeof options.useCaptchaResponse === 'undefined' ? true : options.useCaptchaResponse;
|
|
128
125
|
|
|
129
126
|
// Check for required options
|
|
130
|
-
const period =
|
|
131
|
-
const allowed =
|
|
127
|
+
const period = self.getUsage(path)
|
|
128
|
+
const allowed = self.getLimits(path);
|
|
132
129
|
|
|
133
130
|
// Log
|
|
134
131
|
self.log(`Usage.validate(): Checking ${period}/${allowed} for ${path}...`);
|
|
@@ -194,11 +191,42 @@ Usage.prototype.increment = function (path, value, options) {
|
|
|
194
191
|
});
|
|
195
192
|
|
|
196
193
|
// Log the updated user
|
|
197
|
-
self.log(`Usage.init(): Incremented user`, self.user);
|
|
194
|
+
self.log(`Usage.init(): Incremented ${path} for user`, self.user);
|
|
195
|
+
|
|
196
|
+
return self;
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
Usage.prototype.set = function (path, value) {
|
|
200
|
+
const self = this;
|
|
201
|
+
const Manager = self.Manager;
|
|
202
|
+
const assistant = self.assistant;
|
|
203
|
+
|
|
204
|
+
// Update total and period
|
|
205
|
+
const resolved = `usage.${path}.${key}`;
|
|
206
|
+
_.set(self.user, resolved, value);
|
|
207
|
+
|
|
208
|
+
// Log the updated user
|
|
209
|
+
self.log(`Usage.init(): Set ${path} for user`, self.user);
|
|
198
210
|
|
|
199
211
|
return self;
|
|
200
212
|
};
|
|
201
213
|
|
|
214
|
+
Usage.prototype.getUsage = function (path) {
|
|
215
|
+
const self = this;
|
|
216
|
+
const Manager = self.Manager;
|
|
217
|
+
const assistant = self.assistant;
|
|
218
|
+
|
|
219
|
+
return _.get(self.user, `usage.${path}.period`, 0);
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
Usage.prototype.getLimit = function (path) {
|
|
223
|
+
const self = this;
|
|
224
|
+
const Manager = self.Manager;
|
|
225
|
+
const assistant = self.assistant;
|
|
226
|
+
|
|
227
|
+
return _.get(self.app, `products.${self.options.app}-${self.user.plan.id}.limits.${path}`, 0);
|
|
228
|
+
};
|
|
229
|
+
|
|
202
230
|
Usage.prototype.update = function () {
|
|
203
231
|
const self = this;
|
|
204
232
|
|