backend-manager 3.2.172 → 3.2.173

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 (87) hide show
  1. package/package.json +3 -3
  2. package/src/cli/cli.js +27 -11
  3. package/dist/cli/cli.js +0 -1534
  4. package/dist/manager/functions/core/actions/api/admin/backup.js +0 -338
  5. package/dist/manager/functions/core/actions/api/admin/create-post.js +0 -388
  6. package/dist/manager/functions/core/actions/api/admin/cron.js +0 -37
  7. package/dist/manager/functions/core/actions/api/admin/database-read.js +0 -35
  8. package/dist/manager/functions/core/actions/api/admin/database-write.js +0 -39
  9. package/dist/manager/functions/core/actions/api/admin/edit-post.js +0 -158
  10. package/dist/manager/functions/core/actions/api/admin/firestore-query.js +0 -165
  11. package/dist/manager/functions/core/actions/api/admin/firestore-read.js +0 -38
  12. package/dist/manager/functions/core/actions/api/admin/firestore-write.js +0 -54
  13. package/dist/manager/functions/core/actions/api/admin/get-stats.js +0 -269
  14. package/dist/manager/functions/core/actions/api/admin/payment-processor.js +0 -57
  15. package/dist/manager/functions/core/actions/api/admin/run-hook.js +0 -95
  16. package/dist/manager/functions/core/actions/api/admin/send-notification.js +0 -197
  17. package/dist/manager/functions/core/actions/api/admin/sync-users.js +0 -125
  18. package/dist/manager/functions/core/actions/api/admin/templates/post.html +0 -16
  19. package/dist/manager/functions/core/actions/api/firebase/get-providers.js +0 -102
  20. package/dist/manager/functions/core/actions/api/general/emails/general:download-app-link.js +0 -21
  21. package/dist/manager/functions/core/actions/api/general/fetch-post.js +0 -99
  22. package/dist/manager/functions/core/actions/api/general/generate-uuid.js +0 -41
  23. package/dist/manager/functions/core/actions/api/general/send-email.js +0 -112
  24. package/dist/manager/functions/core/actions/api/handler/create-post.js +0 -146
  25. package/dist/manager/functions/core/actions/api/special/setup-electron-manager-client.js +0 -103
  26. package/dist/manager/functions/core/actions/api/template.js +0 -33
  27. package/dist/manager/functions/core/actions/api/test/authenticate.js +0 -22
  28. package/dist/manager/functions/core/actions/api/test/create-test-accounts.js +0 -27
  29. package/dist/manager/functions/core/actions/api/test/lab.js +0 -55
  30. package/dist/manager/functions/core/actions/api/test/redirect.js +0 -26
  31. package/dist/manager/functions/core/actions/api/test/webhook.js +0 -30
  32. package/dist/manager/functions/core/actions/api/user/create-custom-token.js +0 -32
  33. package/dist/manager/functions/core/actions/api/user/delete.js +0 -68
  34. package/dist/manager/functions/core/actions/api/user/get-active-sessions.js +0 -45
  35. package/dist/manager/functions/core/actions/api/user/get-subscription-info.js +0 -49
  36. package/dist/manager/functions/core/actions/api/user/oauth2/discord.js +0 -114
  37. package/dist/manager/functions/core/actions/api/user/oauth2/google.js +0 -99
  38. package/dist/manager/functions/core/actions/api/user/oauth2.js +0 -476
  39. package/dist/manager/functions/core/actions/api/user/regenerate-api-keys.js +0 -54
  40. package/dist/manager/functions/core/actions/api/user/resolve.js +0 -32
  41. package/dist/manager/functions/core/actions/api/user/sign-out-all-sessions.js +0 -118
  42. package/dist/manager/functions/core/actions/api/user/sign-up copy.js +0 -544
  43. package/dist/manager/functions/core/actions/api/user/sign-up.js +0 -99
  44. package/dist/manager/functions/core/actions/api/user/submit-feedback.js +0 -96
  45. package/dist/manager/functions/core/actions/api/user/validate-settings.js +0 -86
  46. package/dist/manager/functions/core/actions/api.js +0 -354
  47. package/dist/manager/functions/core/actions/create-post-handler.js +0 -184
  48. package/dist/manager/functions/core/actions/generate-uuid.js +0 -62
  49. package/dist/manager/functions/core/actions/sign-up-handler.js +0 -205
  50. package/dist/manager/functions/core/admin/create-post.js +0 -206
  51. package/dist/manager/functions/core/admin/firestore-write.js +0 -72
  52. package/dist/manager/functions/core/admin/get-stats.js +0 -218
  53. package/dist/manager/functions/core/admin/query.js +0 -198
  54. package/dist/manager/functions/core/admin/send-notification.js +0 -206
  55. package/dist/manager/functions/core/cron/daily/ghostii-auto-publisher.js +0 -377
  56. package/dist/manager/functions/core/cron/daily/reset-usage.js +0 -197
  57. package/dist/manager/functions/core/cron/daily.js +0 -114
  58. package/dist/manager/functions/core/events/auth/before-create.js +0 -124
  59. package/dist/manager/functions/core/events/auth/before-signin.js +0 -62
  60. package/dist/manager/functions/core/events/auth/on-create copy.js +0 -121
  61. package/dist/manager/functions/core/events/auth/on-create.js +0 -564
  62. package/dist/manager/functions/core/events/auth/on-delete.js +0 -72
  63. package/dist/manager/functions/core/events/firestore/on-subscription.js +0 -107
  64. package/dist/manager/functions/test/authenticate.js +0 -38
  65. package/dist/manager/functions/test/create-test-accounts.js +0 -144
  66. package/dist/manager/functions/test/webhook.js +0 -37
  67. package/dist/manager/functions/wrappers/mailchimp/addToList.js +0 -25
  68. package/dist/manager/helpers/analytics copy.js +0 -217
  69. package/dist/manager/helpers/analytics.js +0 -467
  70. package/dist/manager/helpers/api-manager.js +0 -324
  71. package/dist/manager/helpers/assistant.js +0 -1043
  72. package/dist/manager/helpers/metadata.js +0 -32
  73. package/dist/manager/helpers/middleware.js +0 -154
  74. package/dist/manager/helpers/roles.js +0 -69
  75. package/dist/manager/helpers/settings.js +0 -158
  76. package/dist/manager/helpers/subscription-resolver-new.js +0 -828
  77. package/dist/manager/helpers/subscription-resolver.js +0 -842
  78. package/dist/manager/helpers/usage.js +0 -381
  79. package/dist/manager/helpers/user.js +0 -198
  80. package/dist/manager/helpers/utilities.js +0 -292
  81. package/dist/manager/index.js +0 -1076
  82. package/dist/manager/libraries/openai.js +0 -460
  83. package/dist/manager/routes/restart/index.js +0 -52
  84. package/dist/manager/routes/test/index.js +0 -43
  85. package/dist/manager/schemas/restart.js +0 -13
  86. package/dist/manager/schemas/test.js +0 -13
  87. package/dist/require.js +0 -3
@@ -1,292 +0,0 @@
1
- let nanoId;
2
- let _;
3
-
4
- function Utilities(Manager) {
5
- const self = this;
6
-
7
- _ = require('lodash');
8
-
9
- self.cache = {};
10
-
11
- self.Manager = Manager;
12
- }
13
-
14
- Utilities.prototype.iterateCollection = function (callback, options) {
15
- const self = this;
16
- const Manager = self.Manager;
17
- const admin = Manager.libraries.admin;
18
-
19
- return new Promise(function(resolve, reject) {
20
- let batch = -1;
21
- let collectionCount = 0;
22
-
23
- // Set defaults
24
- options = options || {};
25
- options.collection = options.collection || '';
26
- options.batchSize = options.batchSize || 1000;
27
- options.where = options.where || [];
28
- options.orderBy = options.orderBy || null;
29
- options.startAt = options.startAt || null;
30
- options.startAfter = options.startAfter || null;
31
- options.prefetchCursor = typeof options.prefetchCursor === 'undefined'
32
- ? (!!options.startAt || !!options.startAfter) && !options.orderBy
33
- : options.prefetchCursor;
34
- options.log = options.log;
35
-
36
- // List all documents in a collection
37
- async function listAllDocuments(nextPageToken) {
38
- let query = admin.firestore().collection(options.collection);
39
-
40
- // Insert where clauses
41
- options.where
42
- .forEach(clause => {
43
- query = query.where(clause.field, clause.operator, clause.value);
44
- });
45
-
46
- // Insert orderBy
47
- if (options.orderBy) {
48
- query = query.orderBy(options.orderBy);
49
- }
50
-
51
- // Process the first batch differently
52
- if (batch === -1) {
53
- let prefetchedCursor = null;
54
-
55
- // Prefetch the cursor
56
- if (options.prefetchCursor) {
57
- prefetchedCursor = await admin.firestore().doc(`${options.collection}/${options.startAt || options.startAfter}`)
58
- .get()
59
- .catch(e => e);
60
-
61
- if (prefetchedCursor instanceof Error) {
62
- return reject(prefetchedCursor);
63
- }
64
- }
65
-
66
- // Insert startAt or startAfter
67
- if (options.startAt) {
68
- query = query.startAt(prefetchedCursor || options.startAt);
69
- } else if (options.startAfter) {
70
- query = query.startAfter(prefetchedCursor || options.startAfter);
71
- }
72
-
73
- // Calculate count
74
- const collectionCountResult = await query.count().get()
75
- .then((r) => r.data().count)
76
- .catch((e) => e);
77
-
78
- // Check for errors
79
- if (collectionCountResult instanceof Error) {
80
- return reject(collectionCountResult);
81
- }
82
-
83
- // Set collection count
84
- collectionCount = collectionCountResult;
85
-
86
- // Log
87
- if (options.log) {
88
- console.log('Total count:', collectionCount);
89
- }
90
- }
91
-
92
- // Start at next page
93
- if (nextPageToken) {
94
- query = query.startAfter(nextPageToken);
95
- }
96
-
97
- // batchSize
98
- query = query.limit(options.batchSize);
99
-
100
- // Get
101
- query.get()
102
- .then(async (snap) => {
103
- const lastVisible = snap.docs[snap.docs.length - 1];
104
-
105
- batch++;
106
-
107
- if (snap.docs.length === 0) {
108
- return resolve();
109
- }
110
-
111
- if (options.log) {
112
- console.log('Processing batch:', batch);
113
- }
114
-
115
- callback(
116
- {
117
- snap: snap,
118
- docs: snap.docs.map(x => x),
119
- },
120
- batch,
121
- collectionCount,
122
- )
123
- .then((r) => {
124
- // Construct a new query starting at this document
125
- if (lastVisible) {
126
- listAllDocuments(lastVisible)
127
- } else {
128
- return resolve();
129
- }
130
- })
131
- .catch((e) => {
132
- console.error('Callback failed', e);
133
- return reject(e);
134
- });
135
-
136
- })
137
- .catch((e) => {
138
- console.error('Query failed', e);
139
- return reject(e);
140
- });
141
- }
142
-
143
- // Run
144
- listAllDocuments();
145
- });
146
- };
147
-
148
- Utilities.prototype.iterateUsers = function (callback, options) {
149
- const self = this;
150
- const Manager = self.Manager;
151
- const admin = Manager.libraries.admin;
152
-
153
- return new Promise(function(resolve, reject) {
154
- let batch = -1;
155
-
156
- options = options || {};
157
- options.batchSize = options.batchSize || 1000;
158
- options.log = options.log;
159
- options.pageToken = options.pageToken;
160
-
161
- function listAllUsers(nextPageToken) {
162
- // List batch of users, 1000 at a time.
163
- admin.auth()
164
- .listUsers(options.batchSize, nextPageToken)
165
- .then(async (listUsersResult) => {
166
-
167
- batch++;
168
-
169
- if (listUsersResult.users.length === 0) {
170
- return resolve();
171
- }
172
-
173
- if (options.log) {
174
- console.log('Processing batch:', batch);
175
- }
176
-
177
- callback({
178
- snap: listUsersResult,
179
- users: listUsersResult.users,
180
- pageToken: listUsersResult.pageToken,
181
- }, batch)
182
- .then(r => {
183
- if (listUsersResult.pageToken) {
184
- listAllUsers(listUsersResult.pageToken);
185
- } else {
186
- return resolve();
187
- }
188
- })
189
- .catch((e) => {
190
- console.error('Callback failed', e);
191
- return reject(e)
192
- });
193
-
194
- })
195
- .catch((e) => {
196
- console.error('Query failed', e);
197
- return reject(e)
198
- });
199
- }
200
-
201
- listAllUsers(options.pageToken);
202
- });
203
- };
204
-
205
- Utilities.prototype.randomId = function (options) {
206
- const self = this;
207
-
208
- options = options || {};
209
- options.size = options.size || 14;
210
-
211
- if (!nanoId) {
212
- nanoId = require('nanoid');
213
-
214
- nanoId = nanoId.customAlphabet(
215
- nanoId.urlAlphabet.replace(/_|-/g, ''),
216
- options.size,
217
- )
218
- }
219
-
220
- return nanoId();
221
- };
222
-
223
- Utilities.prototype.get = function (docPath, options) {
224
- const self = this;
225
-
226
- return new Promise(function(resolve, reject) {
227
- const Manager = self.Manager;
228
- const { admin } = Manager.libraries;
229
-
230
- // Set defaults
231
- options = options || {};
232
- options.maxAge = options.maxAge || (1000 * 60 * 5); // 5 minutes
233
- options.readTime = typeof options.readTime === 'undefined' ? null : options.readTime;
234
- options.log = typeof options.log === 'undefined' ? false : options.log;
235
- options.format = typeof options.format === 'undefined' ? 'raw' : options.format;
236
-
237
- // Check cache
238
- const item = _.get(self.cache, docPath, null)
239
- const age = item ? Date.now() - item.time : null;
240
-
241
- // Format
242
- function _format(doc) {
243
- if (options.format === 'raw') {
244
- return doc;
245
- } else if (options.format === 'data') {
246
- return doc.data();
247
- }
248
- }
249
-
250
- // Log
251
- if (options.readTime) {
252
- const { Timestamp } = require('firebase-admin/firestore')
253
- const time = Math.round(new Date(options.readTime).getTime() / 1000 / 60);
254
- const timeLog = new Date(time * 1000 * 60);
255
-
256
- // Log
257
- if (options.log) {
258
- console.log('Read time:', timeLog);
259
- }
260
-
261
- // Loop docs
262
- admin.firestore().runTransaction(
263
- updateFunction => updateFunction.get(admin.firestore().doc(docPath)),
264
- {readOnly: true, readTime: new Timestamp(time * 60, 0)}
265
- )
266
- .then((snap) => resolve(_format(snap)))
267
- .catch((e) => reject(e));
268
- } else if (item && age && age < options.maxAge) {
269
- return resolve(_format(item.doc));
270
- } else {
271
- admin.firestore().doc(docPath)
272
- .get()
273
- .then(async (doc) => {
274
- const data = doc.data();
275
-
276
- // Set cache
277
- if (data) {
278
- _.set(self.cache, docPath, {
279
- doc: doc,
280
- time: Date.now(),
281
- })
282
- }
283
-
284
- // Return
285
- return resolve(_format(doc));
286
- })
287
- .catch((e) => reject(e));
288
- }
289
- });
290
- };
291
-
292
- module.exports = Utilities;