UNPKG

sdk-node-apis-efi

Version:

Module for integration with Efi Bank API

282 lines (281 loc) 8.39 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.PayListWebhookResponseSchema = exports.PayConfigWebhookResponseSchema = exports.PayListPaymentsResponseSchema = exports.PayDetailPaymentResponseSchema = exports.PayRequestBarCodeResponseSchema = exports.PayDetailBarCodeResponseSchema = exports.PayDeleteWebhookBodySchema = exports.PayListWebhookParamsSchema = exports.PayWebhookBodySchema = exports.PayListPaymentsParamsSchema = exports.PayDetailPaymentParamsSchema = exports.PayRequestBarCodeBodySchema = exports.PayRequestBarCodeParamsSchema = exports.PayDetailBarCodeParamsSchema = void 0; const z = __importStar(require("zod")); const DateSchema = z.iso.date(); const DateTimeSchema = z.iso.datetime({ offset: true }); const PaymentStatusSchema = z.enum([ 'EM_PROCESSAMENTO', 'AGENDADO', 'REALIZADO', 'LIQUIDADO', 'CANCELADO', 'NAO_REALIZADO', ]); exports.PayDetailBarCodeParamsSchema = z .object({ codBarras: z.string().regex(/^\d{44,48}$/) }) .strict(); exports.PayRequestBarCodeParamsSchema = exports.PayDetailBarCodeParamsSchema; exports.PayRequestBarCodeBodySchema = z .object({ valor: z.number().int().positive(), dataPagamento: DateSchema, descricao: z.string().optional(), }) .strict(); exports.PayDetailPaymentParamsSchema = z.object({ idPagamento: z.string() }).strict(); exports.PayListPaymentsParamsSchema = z .object({ dataInicio: DateSchema, dataFim: DateSchema, }) .strict(); exports.PayWebhookBodySchema = z.object({ url: z.url() }).strict(); exports.PayListWebhookParamsSchema = z .object({ dataInicio: DateTimeSchema, dataFim: DateTimeSchema, }) .strict(); exports.PayDeleteWebhookBodySchema = exports.PayWebhookBodySchema; const PayPartySchema = z .object({ nome: z.string(), documento: z.string(), }) .loose(); const PayBilletValuesSchema = z .object({ original: z.number(), abatimento: z.number(), multa: z.number(), juros: z.number(), desconto: z.number(), final: z.number(), }) .loose(); const PayInformationSchema = z .object({ divergente: z .object({ deveAceitar: z.boolean(), valorMinimo: z.number(), valorMaximo: z.number(), }) .loose(), parcial: z .object({ deveAceitar: z.boolean(), limiteDePagamentos: z.number().int(), }) .loose(), podeSerPago: z.boolean(), }) .loose(); const PayDetailBilletResponseSchema = z .object({ tipo: z.literal('boleto'), banco: z .object({ codigo: z.number().int(), nome: z.string(), }) .loose(), codBarras: z.string(), linhaDigitavel: z.string(), datas: z .object({ vencimento: z.string(), limitePagamento: z.string(), }) .loose(), beneficiario: PayPartySchema.extend({ fantasia: z.string() }).loose(), pagador: PayPartySchema, valores: PayBilletValuesSchema, informacoesPagamento: PayInformationSchema, }) .loose(); const PayDetailTaxResponseSchema = z .object({ tipo: z.literal('tributo'), banco: z.null(), codBarras: z.string(), linhaDigitavel: z.string(), datas: z .object({ vencimento: z.string(), limitePagamento: z.null(), }) .loose(), beneficiario: z.null(), pagador: z.null(), sacadorAvalista: PayPartySchema.nullable(), valores: z .object({ original: z.number(), abatimento: z.number().nullable(), pago: z.number().nullable(), final: z.number(), }) .loose(), informacoesPagamento: z.null(), }) .loose(); exports.PayDetailBarCodeResponseSchema = z.discriminatedUnion('tipo', [ PayDetailBilletResponseSchema, PayDetailTaxResponseSchema, ]); const PayRequestDateResponseSchema = z .object({ solicitacao: z.string(), pagamento: z.string(), }) .loose(); exports.PayRequestBarCodeResponseSchema = z .object({ idPagamento: z.string(), valorPago: z.number().int(), status: PaymentStatusSchema, data: PayRequestDateResponseSchema, }) .loose(); const PayLiquidatedPaymentResponseSchema = z .object({ idPagamento: z.string(), valorPago: z.number().int(), status: z.literal('LIQUIDADO'), motivoRecusa: z.string().nullable(), data: z .object({ solicitacao: z.string(), pagamento: z.string(), }) .loose(), }) .loose(); const PayFailedPaymentResponseSchema = z .object({ idPagamento: z.string(), codBarras: z.string(), linhaDigitavel: z.string(), valorPago: z.number().int(), status: z.literal('NAO_REALIZADO'), retornoBancario: z.string(), protocolo: z.string().nullable(), descricao: z.string(), horario: z .object({ solicitacao: z.string(), }) .loose(), }) .loose(); const PayPendingPaymentResponseSchema = z .object({ idPagamento: z.string(), status: z.enum(['EM_PROCESSAMENTO', 'AGENDADO', 'REALIZADO', 'CANCELADO']), codBarras: z.string().optional(), linhaDigitavel: z.string().optional(), valorPago: z.number().int().optional(), motivoRecusa: z.string().nullable().optional(), retornoBancario: z.string().nullable().optional(), protocolo: z.string().nullable().optional(), descricao: z.string().optional(), data: z .object({ solicitacao: z.string(), pagamento: z.string().nullable().optional(), }) .loose() .optional(), horario: z .object({ solicitacao: z.string(), }) .loose() .optional(), }) .loose(); exports.PayDetailPaymentResponseSchema = z.discriminatedUnion('status', [ PayLiquidatedPaymentResponseSchema, PayFailedPaymentResponseSchema, PayPendingPaymentResponseSchema, ]); exports.PayListPaymentsResponseSchema = z .object({ datas: z .object({ inicial: DateSchema, final: DateSchema, }) .loose(), solicitacoes: z .object({ total: z.number().int(), processando: z.number().int(), sucesso: z.number().int(), falha: z.number().int(), cancelada: z.number().int(), }) .loose(), solicitacoesFalhas: z.array(z.number().int()), }) .loose(); exports.PayConfigWebhookResponseSchema = z.object({ url: z.string() }).loose(); exports.PayListWebhookResponseSchema = z .object({ parametros: z .object({ inicio: z.string(), fim: z.string(), paginacao: z .object({ paginaAtual: z.number().int(), itensPorPagina: z.number().int(), quantidadeDePaginas: z.number().int(), quantidadeTotalDeItens: z.number().int(), }) .loose(), }) .loose(), webhooks: z.array(z .object({ url: z.string(), criacao: z.string(), }) .loose()), }) .loose();