backend-manager 2.2.4 → 2.3.0
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
package/src/cli/cli.js
CHANGED
|
@@ -43,9 +43,9 @@ const fetch = require('node-fetch');
|
|
|
43
43
|
|
|
44
44
|
let bem_giRegex = 'Set in .setup()'
|
|
45
45
|
let bem_giRegexOuter = /# BEM>>>(.*\n?)# <<<BEM/sg;
|
|
46
|
-
let
|
|
47
|
-
let
|
|
48
|
-
let
|
|
46
|
+
let bem_allRulesRegex = /(\/\/\/---backend-manager---\/\/\/)(.*?)(\/\/\/---------end---------\/\/\/)/sgm;
|
|
47
|
+
let bem_allRulesDefaultRegex = /(\/\/\/---default-rules---\/\/\/)(.*?)(\/\/\/---------end---------\/\/\/)/sgm;
|
|
48
|
+
let bem_allRulesBackupRegex = /({{\s*?backend-manager\s*?}})/sgm;
|
|
49
49
|
let MOCHA_PKG_SCRIPT = 'mocha ../test/ --recursive --timeout=10000';
|
|
50
50
|
let NPM_CLEAN_SCRIPT = 'rm -fr node_modules && rm -fr package-lock.json && npm cache clean --force && npm install && npm rb';
|
|
51
51
|
let NOFIX_TEXT = chalk.red(`There is no automatic fix for this check.`);
|
|
@@ -139,7 +139,7 @@ Main.prototype.process = async function (args) {
|
|
|
139
139
|
|
|
140
140
|
if (self.options['rules:default'] || self.options['rules:getdefault']) {
|
|
141
141
|
self.getRulesFile();
|
|
142
|
-
console.log(self.default.firestoreRulesWhole.match(
|
|
142
|
+
console.log(self.default.firestoreRulesWhole.match(bem_allRulesDefaultRegex)[0].replace(' ///', '///'));
|
|
143
143
|
return;
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -205,9 +205,11 @@ module.exports = Main;
|
|
|
205
205
|
|
|
206
206
|
Main.prototype.getRulesFile = function () {
|
|
207
207
|
const self = this;
|
|
208
|
-
self.default.firestoreRulesWhole = (jetpack.read(path.resolve(`${__dirname}/../../templates/firestore.rules`))).replace('=0.0.0-',
|
|
209
|
-
self.default.firestoreRulesCore = self.default.firestoreRulesWhole.match(
|
|
208
|
+
self.default.firestoreRulesWhole = (jetpack.read(path.resolve(`${__dirname}/../../templates/firestore.rules`))).replace('=0.0.0-', `=${self.default.version}-`);
|
|
209
|
+
self.default.firestoreRulesCore = self.default.firestoreRulesWhole.match(bem_allRulesRegex)[0];
|
|
210
210
|
|
|
211
|
+
self.default.databaseRulesWhole = (jetpack.read(path.resolve(`${__dirname}/../../templates/database.rules.json`))).replace('=0.0.0-', `=${self.default.version}-`);
|
|
212
|
+
self.default.databaseRulesCore = self.default.databaseRulesWhole.match(bem_allRulesRegex)[0];
|
|
211
213
|
};
|
|
212
214
|
|
|
213
215
|
Main.prototype.setup = async function () {
|
|
@@ -243,7 +245,7 @@ Main.prototype.setup = async function () {
|
|
|
243
245
|
|
|
244
246
|
self.getRulesFile();
|
|
245
247
|
|
|
246
|
-
self.default.
|
|
248
|
+
self.default.rulesVersionRegex = new RegExp(`///---version-${self.default.version}---///`)
|
|
247
249
|
// bem_giRegex = new RegExp(jetpack.read(path.resolve(`${__dirname}/../../templates/gitignore.md`)).replace(/\./g, '\\.'), 'm' )
|
|
248
250
|
bem_giRegex = new RegExp(jetpack.read(path.resolve(`${__dirname}/../../templates/gitignore.md`)), 'm' )
|
|
249
251
|
|
|
@@ -478,22 +480,26 @@ Main.prototype.setup = async function () {
|
|
|
478
480
|
|
|
479
481
|
// Update actual files
|
|
480
482
|
await self.test('update firestore rules file', function () {
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
483
|
+
const exists = jetpack.exists(`${self.firebaseProjectPath}/firestore.rules`);
|
|
484
|
+
const contents = jetpack.read(`${self.firebaseProjectPath}/firestore.rules`) || '';
|
|
485
|
+
const containsCore = contents.match(bem_allRulesRegex);
|
|
486
|
+
const matchesVersion = contents.match(self.default.rulesVersionRegex);
|
|
485
487
|
|
|
486
488
|
return (!!exists && !!containsCore && !!matchesVersion);
|
|
487
489
|
}, fix_firestoreRulesFile);
|
|
488
490
|
|
|
489
491
|
await self.test('update firestore indexes file', function () {
|
|
490
|
-
|
|
492
|
+
const exists = jetpack.exists(`${self.firebaseProjectPath}/firestore.indexes.json`);
|
|
491
493
|
return (!!exists);
|
|
492
494
|
}, fix_firestoreIndexesFile);
|
|
493
495
|
|
|
494
496
|
await self.test('update realtime rules file', function () {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
+
const exists = jetpack.exists(`${self.firebaseProjectPath}/database.rules.json`);
|
|
498
|
+
const contents = jetpack.read(`${self.firebaseProjectPath}/database.rules.json`) || '';
|
|
499
|
+
const containsCore = contents.match(bem_allRulesRegex);
|
|
500
|
+
const matchesVersion = contents.match(self.default.rulesVersionRegex);
|
|
501
|
+
|
|
502
|
+
return (!!exists && !!containsCore && !!matchesVersion);
|
|
497
503
|
}, fix_realtimeRulesFile);
|
|
498
504
|
|
|
499
505
|
await self.test('update storage rules file', function () {
|
|
@@ -874,61 +880,94 @@ function fix_remoteconfigTemplate(self) {
|
|
|
874
880
|
|
|
875
881
|
function fix_firestoreRulesFile(self) {
|
|
876
882
|
return new Promise(function(resolve, reject) {
|
|
877
|
-
|
|
883
|
+
const name = 'firestore.rules'
|
|
884
|
+
let path = `${self.firebaseProjectPath}/${name}`;
|
|
878
885
|
let exists = jetpack.exists(path);
|
|
879
886
|
let contents = jetpack.read(path) || '';
|
|
880
887
|
|
|
881
888
|
if (!exists || !contents) {
|
|
882
|
-
log(chalk.yellow(`Writing new
|
|
889
|
+
log(chalk.yellow(`Writing new ${name} file...`));
|
|
883
890
|
jetpack.write(path, self.default.firestoreRulesWhole)
|
|
884
891
|
contents = jetpack.read(path) || '';
|
|
885
892
|
}
|
|
886
893
|
|
|
887
|
-
let hasTemplate = contents.match(
|
|
894
|
+
let hasTemplate = contents.match(bem_allRulesRegex) || contents.match(bem_allRulesBackupRegex);
|
|
888
895
|
|
|
889
896
|
if (!hasTemplate) {
|
|
890
|
-
log(chalk.red(`Could not find rules template. Please edit
|
|
897
|
+
log(chalk.red(`Could not find rules template. Please edit ${name} file and add`), chalk.red(`{{backend-manager}}`), chalk.red(`to it.`));
|
|
891
898
|
reject()
|
|
892
899
|
}
|
|
893
900
|
|
|
894
|
-
let matchesVersion = contents.match(self.default.
|
|
901
|
+
let matchesVersion = contents.match(self.default.rulesVersionRegex);
|
|
895
902
|
if (!matchesVersion) {
|
|
896
903
|
// console.log('replace wih', self.default.firestoreRulesCore);
|
|
897
|
-
contents = contents.replace(
|
|
898
|
-
contents = contents.replace(
|
|
904
|
+
contents = contents.replace(bem_allRulesBackupRegex, self.default.firestoreRulesCore)
|
|
905
|
+
contents = contents.replace(bem_allRulesRegex, self.default.firestoreRulesCore)
|
|
899
906
|
jetpack.write(path, contents)
|
|
900
|
-
log(chalk.yellow(`Writing core rules to
|
|
907
|
+
log(chalk.yellow(`Writing core rules to ${name} file...`));
|
|
901
908
|
}
|
|
902
909
|
resolve();
|
|
903
910
|
});
|
|
904
911
|
};
|
|
905
912
|
|
|
906
|
-
function
|
|
907
|
-
return new Promise(
|
|
908
|
-
const name = '
|
|
909
|
-
let
|
|
910
|
-
let exists = jetpack.exists(
|
|
913
|
+
function fix_realtimeRulesFile(self) {
|
|
914
|
+
return new Promise(function(resolve, reject) {
|
|
915
|
+
const name = 'database.rules.json'
|
|
916
|
+
let path = `${self.firebaseProjectPath}/${name}`;
|
|
917
|
+
let exists = jetpack.exists(path);
|
|
918
|
+
let contents = jetpack.read(path) || '';
|
|
911
919
|
|
|
912
|
-
if (!exists) {
|
|
920
|
+
if (!exists || !contents) {
|
|
913
921
|
log(chalk.yellow(`Writing new ${name} file...`));
|
|
914
|
-
|
|
922
|
+
jetpack.write(path, self.default.databaseRulesWhole)
|
|
923
|
+
contents = jetpack.read(path) || '';
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
let hasTemplate = contents.match(bem_allRulesRegex) || contents.match(bem_allRulesBackupRegex);
|
|
927
|
+
|
|
928
|
+
if (!hasTemplate) {
|
|
929
|
+
log(chalk.red(`Could not find rules template. Please edit ${name} file and add`), chalk.red(`{{backend-manager}}`), chalk.red(`to it.`));
|
|
930
|
+
reject()
|
|
915
931
|
}
|
|
916
932
|
|
|
933
|
+
let matchesVersion = contents.match(self.default.rulesVersionRegex);
|
|
934
|
+
if (!matchesVersion) {
|
|
935
|
+
// console.log('replace wih', self.default.databaseRulesCore);
|
|
936
|
+
contents = contents.replace(bem_allRulesBackupRegex, self.default.databaseRulesCore)
|
|
937
|
+
contents = contents.replace(bem_allRulesRegex, self.default.databaseRulesCore)
|
|
938
|
+
jetpack.write(path, contents)
|
|
939
|
+
log(chalk.yellow(`Writing core rules to ${name} file...`));
|
|
940
|
+
}
|
|
917
941
|
resolve();
|
|
918
942
|
});
|
|
919
943
|
};
|
|
920
944
|
|
|
921
|
-
function fix_realtimeRulesFile(self) {
|
|
922
|
-
|
|
923
|
-
|
|
945
|
+
// function fix_realtimeRulesFile(self) {
|
|
946
|
+
// return new Promise(function(resolve, reject) {
|
|
947
|
+
// const name = 'database.rules.json';
|
|
948
|
+
// let filePath = `${self.firebaseProjectPath}/${name}`;
|
|
949
|
+
// let exists = jetpack.exists(filePath);
|
|
950
|
+
// let contents = jetpack.read(filePath) || '';
|
|
951
|
+
//
|
|
952
|
+
// if (!exists) {
|
|
953
|
+
// log(chalk.yellow(`Writing new ${name} file...`));
|
|
954
|
+
// jetpack.write(filePath, jetpack.read(path.resolve(`${__dirname}/../../templates/${name}`)))
|
|
955
|
+
// contents = jetpack.read(filePath) || '';
|
|
956
|
+
// }
|
|
957
|
+
//
|
|
958
|
+
// resolve();
|
|
959
|
+
// });
|
|
960
|
+
// };
|
|
961
|
+
|
|
962
|
+
function fix_firestoreIndexesFile(self) {
|
|
963
|
+
return new Promise(async function(resolve, reject) {
|
|
964
|
+
const name = 'firestore.indexes.json';
|
|
924
965
|
let filePath = `${self.firebaseProjectPath}/${name}`;
|
|
925
966
|
let exists = jetpack.exists(filePath);
|
|
926
|
-
let contents = jetpack.read(filePath) || '';
|
|
927
967
|
|
|
928
968
|
if (!exists) {
|
|
929
969
|
log(chalk.yellow(`Writing new ${name} file...`));
|
|
930
|
-
|
|
931
|
-
contents = jetpack.read(filePath) || '';
|
|
970
|
+
await cmd_indexesGet(self, name, false);
|
|
932
971
|
}
|
|
933
972
|
|
|
934
973
|
resolve();
|
|
@@ -29,7 +29,7 @@ Module.prototype.main = function () {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const postUrl =
|
|
32
|
+
const postUrl = `${Manager.config.brand.url}/blog/${payload.data.payload.url}`;
|
|
33
33
|
|
|
34
34
|
if (payload.data.payload.invoiceEmail && payload.data.payload.invoicePrice) {
|
|
35
35
|
// Create invoice
|
|
@@ -1,31 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"rules": {
|
|
3
|
+
///---backend-manager---///
|
|
4
|
+
///---version=0.0.0---///
|
|
5
|
+
|
|
6
|
+
// Gathering rules
|
|
3
7
|
"gatherings": {
|
|
4
8
|
".read": false,
|
|
5
9
|
".write": false,
|
|
6
|
-
"
|
|
7
|
-
".read": "
|
|
10
|
+
"$room": {
|
|
11
|
+
".read": "
|
|
12
|
+
(auth.uid != null && query.equalTo == auth.uid)
|
|
13
|
+
",
|
|
8
14
|
".write": false,
|
|
9
15
|
".indexOn": ["uid"],
|
|
10
|
-
"$
|
|
16
|
+
"$id": {
|
|
11
17
|
".read": "
|
|
12
|
-
// Allowed if user is
|
|
18
|
+
// Allowed if user is authenticated AND is the owner of the doc
|
|
13
19
|
(auth != null && auth.uid == data.child('uid').val())
|
|
20
|
+
// Allowed if uid is equal to the doc id [LEGACY FOR SOMIIBO]
|
|
21
|
+
|| (auth != null && auth.uid == $id)
|
|
22
|
+
// Allowed if user is not authenticated AND is the doc has no owner
|
|
23
|
+
|| (auth == null && (data.child('uid').val() == ''))
|
|
14
24
|
",
|
|
15
25
|
".write": "
|
|
16
26
|
// Allowed if the user is signed in AND is the owner of the existing doc
|
|
17
27
|
(auth != null && auth.uid == data.child('uid').val())
|
|
18
28
|
// Allowed if the user is signed in AND is the owner of the new doc
|
|
19
29
|
|| (auth != null && auth.uid == newData.child('uid').val())
|
|
20
|
-
|
|
21
|
-
|| (
|
|
22
|
-
|
|
30
|
+
// Allowed if the user is signed in AND is the owner of the existing doc
|
|
31
|
+
|| (auth != null && auth.uid == data.child('uid').val())
|
|
32
|
+
// Allowed if uid is equal to the doc id [LEGACY FOR SOMIIBO]
|
|
33
|
+
|| (auth != null && auth.uid == $id)
|
|
34
|
+
// Allowed if the existing doc has no owner
|
|
23
35
|
|| (data.child('uid').val() == '')
|
|
24
36
|
// Allowed if the new doc has no owner
|
|
25
37
|
|| (newData.child('uid').val() == '')
|
|
38
|
+
// Allowed if it's a delete
|
|
39
|
+
|| (!newData.exists())
|
|
26
40
|
",
|
|
27
41
|
}
|
|
28
42
|
}
|
|
29
|
-
}
|
|
43
|
+
},
|
|
44
|
+
///---------end---------///
|
|
30
45
|
}
|
|
31
46
|
}
|