@autofleet/sadot 1.0.3 → 1.0.6
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/api/index.js +1 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/v1/definition/index.js +1 -0
- package/dist/api/v1/definition/index.js.map +1 -0
- package/dist/api/v1/definition/validations.js +1 -0
- package/dist/api/v1/definition/validations.js.map +1 -0
- package/dist/api/v1/errors.js +1 -0
- package/dist/api/v1/errors.js.map +1 -0
- package/dist/api/v1/index.js +1 -0
- package/dist/api/v1/index.js.map +1 -0
- package/dist/api/v1/validator/index.js +1 -0
- package/dist/api/v1/validator/index.js.map +1 -0
- package/dist/api/v1/validator/validations.js +1 -0
- package/dist/api/v1/validator/validations.js.map +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/index.js +1 -0
- package/dist/events/index.js.map +1 -0
- package/dist/hooks/create.js +2 -1
- package/dist/hooks/create.js.map +1 -0
- package/dist/hooks/enrich.js +4 -4
- package/dist/hooks/enrich.js.map +1 -0
- package/dist/hooks/find.js +1 -0
- package/dist/hooks/find.js.map +1 -0
- package/dist/hooks/hooks.js +3 -3
- package/dist/hooks/hooks.js.map +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/hooks/update.js +1 -0
- package/dist/hooks/update.js.map +1 -0
- package/dist/hooks/utils/updateInstanceValues.js +1 -0
- package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
- package/dist/hooks/workaround.js +1 -0
- package/dist/hooks/workaround.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/models/CustomFieldDefinition.js +13 -3
- package/dist/models/CustomFieldDefinition.js.map +1 -0
- package/dist/models/CustomFieldEntries.js +9 -2
- package/dist/models/CustomFieldEntries.js.map +1 -0
- package/dist/models/CustomFieldValue.js +13 -3
- package/dist/models/CustomFieldValue.js.map +1 -0
- package/dist/models/CustomValidator.js +9 -2
- package/dist/models/CustomValidator.js.map +1 -0
- package/dist/models/index.js +1 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/tests/AssociatedTestModel.js +4 -1
- package/dist/models/tests/AssociatedTestModel.js.map +1 -0
- package/dist/models/tests/TestModel.js +4 -1
- package/dist/models/tests/TestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +1 -0
- package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js +1 -0
- package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -0
- package/dist/repository/definition.d.ts +2 -1
- package/dist/repository/definition.js +5 -2
- package/dist/repository/definition.js.map +1 -0
- package/dist/repository/entries.js +1 -0
- package/dist/repository/entries.js.map +1 -0
- package/dist/repository/utils/formatValues.js +1 -0
- package/dist/repository/utils/formatValues.js.map +1 -0
- package/dist/repository/validator.js +1 -0
- package/dist/repository/validator.js.map +1 -0
- package/dist/repository/value.js +1 -0
- package/dist/repository/value.js.map +1 -0
- package/dist/scopes/filter.d.ts +1 -1
- package/dist/scopes/filter.js +1 -0
- package/dist/scopes/filter.js.map +1 -0
- package/dist/scopes/helpers/filter.helpers.js +1 -0
- package/dist/scopes/helpers/filter.helpers.js.map +1 -0
- package/dist/scopes/index.js +1 -0
- package/dist/scopes/index.js.map +1 -0
- package/dist/types/definition/index.js +1 -0
- package/dist/types/definition/index.js.map +1 -0
- package/dist/types/entries/index.js +1 -0
- package/dist/types/entries/index.js.map +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/value/index.js +1 -0
- package/dist/types/value/index.js.map +1 -0
- package/dist/utils/constants/index.d.ts +1 -1
- package/dist/utils/constants/index.js +1 -0
- package/dist/utils/constants/index.js.map +1 -0
- package/dist/utils/db/index.js +1 -0
- package/dist/utils/db/index.js.map +1 -0
- package/dist/utils/helpers/index.js +1 -0
- package/dist/utils/helpers/index.js.map +1 -0
- package/dist/utils/init.js +1 -0
- package/dist/utils/init.js.map +1 -0
- package/dist/utils/logger/index.js +1 -0
- package/dist/utils/logger/index.js.map +1 -0
- package/dist/utils/scopeAttributes.js +1 -0
- package/dist/utils/scopeAttributes.js.map +1 -0
- package/dist/utils/validations/index.d.ts +1 -1
- package/dist/utils/validations/index.js +3 -2
- package/dist/utils/validations/index.js.map +1 -0
- package/dist/utils/validations/schema/custom-fields.js +1 -0
- package/dist/utils/validations/schema/custom-fields.js.map +1 -0
- package/dist/utils/validations/schema/validator-schema.js +1 -0
- package/dist/utils/validations/schema/validator-schema.js.map +1 -0
- package/dist/utils/validations/type.js +1 -0
- package/dist/utils/validations/type.js.map +1 -0
- package/dist/utils/validations/validators/index.js +1 -0
- package/dist/utils/validations/validators/index.js.map +1 -0
- package/dist/utils/validations/validators/select.validator.js +1 -0
- package/dist/utils/validations/validators/select.validator.js.map +1 -0
- package/dist/utils/validations/validators/status.validator.js +1 -0
- package/dist/utils/validations/validators/status.validator.js.map +1 -0
- package/package.json +22 -23
- package/.nvmrc +0 -1
- 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/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,106 +0,0 @@
|
|
|
1
|
-
import Ajv from 'ajv';
|
|
2
|
-
import addFormats from 'ajv-formats';
|
|
3
|
-
import { BadRequest } from '@autofleet/errors';
|
|
4
|
-
import logger from '../../logger';
|
|
5
|
-
|
|
6
|
-
// Instantiate Ajv for meta-validation
|
|
7
|
-
const metaValidator = new Ajv({
|
|
8
|
-
allErrors: true,
|
|
9
|
-
strict: false,
|
|
10
|
-
strictTypes: false,
|
|
11
|
-
$data: true, // Enable $data references
|
|
12
|
-
});
|
|
13
|
-
addFormats(metaValidator);
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Schema for validating JSON Schema objects in custom validators
|
|
17
|
-
* This is a meta-schema to ensure that custom validator schemas are valid Ajv schemas
|
|
18
|
-
*/
|
|
19
|
-
const validatorMetaSchema = {
|
|
20
|
-
type: 'object',
|
|
21
|
-
properties: {
|
|
22
|
-
type: { type: 'string', enum: ['object'] },
|
|
23
|
-
properties: {
|
|
24
|
-
type: 'object',
|
|
25
|
-
properties: {
|
|
26
|
-
before: {
|
|
27
|
-
type: 'object',
|
|
28
|
-
properties: {
|
|
29
|
-
type: { type: 'string', enum: ['object'] },
|
|
30
|
-
properties: { type: 'object' },
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
after: {
|
|
34
|
-
type: 'object',
|
|
35
|
-
properties: {
|
|
36
|
-
type: { type: 'string', enum: ['object'] },
|
|
37
|
-
properties: { type: 'object' },
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
required: {
|
|
43
|
-
type: 'array',
|
|
44
|
-
items: { type: 'string' },
|
|
45
|
-
},
|
|
46
|
-
if: { type: 'object' },
|
|
47
|
-
then: { type: 'object' },
|
|
48
|
-
else: { type: 'object' },
|
|
49
|
-
},
|
|
50
|
-
required: ['type', 'properties'],
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Validates that a given schema is a valid Ajv schema
|
|
55
|
-
* This function is used to validate schemas passed to custom validators
|
|
56
|
-
*
|
|
57
|
-
* @param schema The schema to validate
|
|
58
|
-
* @returns true if valid, throws an error if invalid
|
|
59
|
-
*/
|
|
60
|
-
export const validateValidatorSchema = (schema: Record<string, unknown>): boolean => {
|
|
61
|
-
try {
|
|
62
|
-
// First validate the schema structure
|
|
63
|
-
const validateMetaSchema = metaValidator.compile(validatorMetaSchema);
|
|
64
|
-
const isValidStructure = validateMetaSchema(schema);
|
|
65
|
-
|
|
66
|
-
if (!isValidStructure) {
|
|
67
|
-
const errorDetails = validateMetaSchema.errors?.map((err) =>
|
|
68
|
-
`${(err as unknown as { instancePath: string }).instancePath || ''} ${(err as unknown as { message: string }).message || 'Invalid schema structure'}`).join(', ');
|
|
69
|
-
|
|
70
|
-
logger.error('Invalid validator schema structure', {
|
|
71
|
-
errors: validateMetaSchema.errors,
|
|
72
|
-
schema,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
throw new BadRequest(
|
|
76
|
-
[new Error(`Invalid validator schema structure: ${errorDetails}`)],
|
|
77
|
-
['Invalid validator schema structure'],
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Then try to compile the schema with Ajv to verify it's a valid JSON Schema
|
|
82
|
-
try {
|
|
83
|
-
metaValidator.compile(schema);
|
|
84
|
-
return true;
|
|
85
|
-
} catch (compileError) {
|
|
86
|
-
logger.error('Failed to compile validator schema', { error: compileError, schema });
|
|
87
|
-
|
|
88
|
-
throw new BadRequest(
|
|
89
|
-
[new Error(`Failed to compile validator schema: ${(compileError as Error).message}`)],
|
|
90
|
-
['Invalid validator schema'],
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
} catch (error) {
|
|
94
|
-
if (error instanceof BadRequest) {
|
|
95
|
-
throw error;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
logger.error('Error validating validator schema', { error, schema });
|
|
99
|
-
throw new BadRequest(
|
|
100
|
-
[new Error(`Error validating validator schema: ${(error as Error).message}`)],
|
|
101
|
-
['Invalid validator schema'],
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export default validateValidatorSchema;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ValidationResult } from 'joi';
|
|
2
|
-
import type { CustomFieldDefinitionType } from '../constants';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Validator is a function that validates a custom-field `value`,
|
|
6
|
-
* against a custom-field definition `validation object`.
|
|
7
|
-
* @returns `true` if the value is valid, `false` otherwise.
|
|
8
|
-
*/
|
|
9
|
-
export type Validator<Value, DefinitionValidationObject> = (
|
|
10
|
-
value: Value,
|
|
11
|
-
validation?: DefinitionValidationObject
|
|
12
|
-
) => ValidationResult;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Validators is a map of custom-field types to their respective validators.
|
|
16
|
-
* The key is the custom-field type, and the value is the validator function.
|
|
17
|
-
*/
|
|
18
|
-
export type Validators = {
|
|
19
|
-
[K in CustomFieldDefinitionType]: Validator<unknown, unknown>;
|
|
20
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import { CustomFieldDefinitionType } from '../../constants';
|
|
3
|
-
import type { Validators } from '../type';
|
|
4
|
-
import { validateSelect } from './select.validator';
|
|
5
|
-
import { validateStatus } from './status.validator';
|
|
6
|
-
|
|
7
|
-
type CustomValidationTypes = Extract<CustomFieldDefinitionType, 'select' | 'status'>;
|
|
8
|
-
/**
|
|
9
|
-
* Custom field types that must have custom validation.
|
|
10
|
-
* TODO: remove this after moving to schema-based validation
|
|
11
|
-
*/
|
|
12
|
-
export const CustomValidationTypes = {
|
|
13
|
-
[CustomFieldDefinitionType.SELECT]: CustomFieldDefinitionType.SELECT,
|
|
14
|
-
[CustomFieldDefinitionType.STATUS]: CustomFieldDefinitionType.STATUS,
|
|
15
|
-
} as const;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Validators for custom fields
|
|
19
|
-
*/
|
|
20
|
-
export const validators: Validators = {
|
|
21
|
-
[CustomFieldDefinitionType.SELECT]: validateSelect,
|
|
22
|
-
[CustomFieldDefinitionType.STATUS]: validateStatus,
|
|
23
|
-
[CustomFieldDefinitionType.TEXT]: (value) => Joi.string().min(0).validate(value),
|
|
24
|
-
[CustomFieldDefinitionType.NUMBER]: (value) => Joi.number().strict(true).validate(value),
|
|
25
|
-
[CustomFieldDefinitionType.BOOLEAN]: (value) => Joi.boolean().strict().validate(value),
|
|
26
|
-
[CustomFieldDefinitionType.DATE]: (value) => Joi.date().validate(value),
|
|
27
|
-
[CustomFieldDefinitionType.DATETIME]: (value) => Joi.date().validate(value),
|
|
28
|
-
[CustomFieldDefinitionType.IMAGE]: (value) => Joi.array().min(1).unique()
|
|
29
|
-
.items(Joi.string().uri())
|
|
30
|
-
.validate(value),
|
|
31
|
-
[CustomFieldDefinitionType.FILE]: (value) => Joi.array().min(1).unique().items(Joi.object({
|
|
32
|
-
name: Joi.string().required(),
|
|
33
|
-
type: Joi.string(),
|
|
34
|
-
size: Joi.string(),
|
|
35
|
-
addedBy: Joi.string().uuid(),
|
|
36
|
-
}))
|
|
37
|
-
.validate(value),
|
|
38
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import type { Validator } from '../type';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Validate that the value is one of the select values
|
|
6
|
-
*/
|
|
7
|
-
export const validateSelect: Validator<string, string[]> = (
|
|
8
|
-
value,
|
|
9
|
-
selectValues,
|
|
10
|
-
) => (
|
|
11
|
-
Joi.string().allow(null).valid(...selectValues).validate(value)
|
|
12
|
-
);
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import Joi from 'joi';
|
|
2
|
-
import type { Validator } from '../type';
|
|
3
|
-
|
|
4
|
-
type StatusColor = string | null; // TODO: Takes from @autofleet/colors ?
|
|
5
|
-
type StatusValue = string;
|
|
6
|
-
type StatusOption = {
|
|
7
|
-
value: StatusValue;
|
|
8
|
-
color: StatusColor;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Validate that the value is one of the status values
|
|
13
|
-
*/
|
|
14
|
-
export const validateStatus: Validator<StatusValue, StatusOption[]> = (
|
|
15
|
-
value,
|
|
16
|
-
statusValues,
|
|
17
|
-
) => (
|
|
18
|
-
Joi.string()
|
|
19
|
-
.allow(null)
|
|
20
|
-
.valid(...statusValues.map((statusValue) => statusValue.value))
|
|
21
|
-
.validate(value)
|
|
22
|
-
);
|
package/tsconfig.build.json
DELETED
package/tsconfig.json
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2020",
|
|
4
|
-
"module": "commonjs",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"experimentalDecorators": true,
|
|
9
|
-
"emitDecoratorMetadata": true,
|
|
10
|
-
"allowJs": true
|
|
11
|
-
},
|
|
12
|
-
"include": [
|
|
13
|
-
"src/**/*",
|
|
14
|
-
],
|
|
15
|
-
"exclude": ["node_modules"]
|
|
16
|
-
}
|