opf-validator-beta 0.0.13
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 +557 -0
- package/dist/consent/index.d.ts +9 -0
- package/dist/consent/index.d.ts.map +1 -0
- package/dist/consent/index.js +12 -0
- package/dist/consent/index.js.map +1 -0
- package/dist/consent/package.json +6 -0
- package/dist/consent/successResponses/index.d.ts +89 -0
- package/dist/consent/successResponses/index.d.ts.map +1 -0
- package/dist/consent/successResponses/index.js +6 -0
- package/dist/consent/successResponses/index.js.map +1 -0
- package/dist/consent/validators/createConsent.d.ts +33 -0
- package/dist/consent/validators/createConsent.d.ts.map +1 -0
- package/dist/consent/validators/createConsent.js +206 -0
- package/dist/consent/validators/createConsent.js.map +1 -0
- package/dist/consent/validators/createConsentExtensions.d.ts +33 -0
- package/dist/consent/validators/createConsentExtensions.d.ts.map +1 -0
- package/dist/consent/validators/createConsentExtensions.js +194 -0
- package/dist/consent/validators/createConsentExtensions.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +7 -0
- package/dist/payments/index.d.ts +11 -0
- package/dist/payments/index.d.ts.map +1 -0
- package/dist/payments/index.js +18 -0
- package/dist/payments/index.js.map +1 -0
- package/dist/payments/package.json +6 -0
- package/dist/payments/successResponses/index.d.ts +129 -0
- package/dist/payments/successResponses/index.d.ts.map +1 -0
- package/dist/payments/successResponses/index.js +6 -0
- package/dist/payments/successResponses/index.js.map +1 -0
- package/dist/payments/validators/createPaymentConsent.d.ts +66 -0
- package/dist/payments/validators/createPaymentConsent.d.ts.map +1 -0
- package/dist/payments/validators/createPaymentConsent.js +509 -0
- package/dist/payments/validators/createPaymentConsent.js.map +1 -0
- package/dist/payments/validators/createPixPayment.d.ts +35 -0
- package/dist/payments/validators/createPixPayment.d.ts.map +1 -0
- package/dist/payments/validators/createPixPayment.js +343 -0
- package/dist/payments/validators/createPixPayment.js.map +1 -0
- package/dist/payments/validators/patchPixPayment.d.ts +40 -0
- package/dist/payments/validators/patchPixPayment.d.ts.map +1 -0
- package/dist/payments/validators/patchPixPayment.js +192 -0
- package/dist/payments/validators/patchPixPayment.js.map +1 -0
- package/dist/recurring-payments/index.d.ts +13 -0
- package/dist/recurring-payments/index.d.ts.map +1 -0
- package/dist/recurring-payments/index.js +17 -0
- package/dist/recurring-payments/index.js.map +1 -0
- package/dist/recurring-payments/package.json +6 -0
- package/dist/recurring-payments/successResponses/index.d.ts +175 -0
- package/dist/recurring-payments/successResponses/index.d.ts.map +1 -0
- package/dist/recurring-payments/successResponses/index.js +6 -0
- package/dist/recurring-payments/successResponses/index.js.map +1 -0
- package/dist/recurring-payments/validators/createRecurringConsent.d.ts +96 -0
- package/dist/recurring-payments/validators/createRecurringConsent.d.ts.map +1 -0
- package/dist/recurring-payments/validators/createRecurringConsent.js +664 -0
- package/dist/recurring-payments/validators/createRecurringConsent.js.map +1 -0
- package/dist/recurring-payments/validators/createRecurringRetryPixPayment.d.ts +19 -0
- package/dist/recurring-payments/validators/createRecurringRetryPixPayment.d.ts.map +1 -0
- package/dist/recurring-payments/validators/createRecurringRetryPixPayment.js +42 -0
- package/dist/recurring-payments/validators/createRecurringRetryPixPayment.js.map +1 -0
- package/dist/recurring-payments/validators/patchPixPayment.d.ts +38 -0
- package/dist/recurring-payments/validators/patchPixPayment.d.ts.map +1 -0
- package/dist/recurring-payments/validators/patchPixPayment.js +124 -0
- package/dist/recurring-payments/validators/patchPixPayment.js.map +1 -0
- package/dist/recurring-payments/validators/patchRecurringConsent.d.ts +87 -0
- package/dist/recurring-payments/validators/patchRecurringConsent.d.ts.map +1 -0
- package/dist/recurring-payments/validators/patchRecurringConsent.js +558 -0
- package/dist/recurring-payments/validators/patchRecurringConsent.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +25 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/openFinanceErrors.d.ts +90 -0
- package/dist/utils/openFinanceErrors.d.ts.map +1 -0
- package/dist/utils/openFinanceErrors.js +114 -0
- package/dist/utils/openFinanceErrors.js.map +1 -0
- package/dist/utils/package.json +6 -0
- package/dist/utils/paymentErrors.d.ts +9 -0
- package/dist/utils/paymentErrors.d.ts.map +1 -0
- package/dist/utils/paymentErrors.js +13 -0
- package/dist/utils/paymentErrors.js.map +1 -0
- package/dist/utils/successResponses.d.ts +52 -0
- package/dist/utils/successResponses.d.ts.map +1 -0
- package/dist/utils/successResponses.js +6 -0
- package/dist/utils/successResponses.js.map +1 -0
- package/dist/utils/validateHeaderParameters.d.ts +51 -0
- package/dist/utils/validateHeaderParameters.d.ts.map +1 -0
- package/dist/utils/validateHeaderParameters.js +197 -0
- package/dist/utils/validateHeaderParameters.js.map +1 -0
- package/dist/utils/validationHelpers.d.ts +89 -0
- package/dist/utils/validationHelpers.d.ts.map +1 -0
- package/dist/utils/validationHelpers.js +374 -0
- package/dist/utils/validationHelpers.js.map +1 -0
- package/package.json +30 -0
package/README.md
ADDED
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
# OPF Validator
|
|
2
|
+
|
|
3
|
+
Biblioteca TypeScript para validar requisições da Open Finance Brasil.
|
|
4
|
+
|
|
5
|
+
- ✅ Validadores para consentimentos, pagamentos únicos e recorrentes
|
|
6
|
+
- ✅ Suporte completo a TypeScript com interfaces tipadas
|
|
7
|
+
- ✅ Tratamento de erros conforme Open Finance Brasil
|
|
8
|
+
- ✅ Sem dependências externas
|
|
9
|
+
|
|
10
|
+
## Instalação
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install opf-validator
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Importar
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
// Importar funções diretamente
|
|
20
|
+
import {
|
|
21
|
+
validateCreateConsent,
|
|
22
|
+
validateCreatePaymentConsent,
|
|
23
|
+
validateCreatePixPayment,
|
|
24
|
+
validateCreateRecurringConsent,
|
|
25
|
+
validateRecurringRetryPixPaymentAgainstConsent,
|
|
26
|
+
} from 'opf-validator';
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## Módulo Consent
|
|
32
|
+
|
|
33
|
+
### Funções
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
export function validateCreateConsent(payload: CreateConsentPayload): ValidationResult
|
|
37
|
+
export function validateCreateConsentExtensions(payload: CreateConsentExtensionsPayload): ValidationResult
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Interfaces
|
|
41
|
+
|
|
42
|
+
**CreateConsentPayload:**
|
|
43
|
+
```typescript
|
|
44
|
+
interface CreateConsentPayload {
|
|
45
|
+
data: {
|
|
46
|
+
permissions: string[];
|
|
47
|
+
expirationDateTime?: string;
|
|
48
|
+
transactionFromDateTime?: string;
|
|
49
|
+
transactionToDateTime?: string;
|
|
50
|
+
loggedUser: {
|
|
51
|
+
document: { identification: string; rel: string };
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**GetConsentSuccessResponse:**
|
|
58
|
+
```typescript
|
|
59
|
+
interface GetConsentSuccessResponse {
|
|
60
|
+
data: {
|
|
61
|
+
consentId: string;
|
|
62
|
+
creationDateTime: string;
|
|
63
|
+
status: string;
|
|
64
|
+
statusUpdateDateTime: string;
|
|
65
|
+
permissions: string[];
|
|
66
|
+
expirationDateTime?: string;
|
|
67
|
+
loggedUser: { document: { identification: string; rel: string } };
|
|
68
|
+
};
|
|
69
|
+
links: { self: string };
|
|
70
|
+
meta: { requestDateTime: string };
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Módulo Payments
|
|
77
|
+
|
|
78
|
+
### Funções
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
export function validateCreatePaymentConsent(payload: CreatePaymentConsentPayload): ValidationResult
|
|
82
|
+
export function validateCreatePixPayment(payload: CreatePixPaymentPayload): ValidationResult
|
|
83
|
+
export function validatePatchPixPayment(payload: PatchPixPaymentPayload): ValidationResult
|
|
84
|
+
export function validatePixPaymentAgainstConsent(payment: CreatePixPaymentPayload, consent: GetPaymentConsentSuccessResponse): ValidationResult
|
|
85
|
+
export function validateRecurringPixPaymentAgainstConsent(payment: CreatePixPaymentPayload, consent: GetPaymentConsentSuccessResponse): ValidationResult
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Interfaces
|
|
89
|
+
|
|
90
|
+
**CreatePaymentConsentPayload:**
|
|
91
|
+
```typescript
|
|
92
|
+
interface CreatePaymentConsentPayload {
|
|
93
|
+
data: {
|
|
94
|
+
permissions: string[];
|
|
95
|
+
loggedUser: {
|
|
96
|
+
document: { identification: string; rel: string };
|
|
97
|
+
};
|
|
98
|
+
creditorAccount: {
|
|
99
|
+
ispb: string;
|
|
100
|
+
issuer: string;
|
|
101
|
+
number: string;
|
|
102
|
+
accountType: string;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**CreatePixPaymentPayload:**
|
|
109
|
+
```typescript
|
|
110
|
+
interface CreatePixPaymentPayload {
|
|
111
|
+
data: {
|
|
112
|
+
consentId: string;
|
|
113
|
+
endToEndId: string;
|
|
114
|
+
amount: string;
|
|
115
|
+
creditorAccount: {
|
|
116
|
+
ispb: string;
|
|
117
|
+
issuer: string;
|
|
118
|
+
number: string;
|
|
119
|
+
accountType: string;
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**PatchPixPaymentPayload:**
|
|
126
|
+
```typescript
|
|
127
|
+
interface PatchPixPaymentPayload {
|
|
128
|
+
data: {
|
|
129
|
+
status: string;
|
|
130
|
+
cancellationReason?: string;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
**GetPaymentConsentSuccessResponse:**
|
|
136
|
+
```typescript
|
|
137
|
+
interface GetPaymentConsentSuccessResponse {
|
|
138
|
+
data: {
|
|
139
|
+
consentId: string;
|
|
140
|
+
creationDateTime: string;
|
|
141
|
+
status: string;
|
|
142
|
+
statusUpdateDateTime: string;
|
|
143
|
+
permissions: string[];
|
|
144
|
+
loggedUser: { document: { identification: string; rel: string } };
|
|
145
|
+
creditorAccount: {
|
|
146
|
+
ispb: string;
|
|
147
|
+
issuer: string;
|
|
148
|
+
number: string;
|
|
149
|
+
accountType: string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
links: { self: string };
|
|
153
|
+
meta: { requestDateTime: string };
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## Módulo Recurring Payments
|
|
160
|
+
|
|
161
|
+
### Funções
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
export function validateCreateRecurringConsent(payload: CreateRecurringConsentPayload): ValidationResult
|
|
165
|
+
export function validatePatchRecurringConsent(payload: PatchRecurringConsentPayload): ValidationResult
|
|
166
|
+
export function validateCreateRecurringRetryPixPayment(payload: CreateRecurringRetryPixPaymentPayload): ValidationResult
|
|
167
|
+
export function validatePatchRecurringPixPayment(payload: PatchRecurringPixPaymentPayload): ValidationResult
|
|
168
|
+
export function validateCreateRecurringPixPaymentAgainstConsent(payment: any, consent: GetRecurringConsentSuccessResponse): ValidationResult
|
|
169
|
+
export function validateRecurringRetryPixPaymentAgainstConsent(retryPayment: CreateRecurringRetryPixPaymentPayload, consent: GetRecurringConsentSuccessResponse): ValidationResult
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Interfaces
|
|
173
|
+
|
|
174
|
+
**CreateRecurringConsentPayload:**
|
|
175
|
+
```typescript
|
|
176
|
+
interface CreateRecurringConsentPayload {
|
|
177
|
+
data: {
|
|
178
|
+
permissions: string[];
|
|
179
|
+
recurringConfiguration: {
|
|
180
|
+
frequency: string;
|
|
181
|
+
frequencyAdditionalInfo?: string;
|
|
182
|
+
startDateTime: string;
|
|
183
|
+
endDateTime?: string;
|
|
184
|
+
};
|
|
185
|
+
creditorAccount: {
|
|
186
|
+
ispb: string;
|
|
187
|
+
issuer: string;
|
|
188
|
+
number: string;
|
|
189
|
+
accountType: string;
|
|
190
|
+
};
|
|
191
|
+
loggedUser: {
|
|
192
|
+
document: { identification: string; rel: string };
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**CreateRecurringRetryPixPaymentPayload:**
|
|
199
|
+
```typescript
|
|
200
|
+
interface CreateRecurringRetryPixPaymentPayload {
|
|
201
|
+
data: {
|
|
202
|
+
endToEndId: string;
|
|
203
|
+
date: string; // YYYY-MM-DD
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**PatchRecurringConsentPayload:**
|
|
209
|
+
```typescript
|
|
210
|
+
interface PatchRecurringConsentPayload {
|
|
211
|
+
data: {
|
|
212
|
+
status: string;
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
**PatchRecurringPixPaymentPayload:**
|
|
218
|
+
```typescript
|
|
219
|
+
interface PatchRecurringPixPaymentPayload {
|
|
220
|
+
data: {
|
|
221
|
+
status: string;
|
|
222
|
+
cancellationReason?: string;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
**GetRecurringConsentSuccessResponse:**
|
|
228
|
+
```typescript
|
|
229
|
+
interface GetRecurringConsentSuccessResponse {
|
|
230
|
+
data: {
|
|
231
|
+
recurringConsentId: string;
|
|
232
|
+
creationDateTime: string;
|
|
233
|
+
status: string;
|
|
234
|
+
statusUpdateDateTime: string;
|
|
235
|
+
permissions: string[];
|
|
236
|
+
recurringConfiguration: {
|
|
237
|
+
frequency: string;
|
|
238
|
+
frequencyAdditionalInfo?: string;
|
|
239
|
+
startDateTime: string;
|
|
240
|
+
endDateTime?: string;
|
|
241
|
+
};
|
|
242
|
+
loggedUser: {
|
|
243
|
+
document: { identification: string; rel: string };
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
links: { self: string };
|
|
247
|
+
meta: { requestDateTime: string };
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## Estrutura de Resposta
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
interface ValidationResult {
|
|
257
|
+
isValid: boolean; // true se validação passou
|
|
258
|
+
statusCode: number; // 201 (sucesso), 422 (erro), 400 (genérico)
|
|
259
|
+
errors: ErrorDetail[]; // Array de erros encontrados
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
interface ErrorDetail {
|
|
263
|
+
code: string; // Código do erro
|
|
264
|
+
title: string; // Título descritivo
|
|
265
|
+
detail: string; // Detalhes adicionais
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## Exemplos
|
|
272
|
+
|
|
273
|
+
### Validar Consentimento de Pagamento
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
import { validateCreatePaymentConsent } from 'opf-validator';
|
|
277
|
+
|
|
278
|
+
const payload = {
|
|
279
|
+
data: {
|
|
280
|
+
permissions: ['PAYMENTS_INITIATE_PIX'],
|
|
281
|
+
loggedUser: { document: { identification: '12345678901', rel: 'CPF' } },
|
|
282
|
+
creditorAccount: {
|
|
283
|
+
ispb: '12345678',
|
|
284
|
+
issuer: '0001',
|
|
285
|
+
number: '123456789',
|
|
286
|
+
accountType: 'CACC'
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const result = validateCreatePaymentConsent(payload);
|
|
292
|
+
if (!result.isValid) {
|
|
293
|
+
console.error('Erros:', result.errors);
|
|
294
|
+
return res.status(result.statusCode).json({ errors: result.errors });
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Validar Pagamento contra Consentimento
|
|
299
|
+
|
|
300
|
+
```typescript
|
|
301
|
+
import { validatePixPaymentAgainstConsent, GetPaymentConsentSuccessResponse } from 'opf-validator';
|
|
302
|
+
|
|
303
|
+
const consent: GetPaymentConsentSuccessResponse = await getConsent(consentId);
|
|
304
|
+
const payment = {
|
|
305
|
+
data: {
|
|
306
|
+
consentId: consent.data.consentId,
|
|
307
|
+
endToEndId: 'E12345678901234567890123456789',
|
|
308
|
+
amount: '100.00',
|
|
309
|
+
creditorAccount: { ... }
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
const result = validatePixPaymentAgainstConsent(payment, consent);
|
|
314
|
+
if (!result.isValid) {
|
|
315
|
+
return res.status(result.statusCode).json({ errors: result.errors });
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Validar Pagamento Recorrente contra Consentimento
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import {
|
|
323
|
+
validateRecurringRetryPixPaymentAgainstConsent,
|
|
324
|
+
GetRecurringConsentSuccessResponse
|
|
325
|
+
} from 'opf-validator';
|
|
326
|
+
|
|
327
|
+
const consent: GetRecurringConsentSuccessResponse = await getRecurringConsent(consentId);
|
|
328
|
+
const payment = {
|
|
329
|
+
data: {
|
|
330
|
+
endToEndId: 'E12345678901234567890123456789',
|
|
331
|
+
date: '2025-02-15'
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
const result = validateRecurringRetryPixPaymentAgainstConsent(payment, consent);
|
|
336
|
+
if (!result.isValid) {
|
|
337
|
+
return res.status(result.statusCode).json({ errors: result.errors });
|
|
338
|
+
}
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
---
|
|
342
|
+
|
|
343
|
+
## Documentação Completa
|
|
344
|
+
|
|
345
|
+
Para documentação detalhada de cada função, veja [VALIDATORS_REFERENCE.md](./VALIDATORS_REFERENCE.md)
|
|
346
|
+
proxy?: string; // Chave DICT para DICT
|
|
347
|
+
cnpjInitiator: string; // CNPJ do iniciador
|
|
348
|
+
transactionIdentification?: string; // ID da transação
|
|
349
|
+
authorisationFlow?: string; // Fluxo: HYBRID_FLOW, CIBA_FLOW, FIDO_FLOW
|
|
350
|
+
consentId?: string; // ID do consentimento
|
|
351
|
+
}
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
**PIX - Resposta de Sucesso:**
|
|
355
|
+
```typescript
|
|
356
|
+
interface CreatePixPaymentSuccessResponse {
|
|
357
|
+
data: {
|
|
358
|
+
paymentId: string; // ID único do pagamento
|
|
359
|
+
endToEndId: string; // Identificador E2E
|
|
360
|
+
consentId: string; // ID do consentimento utilizado
|
|
361
|
+
creationDateTime: string; // Data/hora de criação em RFC-3339
|
|
362
|
+
status: string; // Status (ex: "ACSP", "ACCC", "RJCT")
|
|
363
|
+
statusUpdateDateTime: string;
|
|
364
|
+
amount: string;
|
|
365
|
+
currency: string;
|
|
366
|
+
};
|
|
367
|
+
links?: { self: string };
|
|
368
|
+
meta?: { requestDateTime: string };
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Pagamentos Recorrentes
|
|
373
|
+
|
|
374
|
+
**Consentimento Recorrente - Payload:**
|
|
375
|
+
```typescript
|
|
376
|
+
interface CreateRecurringConsentPayload {
|
|
377
|
+
data: {
|
|
378
|
+
loggedUser: LoggedUser; // Usuário logado (obrigatório)
|
|
379
|
+
businessEntity?: BusinessEntity; // Entidade de negócio (opcional)
|
|
380
|
+
creditors: Creditor[]; // Array de credores (obrigatório)
|
|
381
|
+
expirationDateTime?: string; // Expiração em RFC-3339
|
|
382
|
+
additionalInformation?: string; // Informações adicionais
|
|
383
|
+
debtorAccount?: DebtorAccount; // Conta de débito
|
|
384
|
+
recurringConfiguration: { // Configuração de recorrência
|
|
385
|
+
automatic: {
|
|
386
|
+
contractId: string;
|
|
387
|
+
interval: string; // SEMANAL, MENSAL, ANUAL, SEMESTRAL, TRIMESTRAL
|
|
388
|
+
contractDebtor: {
|
|
389
|
+
name: string;
|
|
390
|
+
document: { identification: string; rel: string };
|
|
391
|
+
};
|
|
392
|
+
isRetryAccepted: boolean;
|
|
393
|
+
referenceStartDate: string; // Data de início em YYYY-MM-DD
|
|
394
|
+
fixedAmount?: string; // Valor fixo
|
|
395
|
+
maximumVariableAmount?: string;
|
|
396
|
+
minimumVariableAmount?: string;
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
interface Creditor {
|
|
403
|
+
personType: string; // PESSOA_NATURAL ou PESSOA_JURIDICA
|
|
404
|
+
cpfCnpj: string; // CPF (11) ou CNPJ (14)
|
|
405
|
+
name: string; // Nome do credor
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
interface DebtorAccount {
|
|
409
|
+
ispb: string; // ISPB (8 dígitos)
|
|
410
|
+
issuer?: string; // Código do emissor
|
|
411
|
+
number: string; // Número da conta
|
|
412
|
+
accountType: string; // CACC, SVGS, TRAN
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
**Consentimento Recorrente - Resposta:**
|
|
417
|
+
```typescript
|
|
418
|
+
interface CreateRecurringConsentSuccessResponse {
|
|
419
|
+
data: {
|
|
420
|
+
recurringConsentId: string; // ID do consentimento recorrente
|
|
421
|
+
creationDateTime: string;
|
|
422
|
+
status: string; // Status do consentimento
|
|
423
|
+
statusUpdateDateTime: string;
|
|
424
|
+
permissions: string[];
|
|
425
|
+
recurringConfiguration: {
|
|
426
|
+
frequency: string;
|
|
427
|
+
frequencyAdditionalInfo?: string;
|
|
428
|
+
startDateTime?: string;
|
|
429
|
+
endDateTime?: string;
|
|
430
|
+
};
|
|
431
|
+
};
|
|
432
|
+
links?: { self: string };
|
|
433
|
+
meta?: { requestDateTime: string };
|
|
434
|
+
}
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
## Exemplo: Express.js
|
|
438
|
+
|
|
439
|
+
```typescript
|
|
440
|
+
import express from 'express';
|
|
441
|
+
import * as opf from 'opf-validator';
|
|
442
|
+
|
|
443
|
+
const app = express();
|
|
444
|
+
app.use(express.json());
|
|
445
|
+
|
|
446
|
+
// Middleware: validar headers
|
|
447
|
+
app.use((req, res, next) => {
|
|
448
|
+
const validation = opf.validators.validateHeaders(req.headers);
|
|
449
|
+
if (!validation.isValid) return res.status(validation.statusCode).json({ errors: validation.errors });
|
|
450
|
+
next();
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// POST /consents
|
|
454
|
+
app.post('/consents', (req, res) => {
|
|
455
|
+
const headerValidation = opf.validators.validateHeaders(req.headers);
|
|
456
|
+
if (!headerValidation.isValid) return res.status(headerValidation.statusCode).json({ errors: headerValidation.errors });
|
|
457
|
+
|
|
458
|
+
const payloadValidation = opf.consent.validateCreateConsent(req.body);
|
|
459
|
+
if (!payloadValidation.isValid) return res.status(validation.statusCode).json({ errors: payloadValidation.errors });
|
|
460
|
+
|
|
461
|
+
res.status(201).json({ success: true });
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// POST /payments (com x-fapi-interaction-id obrigatório)
|
|
465
|
+
app.post('/payments', (req, res) => {
|
|
466
|
+
const headerValidation = opf.validators.validateHeadersWithFapiRequired(req.headers);
|
|
467
|
+
if (!headerValidation.isValid) return res.status(headerValidation.statusCode).json({ errors: headerValidation.errors });
|
|
468
|
+
|
|
469
|
+
const payloadValidation = opf.payments.validateCreatePixPayment(req.body);
|
|
470
|
+
if (!payloadValidation.isValid) return res.status(validation.statusCode).json({ errors: payloadValidation.errors });
|
|
471
|
+
|
|
472
|
+
res.status(201).json({ success: true });
|
|
473
|
+
});
|
|
474
|
+
|
|
475
|
+
app.listen(3000);
|
|
476
|
+
```
|
|
477
|
+
|
|
478
|
+
## Resposta
|
|
479
|
+
|
|
480
|
+
```typescript
|
|
481
|
+
// Sucesso (HTTP 201)
|
|
482
|
+
{ isValid: true, statusCode: 201, errors: [] }
|
|
483
|
+
|
|
484
|
+
// Erro - Parâmetro inválido (HTTP 422)
|
|
485
|
+
{
|
|
486
|
+
isValid: false,
|
|
487
|
+
statusCode: 422,
|
|
488
|
+
errors: [
|
|
489
|
+
{ code: "PARAMETRO_INVALIDO", title: "Parâmetro inválido", detail: "..." }
|
|
490
|
+
]
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// Erro - Requisição malformada (HTTP 400)
|
|
494
|
+
{
|
|
495
|
+
isValid: false,
|
|
496
|
+
statusCode: 400,
|
|
497
|
+
errors: [
|
|
498
|
+
{ code: "ERRO_NAO_MAPEADO", title: "Erro não mapeado", detail: "..." }
|
|
499
|
+
]
|
|
500
|
+
}
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
## TypeScript
|
|
504
|
+
|
|
505
|
+
```typescript
|
|
506
|
+
import type {
|
|
507
|
+
// Validação
|
|
508
|
+
ValidationResult,
|
|
509
|
+
ErrorDetail,
|
|
510
|
+
|
|
511
|
+
// Consentimentos
|
|
512
|
+
CreateConsentPayload,
|
|
513
|
+
CreateConsentSuccessResponse,
|
|
514
|
+
GetConsentSuccessResponse,
|
|
515
|
+
CreateConsentExtensionsSuccessResponse,
|
|
516
|
+
|
|
517
|
+
// Pagamentos
|
|
518
|
+
CreatePixPaymentPayload,
|
|
519
|
+
CreatePixPaymentSuccessResponse,
|
|
520
|
+
GetPixPaymentSuccessResponse,
|
|
521
|
+
CreatePaymentConsentSuccessResponse,
|
|
522
|
+
GetPaymentConsentSuccessResponse,
|
|
523
|
+
|
|
524
|
+
// Pagamentos Recorrentes
|
|
525
|
+
CreateRecurringConsentSuccessResponse,
|
|
526
|
+
GetRecurringConsentSuccessResponse,
|
|
527
|
+
PatchRecurringConsentSuccessResponse,
|
|
528
|
+
CreateRecurringPixPaymentSuccessResponse,
|
|
529
|
+
PatchRecurringPixPaymentSuccessResponse,
|
|
530
|
+
CreateRecurringRetryPixPaymentSuccessResponse,
|
|
531
|
+
} from "opf-validator";
|
|
532
|
+
|
|
533
|
+
// Tipagem em validações
|
|
534
|
+
const payload: CreatePixPaymentPayload = { /* ... */ };
|
|
535
|
+
const result: ValidationResult = opf.payments.validateCreatePixPayment(payload);
|
|
536
|
+
|
|
537
|
+
// Tipagem em respostas de sucesso
|
|
538
|
+
const response: CreatePixPaymentSuccessResponse = {
|
|
539
|
+
data: {
|
|
540
|
+
paymentId: "pay-123",
|
|
541
|
+
endToEndId: "E12345678901234567890123456789",
|
|
542
|
+
consentId: "con-456",
|
|
543
|
+
creationDateTime: "2025-01-15T10:30:00Z",
|
|
544
|
+
status: "ACSP",
|
|
545
|
+
statusUpdateDateTime: "2025-01-15T10:30:00Z",
|
|
546
|
+
amount: "250.75",
|
|
547
|
+
currency: "BRL"
|
|
548
|
+
},
|
|
549
|
+
meta: { requestDateTime: "2025-01-15T10:30:00Z" }
|
|
550
|
+
};
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
## Referências
|
|
554
|
+
|
|
555
|
+
- [Open Finance Brasil](https://openfinancebrasil.atlassian.net/)
|
|
556
|
+
- [Status Codes Mapping](./STATUS_CODES.md) - Documentação de status codes HTTP
|
|
557
|
+
- [Validators Reference](./VALIDATORS_REFERENCE.md) - Referência completa de todas as funções
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consent Module - Exports all validators and success responses
|
|
3
|
+
*/
|
|
4
|
+
export { validateCreateConsent } from "./validators/createConsent";
|
|
5
|
+
export type { CreateConsentPayload, CreateConsentData } from "./validators/createConsent";
|
|
6
|
+
export { validateCreateConsentExtensions } from "./validators/createConsentExtensions";
|
|
7
|
+
export type { CreateConsentExtensionsPayload, CreateConsentExtensionsData, LoggedUserExtensions, BusinessEntityExtensions, } from "./validators/createConsentExtensions";
|
|
8
|
+
export type { CreateConsentSuccessResponse, GetConsentSuccessResponse, CreateConsentExtensionsSuccessResponse, } from "./successResponses";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/consent/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,YAAY,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE1F,OAAO,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AACvF,YAAY,EACV,8BAA8B,EAC9B,2BAA2B,EAC3B,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,sCAAsC,CAAC;AAG9C,YAAY,EACV,4BAA4B,EAC5B,yBAAyB,EACzB,sCAAsC,GACvC,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Consent Module - Exports all validators and success responses
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validateCreateConsentExtensions = exports.validateCreateConsent = void 0;
|
|
7
|
+
// Validators
|
|
8
|
+
var createConsent_1 = require("./validators/createConsent");
|
|
9
|
+
Object.defineProperty(exports, "validateCreateConsent", { enumerable: true, get: function () { return createConsent_1.validateCreateConsent; } });
|
|
10
|
+
var createConsentExtensions_1 = require("./validators/createConsentExtensions");
|
|
11
|
+
Object.defineProperty(exports, "validateCreateConsentExtensions", { enumerable: true, get: function () { return createConsentExtensions_1.validateCreateConsentExtensions; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consent/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,aAAa;AACb,4DAAmE;AAA1D,sHAAA,qBAAqB,OAAA;AAG9B,gFAAuF;AAA9E,0IAAA,+BAA+B,OAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interfaces de Sucesso para Respostas de Consent
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Resposta de sucesso para POST /consents (CreateConsent)
|
|
6
|
+
*/
|
|
7
|
+
export interface CreateConsentSuccessResponse {
|
|
8
|
+
data: {
|
|
9
|
+
consentId: string;
|
|
10
|
+
status: string;
|
|
11
|
+
statusUpdateDateTime: string;
|
|
12
|
+
permissions: string[];
|
|
13
|
+
expirationDateTime: string;
|
|
14
|
+
loggedUser?: {
|
|
15
|
+
document: {
|
|
16
|
+
identification: string;
|
|
17
|
+
rel: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
links?: {
|
|
22
|
+
self: string;
|
|
23
|
+
first?: string;
|
|
24
|
+
prev?: string;
|
|
25
|
+
next?: string;
|
|
26
|
+
last?: string;
|
|
27
|
+
};
|
|
28
|
+
meta?: {
|
|
29
|
+
totalRecords?: number;
|
|
30
|
+
totalPages?: number;
|
|
31
|
+
requestDateTime: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Resposta de sucesso para GET /consents/:consentId (GetConsent)
|
|
36
|
+
*/
|
|
37
|
+
export interface GetConsentSuccessResponse {
|
|
38
|
+
data: {
|
|
39
|
+
consentId: string;
|
|
40
|
+
status: string;
|
|
41
|
+
statusUpdateDateTime: string;
|
|
42
|
+
permissions: string[];
|
|
43
|
+
expirationDateTime: string;
|
|
44
|
+
creationDateTime: string;
|
|
45
|
+
loggedUser?: {
|
|
46
|
+
document: {
|
|
47
|
+
identification: string;
|
|
48
|
+
rel: string;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
links?: {
|
|
53
|
+
self: string;
|
|
54
|
+
};
|
|
55
|
+
meta?: {
|
|
56
|
+
requestDateTime: string;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Resposta de sucesso para POST /consents/:consentId/extensions (CreateConsentExtensions)
|
|
61
|
+
*/
|
|
62
|
+
export interface CreateConsentExtensionsSuccessResponse {
|
|
63
|
+
data: {
|
|
64
|
+
consentId: string;
|
|
65
|
+
status: string;
|
|
66
|
+
statusUpdateDateTime: string;
|
|
67
|
+
permissions: string[];
|
|
68
|
+
expirationDateTime: string;
|
|
69
|
+
loggedUser?: {
|
|
70
|
+
document: {
|
|
71
|
+
identification: string;
|
|
72
|
+
rel: string;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
businessEntity?: {
|
|
76
|
+
document: {
|
|
77
|
+
identification: string;
|
|
78
|
+
rel: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
links?: {
|
|
83
|
+
self: string;
|
|
84
|
+
};
|
|
85
|
+
meta?: {
|
|
86
|
+
requestDateTime: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/consent/successResponses/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,oBAAoB,EAAE,MAAM,CAAC;QAC7B,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,UAAU,CAAC,EAAE;YACX,QAAQ,EAAE;gBACR,cAAc,EAAE,MAAM,CAAC;gBACvB,GAAG,EAAE,MAAM,CAAC;aACb,CAAC;SACH,CAAC;KACH,CAAC;IACF,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC;IACF,IAAI,CAAC,EAAE;QACL,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,oBAAoB,EAAE,MAAM,CAAC;QAC7B,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,gBAAgB,EAAE,MAAM,CAAC;QACzB,UAAU,CAAC,EAAE;YACX,QAAQ,EAAE;gBACR,cAAc,EAAE,MAAM,CAAC;gBACvB,GAAG,EAAE,MAAM,CAAC;aACb,CAAC;SACH,CAAC;KACH,CAAC;IACF,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,CAAC,EAAE;QACL,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,sCAAsC;IACrD,IAAI,EAAE;QACJ,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,CAAC;QACf,oBAAoB,EAAE,MAAM,CAAC;QAC7B,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,UAAU,CAAC,EAAE;YACX,QAAQ,EAAE;gBACR,cAAc,EAAE,MAAM,CAAC;gBACvB,GAAG,EAAE,MAAM,CAAC;aACb,CAAC;SACH,CAAC;QACF,cAAc,CAAC,EAAE;YACf,QAAQ,EAAE;gBACR,cAAc,EAAE,MAAM,CAAC;gBACvB,GAAG,EAAE,MAAM,CAAC;aACb,CAAC;SACH,CAAC;KACH,CAAC;IACF,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,CAAC,EAAE;QACL,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/consent/successResponses/index.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|