@objectstack/console 7.2.1 → 7.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/assets/{AiPendingActionsPage-DYX4ANzZ.js → AiPendingActionsPage-C2C3Ja_n.js} +1 -1
  2. package/dist/assets/ApiConsolePage-ePJcxhf9.js +1 -0
  3. package/dist/assets/{AppManagementPage-BnwBNW_m.js → AppManagementPage-CFHAXcEw.js} +1 -1
  4. package/dist/assets/ApprovalsInboxPage-DuHpUtLO.js +1 -0
  5. package/dist/assets/{AuditLogPage-C1CgKWC8.js → AuditLogPage-Dw6wpFTf.js} +1 -1
  6. package/dist/assets/{ComponentNavView-g_X1YUdk.js → ComponentNavView-DyNUAEnY.js} +1 -1
  7. package/dist/assets/ConsoleFloatingChatbot-vOXH4hva.js +1 -0
  8. package/dist/assets/{DeveloperHubPage-CcV4mWRr.js → DeveloperHubPage-Di9VELMr.js} +1 -1
  9. package/dist/assets/FlowRunsPage-C2ElJEUw.js +1 -0
  10. package/dist/assets/ProfilePage-DbEzcgM3.js +1 -0
  11. package/dist/assets/{PublicFormsPage-BNIOSFr1.js → PublicFormsPage-CFO_htk4.js} +1 -1
  12. package/dist/assets/{RecentItemsProvider-Dt0K6V1V.js → RecentItemsProvider-VqVTd5Ra.js} +1 -1
  13. package/dist/assets/{SettingsHub-4RDkAyKq.js → SettingsHub-RgZdAo3g.js} +1 -1
  14. package/dist/assets/{SettingsView-_5h2mExc.js → SettingsView-C4bpsbjP.js} +1 -1
  15. package/dist/assets/{SystemHubPage-DRRxgNWV.js → SystemHubPage-DCtNkrqu.js} +1 -1
  16. package/dist/assets/data-adapter-BI1S6gix.js +1 -0
  17. package/dist/assets/framework-Bsl5NTfe.js +34 -0
  18. package/dist/assets/{highlighted-body-OFNGDK62-Dp9QBuY-.js → highlighted-body-OFNGDK62-DolMghKp.js} +1 -1
  19. package/dist/assets/index-C2SC5SiS.css +2 -0
  20. package/dist/assets/index-D8443YMB.js +33 -0
  21. package/dist/assets/{infrastructure-IQKE4Vv8.js → infrastructure-CFhpdDcd.js} +1 -1
  22. package/dist/assets/mermaid-GHXKKRXX-qaGVEVOV.js +1 -0
  23. package/dist/assets/plugin-calendar-CQDuOrA8.js +1 -0
  24. package/dist/assets/plugin-charts-BDWqi8DX.js +7 -0
  25. package/dist/assets/plugin-chatbot-MXXPNrIm.js +120 -0
  26. package/dist/assets/plugin-dashboard-Do4xOja1.js +3 -0
  27. package/dist/assets/plugin-form-DGz9Ldoi.js +1 -0
  28. package/dist/assets/plugin-gantt-Bv3kYo78.js +1 -0
  29. package/dist/assets/plugin-grid-X6RP2gd8.js +6 -0
  30. package/dist/assets/plugin-kanban-BhsP-1E9.js +1 -0
  31. package/dist/assets/{plugin-map-DRf0LmJy.js → plugin-map-Bl9-aL25.js} +1 -1
  32. package/dist/assets/{plugin-markdown-BVFW0U6V.js → plugin-markdown-DSLEFWrT.js} +1 -1
  33. package/dist/assets/plugin-report-DcNaFUN2.js +59 -0
  34. package/dist/assets/plugin-timeline-Bb7f-Qd7.js +1 -0
  35. package/dist/assets/plugin-view-DoIbSHeI.js +1 -0
  36. package/dist/assets/plugins-views-BNDN6gD4.js +4 -0
  37. package/dist/assets/{src-DL8N52oz.js → src-AD-6EnzK.js} +1 -1
  38. package/dist/assets/{types-CbmNTewl.js → types-BYLUnF0C.js} +1 -1
  39. package/dist/assets/ui-components-D0tUqjB3.js +41 -0
  40. package/dist/assets/{ui-layout-DGPxy1gI.js → ui-layout-C9W0Gcnt.js} +1 -1
  41. package/dist/assets/vendor-objectstack-D6pAOWWu.js +65 -0
  42. package/dist/index.html +4 -4
  43. package/package.json +1 -1
  44. package/dist/assets/ApiConsolePage-C70S6MYv.js +0 -1
  45. package/dist/assets/ApprovalsInboxPage-CQQmK4Pz.js +0 -1
  46. package/dist/assets/ConsoleFloatingChatbot-DJW7zeKU.js +0 -1
  47. package/dist/assets/FlowRunsPage-Rtd6u1e_.js +0 -1
  48. package/dist/assets/ProfilePage-DPGkAZWG.js +0 -1
  49. package/dist/assets/data-adapter-Bi1Re1fK.js +0 -1
  50. package/dist/assets/framework-DVkqUSPj.js +0 -34
  51. package/dist/assets/index-DWtLSzKK.js +0 -33
  52. package/dist/assets/index-JLLCOoA3.css +0 -2
  53. package/dist/assets/mermaid-GHXKKRXX-PDO-QkSF.js +0 -1
  54. package/dist/assets/plugin-calendar-D1wyyvEx.js +0 -1
  55. package/dist/assets/plugin-charts-DrCI3cJo.js +0 -7
  56. package/dist/assets/plugin-chatbot-CiVctLlf.js +0 -120
  57. package/dist/assets/plugin-dashboard-BRn9AjyQ.js +0 -3
  58. package/dist/assets/plugin-form-KOOMD5ZY.js +0 -1
  59. package/dist/assets/plugin-gantt-D3OFukY1.js +0 -1
  60. package/dist/assets/plugin-grid-DGQxmfxn.js +0 -6
  61. package/dist/assets/plugin-kanban-C-qMP4VL.js +0 -1
  62. package/dist/assets/plugin-report-CJSBthhg.js +0 -59
  63. package/dist/assets/plugin-timeline-RAn1F_nX.js +0 -1
  64. package/dist/assets/plugin-view-DspcF1Mc.js +0 -1
  65. package/dist/assets/plugins-views-DUx-xpiH.js +0 -4
  66. package/dist/assets/ui-components-CIdYg6m3.js +0 -41
  67. package/dist/assets/vendor-objectstack-B3zP6Fz_.js +0 -65
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{n as r}from"./plugin-chatbot-CiVctLlf.js";var i=e(n(),1),a=t();function o(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},t=e.VITE_AI_BASE_URL;return t?t.replace(/\/$/,``):`${(e.VITE_SERVER_URL??``).replace(/\/$/,``)}/api/v1/ai`}function s(){let e=(0,i.useMemo)(()=>o(),[]);return(0,a.jsxs)(`div`,{className:`p-6 max-w-6xl mx-auto`,children:[(0,a.jsxs)(`div`,{className:`mb-4`,children:[(0,a.jsx)(`h1`,{className:`text-2xl font-semibold`,children:`AI Approvals`}),(0,a.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Review actions an AI agent proposed. Approve to execute them server-side; reject to send a reason back to the model so it can revise the next turn.`})]}),(0,a.jsx)(r,{apiBase:e,variant:`card`,title:`Queue`,description:`Polled every 5 seconds. Decisions are recorded under your identity.`})]})}export{s as AiPendingActionsPage,s as default};
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{n as r}from"./plugin-chatbot-MXXPNrIm.js";var i=e(n(),1),a=t();function o(){let e={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},t=e.VITE_AI_BASE_URL;return t?t.replace(/\/$/,``):`${(e.VITE_SERVER_URL??``).replace(/\/$/,``)}/api/v1/ai`}function s(){let e=(0,i.useMemo)(()=>o(),[]);return(0,a.jsxs)(`div`,{className:`p-6 max-w-6xl mx-auto`,children:[(0,a.jsxs)(`div`,{className:`mb-4`,children:[(0,a.jsx)(`h1`,{className:`text-2xl font-semibold`,children:`AI Approvals`}),(0,a.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Review actions an AI agent proposed. Approve to execute them server-side; reject to send a reason back to the model so it can revise the next turn.`})]}),(0,a.jsx)(r,{apiBase:e,variant:`card`,title:`Queue`,description:`Polled every 5 seconds. Decisions are recorded under your identity.`})]})}export{s as AiPendingActionsPage,s as default};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{S as r}from"./framework-Bsl5NTfe.js";import{Ai as i,Bi as a,Bo as o,Ea as s,Fo as c,Hn as l,Lr as u,Qn as d,Ri as f,Un as p,Wn as m,as as h,eo as g,is as _,ns as v,vi as ee,xr as te}from"./ui-components-D0tUqjB3.js";import"./index-D8443YMB.js";var y=e(n(),1),b=[`plugin`,`plugins`,`kind`,`package`];function x(e){return[{method:`POST`,path:`${e}/sign-in/email`,desc:`Sign in (email)`,group:`Auth`,bodyTemplate:{email:`user@example.com`,password:``}},{method:`POST`,path:`${e}/sign-up/email`,desc:`Sign up (email)`,group:`Auth`,bodyTemplate:{email:``,password:``,name:``}},{method:`POST`,path:`${e}/sign-out`,desc:`Sign out`,group:`Auth`},{method:`GET`,path:`${e}/get-session`,desc:`Get session`,group:`Auth`}]}var S={ai:{group:`AI`,defaultRoute:`/api/v1/ai`,endpoints:[{method:`POST`,path:`/chat`,desc:`Chat completion`,bodyTemplate:{messages:[{role:`user`,content:``}]}},{method:`POST`,path:`/chat/stream`,desc:`Streaming chat (SSE)`,bodyTemplate:{messages:[{role:`user`,content:``}]}},{method:`POST`,path:`/complete`,desc:`Text completion`,bodyTemplate:{prompt:``}},{method:`GET`,path:`/models`,desc:`List available models`},{method:`POST`,path:`/nlq`,desc:`Natural language query`,bodyTemplate:{query:``}},{method:`POST`,path:`/suggest`,desc:`AI-powered suggestions`,bodyTemplate:{object:``,field:``,context:{}}},{method:`POST`,path:`/insights`,desc:`AI-generated insights`,bodyTemplate:{object:``,recordIds:[]}},{method:`POST`,path:`/conversations`,desc:`Create conversation`,bodyTemplate:{}},{method:`GET`,path:`/conversations`,desc:`List conversations`},{method:`POST`,path:`/conversations/:id/messages`,desc:`Add message to conversation`,bodyTemplate:{role:`user`,content:``}},{method:`DELETE`,path:`/conversations/:id`,desc:`Delete conversation`}]},workflow:{group:`Workflow`,defaultRoute:`/api/v1/workflow`,endpoints:[{method:`GET`,path:`/:object/config`,desc:`Get workflow configuration`},{method:`GET`,path:`/:object/:recordId/state`,desc:`Get workflow state`},{method:`POST`,path:`/:object/:recordId/transition`,desc:`Execute workflow transition`,bodyTemplate:{targetState:``}},{method:`POST`,path:`/:object/:recordId/approve`,desc:`Approve workflow step`,bodyTemplate:{comment:``}},{method:`POST`,path:`/:object/:recordId/reject`,desc:`Reject workflow step`,bodyTemplate:{comment:``}}]},realtime:{group:`Realtime`,defaultRoute:`/api/v1/realtime`,endpoints:[{method:`POST`,path:`/connect`,desc:`Establish realtime connection`,bodyTemplate:{transport:`websocket`}},{method:`POST`,path:`/disconnect`,desc:`Close realtime connection`,bodyTemplate:{connectionId:``}},{method:`POST`,path:`/subscribe`,desc:`Subscribe to channel`,bodyTemplate:{channel:``}},{method:`POST`,path:`/unsubscribe`,desc:`Unsubscribe from channel`,bodyTemplate:{channel:``}},{method:`PUT`,path:`/presence/:channel`,desc:`Set presence state`,bodyTemplate:{status:`online`}},{method:`GET`,path:`/presence/:channel`,desc:`Get channel presence`}]},notification:{group:`Notifications`,defaultRoute:`/api/v1/notifications`,endpoints:[{method:`GET`,path:``,desc:`List notifications`},{method:`POST`,path:`/devices`,desc:`Register device for push`,bodyTemplate:{token:``,platform:`web`}},{method:`DELETE`,path:`/devices/:deviceId`,desc:`Unregister device`},{method:`GET`,path:`/preferences`,desc:`Get notification preferences`},{method:`PATCH`,path:`/preferences`,desc:`Update notification preferences`,bodyTemplate:{email:!0,push:!0}},{method:`POST`,path:`/read`,desc:`Mark notifications as read`,bodyTemplate:{ids:[]}},{method:`POST`,path:`/read/all`,desc:`Mark all as read`}]},analytics:{group:`Analytics`,defaultRoute:`/api/v1/analytics`,endpoints:[{method:`POST`,path:`/query`,desc:`Execute analytics query`,bodyTemplate:{measures:[],dimensions:[]}},{method:`GET`,path:`/meta`,desc:`Get analytics metadata`}]},automation:{group:`Automation`,defaultRoute:`/api/v1/automation`,endpoints:[{method:`POST`,path:`/trigger`,desc:`Trigger automation`,bodyTemplate:{name:``,params:{}}}]},i18n:{group:`i18n`,defaultRoute:`/api/v1/i18n`,endpoints:[{method:`GET`,path:`/locales`,desc:`Get available locales`},{method:`GET`,path:`/translations/:locale`,desc:`Get translations for locale`},{method:`GET`,path:`/labels/:object/:locale`,desc:`Get translated field labels`}]},ui:{group:`UI`,defaultRoute:`/api/v1/ui`,endpoints:[{method:`GET`,path:`/views`,desc:`List views`},{method:`GET`,path:`/views/:id`,desc:`Get view by ID`},{method:`POST`,path:`/views`,desc:`Create view`,bodyTemplate:{name:``,object:``,type:`list`}},{method:`PATCH`,path:`/views/:id`,desc:`Update view`,bodyTemplate:{name:``}},{method:`DELETE`,path:`/views/:id`,desc:`Delete view`}]},feed:{group:`Feed`,defaultRoute:`/api/v1/feed`,endpoints:[{method:`GET`,path:`/:object/:recordId`,desc:`Get feed items`},{method:`POST`,path:`/:object/:recordId`,desc:`Post feed item`,bodyTemplate:{body:``}}]},storage:{group:`Storage`,defaultRoute:`/api/v1/storage`,endpoints:[{method:`POST`,path:`/upload`,desc:`Upload file (multipart/form-data)`},{method:`GET`,path:`/:fileId`,desc:`Download file`},{method:`DELETE`,path:`/:fileId`,desc:`Delete file`}]}};function C(e,t){let n=S[e];return n?n.endpoints.map(e=>({method:e.method,path:`${t}${e.path}`,desc:e.desc,group:n.group,...e.bodyTemplate?{bodyTemplate:e.bodyTemplate}:{}})):[]}function ne(){let e=r(),[t,n]=(0,y.useState)([]),[i,a]=(0,y.useState)([]),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(null),u=(0,y.useCallback)(async()=>{s(!0),l(null);let t=`/api/v1`,r=`${t}/discovery`,i=[{method:`GET`,path:r,desc:`API Discovery`,group:`System`},{method:`GET`,path:`${t}/meta/types`,desc:`List metadata types`,group:`Metadata`},{method:`GET`,path:`${t}/packages`,desc:`List packages`,group:`System`},{method:`GET`,path:`/api/v1/health`,desc:`Health check`,group:`System`}];try{let o=`/api/v1/auth`,s={},c={};try{let e=await fetch(r);if(e.ok){let t=await e.json(),n=t?.data??t;c=n?.routes??{},s=n?.services??{},c.auth&&(o=c.auth)}}catch{}let l=[];for(let[e,t]of Object.entries(S)){let n=s[e],r=n?.enabled??!1,i=n?.handlerReady??(n?.status===`available`||n?.status===`degraded`),a=n?.route??c[e]??t.defaultRoute;r&&i&&l.push(...C(e,a))}let u=e?.getClient?.(),d=[];try{let e=await u?.meta?.getTypes?.();e&&Array.isArray(e.types)?d=e.types:Array.isArray(e)&&(d=e)}catch{}let f=[];try{let e=d.includes(`object`)?`object`:null;if(e&&u?.meta?.getItems){let t=await u.meta.getItems(e),n=[];Array.isArray(t)?n=t:t&&Array.isArray(t.items)?n=t.items:t&&Array.isArray(t.value)&&(n=t.value),f=n.map(e=>e.name||e.id).filter(Boolean)}}catch{}let p=f.flatMap(e=>{let n=e.startsWith(`sys_`)?`Data: system tables`:`Data: ${e}`;return[{method:`GET`,path:`${t}/data/${e}`,desc:`List ${e}`,group:n},{method:`POST`,path:`${t}/data/${e}`,desc:`Create ${e}`,group:n,bodyTemplate:{name:`example`}},{method:`GET`,path:`${t}/data/${e}/:id`,desc:`Get ${e} by ID`,group:n},{method:`PATCH`,path:`${t}/data/${e}/:id`,desc:`Update ${e}`,group:n,bodyTemplate:{name:`updated`}},{method:`DELETE`,path:`${t}/data/${e}/:id`,desc:`Delete ${e}`,group:n}]}),m=d.filter(e=>!b.includes(e)).map(e=>({method:`GET`,path:`${t}/meta/${e}`,desc:`List ${e} metadata`,group:`Metadata`})),h=f.map(e=>({method:`GET`,path:`${t}/meta/object/${e}`,desc:`${e} schema`,group:`Metadata`})),g=[...i,...x(o),...l,...m,...h,...p],_=new Map;for(let e of g){let t=_.get(e.group)||[];t.push(e),_.set(e.group,t)}let v=[`System`,`Auth`,`AI`,`Workflow`,`Realtime`,`Notifications`,`Analytics`,`Automation`,`i18n`,`UI`,`Feed`,`Storage`,`Metadata`];n(Array.from(_.entries()).sort(([e],[t])=>{let n=v.indexOf(e),r=v.indexOf(t);return n!==-1&&r!==-1?n-r:n===-1?r===-1?e.localeCompare(t):1:-1}).map(([e,t])=>({key:e,label:e,endpoints:t}))),a(g)}catch(e){l(e.message||`Failed to discover APIs`)}finally{s(!1)}},[e]);return(0,y.useEffect)(()=>{u()},[u]),{groups:t,allEndpoints:i,loading:o,error:c,refresh:u}}var w=t(),T={GET:`text-emerald-600 bg-emerald-50 border-emerald-200 dark:text-emerald-400 dark:bg-emerald-950/50`,POST:`text-blue-600 bg-blue-50 border-blue-200 dark:text-blue-400 dark:bg-blue-950/50`,PATCH:`text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950/50`,PUT:`text-amber-600 bg-amber-50 border-amber-200 dark:text-amber-400 dark:bg-amber-950/50`,DELETE:`text-red-600 bg-red-50 border-red-200 dark:text-red-400 dark:bg-red-950/50`},re={2:`text-emerald-600 dark:text-emerald-400`,3:`text-blue-600 dark:text-blue-400`,4:`text-amber-600 dark:text-amber-400`,5:`text-red-600 dark:text-red-400`},E=[{key:`$top`,placeholder:`10`,hint:`limit`},{key:`$skip`,placeholder:`0`,hint:`offset`},{key:`$sort`,placeholder:`name`,hint:`sort field`},{key:`$select`,placeholder:`name,email`,hint:`fields`},{key:`$count`,placeholder:`true`,hint:`total count`},{key:`$filter`,placeholder:`status eq 'active'`,hint:`OData filter`}],D=1;function O(){let e=r()?.getClient?.(),{groups:t,loading:n,refresh:b}=ne(),[x,S]=(0,y.useState)(``),[C,O]=(0,y.useState)(new Set),[k,A]=(0,y.useState)(null),[ie,j]=(0,y.useState)(``),[ae,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(``),[F,I]=(0,y.useState)([]),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)([]),[U,oe]=(0,y.useState)(null),[W,G]=(0,y.useState)(!1),K=(0,y.useMemo)(()=>{if(!x)return t;let e=x.toLowerCase();return t.map(t=>({...t,endpoints:t.endpoints.filter(t=>t.desc.toLowerCase().includes(e)||t.path.toLowerCase().includes(e)||t.method.toLowerCase().includes(e))})).filter(e=>e.endpoints.length>0)},[t,x]),se=(0,y.useCallback)(e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=(0,y.useCallback)(e=>{A(e),j(e.method),M(e.path),P(e.bodyTemplate?JSON.stringify(e.bodyTemplate,null,2):``),I([]),B(null)},[]),q=ie||k?.method||`GET`,J=ae||k?.path||``,Y=(0,y.useMemo)(()=>{let e=F.filter(e=>e.enabled&&e.key.trim());return e.length===0?J:`${J}?${e.map(e=>`${encodeURIComponent(e.key)}=${encodeURIComponent(e.value)}`).join(`&`)}`},[J,F]),X=(0,y.useCallback)((e=``,t=``)=>{I(n=>[...n,{id:D++,key:e,value:t,enabled:!0}])},[]),le=(0,y.useCallback)(e=>{I(t=>t.filter(t=>t.id!==e))},[]),Z=(0,y.useCallback)((e,t,n)=>{I(r=>r.map(r=>r.id===e?{...r,[t]:n}:r))},[]),ue=(0,y.useCallback)(e=>{I(t=>t.map(t=>t.id===e?{...t,enabled:!t.enabled}:t))},[]),Q=(0,y.useCallback)(async()=>{if(L||!Y)return;let t=`${e?.baseUrl??``}${Y}`;R(!0);let n=performance.now();try{let e={method:q,headers:{"Content-Type":`application/json`}};[`POST`,`PATCH`,`PUT`].includes(q)&&N.trim()&&(e.body=N);let r=await fetch(t,e),i=Math.round(performance.now()-n),a;if((r.headers.get(`content-type`)??``).includes(`json`)){let e=await r.json();a=JSON.stringify(e,null,2)}else a=await r.text();B({status:r.status,body:a,duration:i}),H(e=>[{id:Date.now(),method:q,url:Y,body:N||void 0,status:r.status,duration:i,response:a,timestamp:new Date},...e].slice(0,50))}catch(e){let t=Math.round(performance.now()-n);B({status:0,body:`Network Error: ${e.message}`,duration:t})}finally{R(!1)}},[e,Y,q,N,L]),de=(0,y.useCallback)(e=>{j(e.method);let[t,n]=e.url.split(`?`);if(M(t),P(e.body||``),n){let e=new URLSearchParams(n),t=[];e.forEach((e,n)=>{t.push({id:D++,key:n,value:e,enabled:!0})}),I(t)}else I([]);B(null),A(null)},[]),fe=(0,y.useCallback)(()=>{z?.body&&(navigator.clipboard.writeText(z.body),G(!0),setTimeout(()=>G(!1),1500))},[z]),$=e=>re[String(e)[0]]??`text-muted-foreground`;return(0,w.jsxs)(`div`,{className:`flex flex-1 min-h-0 overflow-hidden`,children:[(0,w.jsxs)(`div`,{className:`w-72 shrink-0 border-r flex flex-col overflow-hidden`,children:[(0,w.jsxs)(`div`,{className:`p-3 border-b space-y-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`h3`,{className:`text-sm font-semibold text-foreground flex-1`,children:`API Endpoints`}),(0,w.jsx)(`button`,{onClick:b,disabled:n,className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,title:`Refresh endpoints`,children:(0,w.jsx)(i,{className:`h-3.5 w-3.5 ${n?`animate-spin`:``}`})})]}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(ee,{className:`absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,w.jsx)(`input`,{type:`text`,value:x,onChange:e=>S(e.target.value),placeholder:`Search endpoints...`,className:`w-full rounded-md border bg-background pl-8 pr-3 py-1.5 text-sm focus:outline-none focus:ring-1 focus:ring-ring`})]})]}),(0,w.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:n?(0,w.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,w.jsx)(s,{className:`h-4 w-4 animate-spin mr-2`}),`Discovering APIs...`]}):K.length===0?(0,w.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,w.jsx)(g,{className:`h-6 w-6 opacity-30 mb-2`}),(0,w.jsx)(`span`,{children:x?`No matching endpoints`:`No endpoints found`})]}):K.map(e=>{let t=C.has(e.key)||!!x;return(0,w.jsxs)(l,{open:t,onOpenChange:()=>se(e.key),children:[(0,w.jsx)(m,{asChild:!0,children:(0,w.jsxs)(`button`,{className:`w-full flex items-center gap-1.5 px-2 py-1.5 rounded-md text-xs font-medium text-muted-foreground hover:bg-muted/50 hover:text-foreground transition-colors`,children:[(0,w.jsx)(v,{className:`h-3 w-3 shrink-0 transition-transform duration-200 ${t?`rotate-90`:``}`}),(0,w.jsx)(`span`,{className:`flex-1 text-left truncate`,children:e.label}),(0,w.jsx)(`span`,{className:`shrink-0 text-[10px] tabular-nums opacity-60`,children:e.endpoints.length})]})}),(0,w.jsx)(p,{children:(0,w.jsx)(`div`,{className:`ml-3 space-y-0.5 mt-0.5`,children:e.endpoints.map((e,t)=>(0,w.jsxs)(`button`,{onClick:()=>ce(e),className:`w-full text-left flex items-center gap-1.5 px-2 py-1 rounded text-xs transition-colors ${k===e?`bg-accent text-accent-foreground`:`hover:bg-muted/50 text-muted-foreground hover:text-foreground`}`,children:[(0,w.jsx)(d,{variant:`outline`,className:`font-mono text-[9px] shrink-0 px-1 py-0 ${T[e.method]||``}`,children:e.method}),(0,w.jsx)(`span`,{className:`truncate`,children:e.desc})]},`${e.method}-${e.path}-${t}`))})})]},e.key)})}),(0,w.jsxs)(`div`,{className:`p-3 border-t space-y-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,w.jsx)(`h4`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:`Query Parameters`}),(0,w.jsxs)(`button`,{onClick:()=>X(),className:`inline-flex items-center gap-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,w.jsx)(f,{className:`h-3 w-3`}),`Add`]})]}),(0,w.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:E.map(e=>(0,w.jsx)(`button`,{onClick:()=>X(e.key,``),className:`text-[10px] px-1.5 py-0.5 rounded border bg-muted/30 text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors font-mono`,title:e.hint,children:e.key},e.key))}),F.length>0&&(0,w.jsx)(`div`,{className:`space-y-1`,children:F.map(e=>(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>ue(e.id),className:`h-3 w-3 shrink-0 rounded border accent-primary`}),(0,w.jsx)(`input`,{type:`text`,value:e.key,onChange:t=>Z(e.id,`key`,t.target.value),placeholder:`key`,className:`flex-1 min-w-0 rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono focus:outline-none focus:ring-1 focus:ring-ring`}),(0,w.jsx)(`input`,{type:`text`,value:e.value,onChange:t=>Z(e.id,`value`,t.target.value),placeholder:`value`,className:`flex-1 min-w-0 rounded border bg-background px-1.5 py-0.5 text-[10px] font-mono focus:outline-none focus:ring-1 focus:ring-ring`}),(0,w.jsx)(`button`,{onClick:()=>le(e.id),className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-destructive transition-colors`,children:(0,w.jsx)(te,{className:`h-3 w-3`})})]},e.id))})]})]}),(0,w.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 overflow-hidden`,children:[(0,w.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`select`,{value:q,onChange:e=>j(e.target.value),className:`rounded-md border bg-background px-2 py-1.5 font-mono text-xs font-semibold focus:outline-none focus:ring-1 focus:ring-ring ${T[q]||``}`,children:[`GET`,`POST`,`PATCH`,`PUT`,`DELETE`].map(e=>(0,w.jsx)(`option`,{value:e,children:e},e))}),(0,w.jsx)(`input`,{type:`text`,value:J,onChange:e=>M(e.target.value),className:`flex-1 rounded-md border bg-background px-3 py-1.5 font-mono text-sm focus:outline-none focus:ring-1 focus:ring-ring`,placeholder:`/api/v1/...`,onKeyDown:e=>{e.key===`Enter`&&Q()}}),(0,w.jsxs)(`button`,{onClick:Q,disabled:L||!Y,className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-4 py-1.5 text-sm font-medium text-primary-foreground hover:bg-primary/90 disabled:opacity-50 transition-colors`,children:[L?(0,w.jsx)(s,{className:`h-3.5 w-3.5 animate-spin`}):(0,w.jsx)(a,{className:`h-3.5 w-3.5`}),`Send`]})]}),F.some(e=>e.enabled&&e.key.trim())&&(0,w.jsxs)(`div`,{className:`text-[10px] font-mono text-muted-foreground truncate pl-1`,children:[`→ `,Y]})]}),(0,w.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 overflow-auto`,children:[[`POST`,`PATCH`,`PUT`].includes(q)&&(0,w.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,w.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Request Body (JSON)`}),(0,w.jsx)(`textarea`,{value:N,onChange:e=>P(e.target.value),rows:5,className:`w-full rounded-md border bg-background px-3 py-2 font-mono text-xs focus:outline-none focus:ring-1 focus:ring-ring resize-y`,placeholder:`{ "key": "value" }`})]}),L&&(0,w.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,w.jsx)(s,{className:`h-4 w-4 animate-spin mr-2`}),`Sending request...`]}),z&&!L&&(0,w.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-muted/30 border-b`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,w.jsx)(`span`,{className:`font-mono font-semibold ${$(z.status)}`,children:z.status||`ERR`}),(0,w.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,w.jsx)(o,{className:`h-3 w-3`}),z.duration,`ms`]})]}),(0,w.jsxs)(`button`,{onClick:fe,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[W?(0,w.jsx)(h,{className:`h-3 w-3`}):(0,w.jsx)(c,{className:`h-3 w-3`}),W?`Copied`:`Copy`]})]}),(0,w.jsx)(`pre`,{className:`flex-1 overflow-auto p-3 text-xs font-mono bg-muted/10 whitespace-pre-wrap break-all`,children:z.body})]}),!z&&!L&&(0,w.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground text-sm`,children:(0,w.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,w.jsx)(g,{className:`h-10 w-10 mx-auto opacity-20`}),(0,w.jsxs)(`p`,{children:[`Select an endpoint or type a URL and click `,(0,w.jsx)(`strong`,{children:`Send`})]}),(0,w.jsx)(`p`,{className:`text-xs opacity-60`,children:`All registered APIs are auto-discovered from the platform`})]})}),V.length>0&&(0,w.jsxs)(`div`,{className:`border-t`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2`,children:[(0,w.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:[`History (`,V.length,`)`]}),(0,w.jsxs)(`button`,{onClick:()=>H([]),className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,w.jsx)(u,{className:`h-3 w-3`}),`Clear`]})]}),(0,w.jsx)(`div`,{className:`space-y-0.5 px-2 pb-2 max-h-60 overflow-auto`,children:V.map(e=>(0,w.jsxs)(`div`,{className:`rounded border`,children:[(0,w.jsxs)(`button`,{onClick:()=>oe(U===e.id?null:e.id),className:`w-full flex items-center gap-2 px-2 py-1.5 text-xs hover:bg-muted/30 transition-colors`,children:[U===e.id?(0,w.jsx)(_,{className:`h-3 w-3 shrink-0`}):(0,w.jsx)(v,{className:`h-3 w-3 shrink-0`}),(0,w.jsx)(d,{variant:`outline`,className:`font-mono text-[9px] shrink-0 ${T[e.method]||``}`,children:e.method}),(0,w.jsx)(`span`,{className:`font-mono truncate text-left flex-1`,children:e.url}),(0,w.jsx)(`span`,{className:`ml-auto shrink-0 font-mono ${$(e.status)}`,children:e.status}),(0,w.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.duration,`ms`]}),(0,w.jsx)(`button`,{onClick:t=>{t.stopPropagation(),de(e)},className:`shrink-0 p-0.5 rounded hover:bg-muted text-muted-foreground hover:text-foreground transition-colors`,title:`Replay request`,children:(0,w.jsx)(a,{className:`h-2.5 w-2.5`})})]}),U===e.id&&(0,w.jsx)(`pre`,{className:`px-3 py-2 text-xs font-mono bg-muted/10 border-t overflow-auto max-h-40 whitespace-pre-wrap break-all`,children:e.response})]},e.id))})]})]})]})]})}export{O as ApiConsolePage};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{f as t,m as n,r,y as i}from"./vendor-react-CyVA1SE-.js";import{S as a}from"./framework-DVkqUSPj.js";import{Br as o,Fi as s,Gn as c,Hi as l,Kn as u,Lr as d,Qn as f,Qr as p,Rr as m,_i as h,en as g,fo as _,ka as v,mr as y,qn as b}from"./ui-components-CIdYg6m3.js";import{o as x}from"./vendor-ui-utils-BbOuugky.js";import"./index-DWtLSzKK.js";var S=e(i(),1);function C(e,t){if(e!=null){if(typeof e==`string`)return e;if(t){let n=t(e.key,{defaultValue:e.defaultValue,...e.params});if(n&&n!==e.key)return n}return e.defaultValue||e.key}}var w=r();function T(){let e=t(),{appName:r}=n(),i=r?`/apps/${r}`:``,{apps:T,refresh:E}=a(),[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(new Set),[j,M]=(0,S.useState)(null),[N,P]=(0,S.useState)(!1),F=(T||[]).filter(e=>{if(!D)return!0;let t=D.toLowerCase();return(e.name||``).toLowerCase().includes(t)||(e.label||``).toLowerCase().includes(t)||(e.description||``).toLowerCase().includes(t)}),I=(0,S.useCallback)(e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),L=(0,S.useCallback)(()=>{k.size===F.length?A(new Set):A(new Set(F.map(e=>e.name)))},[k.size,F]),R=(0,S.useCallback)(async e=>{P(!0);try{let t=e.active===!1;x.success(`${e.label||e.name} ${t?`enabled`:`disabled`}`),await E()}catch{x.error(`Failed to toggle app status`)}finally{P(!1)}},[E]),z=(0,S.useCallback)(async e=>{P(!0);try{x.success(`${e.label||e.name} set as default`),await E()}catch{x.error(`Failed to set default app`)}finally{P(!1)}},[E]),B=(0,S.useCallback)(async e=>{if(j!==e.name){M(e.name);return}P(!0);try{x.success(`${e.label||e.name} deleted`),M(null),await E()}catch{x.error(`Failed to delete app`)}finally{P(!1)}},[j,E]),V=(0,S.useCallback)(async e=>{P(!0);try{x.success(`${k.size} apps ${e?`enabled`:`disabled`}`),A(new Set),await E()}catch{x.error(`Bulk operation failed`)}finally{P(!1)}},[k,E]);return(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Applications`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage all configured applications`})]}),(0,w.jsxs)(y,{onClick:()=>e(`${i}/create-app`),"data-testid":`create-app-btn`,children:[(0,w.jsx)(s,{className:`h-4 w-4 mr-2`}),`New App`]})]}),(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,w.jsx)(`label`,{htmlFor:`app-search`,className:`sr-only`,children:`Search apps`}),(0,w.jsx)(h,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,w.jsx)(g,{id:`app-search`,placeholder:`Search apps...`,value:D,onChange:e=>O(e.target.value),className:`pl-8`,"data-testid":`app-search-input`})]}),k.size>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(f,{variant:`secondary`,children:[k.size,` selected`]}),(0,w.jsx)(y,{variant:`outline`,size:`sm`,onClick:()=>V(!0),disabled:N,children:`Enable`}),(0,w.jsx)(y,{variant:`outline`,size:`sm`,onClick:()=>V(!1),disabled:N,children:`Disable`})]})]}),F.length>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,w.jsx)(c,{id:`select-all-apps`,checked:k.size===F.length&&F.length>0,onCheckedChange:()=>L()}),(0,w.jsxs)(`label`,{htmlFor:`select-all-apps`,className:`cursor-pointer`,children:[`Select all (`,F.length,`)`]})]}),F.length===0?(0,w.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground`,"data-testid":`no-apps-message`,children:[(0,w.jsx)(v,{className:`h-12 w-12 mx-auto mb-3 opacity-30`}),(0,w.jsx)(`p`,{children:`No apps found.`})]}):(0,w.jsx)(`div`,{className:`grid gap-3`,children:F.map(t=>{let n=t.active!==!1,r=t.isDefault===!0,a=j===t.name;return(0,w.jsx)(u,{className:n?``:`opacity-60`,"data-testid":`app-card-${t.name}`,children:(0,w.jsxs)(b,{className:`flex items-center gap-3 py-3 px-4`,children:[(0,w.jsx)(c,{id:`select-app-${t.name}`,checked:k.has(t.name),onCheckedChange:()=>I(t.name),"aria-label":`Select ${t.label||t.name}`,className:`shrink-0`}),(0,w.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,w.jsx)(v,{className:`h-4 w-4`})}),(0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`span`,{className:`font-medium truncate`,children:C(t.label)||t.name}),r&&(0,w.jsx)(f,{variant:`default`,className:`text-xs`,children:`Default`}),(0,w.jsx)(f,{variant:n?`secondary`:`outline`,className:`text-xs`,children:n?`Active`:`Inactive`})]}),t.description&&(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:C(t.description)})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,w.jsx)(y,{variant:`ghost`,size:`icon`,title:`Open app`,"aria-label":`Open ${t.label||t.name}`,onClick:()=>e(`/apps/${t.name}`),children:(0,w.jsx)(_,{className:`h-4 w-4`})}),(0,w.jsx)(y,{variant:`ghost`,size:`icon`,title:`Edit app`,"aria-label":`Edit ${t.label||t.name}`,onClick:()=>e(`${i}/edit-app/${t.name}`),children:(0,w.jsx)(l,{className:`h-4 w-4`})}),(0,w.jsx)(y,{variant:`ghost`,size:`icon`,title:n?`Disable app`:`Enable app`,"aria-label":n?`Disable ${t.label||t.name}`:`Enable ${t.label||t.name}`,onClick:()=>R(t),disabled:N,children:n?(0,w.jsx)(m,{className:`h-4 w-4`}):(0,w.jsx)(o,{className:`h-4 w-4`})}),(0,w.jsx)(y,{variant:`ghost`,size:`icon`,title:`Set as default`,"aria-label":`Set ${t.label||t.name} as default`,onClick:()=>z(t),disabled:N||r,children:(0,w.jsx)(p,{className:`h-4 w-4 ${r?`fill-current text-yellow-500`:``}`})}),(0,w.jsx)(y,{variant:`ghost`,size:`icon`,title:a?`Click again to confirm delete`:`Delete app`,"aria-label":a?`Confirm delete ${t.label||t.name}`:`Delete ${t.label||t.name}`,onClick:()=>B(t),disabled:N,className:a?`text-destructive`:``,children:(0,w.jsx)(d,{className:`h-4 w-4`})})]})]})},t.name)})})]})}export{T as AppManagementPage};
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{f as t,m as n,r,y as i}from"./vendor-react-CyVA1SE-.js";import{C as a}from"./framework-Bsl5NTfe.js";import{$r as o,Br as s,Co as c,Gi as l,Gn as u,Kn as d,Lr as f,Pa as p,Qn as m,Ri as h,Rr as g,en as _,mr as v,qn as y,vi as b}from"./ui-components-D0tUqjB3.js";import{o as x}from"./vendor-ui-utils-BbOuugky.js";import"./index-D8443YMB.js";var S=e(i(),1);function C(e,t){if(e!=null){if(typeof e==`string`)return e;if(t){let n=t(e.key,{defaultValue:e.defaultValue,...e.params});if(n&&n!==e.key)return n}return e.defaultValue||e.key}}var w=r();function T(){let e=t(),{appName:r}=n(),i=r?`/apps/${r}`:``,{apps:T,refresh:E}=a(),[D,O]=(0,S.useState)(``),[k,A]=(0,S.useState)(new Set),[j,M]=(0,S.useState)(null),[N,P]=(0,S.useState)(!1),F=(T||[]).filter(e=>{if(!D)return!0;let t=D.toLowerCase();return(e.name||``).toLowerCase().includes(t)||(e.label||``).toLowerCase().includes(t)||(e.description||``).toLowerCase().includes(t)}),I=(0,S.useCallback)(e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),L=(0,S.useCallback)(()=>{k.size===F.length?A(new Set):A(new Set(F.map(e=>e.name)))},[k.size,F]),R=(0,S.useCallback)(async e=>{P(!0);try{let t=e.active===!1;x.success(`${e.label||e.name} ${t?`enabled`:`disabled`}`),await E()}catch{x.error(`Failed to toggle app status`)}finally{P(!1)}},[E]),z=(0,S.useCallback)(async e=>{P(!0);try{x.success(`${e.label||e.name} set as default`),await E()}catch{x.error(`Failed to set default app`)}finally{P(!1)}},[E]),B=(0,S.useCallback)(async e=>{if(j!==e.name){M(e.name);return}P(!0);try{x.success(`${e.label||e.name} deleted`),M(null),await E()}catch{x.error(`Failed to delete app`)}finally{P(!1)}},[j,E]),V=(0,S.useCallback)(async e=>{P(!0);try{x.success(`${k.size} apps ${e?`enabled`:`disabled`}`),A(new Set),await E()}catch{x.error(`Bulk operation failed`)}finally{P(!1)}},[k,E]);return(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row sm:items-center justify-between gap-3`,children:[(0,w.jsxs)(`div`,{className:`min-w-0`,children:[(0,w.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Applications`}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage all configured applications`})]}),(0,w.jsxs)(v,{onClick:()=>e(`${i}/create-app`),"data-testid":`create-app-btn`,children:[(0,w.jsx)(h,{className:`h-4 w-4 mr-2`}),`New App`]})]}),(0,w.jsxs)(`div`,{className:`flex flex-col sm:flex-row items-start sm:items-center gap-2`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 max-w-sm`,children:[(0,w.jsx)(`label`,{htmlFor:`app-search`,className:`sr-only`,children:`Search apps`}),(0,w.jsx)(b,{className:`pointer-events-none absolute left-2.5 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground`,"aria-hidden":`true`}),(0,w.jsx)(_,{id:`app-search`,placeholder:`Search apps...`,value:D,onChange:e=>O(e.target.value),className:`pl-8`,"data-testid":`app-search-input`})]}),k.size>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(m,{variant:`secondary`,children:[k.size,` selected`]}),(0,w.jsx)(v,{variant:`outline`,size:`sm`,onClick:()=>V(!0),disabled:N,children:`Enable`}),(0,w.jsx)(v,{variant:`outline`,size:`sm`,onClick:()=>V(!1),disabled:N,children:`Disable`})]})]}),F.length>0&&(0,w.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,w.jsx)(u,{id:`select-all-apps`,checked:k.size===F.length&&F.length>0,onCheckedChange:()=>L()}),(0,w.jsxs)(`label`,{htmlFor:`select-all-apps`,className:`cursor-pointer`,children:[`Select all (`,F.length,`)`]})]}),F.length===0?(0,w.jsxs)(`div`,{className:`text-center py-12 text-muted-foreground`,"data-testid":`no-apps-message`,children:[(0,w.jsx)(p,{className:`h-12 w-12 mx-auto mb-3 opacity-30`}),(0,w.jsx)(`p`,{children:`No apps found.`})]}):(0,w.jsx)(`div`,{className:`grid gap-3`,children:F.map(t=>{let n=t.active!==!1,r=t.isDefault===!0,a=j===t.name;return(0,w.jsx)(d,{className:n?``:`opacity-60`,"data-testid":`app-card-${t.name}`,children:(0,w.jsxs)(y,{className:`flex items-center gap-3 py-3 px-4`,children:[(0,w.jsx)(u,{id:`select-app-${t.name}`,checked:k.has(t.name),onCheckedChange:()=>I(t.name),"aria-label":`Select ${t.label||t.name}`,className:`shrink-0`}),(0,w.jsx)(`div`,{className:`flex h-9 w-9 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,w.jsx)(p,{className:`h-4 w-4`})}),(0,w.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`span`,{className:`font-medium truncate`,children:C(t.label)||t.name}),r&&(0,w.jsx)(m,{variant:`default`,className:`text-xs`,children:`Default`}),(0,w.jsx)(m,{variant:n?`secondary`:`outline`,className:`text-xs`,children:n?`Active`:`Inactive`})]}),t.description&&(0,w.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:C(t.description)})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,w.jsx)(v,{variant:`ghost`,size:`icon`,title:`Open app`,"aria-label":`Open ${t.label||t.name}`,onClick:()=>e(`/apps/${t.name}`),children:(0,w.jsx)(c,{className:`h-4 w-4`})}),(0,w.jsx)(v,{variant:`ghost`,size:`icon`,title:`Edit app`,"aria-label":`Edit ${t.label||t.name}`,onClick:()=>e(`${i}/edit-app/${t.name}`),children:(0,w.jsx)(l,{className:`h-4 w-4`})}),(0,w.jsx)(v,{variant:`ghost`,size:`icon`,title:n?`Disable app`:`Enable app`,"aria-label":n?`Disable ${t.label||t.name}`:`Enable ${t.label||t.name}`,onClick:()=>R(t),disabled:N,children:n?(0,w.jsx)(g,{className:`h-4 w-4`}):(0,w.jsx)(s,{className:`h-4 w-4`})}),(0,w.jsx)(v,{variant:`ghost`,size:`icon`,title:`Set as default`,"aria-label":`Set ${t.label||t.name} as default`,onClick:()=>z(t),disabled:N||r,children:(0,w.jsx)(o,{className:`h-4 w-4 ${r?`fill-current text-yellow-500`:``}`})}),(0,w.jsx)(v,{variant:`ghost`,size:`icon`,title:a?`Click again to confirm delete`:`Delete app`,"aria-label":a?`Confirm delete ${t.label||t.name}`:`Delete ${t.label||t.name}`,onClick:()=>B(t),disabled:N,className:a?`text-destructive`:``,children:(0,w.jsx)(f,{className:`h-4 w-4`})})]})]})},t.name)})})]})}export{T as AppManagementPage};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{f as r}from"./infrastructure-CFhpdDcd.js";import{$ as i,$o as a,Ai as o,At as s,Bo as ee,Bt as c,F as te,Fo as ne,Ft as re,Gn as ie,Ht as ae,I as oe,It as se,Kn as ce,Lt as l,Mr as le,Mt as ue,Nt as de,Pt as fe,Q as pe,Qn as u,Rt as me,Vt as he,Wo as ge,Zo as _e,ar as ve,at as d,cr as ye,ct as be,dr as f,en as xe,et as Se,fr as Ce,ii as we,in as Te,it as Ee,lr as De,mr as p,nr as Oe,nt as m,or as h,ot as g,pr as ke,qn as Ae,rr as je,rt as Me,sr as Ne,st as Pe,tt as Fe,ur as Ie,vi as Le,xr as Re,z as ze,zt as Be}from"./ui-components-D0tUqjB3.js";import{o as _}from"./vendor-ui-utils-BbOuugky.js";var v=e(n(),1),Ve=`${``.replace(/\/$/,``)}/api/v1`;async function y(e,t){let n=await fetch(`${Ve}${e}`,{credentials:`include`,headers:{"Content-Type":`application/json`,...t?.headers||{}},...t}),r=null;try{r=await n.json()}catch{}if(!n.ok){let e=r?.code??`HTTP_${n.status}`,t=r?.message??r?.error??n.statusText,i=Error(`${e}: ${t}`);throw i.code=e,i.status=n.status,i.details=r,i}return r}var b={listProcesses(e={}){let t=new URLSearchParams;e.object&&t.set(`object`,e.object),e.activeOnly&&t.set(`activeOnly`,`true`);let n=t.toString();return y(`/approvals/processes${n?`?${n}`:``}`)},listRequests(e={}){let t=new URLSearchParams;e.status&&t.set(`status`,e.status),e.object&&t.set(`object`,e.object),e.recordId&&t.set(`recordId`,e.recordId),e.approverId&&t.set(`approverId`,e.approverId),e.submitterId&&t.set(`submitterId`,e.submitterId);let n=t.toString();return y(`/approvals/requests${n?`?${n}`:``}`)},async getRequest(e){return{data:await y(`/approvals/requests/${encodeURIComponent(e)}`)}},listActions(e){return y(`/approvals/requests/${encodeURIComponent(e)}/actions`)},async approve(e,t){let n=await y(`/approvals/requests/${encodeURIComponent(e)}/approve`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async reject(e,t){let n=await y(`/approvals/requests/${encodeURIComponent(e)}/reject`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async recall(e,t){let n=await y(`/approvals/requests/${encodeURIComponent(e)}/recall`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async submit(e){return y(`/approvals/requests`,{method:`POST`,body:JSON.stringify(e)})}};function He(e){if(!e)return[];let t=new Set;e.id&&t.add(e.id),e.email&&t.add(e.email);for(let n of e.roles||[])n&&t.add(`role:${n}`);return Array.from(t)}var x=t(),S={pending:{variant:`secondary`,label:`Pending`},approved:{variant:`default`,label:`Approved`},rejected:{variant:`destructive`,label:`Rejected`},recalled:{variant:`outline`,label:`Recalled`}};function C({status:e}){let t=S[e]??{variant:`outline`,label:e};return(0,x.jsx)(u,{variant:t.variant,children:t.label})}function w(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function T(e){if(!e)return`—`;let t=Date.parse(e);if(Number.isNaN(t))return e;let n=Date.now()-t,r=Math.round(n/1e3);if(r<45)return`just now`;let i=Math.round(r/60);if(i<60)return`${i}m ago`;let a=Math.round(i/60);if(a<24)return`${a}h ago`;let o=Math.round(a/24);if(o<30)return`${o}d ago`;try{return new Date(e).toLocaleDateString()}catch{return e}}function E(e){return e?e.includes(`@`)?e:e.startsWith(`role:`)?`Role: ${e.slice(5)}`:e.length>14?`${e.slice(0,6)}…${e.slice(-4)}`:e:`—`}function D(){let{user:e}=r(),t=(0,v.useMemo)(()=>He(e),[e]),[n,Ve]=(0,v.useState)(`pending`),[y,S]=(0,v.useState)([]),[D,O]=(0,v.useState)(!1),[k,A]=(0,v.useState)(null),[Ue,j]=(0,v.useState)(null),[M,N]=(0,v.useState)(null),[We,P]=(0,v.useState)([]),[Ge,Ke]=(0,v.useState)(!1),[F,I]=(0,v.useState)(``),[L,R]=(0,v.useState)(``),[z,qe]=(0,v.useState)(null),[B,Je]=(0,v.useState)(``),[V,Ye]=(0,v.useState)(`all`),[H,Xe]=(0,v.useState)(`all`),[U,W]=(0,v.useState)(new Set),[G,Ze]=(0,v.useState)(!1),K=(0,v.useCallback)(async()=>{O(!0),A(null);try{let r=[];if(n===`pending`){let e=new Set;if(t.length===0){let e=await b.listRequests({status:`pending`});for(let t of e.data)r.push(t)}else for(let n of t){let t=await b.listRequests({status:`pending`,approverId:n});for(let n of t.data)e.has(n.id)||(e.add(n.id),r.push(n))}}else if(n===`submitted`){let t=e?.id;if(!t){S([]),O(!1);return}let n=await b.listRequests({submitterId:t});r.push(...n.data)}else{let e=await b.listRequests({});r.push(...e.data)}r.sort((e,t)=>(t.submitted_at||``).localeCompare(e.submitted_at||``)),S(r)}catch(e){A(e?.message||String(e)),S([])}finally{O(!1)}},[n,t,e?.id]);(0,v.useEffect)(()=>{K()},[K]);let Qe=(0,v.useCallback)(async e=>{j(e),Ke(!0),I(``),R(``);try{let[t,n]=await Promise.all([b.getRequest(e),b.listActions(e)]);N(t.data),P(n.data)}catch(e){_.error(e?.message||`Failed to load request`),N(null),P([])}finally{Ke(!1)}},[]),$e=()=>{j(null),N(null),P([]),I(``),R(``)},q=(0,v.useCallback)(n=>{if(L.trim())return L.trim();if(!n)return e?.id||``;let r=new Set(n.pending_approvers||[]);for(let e of t)if(r.has(e))return e;return e?.id||``},[L,t,e?.id]),J=(0,v.useCallback)(async e=>{if(!M)return;let t=q(M);if(!t){_.error(`Cannot determine actor id`);return}qe(e);try{let n={actor_id:t,comment:F.trim()||void 0},r=await(e===`approve`?b.approve:e===`reject`?b.reject:b.recall)(M.id,n);_.success(e===`approve`?r.finalized?`Approved (finalized)`:`Approved — advanced to next step`:e===`reject`?r.finalized?`Rejected`:`Rejected — returned to previous step`:`Recalled`),I(``);let[i,a]=await Promise.all([b.getRequest(M.id),b.listActions(M.id)]);N(i.data),P(a.data),K()}catch(t){_.error(t?.message||`Failed to ${e}`)}finally{qe(null)}},[M,q,F,K]),Y=(0,v.useMemo)(()=>{if(!M||M.status!==`pending`)return!1;let e=new Set(M.pending_approvers||[]);return t.some(t=>e.has(t))||L.trim().length>0},[M,t,L]),et=(0,v.useMemo)(()=>!M||M.status!==`pending`?!1:M.submitter_id===e?.id||L.trim().length>0,[M,e?.id,L]),tt=(0,v.useMemo)(()=>y.filter(e=>e.status===`pending`).length,[y]),nt=(0,v.useMemo)(()=>{let e=new Set;for(let t of y)t.process_name&&e.add(t.process_name);return Array.from(e).sort()},[y]),rt=(0,v.useMemo)(()=>{let e=new Set;for(let t of y)t.object_name&&e.add(t.object_name);return Array.from(e).sort()},[y]),X=(0,v.useMemo)(()=>{let e=B.trim().toLowerCase();return y.filter(t=>V!==`all`&&t.process_name!==V||H!==`all`&&t.object_name!==H?!1:e?[t.process_name,t.object_name,t.record_id,t.submitter_id,...t.pending_approvers||[]].filter(Boolean).join(` `).toLowerCase().includes(e):!0)},[y,B,V,H]);(0,v.useEffect)(()=>{if(U.size===0)return;let e=new Set(X.map(e=>e.id)),t=!1,n=new Set;for(let r of U)e.has(r)?n.add(r):t=!0;t&&W(n)},[X,U]);let Z=(0,v.useMemo)(()=>{let e=new Set(t);return X.filter(t=>U.has(t.id)&&t.status===`pending`&&(t.pending_approvers||[]).some(t=>e.has(t)))},[X,U,t]),Q=X.filter(e=>e.status===`pending`),$=Q.length>0&&Q.every(e=>U.has(e.id)),it=(0,v.useCallback)(()=>{W(e=>{if($)return new Set;let t=new Set(e);for(let e of Q)t.add(e.id);return t})},[$,Q]),at=(0,v.useCallback)(e=>{W(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ot=(0,v.useCallback)(async n=>{let r=Z;if(r.length===0)return;Ze(!0);let i=0,a=0;for(let o of r){let r=new Set(o.pending_approvers||[]),s=t.find(e=>r.has(e))||e?.id||``;try{await(n===`approve`?b.approve:b.reject)(o.id,{actor_id:s}),i++}catch{a++}}Ze(!1),W(new Set),a===0?_.success(`${n===`approve`?`Approved`:`Rejected`} ${i} request${i===1?``:`s`}`):_.error(`${i} succeeded, ${a} failed`),K()},[Z,t,e?.id,K]);return(0,x.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-6xl`,children:[(0,x.jsxs)(`header`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsxs)(`h1`,{className:`text-2xl font-semibold flex items-center gap-2`,children:[(0,x.jsx)(we,{className:`h-6 w-6`}),`Approvals Inbox`]}),(0,x.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Review and act on multi-step approval requests.`})]}),(0,x.jsxs)(p,{variant:`outline`,size:`sm`,onClick:K,disabled:D,children:[(0,x.jsx)(o,{className:`h-4 w-4 mr-2 ${D?`animate-spin`:``}`}),`Refresh`]})]}),k&&(0,x.jsxs)(Oe,{variant:`destructive`,children:[(0,x.jsx)(a,{className:`h-4 w-4`}),(0,x.jsx)(je,{children:k})]}),(0,x.jsxs)(i,{value:n,onValueChange:e=>Ve(e),children:[(0,x.jsxs)(Fe,{children:[(0,x.jsxs)(m,{value:`pending`,children:[`My Pending`,tt>0&&(0,x.jsx)(u,{variant:`secondary`,className:`ml-2`,children:tt})]}),(0,x.jsx)(m,{value:`submitted`,children:`Submitted by me`}),(0,x.jsx)(m,{value:`all`,children:`All`})]}),(0,x.jsxs)(Se,{value:n,className:`mt-4 space-y-3`,children:[!D&&y.length>0&&(0,x.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,x.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-sm`,children:[(0,x.jsx)(Le,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,x.jsx)(xe,{value:B,onChange:e=>Je(e.target.value),placeholder:`Search process, record, approver…`,className:`pl-8 h-8 text-sm`}),B&&(0,x.jsx)(`button`,{type:`button`,onClick:()=>Je(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":`Clear search`,children:(0,x.jsx)(Re,{className:`h-3.5 w-3.5`})})]}),nt.length>1&&(0,x.jsxs)(me,{value:V,onValueChange:Ye,children:[(0,x.jsx)(he,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,x.jsx)(ae,{placeholder:`Process`})}),(0,x.jsxs)(Be,{children:[(0,x.jsx)(c,{value:`all`,children:`All processes`}),nt.map(e=>(0,x.jsx)(c,{value:e,children:e},e))]})]}),rt.length>1&&(0,x.jsxs)(me,{value:H,onValueChange:Xe,children:[(0,x.jsx)(he,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,x.jsx)(ae,{placeholder:`Object`})}),(0,x.jsxs)(Be,{children:[(0,x.jsx)(c,{value:`all`,children:`All objects`}),rt.map(e=>(0,x.jsx)(c,{value:e,children:e},e))]})]}),(B||V!==`all`||H!==`all`)&&(0,x.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[X.length,` of `,y.length]})]}),n===`pending`&&U.size>0&&(0,x.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2 rounded-md border bg-accent/30 text-sm`,children:[(0,x.jsxs)(`span`,{children:[(0,x.jsx)(`strong`,{children:U.size}),` selected`,Z.length!==U.size&&(0,x.jsxs)(`span`,{className:`text-muted-foreground ml-1`,children:[`(`,Z.length,` actionable)`]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,x.jsxs)(p,{size:`sm`,onClick:()=>ot(`approve`),disabled:G||Z.length===0,children:[(0,x.jsx)(_e,{className:`h-3.5 w-3.5 mr-1`}),`Approve `,Z.length||``]}),(0,x.jsxs)(ve,{children:[(0,x.jsx)(ke,{asChild:!0,children:(0,x.jsxs)(p,{size:`sm`,variant:`outline`,disabled:G||Z.length===0,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,x.jsx)(ge,{className:`h-3.5 w-3.5 mr-1`}),`Reject `,Z.length||``]})}),(0,x.jsxs)(ye,{children:[(0,x.jsxs)(f,{children:[(0,x.jsxs)(Ce,{children:[`Reject `,Z.length,` requests?`]}),(0,x.jsx)(De,{children:`This will reject the selected requests and notify their submitters.`})]}),(0,x.jsxs)(Ie,{children:[(0,x.jsx)(Ne,{children:`Cancel`}),(0,x.jsxs)(h,{onClick:()=>ot(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:[`Reject `,Z.length]})]})]})]}),(0,x.jsx)(p,{size:`sm`,variant:`ghost`,onClick:()=>W(new Set),disabled:G,children:`Clear`})]})]}),D?(0,x.jsxs)(`div`,{className:`space-y-2`,children:[(0,x.jsx)(s,{className:`h-10 w-full`}),(0,x.jsx)(s,{className:`h-10 w-full`}),(0,x.jsx)(s,{className:`h-10 w-full`})]}):y.length===0?(0,x.jsx)(`div`,{className:`flex items-center justify-center min-h-[240px] rounded-md border border-dashed`,children:(0,x.jsxs)(te,{children:[(0,x.jsx)(ze,{children:`No requests`}),(0,x.jsx)(oe,{children:n===`pending`?`You have no pending approvals.`:`Nothing here yet.`})]})}):X.length===0?(0,x.jsx)(`div`,{className:`flex items-center justify-center min-h-[160px] rounded-md border border-dashed text-sm text-muted-foreground`,children:`No matches for current filters.`}):(0,x.jsx)(ce,{children:(0,x.jsx)(Ae,{className:`p-0`,children:(0,x.jsxs)(Me,{children:[(0,x.jsx)(Pe,{children:(0,x.jsxs)(be,{children:[n===`pending`&&(0,x.jsx)(g,{className:`w-10`,children:(0,x.jsx)(ie,{checked:$,onCheckedChange:it,"aria-label":`Select all`,disabled:Q.length===0})}),(0,x.jsx)(g,{children:`Process`}),(0,x.jsx)(g,{children:`Object`}),(0,x.jsx)(g,{children:`Record`}),(0,x.jsx)(g,{children:`Step`}),(0,x.jsx)(g,{children:`Status`}),(0,x.jsx)(g,{children:`Approvers`}),(0,x.jsx)(g,{children:`Submitted`})]})}),(0,x.jsx)(Ee,{children:X.map(e=>(0,x.jsxs)(be,{className:`cursor-pointer hover:bg-accent/50`,onClick:()=>Qe(e.id),children:[n===`pending`&&(0,x.jsx)(d,{className:`w-10`,onClick:e=>e.stopPropagation(),children:(0,x.jsx)(ie,{checked:U.has(e.id),onCheckedChange:()=>at(e.id),disabled:e.status!==`pending`,"aria-label":`Select request ${e.id}`})}),(0,x.jsx)(d,{className:`font-medium`,children:e.process_name}),(0,x.jsx)(d,{children:e.object_name}),(0,x.jsx)(d,{className:`font-mono text-xs`,title:e.record_id,children:E(e.record_id)}),(0,x.jsx)(d,{children:e.current_step?(0,x.jsxs)(`span`,{className:`text-xs`,children:[e.current_step,typeof e.current_step_index==`number`&&(0,x.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (#`,e.current_step_index,`)`]})]}):`—`}),(0,x.jsx)(d,{children:(0,x.jsx)(C,{status:e.status})}),(0,x.jsx)(d,{className:`max-w-[220px] truncate text-xs text-muted-foreground`,title:(e.pending_approvers||[]).join(`, `),children:(e.pending_approvers||[]).map(E).join(`, `)||`—`}),(0,x.jsxs)(d,{className:`text-xs whitespace-nowrap text-muted-foreground`,title:w(e.submitted_at),children:[(0,x.jsx)(ee,{className:`h-3 w-3 inline mr-1`}),T(e.submitted_at)]})]},e.id))})]})})})]})]}),(0,x.jsx)(ue,{open:!!Ue,onOpenChange:e=>!e&&$e(),children:(0,x.jsxs)(de,{className:`w-full sm:max-w-xl overflow-y-auto`,children:[(0,x.jsxs)(re,{children:[(0,x.jsx)(se,{children:`Approval Request`}),(0,x.jsx)(fe,{children:M?`${M.process_name} · ${M.object_name}/${M.record_id}`:``})]}),Ge?(0,x.jsxs)(`div`,{className:`space-y-2 mt-6`,children:[(0,x.jsx)(s,{className:`h-6 w-3/4`}),(0,x.jsx)(s,{className:`h-6 w-1/2`}),(0,x.jsx)(s,{className:`h-20 w-full`})]}):M?(0,x.jsxs)(`div`,{className:`space-y-4 mt-6`,children:[(0,x.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-sm`,children:[(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Status`}),(0,x.jsx)(C,{status:M.status})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Current Step`}),M.current_step||`—`]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Step Index`}),M.current_step_index??`—`]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Submitter`}),(0,x.jsx)(`span`,{className:`font-mono text-xs`,title:M.submitter_id||``,children:E(M.submitter_id)})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Submitted`}),w(M.submitted_at)]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Completed`}),w(M.completed_at)]}),(0,x.jsxs)(`div`,{className:`col-span-2`,children:[(0,x.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Pending Approvers`}),(0,x.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:(M.pending_approvers||[]).length===0?`—`:(M.pending_approvers||[]).map((e,t)=>(0,x.jsx)(u,{variant:`outline`,className:`font-mono text-[10px]`,title:e,children:E(e)},t))})]}),M.payload&&(0,x.jsxs)(`div`,{className:`col-span-2`,children:[(0,x.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,x.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Payload`}),(0,x.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(JSON.stringify(M.payload,null,2)),_.success(`Payload copied`)}catch{_.error(`Copy failed`)}},className:`text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,x.jsx)(ne,{className:`h-3 w-3`}),`Copy`]})]}),(0,x.jsx)(`pre`,{className:`text-[11px] bg-muted/50 rounded p-2 overflow-auto max-h-32 mt-1`,children:JSON.stringify(M.payload,null,2)})]})]}),(0,x.jsx)(l,{}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Action History`}),We.length===0?(0,x.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`No actions yet.`}):(0,x.jsx)(`ol`,{className:`relative space-y-3 pl-5 before:absolute before:left-[7px] before:top-1 before:bottom-1 before:w-px before:bg-border`,children:We.map(e=>(0,x.jsxs)(`li`,{className:`relative text-xs`,children:[(0,x.jsx)(`span`,{className:`absolute -left-[18px] top-1 h-3 w-3 rounded-full ring-2 ring-background ${e.action===`approve`?`bg-emerald-500`:e.action===`reject`?`bg-destructive`:e.action===`submit`?`bg-blue-500`:(e.action,`bg-muted-foreground`)}`,"aria-hidden":!0}),(0,x.jsxs)(`div`,{className:`flex items-baseline gap-1.5 flex-wrap`,children:[(0,x.jsx)(`span`,{className:`font-medium capitalize`,children:e.action}),(0,x.jsx)(`span`,{className:`text-muted-foreground`,children:`by`}),(0,x.jsx)(`span`,{className:`font-mono`,title:e.actor_id||``,children:E(e.actor_id)}),e.step_name&&(0,x.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,e.step_name,` (#`,e.step_index,`)`]}),(0,x.jsx)(`span`,{className:`ml-auto text-muted-foreground text-[10px]`,title:w(e.created_at),children:T(e.created_at)})]}),e.comment&&(0,x.jsxs)(`div`,{className:`text-muted-foreground italic mt-0.5`,children:[`"`,e.comment,`"`]})]},e.id))})]}),M.status===`pending`&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(l,{}),(0,x.jsxs)(`div`,{className:`space-y-3`,children:[(0,x.jsxs)(`details`,{className:`group`,children:[(0,x.jsx)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground select-none`,children:`Override actor (advanced)`}),(0,x.jsxs)(`div`,{className:`mt-2`,children:[(0,x.jsx)(Te,{htmlFor:`actor-override`,className:`text-xs`,children:`Actor`}),(0,x.jsx)(`input`,{id:`actor-override`,type:`text`,value:L,onChange:e=>R(e.target.value),placeholder:`Auto: ${q(M)||`(none)`}`,className:`w-full mt-1 px-3 py-2 text-sm border rounded-md bg-background`}),(0,x.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`e.g. `,(0,x.jsx)(`code`,{children:`role:sales_manager`}),`. Leave blank to use auto-detected.`]})]})]}),(0,x.jsxs)(`div`,{children:[(0,x.jsx)(Te,{htmlFor:`comment`,className:`text-xs`,children:`Comment (optional)`}),(0,x.jsx)(pe,{id:`comment`,value:F,onChange:e=>I(e.target.value),rows:2,className:`mt-1`})]}),(0,x.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,x.jsxs)(p,{size:`sm`,onClick:()=>J(`approve`),disabled:!Y||z!==null,children:[(0,x.jsx)(_e,{className:`h-4 w-4 mr-1`}),z===`approve`?`Approving…`:`Approve`]}),(0,x.jsxs)(ve,{children:[(0,x.jsx)(ke,{asChild:!0,children:(0,x.jsxs)(p,{size:`sm`,variant:`outline`,disabled:!Y||z!==null,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,x.jsx)(ge,{className:`h-4 w-4 mr-1`}),z===`reject`?`Rejecting…`:`Reject`]})}),(0,x.jsxs)(ye,{children:[(0,x.jsxs)(f,{children:[(0,x.jsx)(Ce,{children:`Reject this request?`}),(0,x.jsxs)(De,{children:[`This will mark the request as rejected and notify the submitter.`,M.current_step_index!=null&&M.current_step_index>0?` If the process is multi-step, it returns to the previous step.`:``]})]}),(0,x.jsxs)(Ie,{children:[(0,x.jsx)(Ne,{children:`Cancel`}),(0,x.jsx)(h,{onClick:()=>J(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Reject`})]})]})]}),(0,x.jsxs)(p,{size:`sm`,variant:`outline`,onClick:()=>J(`recall`),disabled:!et||z!==null,children:[(0,x.jsx)(le,{className:`h-4 w-4 mr-1`}),z===`recall`?`Recalling…`:`Recall`]})]}),!Y&&!et&&(0,x.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`You are not in the pending approvers list and did not submit this request. Use the override above to act as another identity (e.g. `,(0,x.jsx)(`code`,{children:`role:sales_manager`}),`).`]})]})]})]}):null]})})]})}export{D as ApprovalsInboxPage};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{At as r,Bt as i,F as a,Ft as ee,Ht as te,I as o,It as ne,Kn as s,Lt as c,Mt as re,Nt as ie,Oi as l,Pt as ae,Qn as u,Rt as oe,Vo as d,Vt as f,_i as se,at as p,ct as m,en as h,in as g,it as _,mr as v,nr as ce,ot as y,qn as b,rr as le,rt as ue,st as x,vi as S,xr as C,z as w,zt as T}from"./ui-components-CIdYg6m3.js";var E=e(n(),1),D=t(),de=`${``.replace(/\/$/,``)}/api/v1`,fe=[`create`,`update`,`delete`,`restore`,`login`,`logout`,`permission_change`,`config_change`,`export`,`import`],O={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`},k=50;function A(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function j(e,t=24){return e?e.length>t?`${e.slice(0,t-1)}…`:e:`—`}function M(e){if(!e)return``;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function N(){let[e,t]=(0,E.useState)([]),[n,N]=(0,E.useState)(!1),[P,F]=(0,E.useState)(null),[I,L]=(0,E.useState)(`all`),[R,z]=(0,E.useState)(``),[B,V]=(0,E.useState)(``),[H,U]=(0,E.useState)(``),[W,G]=(0,E.useState)(``),[K,q]=(0,E.useState)(0),[J,Y]=(0,E.useState)(!1),[X,Z]=(0,E.useState)(null),Q=(0,E.useCallback)(async()=>{N(!0),F(null);try{let e={};I&&I!==`all`&&(e.action=I),R.trim()&&(e.object_name=R.trim()),B.trim()&&(e.user_id=B.trim()),H&&(e.created_at={...e.created_at||{},$gte:H}),W&&(e.created_at={...e.created_at||{},$lte:`${W}T23:59:59`});let n=new URLSearchParams;Object.keys(e).length>0&&n.set(`$filter`,JSON.stringify(e)),n.set(`$orderby`,`created_at desc`),n.set(`$top`,`51`),n.set(`$skip`,String(K*k));let r=await fetch(`${de}/data/sys_audit_log?${n.toString()}`,{credentials:`include`});if(!r.ok){let e=await r.text().catch(()=>``);throw Error(`HTTP ${r.status}: ${e.slice(0,200)||r.statusText}`)}let i=await r.json(),a=Array.isArray(i)?i:Array.isArray(i?.records)?i.records:Array.isArray(i?.data)?i.data:[];Y(a.length>k),t(a.slice(0,k))}catch(e){console.warn(`[AuditLogPage] load failed:`,e),F(e?.message||`Failed to load audit log`),t([]),Y(!1)}finally{N(!1)}},[I,R,B,H,W,K]);(0,E.useEffect)(()=>{Q()},[Q]);let pe=(0,E.useCallback)(()=>{L(`all`),z(``),V(``),U(``),G(``),q(0)},[]),$=(0,E.useMemo)(()=>{let e=0;return I!==`all`&&(e+=1),R.trim()&&(e+=1),B.trim()&&(e+=1),H&&(e+=1),W&&(e+=1),e},[I,R,B,H,W]);return(0,D.jsxs)(`div`,{className:`p-6 space-y-4 max-w-screen-2xl mx-auto`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsx)(S,{className:`h-6 w-6 text-muted-foreground`}),(0,D.jsxs)(`div`,{className:`flex-1`,children:[(0,D.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Audit Log`}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Read-only system activity and record changes. Newest first.`})]}),(0,D.jsxs)(v,{variant:`outline`,size:`sm`,onClick:Q,disabled:n,children:[(0,D.jsx)(l,{className:`h-4 w-4 mr-1 ${n?`animate-spin`:``}`}),`Refresh`]})]}),(0,D.jsx)(s,{children:(0,D.jsxs)(b,{className:`p-4 grid grid-cols-1 md:grid-cols-5 gap-3`,children:[(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(g,{className:`text-xs`,children:`Action`}),(0,D.jsxs)(oe,{value:I,onValueChange:e=>{L(e),q(0)},children:[(0,D.jsx)(f,{className:`h-9`,children:(0,D.jsx)(te,{})}),(0,D.jsxs)(T,{children:[(0,D.jsx)(i,{value:`all`,children:`All actions`}),fe.map(e=>(0,D.jsx)(i,{value:e,children:e},e))]})]})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(g,{className:`text-xs`,children:`Object`}),(0,D.jsx)(h,{placeholder:`e.g. account`,value:R,onChange:e=>{z(e.target.value),q(0)},className:`h-9`})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(g,{className:`text-xs`,children:`Actor (user id)`}),(0,D.jsx)(h,{placeholder:`user id`,value:B,onChange:e=>{V(e.target.value),q(0)},className:`h-9`})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(g,{className:`text-xs`,children:`From`}),(0,D.jsx)(h,{type:`date`,value:H,onChange:e=>{U(e.target.value),q(0)},className:`h-9`})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(g,{className:`text-xs`,children:`To`}),(0,D.jsx)(h,{type:`date`,value:W,onChange:e=>{G(e.target.value),q(0)},className:`h-9`})]}),$>0&&(0,D.jsx)(`div`,{className:`md:col-span-5 flex justify-end`,children:(0,D.jsxs)(v,{variant:`ghost`,size:`sm`,onClick:pe,children:[(0,D.jsx)(C,{className:`h-4 w-4 mr-1`}),`Clear filters (`,$,`)`]})})]})}),P&&(0,D.jsxs)(ce,{variant:`destructive`,children:[(0,D.jsx)(d,{className:`h-4 w-4`}),(0,D.jsx)(le,{children:P})]}),(0,D.jsx)(s,{children:(0,D.jsx)(b,{className:`p-0`,children:n&&e.length===0?(0,D.jsx)(`div`,{className:`p-6 space-y-2`,children:Array.from({length:6}).map((e,t)=>(0,D.jsx)(r,{className:`h-9 w-full`},t))}):e.length===0?(0,D.jsx)(`div`,{className:`p-12`,children:(0,D.jsxs)(a,{children:[(0,D.jsx)(se,{className:`h-8 w-8 text-muted-foreground mb-3`}),(0,D.jsx)(w,{children:`No audit entries`}),(0,D.jsx)(o,{children:$>0?`Try clearing filters or widening the date range.`:`Events will appear here once tracked objects are modified.`})]})}):(0,D.jsxs)(ue,{children:[(0,D.jsx)(x,{children:(0,D.jsxs)(m,{children:[(0,D.jsx)(y,{className:`w-[180px]`,children:`Timestamp`}),(0,D.jsx)(y,{className:`w-[130px]`,children:`Action`}),(0,D.jsx)(y,{children:`Object`}),(0,D.jsx)(y,{children:`Record`}),(0,D.jsx)(y,{children:`Actor`}),(0,D.jsx)(y,{className:`w-[130px]`,children:`IP`})]})}),(0,D.jsx)(_,{children:e.map(e=>{let t=O[e.action||``]||`outline`;return(0,D.jsxs)(m,{className:`cursor-pointer`,onClick:()=>Z(e),children:[(0,D.jsx)(p,{className:`font-mono text-xs`,children:A(e.created_at)}),(0,D.jsx)(p,{children:(0,D.jsx)(u,{variant:t,children:e.action||`—`})}),(0,D.jsx)(p,{children:e.object_name||`—`}),(0,D.jsx)(p,{className:`font-mono text-xs`,children:j(e.record_id,18)}),(0,D.jsx)(p,{className:`font-mono text-xs`,children:j(e.user_id,18)}),(0,D.jsx)(p,{className:`font-mono text-xs`,children:e.ip_address||`—`})]},e.id)})})]})})}),(e.length>0||K>0)&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-sm text-muted-foreground`,children:[(0,D.jsxs)(`span`,{children:[`Page `,K+1,J?``:` · end`]}),(0,D.jsxs)(`div`,{className:`flex gap-2`,children:[(0,D.jsx)(v,{variant:`outline`,size:`sm`,disabled:K===0||n,onClick:()=>q(e=>Math.max(0,e-1)),children:`Previous`}),(0,D.jsx)(v,{variant:`outline`,size:`sm`,disabled:!J||n,onClick:()=>q(e=>e+1),children:`Next`})]})]}),(0,D.jsx)(re,{open:!!X,onOpenChange:e=>!e&&Z(null),children:(0,D.jsxs)(ie,{side:`right`,className:`sm:max-w-2xl w-full overflow-y-auto`,children:[(0,D.jsxs)(ee,{children:[(0,D.jsxs)(ne,{className:`flex items-center gap-2`,children:[(0,D.jsx)(u,{variant:X&&O[X.action||``]||`outline`,children:X?.action||`—`}),X?.object_name||`Audit Event`]}),(0,D.jsx)(ae,{children:X?.id?(0,D.jsx)(`span`,{className:`font-mono text-xs`,children:X.id}):null})]}),X&&(0,D.jsxs)(`div`,{className:`mt-6 space-y-5`,children:[(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-sm`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Timestamp`}),(0,D.jsx)(`div`,{className:`font-mono`,children:A(X.created_at)})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`IP Address`}),(0,D.jsx)(`div`,{className:`font-mono`,children:X.ip_address||`—`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Actor (user_id)`}),(0,D.jsx)(`div`,{className:`font-mono break-all`,children:X.user_id||`—`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Tenant`}),(0,D.jsx)(`div`,{className:`font-mono break-all`,children:X.tenant_id||`—`})]}),(0,D.jsxs)(`div`,{className:`col-span-2`,children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Target record`}),(0,D.jsxs)(`div`,{className:`font-mono text-sm break-all`,children:[X.object_name||`—`,` / `,X.record_id||`—`]})]}),X.user_agent&&(0,D.jsxs)(`div`,{className:`col-span-2`,children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`User Agent`}),(0,D.jsx)(`div`,{className:`font-mono text-xs break-all`,children:X.user_agent})]})]}),(X.old_value||X.new_value)&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(c,{}),(0,D.jsxs)(`div`,{className:`space-y-3`,children:[(0,D.jsx)(`div`,{className:`text-sm font-medium`,children:`Change payload`}),X.old_value&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground mb-1`,children:`Before`}),(0,D.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-64 overflow-auto`,children:M(X.old_value)})]}),X.new_value&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground mb-1`,children:`After`}),(0,D.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-64 overflow-auto`,children:M(X.new_value)})]})]})]}),X.metadata&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(c,{}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-sm font-medium mb-2`,children:`Metadata`}),(0,D.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-48 overflow-auto`,children:M(X.metadata)})]})]})]})]})})]})}export{N as AuditLogPage};
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{$o as r,Ai as i,At as a,Bt as o,F as ee,Ft as s,Ht as c,I as te,It as ne,Kn as l,Lt as u,Mt as re,Nt as ie,Pt as ae,Qn as d,Rt as f,Vt as p,at as m,ct as h,en as g,in as _,it as oe,mr as v,nr as se,ot as y,qn as b,rr as ce,rt as le,st as ue,vi as x,xr as S,yi as C,z as w,zt as T}from"./ui-components-D0tUqjB3.js";var E=e(n(),1),D=t(),de=`${``.replace(/\/$/,``)}/api/v1`,fe=[`create`,`update`,`delete`,`restore`,`login`,`logout`,`permission_change`,`config_change`,`export`,`import`],O={create:`default`,update:`secondary`,delete:`destructive`,restore:`outline`,login:`outline`,logout:`outline`,permission_change:`secondary`,config_change:`secondary`,export:`outline`,import:`outline`},k=50;function A(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function j(e,t=24){return e?e.length>t?`${e.slice(0,t-1)}…`:e:`—`}function M(e){if(!e)return``;try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}}function N(){let[e,t]=(0,E.useState)([]),[n,N]=(0,E.useState)(!1),[P,F]=(0,E.useState)(null),[I,L]=(0,E.useState)(`all`),[R,z]=(0,E.useState)(``),[B,V]=(0,E.useState)(``),[H,U]=(0,E.useState)(``),[W,G]=(0,E.useState)(``),[K,q]=(0,E.useState)(0),[J,Y]=(0,E.useState)(!1),[X,Z]=(0,E.useState)(null),Q=(0,E.useCallback)(async()=>{N(!0),F(null);try{let e={};I&&I!==`all`&&(e.action=I),R.trim()&&(e.object_name=R.trim()),B.trim()&&(e.user_id=B.trim()),H&&(e.created_at={...e.created_at||{},$gte:H}),W&&(e.created_at={...e.created_at||{},$lte:`${W}T23:59:59`});let n=new URLSearchParams;Object.keys(e).length>0&&n.set(`$filter`,JSON.stringify(e)),n.set(`$orderby`,`created_at desc`),n.set(`$top`,`51`),n.set(`$skip`,String(K*k));let r=await fetch(`${de}/data/sys_audit_log?${n.toString()}`,{credentials:`include`});if(!r.ok){let e=await r.text().catch(()=>``);throw Error(`HTTP ${r.status}: ${e.slice(0,200)||r.statusText}`)}let i=await r.json(),a=Array.isArray(i)?i:Array.isArray(i?.records)?i.records:Array.isArray(i?.data)?i.data:[];Y(a.length>k),t(a.slice(0,k))}catch(e){console.warn(`[AuditLogPage] load failed:`,e),F(e?.message||`Failed to load audit log`),t([]),Y(!1)}finally{N(!1)}},[I,R,B,H,W,K]);(0,E.useEffect)(()=>{Q()},[Q]);let pe=(0,E.useCallback)(()=>{L(`all`),z(``),V(``),U(``),G(``),q(0)},[]),$=(0,E.useMemo)(()=>{let e=0;return I!==`all`&&(e+=1),R.trim()&&(e+=1),B.trim()&&(e+=1),H&&(e+=1),W&&(e+=1),e},[I,R,B,H,W]);return(0,D.jsxs)(`div`,{className:`p-6 space-y-4 max-w-screen-2xl mx-auto`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsx)(C,{className:`h-6 w-6 text-muted-foreground`}),(0,D.jsxs)(`div`,{className:`flex-1`,children:[(0,D.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Audit Log`}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Read-only system activity and record changes. Newest first.`})]}),(0,D.jsxs)(v,{variant:`outline`,size:`sm`,onClick:Q,disabled:n,children:[(0,D.jsx)(i,{className:`h-4 w-4 mr-1 ${n?`animate-spin`:``}`}),`Refresh`]})]}),(0,D.jsx)(l,{children:(0,D.jsxs)(b,{className:`p-4 grid grid-cols-1 md:grid-cols-5 gap-3`,children:[(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(_,{className:`text-xs`,children:`Action`}),(0,D.jsxs)(f,{value:I,onValueChange:e=>{L(e),q(0)},children:[(0,D.jsx)(p,{className:`h-9`,children:(0,D.jsx)(c,{})}),(0,D.jsxs)(T,{children:[(0,D.jsx)(o,{value:`all`,children:`All actions`}),fe.map(e=>(0,D.jsx)(o,{value:e,children:e},e))]})]})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(_,{className:`text-xs`,children:`Object`}),(0,D.jsx)(g,{placeholder:`e.g. account`,value:R,onChange:e=>{z(e.target.value),q(0)},className:`h-9`})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(_,{className:`text-xs`,children:`Actor (user id)`}),(0,D.jsx)(g,{placeholder:`user id`,value:B,onChange:e=>{V(e.target.value),q(0)},className:`h-9`})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(_,{className:`text-xs`,children:`From`}),(0,D.jsx)(g,{type:`date`,value:H,onChange:e=>{U(e.target.value),q(0)},className:`h-9`})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsx)(_,{className:`text-xs`,children:`To`}),(0,D.jsx)(g,{type:`date`,value:W,onChange:e=>{G(e.target.value),q(0)},className:`h-9`})]}),$>0&&(0,D.jsx)(`div`,{className:`md:col-span-5 flex justify-end`,children:(0,D.jsxs)(v,{variant:`ghost`,size:`sm`,onClick:pe,children:[(0,D.jsx)(S,{className:`h-4 w-4 mr-1`}),`Clear filters (`,$,`)`]})})]})}),P&&(0,D.jsxs)(se,{variant:`destructive`,children:[(0,D.jsx)(r,{className:`h-4 w-4`}),(0,D.jsx)(ce,{children:P})]}),(0,D.jsx)(l,{children:(0,D.jsx)(b,{className:`p-0`,children:n&&e.length===0?(0,D.jsx)(`div`,{className:`p-6 space-y-2`,children:Array.from({length:6}).map((e,t)=>(0,D.jsx)(a,{className:`h-9 w-full`},t))}):e.length===0?(0,D.jsx)(`div`,{className:`p-12`,children:(0,D.jsxs)(ee,{children:[(0,D.jsx)(x,{className:`h-8 w-8 text-muted-foreground mb-3`}),(0,D.jsx)(w,{children:`No audit entries`}),(0,D.jsx)(te,{children:$>0?`Try clearing filters or widening the date range.`:`Events will appear here once tracked objects are modified.`})]})}):(0,D.jsxs)(le,{children:[(0,D.jsx)(ue,{children:(0,D.jsxs)(h,{children:[(0,D.jsx)(y,{className:`w-[180px]`,children:`Timestamp`}),(0,D.jsx)(y,{className:`w-[130px]`,children:`Action`}),(0,D.jsx)(y,{children:`Object`}),(0,D.jsx)(y,{children:`Record`}),(0,D.jsx)(y,{children:`Actor`}),(0,D.jsx)(y,{className:`w-[130px]`,children:`IP`})]})}),(0,D.jsx)(oe,{children:e.map(e=>{let t=O[e.action||``]||`outline`;return(0,D.jsxs)(h,{className:`cursor-pointer`,onClick:()=>Z(e),children:[(0,D.jsx)(m,{className:`font-mono text-xs`,children:A(e.created_at)}),(0,D.jsx)(m,{children:(0,D.jsx)(d,{variant:t,children:e.action||`—`})}),(0,D.jsx)(m,{children:e.object_name||`—`}),(0,D.jsx)(m,{className:`font-mono text-xs`,children:j(e.record_id,18)}),(0,D.jsx)(m,{className:`font-mono text-xs`,children:j(e.user_id,18)}),(0,D.jsx)(m,{className:`font-mono text-xs`,children:e.ip_address||`—`})]},e.id)})})]})})}),(e.length>0||K>0)&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-sm text-muted-foreground`,children:[(0,D.jsxs)(`span`,{children:[`Page `,K+1,J?``:` · end`]}),(0,D.jsxs)(`div`,{className:`flex gap-2`,children:[(0,D.jsx)(v,{variant:`outline`,size:`sm`,disabled:K===0||n,onClick:()=>q(e=>Math.max(0,e-1)),children:`Previous`}),(0,D.jsx)(v,{variant:`outline`,size:`sm`,disabled:!J||n,onClick:()=>q(e=>e+1),children:`Next`})]})]}),(0,D.jsx)(re,{open:!!X,onOpenChange:e=>!e&&Z(null),children:(0,D.jsxs)(ie,{side:`right`,className:`sm:max-w-2xl w-full overflow-y-auto`,children:[(0,D.jsxs)(s,{children:[(0,D.jsxs)(ne,{className:`flex items-center gap-2`,children:[(0,D.jsx)(d,{variant:X&&O[X.action||``]||`outline`,children:X?.action||`—`}),X?.object_name||`Audit Event`]}),(0,D.jsx)(ae,{children:X?.id?(0,D.jsx)(`span`,{className:`font-mono text-xs`,children:X.id}):null})]}),X&&(0,D.jsxs)(`div`,{className:`mt-6 space-y-5`,children:[(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-sm`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Timestamp`}),(0,D.jsx)(`div`,{className:`font-mono`,children:A(X.created_at)})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`IP Address`}),(0,D.jsx)(`div`,{className:`font-mono`,children:X.ip_address||`—`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Actor (user_id)`}),(0,D.jsx)(`div`,{className:`font-mono break-all`,children:X.user_id||`—`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Tenant`}),(0,D.jsx)(`div`,{className:`font-mono break-all`,children:X.tenant_id||`—`})]}),(0,D.jsxs)(`div`,{className:`col-span-2`,children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`Target record`}),(0,D.jsxs)(`div`,{className:`font-mono text-sm break-all`,children:[X.object_name||`—`,` / `,X.record_id||`—`]})]}),X.user_agent&&(0,D.jsxs)(`div`,{className:`col-span-2`,children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`User Agent`}),(0,D.jsx)(`div`,{className:`font-mono text-xs break-all`,children:X.user_agent})]})]}),(X.old_value||X.new_value)&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(u,{}),(0,D.jsxs)(`div`,{className:`space-y-3`,children:[(0,D.jsx)(`div`,{className:`text-sm font-medium`,children:`Change payload`}),X.old_value&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground mb-1`,children:`Before`}),(0,D.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-64 overflow-auto`,children:M(X.old_value)})]}),X.new_value&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-xs text-muted-foreground mb-1`,children:`After`}),(0,D.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-64 overflow-auto`,children:M(X.new_value)})]})]})]}),X.metadata&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(u,{}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-sm font-medium mb-2`,children:`Metadata`}),(0,D.jsx)(`pre`,{className:`rounded-md bg-muted p-3 text-xs font-mono whitespace-pre-wrap max-h-48 overflow-auto`,children:M(X.metadata)})]})]})]})]})})]})}export{N as AuditLogPage};
@@ -1 +1 @@
1
- import"./rolldown-runtime-CMxvf4Kt.js";import{h as e,m as t,r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{F as i,I as a,z as o}from"./ui-components-CIdYg6m3.js";import{t as s}from"./index-DWtLSzKK.js";r();var c=n();function l({extraProps:n}={}){let r=t(),[l]=e(),u=r.ns,d=r.name,f=u&&d?`${u}:${d}`:u??``,p=s(f);if(!p)return(0,c.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,c.jsxs)(i,{children:[(0,c.jsx)(o,{children:`Component not registered`}),(0,c.jsxs)(a,{children:[`No component is registered for `,(0,c.jsx)(`code`,{className:`font-mono`,children:f||`(empty)`}),`. Ensure the plugin that provides this surface is installed and has called`,(0,c.jsx)(`code`,{className:`font-mono`,children:` registerAppComponent()`}),`.`]})]})});let m={};for(let[e,t]of l.entries())m[e]=t;let h=p.component;return(0,c.jsx)(h,{...m,...n??{}})}export{l as ComponentNavView,l as default};
1
+ import"./rolldown-runtime-CMxvf4Kt.js";import{h as e,m as t,r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{F as i,I as a,z as o}from"./ui-components-D0tUqjB3.js";import{t as s}from"./index-D8443YMB.js";r();var c=n();function l({extraProps:n}={}){let r=t(),[l]=e(),u=r.ns,d=r.name,f=u&&d?`${u}:${d}`:u??``,p=s(f);if(!p)return(0,c.jsx)(`div`,{className:`h-full flex items-center justify-center p-8`,children:(0,c.jsxs)(i,{children:[(0,c.jsx)(o,{children:`Component not registered`}),(0,c.jsxs)(a,{children:[`No component is registered for `,(0,c.jsx)(`code`,{className:`font-mono`,children:f||`(empty)`}),`. Ensure the plugin that provides this surface is installed and has called`,(0,c.jsx)(`code`,{className:`font-mono`,children:` registerAppComponent()`}),`.`]})]})});let m={};for(let[e,t]of l.entries())m[e]=t;let h=p.component;return(0,c.jsx)(h,{...m,...n??{}})}export{l as ComponentNavView,l as default};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{r}from"./framework-Bsl5NTfe.js";import{Bt as i,Ht as a,Rt as o,Vt as s,mi as c,mr as l,ni as u,x as d,zt as f}from"./ui-components-D0tUqjB3.js";import{d as p,l as m,r as h,t as g,u as _}from"./plugin-chatbot-MXXPNrIm.js";import{n as v}from"./index-D8443YMB.js";var y=e(n(),1),b=t(),x={data_chat:{zh:`数据助手`,en:`Data Assistant`},metadata_assistant:{zh:`元数据开发助手`,en:`Metadata Assistant`}};function S(e,t,n){let r=t?x[t]:void 0;return r?e?r.zh:r.en:n}function C(e,t,n,r,i){let a=(e??``).toLowerCase().startsWith(`zh`),o=S(a,n,r),s=i.slice(0,2).map(e=>e.label||e.name);if(a){let e=[s[0]?`查询最近创建的${s[0]}`:`帮我查询最近的数据`,s[0]?`统计${s[0]}的总数量`:`统计各对象的记录数量`,s[1]?`${s[1]}有哪些字段?`:`当前应用里有哪些数据对象?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`你好,我是${o}`,emptyDescription:`随时帮你查询和分析「${t}」中的数据。试试下面的问题,或直接输入你的需求。`,clear:`清空对话`,sendHint:`发送`},placeholder:`向${o}提问…`,loadingPlaceholder:`正在加载助手…`,title:`${t} 智能助手`,newChat:`开启新对话`,share:`分享对话`,suggestions:e}}let c=[s[0]?`Show the latest ${s[0]}`:`Show my most recent records`,s[0]?`How many ${s[0]} are there?`:`Count records by status`,s[1]?`What fields does ${s[1]} have?`:`What data can I work with here?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`Hi, I'm ${o}`,emptyDescription:`I can help you query and analyze your ${t} data. Try a prompt below, or just type your question.`,clear:`Clear`,sendHint:`to send`},placeholder:`Ask ${o}...`,loadingPlaceholder:`Loading assistant...`,title:`${t} Assistant`,newChat:`New chat`,share:`Share conversation`,suggestions:c}}var w=`/api/v1/ai`;function T(e){if(e)return e.replace(/\/$/,``);let t={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},n=t.VITE_AI_BASE_URL;return n?n.replace(/\/$/,``):`${(t.VITE_SERVER_URL??``).replace(/\/$/,``)}${w}`}function E({appLabel:e,appName:t,objects:n,agents:m,agentsLoading:_,activeAgent:v,onAgentChange:x,showAgentPicker:S,chatApi:w,apiBase:T,defaultOpen:E=!1,conversationId:D,initialMessages:O}){let{language:k}=r(),A=y.useMemo(()=>!O||O.length===0?[]:O.map(e=>({id:e.id,role:e.role,content:e.parts.map(e=>e.text).join(``)})),[O]),j=y.useMemo(()=>m.find(e=>e.name===v)?.label??v??e,[m,v,e]),M=y.useMemo(()=>C(k,e,v,j,n),[k,e,v,j,n]),{messages:N,isLoading:P,error:F,sendMessage:I,stop:L,reload:R,clear:z}=p({api:w,conversationId:D,body:{context:{activeApp:e,appName:t,objects:n.map(e=>({name:e.name,label:e.label})),agentName:v}},initialMessages:A,autoResponse:!w,autoResponseText:n.length>0?`I can help you work with ${n.map(e=>e.label||e.name).join(`, `)}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600}),B=g({messages:N,apiBase:T,continueConversation:e=>{I(e)}}),V=S&&m.length>1?(0,b.jsxs)(o,{value:v,onValueChange:x,disabled:_,children:[(0,b.jsx)(s,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,b.jsx)(a,{placeholder:`Choose agent...`})}),(0,b.jsx)(f,{align:`end`,children:m.map(e=>(0,b.jsxs)(i,{value:e.name,className:`text-xs`,children:[(0,b.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,b.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null,[H,U]=y.useState(!1),W=y.useMemo(()=>T.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[T]),G=(0,b.jsxs)(b.Fragment,{children:[N.length>0?(0,b.jsx)(l,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":M.newChat,title:M.newChat,"data-testid":`floating-chatbot-new`,onClick:z,children:(0,b.jsx)(u,{className:`h-4 w-4`})}):null,D?(0,b.jsx)(l,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":M.share,title:M.share,"data-testid":`floating-chatbot-share`,onClick:()=>U(!0),children:(0,b.jsx)(c,{className:`h-4 w-4`})}):null]});return(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(h,{floatingConfig:{position:`bottom-right`,defaultOpen:E,panelWidth:420,panelHeight:560,title:M.title,triggerSize:56},headerExtra:V,headerActions:G,messages:N,labels:M.labels,showAvatars:!0,hideClearBar:!0,assistantAvatarFallback:M.agentLabel,suggestions:N.length===0?M.suggestions:void 0,placeholder:v?M.placeholder:_?M.loadingPlaceholder:M.placeholder,onSendMessage:e=>I(e),onClear:z,onStop:P?L:void 0,onReload:R,isLoading:P,error:F,enableMarkdown:!0,onToolApprove:B.decide,toolDecisions:B.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`}),D&&(0,b.jsx)(d,{open:H,onOpenChange:U,objectName:`ai_conversations`,recordId:D,recordLabel:`this conversation`,apiBase:W})]})}function D({appLabel:e,appName:t,objects:n,apiBase:r,defaultAgent:i,showAgentPicker:a,defaultOpen:o=!1,userId:s}){let c=y.useMemo(()=>T(r),[r]),l={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},u=l.VITE_AI_DEFAULT_AGENT,d=a??l.VITE_AI_SHOW_AGENT_PICKER===`true`,{agents:f,isLoading:p,error:h}=_({apiBase:c}),[g,x]=y.useState(void 0);y.useEffect(()=>{if(!g&&f.length>0){let e=m(f,i??u);e&&x(e)}},[f,g,i,u]);let S=g?`${c}/agents/${encodeURIComponent(g)}/chat`:void 0,{conversationId:C,initialMessages:w}=v({userId:s,scope:g,apiBase:c});return(0,b.jsx)(E,{appLabel:e,appName:t,objects:n,agents:f,agentsLoading:p,agentsError:h,activeAgent:g,onAgentChange:x,showAgentPicker:d,chatApi:S,apiBase:c,defaultOpen:o,conversationId:C,initialMessages:w},`${S??`local`}:${C??`pending`}`)}export{D as default};
@@ -1 +1 @@
1
- import{f as e,m as t,r as n}from"./vendor-react-CyVA1SE-.js";import{Cr as r,Jn as i,Kn as a,Wr as o,Xn as s,Yn as c,ao as l,qn as u}from"./ui-components-CIdYg6m3.js";var d=n();function f(){let n=e(),{appName:f}=t(),p=f?`/apps/${f}`:``,m=[{title:`API Console`,description:`Inspect and exercise REST endpoints with auto-discovered services`,icon:o,href:`${p}/developer/api-console`},{title:`Flow Runs`,description:`Trigger flows with sample inputs and inspect recent run history`,icon:r,href:`${p}/developer/flow-runs`},{title:`Public Forms`,description:`Publish, share, and embed FormViews available to anonymous users`,icon:l,href:`${p}/developer/public-forms`}];return(0,d.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,d.jsxs)(`div`,{className:`min-w-0`,children:[(0,d.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Developer`}),(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Tools for building, debugging, and sharing ObjectStack apps`})]}),(0,d.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:m.map(e=>{let t=e.icon;return(0,d.jsxs)(a,{className:`cursor-pointer transition-colors hover:bg-accent/50`,onClick:()=>n(e.href),"data-testid":`hub-card-${e.title.toLowerCase().replace(/\s+/g,`-`)}`,role:`link`,tabIndex:0,"aria-label":`${e.title}: ${e.description}`,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.href))},children:[(0,d.jsxs)(c,{className:`flex flex-row items-center gap-3 pb-2`,children:[(0,d.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,d.jsx)(t,{className:`h-5 w-5`})}),(0,d.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,d.jsx)(s,{className:`text-base`,children:e.title}),(0,d.jsx)(i,{className:`text-xs`,children:e.description})]})]}),(0,d.jsx)(u,{className:`pt-0`})]},e.title)})})]})}export{f as DeveloperHubPage};
1
+ import{f as e,m as t,r as n}from"./vendor-react-CyVA1SE-.js";import{Cr as r,Jn as i,Kn as a,Wr as o,Xn as s,Yn as c,po as l,qn as u}from"./ui-components-D0tUqjB3.js";var d=n();function f(){let n=e(),{appName:f}=t(),p=f?`/apps/${f}`:``,m=[{title:`API Console`,description:`Inspect and exercise REST endpoints with auto-discovered services`,icon:o,href:`${p}/developer/api-console`},{title:`Flow Runs`,description:`Trigger flows with sample inputs and inspect recent run history`,icon:r,href:`${p}/developer/flow-runs`},{title:`Public Forms`,description:`Publish, share, and embed FormViews available to anonymous users`,icon:l,href:`${p}/developer/public-forms`}];return(0,d.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,d.jsxs)(`div`,{className:`min-w-0`,children:[(0,d.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Developer`}),(0,d.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Tools for building, debugging, and sharing ObjectStack apps`})]}),(0,d.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:m.map(e=>{let t=e.icon;return(0,d.jsxs)(a,{className:`cursor-pointer transition-colors hover:bg-accent/50`,onClick:()=>n(e.href),"data-testid":`hub-card-${e.title.toLowerCase().replace(/\s+/g,`-`)}`,role:`link`,tabIndex:0,"aria-label":`${e.title}: ${e.description}`,onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),n(e.href))},children:[(0,d.jsxs)(c,{className:`flex flex-row items-center gap-3 pb-2`,children:[(0,d.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,d.jsx)(t,{className:`h-5 w-5`})}),(0,d.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,d.jsx)(s,{className:`text-base`,children:e.title}),(0,d.jsx)(i,{className:`text-xs`,children:e.description})]})]}),(0,d.jsx)(u,{className:`pt-0`})]},e.title)})})]})}export{f as DeveloperHubPage};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{S as r}from"./framework-Bsl5NTfe.js";import{$o as i,Ai as a,At as o,Bi as s,Bo as c,Cr as l,Ea as u,Ft as d,It as f,Jn as p,Kn as m,Mt as h,Nt as g,Pt as _,Q as v,Qn as y,Ut as b,Wo as x,Xn as S,Yn as C,Zo as w,at as T,ct as E,en as D,in as O,it as k,lt as A,mr as j,ot as M,qn as N,rt as P,st as F}from"./ui-components-D0tUqjB3.js";import"./index-D8443YMB.js";var I=e(n(),1),L=t();function R({status:e}){let t={success:{icon:w,cls:`text-emerald-600 border-emerald-300`},completed:{icon:w,cls:`text-emerald-600 border-emerald-300`},failed:{icon:x,cls:`text-red-600 border-red-300`},error:{icon:x,cls:`text-red-600 border-red-300`},running:{icon:u,cls:`text-blue-600 border-blue-300 animate-pulse`},pending:{icon:c,cls:`text-amber-600 border-amber-300`},skipped:{icon:i,cls:`text-muted-foreground`}}[e]??{icon:i,cls:`text-muted-foreground`},n=t.icon;return(0,L.jsxs)(y,{variant:`outline`,className:`text-[10px] font-mono inline-flex items-center gap-1 ${t.cls}`,children:[(0,L.jsx)(n,{className:`h-3 w-3`}),e]})}function z(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function B(e,t){switch(t){case`number`:{if(e===``)return;let t=Number(e);return Number.isNaN(t)?e:t}case`boolean`:return e===`true`;case`object`:case`list`:case`array`:if(e.trim()===``)return;try{return JSON.parse(e)}catch{return e}default:return e}}function V({data:e}){return(0,L.jsx)(`pre`,{className:`rounded border bg-muted/30 p-2 text-xs font-mono overflow-auto whitespace-pre-wrap break-all max-h-96`,children:JSON.stringify(e,null,2)})}function H(){let e=r()?.getClient?.(),[t,n]=(0,I.useState)([]),[i,s]=(0,I.useState)(!0),[c,u]=(0,I.useState)(null),[d,f]=(0,I.useState)(``),[h,g]=(0,I.useState)(0),_=(0,I.useCallback)(async()=>{if(!e?.meta?.getItems){u(`meta.getItems is not available on this client`),s(!1);return}s(!0),u(null);try{let t=await e.meta.getItems(`flow`),r=(Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[]).map(e=>({name:e?.spec?.name??e?.name,label:e?.spec?.label,spec:e?.spec??e,updatedAt:e?.updatedAt??e?.updated_at})).filter(e=>e.name);n(r),!d&&r.length>0&&f(r[0].name)}catch(e){u(e?.message??String(e))}finally{s(!1)}},[e,d]);(0,I.useEffect)(()=>{_()},[_]);let v=(0,I.useMemo)(()=>t.find(e=>e.name===d)??null,[t,d]);return(0,L.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 sm:p-6`,children:[(0,L.jsxs)(`div`,{className:`min-w-0`,children:[(0,L.jsxs)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight flex items-center gap-2`,children:[(0,L.jsx)(l,{className:`h-5 w-5`}),`Flow Runs`]}),(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Pick a flow, trigger a test run with sample inputs, and inspect recent run history`})]}),(0,L.jsxs)(m,{children:[(0,L.jsx)(C,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(S,{className:`text-base`,children:`Flow`}),(0,L.jsx)(p,{children:`Select a flow definition to test`})]}),(0,L.jsxs)(j,{variant:`outline`,size:`sm`,onClick:_,disabled:i,children:[(0,L.jsx)(a,{className:`h-3.5 w-3.5 mr-2 ${i?`animate-spin`:``}`}),`Refresh`]})]})}),(0,L.jsxs)(N,{children:[i&&(0,L.jsx)(o,{className:`h-9 w-72`}),c&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:c}),!i&&!c&&t.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No flow definitions found.`}),!i&&!c&&t.length>0&&(0,L.jsx)(`select`,{value:d,onChange:e=>f(e.target.value),className:`flex h-9 w-full max-w-md rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm focus:outline-none focus:ring-1 focus:ring-ring`,children:t.map(e=>(0,L.jsx)(`option`,{value:e.name,children:e.label?`${e.label} (${e.name})`:e.name},e.name))})]})]}),v&&(0,L.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,L.jsx)(U,{client:e,flow:v.spec,onExecuted:()=>g(e=>e+1)}),(0,L.jsx)(W,{client:e,flowName:v.name,refreshKey:h})]})]})}function U({client:e,flow:t,onExecuted:n}){let r=(0,I.useMemo)(()=>(t?.variables??[]).filter(e=>e?.isInput),[t]),[i,a]=(0,I.useState)({}),[o,c]=(0,I.useState)(!1),[l,d]=(0,I.useState)(null),[f,h]=(0,I.useState)(null);(0,I.useEffect)(()=>{a({}),d(null),h(null)},[t?.name]);let g=(e,t)=>a(n=>({...n,[e]:t}));return(0,L.jsxs)(m,{children:[(0,L.jsxs)(C,{className:`pb-3`,children:[(0,L.jsx)(S,{className:`text-base`,children:`Test Run`}),(0,L.jsx)(p,{children:`Provide input values and invoke the flow`})]}),(0,L.jsxs)(N,{className:`space-y-3`,children:[r.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This flow declares no input variables. Click Run to invoke with no parameters.`}),r.map(e=>(0,L.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,L.jsxs)(O,{htmlFor:`var-${e.name}`,className:`flex items-center gap-2`,children:[(0,L.jsx)(`span`,{className:`font-mono text-xs`,children:e.name}),(0,L.jsx)(y,{variant:`outline`,className:`text-[10px] font-mono`,children:e.type})]}),e.type===`boolean`?(0,L.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,L.jsx)(A,{id:`var-${e.name}`,checked:i[e.name]===`true`,onCheckedChange:t=>g(e.name,t?`true`:`false`)}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:i[e.name]===`true`?`true`:`false`})]}):e.type===`object`||e.type===`list`||e.type===`array`?(0,L.jsx)(v,{id:`var-${e.name}`,placeholder:`JSON ${e.type}`,value:i[e.name]??``,onChange:t=>g(e.name,t.target.value),className:`font-mono text-xs min-h-[80px]`}):(0,L.jsx)(D,{id:`var-${e.name}`,type:e.type===`number`?`number`:`text`,value:i[e.name]??``,onChange:t=>g(e.name,t.target.value)})]},e.name)),(0,L.jsx)(`div`,{className:`pt-1`,children:(0,L.jsxs)(j,{onClick:async()=>{if(!e?.automation?.execute){h(`automation.execute is not available on this client`);return}c(!0),h(null),d(null);try{let a={};for(let e of r){let t=i[e.name];t!==void 0&&(a[e.name]=B(t,e.type))}d(await e.automation.execute(t.name,{params:a})),n?.()}catch(e){h(e?.message??String(e))}finally{c(!1)}},disabled:o,size:`sm`,children:[o?(0,L.jsx)(u,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(s,{className:`h-3.5 w-3.5 mr-2`}),o?`Running…`:`Run Flow`]})}),(l||f)&&(0,L.jsxs)(`div`,{className:`pt-2 border-t mt-2 space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium`,children:[f||l?.success===!1?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(x,{className:`h-4 w-4 text-red-500`}),` Failed`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(w,{className:`h-4 w-4 text-emerald-500`}),` Result`]}),typeof l?.durationMs==`number`&&(0,L.jsxs)(y,{variant:`secondary`,className:`text-[10px] font-mono`,children:[l.durationMs,` ms`]})]}),f&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:f}),l&&(0,L.jsx)(V,{data:l})]})]})]})}function W({client:e,flowName:t,refreshKey:n}){let[r,i]=(0,I.useState)([]),[s,c]=(0,I.useState)(!0),[l,v]=(0,I.useState)(null),[x,w]=(0,I.useState)(null),[D,O]=(0,I.useState)(null),[A,B]=(0,I.useState)(!1),[H,U]=(0,I.useState)(null),W=(0,I.useCallback)(async()=>{if(!e?.automation?.listRuns){v(`automation.listRuns is not available on this client`),c(!1);return}c(!0),v(null);try{let n=await e.automation.listRuns(t,{limit:20});i(Array.isArray(n)?n:n?.items??n?.runs??[])}catch(e){v(e?.message??String(e))}finally{c(!1)}},[e,t]);(0,I.useEffect)(()=>{W()},[W,n]);let G=async n=>{w(n),O(null),U(null),B(!0);try{let r=await e.automation.getRun(t,n);O(r?.run??r)}catch(e){U(e?.message??String(e))}finally{B(!1)}};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(m,{children:[(0,L.jsx)(C,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(S,{className:`text-base`,children:`Recent Runs`}),(0,L.jsx)(p,{className:`font-mono text-xs`,children:t})]}),(0,L.jsxs)(j,{variant:`outline`,size:`sm`,onClick:W,disabled:s,children:[s?(0,L.jsx)(u,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(a,{className:`h-3.5 w-3.5 mr-2`}),`Refresh`]})]})}),(0,L.jsxs)(N,{children:[s&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(o,{className:`h-8 w-full`}),(0,L.jsx)(o,{className:`h-8 w-full`}),(0,L.jsx)(o,{className:`h-8 w-full`})]}),!s&&l&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:l}),!s&&!l&&r.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground py-6 text-center`,children:`No runs yet. Use the Test Run panel to invoke this flow.`}),!s&&!l&&r.length>0&&(0,L.jsxs)(P,{children:[(0,L.jsx)(F,{children:(0,L.jsxs)(E,{children:[(0,L.jsx)(M,{children:`Run`}),(0,L.jsx)(M,{children:`Status`}),(0,L.jsx)(M,{children:`Started`}),(0,L.jsx)(M,{className:`text-right`,children:`Duration`})]})}),(0,L.jsx)(k,{children:r.map(e=>(0,L.jsxs)(E,{className:`cursor-pointer`,onClick:()=>G(e.id),children:[(0,L.jsxs)(T,{className:`font-mono text-xs`,children:[e.id.slice(0,12),`…`]}),(0,L.jsx)(T,{children:(0,L.jsx)(R,{status:e.status})}),(0,L.jsx)(T,{className:`text-xs text-muted-foreground`,children:z(e.startedAt)}),(0,L.jsx)(T,{className:`text-right font-mono text-xs`,children:typeof e.durationMs==`number`?`${e.durationMs} ms`:`—`})]},e.id))})]})]})]}),(0,L.jsx)(h,{open:!!x,onOpenChange:e=>{e||(w(null),O(null))},children:(0,L.jsxs)(g,{side:`right`,className:`w-full sm:max-w-2xl p-0 flex flex-col`,children:[(0,L.jsxs)(d,{className:`p-4 border-b`,children:[(0,L.jsxs)(f,{className:`font-mono text-sm break-all`,children:[`Run `,x]}),(0,L.jsx)(_,{children:D&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(R,{status:D.status}),typeof D.durationMs==`number`&&(0,L.jsxs)(y,{variant:`secondary`,className:`text-[10px] font-mono`,children:[D.durationMs,` ms`]}),(0,L.jsx)(`span`,{className:`text-xs`,children:z(D.startedAt)})]})})]}),(0,L.jsxs)(b,{className:`flex-1 p-4`,children:[A&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(o,{className:`h-16 w-full`}),(0,L.jsx)(o,{className:`h-16 w-full`}),(0,L.jsx)(o,{className:`h-16 w-full`})]}),H&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:H}),!A&&D&&(0,L.jsx)(`div`,{className:`space-y-3`,children:Array.isArray(D.steps)&&D.steps.length>0?D.steps.map((e,t)=>(0,L.jsxs)(`div`,{className:`rounded-md border p-3 space-y-2`,children:[(0,L.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,L.jsxs)(`span`,{className:`text-muted-foreground font-mono text-xs`,children:[`#`,t+1]}),(0,L.jsx)(`span`,{className:`font-mono text-sm font-medium`,children:e.nodeLabel||e.nodeId}),e.nodeType&&(0,L.jsx)(y,{variant:`outline`,className:`text-[10px] font-mono`,children:e.nodeType}),(0,L.jsx)(R,{status:e.status}),typeof e.durationMs==`number`&&(0,L.jsxs)(y,{variant:`secondary`,className:`text-[10px] font-mono ml-auto`,children:[e.durationMs,` ms`]})]}),e.input!==void 0&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Input`}),(0,L.jsx)(V,{data:e.input})]}),e.output!==void 0&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Output`}),(0,L.jsx)(V,{data:e.output})]}),e.error&&(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[10px] uppercase text-red-500 mb-1`,children:`Error`}),(0,L.jsx)(V,{data:e.error})]})]},`${e.nodeId}-${t}`)):(0,L.jsxs)(`div`,{children:[(0,L.jsx)(`div`,{className:`text-[10px] uppercase text-muted-foreground mb-1`,children:`Run`}),(0,L.jsx)(V,{data:D})]})})]})]})})]})}export{H as FlowRunsPage};
@@ -0,0 +1 @@
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{f as r,o as i}from"./infrastructure-CFhpdDcd.js";import{$n as a,$o as o,Ea as s,Jn as c,Kn as l,Or as u,Qn as d,Ta as f,Xn as p,Yn as m,Zo as h,_ as g,en as _,er as v,in as y,ir as b,jr as x,mr as S,nr as C,pi as w,qn as T,rr as E,tr as D,xr as O}from"./ui-components-D0tUqjB3.js";var k=e(n(),1),A=t();function j(){let[e,t]=(0,k.useState)(!1);return(0,k.useEffect)(()=>{typeof window>`u`||t(new URLSearchParams(window.location.search).get(`recovery_needed`)===`true`)},[]),{recoveryNeeded:e,clear:()=>{if(typeof window>`u`)return;let e=new URL(window.location.href);e.searchParams.delete(`recovery_needed`),window.history.replaceState({},``,e.toString()),t(!1)}}}function M(){let{user:e,updateUser:t,isLoading:n,changePassword:f,setInitialPassword:M,hasLocalPassword:P}=r(),{upload:F}=g(),[I,L]=(0,k.useState)(e?.name??``),[R,z]=(0,k.useState)(!1),[B,V]=(0,k.useState)(null),H=(0,k.useRef)(null),[U,W]=(0,k.useState)(!1),[G,K]=(0,k.useState)(null),q=(0,k.useRef)(null),{recoveryNeeded:J,clear:Y}=j();return(0,k.useEffect)(()=>{L(e?.name??``)},[e?.name]),(0,k.useEffect)(()=>{if(!J)return;let e=setTimeout(()=>{q.current?.scrollIntoView({behavior:`smooth`,block:`start`})},200);return()=>clearTimeout(e)},[J]),e?(0,A.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-2xl`,children:[(0,A.jsxs)(`div`,{className:`min-w-0`,children:[(0,A.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Profile`}),(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage your account settings`})]}),J&&(0,A.jsxs)(C,{variant:`default`,className:`border-amber-300 bg-amber-50 text-amber-900 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-200`,"data-testid":`profile-recovery-banner`,children:[(0,A.jsx)(w,{className:`h-4 w-4`}),(0,A.jsx)(b,{children:`Set a recovery password`}),(0,A.jsx)(E,{children:`You signed in via single sign-on from the control plane. Set a local password below so you can still sign in to this environment directly if SSO ever becomes unavailable.`})]}),(0,A.jsx)(l,{children:(0,A.jsxs)(T,{className:`pt-6`,children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,A.jsxs)(a,{className:`h-16 w-16`,children:[(0,A.jsx)(D,{src:e.image??void 0,alt:e.name??`User`}),(0,A.jsx)(v,{className:`text-lg bg-primary text-primary-foreground`,children:i(e)})]}),(0,A.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,A.jsx)(`p`,{className:`text-lg font-semibold truncate`,children:e.name??`User`}),(0,A.jsx)(`p`,{className:`text-sm text-muted-foreground truncate`,children:e.email}),(0,A.jsx)(d,{variant:`secondary`,className:`mt-1`,children:e.role??`member`})]}),(0,A.jsxs)(`div`,{className:`flex flex-col gap-2 shrink-0`,children:[(0,A.jsx)(`input`,{ref:H,type:`file`,accept:`image/*`,className:`hidden`,onChange:async e=>{let n=e.target.files?.[0];if(H.current&&(H.current.value=``),n){W(!0),K(null);try{await t({image:(await F(n)).url})}catch(e){K(e instanceof Error?e.message:String(e))}finally{W(!1)}}},"data-testid":`profile-avatar-file`}),(0,A.jsxs)(S,{type:`button`,variant:`outline`,size:`sm`,disabled:U,onClick:()=>H.current?.click(),"data-testid":`profile-avatar-upload-btn`,children:[U?(0,A.jsx)(s,{className:`mr-2 h-4 w-4 animate-spin`}):(0,A.jsx)(x,{className:`mr-2 h-4 w-4`}),e.image?`Replace`:`Upload`]}),e.image&&(0,A.jsxs)(S,{type:`button`,variant:`ghost`,size:`sm`,disabled:U,onClick:async()=>{W(!0),K(null);try{await t({image:null})}catch(e){K(e instanceof Error?e.message:String(e))}finally{W(!1)}},"data-testid":`profile-avatar-remove-btn`,children:[(0,A.jsx)(O,{className:`mr-2 h-4 w-4`}),`Remove`]})]})]}),G&&(0,A.jsxs)(C,{variant:`destructive`,className:`mt-4`,children:[(0,A.jsx)(o,{className:`h-4 w-4`}),(0,A.jsx)(E,{children:G})]})]})}),(0,A.jsxs)(l,{children:[(0,A.jsxs)(m,{children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(u,{className:`h-4 w-4 text-muted-foreground`}),(0,A.jsx)(p,{className:`text-base sm:text-lg`,children:`Personal Information`})]}),(0,A.jsx)(c,{children:`Update your name and view account details`})]}),(0,A.jsx)(T,{children:(0,A.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),V(null),z(!1);try{await t({name:I}),z(!0)}catch(e){V(e instanceof Error?e.message:String(e))}},className:`space-y-4`,children:[B&&(0,A.jsxs)(C,{variant:`destructive`,children:[(0,A.jsx)(o,{className:`h-4 w-4`}),(0,A.jsx)(E,{children:B})]}),R&&(0,A.jsxs)(C,{children:[(0,A.jsx)(h,{className:`h-4 w-4 text-green-600`}),(0,A.jsx)(E,{className:`text-green-800 dark:text-green-400`,children:`Profile updated successfully.`})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(y,{htmlFor:`profile-name`,children:`Name`}),(0,A.jsx)(_,{id:`profile-name`,type:`text`,value:I,onChange:e=>L(e.target.value),required:!0,"aria-required":`true`,disabled:n})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(y,{htmlFor:`profile-email`,children:`Email`}),(0,A.jsx)(_,{id:`profile-email`,type:`email`,value:e.email,disabled:!0,className:`bg-muted text-muted-foreground`}),(0,A.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Email cannot be changed.`})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(y,{children:`Role`}),(0,A.jsx)(_,{type:`text`,value:e.role??`member`,disabled:!0,className:`bg-muted text-muted-foreground`})]}),(0,A.jsx)(S,{type:`submit`,disabled:n,className:`w-full sm:w-auto`,children:n?`Saving…`:`Save Changes`})]})})]}),(0,A.jsx)(`div`,{ref:q,children:(0,A.jsx)(N,{changePassword:f,setInitialPassword:M,hasLocalPassword:P,highlight:J,onPasswordSet:Y})})]}):null}function N({changePassword:e,setInitialPassword:t,hasLocalPassword:n,highlight:r,onPasswordSet:i}){let[a,s]=(0,k.useState)(null),[u,d]=(0,k.useState)(``),[g,v]=(0,k.useState)(``),[b,x]=(0,k.useState)(``),[w,D]=(0,k.useState)(!1),[O,j]=(0,k.useState)(null),[M,N]=(0,k.useState)(null);(0,k.useEffect)(()=>{let e=!1;return n().then(t=>{e||s(t)}).catch(()=>{e||s(!1)}),()=>{e=!0}},[n]);let P=()=>{d(``),v(``),x(``)},F=async n=>{if(n.preventDefault(),j(null),N(null),g.length<8){j(`Password must be at least 8 characters`);return}if(g!==b){j(`Passwords do not match`);return}D(!0);try{if(a){if(!u){j(`Enter your current password`),D(!1);return}await e(u,g),N(`Password changed.`)}else await t(g),N(`Local password set. You can now sign in with email and password on this environment.`),s(!0),i?.();P()}catch(e){j(e instanceof Error?e.message:String(e))}finally{D(!1)}},I=a===null;return(0,A.jsxs)(l,{className:r?`ring-2 ring-amber-300 dark:ring-amber-700`:void 0,children:[(0,A.jsxs)(m,{children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(f,{className:`h-4 w-4 text-muted-foreground`}),(0,A.jsx)(p,{className:`text-base sm:text-lg`,children:a?`Change Password`:`Set Local Password`})]}),(0,A.jsx)(c,{children:a?`Update the password you use to sign in to this environment.`:`You signed in via single sign-on. Set a local password to also sign in with email and password on this environment.`})]}),(0,A.jsx)(T,{children:(0,A.jsxs)(`form`,{onSubmit:F,className:`space-y-4 max-w-md`,children:[a&&(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(y,{htmlFor:`current-password`,children:`Current password`}),(0,A.jsx)(_,{id:`current-password`,type:`password`,autoComplete:`current-password`,value:u,onChange:e=>d(e.target.value),disabled:w||I,required:!0})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(y,{htmlFor:`new-password`,children:a?`New password`:`Password`}),(0,A.jsx)(_,{id:`new-password`,type:`password`,autoComplete:`new-password`,value:g,onChange:e=>v(e.target.value),disabled:w||I,minLength:8,required:!0})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(y,{htmlFor:`confirm-password`,children:`Confirm password`}),(0,A.jsx)(_,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,value:b,onChange:e=>x(e.target.value),disabled:w||I,minLength:8,required:!0})]}),O&&(0,A.jsxs)(C,{variant:`destructive`,children:[(0,A.jsx)(o,{className:`h-4 w-4`}),(0,A.jsx)(E,{children:O})]}),M&&(0,A.jsxs)(C,{children:[(0,A.jsx)(h,{className:`h-4 w-4`}),(0,A.jsx)(E,{children:M})]}),(0,A.jsx)(S,{type:`submit`,disabled:w||I,className:`w-full sm:w-auto`,children:w?`Saving…`:a?`Change password`:`Set password`})]})})]})}export{M as ProfilePage};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{x as r}from"./framework-DVkqUSPj.js";import{Bn as i,Co as a,Do as o,Ea as ee,Fi as te,Fn as s,In as c,Jn as ne,Kn as re,Ln as l,Oi as ie,Qn as ae,Rn as u,Xn as oe,Yn as se,at as d,ct as f,en as p,fo as ce,hi as le,in as m,it as ue,ji as de,mr as h,ot as g,qn as fe,rt as pe,st as me,zn as _}from"./ui-components-CIdYg6m3.js";import{o as v}from"./vendor-ui-utils-BbOuugky.js";import"./index-DWtLSzKK.js";var y=e(n(),1),b=t();function he(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function x(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``)}function S(){let e=r()?.getClient?.(),[t,n]=(0,y.useState)([]),[S,ge]=(0,y.useState)([]),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(null),[_e,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(!1),[ve,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(`thank-you`),[V,H]=(0,y.useState)(``),[U,W]=(0,y.useState)(``),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=async()=>{if(!e?.meta?.getItems){E(`meta.getItems is not available on this client`),w(!1);return}w(!0),E(null);try{let t=await e.meta.getItems(`view`),r=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[],i=[],a=[];for(let e of r){let t=e?.spec??e;if(!(t?.sections||t?.groups||t?.form||t?.type===`simple`||t?.type===`tabbed`||t?.type===`wizard`||t?.viewType===`form`))continue;let n=t?.sharing,r=n?.publicLink,o=he(r);n?.allowAnonymous&&o&&r?i.push({name:t?.name??e?.name,label:t?.label,object:t?.object,slug:o,publicLink:r,updatedAt:e?.updatedAt??e?.updated_at,spec:t}):a.push({name:t?.name??e?.name,label:t?.label,object:t?.object,spec:t})}n(i),ge(a)}catch(e){E(e?.message??String(e))}finally{w(!1)}};(0,y.useEffect)(()=>{Y()},[]);let ye=typeof window<`u`?window.location.origin:``,X=e=>`${ye}/console/f/${e}`,Z=e=>`<iframe src="${X(e)}" width="100%" height="640" frameborder="0" style="border:0;"></iframe>`,be=e=>`<iframe\n src={\`${X(e)}\`}\n title="Public form"\n style={{ width: '100%', height: 640, border: 0 }}\n/>`,Q=async(e,t)=>{try{await navigator.clipboard.writeText(t),v.success(`Copied ${e}`)}catch{v.error(`Clipboard unavailable`)}},xe=async()=>{if(!O||!A)return;let t=S.find(e=>e.name===O);if(!t)return;let n=x(A);if(!n){v.error(`Invalid slug`);return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};N(!0);try{await e.meta.saveItem(`view`,t.name,r),v.success(`Published ${t.name}`),D(!1),k(``),j(``),await Y()}catch(e){v.error(`Publish failed: ${e?.message??e}`)}finally{N(!1)}},Se=e=>{I(e),R(e.slug);let t=e.spec?.submitBehavior;B(t?.kind??`thank-you`),H(t?.title??``),W(t?.message??``),K(t?.url??``),P(!0)},Ce=async()=>{if(!F)return;let t=x(L);if(!t){v.error(`Invalid slug`);return}let n;switch(z){case`thank-you`:n={kind:`thank-you`},V&&(n.title=V),U&&(n.message=U);break;case`redirect`:if(!G){v.error(`Redirect URL is required`);return}n={kind:`redirect`,url:G};break;case`continue`:case`next-record`:n={kind:z};break}let r={...F.spec,sharing:{...F.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};J(!0);try{await e.meta.saveItem(`view`,F.name,r),v.success(`Saved ${F.name}`),P(!1),I(null),await Y()}catch(e){v.error(`Save failed: ${e?.message??e}`)}finally{J(!1)}},$=t.length>0;return(0,b.jsxs)(`div`,{className:`flex flex-1 flex-col gap-4 p-4 md:p-6 overflow-auto`,children:[(0,b.jsxs)(re,{children:[(0,b.jsxs)(se,{className:`flex flex-row items-start justify-between gap-4 space-y-0`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(oe,{className:`flex items-center gap-2`,children:[(0,b.jsx)(de,{className:`h-4 w-4`}),`Public Forms`]}),(0,b.jsx)(ne,{children:`Forms anyone can fill out — no login required. Publish a form to get a shareable link; submissions land directly in the bound object.`})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`default`,size:`sm`,onClick:()=>D(!0),disabled:S.length===0,title:S.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,b.jsx)(te,{className:`h-3.5 w-3.5`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Publish form…`})]}),(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:Y,disabled:C,children:[(0,b.jsx)(ie,{className:`h-3.5 w-3.5 ${C?`animate-spin`:``}`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,b.jsxs)(fe,{children:[T&&(0,b.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:T}),!C&&!$&&(0,b.jsxs)(`div`,{className:`rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground`,children:[(0,b.jsx)(`p`,{className:`font-medium text-foreground`,children:`No public forms yet`}),(0,b.jsxs)(`p`,{className:`mt-1`,children:[`Click `,(0,b.jsx)(`strong`,{children:`Publish form…`}),` above to share an existing form, or build a new one in Views & Apps and mark it public.`]})]}),$&&(0,b.jsxs)(pe,{children:[(0,b.jsx)(me,{children:(0,b.jsxs)(f,{children:[(0,b.jsx)(g,{children:`Name`}),(0,b.jsx)(g,{children:`Object`}),(0,b.jsx)(g,{children:`Slug`}),(0,b.jsx)(g,{children:`Public URL`}),(0,b.jsx)(g,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(ue,{children:t.map(e=>{let t=X(e.slug);return(0,b.jsxs)(f,{children:[(0,b.jsx)(d,{children:(0,b.jsxs)(`div`,{className:`flex flex-col`,children:[(0,b.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),(0,b.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.name})]})}),(0,b.jsx)(d,{children:e.object?(0,b.jsx)(ae,{variant:`secondary`,children:e.object}):(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,b.jsx)(d,{children:(0,b.jsx)(`code`,{className:`text-xs`,children:e.slug})}),(0,b.jsx)(d,{children:(0,b.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary underline-offset-2 hover:underline`,children:[t,(0,b.jsx)(ce,{className:`h-3 w-3`})]})}),(0,b.jsx)(d,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`inline-flex gap-1`,children:[(0,b.jsx)(h,{variant:`ghost`,size:`sm`,title:`Copy URL`,onClick:()=>Q(`URL`,t),children:(0,b.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(h,{variant:`ghost`,size:`sm`,title:`Copy <iframe> embed`,onClick:()=>Q(`iframe snippet`,Z(e.slug)),children:(0,b.jsx)(o,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(h,{variant:`ghost`,size:`sm`,title:`Copy React snippet`,onClick:()=>Q(`React snippet`,be(e.slug)),children:(0,b.jsx)(a,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(h,{variant:`ghost`,size:`sm`,title:`Edit sharing & post-submit behavior`,onClick:()=>Se(e),children:(0,b.jsx)(le,{className:`h-3.5 w-3.5`})})]})})]},e.name)})})]})]})]}),(0,b.jsx)(s,{open:_e,onOpenChange:D,children:(0,b.jsxs)(c,{className:`sm:max-w-md`,children:[(0,b.jsxs)(_,{children:[(0,b.jsx)(i,{children:`Publish a FormView`}),(0,b.jsxs)(l,{children:[`Pick an existing FormView and turn it into a public form by enabling `,(0,b.jsx)(`code`,{className:`text-xs`,children:`sharing.allowAnonymous`}),` `,`and setting `,(0,b.jsx)(`code`,{className:`text-xs`,children:`publicLink`}),`.`]})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`publish-view`,children:`FormView`}),(0,b.jsxs)(`select`,{id:`publish-view`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:O,onChange:e=>k(e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:`— Select a FormView —`}),S.map(e=>(0,b.jsxs)(`option`,{value:e.name,children:[e.label??e.name,` (`,e.name,`) `,e.object?`· ${e.object}`:``]},e.name))]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`publish-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(p,{id:`publish-slug`,placeholder:`contact-us`,value:A,onChange:e=>j(e.target.value)})]}),(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase letters, digits, dashes and underscores only.`})]})]}),(0,b.jsxs)(u,{children:[(0,b.jsx)(h,{variant:`ghost`,onClick:()=>D(!1),disabled:M,children:`Cancel`}),(0,b.jsx)(h,{onClick:xe,disabled:M||!O||!A,children:M?`Publishing…`:`Publish`})]})]})}),(0,b.jsx)(s,{open:ve,onOpenChange:P,children:(0,b.jsxs)(c,{className:`sm:max-w-lg`,children:[(0,b.jsxs)(_,{children:[(0,b.jsx)(i,{children:F?`Edit ${F.label??F.name}`:`Edit form`}),(0,b.jsx)(l,{children:`Configure the public URL and what happens after submit.`})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(p,{id:`edit-slug`,value:L,onChange:e=>R(e.target.value)})]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-behavior`,children:`After submit`}),(0,b.jsxs)(`select`,{id:`edit-behavior`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:z,onChange:e=>B(e.target.value),children:[(0,b.jsx)(`option`,{value:`thank-you`,children:`Show a thank-you panel`}),(0,b.jsx)(`option`,{value:`redirect`,children:`Redirect to a URL`}),(0,b.jsx)(`option`,{value:`continue`,children:`Reset for another response`}),(0,b.jsx)(`option`,{value:`next-record`,children:`Advance to next record (internal queues)`})]})]}),z===`thank-you`&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-tytitle`,children:`Title`}),(0,b.jsx)(p,{id:`edit-tytitle`,placeholder:`Thanks!`,value:V,onChange:e=>H(e.target.value)})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-tymsg`,children:`Message`}),(0,b.jsx)(p,{id:`edit-tymsg`,placeholder:`Your submission has been received.`,value:U,onChange:e=>W(e.target.value)})]})]}),z===`redirect`&&(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-url`,children:`Redirect URL`}),(0,b.jsx)(p,{id:`edit-url`,type:`url`,placeholder:`https://example.com/thanks`,value:G,onChange:e=>K(e.target.value)})]})]}),(0,b.jsxs)(u,{children:[(0,b.jsx)(h,{variant:`ghost`,onClick:()=>P(!1),disabled:q,children:`Cancel`}),(0,b.jsx)(h,{onClick:Ce,disabled:q||!L,children:q?`Saving…`:`Save`})]})]})})]})}export{S as PublicFormsPage};
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{S as r}from"./framework-Bsl5NTfe.js";import{Ai as i,Bn as a,Co as o,Fn as s,Fo as ee,In as c,Jn as te,Kn as ne,Ln as l,Ni as re,Qn as ie,Ri as ae,Rn as u,Xn as oe,Yn as se,at as d,ct as f,en as p,gi as ce,in as m,it as le,ja as ue,mr as h,ot as g,qn as de,rt as fe,st as pe,zn as _,zo as me}from"./ui-components-D0tUqjB3.js";import{o as v}from"./vendor-ui-utils-BbOuugky.js";import"./index-D8443YMB.js";var y=e(n(),1),b=t();function he(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function x(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``)}function S(){let e=r()?.getClient?.(),[t,n]=(0,y.useState)([]),[S,ge]=(0,y.useState)([]),[C,w]=(0,y.useState)(!0),[T,E]=(0,y.useState)(null),[_e,D]=(0,y.useState)(!1),[O,k]=(0,y.useState)(``),[A,j]=(0,y.useState)(``),[M,N]=(0,y.useState)(!1),[ve,P]=(0,y.useState)(!1),[F,I]=(0,y.useState)(null),[L,R]=(0,y.useState)(``),[z,B]=(0,y.useState)(`thank-you`),[V,H]=(0,y.useState)(``),[U,W]=(0,y.useState)(``),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=async()=>{if(!e?.meta?.getItems){E(`meta.getItems is not available on this client`),w(!1);return}w(!0),E(null);try{let t=await e.meta.getItems(`view`),r=Array.isArray(t)?t:Array.isArray(t?.items)?t.items:Array.isArray(t?.value)?t.value:[],i=[],a=[];for(let e of r){let t=e?.spec??e;if(!(t?.sections||t?.groups||t?.form||t?.type===`simple`||t?.type===`tabbed`||t?.type===`wizard`||t?.viewType===`form`))continue;let n=t?.sharing,r=n?.publicLink,o=he(r);n?.allowAnonymous&&o&&r?i.push({name:t?.name??e?.name,label:t?.label,object:t?.object,slug:o,publicLink:r,updatedAt:e?.updatedAt??e?.updated_at,spec:t}):a.push({name:t?.name??e?.name,label:t?.label,object:t?.object,spec:t})}n(i),ge(a)}catch(e){E(e?.message??String(e))}finally{w(!1)}};(0,y.useEffect)(()=>{Y()},[]);let ye=typeof window<`u`?window.location.origin:``,X=e=>`${ye}/console/f/${e}`,Z=e=>`<iframe src="${X(e)}" width="100%" height="640" frameborder="0" style="border:0;"></iframe>`,be=e=>`<iframe\n src={\`${X(e)}\`}\n title="Public form"\n style={{ width: '100%', height: 640, border: 0 }}\n/>`,Q=async(e,t)=>{try{await navigator.clipboard.writeText(t),v.success(`Copied ${e}`)}catch{v.error(`Clipboard unavailable`)}},xe=async()=>{if(!O||!A)return;let t=S.find(e=>e.name===O);if(!t)return;let n=x(A);if(!n){v.error(`Invalid slug`);return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};N(!0);try{await e.meta.saveItem(`view`,t.name,r),v.success(`Published ${t.name}`),D(!1),k(``),j(``),await Y()}catch(e){v.error(`Publish failed: ${e?.message??e}`)}finally{N(!1)}},Se=e=>{I(e),R(e.slug);let t=e.spec?.submitBehavior;B(t?.kind??`thank-you`),H(t?.title??``),W(t?.message??``),K(t?.url??``),P(!0)},Ce=async()=>{if(!F)return;let t=x(L);if(!t){v.error(`Invalid slug`);return}let n;switch(z){case`thank-you`:n={kind:`thank-you`},V&&(n.title=V),U&&(n.message=U);break;case`redirect`:if(!G){v.error(`Redirect URL is required`);return}n={kind:`redirect`,url:G};break;case`continue`:case`next-record`:n={kind:z};break}let r={...F.spec,sharing:{...F.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};J(!0);try{await e.meta.saveItem(`view`,F.name,r),v.success(`Saved ${F.name}`),P(!1),I(null),await Y()}catch(e){v.error(`Save failed: ${e?.message??e}`)}finally{J(!1)}},$=t.length>0;return(0,b.jsxs)(`div`,{className:`flex flex-1 flex-col gap-4 p-4 md:p-6 overflow-auto`,children:[(0,b.jsxs)(ne,{children:[(0,b.jsxs)(se,{className:`flex flex-row items-start justify-between gap-4 space-y-0`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(oe,{className:`flex items-center gap-2`,children:[(0,b.jsx)(re,{className:`h-4 w-4`}),`Public Forms`]}),(0,b.jsx)(te,{children:`Forms anyone can fill out — no login required. Publish a form to get a shareable link; submissions land directly in the bound object.`})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`default`,size:`sm`,onClick:()=>D(!0),disabled:S.length===0,title:S.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,b.jsx)(ae,{className:`h-3.5 w-3.5`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Publish form…`})]}),(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:Y,disabled:C,children:[(0,b.jsx)(i,{className:`h-3.5 w-3.5 ${C?`animate-spin`:``}`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,b.jsxs)(de,{children:[T&&(0,b.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:T}),!C&&!$&&(0,b.jsxs)(`div`,{className:`rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground`,children:[(0,b.jsx)(`p`,{className:`font-medium text-foreground`,children:`No public forms yet`}),(0,b.jsxs)(`p`,{className:`mt-1`,children:[`Click `,(0,b.jsx)(`strong`,{children:`Publish form…`}),` above to share an existing form, or build a new one in Views & Apps and mark it public.`]})]}),$&&(0,b.jsxs)(fe,{children:[(0,b.jsx)(pe,{children:(0,b.jsxs)(f,{children:[(0,b.jsx)(g,{children:`Name`}),(0,b.jsx)(g,{children:`Object`}),(0,b.jsx)(g,{children:`Slug`}),(0,b.jsx)(g,{children:`Public URL`}),(0,b.jsx)(g,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(le,{children:t.map(e=>{let t=X(e.slug);return(0,b.jsxs)(f,{children:[(0,b.jsx)(d,{children:(0,b.jsxs)(`div`,{className:`flex flex-col`,children:[(0,b.jsx)(`span`,{className:`font-medium`,children:e.label??e.name}),(0,b.jsx)(`code`,{className:`text-xs text-muted-foreground`,children:e.name})]})}),(0,b.jsx)(d,{children:e.object?(0,b.jsx)(ie,{variant:`secondary`,children:e.object}):(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,b.jsx)(d,{children:(0,b.jsx)(`code`,{className:`text-xs`,children:e.slug})}),(0,b.jsx)(d,{children:(0,b.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-primary underline-offset-2 hover:underline`,children:[t,(0,b.jsx)(o,{className:`h-3 w-3`})]})}),(0,b.jsx)(d,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`inline-flex gap-1`,children:[(0,b.jsx)(h,{variant:`ghost`,size:`sm`,title:`Copy URL`,onClick:()=>Q(`URL`,t),children:(0,b.jsx)(ue,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(h,{variant:`ghost`,size:`sm`,title:`Copy <iframe> embed`,onClick:()=>Q(`iframe snippet`,Z(e.slug)),children:(0,b.jsx)(me,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(h,{variant:`ghost`,size:`sm`,title:`Copy React snippet`,onClick:()=>Q(`React snippet`,be(e.slug)),children:(0,b.jsx)(ee,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(h,{variant:`ghost`,size:`sm`,title:`Edit sharing & post-submit behavior`,onClick:()=>Se(e),children:(0,b.jsx)(ce,{className:`h-3.5 w-3.5`})})]})})]},e.name)})})]})]})]}),(0,b.jsx)(s,{open:_e,onOpenChange:D,children:(0,b.jsxs)(c,{className:`sm:max-w-md`,children:[(0,b.jsxs)(_,{children:[(0,b.jsx)(a,{children:`Publish a FormView`}),(0,b.jsxs)(l,{children:[`Pick an existing FormView and turn it into a public form by enabling `,(0,b.jsx)(`code`,{className:`text-xs`,children:`sharing.allowAnonymous`}),` `,`and setting `,(0,b.jsx)(`code`,{className:`text-xs`,children:`publicLink`}),`.`]})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`publish-view`,children:`FormView`}),(0,b.jsxs)(`select`,{id:`publish-view`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:O,onChange:e=>k(e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:`— Select a FormView —`}),S.map(e=>(0,b.jsxs)(`option`,{value:e.name,children:[e.label??e.name,` (`,e.name,`) `,e.object?`· ${e.object}`:``]},e.name))]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`publish-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(p,{id:`publish-slug`,placeholder:`contact-us`,value:A,onChange:e=>j(e.target.value)})]}),(0,b.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Lowercase letters, digits, dashes and underscores only.`})]})]}),(0,b.jsxs)(u,{children:[(0,b.jsx)(h,{variant:`ghost`,onClick:()=>D(!1),disabled:M,children:`Cancel`}),(0,b.jsx)(h,{onClick:xe,disabled:M||!O||!A,children:M?`Publishing…`:`Publish`})]})]})}),(0,b.jsx)(s,{open:ve,onOpenChange:P,children:(0,b.jsxs)(c,{className:`sm:max-w-lg`,children:[(0,b.jsxs)(_,{children:[(0,b.jsx)(a,{children:F?`Edit ${F.label??F.name}`:`Edit form`}),(0,b.jsx)(l,{children:`Configure the public URL and what happens after submit.`})]}),(0,b.jsxs)(`div`,{className:`space-y-3`,children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-slug`,children:`URL slug`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-xs text-muted-foreground whitespace-nowrap`,children:`/console/f/`}),(0,b.jsx)(p,{id:`edit-slug`,value:L,onChange:e=>R(e.target.value)})]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-behavior`,children:`After submit`}),(0,b.jsxs)(`select`,{id:`edit-behavior`,className:`flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm`,value:z,onChange:e=>B(e.target.value),children:[(0,b.jsx)(`option`,{value:`thank-you`,children:`Show a thank-you panel`}),(0,b.jsx)(`option`,{value:`redirect`,children:`Redirect to a URL`}),(0,b.jsx)(`option`,{value:`continue`,children:`Reset for another response`}),(0,b.jsx)(`option`,{value:`next-record`,children:`Advance to next record (internal queues)`})]})]}),z===`thank-you`&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-tytitle`,children:`Title`}),(0,b.jsx)(p,{id:`edit-tytitle`,placeholder:`Thanks!`,value:V,onChange:e=>H(e.target.value)})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-tymsg`,children:`Message`}),(0,b.jsx)(p,{id:`edit-tymsg`,placeholder:`Your submission has been received.`,value:U,onChange:e=>W(e.target.value)})]})]}),z===`redirect`&&(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(m,{htmlFor:`edit-url`,children:`Redirect URL`}),(0,b.jsx)(p,{id:`edit-url`,type:`url`,placeholder:`https://example.com/thanks`,value:G,onChange:e=>K(e.target.value)})]})]}),(0,b.jsxs)(u,{children:[(0,b.jsx)(h,{variant:`ghost`,onClick:()=>P(!1),disabled:q,children:`Cancel`}),(0,b.jsx)(h,{onClick:Ce,disabled:q||!L,children:q?`Saving…`:`Save`})]})]})})]})}export{S as PublicFormsPage};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{f as r}from"./infrastructure-IQKE4Vv8.js";var i=e(n(),1),a=t(),o=(0,i.createContext)({favorites:null,recent:null}),s=(0,i.createContext)(null);function c({children:e}){let[t,n]=(0,i.useState)({favorites:null,recent:null}),r=(0,i.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,a.jsx)(s.Provider,{value:r.current,children:(0,a.jsx)(o.Provider,{value:t,children:e})})}function l(e){return(0,i.useContext)(o)[e]}function u(){let e=(0,i.useContext)(s);return(0,i.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function d(e,t){return t?`${e}:u:${t}`:e}function f(e,t){let n=(0,i.useRef)(t);n.current=t,(0,i.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(!(t.key!==e||t.storageArea!==localStorage)){if(t.newValue==null){n.current(null);return}try{n.current(JSON.parse(t.newValue))}catch{n.current(null)}}};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e])}function p(e,t=500){let n=null,r=null,i=!1,a=async()=>{if(n&&=(clearTimeout(n),null),!i)return;let t=r;i=!1,r=null;try{await e(t)}catch{}};return{schedule:e=>{r=e,i=!0,n&&clearTimeout(n),n=setTimeout(()=>{n=null,a()},t)},flush:a,cancel:()=>{n&&clearTimeout(n),n=null,i=!1,r=null}}}var m=`objectui-recent-items`,h=8;function g(e){try{let t=localStorage.getItem(d(m,e));return t?JSON.parse(t):[]}catch{return[]}}function _(e,t){try{localStorage.setItem(d(m,t),JSON.stringify(e))}catch{}}var v=(0,i.createContext)(null);function y({children:e}){let{user:t}=r(),n=t?.id??null,o=l(`recent`),[s,c]=(0,i.useState)(()=>g(n));(0,i.useEffect)(()=>{c(g(n))},[n]),f(d(m,n),e=>{c(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,h):[])});let u=(0,i.useRef)(0);(0,i.useEffect)(()=>{if(!o)return;let e=++u.current,t=!1;return(async()=>{try{let r=await o.load();if(t||e!==u.current)return;let i=(Array.isArray(r)?r:[]).filter(e=>e&&typeof e.id==`string`).slice(0,h);c(i),_(i,n)}catch{}})(),()=>{t=!0}},[o,n]);let y=(0,i.useMemo)(()=>p(async e=>{o&&await o.save(e)},500),[o]);(0,i.useEffect)(()=>()=>{y.flush()},[y]);let b=(0,i.useCallback)(e=>{_(e,n),o&&y.schedule(e)},[n,o,y]),x=(0,i.useCallback)(e=>{c(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,h);return b(r),r})},[b]),S=(0,i.useCallback)(()=>{c([]),b([])},[b]),C=(0,i.useMemo)(()=>({recentItems:s,addRecentItem:x,clearRecentItems:S}),[s,x,S]);return(0,a.jsx)(v.Provider,{value:C,children:e})}function b(){return(0,i.useContext)(v)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}export{d as a,l as c,p as i,b as n,u as o,c as r,f as s,y as t};
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{f as r}from"./infrastructure-CFhpdDcd.js";var i=e(n(),1),a=t(),o=(0,i.createContext)({favorites:null,recent:null}),s=(0,i.createContext)(null);function c({children:e}){let[t,n]=(0,i.useState)({favorites:null,recent:null}),r=(0,i.useRef)({attach:(e,t)=>{n(n=>n[e]===t?n:{...n,[e]:t})}});return(0,a.jsx)(s.Provider,{value:r.current,children:(0,a.jsx)(o.Provider,{value:t,children:e})})}function l(e){return(0,i.useContext)(o)[e]}function u(){let e=(0,i.useContext)(s);return(0,i.useCallback)((t,n)=>{e?.attach(t,n)},[e])}function d(e,t){return t?`${e}:u:${t}`:e}function f(e,t){let n=(0,i.useRef)(t);n.current=t,(0,i.useEffect)(()=>{if(typeof window>`u`)return;let t=t=>{if(!(t.key!==e||t.storageArea!==localStorage)){if(t.newValue==null){n.current(null);return}try{n.current(JSON.parse(t.newValue))}catch{n.current(null)}}};return window.addEventListener(`storage`,t),()=>window.removeEventListener(`storage`,t)},[e])}function p(e,t=500){let n=null,r=null,i=!1,a=async()=>{if(n&&=(clearTimeout(n),null),!i)return;let t=r;i=!1,r=null;try{await e(t)}catch{}};return{schedule:e=>{r=e,i=!0,n&&clearTimeout(n),n=setTimeout(()=>{n=null,a()},t)},flush:a,cancel:()=>{n&&clearTimeout(n),n=null,i=!1,r=null}}}var m=`objectui-recent-items`,h=8;function g(e){try{let t=localStorage.getItem(d(m,e));return t?JSON.parse(t):[]}catch{return[]}}function _(e,t){try{localStorage.setItem(d(m,t),JSON.stringify(e))}catch{}}var v=(0,i.createContext)(null);function y({children:e}){let{user:t}=r(),n=t?.id??null,o=l(`recent`),[s,c]=(0,i.useState)(()=>g(n));(0,i.useEffect)(()=>{c(g(n))},[n]),f(d(m,n),e=>{c(Array.isArray(e)?e.filter(e=>e&&typeof e.id==`string`).slice(0,h):[])});let u=(0,i.useRef)(0);(0,i.useEffect)(()=>{if(!o)return;let e=++u.current,t=!1;return(async()=>{try{let r=await o.load();if(t||e!==u.current)return;let i=(Array.isArray(r)?r:[]).filter(e=>e&&typeof e.id==`string`).slice(0,h);c(i),_(i,n)}catch{}})(),()=>{t=!0}},[o,n]);let y=(0,i.useMemo)(()=>p(async e=>{o&&await o.save(e)},500),[o]);(0,i.useEffect)(()=>()=>{y.flush()},[y]);let b=(0,i.useCallback)(e=>{_(e,n),o&&y.schedule(e)},[n,o,y]),x=(0,i.useCallback)(e=>{c(t=>{let n=t.filter(t=>t.id!==e.id),r=[{...e,visitedAt:new Date().toISOString()},...n].slice(0,h);return b(r),r})},[b]),S=(0,i.useCallback)(()=>{c([]),b([])},[b]),C=(0,i.useMemo)(()=>({recentItems:s,addRecentItem:x,clearRecentItems:S}),[s,x,S]);return(0,a.jsx)(v.Provider,{value:C,children:e})}function b(){return(0,i.useContext)(v)||{recentItems:[],addRecentItem:()=>{},clearRecentItems:()=>{}}}export{d as a,l as c,p as i,b as n,u as o,c as r,f as s,y as t};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{f as t,r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{At as i,Jn as a,Kn as o,Qn as s,Xn as c,Yn as l,mi as u,qn as d}from"./ui-components-CIdYg6m3.js";import{o as f,r as p,t as m}from"./types-CbmNTewl.js";var h=e(r(),1),g=n();function _(){let e=t(),[n,r]=(0,h.useState)(null),[_,v]=(0,h.useState)(null);(0,h.useEffect)(()=>{p().then(e=>r(e.manifests??[])).catch(e=>v(e?.message??`Failed to load settings`))},[]);let y=(0,h.useMemo)(()=>{if(!n)return null;let e=new Map;for(let t of[...n].sort((e,t)=>(e.order??999)-(t.order??999))){let n=t.category??`Other`,r=e.get(n)??[];r.push(t),e.set(n,r)}return e},[n]);return(0,g.jsxs)(`div`,{className:`p-6 max-w-6xl mx-auto`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,g.jsx)(u,{className:`h-7 w-7 text-muted-foreground`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Settings`}),(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure your workspace, integrations, and feature flags.`})]})]}),_?(0,g.jsx)(o,{children:(0,g.jsx)(d,{className:`py-8 text-center text-sm text-destructive`,children:_})}):null,n?n.length===0?(0,g.jsx)(o,{children:(0,g.jsx)(d,{className:`py-12 text-center text-sm text-muted-foreground`,children:`No settings registered. Plugins can register settings manifests via the SettingsService.`})}):Array.from(y??[]).map(([t,n])=>(0,g.jsxs)(`section`,{className:`mb-8`,children:[(0,g.jsx)(`h2`,{className:`text-sm font-semibold tracking-wide uppercase text-muted-foreground mb-3`,children:t}),(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:n.map(t=>(0,g.jsxs)(o,{className:`cursor-pointer hover:border-primary/50 hover:shadow-sm transition-all`,onClick:()=>e(`/system/settings/${t.namespace}`),children:[(0,g.jsxs)(l,{className:`pb-3`,children:[(0,g.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,g.jsx)(t.icon?f(t.icon):u,{className:`h-6 w-6 text-muted-foreground`}),t.beta?(0,g.jsx)(s,{variant:`secondary`,className:`text-[10px]`,children:`Beta`}):null]}),(0,g.jsx)(c,{className:`text-base mt-2`,children:m(t.label)}),t.description?(0,g.jsx)(a,{className:`text-xs`,children:t.description}):null]}),(0,g.jsx)(d,{className:`pt-0`,children:(0,g.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.specifiers.length,` setting`,t.specifiers.length===1?``:`s`]})})]},t.namespace))})]},t)):(0,g.jsxs)(`div`,{className:`space-y-4`,children:[(0,g.jsx)(i,{className:`h-6 w-32`}),(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Array.from({length:3}).map((e,t)=>(0,g.jsx)(i,{className:`h-32 w-full`},t))})]})]})}export{_ as SettingsHub};
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{f as t,r as n,y as r}from"./vendor-react-CyVA1SE-.js";import{At as i,Jn as a,Kn as o,Qn as s,Xn as c,Yn as l,hi as u,qn as d}from"./ui-components-D0tUqjB3.js";import{o as f,r as p,t as m}from"./types-BYLUnF0C.js";var h=e(r(),1),g=n();function _(){let e=t(),[n,r]=(0,h.useState)(null),[_,v]=(0,h.useState)(null);(0,h.useEffect)(()=>{p().then(e=>r(e.manifests??[])).catch(e=>v(e?.message??`Failed to load settings`))},[]);let y=(0,h.useMemo)(()=>{if(!n)return null;let e=new Map;for(let t of[...n].sort((e,t)=>(e.order??999)-(t.order??999))){let n=t.category??`Other`,r=e.get(n)??[];r.push(t),e.set(n,r)}return e},[n]);return(0,g.jsxs)(`div`,{className:`p-6 max-w-6xl mx-auto`,children:[(0,g.jsxs)(`div`,{className:`flex items-center gap-3 mb-6`,children:[(0,g.jsx)(u,{className:`h-7 w-7 text-muted-foreground`}),(0,g.jsxs)(`div`,{children:[(0,g.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:`Settings`}),(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure your workspace, integrations, and feature flags.`})]})]}),_?(0,g.jsx)(o,{children:(0,g.jsx)(d,{className:`py-8 text-center text-sm text-destructive`,children:_})}):null,n?n.length===0?(0,g.jsx)(o,{children:(0,g.jsx)(d,{className:`py-12 text-center text-sm text-muted-foreground`,children:`No settings registered. Plugins can register settings manifests via the SettingsService.`})}):Array.from(y??[]).map(([t,n])=>(0,g.jsxs)(`section`,{className:`mb-8`,children:[(0,g.jsx)(`h2`,{className:`text-sm font-semibold tracking-wide uppercase text-muted-foreground mb-3`,children:t}),(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:n.map(t=>(0,g.jsxs)(o,{className:`cursor-pointer hover:border-primary/50 hover:shadow-sm transition-all`,onClick:()=>e(`/system/settings/${t.namespace}`),children:[(0,g.jsxs)(l,{className:`pb-3`,children:[(0,g.jsxs)(`div`,{className:`flex items-start justify-between`,children:[(0,g.jsx)(t.icon?f(t.icon):u,{className:`h-6 w-6 text-muted-foreground`}),t.beta?(0,g.jsx)(s,{variant:`secondary`,className:`text-[10px]`,children:`Beta`}):null]}),(0,g.jsx)(c,{className:`text-base mt-2`,children:m(t.label)}),t.description?(0,g.jsx)(a,{className:`text-xs`,children:t.description}):null]}),(0,g.jsx)(d,{className:`pt-0`,children:(0,g.jsxs)(`div`,{className:`text-[11px] text-muted-foreground`,children:[t.specifiers.length,` setting`,t.specifiers.length===1?``:`s`]})})]},t.namespace))})]},t)):(0,g.jsxs)(`div`,{className:`space-y-4`,children:[(0,g.jsx)(i,{className:`h-6 w-32`}),(0,g.jsx)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4`,children:Array.from({length:3}).map((e,t)=>(0,g.jsx)(i,{className:`h-32 w-full`},t))})]})]})}export{_ as SettingsHub};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{f as t,m as n,r,y as i}from"./vendor-react-CyVA1SE-.js";import{r as a}from"./framework-DVkqUSPj.js";import{At as o,Bt as s,Gn as c,Ht as l,Jt as u,Kn as d,La as f,Lt as p,Q as m,Qn as h,Rt as g,Vt as _,Wo as v,Yt as y,ba as b,en as x,in as S,ir as C,lt as w,mr as T,nr as E,qn as D,rr as O,ut as k,wi as A,ws as j,xa as M,zt as N}from"./ui-components-CIdYg6m3.js";import{o as P}from"./vendor-ui-utils-BbOuugky.js";import{a as F,i as I,n as L,o as R,t as z}from"./types-CbmNTewl.js";var B=e(i(),1),V=r();function H({reason:e,className:t}){return(0,V.jsxs)(h,{variant:`outline`,className:`gap-1 border-amber-300 bg-amber-50 text-amber-900 ${t??``}`,title:e??`Pinned by environment variable — cannot be edited from the UI.`,children:[(0,V.jsx)(b,{className:`h-3 w-3`}),`Locked by env`]})}function U({resolved:e,labels:t}){let n=e.cascadeChain;if(!n||n.length===0)return null;let r=n.find(e=>e.effective)??n[n.length-1],i=n.find(e=>e!==r&&e.value!==null&&e.value!==void 0),a=e=>t?.sourceLabel?.(e)??e;return r.scope!==`default`&&r.scope!==`user`&&r.scope!==`tenant`?(0,V.jsxs)(h,{variant:`outline`,className:`text-blue-700 border-blue-300 text-[10px]`,children:[`Inherited from `,a(r.scope)]}):i?(0,V.jsxs)(h,{variant:`outline`,className:`text-amber-700 border-amber-300 text-[10px]`,children:[`Overrides `,a(i.scope)]}):null}function W({spec:e,resolved:t,labelText:n,labels:r}){return(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(S,{className:`text-sm font-medium`,children:[n,e.required?(0,V.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`}):null]}),e.deprecated?(0,V.jsxs)(h,{variant:`outline`,className:`text-amber-700 border-amber-300`,children:[`Deprecated`,e.replacedBy?` → ${e.replacedBy}`:``]}):null,t?.locked?(0,V.jsx)(H,{reason:t.lockedReason}):null,t&&!t.locked?(0,V.jsx)(U,{resolved:t,labels:r}):null,t?.source&&t.source!==`default`&&!t.locked?(0,V.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:r?.sourceLabel?.(t.source)??t.source}):null]})}function G({description:e}){return e?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e}):null}function K(e){let{spec:t,resolved:n,value:r,onChange:i,onAction:a,locked:o,saving:d,labels:h}=e,b=(0,B.useId)(),D=!!(o||d),A=z(t.label),j=t.key&&h?h.fieldLabel(t.key,A):A,M=t.key&&h?h.fieldHelp(t.key,t.description):t.description;if(t.type===`group`){let e=t.id&&h?h.groupTitle(t.id,A):A,n=t.id&&h?h.groupDescription(t.id,t.description):t.description;return(0,V.jsxs)(`div`,{className:`pt-6 pb-2`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-semibold tracking-tight text-foreground/90`,children:e}),n?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:n}):null,(0,V.jsx)(p,{className:`mt-3`})]})}if(t.type===`info_banner`)return(0,V.jsxs)(E,{variant:t.bannerSeverity===`error`?`destructive`:`default`,className:`my-2`,children:[(0,V.jsx)(f,{className:`h-4 w-4`}),(0,V.jsx)(C,{children:A}),t.bannerText?(0,V.jsx)(O,{children:t.bannerText}):null]});if(t.type===`child_pane`)return(0,V.jsxs)(`a`,{href:`#/settings/${t.childNamespace}`,className:`flex items-center justify-between rounded-md border border-border bg-card px-4 py-3 hover:bg-accent transition-colors`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium`,children:A}),t.description?(0,V.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description}):null]}),(0,V.jsx)(v,{className:`h-4 w-4 text-muted-foreground`})]});if(t.type===`title_value`)return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-2`,children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:j,labels:h}),(0,V.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:String(r??`—`)})]});if(t.type===`action_button`){let e=t.icon?R(t.icon):null,n=t.id??t.key??`test`,r=h?h.actionLabel(n,A):A;return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium`,children:r}),t.description?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:t.description}):null]}),(0,V.jsxs)(T,{size:`sm`,variant:`secondary`,onClick:a,disabled:d,children:[e?(0,V.jsx)(e,{className:`h-4 w-4 mr-1.5`}):null,r]})]})}let P=e=>(0,V.jsxs)(`div`,{className:`space-y-1.5 py-2`,children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:j,labels:h}),e,(0,V.jsx)(G,{description:M})]}),F=e=>{let n=typeof e.label==`string`?e.label:e.label?.defaultValue??String(e.value);return!t.key||!h?n:h.optionLabel(t.key,String(e.value),n)};switch(t.type){case`text`:case`email`:case`url`:case`phone`:return P((0,V.jsx)(x,{id:b,type:t.type===`email`?`email`:t.type===`url`?`url`:`text`,value:r??``,minLength:t.minLength,maxLength:t.maxLength,pattern:t.pattern,disabled:D,onChange:e=>i(e.target.value)}));case`password`:return P((0,V.jsx)(x,{id:b,type:`password`,autoComplete:`new-password`,placeholder:r?`••••••••`:``,disabled:D,onChange:e=>i(e.target.value)}));case`textarea`:return P((0,V.jsx)(m,{id:b,rows:t.rows??4,value:r??``,minLength:t.minLength,maxLength:t.maxLength,disabled:D,onChange:e=>i(e.target.value)}));case`number`:return P((0,V.jsx)(x,{id:b,type:`number`,value:r,min:t.min,max:t.max,step:t.step,disabled:D,onChange:e=>i(e.target.value===``?null:Number(e.target.value))}));case`toggle`:return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:j,labels:h}),(0,V.jsx)(G,{description:M})]}),(0,V.jsx)(w,{id:b,checked:!!r,disabled:D,onCheckedChange:e=>i(e)})]});case`select`:return P((0,V.jsxs)(g,{value:r==null?void 0:String(r),onValueChange:e=>i(e),disabled:D,children:[(0,V.jsx)(_,{id:b,children:(0,V.jsx)(l,{placeholder:`Select…`})}),(0,V.jsx)(N,{children:t.options?.map(e=>(0,V.jsx)(s,{value:String(e.value),children:F(e)},String(e.value)))})]}));case`radio`:return P((0,V.jsx)(u,{value:r==null?void 0:String(r),onValueChange:e=>i(e),disabled:D,children:t.options?.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(y,{value:String(e.value),id:`${b}-${e.value}`}),(0,V.jsx)(S,{htmlFor:`${b}-${e.value}`,className:`text-sm font-normal`,children:F(e)})]},String(e.value)))}));case`multiselect`:{let e=Array.isArray(r)?r:[];return P((0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:t.options?.map(t=>{let n=String(t.value);return(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,V.jsx)(c,{checked:e.map(String).includes(n),disabled:D,onCheckedChange:t=>{let r=new Set(e.map(String));t?r.add(n):r.delete(n),i(Array.from(r))}}),F(t)]},n)})}))}case`slider`:return P((0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(k,{value:[Number(r??t.min??0)],min:t.min??0,max:t.max??100,step:t.step??1,disabled:D,onValueChange:e=>i(e[0]),className:`flex-1`}),(0,V.jsx)(`span`,{className:`text-sm tabular-nums w-12 text-right`,children:String(r??t.min??0)})]}));case`color`:return P((0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(x,{id:b,type:`color`,value:r??`#000000`,disabled:D,onChange:e=>i(e.target.value),className:`w-16 h-9 p-1`}),(0,V.jsx)(x,{value:r??``,disabled:D,onChange:e=>i(e.target.value),className:`flex-1 font-mono text-sm`})]}));case`json`:return P((0,V.jsx)(m,{id:b,rows:t.rows??6,className:`font-mono text-xs`,value:typeof r==`string`?r:JSON.stringify(r??null,null,2),disabled:D,onChange:e=>i(e.target.value)}));default:return P((0,V.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[`Unsupported specifier type: `,t.type]}))}}var q=new Set([`common`,`validation`,`errors`,`system`,`auth`]);function J(e){let{t,i18n:n}=a();return(0,B.useMemo)(()=>{let r=()=>{if(!n||typeof n.getResourceBundle!=`function`)return[];let e=n.language||`en`,t=n.getResourceBundle(e,`translation`);return t?Object.keys(t).filter(e=>!q.has(e)&&t[e]&&typeof t[e]==`object`&&t[e].settings):[]},i=(n,i)=>{if(!e)return i;try{let i=r();for(let r of i){let i=`${r}.settings.${e}.${n}`,a=t(i,{defaultValue:``});if(a&&a!==i&&a!==``)return a}}catch{}return i},a=(e,r)=>{try{if(!n||typeof n.getResourceBundle!=`function`)return r;let i=n.language||`en`,a=n.getResourceBundle(i,`translation`);if(!a)return r;for(let n of Object.keys(a)){if(q.has(n))continue;let r=a[n];if(!r||typeof r!=`object`||!(`settingsCommon`in r))continue;let i=`${n}.settingsCommon.${e}`,o=t(i,{defaultValue:``});if(o&&o!==i&&o!==``)return o}}catch{}return r},o={env:`Env`,global:`Global`,tenant:`Tenant`,user:`User`,default:`Default`};return{title:e=>i(`title`,e)??e,description:e=>i(`description`,e),groupTitle:(e,t)=>i(`groups.${e}.title`,t)??t,groupDescription:(e,t)=>i(`groups.${e}.description`,t),fieldLabel:(e,t)=>i(`keys.${e}.label`,t)??t,fieldHelp:(e,t)=>i(`keys.${e}.help`,t),fieldPlaceholder:(e,t)=>i(`keys.${e}.placeholder`,t),optionLabel:(e,t,n)=>i(`keys.${e}.options.${t}`,n)??n,actionLabel:(e,t)=>i(`actions.${e}.label`,t)??t,actionConfirm:(e,t)=>i(`actions.${e}.confirmText`,t),actionSuccess:(e,t)=>i(`actions.${e}.successMessage`,t),sourceLabel:e=>a(`sourceLabels.${e}`,o[e]??e)}},[e,t,n,n?.language])}function Y(e,t){if(!e)return!0;let n=e.trim().match(/^\$\{(.+)\}$/);if(!n)return!0;try{return!!Function(`data`,`with (data) { return (${n[1]}); }`)(t)}catch{return!0}}function X(){let e=n(),r=t(),i=e.namespace??``,[a,s]=(0,B.useState)(null),[c,l]=(0,B.useState)(!0),[u,f]=(0,B.useState)(!1),[p,m]=(0,B.useState)(null),[g,_]=(0,B.useState)({}),v=(0,B.useCallback)(async()=>{l(!0),m(null);try{s(await L(i)),_({})}catch(e){m(e?.message??`Failed to load settings`)}finally{l(!1)}},[i]);(0,B.useEffect)(()=>{i&&v()},[i,v]);let y=(0,B.useMemo)(()=>{let e={};if(!a)return e;for(let[t,n]of Object.entries(a.values))e[t]=n.value;return{...e,...g}},[a,g]),b=(0,B.useMemo)(()=>Object.keys(g),[g]),x=J(i);if(!i)return(0,V.jsx)(`div`,{className:`p-6 text-muted-foreground`,children:`No namespace selected.`});if(c)return(0,V.jsxs)(`div`,{className:`p-6 space-y-3 max-w-3xl`,children:[(0,V.jsx)(o,{className:`h-8 w-1/3`}),(0,V.jsx)(o,{className:`h-4 w-2/3`}),(0,V.jsx)(o,{className:`h-32 w-full`}),(0,V.jsx)(o,{className:`h-32 w-full`})]});if(p)return(0,V.jsxs)(`div`,{className:`p-6 max-w-3xl`,children:[(0,V.jsxs)(T,{variant:`ghost`,size:`sm`,onClick:()=>r(-1),children:[(0,V.jsx)(j,{className:`h-4 w-4 mr-1`}),` Back`]}),(0,V.jsx)(d,{className:`mt-3`,children:(0,V.jsx)(D,{className:`py-8 text-center text-sm text-destructive`,children:p})})]});if(!a)return null;let{manifest:S,values:C}=a,w=S.icon?R(S.icon):null,E=x.title(z(S.label)),O=x.description(S.description),k=async()=>{if(b.length!==0){f(!0);try{let e=await F(i,g);s({...a,values:{...C,...e.values}}),_({}),P.success(`Settings saved`)}catch(e){e?.payload?.error?.code===`SETTINGS_LOCKED`?P.error(`Locked by environment: ${e.payload.error.key}`):P.error(e?.message??`Save failed`)}finally{f(!1)}}},N=async e=>{f(!0);try{let t=await I(i,e,g);t.ok?P.success(t.message??`Action succeeded`):P.error(t.message??`Action failed`)}catch(e){P.error(e?.message??`Action failed`)}finally{f(!1)}};return(0,V.jsxs)(`div`,{className:`p-6 max-w-3xl mx-auto pb-32`,children:[(0,V.jsxs)(T,{variant:`ghost`,size:`sm`,onClick:()=>r(`/system/settings`),children:[(0,V.jsx)(j,{className:`h-4 w-4 mr-1`}),` All settings`]}),(0,V.jsxs)(`div`,{className:`mt-3 flex items-start gap-3`,children:[w?(0,V.jsx)(w,{className:`h-7 w-7 mt-0.5 text-muted-foreground`}):null,(0,V.jsxs)(`div`,{className:`flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:E}),S.beta?(0,V.jsx)(h,{variant:`secondary`,children:`Beta`}):null]}),O?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:O}):null]})]}),S.helpText?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-4 whitespace-pre-wrap`,children:S.helpText}):null,(0,V.jsx)(`div`,{className:`mt-6 divide-y`,children:S.specifiers.filter(e=>Y(e.visible,y)).map((e,t)=>{let n=e.key,r=n?C[n]:void 0;return(0,V.jsx)(K,{spec:e,resolved:r,value:n?n in g?g[n]:r?.value:void 0,onChange:e=>n&&_(t=>({...t,[n]:e})),onAction:e.type===`action_button`?()=>N(e.id??n??`test`):void 0,locked:r?.locked,saving:u,labels:x},(n??`_layout_${t}`)+t)})}),b.length>0?(0,V.jsx)(`div`,{className:`fixed bottom-0 inset-x-0 bg-background/95 backdrop-blur border-t shadow-lg z-40`,children:(0,V.jsxs)(`div`,{className:`max-w-3xl mx-auto px-6 py-3 flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[b.length,` unsaved change`,b.length>1?`s`:``]}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsxs)(T,{variant:`ghost`,size:`sm`,onClick:()=>_({}),disabled:u,children:[(0,V.jsx)(A,{className:`h-4 w-4 mr-1`}),` Discard`]}),(0,V.jsxs)(T,{onClick:k,disabled:u,children:[u?(0,V.jsx)(M,{className:`h-4 w-4 mr-1 animate-spin`}):null,`Save changes`]})]})]})}):null]})}export{X as SettingsView};
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{f as t,m as n,r,y as i}from"./vendor-react-CyVA1SE-.js";import{r as a}from"./framework-Bsl5NTfe.js";import{At as o,Bt as s,Ea as c,Gn as l,Ha as u,Ht as d,Jt as f,Kn as p,Ls as m,Lt as h,Q as g,Qn as _,Rt as v,Ta as y,Ti as b,Vt as x,Yt as S,en as C,in as w,ir as T,lt as E,mr as D,nr as O,ns as k,qn as A,rr as j,ut as M,zt as N}from"./ui-components-D0tUqjB3.js";import{o as P}from"./vendor-ui-utils-BbOuugky.js";import{a as F,i as I,n as L,o as R,t as z}from"./types-BYLUnF0C.js";var B=e(i(),1),V=r();function H({reason:e,className:t}){return(0,V.jsxs)(_,{variant:`outline`,className:`gap-1 border-amber-300 bg-amber-50 text-amber-900 ${t??``}`,title:e??`Pinned by environment variable — cannot be edited from the UI.`,children:[(0,V.jsx)(y,{className:`h-3 w-3`}),`Locked by env`]})}function U({resolved:e,labels:t}){let n=e.cascadeChain;if(!n||n.length===0)return null;let r=n.find(e=>e.effective)??n[n.length-1],i=n.find(e=>e!==r&&e.value!==null&&e.value!==void 0),a=e=>t?.sourceLabel?.(e)??e;return r.scope!==`default`&&r.scope!==`user`&&r.scope!==`tenant`?(0,V.jsxs)(_,{variant:`outline`,className:`text-blue-700 border-blue-300 text-[10px]`,children:[`Inherited from `,a(r.scope)]}):i?(0,V.jsxs)(_,{variant:`outline`,className:`text-amber-700 border-amber-300 text-[10px]`,children:[`Overrides `,a(i.scope)]}):null}function W({spec:e,resolved:t,labelText:n,labels:r}){return(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsxs)(w,{className:`text-sm font-medium`,children:[n,e.required?(0,V.jsx)(`span`,{className:`ml-0.5 text-destructive`,children:`*`}):null]}),e.deprecated?(0,V.jsxs)(_,{variant:`outline`,className:`text-amber-700 border-amber-300`,children:[`Deprecated`,e.replacedBy?` → ${e.replacedBy}`:``]}):null,t?.locked?(0,V.jsx)(H,{reason:t.lockedReason}):null,t&&!t.locked?(0,V.jsx)(U,{resolved:t,labels:r}):null,t?.source&&t.source!==`default`&&!t.locked?(0,V.jsx)(`span`,{className:`text-[11px] text-muted-foreground`,children:r?.sourceLabel?.(t.source)??t.source}):null]})}function G({description:e}){return e?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:e}):null}function K(e){let{spec:t,resolved:n,value:r,onChange:i,onAction:a,locked:o,saving:c,labels:p}=e,m=(0,B.useId)(),_=!!(o||c),y=z(t.label),b=t.key&&p?p.fieldLabel(t.key,y):y,A=t.key&&p?p.fieldHelp(t.key,t.description):t.description;if(t.type===`group`){let e=t.id&&p?p.groupTitle(t.id,y):y,n=t.id&&p?p.groupDescription(t.id,t.description):t.description;return(0,V.jsxs)(`div`,{className:`pt-6 pb-2`,children:[(0,V.jsx)(`h3`,{className:`text-sm font-semibold tracking-tight text-foreground/90`,children:e}),n?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:n}):null,(0,V.jsx)(h,{className:`mt-3`})]})}if(t.type===`info_banner`)return(0,V.jsxs)(O,{variant:t.bannerSeverity===`error`?`destructive`:`default`,className:`my-2`,children:[(0,V.jsx)(u,{className:`h-4 w-4`}),(0,V.jsx)(T,{children:y}),t.bannerText?(0,V.jsx)(j,{children:t.bannerText}):null]});if(t.type===`child_pane`)return(0,V.jsxs)(`a`,{href:`#/settings/${t.childNamespace}`,className:`flex items-center justify-between rounded-md border border-border bg-card px-4 py-3 hover:bg-accent transition-colors`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium`,children:y}),t.description?(0,V.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:t.description}):null]}),(0,V.jsx)(k,{className:`h-4 w-4 text-muted-foreground`})]});if(t.type===`title_value`)return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-2`,children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:b,labels:p}),(0,V.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:String(r??`—`)})]});if(t.type===`action_button`){let e=t.icon?R(t.icon):null,n=t.id??t.key??`test`,r=p?p.actionLabel(n,y):y;return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(`div`,{className:`text-sm font-medium`,children:r}),t.description?(0,V.jsx)(`p`,{className:`text-xs text-muted-foreground mt-1`,children:t.description}):null]}),(0,V.jsxs)(D,{size:`sm`,variant:`secondary`,onClick:a,disabled:c,children:[e?(0,V.jsx)(e,{className:`h-4 w-4 mr-1.5`}):null,r]})]})}let P=e=>(0,V.jsxs)(`div`,{className:`space-y-1.5 py-2`,children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:b,labels:p}),e,(0,V.jsx)(G,{description:A})]}),F=e=>{let n=typeof e.label==`string`?e.label:e.label?.defaultValue??String(e.value);return!t.key||!p?n:p.optionLabel(t.key,String(e.value),n)};switch(t.type){case`text`:case`email`:case`url`:case`phone`:return P((0,V.jsx)(C,{id:m,type:t.type===`email`?`email`:t.type===`url`?`url`:`text`,value:r??``,minLength:t.minLength,maxLength:t.maxLength,pattern:t.pattern,disabled:_,onChange:e=>i(e.target.value)}));case`password`:return P((0,V.jsx)(C,{id:m,type:`password`,autoComplete:`new-password`,placeholder:r?`••••••••`:``,disabled:_,onChange:e=>i(e.target.value)}));case`textarea`:return P((0,V.jsx)(g,{id:m,rows:t.rows??4,value:r??``,minLength:t.minLength,maxLength:t.maxLength,disabled:_,onChange:e=>i(e.target.value)}));case`number`:return P((0,V.jsx)(C,{id:m,type:`number`,value:r,min:t.min,max:t.max,step:t.step,disabled:_,onChange:e=>i(e.target.value===``?null:Number(e.target.value))}));case`toggle`:return(0,V.jsxs)(`div`,{className:`flex items-center justify-between py-3`,children:[(0,V.jsxs)(`div`,{children:[(0,V.jsx)(W,{spec:t,resolved:n,labelText:b,labels:p}),(0,V.jsx)(G,{description:A})]}),(0,V.jsx)(E,{id:m,checked:!!r,disabled:_,onCheckedChange:e=>i(e)})]});case`select`:return P((0,V.jsxs)(v,{value:r==null?void 0:String(r),onValueChange:e=>i(e),disabled:_,children:[(0,V.jsx)(x,{id:m,children:(0,V.jsx)(d,{placeholder:`Select…`})}),(0,V.jsx)(N,{children:t.options?.map(e=>(0,V.jsx)(s,{value:String(e.value),children:F(e)},String(e.value)))})]}));case`radio`:return P((0,V.jsx)(f,{value:r==null?void 0:String(r),onValueChange:e=>i(e),disabled:_,children:t.options?.map(e=>(0,V.jsxs)(`div`,{className:`flex items-center space-x-2`,children:[(0,V.jsx)(S,{value:String(e.value),id:`${m}-${e.value}`}),(0,V.jsx)(w,{htmlFor:`${m}-${e.value}`,className:`text-sm font-normal`,children:F(e)})]},String(e.value)))}));case`multiselect`:{let e=Array.isArray(r)?r:[];return P((0,V.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:t.options?.map(t=>{let n=String(t.value);return(0,V.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,V.jsx)(l,{checked:e.map(String).includes(n),disabled:_,onCheckedChange:t=>{let r=new Set(e.map(String));t?r.add(n):r.delete(n),i(Array.from(r))}}),F(t)]},n)})}))}case`slider`:return P((0,V.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,V.jsx)(M,{value:[Number(r??t.min??0)],min:t.min??0,max:t.max??100,step:t.step??1,disabled:_,onValueChange:e=>i(e[0]),className:`flex-1`}),(0,V.jsx)(`span`,{className:`text-sm tabular-nums w-12 text-right`,children:String(r??t.min??0)})]}));case`color`:return P((0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(C,{id:m,type:`color`,value:r??`#000000`,disabled:_,onChange:e=>i(e.target.value),className:`w-16 h-9 p-1`}),(0,V.jsx)(C,{value:r??``,disabled:_,onChange:e=>i(e.target.value),className:`flex-1 font-mono text-sm`})]}));case`json`:return P((0,V.jsx)(g,{id:m,rows:t.rows??6,className:`font-mono text-xs`,value:typeof r==`string`?r:JSON.stringify(r??null,null,2),disabled:_,onChange:e=>i(e.target.value)}));default:return P((0,V.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[`Unsupported specifier type: `,t.type]}))}}var q=new Set([`common`,`validation`,`errors`,`system`,`auth`]);function J(e){let{t,i18n:n}=a();return(0,B.useMemo)(()=>{let r=()=>{if(!n||typeof n.getResourceBundle!=`function`)return[];let e=n.language||`en`,t=n.getResourceBundle(e,`translation`);return t?Object.keys(t).filter(e=>!q.has(e)&&t[e]&&typeof t[e]==`object`&&t[e].settings):[]},i=(n,i)=>{if(!e)return i;try{let i=r();for(let r of i){let i=`${r}.settings.${e}.${n}`,a=t(i,{defaultValue:``});if(a&&a!==i&&a!==``)return a}}catch{}return i},a=(e,r)=>{try{if(!n||typeof n.getResourceBundle!=`function`)return r;let i=n.language||`en`,a=n.getResourceBundle(i,`translation`);if(!a)return r;for(let n of Object.keys(a)){if(q.has(n))continue;let r=a[n];if(!r||typeof r!=`object`||!(`settingsCommon`in r))continue;let i=`${n}.settingsCommon.${e}`,o=t(i,{defaultValue:``});if(o&&o!==i&&o!==``)return o}}catch{}return r},o={env:`Env`,global:`Global`,tenant:`Tenant`,user:`User`,default:`Default`};return{title:e=>i(`title`,e)??e,description:e=>i(`description`,e),groupTitle:(e,t)=>i(`groups.${e}.title`,t)??t,groupDescription:(e,t)=>i(`groups.${e}.description`,t),fieldLabel:(e,t)=>i(`keys.${e}.label`,t)??t,fieldHelp:(e,t)=>i(`keys.${e}.help`,t),fieldPlaceholder:(e,t)=>i(`keys.${e}.placeholder`,t),optionLabel:(e,t,n)=>i(`keys.${e}.options.${t}`,n)??n,actionLabel:(e,t)=>i(`actions.${e}.label`,t)??t,actionConfirm:(e,t)=>i(`actions.${e}.confirmText`,t),actionSuccess:(e,t)=>i(`actions.${e}.successMessage`,t),sourceLabel:e=>a(`sourceLabels.${e}`,o[e]??e)}},[e,t,n,n?.language])}function Y(e,t){if(!e)return!0;let n=e.trim().match(/^\$\{(.+)\}$/);if(!n)return!0;try{return!!Function(`data`,`with (data) { return (${n[1]}); }`)(t)}catch{return!0}}function X(){let e=n(),r=t(),i=e.namespace??``,[a,s]=(0,B.useState)(null),[l,u]=(0,B.useState)(!0),[d,f]=(0,B.useState)(!1),[h,g]=(0,B.useState)(null),[v,y]=(0,B.useState)({}),x=(0,B.useCallback)(async()=>{u(!0),g(null);try{s(await L(i)),y({})}catch(e){g(e?.message??`Failed to load settings`)}finally{u(!1)}},[i]);(0,B.useEffect)(()=>{i&&x()},[i,x]);let S=(0,B.useMemo)(()=>{let e={};if(!a)return e;for(let[t,n]of Object.entries(a.values))e[t]=n.value;return{...e,...v}},[a,v]),C=(0,B.useMemo)(()=>Object.keys(v),[v]),w=J(i);if(!i)return(0,V.jsx)(`div`,{className:`p-6 text-muted-foreground`,children:`No namespace selected.`});if(l)return(0,V.jsxs)(`div`,{className:`p-6 space-y-3 max-w-3xl`,children:[(0,V.jsx)(o,{className:`h-8 w-1/3`}),(0,V.jsx)(o,{className:`h-4 w-2/3`}),(0,V.jsx)(o,{className:`h-32 w-full`}),(0,V.jsx)(o,{className:`h-32 w-full`})]});if(h)return(0,V.jsxs)(`div`,{className:`p-6 max-w-3xl`,children:[(0,V.jsxs)(D,{variant:`ghost`,size:`sm`,onClick:()=>r(-1),children:[(0,V.jsx)(m,{className:`h-4 w-4 mr-1`}),` Back`]}),(0,V.jsx)(p,{className:`mt-3`,children:(0,V.jsx)(A,{className:`py-8 text-center text-sm text-destructive`,children:h})})]});if(!a)return null;let{manifest:T,values:E}=a,O=T.icon?R(T.icon):null,k=w.title(z(T.label)),j=w.description(T.description),M=async()=>{if(C.length!==0){f(!0);try{let e=await F(i,v);s({...a,values:{...E,...e.values}}),y({}),P.success(`Settings saved`)}catch(e){e?.payload?.error?.code===`SETTINGS_LOCKED`?P.error(`Locked by environment: ${e.payload.error.key}`):P.error(e?.message??`Save failed`)}finally{f(!1)}}},N=async e=>{f(!0);try{let t=await I(i,e,v);t.ok?P.success(t.message??`Action succeeded`):P.error(t.message??`Action failed`)}catch(e){P.error(e?.message??`Action failed`)}finally{f(!1)}};return(0,V.jsxs)(`div`,{className:`p-6 max-w-3xl mx-auto pb-32`,children:[(0,V.jsxs)(D,{variant:`ghost`,size:`sm`,onClick:()=>r(`/system/settings`),children:[(0,V.jsx)(m,{className:`h-4 w-4 mr-1`}),` All settings`]}),(0,V.jsxs)(`div`,{className:`mt-3 flex items-start gap-3`,children:[O?(0,V.jsx)(O,{className:`h-7 w-7 mt-0.5 text-muted-foreground`}):null,(0,V.jsxs)(`div`,{className:`flex-1`,children:[(0,V.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,V.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight`,children:k}),T.beta?(0,V.jsx)(_,{variant:`secondary`,children:`Beta`}):null]}),j?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:j}):null]})]}),T.helpText?(0,V.jsx)(`p`,{className:`text-sm text-muted-foreground mt-4 whitespace-pre-wrap`,children:T.helpText}):null,(0,V.jsx)(`div`,{className:`mt-6 divide-y`,children:T.specifiers.filter(e=>Y(e.visible,S)).map((e,t)=>{let n=e.key,r=n?E[n]:void 0;return(0,V.jsx)(K,{spec:e,resolved:r,value:n?n in v?v[n]:r?.value:void 0,onChange:e=>n&&y(t=>({...t,[n]:e})),onAction:e.type===`action_button`?()=>N(e.id??n??`test`):void 0,locked:r?.locked,saving:d,labels:w},(n??`_layout_${t}`)+t)})}),C.length>0?(0,V.jsx)(`div`,{className:`fixed bottom-0 inset-x-0 bg-background/95 backdrop-blur border-t shadow-lg z-40`,children:(0,V.jsxs)(`div`,{className:`max-w-3xl mx-auto px-6 py-3 flex items-center justify-between`,children:[(0,V.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[C.length,` unsaved change`,C.length>1?`s`:``]}),(0,V.jsxs)(`div`,{className:`flex gap-2`,children:[(0,V.jsxs)(D,{variant:`ghost`,size:`sm`,onClick:()=>y({}),disabled:d,children:[(0,V.jsx)(b,{className:`h-4 w-4 mr-1`}),` Discard`]}),(0,V.jsxs)(D,{onClick:M,disabled:d,children:[d?(0,V.jsx)(c,{className:`h-4 w-4 mr-1 animate-spin`}):null,`Save changes`]})]})]})}):null]})}export{X as SettingsView};
@@ -1 +1 @@
1
- import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{f as t,m as n,r,y as i}from"./vendor-react-CyVA1SE-.js";import{d as a}from"./infrastructure-IQKE4Vv8.js";import{x as o}from"./framework-DVkqUSPj.js";import{Dr as s,Jn as c,Kn as l,Or as u,Pa as d,Qn as f,Wr as p,Xn as m,Yn as h,Zr as g,as as _,bo as v,ka as y,mi as b,qn as x,ui as S,us as C,vi as w,xa as T}from"./ui-components-CIdYg6m3.js";import"./index-DWtLSzKK.js";var E=e(i(),1),D=r();function O(){let e=t(),{appName:r}=n(),i=r?`/apps/${r}`:``,O=o(),k=a(),[A,j]=(0,E.useState)({users:null,orgs:null,roles:null,permissions:null,auditLogs:null}),[M,N]=(0,E.useState)(!0),P=(0,E.useCallback)(async()=>{if(O){N(!0);try{let[e,t,n,r,i]=await Promise.all([O.find(`sys_user`).catch(()=>({data:[]})),O.find(`sys_org`).catch(()=>({data:[]})),O.find(`sys_role`).catch(()=>({data:[]})),O.find(`sys_permission`).catch(()=>({data:[]})),O.find(`sys_audit_log`).catch(()=>({data:[]}))]);j({users:e.data?.length??0,orgs:t.data?.length??0,roles:n.data?.length??0,permissions:r.data?.length??0,auditLogs:i.data?.length??0})}catch{}finally{N(!1)}}},[O]);(0,E.useEffect)(()=>{P()},[P]);let F=[{title:`Applications`,description:`Manage all configured applications`,icon:y,href:`${i}/system/apps`,countLabel:``,count:null},{title:`Metadata`,description:`Browse and edit every metadata type the platform exposes`,icon:v,href:`${i}/component/metadata/directory`,countLabel:``,count:null}],I=[{title:`Users`,description:`Manage system users and accounts`,icon:s,href:`${i}/system/users`,countLabel:`users`,count:A.users},{title:`Organizations`,description:`Manage organizations and teams`,icon:_,href:`${i}/system/organizations`,countLabel:`organizations`,count:A.orgs},{title:`Roles`,description:`Configure roles and access levels`,icon:S,href:`${i}/system/roles`,countLabel:`roles`,count:A.roles},{title:`Permissions`,description:`Manage permission rules and assignments`,icon:d,href:`${i}/system/permissions`,countLabel:`permissions`,count:A.permissions},{title:`Audit Log`,description:`View system activity and changes`,icon:w,href:`${i}/system/audit-log`,countLabel:`entries`,count:A.auditLogs},{title:`AI Approvals`,description:`Review actions AI agents propose before they execute`,icon:C,href:`${i}/system/ai-approvals`,countLabel:``,count:null},{title:`App Marketplace`,description:`Browse and install approved apps from the ObjectStack catalog`,icon:g,href:`${i}/system/marketplace`,countLabel:``,count:null,adminOnly:!0},{title:`Settings`,description:`Configure mail, branding, feature flags, and more`,icon:b,href:`${i}/system/settings`,countLabel:``,count:null},{title:`Developer`,description:`API console, flow runs, and public form management`,icon:p,href:`${i}/developer`,countLabel:``,count:null},{title:`Profile`,description:`View and edit your account settings`,icon:u,href:`${i}/system/profile`,countLabel:``,count:null}],L=[...F,...I].filter(e=>!e.adminOnly||k);return(0,D.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`System Settings`}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage applications, users, roles, permissions, and system configuration`})]}),M&&(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,D.jsx)(T,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading statistics...`]}),(0,D.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:L.map(t=>{let n=t.icon;return(0,D.jsxs)(l,{className:`cursor-pointer transition-colors hover:bg-accent/50`,onClick:()=>e(t.href),"data-testid":`hub-card-${t.title.toLowerCase().replace(/\s+/g,`-`)}`,role:`link`,tabIndex:0,"aria-label":`${t.title}: ${t.description}`,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(t.href))},children:[(0,D.jsxs)(h,{className:`flex flex-row items-center gap-3 pb-2`,children:[(0,D.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,D.jsx)(n,{className:`h-5 w-5`})}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(m,{className:`text-base`,children:t.title}),(0,D.jsx)(c,{className:`text-xs`,children:t.description})]})]}),(0,D.jsx)(x,{className:`pt-0`,children:t.count!==null&&(0,D.jsxs)(f,{variant:`secondary`,children:[t.count,` `,t.countLabel]})})]},t.title)})})]})}export{O as SystemHubPage};
1
+ import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{f as t,m as n,r,y as i}from"./vendor-react-CyVA1SE-.js";import{d as a}from"./infrastructure-CFhpdDcd.js";import{S as o}from"./framework-Bsl5NTfe.js";import{Cs as s,Dr as c,Ea as l,Jn as u,Kn as d,Or as f,Pa as p,Qn as m,Wr as h,Xn as g,Yn as _,Zr as v,_s as y,di as b,hi as x,jo as S,qn as C,yi as w,za as T}from"./ui-components-D0tUqjB3.js";import"./index-D8443YMB.js";var E=e(i(),1),D=r();function O(){let e=t(),{appName:r}=n(),i=r?`/apps/${r}`:``,O=o(),k=a(),[A,j]=(0,E.useState)({users:null,orgs:null,roles:null,permissions:null,auditLogs:null}),[M,N]=(0,E.useState)(!0),P=(0,E.useCallback)(async()=>{if(O){N(!0);try{let[e,t,n,r,i]=await Promise.all([O.find(`sys_user`).catch(()=>({data:[]})),O.find(`sys_org`).catch(()=>({data:[]})),O.find(`sys_role`).catch(()=>({data:[]})),O.find(`sys_permission`).catch(()=>({data:[]})),O.find(`sys_audit_log`).catch(()=>({data:[]}))]);j({users:e.data?.length??0,orgs:t.data?.length??0,roles:n.data?.length??0,permissions:r.data?.length??0,auditLogs:i.data?.length??0})}catch{}finally{N(!1)}}},[O]);(0,E.useEffect)(()=>{P()},[P]);let F=[{title:`Applications`,description:`Manage all configured applications`,icon:p,href:`${i}/system/apps`,countLabel:``,count:null},{title:`Metadata`,description:`Browse and edit every metadata type the platform exposes`,icon:S,href:`${i}/component/metadata/directory`,countLabel:``,count:null}],I=[{title:`Users`,description:`Manage system users and accounts`,icon:c,href:`${i}/system/users`,countLabel:`users`,count:A.users},{title:`Organizations`,description:`Manage organizations and teams`,icon:y,href:`${i}/system/organizations`,countLabel:`organizations`,count:A.orgs},{title:`Roles`,description:`Configure roles and access levels`,icon:b,href:`${i}/system/roles`,countLabel:`roles`,count:A.roles},{title:`Permissions`,description:`Manage permission rules and assignments`,icon:T,href:`${i}/system/permissions`,countLabel:`permissions`,count:A.permissions},{title:`Audit Log`,description:`View system activity and changes`,icon:w,href:`${i}/system/audit-log`,countLabel:`entries`,count:A.auditLogs},{title:`AI Approvals`,description:`Review actions AI agents propose before they execute`,icon:s,href:`${i}/system/ai-approvals`,countLabel:``,count:null},{title:`App Marketplace`,description:`Browse and install approved apps from the ObjectStack catalog`,icon:v,href:`${i}/system/marketplace`,countLabel:``,count:null,adminOnly:!0},{title:`Settings`,description:`Configure mail, branding, feature flags, and more`,icon:x,href:`${i}/system/settings`,countLabel:``,count:null},{title:`Developer`,description:`API console, flow runs, and public form management`,icon:h,href:`${i}/developer`,countLabel:``,count:null},{title:`Profile`,description:`View and edit your account settings`,icon:f,href:`${i}/system/profile`,countLabel:``,count:null}],L=[...F,...I].filter(e=>!e.adminOnly||k);return(0,D.jsxs)(`div`,{className:`flex flex-col gap-6 p-4 sm:p-6`,children:[(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`System Settings`}),(0,D.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage applications, users, roles, permissions, and system configuration`})]}),M&&(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,role:`status`,"aria-live":`polite`,children:[(0,D.jsx)(l,{className:`h-4 w-4 animate-spin`,"aria-hidden":`true`}),`Loading statistics...`]}),(0,D.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 lg:grid-cols-3`,children:L.map(t=>{let n=t.icon;return(0,D.jsxs)(d,{className:`cursor-pointer transition-colors hover:bg-accent/50`,onClick:()=>e(t.href),"data-testid":`hub-card-${t.title.toLowerCase().replace(/\s+/g,`-`)}`,role:`link`,tabIndex:0,"aria-label":`${t.title}: ${t.description}`,onKeyDown:n=>{(n.key===`Enter`||n.key===` `)&&(n.preventDefault(),e(t.href))},children:[(0,D.jsxs)(_,{className:`flex flex-row items-center gap-3 pb-2`,children:[(0,D.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-lg bg-primary/10 text-primary`,children:(0,D.jsx)(n,{className:`h-5 w-5`})}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(g,{className:`text-base`,children:t.title}),(0,D.jsx)(u,{className:`text-xs`,children:t.description})]})]}),(0,D.jsx)(C,{className:`pt-0`,children:t.count!==null&&(0,D.jsxs)(m,{variant:`secondary`,children:[t.count,` `,t.countLabel]})})]},t.title)})})]})}export{O as SystemHubPage};
@@ -0,0 +1 @@
1
+ import{p as e}from"./vendor-objectstack-D6pAOWWu.js";import{ut as t}from"./framework-Bsl5NTfe.js";var n=class{cache;inflight;maxSize;ttl;stats;constructor(e={}){this.cache=new Map,this.inflight=new Map,this.maxSize=e.maxSize||100,this.ttl=e.ttl||300*1e3,this.stats={hits:0,misses:0,evictions:0,coalesced:0}}async get(e,t){let n=Date.now(),r=this.cache.get(e);if(r){if(n-r.timestamp<this.ttl)return r.accessCount++,r.lastAccessed=n,this.stats.hits++,this.cache.delete(e),this.cache.set(e,r),r.data;this.cache.delete(e)}let i=this.inflight.get(e);if(i)return this.stats.coalesced++,i;this.stats.misses++;let a=(async()=>{try{let n=await t();return this.set(e,n),n}finally{this.inflight.delete(e)}})();return this.inflight.set(e,a),a}prime(e,t){this.set(e,t)}set(e,t){let n=Date.now();this.cache.size>=this.maxSize&&!this.cache.has(e)&&this.evictLRU(),this.cache.set(e,{data:t,timestamp:n,accessCount:1,lastAccessed:n})}evictLRU(){let e=this.cache.keys().next().value;e!==void 0&&(this.cache.delete(e),this.stats.evictions++)}invalidate(e){e?this.cache.delete(e):this.cache.clear()}clear(){this.cache.clear(),this.inflight.clear(),this.stats={hits:0,misses:0,evictions:0,coalesced:0}}getStats(){let e=this.stats.hits+this.stats.misses,t=e>0?this.stats.hits/e:0;return{size:this.cache.size,maxSize:this.maxSize,hits:this.stats.hits,misses:this.stats.misses,evictions:this.stats.evictions,coalesced:this.stats.coalesced,hitRate:t}}getCachedSync(e){let t=this.cache.get(e);if(t){if(this.ttl>0&&Date.now()-t.timestamp>this.ttl){this.cache.delete(e);return}return this.cache.delete(e),this.cache.set(e,t),this.stats.hits++,t.data}}has(e){let t=this.cache.get(e);return t?Date.now()-t.timestamp>=this.ttl?(this.cache.delete(e),!1):!0:!1}},r=class extends Error{code;statusCode;details;constructor(e,t,n,r){super(e),this.code=t,this.statusCode=n,this.details=r,this.name=`ObjectStackError`,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor)}toJSON(){return{name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,details:this.details,stack:this.stack}}},i=class extends r{constructor(e,t){super(`Metadata not found for object: ${e}`,`METADATA_NOT_FOUND`,404,{objectName:e,...t}),this.name=`MetadataNotFoundError`}},a=class extends r{successCount;failureCount;errors;constructor(e,t,n,r,i){super(`Bulk ${e} operation failed: ${t} succeeded, ${n} failed`,`BULK_OPERATION_ERROR`,500,{operation:e,successCount:t,failureCount:n,errors:r,...i}),this.successCount=t,this.failureCount=n,this.errors=r,this.name=`BulkOperationError`}getSummary(){let e=this.successCount+this.failureCount,t=e>0?this.failureCount/e:0;return{operation:this.details?.operation,total:e,successful:this.successCount,failed:this.failureCount,failureRate:t,errors:this.errors}}},o=class extends r{url;constructor(e,t,n,r){super(`Connection error: ${e}`,`CONNECTION_ERROR`,r||503,{url:t,...n}),this.url=t,this.name=`ConnectionError`}},s=class extends r{constructor(e=`Authentication failed`,t,n){super(e,`AUTHENTICATION_ERROR`,n||401,t),this.name=`AuthenticationError`}},c=class extends r{field;validationErrors;constructor(e,t,n,r){super(e,`VALIDATION_ERROR`,400,{field:t,validationErrors:n,...r}),this.field=t,this.validationErrors=n,this.name=`ValidationError`}getValidationErrors(){return this.validationErrors||[]}};function l(e,t){let n=e?.status||e?.statusCode||500,a=e?.message||e?.statusText||`Unknown error`,l={context:t,response:{status:n,data:e?.data,headers:e?.headers}};switch(n){case 401:return new s(a,l,401);case 403:return new s(a,l,403);case 404:return t?.includes(`metadata`)||t?.includes(`schema`)||t?.includes(`getObjectSchema`)?new i(u(t),l):new r(a,`NOT_FOUND`,404,l);case 400:return new c(a,void 0,e?.data?.errors,l);case 503:return new o(a,e?.config?.url,l,503);case 504:return new o(a,e?.config?.url,l,504);default:return new r(a,`UNKNOWN_ERROR`,n,l)}}function u(e){if(!e)return`unknown`;let t=e.match(/\(([^)]+)\)/);return t?t[1]:`unknown`}var d=`sys_user_preference`;function f(e){let{dataSource:t,userId:n,key:r,resource:i=d,onError:a=()=>{}}=e,o=null,s=async()=>{let e={$filter:{user_id:n,key:r},$top:1};return((await t.find(i,e))?.data??[]).find(e=>{if(!e)return!1;let t=e.user_id!==void 0&&e.user_id!==n,i=e.key!==void 0&&e.key!==r;return!t&&!i})??null},c=e=>{if(Array.isArray(e))return e;if(typeof e==`string`)try{let t=JSON.parse(e);return Array.isArray(t)?t:[]}catch{return[]}return[]};return{async load(){try{let e=await s();return e?(e.id!==void 0&&e.id!==null&&(o=e.id),c(e.value)):(o=null,[])}catch(e){return a(`load`,e),[]}},async save(e){try{let c=new Date().toISOString();if(o!==null)try{await t.update(i,o,{value:e,updated_at:c});return}catch(e){o=null,a(`save`,e)}let l=await s();if(l&&l.id!==void 0&&l.id!==null){o=l.id,await t.update(i,l.id,{value:e,updated_at:c});return}let u=(await t.create(i,{user_id:n,key:r,value:e,updated_at:c}))?.id;u!=null&&(o=u)}catch(e){a(`save`,e)}}}}var p=`/meta`,m=`/api/v1`;function h(e){let t=e.baseUrl.replace(/\/+$/,``),n=e.environmentId?`${m}/environments/${encodeURIComponent(e.environmentId)}${p}`:`${m}${p}`;return/\/api\/v\d+$/i.test(t)?`${t.replace(/\/api\/v\d+$/i,``)}${e.environmentId?`${m}/environments/${encodeURIComponent(e.environmentId)}${p}`:`${m}${p}`}`:`${t}${n}`}async function g(e){let t;try{t=await e.json()}catch{t=await e.text().catch(()=>void 0)}let n=(t&&typeof t==`object`&&`error`in t?String(t.error):void 0)??`Metadata request failed: ${e.status} ${e.statusText}`,r=Error(n);return r.status=e.status,r.body=t,t&&typeof t==`object`&&`code`in t&&(r.code=String(t.code)),r}var _=class e{base;fetchImpl;headers;constructor(e){this.base=h(e),this.fetchImpl=e.fetch??globalThis.fetch.bind(globalThis),this.headers={Accept:`application/json`,...e.headers??{}}}withEnvironment(t){return new e({baseUrl:this.base.replace(/\/api\/v\d+(?:\/environments\/[^/]+)?\/meta$/,``).replace(/\/+$/,``),environmentId:t,fetch:this.fetchImpl,headers:this.headers})}async listTypes(){let e=await this.fetchImpl(this.base,{method:`GET`,headers:this.headers,cache:`no-store`});if(!e.ok)throw await g(e);let t=await e.json();return Array.isArray(t)?t:t&&Array.isArray(t.entries)?t.entries:t&&Array.isArray(t.items)?t.items:t&&Array.isArray(t.types)?t.types.map(e=>({type:e})):[]}async list(e,t={}){let n=t.packageId?`?package=${encodeURIComponent(t.packageId)}`:``,r=`${this.base}/${encodeURIComponent(e)}${n}`,i=await this.fetchImpl(r,{method:`GET`,headers:this.headers,cache:`no-store`});if(!i.ok)throw await g(i);let a=await i.json();return Array.isArray(a)?a:a&&Array.isArray(a.items)?a.items:[]}async get(e,t,n={}){let r=n.state===`draft`?`?state=draft`:``,i=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r}`,a=await this.fetchImpl(i,{method:`GET`,headers:this.headers,cache:`no-store`});if(a.status===404)return null;if(!a.ok)throw await g(a);return await a.json()}async getDraft(e,t){return this.get(e,t,{state:`draft`})}async save(e,t,n,r={}){let i=[];r.force&&i.push(`force=true`),r.mode===`draft`&&i.push(`mode=draft`),r.packageId&&i.push(`package=${encodeURIComponent(r.packageId)}`);let a=i.length?`?${i.join(`&`)}`:``,o=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}${a}`,s={...this.headers,"Content-Type":`application/json`};r.ifMatch&&(s[`If-Match`]=r.ifMatch),r.actor&&(s[`X-Actor`]=r.actor);let c=await this.fetchImpl(o,{method:`PUT`,headers:s,body:JSON.stringify(n)});if(!c.ok)throw await g(c);return await c.json()}async layered(e,t){let n=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}?layers=true`,r=await this.fetchImpl(n,{method:`GET`,headers:this.headers,cache:`no-store`});if(r.status===404)return{code:null,overlay:null,overlayScope:null,effective:null};if(!r.ok)throw await g(r);let i=await r.json();return i&&(`code`in i||`overlay`in i||`effective`in i)?{code:i.code??null,overlay:i.overlay??null,overlayScope:i.overlayScope??null,effective:i.effective??null,...i._diagnostics?{_diagnostics:i._diagnostics}:{},...i.lock===void 0?{}:{lock:i.lock},...i.lockReason===void 0?{}:{lockReason:i.lockReason},...i.lockSource===void 0?{}:{lockSource:i.lockSource},...i.lockDocsUrl===void 0?{}:{lockDocsUrl:i.lockDocsUrl},...i.provenance===void 0?{}:{provenance:i.provenance},...i.packageId===void 0?{}:{packageId:i.packageId},...i.packageVersion===void 0?{}:{packageVersion:i.packageVersion},...i.editable===void 0?{}:{editable:i.editable},...i.deletable===void 0?{}:{deletable:i.deletable},...i.resettable===void 0?{}:{resettable:i.resettable}}:{code:null,overlay:null,overlayScope:null,effective:i}}async diagnostics(e={}){let t=[];e.type&&t.push(`type=${encodeURIComponent(e.type)}`),e.severity&&t.push(`severity=${encodeURIComponent(e.severity)}`),e.packageId&&t.push(`package=${encodeURIComponent(e.packageId)}`);let n=t.length?`?${t.join(`&`)}`:``,r=`${this.base}/diagnostics${n}`,i=await this.fetchImpl(r,{method:`GET`,headers:this.headers,cache:`no-store`});if(i.status===404)return{entries:[],total:0,scannedTypes:0,scannedItems:0,stats:{}};if(!i.ok)throw await g(i);let a=await i.json();return{entries:Array.isArray(a.entries)?a.entries:[],total:typeof a.total==`number`?a.total:0,scannedTypes:typeof a.scannedTypes==`number`?a.scannedTypes:0,scannedItems:typeof a.scannedItems==`number`?a.scannedItems:0,stats:a.stats&&typeof a.stats==`object`?a.stats:{}}}async references(e,t){let n=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/references`,r=await this.fetchImpl(n,{method:`GET`,headers:this.headers,cache:`no-store`});if(r.status===404)return[];if(!r.ok)throw await g(r);let i=await r.json();return Array.isArray(i)?i:i?.items??[]}async reset(e,t,n={}){let r=n.state===`draft`?`?state=draft`:``,i=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r}`,a={...this.headers};n.ifMatch&&(a[`If-Match`]=n.ifMatch),n.actor&&(a[`X-Actor`]=n.actor);let o=await this.fetchImpl(i,{method:`DELETE`,headers:a});if(!o.ok)throw await g(o);return await o.json()}async publish(e,t,n={}){let r=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/publish`,i={...this.headers,"Content-Type":`application/json`};n.actor&&(i[`X-Actor`]=n.actor);let a=await this.fetchImpl(r,{method:`POST`,headers:i,body:JSON.stringify(n.message?{message:n.message}:{})});if(!a.ok)throw await g(a);return await a.json()}async rollback(e,t,n,r={}){let i=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/rollback`,a={...this.headers,"Content-Type":`application/json`};r.actor&&(a[`X-Actor`]=r.actor);let o=await this.fetchImpl(i,{method:`POST`,headers:a,body:JSON.stringify({toVersion:n,...r.message?{message:r.message}:{}})});if(!o.ok)throw await g(o);return await o.json()}async diff(e,t,n,r){let i=new URLSearchParams;n!==void 0&&i.set(`from`,String(n)),r!==void 0&&i.set(`to`,String(r));let a=i.toString(),o=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/diff${a?`?${a}`:``}`,s=await this.fetchImpl(o,{method:`GET`,headers:this.headers,cache:`no-store`});if(!s.ok)throw await g(s);return await s.json()}async history(e,t,n={}){let r=new URLSearchParams;n.sinceSeq!==void 0&&r.set(`sinceSeq`,String(n.sinceSeq)),n.limit!==void 0&&r.set(`limit`,String(n.limit));let i=r.toString(),a=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/history${i?`?${i}`:``}`,o=await this.fetchImpl(a,{method:`GET`,headers:this.headers,cache:`no-store`});if(!o.ok)throw await g(o);return await o.json()}async audit(e,t,n={}){let r=new URLSearchParams;n.limit!==void 0&&r.set(`limit`,String(n.limit));let i=r.toString(),a=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/audit${i?`?${i}`:``}`,o=await this.fetchImpl(a,{method:`GET`,headers:this.headers,cache:`no-store`});if(!o.ok)throw await g(o);return await o.json()}},v={equals:`=`,eq:`=`,"==":`=`,not_equals:`!=`,notequals:`!=`,ne:`!=`,greater_than:`>`,greaterthan:`>`,gt:`>`,greater_than_or_equal:`>=`,greater_than_or_equals:`>=`,greaterthanorequal:`>=`,gte:`>=`,less_than:`<`,lessthan:`<`,lt:`<`,less_than_or_equal:`<=`,less_than_or_equals:`<=`,lessthanorequal:`<=`,lte:`<=`,in:`in`,not_in:`nin`,notin:`nin`,nin:`nin`,contains:`contains`,not_contains:`notcontains`,notcontains:`notcontains`,starts_with:`startswith`,startswith:`startswith`,ends_with:`endswith`,endswith:`endswith`,between:`between`,is_null:`isnull`,isnull:`isnull`,is_not_null:`isnotnull`,isnotnull:`isnotnull`};function y(e){return typeof e==`string`?v[e.toLowerCase()]??v[e]??e:null}function b(e){if(!e||typeof e!=`object`)return null;let t=e.field??e.name,n=y(e.operator??e.op??`=`);return!t||!n?null:[String(t),n,e.value]}function x(e){if(e!=null){if(Array.isArray(e)){if(e.length===0)return;let t=e[0];if(e.length>0&&typeof t==`object`&&t&&!Array.isArray(t)&&t.field!==void 0){let t=e.map(e=>b(e)).filter(e=>e!==null);return t.length===0?void 0:t.length===1?t[0]:[`and`,...t]}return e}if(typeof e==`object`)return Object.keys(e).length===0?void 0:e}}var S=new Map;async function C(e,t){let n=e||`<default>`,r=S.get(n);if(r)return r;let i=t().catch(e=>{throw S.delete(n),e});return S.set(n,i),i}function w(e){if(!e||typeof e!=`object`)return!1;let t=e;if(t.httpStatus===404||t.status===404||t.statusCode===404)return!0;let n=typeof t.code==`string`?t.code:``;return n===`object_not_found`||n===`record_not_found`}var T=class extends Error{code=`CONCURRENT_UPDATE`;httpStatus=409;currentVersion;currentRecord;constructor(e){super(e.message??`Record was modified by another user`),this.name=`ConcurrentUpdateError`,this.currentVersion=e.currentVersion,this.currentRecord=e.currentRecord}};function E(e){if(!e||typeof e!=`object`)return e;let t=e;if(t.code!==`CONCURRENT_UPDATE`&&t.httpStatus!==409||t.code!==`CONCURRENT_UPDATE`)return e;let n=t.details??{};return new T({currentVersion:typeof n.currentVersion==`string`?n.currentVersion:null,currentRecord:n.currentRecord??null,message:typeof t.message==`string`?t.message:void 0})}function D(){let e=e=>{if(!e||typeof e!=`object`)return!1;if(e.status===404||e.statusCode===404)return!0;let t=e.error;if(t&&typeof t==`object`){let e=t.code;if(e===`object_not_found`||e===`record_not_found`)return!0}return!1},t={debug:(e,t)=>console.debug(e,t??``),info:(e,t)=>console.info(e,t??``),warn:(e,t)=>console.warn(e,t??``),error:(t,n,r)=>{if(e(r)){console.debug(`[ObjectStack] ${t} (suppressed expected 404)`,r);return}console.error(t,n??``,r??``)},fatal:(e,t,n)=>console.error(e,t??``,n??``),log:(e,...t)=>console.log(e,...t),child:()=>t,withTrace:()=>t};return t}function O(e){if(typeof e!=`object`||!e)return JSON.stringify(e);if(Array.isArray(e))return`[${e.map(O).join(`,`)}]`;let t=e;return`{${Object.keys(t).sort().map(e=>`${JSON.stringify(e)}:${O(t[e])}`).join(`,`)}}`}var k=class{client;connected=!1;connectPromise=null;metadataCache;connectionState=`disconnected`;connectionStateListeners=[];batchProgressListeners=[];autoReconnect;maxReconnectAttempts;reconnectDelay;reconnectAttempts=0;baseUrl;token;fetchImpl;inflightFinds=new Map;missingResources=new Set;constructor(t){this.client=new e({...t,logger:D()}),this.metadataCache=new n(t.cache),this.autoReconnect=t.autoReconnect??!0,this.maxReconnectAttempts=t.maxReconnectAttempts??3,this.reconnectDelay=t.reconnectDelay??1e3,this.baseUrl=t.baseUrl,this.token=t.token,this.fetchImpl=t.fetch||globalThis.fetch.bind(globalThis)}async connect(){if(!this.connected)return this.connectPromise?this.connectPromise:(this.setConnectionState(`connecting`),this.connectPromise=(async()=>{try{let e=this.baseUrl||``,t=e?`${e.replace(/\/$/,``)}/api/v1/discovery`:`/api/v1/discovery`,n=await C(e,async()=>{let e=await this.fetchImpl(t,{method:`GET`,headers:this.token?{Authorization:`Bearer ${this.token}`}:void 0});if(!e.ok)throw Error(`discovery ${e.status} ${e.statusText}`);let n=await e.json();return n&&typeof n.success==`boolean`&&`data`in n?n.data:n});this.client.discoveryInfo=n,this.connected=!0,this.reconnectAttempts=0,this.setConnectionState(`connected`)}catch(e){let t=new o(e instanceof Error?e.message:`Failed to connect to ObjectStack server`,void 0,{originalError:e});if(this.setConnectionState(`error`,t),this.autoReconnect&&this.reconnectAttempts<this.maxReconnectAttempts)await this.attemptReconnect();else throw t}finally{this.connectPromise=null}})(),this.connectPromise)}async attemptReconnect(){this.reconnectAttempts++,this.setConnectionState(`reconnecting`);let e=this.reconnectDelay*2**(this.reconnectAttempts-1);await new Promise(t=>setTimeout(t,e)),this.connected=!1,await this.connect()}getConnectionState(){return this.connectionState}isConnected(){return this.connected&&this.connectionState===`connected`}onConnectionStateChange(e){return this.connectionStateListeners.push(e),()=>{let t=this.connectionStateListeners.indexOf(e);t>-1&&this.connectionStateListeners.splice(t,1)}}onBatchProgress(e){return this.batchProgressListeners.push(e),()=>{let t=this.batchProgressListeners.indexOf(e);t>-1&&this.batchProgressListeners.splice(t,1)}}setConnectionState(e,t){this.connectionState=e;let n={state:e,timestamp:Date.now(),error:t};this.connectionStateListeners.forEach(e=>{try{e(n)}catch(e){console.error(`Error in connection state listener:`,e)}})}emitBatchProgress(e){this.batchProgressListeners.forEach(t=>{try{t(e)}catch(e){console.error(`Error in batch progress listener:`,e)}})}async find(e,t){if(this.missingResources.has(e))return{data:[],total:0};let n=`${e}::${O(t)}`,r=this.inflightFinds.get(n);if(r)return r;let i=(async()=>{if(await this.connect(),t?.$expand&&t.$expand.length>0){let n=await this.rawFindWithPopulate(e,t);return this.normalizeQueryResult(n,t)}let n=this.convertQueryParams(t);try{let r=await this.client.data.find(e,n);return this.normalizeQueryResult(r,t)}catch(t){if(w(t))return this.missingResources.add(e),{data:[],total:0};throw t}})();this.inflightFinds.set(n,i);let a=()=>{this.inflightFinds.get(n)===i&&this.inflightFinds.delete(n)};return i.then(a,a),i}async findOne(e,t,n){if(await this.connect(),n?.$expand&&n.$expand.length>0)try{let r={...n,$filter:{id:String(t)},$top:1},i=await this.rawFindWithPopulate(e,r);if(Array.isArray(i))return i[0]||null;let a=i;return(a.records||a.value||[])[0]||null}catch(e){if(w(e))return null}try{return(await this.client.data.get(e,String(t))).record}catch(e){if(w(e))return null;throw e}}async create(e,t){return await this.connect(),(await this.client.data.create(e,t)).record}async update(e,t,n,r){await this.connect();try{return(await this.client.data.update(e,String(t),n,r?.ifMatch?{ifMatch:r.ifMatch}:void 0)).record}catch(e){throw E(e)}}async delete(e,t,n){await this.connect();try{return(await this.client.data.delete(e,String(t),n?.ifMatch?{ifMatch:n.ifMatch}:void 0)).deleted}catch(e){throw E(e)}}async bulkUpdate(e,t,n){if(await this.connect(),!t||t.length===0)return 0;let r=t.map(e=>({id:String(e),data:n})),i=this.client.data.updateMany;if(typeof i==`function`)try{let n=await i(e,r,{continueOnError:!0});return n&&typeof n==`object`&&typeof n.succeeded==`number`?n.succeeded:Array.isArray(n)?n.length:t.length}catch(e){throw E(e)}let a=0;for(let r of t)try{await this.client.data.update(e,String(r),n),a++}catch{}return a}async bulkDelete(e,t){if(await this.connect(),!t||t.length===0)return 0;let n=t.map(e=>String(e)),r=this.client.data.deleteMany;if(typeof r==`function`)try{let t=await r(e,n,{continueOnError:!0});return t&&typeof t==`object`&&typeof t.succeeded==`number`?t.succeeded:Array.isArray(t)?t.length:n.length}catch(e){throw E(e)}let i=0;for(let t of n)try{await this.client.data.delete(e,t),i++}catch{}return i}async bulk(e,t,n){if(await this.connect(),!n||n.length===0)return[];let i=n.length,o=0,s=0,c=()=>{this.emitBatchProgress({operation:t,total:i,completed:o,failed:s,percentage:i>0?(o+s)/i*100:0})};try{switch(t){case`create`:{c();let t=await this.client.data.createMany(e,n);return o=t.length,s=i-o,c(),t}case`delete`:{let t=n.map(e=>e.id).filter(Boolean);if(t.length===0){let e=n.map((e,t)=>({index:t,error:`Missing ID for item at index ${t}`}));throw s=n.length,c(),new a(`delete`,0,n.length,e)}return c(),await this.client.data.deleteMany(e,t),o=t.length,s=i-o,c(),[]}case`update`:{if(typeof this.client.data.updateMany==`function`)try{c();let t=this.client.data.updateMany,r=await t(e,n);return o=r.length,s=i-o,c(),r}catch{}let t=[],r=[];for(let i=0;i<n.length;i++){let a=n[i],l=a.id;if(!l){r.push({index:i,error:`Missing ID`}),s++,c();continue}try{let n=await this.client.data.update(e,String(l),a);t.push(n.record),o++,c()}catch(e){let t=e instanceof Error?e.message:String(e);r.push({index:i,error:t}),s++,c()}}if(r.length>0)throw new a(`update`,t.length,r.length,r,{resource:e,totalRecords:n.length});return t}default:throw new r(`Unsupported bulk operation: ${t}`,`UNSUPPORTED_OPERATION`,400)}}catch(i){if(c(),i instanceof a||i instanceof r)throw i;let o=i instanceof Error?i.message:String(i),s=n.map((e,t)=>({index:t,error:o}));throw new a(t,0,n.length,s,{resource:e,originalError:i})}}normalizeQueryResult(e,t){if(Array.isArray(e))return{data:e,total:e.length,page:1,pageSize:e.length,hasMore:!1};let n=e,r=n.records||n.value||[];return{data:r,total:n.total??n.count??r.length,page:t?.$skip&&t.$top?Math.floor(t.$skip/t.$top)+1:1,pageSize:t?.$top,hasMore:t?.$top?r.length===t.$top:!1}}async rawFindWithPopulate(e,t){let n=new URLSearchParams;if(t.$expand&&t.$expand.length>0&&n.set(`populate`,t.$expand.join(`,`)),t.$top!==void 0&&n.set(`top`,String(t.$top)),t.$skip!==void 0&&n.set(`skip`,String(t.$skip)),t.$select&&t.$select.length>0){let e=t.$select.includes(`id`)?t.$select:[`id`,...t.$select];n.set(`select`,e.join(`,`))}if(t.$orderby)if(Array.isArray(t.$orderby)){let e=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}).join(`,`);n.set(`sort`,e)}else{let e=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e).join(`,`);n.set(`sort`,e)}if(t.$filter!==void 0&&t.$filter!==null){let e=x(t.$filter);e!==void 0&&n.set(`filter`,JSON.stringify(e))}let r=this.baseUrl.replace(/\/$/,``),i=n.toString(),a=`${r}${/\/api\/v\d+$/i.test(r)?`/data`:`/api/v1/data`}/${e}${i?`?${i}`:``}`,o={"Content-Type":`application/json`};this.token&&(o.Authorization=`Bearer ${this.token}`);let s=await this.fetchImpl(a,{method:`GET`,headers:o});if(!s.ok){let e=await s.json().catch(()=>({message:s.statusText})),t=Error(e?.error?.message||e?.message||s.statusText);throw t.status=s.status,t}let c=await s.json();return c&&typeof c.success==`boolean`&&`data`in c?c.data:c}convertQueryParams(e){if(!e)return{};let n={};if(e.$select&&(n.select=e.$select.includes(`id`)?e.$select:[`id`,...e.$select]),e.$filter!==void 0&&e.$filter!==null&&!(Array.isArray(e.$filter)?e.$filter.length===0:typeof e.$filter==`object`&&Object.keys(e.$filter).length===0))if(Array.isArray(e.$filter))if(e.$filter.length>0&&typeof e.$filter[0]==`object`&&!Array.isArray(e.$filter[0])&&e.$filter[0].field!==void 0){let t=e.$filter.map(e=>b(e)).filter(e=>e!==null);t.length===0||(t.length===1?n.filters=t[0]:n.filters=[`and`,...t])}else n.filters=e.$filter;else n.filters=t(e.$filter);return e.$orderby&&(Array.isArray(e.$orderby)?n.sort=e.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}):n.sort=Object.entries(e.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e)),e.$skip!==void 0&&(n.skip=e.$skip),e.$top!==void 0&&(n.top=e.$top),n}async getObjectSchema(e){await this.connect();try{return await this.metadataCache.get(e,async()=>{let t=await this.client.meta.getItem(`object`,e);return t&&t.item?t.item:t})}catch(t){let n=t;throw w(n)?new i(e,{originalError:t}):t instanceof r?t:l(n,`getObjectSchema(${e})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async listViewOverrides(e){await this.connect();try{let t=`view-overrides:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItems(e),n=Array.isArray(t?.items)?t.items:[],r={};for(let e of n){if(!e||typeof e!=`object`)continue;let t=e.name??e.id??e._name;typeof t==`string`&&t&&(r[t]=e)}return r})}catch{return{}}}async getView(e,t){await this.connect();try{let n=`view:${e}:${t}`;return await this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,t);return n&&n.item?n.item:n??null})}catch{return null}}async updateViewConfig(e,t,n){await this.connect();try{let r={...n||{},object:n?.object||e,name:t},i=await this.client.meta.saveItem(`view`,t,r),a=`view:${e}:${t}`;return this.metadataCache.invalidate?.(a),this.metadataCache.invalidate?.(`view-overrides:${e}`),this.metadataCache.invalidate?.(`views:${e}`),i&&i.item?i.item:i??void 0}catch(e){throw e}}async listViews(e){await this.connect();try{let t=await this.client.meta.getItems(`view`),n=Array.isArray(t?.items)?t.items:Array.isArray(t)?t:[],r=new Set([`form`,`detail`]);return n.filter(t=>{if(!t)return!1;let n=t.list??t;if((n?.data?.object??n?.object??n?.objectName)!==e)return!1;let i=t.viewKind??n?.viewKind;return!(i&&r.has(i))}).map(e=>{let t=e.list??e;return t&&t.config&&typeof t.config==`object`?{...t.config,name:t.name??t.config.name,label:t.label??t.config.label,isDefault:!!t.isDefault}:t})}catch(e){return console.warn(`[OBJECTSTACKDataSource] listViews failed:`,e),[]}}async createView(e,t){await this.connect();let n=String(t?.name||``).trim();if(!n){let r=String(t?.label||e||`view`).toLowerCase().replace(/[^a-z0-9_]+/g,`_`).replace(/^_+|_+$/g,``).slice(0,40);(!r||/^[0-9]/.test(r))&&(r=r?`view_${r}`:`view`);let i=Date.now().toString(36);n=`${r}_${i}`}let r={...t,name:n,object:t?.object||e,data:t?.data||{provider:`object`,object:e}};try{let t=await this.client.meta.saveItem(`view`,n,r);return this.metadataCache.invalidate?.(`views:${e}`),t&&t.item?t.item:r}catch(e){throw e}}async updateView(e,t,n){await this.connect();let r={};try{let e=await this.client.meta.getItem(`view`,t);r=e&&(e.item||e)||{},r?.list&&(r=r.list)}catch{}let i={...r,...n,name:t,object:r?.object||r?.data?.object||e};try{let n=await this.client.meta.saveItem(`view`,t,i);return this.metadataCache.invalidate?.(`views:${e}`),this.metadataCache.invalidate?.(`view:${e}:${t}`),n&&n.item?n.item:i}catch(e){throw e}}async deleteView(e,t){await this.connect();try{let n=await this.client.meta.deleteItem(`view`,t);return this.metadataCache.invalidate?.(`views:${e}`),this.metadataCache.invalidate?.(`view:${e}:${t}`),{deleted:!!(n?.deleted??n?.reset??!0)}}catch(e){throw e}}async getApp(e){await this.connect();try{let t=`app:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`apps`,e);return t&&t.item?t.item:t??null})}catch{return null}}async getPage(e){await this.connect();try{let t=`page:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`pages`,e);return t&&t.item?t.item:t??null})}catch{return null}}async updateDashboard(e,t){await this.connect();try{let n=await this.client.meta.saveItem(`dashboard`,e,t);return this.metadataCache.invalidate?.(`dashboards`),this.metadataCache.invalidate?.(`dashboard:${e}`),n&&n.item?n.item:n??void 0}catch(e){throw e}}async aggregate(e,t){if(await this.connect(),t!=null&&(Array.isArray(t.groupBy)||Array.isArray(t.aggregations)||t.where!==void 0)){let n={};Array.isArray(t.groupBy)&&(n.groupBy=t.groupBy),Array.isArray(t.aggregations)&&(n.aggregations=t.aggregations),t.where!==void 0&&(n.where=t.where),typeof t.limit==`number`&&(n.limit=t.limit);let r=await this.client.data.query(e,n);return Array.isArray(r)?r:Array.isArray(r?.records)?r.records:Array.isArray(r?.data)?r.data:[]}try{let n=t.function===`count`?`count`:`${t.field}_${t.function}`,r={cube:e,measures:[n],dimensions:t.groupBy&&t.groupBy!==`_all`?[t.groupBy]:[]};t.filter&&(r.where=t.filter);let i=await this.client.analytics.query(r),a=Array.isArray(i)?i:i?.rows&&Array.isArray(i.rows)?i.rows:i?.data&&Array.isArray(i.data)?i.data:i?.data?.rows&&Array.isArray(i.data.rows)?i.data.rows:i?.results&&Array.isArray(i.results)?i.results:[];if(a.length>0&&a.every(e=>e==null?!0:!(n in e&&e[n]!=null||t.field in e&&e[t.field]!=null))){let n=(await this.find(e,t.filter?{$filter:t.filter}:void 0)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}return a.map(e=>{let r={...e};return n!==t.field&&n in r&&(r[t.field]=r[n],delete r[n]),r})}catch{let n=(await this.find(e,t.filter?{$filter:t.filter}:void 0)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}}aggregateClientSide(e,t){let{field:n,function:r,groupBy:i}=t,a={};for(let t of e){let e=String(t[i]??`Unknown`);a[e]||(a[e]=[]),a[e].push(t)}return Object.entries(a).map(([e,t])=>{let a=t.map(e=>Number(e[n])||0),o;switch(r){case`count`:o=t.length;break;case`avg`:o=a.length>0?a.reduce((e,t)=>e+t,0)/a.length:0;break;case`min`:o=a.length>0?Math.min(...a):0;break;case`max`:o=a.length>0?Math.max(...a):0;break;default:o=a.reduce((e,t)=>e+t,0);break}return{[i]:e,[n]:o}})}async getItems(e,t){return await this.connect(),await Promise.all(t.map(async t=>{let n=`${e}:${t}`;return this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,t);return n&&n.item?n.item:n})}))}getCached(e){return this.metadataCache.getCachedSync(e)}getCacheStats(){return this.metadataCache.getStats()}invalidateCache(e){this.metadataCache.invalidate(e)}clearCache(){this.metadataCache.clear()}async uploadFile(e,t,n){await this.connect();let i=new FormData;i.append(`file`,t),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}async uploadFiles(e,t,n){await this.connect();let i=new FormData;t.forEach((e,t)=>{i.append(`files`,e,e.name||`file-${t}`)}),n?.recordId&&i.append(`recordId`,n.recordId),n?.fieldName&&i.append(`fieldName`,n.fieldName),n?.metadata&&i.append(`metadata`,JSON.stringify(n.metadata));let a=`${this.baseUrl}/api/data/${encodeURIComponent(e)}/upload`,o=await fetch(a,{method:`POST`,body:i,headers:{...this.getAuthHeaders()}});if(!o.ok)throw new r((await o.json().catch(()=>({message:o.statusText}))).message||`Upload failed with status ${o.status}`,`UPLOAD_ERROR`,o.status);return o.json()}async cancelPendingApproval(e,t){await this.connect();let n=`${this.baseUrl}/api/v1/approvals/requests?recordId=${encodeURIComponent(t)}&object=${encodeURIComponent(e)}`,i=await this.fetchImpl(n,{method:`GET`,headers:{"Content-Type":`application/json`,...this.getAuthHeaders()}});if(!i.ok)throw new r(`Failed to look up approval requests (status ${i.status})`,`APPROVAL_LOOKUP_FAILED`,i.status);let a=await i.json().catch(()=>({})),o=(Array.isArray(a)?a:a?.data??[]).find(e=>e?.status===`pending`||e?.status===`in_approval`);if(!o?.id)throw new r(`No pending approval request found for this record`,`NO_PENDING_REQUEST`,404);let s=`${this.baseUrl}/api/v1/approvals/requests/${encodeURIComponent(o.id)}/recall`,c=await this.fetchImpl(s,{method:`POST`,headers:{"Content-Type":`application/json`,...this.getAuthHeaders()},body:JSON.stringify({})});if(!c.ok){let e=await c.json().catch(()=>({}));throw new r(e?.error||e?.message||`Recall failed with status ${c.status}`,e?.code||`APPROVAL_RECALL_FAILED`,c.status)}let l=await c.json().catch(()=>({}));return{requestId:o.id,status:l?.data?.request?.status??`recalled`}}getAuthHeaders(){let e={};return this.token&&(e.Authorization=`Bearer ${this.token}`),e}};export{_ as n,f as r,k as t};