mandarina-server 1.3.0 → 1.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.
|
@@ -16,7 +16,7 @@ export declare class CustomAction {
|
|
|
16
16
|
*/
|
|
17
17
|
constructor(schema: Schema | string, actionOptions: ActionOptions);
|
|
18
18
|
static getInstance(name: string): CustomAction;
|
|
19
|
-
getFields():
|
|
19
|
+
getFields(): any;
|
|
20
20
|
getActions(): {};
|
|
21
21
|
}
|
|
22
22
|
export interface ActionOptions {
|
|
@@ -35,10 +35,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
|
+
};
|
|
38
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
42
|
var Schema_1 = require("mandarina/build/Schema/Schema");
|
|
40
43
|
var TableInstanceNotFound_1 = require("../Errors/TableInstanceNotFound");
|
|
41
44
|
var UniqueActionError_1 = require("../Errors/UniqueActionError");
|
|
45
|
+
var Mandarina_1 = __importDefault(require("../Mandarina"));
|
|
42
46
|
var CustomAction = /** @class */ (function () {
|
|
43
47
|
/**
|
|
44
48
|
*
|
|
@@ -76,32 +80,21 @@ var CustomAction = /** @class */ (function () {
|
|
|
76
80
|
var result = {};
|
|
77
81
|
Object.keys(actions).forEach(function (action) {
|
|
78
82
|
result[action] = function (_, args, context, info) { return __awaiter(_this, void 0, void 0, function () {
|
|
83
|
+
var user, roles, permissions;
|
|
79
84
|
return __generator(this, function (_a) {
|
|
80
85
|
switch (_a.label) {
|
|
81
|
-
case 0: return [4 /*yield*/,
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
];
|
|
92
|
-
case
|
|
93
|
-
//todo: check permissions
|
|
94
|
-
return [2 /*return*/, _a.sent()
|
|
95
|
-
// console.error('Actions permissions are not checked', this.permissions)
|
|
96
|
-
// if (this.options.onBefore) {
|
|
97
|
-
// await this.options.onBefore(action, _, args, context, info)
|
|
98
|
-
// }
|
|
99
|
-
// const result = await actions[action].action(_, args, context, info)
|
|
100
|
-
// if (this.options.onAfter) {
|
|
101
|
-
// this.options.onAfter(action, _, args, context, info)
|
|
102
|
-
// }
|
|
103
|
-
// return result
|
|
104
|
-
];
|
|
86
|
+
case 0: return [4 /*yield*/, Mandarina_1.default.config.getUser(context)];
|
|
87
|
+
case 1:
|
|
88
|
+
user = _a.sent();
|
|
89
|
+
roles = (user && user.roles) || [];
|
|
90
|
+
if (roles.includes('nobody')) {
|
|
91
|
+
throw new Error('Action not allowed');
|
|
92
|
+
}
|
|
93
|
+
permissions = actions[action].permission || [];
|
|
94
|
+
if (!(roles.includes('everybody') || permissions.some(function (permission) { return roles.includes(permission); }))) return [3 /*break*/, 3];
|
|
95
|
+
return [4 /*yield*/, actions[action].action(_, args, context, info)];
|
|
96
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
97
|
+
case 3: throw new Error('Action not allowed for this user');
|
|
105
98
|
}
|
|
106
99
|
});
|
|
107
100
|
}); };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CustomAction.js","sourceRoot":"","sources":["../../src/Action/CustomAction.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CustomAction.js","sourceRoot":"","sources":["../../src/Action/CustomAction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wDAA4E;AAC5E,yEAAsE;AACtE,iEAA8D;AAG9D,2DAAqC;AAIrC;IAUI;;;;;OAKG;IACH,sBAAY,MAAuB,EAAE,aAA4B;QAC7D,YAAY,CAAC,SAA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A;;4BAA9C,IAAI,GAAG,SAAuC;4BAC9C,KAAK,GAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,CAAE,IAAI,EAAE,CAAA;4BACvC,IAAI,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAC;gCACzB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAA;6BACxC;4BACK,WAAW,GAAY,OAAO,CAAC,MAAM,CAAC,CAAC,UAAU,IAAI,EAAE,CAAA;iCACzD,CAAA,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,UAAA,UAAU,IAAE,OAAA,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC,EAA1B,CAA0B,CAAC,CAAA,EAAvF,wBAAuF;4BAChF,qBAAM,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAA;gCAA3D,sBAAO,SAAoD,EAAA;gCAE/D,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;;;iBACtD,CAAC;QACV,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAClB,CAAC;IACL,mBAAC;AAAD,CAAC,AApED,IAoEC;AApEY,oCAAY"}
|
package/build/Table/Table.d.ts
CHANGED
|
@@ -21,12 +21,12 @@ export declare class Table {
|
|
|
21
21
|
options: TableSchemaOptions & TableShapeOptions;
|
|
22
22
|
constructor(schema: Schema, tableOptions?: TableShapeOptions);
|
|
23
23
|
static getInstance(name: string): Table;
|
|
24
|
-
getFields():
|
|
24
|
+
getFields(): any;
|
|
25
25
|
shouldHasManyUpdate(): boolean;
|
|
26
26
|
getDefaultActions(type: operationType): {
|
|
27
27
|
[resolverName: string]: (_: any, args: any, context: Context, info: any) => void;
|
|
28
28
|
};
|
|
29
|
-
insertWhereIntoInfo: (info: GraphQLResolveInfo, user: UserType | null | undefined, isSingleMutation: boolean | undefined, action:
|
|
29
|
+
insertWhereIntoInfo: (info: GraphQLResolveInfo, user: UserType | null | undefined, isSingleMutation: boolean | undefined, action: any, operationName: string) => {
|
|
30
30
|
fields: string[];
|
|
31
31
|
query: any;
|
|
32
32
|
queryString: string;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { Schema } from "mandarina";
|
|
2
1
|
import { CustomAction } from "../../";
|
|
3
|
-
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const getGraphQLInput: (schema: Schema) => string;
|
|
2
|
+
export declare const getGraphQLType: (def: any, key: string, required?: "" | "!", isInput?: boolean) => string;
|
|
3
|
+
export declare const getGraphQLModel: (schema: any) => string;
|
|
4
|
+
export declare const getGraphQLInput: (schema: any) => string;
|
|
7
5
|
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
8
6
|
export declare const createDir: (dir: string) => void;
|
|
9
7
|
export declare const saveFile: (dir: string, fileName: string, content: string, fileType: "input" | "model" | "operation") => void;
|
|
10
8
|
export declare const resetDir: (dir: string) => void;
|
|
11
9
|
export declare const savePrismaYaml: (datamodel: Set<string>, dir: string, endpoint: string, secret?: string | undefined) => void;
|
|
12
10
|
export declare const saveDockerComposeYaml: (dir: string, port: string) => void;
|
|
13
|
-
export declare const getSubSchemas: (schema:
|
|
14
|
-
export declare const getGraphQLOperation: (action: CustomAction, schema:
|
|
11
|
+
export declare const getSubSchemas: (schema: any, processedSchemas?: string[]) => string[];
|
|
12
|
+
export declare const getGraphQLOperation: (action: CustomAction, schema: any) => string;
|
|
15
13
|
export declare const getAuthOperation: () => string;
|
package/package.json
CHANGED
|
@@ -3,6 +3,7 @@ import {TableInstanceNotFound} from "../Errors/TableInstanceNotFound";
|
|
|
3
3
|
import {UniqueActionError} from "../Errors/UniqueActionError";
|
|
4
4
|
|
|
5
5
|
import {Permission} from "mandarina/build/Schema/Schema";
|
|
6
|
+
import Mandarina from "../Mandarina";
|
|
6
7
|
|
|
7
8
|
|
|
8
9
|
|
|
@@ -59,18 +60,17 @@ export class CustomAction {
|
|
|
59
60
|
Object.keys(actions).forEach((action) => {
|
|
60
61
|
result[action] = async (_: any, args: any, context: any, info: any): Promise<any> => {
|
|
61
62
|
//todo: check permissions
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
;
|
|
63
|
+
const user = await Mandarina.config.getUser(context)
|
|
64
|
+
const roles=(user && user.roles ) || []
|
|
65
|
+
if (roles.includes('nobody')){
|
|
66
|
+
throw new Error('Action not allowed')
|
|
67
|
+
}
|
|
68
|
+
const permissions: string[]= actions[action].permission || []
|
|
69
|
+
if (roles.includes('everybody') || permissions.some(permission=>roles.includes(permission))){
|
|
70
|
+
return await actions[action].action(_, args, context, info)
|
|
71
|
+
}
|
|
72
|
+
throw new Error('Action not allowed for this user')
|
|
73
|
+
};
|
|
74
74
|
});
|
|
75
75
|
|
|
76
76
|
return result;
|