@silexpert/core 1.0.149 → 1.0.151

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 (53) hide show
  1. package/es/types/Interface/api/commercialManagement/Create.d.ts +1 -0
  2. package/es/types/Interface/api/commercialManagement/Create.d.ts.map +1 -1
  3. package/es/types/Interface/api/commercialManagement/Create.js +4 -0
  4. package/es/types/Interface/api/commercialManagement/Create.js.map +1 -1
  5. package/es/types/Interface/api/loan/CreateLoan.d.ts +1 -1
  6. package/es/types/Interface/api/loan/CreateLoan.js +3 -3
  7. package/es/types/Interface/api/loan/CreateLoan.js.map +1 -1
  8. package/es/types/Interface/api/loan/UpdateLoan.d.ts +1 -1
  9. package/es/types/Interface/api/loan/UpdateLoan.js +2 -2
  10. package/es/types/Interface/api/loan/UpdateLoan.js.map +1 -1
  11. package/es/types/Interface/models/ILoan.d.ts +1 -1
  12. package/es/types/Interface/models/ILoan.js.map +1 -1
  13. package/es/types/Interface/models/ISocietyGescom.d.ts +1 -0
  14. package/es/types/Interface/models/ISocietyGescom.d.ts.map +1 -1
  15. package/es/types/Interface/models/ISocietyGescom.js.map +1 -1
  16. package/es/utils/commercialManagement/document.d.ts.map +1 -1
  17. package/es/utils/commercialManagement/document.js +1 -1
  18. package/es/utils/commercialManagement/document.js.map +1 -1
  19. package/es/utils/commercialManagement/templates/body.d.ts.map +1 -1
  20. package/es/utils/commercialManagement/templates/body.js +3 -2
  21. package/es/utils/commercialManagement/templates/body.js.map +1 -1
  22. package/es/utils/documents.js +1 -1
  23. package/es/utils/documents.js.map +1 -1
  24. package/es/utils/siretValidation.d.ts +1 -0
  25. package/es/utils/siretValidation.d.ts.map +1 -1
  26. package/es/utils/siretValidation.js +22 -3
  27. package/es/utils/siretValidation.js.map +1 -1
  28. package/js/types/Interface/api/commercialManagement/Create.js +3 -0
  29. package/js/types/Interface/api/commercialManagement/Create.js.map +1 -1
  30. package/js/types/Interface/api/loan/CreateLoan.js +1 -1
  31. package/js/types/Interface/api/loan/CreateLoan.js.map +1 -1
  32. package/js/types/Interface/api/loan/UpdateLoan.js +1 -1
  33. package/js/types/Interface/api/loan/UpdateLoan.js.map +1 -1
  34. package/js/types/Interface/models/ILoan.js.map +1 -1
  35. package/js/types/Interface/models/ISocietyGescom.js.map +1 -1
  36. package/js/utils/commercialManagement/document.js +2 -1
  37. package/js/utils/commercialManagement/document.js.map +1 -1
  38. package/js/utils/commercialManagement/templates/body.js +3 -2
  39. package/js/utils/commercialManagement/templates/body.js.map +1 -1
  40. package/js/utils/documents.js +1 -1
  41. package/js/utils/documents.js.map +1 -1
  42. package/js/utils/siretValidation.js +21 -3
  43. package/js/utils/siretValidation.js.map +1 -1
  44. package/package.json +1 -1
  45. package/ts/types/Interface/api/commercialManagement/Create.ts +3 -0
  46. package/ts/types/Interface/api/loan/CreateLoan.ts +3 -3
  47. package/ts/types/Interface/api/loan/UpdateLoan.ts +2 -2
  48. package/ts/types/Interface/models/ILoan.ts +1 -1
  49. package/ts/types/Interface/models/ISocietyGescom.ts +1 -0
  50. package/ts/utils/commercialManagement/document.ts +1 -0
  51. package/ts/utils/commercialManagement/templates/body.ts +3 -2
  52. package/ts/utils/documents.ts +1 -1
  53. package/ts/utils/siretValidation.ts +23 -3
@@ -1,8 +1,28 @@
1
1
  import { isDefined } from 'class-validator';
2
2
  import { CountryId } from '../types/Enum/Country';
3
3
 
4
+ // Function to validate SIREN (9 digits)
5
+ export function validateSiren(siren: string) {
6
+ if (!/^\d{9}$/.test(siren)) throw new Error('Format du SIREN invalide');
7
+
8
+ const sirenArray = Array.from(siren).map(Number).reverse();
9
+ const luhnSum = sirenArray.reduce((acc, v, i) => {
10
+ if (i % 2 === 1) {
11
+ const currentVal = v * 2;
12
+ if (currentVal > 9) {
13
+ const array = Array.from(currentVal.toString());
14
+ return acc + Number(array[0]) + Number(array[1]);
15
+ }
16
+ return acc + currentVal;
17
+ }
18
+ return acc + v;
19
+ }, 0);
20
+
21
+ if (luhnSum % 10 !== 0) throw new Error('SIREN invalide');
22
+ }
23
+
4
24
  export function validateSiret(siret: string) {
5
- if (!/^\d{14}$/.test(siret)) throw new Error('Invalid SIRET format');
25
+ if (!/^\d{14}$/.test(siret)) throw new Error('Format du SIRET invalide');
6
26
 
7
27
  const siretArray = Array.from(siret).map(Number).reverse();
8
28
  const luhnSum = siretArray.reduce((acc, v, i) => {
@@ -22,10 +42,10 @@ export function validateSiret(siret: string) {
22
42
  if (siret.startsWith('356000000')) {
23
43
  const sum = siretArray.reduce((acc, v) => acc + v, 0);
24
44
  if (sum % 5 !== 0) {
25
- throw new Error('Invalid SIRET');
45
+ throw new Error('SIRET invalide');
26
46
  }
27
47
  } else {
28
- throw new Error('Invalid SIRET');
48
+ throw new Error('SIRET invalide');
29
49
  }
30
50
  }
31
51
  }