@flowerforce/flowerbase 1.2.0 → 1.2.1-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/controller.d.ts.map +1 -1
- package/dist/auth/controller.js +3 -0
- package/dist/auth/providers/custom-function/controller.d.ts.map +1 -1
- package/dist/auth/providers/custom-function/controller.js +5 -2
- package/dist/auth/providers/local-userpass/controller.d.ts.map +1 -1
- package/dist/auth/providers/local-userpass/controller.js +7 -10
- package/dist/auth/utils.d.ts +1 -1
- package/dist/auth/utils.d.ts.map +1 -1
- package/dist/auth/utils.js +4 -3
- package/dist/constants.d.ts +5 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +5 -1
- package/dist/features/functions/controller.d.ts.map +1 -1
- package/dist/features/functions/controller.js +28 -2
- package/dist/features/rules/utils.d.ts.map +1 -1
- package/dist/features/rules/utils.js +11 -2
- package/dist/features/triggers/utils.d.ts.map +1 -1
- package/dist/features/triggers/utils.js +52 -2
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/services/mongodb-atlas/index.d.ts.map +1 -1
- package/dist/services/mongodb-atlas/index.js +540 -483
- 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 +113 -23
- package/dist/shared/handleUserRegistration.d.ts.map +1 -1
- package/dist/shared/handleUserRegistration.js +1 -0
- package/dist/shared/models/handleUserRegistration.model.d.ts +6 -2
- package/dist/shared/models/handleUserRegistration.model.d.ts.map +1 -1
- package/dist/utils/context/helpers.d.ts +6 -5
- package/dist/utils/context/helpers.d.ts.map +1 -1
- package/dist/utils/context/helpers.js +3 -0
- package/dist/utils/context/index.d.ts.map +1 -1
- package/dist/utils/context/index.js +2 -0
- package/dist/utils/initializer/exposeRoutes.d.ts.map +1 -1
- package/dist/utils/initializer/exposeRoutes.js +11 -4
- package/dist/utils/initializer/registerPlugins.d.ts +3 -1
- package/dist/utils/initializer/registerPlugins.d.ts.map +1 -1
- package/dist/utils/initializer/registerPlugins.js +9 -6
- package/dist/utils/roles/helpers.js +9 -2
- package/dist/utils/roles/machines/commonValidators.d.ts.map +1 -1
- package/dist/utils/roles/machines/commonValidators.js +10 -6
- package/dist/utils/roles/machines/read/B/validators.d.ts +4 -0
- package/dist/utils/roles/machines/read/B/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/B/validators.js +8 -0
- package/dist/utils/roles/machines/read/C/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/C/index.js +10 -7
- package/dist/utils/roles/machines/read/C/validators.d.ts +5 -0
- package/dist/utils/roles/machines/read/C/validators.d.ts.map +1 -0
- package/dist/utils/roles/machines/read/C/validators.js +29 -0
- package/dist/utils/roles/machines/read/D/index.d.ts.map +1 -1
- package/dist/utils/roles/machines/read/D/index.js +13 -11
- package/dist/utils/rules.d.ts +1 -1
- package/dist/utils/rules.d.ts.map +1 -1
- package/dist/utils/rules.js +26 -17
- package/jest.config.ts +2 -12
- package/jest.setup.ts +28 -0
- package/package.json +1 -1
- package/src/auth/controller.ts +3 -0
- package/src/auth/providers/custom-function/controller.ts +5 -2
- package/src/auth/providers/local-userpass/controller.ts +13 -10
- package/src/auth/utils.ts +7 -4
- package/src/constants.ts +7 -2
- package/src/fastify.d.ts +32 -15
- package/src/features/functions/controller.ts +36 -2
- package/src/features/rules/utils.ts +11 -2
- package/src/features/triggers/utils.ts +59 -2
- package/src/index.ts +21 -8
- package/src/services/mongodb-atlas/__tests__/utils.test.ts +141 -0
- package/src/services/mongodb-atlas/index.ts +143 -90
- package/src/services/mongodb-atlas/utils.ts +158 -22
- package/src/shared/handleUserRegistration.ts +3 -3
- package/src/shared/models/handleUserRegistration.model.ts +8 -3
- package/src/types/fastify-raw-body.d.ts +22 -0
- package/src/utils/__tests__/STEP_B_STATES.test.ts +1 -1
- package/src/utils/__tests__/STEP_C_STATES.test.ts +1 -1
- package/src/utils/__tests__/STEP_D_STATES.test.ts +2 -2
- package/src/utils/__tests__/checkIsValidFieldNameFn.test.ts +9 -4
- package/src/utils/__tests__/registerPlugins.test.ts +16 -1
- package/src/utils/context/helpers.ts +3 -0
- package/src/utils/context/index.ts +1 -0
- package/src/utils/initializer/exposeRoutes.ts +15 -8
- package/src/utils/initializer/registerPlugins.ts +15 -7
- package/src/utils/roles/helpers.ts +20 -3
- package/src/utils/roles/machines/commonValidators.ts +10 -5
- package/src/utils/roles/machines/read/B/validators.ts +8 -0
- package/src/utils/roles/machines/read/C/index.ts +11 -7
- package/src/utils/roles/machines/read/C/validators.ts +21 -0
- package/src/utils/roles/machines/read/D/index.ts +22 -12
- package/src/utils/rules.ts +31 -22
- package/tsconfig.spec.json +7 -0
|
@@ -5,12 +5,14 @@ import { AggregationPipeline, Filter, Projection, Rules } from '../../features/r
|
|
|
5
5
|
import { Role } from '../../utils/roles/interface';
|
|
6
6
|
import { CRUD_OPERATIONS, GetValidRuleParams } from './model';
|
|
7
7
|
export declare const getValidRule: <T extends Role | Filter>({ filters, user, record }: GetValidRuleParams<T>) => T[];
|
|
8
|
-
export declare const getFormattedQuery: (filters: Filter[] | undefined, query: Parameters<Collection<Document>["findOne"]>[0], user?: User) =>
|
|
8
|
+
export declare const getFormattedQuery: (filters: Filter[] | undefined, query: Parameters<Collection<Document>["findOne"]>[0], user?: User) => FilterMongoDB<Document>[];
|
|
9
9
|
export declare const getFormattedProjection: (filters?: Filter[], user?: User) => Projection | null;
|
|
10
10
|
export declare const applyAccessControlToPipeline: (pipeline: AggregationPipeline, rules: Record<string, {
|
|
11
11
|
filters?: Filter[];
|
|
12
12
|
roles?: Role[];
|
|
13
|
-
}>, user: User
|
|
13
|
+
}>, user: User, collectionName: string, options?: {
|
|
14
|
+
isClientPipeline?: boolean;
|
|
15
|
+
}) => AggregationPipeline;
|
|
14
16
|
export declare const checkDenyOperation: (rules: Rules, collectionName: string, operation: CRUD_OPERATIONS) => void;
|
|
15
17
|
export declare function normalizeQuery(query: FilterMongoDB<Document>[]): {
|
|
16
18
|
[x: string]: any;
|
|
@@ -28,4 +30,9 @@ export declare function normalizeQuery(query: FilterMongoDB<Document>[]): {
|
|
|
28
30
|
$comment?: string | Document;
|
|
29
31
|
}[];
|
|
30
32
|
export declare const getCollectionsFromPipeline: (pipeline: Document[]) => string[];
|
|
33
|
+
export declare function ensureClientPipelineStages(pipeline: AggregationPipeline): void;
|
|
34
|
+
export declare function getHiddenFieldsFromRulesConfig(rulesConfig?: {
|
|
35
|
+
roles?: Role[];
|
|
36
|
+
}): string[];
|
|
37
|
+
export declare function prependUnsetStage(pipeline: AggregationPipeline, hiddenFields: string[]): AggregationPipeline;
|
|
31
38
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,SAAS,CAAA;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EACL,mBAAmB,EAEnB,MAAM,EAEN,UAAU,EACV,KAAK,EAGN,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAGlD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE7D,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,IAAI,GAAG,MAAM,EAAE,2BAInD,kBAAkB,CAAC,CAAC,CAAC,QA2BvB,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,EAAE,YAAK,EACtB,OAAO,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EACrD,OAAO,IAAI,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/services/mongodb-atlas/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,SAAS,CAAA;AACvE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EACL,mBAAmB,EAEnB,MAAM,EAEN,UAAU,EACV,KAAK,EAGN,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAGlD,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE7D,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,IAAI,GAAG,MAAM,EAAE,2BAInD,kBAAkB,CAAC,CAAC,CAAC,QA2BvB,CAAA;AAED,eAAO,MAAM,iBAAiB,GAC5B,SAAS,MAAM,EAAE,YAAK,EACtB,OAAO,UAAU,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,EACrD,OAAO,IAAI,8BAcZ,CAAA;AAED,eAAO,MAAM,sBAAsB,GACjC,UAAS,MAAM,EAAO,EACtB,OAAO,IAAI,KACV,UAAU,GAAG,IAaf,CAAA;AAED,eAAO,MAAM,4BAA4B,GACvC,UAAU,mBAAmB,EAC7B,OAAO,MAAM,CACX,MAAM,EACN;IACE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAA;IAClB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAA;CACf,CACF,EACD,MAAM,IAAI,EACV,gBAAgB,MAAM,EACtB,UAAU;IACR,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAC3B,KACA,mBA6GF,CAAA;AAED,eAAO,MAAM,kBAAkB,GAC7B,OAAO,KAAK,EACZ,gBAAgB,MAAM,EACtB,WAAW,eAAe,SAM3B,CAAA;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE;;;;;;;;iBA2Hs1rS,CAAC;sBAAgC,CAAC;2BAAsC,CAAC;;;;IAnH79rS;AAED,eAAO,MAAM,0BAA0B,GAAI,UAAU,QAAQ,EAAE,aAgC9D,CAAA;AAYD,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,mBAAmB,QA+BvE;AAED,wBAAgB,8BAA8B,CAAC,WAAW,CAAC,EAAE;IAAE,KAAK,CAAC,EAAE,IAAI,EAAE,CAAA;CAAE,YAK9E;AAyBD,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,EAAE,uBAKtF"}
|
|
@@ -5,10 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getCollectionsFromPipeline = exports.checkDenyOperation = exports.applyAccessControlToPipeline = exports.getFormattedProjection = exports.getFormattedQuery = exports.getValidRule = void 0;
|
|
7
7
|
exports.normalizeQuery = normalizeQuery;
|
|
8
|
+
exports.ensureClientPipelineStages = ensureClientPipelineStages;
|
|
9
|
+
exports.getHiddenFieldsFromRulesConfig = getHiddenFieldsFromRulesConfig;
|
|
10
|
+
exports.prependUnsetStage = prependUnsetStage;
|
|
8
11
|
const mongodb_1 = require("mongodb");
|
|
9
12
|
const interface_1 = require("../../features/rules/interface");
|
|
10
13
|
const rules_1 = require("../../utils/rules");
|
|
11
14
|
const utils_1 = __importDefault(require("../../utils/rules-matcher/utils"));
|
|
15
|
+
const model_1 = require("./model");
|
|
12
16
|
const getValidRule = ({ filters = [], user, record = null }) => {
|
|
13
17
|
if (!filters.length)
|
|
14
18
|
return [];
|
|
@@ -31,10 +35,14 @@ exports.getValidRule = getValidRule;
|
|
|
31
35
|
const getFormattedQuery = (filters = [], query, user) => {
|
|
32
36
|
const preFilter = (0, exports.getValidRule)({ filters, user });
|
|
33
37
|
const isValidPreFilter = !!(preFilter === null || preFilter === void 0 ? void 0 : preFilter.length);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
query
|
|
37
|
-
|
|
38
|
+
const formatted = [];
|
|
39
|
+
if (isValidPreFilter) {
|
|
40
|
+
formatted.push((0, rules_1.expandQuery)(preFilter[0].query, { '%%user': user }));
|
|
41
|
+
}
|
|
42
|
+
if (query && Object.keys(query).length > 0) {
|
|
43
|
+
formatted.push(query);
|
|
44
|
+
}
|
|
45
|
+
return formatted;
|
|
38
46
|
};
|
|
39
47
|
exports.getFormattedQuery = getFormattedQuery;
|
|
40
48
|
const getFormattedProjection = (filters = [], user) => {
|
|
@@ -53,49 +61,66 @@ const getFormattedProjection = (filters = [], user) => {
|
|
|
53
61
|
return Object.assign({}, ...projections);
|
|
54
62
|
};
|
|
55
63
|
exports.getFormattedProjection = getFormattedProjection;
|
|
56
|
-
const applyAccessControlToPipeline = (pipeline, rules, user) => {
|
|
64
|
+
const applyAccessControlToPipeline = (pipeline, rules, user, collectionName, options) => {
|
|
65
|
+
const { isClientPipeline = false } = options || {};
|
|
66
|
+
const hiddenFieldsForCollection = isClientPipeline
|
|
67
|
+
? getHiddenFieldsFromRulesConfig(rules[collectionName])
|
|
68
|
+
: [];
|
|
57
69
|
return pipeline.map((stage) => {
|
|
58
70
|
const [stageName] = Object.keys(stage);
|
|
59
71
|
const value = stage[stageName];
|
|
60
|
-
// CASE LOOKUP
|
|
61
72
|
if (stageName === interface_1.STAGES_TO_SEARCH.LOOKUP) {
|
|
62
73
|
const lookUpStage = value;
|
|
63
74
|
const currentCollection = lookUpStage.from;
|
|
75
|
+
(0, exports.checkDenyOperation)(rules, currentCollection, model_1.CRUD_OPERATIONS.READ);
|
|
64
76
|
const lookupRules = rules[currentCollection] || {};
|
|
65
77
|
const formattedQuery = (0, exports.getFormattedQuery)(lookupRules.filters, {}, user);
|
|
66
78
|
const projection = (0, exports.getFormattedProjection)(lookupRules.filters);
|
|
79
|
+
const nestedPipeline = (0, exports.applyAccessControlToPipeline)(lookUpStage.pipeline || [], rules, user, currentCollection, { isClientPipeline });
|
|
80
|
+
const lookupPipeline = [
|
|
81
|
+
...(formattedQuery.length ? [{ $match: { $and: formattedQuery } }] : []),
|
|
82
|
+
...(projection ? [{ $project: projection }] : []),
|
|
83
|
+
...nestedPipeline
|
|
84
|
+
];
|
|
85
|
+
const pipelineWithHiddenFields = isClientPipeline
|
|
86
|
+
? prependUnsetStage(lookupPipeline, getHiddenFieldsFromRulesConfig(lookupRules))
|
|
87
|
+
: lookupPipeline;
|
|
67
88
|
return {
|
|
68
|
-
$lookup: Object.assign(Object.assign({}, lookUpStage), { pipeline:
|
|
69
|
-
...(formattedQuery.length ? [{ $match: { $and: formattedQuery } }] : []),
|
|
70
|
-
...(projection ? [{ $project: projection }] : []),
|
|
71
|
-
...(0, exports.applyAccessControlToPipeline)(lookUpStage.pipeline || [], rules, user)
|
|
72
|
-
] })
|
|
89
|
+
$lookup: Object.assign(Object.assign({}, lookUpStage), { pipeline: pipelineWithHiddenFields })
|
|
73
90
|
};
|
|
74
91
|
}
|
|
75
|
-
// CASE LOOKUP
|
|
76
92
|
if (stageName === interface_1.STAGES_TO_SEARCH.UNION_WITH) {
|
|
77
93
|
const unionWithStage = value;
|
|
78
94
|
const isSimpleStage = typeof unionWithStage === 'string';
|
|
79
95
|
const currentCollection = isSimpleStage ? unionWithStage : unionWithStage.coll;
|
|
96
|
+
(0, exports.checkDenyOperation)(rules, currentCollection, model_1.CRUD_OPERATIONS.READ);
|
|
80
97
|
const unionRules = rules[currentCollection] || {};
|
|
81
98
|
const formattedQuery = (0, exports.getFormattedQuery)(unionRules.filters, {}, user);
|
|
82
99
|
const projection = (0, exports.getFormattedProjection)(unionRules.filters);
|
|
83
|
-
|
|
100
|
+
if (isSimpleStage) {
|
|
101
|
+
return stage;
|
|
102
|
+
}
|
|
103
|
+
const nestedPipeline = unionWithStage.pipeline || [];
|
|
104
|
+
const sanitizedNestedPipeline = (0, exports.applyAccessControlToPipeline)(nestedPipeline, rules, user, currentCollection, { isClientPipeline });
|
|
105
|
+
const unionPipeline = [
|
|
106
|
+
...(formattedQuery.length ? [{ $match: { $and: formattedQuery } }] : []),
|
|
107
|
+
...(projection ? [{ $project: projection }] : []),
|
|
108
|
+
...sanitizedNestedPipeline
|
|
109
|
+
];
|
|
110
|
+
const pipelineWithHiddenFields = isClientPipeline
|
|
111
|
+
? prependUnsetStage(unionPipeline, getHiddenFieldsFromRulesConfig(unionRules))
|
|
112
|
+
: unionPipeline;
|
|
84
113
|
return {
|
|
85
|
-
$unionWith: {
|
|
86
|
-
coll: currentCollection,
|
|
87
|
-
pipeline: [
|
|
88
|
-
...(formattedQuery.length ? [{ $match: { $and: formattedQuery } }] : []),
|
|
89
|
-
...(projection ? [{ $project: projection }] : []),
|
|
90
|
-
...(0, exports.applyAccessControlToPipeline)(nestedPipeline, rules, user)
|
|
91
|
-
]
|
|
92
|
-
}
|
|
114
|
+
$unionWith: Object.assign(Object.assign({}, unionWithStage), { pipeline: pipelineWithHiddenFields })
|
|
93
115
|
};
|
|
94
116
|
}
|
|
95
|
-
// CASE FACET
|
|
96
117
|
if (stageName === interface_1.STAGES_TO_SEARCH.FACET) {
|
|
97
118
|
const modifiedFacets = Object.fromEntries(Object.entries(value).map(([facetKey, facetPipeline]) => {
|
|
98
|
-
|
|
119
|
+
const sanitizedFacetPipeline = (0, exports.applyAccessControlToPipeline)(facetPipeline, rules, user, collectionName, { isClientPipeline });
|
|
120
|
+
const facetPipelineWithHiddenFields = isClientPipeline
|
|
121
|
+
? prependUnsetStage(sanitizedFacetPipeline, hiddenFieldsForCollection)
|
|
122
|
+
: sanitizedFacetPipeline;
|
|
123
|
+
return [facetKey, facetPipelineWithHiddenFields];
|
|
99
124
|
}));
|
|
100
125
|
return { $facet: modifiedFacets };
|
|
101
126
|
}
|
|
@@ -147,3 +172,68 @@ const getCollectionsFromPipeline = (pipeline) => {
|
|
|
147
172
|
}, []);
|
|
148
173
|
};
|
|
149
174
|
exports.getCollectionsFromPipeline = getCollectionsFromPipeline;
|
|
175
|
+
const CLIENT_STAGE_BLACKLIST = new Set([
|
|
176
|
+
'$replaceRoot',
|
|
177
|
+
'$merge',
|
|
178
|
+
'$out',
|
|
179
|
+
'$function',
|
|
180
|
+
'$where',
|
|
181
|
+
'$accumulator',
|
|
182
|
+
'$graphLookup'
|
|
183
|
+
]);
|
|
184
|
+
function ensureClientPipelineStages(pipeline) {
|
|
185
|
+
pipeline.forEach((stage) => {
|
|
186
|
+
const [stageName] = Object.keys(stage);
|
|
187
|
+
if (!stageName)
|
|
188
|
+
return;
|
|
189
|
+
if (CLIENT_STAGE_BLACKLIST.has(stageName)) {
|
|
190
|
+
throw new Error(`Stage ${stageName} is not allowed in client aggregate pipelines`);
|
|
191
|
+
}
|
|
192
|
+
const value = stage[stageName];
|
|
193
|
+
if (stageName === interface_1.STAGES_TO_SEARCH.LOOKUP) {
|
|
194
|
+
ensureClientPipelineStages(value.pipeline || []);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
if (stageName === interface_1.STAGES_TO_SEARCH.UNION_WITH) {
|
|
198
|
+
if (typeof value === 'string') {
|
|
199
|
+
throw new Error('$unionWith must provide a pipeline when called from the client');
|
|
200
|
+
}
|
|
201
|
+
const unionStage = value;
|
|
202
|
+
ensureClientPipelineStages(unionStage.pipeline || []);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (stageName === interface_1.STAGES_TO_SEARCH.FACET) {
|
|
206
|
+
Object.values(value).forEach((facetPipeline) => ensureClientPipelineStages(facetPipeline));
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
function getHiddenFieldsFromRulesConfig(rulesConfig) {
|
|
211
|
+
if (!rulesConfig) {
|
|
212
|
+
return [];
|
|
213
|
+
}
|
|
214
|
+
return collectHiddenFieldsFromRoles(rulesConfig.roles);
|
|
215
|
+
}
|
|
216
|
+
function collectHiddenFieldsFromRoles(roles = []) {
|
|
217
|
+
const hiddenFields = new Set();
|
|
218
|
+
const collectFromFields = (fields) => {
|
|
219
|
+
if (!fields)
|
|
220
|
+
return;
|
|
221
|
+
Object.entries(fields).forEach(([fieldName, permissions]) => {
|
|
222
|
+
const canRead = Boolean((permissions === null || permissions === void 0 ? void 0 : permissions.read) || (permissions === null || permissions === void 0 ? void 0 : permissions.write));
|
|
223
|
+
if (!canRead) {
|
|
224
|
+
hiddenFields.add(fieldName);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
};
|
|
228
|
+
roles.forEach((role) => {
|
|
229
|
+
collectFromFields(role.fields);
|
|
230
|
+
collectFromFields(role.additional_fields);
|
|
231
|
+
});
|
|
232
|
+
return Array.from(hiddenFields);
|
|
233
|
+
}
|
|
234
|
+
function prependUnsetStage(pipeline, hiddenFields) {
|
|
235
|
+
if (!hiddenFields.length) {
|
|
236
|
+
return pipeline;
|
|
237
|
+
}
|
|
238
|
+
return [{ $unset: hiddenFields }, ...pipeline];
|
|
239
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleUserRegistration.d.ts","sourceRoot":"","sources":["../../src/shared/handleUserRegistration.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handleUserRegistration.d.ts","sourceRoot":"","sources":["../../src/shared/handleUserRegistration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAA;AAE9E;;;;;;GAMG;AACH,QAAA,MAAM,sBAAsB,EAAE,sBAmD7B,CAAA;AAED,eAAe,sBAAsB,CAAA"}
|
|
@@ -35,6 +35,7 @@ const handleUserRegistration = (app, opt) => (_a) => __awaiter(void 0, [_a], voi
|
|
|
35
35
|
email,
|
|
36
36
|
password: hashedPassword,
|
|
37
37
|
status: skipUserCheck ? 'confirmed' : 'pending',
|
|
38
|
+
createdAt: new Date(),
|
|
38
39
|
custom_data: {
|
|
39
40
|
// TODO: aggiungere dati personalizzati alla registrazione
|
|
40
41
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { FastifyInstance } from "fastify/types/instance";
|
|
2
|
-
import { InsertOneResult } from "mongodb/mongodb";
|
|
3
2
|
import { User } from "../../auth/dtos";
|
|
4
3
|
import { Rules } from "../../features/rules/interface";
|
|
5
4
|
type RegistrationParams = {
|
|
@@ -13,7 +12,12 @@ export type Options = {
|
|
|
13
12
|
provider?: PROVIDER;
|
|
14
13
|
run_as_system?: boolean;
|
|
15
14
|
};
|
|
16
|
-
|
|
15
|
+
type RegistrationResult = {
|
|
16
|
+
insertedId?: {
|
|
17
|
+
toString: () => string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type HandleUserRegistration = (app: FastifyInstance, opt: Options) => (params: RegistrationParams) => Promise<RegistrationResult>;
|
|
17
21
|
export declare enum PROVIDER {
|
|
18
22
|
LOCAL_USERPASS = "local-userpass",
|
|
19
23
|
CUSTOM_FUNCTION = "custom-function"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleUserRegistration.model.d.ts","sourceRoot":"","sources":["../../../src/shared/models/handleUserRegistration.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"handleUserRegistration.model.d.ts","sourceRoot":"","sources":["../../../src/shared/models/handleUserRegistration.model.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAA;AAEtD,KAAK,kBAAkB,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,CAAC,EAAE,IAAI,CAAA;IACX,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,aAAa,CAAC,EAAE,OAAO,CAAA;CACxB,CAAA;AAED,KAAK,kBAAkB,GAAG;IACxB,UAAU,CAAC,EAAE;QACX,QAAQ,EAAE,MAAM,MAAM,CAAA;KACvB,CAAA;CACF,CAAA;AAED,MAAM,MAAM,sBAAsB,GAAG,CACnC,GAAG,EAAE,eAAe,EACpB,GAAG,EAAE,OAAO,KACT,CAAC,MAAM,EAAE,kBAAkB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAA;AAEhE,oBAAY,QAAQ;IAClB,cAAc,mBAAmB;IACjC,eAAe,oBAAoB;CACpC"}
|
|
@@ -15,14 +15,15 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
15
15
|
BSON: typeof mongodb.BSON;
|
|
16
16
|
console: {
|
|
17
17
|
log: (...args: Arguments) => void;
|
|
18
|
+
error: (...args: Arguments) => void;
|
|
18
19
|
};
|
|
19
20
|
context: {
|
|
20
21
|
request: {
|
|
21
22
|
remoteIPAddress: string | undefined;
|
|
22
|
-
id?: string | undefined;
|
|
23
23
|
method?: string | undefined;
|
|
24
24
|
url?: string | undefined;
|
|
25
25
|
host?: string | undefined;
|
|
26
|
+
id?: string | undefined;
|
|
26
27
|
ips?: string[];
|
|
27
28
|
hostname?: string | undefined;
|
|
28
29
|
ip?: string | undefined;
|
|
@@ -36,6 +37,10 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
36
37
|
};
|
|
37
38
|
services: {
|
|
38
39
|
get: (serviceName: keyof typeof services) => {
|
|
40
|
+
db: (dbName: string) => {
|
|
41
|
+
collection: (collName: string) => ReturnType<import("../../services/mongodb-atlas/model").GetOperatorsFunction>;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
39
44
|
get: <T = null>({ url, headers }: import("../../services/api/model").GetParams) => Promise<{
|
|
40
45
|
status: number;
|
|
41
46
|
headers: import("undici/types/header").IncomingHttpHeaders;
|
|
@@ -74,10 +79,6 @@ export declare const generateContextData: ({ user, services, app, rules, current
|
|
|
74
79
|
InvokeAsync: import("aws-sdk").Lambda["invokeAsync"];
|
|
75
80
|
};
|
|
76
81
|
s3: (region: string) => import("aws-sdk").S3;
|
|
77
|
-
} | {
|
|
78
|
-
db: (dbName: string) => {
|
|
79
|
-
collection: (collName: string) => ReturnType<import("../../services/mongodb-atlas/model").GetOperatorsFunction>;
|
|
80
|
-
};
|
|
81
82
|
} | undefined;
|
|
82
83
|
};
|
|
83
84
|
functions: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;uBAGT,SAAS;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/utils/context/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAA;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAAI,0FASjC,yBAAyB;;;uBAGT,SAAS;yBAGP,SAAS;;;;;;;;;;;;;;;;;;uBAcb,MAAM;;;+BAGE,MAAM,OAAO,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAlCG,GAE3C;;;;;;;4BAiDgB,MAAM,OAAO,aAAa,WAAW,SAAS;;;CAclE,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/context/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,EACpC,IAAI,EACJ,GAAG,EACH,KAAK,EACL,IAAI,EACJ,eAAe,EACf,aAAa,EACb,QAAQ,EACR,WAAW,EACX,eAAsB,EACtB,OAAO,EACP,OAAO,EACR,EAAE,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/context/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAEnD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,EACpC,IAAI,EACJ,GAAG,EACH,KAAK,EACL,IAAI,EACJ,eAAe,EACf,aAAa,EACb,QAAQ,EACR,WAAW,EACX,eAAsB,EACtB,OAAO,EACP,OAAO,EACR,EAAE,qBAAqB,gBA4CvB"}
|
|
@@ -31,6 +31,8 @@ const helpers_1 = require("./helpers");
|
|
|
31
31
|
*/
|
|
32
32
|
function GenerateContext(_a) {
|
|
33
33
|
return __awaiter(this, arguments, void 0, function* ({ args, app, rules, user, currentFunction, functionsList, services, runAsSystem, deserializeArgs = true, enqueue, request }) {
|
|
34
|
+
if (!currentFunction)
|
|
35
|
+
return;
|
|
34
36
|
const functionsQueue = state_1.StateManager.select("functionsQueue");
|
|
35
37
|
const functionToRun = Object.assign({ run_as_system: runAsSystem }, currentFunction);
|
|
36
38
|
const run = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exposeRoutes.d.ts","sourceRoot":"","sources":["../../../src/utils/initializer/exposeRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzC;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,SAAS,eAAe,
|
|
1
|
+
{"version":3,"file":"exposeRoutes.d.ts","sourceRoot":"","sources":["../../../src/utils/initializer/exposeRoutes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAOzC;;;;GAIG;AACH,eAAO,MAAM,YAAY,GAAU,SAAS,eAAe,kBA0E1D,CAAA"}
|
|
@@ -23,12 +23,19 @@ const crypto_1 = require("../crypto");
|
|
|
23
23
|
const exposeRoutes = (fastify) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
24
|
try {
|
|
25
25
|
fastify.get(`${constants_1.API_VERSION}/app/:appId/location`, (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
-
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
const schema = (_a = constants_1.DEFAULT_CONFIG === null || constants_1.DEFAULT_CONFIG === void 0 ? void 0 : constants_1.DEFAULT_CONFIG.HTTPS_SCHEMA) !== null && _a !== void 0 ? _a : 'http';
|
|
28
|
+
const headerHost = (_b = req.headers.host) !== null && _b !== void 0 ? _b : 'localhost:3000';
|
|
29
|
+
const hostname = headerHost.split(':')[0];
|
|
30
|
+
const port = (_c = constants_1.DEFAULT_CONFIG === null || constants_1.DEFAULT_CONFIG === void 0 ? void 0 : constants_1.DEFAULT_CONFIG.PORT) !== null && _c !== void 0 ? _c : 3000;
|
|
31
|
+
const host = `${hostname}:${port}`;
|
|
32
|
+
const wsSchema = 'wss';
|
|
33
|
+
return {
|
|
27
34
|
deployment_model: 'LOCAL',
|
|
28
35
|
location: 'IE',
|
|
29
|
-
hostname: `${
|
|
30
|
-
ws_hostname: `${
|
|
31
|
-
}
|
|
36
|
+
hostname: `${schema}://${host}`,
|
|
37
|
+
ws_hostname: `${wsSchema}://${host}`
|
|
38
|
+
};
|
|
32
39
|
}));
|
|
33
40
|
fastify.get('/health', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
41
|
return ({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import { CorsConfig } from '../../';
|
|
2
3
|
import { Functions } from '../../features/functions/interface';
|
|
3
4
|
type RegisterFunction = FastifyInstance['register'];
|
|
4
5
|
type RegisterPluginsParams = {
|
|
@@ -6,6 +7,7 @@ type RegisterPluginsParams = {
|
|
|
6
7
|
mongodbUrl: string;
|
|
7
8
|
jwtSecret: string;
|
|
8
9
|
functionsList: Functions;
|
|
10
|
+
corsConfig?: CorsConfig;
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
13
|
* > Used to register all plugins
|
|
@@ -14,6 +16,6 @@ type RegisterPluginsParams = {
|
|
|
14
16
|
* @param jwtSecret -> connection jwt
|
|
15
17
|
* @tested
|
|
16
18
|
*/
|
|
17
|
-
export declare const registerPlugins: ({ register, mongodbUrl, jwtSecret, functionsList }: RegisterPluginsParams) => Promise<void>;
|
|
19
|
+
export declare const registerPlugins: ({ register, mongodbUrl, jwtSecret, functionsList, corsConfig }: RegisterPluginsParams) => Promise<void>;
|
|
18
20
|
export {};
|
|
19
21
|
//# sourceMappingURL=registerPlugins.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerPlugins.d.ts","sourceRoot":"","sources":["../../../src/utils/initializer/registerPlugins.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"registerPlugins.d.ts","sourceRoot":"","sources":["../../../src/utils/initializer/registerPlugins.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAEzC,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAMnC,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAA;AAE9D,KAAK,gBAAgB,GAAG,eAAe,CAAC,UAAU,CAAC,CAAA;AAGnD,KAAK,qBAAqB,GAAG;IAC3B,QAAQ,EAAE,gBAAgB,CAAA;IAC1B,UAAU,EAAE,MAAM,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,SAAS,CAAA;IACxB,UAAU,CAAC,EAAE,UAAU,CAAA;CACxB,CAAA;AAQD;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,GAAU,gEAMnC,qBAAqB,kBAsBvB,CAAA"}
|
|
@@ -28,11 +28,12 @@ const constants_1 = require("../../constants");
|
|
|
28
28
|
* @param jwtSecret -> connection jwt
|
|
29
29
|
* @tested
|
|
30
30
|
*/
|
|
31
|
-
const registerPlugins = (_a) => __awaiter(void 0, [_a], void 0, function* ({ register, mongodbUrl, jwtSecret, functionsList }) {
|
|
31
|
+
const registerPlugins = (_a) => __awaiter(void 0, [_a], void 0, function* ({ register, mongodbUrl, jwtSecret, functionsList, corsConfig }) {
|
|
32
32
|
try {
|
|
33
33
|
const registersConfig = yield getRegisterConfig({
|
|
34
34
|
mongodbUrl,
|
|
35
35
|
jwtSecret,
|
|
36
|
+
corsConfig,
|
|
36
37
|
functionsList
|
|
37
38
|
});
|
|
38
39
|
registersConfig.forEach(({ plugin, options, pluginName }) => {
|
|
@@ -43,6 +44,7 @@ const registerPlugins = (_a) => __awaiter(void 0, [_a], void 0, function* ({ reg
|
|
|
43
44
|
catch (e) {
|
|
44
45
|
console.log('Registration FAILED --->', pluginName);
|
|
45
46
|
console.log('Error --->', e);
|
|
47
|
+
throw e;
|
|
46
48
|
}
|
|
47
49
|
});
|
|
48
50
|
}
|
|
@@ -57,15 +59,16 @@ exports.registerPlugins = registerPlugins;
|
|
|
57
59
|
* @param jwtSecret -> connection jwt
|
|
58
60
|
* @testable
|
|
59
61
|
*/
|
|
60
|
-
const getRegisterConfig = (_a) => __awaiter(void 0, [_a], void 0, function* ({ mongodbUrl, jwtSecret }) {
|
|
62
|
+
const getRegisterConfig = (_a) => __awaiter(void 0, [_a], void 0, function* ({ mongodbUrl, jwtSecret, corsConfig }) {
|
|
63
|
+
const corsOptions = corsConfig !== null && corsConfig !== void 0 ? corsConfig : {
|
|
64
|
+
origin: '*',
|
|
65
|
+
methods: ['POST', 'GET']
|
|
66
|
+
};
|
|
61
67
|
return [
|
|
62
68
|
{
|
|
63
69
|
pluginName: 'cors',
|
|
64
70
|
plugin: cors_1.default,
|
|
65
|
-
options:
|
|
66
|
-
origin: '*',
|
|
67
|
-
methods: ['POST', 'GET', 'DELETE']
|
|
68
|
-
}
|
|
71
|
+
options: corsOptions
|
|
69
72
|
},
|
|
70
73
|
{
|
|
71
74
|
pluginName: 'fastifyMongodb',
|
|
@@ -31,13 +31,20 @@ const evaluateExpression = (params, expression, user) => __awaiter(void 0, void
|
|
|
31
31
|
});
|
|
32
32
|
exports.evaluateExpression = evaluateExpression;
|
|
33
33
|
const evaluateComplexExpression = (condition, params, user) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
var _a;
|
|
34
35
|
const [key, config] = condition;
|
|
35
|
-
const
|
|
36
|
+
const functionConfig = config['%function'];
|
|
37
|
+
const { name, arguments: fnArguments } = functionConfig;
|
|
36
38
|
const functionsList = state_1.StateManager.select('functions');
|
|
37
39
|
const app = state_1.StateManager.select('app');
|
|
38
40
|
const currentFunction = functionsList[name];
|
|
41
|
+
const expansionContext = Object.assign(Object.assign(Object.assign({}, params.expansions), params.cursor), { '%%root': params.cursor, '%%user': user, '%%true': true, '%%false': false });
|
|
42
|
+
const expandedArguments = fnArguments && fnArguments.length
|
|
43
|
+
? ((_a = (0, rules_1.expandQuery)({ args: fnArguments }, expansionContext)
|
|
44
|
+
.args) !== null && _a !== void 0 ? _a : [])
|
|
45
|
+
: [params.cursor];
|
|
39
46
|
const response = yield (0, context_1.GenerateContext)({
|
|
40
|
-
args:
|
|
47
|
+
args: expandedArguments,
|
|
41
48
|
app,
|
|
42
49
|
rules: state_1.StateManager.select("rules"),
|
|
43
50
|
user,
|
|
@@ -1 +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,GACpC,wBAAwB,cAAc,EACtC,aAAa,MAAM,0BAA0B,qBAS9C,CAAA;AAED,eAAO,MAAM,6BAA6B,GACxC,wBAAwB,cAAc,EACtC,aAAa,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,
|
|
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,GACpC,wBAAwB,cAAc,EACtC,aAAa,MAAM,0BAA0B,qBAS9C,CAAA;AAED,eAAO,MAAM,6BAA6B,GACxC,wBAAwB,cAAc,EACtC,aAAa,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,iCAQ9C,CAAA;AAED,eAAO,MAAM,yBAAyB,GAAI,UAAU,cAAc,YAIjE,CAAA"}
|
|
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.checkFieldsPropertyExists = exports.evaluateTopLevelPermissionsFn = exports.evaluateDocumentFiltersFn = void 0;
|
|
13
13
|
const someAsync_1 = require("../../helpers/someAsync");
|
|
14
14
|
const helpers_1 = require("../helpers");
|
|
15
|
-
const readOnlyPermissions = ['read'];
|
|
15
|
+
const readOnlyPermissions = ['read', 'search'];
|
|
16
16
|
const readWritePermissions = ['write', 'delete', 'insert', ...readOnlyPermissions];
|
|
17
17
|
const evaluateDocumentFiltersFn = (_a, currentType_1) => __awaiter(void 0, [_a, currentType_1], void 0, function* ({ params, role, user }, currentType) {
|
|
18
18
|
var _b;
|
|
@@ -21,13 +21,17 @@ const evaluateDocumentFiltersFn = (_a, currentType_1) => __awaiter(void 0, [_a,
|
|
|
21
21
|
});
|
|
22
22
|
exports.evaluateDocumentFiltersFn = evaluateDocumentFiltersFn;
|
|
23
23
|
const evaluateTopLevelPermissionsFn = (_a, currentType_1) => __awaiter(void 0, [_a, currentType_1], void 0, function* ({ params, role, user }, currentType) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const permission = role === null || role === void 0 ? void 0 : role[currentType];
|
|
25
|
+
if (typeof permission === 'undefined') {
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
return yield (0, helpers_1.evaluateExpression)(params, permission, user);
|
|
27
29
|
});
|
|
28
30
|
exports.evaluateTopLevelPermissionsFn = evaluateTopLevelPermissionsFn;
|
|
29
31
|
const checkFieldsPropertyExists = ({ role }) => {
|
|
30
|
-
var _a;
|
|
31
|
-
|
|
32
|
+
var _a, _b;
|
|
33
|
+
const hasFields = !!Object.keys((_a = role === null || role === void 0 ? void 0 : role.fields) !== null && _a !== void 0 ? _a : {}).length;
|
|
34
|
+
const hasAdditional = !!Object.keys((_b = role === null || role === void 0 ? void 0 : role.additional_fields) !== null && _b !== void 0 ? _b : {}).length;
|
|
35
|
+
return hasFields || hasAdditional;
|
|
32
36
|
};
|
|
33
37
|
exports.checkFieldsPropertyExists = checkFieldsPropertyExists;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { MachineContext } from '../../interface';
|
|
2
|
+
export declare const evaluateDocumentFiltersReadFn: (context: MachineContext) => Promise<boolean>;
|
|
3
|
+
export declare const evaluateDocumentFiltersWriteFn: (context: MachineContext) => Promise<boolean>;
|
|
4
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/B/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGhD,eAAO,MAAM,6BAA6B,GAAI,SAAS,cAAc,qBACzB,CAAA;AAE5C,eAAO,MAAM,8BAA8B,GAAI,SAAS,cAAc,qBACzB,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateDocumentFiltersWriteFn = exports.evaluateDocumentFiltersReadFn = void 0;
|
|
4
|
+
const commonValidators_1 = require("../../commonValidators");
|
|
5
|
+
const evaluateDocumentFiltersReadFn = (context) => (0, commonValidators_1.evaluateDocumentFiltersFn)(context, 'read');
|
|
6
|
+
exports.evaluateDocumentFiltersReadFn = evaluateDocumentFiltersReadFn;
|
|
7
|
+
const evaluateDocumentFiltersWriteFn = (context) => (0, commonValidators_1.evaluateDocumentFiltersFn)(context, 'write');
|
|
8
|
+
exports.evaluateDocumentFiltersWriteFn = evaluateDocumentFiltersWriteFn;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/C/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/C/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAGxC,eAAO,MAAM,aAAa,EAAE,MAyC3B,CAAA"}
|
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.STEP_C_STATES = void 0;
|
|
13
|
-
const
|
|
13
|
+
const validators_1 = require("./validators");
|
|
14
14
|
const utils_1 = require("../../utils");
|
|
15
15
|
exports.STEP_C_STATES = {
|
|
16
16
|
evaluateTopLevelRead: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, next, endValidation }) {
|
|
@@ -20,10 +20,13 @@ exports.STEP_C_STATES = {
|
|
|
20
20
|
step: 1,
|
|
21
21
|
stepName: 'evaluateTopLevelRead'
|
|
22
22
|
});
|
|
23
|
-
const check = yield (0,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const check = yield (0, validators_1.evaluateTopLevelReadFn)(context);
|
|
24
|
+
if (check) {
|
|
25
|
+
return (0, validators_1.checkFieldsPropertyExists)(context)
|
|
26
|
+
? next('checkFieldsProperty')
|
|
27
|
+
: endValidation({ success: true });
|
|
28
|
+
}
|
|
29
|
+
return next('evaluateTopLevelWrite', { check });
|
|
27
30
|
}),
|
|
28
31
|
evaluateTopLevelWrite: (_a) => __awaiter(void 0, [_a], void 0, function* ({ context, next, endValidation }) {
|
|
29
32
|
var _b;
|
|
@@ -33,7 +36,7 @@ exports.STEP_C_STATES = {
|
|
|
33
36
|
step: 2,
|
|
34
37
|
stepName: 'evaluateTopLevelWrite'
|
|
35
38
|
});
|
|
36
|
-
const check = yield (0,
|
|
39
|
+
const check = yield (0, validators_1.evaluateTopLevelWriteFn)(context);
|
|
37
40
|
if (check)
|
|
38
41
|
return endValidation({ success: true });
|
|
39
42
|
return ((_b = context === null || context === void 0 ? void 0 : context.prevParams) === null || _b === void 0 ? void 0 : _b.check) === false
|
|
@@ -47,7 +50,7 @@ exports.STEP_C_STATES = {
|
|
|
47
50
|
step: 3,
|
|
48
51
|
stepName: 'checkFieldsProperty'
|
|
49
52
|
});
|
|
50
|
-
const check = (0,
|
|
53
|
+
const check = (0, validators_1.checkFieldsPropertyExists)(context);
|
|
51
54
|
return goToNextValidationStage(check ? 'checkIsValidFieldName' : 'checkAdditionalFields');
|
|
52
55
|
})
|
|
53
56
|
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { MachineContext } from '../../interface';
|
|
2
|
+
export declare const evaluateTopLevelReadFn: (context: MachineContext) => Promise<boolean | undefined>;
|
|
3
|
+
export declare const evaluateTopLevelWriteFn: (context: MachineContext) => Promise<boolean | undefined>;
|
|
4
|
+
export { checkFieldsPropertyExists } from '../../commonValidators';
|
|
5
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/C/validators.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAMhD,eAAO,MAAM,sBAAsB,GAAU,SAAS,cAAc,iCAKnE,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAU,SAAS,cAAc,iCAKpE,CAAA;AAED,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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.evaluateTopLevelWriteFn = exports.evaluateTopLevelReadFn = void 0;
|
|
13
|
+
const commonValidators_1 = require("../../commonValidators");
|
|
14
|
+
const evaluateTopLevelReadFn = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
if (context.params.type !== 'read') {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
return (0, commonValidators_1.evaluateTopLevelPermissionsFn)(context, 'read');
|
|
19
|
+
});
|
|
20
|
+
exports.evaluateTopLevelReadFn = evaluateTopLevelReadFn;
|
|
21
|
+
const evaluateTopLevelWriteFn = (context) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
if (!['read', 'write'].includes(context.params.type)) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
return (0, commonValidators_1.evaluateTopLevelPermissionsFn)(context, 'write');
|
|
26
|
+
});
|
|
27
|
+
exports.evaluateTopLevelWriteFn = evaluateTopLevelWriteFn;
|
|
28
|
+
var commonValidators_2 = require("../../commonValidators");
|
|
29
|
+
Object.defineProperty(exports, "checkFieldsPropertyExists", { enumerable: true, get: function () { return commonValidators_2.checkFieldsPropertyExists; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/D/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/utils/roles/machines/read/D/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAqBxD,eAAO,MAAM,aAAa,EAAE,MAa3B,CAAA"}
|