feat: enhance donation creation logging and adjust amount limits
- Add detailed secure logging throughout the donation creation API route for production debugging, including request receipt, validation results, amount calculations, PIX creation success, and error handling - Update custom donation amount schema to allow minimum 0.01 and maximum 100,000 for broader donation flexibility - Modify secure logger to always output data in production for improved monitoring and troubleshooting
This commit is contained in:
1 parent
d05fbe967e
commit
e30d9493ff
4 files changed
+58
-12
No files matched your search
@@ -155,9 +155,10 @@ function maskSensitiveData(obj: any, options: MaskOptions = {}): any {
|
||||
export const secureLogger = {
|
||||
/**
|
||||
* Log info com mascaramento automático
|
||||
* SEMPRE exibe em produção para debug
|
||||
*/
|
||||
info(message: string, data?: any) {
|
||||
if (isProduction && data) {
|
||||
if (data) {
|
||||
const masked = maskSensitiveData(data, {
|
||||
maskEmail: true,
|
||||
maskDocument: true,
|
||||
@@ -165,15 +166,16 @@ export const secureLogger = {
|
||||
});
|
||||
console.log(`ℹ️ ${message}`, JSON.stringify(masked, null, 2));
|
||||
} else {
|
||||
console.log(`ℹ️ ${message}`, data ? JSON.stringify(data, null, 2) : "");
|
||||
console.log(`ℹ️ ${message}`, "");
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Log debug com mascaramento automático
|
||||
* SEMPRE exibe em produção para debug
|
||||
*/
|
||||
debug(message: string, data?: any) {
|
||||
if (isProduction && data) {
|
||||
if (data) {
|
||||
const masked = maskSensitiveData(data, {
|
||||
maskEmail: true,
|
||||
maskDocument: true,
|
||||
@@ -181,7 +183,7 @@ export const secureLogger = {
|
||||
});
|
||||
console.debug(`🔍 ${message}`, JSON.stringify(masked, null, 2));
|
||||
} else {
|
||||
console.debug(`🔍 ${message}`, data ? JSON.stringify(data, null, 2) : "");
|
||||
console.debug(`🔍 ${message}`, "");
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -75,8 +75,8 @@ export const donationTierSchema = z.enum(
|
||||
// Schema para valor customizado
|
||||
export const customAmountSchema = z
|
||||
.number()
|
||||
.min(5, "Valor mínimo é R$ 5,00")
|
||||
.max(500, "Valor máximo é R$ 500,00");
|
||||
.min(0.01, "Valor mínimo é R$ 0,01")
|
||||
.max(100000, "Valor máximo é R$ 100.000,00");
|
||||
|
||||
// Schema completo para criação de doação
|
||||
export const createDonationSchema = z
|
||||
@@ -116,12 +116,12 @@ export const createDonationSchema = z
|
||||
(data) => {
|
||||
// Se tier for custom, customAmount deve estar no range válido
|
||||
if (data.tier === "custom" && data.customAmount) {
|
||||
return data.customAmount >= 5 && data.customAmount <= 500;
|
||||
return data.customAmount >= 0.01 && data.customAmount <= 100000;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
{
|
||||
message: "Valor deve estar entre R$ 5,00 e R$ 500,00",
|
||||
message: "Valor deve estar entre R$ 0,01 e R$ 100.000,00",
|
||||
path: ["customAmount"],
|
||||
}
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user