@autofleet/sadot 1.6.18-beta.2 → 1.6.18-beta.21
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/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.cjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js +10 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js +7 -0
- package/dist/_virtual/rolldown_runtime.cjs +43 -0
- package/dist/{chunk-DJulfCLt.js → _virtual/rolldown_runtime.js} +1 -2
- package/dist/api/index.cjs +12 -0
- package/dist/api/index.js +11 -0
- package/dist/api/v1/definition/index.cjs +113 -0
- package/dist/api/v1/definition/index.js +112 -0
- package/dist/api/v1/definition/validations.cjs +128 -0
- package/dist/api/v1/definition/validations.js +125 -0
- package/dist/api/v1/errors.cjs +14 -0
- package/dist/api/v1/errors.js +13 -0
- package/dist/api/v1/field-policies/index.cjs +104 -0
- package/dist/api/v1/field-policies/index.js +103 -0
- package/dist/api/v1/index.cjs +16 -0
- package/dist/api/v1/index.js +15 -0
- package/dist/api/v1/validator/index.cjs +132 -0
- package/dist/api/v1/validator/index.js +131 -0
- package/dist/api/v1/validator/validations.cjs +40 -0
- package/dist/api/v1/validator/validations.d.cts +22 -0
- package/dist/api/v1/validator/validations.d.ts +22 -0
- package/dist/api/v1/validator/validations.js +38 -0
- package/dist/errors/index.cjs +62 -0
- package/dist/errors/index.js +55 -0
- package/dist/events/index.cjs +52 -0
- package/dist/events/index.js +50 -0
- package/dist/hooks/enrich.cjs +175 -0
- package/dist/hooks/enrich.js +175 -0
- package/dist/hooks/find.cjs +22 -0
- package/dist/hooks/find.js +22 -0
- package/dist/hooks/hooks.cjs +310 -0
- package/dist/hooks/hooks.js +302 -0
- package/dist/hooks/index.cjs +3 -0
- package/dist/hooks/index.js +5 -0
- package/dist/hooks/utils/updateInstanceValues.cjs +27 -0
- package/dist/hooks/utils/updateInstanceValues.js +27 -0
- package/dist/index.cjs +48 -33508
- package/dist/index.d.cts +13 -396
- package/dist/index.d.ts +14 -394
- package/dist/index.js +21 -33435
- package/dist/init-state.cjs +56 -0
- package/dist/init-state.d.cts +35 -0
- package/dist/init-state.d.ts +35 -0
- package/dist/init-state.js +55 -0
- package/dist/mat-path-state.cjs +10 -0
- package/dist/mat-path-state.js +9 -0
- package/dist/migrations/001-create-core-tables.cjs +70 -0
- package/dist/migrations/001-create-core-tables.js +68 -0
- package/dist/migrations/002-create-custom-field-entries.cjs +27 -0
- package/dist/migrations/002-create-custom-field-entries.js +25 -0
- package/dist/migrations/003-create-custom-field-model-type-map.cjs +35 -0
- package/dist/migrations/003-create-custom-field-model-type-map.js +33 -0
- package/dist/migrations/004-create-field-policy-tables.cjs +29 -0
- package/dist/migrations/004-create-field-policy-tables.js +27 -0
- package/dist/migrations/005-add-entity-type-to-field-policies.cjs +20 -0
- package/dist/migrations/005-add-entity-type-to-field-policies.js +18 -0
- package/dist/migrations/index.cjs +94 -0
- package/dist/migrations/index.js +95 -0
- package/dist/models/CustomFieldDefinition.cjs +147 -0
- package/dist/models/CustomFieldDefinition.d.cts +40 -0
- package/dist/models/CustomFieldDefinition.d.ts +40 -0
- package/dist/models/CustomFieldDefinition.js +146 -0
- package/dist/models/CustomFieldEntries.cjs +71 -0
- package/dist/models/CustomFieldEntries.d.cts +15 -0
- package/dist/models/CustomFieldEntries.d.ts +15 -0
- package/dist/models/CustomFieldEntries.js +70 -0
- package/dist/models/CustomFieldModelTypeMap.cjs +62 -0
- package/dist/models/CustomFieldModelTypeMap.d.cts +14 -0
- package/dist/models/CustomFieldModelTypeMap.d.ts +14 -0
- package/dist/models/CustomFieldModelTypeMap.js +61 -0
- package/dist/models/CustomFieldValue.cjs +109 -0
- package/dist/models/CustomFieldValue.d.cts +20 -0
- package/dist/models/CustomFieldValue.d.ts +20 -0
- package/dist/models/CustomFieldValue.js +108 -0
- package/dist/models/CustomValidator.cjs +68 -0
- package/dist/models/CustomValidator.d.cts +18 -0
- package/dist/models/CustomValidator.d.ts +18 -0
- package/dist/models/CustomValidator.js +67 -0
- package/dist/models/FieldPolicy.cjs +54 -0
- package/dist/models/FieldPolicy.d.cts +25 -0
- package/dist/models/FieldPolicy.d.ts +25 -0
- package/dist/models/FieldPolicy.js +53 -0
- package/dist/models/index.cjs +163 -0
- package/dist/models/index.d.ts +11 -0
- package/dist/models/index.js +161 -0
- package/dist/models/tests/AssociatedTestModel.cjs +51 -0
- package/dist/models/tests/AssociatedTestModel.d.ts +2 -0
- package/dist/models/tests/AssociatedTestModel.js +50 -0
- package/dist/models/tests/TestModel.cjs +43 -0
- package/dist/models/tests/TestModel.d.ts +2 -0
- package/dist/models/tests/TestModel.js +42 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +35 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +34 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +33 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +32 -0
- package/dist/repository/definition.cjs +221 -0
- package/dist/repository/definition.js +212 -0
- package/dist/repository/entries.cjs +69 -0
- package/dist/repository/entries.js +67 -0
- package/dist/repository/field-policy.cjs +69 -0
- package/dist/repository/field-policy.d.cts +35 -0
- package/dist/repository/field-policy.d.ts +35 -0
- package/dist/repository/field-policy.js +59 -0
- package/dist/repository/utils/formatValues.cjs +14 -0
- package/dist/repository/utils/formatValues.js +14 -0
- package/dist/repository/validator.cjs +85 -0
- package/dist/repository/validator.js +78 -0
- package/dist/repository/value.cjs +77 -0
- package/dist/repository/value.js +76 -0
- package/dist/scopes/filter.cjs +56 -0
- package/dist/scopes/filter.d.cts +22 -0
- package/dist/scopes/filter.d.ts +22 -0
- package/dist/scopes/filter.js +54 -0
- package/dist/scopes/helpers/filter.helpers.cjs +152 -0
- package/dist/scopes/helpers/filter.helpers.d.cts +16 -0
- package/dist/scopes/helpers/filter.helpers.d.ts +16 -0
- package/dist/scopes/helpers/filter.helpers.js +147 -0
- package/dist/scopes/index.cjs +1 -0
- package/dist/scopes/index.js +3 -0
- package/dist/types/index.d.cts +75 -0
- package/dist/types/index.d.ts +76 -0
- package/dist/utils/constants/index.cjs +32 -0
- package/dist/utils/constants/index.d.cts +23 -0
- package/dist/utils/constants/index.d.ts +23 -0
- package/dist/utils/constants/index.js +29 -0
- package/dist/utils/db/index.cjs +15 -0
- package/dist/utils/db/index.js +14 -0
- package/dist/utils/helpers/index.cjs +23 -0
- package/dist/utils/helpers/index.d.cts +30 -0
- package/dist/utils/helpers/index.d.ts +30 -0
- package/dist/utils/helpers/index.js +21 -0
- package/dist/utils/init.cjs +115 -0
- package/dist/utils/init.js +111 -0
- package/dist/utils/logger/index.cjs +15 -0
- package/dist/utils/logger/index.js +12 -0
- package/dist/utils/scopeAttributes.cjs +12 -0
- package/dist/utils/scopeAttributes.js +11 -0
- package/dist/utils/validations/index.cjs +34 -0
- package/dist/utils/validations/index.js +32 -0
- package/dist/utils/validations/schema/custom-fields.cjs +9 -0
- package/dist/utils/validations/schema/custom-fields.d.cts +6 -0
- package/dist/utils/validations/schema/custom-fields.d.ts +6 -0
- package/dist/utils/validations/schema/custom-fields.js +7 -0
- package/dist/utils/validations/schema/validator-schema.cjs +102 -0
- package/dist/utils/validations/schema/validator-schema.js +99 -0
- package/dist/utils/validations/validators/index.cjs +45 -0
- package/dist/utils/validations/validators/index.js +42 -0
- package/dist/utils/validations/validators/multi-select-dropdown.validator.cjs +7 -0
- package/dist/utils/validations/validators/multi-select-dropdown.validator.js +7 -0
- package/dist/utils/validations/validators/multi-select-status.validator.cjs +10 -0
- package/dist/utils/validations/validators/multi-select-status.validator.js +10 -0
- package/dist/utils/validations/validators/multi-select.helpers.cjs +12 -0
- package/dist/utils/validations/validators/multi-select.helpers.js +10 -0
- package/dist/utils/validations/validators/select.validator.cjs +12 -0
- package/dist/utils/validations/validators/select.validator.js +10 -0
- package/dist/utils/validations/validators/status.validator.cjs +12 -0
- package/dist/utils/validations/validators/status.validator.js +10 -0
- package/package.json +4 -4
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('../../../utils/logger/index.cjs');
|
|
3
|
+
const require_errors = require('../errors.cjs');
|
|
4
|
+
const require_mat_path_state = require('../../../mat-path-state.cjs');
|
|
5
|
+
const require_field_policy = require('../../../repository/field-policy.cjs');
|
|
6
|
+
let sequelize = require("sequelize");
|
|
7
|
+
let _autofleet_node_common = require("@autofleet/node-common");
|
|
8
|
+
|
|
9
|
+
//#region src/api/v1/field-policies/index.ts
|
|
10
|
+
const router = (0, _autofleet_node_common.Router)({
|
|
11
|
+
logger: require_index.default,
|
|
12
|
+
mergeParams: true
|
|
13
|
+
});
|
|
14
|
+
router.get("/effective", async (req, res) => {
|
|
15
|
+
const { withMatPath } = require_mat_path_state.matPathState;
|
|
16
|
+
if (!withMatPath) return res.status(501).json({ error: "Effective field policy resolution is not configured" });
|
|
17
|
+
const entityType = req.params.entityType;
|
|
18
|
+
try {
|
|
19
|
+
const [policy] = await require_field_policy.findEffectivePolicy(entityType);
|
|
20
|
+
return res.status(200).json(policy ?? null);
|
|
21
|
+
} catch (err) {
|
|
22
|
+
return require_errors.default(err, res, {
|
|
23
|
+
logger: require_index.default,
|
|
24
|
+
message: "Error resolving effective field policy"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
router.get("/", async (_req, res) => {
|
|
29
|
+
try {
|
|
30
|
+
const policies = await require_field_policy.findAll();
|
|
31
|
+
res.status(200).json(policies);
|
|
32
|
+
} catch (err) {
|
|
33
|
+
require_errors.default(err, res, {
|
|
34
|
+
logger: require_index.default,
|
|
35
|
+
message: "Error in get field policies request"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
router.post("/", async (req, res) => {
|
|
40
|
+
const { contextId, name, entityType, fields, models } = req.body;
|
|
41
|
+
if (!contextId || !name) {
|
|
42
|
+
res.status(400).json({ error: "contextId and name are required" });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const policy = await require_field_policy.create({
|
|
47
|
+
contextId,
|
|
48
|
+
name,
|
|
49
|
+
entityType,
|
|
50
|
+
fields,
|
|
51
|
+
models
|
|
52
|
+
});
|
|
53
|
+
res.status(201).json(policy);
|
|
54
|
+
} catch (err) {
|
|
55
|
+
if (err instanceof sequelize.UniqueConstraintError) {
|
|
56
|
+
res.status(409).json({ error: "A field policy for this contextId and name already exists" });
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
require_errors.default(err, res, {
|
|
60
|
+
logger: require_index.default,
|
|
61
|
+
message: "Error in create field policy request"
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
router.put("/:policyId", async (req, res) => {
|
|
66
|
+
const { policyId } = req.params;
|
|
67
|
+
const { entityType, fields, models } = req.body;
|
|
68
|
+
try {
|
|
69
|
+
const updated = await require_field_policy.update(policyId, {
|
|
70
|
+
entityType,
|
|
71
|
+
fields,
|
|
72
|
+
models
|
|
73
|
+
});
|
|
74
|
+
if (!updated) {
|
|
75
|
+
res.status(404).json({ error: "Field policy not found" });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
res.status(200).json(updated);
|
|
79
|
+
} catch (err) {
|
|
80
|
+
require_errors.default(err, res, {
|
|
81
|
+
logger: require_index.default,
|
|
82
|
+
message: "Error in update field policy request"
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
router.delete("/:policyId", async (req, res) => {
|
|
87
|
+
const { policyId } = req.params;
|
|
88
|
+
try {
|
|
89
|
+
if (!await require_field_policy.remove(policyId)) {
|
|
90
|
+
res.status(404).json({ error: "Field policy not found" });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
res.status(204).send();
|
|
94
|
+
} catch (err) {
|
|
95
|
+
require_errors.default(err, res, {
|
|
96
|
+
logger: require_index.default,
|
|
97
|
+
message: "Error in delete field policy request"
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
var field_policies_default = router;
|
|
102
|
+
|
|
103
|
+
//#endregion
|
|
104
|
+
exports.default = field_policies_default;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import logger_default from "../../../utils/logger/index.js";
|
|
2
|
+
import errors_default from "../errors.js";
|
|
3
|
+
import { matPathState } from "../../../mat-path-state.js";
|
|
4
|
+
import { create, findAll, findEffectivePolicy, remove, update } from "../../../repository/field-policy.js";
|
|
5
|
+
import { UniqueConstraintError } from "sequelize";
|
|
6
|
+
import { Router } from "@autofleet/node-common";
|
|
7
|
+
|
|
8
|
+
//#region src/api/v1/field-policies/index.ts
|
|
9
|
+
const router = Router({
|
|
10
|
+
logger: logger_default,
|
|
11
|
+
mergeParams: true
|
|
12
|
+
});
|
|
13
|
+
router.get("/effective", async (req, res) => {
|
|
14
|
+
const { withMatPath } = matPathState;
|
|
15
|
+
if (!withMatPath) return res.status(501).json({ error: "Effective field policy resolution is not configured" });
|
|
16
|
+
const entityType = req.params.entityType;
|
|
17
|
+
try {
|
|
18
|
+
const [policy] = await findEffectivePolicy(entityType);
|
|
19
|
+
return res.status(200).json(policy ?? null);
|
|
20
|
+
} catch (err) {
|
|
21
|
+
return errors_default(err, res, {
|
|
22
|
+
logger: logger_default,
|
|
23
|
+
message: "Error resolving effective field policy"
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
router.get("/", async (_req, res) => {
|
|
28
|
+
try {
|
|
29
|
+
const policies = await findAll();
|
|
30
|
+
res.status(200).json(policies);
|
|
31
|
+
} catch (err) {
|
|
32
|
+
errors_default(err, res, {
|
|
33
|
+
logger: logger_default,
|
|
34
|
+
message: "Error in get field policies request"
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
router.post("/", async (req, res) => {
|
|
39
|
+
const { contextId, name, entityType, fields, models } = req.body;
|
|
40
|
+
if (!contextId || !name) {
|
|
41
|
+
res.status(400).json({ error: "contextId and name are required" });
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
const policy = await create({
|
|
46
|
+
contextId,
|
|
47
|
+
name,
|
|
48
|
+
entityType,
|
|
49
|
+
fields,
|
|
50
|
+
models
|
|
51
|
+
});
|
|
52
|
+
res.status(201).json(policy);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
if (err instanceof UniqueConstraintError) {
|
|
55
|
+
res.status(409).json({ error: "A field policy for this contextId and name already exists" });
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
errors_default(err, res, {
|
|
59
|
+
logger: logger_default,
|
|
60
|
+
message: "Error in create field policy request"
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
router.put("/:policyId", async (req, res) => {
|
|
65
|
+
const { policyId } = req.params;
|
|
66
|
+
const { entityType, fields, models } = req.body;
|
|
67
|
+
try {
|
|
68
|
+
const updated = await update(policyId, {
|
|
69
|
+
entityType,
|
|
70
|
+
fields,
|
|
71
|
+
models
|
|
72
|
+
});
|
|
73
|
+
if (!updated) {
|
|
74
|
+
res.status(404).json({ error: "Field policy not found" });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
res.status(200).json(updated);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
errors_default(err, res, {
|
|
80
|
+
logger: logger_default,
|
|
81
|
+
message: "Error in update field policy request"
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
router.delete("/:policyId", async (req, res) => {
|
|
86
|
+
const { policyId } = req.params;
|
|
87
|
+
try {
|
|
88
|
+
if (!await remove(policyId)) {
|
|
89
|
+
res.status(404).json({ error: "Field policy not found" });
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
res.status(204).send();
|
|
93
|
+
} catch (err) {
|
|
94
|
+
errors_default(err, res, {
|
|
95
|
+
logger: logger_default,
|
|
96
|
+
message: "Error in delete field policy request"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
var field_policies_default = router;
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { field_policies_default as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('../../utils/logger/index.cjs');
|
|
3
|
+
const require_index$1 = require('./definition/index.cjs');
|
|
4
|
+
const require_index$2 = require('./validator/index.cjs');
|
|
5
|
+
const require_index$3 = require('./field-policies/index.cjs');
|
|
6
|
+
let _autofleet_node_common = require("@autofleet/node-common");
|
|
7
|
+
|
|
8
|
+
//#region src/api/v1/index.ts
|
|
9
|
+
const router = (0, _autofleet_node_common.Router)({ logger: require_index.default });
|
|
10
|
+
router.use("/custom-field-definitions/:modelName", require_index$1.default);
|
|
11
|
+
router.use("/custom-validators/:modelName", require_index$2.default);
|
|
12
|
+
router.use("/field-policies/:entityType", require_index$3.default);
|
|
13
|
+
var v1_default = router;
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
exports.default = v1_default;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import logger_default from "../../utils/logger/index.js";
|
|
2
|
+
import definition_default from "./definition/index.js";
|
|
3
|
+
import validator_default from "./validator/index.js";
|
|
4
|
+
import field_policies_default from "./field-policies/index.js";
|
|
5
|
+
import { Router } from "@autofleet/node-common";
|
|
6
|
+
|
|
7
|
+
//#region src/api/v1/index.ts
|
|
8
|
+
const router = Router({ logger: logger_default });
|
|
9
|
+
router.use("/custom-field-definitions/:modelName", definition_default);
|
|
10
|
+
router.use("/custom-validators/:modelName", validator_default);
|
|
11
|
+
router.use("/field-policies/:entityType", field_policies_default);
|
|
12
|
+
var v1_default = router;
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { v1_default as default };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_index = require('../../../utils/logger/index.cjs');
|
|
3
|
+
const require_errors = require('../errors.cjs');
|
|
4
|
+
const require_mat_path_state = require('../../../mat-path-state.cjs');
|
|
5
|
+
const require_validator = require('../../../repository/validator.cjs');
|
|
6
|
+
const require_validations = require('./validations.cjs');
|
|
7
|
+
const require_validator_schema = require('../../../utils/validations/schema/validator-schema.cjs');
|
|
8
|
+
let _autofleet_errors = require("@autofleet/errors");
|
|
9
|
+
let _autofleet_node_common = require("@autofleet/node-common");
|
|
10
|
+
let http_status_codes = require("http-status-codes");
|
|
11
|
+
|
|
12
|
+
//#region src/api/v1/validator/index.ts
|
|
13
|
+
const router = (0, _autofleet_node_common.Router)({ logger: require_index.default });
|
|
14
|
+
const ENTITY = "CustomValidator";
|
|
15
|
+
/**
|
|
16
|
+
* Create
|
|
17
|
+
*/
|
|
18
|
+
router.post("/", async (req, res) => {
|
|
19
|
+
const { modelName } = req.params;
|
|
20
|
+
try {
|
|
21
|
+
const validatedPayload = await require_validations.default.create.validateAsync(req.body);
|
|
22
|
+
require_validator_schema.validateValidatorSchema(validatedPayload.schema);
|
|
23
|
+
const validator = await require_validator.create({
|
|
24
|
+
...validatedPayload,
|
|
25
|
+
modelType: modelName
|
|
26
|
+
});
|
|
27
|
+
return res.status(http_status_codes.StatusCodes.CREATED).json(validator);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
return require_errors.default(err, res, {
|
|
30
|
+
logger: require_index.default,
|
|
31
|
+
message: `Error in create ${ENTITY} request`
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
/**
|
|
36
|
+
* Get all
|
|
37
|
+
*/
|
|
38
|
+
router.get("/", async (req, res) => {
|
|
39
|
+
try {
|
|
40
|
+
const { modelName } = req.params;
|
|
41
|
+
const { entityId, entityType } = req.query;
|
|
42
|
+
const applyEntityFilters = !require_mat_path_state.matPathState.isMatPathEnabled?.();
|
|
43
|
+
const where = {
|
|
44
|
+
modelType: modelName,
|
|
45
|
+
...applyEntityFilters && entityId && { entityId },
|
|
46
|
+
...applyEntityFilters && entityType && { entityType }
|
|
47
|
+
};
|
|
48
|
+
const validators = await require_validator.findAll(where);
|
|
49
|
+
return res.status(http_status_codes.StatusCodes.OK).json({ validators });
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return require_errors.default(err, res, {
|
|
52
|
+
logger: require_index.default,
|
|
53
|
+
message: `Error in get all ${ENTITY} request`
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Effective
|
|
59
|
+
*/
|
|
60
|
+
router.get("/effective", async (req, res) => {
|
|
61
|
+
const { withMatPath } = require_mat_path_state.matPathState;
|
|
62
|
+
if (!withMatPath) return res.status(http_status_codes.StatusCodes.NOT_IMPLEMENTED).json({ error: "Effective validator resolution is not configured" });
|
|
63
|
+
try {
|
|
64
|
+
const { modelName } = req.params;
|
|
65
|
+
const [validator] = await require_validator.findEffective(modelName);
|
|
66
|
+
return res.status(http_status_codes.StatusCodes.OK).json(validator ?? null);
|
|
67
|
+
} catch (err) {
|
|
68
|
+
return require_errors.default(err, res, {
|
|
69
|
+
logger: require_index.default,
|
|
70
|
+
message: `Error resolving effective ${ENTITY}`
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Get by id
|
|
76
|
+
*/
|
|
77
|
+
router.get("/:validatorId", async (req, res) => {
|
|
78
|
+
try {
|
|
79
|
+
const { validatorId, modelName } = req.params;
|
|
80
|
+
const validators = await require_validator.findAll({
|
|
81
|
+
id: validatorId,
|
|
82
|
+
modelType: modelName
|
|
83
|
+
}, { withDisabled: true });
|
|
84
|
+
if (!validators.length) throw new _autofleet_errors.ResourceNotFoundError("Validator not found");
|
|
85
|
+
return res.status(http_status_codes.StatusCodes.OK).json(validators[0]);
|
|
86
|
+
} catch (err) {
|
|
87
|
+
return require_errors.default(err, res, {
|
|
88
|
+
logger: require_index.default,
|
|
89
|
+
message: `Error in get ${ENTITY} request`
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Update
|
|
95
|
+
*/
|
|
96
|
+
router.patch("/:validatorId", async (req, res) => {
|
|
97
|
+
try {
|
|
98
|
+
const { validatorId } = req.params;
|
|
99
|
+
const validatedPayload = await require_validations.default.update.validateAsync(req.body);
|
|
100
|
+
if (validatedPayload.schema) require_validator_schema.validateValidatorSchema(validatedPayload.schema);
|
|
101
|
+
if (!(await require_validator.findAll({ id: validatorId }, { withDisabled: true })).length) throw new _autofleet_errors.ResourceNotFoundError("Validator not found");
|
|
102
|
+
const [count, validators] = await require_validator.update(validatorId, validatedPayload);
|
|
103
|
+
if (!count) throw new _autofleet_errors.ResourceNotFoundError("Validator not found");
|
|
104
|
+
return res.status(http_status_codes.StatusCodes.OK).json(validators[0]);
|
|
105
|
+
} catch (err) {
|
|
106
|
+
return require_errors.default(err, res, {
|
|
107
|
+
logger: require_index.default,
|
|
108
|
+
message: `Error in update ${ENTITY} request`
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
/**
|
|
113
|
+
* Delete (disable)
|
|
114
|
+
*/
|
|
115
|
+
router.delete("/:validatorId", async (req, res) => {
|
|
116
|
+
try {
|
|
117
|
+
const { validatorId } = req.params;
|
|
118
|
+
if (!(await require_validator.findAll({ id: validatorId }, { withDisabled: true })).length) throw new _autofleet_errors.ResourceNotFoundError("Validator not found");
|
|
119
|
+
const [count] = await require_validator.disable(validatorId);
|
|
120
|
+
if (!count) throw new _autofleet_errors.ResourceNotFoundError("Validator failed to be disabled");
|
|
121
|
+
return res.status(http_status_codes.StatusCodes.NO_CONTENT).send();
|
|
122
|
+
} catch (err) {
|
|
123
|
+
return require_errors.default(err, res, {
|
|
124
|
+
logger: require_index.default,
|
|
125
|
+
message: `Error in delete ${ENTITY} request`
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
var validator_default = router;
|
|
130
|
+
|
|
131
|
+
//#endregion
|
|
132
|
+
exports.default = validator_default;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import logger_default from "../../../utils/logger/index.js";
|
|
2
|
+
import errors_default from "../errors.js";
|
|
3
|
+
import { matPathState } from "../../../mat-path-state.js";
|
|
4
|
+
import { create, disable, findAll, findEffective, update } from "../../../repository/validator.js";
|
|
5
|
+
import validations_default from "./validations.js";
|
|
6
|
+
import { validateValidatorSchema } from "../../../utils/validations/schema/validator-schema.js";
|
|
7
|
+
import { ResourceNotFoundError } from "@autofleet/errors";
|
|
8
|
+
import { Router } from "@autofleet/node-common";
|
|
9
|
+
import { StatusCodes } from "http-status-codes";
|
|
10
|
+
|
|
11
|
+
//#region src/api/v1/validator/index.ts
|
|
12
|
+
const router = Router({ logger: logger_default });
|
|
13
|
+
const ENTITY = "CustomValidator";
|
|
14
|
+
/**
|
|
15
|
+
* Create
|
|
16
|
+
*/
|
|
17
|
+
router.post("/", async (req, res) => {
|
|
18
|
+
const { modelName } = req.params;
|
|
19
|
+
try {
|
|
20
|
+
const validatedPayload = await validations_default.create.validateAsync(req.body);
|
|
21
|
+
validateValidatorSchema(validatedPayload.schema);
|
|
22
|
+
const validator = await create({
|
|
23
|
+
...validatedPayload,
|
|
24
|
+
modelType: modelName
|
|
25
|
+
});
|
|
26
|
+
return res.status(StatusCodes.CREATED).json(validator);
|
|
27
|
+
} catch (err) {
|
|
28
|
+
return errors_default(err, res, {
|
|
29
|
+
logger: logger_default,
|
|
30
|
+
message: `Error in create ${ENTITY} request`
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
/**
|
|
35
|
+
* Get all
|
|
36
|
+
*/
|
|
37
|
+
router.get("/", async (req, res) => {
|
|
38
|
+
try {
|
|
39
|
+
const { modelName } = req.params;
|
|
40
|
+
const { entityId, entityType } = req.query;
|
|
41
|
+
const applyEntityFilters = !matPathState.isMatPathEnabled?.();
|
|
42
|
+
const where = {
|
|
43
|
+
modelType: modelName,
|
|
44
|
+
...applyEntityFilters && entityId && { entityId },
|
|
45
|
+
...applyEntityFilters && entityType && { entityType }
|
|
46
|
+
};
|
|
47
|
+
const validators = await findAll(where);
|
|
48
|
+
return res.status(StatusCodes.OK).json({ validators });
|
|
49
|
+
} catch (err) {
|
|
50
|
+
return errors_default(err, res, {
|
|
51
|
+
logger: logger_default,
|
|
52
|
+
message: `Error in get all ${ENTITY} request`
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* Effective
|
|
58
|
+
*/
|
|
59
|
+
router.get("/effective", async (req, res) => {
|
|
60
|
+
const { withMatPath } = matPathState;
|
|
61
|
+
if (!withMatPath) return res.status(StatusCodes.NOT_IMPLEMENTED).json({ error: "Effective validator resolution is not configured" });
|
|
62
|
+
try {
|
|
63
|
+
const { modelName } = req.params;
|
|
64
|
+
const [validator] = await findEffective(modelName);
|
|
65
|
+
return res.status(StatusCodes.OK).json(validator ?? null);
|
|
66
|
+
} catch (err) {
|
|
67
|
+
return errors_default(err, res, {
|
|
68
|
+
logger: logger_default,
|
|
69
|
+
message: `Error resolving effective ${ENTITY}`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
/**
|
|
74
|
+
* Get by id
|
|
75
|
+
*/
|
|
76
|
+
router.get("/:validatorId", async (req, res) => {
|
|
77
|
+
try {
|
|
78
|
+
const { validatorId, modelName } = req.params;
|
|
79
|
+
const validators = await findAll({
|
|
80
|
+
id: validatorId,
|
|
81
|
+
modelType: modelName
|
|
82
|
+
}, { withDisabled: true });
|
|
83
|
+
if (!validators.length) throw new ResourceNotFoundError("Validator not found");
|
|
84
|
+
return res.status(StatusCodes.OK).json(validators[0]);
|
|
85
|
+
} catch (err) {
|
|
86
|
+
return errors_default(err, res, {
|
|
87
|
+
logger: logger_default,
|
|
88
|
+
message: `Error in get ${ENTITY} request`
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
/**
|
|
93
|
+
* Update
|
|
94
|
+
*/
|
|
95
|
+
router.patch("/:validatorId", async (req, res) => {
|
|
96
|
+
try {
|
|
97
|
+
const { validatorId } = req.params;
|
|
98
|
+
const validatedPayload = await validations_default.update.validateAsync(req.body);
|
|
99
|
+
if (validatedPayload.schema) validateValidatorSchema(validatedPayload.schema);
|
|
100
|
+
if (!(await findAll({ id: validatorId }, { withDisabled: true })).length) throw new ResourceNotFoundError("Validator not found");
|
|
101
|
+
const [count, validators] = await update(validatorId, validatedPayload);
|
|
102
|
+
if (!count) throw new ResourceNotFoundError("Validator not found");
|
|
103
|
+
return res.status(StatusCodes.OK).json(validators[0]);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
return errors_default(err, res, {
|
|
106
|
+
logger: logger_default,
|
|
107
|
+
message: `Error in update ${ENTITY} request`
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
/**
|
|
112
|
+
* Delete (disable)
|
|
113
|
+
*/
|
|
114
|
+
router.delete("/:validatorId", async (req, res) => {
|
|
115
|
+
try {
|
|
116
|
+
const { validatorId } = req.params;
|
|
117
|
+
if (!(await findAll({ id: validatorId }, { withDisabled: true })).length) throw new ResourceNotFoundError("Validator not found");
|
|
118
|
+
const [count] = await disable(validatorId);
|
|
119
|
+
if (!count) throw new ResourceNotFoundError("Validator failed to be disabled");
|
|
120
|
+
return res.status(StatusCodes.NO_CONTENT).send();
|
|
121
|
+
} catch (err) {
|
|
122
|
+
return errors_default(err, res, {
|
|
123
|
+
logger: logger_default,
|
|
124
|
+
message: `Error in delete ${ENTITY} request`
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
var validator_default = router;
|
|
129
|
+
|
|
130
|
+
//#endregion
|
|
131
|
+
export { validator_default as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let joi = require("joi");
|
|
3
|
+
joi = require_rolldown_runtime.__toESM(joi);
|
|
4
|
+
|
|
5
|
+
//#region src/api/v1/validator/validations.ts
|
|
6
|
+
const jsonSchemaValidation = joi.default.object().unknown(true);
|
|
7
|
+
const schemaObject = joi.default.object({
|
|
8
|
+
type: joi.default.string().valid("object"),
|
|
9
|
+
properties: joi.default.object({
|
|
10
|
+
before: jsonSchemaValidation,
|
|
11
|
+
after: jsonSchemaValidation
|
|
12
|
+
}).required(),
|
|
13
|
+
required: joi.default.array().items(joi.default.string()),
|
|
14
|
+
allOf: joi.default.array().items(joi.default.object()),
|
|
15
|
+
anyOf: joi.default.array().items(joi.default.object()),
|
|
16
|
+
oneOf: joi.default.array().items(joi.default.object()),
|
|
17
|
+
additionalProperties: joi.default.alternatives().try(joi.default.boolean(), joi.default.object()),
|
|
18
|
+
$id: joi.default.string(),
|
|
19
|
+
$schema: joi.default.string(),
|
|
20
|
+
if: joi.default.object(),
|
|
21
|
+
then: joi.default.object(),
|
|
22
|
+
else: joi.default.object()
|
|
23
|
+
});
|
|
24
|
+
const validationSchemas = {
|
|
25
|
+
create: joi.default.object({
|
|
26
|
+
entityId: joi.default.string().uuid().required(),
|
|
27
|
+
entityType: joi.default.string().required(),
|
|
28
|
+
schema: schemaObject.required()
|
|
29
|
+
}),
|
|
30
|
+
update: joi.default.object({
|
|
31
|
+
entityId: joi.default.string().uuid(),
|
|
32
|
+
entityType: joi.default.string(),
|
|
33
|
+
schema: schemaObject,
|
|
34
|
+
disabled: joi.default.boolean()
|
|
35
|
+
}).min(1)
|
|
36
|
+
};
|
|
37
|
+
var validations_default = validationSchemas;
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.default = validations_default;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
|
|
3
|
+
//#region src/api/v1/validator/validations.d.ts
|
|
4
|
+
interface SchemaObject {
|
|
5
|
+
type: "object";
|
|
6
|
+
properties?: {
|
|
7
|
+
before?: object;
|
|
8
|
+
after?: object;
|
|
9
|
+
};
|
|
10
|
+
required?: string[];
|
|
11
|
+
allOf?: object[];
|
|
12
|
+
anyOf?: object[];
|
|
13
|
+
oneOf?: object[];
|
|
14
|
+
additionalProperties?: boolean | object;
|
|
15
|
+
$id?: string;
|
|
16
|
+
$schema?: string;
|
|
17
|
+
if?: object;
|
|
18
|
+
then?: object;
|
|
19
|
+
else?: object;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SchemaObject };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
|
|
3
|
+
//#region src/api/v1/validator/validations.d.ts
|
|
4
|
+
interface SchemaObject {
|
|
5
|
+
type: "object";
|
|
6
|
+
properties?: {
|
|
7
|
+
before?: object;
|
|
8
|
+
after?: object;
|
|
9
|
+
};
|
|
10
|
+
required?: string[];
|
|
11
|
+
allOf?: object[];
|
|
12
|
+
anyOf?: object[];
|
|
13
|
+
oneOf?: object[];
|
|
14
|
+
additionalProperties?: boolean | object;
|
|
15
|
+
$id?: string;
|
|
16
|
+
$schema?: string;
|
|
17
|
+
if?: object;
|
|
18
|
+
then?: object;
|
|
19
|
+
else?: object;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SchemaObject };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import Joi from "joi";
|
|
2
|
+
|
|
3
|
+
//#region src/api/v1/validator/validations.ts
|
|
4
|
+
const jsonSchemaValidation = Joi.object().unknown(true);
|
|
5
|
+
const schemaObject = Joi.object({
|
|
6
|
+
type: Joi.string().valid("object"),
|
|
7
|
+
properties: Joi.object({
|
|
8
|
+
before: jsonSchemaValidation,
|
|
9
|
+
after: jsonSchemaValidation
|
|
10
|
+
}).required(),
|
|
11
|
+
required: Joi.array().items(Joi.string()),
|
|
12
|
+
allOf: Joi.array().items(Joi.object()),
|
|
13
|
+
anyOf: Joi.array().items(Joi.object()),
|
|
14
|
+
oneOf: Joi.array().items(Joi.object()),
|
|
15
|
+
additionalProperties: Joi.alternatives().try(Joi.boolean(), Joi.object()),
|
|
16
|
+
$id: Joi.string(),
|
|
17
|
+
$schema: Joi.string(),
|
|
18
|
+
if: Joi.object(),
|
|
19
|
+
then: Joi.object(),
|
|
20
|
+
else: Joi.object()
|
|
21
|
+
});
|
|
22
|
+
const validationSchemas = {
|
|
23
|
+
create: Joi.object({
|
|
24
|
+
entityId: Joi.string().uuid().required(),
|
|
25
|
+
entityType: Joi.string().required(),
|
|
26
|
+
schema: schemaObject.required()
|
|
27
|
+
}),
|
|
28
|
+
update: Joi.object({
|
|
29
|
+
entityId: Joi.string().uuid(),
|
|
30
|
+
entityType: Joi.string(),
|
|
31
|
+
schema: schemaObject,
|
|
32
|
+
disabled: Joi.boolean()
|
|
33
|
+
}).min(1)
|
|
34
|
+
};
|
|
35
|
+
var validations_default = validationSchemas;
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { validations_default as default };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let _autofleet_errors = require("@autofleet/errors");
|
|
3
|
+
|
|
4
|
+
//#region src/errors/index.ts
|
|
5
|
+
var MissingRequiredCustomFieldError = class extends _autofleet_errors.BadRequest {
|
|
6
|
+
constructor(missingFields) {
|
|
7
|
+
const err = /* @__PURE__ */ new Error(`The following custom fields are required: ${missingFields.join(",")}`);
|
|
8
|
+
super([err], void 0, missingFields);
|
|
9
|
+
this.message = "MISSING_REQUIRED_CUSTOM_FIELDS";
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var UnsupportedCustomFieldTypeError = class extends _autofleet_errors.BadRequest {
|
|
13
|
+
constructor(fieldType) {
|
|
14
|
+
const err = /* @__PURE__ */ new Error(`Type "${fieldType}" is not supported`);
|
|
15
|
+
super([err], void 0, null);
|
|
16
|
+
this.message = "UNSUPPORTED_CUSTOM_FIELD_TYPE";
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var UnsupportedCustomValidationError = class extends _autofleet_errors.BadRequest {
|
|
20
|
+
constructor(fieldType) {
|
|
21
|
+
const err = /* @__PURE__ */ new Error(`Validation for "${fieldType}" is not supported`);
|
|
22
|
+
super([err], void 0, null);
|
|
23
|
+
this.message = "UNSUPPORTED_CUSTOM_VALIDATION_TYPE";
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var InvalidFieldTypeError = class extends _autofleet_errors.BadRequest {
|
|
27
|
+
constructor(fieldType) {
|
|
28
|
+
const err = /* @__PURE__ */ new Error(`Invalid field type ${fieldType}`);
|
|
29
|
+
super([err], void 0, null);
|
|
30
|
+
this.message = "INVALID_FIELD_TYPE";
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var InvalidValueError = class extends _autofleet_errors.BadRequest {
|
|
34
|
+
constructor(value, fieldDefinitionName, joiValidationError) {
|
|
35
|
+
const invalidValueMessage = `Invalid Value on field '${fieldDefinitionName}'. ${joiValidationError.message.replace(/"/g, "").replace("value", `'${fieldDefinitionName}'`)}. received: '${typeof value === "object" ? JSON.stringify(value) : value}'`;
|
|
36
|
+
super([new Error(invalidValueMessage)], void 0, null);
|
|
37
|
+
this.message = invalidValueMessage;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var InvalidEntriesError = class extends _autofleet_errors.BadRequest {
|
|
41
|
+
constructor(modelId, validationErrors) {
|
|
42
|
+
const errors = validationErrors.map((validationError) => new InvalidValueError(validationError.value, validationError.fieldDefinitionName, validationError.joiValidationError));
|
|
43
|
+
super(errors, void 0, null);
|
|
44
|
+
this.message = `Invalid entries on ${modelId}\n${validationErrors.map((validationError) => `${validationError.fieldDefinitionName} - ${validationError.joiValidationError.message}`).join("\n")}`;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
var MissingDefinitionError = class extends _autofleet_errors.BadRequest {
|
|
48
|
+
constructor(fieldNames) {
|
|
49
|
+
const err = /* @__PURE__ */ new Error(`Missing custom field definition for field ${fieldNames.join(",")}`);
|
|
50
|
+
super([err], void 0, null);
|
|
51
|
+
this.message = "MISSING_DEFINITION";
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.InvalidEntriesError = InvalidEntriesError;
|
|
57
|
+
exports.InvalidFieldTypeError = InvalidFieldTypeError;
|
|
58
|
+
exports.InvalidValueError = InvalidValueError;
|
|
59
|
+
exports.MissingDefinitionError = MissingDefinitionError;
|
|
60
|
+
exports.MissingRequiredCustomFieldError = MissingRequiredCustomFieldError;
|
|
61
|
+
exports.UnsupportedCustomFieldTypeError = UnsupportedCustomFieldTypeError;
|
|
62
|
+
exports.UnsupportedCustomValidationError = UnsupportedCustomValidationError;
|