@autofleet/sadot 0.13.0-beta.11 → 0.13.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,7 @@ const validationSchemas = {
23
23
  }),
24
24
  update: joi_1.default.object({
25
25
  entityId: joi_1.default.string().uuid(),
26
+ entityType: joi_1.default.string(),
26
27
  schema: joi_1.default.object({
27
28
  type: joi_1.default.string().valid('object'),
28
29
  properties: joi_1.default.object({
@@ -41,7 +41,6 @@ const ajv = new ajv_1.default({
41
41
  allErrors: true,
42
42
  strict: false, // Disable strict mode to avoid warnings
43
43
  strictTypes: false, // Disable strict type checking
44
- $data: true, // Enable $data references
45
44
  });
46
45
  (0, ajv_formats_1.default)(ajv);
47
46
  /**
@@ -107,12 +106,12 @@ const validateModel = async (instance, options, scopeAttributes, isCreate = fals
107
106
  after: typedSchema.properties.after,
108
107
  },
109
108
  });
110
- const isValid = validateSchema(JSON.parse(JSON.stringify({
109
+ const isValid = validateSchema({
111
110
  after: {
112
111
  ...instance.dataValues,
113
- customFields: instance.customFields,
112
+ ...instance.customFields,
114
113
  },
115
- })));
114
+ });
116
115
  if (!isValid) {
117
116
  const errorDetails = validateSchema.errors?.map((err) => `${err.instancePath || ''} ${err.message || 'Invalid value'}`).join(', ');
118
117
  throw new errors_1.BadRequest([new Error(`Validation failed for ${modelType}: ${errorDetails}`)]);
@@ -122,21 +121,11 @@ const validateModel = async (instance, options, scopeAttributes, isCreate = fals
122
121
  else {
123
122
  // For update operations, we need both before and after
124
123
  const validateSchema = ajv.compile(typedSchema);
125
- const isValid = validateSchema(JSON.parse(JSON.stringify({
124
+ const isValid = validateSchema({
126
125
  before: originalValues,
127
126
  after: {
128
127
  ...instance.dataValues,
129
- customFields: instance.customFields,
130
- },
131
- })));
132
- logger_1.default.info('sadot - validation result', {
133
- isValid,
134
- test: {
135
- before: originalValues,
136
- after: {
137
- ...instance.dataValues,
138
- ...instance.customFields,
139
- },
128
+ ...instance.customFields,
140
129
  },
141
130
  });
142
131
  if (!isValid) {
@@ -13,7 +13,6 @@ const metaValidator = new ajv_1.default({
13
13
  allErrors: true,
14
14
  strict: false,
15
15
  strictTypes: false,
16
- $data: true, // Enable $data references
17
16
  });
18
17
  (0, ajv_formats_1.default)(metaValidator);
19
18
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autofleet/sadot",
3
- "version": "0.13.0-beta.11",
3
+ "version": "0.13.0-beta.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -21,6 +21,7 @@ const validationSchemas = {
21
21
 
22
22
  update: Joi.object({
23
23
  entityId: Joi.string().uuid(),
24
+ entityType: Joi.string(),
24
25
  schema: Joi.object({
25
26
  type: Joi.string().valid('object'),
26
27
  properties: Joi.object({
@@ -1,6 +1,6 @@
1
1
  import type { WhereOptions } from 'sequelize';
2
2
  import Ajv from 'ajv';
3
- import addFormats from 'ajv-formats';
3
+ import addFormats from "ajv-formats";
4
4
  import { BadRequest } from '@autofleet/errors';
5
5
  import logger from '../utils/logger';
6
6
  import * as ValidatorRepo from '../repository/validator';
@@ -15,7 +15,6 @@ const ajv = new Ajv({
15
15
  allErrors: true,
16
16
  strict: false, // Disable strict mode to avoid warnings
17
17
  strictTypes: false, // Disable strict type checking
18
- $data: true, // Enable $data references
19
18
  });
20
19
 
21
20
  addFormats(ajv);
@@ -107,12 +106,12 @@ const validateModel = async (
107
106
  },
108
107
  });
109
108
 
110
- const isValid = validateSchema(JSON.parse(JSON.stringify({
109
+ const isValid = validateSchema({
111
110
  after: {
112
111
  ...instance.dataValues,
113
- customFields: instance.customFields,
112
+ ...instance.customFields,
114
113
  },
115
- })));
114
+ });
116
115
 
117
116
  if (!isValid) {
118
117
  const errorDetails = validateSchema.errors?.map((err) =>
@@ -125,22 +124,11 @@ const validateModel = async (
125
124
  // For update operations, we need both before and after
126
125
  const validateSchema = ajv.compile(typedSchema);
127
126
 
128
- const isValid = validateSchema(JSON.parse(JSON.stringify({
127
+ const isValid = validateSchema({
129
128
  before: originalValues,
130
129
  after: {
131
130
  ...instance.dataValues,
132
- customFields: instance.customFields,
133
- },
134
- })));
135
-
136
- logger.info('sadot - validation result', {
137
- isValid,
138
- test: {
139
- before: originalValues,
140
- after: {
141
- ...instance.dataValues,
142
- ...instance.customFields,
143
- },
131
+ ...instance.customFields,
144
132
  },
145
133
  });
146
134
 
@@ -8,7 +8,6 @@ const metaValidator = new Ajv({
8
8
  allErrors: true,
9
9
  strict: false,
10
10
  strictTypes: false,
11
- $data: true, // Enable $data references
12
11
  });
13
12
  addFormats(metaValidator);
14
13
 
package/validator-test.js DELETED
@@ -1,79 +0,0 @@
1
- const Ajv = require("ajv");
2
- const addFormats = require("ajv-formats");
3
- const ajv = new Ajv({
4
- allErrors: true,
5
- strict: false, // Disable strict mode to avoid warnings
6
- strictTypes: false, // Disable strict type checking
7
- $data: true, // Enable $data references
8
- }); // options can be passed, e.g. {allErrors: true}
9
- addFormats(ajv);
10
-
11
-
12
- const schema = {
13
- "type": "object",
14
- "properties": {
15
- "after": {
16
- "type": "object",
17
- "properties": {
18
- "customFields": {
19
- "type": "object",
20
- "properties": {
21
- "actualStartTime": {
22
- "type": "string",
23
- "format": "date-time"
24
- },
25
- "actualEndTime": {
26
- "type": "string",
27
- "format": "date-time",
28
- "formatMinimum": {
29
- "$data": "/after/customFields/actualStartTime"
30
- }
31
- }
32
- }
33
- }
34
- }
35
- }
36
- }
37
- };
38
-
39
- const validate = ajv.compile(schema);
40
-
41
- const data = {
42
- "id": "c9c87cec-28c7-4a1f-9376-4d8a4ba0f49c",
43
- "typeId": "4fcd7096-4c90-46a2-a20e-91bb5bff3ced",
44
- "priorityId": null,
45
- "statusId": "51d28a37-c042-429f-a9cd-fbc81bba2b39",
46
- "subjectId": null,
47
- "subjectType": null,
48
- "title": "ff",
49
- "description": null,
50
- "dueTime": null,
51
- "startTime": null,
52
- "endTime": null,
53
- "driverId": null,
54
- "vendorId": null,
55
- "userId": null,
56
- "businessModelId": "72ecf740-42a1-46f4-81ca-8132b08c4f04",
57
- "createdAt": "2025-03-12T12:58:05.529Z",
58
- "updatedAt": "2025-03-12T12:58:05.529Z",
59
- "deletedAt": null,
60
- "actions": [],
61
- "customFields": {
62
- "actualStartTime": "2025-03-14T12:48:01.373Z",
63
- "actualEndTime": "2025-03-01T12:51:46.685Z"
64
- },
65
- "isBlocker": false
66
- };
67
-
68
- const valid = validate({after: data});
69
-
70
- if (!valid) {
71
- console.log("invalid, the errors is: ");
72
- validate.errors.forEach((error) =>
73
- console.log(error.instancePath, error.message)
74
- );
75
- } else {
76
- console.log("valid");
77
- }
78
-
79
- console.log("--------------------");