feat: customers buy with a CPF or a CNPJ
All checks were successful
Build and deploy / Validate source (push) Successful in 1m38s
Build and deploy / Integration suite on a real stack (push) Successful in 4m57s
Build and deploy / Secret scan and release gate (push) Successful in 13s
Build and deploy / Publish images (push) Successful in 2m1s

The cart and the account signup take either document, each with its own
mask and check digits. Tiny gets a person (F) for a CPF, Mercado Pago the
matching identification type, and only CNPJs go to the company registry.
The Kanban, the account page and the alerts show which one it is.

Also pins the Correios test's clock: its fake token expired today, so the
suite failed from Oct 16 on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-16 13:33:50 -03:00
parent 37246917b9
commit b83e60ef0c
23 changed files with 138 additions and 46 deletions

View File

@@ -97,20 +97,32 @@ let pedido=[]; // itens já fechados · o pagamento
let entrega={tipo:'retira', cep:'', valor:0, cotado:true, end:{}, servico:'', opcoes:[]};
let cliente={cnpj:'', zap:'', mail:''};
// CNPJ com os dois dígitos verificadores · máscara sem conta não vale nada
function cnpjOk(v){
// CPF (11 dígitos) ou CNPJ (14), com os dois dígitos verificadores · máscara
// sem conta não vale nada. A chave cliente.cnpj guarda qualquer um dos dois.
function docOk(v){
const d=(v||'').replace(/\D/g,'');
if(d.length!==14 || /^(\d)\1{13}$/.test(d)) return false;
if((d.length!==11 && d.length!==14) || /^(\d)\1+$/.test(d)) return false;
const calc=(base,pesos)=>{
const soma=base.split('').reduce((t,n,i)=>t+ +n*pesos[i],0);
const r=soma%11; return r<2? 0 : 11-r;
};
if(d.length===11){
const p1=[10,9,8,7,6,5,4,3,2], p2=[11,...p1];
return calc(d.slice(0,9),p1)===+d[9] && calc(d.slice(0,10),p2)===+d[10];
}
const p1=[5,4,3,2,9,8,7,6,5,4,3,2], p2=[6,...p1];
return calc(d.slice(0,12),p1)===+d[12] && calc(d.slice(0,13),p2)===+d[13];
}
// 000.000.000-00 até 11 dígitos; passando disso, 00.000.000/0000-00.
function fmtDoc(v){
const d=(v||'').replace(/\D/g,'').slice(0,14);
if(d.length<=11) return d.replace(/^(\d{3})(\d)/,'$1.$2').replace(/^(\d{3})\.(\d{3})(\d)/,'$1.$2.$3')
.replace(/^(\d{3})\.(\d{3})\.(\d{3})(\d)/,'$1.$2.$3-$4');
return d.replace(/^(\d{2})(\d{3})(\d{3})(\d{4})(\d{0,2})/,'$1.$2.$3/$4-$5');
}
const zapOk=v=>{ const d=(v||'').replace(/\D/g,''); return d.length===10||d.length===11; };
const mailOk=v=>/^[^\s@]+@[^\s@]+\.[a-z]{2,}$/i.test((v||'').trim());
const clienteOk=()=>cnpjOk(cliente.cnpj)&&zapOk(cliente.zap)&&mailOk(cliente.mail);
const clienteOk=()=>docOk(cliente.cnpj)&&zapOk(cliente.zap)&&mailOk(cliente.mail);
// Frete cotado pelo CEP não entrega nada sozinho: a transportadora e o Tiny
// precisam do endereço completo antes do pagamento.
const UFS='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'.split(' ');