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,564 +0,0 @@
1
- const { get, merge } = require('lodash');
2
- const powertools = require('node-powertools');
3
- const fetch = require('wonderful-fetch');
4
- const moment = require('moment');
5
-
6
- const MAX_SIGNUPS = 3;
7
- const MAX_AGE = 30;
8
-
9
- function Module() {
10
- const self = this;
11
- }
12
-
13
- Module.prototype.init = function (Manager, payload) {
14
- const self = this;
15
- self.Manager = Manager;
16
- self.assistant = Manager.Assistant();
17
- self.libraries = Manager.libraries;
18
- self.user = payload.user
19
- self.context = payload.context
20
-
21
- return self;
22
- };
23
-
24
- Module.prototype.main = function () {
25
- const self = this;
26
- const Manager = self.Manager;
27
- const assistant = self.assistant;
28
- const user = self.user;
29
- const context = self.context;
30
-
31
- return new Promise(async function(resolve, reject) {
32
- const { admin, functions } = self.libraries;
33
-
34
- // ⛔️⛔️⛔️ This function could be triggered when the user signs up with Google after already having a email/password account
35
-
36
- assistant.log(`Request: ${user.uid}`, user, context);
37
-
38
- // Calculate user age before the poll
39
- const ageInSeconds = (Date.now() - new Date(user.metadata.creationTime)) / 1000;
40
-
41
- // If user is not new, skip auth-on-create handler
42
- // This is important to prevent this from running when they link another provider
43
- if (ageInSeconds >= MAX_AGE) {
44
- assistant.log(`Skipping because ${user.uid} is NOT NEW (age=${ageInSeconds}):`, existingUser);
45
-
46
- return resolve(self);
47
- }
48
-
49
- // Check if exists already
50
- let existingUser;
51
- await powertools.poll(async () => {
52
- existingUser = await admin.firestore().doc(`users/${user.uid}`)
53
- .get()
54
- .then((doc) => doc.data())
55
- .catch(e => e);
56
-
57
- assistant.log(`Polling for existing user ${user.uid}...`, existingUser);
58
-
59
- if (existingUser instanceof Error) {
60
- return false;
61
- }
62
-
63
- return existingUser;
64
- }, {interval: 1000, timeout: 30000})
65
- .catch(e => {
66
- assistant.error(`Timeout for existing user expired`, e);
67
- });
68
-
69
- // Log existing user
70
- assistant.log(`Result of existing user ${user.uid} search (age=${ageInSeconds}):`, existingUser);
71
-
72
- // Build user object
73
- let userRecord = Manager.User().properties;
74
- userRecord = merge(userRecord, existingUser, {
75
- auth: {
76
- uid: user.uid,
77
- email: user.email,
78
- },
79
- });
80
-
81
- // Fill in location
82
- // userRecord.personal.location.country = userRecord.activity.geolocation.country;
83
- // userRecord.personal.location.region = userRecord.activity.geolocation.region;
84
- // userRecord.personal.location.city = userRecord.activity.geolocation.city;
85
-
86
- const ip = userRecord.activity.geolocation.ip || '';
87
- const ipKey = ip.replace(/[\.:]/g, '_');
88
-
89
- // Init usage
90
- const usage = await Manager.Usage().init(assistant, {log: true, key: ip});
91
-
92
- // Check if IP has signed up too many times
93
- const signups = usage.getUsage('signups');
94
-
95
- // Log the signup
96
- assistant.log(`Validating signups ${signups}/${MAX_SIGNUPS} for ip ${ip}`, userRecord);
97
-
98
- // Check if the user has signed up too many times
99
- if (!ip) {
100
- assistant.log(`Skipping validation because IP was not provided`, ip);
101
- } else if (signups >= MAX_SIGNUPS) {
102
- // ⛔️ Important to increment user count before deleting the user because user:delete will decrement the count
103
- await self.incrementUserCount().catch(e => e);
104
- await self.deleteUser(userRecord).catch(e => e);
105
- // Disabled because most users create a fake email which will harm the reputation of the domain
106
- // await self.sendRateEmail(userRecord).catch(e => e);
107
-
108
- return reject(assistant.errorify(`Too many signups from this IP`, {code: 400}));
109
- }
110
-
111
- // Set up analytics
112
- const analytics = Manager.Analytics({
113
- assistant: assistant,
114
- uuid: userRecord.auth.uid,
115
- })
116
-
117
- // Don't save if anonymous
118
- if (user.providerData.filter(function (item) {
119
- if (item.providerId !== 'anonymous') {
120
- analytics.event({
121
- name: 'sign_up',
122
- params: {
123
- method: item.providerId,
124
- },
125
- });
126
-
127
- return true
128
- }
129
- }).length < 1) {
130
- return resolve(self);
131
- }
132
-
133
- // Increment signups
134
- usage.increment('signups');
135
-
136
- // Update signups
137
- await usage.update();
138
-
139
- // Increment user count
140
- await self.incrementUserCount().catch(e => e);
141
-
142
- // Add metadata
143
- userRecord.metadata = Manager.Metadata().set({tag: 'auth:on-create'});
144
-
145
- // Log
146
- assistant.log(`main(): User record created ${userRecord.auth.uid}:`, userRecord);
147
-
148
- // Add user record
149
- await admin.firestore().doc(`users/${userRecord.auth.uid}`)
150
- .set(userRecord, {merge: true})
151
- .catch((e) => {
152
- assistant.error(`Failed save user record`, e);
153
- })
154
-
155
- // Update referral
156
- await self.updateReferral(userRecord).catch(e => e);
157
-
158
- // Add to SendGrid list
159
- // TODO: This should only be done if the user has opted in to marketing
160
- await self.addToSendGridList(userRecord).catch(e => e);
161
-
162
- // Send welcome emails
163
- await self.sendWelcomeEmail(userRecord).catch(e => e);
164
- await self.sendCheckupEmail(userRecord).catch(e => e);
165
- await self.sendFeedbackEmail(userRecord).catch(e => e);
166
-
167
- return resolve(self);
168
- });
169
- };
170
-
171
- // Delete user
172
- Module.prototype.deleteUser = function (user) {
173
- const self = this;
174
-
175
- return new Promise(async function(resolve, reject) {
176
- const Manager = self.Manager;
177
- const assistant = self.assistant;
178
-
179
- // Log
180
- assistant.log(`deleteUser(): Starting...`, user.auth.uid);
181
-
182
- // Delete user
183
- await fetch(`https://us-central1-${Manager.project.projectId}.cloudfunctions.net/bm_api`, {
184
- method: 'post',
185
- timeout: 30000,
186
- response: 'json',
187
- log: true,
188
- body: {
189
- backendManagerKey: Manager.config.backend_manager.key,
190
- command: 'user:delete',
191
- payload: {
192
- uid: user.auth.uid,
193
- },
194
- },
195
- })
196
- .then((json) => {
197
- assistant.log(`deleteUser(): Success`, json);
198
-
199
- return resolve(json);
200
- })
201
- .catch(e => {
202
- assistant.error(`deleteUser(): Failed`, e);
203
-
204
- return reject(e);
205
- })
206
- });
207
- };
208
-
209
- // Increment user count
210
- Module.prototype.incrementUserCount = function () {
211
- const self = this;
212
-
213
- return new Promise(async function(resolve, reject) {
214
- const Manager = self.Manager;
215
- const assistant = self.assistant;
216
- const { admin } = self.libraries;
217
-
218
- // Log
219
- assistant.log(`incrementUserCount(): Starting...`);
220
-
221
- // Increment user count
222
- await admin.firestore().doc(`meta/stats`)
223
- .update({
224
- 'users.total': admin.firestore.FieldValue.increment(1),
225
- })
226
- .then(() => {
227
- assistant.log(`incrementUserCount(): Success`);
228
-
229
- return resolve();
230
- })
231
- .catch(e => {
232
- assistant.error(`incrementUserCount(): Failed`, e);
233
-
234
- return reject(e);
235
- })
236
- });
237
- };
238
-
239
- Module.prototype.sendRateEmail = function (user) {
240
- const self = this;
241
-
242
- return new Promise(async function(resolve, reject) {
243
- const Manager = self.Manager;
244
- const assistant = self.assistant;
245
-
246
- // Send email
247
- fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
248
- method: 'post',
249
- response: 'json',
250
- log: true,
251
- body: {
252
- backendManagerKey: Manager.config.backend_manager.key,
253
- app: Manager.config.app.id,
254
- to: {
255
- email: user.auth.email,
256
- },
257
- categories: [`account/too-many-signups`],
258
- subject: `Your ${Manager.config.brand.name} account has been deleted [${user.auth.uid}]`,
259
- template: 'd-b7f8da3c98ad49a2ad1e187f3a67b546',
260
- group: 25927,
261
- copy: true,
262
- data: {
263
- email: {
264
- preview: `You have signed up for too many accounts at ${Manager.config.brand.name}! Your account has been deleted.`,
265
- },
266
- body: {
267
- title: `${Manager.config.brand.name} account deleted`,
268
- message: `
269
- Your account at <strong>${Manager.config.brand.name}</strong> has been <strong>deleted</strong> because you have signed up for too many accounts.
270
- <br>
271
- <br>
272
- If you believe this is a mistake, please contact us at ${Manager.config.brand.email}.
273
- <br>
274
- <br>
275
- <strong>User Details</strong>:
276
- <br>
277
- <strong>UID</strong>: ${user.auth.uid}
278
- <br>
279
- <strong>Email</strong>: ${user.auth.email}
280
- <br>
281
- `,
282
- },
283
- },
284
- },
285
- })
286
- .then((json) => {
287
- assistant.log('sendRateEmail(): Success', json);
288
-
289
- return resolve(json);
290
- })
291
- .catch((e) => {
292
- assistant.error('sendRateEmail(): Failed', e);
293
-
294
- return reject(e);
295
- });
296
- });
297
- }
298
-
299
- Module.prototype.updateReferral = function (user) {
300
- const self = this;
301
-
302
- return new Promise(function(resolve, reject) {
303
- const Manager = self.Manager;
304
- const assistant = self.assistant;
305
- const { admin } = self.libraries;
306
-
307
- // Log
308
- assistant.log(`updateReferral(): user`, user.auth.uid, user.affiliate.referrer)
309
-
310
- // Result
311
- admin.firestore().collection('users')
312
- .where('affiliate.code', '==', user.affiliate.referrer)
313
- .get()
314
- .then(async (snapshot) => {
315
- if (snapshot.empty) {
316
- return resolve()
317
- }
318
- let count = 0;
319
- let found = false;
320
- let error = null;
321
-
322
- for (var i = 0; i < snapshot.size; i++) {
323
- const doc = snapshot.docs[i];
324
- if (!found) {
325
- let data = doc.data() || {};
326
-
327
- let referrals = data.affiliate && data.affiliate.referrals ? data.affiliate.referrals : [];
328
- referrals = Array.isArray(referrals) ? referrals : [];
329
- count = referrals.length;
330
- referrals = referrals.concat({
331
- uid: user.auth.uid,
332
- timestamp: assistant.meta.startTime.timestamp,
333
- })
334
-
335
- // Log
336
- assistant.log(`updateReferral(): appending referrals...`, doc.ref.id, referrals)
337
-
338
- // Update referrer
339
- await admin.firestore().doc(`users/${doc.ref.id}`)
340
- .set({
341
- affiliate: {
342
- referrals: referrals,
343
- }
344
- }, {merge: true})
345
- .then(r => {
346
- assistant.log('updateReferral(): append success');
347
- })
348
- .catch(e => {
349
- assistant.error('updateReferral(): append error', e);
350
- })
351
- }
352
- }
353
-
354
- return resolve();
355
- })
356
- .catch(e => {
357
- return reject(e);
358
- });
359
- });
360
- }
361
-
362
- Module.prototype.addToSendGridList = function (user) {
363
- const self = this;
364
-
365
- return new Promise(async function(resolve, reject) {
366
- const Manager = self.Manager;
367
- const assistant = self.assistant;
368
- const Api = self.Api;
369
-
370
- if (!user.auth.email) {
371
- return reject(new Error('Cannot add user to SendGrid list without email.'))
372
- }
373
-
374
- // Add to SendGrid list
375
- fetch('https://api.itwcreativeworks.com/wrapper', {
376
- method: 'post',
377
- response: 'json',
378
- body: {
379
- backendManagerKey: Manager.config.backend_manager.key,
380
- service: 'sendgrid',
381
- command: `v3/marketing/contacts`,
382
- method: `put`,
383
- supplemental: {
384
- app: Manager.config.app.id,
385
- source: 'backend-manager:auth:on-create',
386
- user: user,
387
- }
388
- },
389
- })
390
- .then((r) => {
391
- assistant.log('addToSendGridList(): Success', r)
392
- return resolve(r);
393
- })
394
- .catch((e) => {
395
- assistant.error('addToSendGridList(): Failed', e)
396
- return reject(e);
397
- })
398
- });
399
- }
400
-
401
- Module.prototype.sendWelcomeEmail = function (user) {
402
- const self = this;
403
-
404
- return new Promise(async function(resolve, reject) {
405
- const Manager = self.Manager;
406
- const assistant = self.assistant;
407
-
408
- // Send email
409
- fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
410
- method: 'post',
411
- response: 'json',
412
- log: true,
413
- body: {
414
- backendManagerKey: Manager.config.backend_manager.key,
415
- app: Manager.config.app.id,
416
- to: {
417
- email: user.auth.email,
418
- },
419
- categories: [`account/welcome`],
420
- subject: `Welcome to ${Manager.config.brand.name}!`,
421
- template: 'd-b7f8da3c98ad49a2ad1e187f3a67b546',
422
- group: 25928,
423
- copy: false,
424
- sendAt: moment().add(1, 'hour').unix(),
425
- data: {
426
- email: {
427
- preview: `Welcome aboard! I'm Ian, the CEO and founder of ${Manager.config.brand.name}. I'm here to ensure your journey with us gets off to a great start.`,
428
- },
429
- body: {
430
- title: `Welcome to ${Manager.config.brand.name}!`,
431
- message: `
432
- Welcome aboard!
433
- <br><br>
434
- I'm Ian, the founder and CEO of <strong>${Manager.config.brand.name}</strong>, and I'm thrilled to have you with us.
435
- Your journey begins today, and we are committed to supporting you every step of the way.
436
- <br><br>
437
- Feel free to reply directly to this email with any questions you may have.
438
- Our team and I are dedicated to ensuring your experience is exceptional.
439
- <br><br>
440
- Thank you for choosing <strong>${Manager.config.brand.name}</strong>. Here's to new beginnings!
441
- `
442
- },
443
- signoff: {
444
- type: 'personal',
445
- image: undefined,
446
- name: 'Ian Wiedenman, CEO',
447
- url: `https://ianwiedenman.com?utm_source=welcome-email&utm_medium=email&utm_campaign=${Manager.config.app.id}`,
448
- urlText: '@ianwieds',
449
- },
450
- },
451
- },
452
- })
453
- .then((json) => {
454
- assistant.log('sendWelcomeEmail(): Success', json)
455
- return resolve(json);
456
- })
457
- .catch((e) => {
458
- assistant.error('sendWelcomeEmail(): Failed', e)
459
- return reject(e);
460
- });
461
- });
462
- }
463
-
464
- Module.prototype.sendCheckupEmail = function (user) {
465
- const self = this;
466
-
467
- return new Promise(async function(resolve, reject) {
468
- const Manager = self.Manager;
469
- const assistant = self.assistant;
470
-
471
- // Send email
472
- fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
473
- method: 'post',
474
- response: 'json',
475
- log: true,
476
- body: {
477
- backendManagerKey: Manager.config.backend_manager.key,
478
- app: Manager.config.app.id,
479
- to: {
480
- email: user.auth.email,
481
- },
482
- categories: [`account/checkup`],
483
- subject: `How's your experience with ${Manager.config.brand.name}?`,
484
- template: 'd-b7f8da3c98ad49a2ad1e187f3a67b546',
485
- group: 25928,
486
- copy: false,
487
- sendAt: moment().add(7, 'days').unix(),
488
- data: {
489
- email: {
490
- preview: `Checking in from ${Manager.config.brand.name} to see how things are going. Let us know if you have any questions or feedback!`,
491
- },
492
- body: {
493
- title: `How's everything going?`,
494
- message: `
495
- Hi there,
496
- <br><br>
497
- It's Ian again from <strong>${Manager.config.brand.name}</strong>. Just checking in to see how things are going for you.
498
- <br><br>
499
- Have you had a chance to explore all our features? Any questions or feedback for us?
500
- <br><br>
501
- We're always here to help, so don't hesitate to reach out. Just reply to this email and we'll get back to you as soon as possible.
502
- <br><br>
503
- Thank you for choosing <strong>${Manager.config.brand.name}</strong>. Here's to new beginnings!
504
- `
505
- },
506
- signoff: {
507
- type: 'personal',
508
- image: undefined,
509
- name: 'Ian Wiedenman, CEO',
510
- url: `https://ianwiedenman.com?utm_source=checkup-email&utm_medium=email&utm_campaign=${Manager.config.app.id}`,
511
- urlText: '@ianwieds',
512
- },
513
- },
514
- },
515
- })
516
- .then((json) => {
517
- assistant.log('sendCheckupEmail(): Success', json)
518
- return resolve(json);
519
- })
520
- .catch((e) => {
521
- assistant.error('sendCheckupEmail(): Failed', e)
522
- return reject(e);
523
- });
524
- });
525
- }
526
-
527
- Module.prototype.sendFeedbackEmail = function (user) {
528
- const self = this;
529
-
530
- return new Promise(async function(resolve, reject) {
531
- const Manager = self.Manager;
532
- const assistant = self.assistant;
533
-
534
- // Send email
535
- fetch(`https://us-central1-itw-creative-works.cloudfunctions.net/sendEmail`, {
536
- method: 'post',
537
- response: 'json',
538
- log: true,
539
- body: {
540
- backendManagerKey: Manager.config.backend_manager.key,
541
- app: Manager.config.app.id,
542
- to: {
543
- email: user.auth.email,
544
- },
545
- categories: [`engagement/feedback`],
546
- subject: `Want to share your feedback about ${Manager.config.brand.name}?`,
547
- template: 'd-c1522214c67b47058669acc5a81ed663',
548
- group: 25928,
549
- copy: false,
550
- sendAt: moment().add(14, 'days').unix(),
551
- },
552
- })
553
- .then((json) => {
554
- assistant.log('sendFeedbackEmail(): Success', json)
555
- return resolve(json);
556
- })
557
- .catch((e) => {
558
- assistant.error('sendFeedbackEmail(): Failed', e)
559
- return reject(e);
560
- });
561
- });
562
- }
563
-
564
- module.exports = Module;
@@ -1,72 +0,0 @@
1
- const fetch = require('wonderful-fetch');
2
-
3
- function Module() {
4
- const self = this;
5
- }
6
-
7
- Module.prototype.init = function (Manager, payload) {
8
- const self = this;
9
- self.Manager = Manager;
10
- self.assistant = Manager.Assistant();
11
- self.libraries = Manager.libraries;
12
- self.user = payload.user
13
- self.context = payload.context
14
-
15
- return self;
16
- };
17
-
18
- Module.prototype.main = function () {
19
- const self = this;
20
- const Manager = self.Manager;
21
- const assistant = self.assistant;
22
- const user = self.user;
23
- const context = self.context;
24
-
25
- return new Promise(async function(resolve, reject) {
26
- const { admin, functions } = self.libraries;
27
-
28
- assistant.log(`Request: ${user.uid}`, user, context);
29
-
30
- // Set up analytics
31
- const analytics = Manager.Analytics({
32
- assistant: assistant,
33
- uuid: user.uid,
34
- })
35
- .event({
36
- name: 'user-delete',
37
- params: {},
38
- });
39
-
40
- // Delete user record
41
- assistant.log(`Delete user record...`);
42
- await admin.firestore().doc(`users/${user.uid}`)
43
- .delete()
44
- .then((r) => {
45
- assistant.log(`Delete user record success`);
46
- })
47
- .catch((e) => {
48
- assistant.error(`Delete user record failed`, e);
49
- })
50
-
51
- // Update user count
52
- assistant.log(`Decrement user count...`);
53
- await admin.firestore().doc(`meta/stats`)
54
- .update({
55
- 'users.total': admin.firestore.FieldValue.increment(-1),
56
- })
57
- .then((r) => {
58
- assistant.log(`Decrement user count success`);
59
- })
60
- .catch((e) => {
61
- assistant.error(`Failed to decrement user`, e);
62
- })
63
-
64
- // Log the updated user
65
- assistant.log(`User deleted ${user.uid}:`, user, context);
66
-
67
- // Send response
68
- return resolve(self);
69
- });
70
- };
71
-
72
- module.exports = Module;