backend-manager 4.2.2 → 4.2.4
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "backend-manager",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.4",
|
|
4
4
|
"description": "Quick tools for developing Firebase functions",
|
|
5
5
|
"main": "src/manager/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -74,7 +74,6 @@
|
|
|
74
74
|
"paypal-server-api": "^2.0.14",
|
|
75
75
|
"pushid": "^1.0.0",
|
|
76
76
|
"resolve-account": "^1.0.26",
|
|
77
|
-
"semver": "^7.6.3",
|
|
78
77
|
"shortid": "^2.2.16",
|
|
79
78
|
"sizeitup": "^1.0.9",
|
|
80
79
|
"uid-generator": "^2.0.0",
|
|
@@ -82,6 +81,7 @@
|
|
|
82
81
|
"uuid": "^9.0.1",
|
|
83
82
|
"wonderful-fetch": "^1.3.0",
|
|
84
83
|
"wonderful-log": "^1.0.7",
|
|
84
|
+
"wonderful-version": "^1.1.0",
|
|
85
85
|
"yaml": "^2.6.1",
|
|
86
86
|
"yargs": "^17.7.2"
|
|
87
87
|
},
|
package/src/cli/cli.js
CHANGED
|
@@ -11,7 +11,7 @@ const chalk = require('chalk');
|
|
|
11
11
|
const _ = require('lodash');
|
|
12
12
|
const log = console.log;
|
|
13
13
|
const Npm = require('npm-api');
|
|
14
|
-
const
|
|
14
|
+
const wonderfulVersion = require('wonderful-version');
|
|
15
15
|
const inquirer = require('inquirer');
|
|
16
16
|
const JSON5 = require('json5');
|
|
17
17
|
const fetch = require('wonderful-fetch');
|
|
@@ -256,94 +256,113 @@ Main.prototype.setup = async function () {
|
|
|
256
256
|
return exists;
|
|
257
257
|
}, fix_isFirebase);
|
|
258
258
|
|
|
259
|
+
// Test: Is the project using the correct version of Node.js
|
|
259
260
|
await self.test(`using at least Node.js v${self.packageJSON.engines.node}`, function () {
|
|
260
|
-
const
|
|
261
|
-
const
|
|
262
|
-
const
|
|
261
|
+
const engineReqVer = self.packageJSON.engines.node;
|
|
262
|
+
const engineHasVer = self.package.engines.node;
|
|
263
|
+
const processVer = process.versions.node;
|
|
263
264
|
|
|
264
|
-
if
|
|
265
|
-
|
|
265
|
+
// Check if the process version is less than the required version
|
|
266
|
+
if (wonderfulVersion.is(processVer, '<', engineReqVer)) {
|
|
267
|
+
return new Error(`Please use at least version ${engineReqVer} of Node.js with this project. You need to update your package.json and your .nvmrc file. Then, make sure to run ${chalk.bold(`nvm use ${engineReqVer}`)}`)
|
|
266
268
|
}
|
|
267
269
|
|
|
268
|
-
if
|
|
269
|
-
|
|
270
|
+
// Check if the engine version is less than the required version
|
|
271
|
+
if (!wonderfulVersion.is(engineHasVer, '===', engineReqVer)) {
|
|
272
|
+
console.log(chalk.yellow(`You are using Node.js version ${processVer} but this project suggests ${engineReqVer}.`));
|
|
270
273
|
}
|
|
271
274
|
|
|
272
|
-
|
|
275
|
+
// Return
|
|
276
|
+
return wonderfulVersion.is(engineHasVer, '>=', engineReqVer);
|
|
273
277
|
}, fix_nodeVersion);
|
|
274
278
|
|
|
279
|
+
// Test: Is the project using the correct version of Node.js
|
|
275
280
|
await self.test('.nvmrc file has proper version', async function () {
|
|
276
|
-
const
|
|
277
|
-
const
|
|
281
|
+
const engineReqVer = self.packageJSON.engines.node;
|
|
282
|
+
const nvmrcVer = jetpack.read(`${self.firebaseProjectPath}/functions/.nvmrc`);
|
|
278
283
|
|
|
279
|
-
//
|
|
280
|
-
return
|
|
284
|
+
// Check to ensure nvmrc is greater than or equal to the engine version
|
|
285
|
+
return wonderfulVersion.is(nvmrcVer, '>=', engineReqVer);
|
|
281
286
|
}, fix_nvmrc);
|
|
282
287
|
|
|
288
|
+
// Test: Does the project have a package.json
|
|
283
289
|
// await self.test('project level package.json exists', async function () {
|
|
284
290
|
// return !!(self.projectPackage && self.projectPackage.version && self.projectPackage.name);
|
|
285
291
|
// }, fix_projpackage);
|
|
286
292
|
|
|
293
|
+
// Test: Does the project have a package.json
|
|
287
294
|
await self.test('functions level package.json exists', async function () {
|
|
288
295
|
return !!self.package && !!self.package.dependencies && !!self.package.devDependencies && !!self.package.version;
|
|
289
296
|
}, fix_functionspackage);
|
|
290
297
|
|
|
298
|
+
// Test: Does the project have an updated package.json
|
|
291
299
|
// await self.test('functions level package.json has updated version', async function () {
|
|
292
300
|
// return self.package.version === self.projectPackage.version;
|
|
293
301
|
// }, fix_packageversion);
|
|
294
302
|
|
|
303
|
+
// Test: Is the project using the correct version of firebase-admin
|
|
295
304
|
await self.test('using updated firebase-admin', async function () {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
305
|
+
const pkg = 'firebase-admin';
|
|
306
|
+
const latest = self.packageJSON.dependencies['firebase-admin'];
|
|
307
|
+
const mine = self.package.dependencies[pkg];
|
|
308
|
+
const bemv = self.packageJSON.dependencies[pkg];
|
|
309
|
+
|
|
310
|
+
// Get level difference
|
|
311
|
+
const levelDifference = wonderfulVersion.levelDifference(latest, mine);
|
|
312
|
+
|
|
313
|
+
// Log
|
|
302
314
|
bemPackageVersionWarning(pkg, bemv, latest);
|
|
303
315
|
|
|
304
|
-
if
|
|
316
|
+
// Log if major version mismatch
|
|
317
|
+
if (levelDifference === 'major') {
|
|
305
318
|
console.log(chalk.red(`Version ${chalk.bold(latest)} of ${chalk.bold(pkg)} available but you must install this manually because it is a major update.`));
|
|
306
319
|
}
|
|
307
320
|
|
|
308
|
-
|
|
321
|
+
// Ensure the version is up to date
|
|
322
|
+
return wonderfulVersion.is(mine, '>=', latest) || levelDifference === 'major';
|
|
309
323
|
}, fix_fba);
|
|
310
324
|
|
|
325
|
+
// Test: Is the project using the correct version of firebase-functions
|
|
311
326
|
await self.test('using updated firebase-functions', async function () {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
327
|
+
const pkg = 'firebase-functions';
|
|
328
|
+
const latest = self.packageJSON.dependencies['firebase-functions'];
|
|
329
|
+
const mine = self.package.dependencies[pkg];
|
|
330
|
+
const bemv = self.packageJSON.dependencies[pkg];
|
|
331
|
+
|
|
332
|
+
// Get level difference
|
|
333
|
+
const levelDifference = wonderfulVersion.levelDifference(latest, mine);
|
|
334
|
+
|
|
335
|
+
// Log
|
|
318
336
|
bemPackageVersionWarning(pkg, bemv, latest);
|
|
319
337
|
|
|
320
|
-
if
|
|
338
|
+
// Log if major version mismatch
|
|
339
|
+
if (levelDifference === 'major') {
|
|
321
340
|
console.log(chalk.red(`Version ${chalk.bold(latest)} of ${chalk.bold(pkg)} available but you must install this manually because it is a major update.`));
|
|
322
341
|
}
|
|
323
342
|
|
|
324
|
-
|
|
343
|
+
// Ensure the version is up to date
|
|
344
|
+
return wonderfulVersion.is(mine, '>=', latest) || levelDifference === 'major';
|
|
325
345
|
}, fix_fbf);
|
|
326
346
|
|
|
347
|
+
// Test: Is the project using the correct version of backend-manager
|
|
327
348
|
await self.test('using updated backend-manager', async function () {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
349
|
+
const pkg = 'backend-manager';
|
|
350
|
+
const latest = await getPkgVersion(pkg);
|
|
351
|
+
const mine = self.package.dependencies[pkg];
|
|
352
|
+
|
|
353
|
+
// Get level difference
|
|
354
|
+
const levelDifference = wonderfulVersion.levelDifference(latest, mine);
|
|
332
355
|
|
|
333
|
-
if
|
|
356
|
+
// Log if major version mismatch
|
|
357
|
+
if (!isLocal(mine) && levelDifference === 'major') {
|
|
334
358
|
console.log(chalk.red(`Version ${chalk.bold(latest)} of ${chalk.bold(pkg)} available but you must install this manually because it is a major update.`));
|
|
335
359
|
}
|
|
336
360
|
|
|
337
|
-
|
|
361
|
+
// Ensure the version is up to date
|
|
362
|
+
return isLocal(mine) || wonderfulVersion.is(mine, '>=', latest) || levelDifference === 'major';
|
|
338
363
|
}, fix_bem);
|
|
339
364
|
|
|
340
|
-
//
|
|
341
|
-
// let pkg = 'ultimate-jekyll-poster';
|
|
342
|
-
// let latest = semver.clean(await getPkgVersion(pkg));
|
|
343
|
-
// let mine = (self.package.dependencies[pkg] || '0.0.0').replace('^', '').replace('~', '');
|
|
344
|
-
// return isLocal(mine) || !(semver.gt(latest, mine));
|
|
345
|
-
// }, fix_ujp);
|
|
346
|
-
|
|
365
|
+
// Test: Is the project using the correct version of @firebase/testing
|
|
347
366
|
// await self.test('using updated @firebase/testing', async function () {
|
|
348
367
|
// let pkg = '@firebase/testing';
|
|
349
368
|
// let latest = semver.clean(await getPkgVersion(pkg));
|
|
@@ -351,20 +370,25 @@ Main.prototype.setup = async function () {
|
|
|
351
370
|
// return isLocal(mine) || !(semver.gt(latest, mine));
|
|
352
371
|
// }, fix_fbTesting);
|
|
353
372
|
|
|
373
|
+
// Test: Is the project using the correct version of mocha
|
|
354
374
|
// await self.test('using updated mocha', async function () {
|
|
355
375
|
// let pkg = 'mocha';
|
|
356
376
|
// let latest = semver.clean(await getPkgVersion(pkg));
|
|
357
377
|
// let mine = (self.package.devDependencies[pkg] || '0.0.0').replace('^', '').replace('~', '');
|
|
358
378
|
// return isLocal(mine) || !(semver.gt(latest, mine));
|
|
359
379
|
// }, fix_mocha);
|
|
380
|
+
|
|
381
|
+
// Test: Does the project have a "npm start" script
|
|
360
382
|
await self.test(`has "npm start" script`, function () {
|
|
361
383
|
return self.package.scripts.start
|
|
362
384
|
}, fix_startScript);
|
|
363
385
|
|
|
386
|
+
// Test: Does the project have a "npm dist" script
|
|
364
387
|
await self.test(`has "npm dist" script`, function () {
|
|
365
388
|
return self.package.scripts.dist
|
|
366
389
|
}, fix_distScript);
|
|
367
390
|
|
|
391
|
+
// Test: Is the project using a proper .runtimeconfig
|
|
368
392
|
await self.test('using proper .runtimeconfig', async function () {
|
|
369
393
|
// Set pass
|
|
370
394
|
let pass = true;
|
|
@@ -383,6 +407,7 @@ Main.prototype.setup = async function () {
|
|
|
383
407
|
return pass;
|
|
384
408
|
}, fix_runtimeConfig);
|
|
385
409
|
|
|
410
|
+
// Test: Is the project using a proper backend-manager-config.json
|
|
386
411
|
await self.test('using proper backend-manager-config.json', async function () {
|
|
387
412
|
// Set pass
|
|
388
413
|
let pass = true;
|
|
@@ -401,6 +426,7 @@ Main.prototype.setup = async function () {
|
|
|
401
426
|
return pass;
|
|
402
427
|
}, fix_bemConfig);
|
|
403
428
|
|
|
429
|
+
// Test: Does the project have the correct ID in backend-manager-config.json
|
|
404
430
|
await self.test('has correct ID in backend-manager-config.json', async function () {
|
|
405
431
|
// Check if the project name matches the projectId
|
|
406
432
|
if (self.projectId !== self.bemConfigJSON?.firebaseConfig?.projectId) {
|
|
@@ -412,6 +438,7 @@ Main.prototype.setup = async function () {
|
|
|
412
438
|
return true;
|
|
413
439
|
}, NOFIX);
|
|
414
440
|
|
|
441
|
+
// Test: Does the project have the correct ID in service-account.json
|
|
415
442
|
await self.test('has correct service-account.json', function () {
|
|
416
443
|
let serviceAccount = jetpack.read(`${self.firebaseProjectPath}/functions/service-account.json`);
|
|
417
444
|
|
|
@@ -433,6 +460,7 @@ Main.prototype.setup = async function () {
|
|
|
433
460
|
return true;
|
|
434
461
|
}, fix_serviceAccount);
|
|
435
462
|
|
|
463
|
+
// Test: Does the project have the correct .gitignore
|
|
436
464
|
await self.test('has correct .gitignore', function () {
|
|
437
465
|
let match = self.gitignore.match(bem_giRegexOuter);
|
|
438
466
|
if (!match) {
|
|
@@ -445,27 +473,32 @@ Main.prototype.setup = async function () {
|
|
|
445
473
|
}
|
|
446
474
|
}, fix_gitignore);
|
|
447
475
|
|
|
448
|
-
//
|
|
476
|
+
// Test: Does the project have the correct firestore rules
|
|
449
477
|
await self.test('firestore rules in JSON', () => {
|
|
450
478
|
return self.firebaseJSON?.firestore?.rules === 'firestore.rules'
|
|
451
479
|
}, fix_firestoreRules);
|
|
452
480
|
|
|
481
|
+
// Test: Does the project have the correct firestore indexes
|
|
453
482
|
await self.test('firestore indexes in JSON', () => {
|
|
454
483
|
return self.firebaseJSON?.firestore?.indexes === 'firestore.indexes.json';
|
|
455
484
|
}, fix_firestoreIndexes);
|
|
456
485
|
|
|
486
|
+
// Test: Does the project have the correct realtime rules
|
|
457
487
|
await self.test('realtime rules in JSON', () => {
|
|
458
488
|
return self.firebaseJSON?.database?.rules === 'database.rules.json';
|
|
459
489
|
}, fix_realtimeRules);
|
|
460
490
|
|
|
491
|
+
// Test: Does the project have the correct storage rules
|
|
461
492
|
await self.test('storage rules in JSON', () => {
|
|
462
493
|
return self.firebaseJSON?.storage?.rules === 'storage.rules';
|
|
463
494
|
}, fix_storageRules);
|
|
464
495
|
|
|
496
|
+
// Test: Does the project have the correct remoteconfig template
|
|
465
497
|
await self.test('remoteconfig template in JSON', () => {
|
|
466
498
|
return self.firebaseJSON?.remoteconfig?.template === 'remoteconfig.template.json';
|
|
467
499
|
}, fix_remoteconfigTemplate);
|
|
468
500
|
|
|
501
|
+
// Test: Does the project have the indexes synced
|
|
469
502
|
await self.test('firestore indexes synced', async function () {
|
|
470
503
|
const tempPath = '_firestore.indexes.json'
|
|
471
504
|
const liveIndexes = await cmd_indexesGet(self, tempPath, false);
|
|
@@ -489,17 +522,19 @@ Main.prototype.setup = async function () {
|
|
|
489
522
|
return !localIndexes_exists || equal
|
|
490
523
|
}, fix_indexesSync);
|
|
491
524
|
|
|
525
|
+
// Test: Does the project have the correct importExportAdmin
|
|
492
526
|
// await self.test('add roles/datastore.importExportAdmin', async function () {
|
|
493
527
|
// const result = await cmd_iamImportExport(self).catch(e => e);
|
|
494
528
|
// return !(result instanceof Error);
|
|
495
529
|
// }, NOFIX);
|
|
496
530
|
|
|
531
|
+
// Test: Does the project have the correct storage lifecycle policy
|
|
497
532
|
await self.test('set storage lifecycle policy', async function () {
|
|
498
533
|
const result = await cmd_setStorageLifecycle(self).catch(e => e);
|
|
499
534
|
return !(result instanceof Error);
|
|
500
535
|
}, fix_setStoragePolicy);
|
|
501
536
|
|
|
502
|
-
//
|
|
537
|
+
// Test: Does the project have the correct firestore rules file
|
|
503
538
|
await self.test('update firestore rules file', function () {
|
|
504
539
|
const exists = jetpack.exists(`${self.firebaseProjectPath}/firestore.rules`);
|
|
505
540
|
const contents = jetpack.read(`${self.firebaseProjectPath}/firestore.rules`) || '';
|
|
@@ -509,11 +544,13 @@ Main.prototype.setup = async function () {
|
|
|
509
544
|
return (exists && !!containsCore && !!matchesVersion);
|
|
510
545
|
}, fix_firestoreRulesFile);
|
|
511
546
|
|
|
547
|
+
// Test: Does the project have the correct firestore indexes file
|
|
512
548
|
await self.test('update firestore indexes file', function () {
|
|
513
549
|
const exists = jetpack.exists(`${self.firebaseProjectPath}/firestore.indexes.json`);
|
|
514
550
|
return exists;
|
|
515
551
|
}, fix_firestoreIndexesFile);
|
|
516
552
|
|
|
553
|
+
// Test: Does the project have the correct realtime rules file
|
|
517
554
|
await self.test('update realtime rules file', function () {
|
|
518
555
|
const exists = jetpack.exists(`${self.firebaseProjectPath}/database.rules.json`);
|
|
519
556
|
const contents = jetpack.read(`${self.firebaseProjectPath}/database.rules.json`) || '';
|
|
@@ -523,27 +560,30 @@ Main.prototype.setup = async function () {
|
|
|
523
560
|
return (exists && !!containsCore && !!matchesVersion);
|
|
524
561
|
}, fix_realtimeRulesFile);
|
|
525
562
|
|
|
563
|
+
// Test: Does the project have the correct storage rules file
|
|
526
564
|
await self.test('update storage rules file', function () {
|
|
527
565
|
const exists = jetpack.exists(`${self.firebaseProjectPath}/storage.rules`);
|
|
528
566
|
return exists;
|
|
529
567
|
}, fix_storageRulesFile);
|
|
530
568
|
|
|
569
|
+
// Test: Does the project have the correct remoteconfig template file
|
|
531
570
|
await self.test('update remoteconfig template file', function () {
|
|
532
571
|
const exists = jetpack.exists(`${self.firebaseProjectPath}/functions/remoteconfig.template.json`);
|
|
533
572
|
return exists;
|
|
534
573
|
}, fix_remoteconfigTemplateFile);
|
|
535
574
|
|
|
536
|
-
//
|
|
575
|
+
// Test: Does the project have the correct hosting folder
|
|
537
576
|
await self.test('hosting is set to dedicated folder in JSON', function () {
|
|
538
577
|
const hosting = _.get(self.firebaseJSON, 'hosting', {});
|
|
539
578
|
return (hosting.public && (hosting.public === 'public' || hosting.public !== '.'))
|
|
540
579
|
}, fix_firebaseHostingFolder);
|
|
541
580
|
|
|
542
|
-
//
|
|
581
|
+
// Test: Does the project have the correct hosting auth page
|
|
543
582
|
// await self.test('hosting has auth page', async function () {
|
|
544
583
|
// return await fix_firebaseHostingAuth(self);
|
|
545
584
|
// }, NOFIX);
|
|
546
585
|
|
|
586
|
+
// Test: Does the project have the correct backend-manager-tests.js file
|
|
547
587
|
await self.test('update backend-manager-tests.js', function () {
|
|
548
588
|
jetpack.write(`${self.firebaseProjectPath}/test/backend-manager-tests.js`,
|
|
549
589
|
(jetpack.read(path.resolve(`${__dirname}/../../templates/backend-manager-tests.js`)))
|
|
@@ -551,6 +591,7 @@ Main.prototype.setup = async function () {
|
|
|
551
591
|
return true;
|
|
552
592
|
}, NOFIX);
|
|
553
593
|
|
|
594
|
+
// Test: Does the project have the correct public .html files
|
|
554
595
|
await self.test('create public .html files', function () {
|
|
555
596
|
const options = {url: self.bemConfigJSON.brand.url}
|
|
556
597
|
// index.html
|
|
@@ -583,15 +624,14 @@ Main.prototype.setup = async function () {
|
|
|
583
624
|
// return script === NPM_CLEAN_SCRIPT;
|
|
584
625
|
// }, fix_cleanNpmScript);
|
|
585
626
|
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
627
|
+
// Log if using local backend-manager
|
|
589
628
|
if (self.package.dependencies['backend-manager'].includes('file:')) {
|
|
590
629
|
console.log('\n' + chalk.yellow(chalk.bold('Warning: ') + 'You are using the local ' + chalk.bold('backend-manager')));
|
|
591
630
|
} else {
|
|
592
631
|
console.log('\n');
|
|
593
632
|
}
|
|
594
633
|
|
|
634
|
+
// Fetch stats
|
|
595
635
|
const statsFetchResult = await fetch(self.bemApiURL, {
|
|
596
636
|
method: 'post',
|
|
597
637
|
timeout: 30000,
|
|
@@ -603,6 +643,7 @@ Main.prototype.setup = async function () {
|
|
|
603
643
|
.then(json => json)
|
|
604
644
|
.catch(e => e);
|
|
605
645
|
|
|
646
|
+
// Check if we ran into an error
|
|
606
647
|
if (statsFetchResult instanceof Error) {
|
|
607
648
|
if (!statsFetchResult.message.includes('network timeout')) {
|
|
608
649
|
console.log(chalk.yellow(`Ran into error while fetching stats endpoint`, statsFetchResult));
|
|
@@ -612,6 +653,7 @@ Main.prototype.setup = async function () {
|
|
|
612
653
|
console.log(chalk.green(`Stats fetched/created properly.`));
|
|
613
654
|
}
|
|
614
655
|
|
|
656
|
+
// Log
|
|
615
657
|
console.log(chalk.green(`Checks finished. Passed ${self.testCount}/${self.testTotal} tests.`));
|
|
616
658
|
if (self.testCount !== self.testTotal) {
|
|
617
659
|
console.log(chalk.yellow(`You should continue to run ${chalk.bold('npx bm setup')} until you pass all tests and fix all errors.`));
|
|
@@ -675,10 +717,6 @@ Main.prototype.test = async function(name, fn, fix, args) {
|
|
|
675
717
|
});
|
|
676
718
|
}
|
|
677
719
|
|
|
678
|
-
function cleanPackageVersion(v) {
|
|
679
|
-
return v.replace('^', '').replace('~', '');
|
|
680
|
-
}
|
|
681
|
-
|
|
682
720
|
// FIXES
|
|
683
721
|
function NOFIX() {
|
|
684
722
|
return new Promise(function(resolve, reject) {
|
|
@@ -688,7 +726,7 @@ function NOFIX() {
|
|
|
688
726
|
}
|
|
689
727
|
|
|
690
728
|
function bemPackageVersionWarning(package, current, latest) {
|
|
691
|
-
if (
|
|
729
|
+
if (wonderfulVersion.greaterThan(latest, current)) {
|
|
692
730
|
log(chalk.yellow(`${package} needs to be updated in backend-manager: ${current} => ${latest}`));
|
|
693
731
|
}
|
|
694
732
|
}
|
|
@@ -97,26 +97,6 @@ Module.prototype.updateStats = function (existingData, update) {
|
|
|
97
97
|
// Log
|
|
98
98
|
self.assistant.log(`updateStats(): Starting...`);
|
|
99
99
|
|
|
100
|
-
// Fix user stats
|
|
101
|
-
if (
|
|
102
|
-
!existingData?.users?.total
|
|
103
|
-
|| update === true
|
|
104
|
-
|| update?.users
|
|
105
|
-
) {
|
|
106
|
-
await self.getAllUsers()
|
|
107
|
-
.then(r => {
|
|
108
|
-
_.set(newData, 'users.total', r.length)
|
|
109
|
-
})
|
|
110
|
-
.catch(e => {
|
|
111
|
-
error = new Error(`Failed fixing stats: ${e}`);
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// Reject if error
|
|
116
|
-
if (error) {
|
|
117
|
-
return reject(error);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
100
|
// Fetch new notification stats
|
|
121
101
|
if (
|
|
122
102
|
update === true || update?.notifications
|
|
@@ -143,6 +123,21 @@ Module.prototype.updateStats = function (existingData, update) {
|
|
|
143
123
|
})
|
|
144
124
|
}
|
|
145
125
|
|
|
126
|
+
// Fix user stats
|
|
127
|
+
if (
|
|
128
|
+
!existingData?.users?.total
|
|
129
|
+
|| update === true
|
|
130
|
+
|| update?.users
|
|
131
|
+
) {
|
|
132
|
+
await self.getAllUsers()
|
|
133
|
+
.then(r => {
|
|
134
|
+
_.set(newData, 'users.total', r.length)
|
|
135
|
+
})
|
|
136
|
+
.catch(e => {
|
|
137
|
+
error = new Error(`Failed fixing stats: ${e}`);
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
|
|
146
141
|
// Reject if error
|
|
147
142
|
if (error) {
|
|
148
143
|
return reject(error);
|
|
@@ -157,7 +152,7 @@ Module.prototype.updateStats = function (existingData, update) {
|
|
|
157
152
|
const existing = newData?.users?.online || 0;
|
|
158
153
|
|
|
159
154
|
// Set new value
|
|
160
|
-
_.set(newData, 'users.online', existing + keys.length)
|
|
155
|
+
_.set(newData, 'users.online', existing + keys.length);
|
|
161
156
|
})
|
|
162
157
|
.catch(e => {
|
|
163
158
|
error = new Error(`Failed getting online users: ${e}`);
|
|
@@ -243,7 +238,7 @@ Module.prototype.getAllNotifications = function () {
|
|
|
243
238
|
self.assistant.log(`getAllNotifications(): Completed with ${count} notifications`);
|
|
244
239
|
|
|
245
240
|
// Return
|
|
246
|
-
return count;
|
|
241
|
+
return resolve(count);
|
|
247
242
|
})
|
|
248
243
|
.catch((e) => {
|
|
249
244
|
return reject(e)
|
|
@@ -4,31 +4,41 @@ function Module() {
|
|
|
4
4
|
|
|
5
5
|
Module.prototype.init = function (Manager, payload) {
|
|
6
6
|
const self = this;
|
|
7
|
+
|
|
8
|
+
// Shortcuts
|
|
7
9
|
self.Manager = Manager;
|
|
8
10
|
self.libraries = Manager.libraries;
|
|
9
11
|
self.assistant = Manager.Assistant();
|
|
10
12
|
self.change = payload.change
|
|
11
13
|
self.context = payload.context
|
|
12
14
|
|
|
15
|
+
// Return
|
|
13
16
|
return self;
|
|
14
17
|
};
|
|
15
18
|
|
|
16
19
|
Module.prototype.main = function () {
|
|
17
20
|
const self = this;
|
|
18
|
-
|
|
21
|
+
|
|
22
|
+
// Shortcuts
|
|
23
|
+
const Manager = self.Manager;
|
|
19
24
|
const assistant = self.assistant;
|
|
25
|
+
const libraries = self.libraries;
|
|
20
26
|
const change = self.change;
|
|
21
27
|
const context = self.context;
|
|
22
28
|
|
|
23
29
|
return new Promise(async function(resolve, reject) {
|
|
24
|
-
|
|
30
|
+
// Libraries
|
|
31
|
+
const _ = Manager.require('lodash');
|
|
25
32
|
|
|
33
|
+
// Shortcuts
|
|
26
34
|
const dataBefore = change.before.data();
|
|
27
35
|
const dataAfter = change.after.data();
|
|
28
36
|
|
|
37
|
+
// Variables
|
|
29
38
|
let analytics;
|
|
30
39
|
let eventType;
|
|
31
40
|
|
|
41
|
+
// Determine event type
|
|
32
42
|
if (dataAfter == undefined) {
|
|
33
43
|
eventType = 'delete';
|
|
34
44
|
} else if (dataBefore && dataAfter) {
|
|
@@ -37,6 +47,7 @@ Module.prototype.main = function () {
|
|
|
37
47
|
eventType = 'create';
|
|
38
48
|
}
|
|
39
49
|
|
|
50
|
+
// Log
|
|
40
51
|
assistant.log('Notification subscription write:', {
|
|
41
52
|
after: dataAfter,
|
|
42
53
|
before: dataBefore,
|
|
@@ -52,7 +63,7 @@ Module.prototype.main = function () {
|
|
|
52
63
|
'notifications.total': libraries.admin.firestore.FieldValue.increment(-1),
|
|
53
64
|
})
|
|
54
65
|
.then(r => {
|
|
55
|
-
analytics =
|
|
66
|
+
analytics = Manager.Analytics({
|
|
56
67
|
assistant: assistant,
|
|
57
68
|
uuid: dataBefore?.owner?.uid,
|
|
58
69
|
})
|
|
@@ -81,7 +92,7 @@ Module.prototype.main = function () {
|
|
|
81
92
|
'notifications.total': libraries.admin.firestore.FieldValue.increment(1),
|
|
82
93
|
})
|
|
83
94
|
.then(r => {
|
|
84
|
-
analytics =
|
|
95
|
+
analytics = Manager.Analytics({
|
|
85
96
|
assistant: assistant,
|
|
86
97
|
uuid: dataAfter?.owner?.uid,
|
|
87
98
|
})
|