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.
- package/package.json +3 -3
- package/src/cli/cli.js +27 -11
- package/src/manager/helpers/assistant.js +51 -76
- package/src/manager/index.js +22 -1
- package/dist/cli/cli.js +0 -1534
- package/dist/manager/functions/core/actions/api/admin/backup.js +0 -338
- package/dist/manager/functions/core/actions/api/admin/create-post.js +0 -388
- package/dist/manager/functions/core/actions/api/admin/cron.js +0 -37
- package/dist/manager/functions/core/actions/api/admin/database-read.js +0 -35
- package/dist/manager/functions/core/actions/api/admin/database-write.js +0 -39
- package/dist/manager/functions/core/actions/api/admin/edit-post.js +0 -158
- package/dist/manager/functions/core/actions/api/admin/firestore-query.js +0 -165
- package/dist/manager/functions/core/actions/api/admin/firestore-read.js +0 -38
- package/dist/manager/functions/core/actions/api/admin/firestore-write.js +0 -54
- package/dist/manager/functions/core/actions/api/admin/get-stats.js +0 -269
- package/dist/manager/functions/core/actions/api/admin/payment-processor.js +0 -57
- package/dist/manager/functions/core/actions/api/admin/run-hook.js +0 -95
- package/dist/manager/functions/core/actions/api/admin/send-notification.js +0 -197
- package/dist/manager/functions/core/actions/api/admin/sync-users.js +0 -125
- package/dist/manager/functions/core/actions/api/admin/templates/post.html +0 -16
- package/dist/manager/functions/core/actions/api/firebase/get-providers.js +0 -102
- package/dist/manager/functions/core/actions/api/general/emails/general:download-app-link.js +0 -21
- package/dist/manager/functions/core/actions/api/general/fetch-post.js +0 -99
- package/dist/manager/functions/core/actions/api/general/generate-uuid.js +0 -41
- package/dist/manager/functions/core/actions/api/general/send-email.js +0 -112
- package/dist/manager/functions/core/actions/api/handler/create-post.js +0 -146
- package/dist/manager/functions/core/actions/api/special/setup-electron-manager-client.js +0 -103
- package/dist/manager/functions/core/actions/api/template.js +0 -33
- package/dist/manager/functions/core/actions/api/test/authenticate.js +0 -22
- package/dist/manager/functions/core/actions/api/test/create-test-accounts.js +0 -27
- package/dist/manager/functions/core/actions/api/test/lab.js +0 -55
- package/dist/manager/functions/core/actions/api/test/redirect.js +0 -26
- package/dist/manager/functions/core/actions/api/test/webhook.js +0 -30
- package/dist/manager/functions/core/actions/api/user/create-custom-token.js +0 -32
- package/dist/manager/functions/core/actions/api/user/delete.js +0 -68
- package/dist/manager/functions/core/actions/api/user/get-active-sessions.js +0 -45
- package/dist/manager/functions/core/actions/api/user/get-subscription-info.js +0 -49
- package/dist/manager/functions/core/actions/api/user/oauth2/discord.js +0 -114
- package/dist/manager/functions/core/actions/api/user/oauth2/google.js +0 -99
- package/dist/manager/functions/core/actions/api/user/oauth2.js +0 -476
- package/dist/manager/functions/core/actions/api/user/regenerate-api-keys.js +0 -54
- package/dist/manager/functions/core/actions/api/user/resolve.js +0 -32
- package/dist/manager/functions/core/actions/api/user/sign-out-all-sessions.js +0 -118
- package/dist/manager/functions/core/actions/api/user/sign-up copy.js +0 -544
- package/dist/manager/functions/core/actions/api/user/sign-up.js +0 -99
- package/dist/manager/functions/core/actions/api/user/submit-feedback.js +0 -96
- package/dist/manager/functions/core/actions/api/user/validate-settings.js +0 -86
- package/dist/manager/functions/core/actions/api.js +0 -354
- package/dist/manager/functions/core/actions/create-post-handler.js +0 -184
- package/dist/manager/functions/core/actions/generate-uuid.js +0 -62
- package/dist/manager/functions/core/actions/sign-up-handler.js +0 -205
- package/dist/manager/functions/core/admin/create-post.js +0 -206
- package/dist/manager/functions/core/admin/firestore-write.js +0 -72
- package/dist/manager/functions/core/admin/get-stats.js +0 -218
- package/dist/manager/functions/core/admin/query.js +0 -198
- package/dist/manager/functions/core/admin/send-notification.js +0 -206
- package/dist/manager/functions/core/cron/daily/ghostii-auto-publisher.js +0 -377
- package/dist/manager/functions/core/cron/daily/reset-usage.js +0 -197
- package/dist/manager/functions/core/cron/daily.js +0 -114
- package/dist/manager/functions/core/events/auth/before-create.js +0 -124
- package/dist/manager/functions/core/events/auth/before-signin.js +0 -62
- package/dist/manager/functions/core/events/auth/on-create copy.js +0 -121
- package/dist/manager/functions/core/events/auth/on-create.js +0 -564
- package/dist/manager/functions/core/events/auth/on-delete.js +0 -72
- package/dist/manager/functions/core/events/firestore/on-subscription.js +0 -107
- package/dist/manager/functions/test/authenticate.js +0 -38
- package/dist/manager/functions/test/create-test-accounts.js +0 -144
- package/dist/manager/functions/test/webhook.js +0 -37
- package/dist/manager/functions/wrappers/mailchimp/addToList.js +0 -25
- package/dist/manager/helpers/analytics copy.js +0 -217
- package/dist/manager/helpers/analytics.js +0 -467
- package/dist/manager/helpers/api-manager.js +0 -324
- package/dist/manager/helpers/assistant.js +0 -1043
- package/dist/manager/helpers/metadata.js +0 -32
- package/dist/manager/helpers/middleware.js +0 -154
- package/dist/manager/helpers/roles.js +0 -69
- package/dist/manager/helpers/settings.js +0 -158
- package/dist/manager/helpers/subscription-resolver-new.js +0 -828
- package/dist/manager/helpers/subscription-resolver.js +0 -842
- package/dist/manager/helpers/usage.js +0 -381
- package/dist/manager/helpers/user.js +0 -198
- package/dist/manager/helpers/utilities.js +0 -292
- package/dist/manager/index.js +0 -1076
- package/dist/manager/libraries/openai.js +0 -460
- package/dist/manager/routes/restart/index.js +0 -52
- package/dist/manager/routes/test/index.js +0 -43
- package/dist/manager/schemas/restart.js +0 -13
- package/dist/manager/schemas/test.js +0 -13
- package/dist/require.js +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backend-manager",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.174",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"homepage": "https://itwcreativeworks.com",
|
|
38
38
|
"preparePackage": {
|
|
39
|
-
"input": "./
|
|
40
|
-
"output": "./
|
|
39
|
+
"input": "./src_",
|
|
40
|
+
"output": "./dist_",
|
|
41
41
|
"replace": {}
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
package/src/cli/cli.js
CHANGED
|
@@ -269,13 +269,13 @@ Main.prototype.setup = async function () {
|
|
|
269
269
|
bem_giRegex = new RegExp(jetpack.read(path.resolve(`${__dirname}/../../templates/gitignore.md`)), 'm' )
|
|
270
270
|
|
|
271
271
|
// tests
|
|
272
|
-
self.
|
|
273
|
-
self.projectUrl = `https://console.firebase.google.com/project/${self.
|
|
272
|
+
self.projectId = self.firebaseRC.projects.default;
|
|
273
|
+
self.projectUrl = `https://console.firebase.google.com/project/${self.projectId}`;
|
|
274
274
|
|
|
275
275
|
self.bemApiURL = `https://us-central1-${self?.firebaseRC?.projects?.default}.cloudfunctions.net/bm_api?authenticationToken=${self?.runtimeConfigJSON?.backend_manager?.key}`;
|
|
276
276
|
|
|
277
277
|
// Log
|
|
278
|
-
log(`ID: `, chalk.bold(`${self.
|
|
278
|
+
log(`ID: `, chalk.bold(`${self.projectId}`));
|
|
279
279
|
log(`URL:`, chalk.bold(`${self.projectUrl}`));
|
|
280
280
|
|
|
281
281
|
if (!self.package || !self.package.engines || !self.package.engines.node) {
|
|
@@ -436,7 +436,7 @@ Main.prototype.setup = async function () {
|
|
|
436
436
|
|
|
437
437
|
await self.test('has correct ID in backend-manager-config.json', async function () {
|
|
438
438
|
// Check if the project name matches the projectId
|
|
439
|
-
if (self.
|
|
439
|
+
if (self.projectId !== self.bemConfigJSON?.firebaseConfig?.projectId) {
|
|
440
440
|
console.error(chalk.red('Mismatch between project name and firebaseConfig.projectId in backend-manager-config.json'));
|
|
441
441
|
return false;
|
|
442
442
|
}
|
|
@@ -445,9 +445,25 @@ Main.prototype.setup = async function () {
|
|
|
445
445
|
return true;
|
|
446
446
|
}, NOFIX);
|
|
447
447
|
|
|
448
|
-
await self.test('has service-account.json', function () {
|
|
449
|
-
let
|
|
450
|
-
|
|
448
|
+
await self.test('has correct service-account.json', function () {
|
|
449
|
+
let serviceAccount = jetpack.read(`${self.firebaseProjectPath}/functions/service-account.json`);
|
|
450
|
+
|
|
451
|
+
// Make sure the service account exists
|
|
452
|
+
if (!serviceAccount) {
|
|
453
|
+
console.error(chalk.red('Missing service-account.json'));
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// Parse the service account
|
|
458
|
+
serviceAccount = JSON5.parse(serviceAccount);
|
|
459
|
+
|
|
460
|
+
// Check if project_id matches the project's ID
|
|
461
|
+
if (self.projectId !== serviceAccount.project_id) {
|
|
462
|
+
console.error(chalk.red('Mismatch between project name and service account project_id'));
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return true;
|
|
451
467
|
}, fix_serviceAccount);
|
|
452
468
|
|
|
453
469
|
await self.test('has correct .gitignore', function () {
|
|
@@ -824,7 +840,7 @@ async function fix_isFirebase(self) {
|
|
|
824
840
|
function fix_projpackage(self) {
|
|
825
841
|
return new Promise(function(resolve, reject) {
|
|
826
842
|
self.projectPackage = self.projectPackage || {};
|
|
827
|
-
self.projectPackage.name = self.projectPackage.name || self.
|
|
843
|
+
self.projectPackage.name = self.projectPackage.name || self.projectId;
|
|
828
844
|
self.projectPackage.version = self.projectPackage.version || '0.0.1';
|
|
829
845
|
self.projectPackage.dependencies = self.projectPackage.dependencies || {};
|
|
830
846
|
self.projectPackage.devDependencies = self.projectPackage.devDependencies || {};
|
|
@@ -1413,7 +1429,7 @@ async function cmd_iamImportExport(self) {
|
|
|
1413
1429
|
--member serviceAccount:{projectId}@appspot.gserviceaccount.com \
|
|
1414
1430
|
--role roles/datastore.importExportAdmin
|
|
1415
1431
|
`
|
|
1416
|
-
.replace(/{projectId}/ig, self.
|
|
1432
|
+
.replace(/{projectId}/ig, self.projectId)
|
|
1417
1433
|
|
|
1418
1434
|
let cmd = exec(command, function (error, stdout, stderr) {
|
|
1419
1435
|
if (error) {
|
|
@@ -1431,10 +1447,10 @@ async function cmd_setStorageLifecycle(self) {
|
|
|
1431
1447
|
return new Promise(function(resolve, reject) {
|
|
1432
1448
|
const command = `gsutil lifecycle set {config} gs://{bucket}`
|
|
1433
1449
|
.replace(/{config}/ig, path.resolve(`${__dirname}/../../templates/storage-lifecycle-config-1-day.json`))
|
|
1434
|
-
.replace(/{bucket}/ig, `us.artifacts.${self.
|
|
1450
|
+
.replace(/{bucket}/ig, `us.artifacts.${self.projectId}.appspot.com`)
|
|
1435
1451
|
const command2 = `gsutil lifecycle set {config} gs://{bucket}`
|
|
1436
1452
|
.replace(/{config}/ig, path.resolve(`${__dirname}/../../templates/storage-lifecycle-config-30-days.json`))
|
|
1437
|
-
.replace(/{bucket}/ig, `bm-backup-firestore-${self.
|
|
1453
|
+
.replace(/{bucket}/ig, `bm-backup-firestore-${self.projectId}`)
|
|
1438
1454
|
|
|
1439
1455
|
exec(command, function (error, stdout, stderr) {
|
|
1440
1456
|
if (error) {
|
|
@@ -4,6 +4,17 @@ const _ = require('lodash');
|
|
|
4
4
|
const uuid = require('uuid');
|
|
5
5
|
let JSON5;
|
|
6
6
|
|
|
7
|
+
const LOG_LEVELS = {
|
|
8
|
+
error: 'error',
|
|
9
|
+
warn: 'warn',
|
|
10
|
+
info: 'info',
|
|
11
|
+
debug: 'debug',
|
|
12
|
+
log: 'log',
|
|
13
|
+
notice: 'NOTICE',
|
|
14
|
+
critical: 'CRITICAL',
|
|
15
|
+
emergency: 'EMERGENCY'
|
|
16
|
+
};
|
|
17
|
+
|
|
7
18
|
function BackendAssistant() {
|
|
8
19
|
const self = this;
|
|
9
20
|
|
|
@@ -12,7 +23,24 @@ function BackendAssistant() {
|
|
|
12
23
|
self.initialized = false;
|
|
13
24
|
|
|
14
25
|
// Add log methods
|
|
15
|
-
|
|
26
|
+
Object.keys(LOG_LEVELS)
|
|
27
|
+
.forEach((level) => {
|
|
28
|
+
// Skip log because it is already a method
|
|
29
|
+
// if (level === 'log') {
|
|
30
|
+
// return;
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
// Add log method
|
|
34
|
+
BackendAssistant.prototype[level] = function() {
|
|
35
|
+
const self = this;
|
|
36
|
+
const args = Array.prototype.slice.call(arguments);
|
|
37
|
+
|
|
38
|
+
// Prepend level to args
|
|
39
|
+
args.unshift(level);
|
|
40
|
+
// self.log.apply(this, args);
|
|
41
|
+
self._log.apply(this, args);
|
|
42
|
+
};
|
|
43
|
+
});
|
|
16
44
|
|
|
17
45
|
return self;
|
|
18
46
|
}
|
|
@@ -33,12 +61,14 @@ function tryParse(input) {
|
|
|
33
61
|
BackendAssistant.prototype.init = function (ref, options) {
|
|
34
62
|
const self = this;
|
|
35
63
|
|
|
64
|
+
// Set options
|
|
36
65
|
options = options || {};
|
|
37
66
|
options.accept = options.accept || 'json';
|
|
38
67
|
options.showOptionsLog = typeof options.showOptionsLog !== 'undefined' ? options.showOptionsLog : false;
|
|
39
68
|
options.optionsLogString = typeof options.optionsLogString !== 'undefined' ? options.optionsLogString : '\n\n\n\n\n';
|
|
40
69
|
options.fileSavePath = options.fileSavePath || process.env.npm_package_name || '';
|
|
41
70
|
|
|
71
|
+
// Set now
|
|
42
72
|
const now = new Date();
|
|
43
73
|
|
|
44
74
|
// Attached libraries - used in .errorify()
|
|
@@ -236,96 +266,41 @@ BackendAssistant.prototype.logProd = function () {
|
|
|
236
266
|
self._log.apply(self, args);
|
|
237
267
|
};
|
|
238
268
|
|
|
239
|
-
BackendAssistant.prototype.
|
|
269
|
+
BackendAssistant.prototype._log = function () {
|
|
240
270
|
const self = this;
|
|
271
|
+
const logs = [...arguments];
|
|
272
|
+
const prefix = self.logPrefix ? ` ${self.logPrefix}:` : ':';
|
|
241
273
|
|
|
242
|
-
|
|
274
|
+
// Prepend log prefix log string
|
|
275
|
+
logs.unshift(`[${self.tag} @ ${new Date().toISOString()}]${prefix}`);
|
|
243
276
|
|
|
244
|
-
|
|
245
|
-
|
|
277
|
+
// Get the log level
|
|
278
|
+
const level = logs[1];
|
|
246
279
|
|
|
247
|
-
|
|
248
|
-
|
|
280
|
+
// Pass along arguments to console.log
|
|
281
|
+
if (LOG_LEVELS[level]) {
|
|
282
|
+
logs.splice(1, 1);
|
|
249
283
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const args = Array.prototype.slice.call(arguments);
|
|
255
|
-
|
|
256
|
-
// Prepend level to args
|
|
257
|
-
args.unshift(level);
|
|
258
|
-
self.log.apply(this, args);
|
|
259
|
-
};
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
BackendAssistant.prototype._log = function () {
|
|
264
|
-
const self = this;
|
|
265
|
-
|
|
266
|
-
// 1. Convert args to a normal array
|
|
267
|
-
const logs = [...Array.prototype.slice.call(arguments)];
|
|
268
|
-
|
|
269
|
-
// Add log prefix
|
|
270
|
-
const prefix = self.logPrefix
|
|
271
|
-
? ` ${self.logPrefix}:`
|
|
272
|
-
: ':';
|
|
273
|
-
|
|
274
|
-
// 2. Prepend log prefix log string
|
|
275
|
-
logs.unshift(
|
|
276
|
-
`[${self.tag} @ ${new Date().toISOString()}]${prefix}`
|
|
277
|
-
);
|
|
278
|
-
|
|
279
|
-
// 3. Pass along arguments to console.log
|
|
280
|
-
if (logs[1] === 'error') {
|
|
281
|
-
logs.splice(1,1)
|
|
282
|
-
console.error.apply(console, logs);
|
|
283
|
-
} else if (logs[1] === 'warn') {
|
|
284
|
-
logs.splice(1,1)
|
|
285
|
-
console.warn.apply(console, logs);
|
|
286
|
-
} else if (logs[1] === 'info') {
|
|
287
|
-
logs.splice(1,1)
|
|
288
|
-
console.info.apply(console, logs);
|
|
289
|
-
} else if (logs[1] === 'debug') {
|
|
290
|
-
logs.splice(1,1)
|
|
291
|
-
console.debug.apply(console, logs);
|
|
292
|
-
} else if (logs[1] === 'notice') {
|
|
293
|
-
logs.splice(1,1)
|
|
294
|
-
if (self.isDevelopment()) {
|
|
295
|
-
console.log.apply(console, logs);
|
|
296
|
-
} else {
|
|
297
|
-
self.ref.functions.logger.write({
|
|
298
|
-
severity: 'NOTICE',
|
|
299
|
-
message: logs,
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
} else if (logs[1] === 'critical') {
|
|
303
|
-
logs.splice(1,1)
|
|
304
|
-
if (isDevelopment) {
|
|
284
|
+
// Determine how to log
|
|
285
|
+
if (level in console) {
|
|
286
|
+
console[level].apply(console, logs);
|
|
287
|
+
} else if (self.isDevelopment()) {
|
|
305
288
|
console.log.apply(console, logs);
|
|
306
289
|
} else {
|
|
307
290
|
self.ref.functions.logger.write({
|
|
308
|
-
severity:
|
|
291
|
+
severity: LOG_LEVELS[level].toUpperCase(),
|
|
309
292
|
message: logs,
|
|
310
293
|
});
|
|
311
294
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (
|
|
315
|
-
|
|
316
|
-
} else {
|
|
317
|
-
self.ref.functions.logger.write({
|
|
318
|
-
severity: 'EMERGENCY',
|
|
319
|
-
message: logs,
|
|
320
|
-
});
|
|
295
|
+
|
|
296
|
+
// Write with wonderful-log
|
|
297
|
+
if (self.Manager?.libraries?.logger?.[level]) {
|
|
298
|
+
self.Manager?.libraries?.logger?.[level](...logs)
|
|
321
299
|
}
|
|
322
|
-
} else if (logs[1] === 'log') {
|
|
323
|
-
logs.splice(1,1)
|
|
324
|
-
console.log.apply(console, logs);
|
|
325
300
|
} else {
|
|
326
301
|
console.log.apply(console, logs);
|
|
327
302
|
}
|
|
328
|
-
}
|
|
303
|
+
};
|
|
329
304
|
|
|
330
305
|
BackendAssistant.prototype.setLogPrefix = function (s) {
|
|
331
306
|
const self = this;
|
package/src/manager/index.js
CHANGED
|
@@ -70,6 +70,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
70
70
|
options.assistant = options.assistant || {};
|
|
71
71
|
options.cwd = typeof options.cwd === 'undefined' ? process.cwd() : options.cwd;
|
|
72
72
|
options.projectPackageDirectory = typeof options.projectPackageDirectory === 'undefined' ? undefined : options.projectPackageDirectory;
|
|
73
|
+
options.logSavePath = typeof options.logSavePath === 'undefined' ? false : options.logSavePath;
|
|
73
74
|
// options.assistant.optionsLogString = options.assistant.optionsLogString || undefined;
|
|
74
75
|
|
|
75
76
|
// Load libraries
|
|
@@ -87,6 +88,7 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
87
88
|
localDatabase: null,
|
|
88
89
|
User: null,
|
|
89
90
|
Analytics: null,
|
|
91
|
+
logger: null,
|
|
90
92
|
};
|
|
91
93
|
|
|
92
94
|
// Set properties
|
|
@@ -118,8 +120,27 @@ Manager.prototype.init = function (exporter, options) {
|
|
|
118
120
|
// Get app ID
|
|
119
121
|
const appId = self.config?.app?.id;
|
|
120
122
|
|
|
123
|
+
// Set log
|
|
124
|
+
if (options.logSavePath) {
|
|
125
|
+
self.libraries.logger = new (require('wonderful-log'))({
|
|
126
|
+
console: {
|
|
127
|
+
enabled: false,
|
|
128
|
+
},
|
|
129
|
+
file: {
|
|
130
|
+
enabled: true,
|
|
131
|
+
path: options.logSavePath,
|
|
132
|
+
},
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
121
136
|
// Init assistant
|
|
122
|
-
self.assistant = self.Assistant().init(
|
|
137
|
+
self.assistant = self.Assistant().init({
|
|
138
|
+
req: null,
|
|
139
|
+
res: null,
|
|
140
|
+
admin: self.libraries.admin,
|
|
141
|
+
functions: self.libraries.functions,
|
|
142
|
+
Manager: self,
|
|
143
|
+
}, options.assistant);
|
|
123
144
|
|
|
124
145
|
// Set more properties (need to wait for assistant to determine if DEV)
|
|
125
146
|
self.project.functionsUrl = self.assistant.isDevelopment()
|