sdk-node-apis-efi
Version:
Module for integration with Efi Bank API
441 lines (440 loc) • 15.2 kB
JavaScript
import * as z from "zod";
const UfSchema = z.enum([
'AC',
'AL',
'AP',
'AM',
'BA',
'CE',
'DF',
'ES',
'GO',
'MA',
'MT',
'MS',
'MG',
'PA',
'PB',
'PR',
'PE',
'PI',
'RJ',
'RN',
'RS',
'RO',
'RR',
'SC',
'SP',
'SE',
'TO',
]);
const NumberIdParamsSchema = z.object({ id: z.number().int() }).strict();
const ChargeEmailBodySchema = z.object({ email: z.string() }).strict();
const ChargeHistoryBodySchema = z.object({ description: z.string() }).strict();
export const ChargeItemSchema = z
.object({
name: z.string(),
value: z.number().int(),
amount: z.number().int(),
marketplace: z
.object({
mode: z.union([z.literal(1), z.literal(2)]).optional(),
payee_code: z.string().optional(),
percentage: z.number().optional(),
fixed: z.number().optional(),
repasses: z
.array(z
.object({
payee_code: z.string(),
percentage: z.number().optional(),
fixed: z.number().optional(),
})
.strict())
.optional(),
})
.strict()
.optional(),
})
.strict();
export const ChargeShippingSchema = z
.object({
name: z.string(),
value: z.number().int(),
payee_code: z.string().optional(),
})
.strict();
export const ChargeMetadataSchema = z
.object({
custom_id: z.string().optional(),
notification_url: z.string().optional(),
})
.strict();
export const ChargeAddressSchema = z
.object({
street: z.string(),
number: z.union([z.string(), z.number()]),
neighborhood: z.string(),
zipcode: z.string(),
city: z.string(),
complement: z.string().nullable().optional(),
state: UfSchema.or(z.string()),
})
.strict();
export const ChargeCustomerSchema = z
.object({
name: z.string().optional(),
cpf: z.string().optional(),
email: z.string().optional(),
phone_number: z.string().optional(),
birth: z.string().optional(),
address: ChargeAddressSchema.optional(),
juridical_person: z
.object({
corporate_name: z.string(),
cnpj: z.string(),
})
.strict()
.optional(),
})
.strict();
export const ChargeDiscountSchema = z
.object({
type: z.enum(['percentage', 'currency']),
value: z.number().int(),
})
.strict();
export const ChargeConditionalDiscountSchema = ChargeDiscountSchema.extend({
until_date: z.string(),
});
export const ChargeInterestSchema = z.union([
z.number().int(),
z
.object({
value: z.number().int(),
type: z.enum(['monthly', 'daily']),
})
.strict(),
]);
export const BankingBilletPaymentSchema = z
.object({
banking_billet: z
.object({
customer: ChargeCustomerSchema,
expire_at: z.string(),
discount: ChargeDiscountSchema.optional(),
conditional_discount: ChargeConditionalDiscountSchema.optional(),
configurations: z
.object({
days_to_write_off: z.number().int().optional(),
fine: z.number().int().optional(),
interest: ChargeInterestSchema.optional(),
})
.strict()
.optional(),
message: z.string().optional(),
})
.strict(),
})
.strict();
export const CreditCardPaymentSchema = z
.object({
credit_card: z
.object({
customer: ChargeCustomerSchema.extend({ email: z.string() }),
installments: z.number().int().optional(),
discount: ChargeDiscountSchema.optional(),
billing_address: ChargeAddressSchema.optional(),
payment_token: z.string(),
message: z.string().optional(),
trial_days: z.number().int().optional(),
})
.strict(),
})
.strict();
export const ChargePaymentSchema = z.union([
BankingBilletPaymentSchema.extend({ credit_card: z.never().optional() }).strict(),
CreditCardPaymentSchema.extend({ banking_billet: z.never().optional() }).strict(),
]);
export const CreateChargeBodySchema = z
.object({
items: z.array(ChargeItemSchema),
shippings: z.array(ChargeShippingSchema).optional(),
metadata: ChargeMetadataSchema.optional(),
})
.strict();
export const CreateOneStepChargeBodySchema = CreateChargeBodySchema.extend({
payment: ChargePaymentSchema,
}).strict();
export const DefinePayMethodParamsSchema = NumberIdParamsSchema;
export const DefinePayMethodBodySchema = z.object({ payment: ChargePaymentSchema }).strict();
export const DetailChargeParamsSchema = NumberIdParamsSchema;
export const ChargeListStatusSchema = z.enum([
'new',
'waiting',
'link',
'paid',
'unpaid',
'canceled',
'identified',
'settled',
'expired',
]);
export const ListChargesParamsSchema = z
.object({
charge_type: z.enum(['billet', 'carnet', 'subscription', 'card']),
begin_date: z.string(),
end_date: z.string(),
date_of: z.enum(['creation', 'payment', 'expired']).optional(),
status: ChargeListStatusSchema.optional(),
customer_document: z.string().optional(),
custom_id: z.string().optional(),
value: z.number().int().optional(),
limit: z.number().int().optional(),
page: z.number().int().optional(),
})
.strict();
export const UpdateChargeMetadataParamsSchema = NumberIdParamsSchema;
export const UpdateChargeMetadataBodySchema = ChargeMetadataSchema;
export const UpdateBilletParamsSchema = NumberIdParamsSchema;
export const UpdateBilletBodySchema = z.object({ expire_at: z.string() }).strict();
export const CancelChargeParamsSchema = NumberIdParamsSchema;
export const SendBilletEmailParamsSchema = NumberIdParamsSchema;
export const SendBilletEmailBodySchema = ChargeEmailBodySchema;
export const CreateChargeHistoryParamsSchema = NumberIdParamsSchema;
export const CreateChargeHistoryBodySchema = ChargeHistoryBodySchema;
export const DefineBalanceSheetBilletParamsSchema = NumberIdParamsSchema;
export const DefineBalanceSheetBilletBodySchema = z
.object({
title: z.string(),
body: z.record(z.string(), z.unknown()),
})
.strict();
export const SettleChargeParamsSchema = NumberIdParamsSchema;
export const CardPaymentRetryParamsSchema = NumberIdParamsSchema;
export const CardPaymentRetryBodySchema = DefinePayMethodBodySchema;
export const RefundCardParamsSchema = NumberIdParamsSchema;
export const RefundCardBodySchema = z.object({ amount: z.number().int().optional() }).strict();
export const GetInstallmentsParamsSchema = z
.object({
total: z.number().int(),
brand: z.enum(['visa', 'mastercard', 'amex', 'elo']).or(z.string()),
})
.strict();
export const CreateCarnetBodySchema = z
.object({
items: z.array(ChargeItemSchema),
customer: ChargeCustomerSchema,
expire_at: z.string(),
repeats: z.number().int(),
split_items: z.boolean().optional(),
configurations: z
.object({
fine: z.number().int().optional(),
interest: ChargeInterestSchema.optional(),
})
.strict()
.optional(),
discount: ChargeDiscountSchema.optional(),
conditional_discount: ChargeConditionalDiscountSchema.optional(),
message: z.string().optional(),
metadata: ChargeMetadataSchema.optional(),
})
.strict();
export const DetailCarnetParamsSchema = NumberIdParamsSchema;
export const UpdateCarnetMetadataParamsSchema = NumberIdParamsSchema;
export const UpdateCarnetMetadataBodySchema = ChargeMetadataSchema;
export const UpdateCarnetParcelParamsSchema = z.object({ id: z.number().int(), parcel: z.number().int() }).strict();
export const UpdateCarnetParcelBodySchema = z.object({ expire_at: z.string() }).strict();
export const UpdateCarnetParcelsParamsSchema = NumberIdParamsSchema;
export const UpdateCarnetParcelsBodySchema = z
.object({
parcels: z.array(z
.object({
parcel: z.number().int(),
expire_at: z.string(),
})
.strict()),
})
.strict();
export const CancelCarnetParamsSchema = NumberIdParamsSchema;
export const CancelCarnetParcelParamsSchema = UpdateCarnetParcelParamsSchema;
export const SendCarnetEmailParamsSchema = NumberIdParamsSchema;
export const SendCarnetEmailBodySchema = ChargeEmailBodySchema;
export const SendCarnetParcelEmailParamsSchema = UpdateCarnetParcelParamsSchema;
export const SendCarnetParcelEmailBodySchema = ChargeEmailBodySchema;
export const CreateCarnetHistoryParamsSchema = NumberIdParamsSchema;
export const CreateCarnetHistoryBodySchema = ChargeHistoryBodySchema;
export const SettleCarnetParamsSchema = NumberIdParamsSchema;
export const SettleCarnetParcelParamsSchema = UpdateCarnetParcelParamsSchema;
export const CreatePlanBodySchema = z
.object({
name: z.string(),
interval: z.number().int(),
repeats: z.number().int().nullable().optional(),
})
.strict();
export const ListPlansParamsSchema = z
.object({
name: z.string().optional(),
limit: z.number().int().optional(),
offset: z.number().int().optional(),
})
.strict();
export const UpdatePlanParamsSchema = NumberIdParamsSchema;
export const UpdatePlanBodySchema = z.object({ name: z.string() }).strict();
export const DeletePlanParamsSchema = NumberIdParamsSchema;
export const CreateSubscriptionParamsSchema = NumberIdParamsSchema;
export const CreateSubscriptionBodySchema = CreateChargeBodySchema;
export const CreateOneStepSubscriptionParamsSchema = NumberIdParamsSchema;
export const CreateOneStepSubscriptionBodySchema = CreateOneStepChargeBodySchema;
export const DefineSubscriptionPayMethodParamsSchema = NumberIdParamsSchema;
export const DefineSubscriptionPayMethodBodySchema = DefinePayMethodBodySchema;
export const DetailSubscriptionParamsSchema = NumberIdParamsSchema;
export const CreateOneStepSubscriptionLinkParamsSchema = NumberIdParamsSchema;
export const UpdateSubscriptionMetadataParamsSchema = NumberIdParamsSchema;
export const UpdateSubscriptionMetadataBodySchema = ChargeMetadataSchema;
export const UpdateSubscriptionParamsSchema = NumberIdParamsSchema;
export const UpdateSubscriptionBodySchema = z
.object({
plan_id: z.number().int().optional(),
customer: z
.object({
email: z.email().optional(),
phone_number: z.string().optional(),
})
.strict()
.optional(),
items: z.array(ChargeItemSchema).optional(),
shippings: z.array(ChargeShippingSchema).optional(),
payment_token: z.string().regex(/^[a-fA-F0-9]{40}$/).optional(),
})
.strict();
export const CancelSubscriptionParamsSchema = NumberIdParamsSchema;
export const CreateSubscriptionHistoryParamsSchema = NumberIdParamsSchema;
export const CreateSubscriptionHistoryBodySchema = ChargeHistoryBodySchema;
export const SendSubscriptionLinkEmailParamsSchema = NumberIdParamsSchema;
export const SendSubscriptionLinkEmailBodySchema = ChargeEmailBodySchema;
export const LinkSettingsSchema = z
.object({
billet_discount: z.number().int().optional(),
conditional_discount: ChargeConditionalDiscountSchema.optional(),
card_discount: z.number().int().optional(),
message: z.string().optional(),
expire_at: z.string().optional(),
request_delivery_address: z.boolean().optional(),
payment_method: z.enum(['banking_billet', 'credit_card', 'all']).optional(),
})
.strict();
export const CreateOneStepLinkBodySchema = CreateChargeBodySchema.extend({
settings: LinkSettingsSchema.optional(),
}).strict();
export const CreateOneStepSubscriptionLinkBodySchema = CreateOneStepLinkBodySchema;
export const DefineLinkPayMethodParamsSchema = NumberIdParamsSchema;
export const DefineLinkPayMethodBodySchema = LinkSettingsSchema;
export const UpdateChargeLinkParamsSchema = NumberIdParamsSchema;
export const UpdateChargeLinkBodySchema = LinkSettingsSchema;
export const SendLinkEmailParamsSchema = NumberIdParamsSchema;
export const SendLinkEmailBodySchema = ChargeEmailBodySchema;
export const GetNotificationParamsSchema = z.object({ token: z.string() }).strict();
const ChargeCardAddressSchema = z
.object({
street: z.string(),
number: z.string(),
neighborhood: z.string(),
zipcode: z.string().regex(/^\d{8}$/),
city: z.string(),
complement: z.string().nullable().optional(),
state: UfSchema,
})
.strict();
const ChargeCardRepasseSchema = z.union([
z
.object({
payee_code: z.string().regex(/^[a-fA-F0-9]{32}$/),
percentage: z.number().int().min(0).max(10000),
fixed: z.never().optional(),
})
.strict(),
z
.object({
payee_code: z.string().regex(/^[a-fA-F0-9]{32}$/),
fixed: z.number().int().nonnegative(),
percentage: z.never().optional(),
})
.strict(),
]);
const ChargeCardShippingSchema = z
.object({
name: z.string().max(255),
value: z.number().int().nonnegative(),
payee_code: z.string().regex(/^[a-fA-F0-9]{32}$/).optional(),
})
.strict();
export const ChargeCardItemSchema = z
.object({
name: z.string().min(1).max(255).regex(/^[^<>]+$/),
value: z.number().int().nonnegative(),
amount: z.number().int().positive().optional(),
marketplace: z
.object({
mode: z.union([z.literal(1), z.literal(2)]).optional(),
repasses: z.array(ChargeCardRepasseSchema).min(1),
})
.strict()
.optional(),
})
.strict();
const ChargeCardCustomerBaseSchema = z.object({
email: z.email().max(255),
phone_number: z.string().regex(/^[1-9]{2}9?[0-9]{8}$/),
birth: z.iso.date().optional(),
address: ChargeCardAddressSchema.optional(),
});
export const ChargeCardCustomerSchema = z.union([
ChargeCardCustomerBaseSchema.extend({
name: z
.string()
.min(1)
.max(255)
.regex(/^(?!.*[\u0600-\u06FF])[ ]*(.+[ ]+)+.+[ ]*$/),
cpf: z.string().regex(/^\d{11}$/),
juridical_person: z.never().optional(),
}).strict(),
ChargeCardCustomerBaseSchema.extend({
name: z.never().optional(),
cpf: z.never().optional(),
juridical_person: z
.object({
corporate_name: z.string().min(1).max(255),
cnpj: z.string().regex(/^\d{14}$/),
})
.strict(),
}).strict(),
]);
export const CreateChargeCardBodySchema = z
.object({
items: z.array(ChargeCardItemSchema).min(1),
shippings: z.array(ChargeCardShippingSchema).min(1).optional(),
customer: ChargeCardCustomerSchema,
installments: z.number().int().min(1).max(12).optional(),
billing_address: ChargeCardAddressSchema.optional(),
payment_token: z.string().regex(/^[a-fA-F0-9]{40}$/),
tds_info: z
.object({
tds_identifier: z.uuid(),
challenge_callback_url: z.url().regex(/^https?:\/\//),
})
.strict(),
discount: z
.object({
type: z.enum(['currency', 'percentage']),
value: z.number().int().positive(),
})
.strict()
.optional(),
message: z
.string()
.regex(/^[^\n]{0,100}(\n[^\n]{0,100}){0,3}$/)
.optional(),
})
.strict();