not-node 5.0.9 → 5.0.10
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 +1 -1
- package/src/auth/rules.js +13 -15
- package/src/core/locales/en.json +2 -0
- package/src/core/locales/ru.json +2 -0
- package/src/model/increment.js +16 -3
- package/src/fields/.old.js +0 -193
- package/src/init/layers/fields.js +0 -7
- package/src/init/layers/forms.js +0 -0
- package/src/init/layers/models.js +0 -0
- package/src/init/layers/routes.js +0 -0
package/package.json
CHANGED
package/src/auth/rules.js
CHANGED
|
@@ -6,11 +6,11 @@ function ruleHasRootDirective(rule){
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
function compareWithRoot(rule,
|
|
9
|
+
function compareWithRoot(rule, root){
|
|
10
10
|
if (Object.prototype.hasOwnProperty.call(rule, 'admin')) {
|
|
11
|
-
return rule.admin &&
|
|
11
|
+
return rule.admin && root;
|
|
12
12
|
} else {
|
|
13
|
-
return rule.root &&
|
|
13
|
+
return rule.root && root;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -51,18 +51,16 @@ function compareAuthStatus(rule, auth){
|
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Check rule against presented credentials
|
|
54
|
-
* @param {object}
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
* @param
|
|
61
|
-
* @
|
|
62
|
-
* @param {Boolean} admin user state of admin
|
|
63
|
-
* @return {boolean} pass or not
|
|
54
|
+
* @param {object} rule action rule
|
|
55
|
+
* @param {boolean} rule.auth if user should be authenticated
|
|
56
|
+
* @param {Array<String>} rule.role if user shoud have some role
|
|
57
|
+
* @param {boolean} rule.root if user should be super user
|
|
58
|
+
* @param {Boolean} auth user state of auth
|
|
59
|
+
* @param {String|Array} role user state of role
|
|
60
|
+
* @param {Boolean} root user state of root
|
|
61
|
+
* @return {boolean} pass or not
|
|
64
62
|
*/
|
|
65
|
-
function checkCredentials(rule, auth, role,
|
|
63
|
+
function checkCredentials(rule, auth, role, root) {
|
|
66
64
|
//no rule - no access
|
|
67
65
|
if (typeof rule === 'undefined' || rule === null) {
|
|
68
66
|
return false;
|
|
@@ -72,7 +70,7 @@ function checkCredentials(rule, auth, role, admin) {
|
|
|
72
70
|
//start comparing from top tier flags
|
|
73
71
|
//if we have root/admin(obsolete) field field in rule compare only it
|
|
74
72
|
if (ruleHasRootDirective(rule)) {
|
|
75
|
-
return compareWithRoot(rule,
|
|
73
|
+
return compareWithRoot(rule, root);
|
|
76
74
|
} else {
|
|
77
75
|
//if we have roles in rule, then using role based aproach
|
|
78
76
|
if (Object.prototype.hasOwnProperty.call(rule, 'role')) {
|
package/src/core/locales/en.json
CHANGED
package/src/core/locales/ru.json
CHANGED
package/src/model/increment.js
CHANGED
|
@@ -62,6 +62,19 @@ function secureUpdate(thisModel, which, cmd, opts){
|
|
|
62
62
|
|
|
63
63
|
module.exports.secureUpdate = secureUpdate;
|
|
64
64
|
|
|
65
|
+
function updateResponseSuccess(res){
|
|
66
|
+
if(res){
|
|
67
|
+
const responseList = Object.keys(res);
|
|
68
|
+
if(responseList.includes('ok')){
|
|
69
|
+
return (res.ok === 1 && res.n === 1);
|
|
70
|
+
}else{
|
|
71
|
+
return (res.matchedCount === 1 && res.modifiedCount === 1);
|
|
72
|
+
}
|
|
73
|
+
}else{
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
65
78
|
/**
|
|
66
79
|
* Generate new ID for current model and filterFields
|
|
67
80
|
**/
|
|
@@ -99,8 +112,8 @@ function newGetNext() {
|
|
|
99
112
|
new: true,
|
|
100
113
|
upsert: true
|
|
101
114
|
};
|
|
102
|
-
|
|
103
|
-
if(res
|
|
115
|
+
const res = await secureUpdate(thisModel, which, cmd, opts);
|
|
116
|
+
if(updateResponseSuccess(res)){
|
|
104
117
|
const doc = await thisModel.findOne({id});
|
|
105
118
|
return doc.seq;
|
|
106
119
|
}else{
|
|
@@ -133,7 +146,7 @@ function newRebase(){
|
|
|
133
146
|
};
|
|
134
147
|
//updating
|
|
135
148
|
let res = await secureUpdate(thisModel, which, cmd, opts);
|
|
136
|
-
if(res
|
|
149
|
+
if(updateResponseSuccess(res)){
|
|
137
150
|
return ID;
|
|
138
151
|
}else{
|
|
139
152
|
throw new Error('ID generator rebase failed');
|
package/src/fields/.old.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
const clone = require('rfdc')();
|
|
2
|
-
const fs = require('fs');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const {objHas, tryFile} = require('../common');
|
|
5
|
-
|
|
6
|
-
const DEFAULT_FIELD_REGISTRATION_RULES = {
|
|
7
|
-
overwrite: false,
|
|
8
|
-
compose: true
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const FIELDS = {};
|
|
12
|
-
|
|
13
|
-
module.exports.importFromDir = (srcDir, {overwrite = false, compose = true} = DEFAULT_FIELD_REGISTRATION_RULES)=>{
|
|
14
|
-
fs.readdirSync(srcDir).forEach((file) => {
|
|
15
|
-
let fromPath = path.join(srcDir, file);
|
|
16
|
-
if (!tryFile(fromPath)) { return; }
|
|
17
|
-
const parts = path.parse(fromPath);
|
|
18
|
-
registerField(parts.name, require(fromPath), {overwrite, compose});
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const registerField = module.exports.registerField = (name, value, {overwrite = false, compose = true} = DEFAULT_FIELD_REGISTRATION_RULES)=>{
|
|
24
|
-
if(objHas(FIELDS, name)){
|
|
25
|
-
if(overwrite){
|
|
26
|
-
FIELDS[name] = value;
|
|
27
|
-
}else if(compose){
|
|
28
|
-
Object.assign(FIELDS[name], value);
|
|
29
|
-
}
|
|
30
|
-
}else{
|
|
31
|
-
FIELDS[name] = value;
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
module.exports.registerFields = (fields, {overwrite = false, compose = true})=>{
|
|
37
|
-
for(let t in fields){
|
|
38
|
-
module.exports.registerField(t, fields[t], {overwrite, compose});
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
list = [
|
|
44
|
-
'title', //for standart only name
|
|
45
|
-
['titleNonStandart', {component: 'UITextforBlind'}] //arrays of [name, mutation]
|
|
46
|
-
['someID', {}, 'ID'], //copy of standart ID field under name as someID
|
|
47
|
-
]
|
|
48
|
-
*/
|
|
49
|
-
module.exports.initFields = (list, type = 'ui') => {
|
|
50
|
-
let fields = {};
|
|
51
|
-
list.forEach((field) => {
|
|
52
|
-
let res = module.exports.initField(field, false, type);
|
|
53
|
-
fields[res[0]] = res[1];
|
|
54
|
-
});
|
|
55
|
-
return fields;
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Retrieves field information
|
|
61
|
-
* there are few signatures of this function
|
|
62
|
-
* (field:string, resultOnly:boolean = true, type:string = 'ui')=> Object | [string, Object]
|
|
63
|
-
* (field:Array<string, Object>, resultOnly:boolean = true, type:string = 'ui')=> Object | [string, Object]
|
|
64
|
-
* @param {(string|Array)} field field to retrieve from store and init
|
|
65
|
-
field: string - just name of the field
|
|
66
|
-
field: Array - [destinationField:string, mutation: Object, sourceField:string]
|
|
67
|
-
field: Array - [sourceField:string, mutation: Object]
|
|
68
|
-
sourceField - standart field to extend
|
|
69
|
-
mutation - to extend by
|
|
70
|
-
destinationField - name of resulting field,
|
|
71
|
-
if no dest then src will be used
|
|
72
|
-
* @param {boolean} resultOnly return only result, if false then returns [name, value]
|
|
73
|
-
* @param {string} type type of field information
|
|
74
|
-
**/
|
|
75
|
-
module.exports.initField = (field, resultOnly = true, type = 'ui') => {
|
|
76
|
-
let srcName, destName, mutation = {};
|
|
77
|
-
if (Array.isArray(field)) {
|
|
78
|
-
destName = srcName = field[0];
|
|
79
|
-
mutation = field[1];
|
|
80
|
-
if (field.length === 3) {
|
|
81
|
-
srcName = field[2];
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
destName = srcName = field;
|
|
85
|
-
}
|
|
86
|
-
let proto = findFieldDescription(srcName, type);
|
|
87
|
-
let result = Object.assign({}, clone(proto), mutation);
|
|
88
|
-
if (resultOnly) {
|
|
89
|
-
return result;
|
|
90
|
-
} else {
|
|
91
|
-
return [destName, result];
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
function findFieldDescription(name, type){
|
|
96
|
-
return (objHas(FIELDS, name) && objHas(FIELDS[name], type)) ? FIELDS[name][type]:{};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Returns mutation tuple for a field or false
|
|
103
|
-
* @param {string} name field name
|
|
104
|
-
* @param {Array} list fields description lists
|
|
105
|
-
* @return {boolean|item}
|
|
106
|
-
*/
|
|
107
|
-
function getMutationForField(name, list) {
|
|
108
|
-
for(let item of list){
|
|
109
|
-
if (Array.isArray(item) && item[0] === name) {
|
|
110
|
-
return item;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return false;
|
|
114
|
-
}
|
|
115
|
-
module.exports.getMutationForField = getMutationForField;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Takes in mongoose model schema, scans for fields names and creates list of
|
|
119
|
-
* field's names to initialize from LIB, if in supplied rawMutationsList, exists
|
|
120
|
-
* mutation for a field in list, field name in list will be replaced by a
|
|
121
|
-
* mutation description
|
|
122
|
-
* @param {Object} schema mongoose model schema
|
|
123
|
-
* @param {Array} rawMutationsList list of mutations [src, mutation]/[dst,mutation,src]
|
|
124
|
-
* @returns {Object} initialized ui descriptions of fields for schema
|
|
125
|
-
**/
|
|
126
|
-
module.exports.fromSchema = (schema, rawMutationsList = []) => {
|
|
127
|
-
let
|
|
128
|
-
//shallow copy of array
|
|
129
|
-
mutationsList = [...rawMutationsList],
|
|
130
|
-
list = [];
|
|
131
|
-
if (schema && Object.keys(schema).length > 0) {
|
|
132
|
-
let rawKeys = Object.keys(schema);
|
|
133
|
-
rawKeys.forEach((key) => {
|
|
134
|
-
let mutation = getMutationForField(key, mutationsList);
|
|
135
|
-
if (mutation) {
|
|
136
|
-
list.push(mutation);
|
|
137
|
-
mutationsList.splice(mutationsList.indexOf(mutation), 1);
|
|
138
|
-
} else {
|
|
139
|
-
list.push(key);
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
list.push(...mutationsList);
|
|
143
|
-
return module.exports.initFields(list);
|
|
144
|
-
}else{
|
|
145
|
-
return {};
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
module.exports.LIB = FIELDS;
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
module.exports.initFieldsFromApp = (list, type = 'ui', app) => {
|
|
153
|
-
let fields = {};
|
|
154
|
-
list.forEach((field) => {
|
|
155
|
-
let res = module.exports.initFieldFromApp(field, false, type, app);
|
|
156
|
-
fields[res[0]] = res[1];
|
|
157
|
-
});
|
|
158
|
-
return fields;
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
module.exports.initFieldFromApp = (field, resultOnly = true, type = 'ui', app) => {
|
|
163
|
-
let srcName, destName, mutation = {};
|
|
164
|
-
if (Array.isArray(field)) {
|
|
165
|
-
destName = srcName = field[0];
|
|
166
|
-
mutation = field[1];
|
|
167
|
-
if (field.length === 3) {
|
|
168
|
-
srcName = field[2];
|
|
169
|
-
}
|
|
170
|
-
} else {
|
|
171
|
-
destName = srcName = field;
|
|
172
|
-
}
|
|
173
|
-
let proto = findFieldDescriptionFromApp(srcName, type, app);
|
|
174
|
-
if(proto){
|
|
175
|
-
let result = Object.assign({}, clone(proto), mutation);
|
|
176
|
-
if (resultOnly) {
|
|
177
|
-
return result;
|
|
178
|
-
} else {
|
|
179
|
-
return [destName, result];
|
|
180
|
-
}
|
|
181
|
-
}else{
|
|
182
|
-
throw new Error(`Field (${srcName}) definition is not found`);
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
function findFieldDescriptionFromApp(name, type, app){
|
|
187
|
-
const field = app.getField(name);
|
|
188
|
-
if(field && objHas(field, type)){
|
|
189
|
-
return field[type];
|
|
190
|
-
}else{
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
}
|
package/src/init/layers/forms.js
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|