very-express 0.3.2 → 0.3.3
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/dist/cli.js +9 -9
- package/dist/generators/role.generator.js +1 -0
- package/dist/preprocess/roleSetupFile.d.ts +3 -0
- package/dist/preprocess/roleSetupFile.js +32 -6
- package/dist/templates/jsonSchema/User.json +16 -10
- package/dist/types/types.d.ts +4 -1
- package/dist/utils/generator.js +2 -0
- package/package.json +1 -1
- package/vex.config.json +8 -5
package/dist/cli.js
CHANGED
|
@@ -33,15 +33,15 @@ config.app = config.app || {},
|
|
|
33
33
|
config.app.useUserSchema = config.app.useUserSchema || true,
|
|
34
34
|
config.app.useObjectID = config.app.useObjectID || true,
|
|
35
35
|
config.app.allowApiCreateUpdate_id = config.app.allowApiCreateUpdate_id || false,
|
|
36
|
-
config.useRBAC = config.useRBAC || {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
config.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
config.useRBAC = config.useRBAC || { roles: [], default: "", schemaIncluded: [] };
|
|
37
|
+
config.useRBAC.roles = config.useRBAC.roles || ["user"];
|
|
38
|
+
config.useRBAC.default = config.useRBAC.default || "user";
|
|
39
|
+
config.useRBAC.schemaIncluded = config.useRBAC.schemaIncluded || ["user"];
|
|
40
|
+
config.useOauth = config.useOauth || {};
|
|
41
|
+
config.useOauth.google = config.useOauth.google || false;
|
|
42
|
+
config.useOauth.facebook = config.useOauth.facebook || false;
|
|
43
|
+
config.useOauth.github = config.useOauth.github || false;
|
|
44
|
+
config.useOauth.microsoft = config.useOauth.microsoft || false;
|
|
45
45
|
if (config.app.useObjectID && config.app.allowApiCreateUpdate_id) {
|
|
46
46
|
logger_1.default.warn("Not recommended to use \"useObjectID\" with \"allowApiCreateUpdate_id\",\nthis may cause some logic issues");
|
|
47
47
|
}
|
|
@@ -34,6 +34,7 @@ const utils_1 = require("../utils");
|
|
|
34
34
|
const roleSetupFile_1 = require("../preprocess/roleSetupFile");
|
|
35
35
|
function compile(options) {
|
|
36
36
|
var _a;
|
|
37
|
+
(0, roleSetupFile_1.roleSchemaFormat)({ compilerOptions: options.compilerOptions });
|
|
37
38
|
(0, roleSetupFile_1.roleSetupFile)({
|
|
38
39
|
collectionList: options.collectionList,
|
|
39
40
|
roleSetupDir: options.roleSourceDir,
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.roleSetupFile = void 0;
|
|
6
|
+
exports.roleSchemaFormat = exports.roleSetupFile = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
8
|
const utils_1 = require("../utils");
|
|
9
9
|
const logger_1 = __importDefault(require("../utils/logger"));
|
|
@@ -11,18 +11,44 @@ function roleSetupFile(options) {
|
|
|
11
11
|
var _a;
|
|
12
12
|
const actionArray = ["create", "search", "read", "update", "delete"];
|
|
13
13
|
(_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.roles.forEach((role) => {
|
|
14
|
-
logger_1.default.process(`
|
|
14
|
+
logger_1.default.process(`Role Setting File : ${role}`);
|
|
15
15
|
const roleFilePath = `${options.roleSetupDir}/${role}.json`;
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const content = {};
|
|
17
|
+
if (fs_1.default.existsSync(roleFilePath)) {
|
|
18
|
+
Object.assign(content, (0, utils_1.loadJson)(roleFilePath));
|
|
18
19
|
}
|
|
19
|
-
const content = (0, utils_1.loadJson)(roleFilePath);
|
|
20
20
|
options.collectionList.forEach(collectionName => {
|
|
21
21
|
if (!content[collectionName]) {
|
|
22
22
|
content[collectionName] = actionArray;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
(0, utils_1.writeFile)(`
|
|
25
|
+
(0, utils_1.writeFile)(`Role Setting File : ${roleFilePath}`, roleFilePath, JSON.stringify(content, null, 4));
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
exports.roleSetupFile = roleSetupFile;
|
|
29
|
+
function roleSchemaFormat(options) {
|
|
30
|
+
var _a;
|
|
31
|
+
(_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.schemaIncluded.forEach((file) => {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
logger_1.default.process(`Schema Role Format : ${file}.json`);
|
|
34
|
+
const roleSchemaPath = `${options.compilerOptions.jsonSchemaDir}/${file}.json`;
|
|
35
|
+
const schema = (0, utils_1.loadJson)(roleSchemaPath);
|
|
36
|
+
for (const key in schema.properties) {
|
|
37
|
+
const prop = schema.properties[key];
|
|
38
|
+
if (prop["x-vexData"] === "role") {
|
|
39
|
+
prop.type = "array";
|
|
40
|
+
prop.required = true;
|
|
41
|
+
if (!prop.items) {
|
|
42
|
+
prop.items = { type: "" };
|
|
43
|
+
}
|
|
44
|
+
prop.items.type = "string";
|
|
45
|
+
prop.items.required = true;
|
|
46
|
+
prop.items.default = (_a = options.compilerOptions.useRBAC) === null || _a === void 0 ? void 0 : _a.default;
|
|
47
|
+
prop.items.enum = (_b = options.compilerOptions.useRBAC) === null || _b === void 0 ? void 0 : _b.roles;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
(0, utils_1.writeFile)("Schema Role Format", roleSchemaPath, JSON.stringify(schema, null, 4));
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
exports.roleSchemaFormat = roleSchemaFormat;
|
|
@@ -15,12 +15,6 @@
|
|
|
15
15
|
"type": "string",
|
|
16
16
|
"index": true
|
|
17
17
|
},
|
|
18
|
-
"role":{
|
|
19
|
-
"type": "string",
|
|
20
|
-
"enum": ["user"],
|
|
21
|
-
"default": "user",
|
|
22
|
-
"required": true
|
|
23
|
-
},
|
|
24
18
|
"authProvider": {
|
|
25
19
|
"type": "string"
|
|
26
20
|
},
|
|
@@ -39,14 +33,26 @@
|
|
|
39
33
|
"maxLength": 64,
|
|
40
34
|
"required": true
|
|
41
35
|
},
|
|
36
|
+
"active": {
|
|
37
|
+
"type": "boolean",
|
|
38
|
+
"default": true,
|
|
39
|
+
"required": true
|
|
40
|
+
},
|
|
42
41
|
"locale": {
|
|
43
42
|
"type": "string",
|
|
44
43
|
"maxLength": 8
|
|
45
44
|
},
|
|
46
|
-
"
|
|
47
|
-
"type": "
|
|
48
|
-
"
|
|
49
|
-
"
|
|
45
|
+
"roles":{
|
|
46
|
+
"type": "array",
|
|
47
|
+
"x-vexData": "role",
|
|
48
|
+
"items": {
|
|
49
|
+
"type": "string",
|
|
50
|
+
"default": "user",
|
|
51
|
+
"required": true,
|
|
52
|
+
"enum": [
|
|
53
|
+
"user"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
58
|
}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface compilerOptions {
|
|
|
14
14
|
};
|
|
15
15
|
useRBAC?: {
|
|
16
16
|
roles: string[];
|
|
17
|
+
default: string;
|
|
18
|
+
schemaIncluded: string[];
|
|
17
19
|
};
|
|
18
20
|
useOauth?: {
|
|
19
21
|
google?: boolean;
|
|
@@ -48,11 +50,12 @@ export interface jsonSchemaPropsItem {
|
|
|
48
50
|
required?: boolean | string[];
|
|
49
51
|
index?: boolean;
|
|
50
52
|
example?: any;
|
|
51
|
-
"x-format"?: string;
|
|
52
53
|
minLength?: number;
|
|
53
54
|
maxLength?: number;
|
|
54
55
|
minimum?: number;
|
|
55
56
|
maximum?: number;
|
|
57
|
+
"x-format"?: string;
|
|
58
|
+
"x-vexData"?: string;
|
|
56
59
|
[key: string]: string | boolean | number | string[] | jsonSchemaPropsItem | {
|
|
57
60
|
[key: string]: jsonSchemaPropsItem;
|
|
58
61
|
} | any[] | undefined;
|
package/dist/utils/generator.js
CHANGED
package/package.json
CHANGED
package/vex.config.json
CHANGED
|
@@ -5,10 +5,6 @@
|
|
|
5
5
|
"srcDir": "./output/src",
|
|
6
6
|
"openapiDir": "./output/openapi",
|
|
7
7
|
"app": {
|
|
8
|
-
"roles": [
|
|
9
|
-
"admin",
|
|
10
|
-
"user"
|
|
11
|
-
],
|
|
12
8
|
"enableSwagger": true,
|
|
13
9
|
"useUserSchema": true,
|
|
14
10
|
"useObjectID": true,
|
|
@@ -18,10 +14,17 @@
|
|
|
18
14
|
"google": true,
|
|
19
15
|
"microsoft": false,
|
|
20
16
|
"apple": false,
|
|
21
|
-
"github": false
|
|
17
|
+
"github": false,
|
|
18
|
+
"facebook": false
|
|
22
19
|
},
|
|
23
20
|
"useRBAC": {
|
|
24
21
|
"roles": [
|
|
22
|
+
"visitor",
|
|
23
|
+
"member",
|
|
24
|
+
"admin"
|
|
25
|
+
],
|
|
26
|
+
"default": "visitor",
|
|
27
|
+
"schemaIncluded": [
|
|
25
28
|
"user"
|
|
26
29
|
]
|
|
27
30
|
}
|