backend-manager 3.2.170 → 3.2.171

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 (88) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/cli/cli.js +1534 -0
  4. package/dist/manager/functions/core/actions/api/admin/backup.js +338 -0
  5. package/dist/manager/functions/core/actions/api/admin/create-post.js +388 -0
  6. package/dist/manager/functions/core/actions/api/admin/cron.js +37 -0
  7. package/dist/manager/functions/core/actions/api/admin/database-read.js +35 -0
  8. package/dist/manager/functions/core/actions/api/admin/database-write.js +39 -0
  9. package/dist/manager/functions/core/actions/api/admin/edit-post.js +158 -0
  10. package/dist/manager/functions/core/actions/api/admin/firestore-query.js +165 -0
  11. package/dist/manager/functions/core/actions/api/admin/firestore-read.js +38 -0
  12. package/dist/manager/functions/core/actions/api/admin/firestore-write.js +54 -0
  13. package/dist/manager/functions/core/actions/api/admin/get-stats.js +269 -0
  14. package/dist/manager/functions/core/actions/api/admin/payment-processor.js +57 -0
  15. package/dist/manager/functions/core/actions/api/admin/run-hook.js +95 -0
  16. package/dist/manager/functions/core/actions/api/admin/send-notification.js +197 -0
  17. package/dist/manager/functions/core/actions/api/admin/sync-users.js +125 -0
  18. package/dist/manager/functions/core/actions/api/admin/templates/post.html +16 -0
  19. package/dist/manager/functions/core/actions/api/firebase/get-providers.js +102 -0
  20. package/dist/manager/functions/core/actions/api/general/emails/general:download-app-link.js +21 -0
  21. package/dist/manager/functions/core/actions/api/general/fetch-post.js +99 -0
  22. package/dist/manager/functions/core/actions/api/general/generate-uuid.js +41 -0
  23. package/dist/manager/functions/core/actions/api/general/send-email.js +112 -0
  24. package/dist/manager/functions/core/actions/api/handler/create-post.js +146 -0
  25. package/dist/manager/functions/core/actions/api/special/setup-electron-manager-client.js +103 -0
  26. package/dist/manager/functions/core/actions/api/template.js +33 -0
  27. package/dist/manager/functions/core/actions/api/test/authenticate.js +22 -0
  28. package/dist/manager/functions/core/actions/api/test/create-test-accounts.js +27 -0
  29. package/dist/manager/functions/core/actions/api/test/lab.js +55 -0
  30. package/dist/manager/functions/core/actions/api/test/redirect.js +26 -0
  31. package/dist/manager/functions/core/actions/api/test/webhook.js +30 -0
  32. package/dist/manager/functions/core/actions/api/user/create-custom-token.js +32 -0
  33. package/dist/manager/functions/core/actions/api/user/delete.js +68 -0
  34. package/dist/manager/functions/core/actions/api/user/get-active-sessions.js +45 -0
  35. package/dist/manager/functions/core/actions/api/user/get-subscription-info.js +49 -0
  36. package/dist/manager/functions/core/actions/api/user/oauth2/discord.js +114 -0
  37. package/dist/manager/functions/core/actions/api/user/oauth2/google.js +99 -0
  38. package/dist/manager/functions/core/actions/api/user/oauth2.js +476 -0
  39. package/dist/manager/functions/core/actions/api/user/regenerate-api-keys.js +54 -0
  40. package/dist/manager/functions/core/actions/api/user/resolve.js +32 -0
  41. package/dist/manager/functions/core/actions/api/user/sign-out-all-sessions.js +118 -0
  42. package/dist/manager/functions/core/actions/api/user/sign-up copy.js +544 -0
  43. package/dist/manager/functions/core/actions/api/user/sign-up.js +99 -0
  44. package/dist/manager/functions/core/actions/api/user/submit-feedback.js +96 -0
  45. package/dist/manager/functions/core/actions/api/user/validate-settings.js +86 -0
  46. package/dist/manager/functions/core/actions/api.js +354 -0
  47. package/dist/manager/functions/core/actions/create-post-handler.js +184 -0
  48. package/dist/manager/functions/core/actions/generate-uuid.js +62 -0
  49. package/dist/manager/functions/core/actions/sign-up-handler.js +205 -0
  50. package/dist/manager/functions/core/admin/create-post.js +206 -0
  51. package/dist/manager/functions/core/admin/firestore-write.js +72 -0
  52. package/dist/manager/functions/core/admin/get-stats.js +218 -0
  53. package/dist/manager/functions/core/admin/query.js +198 -0
  54. package/dist/manager/functions/core/admin/send-notification.js +206 -0
  55. package/dist/manager/functions/core/cron/daily/ghostii-auto-publisher.js +377 -0
  56. package/dist/manager/functions/core/cron/daily/reset-usage.js +197 -0
  57. package/dist/manager/functions/core/cron/daily.js +114 -0
  58. package/dist/manager/functions/core/events/auth/before-create.js +124 -0
  59. package/dist/manager/functions/core/events/auth/before-signin.js +62 -0
  60. package/dist/manager/functions/core/events/auth/on-create copy.js +121 -0
  61. package/dist/manager/functions/core/events/auth/on-create.js +564 -0
  62. package/dist/manager/functions/core/events/auth/on-delete.js +72 -0
  63. package/dist/manager/functions/core/events/firestore/on-subscription.js +107 -0
  64. package/dist/manager/functions/test/authenticate.js +38 -0
  65. package/dist/manager/functions/test/create-test-accounts.js +144 -0
  66. package/dist/manager/functions/test/webhook.js +37 -0
  67. package/dist/manager/functions/wrappers/mailchimp/addToList.js +25 -0
  68. package/dist/manager/helpers/analytics copy.js +217 -0
  69. package/dist/manager/helpers/analytics.js +467 -0
  70. package/dist/manager/helpers/api-manager.js +324 -0
  71. package/dist/manager/helpers/assistant.js +1043 -0
  72. package/dist/manager/helpers/metadata.js +32 -0
  73. package/dist/manager/helpers/middleware.js +154 -0
  74. package/dist/manager/helpers/roles.js +69 -0
  75. package/dist/manager/helpers/settings.js +158 -0
  76. package/dist/manager/helpers/subscription-resolver-new.js +828 -0
  77. package/dist/manager/helpers/subscription-resolver.js +842 -0
  78. package/dist/manager/helpers/usage.js +381 -0
  79. package/dist/manager/helpers/user.js +198 -0
  80. package/dist/manager/helpers/utilities.js +292 -0
  81. package/dist/manager/index.js +1076 -0
  82. package/dist/manager/libraries/openai.js +460 -0
  83. package/dist/manager/routes/restart/index.js +52 -0
  84. package/dist/manager/routes/test/index.js +43 -0
  85. package/dist/manager/schemas/restart.js +13 -0
  86. package/dist/manager/schemas/test.js +13 -0
  87. package/dist/require.js +3 -0
  88. package/package.json +18 -8
@@ -0,0 +1,124 @@
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;
@@ -0,0 +1,62 @@
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;
@@ -0,0 +1,121 @@
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;