@objectstack/console 7.2.1 → 7.3.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.
- package/dist/assets/{AiPendingActionsPage-DYX4ANzZ.js → AiPendingActionsPage-BbZbWYZF.js} +1 -1
- package/dist/assets/ApiConsolePage-CxtzVvxL.js +1 -0
- package/dist/assets/{AppManagementPage-BnwBNW_m.js → AppManagementPage-CFfnxT1t.js} +1 -1
- package/dist/assets/ApprovalsInboxPage-BxQZcCfd.js +1 -0
- package/dist/assets/{AuditLogPage-C1CgKWC8.js → AuditLogPage-D4FqYkQH.js} +1 -1
- package/dist/assets/{ComponentNavView-g_X1YUdk.js → ComponentNavView-XiNMCGMg.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-DQEWG5vB.js +1 -0
- package/dist/assets/{DeveloperHubPage-CcV4mWRr.js → DeveloperHubPage-lZkmDwEj.js} +1 -1
- package/dist/assets/FlowRunsPage-RrJ1_Gcu.js +1 -0
- package/dist/assets/ProfilePage-BGOg1gVa.js +1 -0
- package/dist/assets/PublicFormsPage-IlBXTnnv.js +1 -0
- package/dist/assets/{SettingsHub-4RDkAyKq.js → SettingsHub-D_bBB6HI.js} +1 -1
- package/dist/assets/{SettingsView-_5h2mExc.js → SettingsView-CErPIsVb.js} +1 -1
- package/dist/assets/{SystemHubPage-DRRxgNWV.js → SystemHubPage-B3lD5VE8.js} +1 -1
- package/dist/assets/data-adapter-DD2mxtaH.js +1 -0
- package/dist/assets/{framework-DVkqUSPj.js → framework-DmN5Xd7Z.js} +1 -1
- package/dist/assets/{highlighted-body-OFNGDK62-Dp9QBuY-.js → highlighted-body-OFNGDK62-_uUbA42F.js} +1 -1
- package/dist/assets/index-3n4YIBCx.js +33 -0
- package/dist/assets/index-DRnsSCuD.css +2 -0
- package/dist/assets/mermaid-GHXKKRXX-B0LJSQUI.js +1 -0
- package/dist/assets/plugin-calendar-CBSUjCse.js +1 -0
- package/dist/assets/{plugin-charts-DrCI3cJo.js → plugin-charts-C1pPCTiC.js} +2 -2
- package/dist/assets/plugin-chatbot-BHoielbC.js +120 -0
- package/dist/assets/plugin-dashboard-CrU-RT7P.js +3 -0
- package/dist/assets/{plugin-form-KOOMD5ZY.js → plugin-form-YkI84B6S.js} +1 -1
- package/dist/assets/plugin-gantt-BM_qU02_.js +1 -0
- package/dist/assets/plugin-grid-C__XZwVh.js +6 -0
- package/dist/assets/plugin-kanban-DpM0Y5w1.js +1 -0
- package/dist/assets/{plugin-map-DRf0LmJy.js → plugin-map-D5wjaTuu.js} +1 -1
- package/dist/assets/{plugin-markdown-BVFW0U6V.js → plugin-markdown-BS1-ubYs.js} +1 -1
- package/dist/assets/plugin-report-ClF2T8j-.js +59 -0
- package/dist/assets/plugin-timeline-DHjoax2v.js +1 -0
- package/dist/assets/plugin-view-DPiRuVYV.js +1 -0
- package/dist/assets/plugins-views-DKbDkBwY.js +4 -0
- package/dist/assets/{src-DL8N52oz.js → src-DftmwA5L.js} +1 -1
- package/dist/assets/{types-CbmNTewl.js → types-X_Rma6be.js} +1 -1
- package/dist/assets/ui-components-ClOuWOoQ.js +41 -0
- package/dist/assets/{ui-layout-DGPxy1gI.js → ui-layout-Ciu790M0.js} +1 -1
- package/dist/assets/vendor-objectstack-B5adaLmw.js +65 -0
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ApiConsolePage-C70S6MYv.js +0 -1
- package/dist/assets/ApprovalsInboxPage-CQQmK4Pz.js +0 -1
- package/dist/assets/ConsoleFloatingChatbot-DJW7zeKU.js +0 -1
- package/dist/assets/FlowRunsPage-Rtd6u1e_.js +0 -1
- package/dist/assets/ProfilePage-DPGkAZWG.js +0 -1
- package/dist/assets/PublicFormsPage-BNIOSFr1.js +0 -1
- package/dist/assets/data-adapter-Bi1Re1fK.js +0 -1
- package/dist/assets/index-DWtLSzKK.js +0 -33
- package/dist/assets/index-JLLCOoA3.css +0 -2
- package/dist/assets/mermaid-GHXKKRXX-PDO-QkSF.js +0 -1
- package/dist/assets/plugin-calendar-D1wyyvEx.js +0 -1
- package/dist/assets/plugin-chatbot-CiVctLlf.js +0 -120
- package/dist/assets/plugin-dashboard-BRn9AjyQ.js +0 -3
- package/dist/assets/plugin-gantt-D3OFukY1.js +0 -1
- package/dist/assets/plugin-grid-DGQxmfxn.js +0 -6
- package/dist/assets/plugin-kanban-C-qMP4VL.js +0 -1
- package/dist/assets/plugin-report-CJSBthhg.js +0 -59
- package/dist/assets/plugin-timeline-RAn1F_nX.js +0 -1
- package/dist/assets/plugin-view-DspcF1Mc.js +0 -1
- package/dist/assets/plugins-views-DUx-xpiH.js +0 -4
- package/dist/assets/ui-components-CIdYg6m3.js +0 -41
- package/dist/assets/vendor-objectstack-B3zP6Fz_.js +0 -65
package/dist/index.html
CHANGED
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
<script>
|
|
19
19
|
window.process = window.process || { env: { NODE_ENV: 'development' }, version: '', platform: 'browser' };
|
|
20
20
|
</script>
|
|
21
|
-
<script type="module" crossorigin src="./assets/index-
|
|
21
|
+
<script type="module" crossorigin src="./assets/index-3n4YIBCx.js"></script>
|
|
22
22
|
<link rel="stylesheet" crossorigin href="./assets/ui-components-BL3SEdAz.css">
|
|
23
23
|
<link rel="stylesheet" crossorigin href="./assets/plugin-dashboard-DnNKJB60.css">
|
|
24
|
-
<link rel="stylesheet" crossorigin href="./assets/index-
|
|
25
|
-
<link rel="modulepreload" href="./assets/framework-
|
|
26
|
-
<link rel="modulepreload" href="./assets/ui-components-
|
|
24
|
+
<link rel="stylesheet" crossorigin href="./assets/index-DRnsSCuD.css">
|
|
25
|
+
<link rel="modulepreload" href="./assets/framework-DmN5Xd7Z.js" />
|
|
26
|
+
<link rel="modulepreload" href="./assets/ui-components-ClOuWOoQ.js" />
|
|
27
27
|
<link rel="modulepreload" href="./assets/vendor-radix-thTS_QfF.js" />
|
|
28
28
|
<link rel="modulepreload" href="./assets/vendor-react-CyVA1SE-.js" />
|
|
29
29
|
</head>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@objectstack/console",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "Prebuilt Console SPA pinned to this @objectstack/framework release. Source of truth: @object-ui/console (https://github.com/objectstack-ai/objectui).",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/objectstack-ai/framework/tree/main/packages/console",
|
|
@@ -1 +0,0 @@
|
|
|
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{Co as i,Fi as a,Hn as o,Ko as s,Li as c,Lr as l,Oi as u,Oo as d,Qn as f,Un as p,Wn as m,Wo as h,Ya as g,_i as _,qo as v,xa as y,xr as ee}from"./ui-components-CIdYg6m3.js";import"./index-DWtLSzKK.js";var b=e(n(),1),x=[`plugin`,`plugins`,`kind`,`package`];function S(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 C={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 w(e,t){let n=C[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 te(){let e=r(),[t,n]=(0,b.useState)([]),[i,a]=(0,b.useState)([]),[o,s]=(0,b.useState)(!0),[c,l]=(0,b.useState)(null),u=(0,b.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(C)){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(...w(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=>!x.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,...S(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,b.useEffect)(()=>{u()},[u]),{groups:t,allEndpoints:i,loading:o,error:c,refresh:u}}var T=t(),E={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`},ne={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`},re=[{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:x}=te(),[S,C]=(0,b.useState)(``),[w,O]=(0,b.useState)(new Set),[k,A]=(0,b.useState)(null),[ie,j]=(0,b.useState)(``),[ae,M]=(0,b.useState)(``),[N,P]=(0,b.useState)(``),[F,I]=(0,b.useState)([]),[L,R]=(0,b.useState)(!1),[z,B]=(0,b.useState)(null),[V,H]=(0,b.useState)([]),[U,oe]=(0,b.useState)(null),[W,G]=(0,b.useState)(!1),K=(0,b.useMemo)(()=>{if(!S)return t;let e=S.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,S]),se=(0,b.useCallback)(e=>{O(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ce=(0,b.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,b.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,b.useCallback)((e=``,t=``)=>{I(n=>[...n,{id:D++,key:e,value:t,enabled:!0}])},[]),le=(0,b.useCallback)(e=>{I(t=>t.filter(t=>t.id!==e))},[]),Z=(0,b.useCallback)((e,t,n)=>{I(r=>r.map(r=>r.id===e?{...r,[t]:n}:r))},[]),ue=(0,b.useCallback)(e=>{I(t=>t.map(t=>t.id===e?{...t,enabled:!t.enabled}:t))},[]),Q=(0,b.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,b.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,b.useCallback)(()=>{z?.body&&(navigator.clipboard.writeText(z.body),G(!0),setTimeout(()=>G(!1),1500))},[z]),$=e=>ne[String(e)[0]]??`text-muted-foreground`;return(0,T.jsxs)(`div`,{className:`flex flex-1 min-h-0 overflow-hidden`,children:[(0,T.jsxs)(`div`,{className:`w-72 shrink-0 border-r flex flex-col overflow-hidden`,children:[(0,T.jsxs)(`div`,{className:`p-3 border-b space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.jsx)(`h3`,{className:`text-sm font-semibold text-foreground flex-1`,children:`API Endpoints`}),(0,T.jsx)(`button`,{onClick:x,disabled:n,className:`p-1 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,title:`Refresh endpoints`,children:(0,T.jsx)(u,{className:`h-3.5 w-3.5 ${n?`animate-spin`:``}`})})]}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(_,{className:`absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground`}),(0,T.jsx)(`input`,{type:`text`,value:S,onChange:e=>C(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,T.jsx)(`div`,{className:`flex-1 overflow-auto p-2 space-y-1`,children:n?(0,T.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,T.jsx)(y,{className:`h-4 w-4 animate-spin mr-2`}),`Discovering APIs...`]}):K.length===0?(0,T.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,T.jsx)(g,{className:`h-6 w-6 opacity-30 mb-2`}),(0,T.jsx)(`span`,{children:S?`No matching endpoints`:`No endpoints found`})]}):K.map(e=>{let t=w.has(e.key)||!!S;return(0,T.jsxs)(o,{open:t,onOpenChange:()=>se(e.key),children:[(0,T.jsx)(m,{asChild:!0,children:(0,T.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,T.jsx)(h,{className:`h-3 w-3 shrink-0 transition-transform duration-200 ${t?`rotate-90`:``}`}),(0,T.jsx)(`span`,{className:`flex-1 text-left truncate`,children:e.label}),(0,T.jsx)(`span`,{className:`shrink-0 text-[10px] tabular-nums opacity-60`,children:e.endpoints.length})]})}),(0,T.jsx)(p,{children:(0,T.jsx)(`div`,{className:`ml-3 space-y-0.5 mt-0.5`,children:e.endpoints.map((e,t)=>(0,T.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,T.jsx)(f,{variant:`outline`,className:`font-mono text-[9px] shrink-0 px-1 py-0 ${E[e.method]||``}`,children:e.method}),(0,T.jsx)(`span`,{className:`truncate`,children:e.desc})]},`${e.method}-${e.path}-${t}`))})})]},e.key)})}),(0,T.jsxs)(`div`,{className:`p-3 border-t space-y-2`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,T.jsx)(`h4`,{className:`text-[10px] font-medium text-muted-foreground uppercase tracking-wider`,children:`Query Parameters`}),(0,T.jsxs)(`button`,{onClick:()=>X(),className:`inline-flex items-center gap-0.5 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,T.jsx)(a,{className:`h-3 w-3`}),`Add`]})]}),(0,T.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:re.map(e=>(0,T.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,T.jsx)(`div`,{className:`space-y-1`,children:F.map(e=>(0,T.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>ue(e.id),className:`h-3 w-3 shrink-0 rounded border accent-primary`}),(0,T.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,T.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,T.jsx)(`button`,{onClick:()=>le(e.id),className:`shrink-0 p-0.5 rounded text-muted-foreground hover:text-destructive transition-colors`,children:(0,T.jsx)(ee,{className:`h-3 w-3`})})]},e.id))})]})]}),(0,T.jsxs)(`div`,{className:`flex-1 flex flex-col min-w-0 overflow-hidden`,children:[(0,T.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,T.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 ${E[q]||``}`,children:[`GET`,`POST`,`PATCH`,`PUT`,`DELETE`].map(e=>(0,T.jsx)(`option`,{value:e,children:e},e))}),(0,T.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,T.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,T.jsx)(y,{className:`h-3.5 w-3.5 animate-spin`}):(0,T.jsx)(c,{className:`h-3.5 w-3.5`}),`Send`]})]}),F.some(e=>e.enabled&&e.key.trim())&&(0,T.jsxs)(`div`,{className:`text-[10px] font-mono text-muted-foreground truncate pl-1`,children:[`→ `,Y]})]}),(0,T.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 overflow-auto`,children:[[`POST`,`PATCH`,`PUT`].includes(q)&&(0,T.jsxs)(`div`,{className:`p-3 border-b space-y-1`,children:[(0,T.jsx)(`label`,{className:`text-xs font-medium text-muted-foreground`,children:`Request Body (JSON)`}),(0,T.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,T.jsxs)(`div`,{className:`flex items-center justify-center py-8 text-muted-foreground text-sm`,children:[(0,T.jsx)(y,{className:`h-4 w-4 animate-spin mr-2`}),`Sending request...`]}),z&&!L&&(0,T.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col overflow-hidden`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2 bg-muted/30 border-b`,children:[(0,T.jsxs)(`div`,{className:`flex items-center gap-3 text-sm`,children:[(0,T.jsx)(`span`,{className:`font-mono font-semibold ${$(z.status)}`,children:z.status||`ERR`}),(0,T.jsxs)(`span`,{className:`text-muted-foreground flex items-center gap-1`,children:[(0,T.jsx)(d,{className:`h-3 w-3`}),z.duration,`ms`]})]}),(0,T.jsxs)(`button`,{onClick:fe,className:`inline-flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors`,children:[W?(0,T.jsx)(v,{className:`h-3 w-3`}):(0,T.jsx)(i,{className:`h-3 w-3`}),W?`Copied`:`Copy`]})]}),(0,T.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,T.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-muted-foreground text-sm`,children:(0,T.jsxs)(`div`,{className:`text-center space-y-2`,children:[(0,T.jsx)(g,{className:`h-10 w-10 mx-auto opacity-20`}),(0,T.jsxs)(`p`,{children:[`Select an endpoint or type a URL and click `,(0,T.jsx)(`strong`,{children:`Send`})]}),(0,T.jsx)(`p`,{className:`text-xs opacity-60`,children:`All registered APIs are auto-discovered from the platform`})]})}),V.length>0&&(0,T.jsxs)(`div`,{className:`border-t`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between px-3 py-2`,children:[(0,T.jsxs)(`h4`,{className:`text-xs font-medium text-muted-foreground uppercase tracking-wider`,children:[`History (`,V.length,`)`]}),(0,T.jsxs)(`button`,{onClick:()=>H([]),className:`inline-flex items-center gap-1 text-[10px] text-muted-foreground hover:text-foreground transition-colors`,children:[(0,T.jsx)(l,{className:`h-3 w-3`}),`Clear`]})]}),(0,T.jsx)(`div`,{className:`space-y-0.5 px-2 pb-2 max-h-60 overflow-auto`,children:V.map(e=>(0,T.jsxs)(`div`,{className:`rounded border`,children:[(0,T.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,T.jsx)(s,{className:`h-3 w-3 shrink-0`}):(0,T.jsx)(h,{className:`h-3 w-3 shrink-0`}),(0,T.jsx)(f,{variant:`outline`,className:`font-mono text-[9px] shrink-0 ${E[e.method]||``}`,children:e.method}),(0,T.jsx)(`span`,{className:`font-mono truncate text-left flex-1`,children:e.url}),(0,T.jsx)(`span`,{className:`ml-auto shrink-0 font-mono ${$(e.status)}`,children:e.status}),(0,T.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[e.duration,`ms`]}),(0,T.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,T.jsx)(c,{className:`h-2.5 w-2.5`})})]}),U===e.id&&(0,T.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 +0,0 @@
|
|
|
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";import{$ as i,At as a,Bt as o,Co as ee,F as te,Ft as ne,Gn as s,Ht as c,I as re,It as ie,Kn as ae,Lt as l,Mo as oe,Mr as se,Mt as ce,Nt as le,Oi as ue,Oo as de,Pt as fe,Q as pe,Qn as u,Rt as me,Vo as he,Vt as ge,_i as _e,ar as ve,at as d,cr as ye,ct as be,dr as xe,en as Se,et as Ce,fr as we,in as Te,it as Ee,lr as De,mr as f,nr as Oe,nt as p,or as ke,ot as m,pr as Ae,qn as je,ri as Me,rr as Ne,rt as Pe,sr as h,st as Fe,tt as Ie,ur as g,xr as Le,z as Re,zo as _,zt as v}from"./ui-components-CIdYg6m3.js";import{o as y}from"./vendor-ui-utils-BbOuugky.js";var b=e(n(),1),x=`${``.replace(/\/$/,``)}/api/v1`;async function S(e,t){let n=await fetch(`${x}${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 C={listProcesses(e={}){let t=new URLSearchParams;e.object&&t.set(`object`,e.object),e.activeOnly&&t.set(`activeOnly`,`true`);let n=t.toString();return S(`/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 S(`/approvals/requests${n?`?${n}`:``}`)},async getRequest(e){return{data:await S(`/approvals/requests/${encodeURIComponent(e)}`)}},listActions(e){return S(`/approvals/requests/${encodeURIComponent(e)}/actions`)},async approve(e,t){let n=await S(`/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 S(`/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 S(`/approvals/requests/${encodeURIComponent(e)}/recall`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async submit(e){return S(`/approvals/requests`,{method:`POST`,body:JSON.stringify(e)})}};function ze(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 w=t(),T={pending:{variant:`secondary`,label:`Pending`},approved:{variant:`default`,label:`Approved`},rejected:{variant:`destructive`,label:`Rejected`},recalled:{variant:`outline`,label:`Recalled`}};function E({status:e}){let t=T[e]??{variant:`outline`,label:e};return(0,w.jsx)(u,{variant:t.variant,children:t.label})}function D(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function Be(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 O(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 k(){let{user:e}=r(),t=(0,b.useMemo)(()=>ze(e),[e]),[n,x]=(0,b.useState)(`pending`),[S,T]=(0,b.useState)([]),[k,A]=(0,b.useState)(!1),[Ve,He]=(0,b.useState)(null),[Ue,j]=(0,b.useState)(null),[M,N]=(0,b.useState)(null),[We,P]=(0,b.useState)([]),[Ge,Ke]=(0,b.useState)(!1),[F,I]=(0,b.useState)(``),[L,R]=(0,b.useState)(``),[z,qe]=(0,b.useState)(null),[B,Je]=(0,b.useState)(``),[V,Ye]=(0,b.useState)(`all`),[H,Xe]=(0,b.useState)(`all`),[U,W]=(0,b.useState)(new Set),[G,Ze]=(0,b.useState)(!1),K=(0,b.useCallback)(async()=>{A(!0),He(null);try{let r=[];if(n===`pending`){let e=new Set;if(t.length===0){let e=await C.listRequests({status:`pending`});for(let t of e.data)r.push(t)}else for(let n of t){let t=await C.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){T([]),A(!1);return}let n=await C.listRequests({submitterId:t});r.push(...n.data)}else{let e=await C.listRequests({});r.push(...e.data)}r.sort((e,t)=>(t.submitted_at||``).localeCompare(e.submitted_at||``)),T(r)}catch(e){He(e?.message||String(e)),T([])}finally{A(!1)}},[n,t,e?.id]);(0,b.useEffect)(()=>{K()},[K]);let Qe=(0,b.useCallback)(async e=>{j(e),Ke(!0),I(``),R(``);try{let[t,n]=await Promise.all([C.getRequest(e),C.listActions(e)]);N(t.data),P(n.data)}catch(e){y.error(e?.message||`Failed to load request`),N(null),P([])}finally{Ke(!1)}},[]),$e=()=>{j(null),N(null),P([]),I(``),R(``)},q=(0,b.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,b.useCallback)(async e=>{if(!M)return;let t=q(M);if(!t){y.error(`Cannot determine actor id`);return}qe(e);try{let n={actor_id:t,comment:F.trim()||void 0},r=await(e===`approve`?C.approve:e===`reject`?C.reject:C.recall)(M.id,n);y.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([C.getRequest(M.id),C.listActions(M.id)]);N(i.data),P(a.data),K()}catch(t){y.error(t?.message||`Failed to ${e}`)}finally{qe(null)}},[M,q,F,K]),Y=(0,b.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,b.useMemo)(()=>!M||M.status!==`pending`?!1:M.submitter_id===e?.id||L.trim().length>0,[M,e?.id,L]),tt=(0,b.useMemo)(()=>S.filter(e=>e.status===`pending`).length,[S]),nt=(0,b.useMemo)(()=>{let e=new Set;for(let t of S)t.process_name&&e.add(t.process_name);return Array.from(e).sort()},[S]),rt=(0,b.useMemo)(()=>{let e=new Set;for(let t of S)t.object_name&&e.add(t.object_name);return Array.from(e).sort()},[S]),X=(0,b.useMemo)(()=>{let e=B.trim().toLowerCase();return S.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)},[S,B,V,H]);(0,b.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,b.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,b.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,b.useCallback)(e=>{W(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ot=(0,b.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||[]),ee=t.find(e=>r.has(e))||e?.id||``;try{await(n===`approve`?C.approve:C.reject)(o.id,{actor_id:ee}),i++}catch{a++}}Ze(!1),W(new Set),a===0?y.success(`${n===`approve`?`Approved`:`Rejected`} ${i} request${i===1?``:`s`}`):y.error(`${i} succeeded, ${a} failed`),K()},[Z,t,e?.id,K]);return(0,w.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-6xl`,children:[(0,w.jsxs)(`header`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsxs)(`h1`,{className:`text-2xl font-semibold flex items-center gap-2`,children:[(0,w.jsx)(Me,{className:`h-6 w-6`}),`Approvals Inbox`]}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Review and act on multi-step approval requests.`})]}),(0,w.jsxs)(f,{variant:`outline`,size:`sm`,onClick:K,disabled:k,children:[(0,w.jsx)(ue,{className:`h-4 w-4 mr-2 ${k?`animate-spin`:``}`}),`Refresh`]})]}),Ve&&(0,w.jsxs)(Oe,{variant:`destructive`,children:[(0,w.jsx)(he,{className:`h-4 w-4`}),(0,w.jsx)(Ne,{children:Ve})]}),(0,w.jsxs)(i,{value:n,onValueChange:e=>x(e),children:[(0,w.jsxs)(Ie,{children:[(0,w.jsxs)(p,{value:`pending`,children:[`My Pending`,tt>0&&(0,w.jsx)(u,{variant:`secondary`,className:`ml-2`,children:tt})]}),(0,w.jsx)(p,{value:`submitted`,children:`Submitted by me`}),(0,w.jsx)(p,{value:`all`,children:`All`})]}),(0,w.jsxs)(Ce,{value:n,className:`mt-4 space-y-3`,children:[!k&&S.length>0&&(0,w.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,w.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-sm`,children:[(0,w.jsx)(_e,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,w.jsx)(Se,{value:B,onChange:e=>Je(e.target.value),placeholder:`Search process, record, approver…`,className:`pl-8 h-8 text-sm`}),B&&(0,w.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,w.jsx)(Le,{className:`h-3.5 w-3.5`})})]}),nt.length>1&&(0,w.jsxs)(me,{value:V,onValueChange:Ye,children:[(0,w.jsx)(ge,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,w.jsx)(c,{placeholder:`Process`})}),(0,w.jsxs)(v,{children:[(0,w.jsx)(o,{value:`all`,children:`All processes`}),nt.map(e=>(0,w.jsx)(o,{value:e,children:e},e))]})]}),rt.length>1&&(0,w.jsxs)(me,{value:H,onValueChange:Xe,children:[(0,w.jsx)(ge,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,w.jsx)(c,{placeholder:`Object`})}),(0,w.jsxs)(v,{children:[(0,w.jsx)(o,{value:`all`,children:`All objects`}),rt.map(e=>(0,w.jsx)(o,{value:e,children:e},e))]})]}),(B||V!==`all`||H!==`all`)&&(0,w.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[X.length,` of `,S.length]})]}),n===`pending`&&U.size>0&&(0,w.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2 rounded-md border bg-accent/30 text-sm`,children:[(0,w.jsxs)(`span`,{children:[(0,w.jsx)(`strong`,{children:U.size}),` selected`,Z.length!==U.size&&(0,w.jsxs)(`span`,{className:`text-muted-foreground ml-1`,children:[`(`,Z.length,` actionable)`]})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsxs)(f,{size:`sm`,onClick:()=>ot(`approve`),disabled:G||Z.length===0,children:[(0,w.jsx)(_,{className:`h-3.5 w-3.5 mr-1`}),`Approve `,Z.length||``]}),(0,w.jsxs)(ve,{children:[(0,w.jsx)(Ae,{asChild:!0,children:(0,w.jsxs)(f,{size:`sm`,variant:`outline`,disabled:G||Z.length===0,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,w.jsx)(oe,{className:`h-3.5 w-3.5 mr-1`}),`Reject `,Z.length||``]})}),(0,w.jsxs)(ye,{children:[(0,w.jsxs)(xe,{children:[(0,w.jsxs)(we,{children:[`Reject `,Z.length,` requests?`]}),(0,w.jsx)(De,{children:`This will reject the selected requests and notify their submitters.`})]}),(0,w.jsxs)(g,{children:[(0,w.jsx)(h,{children:`Cancel`}),(0,w.jsxs)(ke,{onClick:()=>ot(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:[`Reject `,Z.length]})]})]})]}),(0,w.jsx)(f,{size:`sm`,variant:`ghost`,onClick:()=>W(new Set),disabled:G,children:`Clear`})]})]}),k?(0,w.jsxs)(`div`,{className:`space-y-2`,children:[(0,w.jsx)(a,{className:`h-10 w-full`}),(0,w.jsx)(a,{className:`h-10 w-full`}),(0,w.jsx)(a,{className:`h-10 w-full`})]}):S.length===0?(0,w.jsx)(`div`,{className:`flex items-center justify-center min-h-[240px] rounded-md border border-dashed`,children:(0,w.jsxs)(te,{children:[(0,w.jsx)(Re,{children:`No requests`}),(0,w.jsx)(re,{children:n===`pending`?`You have no pending approvals.`:`Nothing here yet.`})]})}):X.length===0?(0,w.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,w.jsx)(ae,{children:(0,w.jsx)(je,{className:`p-0`,children:(0,w.jsxs)(Pe,{children:[(0,w.jsx)(Fe,{children:(0,w.jsxs)(be,{children:[n===`pending`&&(0,w.jsx)(m,{className:`w-10`,children:(0,w.jsx)(s,{checked:$,onCheckedChange:it,"aria-label":`Select all`,disabled:Q.length===0})}),(0,w.jsx)(m,{children:`Process`}),(0,w.jsx)(m,{children:`Object`}),(0,w.jsx)(m,{children:`Record`}),(0,w.jsx)(m,{children:`Step`}),(0,w.jsx)(m,{children:`Status`}),(0,w.jsx)(m,{children:`Approvers`}),(0,w.jsx)(m,{children:`Submitted`})]})}),(0,w.jsx)(Ee,{children:X.map(e=>(0,w.jsxs)(be,{className:`cursor-pointer hover:bg-accent/50`,onClick:()=>Qe(e.id),children:[n===`pending`&&(0,w.jsx)(d,{className:`w-10`,onClick:e=>e.stopPropagation(),children:(0,w.jsx)(s,{checked:U.has(e.id),onCheckedChange:()=>at(e.id),disabled:e.status!==`pending`,"aria-label":`Select request ${e.id}`})}),(0,w.jsx)(d,{className:`font-medium`,children:e.process_name}),(0,w.jsx)(d,{children:e.object_name}),(0,w.jsx)(d,{className:`font-mono text-xs`,title:e.record_id,children:O(e.record_id)}),(0,w.jsx)(d,{children:e.current_step?(0,w.jsxs)(`span`,{className:`text-xs`,children:[e.current_step,typeof e.current_step_index==`number`&&(0,w.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (#`,e.current_step_index,`)`]})]}):`—`}),(0,w.jsx)(d,{children:(0,w.jsx)(E,{status:e.status})}),(0,w.jsx)(d,{className:`max-w-[220px] truncate text-xs text-muted-foreground`,title:(e.pending_approvers||[]).join(`, `),children:(e.pending_approvers||[]).map(O).join(`, `)||`—`}),(0,w.jsxs)(d,{className:`text-xs whitespace-nowrap text-muted-foreground`,title:D(e.submitted_at),children:[(0,w.jsx)(de,{className:`h-3 w-3 inline mr-1`}),Be(e.submitted_at)]})]},e.id))})]})})})]})]}),(0,w.jsx)(ce,{open:!!Ue,onOpenChange:e=>!e&&$e(),children:(0,w.jsxs)(le,{className:`w-full sm:max-w-xl overflow-y-auto`,children:[(0,w.jsxs)(ne,{children:[(0,w.jsx)(ie,{children:`Approval Request`}),(0,w.jsx)(fe,{children:M?`${M.process_name} · ${M.object_name}/${M.record_id}`:``})]}),Ge?(0,w.jsxs)(`div`,{className:`space-y-2 mt-6`,children:[(0,w.jsx)(a,{className:`h-6 w-3/4`}),(0,w.jsx)(a,{className:`h-6 w-1/2`}),(0,w.jsx)(a,{className:`h-20 w-full`})]}):M?(0,w.jsxs)(`div`,{className:`space-y-4 mt-6`,children:[(0,w.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-sm`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Status`}),(0,w.jsx)(E,{status:M.status})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Current Step`}),M.current_step||`—`]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Step Index`}),M.current_step_index??`—`]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Submitter`}),(0,w.jsx)(`span`,{className:`font-mono text-xs`,title:M.submitter_id||``,children:O(M.submitter_id)})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Submitted`}),D(M.submitted_at)]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Completed`}),D(M.completed_at)]}),(0,w.jsxs)(`div`,{className:`col-span-2`,children:[(0,w.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Pending Approvers`}),(0,w.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:(M.pending_approvers||[]).length===0?`—`:(M.pending_approvers||[]).map((e,t)=>(0,w.jsx)(u,{variant:`outline`,className:`font-mono text-[10px]`,title:e,children:O(e)},t))})]}),M.payload&&(0,w.jsxs)(`div`,{className:`col-span-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,w.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Payload`}),(0,w.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(JSON.stringify(M.payload,null,2)),y.success(`Payload copied`)}catch{y.error(`Copy failed`)}},className:`text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,w.jsx)(ee,{className:`h-3 w-3`}),`Copy`]})]}),(0,w.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,w.jsx)(l,{}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Action History`}),We.length===0?(0,w.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`No actions yet.`}):(0,w.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,w.jsxs)(`li`,{className:`relative text-xs`,children:[(0,w.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,w.jsxs)(`div`,{className:`flex items-baseline gap-1.5 flex-wrap`,children:[(0,w.jsx)(`span`,{className:`font-medium capitalize`,children:e.action}),(0,w.jsx)(`span`,{className:`text-muted-foreground`,children:`by`}),(0,w.jsx)(`span`,{className:`font-mono`,title:e.actor_id||``,children:O(e.actor_id)}),e.step_name&&(0,w.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,e.step_name,` (#`,e.step_index,`)`]}),(0,w.jsx)(`span`,{className:`ml-auto text-muted-foreground text-[10px]`,title:D(e.created_at),children:Be(e.created_at)})]}),e.comment&&(0,w.jsxs)(`div`,{className:`text-muted-foreground italic mt-0.5`,children:[`"`,e.comment,`"`]})]},e.id))})]}),M.status===`pending`&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(l,{}),(0,w.jsxs)(`div`,{className:`space-y-3`,children:[(0,w.jsxs)(`details`,{className:`group`,children:[(0,w.jsx)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground select-none`,children:`Override actor (advanced)`}),(0,w.jsxs)(`div`,{className:`mt-2`,children:[(0,w.jsx)(Te,{htmlFor:`actor-override`,className:`text-xs`,children:`Actor`}),(0,w.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,w.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`e.g. `,(0,w.jsx)(`code`,{children:`role:sales_manager`}),`. Leave blank to use auto-detected.`]})]})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(Te,{htmlFor:`comment`,className:`text-xs`,children:`Comment (optional)`}),(0,w.jsx)(pe,{id:`comment`,value:F,onChange:e=>I(e.target.value),rows:2,className:`mt-1`})]}),(0,w.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,w.jsxs)(f,{size:`sm`,onClick:()=>J(`approve`),disabled:!Y||z!==null,children:[(0,w.jsx)(_,{className:`h-4 w-4 mr-1`}),z===`approve`?`Approving…`:`Approve`]}),(0,w.jsxs)(ve,{children:[(0,w.jsx)(Ae,{asChild:!0,children:(0,w.jsxs)(f,{size:`sm`,variant:`outline`,disabled:!Y||z!==null,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,w.jsx)(oe,{className:`h-4 w-4 mr-1`}),z===`reject`?`Rejecting…`:`Reject`]})}),(0,w.jsxs)(ye,{children:[(0,w.jsxs)(xe,{children:[(0,w.jsx)(we,{children:`Reject this request?`}),(0,w.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,w.jsxs)(g,{children:[(0,w.jsx)(h,{children:`Cancel`}),(0,w.jsx)(ke,{onClick:()=>J(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Reject`})]})]})]}),(0,w.jsxs)(f,{size:`sm`,variant:`outline`,onClick:()=>J(`recall`),disabled:!et||z!==null,children:[(0,w.jsx)(se,{className:`h-4 w-4 mr-1`}),z===`recall`?`Recalling…`:`Recall`]})]}),!Y&&!et&&(0,w.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,w.jsx)(`code`,{children:`role:sales_manager`}),`).`]})]})]})]}):null]})})]})}export{k as ApprovalsInboxPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{r as t,y as n}from"./vendor-react-CyVA1SE-.js";import{Bt as r,Ht as i,Rt as a,Vt as o,mr as s,pi as c,x as l,zt as u}from"./ui-components-CIdYg6m3.js";import{l as d,r as f,t as p,u as m}from"./plugin-chatbot-CiVctLlf.js";import{n as h}from"./index-DWtLSzKK.js";var g=e(n(),1),_=t(),v=`/api/v1/ai`;function y(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(/\/$/,``)}${v}`}function b({appLabel:e,objects:t,agents:n,agentsLoading:d,agentsError:h,activeAgent:v,onAgentChange:y,chatApi:b,apiBase:x,defaultOpen:S=!1,conversationId:C,initialMessages:w}){let T=t.map(e=>e.label||e.name).join(`, `),E=g.useMemo(()=>!w||w.length===0?[]:w.map(e=>({id:e.id,role:e.role,content:e.parts.map(e=>e.text).join(``)})),[w]),D=g.useMemo(()=>n.find(e=>e.name===v)?.label??v??e,[n,v,e]),O=v?`Hello! I'm **${D}**, your ${e} assistant. How can I help you today?`:`Hello! I'm your **${e}** assistant. ${h?`(Backend unreachable — running in offline demo mode.)`:``}`,{messages:k,isLoading:A,error:j,sendMessage:M,stop:N,reload:P,clear:F}=m({api:b,conversationId:C,body:{context:{activeApp:e,objects:t.map(e=>({name:e.name,label:e.label})),agentName:v}},initialMessages:E.length>0?E:[{id:`welcome`,role:`assistant`,content:O}],autoResponse:!b,autoResponseText:T?`I can help you work with ${T}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600}),I=p({messages:k,apiBase:x,continueConversation:e=>{M(e)}}),L=n.length>0?(0,_.jsxs)(a,{value:v,onValueChange:y,disabled:d,children:[(0,_.jsx)(o,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,_.jsx)(i,{placeholder:`Choose agent...`})}),(0,_.jsx)(u,{align:`end`,children:n.map(e=>(0,_.jsxs)(r,{value:e.name,className:`text-xs`,children:[(0,_.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,_.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null,[R,z]=g.useState(!1),B=g.useMemo(()=>x.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[x]),V=C?(0,_.jsx)(s,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":`Share conversation`,"data-testid":`floating-chatbot-share`,onClick:()=>z(!0),children:(0,_.jsx)(c,{className:`h-4 w-4`})}):null;return(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)(f,{floatingConfig:{position:`bottom-right`,defaultOpen:S,panelWidth:420,panelHeight:560,title:`${e} Assistant`,triggerSize:56},headerExtra:L,headerActions:V,messages:k,placeholder:v?`Ask ${D}...`:d?`Loading agents...`:`Ask anything...`,onSendMessage:e=>M(e),onClear:F,onStop:A?N:void 0,onReload:P,isLoading:A,error:j,enableMarkdown:!0,onToolApprove:I.decide,toolDecisions:I.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`}),C&&(0,_.jsx)(l,{open:R,onOpenChange:z,objectName:`ai_conversations`,recordId:C,recordLabel:`this conversation`,apiBase:B})]})}function x({appLabel:e,objects:t,apiBase:n,defaultAgent:r,defaultOpen:i=!1,userId:a}){let o=g.useMemo(()=>y(n),[n]),s={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`}.VITE_AI_DEFAULT_AGENT,{agents:c,isLoading:l,error:u}=d({apiBase:o}),[f,p]=g.useState(void 0);g.useEffect(()=>{if(!f&&c.length>0){let e=r??s;p(((e?c.find(t=>t.name===e):void 0)??c[0]).name)}},[c,f,r,s]);let m=f?`${o}/agents/${encodeURIComponent(f)}/chat`:void 0,{conversationId:v,initialMessages:x}=h({userId:a,scope:f,apiBase:o});return(0,_.jsx)(b,{appLabel:e,objects:t,agents:c,agentsLoading:l,agentsError:u,activeAgent:f,onAgentChange:p,chatApi:m,apiBase:o,defaultOpen:i,conversationId:v,initialMessages:x},`${m??`local`}:${v??`pending`}`)}export{x as default};
|
|
@@ -1 +0,0 @@
|
|
|
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{At as i,Cr as a,Ft as o,It as s,Jn as c,Kn as l,Li as u,Mo as d,Mt as f,Nt as p,Oi as m,Oo as h,Pt as g,Q as _,Qn as v,Ut as y,Vo as b,Xn as x,Yn as S,at as C,ct as w,en as T,in as E,it as D,lt as O,mr as k,ot as A,qn as j,rt as M,st as N,xa as P,zo as F}from"./ui-components-CIdYg6m3.js";import"./index-DWtLSzKK.js";var I=e(n(),1),L=t();function R({status:e}){let t={success:{icon:F,cls:`text-emerald-600 border-emerald-300`},completed:{icon:F,cls:`text-emerald-600 border-emerald-300`},failed:{icon:d,cls:`text-red-600 border-red-300`},error:{icon:d,cls:`text-red-600 border-red-300`},running:{icon:P,cls:`text-blue-600 border-blue-300 animate-pulse`},pending:{icon:h,cls:`text-amber-600 border-amber-300`},skipped:{icon:b,cls:`text-muted-foreground`}}[e]??{icon:b,cls:`text-muted-foreground`},n=t.icon;return(0,L.jsxs)(v,{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)([]),[o,s]=(0,I.useState)(!0),[u,d]=(0,I.useState)(null),[f,p]=(0,I.useState)(``),[h,g]=(0,I.useState)(0),_=(0,I.useCallback)(async()=>{if(!e?.meta?.getItems){d(`meta.getItems is not available on this client`),s(!1);return}s(!0),d(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),!f&&r.length>0&&p(r[0].name)}catch(e){d(e?.message??String(e))}finally{s(!1)}},[e,f]);(0,I.useEffect)(()=>{_()},[_]);let v=(0,I.useMemo)(()=>t.find(e=>e.name===f)??null,[t,f]);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)(a,{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)(l,{children:[(0,L.jsx)(S,{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)(x,{className:`text-base`,children:`Flow`}),(0,L.jsx)(c,{children:`Select a flow definition to test`})]}),(0,L.jsxs)(k,{variant:`outline`,size:`sm`,onClick:_,disabled:o,children:[(0,L.jsx)(m,{className:`h-3.5 w-3.5 mr-2 ${o?`animate-spin`:``}`}),`Refresh`]})]})}),(0,L.jsxs)(j,{children:[o&&(0,L.jsx)(i,{className:`h-9 w-72`}),u&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:u}),!o&&!u&&t.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No flow definitions found.`}),!o&&!u&&t.length>0&&(0,L.jsx)(`select`,{value:f,onChange:e=>p(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,s]=(0,I.useState)(!1),[f,p]=(0,I.useState)(null),[m,h]=(0,I.useState)(null);(0,I.useEffect)(()=>{a({}),p(null),h(null)},[t?.name]);let g=(e,t)=>a(n=>({...n,[e]:t}));return(0,L.jsxs)(l,{children:[(0,L.jsxs)(S,{className:`pb-3`,children:[(0,L.jsx)(x,{className:`text-base`,children:`Test Run`}),(0,L.jsx)(c,{children:`Provide input values and invoke the flow`})]}),(0,L.jsxs)(j,{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)(E,{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)(v,{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)(O,{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)(_,{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)(T,{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)(k,{onClick:async()=>{if(!e?.automation?.execute){h(`automation.execute is not available on this client`);return}s(!0),h(null),p(null);try{let a={};for(let e of r){let t=i[e.name];t!==void 0&&(a[e.name]=B(t,e.type))}p(await e.automation.execute(t.name,{params:a})),n?.()}catch(e){h(e?.message??String(e))}finally{s(!1)}},disabled:o,size:`sm`,children:[o?(0,L.jsx)(P,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(u,{className:`h-3.5 w-3.5 mr-2`}),o?`Running…`:`Run Flow`]})}),(f||m)&&(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:[m||f?.success===!1?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(d,{className:`h-4 w-4 text-red-500`}),` Failed`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(F,{className:`h-4 w-4 text-emerald-500`}),` Result`]}),typeof f?.durationMs==`number`&&(0,L.jsxs)(v,{variant:`secondary`,className:`text-[10px] font-mono`,children:[f.durationMs,` ms`]})]}),m&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:m}),f&&(0,L.jsx)(V,{data:f})]})]})]})}function W({client:e,flowName:t,refreshKey:n}){let[r,a]=(0,I.useState)([]),[u,d]=(0,I.useState)(!0),[h,_]=(0,I.useState)(null),[b,T]=(0,I.useState)(null),[E,O]=(0,I.useState)(null),[F,B]=(0,I.useState)(!1),[H,U]=(0,I.useState)(null),W=(0,I.useCallback)(async()=>{if(!e?.automation?.listRuns){_(`automation.listRuns is not available on this client`),d(!1);return}d(!0),_(null);try{let n=await e.automation.listRuns(t,{limit:20});a(Array.isArray(n)?n:n?.items??n?.runs??[])}catch(e){_(e?.message??String(e))}finally{d(!1)}},[e,t]);(0,I.useEffect)(()=>{W()},[W,n]);let G=async n=>{T(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)(l,{children:[(0,L.jsx)(S,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(x,{className:`text-base`,children:`Recent Runs`}),(0,L.jsx)(c,{className:`font-mono text-xs`,children:t})]}),(0,L.jsxs)(k,{variant:`outline`,size:`sm`,onClick:W,disabled:u,children:[u?(0,L.jsx)(P,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(m,{className:`h-3.5 w-3.5 mr-2`}),`Refresh`]})]})}),(0,L.jsxs)(j,{children:[u&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(i,{className:`h-8 w-full`}),(0,L.jsx)(i,{className:`h-8 w-full`}),(0,L.jsx)(i,{className:`h-8 w-full`})]}),!u&&h&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:h}),!u&&!h&&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.`}),!u&&!h&&r.length>0&&(0,L.jsxs)(M,{children:[(0,L.jsx)(N,{children:(0,L.jsxs)(w,{children:[(0,L.jsx)(A,{children:`Run`}),(0,L.jsx)(A,{children:`Status`}),(0,L.jsx)(A,{children:`Started`}),(0,L.jsx)(A,{className:`text-right`,children:`Duration`})]})}),(0,L.jsx)(D,{children:r.map(e=>(0,L.jsxs)(w,{className:`cursor-pointer`,onClick:()=>G(e.id),children:[(0,L.jsxs)(C,{className:`font-mono text-xs`,children:[e.id.slice(0,12),`…`]}),(0,L.jsx)(C,{children:(0,L.jsx)(R,{status:e.status})}),(0,L.jsx)(C,{className:`text-xs text-muted-foreground`,children:z(e.startedAt)}),(0,L.jsx)(C,{className:`text-right font-mono text-xs`,children:typeof e.durationMs==`number`?`${e.durationMs} ms`:`—`})]},e.id))})]})]})]}),(0,L.jsx)(f,{open:!!b,onOpenChange:e=>{e||(T(null),O(null))},children:(0,L.jsxs)(p,{side:`right`,className:`w-full sm:max-w-2xl p-0 flex flex-col`,children:[(0,L.jsxs)(o,{className:`p-4 border-b`,children:[(0,L.jsxs)(s,{className:`font-mono text-sm break-all`,children:[`Run `,b]}),(0,L.jsx)(g,{children:E&&(0,L.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,L.jsx)(R,{status:E.status}),typeof E.durationMs==`number`&&(0,L.jsxs)(v,{variant:`secondary`,className:`text-[10px] font-mono`,children:[E.durationMs,` ms`]}),(0,L.jsx)(`span`,{className:`text-xs`,children:z(E.startedAt)})]})})]}),(0,L.jsxs)(y,{className:`flex-1 p-4`,children:[F&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(i,{className:`h-16 w-full`}),(0,L.jsx)(i,{className:`h-16 w-full`}),(0,L.jsx)(i,{className:`h-16 w-full`})]}),H&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:H}),!F&&E&&(0,L.jsx)(`div`,{className:`space-y-3`,children:Array.isArray(E.steps)&&E.steps.length>0?E.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)(v,{variant:`outline`,className:`text-[10px] font-mono`,children:e.nodeType}),(0,L.jsx)(R,{status:e.status}),typeof e.durationMs==`number`&&(0,L.jsxs)(v,{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:E})]})})]})]})})]})}export{H as FlowRunsPage};
|
|
@@ -1 +0,0 @@
|
|
|
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-IQKE4Vv8.js";import{$n as a,Jn as o,Kn as s,Or as c,Qn as l,Vo as u,Xn as d,Yn as f,_ as p,ba as m,en as h,er as g,fi as _,in as v,ir as y,jr as b,mr as x,nr as S,qn as C,rr as w,tr as T,xa as E,xr as D,zo as O}from"./ui-components-CIdYg6m3.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:m,setInitialPassword:M,hasLocalPassword:P}=r(),{upload:F}=p(),[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)(S,{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)(_,{className:`h-4 w-4`}),(0,A.jsx)(y,{children:`Set a recovery password`}),(0,A.jsx)(w,{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)(s,{children:(0,A.jsxs)(C,{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)(T,{src:e.image??void 0,alt:e.name??`User`}),(0,A.jsx)(g,{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)(l,{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)(x,{type:`button`,variant:`outline`,size:`sm`,disabled:U,onClick:()=>H.current?.click(),"data-testid":`profile-avatar-upload-btn`,children:[U?(0,A.jsx)(E,{className:`mr-2 h-4 w-4 animate-spin`}):(0,A.jsx)(b,{className:`mr-2 h-4 w-4`}),e.image?`Replace`:`Upload`]}),e.image&&(0,A.jsxs)(x,{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)(D,{className:`mr-2 h-4 w-4`}),`Remove`]})]})]}),G&&(0,A.jsxs)(S,{variant:`destructive`,className:`mt-4`,children:[(0,A.jsx)(u,{className:`h-4 w-4`}),(0,A.jsx)(w,{children:G})]})]})}),(0,A.jsxs)(s,{children:[(0,A.jsxs)(f,{children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(c,{className:`h-4 w-4 text-muted-foreground`}),(0,A.jsx)(d,{className:`text-base sm:text-lg`,children:`Personal Information`})]}),(0,A.jsx)(o,{children:`Update your name and view account details`})]}),(0,A.jsx)(C,{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)(S,{variant:`destructive`,children:[(0,A.jsx)(u,{className:`h-4 w-4`}),(0,A.jsx)(w,{children:B})]}),R&&(0,A.jsxs)(S,{children:[(0,A.jsx)(O,{className:`h-4 w-4 text-green-600`}),(0,A.jsx)(w,{className:`text-green-800 dark:text-green-400`,children:`Profile updated successfully.`})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(v,{htmlFor:`profile-name`,children:`Name`}),(0,A.jsx)(h,{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)(v,{htmlFor:`profile-email`,children:`Email`}),(0,A.jsx)(h,{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)(v,{children:`Role`}),(0,A.jsx)(h,{type:`text`,value:e.role??`member`,disabled:!0,className:`bg-muted text-muted-foreground`})]}),(0,A.jsx)(x,{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:m,setInitialPassword:M,hasLocalPassword:P,highlight:J,onPasswordSet:Y})})]}):null}function N({changePassword:e,setInitialPassword:t,hasLocalPassword:n,highlight:r,onPasswordSet:i}){let[a,c]=(0,k.useState)(null),[l,p]=(0,k.useState)(``),[g,_]=(0,k.useState)(``),[y,b]=(0,k.useState)(``),[T,E]=(0,k.useState)(!1),[D,j]=(0,k.useState)(null),[M,N]=(0,k.useState)(null);(0,k.useEffect)(()=>{let e=!1;return n().then(t=>{e||c(t)}).catch(()=>{e||c(!1)}),()=>{e=!0}},[n]);let P=()=>{p(``),_(``),b(``)},F=async n=>{if(n.preventDefault(),j(null),N(null),g.length<8){j(`Password must be at least 8 characters`);return}if(g!==y){j(`Passwords do not match`);return}E(!0);try{if(a){if(!l){j(`Enter your current password`),E(!1);return}await e(l,g),N(`Password changed.`)}else await t(g),N(`Local password set. You can now sign in with email and password on this environment.`),c(!0),i?.();P()}catch(e){j(e instanceof Error?e.message:String(e))}finally{E(!1)}},I=a===null;return(0,A.jsxs)(s,{className:r?`ring-2 ring-amber-300 dark:ring-amber-700`:void 0,children:[(0,A.jsxs)(f,{children:[(0,A.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,A.jsx)(m,{className:`h-4 w-4 text-muted-foreground`}),(0,A.jsx)(d,{className:`text-base sm:text-lg`,children:a?`Change Password`:`Set Local Password`})]}),(0,A.jsx)(o,{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)(C,{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)(v,{htmlFor:`current-password`,children:`Current password`}),(0,A.jsx)(h,{id:`current-password`,type:`password`,autoComplete:`current-password`,value:l,onChange:e=>p(e.target.value),disabled:T||I,required:!0})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(v,{htmlFor:`new-password`,children:a?`New password`:`Password`}),(0,A.jsx)(h,{id:`new-password`,type:`password`,autoComplete:`new-password`,value:g,onChange:e=>_(e.target.value),disabled:T||I,minLength:8,required:!0})]}),(0,A.jsxs)(`div`,{className:`space-y-2`,children:[(0,A.jsx)(v,{htmlFor:`confirm-password`,children:`Confirm password`}),(0,A.jsx)(h,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,value:y,onChange:e=>b(e.target.value),disabled:T||I,minLength:8,required:!0})]}),D&&(0,A.jsxs)(S,{variant:`destructive`,children:[(0,A.jsx)(u,{className:`h-4 w-4`}),(0,A.jsx)(w,{children:D})]}),M&&(0,A.jsxs)(S,{children:[(0,A.jsx)(O,{className:`h-4 w-4`}),(0,A.jsx)(w,{children:M})]}),(0,A.jsx)(x,{type:`submit`,disabled:T||I,className:`w-full sm:w-auto`,children:T?`Saving…`:a?`Change password`:`Set password`})]})})]})}export{M as ProfilePage};
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import{u as e}from"./vendor-objectstack-B3zP6Fz_.js";import{lt as t}from"./framework-DVkqUSPj.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`);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`);return(Array.isArray(t?.items)?t.items:Array.isArray(t)?t:[]).filter(t=>{if(!t)return!1;let n=t.list??t;return(n?.data?.object??n?.object??n?.objectName)===e}).map(e=>e.list??e)}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};
|