@flowerforce/flowerbase 1.0.2 → 1.0.3-beta.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/dist/auth/controller.js +3 -3
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +37 -4
- package/dist/auth/utils.d.ts +1 -0
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -2
- package/dist/features/endpoints/index.d.ts +1 -1
- package/dist/features/endpoints/index.d.ts.map +1 -1
- package/dist/features/endpoints/index.js +3 -3
- package/dist/features/endpoints/interface.d.ts +4 -0
- package/dist/features/endpoints/interface.d.ts.map +1 -1
- package/dist/features/endpoints/utils.d.ts +1 -1
- package/dist/features/endpoints/utils.d.ts.map +1 -1
- package/dist/features/endpoints/utils.js +18 -10
- package/dist/features/functions/utils.d.ts +2 -2
- package/dist/features/functions/utils.js +3 -1
- package/dist/features/rules/interface.d.ts +42 -0
- package/dist/features/rules/interface.d.ts.map +1 -1
- package/dist/features/rules/interface.js +7 -0
- package/dist/features/rules/utils.js +41 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +39 -1
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +45 -2
- package/dist/services/mongodb-atlas/model.d.ts +7 -1
- package/dist/services/mongodb-atlas/model.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/model.js +8 -0
- package/dist/services/mongodb-atlas/utils.d.ts +9 -2
- package/dist/services/mongodb-atlas/utils.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/utils.js +104 -1
- package/dist/utils/rules.js +2 -1
- package/package.json +3 -1
- package/src/auth/controller.ts +3 -3
- package/src/auth/providers/local-userpass/controller.ts +41 -4
- package/src/auth/utils.ts +1 -0
- package/src/constants.ts +4 -2
- package/src/features/endpoints/index.ts +4 -3
- package/src/features/endpoints/interface.ts +4 -0
- package/src/features/endpoints/utils.ts +28 -11
- package/src/features/functions/utils.ts +3 -3
- package/src/features/rules/interface.ts +35 -1
- package/src/features/rules/utils.ts +46 -0
- package/src/index.ts +20 -1
- package/src/services/mongodb-atlas/index.ts +60 -5
- package/src/services/mongodb-atlas/model.ts +10 -1
- package/src/services/mongodb-atlas/utils.ts +129 -2
- package/src/utils/rules.ts +3 -3
package/dist/auth/controller.js
CHANGED
|
@@ -65,9 +65,9 @@ function authController(app) {
|
|
|
65
65
|
if (!auth_user) {
|
|
66
66
|
throw new Error(`User with ID ${req.user.sub} not found`);
|
|
67
67
|
}
|
|
68
|
-
const user =
|
|
69
|
-
.collection(userCollection)
|
|
70
|
-
|
|
68
|
+
const user = userCollection && constants_1.AUTH_CONFIG.user_id_field
|
|
69
|
+
? (yield db.collection(userCollection).findOne({ [constants_1.AUTH_CONFIG.user_id_field]: req.user.sub }))
|
|
70
|
+
: {};
|
|
71
71
|
res.status(201);
|
|
72
72
|
return {
|
|
73
73
|
access_token: this.createAccessToken(Object.assign(Object.assign({}, auth_user), { user_data: user }))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/local-userpass/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../../../src/auth/providers/local-userpass/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAuBzC;;;;GAIG;AACH,wBAAsB,uBAAuB,CAAC,GAAG,EAAE,eAAe,iBAiPjE"}
|
|
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.localUserPassController = localUserPassController;
|
|
16
16
|
const mail_1 = __importDefault(require("@sendgrid/mail"));
|
|
17
17
|
const constants_1 = require("../../../constants");
|
|
18
|
+
const services_1 = require("../../../services");
|
|
18
19
|
const state_1 = require("../../../state");
|
|
19
20
|
const context_1 = require("../../../utils/context");
|
|
20
21
|
const crypto_1 = require("../../../utils/crypto");
|
|
@@ -26,7 +27,8 @@ const utils_1 = require("../../utils");
|
|
|
26
27
|
*/
|
|
27
28
|
function localUserPassController(app) {
|
|
28
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const
|
|
30
|
+
const functionsList = state_1.StateManager.select('functions');
|
|
31
|
+
const { authCollection, userCollection, user_id_field, on_user_creation_function_name } = constants_1.AUTH_CONFIG;
|
|
30
32
|
const db = app.mongo.client.db(constants_1.DB_NAME);
|
|
31
33
|
/**
|
|
32
34
|
* Endpoint for user registration.
|
|
@@ -55,7 +57,7 @@ function localUserPassController(app) {
|
|
|
55
57
|
email: email,
|
|
56
58
|
password: hashedPassword,
|
|
57
59
|
custom_data: {
|
|
58
|
-
//
|
|
60
|
+
// TODO da aggiungere in fase di registrazione utente, funzionalità utile che realm non permetteva
|
|
59
61
|
}
|
|
60
62
|
});
|
|
61
63
|
yield (db === null || db === void 0 ? void 0 : db.collection(authCollection).updateOne({
|
|
@@ -72,6 +74,33 @@ function localUserPassController(app) {
|
|
|
72
74
|
]
|
|
73
75
|
}
|
|
74
76
|
}));
|
|
77
|
+
if (result && on_user_creation_function_name && functionsList[on_user_creation_function_name]) {
|
|
78
|
+
const user = yield db.collection(authCollection).findOne({ _id: result === null || result === void 0 ? void 0 : result.insertedId });
|
|
79
|
+
user === null || user === void 0 ? true : delete user.password;
|
|
80
|
+
try {
|
|
81
|
+
const response = yield (0, context_1.GenerateContext)({
|
|
82
|
+
args: [{
|
|
83
|
+
operationType: 'CREATE',
|
|
84
|
+
providers: 'local-userpass',
|
|
85
|
+
user,
|
|
86
|
+
time: new Date().getTime()
|
|
87
|
+
}],
|
|
88
|
+
app,
|
|
89
|
+
rules: {},
|
|
90
|
+
user: undefined,
|
|
91
|
+
currentFunction: functionsList[on_user_creation_function_name],
|
|
92
|
+
functionsList,
|
|
93
|
+
services: services_1.services
|
|
94
|
+
});
|
|
95
|
+
console.log("🚀 ~ response:", response);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.log("🚀 ~ error:", error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
console.error('Error function on_user_creation_function_name: ', on_user_creation_function_name);
|
|
103
|
+
}
|
|
75
104
|
res.status(201);
|
|
76
105
|
return {
|
|
77
106
|
userId: result === null || result === void 0 ? void 0 : result.insertedId
|
|
@@ -99,9 +128,13 @@ function localUserPassController(app) {
|
|
|
99
128
|
if (!passwordMatches) {
|
|
100
129
|
throw new Error(utils_1.AUTH_ERRORS.INVALID_CREDENTIALS);
|
|
101
130
|
}
|
|
131
|
+
const user = user_id_field && userCollection
|
|
132
|
+
? (yield db.collection(userCollection).findOne({ [user_id_field]: storedUser._id.toString() }))
|
|
133
|
+
: {};
|
|
134
|
+
const userWithCustomData = Object.assign(Object.assign({}, storedUser), { user_data: user });
|
|
102
135
|
return {
|
|
103
|
-
access_token: this.createAccessToken(
|
|
104
|
-
refresh_token: this.createRefreshToken(
|
|
136
|
+
access_token: this.createAccessToken(userWithCustomData),
|
|
137
|
+
refresh_token: this.createRefreshToken(userWithCustomData),
|
|
105
138
|
device_id: '',
|
|
106
139
|
user_id: storedUser._id.toString()
|
|
107
140
|
};
|
package/dist/auth/utils.d.ts
CHANGED
package/dist/auth/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/auth/utils.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,YAAY;;;;;;;;;;;;;CASxB,CAAA;AAED,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;CAUhC,CAAA;AAED,eAAO,MAAM,mBAAmB;;;;;;;;;;;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AAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;IACvB,aAAa,EAAE,MAAM,CAAA;IACrB,8BAA8B,EAAE,MAAM,CAAA;CACvC;AAED,eAAO,MAAM,aAAa,mBAAmB,CAAA;AAE7C;;;GAGG;AACH,eAAO,MAAM,cAAc,QAAO,UAGjC,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,kBAAkB,QAAO,oBAGrC,CAAA;AAED,eAAO,MAAM,aAAa,GACxB,qBAAqB,MAAM,EAC3B,OAAO,MAAM,EACb,SAAS,MAAM;;;;;CA4ChB,CAAA"}
|
package/dist/constants.d.ts
CHANGED
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc;;;;;;;;CAQ1B,CAAA;AACD,eAAO,MAAM,WAAW,QAA8C,CAAA;AACtE,eAAO,MAAM,YAAY,QAA8B,CAAA;AACvD,eAAO,MAAM,OAAO,QAAgB,CAAA;AACpC,eAAO,MAAM,WAAW;;;;;;;CAOvB,CAAA"}
|
package/dist/constants.js
CHANGED
|
@@ -13,7 +13,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.AUTH_CONFIG = exports.DB_NAME = exports.HTTPS_SCHEMA = exports.API_VERSION = exports.DEFAULT_CONFIG = void 0;
|
|
15
15
|
const utils_1 = require("./auth/utils");
|
|
16
|
-
const { database_name, collection_name = 'users', user_id_field = 'id' } = (0, utils_1.loadCustomUserData)();
|
|
16
|
+
const { database_name, collection_name = 'users', user_id_field = 'id', on_user_creation_function_name } = (0, utils_1.loadCustomUserData)();
|
|
17
17
|
const _a = (0, utils_1.loadAuthConfig)(), { auth_collection = 'auth_users' } = _a, configuration = __rest(_a, ["auth_collection"]);
|
|
18
18
|
exports.DEFAULT_CONFIG = {
|
|
19
19
|
PORT: Number(process.env.PORT) || 3000,
|
|
@@ -32,5 +32,6 @@ exports.AUTH_CONFIG = {
|
|
|
32
32
|
userCollection: collection_name,
|
|
33
33
|
resetPasswordCollection: 'reset-password-requests',
|
|
34
34
|
resetPasswordConfig: configuration['local-userpass'].config,
|
|
35
|
-
user_id_field
|
|
35
|
+
user_id_field,
|
|
36
|
+
on_user_creation_function_name
|
|
36
37
|
};
|
|
@@ -6,5 +6,5 @@ import { GenerateEndpointsParams } from './interface';
|
|
|
6
6
|
* @param functionsList -> the list of all functions
|
|
7
7
|
* @param endpointsList -> the list of all endpoints
|
|
8
8
|
*/
|
|
9
|
-
export declare const generateEndpoints: ({ app, functionsList, endpointsList }: GenerateEndpointsParams) => Promise<void>;
|
|
9
|
+
export declare const generateEndpoints: ({ app, functionsList, endpointsList, rulesList }: GenerateEndpointsParams) => Promise<void>;
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAGrD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAA;AAGrD;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAAU,kDAKrC,uBAAuB,kBAYzB,CAAA"}
|
|
@@ -18,13 +18,13 @@ const utils_1 = require("./utils");
|
|
|
18
18
|
* @param functionsList -> the list of all functions
|
|
19
19
|
* @param endpointsList -> the list of all endpoints
|
|
20
20
|
*/
|
|
21
|
-
const generateEndpoints = (_a) => __awaiter(void 0, [_a], void 0, function* ({ app, functionsList, endpointsList }) {
|
|
21
|
+
const generateEndpoints = (_a) => __awaiter(void 0, [_a], void 0, function* ({ app, functionsList, endpointsList, rulesList }) {
|
|
22
22
|
endpointsList.forEach(({ http_method, route, disabled, function_name }) => {
|
|
23
23
|
const currentFunction = functionsList[function_name];
|
|
24
24
|
if (disabled || !currentFunction)
|
|
25
25
|
return;
|
|
26
|
-
const handler = (0, utils_1.generateHandler)({ app, currentFunction, functionsList });
|
|
27
|
-
const currentMethod = (0, utils_1.getMethodsConfig)(app, handler, `/app/:appId/endpoint/${route}`)[http_method];
|
|
26
|
+
const handler = (0, utils_1.generateHandler)({ app, rulesList, currentFunction, functionsList, http_method });
|
|
27
|
+
const currentMethod = (0, utils_1.getMethodsConfig)(app, handler, `/app/:appId/endpoint/${route.replace(/^\//, "")}`)[http_method];
|
|
28
28
|
currentMethod();
|
|
29
29
|
});
|
|
30
30
|
});
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify';
|
|
2
2
|
import { Function, Functions } from '../functions/interface';
|
|
3
|
+
import { Rules } from '../rules/interface';
|
|
3
4
|
export type GenerateEndpointsParams = {
|
|
4
5
|
app: FastifyInstance;
|
|
5
6
|
functionsList: Functions;
|
|
6
7
|
endpointsList: Endpoints;
|
|
8
|
+
rulesList: Rules;
|
|
7
9
|
};
|
|
8
10
|
export type GenerateHandlerParams = {
|
|
9
11
|
app: FastifyInstance;
|
|
10
12
|
currentFunction: Function;
|
|
11
13
|
functionsList: Functions;
|
|
14
|
+
http_method: string;
|
|
15
|
+
rulesList: Rules;
|
|
12
16
|
};
|
|
13
17
|
type HTTP_METHOD<T> = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | T;
|
|
14
18
|
export type Endpoint<T = 'ALL'> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE1C,MAAM,MAAM,uBAAuB,GAAG;IACpC,GAAG,EAAE,eAAe,CAAA;IACpB,aAAa,EAAE,SAAS,CAAA;IACxB,aAAa,EAAE,SAAS,CAAA;IACxB,SAAS,EAAE,KAAK,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,qBAAqB,GAAG;IAClC,GAAG,EAAE,eAAe,CAAA;IACpB,eAAe,EAAE,QAAQ,CAAA;IACzB,aAAa,EAAE,SAAS,CAAA;IACxB,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,KAAK,CAAA;CACjB,CAAA;AAED,KAAK,WAAW,CAAC,CAAC,IAAI,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,CAAC,CAAA;AAErE,MAAM,MAAM,QAAQ,CAAC,CAAC,GAAG,KAAK,IAAI;IAChC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;IACnB,iBAAiB,EAAE,MAAM,CAAA;IACzB,cAAc,EAAE,OAAO,CAAA;IACvB,sBAAsB,EAAE,OAAO,CAAA;IAC/B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,QAAQ,EAAE,OAAO,CAAA;CAClB,CAAA;AACD,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAA"}
|
|
@@ -27,5 +27,5 @@ export declare const getMethodsConfig: (app: FastifyInstance, handler: ReturnTyp
|
|
|
27
27
|
* @param currentFunction -> the name of the function that should be called for that endpoint
|
|
28
28
|
* @param functionsList -> the list of all functions
|
|
29
29
|
*/
|
|
30
|
-
export declare const generateHandler: ({ app, currentFunction, functionsList }: GenerateHandlerParams) => (req: FastifyRequest, res: FastifyReply) => Promise<{}>;
|
|
30
|
+
export declare const generateHandler: ({ app, currentFunction, functionsList, rulesList }: GenerateHandlerParams) => (req: FastifyRequest, res: FastifyReply) => Promise<{}>;
|
|
31
31
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKvE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE9D;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/features/endpoints/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAKvE,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAE9D;;;GAGG;AACH,eAAO,MAAM,aAAa,GAAU,gBAAuB,KAAG,OAAO,CAAC,SAAS,CAmB9E,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,GAC3B,KAAK,eAAe,EACpB,SAAS,UAAU,CAAC,OAAO,eAAe,CAAC,EAC3C,UAAU,MAAM;;;;;;;CAQhB,CAAA;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAI,oDAK7B,qBAAqB,MACR,KAAK,cAAc,EAAE,KAAK,YAAY,gBAuBrD,CAAA"}
|
|
@@ -33,13 +33,20 @@ const context_1 = require("../../utils/context");
|
|
|
33
33
|
* @testable
|
|
34
34
|
*/
|
|
35
35
|
const loadEndpoints = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (rootDir = process.cwd()) {
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
const endpoints = [];
|
|
37
|
+
const folders = ['https_endpoints', 'http_endpoints'];
|
|
38
|
+
folders.forEach((endpointsDir) => {
|
|
39
|
+
const endPointsFile = node_path_1.default.join(rootDir, endpointsDir, 'config.json');
|
|
40
|
+
if (fs_1.default.existsSync(endPointsFile)) {
|
|
41
|
+
const config = JSON.parse(fs_1.default.readFileSync(endPointsFile, 'utf-8'));
|
|
42
|
+
const configRemap = config.map((_a) => {
|
|
43
|
+
var { http_method } = _a, endpoint = __rest(_a, ["http_method"]);
|
|
44
|
+
return (Object.assign({ http_method: http_method === '*' ? 'ALL' : http_method }, endpoint));
|
|
45
|
+
});
|
|
46
|
+
endpoints.push(...configRemap);
|
|
47
|
+
}
|
|
42
48
|
});
|
|
49
|
+
return endpoints;
|
|
43
50
|
});
|
|
44
51
|
exports.loadEndpoints = loadEndpoints;
|
|
45
52
|
/**
|
|
@@ -65,19 +72,20 @@ exports.getMethodsConfig = getMethodsConfig;
|
|
|
65
72
|
* @param currentFunction -> the name of the function that should be called for that endpoint
|
|
66
73
|
* @param functionsList -> the list of all functions
|
|
67
74
|
*/
|
|
68
|
-
const generateHandler = ({ app, currentFunction, functionsList }) => {
|
|
75
|
+
const generateHandler = ({ app, currentFunction, functionsList, rulesList }) => {
|
|
69
76
|
return (req, res) => __awaiter(void 0, void 0, void 0, function* () {
|
|
70
77
|
try {
|
|
78
|
+
// TODO gestire tramite http_method le args da passare
|
|
71
79
|
const response = yield (0, context_1.GenerateContext)({
|
|
72
|
-
args: [
|
|
80
|
+
args: [], // TODO passare solo body e query ???
|
|
73
81
|
app,
|
|
74
|
-
rules:
|
|
82
|
+
rules: rulesList,
|
|
75
83
|
user: req.user,
|
|
76
84
|
currentFunction,
|
|
77
85
|
functionsList,
|
|
78
86
|
services: services_1.services
|
|
79
87
|
});
|
|
80
|
-
res.send(response);
|
|
88
|
+
return res.send(response);
|
|
81
89
|
}
|
|
82
90
|
catch (e) {
|
|
83
91
|
console.log(e);
|
|
@@ -15,8 +15,8 @@ export declare const executeQuery: ({ currentMethod, query, update, document, do
|
|
|
15
15
|
findOne: () => Promise<unknown>;
|
|
16
16
|
deleteOne: () => Promise<unknown>;
|
|
17
17
|
insertOne: () => Promise<import("mongodb/mongodb").InsertOneResult<import("bson").Document>>;
|
|
18
|
-
updateOne: () => Promise<unknown> | import("mongodb/mongodb").FindCursor<any> | import("mongodb/mongodb").ChangeStream<import("bson").Document, import("bson").Document
|
|
19
|
-
aggregate: () =>
|
|
18
|
+
updateOne: () => Promise<unknown> | import("mongodb/mongodb").FindCursor<any> | import("mongodb/mongodb").ChangeStream<import("bson").Document, import("bson").Document>;
|
|
19
|
+
aggregate: () => Promise<import("bson").Document[]>;
|
|
20
20
|
insertMany: () => Promise<import("mongodb/mongodb").InsertManyResult<import("bson").Document>>;
|
|
21
21
|
updateMany: () => Promise<import("mongodb/mongodb").UpdateResult<import("bson").Document>>;
|
|
22
22
|
}>;
|
|
@@ -67,7 +67,9 @@ const executeQuery = (_a) => __awaiter(void 0, [_a], void 0, function* ({ curren
|
|
|
67
67
|
deleteOne: () => currentMethod(bson_1.EJSON.deserialize(query)),
|
|
68
68
|
insertOne: () => currentMethod(bson_1.EJSON.deserialize(document)),
|
|
69
69
|
updateOne: () => currentMethod(bson_1.EJSON.deserialize(query), bson_1.EJSON.deserialize(update)),
|
|
70
|
-
aggregate: () =>
|
|
70
|
+
aggregate: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
71
|
+
return (yield currentMethod(bson_1.EJSON.deserialize(query))).toArray();
|
|
72
|
+
}),
|
|
71
73
|
insertMany: () => currentMethod(bson_1.EJSON.deserialize(documents)),
|
|
72
74
|
updateMany: () => currentMethod(bson_1.EJSON.deserialize(query), bson_1.EJSON.deserialize(update))
|
|
73
75
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { Document } from 'mongodb';
|
|
1
2
|
export interface Filter {
|
|
2
3
|
name: string;
|
|
3
4
|
query: Record<string, unknown>;
|
|
4
5
|
apply_when: Record<string, unknown>;
|
|
6
|
+
projection?: Projection;
|
|
5
7
|
}
|
|
8
|
+
export type Projection = Record<string, 0 | 1>;
|
|
6
9
|
export interface Role {
|
|
7
10
|
name: string;
|
|
8
11
|
apply_when: Record<string, unknown>;
|
|
@@ -19,4 +22,43 @@ export interface RulesConfig {
|
|
|
19
22
|
roles: Role[];
|
|
20
23
|
}
|
|
21
24
|
export type Rules = Record<string, RulesConfig>;
|
|
25
|
+
export type AggregationPipelineStage = {
|
|
26
|
+
$match: Record<string, unknown>;
|
|
27
|
+
} | {
|
|
28
|
+
$project: Record<string, unknown>;
|
|
29
|
+
} | {
|
|
30
|
+
$sort: Record<string, unknown>;
|
|
31
|
+
} | {
|
|
32
|
+
$limit: number;
|
|
33
|
+
} | {
|
|
34
|
+
$skip: number;
|
|
35
|
+
} | {
|
|
36
|
+
$group: Record<string, unknown>;
|
|
37
|
+
} | {
|
|
38
|
+
$lookup: LookupStage;
|
|
39
|
+
} | {
|
|
40
|
+
$facet: Record<string, AggregationPipelineStage[]>;
|
|
41
|
+
} | {
|
|
42
|
+
$unionWith: UnionWithStage;
|
|
43
|
+
};
|
|
44
|
+
export interface LookupStage {
|
|
45
|
+
from: string;
|
|
46
|
+
localField?: string;
|
|
47
|
+
foreignField?: string;
|
|
48
|
+
as: string;
|
|
49
|
+
let?: Record<string, unknown>;
|
|
50
|
+
pipeline?: AggregationPipelineStage[];
|
|
51
|
+
}
|
|
52
|
+
export type AggregationPipeline = Document[];
|
|
53
|
+
export type UnionWithStage = string | UnionWithNestedStage;
|
|
54
|
+
type UnionWithNestedStage = {
|
|
55
|
+
coll: string;
|
|
56
|
+
pipeline: AggregationPipelineStage[];
|
|
57
|
+
};
|
|
58
|
+
export declare enum STAGES_TO_SEARCH {
|
|
59
|
+
LOOKUP = "$lookup",
|
|
60
|
+
UNION_WITH = "$unionWith",
|
|
61
|
+
FACET = "$facet"
|
|
62
|
+
}
|
|
63
|
+
export {};
|
|
22
64
|
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/rules/interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/features/rules/interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC9B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,UAAU,CAAC,EAAE,UAAU,CAAA;CACxB;AACD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;AAC9C,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACnC,MAAM,EAAE,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BAAmB,GAAG,QAAQ,EAAE,CAAA;AAE5C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,oBAAoB,CAAA;AAC1D,KAAK,oBAAoB,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,wBAAwB,EAAE,CAAA;CAAE,CAAA;AAElF,oBAAY,gBAAgB;IAC1B,MAAM,YAAY;IAClB,UAAU,eAAe;IACzB,KAAK,WAAW;CACjB"}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STAGES_TO_SEARCH = void 0;
|
|
4
|
+
var STAGES_TO_SEARCH;
|
|
5
|
+
(function (STAGES_TO_SEARCH) {
|
|
6
|
+
STAGES_TO_SEARCH["LOOKUP"] = "$lookup";
|
|
7
|
+
STAGES_TO_SEARCH["UNION_WITH"] = "$unionWith";
|
|
8
|
+
STAGES_TO_SEARCH["FACET"] = "$facet";
|
|
9
|
+
})(STAGES_TO_SEARCH || (exports.STAGES_TO_SEARCH = STAGES_TO_SEARCH = {}));
|
|
@@ -29,3 +29,44 @@ const loadRules = (...args_1) => __awaiter(void 0, [...args_1], void 0, function
|
|
|
29
29
|
return rulesByCollection;
|
|
30
30
|
});
|
|
31
31
|
exports.loadRules = loadRules;
|
|
32
|
+
// export const getNestedPipelines = (pipeline: AggregationPipelineStage[]) => {
|
|
33
|
+
// return pipeline.reduce(
|
|
34
|
+
// (acc, stage) => {
|
|
35
|
+
// const [stageKey] = Object.keys(stage);
|
|
36
|
+
// const stageValue = stage[stageKey as keyof typeof stage];
|
|
37
|
+
// const pipeline = stageValue?.["pipeline"]
|
|
38
|
+
// if (stageKey === '$lookup') {
|
|
39
|
+
// acc.pipelines.push(stageValue);
|
|
40
|
+
// if (pipeline) {
|
|
41
|
+
// const { collections, pipelines } = getNestedPipelines(pipeline);
|
|
42
|
+
// acc.collections.push(...new Set([(stageValue as LookupStage).from, ...collections]));
|
|
43
|
+
// acc.pipelines.push(...pipelines);
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
46
|
+
// if (stageKey === '$facet') {
|
|
47
|
+
// for (const subPipeline of Object.values(stageValue)) {
|
|
48
|
+
// const { collections, pipelines } = getNestedPipelines(subPipeline as AggregationPipelineStage[]);
|
|
49
|
+
// acc.collections.push(...collections);
|
|
50
|
+
// acc.pipelines.push(...pipelines);
|
|
51
|
+
// }
|
|
52
|
+
// }
|
|
53
|
+
// if (
|
|
54
|
+
// stageKey === '$unionWith' &&
|
|
55
|
+
// typeof stageValue === 'object' &&
|
|
56
|
+
// pipeline
|
|
57
|
+
// ) {
|
|
58
|
+
// const { collections, pipelines } = getNestedPipelines(pipeline);
|
|
59
|
+
// acc.collections.push(...new Set([(stageValue as UnionWithStage).coll, ...collections]));
|
|
60
|
+
// acc.pipelines.push(...pipelines);
|
|
61
|
+
// }
|
|
62
|
+
// return acc;
|
|
63
|
+
// },
|
|
64
|
+
// {
|
|
65
|
+
// collections: [],
|
|
66
|
+
// pipelines: [],
|
|
67
|
+
// } as {
|
|
68
|
+
// collections: string[],
|
|
69
|
+
// pipelines: AggregationPipelineStage[]
|
|
70
|
+
// }
|
|
71
|
+
// );
|
|
72
|
+
// }
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AActB,cAAc,SAAS,CAAA;AAEvB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,EAC/B,SAAS,EACT,IAAI,EACJ,SAAqC,EACrC,IAA0B,EAC1B,UAAuC,EACxC,EAAE,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAA;AActB,cAAc,SAAS,CAAA;AAEvB,MAAM,MAAM,gBAAgB,GAAG;IAC7B,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAAC,EAC/B,SAAS,EACT,IAAI,EACJ,SAAqC,EACrC,IAA0B,EAC1B,UAAuC,EACxC,EAAE,gBAAgB,iBAwElB"}
|
package/dist/index.js
CHANGED
|
@@ -10,9 +10,31 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
13
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
20
|
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
16
38
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
17
39
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
18
40
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -77,6 +99,22 @@ function initialize(_a) {
|
|
|
77
99
|
services: services_1.services
|
|
78
100
|
};
|
|
79
101
|
Object.entries(stateConfig).forEach(([key, value]) => state_1.StateManager.setData(key, value));
|
|
102
|
+
yield fastify.register(Promise.resolve().then(() => __importStar(require('@fastify/swagger'))));
|
|
103
|
+
yield fastify.register(Promise.resolve().then(() => __importStar(require('@fastify/swagger-ui'))), {
|
|
104
|
+
routePrefix: '/documentation',
|
|
105
|
+
uiConfig: {
|
|
106
|
+
docExpansion: 'full',
|
|
107
|
+
deepLinking: false
|
|
108
|
+
},
|
|
109
|
+
uiHooks: {
|
|
110
|
+
onRequest: function (request, reply, next) { next(); },
|
|
111
|
+
preHandler: function (request, reply, next) { next(); }
|
|
112
|
+
},
|
|
113
|
+
staticCSP: true,
|
|
114
|
+
transformStaticCSP: (header) => header,
|
|
115
|
+
transformSpecification: (swaggerObject) => { return swaggerObject; },
|
|
116
|
+
transformSpecificationClone: true
|
|
117
|
+
});
|
|
80
118
|
yield (0, registerPlugins_1.registerPlugins)({
|
|
81
119
|
register: fastify.register,
|
|
82
120
|
mongodbUrl,
|
|
@@ -88,7 +126,7 @@ function initialize(_a) {
|
|
|
88
126
|
console.log('APP Routes registration COMPLETED');
|
|
89
127
|
yield (0, functions_1.registerFunctions)({ app: fastify, functionsList, rulesList });
|
|
90
128
|
console.log('Functions registration COMPLETED');
|
|
91
|
-
yield (0, endpoints_1.generateEndpoints)({ app: fastify, functionsList, endpointsList });
|
|
129
|
+
yield (0, endpoints_1.generateEndpoints)({ app: fastify, functionsList, endpointsList, rulesList });
|
|
92
130
|
console.log('HTTP Endpoints registration COMPLETED');
|
|
93
131
|
fastify.ready(() => {
|
|
94
132
|
console.log("FASTIFY IS READY");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/index.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAyC,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAioBrF,QAAA,MAAM,YAAY,EAAE,oBAgBlB,CAAA;AAEF,eAAe,YAAY,CAAA"}
|
|
@@ -16,6 +16,7 @@ const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
|
16
16
|
const mongodb_1 = require("mongodb");
|
|
17
17
|
const machines_1 = require("../../utils/roles/machines");
|
|
18
18
|
const utils_1 = require("../../utils/roles/machines/utils");
|
|
19
|
+
const model_1 = require("./model");
|
|
19
20
|
const utils_2 = require("./utils");
|
|
20
21
|
//TODO aggiungere no-sql inject security
|
|
21
22
|
const getOperators = (collection, { rules = {}, collName, user, run_as_system }) => ({
|
|
@@ -36,6 +37,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
36
37
|
*/
|
|
37
38
|
findOne: (query) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
39
|
if (!run_as_system) {
|
|
40
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.READ);
|
|
39
41
|
const { filters, roles } = rules[collName] || {};
|
|
40
42
|
// Apply access control filters to the query
|
|
41
43
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, query, user);
|
|
@@ -74,6 +76,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
74
76
|
*/
|
|
75
77
|
deleteOne: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (query = {}) {
|
|
76
78
|
if (!run_as_system) {
|
|
79
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.DELETE);
|
|
77
80
|
const { filters, roles } = rules[collName] || {};
|
|
78
81
|
// Apply access control filters
|
|
79
82
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, query, user);
|
|
@@ -118,6 +121,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
118
121
|
insertOne: (data, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
119
122
|
const { roles } = rules[collName] || {};
|
|
120
123
|
if (!run_as_system) {
|
|
124
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.CREATE);
|
|
121
125
|
const winningRole = (0, utils_1.getWinningRole)(data, user, roles);
|
|
122
126
|
const { status, document } = winningRole
|
|
123
127
|
? yield (0, machines_1.checkValidation)(winningRole, {
|
|
@@ -158,6 +162,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
158
162
|
*/
|
|
159
163
|
updateOne: (query, data, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
164
|
if (!run_as_system) {
|
|
165
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.UPDATE);
|
|
161
166
|
const { filters, roles } = rules[collName] || {};
|
|
162
167
|
// Apply access control filters
|
|
163
168
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, query, user);
|
|
@@ -223,9 +228,11 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
223
228
|
*/
|
|
224
229
|
find: (query) => {
|
|
225
230
|
if (!run_as_system) {
|
|
231
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.READ);
|
|
226
232
|
const { filters, roles } = rules[collName] || {};
|
|
227
233
|
// Pre-query filtering based on access control rules
|
|
228
234
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, query, user);
|
|
235
|
+
// aggiunto filter per evitare questo errore: $and argument's entries must be objects
|
|
229
236
|
const originalCursor = collection.find({ $and: formattedQuery });
|
|
230
237
|
// Clone the cursor to override `toArray` with post-query validation
|
|
231
238
|
const client = originalCursor['client'];
|
|
@@ -277,6 +284,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
277
284
|
*/
|
|
278
285
|
watch: (pipeline = [], options) => {
|
|
279
286
|
if (!run_as_system) {
|
|
287
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.READ);
|
|
280
288
|
const { filters, roles } = rules[collName] || {};
|
|
281
289
|
// Apply access filters to initial change stream pipeline
|
|
282
290
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, {}, user);
|
|
@@ -332,7 +340,37 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
332
340
|
return collection.watch(pipeline, options);
|
|
333
341
|
},
|
|
334
342
|
//TODO -> add filter & rules in aggregate
|
|
335
|
-
aggregate: (
|
|
343
|
+
aggregate: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (pipeline = [], options) {
|
|
344
|
+
if (run_as_system) {
|
|
345
|
+
return collection.aggregate(pipeline, options);
|
|
346
|
+
}
|
|
347
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.READ);
|
|
348
|
+
const { filters = [], roles = [] } = rules[collection.collectionName] || {};
|
|
349
|
+
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, {}, user);
|
|
350
|
+
const projection = (0, utils_2.getFormattedProjection)(filters);
|
|
351
|
+
const guardedPipeline = [
|
|
352
|
+
...(formattedQuery.length ? [{ $match: { $and: formattedQuery } }] : []),
|
|
353
|
+
...(projection ? [{ $project: projection }] : []),
|
|
354
|
+
...(0, utils_2.applyAccessControlToPipeline)(pipeline, rules, user)
|
|
355
|
+
];
|
|
356
|
+
// const pipelineCollections = getCollectionsFromPipeline(pipeline)
|
|
357
|
+
// console.log(pipelineCollections)
|
|
358
|
+
// pipelineCollections.every((collection) => checkDenyOperation(rules, collection, CRUD_OPERATIONS.READ))
|
|
359
|
+
const originalCursor = collection.aggregate(guardedPipeline, options);
|
|
360
|
+
const newCursor = Object.create(originalCursor);
|
|
361
|
+
newCursor.toArray = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
362
|
+
const results = yield originalCursor.toArray();
|
|
363
|
+
const filtered = yield Promise.all(results.map((doc) => __awaiter(void 0, void 0, void 0, function* () {
|
|
364
|
+
const role = (0, utils_1.getWinningRole)(doc, user, roles);
|
|
365
|
+
const { status, document } = role
|
|
366
|
+
? yield (0, machines_1.checkValidation)(role, { type: 'read', roles, cursor: doc, expansions: {} }, user)
|
|
367
|
+
: { status: !(roles === null || roles === void 0 ? void 0 : roles.length), document: doc };
|
|
368
|
+
return status ? document : undefined;
|
|
369
|
+
})));
|
|
370
|
+
return filtered.filter(Boolean);
|
|
371
|
+
});
|
|
372
|
+
return newCursor;
|
|
373
|
+
}),
|
|
336
374
|
/**
|
|
337
375
|
* Inserts multiple documents into a MongoDB collection with optional role-based access control and validation.
|
|
338
376
|
*
|
|
@@ -352,6 +390,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
352
390
|
*/
|
|
353
391
|
insertMany: (documents, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
354
392
|
if (!run_as_system) {
|
|
393
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.CREATE);
|
|
355
394
|
const { roles } = rules[collName] || {};
|
|
356
395
|
// Validate each document against user's roles
|
|
357
396
|
const filteredItems = yield Promise.all(documents.map((currentDoc) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -377,6 +416,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
377
416
|
}),
|
|
378
417
|
updateMany: (query, data, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
379
418
|
if (!run_as_system) {
|
|
419
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.UPDATE);
|
|
380
420
|
const { filters, roles } = rules[collName] || {};
|
|
381
421
|
// Apply access control filters
|
|
382
422
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, query, user);
|
|
@@ -437,6 +477,7 @@ const getOperators = (collection, { rules = {}, collName, user, run_as_system })
|
|
|
437
477
|
*/
|
|
438
478
|
deleteMany: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (query = {}) {
|
|
439
479
|
if (!run_as_system) {
|
|
480
|
+
(0, utils_2.checkDenyOperation)(rules, collection.collectionName, model_1.CRUD_OPERATIONS.DELETE);
|
|
440
481
|
const { filters, roles } = rules[collName] || {};
|
|
441
482
|
// Apply access control filters
|
|
442
483
|
const formattedQuery = (0, utils_2.getFormattedQuery)(filters, query, user);
|
|
@@ -480,7 +521,9 @@ const MongodbAtlas = (app, { rules, user, run_as_system } = {}) => ({
|
|
|
480
521
|
const collection = app.mongo.client
|
|
481
522
|
.db(dbName)
|
|
482
523
|
.collection(collName);
|
|
483
|
-
return getOperators(collection, {
|
|
524
|
+
return getOperators(collection, {
|
|
525
|
+
rules, collName, user, run_as_system
|
|
526
|
+
});
|
|
484
527
|
}
|
|
485
528
|
};
|
|
486
529
|
}
|