backend-manager 3.1.2 → 3.1.3

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.
Files changed (36) hide show
  1. package/package.json +2 -2
  2. package/src/manager/functions/core/actions/api/admin/backup.js +3 -3
  3. package/src/manager/functions/core/actions/api/admin/create-post.js +3 -3
  4. package/src/manager/functions/core/actions/api/admin/cron.js +3 -3
  5. package/src/manager/functions/core/actions/api/admin/database-read.js +2 -2
  6. package/src/manager/functions/core/actions/api/admin/database-write.js +3 -3
  7. package/src/manager/functions/core/actions/api/admin/firestore-query.js +2 -2
  8. package/src/manager/functions/core/actions/api/admin/firestore-read.js +3 -3
  9. package/src/manager/functions/core/actions/api/admin/firestore-write.js +3 -3
  10. package/src/manager/functions/core/actions/api/admin/get-stats.js +4 -4
  11. package/src/manager/functions/core/actions/api/admin/payment-processor.js +3 -3
  12. package/src/manager/functions/core/actions/api/admin/send-notification.js +4 -4
  13. package/src/manager/functions/core/actions/api/admin/sync-users.js +2 -2
  14. package/src/manager/functions/core/actions/api/firebase/get-providers.js +4 -4
  15. package/src/manager/functions/core/actions/api/general/generate-uuid.js +2 -2
  16. package/src/manager/functions/core/actions/api/general/send-email.js +5 -5
  17. package/src/manager/functions/core/actions/api/handler/create-post.js +3 -3
  18. package/src/manager/functions/core/actions/api/special/setup-electron-manager-client.js +3 -3
  19. package/src/manager/functions/core/actions/api/template.js +1 -1
  20. package/src/manager/functions/core/actions/api/test/create-test-accounts.js +1 -1
  21. package/src/manager/functions/core/actions/api/test/webhook.js +1 -1
  22. package/src/manager/functions/core/actions/api/user/create-custom-token.js +1 -1
  23. package/src/manager/functions/core/actions/api/user/delete.js +2 -2
  24. package/src/manager/functions/core/actions/api/user/get-active-sessions.js +1 -1
  25. package/src/manager/functions/core/actions/api/user/regenerate-api-keys.js +1 -1
  26. package/src/manager/functions/core/actions/api/user/sign-out-all-sessions.js +3 -3
  27. package/src/manager/functions/core/actions/api/user/sign-up.js +4 -4
  28. package/src/manager/functions/core/actions/api/user/submit-feedback.js +2 -2
  29. package/src/manager/functions/core/actions/api/user/validate-settings.js +2 -2
  30. package/src/manager/functions/core/actions/api.js +4 -4
  31. package/src/manager/functions/core/cron/daily/reset-usage.js +4 -4
  32. package/src/manager/functions/core/cron/daily.js +1 -1
  33. package/src/manager/helpers/assistant.js +36 -25
  34. package/src/manager/helpers/middleware.js +19 -10
  35. package/src/manager/helpers/usage.js +10 -9
  36. package/src/manager/index.js +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "backend-manager",
3
- "version": "3.1.2",
3
+ "version": "3.1.3",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -65,7 +65,7 @@
65
65
  "uid-generator": "^2.0.0",
66
66
  "ultimate-jekyll-poster": "^0.0.15",
67
67
  "uuid": "^9.0.1",
68
- "wonderful-fetch": "^1.0.1",
68
+ "wonderful-fetch": "^1.1.0",
69
69
  "wonderful-log": "^1.0.5",
70
70
  "yargs": "^17.7.2"
71
71
  }
@@ -19,7 +19,7 @@ Module.prototype.main = function () {
19
19
  payload.data.payload.deletionRegex = payload.data.payload.deletionRegex ? powertools.regexify(payload.data.payload.deletionRegex) : payload.data.payload.deletionRegex;
20
20
 
21
21
  if (!payload.user.roles.admin && assistant.meta.environment === 'production') {
22
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
22
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
23
23
  }
24
24
 
25
25
  // https://googleapis.dev/nodejs/firestore/latest/v1.FirestoreAdminClient.html#exportDocuments
@@ -61,7 +61,7 @@ Module.prototype.main = function () {
61
61
  })
62
62
  .catch(async (e) => {
63
63
  await self._setMetaStats(e);
64
- return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true}).error)
64
+ return reject(assistant.errorify(e, {code: 500, sentry: false, send: false, log: true}).error)
65
65
  });
66
66
 
67
67
  });
@@ -96,7 +96,7 @@ Module.prototype._setMetaStats = function (error, meta) {
96
96
  metadata: Manager.Metadata().set({tag: 'admin:backup'}),
97
97
  }, {merge: true})
98
98
  .catch(e => {
99
- assistant.errorManager(e, {code: 500, sentry: false, send: false, log: true});
99
+ assistant.errorify(e, {code: 500, sentry: false, send: false, log: true});
100
100
  })
101
101
 
102
102
  return resolve();
@@ -18,7 +18,7 @@ Module.prototype.main = function () {
18
18
  return new Promise(async function(resolve, reject) {
19
19
  // Perform checks
20
20
  if (!payload.user.roles.admin && !payload.user.roles.blogger) {
21
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
21
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
22
22
  }
23
23
 
24
24
  const repoInfo = assistant.parseRepo(get(self.Manager.config, 'github.repo_website'));
@@ -45,7 +45,7 @@ Module.prototype.main = function () {
45
45
  const finalPost = await poster.create(payload.data).catch(e => e);
46
46
 
47
47
  if (finalPost instanceof Error) {
48
- return reject(assistant.errorManager(`Failed to post: ${finalPost}`, {code: 500, sentry: false, send: false, log: false}).error)
48
+ return reject(assistant.errorify(`Failed to post: ${finalPost}`, {code: 500, sentry: false, send: false, log: false}).error)
49
49
  }
50
50
 
51
51
  // Request indexing
@@ -68,7 +68,7 @@ Module.prototype.main = function () {
68
68
  return resolve({data: finalPost});
69
69
  })
70
70
  .catch((e) => {
71
- return reject(assistant.errorManager(`Failed to post: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
71
+ return reject(assistant.errorify(`Failed to post: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
72
72
  })
73
73
 
74
74
  });
@@ -13,12 +13,12 @@ Module.prototype.main = function () {
13
13
 
14
14
  // Check if the user is an admin
15
15
  if (!payload.user.roles.admin && assistant.meta.environment === 'production') {
16
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
16
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
17
17
  }
18
18
 
19
19
  // Check if the ID is set
20
20
  if (!payload.data.payload.id) {
21
- return reject(assistant.errorManager(`Missing parameter {id}`, {code: 400, sentry: false, send: false, log: false}).error)
21
+ return reject(assistant.errorify(`Missing parameter {id}`, {code: 400, sentry: false, send: false, log: false}).error)
22
22
  }
23
23
 
24
24
  // Run the cron job
@@ -27,7 +27,7 @@ Module.prototype.main = function () {
27
27
  return resolve({data: res});
28
28
  })
29
29
  .catch(e => {
30
- return reject(assistant.errorManager(e, {code: 400, sentry: false, send: false, log: false}).error)
30
+ return reject(assistant.errorify(e, {code: 400, sentry: false, send: false, log: false}).error)
31
31
  })
32
32
  });
33
33
 
@@ -16,9 +16,9 @@ Module.prototype.main = function () {
16
16
 
17
17
  // Perform checks
18
18
  if (!payload.user.roles.admin) {
19
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
19
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
20
20
  } else if (!payload.data.payload.path) {
21
- return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
21
+ return reject(assistant.errorify(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
22
22
  }
23
23
 
24
24
  // Read from Firestore
@@ -17,9 +17,9 @@ Module.prototype.main = function () {
17
17
 
18
18
  // Perform checks
19
19
  if (payload.user.roles.admin) {
20
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
20
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
21
21
  } else if (!payload.data.payload.path) {
22
- return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error);
22
+ return reject(assistant.errorify(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error);
23
23
  }
24
24
 
25
25
  // Write to Firestore
@@ -29,7 +29,7 @@ Module.prototype.main = function () {
29
29
  return resolve({data: payload.data.payload.document});
30
30
  })
31
31
  .catch((e) => {
32
- return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
32
+ return reject(assistant.errorify(e, {code: 500, sentry: false, send: false, log: false}).error)
33
33
  });
34
34
  });
35
35
 
@@ -15,7 +15,7 @@ Module.prototype.main = function () {
15
15
  return new Promise(async function(resolve, reject) {
16
16
  // Perform checks
17
17
  if (!payload.user.roles.admin) {
18
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
18
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
19
19
  }
20
20
 
21
21
  // Run queries
@@ -35,7 +35,7 @@ Module.prototype.main = function () {
35
35
  return resolve({data: self.docs});
36
36
  })
37
37
  .catch((e) => {
38
- return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
38
+ return reject(assistant.errorify(e, {code: 500, sentry: false, send: false, log: false}).error)
39
39
  })
40
40
 
41
41
  });
@@ -16,9 +16,9 @@ Module.prototype.main = function () {
16
16
 
17
17
  // Perform checks
18
18
  if (!payload.user.roles.admin) {
19
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
19
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
20
20
  } else if (!payload.data.payload.path) {
21
- return reject(assistant.errorManager(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
21
+ return reject(assistant.errorify(`<path> parameter required`, {code: 400, sentry: false, send: false, log: false}).error)
22
22
  }
23
23
 
24
24
  // Read from Firestore
@@ -28,7 +28,7 @@ Module.prototype.main = function () {
28
28
  return resolve({data: doc.data()});
29
29
  })
30
30
  .catch(e => {
31
- return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
31
+ return reject(assistant.errorify(e, {code: 500, sentry: false, send: false, log: false}).error)
32
32
  })
33
33
  });
34
34
 
@@ -19,9 +19,9 @@ Module.prototype.main = function () {
19
19
 
20
20
  // Perform checks
21
21
  if (!payload.user.roles.admin) {
22
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
22
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
23
23
  } else if (!payload.data.payload.path) {
24
- return reject(assistant.errorManager(`Path parameter required.`, {code: 400, sentry: false, send: false, log: false}).error)
24
+ return reject(assistant.errorify(`Path parameter required.`, {code: 400, sentry: false, send: false, log: false}).error)
25
25
  }
26
26
 
27
27
  // Set metadata
@@ -37,7 +37,7 @@ Module.prototype.main = function () {
37
37
  return resolve({data: {path: payload.data.payload.path}});
38
38
  })
39
39
  .catch(e => {
40
- return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
40
+ return reject(assistant.errorify(e, {code: 500, sentry: false, send: false, log: false}).error)
41
41
  })
42
42
  });
43
43
 
@@ -17,7 +17,7 @@ Module.prototype.main = function () {
17
17
 
18
18
  // Perform checks
19
19
  if (!payload.user.roles.admin) {
20
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
20
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
21
21
  }
22
22
 
23
23
  // Get stats
@@ -34,7 +34,7 @@ Module.prototype.main = function () {
34
34
  }
35
35
 
36
36
  if (data instanceof Error) {
37
- return reject(assistant.errorManager(data, {code: 500, sentry: false, send: false, log: false}).error)
37
+ return reject(assistant.errorify(data, {code: 500, sentry: false, send: false, log: false}).error)
38
38
  }
39
39
 
40
40
  // Retrieve the stats again after updating
@@ -47,13 +47,13 @@ Module.prototype.main = function () {
47
47
 
48
48
 
49
49
  if (data instanceof Error) {
50
- return reject(assistant.errorManager(data, {code: 500, sentry: false, send: false, log: false}).error)
50
+ return reject(assistant.errorify(data, {code: 500, sentry: false, send: false, log: false}).error)
51
51
  }
52
52
 
53
53
  return resolve({data: data})
54
54
  })
55
55
  .catch(function (e) {
56
- return reject(assistant.errorManager(`Failed to get: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
56
+ return reject(assistant.errorify(`Failed to get: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
57
57
  })
58
58
  });
59
59
 
@@ -15,12 +15,12 @@ Module.prototype.main = function () {
15
15
  return new Promise(async function(resolve, reject) {
16
16
 
17
17
  if (!payload.user.roles.admin) {
18
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
18
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
19
19
  }
20
20
 
21
21
  const productId = _.get(payload, 'data.payload.payload.details.productIdGlobal');
22
22
  if (!productId) {
23
- return reject(assistant.errorManager(`No productId`, {code: 400, sentry: false, send: false, log: false}).error)
23
+ return reject(assistant.errorify(`No productId`, {code: 400, sentry: false, send: false, log: false}).error)
24
24
  }
25
25
  const processorPath = `${process.cwd()}/payment-processors/${productId}.js`
26
26
  let processor;
@@ -45,7 +45,7 @@ Module.prototype.main = function () {
45
45
  return resolve({data: result});
46
46
  })
47
47
  .catch(e => {
48
- return reject(assistant.errorManager(`Payment processor @ "${processorPath}" failed: ${e}`, {code: 400, sentry: true, send: false, log: false}).error)
48
+ return reject(assistant.errorify(`Payment processor @ "${processorPath}" failed: ${e}`, {code: 400, sentry: true, send: false, log: false}).error)
49
49
  })
50
50
  });
51
51
 
@@ -37,17 +37,17 @@ Module.prototype.main = function () {
37
37
  self._notificationPayload.notification.click_action.searchParams.set('cb', new Date().getTime())
38
38
  self._notificationPayload.notification.click_action = self._notificationPayload.notification.click_action.toString()
39
39
  } catch (e) {
40
- assistant.errorManager(`Failed to add cb to URL: ${e}`, {code: 500, sentry: false, send: false, log: true})
40
+ assistant.errorify(`Failed to add cb to URL: ${e}`, {code: 500, sentry: false, send: false, log: true})
41
41
  }
42
42
 
43
43
  assistant.log('Resolved notification payload', self._notificationPayload)
44
44
 
45
45
  if (!payload.user.roles.admin) {
46
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
46
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
47
47
  }
48
48
 
49
49
  if (!payload.data.payload.title || !payload.data.payload.body) {
50
- return reject(assistant.errorManager(`Parameters <title> and <body> required`, {code: 400, sentry: true, send: false, log: false}).error)
50
+ return reject(assistant.errorify(`Parameters <title> and <body> required`, {code: 400, sentry: true, send: false, log: false}).error)
51
51
  }
52
52
 
53
53
  await self.getTokens({tags: false})
@@ -55,7 +55,7 @@ Module.prototype.main = function () {
55
55
  return resolve({data: payload.response.data})
56
56
  })
57
57
  .catch(e => {
58
- return reject(assistant.errorManager(`Failed to send notification: ${e}`, {code: 400, sentry: true, send: false, log: false}).error)
58
+ return reject(assistant.errorify(`Failed to send notification: ${e}`, {code: 400, sentry: true, send: false, log: false}).error)
59
59
  })
60
60
  });
61
61
 
@@ -15,7 +15,7 @@ Module.prototype.main = function () {
15
15
 
16
16
  // If the user is not an admin, reject
17
17
  if (!payload.user.roles.admin && assistant.meta.environment === 'production') {
18
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
18
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
19
19
  }
20
20
 
21
21
  // Get lastPageToken from meta/stats
@@ -116,7 +116,7 @@ Module.prototype.main = function () {
116
116
  return resolve();
117
117
  })
118
118
  .catch(e => {
119
- return reject(assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error)
119
+ return reject(assistant.errorify(e, {code: 500, sentry: false, send: false, log: false}).error)
120
120
  })
121
121
  });
122
122
 
@@ -44,7 +44,7 @@ Module.prototype.main = function () {
44
44
  payload.data.payload.firebaseApiKey = payload.data.payload.firebaseApiKey || _.get(Manager, 'config.firebaseConfig.apiKey') || false;
45
45
 
46
46
  if (!payload.data.payload.firebaseApiKey) {
47
- return reject(assistant.errorManager(`The firebaseApiKey parameter is required.`, {code: 400, sentry: false, send: false, log: false}).error)
47
+ return reject(assistant.errorify(`The firebaseApiKey parameter is required.`, {code: 400, sentry: false, send: false, log: false}).error)
48
48
  }
49
49
 
50
50
  // Default
@@ -91,7 +91,7 @@ Module.prototype.main = function () {
91
91
 
92
92
  payload.response.data[provider.name] = result;
93
93
  } catch (e) {
94
- assistant.errorManager(`Error parsing error: ${e}`, {sentry: true, send: false, log: true})
94
+ assistant.errorify(`Error parsing error: ${e}`, {sentry: true, send: false, log: true})
95
95
  payload.response.data[provider.name] = false;
96
96
  }
97
97
  })
@@ -136,7 +136,7 @@ Module.prototype.main = function () {
136
136
 
137
137
  })
138
138
  .catch(e => {
139
- assistant.errorManager(`Error getting app data: ${e}`, {sentry: false, send: false, log: true})
139
+ assistant.errorify(`Error getting app data: ${e}`, {sentry: false, send: false, log: true})
140
140
  })
141
141
  .finally(r => {
142
142
  return resolve({data: payload.response.data});
@@ -144,7 +144,7 @@ Module.prototype.main = function () {
144
144
 
145
145
  })
146
146
  .catch(e => {
147
- return reject(assistant.errorManager(`Failed to check providers: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
147
+ return reject(assistant.errorify(`Failed to check providers: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
148
148
  })
149
149
 
150
150
  });
@@ -20,14 +20,14 @@ Module.prototype.main = function () {
20
20
 
21
21
  if (payload.data.payload.version === '5') {
22
22
  if (!payload.data.payload.name) {
23
- return reject(assistant.errorManager(`You must provide a name to hash for uuid v5.`, {code: 400, sentry: false, send: false, log: false}).error)
23
+ return reject(assistant.errorify(`You must provide a name to hash for uuid v5.`, {code: 400, sentry: false, send: false, log: false}).error)
24
24
  } else {
25
25
  result = uuid.v5(payload.data.payload.name, payload.data.payload.namespace);
26
26
  }
27
27
  } else if (payload.data.payload.version === '4') {
28
28
  result = uuid.v4();
29
29
  } else {
30
- return reject(assistant.errorManager(`v${payload.data.payload.version} is not a valid version.`, {code: 400, sentry: false, send: false, log: false}).error)
30
+ return reject(assistant.errorify(`v${payload.data.payload.version} is not a valid version.`, {code: 400, sentry: false, send: false, log: false}).error)
31
31
  }
32
32
 
33
33
  assistant.log('UUID Generated', payload.data.payload, result);
@@ -32,9 +32,9 @@ Module.prototype.main = function () {
32
32
  }
33
33
 
34
34
  if (!payload.data.payload.id) {
35
- return reject(assistant.errorManager(`Parameter {id} is required.`, {code: 400, sentry: false, send: false, log: false}).error)
35
+ return reject(assistant.errorify(`Parameter {id} is required.`, {code: 400, sentry: false, send: false, log: false}).error)
36
36
  } else if (!payload.data.payload.email) {
37
- return reject(assistant.errorManager(`Parameter {email} is required.`, {code: 400, sentry: false, send: false, log: false}).error)
37
+ return reject(assistant.errorify(`Parameter {email} is required.`, {code: 400, sentry: false, send: false, log: false}).error)
38
38
  }
39
39
 
40
40
  let emailPayload
@@ -46,7 +46,7 @@ Module.prototype.main = function () {
46
46
  script(payload.data.payload, Manager.config),
47
47
  );
48
48
  } catch (e) {
49
- return reject(assistant.errorManager(`${payload.data.payload.id} is not a valid email ID.`, {code: 400, sentry: false, send: false, log: false}).error)
49
+ return reject(assistant.errorify(`${payload.data.payload.id} is not a valid email ID.`, {code: 400, sentry: false, send: false, log: false}).error)
50
50
  }
51
51
 
52
52
  const storage = Manager.storage({temporary: true});
@@ -70,7 +70,7 @@ Module.prototype.main = function () {
70
70
  assistant.log('Storage:', storage.getState()['api:general:send-email']);
71
71
 
72
72
  if (ipData.count >= emailPayload.spamFilter.ip || emailData.count >= emailPayload.spamFilter.email) {
73
- self.assistant.errorManager(`Spam filter triggered ip=${ipData.count}, email=${emailData.count}`, {code: 429, sentry: false, send: false, log: true})
73
+ self.assistant.errorify(`Spam filter triggered ip=${ipData.count}, email=${emailData.count}`, {code: 429, sentry: false, send: false, log: true})
74
74
  return resolve({data: {success: true}});
75
75
  }
76
76
 
@@ -99,7 +99,7 @@ Module.prototype.main = function () {
99
99
  });
100
100
  })
101
101
  .catch(e => {
102
- return reject(assistant.errorManager(`Error sending email: ${e}`, {code: 500, sentry: true, send: false, log: false}).error)
102
+ return reject(assistant.errorify(`Error sending email: ${e}`, {code: 500, sentry: true, send: false, log: false}).error)
103
103
  });
104
104
 
105
105
  });
@@ -15,7 +15,7 @@ Module.prototype.main = function () {
15
15
  return new Promise(async function(resolve, reject) {
16
16
 
17
17
  if (!payload.user.roles.admin) {
18
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
18
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
19
19
  }
20
20
 
21
21
  payload.response.data = {
@@ -83,7 +83,7 @@ Module.prototype.main = function () {
83
83
  .catch(e => e);
84
84
 
85
85
  if (createdInvoice instanceof Error) {
86
- return reject(assistant.errorManager(createdInvoice, {code: 400, sentry: false, send: false, log: false}).error)
86
+ return reject(assistant.errorify(createdInvoice, {code: 400, sentry: false, send: false, log: false}).error)
87
87
  }
88
88
 
89
89
  // Send invoice
@@ -104,7 +104,7 @@ Module.prototype.main = function () {
104
104
  .catch(e => e);
105
105
 
106
106
  if (sentInvoice instanceof Error) {
107
- return reject(assistant.errorManager(sentInvoice, {code: 500, sentry: false, send: false, log: false}).error)
107
+ return reject(assistant.errorify(sentInvoice, {code: 500, sentry: false, send: false, log: false}).error)
108
108
  }
109
109
 
110
110
  payload.response.data.invoice = {
@@ -32,11 +32,11 @@ Module.prototype.main = function () {
32
32
  signInToken = token;
33
33
  })
34
34
  .catch(e => {
35
- error = assistant.errorManager(`Failed to create custom token: ${e}`, {code: 500, sentry: false, send: false, log: false}).error
35
+ error = assistant.errorify(`Failed to create custom token: ${e}`, {code: 500, sentry: false, send: false, log: false}).error
36
36
  })
37
37
  })
38
38
  .catch(e => {
39
- assistant.errorManager(`Failed to resolve user: ${e}`, {code: 500, sentry: false, send: false, log: true})
39
+ assistant.errorify(`Failed to resolve user: ${e}`, {code: 500, sentry: false, send: false, log: true})
40
40
  })
41
41
 
42
42
  if (error) {
@@ -93,7 +93,7 @@ Module.prototype.main = function () {
93
93
  });
94
94
  })
95
95
  .catch(e => {
96
- return reject(assistant.errorManager(`Error fetching app details: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
96
+ return reject(assistant.errorify(`Error fetching app details: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
97
97
  })
98
98
 
99
99
 
@@ -12,7 +12,7 @@ Module.prototype.main = function () {
12
12
  return new Promise(async function(resolve, reject) {
13
13
 
14
14
  if (!payload.user.roles.admin) {
15
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
15
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
16
16
  }
17
17
 
18
18
  // self.Api.resolveUser({adminRequired: false})
@@ -12,7 +12,7 @@ Module.prototype.main = function () {
12
12
  return new Promise(async function(resolve, reject) {
13
13
 
14
14
  if (!payload.user.roles.admin) {
15
- return reject(assistant.errorManager(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
15
+ return reject(assistant.errorify(`Admin required.`, {code: 401, sentry: false, send: false, log: false}).error)
16
16
  }
17
17
 
18
18
  assistant.log('User:', payload.user);
@@ -19,7 +19,7 @@ Module.prototype.main = function () {
19
19
  if (payload.data.payload.status >= 200 && payload.data.payload.status <= 299) {
20
20
  return resolve({data: payload.data.payload.response, status: payload.data.payload.status});
21
21
  } else if (payload.data.payload.status >= 400 && payload.data.payload.status <= 599) {
22
- return reject(assistant.errorManager(payload.data.payload.response || 'Unknown error message provided', {code: payload.data.payload.status, sentry: false, send: false, log: false}).error)
22
+ return reject(assistant.errorify(payload.data.payload.response || 'Unknown error message provided', {code: payload.data.payload.status, sentry: false, send: false, log: false}).error)
23
23
  }
24
24
 
25
25
  });
@@ -19,7 +19,7 @@ Module.prototype.main = function () {
19
19
  return resolve({data: {token: token}});
20
20
  })
21
21
  .catch(e => {
22
- return reject(assistant.errorManager(`Failed to create custom token: ${e}`, {code: 400, sentry: false, send: false, log: false}).error)
22
+ return reject(assistant.errorify(`Failed to create custom token: ${e}`, {code: 400, sentry: false, send: false, log: false}).error)
23
23
  })
24
24
  })
25
25
  .catch(e => {
@@ -22,7 +22,7 @@ Module.prototype.main = function () {
22
22
  (user?.plan?.status && user?.plan?.status !== 'cancelled')
23
23
  || user?.plan?.payment?.active
24
24
  ) {
25
- return reject(assistant.errorManager(`This account cannot be deleted because it has a paid subscription attached to it. In order to delete the account, you must first cancel the paid subscription.`, {code: 400, sentry: false, send: false, log: false}).error)
25
+ return reject(assistant.errorify(`This account cannot be deleted because it has a paid subscription attached to it. In order to delete the account, you must first cancel the paid subscription.`, {code: 400, sentry: false, send: false, log: false}).error)
26
26
  }
27
27
 
28
28
  // Signout of all sessions
@@ -54,7 +54,7 @@ Module.prototype.main = function () {
54
54
  return resolve({data: {success: true}});
55
55
  })
56
56
  .catch(e => {
57
- return reject(assistant.errorManager(`Failed to delete user: ${e}`, {code: 400, sentry: false, send: false, log: false}).error)
57
+ return reject(assistant.errorify(`Failed to delete user: ${e}`, {code: 400, sentry: false, send: false, log: false}).error)
58
58
  })
59
59
  })
60
60
  .catch(e => {
@@ -30,7 +30,7 @@ Module.prototype.main = function () {
30
30
  return resolve({data: data});
31
31
  })
32
32
  .catch(e => {
33
- return reject(assistant.errorManager(`Session query error: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
33
+ return reject(assistant.errorify(`Session query error: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
34
34
  })
35
35
 
36
36
  })
@@ -39,7 +39,7 @@ Module.prototype.main = function () {
39
39
  return resolve({data: newKeys});
40
40
  })
41
41
  .catch(e => {
42
- return reject(assistant.errorManager(`Failed to generate keys: ${e}`, {code: 500, sentry: true, send: false, log: false}).error)
42
+ return reject(assistant.errorify(`Failed to generate keys: ${e}`, {code: 500, sentry: true, send: false, log: false}).error)
43
43
  })
44
44
 
45
45
  })
@@ -37,10 +37,10 @@ Module.prototype.main = function () {
37
37
  return resolve({data: {sessions: count, message: `Successfully signed ${uid} out of all sessions`}});
38
38
  })
39
39
  .catch(e => {
40
- return reject(assistant.errorManager(`Failed to sign out of all sessions: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
40
+ return reject(assistant.errorify(`Failed to sign out of all sessions: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
41
41
  })
42
42
  } catch (e) {
43
- return reject(assistant.errorManager(`Failed to sign out of all sessions: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
43
+ return reject(assistant.errorify(`Failed to sign out of all sessions: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
44
44
  }
45
45
  })
46
46
  .catch(e => {
@@ -108,7 +108,7 @@ Module.prototype.signOutOfSession = function (uid, session) {
108
108
 
109
109
  })
110
110
  .catch(e => {
111
- assistant.errorManager(`Session query error for session ${session}: ${e}`, {code: 500, sentry: true, send: false, log: true})
111
+ assistant.errorify(`Session query error for session ${session}: ${e}`, {code: 500, sentry: true, send: false, log: true})
112
112
 
113
113
  return reject(e);
114
114
  })
@@ -26,7 +26,7 @@ Module.prototype.main = function () {
26
26
  const usage = await Manager.Usage().init(assistant, {log: true, key: ip});
27
27
 
28
28
  if (authUser instanceof Error) {
29
- return reject(assistant.errorManager(`Failed to get auth user: ${authUser}`, {code: 500, sentry: false, send: false, log: false}).error)
29
+ return reject(assistant.errorify(`Failed to get auth user: ${authUser}`, {code: 500, sentry: false, send: false, log: false}).error)
30
30
  }
31
31
 
32
32
  // Age in seconds
@@ -34,7 +34,7 @@ Module.prototype.main = function () {
34
34
 
35
35
  // If the user is not new, reject
36
36
  if (ageInSeconds >= MAX_AGE) {
37
- return reject(assistant.errorManager(`User is not new.`, {code: 400, sentry: false, send: false, log: false}).error)
37
+ return reject(assistant.errorify(`User is not new.`, {code: 400, sentry: false, send: false, log: false}).error)
38
38
  }
39
39
 
40
40
  // Check if IP has signed up too many times
@@ -86,7 +86,7 @@ Module.prototype.main = function () {
86
86
  });
87
87
 
88
88
  // Reject
89
- return reject(assistant.errorManager(`Too many signups from this IP (${ip}).`, {code: 429, sentry: false, send: false, log: false}).error)
89
+ return reject(assistant.errorify(`Too many signups from this IP (${ip}).`, {code: 429, sentry: false, send: false, log: false}).error)
90
90
  }
91
91
 
92
92
  // Increment signups
@@ -121,7 +121,7 @@ Module.prototype.main = function () {
121
121
  return resolve({data: result});
122
122
  })
123
123
  .catch(function (e) {
124
- return reject(assistant.errorManager(`Failed to sign up: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
124
+ return reject(assistant.errorify(`Failed to sign up: ${e}`, {code: 500, sentry: false, send: false, log: false}).error)
125
125
  })
126
126
  })
127
127
  .catch(e => {
@@ -77,11 +77,11 @@ Module.prototype.main = function () {
77
77
  });
78
78
  })
79
79
  .catch((e) => {
80
- return reject(assistant.errorManager(`Failed to save feedback: ${e.message}`, {code: 500, sentry: true, send: false, log: true}).error)
80
+ return reject(assistant.errorify(`Failed to save feedback: ${e.message}`, {code: 500, sentry: true, send: false, log: true}).error)
81
81
  })
82
82
  })
83
83
  .catch((e) => {
84
- return reject(assistant.errorManager(`Failed to get app: ${e.message}`, {code: 500, sentry: true, send: false, log: true}).error)
84
+ return reject(assistant.errorify(`Failed to get app: ${e.message}`, {code: 500, sentry: true, send: false, log: true}).error)
85
85
  })
86
86
 
87
87
  })
@@ -28,7 +28,7 @@ Module.prototype.main = function () {
28
28
 
29
29
  // Check if the file exists
30
30
  if (!jetpack.exists(resolvedPath)) {
31
- return reject(assistant.errorManager(`Defaults file at ${resolvedPath} does not exist, please add it manually.`, {code: 500, sentry: true, send: false, log: true}).error);
31
+ return reject(assistant.errorify(`Defaults file at ${resolvedPath} does not exist, please add it manually.`, {code: 500, sentry: true, send: false, log: true}).error);
32
32
  }
33
33
 
34
34
  // Load the file
@@ -40,7 +40,7 @@ Module.prototype.main = function () {
40
40
 
41
41
  return resolve({data: powertools.defaults(settings, combined)});
42
42
  } catch (e) {
43
- return reject(assistant.errorManager(`Unable to load file at ${resolvedPath}: ${e}`, {code: 500, sentry: true, send: false, log: true}).error);
43
+ return reject(assistant.errorify(`Unable to load file at ${resolvedPath}: ${e}`, {code: 500, sentry: true, send: false, log: true}).error);
44
44
  }
45
45
 
46
46
  })
@@ -271,7 +271,7 @@ Module.prototype.resolveUser = function (options) {
271
271
 
272
272
  if (options.uid) {
273
273
  if (options.adminRequired && !options.admin) {
274
- user = self.assistant.errorManager('Admin required', {code: 401, sentry: false, send: false, log: false}).error;
274
+ user = self.assistant.errorify('Admin required', {code: 401, sentry: false, send: false, log: false}).error;
275
275
  } else {
276
276
  await self.libraries.admin.firestore().doc(`users/${options.uid}`)
277
277
  .get()
@@ -280,11 +280,11 @@ Module.prototype.resolveUser = function (options) {
280
280
  if (data) {
281
281
  user = data;
282
282
  } else {
283
- user = self.assistant.errorManager(`User does not exist: ${options.uid}`, {code: 400, sentry: false, send: false, log: false}).error;
283
+ user = self.assistant.errorify(`User does not exist: ${options.uid}`, {code: 400, sentry: false, send: false, log: false}).error;
284
284
  }
285
285
  })
286
286
  .catch(function (e) {
287
- user = self.assistant.errorManager(e, {code: 500, sentry: false, send: false, log: false}).error;
287
+ user = self.assistant.errorify(e, {code: 500, sentry: false, send: false, log: false}).error;
288
288
  })
289
289
  }
290
290
  } else if (self.payload.user.authenticated) {
@@ -296,7 +296,7 @@ Module.prototype.resolveUser = function (options) {
296
296
  if (user instanceof Error) {
297
297
  return reject(user);
298
298
  } else if (!user) {
299
- return reject(self.assistant.errorManager('Unable to resolve user', {code: 500, sentry: false, send: false, log: false}).error);
299
+ return reject(self.assistant.errorify('Unable to resolve user', {code: 500, sentry: false, send: false, log: false}).error);
300
300
  } else {
301
301
  return resolve(user);
302
302
  }
@@ -105,7 +105,7 @@ Module.prototype.clearFirestore = function() {
105
105
  assistant.log(`cron/daily/reset-usage() [firestore]: Resetting metrics`, metrics);
106
106
 
107
107
  if (metrics instanceof Error) {
108
- return reject(assistant.errorManager(`Failed to check providers: ${metrics}`, {code: 500, sentry: false, send: false, log: false}).error)
108
+ return reject(assistant.errorify(`Failed to check providers: ${metrics}`, {code: 500, sentry: false, send: false, log: false}).error)
109
109
  }
110
110
 
111
111
  // Reset all metrics with for loop of metrics
@@ -140,7 +140,7 @@ Module.prototype.clearFirestore = function() {
140
140
  assistant.log(`cron/daily/reset-usage() [firestore]: Reset ${metric} for ${doc.id} (${original} -> 0)`);
141
141
  })
142
142
  .catch(e => {
143
- assistant.errorManager(`Error resetting ${metric} for ${doc.id}: ${e}`, {sentry: false, send: false, log: true})
143
+ assistant.errorify(`Error resetting ${metric} for ${doc.id}: ${e}`, {sentry: false, send: false, log: true})
144
144
  })
145
145
  }
146
146
 
@@ -159,7 +159,7 @@ Module.prototype.clearFirestore = function() {
159
159
  assistant.log(`cron/daily/reset-usage() [firestore]: Reset ${metric} for all users complete!`);
160
160
  })
161
161
  .catch(e => {
162
- assistant.errorManager(`Error resetting ${metric} for all users: ${e}`, {sentry: false, send: false, log: true})
162
+ assistant.errorify(`Error resetting ${metric} for all users: ${e}`, {sentry: false, send: false, log: true})
163
163
  })
164
164
  }
165
165
 
@@ -169,7 +169,7 @@ Module.prototype.clearFirestore = function() {
169
169
  assistant.log(`cron/daily/reset-usage() [firestore]: Deleted temporary/usage`);
170
170
  })
171
171
  .catch(e => {
172
- assistant.errorManager(`Error deleting temporary/usage: ${e}`, {sentry: false, send: false, log: true})
172
+ assistant.errorify(`Error deleting temporary/usage: ${e}`, {sentry: false, send: false, log: true})
173
173
  })
174
174
 
175
175
  return resolve();
@@ -48,7 +48,7 @@ Module.prototype.main = function() {
48
48
  assistant.log(`cron/daily(): Job ${jobName} completed...`);
49
49
  })
50
50
  .catch(e => {
51
- assistant.errorManager(`Error executing ${jobName}: ${e}`, {sentry: true, send: false, log: true});
51
+ assistant.errorify(`Error executing ${jobName}: ${e}`, {sentry: true, send: false, log: true});
52
52
  caught = e;
53
53
  })
54
54
  }
@@ -60,7 +60,7 @@ BackendAssistant.prototype.init = function (ref, options) {
60
60
 
61
61
  // Set ID
62
62
  try {
63
- self.id = self.Manager.Utilities().randomId();
63
+ self.id = self.ref.req.headers['function-execution-id'] || self.Manager.Utilities().randomId();
64
64
  } catch {
65
65
  self.id = now.getTime();
66
66
  }
@@ -344,8 +344,9 @@ BackendAssistant.prototype._log = function () {
344
344
  }
345
345
  }
346
346
 
347
- BackendAssistant.prototype.errorManager = function (e, options) {
347
+ BackendAssistant.prototype.errorify = function (e, options) {
348
348
  const self = this;
349
+ const res = self.ref.res;
349
350
 
350
351
  // Set options
351
352
  options = options || {};
@@ -362,7 +363,7 @@ BackendAssistant.prototype.errorManager = function (e, options) {
362
363
  ? true
363
364
  : options.send;
364
365
  options.stack = typeof options.stack === 'undefined'
365
- ? true
366
+ ? false
366
367
  : options.stack;
367
368
 
368
369
  // Construct error
@@ -373,13 +374,7 @@ BackendAssistant.prototype.errorManager = function (e, options) {
373
374
  options.code = newError.code || options.code;
374
375
 
375
376
  // Attach properties
376
- Object.keys(options)
377
- .forEach((item, i) => {
378
- Object.assign(newError, { [item]: options[item] });
379
- });
380
-
381
- // Attach properties
382
- _attachHeaderProperties(self, options);
377
+ _attachHeaderProperties(self, options, newError);
383
378
 
384
379
  // Log the error
385
380
  if (options.log) {
@@ -392,18 +387,24 @@ BackendAssistant.prototype.errorManager = function (e, options) {
392
387
  }
393
388
 
394
389
  // Quit and respond to the request
395
- if (options.send && self.ref.res && self.ref.res.status) {
396
- const sendable = newError?.stack && options.stack
390
+ if (options.send && res && res.status) {
391
+ let sendable = newError?.stack && options.stack
397
392
  ? newError?.stack
398
393
  : newError?.message;
399
394
 
400
- self.ref.res
395
+ // Set error
396
+ sendable = `${sendable || newError || 'Unknown error'}`;
397
+
398
+ // Attach tag
399
+ if (newError.tag) {
400
+ // sendable = `(${newError.tag}) ${sendable}`;
401
+ sendable = `${sendable} (${newError.tag})`;
402
+ }
403
+
404
+ // Send response
405
+ res
401
406
  .status(options.code)
402
- .send((
403
- sendable
404
- ? sendable
405
- : newError
406
- ) || 'Unknown error');
407
+ .send(sendable);
407
408
  }
408
409
 
409
410
  return {
@@ -411,10 +412,11 @@ BackendAssistant.prototype.errorManager = function (e, options) {
411
412
  }
412
413
  }
413
414
 
414
- BackendAssistant.prototype.errorify = BackendAssistant.prototype.errorManager;
415
+ BackendAssistant.prototype.errorManager = BackendAssistant.prototype.errorify;
415
416
 
416
417
  BackendAssistant.prototype.respond = function(response, options) {
417
418
  const self = this;
419
+ const res = self.ref.res;
418
420
 
419
421
  // Set options
420
422
  options = options || {};
@@ -442,12 +444,13 @@ BackendAssistant.prototype.respond = function(response, options) {
442
444
  }
443
445
 
444
446
  // Send response
445
- self.ref.res.status(options.code);
447
+ res.status(options.code);
446
448
 
447
- if (typeof response === 'string') {
448
- self.ref.res.send(response);
449
+ // If it is an object, send as json
450
+ if (response && typeof response === 'object') {
451
+ res.json(response);
449
452
  } else {
450
- self.ref.res.json(response);
453
+ res.send(response);
451
454
  }
452
455
  }
453
456
 
@@ -459,7 +462,7 @@ function stringify(e) {
459
462
  }
460
463
  }
461
464
 
462
- function _attachHeaderProperties(self, options) {
465
+ function _attachHeaderProperties(self, options, error) {
463
466
  // Create headers
464
467
  const headers = {
465
468
  code: options.code,
@@ -473,6 +476,14 @@ function _attachHeaderProperties(self, options) {
473
476
 
474
477
  // Attach properties
475
478
  self.ref.res.header('bm-properties', JSON.stringify(headers));
479
+
480
+ // Attach properties
481
+ if (error) {
482
+ Object.keys(headers)
483
+ .forEach((item, i) => {
484
+ error[item] = headers[item];
485
+ });
486
+ }
476
487
  }
477
488
 
478
489
  BackendAssistant.prototype.authenticate = async function (options) {
@@ -504,7 +515,7 @@ BackendAssistant.prototype.authenticate = async function (options) {
504
515
  }
505
516
  }
506
517
 
507
- if (req?.headers?.authorization?.startsWith('Bearer ')) {
518
+ if (req?.headers?.authorization && req?.headers?.authorization?.startsWith('Bearer ')) {
508
519
  // Read the ID Token from the Authorization header.
509
520
  idToken = req.headers.authorization.split('Bearer ')[1];
510
521
  self.log('Found "Authorization" header', idToken, logOptions);
@@ -36,33 +36,42 @@ Middleware.prototype.run = function (library, req, res, options) {
36
36
  library = path.resolve(process.cwd(), `${library}.js`);
37
37
  library = new (require(library))();
38
38
  } catch (e) {
39
- assistant.errorManager(`Unable to load library @ (${library}): ${e.message}`, {sentry: true, send: true, log: true});
39
+ assistant.errorify(`Unable to load library @ (${library}): ${e.message}`, {sentry: true, send: true, log: true});
40
+ }
41
+
42
+ // Setup usage
43
+ if (options.setupUsage) {
44
+ assistant.usage = await Manager.Usage().init(assistant);
40
45
  }
41
46
 
42
47
  // Setup analytics
43
48
  if (options.setupAnalytics) {
49
+ const uuid = assistant?.usage?.user?.auth?.uid
50
+ || assistant.request.user.auth.uid
51
+ || assistant.request.geolocation.ip
52
+
44
53
  assistant.analytics = Manager.Analytics({
45
54
  assistant: assistant,
46
- uuid: assistant.request.geolocation.ip,
55
+ uuid: uuid,
47
56
  })
48
57
  }
49
58
 
50
- // Setup usage
51
- if (options.setupUsage) {
52
- assistant.usage = await Manager.Usage().init(assistant);
53
- }
54
-
55
59
  // Process
56
60
  try {
57
- library.main(assistant)
61
+ // Set properties
62
+ library.Manager = Manager;
63
+ library.assistant = assistant;
64
+
65
+ // Run library
66
+ library.main(assistant, req, res)
58
67
  // .then(result => {
59
68
  // return res.status(200).json(result);
60
69
  // })
61
70
  .catch(e => {
62
- assistant.errorManager(e, {sentry: true, send: true, log: true});
71
+ assistant.errorify(e, {sentry: true, send: true, log: true});
63
72
  });
64
73
  } catch (e) {
65
- assistant.errorManager(e, {sentry: true, send: true, log: true});
74
+ assistant.errorify(e, {sentry: true, send: true, log: true});
66
75
  }
67
76
  });
68
77
  };
@@ -81,13 +81,14 @@ Usage.prototype.init = function (assistant, options) {
81
81
  let foundUsage;
82
82
 
83
83
  if (options.unauthenticatedMode === 'firestore') {
84
+ // TODO: Make it request using .where() query so it doesnt use a read if it doesnt have to
84
85
  foundUsage = await Manager.libraries.admin.firestore().doc(`temporary/usage`)
85
86
  .get()
86
87
  .then((r) => {
87
88
  return r.data()?.[`${self.key}`];
88
89
  })
89
90
  .catch((e) => {
90
- assistant.errorManager(`Usage.init(): Error fetching usage data: ${e}`, {sentry: true, send: false, log: true});
91
+ assistant.errorify(`Usage.init(): Error fetching usage data: ${e}`, {sentry: true, send: false, log: true});
91
92
  });
92
93
  } else {
93
94
  foundUsage = self.storage.get(`${self.paths.user}.usage`, {}).value();
@@ -114,7 +115,7 @@ Usage.prototype.init = function (assistant, options) {
114
115
  self.storage.set(`${self.paths.app}.lastFetched`, new Date().toISOString()).write();
115
116
  })
116
117
  .catch(e => {
117
- assistant.errorManager(`Usage.init(): Error fetching app data: ${e}`, {sentry: true, send: false, log: true});
118
+ assistant.errorify(`Usage.init(): Error fetching app data: ${e}`, {sentry: true, send: false, log: true});
118
119
  })
119
120
  }
120
121
 
@@ -172,14 +173,14 @@ Usage.prototype.validate = function (path, options) {
172
173
  // If the captcha is valid, resolve
173
174
  if (!captchaResult || captchaResult instanceof Error || !captchaResult.success) {
174
175
  return reject(
175
- assistant.errorManager(`Captcha verification failed.`, {code: 400, sentry: false, send: false, log: false}).error
176
+ assistant.errorify(`Captcha verification failed.`, {code: 400, sentry: false, send: false, log: false}).error
176
177
  );
177
178
  }
178
179
  }
179
180
 
180
181
  // Otherwise, they are over the limit, reject
181
182
  return reject(
182
- assistant.errorManager(`You have exceeded your ${path} usage limit of ${period}/${allowed}.`, {code: 429, sentry: false, send: false, log: false}).error
183
+ assistant.errorify(`You have exceeded your ${path} usage limit of ${period}/${allowed}.`, {code: 429, sentry: false, send: false, log: false}).error
183
184
  );
184
185
  });
185
186
  };
@@ -282,17 +283,17 @@ Usage.prototype.update = function () {
282
283
  .then(() => {
283
284
  self.log(`Usage.update(): Updated user.usage in firestore`, self.user.usage);
284
285
 
285
- return resolve();
286
+ return resolve(self.user.usage);
286
287
  })
287
288
  .catch(e => {
288
- return reject(assistant.errorManager(e, {sentry: true, send: false, log: false}));
289
+ return reject(assistant.errorify(e, {sentry: true, send: false, log: false}));
289
290
  });
290
291
  } else {
291
292
  self.storage.set(`${self.paths.user}.usage`, self.user.usage).write();
292
293
 
293
294
  self.log(`Usage.update(): Updated user.usage in local storage`, self.user.usage);
294
295
 
295
- return resolve();
296
+ return resolve(self.user.usage);
296
297
  }
297
298
  } else {
298
299
  Manager.libraries.admin.firestore().doc(`users/${self.user.auth.uid}`)
@@ -302,10 +303,10 @@ Usage.prototype.update = function () {
302
303
  .then(() => {
303
304
  self.log(`Usage.update(): Updated user.usage in firestore`, self.user.usage);
304
305
 
305
- return resolve();
306
+ return resolve(self.user.usage);
306
307
  })
307
308
  .catch(e => {
308
- return reject(assistant.errorManager(e, {sentry: true, send: false, log: false}));
309
+ return reject(assistant.errorify(e, {sentry: true, send: false, log: false}));
309
310
  });
310
311
  }
311
312
  });
@@ -466,7 +466,7 @@ Manager.prototype._process = function (mod) {
466
466
  function _reject(e, log) {
467
467
  if (log) {
468
468
  // self.assistant.error(e);
469
- mod.assistant.errorManager(e, {code: 500, sentry: true, send: false, log: true});
469
+ mod.assistant.errorify(e, {code: 500, sentry: true, send: false, log: true});
470
470
  }
471
471
  // res.status(500).send(e.message);
472
472
  return resolve()