@flowerforce/flowerbase 1.0.1-beta.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/CHANGELOG.md +0 -0
- package/LICENSE +3 -0
- package/README.md +18 -0
- package/dist/auth/controller.d.ts +8 -0
- package/dist/auth/controller.d.ts.map +1 -0
- package/dist/auth/controller.js +76 -0
- package/dist/auth/dtos.d.ts +6 -0
- package/dist/auth/dtos.d.ts.map +1 -0
- package/dist/auth/dtos.js +2 -0
- package/dist/auth/plugins/jwt.d.ts +14 -0
- package/dist/auth/plugins/jwt.d.ts.map +1 -0
- package/dist/auth/plugins/jwt.js +68 -0
- package/dist/auth/providers/local-userpass/controller.d.ts +8 -0
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -0
- package/dist/auth/providers/local-userpass/controller.js +184 -0
- package/dist/auth/providers/local-userpass/dtos.d.ts +35 -0
- package/dist/auth/providers/local-userpass/dtos.d.ts.map +1 -0
- package/dist/auth/providers/local-userpass/dtos.js +2 -0
- package/dist/auth/utils.d.ts +126 -0
- package/dist/auth/utils.d.ts.map +1 -0
- package/dist/auth/utils.js +125 -0
- package/dist/constants.d.ts +20 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +36 -0
- package/dist/features/endpoints/index.d.ts +10 -0
- package/dist/features/endpoints/index.d.ts.map +1 -0
- package/dist/features/endpoints/index.js +31 -0
- package/dist/features/endpoints/interface.d.ts +27 -0
- package/dist/features/endpoints/interface.d.ts.map +1 -0
- package/dist/features/endpoints/interface.js +2 -0
- package/dist/features/endpoints/utils.d.ts +31 -0
- package/dist/features/endpoints/utils.d.ts.map +1 -0
- package/dist/features/endpoints/utils.js +88 -0
- package/dist/features/functions/controller.d.ts +9 -0
- package/dist/features/functions/controller.d.ts.map +1 -0
- package/dist/features/functions/controller.js +88 -0
- package/dist/features/functions/dtos.d.ts +34 -0
- package/dist/features/functions/dtos.d.ts.map +1 -0
- package/dist/features/functions/dtos.js +2 -0
- package/dist/features/functions/index.d.ts +9 -0
- package/dist/features/functions/index.d.ts.map +1 -0
- package/dist/features/functions/index.js +28 -0
- package/dist/features/functions/interface.d.ts +32 -0
- package/dist/features/functions/interface.d.ts.map +1 -0
- package/dist/features/functions/interface.js +2 -0
- package/dist/features/functions/utils.d.ts +23 -0
- package/dist/features/functions/utils.d.ts.map +1 -0
- package/dist/features/functions/utils.js +75 -0
- package/dist/features/rules/index.d.ts +1 -0
- package/dist/features/rules/index.d.ts.map +1 -0
- package/dist/features/rules/index.js +1 -0
- package/dist/features/rules/interface.d.ts +22 -0
- package/dist/features/rules/interface.d.ts.map +1 -0
- package/dist/features/rules/interface.js +2 -0
- package/dist/features/rules/utils.d.ts +3 -0
- package/dist/features/rules/utils.d.ts.map +1 -0
- package/dist/features/rules/utils.js +31 -0
- package/dist/features/triggers/dtos.d.ts +9 -0
- package/dist/features/triggers/dtos.d.ts.map +1 -0
- package/dist/features/triggers/dtos.js +2 -0
- package/dist/features/triggers/index.d.ts +10 -0
- package/dist/features/triggers/index.d.ts.map +1 -0
- package/dist/features/triggers/index.js +59 -0
- package/dist/features/triggers/interface.d.ts +44 -0
- package/dist/features/triggers/interface.d.ts.map +1 -0
- package/dist/features/triggers/interface.js +2 -0
- package/dist/features/triggers/utils.d.ts +16 -0
- package/dist/features/triggers/utils.d.ts.map +1 -0
- package/dist/features/triggers/utils.js +153 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -0
- package/dist/model.d.ts +2 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +2 -0
- package/dist/services/api/index.d.ts +36 -0
- package/dist/services/api/index.d.ts.map +1 -0
- package/dist/services/api/index.js +36 -0
- package/dist/services/api/model.d.ts +33 -0
- package/dist/services/api/model.d.ts.map +1 -0
- package/dist/services/api/model.js +2 -0
- package/dist/services/api/utils.d.ts +16 -0
- package/dist/services/api/utils.d.ts.map +1 -0
- package/dist/services/api/utils.js +45 -0
- package/dist/services/aws/index.d.ts +13 -0
- package/dist/services/aws/index.d.ts.map +1 -0
- package/dist/services/aws/index.js +50 -0
- package/dist/services/index.d.ts +41 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +14 -0
- package/dist/services/interface.d.ts +3 -0
- package/dist/services/interface.d.ts.map +1 -0
- package/dist/services/interface.js +2 -0
- package/dist/services/mongodb-atlas/index.d.ts +4 -0
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -0
- package/dist/services/mongodb-atlas/index.js +483 -0
- package/dist/services/mongodb-atlas/model.d.ts +39 -0
- package/dist/services/mongodb-atlas/model.d.ts.map +1 -0
- package/dist/services/mongodb-atlas/model.js +2 -0
- package/dist/services/mongodb-atlas/utils.d.ts +8 -0
- package/dist/services/mongodb-atlas/utils.d.ts.map +1 -0
- package/dist/services/mongodb-atlas/utils.js +33 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +18 -0
- package/dist/utils/context/helpers.d.ts +74 -0
- package/dist/utils/context/helpers.d.ts.map +1 -0
- package/dist/utils/context/helpers.js +60 -0
- package/dist/utils/context/index.d.ts +14 -0
- package/dist/utils/context/index.d.ts.map +1 -0
- package/dist/utils/context/index.js +65 -0
- package/dist/utils/context/interface.d.ts +18 -0
- package/dist/utils/context/interface.d.ts.map +1 -0
- package/dist/utils/context/interface.js +2 -0
- package/dist/utils/crypto/index.d.ts +19 -0
- package/dist/utils/crypto/index.d.ts.map +1 -0
- package/dist/utils/crypto/index.js +50 -0
- package/dist/utils/helpers/someAsync.d.ts +12 -0
- package/dist/utils/helpers/someAsync.d.ts.map +1 -0
- package/dist/utils/helpers/someAsync.js +56 -0
- package/dist/utils/index.d.ts +3 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/initializer/exposeRoutes.d.ts +8 -0
- package/dist/utils/initializer/exposeRoutes.d.ts.map +1 -0
- package/dist/utils/initializer/exposeRoutes.js +41 -0
- package/dist/utils/initializer/registerPlugins.d.ts +19 -0
- package/dist/utils/initializer/registerPlugins.d.ts.map +1 -0
- package/dist/utils/initializer/registerPlugins.js +96 -0
- package/dist/utils/roles/helpers.d.ts +4 -0
- package/dist/utils/roles/helpers.d.ts.map +1 -0
- package/dist/utils/roles/helpers.js +47 -0
- package/dist/utils/roles/interface.d.ts +33 -0
- package/dist/utils/roles/interface.d.ts.map +1 -0
- package/dist/utils/roles/interface.js +2 -0
- package/dist/utils/roles/machines/commonValidators.d.ts +6 -0
- package/dist/utils/roles/machines/commonValidators.d.ts.map +1 -0
- package/dist/utils/roles/machines/commonValidators.js +34 -0
- package/dist/utils/roles/machines/index.d.ts +14 -0
- package/dist/utils/roles/machines/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/index.js +27 -0
- package/dist/utils/roles/machines/interface.d.ts +46 -0
- package/dist/utils/roles/machines/interface.d.ts.map +1 -0
- package/dist/utils/roles/machines/interface.js +2 -0
- package/dist/utils/roles/machines/machine.d.ts +15 -0
- package/dist/utils/roles/machines/machine.d.ts.map +1 -0
- package/dist/utils/roles/machines/machine.js +97 -0
- package/dist/utils/roles/machines/read/A/index.d.ts +3 -0
- package/dist/utils/roles/machines/read/A/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/A/index.js +27 -0
- package/dist/utils/roles/machines/read/B/index.d.ts +3 -0
- package/dist/utils/roles/machines/read/B/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/B/index.js +36 -0
- package/dist/utils/roles/machines/read/C/index.d.ts +3 -0
- package/dist/utils/roles/machines/read/C/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/C/index.js +38 -0
- package/dist/utils/roles/machines/read/D/index.d.ts +3 -0
- package/dist/utils/roles/machines/read/D/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/D/index.js +26 -0
- package/dist/utils/roles/machines/read/D/validators.d.ts +4 -0
- package/dist/utils/roles/machines/read/D/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/D/validators.js +24 -0
- package/dist/utils/roles/machines/read/index.d.ts +2 -0
- package/dist/utils/roles/machines/read/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/index.js +8 -0
- package/dist/utils/roles/machines/utils.d.ts +37 -0
- package/dist/utils/roles/machines/utils.d.ts.map +1 -0
- package/dist/utils/roles/machines/utils.js +54 -0
- package/dist/utils/roles/machines/write/A/index.d.ts +3 -0
- package/dist/utils/roles/machines/write/A/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/A/index.js +29 -0
- package/dist/utils/roles/machines/write/B/index.d.ts +3 -0
- package/dist/utils/roles/machines/write/B/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/B/index.js +47 -0
- package/dist/utils/roles/machines/write/C/index.d.ts +3 -0
- package/dist/utils/roles/machines/write/C/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/C/index.js +26 -0
- package/dist/utils/roles/machines/write/C/validators.d.ts +4 -0
- package/dist/utils/roles/machines/write/C/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/C/validators.js +24 -0
- package/dist/utils/roles/machines/write/index.d.ts +2 -0
- package/dist/utils/roles/machines/write/index.d.ts.map +1 -0
- package/dist/utils/roles/machines/write/index.js +7 -0
- package/dist/utils/rules-matcher/interface.d.ts +338 -0
- package/dist/utils/rules-matcher/interface.d.ts.map +1 -0
- package/dist/utils/rules-matcher/interface.js +26 -0
- package/dist/utils/rules-matcher/utils.d.ts +11 -0
- package/dist/utils/rules-matcher/utils.d.ts.map +1 -0
- package/dist/utils/rules-matcher/utils.js +214 -0
- package/dist/utils/rules.d.ts +2 -0
- package/dist/utils/rules.d.ts.map +1 -0
- package/dist/utils/rules.js +22 -0
- package/jest.config.ts +24 -0
- package/package.json +62 -0
- package/project.json +10 -0
- package/rollup.config.js +17 -0
- package/src/auth/controller.ts +78 -0
- package/src/auth/dtos.ts +6 -0
- package/src/auth/plugins/jwt.ts +68 -0
- package/src/auth/providers/local-userpass/controller.ts +226 -0
- package/src/auth/providers/local-userpass/dtos.ts +40 -0
- package/src/auth/utils.ts +168 -0
- package/src/babel.config.json +3 -0
- package/src/constants.ts +24 -0
- package/src/fastify.d.ts +28 -0
- package/src/features/endpoints/index.ts +27 -0
- package/src/features/endpoints/interface.ts +29 -0
- package/src/features/endpoints/utils.ts +74 -0
- package/src/features/functions/controller.ts +102 -0
- package/src/features/functions/dtos.ts +41 -0
- package/src/features/functions/index.ts +21 -0
- package/src/features/functions/interface.ts +38 -0
- package/src/features/functions/utils.ts +82 -0
- package/src/features/rules/index.tsx +0 -0
- package/src/features/rules/interface.ts +24 -0
- package/src/features/rules/utils.ts +20 -0
- package/src/features/triggers/dtos.ts +9 -0
- package/src/features/triggers/index.ts +36 -0
- package/src/features/triggers/interface.ts +44 -0
- package/src/features/triggers/utils.ts +157 -0
- package/src/global.d.ts +0 -0
- package/src/index.ts +90 -0
- package/src/model.ts +1 -0
- package/src/services/api/index.ts +50 -0
- package/src/services/api/model.ts +38 -0
- package/src/services/api/utils.ts +39 -0
- package/src/services/aws/index.ts +48 -0
- package/src/services/index.ts +9 -0
- package/src/services/interface.ts +3 -0
- package/src/services/mongodb-atlas/index.ts +569 -0
- package/src/services/mongodb-atlas/model.ts +67 -0
- package/src/services/mongodb-atlas/utils.ts +44 -0
- package/src/state.ts +24 -0
- package/src/utils/__tests__/STEP_A_STATES.test.ts +54 -0
- package/src/utils/__tests__/STEP_B_STATES.test.ts +113 -0
- package/src/utils/__tests__/STEP_C_STATES.test.ts +87 -0
- package/src/utils/__tests__/STEP_D_STATES.test.ts +93 -0
- package/src/utils/__tests__/checkAdditionalFieldsFn.test.ts +45 -0
- package/src/utils/__tests__/checkApplyWhen.test.ts +49 -0
- package/src/utils/__tests__/checkFieldsPropertyExists.test.ts +47 -0
- package/src/utils/__tests__/checkIsValidFieldNameFn.test.ts +190 -0
- package/src/utils/__tests__/comparePassword.test.ts +38 -0
- package/src/utils/__tests__/evaluateDocumentsFiltersReadFn.test.ts +57 -0
- package/src/utils/__tests__/evaluateDocumentsFiltersWriteFn.test.ts +57 -0
- package/src/utils/__tests__/evaluateTopLevelReadFn.test.ts +58 -0
- package/src/utils/__tests__/evaluateTopLevelWriteFn.test.ts +66 -0
- package/src/utils/__tests__/exposeRoutes.test.ts +65 -0
- package/src/utils/__tests__/generateContextData.test.ts +75 -0
- package/src/utils/__tests__/getDefaultRule.test.ts +29 -0
- package/src/utils/__tests__/getKey.test.ts +12 -0
- package/src/utils/__tests__/getKeys.test.ts +11 -0
- package/src/utils/__tests__/getWinningRole.test.ts +66 -0
- package/src/utils/__tests__/hashPassword.test.ts +28 -0
- package/src/utils/__tests__/isEmpty.test.ts +17 -0
- package/src/utils/__tests__/logMachineInfo.test.ts +15 -0
- package/src/utils/__tests__/operators.test.ts +99 -0
- package/src/utils/__tests__/readFileContent.test.ts +35 -0
- package/src/utils/__tests__/registerPlugins.test.ts +59 -0
- package/src/utils/__tests__/rule.test.ts +51 -0
- package/src/utils/__tests__/rulesMatcherInterfaces.test.ts +57 -0
- package/src/utils/__tests__/rulesMatcherUtils.test.ts +56 -0
- package/src/utils/__tests__/someAsync.test.ts +55 -0
- package/src/utils/context/helpers.ts +71 -0
- package/src/utils/context/index.ts +74 -0
- package/src/utils/context/interface.ts +19 -0
- package/src/utils/crypto/index.ts +36 -0
- package/src/utils/helpers/someAsync.ts +24 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/initializer/exposeRoutes.ts +26 -0
- package/src/utils/initializer/registerPlugins.ts +111 -0
- package/src/utils/roles/helpers.ts +47 -0
- package/src/utils/roles/interface.ts +42 -0
- package/src/utils/roles/machines/commonValidators.ts +24 -0
- package/src/utils/roles/machines/index.ts +20 -0
- package/src/utils/roles/machines/interface.ts +46 -0
- package/src/utils/roles/machines/machine.ts +85 -0
- package/src/utils/roles/machines/read/A/index.ts +19 -0
- package/src/utils/roles/machines/read/B/index.ts +31 -0
- package/src/utils/roles/machines/read/C/index.ts +30 -0
- package/src/utils/roles/machines/read/D/index.ts +20 -0
- package/src/utils/roles/machines/read/D/validators.ts +24 -0
- package/src/utils/roles/machines/read/index.ts +6 -0
- package/src/utils/roles/machines/utils.ts +54 -0
- package/src/utils/roles/machines/write/A/index.ts +25 -0
- package/src/utils/roles/machines/write/B/index.ts +43 -0
- package/src/utils/roles/machines/write/C/index.ts +20 -0
- package/src/utils/roles/machines/write/C/validators.ts +24 -0
- package/src/utils/roles/machines/write/index.ts +5 -0
- package/src/utils/rules-matcher/interface.ts +365 -0
- package/src/utils/rules-matcher/utils.ts +281 -0
- package/src/utils/rules.ts +19 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.evaluateExpression = void 0;
|
|
16
|
+
const services_1 = require("../../services");
|
|
17
|
+
const state_1 = require("../../state");
|
|
18
|
+
const context_1 = require("../context");
|
|
19
|
+
const rules_1 = require("../rules");
|
|
20
|
+
const utils_1 = __importDefault(require("../rules-matcher/utils"));
|
|
21
|
+
const functionsConditions = ["%%true", "%%false"];
|
|
22
|
+
const evaluateExpression = (params, expression, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
if (!expression || typeof expression === 'boolean')
|
|
24
|
+
return !!expression;
|
|
25
|
+
const value = Object.assign(Object.assign(Object.assign({}, params.expansions), params.cursor), { "%%user": user, '%%true': true });
|
|
26
|
+
const conditions = (0, rules_1.expandQuery)(expression, value);
|
|
27
|
+
const complexCondition = Object.entries(conditions).find(([key]) => functionsConditions.includes(key));
|
|
28
|
+
return complexCondition ? yield evaluateComplexExpression(complexCondition, params, user) : utils_1.default.checkRule(conditions, value, {});
|
|
29
|
+
});
|
|
30
|
+
exports.evaluateExpression = evaluateExpression;
|
|
31
|
+
const evaluateComplexExpression = (condition, params, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
const [key, config] = condition;
|
|
33
|
+
const { name } = config["%function"];
|
|
34
|
+
const functionsList = state_1.StateManager.select("functions");
|
|
35
|
+
const app = state_1.StateManager.select("app");
|
|
36
|
+
const currentFunction = functionsList[name];
|
|
37
|
+
const response = yield (0, context_1.GenerateContext)({
|
|
38
|
+
args: [params.cursor],
|
|
39
|
+
app,
|
|
40
|
+
rules: {},
|
|
41
|
+
user,
|
|
42
|
+
currentFunction,
|
|
43
|
+
functionsList,
|
|
44
|
+
services: services_1.services
|
|
45
|
+
});
|
|
46
|
+
return key === "%%true" ? response : !response;
|
|
47
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type PermissionExpression = boolean;
|
|
2
|
+
export type FieldPermissionExpression = {
|
|
3
|
+
read?: boolean;
|
|
4
|
+
write?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export interface DocumentFiltersPermissions {
|
|
7
|
+
read?: PermissionExpression;
|
|
8
|
+
write?: PermissionExpression;
|
|
9
|
+
}
|
|
10
|
+
export interface Role {
|
|
11
|
+
name: string;
|
|
12
|
+
apply_when: Record<string, any>;
|
|
13
|
+
search?: PermissionExpression;
|
|
14
|
+
document_filters?: DocumentFiltersPermissions;
|
|
15
|
+
read?: PermissionExpression;
|
|
16
|
+
write?: PermissionExpression;
|
|
17
|
+
insert?: PermissionExpression;
|
|
18
|
+
delete?: PermissionExpression;
|
|
19
|
+
fields?: {
|
|
20
|
+
[K: string]: FieldPermissionExpression;
|
|
21
|
+
};
|
|
22
|
+
additional_fields?: {
|
|
23
|
+
[K: string]: FieldPermissionExpression;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export interface Params {
|
|
27
|
+
roles: Role[];
|
|
28
|
+
cursor: any;
|
|
29
|
+
expansions: Record<string, any>;
|
|
30
|
+
type: 'insert' | 'read' | 'delete' | 'search' | 'write';
|
|
31
|
+
}
|
|
32
|
+
export type Condition = Record<string, any>;
|
|
33
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../src/utils/roles/interface.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,oBAAoB,GAAG,OAAO,CAAA;AAE1C,MAAM,MAAM,yBAAyB,GAAG;IACtC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB,CAAA;AAED,MAAM,WAAW,0BAA0B;IACzC,IAAI,CAAC,EAAE,oBAAoB,CAAA;IAC3B,KAAK,CAAC,EAAE,oBAAoB,CAAA;CAC7B;AAED,MAAM,WAAW,IAAI;IACnB,IAAI,EAAE,MAAM,CAAA;IAEZ,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B,MAAM,CAAC,EAAE,oBAAoB,CAAA;IAC7B,gBAAgB,CAAC,EAAE,0BAA0B,CAAA;IAC7C,IAAI,CAAC,EAAE,oBAAoB,CAAA;IAC3B,KAAK,CAAC,EAAE,oBAAoB,CAAA;IAC5B,MAAM,CAAC,EAAE,oBAAoB,CAAA;IAC7B,MAAM,CAAC,EAAE,oBAAoB,CAAA;IAC7B,MAAM,CAAC,EAAE;QACP,CAAC,CAAC,EAAE,MAAM,GAAG,yBAAyB,CAAA;KACvC,CAAA;IACD,iBAAiB,CAAC,EAAE;QAClB,CAAC,CAAC,EAAE,MAAM,GAAG,yBAAyB,CAAA;KACvC,CAAA;CACF;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,IAAI,EAAE,CAAA;IAEb,MAAM,EAAE,GAAG,CAAA;IAEX,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAC/B,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAA;CACxD;AAID,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DocumentFiltersPermissions } from "../interface";
|
|
2
|
+
import { MachineContext } from "./interface";
|
|
3
|
+
export declare const evaluateDocumentFiltersFn: ({ params, role, user }: MachineContext, currentType: keyof DocumentFiltersPermissions) => Promise<boolean>;
|
|
4
|
+
export declare const evaluateTopLevelPermissionsFn: ({ params, role, user }: MachineContext, currentType: MachineContext["params"]["type"]) => Promise<boolean | undefined>;
|
|
5
|
+
export declare const checkFieldsPropertyExists: ({ role }: MachineContext) => boolean;
|
|
6
|
+
//# sourceMappingURL=commonValidators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commonValidators.d.ts","sourceRoot":"","sources":["../../../../src/utils/roles/machines/commonValidators.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAK5C,eAAO,MAAM,yBAAyB,GAAU,wBAAwB,cAAc,EAAE,aAAa,MAAM,0BAA0B,qBAMpI,CAAA;AAGD,eAAO,MAAM,6BAA6B,GAAU,wBAAwB,cAAc,EAAE,aAAa,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,iCAExI,CAAA;AAED,eAAO,MAAM,yBAAyB,GAAI,UAAU,cAAc,YAEjE,CAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.checkFieldsPropertyExists = exports.evaluateTopLevelPermissionsFn = exports.evaluateDocumentFiltersFn = void 0;
|
|
13
|
+
const someAsync_1 = require("../../helpers/someAsync");
|
|
14
|
+
const helpers_1 = require("../helpers");
|
|
15
|
+
const readOnlyPermissions = ['read'];
|
|
16
|
+
const readWritePermissions = ['write', 'delete', 'insert', ...readOnlyPermissions];
|
|
17
|
+
const evaluateDocumentFiltersFn = (_a, currentType_1) => __awaiter(void 0, [_a, currentType_1], void 0, function* ({ params, role, user }, currentType) {
|
|
18
|
+
var _b;
|
|
19
|
+
const permissions = currentType === "read" ? readOnlyPermissions : readWritePermissions;
|
|
20
|
+
return yield (0, someAsync_1.someAsync)([
|
|
21
|
+
permissions.includes(params.type) && ((_b = role.document_filters) === null || _b === void 0 ? void 0 : _b[currentType])
|
|
22
|
+
]
|
|
23
|
+
.filter(Boolean), (expr) => __awaiter(void 0, void 0, void 0, function* () { return (0, helpers_1.evaluateExpression)(params, expr, user); }));
|
|
24
|
+
});
|
|
25
|
+
exports.evaluateDocumentFiltersFn = evaluateDocumentFiltersFn;
|
|
26
|
+
const evaluateTopLevelPermissionsFn = (_a, currentType_1) => __awaiter(void 0, [_a, currentType_1], void 0, function* ({ params, role, user }, currentType) {
|
|
27
|
+
return role[currentType] ? yield (0, helpers_1.evaluateExpression)(params, role[currentType], user) : undefined;
|
|
28
|
+
});
|
|
29
|
+
exports.evaluateTopLevelPermissionsFn = evaluateTopLevelPermissionsFn;
|
|
30
|
+
const checkFieldsPropertyExists = ({ role }) => {
|
|
31
|
+
var _a;
|
|
32
|
+
return !!Object.keys((_a = role.fields) !== null && _a !== void 0 ? _a : {}).length;
|
|
33
|
+
};
|
|
34
|
+
exports.checkFieldsPropertyExists = checkFieldsPropertyExists;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { User } from '../../../auth/dtos';
|
|
2
|
+
import { Params, Role } from '../interface';
|
|
3
|
+
import { StepResult } from './interface';
|
|
4
|
+
/**
|
|
5
|
+
* Executes the validation process using the `StateMachine` for the given role, parameters, and user.
|
|
6
|
+
*
|
|
7
|
+
* @param {Role} role - The role configuration for validation.
|
|
8
|
+
* @param {Params} params - The parameters relevant to the validation process.
|
|
9
|
+
* @param {User} user - The user for whom the validation is being performed.
|
|
10
|
+
*
|
|
11
|
+
* @returns {Promise<StepResult>} - The result of the state machine's validation process.
|
|
12
|
+
*/
|
|
13
|
+
export declare const checkValidation: (role: Role, params: Params, user: User, enableLog?: boolean) => Promise<StepResult>;
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/roles/machines/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAU,MAAM,IAAI,EAAE,QAAQ,MAAM,EAAE,MAAM,IAAI,EAAE,YAAY,OAAO,KAAG,OAAO,CAAC,UAAU,CAGrH,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.checkValidation = void 0;
|
|
13
|
+
const machine_1 = require("./machine");
|
|
14
|
+
/**
|
|
15
|
+
* Executes the validation process using the `StateMachine` for the given role, parameters, and user.
|
|
16
|
+
*
|
|
17
|
+
* @param {Role} role - The role configuration for validation.
|
|
18
|
+
* @param {Params} params - The parameters relevant to the validation process.
|
|
19
|
+
* @param {User} user - The user for whom the validation is being performed.
|
|
20
|
+
*
|
|
21
|
+
* @returns {Promise<StepResult>} - The result of the state machine's validation process.
|
|
22
|
+
*/
|
|
23
|
+
const checkValidation = (role, params, user, enableLog) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
const stateMachine = new machine_1.StateMachine(role, params, user, enableLog);
|
|
25
|
+
return yield stateMachine.runValidation();
|
|
26
|
+
});
|
|
27
|
+
exports.checkValidation = checkValidation;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Document } from 'mongodb';
|
|
2
|
+
import { User } from '../../../auth/dtos';
|
|
3
|
+
import { Params, Role } from '../interface';
|
|
4
|
+
export type PrevParams = Record<string, any>;
|
|
5
|
+
export interface MachineContext {
|
|
6
|
+
user: User;
|
|
7
|
+
role: Role;
|
|
8
|
+
params: Params;
|
|
9
|
+
prevParams?: PrevParams;
|
|
10
|
+
enableLog?: boolean;
|
|
11
|
+
}
|
|
12
|
+
type StateFunction = (params: RunParams & {
|
|
13
|
+
context: MachineContext;
|
|
14
|
+
} & {
|
|
15
|
+
next: (step: string, params?: Record<string, any>) => void;
|
|
16
|
+
endValidation: ({ success, document }: {
|
|
17
|
+
success: boolean;
|
|
18
|
+
document?: Document;
|
|
19
|
+
}) => void;
|
|
20
|
+
goToNextValidationStage: (initialStep?: string | null) => void;
|
|
21
|
+
}) => Promise<void>;
|
|
22
|
+
export type States = Record<string, StateFunction>;
|
|
23
|
+
export interface RunParams {
|
|
24
|
+
initialStep: string | null;
|
|
25
|
+
}
|
|
26
|
+
export interface ValidationStatus {
|
|
27
|
+
status: boolean | null;
|
|
28
|
+
document?: Document;
|
|
29
|
+
}
|
|
30
|
+
export interface StepResult {
|
|
31
|
+
status: boolean | null;
|
|
32
|
+
nextInitialStep: string | null;
|
|
33
|
+
document?: Document;
|
|
34
|
+
}
|
|
35
|
+
export interface EndValidationParams {
|
|
36
|
+
success: boolean;
|
|
37
|
+
document?: Document;
|
|
38
|
+
}
|
|
39
|
+
export type LogMachineInfoParams = {
|
|
40
|
+
enabled?: boolean;
|
|
41
|
+
machine: string;
|
|
42
|
+
step: number;
|
|
43
|
+
stepName: string;
|
|
44
|
+
};
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=interface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.d.ts","sourceRoot":"","sources":["../../../../src/utils/roles/machines/interface.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAClC,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAA;AACzC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAE3C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAC5C,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,IAAI,CAAA;IACV,IAAI,EAAE,IAAI,CAAA;IACV,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,KAAK,aAAa,GAAG,CACnB,MAAM,EAAE,SAAS,GAAG;IAClB,OAAO,EAAE,cAAc,CAAA;CACxB,GAAG;IACF,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,CAAA;IAC1D,aAAa,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,KAAK,IAAI,CAAA;IACzF,uBAAuB,EAAE,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;CAC/D,KACE,OAAO,CAAC,IAAI,CAAC,CAAA;AAElB,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAA;AAElD,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,OAAO,GAAG,IAAI,CAAA;IACtB,QAAQ,CAAC,EAAE,QAAQ,CAAA;CACpB;AAGD,MAAM,WAAW,UAAU;IAAG,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAE;AAE3G,MAAM,WAAW,mBAAmB;IAAG,OAAO,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,QAAQ,CAAA;CAAE;AAE9E,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { User } from "../../../auth/dtos";
|
|
2
|
+
import { Params, Role } from "../interface";
|
|
3
|
+
import { StepResult } from "./interface";
|
|
4
|
+
export declare class StateMachine {
|
|
5
|
+
private _context;
|
|
6
|
+
private _validation;
|
|
7
|
+
private _machines;
|
|
8
|
+
private _currentStep;
|
|
9
|
+
constructor(role: Role, params: Params, user: User, enableLog?: boolean);
|
|
10
|
+
runValidation(): Promise<StepResult>;
|
|
11
|
+
private runMachine;
|
|
12
|
+
private endValidation;
|
|
13
|
+
private goToNextValidationStage;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=machine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine.d.ts","sourceRoot":"","sources":["../../../../src/utils/roles/machines/machine.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAsC,UAAU,EAAoB,MAAM,aAAa,CAAC;AAI/F,qBAAa,YAAY;IACrB,OAAO,CAAC,QAAQ,CAAgB;IAChC,OAAO,CAAC,WAAW,CAGlB;IACD,OAAO,CAAC,SAAS,CAAU;IAC3B,OAAO,CAAC,YAAY,CAMnB;gBACW,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,OAAO;IAajE,aAAa;YAeL,UAAU;IAqBxB,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,uBAAuB;CAMlC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
12
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
13
|
+
var m = o[Symbol.asyncIterator], i;
|
|
14
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
15
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
16
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.StateMachine = void 0;
|
|
20
|
+
const read_1 = require("./read");
|
|
21
|
+
const write_1 = require("./write");
|
|
22
|
+
class StateMachine {
|
|
23
|
+
constructor(role, params, user, enableLog) {
|
|
24
|
+
this._validation = {
|
|
25
|
+
status: null,
|
|
26
|
+
nextInitialStep: null
|
|
27
|
+
};
|
|
28
|
+
this._context = { role, params, user, enableLog };
|
|
29
|
+
this._machines = params.type === "read" ? read_1.READ_MACHINE : write_1.WRITE_MACHINE;
|
|
30
|
+
this._currentStep = {
|
|
31
|
+
names: [],
|
|
32
|
+
states: {},
|
|
33
|
+
validation: {
|
|
34
|
+
status: null
|
|
35
|
+
},
|
|
36
|
+
initialStep: null
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
runValidation() {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
var _a, e_1, _b, _c;
|
|
42
|
+
try {
|
|
43
|
+
for (var _d = true, _e = __asyncValues(this._machines), _f; _f = yield _e.next(), _a = _f.done, !_a; _d = true) {
|
|
44
|
+
_c = _f.value;
|
|
45
|
+
_d = false;
|
|
46
|
+
const machine = _c;
|
|
47
|
+
this._currentStep = { names: Object.freeze(Object.keys(machine)), states: machine, validation: { status: null }, initialStep: null };
|
|
48
|
+
yield this.runMachine(this._validation.nextInitialStep);
|
|
49
|
+
this._validation.nextInitialStep = this._currentStep.initialStep;
|
|
50
|
+
if (this._currentStep.validation.status !== null) {
|
|
51
|
+
this._validation.status = this._currentStep.validation.status;
|
|
52
|
+
this._validation.document = this._currentStep.validation.document;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
58
|
+
finally {
|
|
59
|
+
try {
|
|
60
|
+
if (!_d && !_a && (_b = _e.return)) yield _b.call(_e);
|
|
61
|
+
}
|
|
62
|
+
finally { if (e_1) throw e_1.error; }
|
|
63
|
+
}
|
|
64
|
+
return this._validation;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
runMachine(initialStep) {
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const executeStep = (step, params) => __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
const currentStep = this._currentStep.states[step];
|
|
71
|
+
const next = (nextStep, params) => executeStep(nextStep, params);
|
|
72
|
+
yield currentStep({
|
|
73
|
+
context: Object.assign(Object.assign({}, this._context), { prevParams: params }),
|
|
74
|
+
next,
|
|
75
|
+
endValidation: this.endValidation.bind(this),
|
|
76
|
+
goToNextValidationStage: this.goToNextValidationStage.bind(this),
|
|
77
|
+
initialStep
|
|
78
|
+
});
|
|
79
|
+
if (this._currentStep.validation.status !== null || this._currentStep.completed !== undefined)
|
|
80
|
+
return Object.assign({ isValid: this._currentStep.validation.status }, this._currentStep);
|
|
81
|
+
});
|
|
82
|
+
const nextStep = initialStep && this._currentStep.states[initialStep] ? initialStep : this._currentStep.names[0];
|
|
83
|
+
yield executeStep(nextStep);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
endValidation({ success, document }) {
|
|
87
|
+
this._currentStep.validation.status = success;
|
|
88
|
+
if (success) {
|
|
89
|
+
this._currentStep.validation.document = document || this._context.params.cursor;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
goToNextValidationStage(initialStep = null) {
|
|
93
|
+
this._currentStep.completed = true;
|
|
94
|
+
this._currentStep.initialStep = initialStep;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
exports.StateMachine = StateMachine;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/A/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGxC,eAAO,MAAM,aAAa,EAAE,MAa3B,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.STEP_A_STATES = void 0;
|
|
13
|
+
const utils_1 = require("../../utils");
|
|
14
|
+
exports.STEP_A_STATES = {
|
|
15
|
+
checkSearchRequest: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, next, goToNextValidationStage }) {
|
|
16
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "A", step: 1, stepName: "checkSearchRequest" });
|
|
17
|
+
if (context.params.type === 'search') {
|
|
18
|
+
return next('evaluateSearch');
|
|
19
|
+
}
|
|
20
|
+
return goToNextValidationStage();
|
|
21
|
+
}),
|
|
22
|
+
evaluateSearch: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, endValidation }) {
|
|
23
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "A", step: 2, stepName: "evaluateSearch" });
|
|
24
|
+
// NOTE -> we don't support search operations
|
|
25
|
+
return endValidation({ success: false });
|
|
26
|
+
})
|
|
27
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/B/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGxC,eAAO,MAAM,aAAa,EAAE,MAwB3B,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.STEP_B_STATES = void 0;
|
|
13
|
+
const commonValidators_1 = require("../../commonValidators");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
exports.STEP_B_STATES = {
|
|
16
|
+
checkDocumentsFilters: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, next, goToNextValidationStage }) {
|
|
17
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "B", step: 1, stepName: "checkDocumentsFilters" });
|
|
18
|
+
const { role } = context;
|
|
19
|
+
if (role.document_filters) {
|
|
20
|
+
return next('evaluateDocumentsFiltersRead');
|
|
21
|
+
}
|
|
22
|
+
return goToNextValidationStage();
|
|
23
|
+
}),
|
|
24
|
+
evaluateDocumentsFiltersRead: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, next, goToNextValidationStage }) {
|
|
25
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "B", step: 2, stepName: "evaluateDocumentsFiltersRead" });
|
|
26
|
+
const hasDocumentFiltersRead = yield (0, commonValidators_1.evaluateDocumentFiltersFn)(context, "read");
|
|
27
|
+
if (!hasDocumentFiltersRead)
|
|
28
|
+
return next('evaluateDocumentsFiltersWrite');
|
|
29
|
+
return goToNextValidationStage();
|
|
30
|
+
}),
|
|
31
|
+
evaluateDocumentsFiltersWrite: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, endValidation, goToNextValidationStage }) {
|
|
32
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "B", step: 3, stepName: "evaluateDocumentsFiltersWrite" });
|
|
33
|
+
const check = yield (0, commonValidators_1.evaluateDocumentFiltersFn)(context, "write");
|
|
34
|
+
return check ? goToNextValidationStage() : endValidation({ success: false });
|
|
35
|
+
})
|
|
36
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/C/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAIxC,eAAO,MAAM,aAAa,EAAE,MAuB3B,CAAA"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.STEP_C_STATES = void 0;
|
|
13
|
+
const commonValidators_1 = require("../../commonValidators");
|
|
14
|
+
const utils_1 = require("../../utils");
|
|
15
|
+
exports.STEP_C_STATES = {
|
|
16
|
+
evaluateTopLevelRead: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, next, endValidation }) {
|
|
17
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "C", step: 1, stepName: "evaluateTopLevelRead" });
|
|
18
|
+
const check = yield (0, commonValidators_1.evaluateTopLevelPermissionsFn)(context, "read");
|
|
19
|
+
return check
|
|
20
|
+
? endValidation({ success: true })
|
|
21
|
+
: next('evaluateTopLevelWrite', { check });
|
|
22
|
+
}),
|
|
23
|
+
evaluateTopLevelWrite: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, next, endValidation }) {
|
|
24
|
+
var _b;
|
|
25
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "C", step: 2, stepName: "evaluateTopLevelWrite" });
|
|
26
|
+
const check = yield (0, commonValidators_1.evaluateTopLevelPermissionsFn)(context, "write");
|
|
27
|
+
if (check)
|
|
28
|
+
return endValidation({ success: true });
|
|
29
|
+
return ((_b = context === null || context === void 0 ? void 0 : context.prevParams) === null || _b === void 0 ? void 0 : _b.check) === false
|
|
30
|
+
? endValidation({ success: false })
|
|
31
|
+
: next('checkFieldsProperty');
|
|
32
|
+
}),
|
|
33
|
+
checkFieldsProperty: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, goToNextValidationStage }) {
|
|
34
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "C", step: 3, stepName: "checkFieldsProperty" });
|
|
35
|
+
const check = (0, commonValidators_1.checkFieldsPropertyExists)(context);
|
|
36
|
+
return goToNextValidationStage(check ? 'checkIsValidFieldName' : 'checkAdditionalFields');
|
|
37
|
+
})
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/D/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAOxC,eAAO,MAAM,aAAa,EAAE,MAW3B,CAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.STEP_D_STATES = void 0;
|
|
13
|
+
const utils_1 = require("../../utils");
|
|
14
|
+
const validators_1 = require("./validators");
|
|
15
|
+
exports.STEP_D_STATES = {
|
|
16
|
+
checkAdditionalFields: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, next, endValidation }) {
|
|
17
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "D", step: 1, stepName: "checkAdditionalFields" });
|
|
18
|
+
const check = (0, validators_1.checkAdditionalFieldsFn)(context);
|
|
19
|
+
return check ? next('checkIsValidFieldName') : endValidation({ success: false });
|
|
20
|
+
}),
|
|
21
|
+
checkIsValidFieldName: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, endValidation }) {
|
|
22
|
+
(0, utils_1.logMachineInfo)({ enabled: context.enableLog, machine: "D", step: 2, stepName: "checkIsValidFieldName" });
|
|
23
|
+
const document = (0, validators_1.checkIsValidFieldNameFn)(context);
|
|
24
|
+
return endValidation({ success: !!Object.keys(document).length, document });
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/D/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGhD,eAAO,MAAM,uBAAuB,GAAI,UAAU,cAAc,YAE/D,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,kBAAkB,cAAc,OAgBvE,CAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkIsValidFieldNameFn = exports.checkAdditionalFieldsFn = void 0;
|
|
4
|
+
const checkAdditionalFieldsFn = ({ role }) => {
|
|
5
|
+
return !!Object.keys(role.additional_fields || {}).length;
|
|
6
|
+
};
|
|
7
|
+
exports.checkAdditionalFieldsFn = checkAdditionalFieldsFn;
|
|
8
|
+
const checkIsValidFieldNameFn = ({ role, params }) => {
|
|
9
|
+
const { cursor } = params;
|
|
10
|
+
const { fields = {}, additional_fields = {} } = role;
|
|
11
|
+
const rulesOnId = !!(fields["_id"] || additional_fields["_id"]);
|
|
12
|
+
const filteredDocument = Object.entries(cursor).reduce((filteredDocument, [key, value]) => {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
if (fields[key]) {
|
|
15
|
+
return (role.fields[key].read || role.fields[key].write) ? Object.assign(Object.assign({}, filteredDocument), { [key]: value }) : filteredDocument;
|
|
16
|
+
}
|
|
17
|
+
if (additional_fields[key]) {
|
|
18
|
+
return (((_a = additional_fields[key]) === null || _a === void 0 ? void 0 : _a.read) || ((_b = additional_fields[key]) === null || _b === void 0 ? void 0 : _b.write)) ? Object.assign(Object.assign({}, filteredDocument), { [key]: value }) : filteredDocument;
|
|
19
|
+
}
|
|
20
|
+
return Object.assign(Object.assign({}, filteredDocument), { [key]: value });
|
|
21
|
+
}, {});
|
|
22
|
+
return (rulesOnId || cursor._id === undefined) ? filteredDocument : Object.assign(Object.assign({}, filteredDocument), { "_id": cursor._id });
|
|
23
|
+
};
|
|
24
|
+
exports.checkIsValidFieldNameFn = checkIsValidFieldNameFn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/roles/machines/read/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,YAAY,iCAA+D,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.READ_MACHINE = void 0;
|
|
4
|
+
const A_1 = require("./A");
|
|
5
|
+
const B_1 = require("./B");
|
|
6
|
+
const C_1 = require("./C");
|
|
7
|
+
const D_1 = require("./D");
|
|
8
|
+
exports.READ_MACHINE = [A_1.STEP_A_STATES, B_1.STEP_B_STATES, C_1.STEP_C_STATES, D_1.STEP_D_STATES];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Document, OptionalId } from "mongodb";
|
|
2
|
+
import { User } from "../../../auth/dtos";
|
|
3
|
+
import { Role } from "../interface";
|
|
4
|
+
import { LogMachineInfoParams } from "./interface";
|
|
5
|
+
/**
|
|
6
|
+
* Determines the first applicable role for a given user and document.
|
|
7
|
+
*
|
|
8
|
+
* @param {OptionalId<Document> | null} document - The document to check against role conditions.
|
|
9
|
+
* @param {User} user - The user for whom the role is being determined.
|
|
10
|
+
* @param {Role[]} [roles=[]] - The list of available roles to evaluate.
|
|
11
|
+
*
|
|
12
|
+
* @returns {Role | null} - Returns the first role that matches the `apply_when` condition, or `null` if none match.
|
|
13
|
+
*/
|
|
14
|
+
export declare const getWinningRole: (document: OptionalId<Document> | null, user: User, roles?: Role[]) => Role | null;
|
|
15
|
+
/**
|
|
16
|
+
* Checks if the `apply_when` condition is valid for the given user and document.
|
|
17
|
+
*
|
|
18
|
+
* @param {Role["apply_when"]} apply_when - The rule condition to evaluate.
|
|
19
|
+
* @param {User} user - The user for whom the condition is being checked.
|
|
20
|
+
* @param {WithId<Document> | null} document - The document to check against the condition.
|
|
21
|
+
*
|
|
22
|
+
* @returns {boolean} - Returns `true` if at least one valid rule is found, otherwise `false`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const checkApplyWhen: (apply_when: Role["apply_when"], user: User, document: OptionalId<Document> | null) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Logs machine step information if logging is enabled.
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} params - The parameters for logging machine info.
|
|
29
|
+
* @param {boolean} params.enabled - Whether logging is enabled.
|
|
30
|
+
* @param {string} params.machine - The name of the machine.
|
|
31
|
+
* @param {number} params.step - The current step number.
|
|
32
|
+
* @param {string} params.stepName - The name of the current step.
|
|
33
|
+
*
|
|
34
|
+
* @returns {void}
|
|
35
|
+
*/
|
|
36
|
+
export declare const logMachineInfo: ({ enabled, machine, step, stepName }: LogMachineInfoParams) => void;
|
|
37
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/utils/roles/machines/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAG1C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,EAAE,MAAM,IAAI,EAAE,QAAO,IAAI,EAAO,KAAG,IAAI,GAAG,IAQ7G,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,YAAY,IAAI,CAAC,YAAY,CAAC,EAAE,MAAM,IAAI,EAAE,UAAU,UAAU,CAAC,QAAQ,CAAC,GAAG,IAAI,YAG/G,CAAA;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,GAAI,sCAAsC,oBAAoB,SAExF,CAAA"}
|