@stbmoz-onboarding/core 1.0.25 → 1.0.27

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.
@@ -0,0 +1,90 @@
1
+ const { isAboveMaxLength, isMinLength, notIncludes, isIn } = require("./../Validations")
2
+
3
+ const feedbacks = {
4
+ oversized: "Ultrapassou o limite de caracteres",
5
+ invalidChars: "O campo contem caracteres inválidos",
6
+ required: "Campo obrigatório"
7
+ }
8
+
9
+ module.exports.GenerateNumericPin = async (pinSize) => {
10
+ let pin = ''
11
+ const numbers = [0, 1, 2, 6, 4, 5, 6, 7, 8, 9]
12
+
13
+ for (let i = 0; i < pinSize; i++) {
14
+ pin = pin + numbers[Math.floor(Math.random() * 10)]
15
+ }
16
+ return pin
17
+ }
18
+
19
+ module.exports.ReferenceGenerator = async (length) => {
20
+
21
+ let charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".split("")
22
+ let reference = ""
23
+
24
+ for (let i = 0; i < length; i++) {
25
+ const aux = charset[Math.floor(Math.random() * charset.length)]
26
+ reference = reference + aux
27
+ }
28
+
29
+ const date = new Date()
30
+ reference = `${date.getFullYear()}${date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : `${date.getMonth() + 1}`}` + reference
31
+
32
+ return reference
33
+ }
34
+
35
+ module.exports.AllowedPrefixes = [
36
+ '25884', '25885', '25886', '25887', '25882', '25883'
37
+ ]
38
+
39
+ module.exports.Sanitize = (values, key, errors, isRequired, failMessage, _minLength, _maxLength, allowedChars) => {
40
+ try {
41
+ values[key] = values[key].replace(/(\r\n|\n|\r)/gm, " ")
42
+
43
+ if (!values[key] && isRequired) {
44
+ errors[key] = feedbacks.required
45
+ } else if (!notIncludes(values[key], allowedChars)) {
46
+ if (!isMinLength(values[key], _minLength)) {
47
+ errors[key] = failMessage
48
+ } else {
49
+ if (!isAboveMaxLength(values[key], _maxLength)) {
50
+ errors[key] = feedbacks.oversized
51
+ }
52
+ }
53
+ } else {
54
+ errors[key] = feedbacks.invalidChars
55
+ }
56
+ } catch (e) {
57
+ errors[key] = failMessage
58
+ }
59
+
60
+
61
+
62
+ }
63
+
64
+ module.exports.Serializer = (requestBody, allowedFieldsArray) => {
65
+
66
+ Object.entries(requestBody).forEach(([key, value]) => {
67
+ if (!isIn(key, allowedFieldsArray)) {
68
+ delete requestBody[key]
69
+ } else {
70
+ try {
71
+ if (typeof value == "string") {
72
+ if (key == 'email') {
73
+ requestBody[key] = requestBody[key].toLowerCase()
74
+ } else if (value == "TRUE" || value == "true") {
75
+ requestBody[key] = true
76
+ } else if (value == "FALSE" || value == "false") {
77
+ requestBody[key] = false
78
+ }
79
+ else {
80
+ requestBody[key] = requestBody[key].toUpperCase()
81
+ }
82
+ }
83
+ } catch (error) {
84
+ console.log(error)
85
+ }
86
+ }
87
+ })
88
+
89
+ return requestBody
90
+ }
@@ -0,0 +1,7 @@
1
+ const {
2
+ AllowedPrefixes, GenerateNumericPin, ReferenceGenerator, Sanitize, Serializer
3
+ } = require("./functions")
4
+
5
+ module.exports = {
6
+ AllowedPrefixes, GenerateNumericPin, ReferenceGenerator, Sanitize, Serializer
7
+ }
@@ -3,4 +3,10 @@ const {
3
3
  WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
4
4
  isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
5
5
  isMinValue, isPasswordStrong, isSameAs, startsWith
6
- } = require("./rules")
6
+ } = require("./rules")
7
+
8
+ module.exports = {
9
+ isBIValid, isMinor, isPDF, isValidCertificateNumber, isValidNuit,
10
+ WordsCount, allowedCharsOnly, containesWhiteSpace, isAboveMaxLength,
11
+ isContactValid, isEmailValid, isIn, isInteger, isLength, isMinLength,
12
+ isMinValue, isPasswordStrong, isSameAs, startsWith }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stbmoz-onboarding/core",
3
3
  "type": "module",
4
- "version": "1.0.25",
4
+ "version": "1.0.27",
5
5
  "description": "\"core module\"",
6
6
  "main": "index.js",
7
7
  "scripts": {