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,124 +0,0 @@
1
- const { get, merge } = require('lodash');
2
-
3
- const ERROR_TOO_MANY_ATTEMPTS = 'You have created too many accounts with our service. Please try again later.';
4
-
5
- function Module() {
6
- const self = this;
7
- }
8
-
9
- Module.prototype.init = function (Manager, payload) {
10
- const self = this;
11
- self.Manager = Manager;
12
- self.assistant = Manager.Assistant();
13
- self.libraries = Manager.libraries;
14
- self.user = payload.user;
15
- self.context = payload.context;
16
-
17
- return self;
18
- };
19
-
20
- Module.prototype.main = function () {
21
- const self = this;
22
- const Manager = self.Manager;
23
- const assistant = self.assistant;
24
- const user = self.user;
25
- const context = self.context;
26
-
27
- return new Promise(async function(resolve, reject) {
28
- const { admin, functions } = self.libraries;
29
- const storage = Manager.storage({ temporary: true, name: 'rate-limiting' });
30
-
31
- assistant.log(`Request: ${user.uid}`, user, context);
32
-
33
- // TODO: ⛔️⛔️⛔️ UTILIZE THE NEW .usage() system (similar to src/manager/functions/core/actions/api/user/sign-up.js)
34
-
35
- // if (context.additionalUserInfo.recaptchaScore < 0.5) {
36
- // assistant.error(`Recaptcha score (${context.additionalUserInfo.recaptchaScore}) too low for ${user.uid}`);
37
-
38
- // throw new functions.auth.HttpsError('resource-exhausted', ERROR_TOO_MANY_ATTEMPTS);
39
- // }
40
-
41
- const ipAddress = context.ipAddress;
42
- const currentTime = Date.now();
43
- const oneHour = 60 * 60 * 1000; // One hour in milliseconds
44
-
45
- // Get current rate-limiting data
46
- const rateLimitingData = storage.get(`ipRateLimits.${ipAddress}`).value();
47
- const count = get(rateLimitingData, 'count', 0);
48
- const lastTime = get(rateLimitingData, 'lastTime', 0);
49
-
50
- assistant.log(`Rate limiting for ${ipAddress}:`, rateLimitingData);
51
-
52
- if (currentTime - lastTime < oneHour && count >= 2) {
53
- assistant.error(`Too many attemps to create an account for ${ipAddress}`);
54
-
55
- throw new functions.auth.HttpsError('resource-exhausted', ERROR_TOO_MANY_ATTEMPTS);
56
- }
57
-
58
- // Update rate-limiting data
59
- storage.set(`ipRateLimits.${ipAddress}`, { count: count + 1, lastTime: currentTime }).write();
60
-
61
- const existingAccount = await admin.firestore().doc(`users/${user.uid}`)
62
- .get()
63
- .then((doc) => doc.data())
64
- .catch(e => e);
65
-
66
- // If user already exists, skip auth-on-create handler
67
- if (existingAccount instanceof Error) {
68
- assistant.error(`Failed to get existing account ${user.uid}:`, existingAccount);
69
-
70
- throw new functions.auth.HttpsError('internal', `Failed to get existing account: ${existingAccount}`);
71
- }
72
-
73
- let account = {
74
- activity: {
75
- lastActivity: {
76
- timestamp: new Date(currentTime).toISOString(),
77
- timestampUNIX: Math.round(currentTime / 1000),
78
- },
79
- geolocation: {
80
- ip: ipAddress,
81
- language: context.locale,
82
- },
83
- client: {
84
- userAgent: context.userAgent,
85
- },
86
- },
87
- };
88
-
89
- // If it exists, just add the activity data
90
- if (!get(existingAccount, 'auth.uid', null) || !get(existingAccount, 'auth.email', null)) {
91
- account = merge(
92
- Manager.User({
93
- auth: {
94
- uid: user.uid,
95
- email: user.email,
96
- },
97
- activity: {
98
- created: {
99
- timestamp: new Date(currentTime).toISOString(),
100
- timestampUNIX: Math.round(currentTime / 1000),
101
- },
102
- },
103
- }).properties,
104
- account,
105
- );
106
- }
107
-
108
- // Save IP to Firestore after successful IP check
109
- const update = await admin.firestore().doc(`users/${user.uid}`)
110
- .set(account, { merge: true });
111
-
112
- if (update instanceof Error) {
113
- assistant.error(`Failed to update user ${user.uid}:`, update);
114
-
115
- throw new functions.auth.HttpsError('internal', `Failed to update user: ${update}`);
116
- }
117
-
118
- assistant.log(`User created at users/${user.uid}`, account);
119
-
120
- return resolve(self);
121
- });
122
- };
123
-
124
- module.exports = Module;
@@ -1,62 +0,0 @@
1
- const { get } = require('lodash');
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
- const now = new Date();
31
-
32
- // Save IP to Firestore after successful IP check
33
- const update = await admin.firestore().doc(`users/${user.uid}`)
34
- .set({
35
- activity: {
36
- lastActivity: {
37
- timestamp: now.toISOString(),
38
- timestampUNIX: Math.round(now.getTime() / 1000),
39
- },
40
- geolocation: {
41
- ip: context.ipAddress,
42
- language: context.locale,
43
- },
44
- client: {
45
- userAgent: context.userAgent,
46
- },
47
- },
48
- }, { merge: true });
49
-
50
- if (update instanceof Error) {
51
- assistant.error(`Failed to update user ${user.uid}:`, update);
52
-
53
- throw new functions.auth.HttpsError('internal', `Failed to update user: ${update}`);
54
- }
55
-
56
- assistant.log(`Updated user activity`);
57
-
58
- return resolve(self);
59
- });
60
- };
61
-
62
- module.exports = Module;
@@ -1,121 +0,0 @@
1
- const { get, merge } = require('lodash');
2
- const powertools = require('node-powertools');
3
-
4
- const MAX_AGE = 30;
5
-
6
- function Module() {
7
- const self = this;
8
- }
9
-
10
- Module.prototype.init = function (Manager, payload) {
11
- const self = this;
12
- self.Manager = Manager;
13
- self.libraries = Manager.libraries;
14
- self.assistant = Manager.Assistant();
15
- self.user = payload.user
16
- self.context = payload.context
17
-
18
- return self;
19
- };
20
-
21
- Module.prototype.main = function () {
22
- const self = this;
23
- const libraries = self.libraries;
24
- const assistant = self.assistant;
25
- const user = self.user;
26
- const context = self.context;
27
-
28
- return new Promise(async function(resolve, reject) {
29
- // ⛔️⛔️⛔️ This function could be triggered when the user signs up with Google after already having a email/password account
30
-
31
- assistant.log(`Request: ${user.uid}`, user, context);
32
-
33
- // Calculate user age before the poll
34
- const ageInSeconds = (Date.now() - new Date(user.metadata.creationTime)) / 1000;
35
-
36
- // If user is not new, skip auth-on-create handler
37
- if (ageInSeconds >= MAX_AGE) {
38
- assistant.log(`Skipping because ${user.uid} is NOT NEW (age=${ageInSeconds}):`, existingUser);
39
-
40
- return resolve(self);
41
- }
42
-
43
- // Check if exists already
44
- let existingUser;
45
- await powertools.poll(async () => {
46
- existingUser = await libraries.admin.firestore().doc(`users/${user.uid}`)
47
- .get()
48
- .then((doc) => doc.data())
49
- .catch(e => e);
50
-
51
- assistant.log(`Polling for existing user ${user.uid}...`, existingUser);
52
-
53
- if (existingUser instanceof Error) {
54
- return false;
55
- }
56
-
57
- return existingUser;
58
- }, {interval: 1000, timeout: 30000})
59
- .catch(e => {
60
- assistant.error(`Timeout for existing user expired`, e);
61
- });
62
-
63
- // Log existing user
64
- assistant.log(`Existing user ${user.uid} found (age=${ageInSeconds}):`, existingUser);
65
-
66
- // Build user object
67
- let newUser = self.Manager.User().properties;
68
-
69
- newUser = merge(newUser, existingUser, {
70
- auth: {
71
- uid: user.uid,
72
- email: user.email,
73
- },
74
- });
75
-
76
- // Set up analytics
77
- const analytics = self.Manager.Analytics({
78
- assistant: assistant,
79
- uuid: user.uid,
80
- })
81
-
82
- // Don't save if anonymous
83
- if (user.providerData.filter(function (item) {
84
- if (item.providerId !== 'anonymous') {
85
- analytics.event({
86
- category: 'engagement',
87
- action: 'signup',
88
- label: item.providerId,
89
- });
90
- return true
91
- }
92
- }).length < 1) {
93
- return resolve(self);
94
- }
95
-
96
- // Add metadata
97
- newUser.metadata = self.Manager.Metadata().set({tag: 'auth:on-create'});
98
-
99
- // Add user record
100
- await libraries.admin.firestore().doc(`users/${newUser.auth.uid}`)
101
- .set(newUser, {merge: true})
102
- .catch((e) => {
103
- assistant.error(`Failed save user record`, e);
104
- })
105
-
106
- // Update user count
107
- await libraries.admin.firestore().doc(`meta/stats`)
108
- .update({
109
- 'users.total': libraries.admin.firestore.FieldValue.increment(1),
110
- })
111
- .catch((e) => {
112
- assistant.error(`Failed to increment user`, e);
113
- })
114
-
115
- assistant.log(`User created ${user.uid}:`, newUser, user, context);
116
-
117
- return resolve(self);
118
- });
119
- };
120
-
121
- module.exports = Module;