@autofleet/sadot 1.1.3 → 1.1.5-beta
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/.nvmrc +1 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +12 -2
- package/dist/api/v1/definition/index.d.ts +3 -0
- package/dist/api/v1/definition/index.js +116 -2
- package/dist/api/v1/definition/validations.d.ts +2 -0
- package/dist/api/v1/definition/validations.js +77 -2
- package/dist/api/v1/errors.d.ts +4 -0
- package/dist/api/v1/errors.js +12 -2
- package/dist/api/v1/index.d.ts +3 -0
- package/dist/api/v1/index.js +13 -2
- package/dist/api/v1/validator/index.d.ts +3 -0
- package/dist/api/v1/validator/index.js +143 -2
- package/dist/api/v1/validator/validations.d.ts +6 -23
- package/dist/api/v1/validator/validations.js +38 -2
- package/dist/errors/index.d.ts +24 -0
- package/dist/errors/index.js +66 -3
- package/dist/events/index.d.ts +5 -0
- package/dist/events/index.js +54 -2
- package/dist/hooks/create.d.ts +10 -0
- package/dist/hooks/create.js +95 -0
- package/dist/hooks/enrich.d.ts +25 -0
- package/dist/hooks/enrich.js +198 -2
- package/dist/hooks/find.d.ts +1 -0
- package/dist/hooks/find.js +29 -2
- package/dist/hooks/hooks.d.ts +17 -0
- package/dist/hooks/hooks.js +388 -2
- package/dist/hooks/index.d.ts +5 -0
- package/dist/hooks/index.js +17 -1
- package/dist/hooks/update.d.ts +10 -0
- package/dist/hooks/update.js +49 -0
- package/dist/hooks/utils/updateInstanceValues.d.ts +15 -0
- package/dist/hooks/utils/updateInstanceValues.js +50 -2
- package/dist/hooks/workaround.d.ts +10 -0
- package/dist/hooks/workaround.js +37 -0
- package/dist/index.d.ts +12 -22
- package/dist/index.js +67 -2
- package/dist/models/CustomFieldDefinition.d.ts +23 -29
- package/dist/models/CustomFieldDefinition.js +192 -2
- package/dist/models/CustomFieldEntries.d.ts +13 -14
- package/dist/models/CustomFieldEntries.js +123 -2
- package/dist/models/CustomFieldValue.d.ts +14 -20
- package/dist/models/CustomFieldValue.js +151 -2
- package/dist/models/CustomValidator.d.ts +15 -17
- package/dist/models/CustomValidator.js +98 -2
- package/dist/models/index.d.ts +18 -6
- package/dist/models/index.js +131 -2
- package/dist/models/tests/AssociatedTestModel.d.ts +12 -0
- package/dist/models/tests/AssociatedTestModel.js +71 -2
- package/dist/models/tests/TestModel.d.ts +12 -0
- package/dist/models/tests/TestModel.js +69 -2
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +10 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +53 -2
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +13 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +47 -2
- package/dist/repository/definition.d.ts +36 -0
- package/dist/repository/definition.js +121 -2
- package/dist/repository/entries.d.ts +13 -0
- package/dist/repository/entries.js +92 -2
- package/dist/repository/utils/formatValues.d.ts +3 -0
- package/dist/repository/utils/formatValues.js +16 -2
- package/dist/repository/validator.d.ts +27 -0
- package/dist/repository/validator.js +69 -2
- package/dist/repository/value.d.ts +28 -0
- package/dist/repository/value.js +124 -2
- package/dist/scopes/filter.d.ts +29 -22
- package/dist/scopes/filter.js +75 -2
- package/dist/scopes/helpers/filter.helpers.d.ts +40 -15
- package/dist/scopes/helpers/filter.helpers.js +183 -25
- package/dist/scopes/index.d.ts +2 -0
- package/dist/scopes/index.js +6 -1
- package/dist/tests/api/test-api.d.ts +2 -0
- package/dist/tests/api/test-api.js +38 -0
- package/dist/tests/functional/searching/index.d.ts +8 -0
- package/dist/tests/functional/searching/index.js +44 -0
- package/dist/tests/helpers/commonHooks.d.ts +6 -0
- package/dist/tests/helpers/commonHooks.js +62 -0
- package/dist/tests/helpers/database-config.d.ts +16 -0
- package/dist/tests/helpers/database-config.js +17 -0
- package/dist/tests/helpers/index.d.ts +7 -0
- package/dist/tests/helpers/index.js +33 -0
- package/dist/tests/mocks/definition.mock.d.ts +48 -0
- package/dist/tests/mocks/definition.mock.js +78 -0
- package/dist/tests/mocks/events.mock.d.ts +4 -0
- package/dist/tests/mocks/events.mock.js +21 -0
- package/dist/tests/mocks/testModel.d.ts +12 -0
- package/dist/tests/mocks/testModel.js +35 -0
- package/dist/types/definition/index.d.ts +25 -0
- package/dist/types/definition/index.js +2 -0
- package/dist/types/entries/index.d.ts +25 -0
- package/dist/types/entries/index.js +2 -0
- package/dist/types/index.d.ts +46 -45
- package/dist/types/index.js +2 -0
- package/dist/types/value/index.d.ts +15 -0
- package/dist/types/value/index.js +2 -0
- package/dist/utils/constants/index.d.ts +17 -20
- package/dist/utils/constants/index.js +22 -2
- package/dist/utils/db/index.d.ts +4 -0
- package/dist/utils/db/index.js +24 -2
- package/dist/utils/helpers/index.d.ts +23 -28
- package/dist/utils/helpers/index.js +40 -2
- package/dist/utils/init.d.ts +7 -0
- package/dist/utils/init.js +112 -2
- package/dist/utils/logger/index.d.ts +3 -0
- package/dist/utils/logger/index.js +42 -2
- package/dist/utils/scopeAttributes.d.ts +2 -0
- package/dist/utils/scopeAttributes.js +11 -2
- package/dist/utils/validations/index.d.ts +8 -0
- package/dist/utils/validations/index.js +41 -2
- package/dist/utils/validations/schema/custom-fields.d.ts +2 -6
- package/dist/utils/validations/schema/custom-fields.js +9 -2
- package/dist/utils/validations/schema/validator-schema.d.ts +9 -0
- package/dist/utils/validations/schema/validator-schema.js +95 -2
- package/dist/utils/validations/type.d.ts +15 -0
- package/dist/utils/validations/type.js +2 -0
- package/dist/utils/validations/validators/index.d.ts +14 -0
- package/dist/utils/validations/validators/index.js +40 -2
- package/dist/utils/validations/validators/select.validator.d.ts +5 -0
- package/dist/utils/validations/validators/select.validator.js +12 -2
- package/dist/utils/validations/validators/status.validator.d.ts +12 -0
- package/dist/utils/validations/validators/status.validator.js +15 -2
- package/package.json +39 -40
- package/src/api/index.ts +10 -0
- package/src/api/v1/definition/index.ts +104 -0
- package/src/api/v1/definition/validations.ts +75 -0
- package/src/api/v1/errors.ts +13 -0
- package/src/api/v1/index.ts +11 -0
- package/src/api/v1/validator/index.ts +141 -0
- package/src/api/v1/validator/validations.ts +38 -0
- package/src/errors/index.ts +70 -0
- package/src/events/index.ts +63 -0
- package/src/hooks/create.ts +81 -0
- package/src/hooks/enrich.ts +255 -0
- package/src/hooks/find.ts +27 -0
- package/src/hooks/hooks.ts +482 -0
- package/src/hooks/index.ts +20 -0
- package/src/hooks/update.ts +55 -0
- package/src/hooks/utils/updateInstanceValues.ts +63 -0
- package/src/hooks/workaround.ts +47 -0
- package/src/index.ts +52 -0
- package/src/models/CustomFieldDefinition.ts +162 -0
- package/src/models/CustomFieldEntries.ts +81 -0
- package/src/models/CustomFieldValue.ts +118 -0
- package/src/models/CustomValidator.ts +78 -0
- package/src/models/index.ts +165 -0
- package/src/models/tests/AssociatedTestModel.ts +57 -0
- package/src/models/tests/TestModel.ts +54 -0
- package/src/models/tests/contextAwareModels/ContextAwareTestModel.ts +43 -0
- package/src/models/tests/contextAwareModels/ContextTestModel.ts +38 -0
- package/src/repository/definition.ts +175 -0
- package/src/repository/entries.ts +88 -0
- package/src/repository/utils/formatValues.ts +14 -0
- package/src/repository/validator.ts +104 -0
- package/src/repository/value.ts +116 -0
- package/src/scopes/filter.ts +100 -0
- package/src/scopes/helpers/filter.helpers.ts +227 -0
- package/src/scopes/index.ts +6 -0
- package/src/tests/api/test-api.ts +40 -0
- package/src/tests/functional/searching/index.ts +39 -0
- package/src/tests/helpers/commonHooks.ts +43 -0
- package/src/tests/helpers/database-config.ts +15 -0
- package/src/tests/helpers/index.ts +35 -0
- package/src/tests/mocks/definition.mock.ts +84 -0
- package/src/tests/mocks/events.mock.ts +21 -0
- package/src/tests/mocks/testModel.ts +37 -0
- package/src/types/definition/index.ts +24 -0
- package/src/types/entries/index.ts +27 -0
- package/src/types/index.ts +52 -0
- package/src/types/value/index.ts +14 -0
- package/src/utils/constants/index.ts +25 -0
- package/src/utils/db/index.ts +21 -0
- package/src/utils/helpers/index.ts +66 -0
- package/src/utils/init.ts +120 -0
- package/src/utils/logger/index.ts +14 -0
- package/src/utils/scopeAttributes.ts +12 -0
- package/src/utils/validations/index.ts +46 -0
- package/src/utils/validations/schema/README.md +93 -0
- package/src/utils/validations/schema/custom-fields.ts +8 -0
- package/src/utils/validations/schema/validator-schema.ts +106 -0
- package/src/utils/validations/type.ts +20 -0
- package/src/utils/validations/validators/index.ts +38 -0
- package/src/utils/validations/validators/select.validator.ts +12 -0
- package/src/utils/validations/validators/status.validator.ts +22 -0
- package/tsconfig.build.json +7 -0
- package/tsconfig.json +16 -0
- package/dist/_virtual/_@oxc-project_runtime@0.101.0/helpers/decorate.cjs +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.101.0/helpers/decorate.js +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.101.0/helpers/decorateMetadata.cjs +0 -1
- package/dist/_virtual/_@oxc-project_runtime@0.101.0/helpers/decorateMetadata.js +0 -1
- package/dist/_virtual/rolldown_runtime.cjs +0 -1
- package/dist/api/index.cjs +0 -2
- package/dist/api/index.cjs.map +0 -1
- package/dist/api/index.js.map +0 -1
- package/dist/api/v1/definition/index.cjs +0 -2
- package/dist/api/v1/definition/index.cjs.map +0 -1
- package/dist/api/v1/definition/index.js.map +0 -1
- package/dist/api/v1/definition/validations.cjs +0 -2
- package/dist/api/v1/definition/validations.cjs.map +0 -1
- package/dist/api/v1/definition/validations.js.map +0 -1
- package/dist/api/v1/errors.cjs +0 -2
- package/dist/api/v1/errors.cjs.map +0 -1
- package/dist/api/v1/errors.js.map +0 -1
- package/dist/api/v1/index.cjs +0 -2
- package/dist/api/v1/index.cjs.map +0 -1
- package/dist/api/v1/index.js.map +0 -1
- package/dist/api/v1/validator/index.cjs +0 -2
- package/dist/api/v1/validator/index.cjs.map +0 -1
- package/dist/api/v1/validator/index.js.map +0 -1
- package/dist/api/v1/validator/validations.cjs +0 -2
- package/dist/api/v1/validator/validations.cjs.map +0 -1
- package/dist/api/v1/validator/validations.d.cts +0 -23
- package/dist/api/v1/validator/validations.js.map +0 -1
- package/dist/errors/index.cjs +0 -3
- package/dist/errors/index.cjs.map +0 -1
- package/dist/errors/index.js.map +0 -1
- package/dist/events/index.cjs +0 -2
- package/dist/events/index.cjs.map +0 -1
- package/dist/events/index.js.map +0 -1
- package/dist/hooks/enrich.cjs +0 -2
- package/dist/hooks/enrich.cjs.map +0 -1
- package/dist/hooks/enrich.js.map +0 -1
- package/dist/hooks/find.cjs +0 -2
- package/dist/hooks/find.cjs.map +0 -1
- package/dist/hooks/find.js.map +0 -1
- package/dist/hooks/hooks.cjs +0 -2
- package/dist/hooks/hooks.cjs.map +0 -1
- package/dist/hooks/hooks.js.map +0 -1
- package/dist/hooks/index.cjs +0 -1
- package/dist/hooks/utils/updateInstanceValues.cjs +0 -2
- package/dist/hooks/utils/updateInstanceValues.cjs.map +0 -1
- package/dist/hooks/utils/updateInstanceValues.js.map +0 -1
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -23
- package/dist/index.js.map +0 -1
- package/dist/models/CustomFieldDefinition.cjs +0 -2
- package/dist/models/CustomFieldDefinition.cjs.map +0 -1
- package/dist/models/CustomFieldDefinition.d.cts +0 -31
- package/dist/models/CustomFieldDefinition.js.map +0 -1
- package/dist/models/CustomFieldEntries.cjs +0 -2
- package/dist/models/CustomFieldEntries.cjs.map +0 -1
- package/dist/models/CustomFieldEntries.d.cts +0 -16
- package/dist/models/CustomFieldEntries.js.map +0 -1
- package/dist/models/CustomFieldValue.cjs +0 -2
- package/dist/models/CustomFieldValue.cjs.map +0 -1
- package/dist/models/CustomFieldValue.d.cts +0 -22
- package/dist/models/CustomFieldValue.js.map +0 -1
- package/dist/models/CustomValidator.cjs +0 -2
- package/dist/models/CustomValidator.cjs.map +0 -1
- package/dist/models/CustomValidator.d.cts +0 -19
- package/dist/models/CustomValidator.js.map +0 -1
- package/dist/models/index.cjs +0 -2
- package/dist/models/index.cjs.map +0 -1
- package/dist/models/index.d.cts +0 -6
- package/dist/models/index.js.map +0 -1
- package/dist/models/tests/AssociatedTestModel.cjs +0 -2
- package/dist/models/tests/AssociatedTestModel.cjs.map +0 -1
- package/dist/models/tests/AssociatedTestModel.js.map +0 -1
- package/dist/models/tests/TestModel.cjs +0 -2
- package/dist/models/tests/TestModel.cjs.map +0 -1
- package/dist/models/tests/TestModel.js.map +0 -1
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +0 -2
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +0 -1
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +0 -1
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +0 -2
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +0 -1
- package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +0 -1
- package/dist/repository/definition.cjs +0 -2
- package/dist/repository/definition.cjs.map +0 -1
- package/dist/repository/definition.js.map +0 -1
- package/dist/repository/entries.cjs +0 -2
- package/dist/repository/entries.cjs.map +0 -1
- package/dist/repository/entries.js.map +0 -1
- package/dist/repository/utils/formatValues.cjs +0 -2
- package/dist/repository/utils/formatValues.cjs.map +0 -1
- package/dist/repository/utils/formatValues.js.map +0 -1
- package/dist/repository/validator.cjs +0 -2
- package/dist/repository/validator.cjs.map +0 -1
- package/dist/repository/validator.js.map +0 -1
- package/dist/repository/value.cjs +0 -2
- package/dist/repository/value.cjs.map +0 -1
- package/dist/repository/value.js.map +0 -1
- package/dist/scopes/filter.cjs +0 -2
- package/dist/scopes/filter.cjs.map +0 -1
- package/dist/scopes/filter.d.cts +0 -23
- package/dist/scopes/filter.js.map +0 -1
- package/dist/scopes/helpers/filter.helpers.cjs +0 -46
- package/dist/scopes/helpers/filter.helpers.cjs.map +0 -1
- package/dist/scopes/helpers/filter.helpers.d.cts +0 -17
- package/dist/scopes/helpers/filter.helpers.js.map +0 -1
- package/dist/scopes/index.cjs +0 -1
- package/dist/types/index.d.cts +0 -45
- package/dist/utils/constants/index.cjs +0 -2
- package/dist/utils/constants/index.cjs.map +0 -1
- package/dist/utils/constants/index.d.cts +0 -22
- package/dist/utils/constants/index.js.map +0 -1
- package/dist/utils/db/index.cjs +0 -2
- package/dist/utils/db/index.cjs.map +0 -1
- package/dist/utils/db/index.js.map +0 -1
- package/dist/utils/helpers/index.cjs +0 -2
- package/dist/utils/helpers/index.cjs.map +0 -1
- package/dist/utils/helpers/index.d.cts +0 -31
- package/dist/utils/helpers/index.js.map +0 -1
- package/dist/utils/init.cjs +0 -2
- package/dist/utils/init.cjs.map +0 -1
- package/dist/utils/init.js.map +0 -1
- package/dist/utils/logger/index.cjs +0 -2
- package/dist/utils/logger/index.cjs.map +0 -1
- package/dist/utils/logger/index.js.map +0 -1
- package/dist/utils/scopeAttributes.cjs +0 -2
- package/dist/utils/scopeAttributes.cjs.map +0 -1
- package/dist/utils/scopeAttributes.js.map +0 -1
- package/dist/utils/validations/index.cjs +0 -2
- package/dist/utils/validations/index.cjs.map +0 -1
- package/dist/utils/validations/index.js.map +0 -1
- package/dist/utils/validations/schema/custom-fields.cjs +0 -2
- package/dist/utils/validations/schema/custom-fields.cjs.map +0 -1
- package/dist/utils/validations/schema/custom-fields.d.cts +0 -7
- package/dist/utils/validations/schema/custom-fields.js.map +0 -1
- package/dist/utils/validations/schema/validator-schema.cjs +0 -2
- package/dist/utils/validations/schema/validator-schema.cjs.map +0 -1
- package/dist/utils/validations/schema/validator-schema.js.map +0 -1
- package/dist/utils/validations/validators/index.cjs +0 -2
- package/dist/utils/validations/validators/index.cjs.map +0 -1
- package/dist/utils/validations/validators/index.js.map +0 -1
- package/dist/utils/validations/validators/select.validator.cjs +0 -2
- package/dist/utils/validations/validators/select.validator.cjs.map +0 -1
- package/dist/utils/validations/validators/select.validator.js.map +0 -1
- package/dist/utils/validations/validators/status.validator.cjs +0 -2
- package/dist/utils/validations/validators/status.validator.cjs.map +0 -1
- package/dist/utils/validations/validators/status.validator.js.map +0 -1
package/.nvmrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
22.9.0
|
package/dist/api/index.js
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
// export the api object
|
|
7
|
+
const node_common_1 = require("@autofleet/node-common");
|
|
8
|
+
const v1_1 = __importDefault(require("./v1"));
|
|
9
|
+
const logger_1 = __importDefault(require("../utils/logger"));
|
|
10
|
+
const router = (0, node_common_1.Router)({ logger: logger_1.default });
|
|
11
|
+
router.use('/v1', v1_1.default);
|
|
12
|
+
exports.default = router;
|
|
@@ -1,2 +1,116 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const errors_1 = require("@autofleet/errors");
|
|
30
|
+
const node_common_1 = require("@autofleet/node-common");
|
|
31
|
+
const errors_2 = __importDefault(require("../errors"));
|
|
32
|
+
const DefinitionRepo = __importStar(require("../../../repository/definition"));
|
|
33
|
+
const validations_1 = require("./validations");
|
|
34
|
+
const logger_1 = __importDefault(require("../../../utils/logger"));
|
|
35
|
+
const router = (0, node_common_1.Router)({ logger: logger_1.default });
|
|
36
|
+
const ENTITY = 'CustomFieldDefinition';
|
|
37
|
+
const toPascalCase = (str) => str.replace(/(^\w|-\w)/g, (subStr) => subStr.replace(/-/, '').toUpperCase());
|
|
38
|
+
/**
|
|
39
|
+
* Create
|
|
40
|
+
*/
|
|
41
|
+
router.post('/', async (req, res) => {
|
|
42
|
+
const { modelName } = req.params;
|
|
43
|
+
const modelType = toPascalCase(modelName);
|
|
44
|
+
try {
|
|
45
|
+
const validatedPayload = await (0, validations_1.validateCustomFieldDefinitionCreation)(req.body);
|
|
46
|
+
const customFieldDefinition = await DefinitionRepo.create({
|
|
47
|
+
...validatedPayload,
|
|
48
|
+
modelType,
|
|
49
|
+
});
|
|
50
|
+
return res.status(201).json(customFieldDefinition);
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
logger_1.default.error('Failed to create custom field definition', err);
|
|
54
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in create ${ENTITY} request` });
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
/**
|
|
58
|
+
* Get by id
|
|
59
|
+
*/
|
|
60
|
+
router.get('/:customFieldDefinitionId', async (req, res) => {
|
|
61
|
+
const { customFieldDefinitionId } = req.params;
|
|
62
|
+
try {
|
|
63
|
+
const customFieldDefinition = await DefinitionRepo.findById(customFieldDefinitionId);
|
|
64
|
+
if (!customFieldDefinition) {
|
|
65
|
+
throw new errors_1.ResourceNotFoundError();
|
|
66
|
+
}
|
|
67
|
+
return res.json(customFieldDefinition);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
logger_1.default.error('Failed to fetch custom field definition', err);
|
|
71
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in get ${ENTITY} request` });
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
/**
|
|
75
|
+
* Get all
|
|
76
|
+
*/
|
|
77
|
+
router.get('/', async (req, res) => {
|
|
78
|
+
const { params: { modelName }, query: { entityIds } } = req;
|
|
79
|
+
const modelType = toPascalCase(modelName);
|
|
80
|
+
try {
|
|
81
|
+
const where = {
|
|
82
|
+
modelType,
|
|
83
|
+
...(entityIds?.length > 0 && { entityId: entityIds }),
|
|
84
|
+
};
|
|
85
|
+
const customFieldDefinitions = await DefinitionRepo.findAll(where, { withDisabled: true });
|
|
86
|
+
return res.json(customFieldDefinitions);
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
logger_1.default.error('Failed to fetch custom field definitions', err);
|
|
90
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in get all ${ENTITY} request` });
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Update
|
|
95
|
+
*/
|
|
96
|
+
router.patch('/:customFieldDefinitionId', async (req, res) => {
|
|
97
|
+
const { customFieldDefinitionId, modelName } = req.params;
|
|
98
|
+
const modelType = toPascalCase(modelName);
|
|
99
|
+
try {
|
|
100
|
+
const validatedPayload = await (0, validations_1.validateCustomFieldDefinitionUpdate)(req.body);
|
|
101
|
+
const customFieldDefinition = await DefinitionRepo.findByWhere({
|
|
102
|
+
id: customFieldDefinitionId,
|
|
103
|
+
modelType,
|
|
104
|
+
});
|
|
105
|
+
if (!customFieldDefinition) {
|
|
106
|
+
throw new errors_1.ResourceNotFoundError();
|
|
107
|
+
}
|
|
108
|
+
const updatedCustomFieldDefinition = await DefinitionRepo.update(customFieldDefinitionId, { ...validatedPayload, modelType });
|
|
109
|
+
return res.status(200).json(updatedCustomFieldDefinition);
|
|
110
|
+
}
|
|
111
|
+
catch (err) {
|
|
112
|
+
logger_1.default.error('Failed to patch custom field definition', err);
|
|
113
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in update ${ENTITY} request` });
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
exports.default = router;
|
|
@@ -1,2 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateCustomFieldDefinitionUpdate = exports.validateCustomFieldDefinitionCreation = void 0;
|
|
7
|
+
/* eslint-disable newline-per-chained-call */
|
|
8
|
+
const joi_1 = __importDefault(require("joi"));
|
|
9
|
+
const constants_1 = require("../../../utils/constants");
|
|
10
|
+
const FileValidationSchema = joi_1.default.object({
|
|
11
|
+
name: joi_1.default.string().required(),
|
|
12
|
+
type: joi_1.default.string(),
|
|
13
|
+
size: joi_1.default.string(),
|
|
14
|
+
addedBy: joi_1.default.string().uuid(),
|
|
15
|
+
});
|
|
16
|
+
const statusValidationObject = joi_1.default.object({
|
|
17
|
+
value: joi_1.default.string().required(),
|
|
18
|
+
color: joi_1.default.string().required(),
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Schema for the validation of custom field definition
|
|
22
|
+
* The only custom validation is for
|
|
23
|
+
* {@link CustomFieldDefinitionType.SELECT SELECT}
|
|
24
|
+
* and
|
|
25
|
+
* {@link CustomFieldDefinitionType.STATUS STATUS}
|
|
26
|
+
* field types.
|
|
27
|
+
* The rest of the field types are validated by Joi
|
|
28
|
+
*/
|
|
29
|
+
const ValidationSchema = joi_1.default.when('fieldType', {
|
|
30
|
+
is: constants_1.CustomFieldDefinitionType.SELECT,
|
|
31
|
+
then: joi_1.default.array().required().items(joi_1.default.string()).min(1).unique(),
|
|
32
|
+
otherwise: joi_1.default.when('fieldType', {
|
|
33
|
+
is: constants_1.CustomFieldDefinitionType.STATUS,
|
|
34
|
+
then: joi_1.default.array().required().items(statusValidationObject).min(1).unique('value'),
|
|
35
|
+
otherwise: joi_1.default.forbidden(),
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
const DefaultValueSchema = joi_1.default.when('fieldType', {
|
|
39
|
+
switch: [
|
|
40
|
+
{ is: constants_1.CustomFieldDefinitionType.BOOLEAN, then: joi_1.default.boolean().allow(null) },
|
|
41
|
+
{ is: constants_1.CustomFieldDefinitionType.DATE, then: joi_1.default.date().allow(null) },
|
|
42
|
+
{ is: constants_1.CustomFieldDefinitionType.DATETIME, then: joi_1.default.date().allow(null) },
|
|
43
|
+
{ is: constants_1.CustomFieldDefinitionType.FILE, then: joi_1.default.array().items(FileValidationSchema).allow(null) },
|
|
44
|
+
{ is: constants_1.CustomFieldDefinitionType.IMAGE, then: joi_1.default.array().items(joi_1.default.string().uri()).allow(null) },
|
|
45
|
+
{ is: constants_1.CustomFieldDefinitionType.NUMBER, then: joi_1.default.number().allow(null) },
|
|
46
|
+
{ is: constants_1.CustomFieldDefinitionType.SELECT, then: joi_1.default.string().allow(null) },
|
|
47
|
+
{ is: constants_1.CustomFieldDefinitionType.STATUS, then: joi_1.default.string().allow(null) },
|
|
48
|
+
{ is: constants_1.CustomFieldDefinitionType.TEXT, then: joi_1.default.string().allow(null) },
|
|
49
|
+
],
|
|
50
|
+
});
|
|
51
|
+
const CustomFieldDefinitionCreationSchema = joi_1.default.object({
|
|
52
|
+
name: joi_1.default.string().required(),
|
|
53
|
+
displayName: joi_1.default.string().required(),
|
|
54
|
+
validation: ValidationSchema,
|
|
55
|
+
defaultValue: DefaultValueSchema,
|
|
56
|
+
fieldType: joi_1.default.string().valid(...Object.values(constants_1.CustomFieldDefinitionType)).required(),
|
|
57
|
+
entityId: joi_1.default.string().guid().required(),
|
|
58
|
+
entityType: joi_1.default.string().required(),
|
|
59
|
+
description: joi_1.default.string(),
|
|
60
|
+
required: joi_1.default.boolean(),
|
|
61
|
+
disabled: joi_1.default.boolean(),
|
|
62
|
+
blockEditingFromUI: joi_1.default.boolean(),
|
|
63
|
+
}).oxor('required', 'blockEditingFromUI', { isPresent: (value) => value === true });
|
|
64
|
+
const CustomFieldDefinitionUpdateSchema = joi_1.default.object({
|
|
65
|
+
displayName: joi_1.default.string(),
|
|
66
|
+
validation: ValidationSchema,
|
|
67
|
+
defaultValue: DefaultValueSchema,
|
|
68
|
+
fieldType: joi_1.default.string().valid(...Object.values(constants_1.CustomFieldDefinitionType)),
|
|
69
|
+
description: joi_1.default.string().allow(null),
|
|
70
|
+
required: joi_1.default.boolean(),
|
|
71
|
+
disabled: joi_1.default.boolean(),
|
|
72
|
+
blockEditingFromUI: joi_1.default.boolean(),
|
|
73
|
+
}).oxor('required', 'blockEditingFromUI', { isPresent: (value) => value === true });
|
|
74
|
+
const validateCustomFieldDefinitionCreation = (payload) => CustomFieldDefinitionCreationSchema.validateAsync(payload, { abortEarly: false });
|
|
75
|
+
exports.validateCustomFieldDefinitionCreation = validateCustomFieldDefinitionCreation;
|
|
76
|
+
const validateCustomFieldDefinitionUpdate = (payload) => CustomFieldDefinitionUpdateSchema.validateAsync(payload, { abortEarly: false });
|
|
77
|
+
exports.validateCustomFieldDefinitionUpdate = validateCustomFieldDefinitionUpdate;
|
package/dist/api/v1/errors.js
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const errors_1 = require("@autofleet/errors");
|
|
4
|
+
const joi_1 = require("joi");
|
|
5
|
+
const sequelize_1 = require("sequelize");
|
|
6
|
+
exports.default = (err, res, additionalData = undefined) => {
|
|
7
|
+
let error = err;
|
|
8
|
+
if ([joi_1.ValidationError, sequelize_1.ValidationError].some((ErrClass) => err instanceof ErrClass)) {
|
|
9
|
+
error = new errors_1.BadRequest([err], null);
|
|
10
|
+
}
|
|
11
|
+
return (0, errors_1.handleError)(error, res, additionalData);
|
|
12
|
+
};
|
package/dist/api/v1/index.js
CHANGED
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_common_1 = require("@autofleet/node-common");
|
|
7
|
+
const logger_1 = __importDefault(require("../../utils/logger"));
|
|
8
|
+
const definition_1 = __importDefault(require("./definition"));
|
|
9
|
+
const validator_1 = __importDefault(require("./validator"));
|
|
10
|
+
const router = (0, node_common_1.Router)({ logger: logger_1.default });
|
|
11
|
+
router.use('/custom-field-definitions/:modelName', definition_1.default);
|
|
12
|
+
router.use('/custom-validators/:modelName', validator_1.default);
|
|
13
|
+
exports.default = router;
|
|
@@ -1,2 +1,143 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const errors_1 = require("@autofleet/errors");
|
|
30
|
+
const node_common_1 = require("@autofleet/node-common");
|
|
31
|
+
const http_status_codes_1 = require("http-status-codes");
|
|
32
|
+
const errors_2 = __importDefault(require("../errors"));
|
|
33
|
+
const ValidatorRepo = __importStar(require("../../../repository/validator"));
|
|
34
|
+
const validations_1 = __importDefault(require("./validations"));
|
|
35
|
+
const logger_1 = __importDefault(require("../../../utils/logger"));
|
|
36
|
+
const validator_schema_1 = require("../../../utils/validations/schema/validator-schema");
|
|
37
|
+
const router = (0, node_common_1.Router)({ logger: logger_1.default });
|
|
38
|
+
const ENTITY = 'CustomValidator';
|
|
39
|
+
/**
|
|
40
|
+
* Create
|
|
41
|
+
*/
|
|
42
|
+
router.post('/', async (req, res) => {
|
|
43
|
+
const { modelName } = req.params;
|
|
44
|
+
try {
|
|
45
|
+
// Validate the request body
|
|
46
|
+
const validatedPayload = await validations_1.default.create.validateAsync(req.body);
|
|
47
|
+
// Validate that the schema is a valid AJV schema
|
|
48
|
+
(0, validator_schema_1.validateValidatorSchema)(validatedPayload.schema);
|
|
49
|
+
const validator = await ValidatorRepo.create({
|
|
50
|
+
...validatedPayload,
|
|
51
|
+
modelType: modelName,
|
|
52
|
+
});
|
|
53
|
+
return res.status(http_status_codes_1.StatusCodes.CREATED).json(validator);
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in create ${ENTITY} request` });
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Get all
|
|
61
|
+
*/
|
|
62
|
+
router.get('/', async (req, res) => {
|
|
63
|
+
try {
|
|
64
|
+
const { modelName } = req.params;
|
|
65
|
+
const { entityId, entityType } = req.query;
|
|
66
|
+
const where = {
|
|
67
|
+
modelType: modelName,
|
|
68
|
+
...(entityId && { entityId }),
|
|
69
|
+
...(entityType && { entityType }),
|
|
70
|
+
};
|
|
71
|
+
const validators = await ValidatorRepo.findAll(where);
|
|
72
|
+
return res.status(http_status_codes_1.StatusCodes.OK).json({ validators });
|
|
73
|
+
}
|
|
74
|
+
catch (err) {
|
|
75
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in get all ${ENTITY} request` });
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
/**
|
|
79
|
+
* Get by id
|
|
80
|
+
*/
|
|
81
|
+
router.get('/:validatorId', async (req, res) => {
|
|
82
|
+
try {
|
|
83
|
+
const { validatorId, modelName } = req.params;
|
|
84
|
+
// Include disabled validators when fetching by ID
|
|
85
|
+
const validators = await ValidatorRepo.findAll({ id: validatorId, modelType: modelName }, { withDisabled: true });
|
|
86
|
+
if (!validators.length) {
|
|
87
|
+
throw new errors_1.ResourceNotFoundError('Validator not found');
|
|
88
|
+
}
|
|
89
|
+
return res.status(http_status_codes_1.StatusCodes.OK).json(validators[0]);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in get ${ENTITY} request` });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Update
|
|
97
|
+
*/
|
|
98
|
+
router.patch('/:validatorId', async (req, res) => {
|
|
99
|
+
try {
|
|
100
|
+
const { validatorId } = req.params;
|
|
101
|
+
// Validate the request body
|
|
102
|
+
const validatedPayload = await validations_1.default.update.validateAsync(req.body);
|
|
103
|
+
// If schema is included in the update, validate that it's a valid AJV schema
|
|
104
|
+
if (validatedPayload.schema) {
|
|
105
|
+
(0, validator_schema_1.validateValidatorSchema)(validatedPayload.schema);
|
|
106
|
+
}
|
|
107
|
+
// First verify the validator exists, including disabled ones
|
|
108
|
+
const existingValidators = await ValidatorRepo.findAll({ id: validatorId }, { withDisabled: true });
|
|
109
|
+
if (!existingValidators.length) {
|
|
110
|
+
throw new errors_1.ResourceNotFoundError('Validator not found');
|
|
111
|
+
}
|
|
112
|
+
const [count, validators] = await ValidatorRepo.update(validatorId, validatedPayload);
|
|
113
|
+
if (!count) {
|
|
114
|
+
throw new errors_1.ResourceNotFoundError('Validator not found');
|
|
115
|
+
}
|
|
116
|
+
return res.status(http_status_codes_1.StatusCodes.OK).json(validators[0]);
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in update ${ENTITY} request` });
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
/**
|
|
123
|
+
* Delete (disable)
|
|
124
|
+
*/
|
|
125
|
+
router.delete('/:validatorId', async (req, res) => {
|
|
126
|
+
try {
|
|
127
|
+
const { validatorId } = req.params;
|
|
128
|
+
// First verify the validator exists, including disabled ones
|
|
129
|
+
const existingValidators = await ValidatorRepo.findAll({ id: validatorId }, { withDisabled: true });
|
|
130
|
+
if (!existingValidators.length) {
|
|
131
|
+
throw new errors_1.ResourceNotFoundError('Validator not found');
|
|
132
|
+
}
|
|
133
|
+
const [count] = await ValidatorRepo.disable(validatorId);
|
|
134
|
+
if (!count) {
|
|
135
|
+
throw new errors_1.ResourceNotFoundError('Validator failed to be disabled');
|
|
136
|
+
}
|
|
137
|
+
return res.status(http_status_codes_1.StatusCodes.NO_CONTENT).send();
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
return (0, errors_2.default)(err, res, { logger: logger_1.default, message: `Error in delete ${ENTITY} request` });
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
exports.default = router;
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
import Joi from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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 };
|
|
23
|
-
//# sourceMappingURL=validations.d.ts.map
|
|
1
|
+
import Joi from 'joi';
|
|
2
|
+
declare const validationSchemas: {
|
|
3
|
+
create: Joi.ObjectSchema<any>;
|
|
4
|
+
update: Joi.ObjectSchema<any>;
|
|
5
|
+
};
|
|
6
|
+
export default validationSchemas;
|
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const joi_1 = __importDefault(require("joi"));
|
|
7
|
+
const jsonSchemaValidation = joi_1.default.object().unknown(true);
|
|
8
|
+
const schemaObject = joi_1.default.object({
|
|
9
|
+
type: joi_1.default.string().valid('object'),
|
|
10
|
+
properties: joi_1.default.object({
|
|
11
|
+
before: jsonSchemaValidation,
|
|
12
|
+
after: jsonSchemaValidation,
|
|
13
|
+
}).required(),
|
|
14
|
+
required: joi_1.default.array().items(joi_1.default.string()),
|
|
15
|
+
allOf: joi_1.default.array().items(joi_1.default.object()),
|
|
16
|
+
anyOf: joi_1.default.array().items(joi_1.default.object()),
|
|
17
|
+
oneOf: joi_1.default.array().items(joi_1.default.object()),
|
|
18
|
+
additionalProperties: joi_1.default.alternatives().try(joi_1.default.boolean(), joi_1.default.object()),
|
|
19
|
+
$id: joi_1.default.string(),
|
|
20
|
+
$schema: joi_1.default.string(),
|
|
21
|
+
if: joi_1.default.object(),
|
|
22
|
+
then: joi_1.default.object(),
|
|
23
|
+
else: joi_1.default.object(),
|
|
24
|
+
});
|
|
25
|
+
const validationSchemas = {
|
|
26
|
+
create: joi_1.default.object({
|
|
27
|
+
entityId: joi_1.default.string().uuid().required(),
|
|
28
|
+
entityType: joi_1.default.string().required(),
|
|
29
|
+
schema: schemaObject.required(),
|
|
30
|
+
}),
|
|
31
|
+
update: joi_1.default.object({
|
|
32
|
+
entityId: joi_1.default.string().uuid(),
|
|
33
|
+
entityType: joi_1.default.string(),
|
|
34
|
+
schema: schemaObject,
|
|
35
|
+
disabled: joi_1.default.boolean(),
|
|
36
|
+
}).min(1),
|
|
37
|
+
};
|
|
38
|
+
exports.default = validationSchemas;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { BadRequest } from '@autofleet/errors';
|
|
2
|
+
import type { ValidationError } from 'joi';
|
|
3
|
+
import type { EntriesValidationError } from '../types/entries';
|
|
4
|
+
export declare class MissingRequiredCustomFieldError extends BadRequest {
|
|
5
|
+
constructor(missingFields: string[]);
|
|
6
|
+
}
|
|
7
|
+
export declare class UnsupportedCustomFieldTypeError extends BadRequest {
|
|
8
|
+
constructor(fieldType: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class UnsupportedCustomValidationError extends BadRequest {
|
|
11
|
+
constructor(fieldType: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class InvalidFieldTypeError extends BadRequest {
|
|
14
|
+
constructor(fieldType: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class InvalidValueError extends BadRequest {
|
|
17
|
+
constructor(value: any, fieldDefinitionName: string, joiValidationError: ValidationError);
|
|
18
|
+
}
|
|
19
|
+
export declare class InvalidEntriesError extends BadRequest {
|
|
20
|
+
constructor(modelId: string, validationErrors: EntriesValidationError[]);
|
|
21
|
+
}
|
|
22
|
+
export declare class MissingDefinitionError extends BadRequest {
|
|
23
|
+
constructor(fieldNames: string[]);
|
|
24
|
+
}
|
package/dist/errors/index.js
CHANGED
|
@@ -1,3 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MissingDefinitionError = exports.InvalidEntriesError = exports.InvalidValueError = exports.InvalidFieldTypeError = exports.UnsupportedCustomValidationError = exports.UnsupportedCustomFieldTypeError = exports.MissingRequiredCustomFieldError = void 0;
|
|
4
|
+
/* eslint-disable max-classes-per-file */
|
|
5
|
+
const errors_1 = require("@autofleet/errors");
|
|
6
|
+
class MissingRequiredCustomFieldError extends errors_1.BadRequest {
|
|
7
|
+
constructor(missingFields) {
|
|
8
|
+
const err = new Error(`The following custom fields are required: ${missingFields.join(',')}`);
|
|
9
|
+
super([err], null, missingFields);
|
|
10
|
+
this.message = 'MISSING_REQUIRED_CUSTOM_FIELDS';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.MissingRequiredCustomFieldError = MissingRequiredCustomFieldError;
|
|
14
|
+
class UnsupportedCustomFieldTypeError extends errors_1.BadRequest {
|
|
15
|
+
constructor(fieldType) {
|
|
16
|
+
const err = new Error(`Type "${fieldType}" is not supported`);
|
|
17
|
+
super([err], null, null);
|
|
18
|
+
this.message = 'UNSUPPORTED_CUSTOM_FIELD_TYPE';
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.UnsupportedCustomFieldTypeError = UnsupportedCustomFieldTypeError;
|
|
22
|
+
class UnsupportedCustomValidationError extends errors_1.BadRequest {
|
|
23
|
+
constructor(fieldType) {
|
|
24
|
+
const err = new Error(`Validation for "${fieldType}" is not supported`);
|
|
25
|
+
super([err], null, null);
|
|
26
|
+
this.message = 'UNSUPPORTED_CUSTOM_VALIDATION_TYPE';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.UnsupportedCustomValidationError = UnsupportedCustomValidationError;
|
|
30
|
+
class InvalidFieldTypeError extends errors_1.BadRequest {
|
|
31
|
+
constructor(fieldType) {
|
|
32
|
+
const err = new Error(`Invalid field type ${fieldType}`);
|
|
33
|
+
super([err], null, null);
|
|
34
|
+
this.message = 'INVALID_FIELD_TYPE';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.InvalidFieldTypeError = InvalidFieldTypeError;
|
|
38
|
+
class InvalidValueError extends errors_1.BadRequest {
|
|
39
|
+
constructor(value, fieldDefinitionName, joiValidationError) {
|
|
40
|
+
const formattedErrorMessage = joiValidationError.message
|
|
41
|
+
.replace(/"/g, '')
|
|
42
|
+
.replace('value', `'${fieldDefinitionName}'`);
|
|
43
|
+
const formattedValue = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
44
|
+
const invalidValueMessage = `Invalid Value on field '${fieldDefinitionName}'. ${formattedErrorMessage}. received: '${formattedValue}'`;
|
|
45
|
+
const err = new Error(invalidValueMessage);
|
|
46
|
+
super([err], null, null);
|
|
47
|
+
this.message = invalidValueMessage;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.InvalidValueError = InvalidValueError;
|
|
51
|
+
class InvalidEntriesError extends errors_1.BadRequest {
|
|
52
|
+
constructor(modelId, validationErrors) {
|
|
53
|
+
const errors = validationErrors.map((validationError) => new InvalidValueError(validationError.value, validationError.fieldDefinitionName, validationError.joiValidationError));
|
|
54
|
+
super(errors, null, null);
|
|
55
|
+
this.message = `Invalid entries on ${modelId}\n${validationErrors.map((validationError) => (`${validationError.fieldDefinitionName} - ${validationError.joiValidationError.message}`)).join('\n')}`;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.InvalidEntriesError = InvalidEntriesError;
|
|
59
|
+
class MissingDefinitionError extends errors_1.BadRequest {
|
|
60
|
+
constructor(fieldNames) {
|
|
61
|
+
const err = new Error(`Missing custom field definition for field ${fieldNames.join(',')}`);
|
|
62
|
+
super([err], null, null);
|
|
63
|
+
this.message = 'MISSING_DEFINITION';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.MissingDefinitionError = MissingDefinitionError;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Events from '@autofleet/events';
|
|
2
|
+
import type { CustomFieldDefinition, CustomFieldEntries, CustomFieldValue, CustomValidator } from '../models';
|
|
3
|
+
declare const events: Events;
|
|
4
|
+
export declare const sendDimEvent: (instance: CustomFieldDefinition | CustomFieldValue | CustomFieldEntries | CustomValidator) => void;
|
|
5
|
+
export default events;
|