@autofleet/sadot 1.0.5 → 1.0.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.
Files changed (325) hide show
  1. package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.cjs +1 -0
  2. package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorate.js +1 -0
  3. package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.cjs +1 -0
  4. package/dist/_virtual/_@oxc-project_runtime@0.89.0/helpers/decorateMetadata.js +1 -0
  5. package/dist/_virtual/rolldown_runtime.cjs +1 -0
  6. package/dist/api/index.cjs +2 -0
  7. package/dist/api/index.cjs.map +1 -0
  8. package/dist/api/index.js +2 -12
  9. package/dist/api/index.js.map +1 -0
  10. package/dist/api/v1/definition/index.cjs +2 -0
  11. package/dist/api/v1/definition/index.cjs.map +1 -0
  12. package/dist/api/v1/definition/index.js +2 -116
  13. package/dist/api/v1/definition/index.js.map +1 -0
  14. package/dist/api/v1/definition/validations.cjs +2 -0
  15. package/dist/api/v1/definition/validations.cjs.map +1 -0
  16. package/dist/api/v1/definition/validations.js +2 -77
  17. package/dist/api/v1/definition/validations.js.map +1 -0
  18. package/dist/api/v1/errors.cjs +2 -0
  19. package/dist/api/v1/errors.cjs.map +1 -0
  20. package/dist/api/v1/errors.js +2 -12
  21. package/dist/api/v1/errors.js.map +1 -0
  22. package/dist/api/v1/index.cjs +2 -0
  23. package/dist/api/v1/index.cjs.map +1 -0
  24. package/dist/api/v1/index.js +2 -13
  25. package/dist/api/v1/index.js.map +1 -0
  26. package/dist/api/v1/validator/index.cjs +2 -0
  27. package/dist/api/v1/validator/index.cjs.map +1 -0
  28. package/dist/api/v1/validator/index.js +2 -143
  29. package/dist/api/v1/validator/index.js.map +1 -0
  30. package/dist/api/v1/validator/validations.cjs +2 -0
  31. package/dist/api/v1/validator/validations.cjs.map +1 -0
  32. package/dist/api/v1/validator/validations.js +2 -38
  33. package/dist/api/v1/validator/validations.js.map +1 -0
  34. package/dist/errors/index.cjs +3 -0
  35. package/dist/errors/index.cjs.map +1 -0
  36. package/dist/errors/index.js +3 -66
  37. package/dist/errors/index.js.map +1 -0
  38. package/dist/events/index.cjs +2 -0
  39. package/dist/events/index.cjs.map +1 -0
  40. package/dist/events/index.js +2 -54
  41. package/dist/events/index.js.map +1 -0
  42. package/dist/hooks/enrich.cjs +2 -0
  43. package/dist/hooks/enrich.cjs.map +1 -0
  44. package/dist/hooks/enrich.js +2 -198
  45. package/dist/hooks/enrich.js.map +1 -0
  46. package/dist/hooks/find.cjs +2 -0
  47. package/dist/hooks/find.cjs.map +1 -0
  48. package/dist/hooks/find.js +2 -29
  49. package/dist/hooks/find.js.map +1 -0
  50. package/dist/hooks/hooks.cjs +2 -0
  51. package/dist/hooks/hooks.cjs.map +1 -0
  52. package/dist/hooks/hooks.js +2 -388
  53. package/dist/hooks/hooks.js.map +1 -0
  54. package/dist/hooks/index.cjs +1 -0
  55. package/dist/hooks/index.js +1 -17
  56. package/dist/hooks/utils/updateInstanceValues.cjs +2 -0
  57. package/dist/hooks/utils/updateInstanceValues.cjs.map +1 -0
  58. package/dist/hooks/utils/updateInstanceValues.js +2 -50
  59. package/dist/hooks/utils/updateInstanceValues.js.map +1 -0
  60. package/dist/index.cjs +2 -0
  61. package/dist/index.cjs.map +1 -0
  62. package/dist/index.d.cts +19 -0
  63. package/dist/index.d.ts +18 -12
  64. package/dist/index.js +2 -67
  65. package/dist/index.js.map +1 -0
  66. package/dist/models/CustomFieldDefinition.cjs +2 -0
  67. package/dist/models/CustomFieldDefinition.cjs.map +1 -0
  68. package/dist/models/CustomFieldDefinition.js +2 -192
  69. package/dist/models/CustomFieldDefinition.js.map +1 -0
  70. package/dist/models/CustomFieldEntries.cjs +2 -0
  71. package/dist/models/CustomFieldEntries.cjs.map +1 -0
  72. package/dist/models/CustomFieldEntries.js +2 -123
  73. package/dist/models/CustomFieldEntries.js.map +1 -0
  74. package/dist/models/CustomFieldValue.cjs +2 -0
  75. package/dist/models/CustomFieldValue.cjs.map +1 -0
  76. package/dist/models/CustomFieldValue.js +2 -151
  77. package/dist/models/CustomFieldValue.js.map +1 -0
  78. package/dist/models/CustomValidator.cjs +2 -0
  79. package/dist/models/CustomValidator.cjs.map +1 -0
  80. package/dist/models/CustomValidator.js +2 -98
  81. package/dist/models/CustomValidator.js.map +1 -0
  82. package/dist/models/index.cjs +2 -0
  83. package/dist/models/index.cjs.map +1 -0
  84. package/dist/models/index.js +2 -131
  85. package/dist/models/index.js.map +1 -0
  86. package/dist/models/tests/AssociatedTestModel.cjs +2 -0
  87. package/dist/models/tests/AssociatedTestModel.cjs.map +1 -0
  88. package/dist/models/tests/AssociatedTestModel.js +2 -71
  89. package/dist/models/tests/AssociatedTestModel.js.map +1 -0
  90. package/dist/models/tests/TestModel.cjs +2 -0
  91. package/dist/models/tests/TestModel.cjs.map +1 -0
  92. package/dist/models/tests/TestModel.js +2 -69
  93. package/dist/models/tests/TestModel.js.map +1 -0
  94. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs +2 -0
  95. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.cjs.map +1 -0
  96. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js +2 -53
  97. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.js.map +1 -0
  98. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs +2 -0
  99. package/dist/models/tests/contextAwareModels/ContextTestModel.cjs.map +1 -0
  100. package/dist/models/tests/contextAwareModels/ContextTestModel.js +2 -47
  101. package/dist/models/tests/contextAwareModels/ContextTestModel.js.map +1 -0
  102. package/dist/repository/definition.cjs +2 -0
  103. package/dist/repository/definition.cjs.map +1 -0
  104. package/dist/repository/definition.js +2 -121
  105. package/dist/repository/definition.js.map +1 -0
  106. package/dist/repository/entries.cjs +2 -0
  107. package/dist/repository/entries.cjs.map +1 -0
  108. package/dist/repository/entries.js +2 -92
  109. package/dist/repository/entries.js.map +1 -0
  110. package/dist/repository/utils/formatValues.cjs +2 -0
  111. package/dist/repository/utils/formatValues.cjs.map +1 -0
  112. package/dist/repository/utils/formatValues.js +2 -16
  113. package/dist/repository/utils/formatValues.js.map +1 -0
  114. package/dist/repository/validator.cjs +2 -0
  115. package/dist/repository/validator.cjs.map +1 -0
  116. package/dist/repository/validator.js +2 -69
  117. package/dist/repository/validator.js.map +1 -0
  118. package/dist/repository/value.cjs +2 -0
  119. package/dist/repository/value.cjs.map +1 -0
  120. package/dist/repository/value.js +2 -124
  121. package/dist/repository/value.js.map +1 -0
  122. package/dist/scopes/filter.cjs +2 -0
  123. package/dist/scopes/filter.cjs.map +1 -0
  124. package/dist/scopes/filter.d.cts +23 -0
  125. package/dist/scopes/filter.d.ts +22 -29
  126. package/dist/scopes/filter.js +2 -75
  127. package/dist/scopes/filter.js.map +1 -0
  128. package/dist/scopes/helpers/filter.helpers.cjs +46 -0
  129. package/dist/scopes/helpers/filter.helpers.cjs.map +1 -0
  130. package/dist/scopes/helpers/filter.helpers.d.cts +17 -0
  131. package/dist/scopes/helpers/filter.helpers.d.ts +15 -40
  132. package/dist/scopes/helpers/filter.helpers.js +25 -183
  133. package/dist/scopes/helpers/filter.helpers.js.map +1 -0
  134. package/dist/scopes/index.cjs +1 -0
  135. package/dist/scopes/index.js +1 -6
  136. package/dist/types/index.d.cts +44 -0
  137. package/dist/types/index.d.ts +41 -44
  138. package/dist/utils/constants/index.cjs +2 -0
  139. package/dist/utils/constants/index.cjs.map +1 -0
  140. package/dist/utils/constants/index.d.cts +22 -0
  141. package/dist/utils/constants/index.d.ts +20 -17
  142. package/dist/utils/constants/index.js +2 -22
  143. package/dist/utils/constants/index.js.map +1 -0
  144. package/dist/utils/db/index.cjs +2 -0
  145. package/dist/utils/db/index.cjs.map +1 -0
  146. package/dist/utils/db/index.js +2 -24
  147. package/dist/utils/db/index.js.map +1 -0
  148. package/dist/utils/helpers/index.cjs +2 -0
  149. package/dist/utils/helpers/index.cjs.map +1 -0
  150. package/dist/utils/helpers/index.d.cts +31 -0
  151. package/dist/utils/helpers/index.d.ts +28 -23
  152. package/dist/utils/helpers/index.js +2 -40
  153. package/dist/utils/helpers/index.js.map +1 -0
  154. package/dist/utils/init.cjs +2 -0
  155. package/dist/utils/init.cjs.map +1 -0
  156. package/dist/utils/init.js +2 -112
  157. package/dist/utils/init.js.map +1 -0
  158. package/dist/utils/logger/index.cjs +2 -0
  159. package/dist/utils/logger/index.cjs.map +1 -0
  160. package/dist/utils/logger/index.js +2 -42
  161. package/dist/utils/logger/index.js.map +1 -0
  162. package/dist/utils/scopeAttributes.cjs +2 -0
  163. package/dist/utils/scopeAttributes.cjs.map +1 -0
  164. package/dist/utils/scopeAttributes.js +2 -11
  165. package/dist/utils/scopeAttributes.js.map +1 -0
  166. package/dist/utils/validations/index.cjs +2 -0
  167. package/dist/utils/validations/index.cjs.map +1 -0
  168. package/dist/utils/validations/index.js +2 -41
  169. package/dist/utils/validations/index.js.map +1 -0
  170. package/dist/utils/validations/schema/custom-fields.cjs +2 -0
  171. package/dist/utils/validations/schema/custom-fields.cjs.map +1 -0
  172. package/dist/utils/validations/schema/custom-fields.d.cts +7 -0
  173. package/dist/utils/validations/schema/custom-fields.d.ts +6 -2
  174. package/dist/utils/validations/schema/custom-fields.js +2 -9
  175. package/dist/utils/validations/schema/custom-fields.js.map +1 -0
  176. package/dist/utils/validations/schema/validator-schema.cjs +2 -0
  177. package/dist/utils/validations/schema/validator-schema.cjs.map +1 -0
  178. package/dist/utils/validations/schema/validator-schema.js +2 -95
  179. package/dist/utils/validations/schema/validator-schema.js.map +1 -0
  180. package/dist/utils/validations/validators/index.cjs +2 -0
  181. package/dist/utils/validations/validators/index.cjs.map +1 -0
  182. package/dist/utils/validations/validators/index.js +2 -40
  183. package/dist/utils/validations/validators/index.js.map +1 -0
  184. package/dist/utils/validations/validators/select.validator.cjs +2 -0
  185. package/dist/utils/validations/validators/select.validator.cjs.map +1 -0
  186. package/dist/utils/validations/validators/select.validator.js +2 -12
  187. package/dist/utils/validations/validators/select.validator.js.map +1 -0
  188. package/dist/utils/validations/validators/status.validator.cjs +2 -0
  189. package/dist/utils/validations/validators/status.validator.cjs.map +1 -0
  190. package/dist/utils/validations/validators/status.validator.js +2 -15
  191. package/dist/utils/validations/validators/status.validator.js.map +1 -0
  192. package/package.json +26 -23
  193. package/.nvmrc +0 -1
  194. package/dist/api/index.d.ts +0 -3
  195. package/dist/api/v1/definition/index.d.ts +0 -3
  196. package/dist/api/v1/definition/validations.d.ts +0 -2
  197. package/dist/api/v1/errors.d.ts +0 -4
  198. package/dist/api/v1/index.d.ts +0 -3
  199. package/dist/api/v1/validator/index.d.ts +0 -3
  200. package/dist/api/v1/validator/validations.d.ts +0 -6
  201. package/dist/errors/index.d.ts +0 -24
  202. package/dist/events/index.d.ts +0 -5
  203. package/dist/hooks/create.d.ts +0 -10
  204. package/dist/hooks/create.js +0 -95
  205. package/dist/hooks/enrich.d.ts +0 -25
  206. package/dist/hooks/find.d.ts +0 -1
  207. package/dist/hooks/hooks.d.ts +0 -17
  208. package/dist/hooks/index.d.ts +0 -5
  209. package/dist/hooks/update.d.ts +0 -10
  210. package/dist/hooks/update.js +0 -49
  211. package/dist/hooks/utils/updateInstanceValues.d.ts +0 -15
  212. package/dist/hooks/workaround.d.ts +0 -10
  213. package/dist/hooks/workaround.js +0 -37
  214. package/dist/models/CustomFieldDefinition.d.ts +0 -25
  215. package/dist/models/CustomFieldEntries.d.ts +0 -15
  216. package/dist/models/CustomFieldValue.d.ts +0 -16
  217. package/dist/models/CustomValidator.d.ts +0 -17
  218. package/dist/models/index.d.ts +0 -18
  219. package/dist/models/tests/AssociatedTestModel.d.ts +0 -12
  220. package/dist/models/tests/TestModel.d.ts +0 -12
  221. package/dist/models/tests/contextAwareModels/ContextAwareTestModel.d.ts +0 -10
  222. package/dist/models/tests/contextAwareModels/ContextTestModel.d.ts +0 -13
  223. package/dist/repository/definition.d.ts +0 -36
  224. package/dist/repository/entries.d.ts +0 -13
  225. package/dist/repository/utils/formatValues.d.ts +0 -3
  226. package/dist/repository/validator.d.ts +0 -28
  227. package/dist/repository/value.d.ts +0 -28
  228. package/dist/scopes/index.d.ts +0 -2
  229. package/dist/tests/api/test-api.d.ts +0 -2
  230. package/dist/tests/api/test-api.js +0 -38
  231. package/dist/tests/functional/searching/index.d.ts +0 -8
  232. package/dist/tests/functional/searching/index.js +0 -44
  233. package/dist/tests/helpers/commonHooks.d.ts +0 -6
  234. package/dist/tests/helpers/commonHooks.js +0 -62
  235. package/dist/tests/helpers/database-config.d.ts +0 -16
  236. package/dist/tests/helpers/database-config.js +0 -17
  237. package/dist/tests/helpers/index.d.ts +0 -7
  238. package/dist/tests/helpers/index.js +0 -33
  239. package/dist/tests/mocks/definition.mock.d.ts +0 -48
  240. package/dist/tests/mocks/definition.mock.js +0 -78
  241. package/dist/tests/mocks/events.mock.d.ts +0 -4
  242. package/dist/tests/mocks/events.mock.js +0 -21
  243. package/dist/tests/mocks/testModel.d.ts +0 -12
  244. package/dist/tests/mocks/testModel.js +0 -35
  245. package/dist/types/definition/index.d.ts +0 -25
  246. package/dist/types/definition/index.js +0 -2
  247. package/dist/types/entries/index.d.ts +0 -25
  248. package/dist/types/entries/index.js +0 -2
  249. package/dist/types/index.js +0 -2
  250. package/dist/types/value/index.d.ts +0 -15
  251. package/dist/types/value/index.js +0 -2
  252. package/dist/utils/db/index.d.ts +0 -4
  253. package/dist/utils/init.d.ts +0 -7
  254. package/dist/utils/logger/index.d.ts +0 -3
  255. package/dist/utils/scopeAttributes.d.ts +0 -2
  256. package/dist/utils/validations/index.d.ts +0 -8
  257. package/dist/utils/validations/schema/validator-schema.d.ts +0 -9
  258. package/dist/utils/validations/type.d.ts +0 -15
  259. package/dist/utils/validations/type.js +0 -2
  260. package/dist/utils/validations/validators/index.d.ts +0 -14
  261. package/dist/utils/validations/validators/select.validator.d.ts +0 -5
  262. package/dist/utils/validations/validators/status.validator.d.ts +0 -12
  263. package/src/api/index.ts +0 -10
  264. package/src/api/v1/definition/index.ts +0 -104
  265. package/src/api/v1/definition/validations.ts +0 -75
  266. package/src/api/v1/errors.ts +0 -13
  267. package/src/api/v1/index.ts +0 -11
  268. package/src/api/v1/validator/index.ts +0 -141
  269. package/src/api/v1/validator/validations.ts +0 -38
  270. package/src/errors/index.ts +0 -70
  271. package/src/events/index.ts +0 -63
  272. package/src/hooks/create.ts +0 -81
  273. package/src/hooks/enrich.ts +0 -255
  274. package/src/hooks/find.ts +0 -27
  275. package/src/hooks/hooks.ts +0 -479
  276. package/src/hooks/index.ts +0 -20
  277. package/src/hooks/update.ts +0 -55
  278. package/src/hooks/utils/updateInstanceValues.ts +0 -63
  279. package/src/hooks/workaround.ts +0 -47
  280. package/src/index.ts +0 -52
  281. package/src/models/CustomFieldDefinition.ts +0 -162
  282. package/src/models/CustomFieldEntries.ts +0 -81
  283. package/src/models/CustomFieldValue.ts +0 -118
  284. package/src/models/CustomValidator.ts +0 -78
  285. package/src/models/index.ts +0 -165
  286. package/src/models/tests/AssociatedTestModel.ts +0 -57
  287. package/src/models/tests/TestModel.ts +0 -54
  288. package/src/models/tests/contextAwareModels/ContextAwareTestModel.ts +0 -43
  289. package/src/models/tests/contextAwareModels/ContextTestModel.ts +0 -38
  290. package/src/repository/definition.ts +0 -175
  291. package/src/repository/entries.ts +0 -88
  292. package/src/repository/utils/formatValues.ts +0 -14
  293. package/src/repository/validator.ts +0 -119
  294. package/src/repository/value.ts +0 -116
  295. package/src/scopes/filter.ts +0 -100
  296. package/src/scopes/helpers/filter.helpers.ts +0 -227
  297. package/src/scopes/index.ts +0 -6
  298. package/src/tests/api/test-api.ts +0 -40
  299. package/src/tests/functional/searching/index.ts +0 -39
  300. package/src/tests/helpers/commonHooks.ts +0 -43
  301. package/src/tests/helpers/database-config.ts +0 -15
  302. package/src/tests/helpers/index.ts +0 -35
  303. package/src/tests/mocks/definition.mock.ts +0 -84
  304. package/src/tests/mocks/events.mock.ts +0 -21
  305. package/src/tests/mocks/testModel.ts +0 -37
  306. package/src/types/definition/index.ts +0 -24
  307. package/src/types/entries/index.ts +0 -27
  308. package/src/types/index.ts +0 -52
  309. package/src/types/value/index.ts +0 -14
  310. package/src/utils/constants/index.ts +0 -25
  311. package/src/utils/db/index.ts +0 -21
  312. package/src/utils/helpers/index.ts +0 -66
  313. package/src/utils/init.ts +0 -122
  314. package/src/utils/logger/index.ts +0 -14
  315. package/src/utils/scopeAttributes.ts +0 -12
  316. package/src/utils/validations/index.ts +0 -46
  317. package/src/utils/validations/schema/README.md +0 -93
  318. package/src/utils/validations/schema/custom-fields.ts +0 -8
  319. package/src/utils/validations/schema/validator-schema.ts +0 -106
  320. package/src/utils/validations/type.ts +0 -20
  321. package/src/utils/validations/validators/index.ts +0 -38
  322. package/src/utils/validations/validators/select.validator.ts +0 -12
  323. package/src/utils/validations/validators/status.validator.ts +0 -22
  324. package/tsconfig.build.json +0 -7
  325. package/tsconfig.json +0 -16
@@ -1,12 +0,0 @@
1
- import { TestModel } from '../../models';
2
- export declare const createTestModel: (payload?: {}) => Promise<TestModel>;
3
- export declare const createTestModels: (fleetId: any, total: number) => Promise<TestModel[]>;
4
- export declare const upsertTestModel: (payload: any) => Promise<[TestModel, boolean]>;
5
- export declare const destroyTestModels: () => Promise<number>;
6
- export declare const getTestModel: (id: string, options?: {}) => Promise<TestModel | null>;
7
- export declare const getSomeTestModels: (options?: {
8
- limit: number;
9
- }) => Promise<TestModel[]>;
10
- export declare const updateTestModel: (payload: any, query: any) => Promise<[affectedCount: number, affectedRows: TestModel[]]>;
11
- export declare const createTestModelWithAssociation: () => Promise<TestModel>;
12
- export declare const getTestModelWithAssociation: (limit?: number) => Promise<TestModel[]>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTestModelWithAssociation = exports.createTestModelWithAssociation = exports.updateTestModel = exports.getSomeTestModels = exports.getTestModel = exports.destroyTestModels = exports.upsertTestModel = exports.createTestModels = exports.createTestModel = void 0;
4
- const models_1 = require("../../models");
5
- const createTestModel = (payload = {}) => models_1.TestModel.create(payload);
6
- exports.createTestModel = createTestModel;
7
- const createTestModels = (fleetId, total) => {
8
- const models = [];
9
- for (let i = 0; i < total; i += 1) {
10
- models.push((0, exports.createTestModel)({ fleetId }));
11
- }
12
- return Promise.all(models);
13
- };
14
- exports.createTestModels = createTestModels;
15
- const upsertTestModel = (payload) => models_1.TestModel.upsert(payload);
16
- exports.upsertTestModel = upsertTestModel;
17
- const destroyTestModels = () => models_1.TestModel.destroy({ truncate: true });
18
- exports.destroyTestModels = destroyTestModels;
19
- const getTestModel = (id, options = {}) => models_1.TestModel.findByPk(id, options);
20
- exports.getTestModel = getTestModel;
21
- const getSomeTestModels = (options = { limit: 1 }) => models_1.TestModel.findAll(options);
22
- exports.getSomeTestModels = getSomeTestModels;
23
- const updateTestModel = (payload, query) => models_1.TestModel.update(payload, query);
24
- exports.updateTestModel = updateTestModel;
25
- // Associations
26
- const createTestModelWithAssociation = async () => {
27
- const model = await models_1.TestModel.create({});
28
- await models_1.AssociatedTestModel.create({ testModelId: model.id });
29
- return model;
30
- };
31
- exports.createTestModelWithAssociation = createTestModelWithAssociation;
32
- const getTestModelWithAssociation = (limit = 1) => models_1.TestModel.findAll({
33
- limit, include: [models_1.AssociatedTestModel],
34
- });
35
- exports.getTestModelWithAssociation = getTestModelWithAssociation;
@@ -1,25 +0,0 @@
1
- export interface CustomFieldDefinitionDTO {
2
- id: string;
3
- name: string;
4
- displayName?: string;
5
- validation?: any;
6
- defaultValue?: any;
7
- fieldType: string;
8
- entityId: string;
9
- entityType: string;
10
- modelType: string;
11
- required?: boolean;
12
- description?: string;
13
- disabled?: boolean;
14
- createdAt?: Date;
15
- updatedAt?: Date;
16
- deletedAt?: Date;
17
- blockEditingFromUI?: boolean;
18
- }
19
- export type CreateCustomFieldDefinition = Omit<CustomFieldDefinitionDTO, 'id'>;
20
- export type UpdateCustomFieldDefinition = Partial<CreateCustomFieldDefinition>;
21
- export type SerializedCustomFields = {
22
- [name: string]: CustomFieldDefinitionDTO & {
23
- value: any;
24
- };
25
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,25 +0,0 @@
1
- import type { ValidationError } from 'joi';
2
- export interface CustomFieldEntriesDTO {
3
- modelId: string;
4
- entityId: string;
5
- modelType: string;
6
- /**
7
- * A collection of custom fields where each key is the name of a CustomFieldDefinition and
8
- * each value is the value of that custom field for this specific `modelId`.
9
- *
10
- * Example:
11
- * {
12
- * "vehicleColor": "Red",
13
- * "vehicleType": "premium",
14
- * "isActive": true
15
- * }
16
- */
17
- customFields: Record<string, any>;
18
- createdAt?: Date;
19
- updatedAt?: Date;
20
- }
21
- export interface EntriesValidationError {
22
- value: any;
23
- fieldDefinitionName: string;
24
- joiValidationError: ValidationError;
25
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +0,0 @@
1
- export interface CustomFieldValueDTO {
2
- id?: string;
3
- modelId: string;
4
- customFieldDefinitionId: string;
5
- value: any;
6
- createdAt?: Date;
7
- updatedAt?: Date;
8
- deletedAt?: Date;
9
- }
10
- export type ValuesToUpdate = {
11
- [name: string]: any;
12
- };
13
- export type CreateCustomFieldValue = Omit<CustomFieldValueDTO, 'id'>;
14
- export type UpdateCustomFieldValue = ValuesToUpdate;
15
- export type BulkUpdateCustomFieldValue = Partial<CustomFieldValueDTO>[];
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- import { Sequelize } from 'sequelize-typescript';
2
- declare const _default: (databaseConfig: any) => Sequelize;
3
- export default _default;
4
- export declare const createSequelizeMeta: (sequelize: Sequelize) => Promise<object[]>;
@@ -1,7 +0,0 @@
1
- import type { CustomFieldOptions, ModelFetcher, Models } from '../types';
2
- export declare const addHooks: (models: Models[], getModel: ModelFetcher, sadotOptions?: {
3
- useCustomFieldsEntries: boolean;
4
- }) => void;
5
- export declare const removeHooks: (models: Models[], getModel: ModelFetcher) => void;
6
- export declare const addScopes: (models: Models[], getModel: ModelFetcher, options?: Pick<CustomFieldOptions, 'useCustomFieldsEntries'>) => void;
7
- export declare const applyCustomAssociation: (models: Models[]) => void;
@@ -1,3 +0,0 @@
1
- declare const logger: import("@autofleet/logger").LoggerInstanceManager;
2
- export declare function tryAddingTraceIdMiddleware(): Promise<void>;
3
- export default logger;
@@ -1,2 +0,0 @@
1
- declare const applyScopeToInstance: (instance: any, scopeAttributes: string[]) => any[];
2
- export default applyScopeToInstance;
@@ -1,8 +0,0 @@
1
- import type { CustomFieldDefinition } from '../../models';
2
- import type { CustomFieldEntriesDTO } from '../../types/entries';
3
- import type { CustomFieldDefinitionType } from '../constants';
4
- export declare const validateFieldType: (type: CustomFieldDefinitionType) => boolean;
5
- export declare const validateValue: (value: unknown, valueType: CustomFieldDefinitionType, validation?: unknown) => import("joi").ValidationResult;
6
- export declare const validateInstanceCustomFieldEntries: (instance: CustomFieldEntriesDTO, definitionsByName: {
7
- [defName: string]: CustomFieldDefinition;
8
- }) => void;
@@ -1,9 +0,0 @@
1
- /**
2
- * Validates that a given schema is a valid Ajv schema
3
- * This function is used to validate schemas passed to custom validators
4
- *
5
- * @param schema The schema to validate
6
- * @returns true if valid, throws an error if invalid
7
- */
8
- export declare const validateValidatorSchema: (schema: Record<string, unknown>) => boolean;
9
- export default validateValidatorSchema;
@@ -1,15 +0,0 @@
1
- import type { ValidationResult } from 'joi';
2
- import type { CustomFieldDefinitionType } from '../constants';
3
- /**
4
- * Validator is a function that validates a custom-field `value`,
5
- * against a custom-field definition `validation object`.
6
- * @returns `true` if the value is valid, `false` otherwise.
7
- */
8
- export type Validator<Value, DefinitionValidationObject> = (value: Value, validation?: DefinitionValidationObject) => ValidationResult;
9
- /**
10
- * Validators is a map of custom-field types to their respective validators.
11
- * The key is the custom-field type, and the value is the validator function.
12
- */
13
- export type Validators = {
14
- [K in CustomFieldDefinitionType]: Validator<unknown, unknown>;
15
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,14 +0,0 @@
1
- import { CustomFieldDefinitionType } from '../../constants';
2
- import type { Validators } from '../type';
3
- /**
4
- * Custom field types that must have custom validation.
5
- * TODO: remove this after moving to schema-based validation
6
- */
7
- export declare const CustomValidationTypes: {
8
- readonly select: CustomFieldDefinitionType.SELECT;
9
- readonly status: CustomFieldDefinitionType.STATUS;
10
- };
11
- /**
12
- * Validators for custom fields
13
- */
14
- export declare const validators: Validators;
@@ -1,5 +0,0 @@
1
- import type { Validator } from '../type';
2
- /**
3
- * Validate that the value is one of the select values
4
- */
5
- export declare const validateSelect: Validator<string, string[]>;
@@ -1,12 +0,0 @@
1
- import type { Validator } from '../type';
2
- type StatusColor = string | null;
3
- type StatusValue = string;
4
- type StatusOption = {
5
- value: StatusValue;
6
- color: StatusColor;
7
- };
8
- /**
9
- * Validate that the value is one of the status values
10
- */
11
- export declare const validateStatus: Validator<StatusValue, StatusOption[]>;
12
- export {};
package/src/api/index.ts DELETED
@@ -1,10 +0,0 @@
1
- // export the api object
2
- import { Router } from '@autofleet/node-common';
3
- import v1 from './v1';
4
- import logger from '../utils/logger';
5
-
6
- const router = Router({ logger });
7
-
8
- router.use('/v1', v1);
9
-
10
- export default router;
@@ -1,104 +0,0 @@
1
- import { ResourceNotFoundError } from '@autofleet/errors';
2
- import { Router } from '@autofleet/node-common';
3
- import handleError from '../errors';
4
- import * as DefinitionRepo from '../../../repository/definition';
5
- import type { CreateCustomFieldDefinition, UpdateCustomFieldDefinition } from '../../../types/definition';
6
- import { validateCustomFieldDefinitionCreation, validateCustomFieldDefinitionUpdate } from './validations';
7
- import logger from '../../../utils/logger';
8
- import type { CustomFieldDefinition } from '../../../models';
9
-
10
- const router = Router({ logger });
11
- const ENTITY = 'CustomFieldDefinition';
12
-
13
- const toPascalCase = (str: string): string => str.replace(/(^\w|-\w)/g, (subStr) => subStr.replace(/-/, '').toUpperCase());
14
-
15
- /**
16
- * Create
17
- */
18
- router.post<{ modelName: string; }>('/', async (req, res) => {
19
- const { modelName } = req.params;
20
- const modelType = toPascalCase(modelName);
21
- try {
22
- const validatedPayload: CreateCustomFieldDefinition = await validateCustomFieldDefinitionCreation(req.body);
23
-
24
- const customFieldDefinition = await DefinitionRepo.create({
25
- ...validatedPayload,
26
- modelType,
27
- });
28
- return res.status(201).json(customFieldDefinition);
29
- } catch (err) {
30
- logger.error('Failed to create custom field definition', err);
31
- return handleError(err, res, { logger, message: `Error in create ${ENTITY} request` });
32
- }
33
- });
34
-
35
- /**
36
- * Get by id
37
- */
38
- router.get<{ modelName: string; customFieldDefinitionId: string; }, CustomFieldDefinition>('/:customFieldDefinitionId', async (req, res) => {
39
- const { customFieldDefinitionId } = req.params;
40
- try {
41
- const customFieldDefinition = await DefinitionRepo.findById(customFieldDefinitionId);
42
-
43
- if (!customFieldDefinition) {
44
- throw new ResourceNotFoundError();
45
- }
46
-
47
- return res.json(customFieldDefinition);
48
- } catch (err) {
49
- logger.error('Failed to fetch custom field definition', err);
50
- return handleError(err, res, { logger, message: `Error in get ${ENTITY} request` });
51
- }
52
- });
53
-
54
- /**
55
- * Get all
56
- */
57
- router.get<{ modelName: string; }, CustomFieldDefinition[], never, { entityIds?: string[]; }>('/', async (req, res) => {
58
- const { params: { modelName }, query: { entityIds } } = req;
59
-
60
- const modelType = toPascalCase(modelName);
61
- try {
62
- const where = {
63
- modelType,
64
- ...(entityIds?.length > 0 && { entityId: entityIds }),
65
- };
66
- const customFieldDefinitions = await DefinitionRepo.findAll(where, { withDisabled: true });
67
- return res.json(customFieldDefinitions);
68
- } catch (err) {
69
- logger.error('Failed to fetch custom field definitions', err);
70
- return handleError(err, res, { logger, message: `Error in get all ${ENTITY} request` });
71
- }
72
- });
73
-
74
- /**
75
- * Update
76
- */
77
- router.patch<{ modelName: string; customFieldDefinitionId: string; }, CustomFieldDefinition>('/:customFieldDefinitionId', async (req, res) => {
78
- const { customFieldDefinitionId, modelName } = req.params;
79
- const modelType = toPascalCase(modelName);
80
- try {
81
- const validatedPayload: UpdateCustomFieldDefinition = await validateCustomFieldDefinitionUpdate(req.body);
82
-
83
- const customFieldDefinition = await DefinitionRepo.findByWhere({
84
- id: customFieldDefinitionId,
85
- modelType,
86
- });
87
-
88
- if (!customFieldDefinition) {
89
- throw new ResourceNotFoundError();
90
- }
91
-
92
- const updatedCustomFieldDefinition = await DefinitionRepo.update(
93
- customFieldDefinitionId,
94
- { ...validatedPayload, modelType },
95
- );
96
-
97
- return res.status(200).json(updatedCustomFieldDefinition);
98
- } catch (err) {
99
- logger.error('Failed to patch custom field definition', err);
100
- return handleError(err, res, { logger, message: `Error in update ${ENTITY} request` });
101
- }
102
- });
103
-
104
- export default router;
@@ -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 });
@@ -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
- };
@@ -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;