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.
Files changed (94) hide show
  1. package/README.md +557 -0
  2. package/dist/consent/index.d.ts +9 -0
  3. package/dist/consent/index.d.ts.map +1 -0
  4. package/dist/consent/index.js +12 -0
  5. package/dist/consent/index.js.map +1 -0
  6. package/dist/consent/package.json +6 -0
  7. package/dist/consent/successResponses/index.d.ts +89 -0
  8. package/dist/consent/successResponses/index.d.ts.map +1 -0
  9. package/dist/consent/successResponses/index.js +6 -0
  10. package/dist/consent/successResponses/index.js.map +1 -0
  11. package/dist/consent/validators/createConsent.d.ts +33 -0
  12. package/dist/consent/validators/createConsent.d.ts.map +1 -0
  13. package/dist/consent/validators/createConsent.js +206 -0
  14. package/dist/consent/validators/createConsent.js.map +1 -0
  15. package/dist/consent/validators/createConsentExtensions.d.ts +33 -0
  16. package/dist/consent/validators/createConsentExtensions.d.ts.map +1 -0
  17. package/dist/consent/validators/createConsentExtensions.js +194 -0
  18. package/dist/consent/validators/createConsentExtensions.js.map +1 -0
  19. package/dist/index.d.ts +7 -0
  20. package/dist/index.d.ts.map +1 -0
  21. package/dist/index.js +54 -0
  22. package/dist/index.js.map +7 -0
  23. package/dist/payments/index.d.ts +11 -0
  24. package/dist/payments/index.d.ts.map +1 -0
  25. package/dist/payments/index.js +18 -0
  26. package/dist/payments/index.js.map +1 -0
  27. package/dist/payments/package.json +6 -0
  28. package/dist/payments/successResponses/index.d.ts +129 -0
  29. package/dist/payments/successResponses/index.d.ts.map +1 -0
  30. package/dist/payments/successResponses/index.js +6 -0
  31. package/dist/payments/successResponses/index.js.map +1 -0
  32. package/dist/payments/validators/createPaymentConsent.d.ts +66 -0
  33. package/dist/payments/validators/createPaymentConsent.d.ts.map +1 -0
  34. package/dist/payments/validators/createPaymentConsent.js +509 -0
  35. package/dist/payments/validators/createPaymentConsent.js.map +1 -0
  36. package/dist/payments/validators/createPixPayment.d.ts +35 -0
  37. package/dist/payments/validators/createPixPayment.d.ts.map +1 -0
  38. package/dist/payments/validators/createPixPayment.js +343 -0
  39. package/dist/payments/validators/createPixPayment.js.map +1 -0
  40. package/dist/payments/validators/patchPixPayment.d.ts +40 -0
  41. package/dist/payments/validators/patchPixPayment.d.ts.map +1 -0
  42. package/dist/payments/validators/patchPixPayment.js +192 -0
  43. package/dist/payments/validators/patchPixPayment.js.map +1 -0
  44. package/dist/recurring-payments/index.d.ts +13 -0
  45. package/dist/recurring-payments/index.d.ts.map +1 -0
  46. package/dist/recurring-payments/index.js +17 -0
  47. package/dist/recurring-payments/index.js.map +1 -0
  48. package/dist/recurring-payments/package.json +6 -0
  49. package/dist/recurring-payments/successResponses/index.d.ts +175 -0
  50. package/dist/recurring-payments/successResponses/index.d.ts.map +1 -0
  51. package/dist/recurring-payments/successResponses/index.js +6 -0
  52. package/dist/recurring-payments/successResponses/index.js.map +1 -0
  53. package/dist/recurring-payments/validators/createRecurringConsent.d.ts +96 -0
  54. package/dist/recurring-payments/validators/createRecurringConsent.d.ts.map +1 -0
  55. package/dist/recurring-payments/validators/createRecurringConsent.js +664 -0
  56. package/dist/recurring-payments/validators/createRecurringConsent.js.map +1 -0
  57. package/dist/recurring-payments/validators/createRecurringRetryPixPayment.d.ts +19 -0
  58. package/dist/recurring-payments/validators/createRecurringRetryPixPayment.d.ts.map +1 -0
  59. package/dist/recurring-payments/validators/createRecurringRetryPixPayment.js +42 -0
  60. package/dist/recurring-payments/validators/createRecurringRetryPixPayment.js.map +1 -0
  61. package/dist/recurring-payments/validators/patchPixPayment.d.ts +38 -0
  62. package/dist/recurring-payments/validators/patchPixPayment.d.ts.map +1 -0
  63. package/dist/recurring-payments/validators/patchPixPayment.js +124 -0
  64. package/dist/recurring-payments/validators/patchPixPayment.js.map +1 -0
  65. package/dist/recurring-payments/validators/patchRecurringConsent.d.ts +87 -0
  66. package/dist/recurring-payments/validators/patchRecurringConsent.d.ts.map +1 -0
  67. package/dist/recurring-payments/validators/patchRecurringConsent.js +558 -0
  68. package/dist/recurring-payments/validators/patchRecurringConsent.js.map +1 -0
  69. package/dist/utils/index.d.ts +9 -0
  70. package/dist/utils/index.d.ts.map +1 -0
  71. package/dist/utils/index.js +25 -0
  72. package/dist/utils/index.js.map +1 -0
  73. package/dist/utils/openFinanceErrors.d.ts +90 -0
  74. package/dist/utils/openFinanceErrors.d.ts.map +1 -0
  75. package/dist/utils/openFinanceErrors.js +114 -0
  76. package/dist/utils/openFinanceErrors.js.map +1 -0
  77. package/dist/utils/package.json +6 -0
  78. package/dist/utils/paymentErrors.d.ts +9 -0
  79. package/dist/utils/paymentErrors.d.ts.map +1 -0
  80. package/dist/utils/paymentErrors.js +13 -0
  81. package/dist/utils/paymentErrors.js.map +1 -0
  82. package/dist/utils/successResponses.d.ts +52 -0
  83. package/dist/utils/successResponses.d.ts.map +1 -0
  84. package/dist/utils/successResponses.js +6 -0
  85. package/dist/utils/successResponses.js.map +1 -0
  86. package/dist/utils/validateHeaderParameters.d.ts +51 -0
  87. package/dist/utils/validateHeaderParameters.d.ts.map +1 -0
  88. package/dist/utils/validateHeaderParameters.js +197 -0
  89. package/dist/utils/validateHeaderParameters.js.map +1 -0
  90. package/dist/utils/validationHelpers.d.ts +89 -0
  91. package/dist/utils/validationHelpers.d.ts.map +1 -0
  92. package/dist/utils/validationHelpers.js +374 -0
  93. package/dist/utils/validationHelpers.js.map +1 -0
  94. package/package.json +30 -0
@@ -0,0 +1,664 @@
1
+ "use strict";
2
+ /**
3
+ * Validações para CreateRecurringConsent
4
+ * Segue as regras especificadas no Open Finance Brasil - API de Pagamentos Automáticos
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.validateCreateRecurringConsent = validateCreateRecurringConsent;
8
+ const openFinanceErrors_1 = require("../../utils/openFinanceErrors");
9
+ /**
10
+ * Tipos de documento válidos
11
+ */
12
+ const VALID_DOCUMENT_TYPES = ["CPF", "CNPJ"];
13
+ /**
14
+ * Tipos de conta válidos para consentimentos
15
+ */
16
+ const VALID_ACCOUNT_TYPES = ["CACC", "SVGS", "TRAN"];
17
+ /**
18
+ * Intervalos válidos para Pix Automático
19
+ */
20
+ const VALID_INTERVALS = ["SEMANAL", "MENSAL", "ANUAL", "SEMESTRAL", "TRIMESTRAL"];
21
+ /**
22
+ * Tipos de pessoa válidos
23
+ */
24
+ const VALID_PERSON_TYPES = ["PESSOA_NATURAL", "PESSOA_JURIDICA"];
25
+ /**
26
+ * Valida o payload de criação de consentimento de pagamento recorrente
27
+ */
28
+ function validateCreateRecurringConsent(payload) {
29
+ const errors = [];
30
+ // Validação: data deve existir
31
+ if (!payload.data) {
32
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("data"));
33
+ return { isValid: false, statusCode: (0, openFinanceErrors_1.getStatusCode)(errors), errors };
34
+ }
35
+ const data = payload.data;
36
+ // Validação: loggedUser é obrigatório
37
+ if (!data.loggedUser) {
38
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("loggedUser"));
39
+ }
40
+ else {
41
+ const loggedUserErrors = validateLoggedUser(data.loggedUser);
42
+ errors.push(...loggedUserErrors);
43
+ }
44
+ // Validação: businessEntity (opcional, mas se presente deve ser válida)
45
+ if (data.businessEntity) {
46
+ const businessEntityErrors = validateBusinessEntity(data.businessEntity);
47
+ errors.push(...businessEntityErrors);
48
+ }
49
+ // Validação: creditors é obrigatório
50
+ if (!data.creditors) {
51
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("creditors"));
52
+ }
53
+ else {
54
+ const creditorsErrors = validateCreditors(data.creditors);
55
+ errors.push(...creditorsErrors);
56
+ }
57
+ // Validação: recurringConfiguration é obrigatório
58
+ if (!data.recurringConfiguration) {
59
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("recurringConfiguration"));
60
+ }
61
+ else {
62
+ const recurringConfigErrors = validateRecurringConfiguration(data.recurringConfiguration);
63
+ errors.push(...recurringConfigErrors);
64
+ }
65
+ // Validação: expirationDateTime (opcional)
66
+ if (data.expirationDateTime) {
67
+ const expirationErrors = validateExpirationDateTime(data.expirationDateTime, data.recurringConfiguration);
68
+ errors.push(...expirationErrors);
69
+ }
70
+ // Validação: additionalInformation (opcional)
71
+ if (data.additionalInformation) {
72
+ const additionalInfoErrors = validateAdditionalInformation(data.additionalInformation);
73
+ errors.push(...additionalInfoErrors);
74
+ }
75
+ // Validação: debtorAccount (opcional)
76
+ if (data.debtorAccount) {
77
+ const debtorAccountErrors = validateDebtorAccount(data.debtorAccount);
78
+ errors.push(...debtorAccountErrors);
79
+ }
80
+ // Validação: journey (opcional)
81
+ if (data.journey) {
82
+ const journeyErrors = validateJourney(data.journey);
83
+ errors.push(...journeyErrors);
84
+ }
85
+ return {
86
+ isValid: errors.length === 0,
87
+ statusCode: (0, openFinanceErrors_1.getStatusCode)(errors),
88
+ errors,
89
+ };
90
+ }
91
+ /**
92
+ * Valida LoggedUser
93
+ */
94
+ function validateLoggedUser(loggedUser) {
95
+ const errors = [];
96
+ if (typeof loggedUser !== "object" || loggedUser === null) {
97
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("loggedUser", "Deve ser um objeto"));
98
+ return errors;
99
+ }
100
+ if (!loggedUser.document) {
101
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("loggedUser.document"));
102
+ }
103
+ else {
104
+ const documentErrors = validateLoggedUserDocument(loggedUser.document);
105
+ errors.push(...documentErrors);
106
+ }
107
+ return errors;
108
+ }
109
+ /**
110
+ * Valida documento do LoggedUser
111
+ */
112
+ function validateLoggedUserDocument(document) {
113
+ const errors = [];
114
+ if (typeof document !== "object" || document === null) {
115
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("loggedUser.document", "Deve ser um objeto"));
116
+ return errors;
117
+ }
118
+ // identification é obrigatório
119
+ if (!document.identification) {
120
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("loggedUser.document.identification"));
121
+ }
122
+ else if (typeof document.identification !== "string") {
123
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("loggedUser.document.identification", "Deve ser uma string"));
124
+ }
125
+ else if (document.identification.length > 11) {
126
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("loggedUser.document.identification", "CPF deve ter no máximo 11 dígitos"));
127
+ }
128
+ else if (!/^\d{11}$/.test(document.identification)) {
129
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("loggedUser.document.identification", "CPF deve conter apenas dígitos"));
130
+ }
131
+ // rel é obrigatório
132
+ if (!document.rel) {
133
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("loggedUser.document.rel"));
134
+ }
135
+ else if (document.rel !== "CPF") {
136
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("loggedUser.document.rel", "Deve ser 'CPF' para usuário logado"));
137
+ }
138
+ return errors;
139
+ }
140
+ /**
141
+ * Valida BusinessEntity
142
+ */
143
+ function validateBusinessEntity(businessEntity) {
144
+ const errors = [];
145
+ if (typeof businessEntity !== "object" || businessEntity === null) {
146
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("businessEntity", "Deve ser um objeto"));
147
+ return errors;
148
+ }
149
+ if (!businessEntity.document) {
150
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("businessEntity.document"));
151
+ }
152
+ else {
153
+ const documentErrors = validateBusinessEntityDocument(businessEntity.document);
154
+ errors.push(...documentErrors);
155
+ }
156
+ return errors;
157
+ }
158
+ /**
159
+ * Valida documento de BusinessEntity
160
+ */
161
+ function validateBusinessEntityDocument(document) {
162
+ const errors = [];
163
+ if (typeof document !== "object" || document === null) {
164
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("businessEntity.document", "Deve ser um objeto"));
165
+ return errors;
166
+ }
167
+ // identification é obrigatório
168
+ if (!document.identification) {
169
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("businessEntity.document.identification"));
170
+ }
171
+ else if (typeof document.identification !== "string") {
172
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("businessEntity.document.identification", "Deve ser uma string"));
173
+ }
174
+ else if (!/^[0-9A-Z]{12}[0-9]{2}$/.test(document.identification)) {
175
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("businessEntity.document.identification", "CNPJ deve ter 14 caracteres no formato esperado"));
176
+ }
177
+ // rel é obrigatório
178
+ if (!document.rel) {
179
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("businessEntity.document.rel"));
180
+ }
181
+ else if (document.rel !== "CNPJ") {
182
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("businessEntity.document.rel", "Deve ser 'CNPJ' para entidade de negócio"));
183
+ }
184
+ return errors;
185
+ }
186
+ /**
187
+ * Valida array de creditors (recebedores)
188
+ */
189
+ function validateCreditors(creditors) {
190
+ const errors = [];
191
+ if (!Array.isArray(creditors)) {
192
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("creditors", "Deve ser um array"));
193
+ return errors;
194
+ }
195
+ if (creditors.length === 0) {
196
+ errors.push((0, openFinanceErrors_1.createError)("PARAMETRO_INVALIDO", "Parâmetro inválido.", "Array de creditors deve conter pelo menos um item"));
197
+ return errors;
198
+ }
199
+ creditors.forEach((creditor, index) => {
200
+ const creditorErrors = validateCreditor(creditor);
201
+ creditorErrors.forEach((error) => {
202
+ errors.push({
203
+ ...error,
204
+ detail: `creditors[${index}]: ${error.detail}`,
205
+ });
206
+ });
207
+ });
208
+ return errors;
209
+ }
210
+ /**
211
+ * Valida um creditor individual
212
+ */
213
+ function validateCreditor(creditor) {
214
+ const errors = [];
215
+ if (typeof creditor !== "object" || creditor === null) {
216
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("creditor", "Deve ser um objeto"));
217
+ return errors;
218
+ }
219
+ // personType é obrigatório
220
+ if (!creditor.personType) {
221
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("personType"));
222
+ }
223
+ else if (!VALID_PERSON_TYPES.includes(creditor.personType)) {
224
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("personType", `Deve ser um dos: ${VALID_PERSON_TYPES.join(", ")}`));
225
+ }
226
+ // cpfCnpj é obrigatório
227
+ if (!creditor.cpfCnpj) {
228
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("cpfCnpj"));
229
+ }
230
+ else if (typeof creditor.cpfCnpj !== "string") {
231
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("cpfCnpj", "Deve ser uma string"));
232
+ }
233
+ else {
234
+ // Validar formato de CPF ou CNPJ
235
+ const isCpf = /^\d{11}$/.test(creditor.cpfCnpj);
236
+ const isCnpj = /^[0-9A-Z]{12}[0-9]{2}$/.test(creditor.cpfCnpj);
237
+ if (!isCpf && !isCnpj) {
238
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("cpfCnpj", "Deve ser um CPF (11 dígitos) ou CNPJ (14 caracteres)"));
239
+ }
240
+ }
241
+ // name é obrigatório
242
+ if (!creditor.name) {
243
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("name"));
244
+ }
245
+ else if (typeof creditor.name !== "string") {
246
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("name", "Deve ser uma string"));
247
+ }
248
+ else if (creditor.name.length > 120) {
249
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("name", "Deve ter no máximo 120 caracteres"));
250
+ }
251
+ return errors;
252
+ }
253
+ /**
254
+ * Valida recurringConfiguration
255
+ */
256
+ function validateRecurringConfiguration(config) {
257
+ const errors = [];
258
+ if (typeof config !== "object" || config === null) {
259
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("recurringConfiguration", "Deve ser um objeto"));
260
+ return errors;
261
+ }
262
+ // Validar que apenas um dos tipos está presente
263
+ const hasAutomatic = !!config.automatic;
264
+ const hasSweeping = !!config.sweeping;
265
+ const hasVrp = !!config.vrp;
266
+ const configCount = [hasAutomatic, hasSweeping, hasVrp].filter(Boolean).length;
267
+ if (configCount !== 1) {
268
+ errors.push((0, openFinanceErrors_1.createError)("PARAMETRO_INVALIDO", "Parâmetro inválido.", "recurringConfiguration deve conter exatamente um dos: automatic, sweeping ou vrp"));
269
+ return errors;
270
+ }
271
+ if (hasAutomatic) {
272
+ const automaticErrors = validateAutomaticConfig(config.automatic);
273
+ errors.push(...automaticErrors);
274
+ }
275
+ if (hasSweeping) {
276
+ const sweepingErrors = validateSweepingConfig(config.sweeping);
277
+ errors.push(...sweepingErrors);
278
+ }
279
+ if (hasVrp) {
280
+ const vrpErrors = validateVrpConfig(config.vrp);
281
+ errors.push(...vrpErrors);
282
+ }
283
+ return errors;
284
+ }
285
+ /**
286
+ * Valida configuração de Pix Automático
287
+ */
288
+ function validateAutomaticConfig(automatic) {
289
+ const errors = [];
290
+ if (typeof automatic !== "object" || automatic === null) {
291
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("automatic", "Deve ser um objeto"));
292
+ return errors;
293
+ }
294
+ // contractId é obrigatório
295
+ if (!automatic.contractId) {
296
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("recurringConfiguration.automatic.contractId"));
297
+ }
298
+ else if (typeof automatic.contractId !== "string") {
299
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("contractId", "Deve ser uma string"));
300
+ }
301
+ else if (!/^[a-zA-Z0-9]{1,35}$/.test(automatic.contractId)) {
302
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("contractId", "Deve conter de 1 a 35 caracteres alfanuméricos"));
303
+ }
304
+ // interval é obrigatório
305
+ if (!automatic.interval) {
306
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("recurringConfiguration.automatic.interval"));
307
+ }
308
+ else if (!VALID_INTERVALS.includes(automatic.interval)) {
309
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("interval", `Deve ser um dos: ${VALID_INTERVALS.join(", ")}`));
310
+ }
311
+ // contractDebtor é obrigatório
312
+ if (!automatic.contractDebtor) {
313
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("recurringConfiguration.automatic.contractDebtor"));
314
+ }
315
+ else {
316
+ const debtorErrors = validateContractDebtor(automatic.contractDebtor);
317
+ errors.push(...debtorErrors);
318
+ }
319
+ // isRetryAccepted é obrigatório
320
+ if (automatic.isRetryAccepted === undefined) {
321
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("recurringConfiguration.automatic.isRetryAccepted"));
322
+ }
323
+ else if (typeof automatic.isRetryAccepted !== "boolean") {
324
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("isRetryAccepted", "Deve ser um valor booleano"));
325
+ }
326
+ // referenceStartDate é obrigatório
327
+ if (!automatic.referenceStartDate) {
328
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("recurringConfiguration.automatic.referenceStartDate"));
329
+ }
330
+ else {
331
+ const dateErrors = validateReferenceStartDate(automatic.referenceStartDate);
332
+ errors.push(...dateErrors);
333
+ }
334
+ // fixedAmount e maximumVariableAmount são excludentes
335
+ if (automatic.fixedAmount && automatic.maximumVariableAmount) {
336
+ errors.push((0, openFinanceErrors_1.createError)("PARAMETRO_INVALIDO", "Parâmetro inválido.", "fixedAmount e maximumVariableAmount são excludentes"));
337
+ }
338
+ // Validar fixedAmount se presente
339
+ if (automatic.fixedAmount) {
340
+ const fixedAmountErrors = validateAmount(automatic.fixedAmount, "fixedAmount");
341
+ errors.push(...fixedAmountErrors);
342
+ }
343
+ // Validar maximumVariableAmount se presente
344
+ if (automatic.maximumVariableAmount) {
345
+ const maxAmountErrors = validateAmount(automatic.maximumVariableAmount, "maximumVariableAmount");
346
+ errors.push(...maxAmountErrors);
347
+ // Se maximumVariableAmount está presente, minimumVariableAmount não pode excedê-lo
348
+ if (automatic.minimumVariableAmount) {
349
+ const minAmountErrors = validateAmount(automatic.minimumVariableAmount, "minimumVariableAmount");
350
+ errors.push(...minAmountErrors);
351
+ // Comparar valores
352
+ const maxValue = parseFloat(automatic.maximumVariableAmount);
353
+ const minValue = parseFloat(automatic.minimumVariableAmount);
354
+ if (minValue > maxValue) {
355
+ errors.push((0, openFinanceErrors_1.createError)("DETALHE_PAGAMENTO_INVALIDO", "Detalhe do pagamento inválido.", "minimumVariableAmount não pode ser maior que maximumVariableAmount"));
356
+ }
357
+ }
358
+ }
359
+ // Validar firstPayment se presente
360
+ if (automatic.firstPayment) {
361
+ const firstPaymentErrors = validateFirstPayment(automatic.firstPayment);
362
+ errors.push(...firstPaymentErrors);
363
+ }
364
+ return errors;
365
+ }
366
+ /**
367
+ * Valida ContractDebtor
368
+ */
369
+ function validateContractDebtor(debtor) {
370
+ const errors = [];
371
+ if (typeof debtor !== "object" || debtor === null) {
372
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("contractDebtor", "Deve ser um objeto"));
373
+ return errors;
374
+ }
375
+ // name é obrigatório
376
+ if (!debtor.name) {
377
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("recurringConfiguration.automatic.contractDebtor.name"));
378
+ }
379
+ else if (typeof debtor.name !== "string") {
380
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("name", "Deve ser uma string"));
381
+ }
382
+ else if (debtor.name.length > 120) {
383
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("name", "Deve ter no máximo 120 caracteres"));
384
+ }
385
+ // document é obrigatório
386
+ if (!debtor.document) {
387
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("recurringConfiguration.automatic.contractDebtor.document"));
388
+ }
389
+ else {
390
+ const docErrors = validateContractDebtorDocument(debtor.document);
391
+ errors.push(...docErrors);
392
+ }
393
+ return errors;
394
+ }
395
+ /**
396
+ * Valida documento do ContractDebtor
397
+ */
398
+ function validateContractDebtorDocument(document) {
399
+ const errors = [];
400
+ if (typeof document !== "object" || document === null) {
401
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("document", "Deve ser um objeto"));
402
+ return errors;
403
+ }
404
+ // identification é obrigatório
405
+ if (!document.identification) {
406
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("document.identification"));
407
+ }
408
+ else if (!/^(\d{11})|([0-9A-Z]{12}\d{2})$/.test(document.identification)) {
409
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("document.identification", "Deve ser um CPF (11 dígitos) ou CNPJ (14 caracteres)"));
410
+ }
411
+ // rel é obrigatório
412
+ if (!document.rel) {
413
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("document.rel"));
414
+ }
415
+ else if (!["CPF", "CNPJ"].includes(document.rel)) {
416
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("document.rel", "Deve ser 'CPF' ou 'CNPJ'"));
417
+ }
418
+ return errors;
419
+ }
420
+ /**
421
+ * Valida data de início da recorrência
422
+ */
423
+ function validateReferenceStartDate(date) {
424
+ const errors = [];
425
+ if (typeof date !== "string") {
426
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("referenceStartDate", "Deve ser uma string"));
427
+ return errors;
428
+ }
429
+ const datePattern = /^(\d{4})-(1[0-2]|0?[1-9])-(3[01]|[12][0-9]|0?[1-9])$/;
430
+ if (!datePattern.test(date)) {
431
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("referenceStartDate", "Deve estar no formato YYYY-MM-DD"));
432
+ }
433
+ return errors;
434
+ }
435
+ /**
436
+ * Valida valor monetário
437
+ */
438
+ function validateAmount(amount, fieldName) {
439
+ const errors = [];
440
+ if (typeof amount !== "string") {
441
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO(fieldName, "Deve ser uma string"));
442
+ return errors;
443
+ }
444
+ const amountPattern = /^(\d{1,16}\.\d{2})$/;
445
+ if (!amountPattern.test(amount)) {
446
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO(fieldName, "Deve ser um valor monetário no formato 0000000.00"));
447
+ }
448
+ return errors;
449
+ }
450
+ /**
451
+ * Valida FirstPayment
452
+ */
453
+ function validateFirstPayment(payment) {
454
+ const errors = [];
455
+ if (typeof payment !== "object" || payment === null) {
456
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("firstPayment", "Deve ser um objeto"));
457
+ return errors;
458
+ }
459
+ // type é obrigatório
460
+ if (!payment.type) {
461
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("firstPayment.type"));
462
+ }
463
+ else if (payment.type !== "PIX") {
464
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("type", "Deve ser 'PIX'"));
465
+ }
466
+ // date é obrigatório
467
+ if (!payment.date) {
468
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("firstPayment.date"));
469
+ }
470
+ else {
471
+ const dateErrors = validateReferenceStartDate(payment.date);
472
+ errors.push(...dateErrors);
473
+ }
474
+ // currency é obrigatório
475
+ if (!payment.currency) {
476
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("firstPayment.currency"));
477
+ }
478
+ else if (payment.currency !== "BRL") {
479
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("currency", "Deve ser 'BRL' (Real Brasileiro)"));
480
+ }
481
+ // amount é obrigatório
482
+ if (!payment.amount) {
483
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("firstPayment.amount"));
484
+ }
485
+ else {
486
+ const amountErrors = validateAmount(payment.amount, "amount");
487
+ errors.push(...amountErrors);
488
+ }
489
+ // creditorAccount é obrigatório
490
+ if (!payment.creditorAccount) {
491
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("firstPayment.creditorAccount"));
492
+ }
493
+ else {
494
+ const creditorAccountErrors = validateCreditorAccount(payment.creditorAccount);
495
+ errors.push(...creditorAccountErrors);
496
+ }
497
+ return errors;
498
+ }
499
+ /**
500
+ * Valida conta de crédito
501
+ */
502
+ function validateCreditorAccount(account) {
503
+ const errors = [];
504
+ if (typeof account !== "object" || account === null) {
505
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("creditorAccount", "Deve ser um objeto"));
506
+ return errors;
507
+ }
508
+ // ispb é obrigatório
509
+ if (!account.ispb) {
510
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("creditorAccount.ispb"));
511
+ }
512
+ else if (!/^[0-9A-Z]{8}$/.test(account.ispb)) {
513
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("ispb", "Deve ter exatamente 8 caracteres alfanuméricos"));
514
+ }
515
+ // number é obrigatório
516
+ if (!account.number) {
517
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("creditorAccount.number"));
518
+ }
519
+ else if (!/^\d{1,20}$/.test(account.number)) {
520
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("number", "Deve ter de 1 a 20 dígitos"));
521
+ }
522
+ // accountType é obrigatório
523
+ if (!account.accountType) {
524
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("creditorAccount.accountType"));
525
+ }
526
+ else if (!VALID_ACCOUNT_TYPES.includes(account.accountType)) {
527
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("accountType", `Deve ser um dos: ${VALID_ACCOUNT_TYPES.join(", ")}`));
528
+ }
529
+ // issuer é opcional, mas se presente deve ser válido
530
+ if (account.issuer && !/^\d{1,4}$/.test(account.issuer)) {
531
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("issuer", "Deve ter de 1 a 4 dígitos"));
532
+ }
533
+ return errors;
534
+ }
535
+ /**
536
+ * Valida DebtorAccount (opcional)
537
+ */
538
+ function validateDebtorAccount(account) {
539
+ const errors = [];
540
+ if (typeof account !== "object" || account === null) {
541
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("debtorAccount", "Deve ser um objeto"));
542
+ return errors;
543
+ }
544
+ // ispb é obrigatório
545
+ if (!account.ispb) {
546
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("debtorAccount.ispb"));
547
+ }
548
+ else if (!/^[0-9A-Z]{8}$/.test(account.ispb)) {
549
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("ispb", "Deve ter exatamente 8 caracteres alfanuméricos"));
550
+ }
551
+ // number é obrigatório
552
+ if (!account.number) {
553
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("debtorAccount.number"));
554
+ }
555
+ else if (!/^\d{1,20}$/.test(account.number)) {
556
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("number", "Deve ter de 1 a 20 dígitos"));
557
+ }
558
+ // accountType é obrigatório
559
+ if (!account.accountType) {
560
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("debtorAccount.accountType"));
561
+ }
562
+ else if (!VALID_ACCOUNT_TYPES.includes(account.accountType)) {
563
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("accountType", `Deve ser um dos: ${VALID_ACCOUNT_TYPES.join(", ")}`));
564
+ }
565
+ // issuer é opcional, mas se presente deve ser válido
566
+ if (account.issuer && !/^\d{1,4}$/.test(account.issuer)) {
567
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("issuer", "Deve ter de 1 a 4 dígitos"));
568
+ }
569
+ return errors;
570
+ }
571
+ /**
572
+ * Valida expirationDateTime
573
+ * [Restrição] Caso o consentimento seja para Pix Automático, o horário de expiração do consentimento precisa ser às 23:59:59 (UTC).
574
+ */
575
+ function validateExpirationDateTime(expirationDateTime, recurringConfiguration) {
576
+ const errors = [];
577
+ if (typeof expirationDateTime !== "string") {
578
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("expirationDateTime", "Deve ser uma string"));
579
+ return errors;
580
+ }
581
+ const rfc3339Pattern = /^(\d{4})-(1[0-2]|0?[1-9])-(3[01]|[12][0-9]|0?[1-9])T(?:[01]\d|2[0123]):(?:[012345]\d):(?:[012345]\d)Z$/;
582
+ if (!rfc3339Pattern.test(expirationDateTime)) {
583
+ errors.push((0, openFinanceErrors_1.createError)("PARAMETRO_INVALIDO", "Parâmetro inválido.", "expirationDateTime deve estar no formato RFC-3339 com timezone UTC (YYYY-MM-DDTHH:mm:ssZ)"));
584
+ return errors;
585
+ }
586
+ // Validar que é Pix Automático
587
+ if (recurringConfiguration?.automatic) {
588
+ // Extrair hora do expirationDateTime
589
+ const hourMatch = expirationDateTime.match(/T(\d{2}):(\d{2}):(\d{2})Z$/);
590
+ if (hourMatch) {
591
+ const hour = hourMatch[1];
592
+ const minute = hourMatch[2];
593
+ const second = hourMatch[3];
594
+ if (hour !== "23" || minute !== "59" || second !== "59") {
595
+ errors.push((0, openFinanceErrors_1.createError)("DATA_EXPIRACAO_INVALIDA", "Nova data para expiração do consentimento é inválida.", "Para Pix Automático, o horário de expiração deve ser às 23:59:59 (UTC)"));
596
+ }
597
+ }
598
+ }
599
+ return errors;
600
+ }
601
+ /**
602
+ * Valida additionalInformation
603
+ */
604
+ function validateAdditionalInformation(info) {
605
+ const errors = [];
606
+ if (typeof info !== "string") {
607
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("additionalInformation", "Deve ser uma string"));
608
+ }
609
+ else if (info.length > 140) {
610
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("additionalInformation", "Deve ter no máximo 140 caracteres"));
611
+ }
612
+ return errors;
613
+ }
614
+ /**
615
+ * Valida Journey
616
+ */
617
+ function validateJourney(journey) {
618
+ const errors = [];
619
+ if (typeof journey !== "object" || journey === null) {
620
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("journey", "Deve ser um objeto"));
621
+ return errors;
622
+ }
623
+ // isLinked é obrigatório
624
+ if (journey.isLinked === undefined) {
625
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("journey.isLinked"));
626
+ }
627
+ else if (typeof journey.isLinked !== "boolean") {
628
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("isLinked", "Deve ser um valor booleano"));
629
+ }
630
+ // linkId é obrigatório
631
+ if (!journey.linkId) {
632
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_NAO_INFORMADO("journey.linkId"));
633
+ }
634
+ else if (typeof journey.linkId !== "string") {
635
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("linkId", "Deve ser uma string"));
636
+ }
637
+ else if (journey.linkId.length > 256) {
638
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("linkId", "Deve ter no máximo 256 caracteres"));
639
+ }
640
+ return errors;
641
+ }
642
+ /**
643
+ * Valida configuração de Sweeping (Transferências Inteligentes)
644
+ */
645
+ function validateSweepingConfig(sweeping) {
646
+ const errors = [];
647
+ // Por enquanto, apenas validar estrutura básica
648
+ if (typeof sweeping !== "object" || sweeping === null) {
649
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("sweeping", "Deve ser um objeto"));
650
+ }
651
+ return errors;
652
+ }
653
+ /**
654
+ * Valida configuração de VRP
655
+ */
656
+ function validateVrpConfig(vrp) {
657
+ const errors = [];
658
+ // Por enquanto, apenas validar estrutura básica
659
+ if (typeof vrp !== "object" || vrp === null) {
660
+ errors.push(openFinanceErrors_1.CommonErrors.PARAMETRO_INVALIDO("vrp", "Deve ser um objeto"));
661
+ }
662
+ return errors;
663
+ }
664
+ //# sourceMappingURL=createRecurringConsent.js.map