backend-manager 3.2.172 → 3.2.174

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 (89) hide show
  1. package/package.json +3 -3
  2. package/src/cli/cli.js +27 -11
  3. package/src/manager/helpers/assistant.js +51 -76
  4. package/src/manager/index.js +22 -1
  5. package/dist/cli/cli.js +0 -1534
  6. package/dist/manager/functions/core/actions/api/admin/backup.js +0 -338
  7. package/dist/manager/functions/core/actions/api/admin/create-post.js +0 -388
  8. package/dist/manager/functions/core/actions/api/admin/cron.js +0 -37
  9. package/dist/manager/functions/core/actions/api/admin/database-read.js +0 -35
  10. package/dist/manager/functions/core/actions/api/admin/database-write.js +0 -39
  11. package/dist/manager/functions/core/actions/api/admin/edit-post.js +0 -158
  12. package/dist/manager/functions/core/actions/api/admin/firestore-query.js +0 -165
  13. package/dist/manager/functions/core/actions/api/admin/firestore-read.js +0 -38
  14. package/dist/manager/functions/core/actions/api/admin/firestore-write.js +0 -54
  15. package/dist/manager/functions/core/actions/api/admin/get-stats.js +0 -269
  16. package/dist/manager/functions/core/actions/api/admin/payment-processor.js +0 -57
  17. package/dist/manager/functions/core/actions/api/admin/run-hook.js +0 -95
  18. package/dist/manager/functions/core/actions/api/admin/send-notification.js +0 -197
  19. package/dist/manager/functions/core/actions/api/admin/sync-users.js +0 -125
  20. package/dist/manager/functions/core/actions/api/admin/templates/post.html +0 -16
  21. package/dist/manager/functions/core/actions/api/firebase/get-providers.js +0 -102
  22. package/dist/manager/functions/core/actions/api/general/emails/general:download-app-link.js +0 -21
  23. package/dist/manager/functions/core/actions/api/general/fetch-post.js +0 -99
  24. package/dist/manager/functions/core/actions/api/general/generate-uuid.js +0 -41
  25. package/dist/manager/functions/core/actions/api/general/send-email.js +0 -112
  26. package/dist/manager/functions/core/actions/api/handler/create-post.js +0 -146
  27. package/dist/manager/functions/core/actions/api/special/setup-electron-manager-client.js +0 -103
  28. package/dist/manager/functions/core/actions/api/template.js +0 -33
  29. package/dist/manager/functions/core/actions/api/test/authenticate.js +0 -22
  30. package/dist/manager/functions/core/actions/api/test/create-test-accounts.js +0 -27
  31. package/dist/manager/functions/core/actions/api/test/lab.js +0 -55
  32. package/dist/manager/functions/core/actions/api/test/redirect.js +0 -26
  33. package/dist/manager/functions/core/actions/api/test/webhook.js +0 -30
  34. package/dist/manager/functions/core/actions/api/user/create-custom-token.js +0 -32
  35. package/dist/manager/functions/core/actions/api/user/delete.js +0 -68
  36. package/dist/manager/functions/core/actions/api/user/get-active-sessions.js +0 -45
  37. package/dist/manager/functions/core/actions/api/user/get-subscription-info.js +0 -49
  38. package/dist/manager/functions/core/actions/api/user/oauth2/discord.js +0 -114
  39. package/dist/manager/functions/core/actions/api/user/oauth2/google.js +0 -99
  40. package/dist/manager/functions/core/actions/api/user/oauth2.js +0 -476
  41. package/dist/manager/functions/core/actions/api/user/regenerate-api-keys.js +0 -54
  42. package/dist/manager/functions/core/actions/api/user/resolve.js +0 -32
  43. package/dist/manager/functions/core/actions/api/user/sign-out-all-sessions.js +0 -118
  44. package/dist/manager/functions/core/actions/api/user/sign-up copy.js +0 -544
  45. package/dist/manager/functions/core/actions/api/user/sign-up.js +0 -99
  46. package/dist/manager/functions/core/actions/api/user/submit-feedback.js +0 -96
  47. package/dist/manager/functions/core/actions/api/user/validate-settings.js +0 -86
  48. package/dist/manager/functions/core/actions/api.js +0 -354
  49. package/dist/manager/functions/core/actions/create-post-handler.js +0 -184
  50. package/dist/manager/functions/core/actions/generate-uuid.js +0 -62
  51. package/dist/manager/functions/core/actions/sign-up-handler.js +0 -205
  52. package/dist/manager/functions/core/admin/create-post.js +0 -206
  53. package/dist/manager/functions/core/admin/firestore-write.js +0 -72
  54. package/dist/manager/functions/core/admin/get-stats.js +0 -218
  55. package/dist/manager/functions/core/admin/query.js +0 -198
  56. package/dist/manager/functions/core/admin/send-notification.js +0 -206
  57. package/dist/manager/functions/core/cron/daily/ghostii-auto-publisher.js +0 -377
  58. package/dist/manager/functions/core/cron/daily/reset-usage.js +0 -197
  59. package/dist/manager/functions/core/cron/daily.js +0 -114
  60. package/dist/manager/functions/core/events/auth/before-create.js +0 -124
  61. package/dist/manager/functions/core/events/auth/before-signin.js +0 -62
  62. package/dist/manager/functions/core/events/auth/on-create copy.js +0 -121
  63. package/dist/manager/functions/core/events/auth/on-create.js +0 -564
  64. package/dist/manager/functions/core/events/auth/on-delete.js +0 -72
  65. package/dist/manager/functions/core/events/firestore/on-subscription.js +0 -107
  66. package/dist/manager/functions/test/authenticate.js +0 -38
  67. package/dist/manager/functions/test/create-test-accounts.js +0 -144
  68. package/dist/manager/functions/test/webhook.js +0 -37
  69. package/dist/manager/functions/wrappers/mailchimp/addToList.js +0 -25
  70. package/dist/manager/helpers/analytics copy.js +0 -217
  71. package/dist/manager/helpers/analytics.js +0 -467
  72. package/dist/manager/helpers/api-manager.js +0 -324
  73. package/dist/manager/helpers/assistant.js +0 -1043
  74. package/dist/manager/helpers/metadata.js +0 -32
  75. package/dist/manager/helpers/middleware.js +0 -154
  76. package/dist/manager/helpers/roles.js +0 -69
  77. package/dist/manager/helpers/settings.js +0 -158
  78. package/dist/manager/helpers/subscription-resolver-new.js +0 -828
  79. package/dist/manager/helpers/subscription-resolver.js +0 -842
  80. package/dist/manager/helpers/usage.js +0 -381
  81. package/dist/manager/helpers/user.js +0 -198
  82. package/dist/manager/helpers/utilities.js +0 -292
  83. package/dist/manager/index.js +0 -1076
  84. package/dist/manager/libraries/openai.js +0 -460
  85. package/dist/manager/routes/restart/index.js +0 -52
  86. package/dist/manager/routes/test/index.js +0 -43
  87. package/dist/manager/schemas/restart.js +0 -13
  88. package/dist/manager/schemas/test.js +0 -13
  89. package/dist/require.js +0 -3
@@ -1,112 +0,0 @@
1
- const path = require('path');
2
- const fetch = require('wonderful-fetch');
3
- const {get,set,merge} = require('lodash');
4
-
5
- function Module() {
6
-
7
- }
8
-
9
- Module.prototype.main = function () {
10
- const self = this;
11
- const Manager = self.Manager;
12
- const Api = self.Api;
13
- const assistant = self.assistant;
14
- const payload = self.payload;
15
-
16
- return new Promise(async function(resolve, reject) {
17
- payload.data.payload.id = payload.data.payload.id;
18
- payload.data.payload.email = payload.data.payload.email;
19
- payload.data.payload.name = payload.data.payload.name;
20
-
21
- const DEFAULT = {
22
-
23
- spamFilter: {
24
- ip: 3,
25
- email: 3,
26
- },
27
- delay: 1,
28
- payload: {
29
- backendManagerKey: Manager.config.backend_manager.key,
30
- app: Manager.config.app.id,
31
- },
32
- }
33
-
34
- if (!payload.data.payload.id) {
35
- return reject(assistant.errorify(`Parameter {id} is required.`, {code: 400}));
36
- } else if (!payload.data.payload.email) {
37
- return reject(assistant.errorify(`Parameter {email} is required.`, {code: 400}));
38
- }
39
-
40
- let emailPayload
41
- try {
42
- const script = require(path.join(__dirname, 'emails', `${payload.data.payload.id}.js`))
43
- emailPayload = merge(
44
- {},
45
- DEFAULT,
46
- script(payload.data.payload, Manager.config),
47
- );
48
- } catch (e) {
49
- return reject(assistant.errorify(`${payload.data.payload.id} is not a valid email ID.`, {code: 400}));
50
- }
51
-
52
- const storage = Manager.storage({temporary: true});
53
- const ipPath = ['api:general:send-email', 'ips', assistant.request.geolocation.ip];
54
- const emailPath = ['api:general:send-email', 'emails', payload.data.payload.email];
55
-
56
- const ipData = storage.get(ipPath).value() || {};
57
- const emailData = storage.get(emailPath).value() || {};
58
-
59
- ipData.count = (ipData.count || 0) + 1;
60
- ipData.firstRequestTime = ipData.firstRequestTime ? ipData.firstRequestTime : new Date().toISOString();
61
- ipData.lastRequestTime = new Date().toISOString();
62
-
63
- emailData.count = (emailData.count || 0) + 1;
64
- emailData.firstRequestTime = emailData.firstRequestTime ? emailData.firstRequestTime : new Date().toISOString();
65
- emailData.lastRequestTime = new Date().toISOString();
66
-
67
- storage.set(ipPath, ipData).write();
68
- storage.set(emailPath, emailData).write();
69
-
70
- assistant.log('Storage:', storage.getState()['api:general:send-email']);
71
-
72
- if (ipData.count >= emailPayload.spamFilter.ip || emailData.count >= emailPayload.spamFilter.email) {
73
- self.assistant.errorify(`Spam filter triggered ip=${ipData.count}, email=${emailData.count}`, {code: 429, log: true});
74
-
75
- return resolve({data: {success: true}});
76
- }
77
-
78
- if (emailPayload.delay) {
79
- // emailPayload.payload.sendAt = new Date(new Date().getTime() + (emailPayload.delay * 1000)).toISOString();
80
- emailPayload.payload.sendAt = Math.round((new Date().getTime() + emailPayload.delay) / 1000);
81
- }
82
-
83
- // Log the email payload
84
- assistant.log('Email payload:', emailPayload);
85
-
86
- // Send the email
87
- await fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
88
- method: 'post',
89
- response: 'json',
90
- log: true,
91
- body: emailPayload.payload,
92
- })
93
- .then(async (json) => {
94
- assistant.log('Response:', json);
95
-
96
- return resolve({
97
- data: {
98
- success: true,
99
- }
100
- });
101
- })
102
- .catch(e => {
103
- return reject(assistant.errorify(`Error sending email: ${e}`, {code: 500, sentry: true}));
104
- });
105
-
106
- });
107
-
108
- };
109
-
110
-
111
- module.exports = Module;
112
-
@@ -1,146 +0,0 @@
1
- const fetch = require('wonderful-fetch');
2
- const _ = require('lodash')
3
-
4
- function Module() {
5
-
6
- }
7
-
8
- Module.prototype.main = function () {
9
- const self = this;
10
- const Manager = self.Manager;
11
- const Api = self.Api;
12
- const assistant = self.assistant;
13
- const payload = self.payload;
14
-
15
- return new Promise(async function(resolve, reject) {
16
-
17
- if (!payload.user.roles.admin) {
18
- return reject(assistant.errorify(`Admin required.`, {code: 401}));
19
- }
20
-
21
- payload.response.data = {
22
- invoice: {
23
- success: false,
24
- data: {},
25
- },
26
- notification: {
27
- success: false,
28
- data: {},
29
- }
30
- }
31
-
32
- const postSlug = `/blog/${payload.data.payload.url}`;
33
- const postUrl = `${Manager.config.brand.url}${postSlug}`;
34
- const invoiceNote = `GP to ${Manager.config.brand.name} \nSlug: ${postSlug} \n\n${payload.data.payload.invoiceNote || ''}`
35
-
36
- if (payload.data.payload.invoiceEmail && payload.data.payload.invoicePrice) {
37
- // Create invoice
38
- const createdInvoice = await fetch('https://us-central1-itw-creative-works.cloudfunctions.net/wrapper', {
39
- method: 'POST',
40
- response: 'json',
41
- body: {
42
- authenticationToken: Manager.config.backend_manager.key,
43
- method: 'post',
44
- service: 'paypal',
45
- command: 'v2/invoicing/invoices',
46
- body: {
47
- detail: {
48
- currency_code: 'USD',
49
- // note: `Post to ${Manager.config.brand.name} \n ${payload.data.payload.invoiceNote || ''}`,
50
- // note: `GP to ${Manager.config.brand.name} \n\n${payload.data.payload.invoiceNote || '' }`,
51
- // memo: `GP to ${Manager.config.brand.name} \nSlug: ${postSlug}`,
52
- note: invoiceNote,
53
- memo: invoiceNote,
54
- },
55
- primary_recipients: [
56
- {
57
- billing_info: {
58
- email_address: payload.data.payload.invoiceEmail,
59
- },
60
- }
61
- ],
62
- items: [
63
- {
64
- // name: `Guest Post`,
65
- name: `GP`,
66
- // description: `Post URL: ${postUrl}`,
67
- description: `Slug: ${postSlug}`,
68
- quantity: '1',
69
- unit_amount: {
70
- currency_code: 'USD',
71
- value: `${payload.data.payload.invoicePrice}`
72
- },
73
- // discount: {
74
- // percent: '5'
75
- // },
76
- unit_of_measure: 'QUANTITY',
77
- },
78
- ],
79
- }
80
- },
81
- })
82
- .then(response => response)
83
- .catch(e => e);
84
-
85
- if (createdInvoice instanceof Error) {
86
- return reject(assistant.errorify(createdInvoice, {code: 400}));
87
- }
88
-
89
- // Send invoice
90
- const createdInvoiceId = _.get(createdInvoice, 'href', '').split('/').pop();
91
- const sentInvoice = await fetch('https://us-central1-itw-creative-works.cloudfunctions.net/wrapper', {
92
- method: 'POST',
93
- response: 'json',
94
- body: {
95
- authenticationToken: Manager.config.backend_manager.key,
96
- service: 'paypal',
97
- command: `v2/invoicing/invoices/${createdInvoiceId}/send`,
98
- method: 'post',
99
- body: {
100
- }
101
- },
102
- })
103
- .then(response => response)
104
- .catch(e => e);
105
-
106
- if (sentInvoice instanceof Error) {
107
- return reject(assistant.errorify(sentInvoice, {code: 500}));
108
- }
109
-
110
- payload.response.data.invoice = {
111
- success: true,
112
- data: sentInvoice,
113
- }
114
-
115
- }
116
-
117
- // Send notification
118
- if (payload.data.payload.sendNotification !== false) {
119
- const sentNotification = fetch(`https://us-central1-${Manager.project.projectId}.cloudfunctions.net/bm_api`, {
120
- method: 'POST',
121
- response: 'json',
122
- body: {
123
- authenticationToken: Manager.config.backend_manager.key,
124
- command: `admin:send-notification`,
125
- payload: {
126
- title: payload.data.payload.title,
127
- body: `"${payload.data.payload.title}" was just published on our blog. It's a great read and we think you'll enjoy the content!`,
128
- // click_action: `${Manager.config.brand.url}/${postUrl}`,
129
- click_action: `${Manager.config.brand.url}/blog`,
130
- icon: Manager.config.brand.brandmark,
131
- }
132
- },
133
- })
134
- .then(response => response)
135
- .catch(e => e);
136
- }
137
-
138
- return resolve({data: payload.response.data})
139
-
140
-
141
- });
142
-
143
- };
144
-
145
-
146
- module.exports = Module;
@@ -1,103 +0,0 @@
1
- function Module() {
2
-
3
- }
4
-
5
- Module.prototype.main = function () {
6
- const self = this;
7
- const Manager = self.Manager;
8
- const Api = self.Api;
9
- const assistant = self.assistant;
10
- const payload = self.payload;
11
-
12
- return new Promise(async function(resolve, reject) {
13
-
14
- const fetch = Manager.require('wonderful-fetch');
15
- const _ = Manager.require('lodash');
16
-
17
- let uid = payload.data.payload.uid;
18
- const app = payload.data.payload.appId || payload.data.payload.app || Manager.config.app.id;
19
- let config = payload.data.payload.config || {};
20
-
21
- let uuid = null;
22
- let error;
23
-
24
- let signInToken = null;
25
-
26
- if (payload.data.authenticationToken || payload.data.backendManagerKey) {
27
- await self.Api.resolveUser({adminRequired: true})
28
- .then(async (user) => {
29
- uid = _.get(user, 'auth.uid', null);
30
- await self.libraries.admin.auth().createCustomToken(uid)
31
- .then(token => {
32
- signInToken = token;
33
- })
34
- .catch(e => {
35
- error = assistant.errorify(`Failed to create custom token: ${e}`, {code: 500});
36
- })
37
- })
38
- .catch(e => {
39
- assistant.errorify(`Failed to resolve user: ${e}`, {code: 500, log: true});
40
- })
41
-
42
- if (error) {
43
- return reject(error)
44
- }
45
- }
46
-
47
- // Generate uuid
48
- if (uid) {
49
- await Api.import('general:generate-uuid', {version: 5, name: uid})
50
- .then(library => {
51
-
52
- library.main()
53
- .then(result => {
54
- uuid = result.data.uuid;
55
- })
56
- .catch(e => {
57
- error = e;
58
- })
59
- })
60
- }
61
-
62
- if (error) {
63
- return reject(error)
64
- }
65
-
66
- if (config.backendManagerKey === Manager.config.backend_manager.key && Manager.config.backend_manager.key) {
67
- assistant.log('Validated config', config)
68
- } else {
69
- config = {};
70
- }
71
-
72
- // Fetch app details
73
- await fetch('https://us-central1-itw-creative-works.cloudfunctions.net/getApp', {
74
- method: 'post',
75
- timeout: 30000,
76
- tries: 3,
77
- response: 'json',
78
- body: {
79
- id: app,
80
- },
81
- })
82
- .then(result => {
83
- return resolve({
84
- data: {
85
- uuid: uuid,
86
- signInToken: signInToken,
87
- timestamp: new Date().toISOString(),
88
- ip: assistant.request.geolocation.ip,
89
- country: assistant.request.geolocation.country,
90
- app: result,
91
- config: config,
92
- }
93
- });
94
- })
95
- .catch(e => {
96
- return reject(assistant.errorify(`Error fetching app details: ${e}`, {code: 500}));
97
- })
98
-
99
- });
100
-
101
- };
102
-
103
- module.exports = Module;
@@ -1,33 +0,0 @@
1
- function Module() {
2
-
3
- }
4
-
5
- Module.prototype.main = function () {
6
- const self = this;
7
- const Manager = self.Manager;
8
- const Api = self.Api;
9
- const assistant = self.assistant;
10
- const payload = self.payload;
11
-
12
- return new Promise(async function(resolve, reject) {
13
-
14
- if (!payload.user.roles.admin) {
15
- return reject(assistant.errorify(`Admin required.`, {code: 401}));
16
- }
17
-
18
- // self.Api.resolveUser({adminRequired: false})
19
- // .then(async (user) => {
20
- //
21
- // })
22
- // .catch(e => {
23
- // return reject(e);
24
- // })
25
-
26
- return resolve({data: {success: true}});
27
-
28
- });
29
-
30
- };
31
-
32
-
33
- module.exports = Module;
@@ -1,22 +0,0 @@
1
- function Module() {
2
-
3
- }
4
-
5
- Module.prototype.main = function () {
6
- const self = this;
7
- const Manager = self.Manager;
8
- const Api = self.Api;
9
- const assistant = self.assistant;
10
- const payload = self.payload;
11
-
12
- return new Promise(async function(resolve, reject) {
13
-
14
- assistant.log('User:', payload.user);
15
-
16
- return resolve({data: {user: payload.user}});
17
- });
18
-
19
- };
20
-
21
-
22
- module.exports = Module;
@@ -1,27 +0,0 @@
1
- function Module() {
2
-
3
- }
4
-
5
- Module.prototype.main = function () {
6
- const self = this;
7
- const Manager = self.Manager;
8
- const Api = self.Api;
9
- const assistant = self.assistant;
10
- const payload = self.payload;
11
-
12
- return new Promise(async function(resolve, reject) {
13
-
14
- if (!payload.user.roles.admin) {
15
- return reject(assistant.errorify(`Admin required.`, {code: 401}));
16
- }
17
-
18
- assistant.log('User:', payload.user);
19
-
20
- return resolve({data: {user: user}});
21
-
22
- });
23
-
24
- };
25
-
26
-
27
- module.exports = Module;
@@ -1,55 +0,0 @@
1
- const fetch = require('node-fetch');
2
- const _ = require('lodash')
3
-
4
- function Module() {
5
-
6
- }
7
-
8
- Module.prototype.main = function () {
9
- const self = this;
10
- const Manager = self.Manager;
11
- const Api = self.Api;
12
- const assistant = self.assistant;
13
- const payload = self.payload;
14
-
15
- return new Promise(async function(resolve, reject) {
16
-
17
- if (!payload.user.roles.admin) {
18
- self.assistant.log('User is not admin')
19
- }
20
-
21
- const url = 'https://itwcreativeworks.com';
22
- const title = 'https://itwcreativeworks.com';
23
- const icon = 'https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/socials/itw-creative-works-brandmark-square-black-1024x1024.png?cb=1651834176';
24
-
25
-
26
- await Api.import('admin:send-notification', {
27
- title: 'New blog post!',
28
- click_action: url,
29
- body: `"${title}" was just published on our blog. It's a great read and we think you'll enjoy the content!`,
30
- icon: icon,
31
- })
32
- .then(library => {
33
-
34
- console.log('----');
35
-
36
- library.main()
37
- .then(result => {
38
- return resolve({data: {success: true}});
39
- })
40
- .catch(e => {
41
- console.error('Error', e);
42
- })
43
-
44
- })
45
-
46
- // if (error) {
47
- //
48
- // }
49
-
50
- });
51
-
52
- };
53
-
54
-
55
- module.exports = Module;
@@ -1,26 +0,0 @@
1
- const uuid = require('uuid');
2
-
3
- function Module() {
4
-
5
- }
6
-
7
- Module.prototype.main = function () {
8
- const self = this;
9
- const Manager = self.Manager;
10
- const Api = self.Api;
11
- const assistant = self.assistant;
12
- const payload = self.payload;
13
-
14
- return new Promise(async function(resolve, reject) {
15
-
16
- payload.data.payload.url = payload.data.payload.url || 'https://itwcreativeworks.com'
17
-
18
- assistant.log('Redirecting', payload.data.payload.url);
19
-
20
- return resolve({redirect: payload.data.payload.url});
21
- });
22
-
23
- };
24
-
25
-
26
- module.exports = Module;
@@ -1,30 +0,0 @@
1
- function Module() {
2
-
3
- }
4
-
5
- Module.prototype.main = function () {
6
- const self = this;
7
- const Manager = self.Manager;
8
- const Api = self.Api;
9
- const assistant = self.assistant;
10
- const payload = self.payload;
11
- const powertools = Manager.require('node-powertools');
12
-
13
- return new Promise(async function(resolve, reject) {
14
-
15
- if (payload.data.payload.delay > 0) {
16
- await powertools.wait(payload.data.payload.delay)
17
- }
18
-
19
- if (payload.data.payload.status >= 200 && payload.data.payload.status <= 299) {
20
- return resolve({data: payload.data.payload.response, status: payload.data.payload.status});
21
- } else if (payload.data.payload.status >= 400 && payload.data.payload.status <= 599) {
22
- return reject(assistant.errorify(payload.data.payload.response || 'Unknown error message provided', {code: payload.data.payload.status}));
23
- }
24
-
25
- });
26
-
27
- };
28
-
29
-
30
- module.exports = Module;
@@ -1,32 +0,0 @@
1
- const _ = require('lodash')
2
-
3
- function Module() {
4
-
5
- }
6
-
7
- Module.prototype.main = function () {
8
- const self = this;
9
- const Manager = self.Manager;
10
- const Api = self.Api;
11
- const assistant = self.assistant;
12
- const payload = self.payload;
13
-
14
- return new Promise(async function(resolve, reject) {
15
- Api.resolveUser({adminRequired: true})
16
- .then(async (user) => {
17
- await self.libraries.admin.auth().createCustomToken(_.get(user, 'auth.uid', null))
18
- .then(token => {
19
- return resolve({data: {token: token}});
20
- })
21
- .catch(e => {
22
- return reject(assistant.errorify(`Failed to create custom token: ${e}`, {code: 400}));
23
- })
24
- })
25
- .catch(e => {
26
- return reject(e);
27
- })
28
- });
29
- };
30
-
31
-
32
- module.exports = Module;
@@ -1,68 +0,0 @@
1
- const _ = require('lodash');
2
- const fetch = require('wonderful-fetch');
3
-
4
- function Module() {
5
-
6
- }
7
-
8
- Module.prototype.main = function () {
9
- const self = this;
10
- const Manager = self.Manager;
11
- const Api = self.Api;
12
- const assistant = self.assistant;
13
- const payload = self.payload;
14
-
15
- return new Promise(async function(resolve, reject) {
16
- Api.resolveUser({adminRequired: true})
17
- .then(async (user) => {
18
- const uid = user?.auth?.uid;
19
-
20
- // Disallow deleting users with subscriptions in any state other than cancelled or active payments
21
- if (
22
- (user?.plan?.status && user?.plan?.status !== 'cancelled')
23
- || user?.plan?.payment?.active
24
- ) {
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}));
26
- }
27
-
28
- // Signout of all sessions
29
- assistant.log(`Signout of all sessions...`);
30
- await fetch(`https://us-central1-${self.Manager.project.projectId}.cloudfunctions.net/bm_api`, {
31
- method: 'post',
32
- timeout: 30000,
33
- response: 'json',
34
- tries: 2,
35
- log: true,
36
- body: {
37
- backendManagerKey: self.Manager.config.backend_manager.key,
38
- command: 'user:sign-out-all-sessions',
39
- payload: {
40
- uid: uid,
41
- }
42
- },
43
- })
44
- .then((json) => {
45
- assistant.log(`Signout of all sessions success`, json);
46
- })
47
- .catch(e => {
48
- assistant.error(`Signout of all sessions failed`, e);
49
- })
50
-
51
- // Perform the delete
52
- await self.libraries.admin.auth().deleteUser(uid)
53
- .then(() => {
54
- return resolve({data: {success: true}});
55
- })
56
- .catch(e => {
57
- return reject(assistant.errorify(`Failed to delete user: ${e}`, {code: 400}));
58
- })
59
- })
60
- .catch(e => {
61
- return reject(e);
62
- })
63
- });
64
-
65
- };
66
-
67
-
68
- module.exports = Module;