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
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Padrão de Erros do Open Finance Brasil
|
|
3
|
+
* Seguindo a especificação da API de Consentimentos
|
|
4
|
+
*/
|
|
5
|
+
export interface ErrorDetail {
|
|
6
|
+
code: string;
|
|
7
|
+
title: string;
|
|
8
|
+
detail: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ValidationResult {
|
|
11
|
+
isValid: boolean;
|
|
12
|
+
statusCode: number;
|
|
13
|
+
errors: ErrorDetail[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Códigos de erro para CreateConsent e CreateConsentExtensions
|
|
17
|
+
*/
|
|
18
|
+
export declare const ConsentErrorCodes: {
|
|
19
|
+
DEPENDE_MULTIPLA_ALCADA: {
|
|
20
|
+
title: string;
|
|
21
|
+
code: string;
|
|
22
|
+
};
|
|
23
|
+
ESTADO_CONSENTIMENTO_INVALIDO: {
|
|
24
|
+
title: string;
|
|
25
|
+
code: string;
|
|
26
|
+
};
|
|
27
|
+
DATA_EXPIRACAO_INVALIDA: {
|
|
28
|
+
title: string;
|
|
29
|
+
code: string;
|
|
30
|
+
};
|
|
31
|
+
ERRO_NAO_MAPEADO: {
|
|
32
|
+
title: string;
|
|
33
|
+
code: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Códigos de erro para CreatePaymentConsent
|
|
38
|
+
*/
|
|
39
|
+
export declare const PaymentConsentErrorCodes: {
|
|
40
|
+
FORMA_PAGAMENTO_INVALIDA: {
|
|
41
|
+
title: string;
|
|
42
|
+
code: string;
|
|
43
|
+
};
|
|
44
|
+
DATA_PAGAMENTO_INVALIDA: {
|
|
45
|
+
title: string;
|
|
46
|
+
code: string;
|
|
47
|
+
};
|
|
48
|
+
DETALHE_PAGAMENTO_INVALIDO: {
|
|
49
|
+
title: string;
|
|
50
|
+
code: string;
|
|
51
|
+
};
|
|
52
|
+
PARAMETRO_NAO_INFORMADO: {
|
|
53
|
+
title: string;
|
|
54
|
+
code: string;
|
|
55
|
+
};
|
|
56
|
+
PARAMETRO_INVALIDO: {
|
|
57
|
+
title: string;
|
|
58
|
+
code: string;
|
|
59
|
+
};
|
|
60
|
+
ERRO_IDEMPOTENCIA: {
|
|
61
|
+
title: string;
|
|
62
|
+
code: string;
|
|
63
|
+
};
|
|
64
|
+
NAO_INFORMADO: {
|
|
65
|
+
title: string;
|
|
66
|
+
code: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Factory function para criar erros padronizados
|
|
71
|
+
*/
|
|
72
|
+
export declare function createError(code: string, title: string, detail: string): ErrorDetail;
|
|
73
|
+
/**
|
|
74
|
+
* Determina o status code baseado nos códigos de erro
|
|
75
|
+
* Segue a especificação Open Finance Brasil
|
|
76
|
+
*/
|
|
77
|
+
export declare function getStatusCode(errors: ErrorDetail[]): number;
|
|
78
|
+
/**
|
|
79
|
+
* Mapa de tipos de erros comuns
|
|
80
|
+
*/
|
|
81
|
+
export declare const CommonErrors: {
|
|
82
|
+
PARAMETRO_NAO_INFORMADO: (fieldName: string) => ErrorDetail;
|
|
83
|
+
PARAMETRO_INVALIDO: (fieldName: string, reason: string) => ErrorDetail;
|
|
84
|
+
DETALHE_PAGAMENTO_INVALIDO: (fieldName: string, reason: string) => ErrorDetail;
|
|
85
|
+
DATA_EXPIRACAO_INVALIDA: () => ErrorDetail;
|
|
86
|
+
FORMA_PAGAMENTO_INVALIDA: (paymentType: string) => ErrorDetail;
|
|
87
|
+
DATA_PAGAMENTO_INVALIDA: () => ErrorDetail;
|
|
88
|
+
ERRO_NAO_MAPEADO: (reason: string) => ErrorDetail;
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=openFinanceErrors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openFinanceErrors.d.ts","sourceRoot":"","sources":["../../src/utils/openFinanceErrors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,WAAW,EAAE,CAAC;CACvB;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;CAiB7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BpC,CAAC;AAEF;;GAEG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,WAAW,CAMb;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CA0B3D;AAED;;GAEG;AACH,eAAO,MAAM,YAAY;yCACc,MAAM;oCAOX,MAAM,UAAU,MAAM;4CAOd,MAAM,UAAU,MAAM;;4CActB,MAAM;;+BAcnB,MAAM;CAMlC,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Padrão de Erros do Open Finance Brasil
|
|
4
|
+
* Seguindo a especificação da API de Consentimentos
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CommonErrors = exports.PaymentConsentErrorCodes = exports.ConsentErrorCodes = void 0;
|
|
8
|
+
exports.createError = createError;
|
|
9
|
+
exports.getStatusCode = getStatusCode;
|
|
10
|
+
/**
|
|
11
|
+
* Códigos de erro para CreateConsent e CreateConsentExtensions
|
|
12
|
+
*/
|
|
13
|
+
exports.ConsentErrorCodes = {
|
|
14
|
+
DEPENDE_MULTIPLA_ALCADA: {
|
|
15
|
+
title: "Necessário aprovação de múltipla alçada.",
|
|
16
|
+
code: "DEPENDE_MULTIPLA_ALCADA",
|
|
17
|
+
},
|
|
18
|
+
ESTADO_CONSENTIMENTO_INVALIDO: {
|
|
19
|
+
title: "Estado inválido do consentimento.",
|
|
20
|
+
code: "ESTADO_CONSENTIMENTO_INVALIDO",
|
|
21
|
+
},
|
|
22
|
+
DATA_EXPIRACAO_INVALIDA: {
|
|
23
|
+
title: "Nova data para expiração do consentimento é inválida.",
|
|
24
|
+
code: "DATA_EXPIRACAO_INVALIDA",
|
|
25
|
+
},
|
|
26
|
+
ERRO_NAO_MAPEADO: {
|
|
27
|
+
title: "Erro não mapeado.",
|
|
28
|
+
code: "ERRO_NAO_MAPEADO",
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Códigos de erro para CreatePaymentConsent
|
|
33
|
+
*/
|
|
34
|
+
exports.PaymentConsentErrorCodes = {
|
|
35
|
+
FORMA_PAGAMENTO_INVALIDA: {
|
|
36
|
+
title: "Forma de pagamento inválida.",
|
|
37
|
+
code: "FORMA_PAGAMENTO_INVALIDA",
|
|
38
|
+
},
|
|
39
|
+
DATA_PAGAMENTO_INVALIDA: {
|
|
40
|
+
title: "Data de pagamento inválida.",
|
|
41
|
+
code: "DATA_PAGAMENTO_INVALIDA",
|
|
42
|
+
},
|
|
43
|
+
DETALHE_PAGAMENTO_INVALIDO: {
|
|
44
|
+
title: "Detalhe do pagamento inválido.",
|
|
45
|
+
code: "DETALHE_PAGAMENTO_INVALIDO",
|
|
46
|
+
},
|
|
47
|
+
PARAMETRO_NAO_INFORMADO: {
|
|
48
|
+
title: "Parâmetro não informado.",
|
|
49
|
+
code: "PARAMETRO_NAO_INFORMADO",
|
|
50
|
+
},
|
|
51
|
+
PARAMETRO_INVALIDO: {
|
|
52
|
+
title: "Parâmetro inválido.",
|
|
53
|
+
code: "PARAMETRO_INVALIDO",
|
|
54
|
+
},
|
|
55
|
+
ERRO_IDEMPOTENCIA: {
|
|
56
|
+
title: "Erro idempotência.",
|
|
57
|
+
code: "ERRO_IDEMPOTENCIA",
|
|
58
|
+
},
|
|
59
|
+
NAO_INFORMADO: {
|
|
60
|
+
title: "Não informado.",
|
|
61
|
+
code: "NAO_INFORMADO",
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Factory function para criar erros padronizados
|
|
66
|
+
*/
|
|
67
|
+
function createError(code, title, detail) {
|
|
68
|
+
return {
|
|
69
|
+
code,
|
|
70
|
+
title,
|
|
71
|
+
detail,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Determina o status code baseado nos códigos de erro
|
|
76
|
+
* Segue a especificação Open Finance Brasil
|
|
77
|
+
*/
|
|
78
|
+
function getStatusCode(errors) {
|
|
79
|
+
if (errors.length === 0)
|
|
80
|
+
return 201;
|
|
81
|
+
const errorCodes = errors.map(e => e.code);
|
|
82
|
+
// 422: Unprocessable Entity - erros sintáticos e semânticos previstos
|
|
83
|
+
const unprocessableErrorCodes = [
|
|
84
|
+
'PARAMETRO_INVALIDO',
|
|
85
|
+
'PARAMETRO_NAO_INFORMADO',
|
|
86
|
+
'DETALHE_PAGAMENTO_INVALIDO',
|
|
87
|
+
'DATA_EXPIRACAO_INVALIDA',
|
|
88
|
+
'DATA_PAGAMENTO_INVALIDA',
|
|
89
|
+
'FORMA_PAGAMENTO_INVALIDA',
|
|
90
|
+
'DEPENDE_MULTIPLA_ALCADA',
|
|
91
|
+
'ESTADO_CONSENTIMENTO_INVALIDO',
|
|
92
|
+
'ERRO_IDEMPOTENCIA',
|
|
93
|
+
'FORA_PRAZO_PERMITIDO',
|
|
94
|
+
'NAO_INFORMADO',
|
|
95
|
+
];
|
|
96
|
+
if (errorCodes.some(code => unprocessableErrorCodes.includes(code))) {
|
|
97
|
+
return 422;
|
|
98
|
+
}
|
|
99
|
+
// 400: Bad Request - erros gerais
|
|
100
|
+
return 400;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Mapa de tipos de erros comuns
|
|
104
|
+
*/
|
|
105
|
+
exports.CommonErrors = {
|
|
106
|
+
PARAMETRO_NAO_INFORMADO: (fieldName) => createError("PARAMETRO_NAO_INFORMADO", "Parâmetro não informado.", `Parâmetro [${fieldName}] obrigatório não informado.`),
|
|
107
|
+
PARAMETRO_INVALIDO: (fieldName, reason) => createError("PARAMETRO_INVALIDO", "Parâmetro inválido.", `Parâmetro [${fieldName}] não obedece as regras de formatação esperadas. ${reason}`),
|
|
108
|
+
DETALHE_PAGAMENTO_INVALIDO: (fieldName, reason) => createError("DETALHE_PAGAMENTO_INVALIDO", "Detalhe do pagamento inválido.", `Parâmetro [${fieldName}] não obedece às regras de negócio. ${reason}`),
|
|
109
|
+
DATA_EXPIRACAO_INVALIDA: () => createError("DATA_EXPIRACAO_INVALIDA", "Nova data para expiração do consentimento é inválida.", "A data de expiração deve estar no formato RFC-3339 com timezone UTC (YYYY-MM-DDTHH:mm:ssZ)"),
|
|
110
|
+
FORMA_PAGAMENTO_INVALIDA: (paymentType) => createError("FORMA_PAGAMENTO_INVALIDA", "Forma de pagamento inválida.", `Forma de pagamento [${paymentType}] não suportada. O tipo de pagamento deve ser PIX.`),
|
|
111
|
+
DATA_PAGAMENTO_INVALIDA: () => createError("DATA_PAGAMENTO_INVALIDA", "Data de pagamento inválida.", "Data de pagamento inválida para a forma de pagamento selecionada. Deve estar no formato YYYY-MM-DD."),
|
|
112
|
+
ERRO_NAO_MAPEADO: (reason) => createError("ERRO_NAO_MAPEADO", "Erro não mapeado.", `Erro não mapeado: ${reason}`),
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=openFinanceErrors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openFinanceErrors.js","sourceRoot":"","sources":["../../src/utils/openFinanceErrors.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAyEH,kCAUC;AAMD,sCA0BC;AArGD;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B,uBAAuB,EAAE;QACvB,KAAK,EAAE,0CAA0C;QACjD,IAAI,EAAE,yBAAyB;KAChC;IACD,6BAA6B,EAAE;QAC7B,KAAK,EAAE,mCAAmC;QAC1C,IAAI,EAAE,+BAA+B;KACtC;IACD,uBAAuB,EAAE;QACvB,KAAK,EAAE,uDAAuD;QAC9D,IAAI,EAAE,yBAAyB;KAChC;IACD,gBAAgB,EAAE;QAChB,KAAK,EAAE,mBAAmB;QAC1B,IAAI,EAAE,kBAAkB;KACzB;CACF,CAAC;AAEF;;GAEG;AACU,QAAA,wBAAwB,GAAG;IACtC,wBAAwB,EAAE;QACxB,KAAK,EAAE,8BAA8B;QACrC,IAAI,EAAE,0BAA0B;KACjC;IACD,uBAAuB,EAAE;QACvB,KAAK,EAAE,6BAA6B;QACpC,IAAI,EAAE,yBAAyB;KAChC;IACD,0BAA0B,EAAE;QAC1B,KAAK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ACT,yBAAyB,EACzB,0BAA0B,EAC1B,cAAc,SAAS,8BAA8B,CACtD;IAEH,kBAAkB,EAAE,CAAC,SAAiB,EAAE,MAAc,EAAE,EAAE,CACxD,WAAW,CACT,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,SAAS,oDAAoD,MAAM,EAAE,CACpF;IAEH,0BAA0B,EAAE,CAAC,SAAiB,EAAE,MAAc,EAAE,EAAE,CAChE,WAAW,CACT,4BAA4B,EAC5B,gCAAgC,EAChC,cAAc,SAAS,uCAAuC,MAAM,EAAE,CACvE;IAEH,uBAAuB,EAAE,GAAG,EAAE,CAC5B,WAAW,CACT,yBAAyB,EACzB,uDAAuD,EACvD,4FAA4F,CAC7F;IAEH,wBAAwB,EAAE,CAAC,WAAmB,EAAE,EAAE,CAChD,WAAW,CACT,0BAA0B,EAC1B,8BAA8B,EAC9B,uBAAuB,WAAW,oDAAoD,CACvF;IAEH,uBAAuB,EAAE,GAAG,EAAE,CAC5B,WAAW,CACT,yBAAyB,EACzB,6BAA6B,EAC7B,qGAAqG,CACtG;IAEH,gBAAgB,EAAE,CAAC,MAAc,EAAE,EAAE,CACnC,WAAW,CACT,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,MAAM,EAAE,CAC9B;CACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Erros específicos para validação de Payment Consent
|
|
3
|
+
*/
|
|
4
|
+
export declare const PaymentErrors: {
|
|
5
|
+
FORMA_PAGAMENTO_INVALIDA: (paymentType: string) => import("./openFinanceErrors").ErrorDetail;
|
|
6
|
+
DATA_PAGAMENTO_INVALIDA: () => import("./openFinanceErrors").ErrorDetail;
|
|
7
|
+
DETALHE_PAGAMENTO_INVALIDO: (fieldName: string, reason: string) => import("./openFinanceErrors").ErrorDetail;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=paymentErrors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paymentErrors.d.ts","sourceRoot":"","sources":["../../src/utils/paymentErrors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,eAAO,MAAM,aAAa;4CACgB,MAAM;;4CAcN,MAAM,UAAU,MAAM;CAM/D,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Erros específicos para validação de Payment Consent
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PaymentErrors = void 0;
|
|
7
|
+
const openFinanceErrors_1 = require("./openFinanceErrors");
|
|
8
|
+
exports.PaymentErrors = {
|
|
9
|
+
FORMA_PAGAMENTO_INVALIDA: (paymentType) => (0, openFinanceErrors_1.createError)("FORMA_PAGAMENTO_INVALIDA", "Forma de pagamento inválida.", `Forma de pagamento [${paymentType}] não suportada. O tipo de pagamento deve ser PIX.`),
|
|
10
|
+
DATA_PAGAMENTO_INVALIDA: () => (0, openFinanceErrors_1.createError)("DATA_PAGAMENTO_INVALIDA", "Data de pagamento inválida.", "Data de pagamento inválida para a forma de pagamento selecionada. Deve estar no formato YYYY-MM-DD."),
|
|
11
|
+
DETALHE_PAGAMENTO_INVALIDO: (fieldName, reason) => (0, openFinanceErrors_1.createError)("DETALHE_PAGAMENTO_INVALIDO", "Detalhe do pagamento inválido.", `Parâmetro [${fieldName}] não obedece às regras de negócio. ${reason}`),
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=paymentErrors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paymentErrors.js","sourceRoot":"","sources":["../../src/utils/paymentErrors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2DAAkD;AAErC,QAAA,aAAa,GAAG;IAC3B,wBAAwB,EAAE,CAAC,WAAmB,EAAE,EAAE,CAChD,IAAA,+BAAW,EACT,0BAA0B,EAC1B,8BAA8B,EAC9B,uBAAuB,WAAW,oDAAoD,CACvF;IAEH,uBAAuB,EAAE,GAAG,EAAE,CAC5B,IAAA,+BAAW,EACT,yBAAyB,EACzB,6BAA6B,EAC7B,qGAAqG,CACtG;IAEH,0BAA0B,EAAE,CAAC,SAAiB,EAAE,MAAc,EAAE,EAAE,CAChE,IAAA,+BAAW,EACT,4BAA4B,EAC5B,gCAAgC,EAChC,cAAc,SAAS,uCAAuC,MAAM,EAAE,CACvE;CACJ,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interfaces genéricas de Sucesso para respostas da Open Finance Brasil
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Interface genérica de sucesso para qualquer resposta
|
|
6
|
+
*/
|
|
7
|
+
export interface SuccessResponse<T> {
|
|
8
|
+
data: T;
|
|
9
|
+
links?: {
|
|
10
|
+
self: string;
|
|
11
|
+
first?: string;
|
|
12
|
+
prev?: string;
|
|
13
|
+
next?: string;
|
|
14
|
+
last?: string;
|
|
15
|
+
};
|
|
16
|
+
meta?: {
|
|
17
|
+
totalRecords?: number;
|
|
18
|
+
totalPages?: number;
|
|
19
|
+
requestDateTime: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Resposta de sucesso genérica com dados de paginação
|
|
24
|
+
*/
|
|
25
|
+
export interface PaginatedSuccessResponse<T> {
|
|
26
|
+
data: T[];
|
|
27
|
+
links?: {
|
|
28
|
+
self: string;
|
|
29
|
+
first: string;
|
|
30
|
+
prev?: string;
|
|
31
|
+
next?: string;
|
|
32
|
+
last: string;
|
|
33
|
+
};
|
|
34
|
+
meta: {
|
|
35
|
+
totalRecords: number;
|
|
36
|
+
totalPages: number;
|
|
37
|
+
requestDateTime: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Resposta de sucesso genérica simples
|
|
42
|
+
*/
|
|
43
|
+
export interface SimpleSuccessResponse<T> {
|
|
44
|
+
data: T;
|
|
45
|
+
links?: {
|
|
46
|
+
self: string;
|
|
47
|
+
};
|
|
48
|
+
meta?: {
|
|
49
|
+
requestDateTime: string;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=successResponses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"successResponses.d.ts","sourceRoot":"","sources":["../../src/utils/successResponses.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,IAAI,EAAE,CAAC,CAAC;IACR,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,wBAAwB,CAAC,CAAC;IACzC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,KAAK,CAAC,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;IACF,IAAI,EAAE;QACJ,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,IAAI,EAAE,CAAC,CAAC;IACR,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":"successResponses.js","sourceRoot":"","sources":["../../src/utils/successResponses.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validador de Headers de Requisição HTTP
|
|
3
|
+
* Valida headers enviados no request contra regras de Open Finance Brasil
|
|
4
|
+
*/
|
|
5
|
+
import { ErrorDetail } from "./openFinanceErrors";
|
|
6
|
+
interface HeaderValidationRule {
|
|
7
|
+
name: string;
|
|
8
|
+
headerName: string;
|
|
9
|
+
required: boolean;
|
|
10
|
+
pattern?: string;
|
|
11
|
+
minLength?: number;
|
|
12
|
+
maxLength?: number;
|
|
13
|
+
format?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Regras de validação para headers de Open Finance Brasil (SEM fapi-interaction-id obrigatório)
|
|
17
|
+
*/
|
|
18
|
+
declare const HEADER_VALIDATION_RULES: HeaderValidationRule[];
|
|
19
|
+
/**
|
|
20
|
+
* Regras de validação para headers de Open Finance Brasil (COM fapi-interaction-id obrigatório)
|
|
21
|
+
*/
|
|
22
|
+
declare const HEADER_VALIDATION_RULES_WITH_FAPIINTERACTION_ID: HeaderValidationRule[];
|
|
23
|
+
/**
|
|
24
|
+
* Valida todos os headers de uma requisição (SEM exigir fapi-interaction-id)
|
|
25
|
+
*/
|
|
26
|
+
export declare function validateHeaders(headers: Record<string, string | string[] | undefined>): {
|
|
27
|
+
isValid: boolean;
|
|
28
|
+
statusCode: number;
|
|
29
|
+
errors: ErrorDetail[];
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Valida todos os headers de uma requisição (COM fapi-interaction-id obrigatório)
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateHeadersWithFapiRequired(headers: Record<string, string | string[] | undefined>): {
|
|
35
|
+
isValid: boolean;
|
|
36
|
+
statusCode: number;
|
|
37
|
+
errors: ErrorDetail[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Valida um header específico
|
|
41
|
+
* @param headerName - Nome do header (ex: 'x-fapi-interaction-id')
|
|
42
|
+
* @param headerValue - Valor do header
|
|
43
|
+
* @param required - Se verdadeiro, força o header como obrigatório; se falso, força como opcional; se undefined, usa a regra padrão
|
|
44
|
+
*/
|
|
45
|
+
export declare function validateHeader(headerName: string, headerValue: any): {
|
|
46
|
+
isValid: boolean;
|
|
47
|
+
statusCode: number;
|
|
48
|
+
errors: ErrorDetail[];
|
|
49
|
+
};
|
|
50
|
+
export { HEADER_VALIDATION_RULES, HEADER_VALIDATION_RULES_WITH_FAPIINTERACTION_ID, HeaderValidationRule };
|
|
51
|
+
//# sourceMappingURL=validateHeaderParameters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateHeaderParameters.d.ts","sourceRoot":"","sources":["../../src/utils/validateHeaderParameters.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAgB,MAAM,qBAAqB,CAAC;AAGhE,UAAU,oBAAoB;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,uBAAuB,EAAE,oBAAoB,EA6ClD,CAAC;AAEF;;GAEG;AACH,QAAA,MAAM,+CAA+C,EAAE,oBAAoB,EA6C1E,CAAC;AA0DF;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GACrD;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CAcjE;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GACrD;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CAcjE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,GAAG,GACf;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CAoBjE;AAGD,OAAO,EAAE,uBAAuB,EAAE,+CAA+C,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Validador de Headers de Requisição HTTP
|
|
4
|
+
* Valida headers enviados no request contra regras de Open Finance Brasil
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.HEADER_VALIDATION_RULES_WITH_FAPIINTERACTION_ID = exports.HEADER_VALIDATION_RULES = void 0;
|
|
8
|
+
exports.validateHeaders = validateHeaders;
|
|
9
|
+
exports.validateHeadersWithFapiRequired = validateHeadersWithFapiRequired;
|
|
10
|
+
exports.validateHeader = validateHeader;
|
|
11
|
+
const openFinanceErrors_1 = require("./openFinanceErrors");
|
|
12
|
+
const openFinanceErrors_2 = require("./openFinanceErrors");
|
|
13
|
+
/**
|
|
14
|
+
* Regras de validação para headers de Open Finance Brasil (SEM fapi-interaction-id obrigatório)
|
|
15
|
+
*/
|
|
16
|
+
const HEADER_VALIDATION_RULES = [
|
|
17
|
+
{
|
|
18
|
+
name: 'xFapiInteractionId',
|
|
19
|
+
headerName: 'x-fapi-interaction-id',
|
|
20
|
+
required: false,
|
|
21
|
+
pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$',
|
|
22
|
+
minLength: 36,
|
|
23
|
+
maxLength: 36,
|
|
24
|
+
format: 'uuid',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'XIdempotencyKey',
|
|
28
|
+
headerName: 'X-Idempotency-Key',
|
|
29
|
+
required: false,
|
|
30
|
+
maxLength: 36,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: 'xFapiAuthDate',
|
|
34
|
+
headerName: 'x-fapi-auth-date',
|
|
35
|
+
required: false,
|
|
36
|
+
pattern: '^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4} \\d{2}:\\d{2}:\\d{2} (GMT|UTC)$',
|
|
37
|
+
minLength: 29,
|
|
38
|
+
maxLength: 29,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'xFapiCustomerIpAddress',
|
|
42
|
+
headerName: 'x-fapi-customer-ip-address',
|
|
43
|
+
required: false,
|
|
44
|
+
maxLength: 100,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'xCustomerUserAgent',
|
|
48
|
+
headerName: 'x-customer-user-agent',
|
|
49
|
+
required: false,
|
|
50
|
+
pattern: '^[^\\s](.*[^\\s])?$',
|
|
51
|
+
minLength: 1,
|
|
52
|
+
maxLength: 255,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: 'Authorization',
|
|
56
|
+
headerName: 'Authorization',
|
|
57
|
+
required: true,
|
|
58
|
+
minLength: 1,
|
|
59
|
+
maxLength: 2048,
|
|
60
|
+
},
|
|
61
|
+
];
|
|
62
|
+
exports.HEADER_VALIDATION_RULES = HEADER_VALIDATION_RULES;
|
|
63
|
+
/**
|
|
64
|
+
* Regras de validação para headers de Open Finance Brasil (COM fapi-interaction-id obrigatório)
|
|
65
|
+
*/
|
|
66
|
+
const HEADER_VALIDATION_RULES_WITH_FAPIINTERACTION_ID = [
|
|
67
|
+
{
|
|
68
|
+
name: 'xFapiInteractionId',
|
|
69
|
+
headerName: 'x-fapi-interaction-id',
|
|
70
|
+
required: true,
|
|
71
|
+
pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$',
|
|
72
|
+
minLength: 36,
|
|
73
|
+
maxLength: 36,
|
|
74
|
+
format: 'uuid',
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: 'XIdempotencyKey',
|
|
78
|
+
headerName: 'X-Idempotency-Key',
|
|
79
|
+
required: false,
|
|
80
|
+
maxLength: 36,
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'xFapiAuthDate',
|
|
84
|
+
headerName: 'x-fapi-auth-date',
|
|
85
|
+
required: false,
|
|
86
|
+
pattern: '^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), \\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4} \\d{2}:\\d{2}:\\d{2} (GMT|UTC)$',
|
|
87
|
+
minLength: 29,
|
|
88
|
+
maxLength: 29,
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'xFapiCustomerIpAddress',
|
|
92
|
+
headerName: 'x-fapi-customer-ip-address',
|
|
93
|
+
required: false,
|
|
94
|
+
maxLength: 100,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'xCustomerUserAgent',
|
|
98
|
+
headerName: 'x-customer-user-agent',
|
|
99
|
+
required: false,
|
|
100
|
+
pattern: '^[^\\s](.*[^\\s])?$',
|
|
101
|
+
minLength: 1,
|
|
102
|
+
maxLength: 255,
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'Authorization',
|
|
106
|
+
headerName: 'Authorization',
|
|
107
|
+
required: true,
|
|
108
|
+
minLength: 1,
|
|
109
|
+
maxLength: 2048,
|
|
110
|
+
},
|
|
111
|
+
];
|
|
112
|
+
exports.HEADER_VALIDATION_RULES_WITH_FAPIINTERACTION_ID = HEADER_VALIDATION_RULES_WITH_FAPIINTERACTION_ID;
|
|
113
|
+
/**
|
|
114
|
+
* Valida um header específico com opção de customizar obrigatoriedade
|
|
115
|
+
*/
|
|
116
|
+
function validateSingleHeader(headerValue, rule) {
|
|
117
|
+
const errors = [];
|
|
118
|
+
// Verificar se é obrigatório
|
|
119
|
+
if (rule.required && (!headerValue || String(headerValue).trim() === '')) {
|
|
120
|
+
return [
|
|
121
|
+
openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO(rule.headerName),
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
// Se não é obrigatório e não foi enviado, é válido
|
|
125
|
+
if (!headerValue || String(headerValue).trim() === '') {
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
128
|
+
const value = String(headerValue).trim();
|
|
129
|
+
// Validar tamanho mínimo
|
|
130
|
+
if (rule.minLength && value.length < rule.minLength) {
|
|
131
|
+
errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO(rule.headerName, `Deve ter no mínimo ${rule.minLength} caracteres (${value.length})`));
|
|
132
|
+
}
|
|
133
|
+
// Validar tamanho máximo
|
|
134
|
+
if (rule.maxLength && value.length > rule.maxLength) {
|
|
135
|
+
errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO(rule.headerName, `Deve ter no máximo ${rule.maxLength} caracteres (${value.length})`));
|
|
136
|
+
}
|
|
137
|
+
// Validar padrão (regex)
|
|
138
|
+
if (rule.pattern && !new RegExp(rule.pattern).test(value)) {
|
|
139
|
+
errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO(rule.headerName, `Formato inválido (esperado: ${rule.format || rule.pattern})`));
|
|
140
|
+
}
|
|
141
|
+
return errors;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Valida todos os headers de uma requisição (SEM exigir fapi-interaction-id)
|
|
145
|
+
*/
|
|
146
|
+
function validateHeaders(headers) {
|
|
147
|
+
const errors = [];
|
|
148
|
+
HEADER_VALIDATION_RULES.forEach((rule) => {
|
|
149
|
+
const headerValue = headers[rule.headerName];
|
|
150
|
+
const headerErrors = validateSingleHeader(headerValue, rule);
|
|
151
|
+
errors.push(...headerErrors);
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
isValid: errors.length === 0,
|
|
155
|
+
statusCode: (0, openFinanceErrors_2.getStatusCode)(errors),
|
|
156
|
+
errors,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Valida todos os headers de uma requisição (COM fapi-interaction-id obrigatório)
|
|
161
|
+
*/
|
|
162
|
+
function validateHeadersWithFapiRequired(headers) {
|
|
163
|
+
const errors = [];
|
|
164
|
+
HEADER_VALIDATION_RULES_WITH_FAPIINTERACTION_ID.forEach((rule) => {
|
|
165
|
+
const headerValue = headers[rule.headerName];
|
|
166
|
+
const headerErrors = validateSingleHeader(headerValue, rule);
|
|
167
|
+
errors.push(...headerErrors);
|
|
168
|
+
});
|
|
169
|
+
return {
|
|
170
|
+
isValid: errors.length === 0,
|
|
171
|
+
statusCode: (0, openFinanceErrors_2.getStatusCode)(errors),
|
|
172
|
+
errors,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Valida um header específico
|
|
177
|
+
* @param headerName - Nome do header (ex: 'x-fapi-interaction-id')
|
|
178
|
+
* @param headerValue - Valor do header
|
|
179
|
+
* @param required - Se verdadeiro, força o header como obrigatório; se falso, força como opcional; se undefined, usa a regra padrão
|
|
180
|
+
*/
|
|
181
|
+
function validateHeader(headerName, headerValue) {
|
|
182
|
+
const rule = HEADER_VALIDATION_RULES.find((r) => r.headerName.toLowerCase() === headerName.toLowerCase());
|
|
183
|
+
if (!rule) {
|
|
184
|
+
return {
|
|
185
|
+
isValid: true,
|
|
186
|
+
statusCode: 201,
|
|
187
|
+
errors: [],
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const errors = validateSingleHeader(headerValue, rule);
|
|
191
|
+
return {
|
|
192
|
+
isValid: errors.length === 0,
|
|
193
|
+
statusCode: (0, openFinanceErrors_2.getStatusCode)(errors),
|
|
194
|
+
errors,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=validateHeaderParameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateHeaderParameters.js","sourceRoot":"","sources":["../../src/utils/validateHeaderParameters.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA8KH,0CAgBC;AAKD,0EAgBC;AAQD,wCAuBC;AAhPD,2DAAgE;AAChE,2DAAoD;AAYpD;;GAEG;AACH,MAAM,uBAAuB,GAA2B;IACtD;QACE,IAAI,EAAE,oBAAoB;QAC1B,UAAU,EAAE,uBAAuB;QACnC,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,+EAA+E;QACxF,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;QACb,MAAM,EAAE,MAAM;KACf;IACD;QACE,IAAI,EAAE,iBAAiB;QACvB,UAAU,EAAE,mBAAmB;QAC/B,QAAQ,EAAE,KAAK;QACf,SAAS,EAAE,EAAE;KACd;IACD;QACE,IAAI,EAAE,eAAe;QACrB,UAAU,EAAE,kBAAkB;QAC9B,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,iIAAiI;QAC1I,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,EAAE;KACd;IACD;QACE,IAAI,EAAE,wBAAwB;QAC9B,UAAU,EAAE,4BAA4B;QACxC,QA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