@autofleet/sadot 1.1.7-beta → 1.1.7
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 +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorate.js +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.cjs +1 -0
- package/dist/_virtual/_@oxc-project_runtime@0.103.0/helpers/decorateMetadata.js +1 -0
- package/dist/_virtual/rolldown_runtime.cjs +1 -0
- package/dist/api/index.cjs +2 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.js +2 -12
- package/dist/api/index.js.map +1 -0
- package/dist/api/v1/definition/index.cjs +2 -0
- package/dist/api/v1/definition/index.cjs.map +1 -0
- package/dist/api/v1/definition/index.js +2 -116
- package/dist/api/v1/definition/index.js.map +1 -0
- package/dist/api/v1/definition/validations.cjs +2 -0
- package/dist/api/v1/definition/validations.cjs.map +1 -0
- package/dist/api/v1/definition/validations.js +2 -77
- package/dist/api/v1/definition/validations.js.map +1 -0
- package/dist/api/v1/errors.cjs +2 -0
- package/dist/api/v1/errors.cjs.map +1 -0
- package/dist/api/v1/errors.js +2 -12
- package/dist/api/v1/errors.js.map +1 -0
- package/dist/api/v1/index.cjs +2 -0
- package/dist/api/v1/index.cjs.map +1 -0
- package/dist/api/v1/index.js +2 -13
- package/dist/api/v1/index.js.map +1 -0
- package/dist/api/v1/validator/index.cjs +2 -0
- package/dist/api/v1/validator/index.cjs.map +1 -0
- package/dist/api/v1/validator/index.js +2 -143
- package/dist/api/v1/validator/index.js.map +1 -0
- package/dist/api/v1/validator/validations.cjs +2 -0
- package/dist/api/v1/validator/validations.cjs.map +1 -0
- package/dist/api/v1/validator/validations.d.cts +23 -0
- package/dist/api/v1/validator/validations.d.ts +23 -6
- package/dist/api/v1/validator/validations.js +2 -38
- package/dist/api/v1/validator/validations.js.map +1 -0
- package/dist/errors/index.cjs +3 -0
- package/dist/errors/index.cjs.map +1 -0
- package/dist/errors/index.js +3 -66
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.cjs +2 -0
- package/dist/events/index.cjs.map +1 -0
- package/dist/events/index.js +2 -54
- package/dist/events/index.js.map +1 -0
- package/dist/hooks/enrich.cjs +2 -0
- package/dist/hooks/enrich.cjs.map +1 -0
- package/dist/hooks/enrich.js +2 -198
- package/dist/hooks/enrich.js.map +1 -0
- package/dist/hooks/find.cjs +2 -0
- package/dist/hooks/find.cjs.map +1 -0
- package/dist/hooks/find.js +2 -29
- package/dist/hooks/find.js.map +1 -0
- package/dist/hooks/hooks.cjs +2 -0
- package/dist/hooks/hooks.cjs.map +1 -0
- package/dist/hooks/hooks.js +2 -388
- package/dist/hooks/hooks.js.map +1 -0
- package/dist/hooks/index.cjs +1 -0
- package/dist/hooks/index.js +1 -17
- package/dist/hooks/utils/updateInstanceValues.cjs +2 -0
- package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -0
- package/dist/hooks/utils/updateInstanceValues.js +2 -50
- package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +22 -12
- package/dist/index.js +2 -67
- package/dist/index.js.map +1 -0
- package/dist/models/CustomFieldDefinition.cjs +2 -0
- package/dist/models/CustomFieldDefinition.cjs.map +1 -0
- package/dist/models/CustomFieldDefinition.d.cts +31 -0
- package/dist/models/CustomFieldDefinition.d.ts +29 -23
- package/dist/models/CustomFieldDefinition.js +2 -192
- package/dist/models/CustomFieldDefinition.js.map +1 -0
- package/dist/models/CustomFieldEntries.cjs +2 -0
- package/dist/models/CustomFieldEntries.cjs.map +1 -0
- package/dist/models/CustomFieldEntries.d.cts +16 -0
- package/dist/models/CustomFieldEntries.d.ts +14 -13
- package/dist/models/CustomFieldEntries.js +2 -123
- package/dist/models/CustomFieldEntries.js.map +1 -0
- package/dist/models/CustomFieldValue.cjs +2 -0
- package/dist/models/CustomFieldValue.cjs.map +1 -0
- package/dist/models/CustomFieldValue.d.cts +22 -0
- package/dist/models/CustomFieldValue.d.ts +20 -14
- package/dist/models/CustomFieldValue.js +2 -151
- package/dist/models/CustomFieldValue.js.map +1 -0
- package/dist/models/CustomValidator.cjs +2 -0
- package/dist/models/CustomValidator.cjs.map +1 -0
- package/dist/models/CustomValidator.d.cts +19 -0
- package/dist/models/CustomValidator.d.ts +17 -15
- package/dist/models/CustomValidator.js +2 -98
- package/dist/models/CustomValidator.js.map +1 -0
- package/dist/models/index.cjs +2 -0
- package/dist/models/index.cjs.map +1 -0
- package/dist/models/index.d.cts +6 -0
- package/dist/models/index.d.ts +6 -18
- package/dist/models/index.js +2 -131
- package/dist/models/index.js.map +1 -0
- package/dist/models/tests/AssociatedTestModel.cjs +2 -0
- package/dist/models/tests/AssociatedTestModel.cjs.map +1 -0
- package/dist/models/tests/AssociatedTestModel.js +2 -71
- package/dist/models/tests/AssociatedTestModel.js.map +1 -0
- package/dist/models/tests/TestModel.cjs +2 -0
- package/dist/models/tests/TestModel.cjs.map +1 -0
- package/dist/models/tests/TestModel.js +2 -69
- package/dist/models/tests/TestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +2 -53
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +2 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +2 -47
- package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -0
- package/dist/repository/definition.cjs +2 -0
- package/dist/repository/definition.cjs.map +1 -0
- package/dist/repository/definition.js +2 -121
- package/dist/repository/definition.js.map +1 -0
- package/dist/repository/entries.cjs +2 -0
- package/dist/repository/entries.cjs.map +1 -0
- package/dist/repository/entries.js +2 -92
- package/dist/repository/entries.js.map +1 -0
- package/dist/repository/utils/formatValues.cjs +2 -0
- package/dist/repository/utils/formatValues.cjs.map +1 -0
- package/dist/repository/utils/formatValues.js +2 -16
- package/dist/repository/utils/formatValues.js.map +1 -0
- package/dist/repository/validator.cjs +2 -0
- package/dist/repository/validator.cjs.map +1 -0
- package/dist/repository/validator.js +2 -69
- package/dist/repository/validator.js.map +1 -0
- package/dist/repository/value.cjs +2 -0
- package/dist/repository/value.cjs.map +1 -0
- package/dist/repository/value.js +2 -124
- package/dist/repository/value.js.map +1 -0
- package/dist/scopes/filter.cjs +2 -0
- package/dist/scopes/filter.cjs.map +1 -0
- package/dist/scopes/filter.d.cts +23 -0
- package/dist/scopes/filter.d.ts +22 -29
- package/dist/scopes/filter.js +2 -75
- package/dist/scopes/filter.js.map +1 -0
- package/dist/scopes/helpers/filter.helpers.cjs +46 -0
- package/dist/scopes/helpers/filter.helpers.cjs.map +1 -0
- package/dist/scopes/helpers/filter.helpers.d.cts +17 -0
- package/dist/scopes/helpers/filter.helpers.d.ts +15 -40
- package/dist/scopes/helpers/filter.helpers.js +25 -183
- package/dist/scopes/helpers/filter.helpers.js.map +1 -0
- package/dist/scopes/index.cjs +1 -0
- package/dist/scopes/index.js +1 -6
- package/dist/types/index.d.cts +45 -0
- package/dist/types/index.d.ts +45 -46
- package/dist/utils/constants/index.cjs +2 -0
- package/dist/utils/constants/index.cjs.map +1 -0
- package/dist/utils/constants/index.d.cts +22 -0
- package/dist/utils/constants/index.d.ts +20 -17
- package/dist/utils/constants/index.js +2 -22
- package/dist/utils/constants/index.js.map +1 -0
- package/dist/utils/db/index.cjs +2 -0
- package/dist/utils/db/index.cjs.map +1 -0
- package/dist/utils/db/index.js +2 -24
- package/dist/utils/db/index.js.map +1 -0
- package/dist/utils/helpers/index.cjs +2 -0
- package/dist/utils/helpers/index.cjs.map +1 -0
- package/dist/utils/helpers/index.d.cts +31 -0
- package/dist/utils/helpers/index.d.ts +28 -23
- package/dist/utils/helpers/index.js +2 -40
- package/dist/utils/helpers/index.js.map +1 -0
- package/dist/utils/init.cjs +2 -0
- package/dist/utils/init.cjs.map +1 -0
- package/dist/utils/init.js +2 -112
- package/dist/utils/init.js.map +1 -0
- package/dist/utils/logger/index.cjs +2 -0
- package/dist/utils/logger/index.cjs.map +1 -0
- package/dist/utils/logger/index.js +2 -42
- package/dist/utils/logger/index.js.map +1 -0
- package/dist/utils/scopeAttributes.cjs +2 -0
- package/dist/utils/scopeAttributes.cjs.map +1 -0
- package/dist/utils/scopeAttributes.js +2 -11
- package/dist/utils/scopeAttributes.js.map +1 -0
- package/dist/utils/validations/index.cjs +2 -0
- package/dist/utils/validations/index.cjs.map +1 -0
- package/dist/utils/validations/index.js +2 -41
- package/dist/utils/validations/index.js.map +1 -0
- package/dist/utils/validations/schema/custom-fields.cjs +2 -0
- package/dist/utils/validations/schema/custom-fields.cjs.map +1 -0
- package/dist/utils/validations/schema/custom-fields.d.cts +7 -0
- package/dist/utils/validations/schema/custom-fields.d.ts +6 -2
- package/dist/utils/validations/schema/custom-fields.js +2 -9
- package/dist/utils/validations/schema/custom-fields.js.map +1 -0
- package/dist/utils/validations/schema/validator-schema.cjs +2 -0
- package/dist/utils/validations/schema/validator-schema.cjs.map +1 -0
- package/dist/utils/validations/schema/validator-schema.js +2 -95
- package/dist/utils/validations/schema/validator-schema.js.map +1 -0
- package/dist/utils/validations/validators/index.cjs +2 -0
- package/dist/utils/validations/validators/index.cjs.map +1 -0
- package/dist/utils/validations/validators/index.js +2 -40
- package/dist/utils/validations/validators/index.js.map +1 -0
- package/dist/utils/validations/validators/select.validator.cjs +2 -0
- package/dist/utils/validations/validators/select.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/select.validator.js +2 -12
- package/dist/utils/validations/validators/select.validator.js.map +1 -0
- package/dist/utils/validations/validators/status.validator.cjs +2 -0
- package/dist/utils/validations/validators/status.validator.cjs.map +1 -0
- package/dist/utils/validations/validators/status.validator.js +2 -15
- package/dist/utils/validations/validators/status.validator.js.map +1 -0
- package/package.json +40 -39
- package/.nvmrc +0 -1
- package/dist/api/index.d.ts +0 -3
- package/dist/api/v1/definition/index.d.ts +0 -3
- package/dist/api/v1/definition/validations.d.ts +0 -2
- package/dist/api/v1/errors.d.ts +0 -4
- package/dist/api/v1/index.d.ts +0 -3
- package/dist/api/v1/validator/index.d.ts +0 -3
- package/dist/errors/index.d.ts +0 -24
- package/dist/events/index.d.ts +0 -5
- package/dist/hooks/create.d.ts +0 -10
- package/dist/hooks/create.js +0 -95
- package/dist/hooks/enrich.d.ts +0 -25
- package/dist/hooks/find.d.ts +0 -1
- package/dist/hooks/hooks.d.ts +0 -17
- package/dist/hooks/index.d.ts +0 -5
- package/dist/hooks/update.d.ts +0 -10
- package/dist/hooks/update.js +0 -49
- package/dist/hooks/utils/updateInstanceValues.d.ts +0 -15
- package/dist/hooks/workaround.d.ts +0 -10
- package/dist/hooks/workaround.js +0 -37
- package/dist/models/tests/AssociatedTestModel.d.ts +0 -12
- package/dist/models/tests/TestModel.d.ts +0 -12
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +0 -10
- package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +0 -13
- package/dist/repository/definition.d.ts +0 -36
- package/dist/repository/entries.d.ts +0 -13
- package/dist/repository/utils/formatValues.d.ts +0 -3
- package/dist/repository/validator.d.ts +0 -28
- package/dist/repository/value.d.ts +0 -28
- package/dist/scopes/index.d.ts +0 -2
- package/dist/tests/api/test-api.d.ts +0 -2
- package/dist/tests/api/test-api.js +0 -38
- package/dist/tests/functional/searching/index.d.ts +0 -8
- package/dist/tests/functional/searching/index.js +0 -44
- package/dist/tests/helpers/commonHooks.d.ts +0 -6
- package/dist/tests/helpers/commonHooks.js +0 -62
- package/dist/tests/helpers/database-config.d.ts +0 -16
- package/dist/tests/helpers/database-config.js +0 -17
- package/dist/tests/helpers/index.d.ts +0 -7
- package/dist/tests/helpers/index.js +0 -33
- package/dist/tests/mocks/definition.mock.d.ts +0 -48
- package/dist/tests/mocks/definition.mock.js +0 -78
- package/dist/tests/mocks/events.mock.d.ts +0 -4
- package/dist/tests/mocks/events.mock.js +0 -21
- package/dist/tests/mocks/testModel.d.ts +0 -12
- package/dist/tests/mocks/testModel.js +0 -35
- package/dist/types/definition/index.d.ts +0 -25
- package/dist/types/definition/index.js +0 -2
- package/dist/types/entries/index.d.ts +0 -25
- package/dist/types/entries/index.js +0 -2
- package/dist/types/index.js +0 -2
- package/dist/types/value/index.d.ts +0 -15
- package/dist/types/value/index.js +0 -2
- package/dist/utils/db/index.d.ts +0 -4
- package/dist/utils/init.d.ts +0 -7
- package/dist/utils/logger/index.d.ts +0 -3
- package/dist/utils/scopeAttributes.d.ts +0 -2
- package/dist/utils/validations/index.d.ts +0 -8
- package/dist/utils/validations/schema/validator-schema.d.ts +0 -9
- package/dist/utils/validations/type.d.ts +0 -15
- package/dist/utils/validations/type.js +0 -2
- package/dist/utils/validations/validators/index.d.ts +0 -14
- package/dist/utils/validations/validators/select.validator.d.ts +0 -5
- package/dist/utils/validations/validators/status.validator.d.ts +0 -12
- package/src/api/index.ts +0 -10
- package/src/api/v1/definition/index.ts +0 -104
- package/src/api/v1/definition/validations.ts +0 -75
- package/src/api/v1/errors.ts +0 -13
- package/src/api/v1/index.ts +0 -11
- package/src/api/v1/validator/index.ts +0 -141
- package/src/api/v1/validator/validations.ts +0 -38
- package/src/errors/index.ts +0 -70
- package/src/events/index.ts +0 -63
- package/src/hooks/create.ts +0 -81
- package/src/hooks/enrich.ts +0 -255
- package/src/hooks/find.ts +0 -27
- package/src/hooks/hooks.ts +0 -479
- package/src/hooks/index.ts +0 -20
- package/src/hooks/update.ts +0 -55
- package/src/hooks/utils/updateInstanceValues.ts +0 -63
- package/src/hooks/workaround.ts +0 -47
- package/src/index.ts +0 -52
- package/src/models/CustomFieldDefinition.ts +0 -162
- package/src/models/CustomFieldEntries.ts +0 -81
- package/src/models/CustomFieldValue.ts +0 -118
- package/src/models/CustomValidator.ts +0 -78
- package/src/models/index.ts +0 -165
- package/src/models/tests/AssociatedTestModel.ts +0 -57
- package/src/models/tests/TestModel.ts +0 -54
- package/src/models/tests/contextAwareModels/ContextAwareTestModel.ts +0 -43
- package/src/models/tests/contextAwareModels/ContextTestModel.ts +0 -38
- package/src/repository/definition.ts +0 -175
- package/src/repository/entries.ts +0 -88
- package/src/repository/utils/formatValues.ts +0 -14
- package/src/repository/validator.ts +0 -119
- package/src/repository/value.ts +0 -116
- package/src/scopes/filter.ts +0 -100
- package/src/scopes/helpers/filter.helpers.ts +0 -227
- package/src/scopes/index.ts +0 -6
- package/src/tests/api/test-api.ts +0 -40
- package/src/tests/functional/searching/index.ts +0 -39
- package/src/tests/helpers/commonHooks.ts +0 -43
- package/src/tests/helpers/database-config.ts +0 -15
- package/src/tests/helpers/index.ts +0 -35
- package/src/tests/mocks/definition.mock.ts +0 -84
- package/src/tests/mocks/events.mock.ts +0 -21
- package/src/tests/mocks/testModel.ts +0 -37
- package/src/types/definition/index.ts +0 -24
- package/src/types/entries/index.ts +0 -27
- package/src/types/index.ts +0 -52
- package/src/types/value/index.ts +0 -14
- package/src/utils/constants/index.ts +0 -25
- package/src/utils/db/index.ts +0 -21
- package/src/utils/helpers/index.ts +0 -66
- package/src/utils/init.ts +0 -122
- package/src/utils/logger/index.ts +0 -14
- package/src/utils/scopeAttributes.ts +0 -12
- package/src/utils/validations/index.ts +0 -46
- package/src/utils/validations/schema/README.md +0 -93
- package/src/utils/validations/schema/custom-fields.ts +0 -8
- package/src/utils/validations/schema/validator-schema.ts +0 -106
- package/src/utils/validations/type.ts +0 -20
- package/src/utils/validations/validators/index.ts +0 -38
- package/src/utils/validations/validators/select.validator.ts +0 -12
- package/src/utils/validations/validators/status.validator.ts +0 -22
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -16
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/* eslint-disable newline-per-chained-call */
|
|
2
|
-
import Joi from 'joi';
|
|
3
|
-
import { CustomFieldDefinitionType } from '../../../utils/constants';
|
|
4
|
-
|
|
5
|
-
const FileValidationSchema = Joi.object({
|
|
6
|
-
name: Joi.string().required(),
|
|
7
|
-
type: Joi.string(),
|
|
8
|
-
size: Joi.string(),
|
|
9
|
-
addedBy: Joi.string().uuid(),
|
|
10
|
-
});
|
|
11
|
-
const statusValidationObject = Joi.object({
|
|
12
|
-
value: Joi.string().required(),
|
|
13
|
-
color: Joi.string().required(),
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Schema for the validation of custom field definition
|
|
17
|
-
* The only custom validation is for
|
|
18
|
-
* {@link CustomFieldDefinitionType.SELECT SELECT}
|
|
19
|
-
* and
|
|
20
|
-
* {@link CustomFieldDefinitionType.STATUS STATUS}
|
|
21
|
-
* field types.
|
|
22
|
-
* The rest of the field types are validated by Joi
|
|
23
|
-
*/
|
|
24
|
-
const ValidationSchema = Joi.when('fieldType', {
|
|
25
|
-
is: CustomFieldDefinitionType.SELECT,
|
|
26
|
-
then: Joi.array().required().items(Joi.string()).min(1).unique(),
|
|
27
|
-
otherwise: Joi.when('fieldType', {
|
|
28
|
-
is: CustomFieldDefinitionType.STATUS,
|
|
29
|
-
then: Joi.array().required().items(statusValidationObject).min(1).unique('value'),
|
|
30
|
-
otherwise: Joi.forbidden(),
|
|
31
|
-
}),
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const DefaultValueSchema = Joi.when('fieldType', {
|
|
35
|
-
switch: [
|
|
36
|
-
{ is: CustomFieldDefinitionType.BOOLEAN, then: Joi.boolean().allow(null) },
|
|
37
|
-
{ is: CustomFieldDefinitionType.DATE, then: Joi.date().allow(null) },
|
|
38
|
-
{ is: CustomFieldDefinitionType.DATETIME, then: Joi.date().allow(null) },
|
|
39
|
-
{ is: CustomFieldDefinitionType.FILE, then: Joi.array().items(FileValidationSchema).allow(null) },
|
|
40
|
-
{ is: CustomFieldDefinitionType.IMAGE, then: Joi.array().items(Joi.string().uri()).allow(null) },
|
|
41
|
-
{ is: CustomFieldDefinitionType.NUMBER, then: Joi.number().allow(null) },
|
|
42
|
-
{ is: CustomFieldDefinitionType.SELECT, then: Joi.string().allow(null) },
|
|
43
|
-
{ is: CustomFieldDefinitionType.STATUS, then: Joi.string().allow(null) },
|
|
44
|
-
{ is: CustomFieldDefinitionType.TEXT, then: Joi.string().allow(null) },
|
|
45
|
-
],
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const CustomFieldDefinitionCreationSchema = Joi.object({
|
|
49
|
-
name: Joi.string().required(),
|
|
50
|
-
displayName: Joi.string().required(),
|
|
51
|
-
validation: ValidationSchema,
|
|
52
|
-
defaultValue: DefaultValueSchema,
|
|
53
|
-
fieldType: Joi.string().valid(...Object.values(CustomFieldDefinitionType)).required(),
|
|
54
|
-
entityId: Joi.string().guid().required(),
|
|
55
|
-
entityType: Joi.string().required(),
|
|
56
|
-
description: Joi.string(),
|
|
57
|
-
required: Joi.boolean(),
|
|
58
|
-
disabled: Joi.boolean(),
|
|
59
|
-
blockEditingFromUI: Joi.boolean(),
|
|
60
|
-
}).oxor('required', 'blockEditingFromUI', { isPresent: (value) => value === true });
|
|
61
|
-
|
|
62
|
-
const CustomFieldDefinitionUpdateSchema = Joi.object({
|
|
63
|
-
displayName: Joi.string(),
|
|
64
|
-
validation: ValidationSchema,
|
|
65
|
-
defaultValue: DefaultValueSchema,
|
|
66
|
-
fieldType: Joi.string().valid(...Object.values(CustomFieldDefinitionType)),
|
|
67
|
-
description: Joi.string().allow(null),
|
|
68
|
-
required: Joi.boolean(),
|
|
69
|
-
disabled: Joi.boolean(),
|
|
70
|
-
blockEditingFromUI: Joi.boolean(),
|
|
71
|
-
}).oxor('required', 'blockEditingFromUI', { isPresent: (value) => value === true });
|
|
72
|
-
|
|
73
|
-
export const validateCustomFieldDefinitionCreation = (payload) => CustomFieldDefinitionCreationSchema.validateAsync(payload, { abortEarly: false });
|
|
74
|
-
|
|
75
|
-
export const validateCustomFieldDefinitionUpdate = (payload) => CustomFieldDefinitionUpdateSchema.validateAsync(payload, { abortEarly: false });
|
package/src/api/v1/errors.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Response } from 'express';
|
|
2
|
-
import { handleError, BadRequest, type LogPayload } from '@autofleet/errors';
|
|
3
|
-
import { ValidationError as InputValidationError } from 'joi';
|
|
4
|
-
import { ValidationError as DatabaseValidationError } from 'sequelize';
|
|
5
|
-
|
|
6
|
-
export default (err, res: Response, additionalData: LogPayload = undefined) => {
|
|
7
|
-
let error = err;
|
|
8
|
-
if ([InputValidationError, DatabaseValidationError].some((ErrClass) => err instanceof ErrClass)) {
|
|
9
|
-
error = new BadRequest([err], null);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return handleError(error, res, additionalData);
|
|
13
|
-
};
|
package/src/api/v1/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Router } from '@autofleet/node-common';
|
|
2
|
-
import logger from '../../utils/logger';
|
|
3
|
-
import definitionRouter from './definition';
|
|
4
|
-
import validatorRouter from './validator';
|
|
5
|
-
|
|
6
|
-
const router = Router({ logger });
|
|
7
|
-
|
|
8
|
-
router.use('/custom-field-definitions/:modelName', definitionRouter);
|
|
9
|
-
router.use('/custom-validators/:modelName', validatorRouter);
|
|
10
|
-
|
|
11
|
-
export default router;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { ResourceNotFoundError } from '@autofleet/errors';
|
|
2
|
-
import { Router } from '@autofleet/node-common';
|
|
3
|
-
import { StatusCodes } from 'http-status-codes';
|
|
4
|
-
import handleError from '../errors';
|
|
5
|
-
import * as ValidatorRepo from '../../../repository/validator';
|
|
6
|
-
import validations from './validations';
|
|
7
|
-
import logger from '../../../utils/logger';
|
|
8
|
-
import { validateValidatorSchema } from '../../../utils/validations/schema/validator-schema';
|
|
9
|
-
import type { CustomValidator } from '../../../models';
|
|
10
|
-
|
|
11
|
-
const router = Router({ logger });
|
|
12
|
-
const ENTITY = 'CustomValidator';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Create
|
|
16
|
-
*/
|
|
17
|
-
router.post<{ modelName: string }>('/', async (req, res) => {
|
|
18
|
-
const { modelName } = req.params;
|
|
19
|
-
try {
|
|
20
|
-
// Validate the request body
|
|
21
|
-
const validatedPayload = await validations.create.validateAsync(req.body);
|
|
22
|
-
|
|
23
|
-
// Validate that the schema is a valid AJV schema
|
|
24
|
-
validateValidatorSchema(validatedPayload.schema);
|
|
25
|
-
|
|
26
|
-
const validator = await ValidatorRepo.create({
|
|
27
|
-
...validatedPayload,
|
|
28
|
-
modelType: modelName,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return res.status(StatusCodes.CREATED).json(validator);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
return handleError(err, res, { logger, message: `Error in create ${ENTITY} request` });
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Get all
|
|
39
|
-
*/
|
|
40
|
-
router.get<
|
|
41
|
-
{ modelName: string },
|
|
42
|
-
{ validators: CustomValidator[] },
|
|
43
|
-
never,
|
|
44
|
-
{ entityId?: string; entityType?: string }
|
|
45
|
-
>('/', async (req, res) => {
|
|
46
|
-
try {
|
|
47
|
-
const { modelName } = req.params;
|
|
48
|
-
const { entityId, entityType } = req.query;
|
|
49
|
-
|
|
50
|
-
const where = {
|
|
51
|
-
modelType: modelName,
|
|
52
|
-
...(entityId && { entityId }),
|
|
53
|
-
...(entityType && { entityType }),
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const validators = await ValidatorRepo.findAll(where);
|
|
57
|
-
|
|
58
|
-
return res.status(StatusCodes.OK).json({ validators });
|
|
59
|
-
} catch (err) {
|
|
60
|
-
return handleError(err, res, { logger, message: `Error in get all ${ENTITY} request` });
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Get by id
|
|
66
|
-
*/
|
|
67
|
-
router.get<{ modelName: string; validatorId: string }, CustomValidator>('/:validatorId', async (req, res) => {
|
|
68
|
-
try {
|
|
69
|
-
const { validatorId, modelName } = req.params;
|
|
70
|
-
// Include disabled validators when fetching by ID
|
|
71
|
-
const validators = await ValidatorRepo.findAll({ id: validatorId, modelType: modelName }, { withDisabled: true });
|
|
72
|
-
|
|
73
|
-
if (!validators.length) {
|
|
74
|
-
throw new ResourceNotFoundError('Validator not found');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return res.status(StatusCodes.OK).json(validators[0]);
|
|
78
|
-
} catch (err) {
|
|
79
|
-
return handleError(err, res, { logger, message: `Error in get ${ENTITY} request` });
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Update
|
|
85
|
-
*/
|
|
86
|
-
router.patch<{ modelName: string; validatorId: string }, CustomValidator>('/:validatorId', async (req, res) => {
|
|
87
|
-
try {
|
|
88
|
-
const { validatorId } = req.params;
|
|
89
|
-
|
|
90
|
-
// Validate the request body
|
|
91
|
-
const validatedPayload = await validations.update.validateAsync(req.body);
|
|
92
|
-
|
|
93
|
-
// If schema is included in the update, validate that it's a valid AJV schema
|
|
94
|
-
if (validatedPayload.schema) {
|
|
95
|
-
validateValidatorSchema(validatedPayload.schema);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// First verify the validator exists, including disabled ones
|
|
99
|
-
const existingValidators = await ValidatorRepo.findAll({ id: validatorId }, { withDisabled: true });
|
|
100
|
-
if (!existingValidators.length) {
|
|
101
|
-
throw new ResourceNotFoundError('Validator not found');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const [count, validators] = await ValidatorRepo.update(validatorId, validatedPayload);
|
|
105
|
-
|
|
106
|
-
if (!count) {
|
|
107
|
-
throw new ResourceNotFoundError('Validator not found');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return res.status(StatusCodes.OK).json(validators[0]);
|
|
111
|
-
} catch (err) {
|
|
112
|
-
return handleError(err, res, { logger, message: `Error in update ${ENTITY} request` });
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Delete (disable)
|
|
118
|
-
*/
|
|
119
|
-
router.delete<{ modelName: string; validatorId: string }>('/:validatorId', async (req, res) => {
|
|
120
|
-
try {
|
|
121
|
-
const { validatorId } = req.params;
|
|
122
|
-
|
|
123
|
-
// First verify the validator exists, including disabled ones
|
|
124
|
-
const existingValidators = await ValidatorRepo.findAll({ id: validatorId }, { withDisabled: true });
|
|
125
|
-
if (!existingValidators.length) {
|
|
126
|
-
throw new ResourceNotFoundError('Validator not found');
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const [count] = await ValidatorRepo.disable(validatorId);
|
|
130
|
-
|
|
131
|
-
if (!count) {
|
|
132
|
-
throw new ResourceNotFoundError('Validator failed to be disabled');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return res.status(StatusCodes.NO_CONTENT).send();
|
|
136
|
-
} catch (err) {
|
|
137
|
-
return handleError(err, res, { logger, message: `Error in delete ${ENTITY} request` });
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
export default router;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
|
|
3
|
-
const jsonSchemaValidation = Joi.object().unknown(true);
|
|
4
|
-
|
|
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
|
-
|
|
23
|
-
const validationSchemas = {
|
|
24
|
-
create: Joi.object({
|
|
25
|
-
entityId: Joi.string().uuid().required(),
|
|
26
|
-
entityType: Joi.string().required(),
|
|
27
|
-
schema: schemaObject.required(),
|
|
28
|
-
}),
|
|
29
|
-
|
|
30
|
-
update: Joi.object({
|
|
31
|
-
entityId: Joi.string().uuid(),
|
|
32
|
-
entityType: Joi.string(),
|
|
33
|
-
schema: schemaObject,
|
|
34
|
-
disabled: Joi.boolean(),
|
|
35
|
-
}).min(1),
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export default validationSchemas;
|
package/src/errors/index.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/* eslint-disable max-classes-per-file */
|
|
2
|
-
import { BadRequest } from '@autofleet/errors';
|
|
3
|
-
import type { ValidationError } from 'joi';
|
|
4
|
-
import type { EntriesValidationError } from '../types/entries';
|
|
5
|
-
|
|
6
|
-
export class MissingRequiredCustomFieldError extends BadRequest {
|
|
7
|
-
constructor(missingFields: string[]) {
|
|
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
|
-
|
|
14
|
-
export class UnsupportedCustomFieldTypeError extends BadRequest {
|
|
15
|
-
constructor(fieldType: string) {
|
|
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
|
-
|
|
22
|
-
export class UnsupportedCustomValidationError extends BadRequest {
|
|
23
|
-
constructor(fieldType: string) {
|
|
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
|
-
|
|
30
|
-
export class InvalidFieldTypeError extends BadRequest {
|
|
31
|
-
constructor(fieldType: string) {
|
|
32
|
-
const err = new Error(`Invalid field type ${fieldType}`);
|
|
33
|
-
super([err], null, null);
|
|
34
|
-
this.message = 'INVALID_FIELD_TYPE';
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export class InvalidValueError extends BadRequest {
|
|
39
|
-
constructor(value: any, fieldDefinitionName: string, joiValidationError: ValidationError) {
|
|
40
|
-
const formattedErrorMessage = joiValidationError.message
|
|
41
|
-
.replace(/"/g, '')
|
|
42
|
-
.replace('value', `'${fieldDefinitionName}'`);
|
|
43
|
-
|
|
44
|
-
const formattedValue = typeof value === 'object' ? JSON.stringify(value) : value;
|
|
45
|
-
|
|
46
|
-
const invalidValueMessage = `Invalid Value on field '${fieldDefinitionName}'. ${formattedErrorMessage}. received: '${formattedValue}'`;
|
|
47
|
-
|
|
48
|
-
const err = new Error(invalidValueMessage);
|
|
49
|
-
super([err], null, null);
|
|
50
|
-
this.message = invalidValueMessage;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export class InvalidEntriesError extends BadRequest {
|
|
55
|
-
constructor(modelId: string, validationErrors: EntriesValidationError[]) {
|
|
56
|
-
const errors = validationErrors.map((validationError) => new InvalidValueError(validationError.value, validationError.fieldDefinitionName, validationError.joiValidationError));
|
|
57
|
-
super(errors, null, null);
|
|
58
|
-
this.message = `Invalid entries on ${modelId}\n${validationErrors.map((validationError) => (
|
|
59
|
-
`${validationError.fieldDefinitionName} - ${validationError.joiValidationError.message}`
|
|
60
|
-
)).join('\n')}`;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export class MissingDefinitionError extends BadRequest {
|
|
65
|
-
constructor(fieldNames: string[]) {
|
|
66
|
-
const err = new Error(`Missing custom field definition for field ${fieldNames.join(',')}`);
|
|
67
|
-
super([err], null, null);
|
|
68
|
-
this.message = 'MISSING_DEFINITION';
|
|
69
|
-
}
|
|
70
|
-
}
|
package/src/events/index.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import Events from '@autofleet/events';
|
|
2
|
-
import { getUser } from '@autofleet/zehut';
|
|
3
|
-
import logger from '../utils/logger';
|
|
4
|
-
import type {
|
|
5
|
-
CustomFieldDefinition,
|
|
6
|
-
CustomFieldEntries,
|
|
7
|
-
CustomFieldValue,
|
|
8
|
-
CustomValidator,
|
|
9
|
-
} from '../models';
|
|
10
|
-
|
|
11
|
-
const events = new Events({
|
|
12
|
-
logger,
|
|
13
|
-
getUserId: (payload) => payload?.user_id ?? getUser()?.id ?? null,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const KEYS_TO_CONVERT = ['value', 'defaultValue', 'blockEditingFromUI'];
|
|
17
|
-
|
|
18
|
-
const stringifyBooleans = (savedObject: any, keysToConvert: string[]) => {
|
|
19
|
-
const savedObjectKeySet = new Set(Object.keys(savedObject));
|
|
20
|
-
if (keysToConvert.every((key) => !savedObjectKeySet.has(key))) {
|
|
21
|
-
return savedObject;
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
...savedObject,
|
|
25
|
-
...Object.fromEntries(keysToConvert.map((key) => [key, typeof savedObject[key] === 'boolean' ? savedObject[key].toString() : savedObject[key]])),
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const modelTableMapping = {
|
|
30
|
-
CustomFieldDefinition: {
|
|
31
|
-
tableName: 'dim_custom_field_definition',
|
|
32
|
-
eventVersion: '1',
|
|
33
|
-
},
|
|
34
|
-
CustomFieldValue: {
|
|
35
|
-
tableName: 'dim_custom_field_value',
|
|
36
|
-
eventVersion: '1',
|
|
37
|
-
},
|
|
38
|
-
CustomFieldEntries: {
|
|
39
|
-
tableName: 'dim_custom_field_entries',
|
|
40
|
-
eventVersion: '1',
|
|
41
|
-
},
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const sendDimEvent = (instance: CustomFieldDefinition | CustomFieldValue | CustomFieldEntries | CustomValidator): void => {
|
|
45
|
-
const mapping = modelTableMapping[instance.constructor.name];
|
|
46
|
-
if (!mapping) {
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
let objectToSend = instance.get();
|
|
50
|
-
try {
|
|
51
|
-
objectToSend = stringifyBooleans(instance.get(), KEYS_TO_CONVERT);
|
|
52
|
-
} catch (err) {
|
|
53
|
-
logger.error('Failed to convert booleans in dim event payload', err);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
events.sendObject(
|
|
57
|
-
mapping.tableName,
|
|
58
|
-
mapping.eventVersion,
|
|
59
|
-
objectToSend,
|
|
60
|
-
).catch(() => {});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export default events;
|
package/src/hooks/create.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { WhereOptions } from 'sequelize';
|
|
2
|
-
import logger from '../utils/logger';
|
|
3
|
-
import * as DefinitionRepo from '../repository/definition';
|
|
4
|
-
import { MissingRequiredCustomFieldError } from '../errors';
|
|
5
|
-
import type { CustomFieldOptions, ModelOptions } from '../types';
|
|
6
|
-
import applyScopeToInstance from '../utils/scopeAttributes';
|
|
7
|
-
import updateInstanceValues from './utils/updateInstanceValues';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* A hook to create the custom fields when updating a model (more then one instance).
|
|
11
|
-
*/
|
|
12
|
-
export const beforeBulkCreate = (options): void => {
|
|
13
|
-
// This will activate the beforeCreate hook on each updating instance.
|
|
14
|
-
// eslint-disable-next-line no-param-reassign
|
|
15
|
-
options.individualHooks = true;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* A hook to create the custom fields when updating a model instance.
|
|
19
|
-
* TODO - cleanup if update fail
|
|
20
|
-
*/
|
|
21
|
-
export const beforeCreate = (
|
|
22
|
-
scopeAttributes: string[],
|
|
23
|
-
modelOptions: ModelOptions = {},
|
|
24
|
-
sadotOptions: Pick<CustomFieldOptions, 'useCustomFieldsEntries'> = { useCustomFieldsEntries: false },
|
|
25
|
-
) => async (
|
|
26
|
-
instance,
|
|
27
|
-
options,
|
|
28
|
-
): Promise<void> => {
|
|
29
|
-
logger.debug('sadot - before create hook');
|
|
30
|
-
const { fields } = options;
|
|
31
|
-
const { include, useEntityIdFromInclude } = modelOptions;
|
|
32
|
-
const modelType = instance.constructor.name;
|
|
33
|
-
|
|
34
|
-
const identifiers = applyScopeToInstance(instance, scopeAttributes);
|
|
35
|
-
|
|
36
|
-
const where: WhereOptions = {
|
|
37
|
-
modelType,
|
|
38
|
-
disabled: false,
|
|
39
|
-
...(!useEntityIdFromInclude && { entityId: identifiers }),
|
|
40
|
-
};
|
|
41
|
-
const fieldDefinitions = await DefinitionRepo.findAll(where, { withDisabled: false, transaction: options.transaction, include: include?.(identifiers) });
|
|
42
|
-
const requiredFieldsNames = Array.from(new Set(fieldDefinitions.filter(({ required }) => required).map(({ name }) => name)));
|
|
43
|
-
|
|
44
|
-
const fieldsWithDefaultValue = fieldDefinitions.filter((def) => ![null, undefined].includes(def.defaultValue));
|
|
45
|
-
if (fieldsWithDefaultValue.length) {
|
|
46
|
-
// eslint-disable-next-line no-param-reassign
|
|
47
|
-
instance.customFields ||= {};
|
|
48
|
-
fieldsWithDefaultValue.filter((def) => (instance.customFields?.[def.name] === undefined)).forEach(({ name, defaultValue }) => {
|
|
49
|
-
// eslint-disable-next-line no-param-reassign
|
|
50
|
-
instance.customFields[name] = defaultValue;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const { customFields } = instance;
|
|
55
|
-
const fieldsNames = Object.keys(customFields ?? {});
|
|
56
|
-
const missingFields = requiredFieldsNames.filter((name) => !fieldsNames.includes(name));
|
|
57
|
-
if (missingFields?.length) {
|
|
58
|
-
throw new MissingRequiredCustomFieldError(missingFields);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const customFieldsIdx = fields.indexOf('customFields');
|
|
62
|
-
if (customFieldsIdx === -1 || !customFields || !Object.keys(customFields).length) {
|
|
63
|
-
// After checking for required fields and fields with default values, and we have no custom fields.
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
await updateInstanceValues({
|
|
68
|
-
modelId: instance.id,
|
|
69
|
-
modelType,
|
|
70
|
-
identifiers,
|
|
71
|
-
customFields,
|
|
72
|
-
options: {
|
|
73
|
-
useCustomFieldsEntries: sadotOptions.useCustomFieldsEntries,
|
|
74
|
-
transaction: options.transaction,
|
|
75
|
-
modelOptions,
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// eslint-disable-next-line no-param-reassign
|
|
80
|
-
fields.splice(customFieldsIdx, 1);
|
|
81
|
-
};
|