opf-validator 0.0.7 → 0.0.8
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/README.md +10 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,9 +19,9 @@ npm install opf-validator
|
|
|
19
19
|
## Uso Rápido
|
|
20
20
|
|
|
21
21
|
```typescript
|
|
22
|
-
import
|
|
22
|
+
import * as opf from "opf-validator";
|
|
23
23
|
|
|
24
|
-
const resultado = validateCreatePixPayment({
|
|
24
|
+
const resultado = opf.payments.validateCreatePixPayment({
|
|
25
25
|
data: {
|
|
26
26
|
endToEndId: "E12345678901234567890123456789",
|
|
27
27
|
date: "2025-01-15",
|
|
@@ -68,35 +68,30 @@ if (resultado.isValid) {
|
|
|
68
68
|
Os headers são validados conforme especificações da Open Finance Brasil. Há três formas de validação:
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
|
-
import
|
|
72
|
-
validateHeader,
|
|
73
|
-
validateHeaderRequired,
|
|
74
|
-
validateHeaderOptional,
|
|
75
|
-
validateHeaders
|
|
76
|
-
} from "opf-validator/utils/validateHeaderParameters";
|
|
71
|
+
import * as opf from "opf-validator";
|
|
77
72
|
|
|
78
73
|
// Forma 1: Com override de obrigatoriedade (customizável por endpoint)
|
|
79
|
-
const result = validateHeader('x-fapi-interaction-id', value, false); // Opcional
|
|
80
|
-
const result = validateHeader('Authorization', token, true); // Obrigatório
|
|
74
|
+
const result = opf.validators.validateHeader('x-fapi-interaction-id', value, false); // Opcional
|
|
75
|
+
const result = opf.validators.validateHeader('Authorization', token, true); // Obrigatório
|
|
81
76
|
|
|
82
77
|
// Forma 2: Sempre obrigatório
|
|
83
|
-
const result = validateHeaderRequired('x-fapi-interaction-id', uuid);
|
|
78
|
+
const result = opf.validators.validateHeaderRequired('x-fapi-interaction-id', uuid);
|
|
84
79
|
|
|
85
80
|
// Forma 3: Sempre opcional
|
|
86
|
-
const result = validateHeaderOptional('X-Idempotency-Key', key);
|
|
81
|
+
const result = opf.validators.validateHeaderOptional('X-Idempotency-Key', key);
|
|
87
82
|
|
|
88
83
|
// Validar todos os headers de uma requisição
|
|
89
|
-
const result = validateHeaders(request.headers);
|
|
84
|
+
const result = opf.validators.validateHeaders(request.headers);
|
|
90
85
|
```
|
|
91
86
|
|
|
92
87
|
**Exemplo com Express:**
|
|
93
88
|
|
|
94
89
|
```typescript
|
|
95
90
|
import express from 'express';
|
|
96
|
-
import
|
|
91
|
+
import * as opf from 'opf-validator';
|
|
97
92
|
|
|
98
93
|
app.post('/api/payments', (req, res) => {
|
|
99
|
-
const validation = validateHeaders(req.headers);
|
|
94
|
+
const validation = opf.validators.validateHeaders(req.headers);
|
|
100
95
|
if (!validation.isValid) {
|
|
101
96
|
return res.status(400).json(validation.errors);
|
|
102
97
|
}
|