Files
DeskcommCRM/sentry.edge.config.ts
T
Rafael MelgaçoandClaude Opus 4.8 07eb106303 chore(oss): Sentry opt-in configurável + licença MIT + política de suporte/LGPD
Sentry (modelo comunidade com guardrails):
- DSN deixa de ser hardcoded; resolveSentryDsn() lê SENTRY_DSN em runtime
  (server/edge via process.env; browser via window.__PUBLIC_ENV__)
- default = Sentry da comunidade; SENTRY_DSN=off desliga; <dsn> aponta pro próprio
- opt-out vale no browser sem rebuild (via PublicEnvScript)
- beforeSend sanitizado (CPF/telefone/e-mail) mantido

Licença: adiciona LICENSE MIT (Copyright 2026 Rafael Melgaço).

README: política de suporte 'as-is', responsabilidades self-host, disclaimer
LGPD (quem hospeda é o controlador) e como ligar/desligar a telemetria.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UHfaYtmvsCjiKfdWDLsMdK
2026-07-06 21:10:55 -03:00

50 lines
1.3 KiB
TypeScript

// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from "@sentry/nextjs";
import { resolveSentryDsn } from "./lib/sentry/dsn";
const SENSITIVE_HEADERS = [
"authorization",
"cookie",
"x-api-key",
"x-waha-api-key",
"x-nuvemshop-token",
"x-deskcomm-token",
];
function scrubMessage(input: string): string {
return input
.replace(/\d{3}\.?\d{3}\.?\d{3}-?\d{2}/g, "[CPF]")
.replace(/\+?\d{2}\s?\d{4,5}-?\d{4}/g, "[PHONE]")
.replace(/[\w.+-]+@[\w-]+\.[\w.-]+/g, "[EMAIL]");
}
Sentry.init({
dsn: resolveSentryDsn(process.env.SENTRY_DSN),
tracesSampleRate: 1,
enableLogs: true,
sendDefaultPii: false,
beforeSend(event) {
if (event.request?.headers) {
const headers = event.request.headers as Record<string, string>;
for (const k of Object.keys(headers)) {
if (SENSITIVE_HEADERS.includes(k.toLowerCase())) {
delete headers[k];
}
}
}
if (typeof event.message === "string") {
event.message = scrubMessage(event.message);
}
if (event.exception?.values) {
for (const ex of event.exception.values) {
if (ex.value) ex.value = scrubMessage(ex.value);
}
}
return event;
},
});