PageSourceSearch

https://lojadosanimais.com.br/assets/Versoes-DYCpe4v8.js

js lojadosanimais.com.br collected 2026-10-06 04:47:34 UTC 10,979 bytes, 1 lines download raw bytes

1import{r,j as e,B as i,cG as ie,T as $,Q as ce,cH as de,l as b,C as P,d as me,o as xe,az as p,aG as q,e as Q,ca as ue,D as R,f as T,g as H,h as A,i as X,L as E,I as L,af as he,bw as Y,s as f,ag as u,ba as Z}from"./index-BArGZurd.js";import{T as K,a as W,b as _,c as C}from"./tabs-zNzwwP9_.js";const pe=d=>{const m=d.match(/^v(\d+)\.(\d+)\.(\d+)$/);return m?`v${m[1]}.${m[2]}.${Number(m[3])+1}`:"v1.0.31"};function je(){const[d,m]=r.useState([]),[w,ee]=r.useState([]),[se,O]=r.useState({}),[ae,B]=r.useState(!0),[te,g]=r.useState(!1),[t,j]=r.useState(null),[o,V]=r.useState(null),[z,F]=r.useState(!1),[v,M]=r.useState(!1),[n,N]=r.useState({version:"",notes:"",git_sha:""}),[G,y]=r.useState(""),k=async()=>{B(!0);const[{data:s},{data:a}]=await Promise.all([f.from("app_versions").select("*").order("created_at",{ascending:!1}),f.from("app_version_rollback_log").select("*").order("created_at",{ascending:!1}).limit(50)]),c=s??[];m(c),ee(a??[]);const x=Array.from(new Set(c.map(h=>h.created_by).filter(Boolean)));if(x.length){const{data:h}=await f.from("profiles").select("user_id, name, email").in("user_id",x),J={};(h??[]).forEach(D=>{J[D.user_id]=D.name||D.email||""}),O(J)}else O({});B(!1)};r.useEffect(()=>{k()},[]);const I=d.find(s=>s.is_current),re=()=>{N({version:I?pe(I.version):"v1.0.31",notes:"",git_sha:""}),g(!0)},ne=async()=>{if(!n.version.match(/^v\d+\.\d+\.\d+$/)){u({title:"Versão inválida",description:"Use o formato vX.Y.Z",variant:"destructive"});return}F(!0);const{data:s,error:a}=await f.functions.invoke("version-create",{body:{version:n.version,notes:n.notes,git_sha:n.git_sha||null}});if(F(!1),a||s!=null&&s.error){u({title:"Erro ao criar versão",description:(a==null?void 0:a.message)||(s==null?void 0:s.error),variant:"destructive"});return}u({title:"Versão criada",description:`${n.version} salva com snapshot completo.`}),g(!1),k()},[l,S]=r.useState(null),U=async s=>{if(!t)return;if(G!==t.version){u({title:"Confirmação incorreta",description:`Digite exatamente "${t.version}"`,variant:"destructive"});return}M(!0);const{data:a,error:c}=await f.functions.invoke("version-rollback",{body:{target_version:t.version,confirm:t.version,force:s}});M(!1);const x=a==null?void 0:a.error,h=a==null?void 0:a.message;if(x==="schema_drift_detected"){S((a==null?void 0:a.drift)??null);return}if(c||x){u({title:"Erro no rollback",description:h||(c==null?void 0:c.message)||x,variant:"destructive"});return}u({title:"Rollback concluído",description:`Snapshot de segurança: ${a==null?void 0:a.safety_snapshot}`}),j(null),y(""),S(null),k()},oe=()=>U(!1),le=()=>U(!0);return e.jsxs("div",{className:"p-4 lg:p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-bold",children:"Versões do Sistema"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Snapshots de schema e configuração para rollback controlado."})]}),e.jsxs(i,{onClick:re,className:"gap-2",children:[e.jsx(ie,{className:"h-4 w-4"})," Criar nova versão"]})]}),e.jsxs("div",{className:"rounded-lg border border-amber-500/40 bg-amber-500/5 p-4 flex gap-3",children:[e.jsx($,{className:"h-5 w-5 text-amber-600 shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-medium",children:"Aviso importante"}),e.jsxs("p",{className:"text-muted-foreground",children:["Rollback restaura os ",e.jsx("strong",{children:"dados de configuração"})," (settings, layout, zonas, etc.) da versão escolhida. Alterações estruturais do banco (colunas/tabelas novas) permanecem — apenas os dados de config são substituídos. Um ",e.jsx("strong",{children:"snapshot de segurança"})," é criado automaticamente antes de cada rollback."]})]})]}),e.jsxs(K,{defaultValue:"versions",children:[e.jsxs(W,{children:[e.jsxs(_,{value:"versions",className:"gap-2",children:[e.jsx(ce,{className:"h-4 w-4"})," Versões (",d.length,")"]}),e.jsxs(_,{value:"logs",className:"gap-2",children:[e.jsx(de,{className:"h-4 w-4"})," Log de rollbacks (",w.length,")"]})]}),e.jsx(C,{value:"versions",className:"space-y-3 mt-4",children:ae?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(b,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):d.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:"Nenhuma versão registrada."}):d.map(s=>e.jsxs(P,{children:[e.jsx(me,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs(xe,{className:"text-lg flex items-center gap-2",children:[e.jsx("span",{className:"font-mono",children:s.version}),s.is_current&&e.jsx(p,{children:"Atual"}),s.is_safety_snapshot&&e.jsx(p,{variant:"secondary",className:"bg-amber-500/15 text-amber-700 border-amber-500/30",children:"Segurança"}),e.jsx(p,{variant:"outline",className:"text-xs",children:s.snapshot_status})]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:q(ne
1w Date(s.released_at),"dd/MM/yyyy HH:mm",{locale:Z})})]})}),e.jsxs(Q,{className:"space-y-3",children:[s.notes&&e.jsx("p",{className:"text-sm text-muted-foreground",children:s.notes}),s.git_sha&&e.jsxs("div",{className:"text-xs font-mono text-muted-foreground",children:["Git: ",s.git_sha]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Criada por: ",s.created_by?se[s.created_by]||"Usuário removido":"—"]}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx(i,{variant:"outline",size:"sm",onClick:()=>V(s),children:"Ver snapshot"}),!s.is_current&&s.snapshot_status==="ready"&&s.schema_snapshot&&s.config_snapshot&&e.jsxs(i,{variant:"destructive",size:"sm",onClick:()=>j(s),className:"gap-1",children:[e.jsx(ue,{className:"h-3.5 w-3.5"})," Voltar para esta versão"]}),(!s.schema_snapshot||!s.config_snapshot)&&!s.is_current&&e.jsx(p,{variant:"outline",className:"text-xs border-destructive/40 text-destructive",children:"Snapshot incompleto"})]})]})]},s.id))}),e.jsx(C,{value:"logs",className:"space-y-2 mt-4",children:w.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-10",children:"Nenhum rollback registrado."}):w.map(s=>e.jsx(P,{children:e.jsxs(Q,{className:"p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[e.jsxs("span",{className:"font-mono",children:[s.from_version," → ",s.to_version]}),e.jsx(p,{variant:s.status==="success"?"default":"destructive",children:s.status})]}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:[q(new Date(s.created_at),"dd/MM/yyyy HH:mm",{locale:Z}),s.safety_snapshot_version&&` · Segurança: ${s.safety_snapshot_version}`]}),s.error_message&&e.jsx("div",{className:"text-xs text-destructive mt-1",children:s.error_message})]})},s.id))})]}),e.jsx(R,{open:te,onOpenChange:g,children:e.jsxs(T,{children:[e.jsxs(H,{
1children:[e.jsx(A,{children:"Criar nova versão"}),e.jsx(X,{children:"Captura um snapshot completo do schema do banco e dos dados de configuração."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(E,{children:"Número da versão"}),e.jsx(L,{value:n.version,onChange:s=>N({...n,version:s.target.value}),placeholder:"v1.0.31"})]}),e.jsxs("div",{children:[e.jsx(E,{children:"Notas / changelog"}),e.jsx(he,{value:n.notes,onChange:s=>N({...n,notes:s.target.value}),placeholder:"O que mudou nesta versão?",rows:4})]}),e.jsxs("div",{children:[e.jsx(E,{children:"Git SHA (opcional)"}),e.jsx(L,{value:n.git_sha,onChange:s=>N({...n,git_sha:s.target.value}),placeholder:"abc1234"})]})]}),e.jsxs(Y,{children:[e.jsx(i,{variant:"outline",onClick:()=>g(!1),children:"Cancelar"}),e.jsxs(i,{onClick:ne,disabled:z,children:[z&&e.jsx(b,{className:"h-4 w-4 animate-spin mr-2"}),"Criar versão"]})]})]})}),e.jsx(R,{open:!!t,onOpenChange:s=>{s||(j(null),y(""),S(null))},children:e.jsxs(T,{children:[e.jsxs(H,{children:[e.jsxs(A,{className:"text-destructive flex items-center gap-2",children:[e.jsx($,{className:"h-5 w-5"})," Confirmar rollback"]}),e.jsxs(X,{children:["Você está prestes a restaurar a configuração para"," ",e.jsx("strong",{className:"font-mono",children:t==null?void 0:t.version}),". Um snapshot de segurança será criado automaticamente. Digite exatamente"," ",e.jsx("strong",{className:"font-mono",children:t==null?void 0:t.version})," para confirmar."]})]}),l&&e.jsxs("div",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2 font-medium text-destructive",children:[e.jsx($,{className:"h-4 w-4"})," Alterações de schema detectadas"]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Existem estruturas de banco criadas ",e.jsx("strong",{children:"depois"})," desta versão. Fazer rollback mesmo assim mantém as tabelas/colunas novas, mas os dados de configuração serão sobrescritos e novas colunas podem ficar sem valores default esperados."]}),l.new_tables.length>0&&e.jsxs("div",{className:"text-xs",children:[e.jsx("span",{className:"font-medium",children:"Tabelas novas:"})," ",e.jsx("span",{className:"font-mono",children:l.new_tables.join(", ")})]}),l.new_columns.length>0&&e.jsxs("div",{className:"text-xs",children:[e.jsxs("span",{className:"font-medium",children:["Colunas novas (",l.new_columns.length,"):"]})," ",e.jsxs("span",{className:"font-mono",children:[l.new_columns.slice(0,10).map(s=>`${s.table}.${s.column}`).join(", "),l.new_columns.length>10&&` (+${l.new_columns.length-10})`]})]})]}),e.jsx(L,{value:G,onChange:s=>y(s.target.value),placeholder:t==null?void 0:t.version,className:"font-mono"}),e.jsxs(Y,{className:"gap-2",children:[e.jsx(i,{variant:"outline",onClick:()=>j(null),children:"Cancelar"}),l?e.jsxs(i,{variant:"destructive",onClick:le,disabled:v,children:[v&&e.jsx(b,{className:"h-4 w-4 animate-spin mr-2"}),"Forçar mesmo assim"]}):e.jsxs(i,{variant:"destructive",onClick:oe,disabled:v,children:[v&&e.jsx(b,{className:"h-4 w-4 animate-spin mr-2"}),"Executar rollback"]})]})]})}),e.jsx(R,{open:!!o,onOpenChange:s=>!s&&V(null),children:e.jsxs(T,{className:"max-w-3xl max-h-[80vh] overflow-hidden flex flex-col",children:[e.jsx(H,{children:e.jsxs(A,{children:["Snapshot: ",o==null?void 0:o.version]})}),e.jsxs(K,{defaultValue:"schema",className:"flex-1 overflow-hidden flex flex-col",children:[e.jsxs(W,{children:[e.jsx(_,{value:"schema",children:"Schema"}),e.jsx(_,{value:"config",children:"Config"})]}),e.jsx(C,{value:"schema",className:"flex-1 overflow-auto",children:e.jsx("pre",{className:"text-xs bg-muted p-3 rounded whitespace-pre-wrap break-all",children:JSON.stringify((o==null?void 0:o.schema_snapshot)??{},null,2)})}),e.jsx(C,{value:"config",className:"flex-1 overflow-auto",children:e.jsx("pre",{className:"text-xs bg-muted p-3 rounded whitespace-pre-wrap break-all",children:JSON.stringify((o==null?void 0:o.config_snapshot)??{},null,2)})})]})]})})]})}export{je 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.