1var j=(s,a,l)=>new Promise((c,r)=>{var f=i=>{try{u(l.next(i))}catch(b){r(b)}},p=i=>{try{u(l.throw(i))}catch(b){r(b)}},u=i=>i.done?c(i.value):Promise.resolve(i.value).then(f,p);u((l=l.apply(s,a)).next())});import{r as x,j as e,d as O}from"./vendor-BlJ90GWG.js";import{n as B,o as F,m as I,c3 as M,I as L,E as V,M as $,aD as Q,x as T,ab as K,ac as H,u as U,aj as Y,cX as y,B as P,ba as X,P as Z,L as G,T as J,_ as S,V as ee,cL as se,by as te,Z as ne}from"./index-BIHwndtW.js";import{A as ae}from"./ActionsDropdown-CEk78LeB.js";import{c as A}from"./crmKeys-Dih5WwA9.js";import{u as ie,W as oe,a as re}from"./WebhookFormModal-Cjw5UqGP.js";import{P as w}from"./charts-i6LaAsIH.js";import"./pdf-Ba4Lif-1.js";import"./extractErrorMessage-DjXdhE27.js";import"./Select-CGDbQs1i.js";import"./schemas-Zv2IiRs2.js";(function(){try{var s=typeof window!="undefined"?window:typeof global!="undefined"?global:typeof globalThis!="undefined"?globalThis:typeof self!="undefined"?self:{};s.SENTRY_RELEASE={id:"0d78e8d78eda4804299eff0767f9df5613e65c75"};var a=new s.Error().stack;a&&(s._sentryDebugIds=s._sentryDebugIds||{},s._sentryDebugIds[a]="41d3c5ca-24ee-4aae-a265-34ed61394cb1",s._sentryDebugIdIdentifier="sentry-dbid-41d3c5ca-24ee-4aae-a265-34ed61394cb1")}catch(l){}})();function ce({apiPrefix:s}){const{user:a}=B(),l=F(),{showWarningToast:c}=I(),[r,f]=x.useState(!1),p=x.useRef(new Set);return x.useEffect(()=>{if(!(a!=null&&a.tenant_id))return;const u=M();if(!u)return;const i=`tenant.${a.tenant_id}.crm`,b=n=>n?p.current.has(n)?!0:(p.current.add(n),p.current.size>200&&(p.current=new Set(Array.from(p.current).slice(-100))),!1):!1,o=n=>{var C,k;if(b(n==null?void 0:n.eventId))return;const _=(C=n==null?void 0:n.name)!=null?C:"sem nome",N=(k=n==null?void 0:n.consecutiveFailures)!=null?k:5;c({title:"Webhook desativado por falhas",message:`O webhook "${_}" foi desativado após ${N} falhas consecutivas. Verifique a URL e reative no painel.`}),l.invalidateQueries({queryKey:A.webhooks(s)}),n!=null&&n.webhookId&&l.invalidateQueries({queryKey:A.webhookDetail(s,n.webhookId)})},d=u.private(i);return d.listen(".crm.webhook.auto-disabled",o),f(!0),()=>{try{d.stopListening(".crm.webhook.auto-disabled"),u.leave(i)}catch(n){}f(!1)}},[s,l,a==null?void 0:a.tenant_id,c]),{isConnected:r}}function le(s,a={}){var u,i,b;const c=V(s==="/admins"?"admin":"employee"),r=(u=a.perPage)!=null?u:25,f=L({queryKey:A.webhooks(s),enabled:a.enabled!==!1,initialPageParam:null,queryFn:({pageParam:o,signal:d})=>c.get("/crm/webhooks",{params:{cursor:o!=null?o:void 0,per_page:r},signal:d}).then(n=>n.data),getNextPageParam:o=>{var d,n;return(n=(d=o==null?void 0:o.meta)==null?void 0:d.next_cursor)!=null?n:null},staleTime:3e4}),p=((b=(i=f.data)==null?void 0:i.pages)!=null?b:[]).flatMap(o=>{var d;return(d=o==null?void 0:o.data)!=null?d:[]});return Object.assign(f,{rawWebhooks:p})}const ue="_body_o4oa4_1",de="_warning_o4oa4_9",me="_warningIcon_o4oa4_21",he="_subtitle_o4oa4_28",fe="_secretBox_o4oa4_33",pe="_secretValue_o4oa4_43",be="_hint_o4oa4_52",ge="_actions_o4oa4_66",v={body:ue,warning:de,warningIcon:me,subtitle:he,secretBox:fe,secretValue:pe,hint:be,actions:ge};function D({isOpen:s,secret:a,webhookName:l,onClose:c}){const[r,f]=x.useState(!1),p=()=>j(null,null,function*(){try{yield navigator.clipboard.writeText(a),f(!0),setTimeout(()=>f(!1),2500)}catch(u){}});return e.jsx($,{isOpen:s,onClose:c,title:"Webhook criado",size:"md",closeOnOverlayClick:!1,showCloseButton:!1,children:e.jsxs("div",{className:v.body,children:[e.jsxs("div",{className:v.warning,role:"alert",children:[e.jsx(Q,{className:v.warningIcon,size:20,"aria-hidden":!0}),e.jsxs("span",{children:["Esta é a ",e.jsx("strong",{children:"única vez"})," que você verá o secret deste webhook. Copie agora e guarde em local seguro â não será possÃvel recuperar depois."]})]}),l&&e.jsxs("p",{className:v.subtitle,children:["Webhook: ",e.jsx("strong",{children:l})]}),e.jsxs("div",{className:v.secretBox,children:[e.jsx("code",{className:v.secretValue,children:a}),e.jsx(T,{type:"button",variant:r?"success":"primary",size:"sm",icon:r?e.jsx(K,{size:14}):e.jsx(H,{size:14}),onClick:p,children:r?"Copiado!":"Copiar"})]}),e.jsxs("p",{className:v.hint,children:["O secret é usado para verificar a assinatura HMAC (header"," ",e.jsx("code",{children:"X-WiseData-Signature"}),") das requisições recebidas no destino."]}),e.jsx("div",{className:v.actions,children:e.jsx(T,{type:"button",variant:"primary",onClick:c,children:"Já copiei, fechar"})})]})})}D.propTypes={isOpen:w.bool.isRequired,secret:w.string.isRequired,webhookName:w.string,onClose:w.func.isRequired};const ye={active:{variant:"success",label:"Ativo"},inactive:{variant:"secondary",label:"Inativo"},autoDisabled:{variant:"warning",label:"Auto-desabilitado"}};function R(s){return s!=null&&s.autoDisabledAt?"autoDisabled":s!=null&&s.isActive?"active":"inactive"}function Pe(){const s=U(),a=Y(),l=O(),c=le(s),r=ie(s);
1ce({apiPrefix:s});const f=m=>l(`${a}/crm/config/webhooks/${m}`),[p,u]=x.useState(!1),[i,b]=x.useState(null),[o,d]=x.useState(null),[n,_]=x.useState(null),N=c.rawWebhooks,C=m=>j(null,null,function*(){var g;const t=yield r.create.mutateAsync(m);u(!1);const h=(g=t==null?void 0:t.data)!=null?g:t;h!=null&&h.secret&&_({secret:h.secret,name:h.name})}),k=()=>j(null,null,function*(){if(i)try{yield r.destroy.mutateAsync(i.id),b(null)}catch(m){b(null)}}),W=()=>j(null,null,function*(){if(o)try{yield r.reactivate.mutateAsync(o.id),d(null)}catch(m){d(null)}}),q=m=>j(null,null,function*(){try{yield r.test.mutateAsync(m.id)}catch(t){}}),z=x.useMemo(()=>[{key:"name",title:"Nome",render:(m,t)=>e.jsx("button",{type:"button",className:y.linkButton,onClick:()=>f(t.id),children:t.name})},{key:"url",title:"URL",render:(m,t)=>e.jsx("span",{className:y.urlCell,title:t.url,children:t.url})},{key:"entityType",title:"Tipo",width:"120px",render:(m,t)=>e.jsx(P,{variant:"secondary",size:"sm",children:oe[t.entityType]||t.entityType})},{key:"events",title:"Eventos",width:"90px",render:(m,t)=>{var g,E;const h=((g=t.events)!=null?g:[]).length;return e.jsx("span",{title:((E=t.events)!=null?E:[]).join(", "),children:h})}},{key:"status",title:"Status",width:"160px",render:(m,t)=>{const h=R(t),g=ye[h];return e.jsx(P,{variant:g.variant,size:"sm",children:g.label})}},{key:"lastSuccessAt",title:"Ãltima entrega",width:"140px",render:(m,t)=>{const h=t.lastSuccessAt||t.lastFailureAt;return h?X(h):"â"}},{key:"actions",title:"Ações",width:"80px",align:"right",render:(m,t)=>{const h=R(t),g=[{icon:e.jsx(ee,{size:14}),label:"Editar",onClick:()=>f(t.id)},{icon:e.jsx(se,{size:14}),label:"Enviar teste",onClick:()=>q(t)}];return h==="autoDisabled"&&g.push({icon:e.jsx(te,{size:14}),label:"Reativar",onClick:()=>d(t)}),g.push({icon:e.jsx(ne,{size:14}),label:"Excluir",danger:!0,onClick:()=>b(t)}),e.jsx(ae,{actions:g,size:"sm"})}}],[a]);return e.jsxs("div",{className:y.container,children:[e.jsx(Z,{title:"Webhooks"}),e.jsxs("div",{className:y.header,children:[e.jsxs("div",{className:y.titleContainer,children:[e.jsx("h1",{className:y.title,children:"Webhooks"}),e.jsx("p",{className:y.subtitle,children:"Receba notificações em tempo real (HTTP POST com HMAC) quando contatos, empresas ou negociações mudarem. Plugue Zapier, n8n, Make ou seu próprio sistema."})]}),e.jsx("div",{className:y.headerActions,children:e.jsx(T,{variant:"primary",icon:e.jsx(G,{size:16}),onClick:()=>u(!0),children:"Novo webhook"})})]}),e.jsx(J,{columns:z,data:N,loading:c.isPending,emptyMessage:"Nenhum webhook configurado. Clique em 'Novo webhook' para começar.",loadingMessage:"Carregando webhooks..."}),c.hasNextPage?e.jsx("div",{className:y.loadMoreWrap,children:e.jsx(T,{type:"button",variant:"outline",onClick:()=>c.fetchNextPage(),isLoading:c.isFetchingNextPage,disabled:c.isFetchingNextPage,children:"Carregar mais"})}):null,e.jsx(re,{isOpen:p,onClose:()=>u(!1),onSubmit:C,mode:"create",isSubmitting:r.create.isPending}),n&&e.jsx(D,{isOpen:!0,secret:n.secret,webhookName:n.name,onClose:()=>_(null)}),e.jsx(S,{isOpen:i!==null,onClose:()=>b(null),onConfirm:k,type:"error",title:"Excluir webhook?",message:i?`Tem certeza que deseja excluir "${i.name}"? Esta ação não pode ser desfeita e o destino deixará de receber eventos imediatamente.`:"",confirmText:"Excluir",cancelText:"Cancelar",confirmButtonVariant:"danger",isProcessing:r.destroy.isPending}),e.jsx(S,{isOpen:o!==null,onClose:()=>d(null),onConfirm:W,type:"warning",title:"Reativar webhook?",message:o?`O webhook "${o.name}" voltará a receber eventos. Verifique se a URL de destino está funcionando â caso contrário, ele será desativado novamente após 5 falhas consecutivas.`:"",confirmText:"Reativar",cancelText:"Cancelar",confirmButtonVariant:"primary",isProcessing:r.reactivate.isPending})]})}export{Pe as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.