backend-manager 3.0.53 → 3.0.55

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.53",
3
+ "version": "3.0.55",
4
4
  "description": "Quick tools for developing Firebase functions",
5
5
  "main": "src/manager/index.js",
6
6
  "bin": {
@@ -12,7 +12,7 @@ Module.prototype.main = function () {
12
12
  const payload = self.payload;
13
13
 
14
14
  return new Promise(async function(resolve, reject) {
15
- self.Api.resolveUser({adminRequired: true})
15
+ Api.resolveUser({adminRequired: true})
16
16
  .then(async (user) => {
17
17
  await self.libraries.admin.auth().createCustomToken(_.get(user, 'auth.uid', null))
18
18
  .then(token => {
@@ -12,7 +12,7 @@ Module.prototype.main = function () {
12
12
  const payload = self.payload;
13
13
 
14
14
  return new Promise(async function(resolve, reject) {
15
- self.Api.resolveUser({adminRequired: true})
15
+ Api.resolveUser({adminRequired: true})
16
16
  .then(async (user) => {
17
17
  // Disallow deleting users with subscriptions in any state other than cancelled or active payments
18
18
  if (
@@ -22,12 +22,6 @@ Module.prototype.main = function () {
22
22
  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)
23
23
  }
24
24
 
25
- // Signout of all sessions
26
- await Api.import('user:sign-out-all-sessions')
27
- .then(async (lib) => {
28
- await lib.main().catch(e => e);
29
- })
30
-
31
25
  // Perform the delete
32
26
  await self.libraries.admin.auth().deleteUser(_.get(user, 'auth.uid', null))
33
27
  .then(() => {
@@ -13,7 +13,7 @@ Module.prototype.main = function () {
13
13
 
14
14
  return new Promise(async function(resolve, reject) {
15
15
 
16
- self.Api.resolveUser({adminRequired: true})
16
+ Api.resolveUser({adminRequired: true})
17
17
  .then(async (user) => {
18
18
  const uid = _.get(user, 'auth.uid', null);
19
19
  const id = _.get(payload.data.payload, 'id', 'app');
@@ -16,7 +16,7 @@ Module.prototype.main = function () {
16
16
  const oldDate = powertools.timestamp(new Date(0), {output: 'string'})
17
17
  const oldDateUNIX = powertools.timestamp(oldDate, {output: 'unix'});
18
18
 
19
- self.Api.resolveUser({adminRequired: false})
19
+ Api.resolveUser({adminRequired: false})
20
20
  .then(async (user) => {
21
21
  const result = {
22
22
  plan: {
@@ -22,7 +22,7 @@ Module.prototype.main = function () {
22
22
  const payload = self.payload;
23
23
 
24
24
  return new Promise(async function(resolve, reject) {
25
- self.Api.resolveUser({adminRequired: true})
25
+ Api.resolveUser({adminRequired: true})
26
26
  .then(async (user) => {
27
27
 
28
28
  self.ultimateJekyllOAuth2Url = assistant.meta.environment === 'development'
@@ -16,7 +16,7 @@ Module.prototype.main = function () {
16
16
  const payload = self.payload;
17
17
 
18
18
  return new Promise(async function(resolve, reject) {
19
- self.Api.resolveUser({adminRequired: true})
19
+ Api.resolveUser({adminRequired: true})
20
20
  .then(async (user) => {
21
21
  const keys = powertools.arrayify(_.get(payload.data.payload, 'keys') || ['clientId', 'privateKey']);
22
22
  const newKeys = {};
@@ -12,7 +12,7 @@ Module.prototype.main = function () {
12
12
  const payload = self.payload;
13
13
 
14
14
  return new Promise(async function(resolve, reject) {
15
- self.Api.resolveUser({adminRequired: true})
15
+ Api.resolveUser({adminRequired: true})
16
16
  .then(async (user) => {
17
17
  // TODO: resolve the account and send back
18
18
  // - Limits for the account
@@ -14,7 +14,7 @@ Module.prototype.main = function () {
14
14
 
15
15
  return new Promise(async function(resolve, reject) {
16
16
 
17
- self.Api.resolveUser({adminRequired: true})
17
+ Api.resolveUser({adminRequired: true})
18
18
  .then(async (user) => {
19
19
  const uid = _.get(user, 'auth.uid', null);
20
20
  const id = _.get(payload.data.payload, 'id', 'app');
@@ -17,7 +17,7 @@ Module.prototype.main = function () {
17
17
  const assistant = self.assistant;
18
18
  const payload = self.payload;
19
19
 
20
- self.Api.resolveUser({adminRequired: true})
20
+ Api.resolveUser({adminRequired: true})
21
21
  .then(async (user) => {
22
22
  // ⛔️⛔️⛔️ This function could be triggered when the user signs up with Google after already having a email/password account
23
23
  // Get auth user from firebase
@@ -15,7 +15,7 @@ Module.prototype.main = function () {
15
15
  const payload = self.payload;
16
16
 
17
17
  return new Promise(async function(resolve, reject) {
18
- self.Api.resolveUser({adminRequired: true})
18
+ Api.resolveUser({adminRequired: true})
19
19
  .then(async (user) => {
20
20
 
21
21
  const docId = pushid();
@@ -15,7 +15,7 @@ Module.prototype.main = function () {
15
15
  const payload = self.payload;
16
16
 
17
17
  return new Promise(async function(resolve, reject) {
18
- self.Api.resolveUser({adminRequired: true})
18
+ Api.resolveUser({adminRequired: true})
19
19
  .then(async (user) => {
20
20
 
21
21
  payload.data.payload.defaultsPath = payload.data.payload.defaultsPath || '';
@@ -1,3 +1,5 @@
1
+ const fetch = require('wonderful-fetch');
2
+
1
3
  function Module() {
2
4
  const self = this;
3
5
  }
@@ -35,23 +37,56 @@ Module.prototype.main = function () {
35
37
  });
36
38
 
37
39
  // Delete user record
40
+ assistant.log(`Delete user record...`);
38
41
  await libraries.admin.firestore().doc(`users/${user.uid}`)
39
42
  .delete()
43
+ .then((r) => {
44
+ assistant.log(`Delete user record success`);
45
+ })
40
46
  .catch((e) => {
41
- assistant.error(`Delete user failed`, e);
47
+ assistant.error(`Delete user record failed`, e);
42
48
  })
43
49
 
50
+ // Signout of all sessions
51
+ assistant.log(`Signout of all sessions...`);
52
+ await fetch(`https://us-central1-${self.Manager.project.projectId}.cloudfunctions.net/bm_api`, {
53
+ method: 'post',
54
+ timeout: 30000,
55
+ response: 'json',
56
+ tries: 2,
57
+ log: true,
58
+ body: {
59
+ backendManagerKey: self.Manager.config.backendManagerKey,
60
+ command: 'user:sign-out-all-sessions',
61
+ payload: {
62
+ uid: user.uid,
63
+ }
64
+ },
65
+ })
66
+ .then((json) => {
67
+ assistant.log(`Signout of all sessions success`, json);
68
+ })
69
+ .catch(e => {
70
+ assistant.error(`Signout of all sessions failed`, e);
71
+ })
72
+
44
73
  // Update user count
74
+ assistant.log(`Decrement user count...`);
45
75
  await libraries.admin.firestore().doc(`meta/stats`)
46
76
  .update({
47
77
  'users.total': libraries.admin.firestore.FieldValue.increment(-1),
48
78
  })
79
+ .then((r) => {
80
+ assistant.log(`Decrement user count success`);
81
+ })
49
82
  .catch((e) => {
50
83
  assistant.error(`Failed to decrement user`, e);
51
84
  })
52
85
 
86
+ // Log the updated user
53
87
  assistant.log(`User deleted ${user.uid}:`, user, context);
54
88
 
89
+ // Send response
55
90
  return resolve(self);
56
91
  });
57
92
  };
@@ -49,9 +49,6 @@ Usage.prototype.init = function (assistant, options) {
49
49
  return reject(new Error('Missing required {assistant} parameter'));
50
50
  }
51
51
 
52
- const localKey = (options.localKey || self.assistant.request.geolocation.ip || '')
53
- .replace(/[\.:]/g, '_');
54
-
55
52
  // Set options
56
53
  self.options = options;
57
54
 
@@ -61,6 +58,11 @@ Usage.prototype.init = function (assistant, options) {
61
58
  // Setup storage
62
59
  self.storage = Manager.storage({name: 'usage', temporary: true, clear: options.clear, log: options.log});
63
60
 
61
+ // Set local key
62
+ const localKey = (options.localKey || self.assistant.request.geolocation.ip || '')
63
+ .replace(/[\.:]/g, '_');
64
+
65
+ // Set paths
64
66
  self.paths.user = `users.${localKey}`;
65
67
  self.paths.app = `apps.${options.app}`;
66
68