1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[61345],{61345:function(e,s,a){a.d(s,{f:function(){return R}});var t=a(57437),l=a(2265),r=a(79820),d=a(12381),i=a(69174),n=a(40279),c=a(15291),o=a(74291),x=a(33804),m=a(65302),u=a(45131),h=a(63639),p=a(91723),j=a(90740),g=a(92735),v=a(82431),N=a(73247),f=a(32489),b=a(48736),y=a(92369),_=a(92451),w=a(10407),k=a(29202),S=a(71837),C=a(14438);let Z=e=>({create:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",update:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",delete:"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200",read:"bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200",export:"bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-200",import:"bg-indigo-100 text-indigo-800 dark:bg-indigo-900 dark:text-indigo-200",login:"bg-emerald-100 text-emerald-800 dark:bg-emerald-900 dark:text-emerald-200",logout:"bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200",invite:"bg-cyan-100 text-cyan-800 dark:bg-cyan-900 dark:text-cyan-200",assign:"bg-teal-100 text-teal-800 dark:bg-teal-900 dark:text-teal-200",access_de
1nied:"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200"})[e]||"bg-gray-100 text-gray-800 dark:bg-gray-800 dark:text-gray-200",z=e=>{switch(e){case"success":return(0,t.jsx)(m.Z,{className:"h-4 w-4 text-green-500"});case"failure":return(0,t.jsx)(u.Z,{className:"h-4 w-4 text-red-500"});case"denied":return(0,t.jsx)(h.Z,{className:"h-4 w-4 text-yellow-500"});default:return(0,t.jsx)(p.Z,{className:"h-4 w-4 text-gray-500"})}},A=e=>new Date(e).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}),F=e=>e.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" ");function R(e){let{workspaceId:s}=e,{logs:a,loading:m,error:h,total:p,page:R,limit:U,hasMore:D,actionTypes:L,resourceTypes:P,fetchLogs:O,exportLogs:Q,refresh:I}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{autoFetch:s=!0,initialFilters:a={}}=e,[t,r]=(0,l.useState)([]),[d,i]=(0,l.useState)(null),[n,c]=(0,l.useState)(!1),[o,x]=(0,l.useState)(null),[m,u]=(0,l.useState)(0),[h,p]=(0,l.useState)(a.page||1),[j,g]=(0,l.useState)(a.limit||50),[v,N]=(0,l.useState)(!1),[f,b]=(0,l.useState)([]),[y,_]=(0,l.useState)([]),[w,k]=(0,l.useState)(a),C=(0,l.useCallback)(async e=>{try{c(!0),x(null);let s={...w,...e};k(s);let a=new URLSearchParams;s.action&&a.append("action",s.action),s.resource_type&&a.append("resource_type",s.resource_type),s.user_id&&a.append("user_id",s.user_id
1),s.status&&a.append("status",s.status),s.start_date&&a.append("start_date",s.start_date),s.end_date&&a.append("end_date",s.end_date),s.search&&a.append("search",s.search),a.append("page",String(s.page||1)),a.append("limit",String(s.limit||50));let t=await S.api.get("/audit-logs?".concat(a.toString()));r(t.data.logs),u(t.data.total),p(t.data.page),g(t.data.limit),N(t.data.has_more)}catch(e){var s,a;x((null===(a=e.response)||void 0===a?void 0:null===(s=a.data)||void 0===s?void 0:s.detail)||"Failed to fetch audit logs"),console.error("Failed to fetch audit logs:",e)}finally{c(!1)}},[w]),Z=(0,l.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:30;try{c(!0),x(null);let s=await S.api.get("/audit-logs/statistics?days=".concat(e));i(s.data)}catch(e){var s,a;x((null===(a=e.response)||void 0===a?void 0:null===(s=a.data)||void 0===s?void 0:s.detail)||"Failed to fetch statistics"),console.error("Failed to fetch audit statistics:",e)}finally{c(!1)}},[]),z=(0,l.useCallback)(async(e,s)=>{try{c(!0),x(null);let a={...w,...s},t=new URLSearchParams;t.append("format",e),a.action&&t.append("action",a.action),a.resource_type&&t.append("resource_type",a.resource_type),a.user_id&&t.append("user_id",a.user_id),a.status&&t.append("status",a.status),a.start_date&&t.append("start_date",a.start_date),a.end_date&&t.append("end_date",a.end_date),a.search&&t.append("search",a.search);let l=await S.api.get("/audit-logs/export?".concat(t.toString()),{responseType:"blob"}),r=new Blob([l.data],{type:"json"===e?"application/json":"text/csv"}),d=window.URL.createObjectURL(r),i=document.createElement("a");i.href=d,i.download="audit_logs_".concat(new Date().toISOString().split("T")[0],".").concat(e),document.body.appendChild(i),i.click(),document.body.removeChild(i),window.URL.revokeObjectURL(d)}catch(e){var a,t;x((null===(t=e.response)||void 0===t?void 0:null===(a=t.data)||void 0===a?void 0:a.detail)||"Failed to export audit logs"),console.error("Failed to export audit logs:",e)}finally{c(!1)}},[w]),A=(0,l.useCallback)(async()=>{try{let e=await S.api.get("/audit-logs/actions");b(e.data.actions)}catch(e){console.error("Failed to fetch action types:",e)}},[]),F=(0,l.useCallback)(async()=>{try{let e=await S.api.get("/audit-logs/resource-types");_(e.data.resource_types)}catch(e){console.error("Failed to fetch resource types:",e)}},[]),R=(0,l.useCallback)(async()=>{await Promise.all([C(w),Z()])},[C,Z,w]);return(0,l.useEffect)(()=>{s&&(C(a),A(),F())},[s]),{logs:t,statistics:d,loading:n,error:o,total:m,page:h,limit:j,hasMore:v,actionTypes:f,resourceTypes:y,fetchLogs:C,fetchStatistics:Z,exportLogs:z,fetchActionTypes:A,fetchResourceTypes:F,refresh:R}}({autoFetch:!0}),[q,E]=(0,l.useState)(!1),[T,B]=(0,l.useState)({}),[V,M]=(0,l.useState)(""),[J,K]=(0,l.useState)(null),[Y,$]=(0,l.useState)(!1),G=()=>{O({...T,search:V,page:1})},H=(e,s)=>{let a={...T,[e]:s||void 0,page:1};B(a),O(a)},W=()=>{B({}),M(""),O({page:1})},X=e=>{O({...T,page:e})},ee=async e=>{try{await Q(e,T),C.A.success("Audit logs exported as ".concat(e.toUpperCase()))}catch(e){C.A.error("Failed to export audit logs")}},es=e=>{K(e),$(!0)},ea=Object.values(T).some(e=>e)||V;return(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)(r.Zb,{children:[(0,t.jsx)(r.Ol,{children:(0,t.jsxs)("div",{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(r.ll,{children:"Audit Logs"}),(0,t.jsx)(r.SZ,{children:"Track all workspace activity and security events"})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>E(!q),children:[(0,t.jsx)(j.Z,{className:"h-4 w-4 mr-2"}),"Filters",ea&&(0,t.jsx)(i.C,{variant:"secondary",className:"ml-2 h-5 px-1.5",children:"Active"})]}),(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>ee("csv"),children:[(0,t.jsx)(g.Z,{className:"h-4 w-4 mr-2"}),"CSV"]}),(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>ee("json"),children:[(0,t.jsx)(g.Z,{className:"h-4 w-4 mr-2"}),"JSON"]}),(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:I,disabled:m,children:[(0,t.jsx)(v.Z,{className:"h-4 w-4 mr-2 ".concat(m?"animate-spin":"")}),"Refresh"]})]})]})}),q&&(0,t.jsxs)(r.aY,{className:"border-t pt-4",children:[(0,t.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(n.I,{placeholder:"Search logs...",value:V,onChange:e=>M(e.target.value),onKeyDown:e=>"Enter"===e.key&&G()}),(0,t.jsx)(d.z,{size:"icon",variant:"outline",onClick:G,children:(0,t.jsx)(N.Z,{className:"h-4 w-4"})})]}),(0,t.jsxs)(c.Ph,{value:T.action||"",onValueChange:e=>H("action",e),children:[(0,t.jsx)(c.i4,{children:(0,t.jsx)(c.ki,{placeholder:"All Actions"})}),(0,t.jsxs)(c.Bw,{children:[(0,t.jsx)(c.Ql,{value:"",children:"All Actions"}),L.map(e=>(0,t.jsx)(c.Ql,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1).replace("_"," ")},e))]})]}),(0,t.jsxs)(c.Ph,{value:T.resource_type||"",onValueChange:e=>H("resource_type",e),children:[(0,t.jsx)(c.i4,{children:(0,t.jsx)(c.ki,{placeholder:"All Resources"})}),(0,t.jsxs)(c.Bw,{children:[(0,t.jsx)(c.Ql,{value:"",children:"All Resources"}),P.map(e=>(0,t.jsx)(c.Ql,{value:e,children:F(e)},e))]})]}),(0,t.jsxs)(c.Ph,{value:T.status||"",onValueChange:e=>H("status",e),children:[(0,t.jsx)(c.i4,{children:(0,t.jsx)(c.ki,{placeholder:"All Statuses"})}),(0,t.jsxs)(c.Bw,{children:[(0,t.jsx)(c.Ql,{value:"",children:"All Statuses"}),(0,t.jsx)(c.Ql,{value:"success",children:"Success"}),(0,t.jsx)(c.Ql,{value:"failure",children:"Failure"}),(0,t.jsx)(c.Ql,{value:"denied",children:"Denied"})]})]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4 mt-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm text-muted-foreground mb-1 block",children:"Start Date"}),(0,t.jsx)(n.I,{type:"datetime-local",value:T.start_date||"",onChange:e=>H("start_date",e.target.value)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm text-muted-foreground mb-1 block",children:"End Date"}),(0,t.jsx)(n.I,{type:"datetime-local",value:T.end_date||"",onChange:e=>H("end_date",e.target.value)})]}),(0,t.jsx)("div",{className:"flex items-end",children:(0,t.jsxs)(d.z,{variant:"ghost",size:"sm",onClick:W,className:"w-full",children:[(0,t.jsx)(f.Z,{className:"h-4 w-4 mr-2"}),"Clear Filters"]})})]})]}),(0,t.jsxs)(r.aY,{className:q?"":"pt-0",children:[h&&(0,t.jsxs)("div",{className:"text-center py-8 text-red-500",children:[(0,t.jsx)(u.Z,{className:"h-8 w-8 mx-auto mb-2"}),(0,t.jsx)("p",{children:h})]}),!h&&0===a.length&&!m&&(0,t.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,t.jsx)(b.Z,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,t.jsx)("p",{children:"No audit logs found"}),ea&&(0,t.jsx)(d.z,{variant:"link",onClick:W,className:"mt-2",children:"Clear filters to
1see all logs"})]}),(a.length>0||m)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"rounded-md border overflow-x-auto",children:(0,t.jsxs)(x.iA,{children:[(0,t.jsx)(x.xD,{children:(0,t.jsxs)(x.SC,{children:[(0,t.jsx)(x.ss,{className:"w-[180px]",children:"Timestamp"}),(0,t.jsx)(x.ss,{className:"w-[200px]",children:"User"}),(0,t.jsx)(x.ss,{className:"w-[100px]",children:"Action"}),(0,t.jsx)(x.ss,{className:"w-[120px]",children:"Resource"}),(0,t.jsx)(x.ss,{children:"Description"}),(0,t.jsx)(x.ss,{className:"w-[80px] text-center",children:"Status"})]})}),(0,t.jsx)(x.RM,{children:m&&0===a.length?(0,t.jsx)(x.SC,{children:(0,t.jsxs)(x.pj,{colSpan:6,className:"text-center py-8",children:[(0,t.jsx)(v.Z,{className:"h-6 w-6 animate-spin mx-auto mb-2"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"Loading audit logs..."})]})}):a.map(e=>(0,t.jsxs)(x.SC,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>es(e),children:[(0,t.jsx)(x.pj,{className:"font-mono text-sm",children:A(e.created_at)}),(0,t.jsx)(x.pj,{children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(y.Z,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("span",{className:"truncate max-w-[150px]",title:e.user_email,children:e.user_email})]})}),(0,t.jsx)(x.pj,{children:(0,t.jsx)(i.C,{variant:"secondary",className:Z(e.action),children:e.action})}),(0,t.jsx)(x.pj,{children:(0,t.jsx)("span",{className:"capitalize",children:F(e.resource_type)})}),(0,t.jsx)(x.pj,{children:(0,t.jsx)("span",{className:"truncate block max-w-[300px]",title:e.description||"",children:e.description||"-"})}),(0,t.jsx)(x.pj,{className:"text-center",children:z(e.status)})]},e.id))})]})}),(0,t.jsxs)("div",{className:"flex items-center justify-between mt-4",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Showing ",(R-1)*U+1," to ",Math.min(R*U,p)," of ",p," entries"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>X(R-1),disabled:R<=1||m,children:[(0,t.jsx)(_.Z,{className:"h-4 w-4"}),"Previous"]}),(0,t.jsxs)("span",{className:"text-sm text-muted-foreground px-2",children:["Page ",R," of ",Math.
1ceil(p/U)||1]}),(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>X(R+1),disabled:!D||m,children:["Next",(0,t.jsx)(w.Z,{className:"h-4 w-4"})]})]})]})]})]})]}),(0,t.jsx)(o.Vq,{open:Y,onOpenChange:$,children:(0,t.jsxs)(o.cZ,{className:"max-w-2xl max-h-[80vh] overflow-y-auto",children:[(0,t.jsxs)(o.fK,{children:[(0,t.jsx)(o.$N,{children:"Audit Log Details"}),(0,t.jsx)(o.Be,{children:"Full details of the audit log entry"})]}),J&&(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-muted-foreground",children:"Timestamp"}),(0,t.jsx)("p",{className:"mt-1 font-mono",children:A(J.created_at)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-muted-foreground",children:"Status"}),(0,t.jsxs)("div",{className:"mt-1 flex items-center gap-2",children:[z(J.status),(0,t.jsx)("span",{className:"capitalize",children:J.status})]})]})]}),(0,t.jsxs)("div",{className:"p-3 bg-muted rounded-lg",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,t.jsx)(y.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"font-medium",children:"User"})]}),(0,t.jsx)("p",{children:J.user_email}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground font-mono",children:J.user_id}),J.impersonated_by&&(0,t.jsxs)("p",{className:"text-sm text-yellow-600 mt-1",children:["Impersonated by: ",J.impersonated_by]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-muted-foreground",children:"Action"}),(0,t.jsx)("div",{className:"mt-1",children:(0,t.jsx)(i.C,{className:Z(J.action),children:J.action})})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-muted-foreground",children:"Resource Type"}),(0,t.jsx)("p",{className:"mt-1 capitalize",children:F(J.resource_type)})]})]}),J.resource_id&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-muted-foreground",children:"Resource ID"}),(0,t.jsx)("p",{className:"mt-1 font-mono text-sm",children:J.resource_id})]}),J.description&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-muted-foreground",children:"Description"}),(0,t.jsx)("p",{className:"mt-1",children:J.description})]}),(J.ip_address||J.request_path)&&(0,t.jsxs)("div",{className:"p-3 bg-muted rounded-lg",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,t.jsx)(k.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"font-medium",children:"Request Context"})]}),J.ip_address&&(0,t.jsxs)("p",{className:"text-sm",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"IP Address:"})," ",J.ip_address]}),J.request_path&&(0,t.jsxs)("p",{className:"text-sm font-mono",children:[(0,t.jsx)("span",{className:"text-muted-foreground font-sans",children:"Path:"})," ",J.request_method," ",J.request_path]}),J.user_agent&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground truncate mt-1",title:J.user_agent,children:J.user_agent})]}),J.metadata&&Object.keys(J.metadata).length>0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"text-sm font-medium text-muted-foreground",children:"Metadata"}),(0,t.jsx)("pre",{className:"mt-1 p-3 bg-muted rounded-lg text-sm overflow-x-auto",children:JSON.stringify(J.metadata,null,2)})]})]})]})})]})}}}]);
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.