@objectstack/console 9.0.1 → 9.2.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-B9iWZUDQ.js → AiPendingActionsPage-B-n-gqzM.js} +1 -1
- package/dist/assets/{ApiConsolePage-ZBL7GLt2.js → ApiConsolePage-uPTuvhXX.js} +1 -1
- package/dist/assets/{AppManagementPage-A8AufLcC.js → AppManagementPage-CNpBOuFm.js} +1 -1
- package/dist/assets/ApprovalsInboxPage-BFNNZBXy.js +1 -0
- package/dist/assets/{AuditLogPage-DWQl9my4.js → AuditLogPage-_9ECzJM8.js} +1 -1
- package/dist/assets/{ComponentNavView-CqfUzDMU.js → ComponentNavView-CDdExuCL.js} +1 -1
- package/dist/assets/ConsoleFloatingChatbot-DThmuzxB.js +1 -0
- package/dist/assets/{DeveloperHubPage-D7pt27Ji.js → DeveloperHubPage-mdknfgGp.js} +1 -1
- package/dist/assets/FlowRunsPage-yleJQxJv.js +1 -0
- package/dist/assets/{IntegrationsPage-CHg7ApBe.js → IntegrationsPage-7SUsLOvq.js} +2 -2
- package/dist/assets/ProfilePage-D4yjFTMG.js +1 -0
- package/dist/assets/PublicFormsPage-DWj4wR8t.js +1 -0
- package/dist/assets/{SettingsHub-DerOpof3.js → SettingsHub-7kLSZWnI.js} +1 -1
- package/dist/assets/{SettingsView-BNq6smI8.js → SettingsView-DqnY47y1.js} +1 -1
- package/dist/assets/{SystemHubPage-UTl8x-Bf.js → SystemHubPage-DeiksJan.js} +1 -1
- package/dist/assets/assistantBus-Bppk-Y9t.js +1 -0
- package/dist/assets/data-adapter-D1EJuDUI.js +1 -0
- package/dist/assets/framework-CHiz03zG.js +34 -0
- package/dist/assets/highlighted-body-OFNGDK62-Du4wVUV7.js +1 -0
- package/dist/assets/index-B_NAVTba.js +32 -0
- package/dist/assets/index-DwG7_t-6.css +2 -0
- package/dist/assets/mergeServerFields-CNavewPY.js +7 -0
- package/dist/assets/mermaid-GHXKKRXX-D0s_nNwO.js +1 -0
- package/dist/assets/plugin-calendar-u9Aa9OAR.js +1 -0
- package/dist/assets/{plugin-charts-BjUzf65B.js → plugin-charts-DSBNwB9E.js} +2 -2
- package/dist/assets/{plugin-chatbot-DUla2_T9.js → plugin-chatbot-BzJE6C-F.js} +6 -6
- package/dist/assets/plugin-dashboard-C5nSNZfG.js +5 -0
- package/dist/assets/{plugin-form-CcC4fdyJ.js → plugin-form-DrL6xDfP.js} +1 -1
- package/dist/assets/plugin-gantt-aDdnMW0u.js +1 -0
- package/dist/assets/plugin-grid-CSHgWd0O.js +6 -0
- package/dist/assets/plugin-kanban-D45w069C.js +1 -0
- package/dist/assets/{plugin-map-Bt30Mxn6.js → plugin-map-ue6Mjnhb.js} +1 -1
- package/dist/assets/{plugin-markdown-tayYSGF3.js → plugin-markdown-6MvgfANj.js} +1 -1
- package/dist/assets/plugin-report-QmyiWpfC.js +59 -0
- package/dist/assets/plugin-timeline-DrUpbBdn.js +1 -0
- package/dist/assets/plugin-view-DS-dSLs-.js +1 -0
- package/dist/assets/plugins-views-DH1gGZh6.js +4 -0
- package/dist/assets/{src-DOKKicsm.js → src-s-NNbVef.js} +1 -1
- package/dist/assets/{types-TLjbGkho.js → types-Decs33Tv.js} +1 -1
- package/dist/assets/{ui-components-DeXgqLMc.js → ui-components-BbPoD3rS.js} +2 -2
- package/dist/assets/{ui-layout-CvIgXgRF.js → ui-layout-CWeej0a8.js} +1 -1
- package/dist/assets/vendor-objectstack-RB3xvhcR.js +102 -0
- package/dist/index.html +4 -4
- package/package.json +1 -1
- package/dist/assets/ApprovalsInboxPage-Be6DrS7X.js +0 -1
- package/dist/assets/ConsoleFloatingChatbot-ByiTKdo6.js +0 -1
- package/dist/assets/FlowRunsPage-R-JzHY35.js +0 -1
- package/dist/assets/ProfilePage-D7kxyCKj.js +0 -1
- package/dist/assets/PublicFormsPage-B1VZJXuJ.js +0 -1
- package/dist/assets/data-adapter-DlR5JXpU.js +0 -1
- package/dist/assets/framework-DoGxClbR.js +0 -34
- package/dist/assets/highlighted-body-OFNGDK62-Bu5WidAv.js +0 -1
- package/dist/assets/index-Bt0jFx__.js +0 -32
- package/dist/assets/index-CJppnf0b.css +0 -2
- package/dist/assets/mergeServerFields-DL5isEen.js +0 -7
- package/dist/assets/mermaid-GHXKKRXX-BAcku4Xs.js +0 -1
- package/dist/assets/plugin-calendar-CUnlH4Wo.js +0 -1
- package/dist/assets/plugin-dashboard-DbPGiGy-.js +0 -5
- package/dist/assets/plugin-gantt-BRef4N3J.js +0 -1
- package/dist/assets/plugin-grid-BiWgglXK.js +0 -6
- package/dist/assets/plugin-kanban-C1UyFHza.js +0 -1
- package/dist/assets/plugin-report-qca5M0OZ.js +0 -59
- package/dist/assets/plugin-timeline-DZoFKL82.js +0 -1
- package/dist/assets/plugin-view-Ei4BPIYk.js +0 -1
- package/dist/assets/plugins-views-qoGCOQ47.js +0 -4
- package/dist/assets/vendor-objectstack-B2q1QmZh.js +0 -102
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-B_NAVTba.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-DwG7_t-6.css">
|
|
25
|
+
<link rel="modulepreload" href="./assets/framework-CHiz03zG.js" />
|
|
26
|
+
<link rel="modulepreload" href="./assets/ui-components-BbPoD3rS.js" />
|
|
27
27
|
<link rel="modulepreload" href="./assets/vendor-radix-CSVEhP0L.js" />
|
|
28
28
|
<link rel="modulepreload" href="./assets/vendor-react-DR370ovB.js" />
|
|
29
29
|
</head>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@objectstack/console",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.2.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{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{f as r}from"./infrastructure-CxityHZF.js";import{$ as i,At as a,B as o,Bo as ee,Bt as s,Ft as te,Gn as c,Ht as l,I as ne,It as re,Kn as ie,Ko as ae,L as oe,Lt as se,Mt as ce,Nr as le,Nt as ue,Pt as de,Qn as u,Rt as fe,Vt as pe,Zo as me,ar as he,as as ge,at as _e,cr as ve,ct as ye,dr as be,en as xe,et as Se,fr as Ce,ii as we,in as Te,it as Ee,ji as De,lr as Oe,lt as ke,mr as d,nr as Ae,nt as je,or as Me,ot as f,pr as Ne,qn as Pe,rr as Fe,rt as p,sr as m,ss as Ie,st as h,tt as Le,ur as g,xr as Re,yi as ze,zt as _}from"./ui-components-DeXgqLMc.js";import{r as v}from"./vendor-ui-utils-rQOI1gAo.js";var y=e(t(),1),b=`${``.replace(/\/$/,``)}/api/v1`;async function x(e,t){let n=await fetch(`${b}${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 S={listProcesses(e={}){let t=new URLSearchParams;e.object&&t.set(`object`,e.object),e.activeOnly&&t.set(`activeOnly`,`true`);let n=t.toString();return x(`/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 x(`/approvals/requests${n?`?${n}`:``}`)},async getRequest(e){return{data:await x(`/approvals/requests/${encodeURIComponent(e)}`)}},listActions(e){return x(`/approvals/requests/${encodeURIComponent(e)}/actions`)},async approve(e,t){let n=await x(`/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 x(`/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 x(`/approvals/requests/${encodeURIComponent(e)}/recall`,{method:`POST`,body:JSON.stringify(t)});return{data:n.request,finalized:n.finalized}},async submit(e){return x(`/approvals/requests`,{method:`POST`,body:JSON.stringify(e)})}};function Be(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 C=n(),w={pending:{variant:`secondary`,label:`Pending`},approved:{variant:`default`,label:`Approved`},rejected:{variant:`destructive`,label:`Rejected`},recalled:{variant:`outline`,label:`Recalled`}};function T({status:e}){let t=w[e]??{variant:`outline`,label:e};return(0,C.jsx)(u,{variant:t.variant,children:t.label})}function E(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function Ve(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 D(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 O(){let{user:e}=r(),t=(0,y.useMemo)(()=>Be(e),[e]),[n,b]=(0,y.useState)(`pending`),[x,w]=(0,y.useState)([]),[O,k]=(0,y.useState)(!1),[A,He]=(0,y.useState)(null),[Ue,We]=(0,y.useState)(null),[j,M]=(0,y.useState)(null),[Ge,N]=(0,y.useState)([]),[Ke,qe]=(0,y.useState)(!1),[P,F]=(0,y.useState)(``),[I,L]=(0,y.useState)(``),[R,Je]=(0,y.useState)(null),[z,Ye]=(0,y.useState)(``),[B,Xe]=(0,y.useState)(`all`),[V,Ze]=(0,y.useState)(`all`),[H,U]=(0,y.useState)(new Set),[W,Qe]=(0,y.useState)(!1),G=(0,y.useCallback)(async()=>{k(!0),He(null);try{let r=[];if(n===`pending`){let e=new Set;if(t.length===0){let e=await S.listRequests({status:`pending`});for(let t of e.data)r.push(t)}else for(let n of t){let t=await S.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){w([]),k(!1);return}let n=await S.listRequests({submitterId:t});r.push(...n.data)}else{let e=await S.listRequests({});r.push(...e.data)}r.sort((e,t)=>(t.submitted_at||``).localeCompare(e.submitted_at||``)),w(r)}catch(e){He(e?.message||String(e)),w([])}finally{k(!1)}},[n,t,e?.id]);(0,y.useEffect)(()=>{G()},[G]);let $e=(0,y.useCallback)(async e=>{We(e),qe(!0),F(``),L(``);try{let[t,n]=await Promise.all([S.getRequest(e),S.listActions(e)]);M(t.data),N(n.data)}catch(e){v.error(e?.message||`Failed to load request`),M(null),N([])}finally{qe(!1)}},[]),et=()=>{We(null),M(null),N([]),F(``),L(``)},K=(0,y.useCallback)(n=>{if(I.trim())return I.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||``},[I,t,e?.id]),q=(0,y.useCallback)(async e=>{if(!j)return;let t=K(j);if(!t){v.error(`Cannot determine actor id`);return}Je(e);try{let n={actor_id:t,comment:P.trim()||void 0},r=await(e===`approve`?S.approve:e===`reject`?S.reject:S.recall)(j.id,n);v.success(e===`approve`?r.finalized?`Approved (finalized)`:`Approved — advanced to next step`:e===`reject`?r.finalized?`Rejected`:`Rejected — returned to previous step`:`Recalled`),F(``);let[i,a]=await Promise.all([S.getRequest(j.id),S.listActions(j.id)]);M(i.data),N(a.data),G()}catch(t){v.error(t?.message||`Failed to ${e}`)}finally{Je(null)}},[j,K,P,G]),J=(0,y.useMemo)(()=>{if(!j||j.status!==`pending`)return!1;let e=new Set(j.pending_approvers||[]);return t.some(t=>e.has(t))||I.trim().length>0},[j,t,I]),tt=(0,y.useMemo)(()=>!j||j.status!==`pending`?!1:j.submitter_id===e?.id||I.trim().length>0,[j,e?.id,I]),nt=(0,y.useMemo)(()=>x.filter(e=>e.status===`pending`).length,[x]),rt=(0,y.useMemo)(()=>{let e=new Set;for(let t of x)t.process_name&&e.add(t.process_name);return Array.from(e).sort()},[x]),it=(0,y.useMemo)(()=>{let e=new Set;for(let t of x)t.object_name&&e.add(t.object_name);return Array.from(e).sort()},[x]),Y=(0,y.useMemo)(()=>{let e=z.trim().toLowerCase();return x.filter(t=>B!==`all`&&t.process_name!==B||V!==`all`&&t.object_name!==V?!1:e?[t.process_name,t.object_name,t.record_id,t.submitter_id,...t.pending_approvers||[]].filter(Boolean).join(` `).toLowerCase().includes(e):!0)},[x,z,B,V]);(0,y.useEffect)(()=>{if(H.size===0)return;let e=new Set(Y.map(e=>e.id)),t=!1,n=new Set;for(let r of H)e.has(r)?n.add(r):t=!0;t&&U(n)},[Y,H]);let X=(0,y.useMemo)(()=>{let e=new Set(t);return Y.filter(t=>H.has(t.id)&&t.status===`pending`&&(t.pending_approvers||[]).some(t=>e.has(t)))},[Y,H,t]),Z=Y.filter(e=>e.status===`pending`),Q=Z.length>0&&Z.every(e=>H.has(e.id)),at=(0,y.useCallback)(()=>{U(e=>{if(Q)return new Set;let t=new Set(e);for(let e of Z)t.add(e.id);return t})},[Q,Z]),ot=(0,y.useCallback)(e=>{U(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),$=(0,y.useCallback)(async n=>{let r=X;if(r.length===0)return;Qe(!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`?S.approve:S.reject)(o.id,{actor_id:ee}),i++}catch{a++}}Qe(!1),U(new Set),a===0?v.success(`${n===`approve`?`Approved`:`Rejected`} ${i} request${i===1?``:`s`}`):v.error(`${i} succeeded, ${a} failed`),G()},[X,t,e?.id,G]);return(0,C.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-6xl`,children:[(0,C.jsxs)(`header`,{className:`flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsxs)(`h1`,{className:`text-2xl font-semibold flex items-center gap-2`,children:[(0,C.jsx)(we,{className:`h-6 w-6`}),`Approvals Inbox`]}),(0,C.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Review and act on multi-step approval requests.`})]}),(0,C.jsxs)(d,{variant:`outline`,size:`sm`,onClick:G,disabled:O,children:[(0,C.jsx)(De,{className:`h-4 w-4 mr-2 ${O?`animate-spin`:``}`}),`Refresh`]})]}),A&&(0,C.jsxs)(Ae,{variant:`destructive`,children:[(0,C.jsx)(Ie,{className:`h-4 w-4`}),(0,C.jsx)(Fe,{children:A})]}),(0,C.jsxs)(Se,{value:n,onValueChange:e=>b(e),children:[(0,C.jsxs)(je,{children:[(0,C.jsxs)(p,{value:`pending`,children:[`My Pending`,nt>0&&(0,C.jsx)(u,{variant:`secondary`,className:`ml-2`,children:nt})]}),(0,C.jsx)(p,{value:`submitted`,children:`Submitted by me`}),(0,C.jsx)(p,{value:`all`,children:`All`})]}),(0,C.jsxs)(Le,{value:n,className:`mt-4 space-y-3`,children:[!O&&x.length>0&&(0,C.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,C.jsxs)(`div`,{className:`relative flex-1 min-w-[200px] max-w-sm`,children:[(0,C.jsx)(ze,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground`}),(0,C.jsx)(xe,{value:z,onChange:e=>Ye(e.target.value),placeholder:`Search process, record, approver…`,className:`pl-8 h-8 text-sm`}),z&&(0,C.jsx)(`button`,{type:`button`,onClick:()=>Ye(``),className:`absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground`,"aria-label":`Clear search`,children:(0,C.jsx)(Re,{className:`h-3.5 w-3.5`})})]}),rt.length>1&&(0,C.jsxs)(fe,{value:B,onValueChange:Xe,children:[(0,C.jsx)(pe,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,C.jsx)(l,{placeholder:`Process`})}),(0,C.jsxs)(_,{children:[(0,C.jsx)(s,{value:`all`,children:`All processes`}),rt.map(e=>(0,C.jsx)(s,{value:e,children:e},e))]})]}),it.length>1&&(0,C.jsxs)(fe,{value:V,onValueChange:Ze,children:[(0,C.jsx)(pe,{className:`h-8 w-auto min-w-[140px] text-sm`,children:(0,C.jsx)(l,{placeholder:`Object`})}),(0,C.jsxs)(_,{children:[(0,C.jsx)(s,{value:`all`,children:`All objects`}),it.map(e=>(0,C.jsx)(s,{value:e,children:e},e))]})]}),(z||B!==`all`||V!==`all`)&&(0,C.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[Y.length,` of `,x.length]})]}),n===`pending`&&H.size>0&&(0,C.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2 rounded-md border bg-accent/30 text-sm`,children:[(0,C.jsxs)(`span`,{children:[(0,C.jsx)(`strong`,{children:H.size}),` selected`,X.length!==H.size&&(0,C.jsxs)(`span`,{className:`text-muted-foreground ml-1`,children:[`(`,X.length,` actionable)`]})]}),(0,C.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,C.jsxs)(d,{size:`sm`,onClick:()=>$(`approve`),disabled:W||X.length===0,children:[(0,C.jsx)(ge,{className:`h-3.5 w-3.5 mr-1`}),`Approve `,X.length||``]}),(0,C.jsxs)(he,{children:[(0,C.jsx)(Ne,{asChild:!0,children:(0,C.jsxs)(d,{size:`sm`,variant:`outline`,disabled:W||X.length===0,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,C.jsx)(me,{className:`h-3.5 w-3.5 mr-1`}),`Reject `,X.length||``]})}),(0,C.jsxs)(ve,{children:[(0,C.jsxs)(be,{children:[(0,C.jsxs)(Ce,{children:[`Reject `,X.length,` requests?`]}),(0,C.jsx)(Oe,{children:`This will reject the selected requests and notify their submitters.`})]}),(0,C.jsxs)(g,{children:[(0,C.jsx)(m,{children:`Cancel`}),(0,C.jsxs)(Me,{onClick:()=>$(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:[`Reject `,X.length]})]})]})]}),(0,C.jsx)(d,{size:`sm`,variant:`ghost`,onClick:()=>U(new Set),disabled:W,children:`Clear`})]})]}),O?(0,C.jsxs)(`div`,{className:`space-y-2`,children:[(0,C.jsx)(a,{className:`h-10 w-full`}),(0,C.jsx)(a,{className:`h-10 w-full`}),(0,C.jsx)(a,{className:`h-10 w-full`})]}):x.length===0?(0,C.jsx)(`div`,{className:`flex items-center justify-center min-h-[240px] rounded-md border border-dashed`,children:(0,C.jsxs)(ne,{children:[(0,C.jsx)(o,{children:`No requests`}),(0,C.jsx)(oe,{children:n===`pending`?`You have no pending approvals.`:`Nothing here yet.`})]})}):Y.length===0?(0,C.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,C.jsx)(ie,{children:(0,C.jsx)(Pe,{className:`p-0`,children:(0,C.jsxs)(Ee,{children:[(0,C.jsx)(ye,{children:(0,C.jsxs)(ke,{children:[n===`pending`&&(0,C.jsx)(h,{className:`w-10`,children:(0,C.jsx)(c,{checked:Q,onCheckedChange:at,"aria-label":`Select all`,disabled:Z.length===0})}),(0,C.jsx)(h,{children:`Process`}),(0,C.jsx)(h,{children:`Object`}),(0,C.jsx)(h,{children:`Record`}),(0,C.jsx)(h,{children:`Step`}),(0,C.jsx)(h,{children:`Status`}),(0,C.jsx)(h,{children:`Approvers`}),(0,C.jsx)(h,{children:`Submitted`})]})}),(0,C.jsx)(_e,{children:Y.map(e=>(0,C.jsxs)(ke,{className:`cursor-pointer hover:bg-accent/50`,onClick:()=>$e(e.id),children:[n===`pending`&&(0,C.jsx)(f,{className:`w-10`,onClick:e=>e.stopPropagation(),children:(0,C.jsx)(c,{checked:H.has(e.id),onCheckedChange:()=>ot(e.id),disabled:e.status!==`pending`,"aria-label":`Select request ${e.id}`})}),(0,C.jsx)(f,{className:`font-medium`,children:e.process_name}),(0,C.jsx)(f,{children:e.object_name}),(0,C.jsx)(f,{className:`font-mono text-xs`,title:e.record_id,children:D(e.record_id)}),(0,C.jsx)(f,{children:e.current_step?(0,C.jsxs)(`span`,{className:`text-xs`,children:[e.current_step,typeof e.current_step_index==`number`&&(0,C.jsxs)(`span`,{className:`text-muted-foreground`,children:[` (#`,e.current_step_index,`)`]})]}):`—`}),(0,C.jsx)(f,{children:(0,C.jsx)(T,{status:e.status})}),(0,C.jsx)(f,{className:`max-w-[220px] truncate text-xs text-muted-foreground`,title:(e.pending_approvers||[]).join(`, `),children:(e.pending_approvers||[]).map(D).join(`, `)||`—`}),(0,C.jsxs)(f,{className:`text-xs whitespace-nowrap text-muted-foreground`,title:E(e.submitted_at),children:[(0,C.jsx)(ae,{className:`h-3 w-3 inline mr-1`}),Ve(e.submitted_at)]})]},e.id))})]})})})]})]}),(0,C.jsx)(ce,{open:!!Ue,onOpenChange:e=>!e&&et(),children:(0,C.jsxs)(ue,{className:`w-full sm:max-w-xl overflow-y-auto`,children:[(0,C.jsxs)(te,{children:[(0,C.jsx)(re,{children:`Approval Request`}),(0,C.jsx)(de,{children:j?`${j.process_name} · ${j.object_name}/${j.record_id}`:``})]}),Ke?(0,C.jsxs)(`div`,{className:`space-y-2 mt-6`,children:[(0,C.jsx)(a,{className:`h-6 w-3/4`}),(0,C.jsx)(a,{className:`h-6 w-1/2`}),(0,C.jsx)(a,{className:`h-20 w-full`})]}):j?(0,C.jsxs)(`div`,{className:`space-y-4 mt-6`,children:[(0,C.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 text-sm`,children:[(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Status`}),(0,C.jsx)(T,{status:j.status})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Current Step`}),j.current_step||`—`]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Step Index`}),j.current_step_index??`—`]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Submitter`}),(0,C.jsx)(`span`,{className:`font-mono text-xs`,title:j.submitter_id||``,children:D(j.submitter_id)})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Submitted`}),E(j.submitted_at)]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Completed`}),E(j.completed_at)]}),(0,C.jsxs)(`div`,{className:`col-span-2`,children:[(0,C.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Pending Approvers`}),(0,C.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-1`,children:(j.pending_approvers||[]).length===0?`—`:(j.pending_approvers||[]).map((e,t)=>(0,C.jsx)(u,{variant:`outline`,className:`font-mono text-[10px]`,title:e,children:D(e)},t))})]}),j.payload&&(0,C.jsxs)(`div`,{className:`col-span-2`,children:[(0,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsx)(`div`,{className:`text-muted-foreground text-xs`,children:`Payload`}),(0,C.jsxs)(`button`,{type:`button`,onClick:async()=>{try{await navigator.clipboard.writeText(JSON.stringify(j.payload,null,2)),v.success(`Payload copied`)}catch{v.error(`Copy failed`)}},className:`text-[10px] text-muted-foreground hover:text-foreground inline-flex items-center gap-1`,children:[(0,C.jsx)(ee,{className:`h-3 w-3`}),`Copy`]})]}),(0,C.jsx)(`pre`,{className:`text-[11px] bg-muted/50 rounded p-2 overflow-auto max-h-32 mt-1`,children:JSON.stringify(j.payload,null,2)})]})]}),(0,C.jsx)(se,{}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(`h3`,{className:`text-sm font-semibold mb-3`,children:`Action History`}),Ge.length===0?(0,C.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`No actions yet.`}):(0,C.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:Ge.map(e=>(0,C.jsxs)(`li`,{className:`relative text-xs`,children:[(0,C.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,C.jsxs)(`div`,{className:`flex items-baseline gap-1.5 flex-wrap`,children:[(0,C.jsx)(`span`,{className:`font-medium capitalize`,children:e.action}),(0,C.jsx)(`span`,{className:`text-muted-foreground`,children:`by`}),(0,C.jsx)(`span`,{className:`font-mono`,title:e.actor_id||``,children:D(e.actor_id)}),e.step_name&&(0,C.jsxs)(`span`,{className:`text-muted-foreground`,children:[`· `,e.step_name,` (#`,e.step_index,`)`]}),(0,C.jsx)(`span`,{className:`ml-auto text-muted-foreground text-[10px]`,title:E(e.created_at),children:Ve(e.created_at)})]}),e.comment&&(0,C.jsxs)(`div`,{className:`text-muted-foreground italic mt-0.5`,children:[`"`,e.comment,`"`]})]},e.id))})]}),j.status===`pending`&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(se,{}),(0,C.jsxs)(`div`,{className:`space-y-3`,children:[(0,C.jsxs)(`details`,{className:`group`,children:[(0,C.jsx)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground select-none`,children:`Override actor (advanced)`}),(0,C.jsxs)(`div`,{className:`mt-2`,children:[(0,C.jsx)(Te,{htmlFor:`actor-override`,className:`text-xs`,children:`Actor`}),(0,C.jsx)(`input`,{id:`actor-override`,type:`text`,value:I,onChange:e=>L(e.target.value),placeholder:`Auto: ${K(j)||`(none)`}`,className:`w-full mt-1 px-3 py-2 text-sm border rounded-md bg-background`}),(0,C.jsxs)(`div`,{className:`text-[10px] text-muted-foreground mt-1`,children:[`e.g. `,(0,C.jsx)(`code`,{children:`role:sales_manager`}),`. Leave blank to use auto-detected.`]})]})]}),(0,C.jsxs)(`div`,{children:[(0,C.jsx)(Te,{htmlFor:`comment`,className:`text-xs`,children:`Comment (optional)`}),(0,C.jsx)(i,{id:`comment`,value:P,onChange:e=>F(e.target.value),rows:2,className:`mt-1`})]}),(0,C.jsxs)(`div`,{className:`flex gap-2 flex-wrap`,children:[(0,C.jsxs)(d,{size:`sm`,onClick:()=>q(`approve`),disabled:!J||R!==null,children:[(0,C.jsx)(ge,{className:`h-4 w-4 mr-1`}),R===`approve`?`Approving…`:`Approve`]}),(0,C.jsxs)(he,{children:[(0,C.jsx)(Ne,{asChild:!0,children:(0,C.jsxs)(d,{size:`sm`,variant:`outline`,disabled:!J||R!==null,className:`border-destructive text-destructive hover:bg-destructive hover:text-destructive-foreground`,children:[(0,C.jsx)(me,{className:`h-4 w-4 mr-1`}),R===`reject`?`Rejecting…`:`Reject`]})}),(0,C.jsxs)(ve,{children:[(0,C.jsxs)(be,{children:[(0,C.jsx)(Ce,{children:`Reject this request?`}),(0,C.jsxs)(Oe,{children:[`This will mark the request as rejected and notify the submitter.`,j.current_step_index!=null&&j.current_step_index>0?` If the process is multi-step, it returns to the previous step.`:``]})]}),(0,C.jsxs)(g,{children:[(0,C.jsx)(m,{children:`Cancel`}),(0,C.jsx)(Me,{onClick:()=>q(`reject`),className:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,children:`Reject`})]})]})]}),(0,C.jsxs)(d,{size:`sm`,variant:`outline`,onClick:()=>q(`recall`),disabled:!tt||R!==null,children:[(0,C.jsx)(le,{className:`h-4 w-4 mr-1`}),R===`recall`?`Recalling…`:`Recall`]})]}),!J&&!tt&&(0,C.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,C.jsx)(`code`,{children:`role:sales_manager`}),`).`]})]})]})]}):null]})})]})}export{O as ApprovalsInboxPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n,u as r}from"./vendor-react-DR370ovB.js";import{r as i}from"./framework-DoGxClbR.js";import{Bt as a,Ht as o,Rt as s,S as c,Vt as l,hi as u,mr as d,ni as f,zt as p}from"./ui-components-DeXgqLMc.js";import{r as m}from"./vendor-ui-utils-rQOI1gAo.js";import{i as h}from"./runtime-config-ir5bt3TX.js";import{d as g,f as _,l as v,r as y,t as b,u as x}from"./plugin-chatbot-DUla2_T9.js";import{a as ee,i as S,n as C,o as w,r as T}from"./index-Bt0jFx__.js";var E=e(t(),1),D=n(),O={data_chat:{zh:`数据助手`,en:`Data Assistant`},metadata_assistant:{zh:`元数据开发助手`,en:`Metadata Assistant`}};function k(e,t,n){let r=t?O[t]:void 0;return r?e?r.zh:r.en:n}function A(e,t,n,r,i){let a=(e??``).toLowerCase().startsWith(`zh`),o=k(a,n,r),s=i.slice(0,2).map(e=>e.label||e.name);if(a){let e=[s[0]?`查询最近创建的${s[0]}`:`帮我查询最近的数据`,s[0]?`统计${s[0]}的总数量`:`统计各对象的记录数量`,s[1]?`${s[1]}有哪些字段?`:`当前应用里有哪些数据对象?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`你好,我是${o}`,emptyDescription:`随时帮你查询和分析「${t}」中的数据。试试下面的问题,或直接输入你的需求。`,clear:`清空对话`,sendHint:`发送`,agentActivity:`执行过程`,toolCompleted:`已完成`,toolRunning:`运行中`,toolAwaitingApproval:`等待确认`,toolFailed:`失败`,toolDetailsHidden:`已隐藏工具参数和原始结果,仅保留过程摘要。`,copy:`复制`,copied:`已复制`,regenerate:`重新生成`,model:`模型`,submit:`发送`,uploadFiles:`上传文件`,stopResponse:`停止生成`,trace:`调试 trace`,viewTrace:`查看调试 trace`},placeholder:`向${o}提问…`,loadingPlaceholder:`正在加载助手…`,title:`${t} 智能助手`,newChat:`开启新对话`,share:`分享对话`,reviewDraft:e=>`查看 ${e} 项变更`,publishDrafts:`发布`,published:`已发布`,publishOk:`已发布,对象已生效。`,publishFailed:`发布失败`,seedWarn:`已发布,但部分示例数据未能载入。`,openBuiltApp:`打开应用`,suggestions:e}}let c=[s[0]?`Show the latest ${s[0]}`:`Show my most recent records`,s[0]?`How many ${s[0]} are there?`:`Count records by status`,s[1]?`What fields does ${s[1]} have?`:`What data can I work with here?`].filter(Boolean);return{agentLabel:o,labels:{emptyTitle:`Hi, I'm ${o}`,emptyDescription:`I can help you query and analyze your ${t} data. Try a prompt below, or just type your question.`,clear:`Clear`,sendHint:`to send`,agentActivity:`Agent activity`,toolCompleted:`Completed`,toolRunning:`Running`,toolAwaitingApproval:`Awaiting approval`,toolFailed:`Failed`,toolDetailsHidden:`Tool inputs and raw results are hidden in this view.`,copy:`Copy`,copied:`Copied`,regenerate:`Regenerate`,model:`Model`,submit:`Submit`,uploadFiles:`Upload files`,stopResponse:`Stop response`,trace:`trace`,viewTrace:`View trace`},placeholder:`Ask ${o}...`,loadingPlaceholder:`Loading assistant...`,title:`${t} Assistant`,newChat:`New chat`,share:`Share conversation`,reviewDraft:e=>`Review ${e} change${e===1?``:`s`}`,publishDrafts:`Publish`,published:`Published`,publishOk:`Published — objects are now live.`,publishFailed:`Publish failed`,seedWarn:`Published, but some sample data failed to load.`,openBuiltApp:`Open app`,suggestions:c}}var j=`/api/v1/ai`;function M(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(/\/$/,``)}${j}`}function N(e,t){if(!e||e.type!==`object`)return null;let n=e.label||e.name||`this object`;return(t??``).toLowerCase().startsWith(`zh`)?[`为「${n}」补充字段`,`为「${n}」建议校验规则`,`添加一个状态选项字段`]:[`Add fields to ${n}`,`Suggest validations for ${n}`,`Add a status picklist field`]}function P({appLabel:e,appName:t,objects:n,agents:v,agentsLoading:x,activeAgent:T,onAgentChange:O,showAgentPicker:k,chatApi:j,apiBase:M,defaultOpen:P=!1,conversationId:F,initialMessages:I}){let{language:L}=i(),R=r(),{editor:z}=w(),B=E.useMemo(()=>!I||I.length===0?[]:_(I),[I]),V=E.useMemo(()=>v.find(e=>e.name===T)?.label??T??e,[v,T,e]),H=E.useMemo(()=>A(L,e,T,V,n),[L,e,T,V,n]),U=E.useMemo(()=>N(z,L),[z,L]),{messages:W,isLoading:G,error:K,sendMessage:q,stop:J,reload:Y,clear:X}=g({api:j,conversationId:F,body:{context:{activeApp:e,appName:t,objects:n.map(e=>({name:e.name,label:e.label})),agentName:T,autoPublishAiBuilds:h().features.autoPublishAiBuilds,...z?{editing:z}:{}}},initialMessages:B,autoResponse:!j,autoResponseText:n.length>0?`I can help you work with ${n.map(e=>e.label||e.name).join(`, `)}. What would you like to do?`:`Thanks for your message! I'm here to help you navigate and manage your data.`,autoResponseDelay:600});E.useEffect(()=>{S(F,C(W))},[F,W]);let Z=b({messages:W,apiBase:M,continueConversation:e=>{q(e)}}),Q=k&&v.length>1?(0,D.jsxs)(s,{value:T,onValueChange:O,disabled:x,children:[(0,D.jsx)(l,{className:`h-7 w-[180px] text-xs`,"data-testid":`floating-chatbot-agent-picker`,children:(0,D.jsx)(o,{placeholder:`Choose agent...`})}),(0,D.jsx)(p,{align:`end`,children:v.map(e=>(0,D.jsxs)(a,{value:e.name,className:`text-xs`,children:[(0,D.jsx)(`span`,{className:`font-medium`,children:e.label}),e.description?(0,D.jsx)(`span`,{className:`block text-muted-foreground text-[10px] truncate max-w-[220px]`,children:e.description}):null]},e.name))})]}):null,[te,$]=E.useState(!1),ne=E.useMemo(()=>M.replace(/\/v1\/ai$/,``).replace(/\/ai$/,``)||`/api`,[M]),re=(0,D.jsxs)(D.Fragment,{children:[W.length>0?(0,D.jsx)(d,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":H.newChat,title:H.newChat,"data-testid":`floating-chatbot-new`,onClick:X,children:(0,D.jsx)(f,{className:`h-4 w-4`})}):null,F?(0,D.jsx)(d,{variant:`ghost`,size:`icon`,className:`h-7 w-7`,"aria-label":H.share,title:H.share,"data-testid":`floating-chatbot-share`,onClick:()=>$(!0),children:(0,D.jsx)(u,{className:`h-4 w-4`})}):null]});return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(y,{floatingConfig:{position:`bottom-right`,defaultOpen:P,panelWidth:420,panelHeight:560,title:H.title,triggerSize:56},headerExtra:Q,headerActions:re,messages:W,labels:H.labels,showAvatars:!0,hideClearBar:!0,assistantAvatarFallback:H.agentLabel,suggestions:W.length===0?U??H.suggestions:void 0,placeholder:T?H.placeholder:x?H.loadingPlaceholder:H.placeholder,onSendMessage:e=>q(e),onClear:X,onStop:G?J:void 0,onReload:Y,isLoading:G,error:K,enableMarkdown:!0,onToolApprove:Z.decide,toolDecisions:Z.decisions,toolApproveLabel:`Approve & run`,toolDenyLabel:`Reject`,toolDenyReason:`Operator rejected from chat`,onReviewDraft:e=>{e[0]&&ee(e[0])},toolReviewLabel:H.reviewDraft,onOpenBuiltApp:e=>R(`/apps/${encodeURIComponent(e)}`),openBuiltAppLabel:H.openBuiltApp,onPublishDrafts:async e=>{try{let t=await fetch(`/api/v1/packages/${encodeURIComponent(e)}/publish-drafts`,{method:`POST`,credentials:`include`,headers:{"Content-Type":`application/json`,Accept:`application/json`},body:`{}`}),n=await t.json().catch(()=>null);if(!t.ok||n?.success===!1)throw Error(n?.error?.message||`HTTP ${t.status}`);let r=n?.data?.failedCount??n?.failedCount??0;if(r)throw Error(String(r));let i=n?.data?.seedApplied??n?.seedApplied;i&&i.success===!1?m.warning(H.seedWarn,{description:i.error??(Array.isArray(i.errors)&&i.errors.length?String(i.errors[0]):void 0)}):m.success(H.publishOk);let a=(n?.data?.published??n?.published??[]).find(e=>e?.type===`app`&&e?.name);return a?.name&&R(`/apps/${encodeURIComponent(a.name)}`),!0}catch(e){return m.error(H.publishFailed,{description:e instanceof Error?e.message:void 0}),!1}},publishDraftsLabel:H.publishDrafts,publishedLabel:H.published,autoPublishDrafts:h().features.autoPublishAiBuilds}),F&&(0,D.jsx)(c,{open:te,onOpenChange:$,objectName:`ai_conversations`,recordId:F,recordLabel:`this conversation`,apiBase:ne})]})}function F({appLabel:e,appName:t,objects:n,apiBase:r,defaultAgent:i,showAgentPicker:a,defaultOpen:o=!1,userId:s}){let c=E.useMemo(()=>M(r),[r]),l={BASE_URL:`./`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1,VITE_SENTRY_DSN:`https://1373a588ceb9da150b11e64bf85f583d@o4510356161757184.ingest.us.sentry.io/4511439670673408`,VITE_SENTRY_ENVIRONMENT:`production`,VITE_SENTRY_SEND_DEFAULT_PII:`true`,VITE_SERVER_URL:``,VITE_USE_MOCK_SERVER:`false`},u=l.VITE_AI_DEFAULT_AGENT,d=a??l.VITE_AI_SHOW_AGENT_PICKER===`true`,{agents:f,isLoading:p,error:m}=x({apiBase:c}),[h,g]=E.useState(void 0);E.useEffect(()=>{if(!h&&f.length>0){let e=v(f,i??u);e&&g(e)}},[f,h,i,u]);let _=h?`${c}/agents/${encodeURIComponent(h)}/chat`:void 0,{conversationId:y,initialMessages:b}=T({userId:s,scope:h,apiBase:c});return(0,D.jsx)(P,{appLabel:e,appName:t,objects:n,agents:f,agentsLoading:p,agentsError:m,activeAgent:h,onAgentChange:g,showAgentPicker:d,chatApi:_,apiBase:c,defaultOpen:o,conversationId:y,initialMessages:b},`${_??`local`}:${y??`pending`}`)}export{F as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{w as r}from"./framework-DoGxClbR.js";import{$ as i,At as a,Cr as o,Da as s,Ft as c,It as l,Jn as u,Kn as d,Ko as f,Mt as p,Nt as m,Pt as h,Qn as g,Ut as _,Vi as v,Xn as y,Yn as b,Zo as x,as as S,at as C,ct as w,en as T,in as E,it as D,ji as O,lt as k,mr as A,ot as j,qn as M,ss as N,st as P,ut as F}from"./ui-components-DeXgqLMc.js";import"./index-Bt0jFx__.js";var I=e(t(),1),L=n();function R({status:e}){let t={success:{icon:S,cls:`text-emerald-600 border-emerald-300`},completed:{icon:S,cls:`text-emerald-600 border-emerald-300`},failed:{icon:x,cls:`text-red-600 border-red-300`},error:{icon:x,cls:`text-red-600 border-red-300`},running:{icon:s,cls:`text-blue-600 border-blue-300 animate-pulse`},pending:{icon:f,cls:`text-amber-600 border-amber-300`},skipped:{icon:N,cls:`text-muted-foreground`}}[e]??{icon:N,cls:`text-muted-foreground`},n=t.icon;return(0,L.jsxs)(g,{variant:`outline`,className:`text-[10px] font-mono inline-flex items-center gap-1 ${t.cls}`,children:[(0,L.jsx)(n,{className:`h-3 w-3`}),e]})}function z(e){if(!e)return`—`;try{return new Date(e).toLocaleString()}catch{return e}}function B(e,t){switch(t){case`number`:{if(e===``)return;let t=Number(e);return Number.isNaN(t)?e:t}case`boolean`:return e===`true`;case`object`:case`list`:case`array`:if(e.trim()===``)return;try{return JSON.parse(e)}catch{return e}default:return e}}function V({data:e}){return(0,L.jsx)(`pre`,{className:`rounded border bg-muted/30 p-2 text-xs font-mono overflow-auto whitespace-pre-wrap break-all max-h-96`,children:JSON.stringify(e,null,2)})}function H(){let e=r()?.getClient?.(),[t,n]=(0,I.useState)([]),[i,s]=(0,I.useState)(!0),[c,l]=(0,I.useState)(null),[f,p]=(0,I.useState)(``),[m,h]=(0,I.useState)(0),g=(0,I.useCallback)(async()=>{if(!e?.meta?.getItems){l(`meta.getItems is not available on this client`),s(!1);return}s(!0),l(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){l(e?.message??String(e))}finally{s(!1)}},[e,f]);(0,I.useEffect)(()=>{g()},[g]);let _=(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)(o,{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)(d,{children:[(0,L.jsx)(b,{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)(y,{className:`text-base`,children:`Flow`}),(0,L.jsx)(u,{children:`Select a flow definition to test`})]}),(0,L.jsxs)(A,{variant:`outline`,size:`sm`,onClick:g,disabled:i,children:[(0,L.jsx)(O,{className:`h-3.5 w-3.5 mr-2 ${i?`animate-spin`:``}`}),`Refresh`]})]})}),(0,L.jsxs)(M,{children:[i&&(0,L.jsx)(a,{className:`h-9 w-72`}),c&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:c}),!i&&!c&&t.length===0&&(0,L.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No flow definitions found.`}),!i&&!c&&t.length>0&&(0,L.jsx)(`select`,{value: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))})]})]}),_&&(0,L.jsxs)(`div`,{className:`grid gap-4 lg:grid-cols-2`,children:[(0,L.jsx)(U,{client:e,flow:_.spec,onExecuted:()=>h(e=>e+1)}),(0,L.jsx)(W,{client:e,flowName:_.name,refreshKey:m})]})]})}function U({client:e,flow:t,onExecuted:n}){let r=(0,I.useMemo)(()=>(t?.variables??[]).filter(e=>e?.isInput),[t]),[a,o]=(0,I.useState)({}),[c,l]=(0,I.useState)(!1),[f,p]=(0,I.useState)(null),[m,h]=(0,I.useState)(null);(0,I.useEffect)(()=>{o({}),p(null),h(null)},[t?.name]);let _=(e,t)=>o(n=>({...n,[e]:t}));return(0,L.jsxs)(d,{children:[(0,L.jsxs)(b,{className:`pb-3`,children:[(0,L.jsx)(y,{className:`text-base`,children:`Test Run`}),(0,L.jsx)(u,{children:`Provide input values and invoke the flow`})]}),(0,L.jsxs)(M,{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)(g,{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)(F,{id:`var-${e.name}`,checked:a[e.name]===`true`,onCheckedChange:t=>_(e.name,t?`true`:`false`)}),(0,L.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:a[e.name]===`true`?`true`:`false`})]}):e.type===`object`||e.type===`list`||e.type===`array`?(0,L.jsx)(i,{id:`var-${e.name}`,placeholder:`JSON ${e.type}`,value:a[e.name]??``,onChange:t=>_(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:a[e.name]??``,onChange:t=>_(e.name,t.target.value)})]},e.name)),(0,L.jsx)(`div`,{className:`pt-1`,children:(0,L.jsxs)(A,{onClick:async()=>{if(!e?.automation?.execute){h(`automation.execute is not available on this client`);return}l(!0),h(null),p(null);try{let i={};for(let e of r){let t=a[e.name];t!==void 0&&(i[e.name]=B(t,e.type))}p(await e.automation.execute(t.name,{params:i})),n?.()}catch(e){h(e?.message??String(e))}finally{l(!1)}},disabled:c,size:`sm`,children:[c?(0,L.jsx)(s,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(v,{className:`h-3.5 w-3.5 mr-2`}),c?`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)(x,{className:`h-4 w-4 text-red-500`}),` Failed`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(S,{className:`h-4 w-4 text-emerald-500`}),` Result`]}),typeof f?.durationMs==`number`&&(0,L.jsxs)(g,{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,i]=(0,I.useState)([]),[o,f]=(0,I.useState)(!0),[v,x]=(0,I.useState)(null),[S,T]=(0,I.useState)(null),[E,N]=(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){x(`automation.listRuns is not available on this client`),f(!1);return}f(!0),x(null);try{let n=await e.automation.listRuns(t,{limit:20});i(Array.isArray(n)?n:n?.items??n?.runs??[])}catch(e){x(e?.message??String(e))}finally{f(!1)}},[e,t]);(0,I.useEffect)(()=>{W()},[W,n]);let G=async n=>{T(n),N(null),U(null),B(!0);try{let r=await e.automation.getRun(t,n);N(r?.run??r)}catch(e){U(e?.message??String(e))}finally{B(!1)}};return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsxs)(d,{children:[(0,L.jsx)(b,{className:`pb-3`,children:(0,L.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,L.jsxs)(`div`,{children:[(0,L.jsx)(y,{className:`text-base`,children:`Recent Runs`}),(0,L.jsx)(u,{className:`font-mono text-xs`,children:t})]}),(0,L.jsxs)(A,{variant:`outline`,size:`sm`,onClick:W,disabled:o,children:[o?(0,L.jsx)(s,{className:`h-3.5 w-3.5 mr-2 animate-spin`}):(0,L.jsx)(O,{className:`h-3.5 w-3.5 mr-2`}),`Refresh`]})]})}),(0,L.jsxs)(M,{children:[o&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(a,{className:`h-8 w-full`}),(0,L.jsx)(a,{className:`h-8 w-full`}),(0,L.jsx)(a,{className:`h-8 w-full`})]}),!o&&v&&(0,L.jsx)(`p`,{className:`text-sm text-red-500 font-mono break-all`,children:v}),!o&&!v&&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.`}),!o&&!v&&r.length>0&&(0,L.jsxs)(D,{children:[(0,L.jsx)(w,{children:(0,L.jsxs)(k,{children:[(0,L.jsx)(P,{children:`Run`}),(0,L.jsx)(P,{children:`Status`}),(0,L.jsx)(P,{children:`Started`}),(0,L.jsx)(P,{className:`text-right`,children:`Duration`})]})}),(0,L.jsx)(C,{children:r.map(e=>(0,L.jsxs)(k,{className:`cursor-pointer`,onClick:()=>G(e.id),children:[(0,L.jsxs)(j,{className:`font-mono text-xs`,children:[e.id.slice(0,12),`…`]}),(0,L.jsx)(j,{children:(0,L.jsx)(R,{status:e.status})}),(0,L.jsx)(j,{className:`text-xs text-muted-foreground`,children:z(e.startedAt)}),(0,L.jsx)(j,{className:`text-right font-mono text-xs`,children:typeof e.durationMs==`number`?`${e.durationMs} ms`:`—`})]},e.id))})]})]})]}),(0,L.jsx)(p,{open:!!S,onOpenChange:e=>{e||(T(null),N(null))},children:(0,L.jsxs)(m,{side:`right`,className:`w-full sm:max-w-2xl p-0 flex flex-col`,children:[(0,L.jsxs)(c,{className:`p-4 border-b`,children:[(0,L.jsxs)(l,{className:`font-mono text-sm break-all`,children:[`Run `,S]}),(0,L.jsx)(h,{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)(g,{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)(_,{className:`flex-1 p-4`,children:[F&&(0,L.jsxs)(`div`,{className:`space-y-2`,children:[(0,L.jsx)(a,{className:`h-16 w-full`}),(0,L.jsx)(a,{className:`h-16 w-full`}),(0,L.jsx)(a,{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)(g,{variant:`outline`,className:`text-[10px] font-mono`,children:e.nodeType}),(0,L.jsx)(R,{status:e.status}),typeof e.durationMs==`number`&&(0,L.jsxs)(g,{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{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{f as r,o as i}from"./infrastructure-CxityHZF.js";import{$n as a,Da as o,Ea as s,Jn as c,Kn as l,Mr as u,Qn as d,Xn as f,Yn as p,as as m,en as h,er as g,in as _,kr as v,mr as y,nr as b,qn as x,rr as S,ss as C,tr as w,v as T,xr as E}from"./ui-components-DeXgqLMc.js";var D=e(t(),1),O=n();function k(){let{user:e,updateUser:t,isLoading:n,changePassword:s,setInitialPassword:k,hasLocalPassword:j}=r(),{upload:M}=T(),[N,P]=(0,D.useState)(e?.name??``),[F,I]=(0,D.useState)(!1),[L,R]=(0,D.useState)(null),z=(0,D.useRef)(null),[B,V]=(0,D.useState)(!1),[H,U]=(0,D.useState)(null);return(0,D.useEffect)(()=>{P(e?.name??``)},[e?.name]),e?(0,O.jsxs)(`div`,{className:`flex flex-col gap-4 sm:gap-6 p-4 sm:p-6 max-w-2xl`,children:[(0,O.jsxs)(`div`,{className:`min-w-0`,children:[(0,O.jsx)(`h1`,{className:`text-xl sm:text-2xl font-bold tracking-tight`,children:`Profile`}),(0,O.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:`Manage your account settings`})]}),(0,O.jsx)(l,{children:(0,O.jsxs)(x,{className:`pt-6`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,O.jsxs)(a,{className:`h-16 w-16`,children:[(0,O.jsx)(w,{src:e.image??void 0,alt:e.name??`User`}),(0,O.jsx)(g,{className:`text-lg bg-primary text-primary-foreground`,children:i(e)})]}),(0,O.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,O.jsx)(`p`,{className:`text-lg font-semibold truncate`,children:e.name??`User`}),(0,O.jsx)(`p`,{className:`text-sm text-muted-foreground truncate`,children:e.email}),(0,O.jsx)(d,{variant:`secondary`,className:`mt-1`,children:e.role??`member`})]}),(0,O.jsxs)(`div`,{className:`flex flex-col gap-2 shrink-0`,children:[(0,O.jsx)(`input`,{ref:z,type:`file`,accept:`image/*`,className:`hidden`,onChange:async e=>{let n=e.target.files?.[0];if(z.current&&(z.current.value=``),n){V(!0),U(null);try{await t({image:(await M(n)).url})}catch(e){U(e instanceof Error?e.message:String(e))}finally{V(!1)}}},"data-testid":`profile-avatar-file`}),(0,O.jsxs)(y,{type:`button`,variant:`outline`,size:`sm`,disabled:B,onClick:()=>z.current?.click(),"data-testid":`profile-avatar-upload-btn`,children:[B?(0,O.jsx)(o,{className:`mr-2 h-4 w-4 animate-spin`}):(0,O.jsx)(u,{className:`mr-2 h-4 w-4`}),e.image?`Replace`:`Upload`]}),e.image&&(0,O.jsxs)(y,{type:`button`,variant:`ghost`,size:`sm`,disabled:B,onClick:async()=>{V(!0),U(null);try{await t({image:null})}catch(e){U(e instanceof Error?e.message:String(e))}finally{V(!1)}},"data-testid":`profile-avatar-remove-btn`,children:[(0,O.jsx)(E,{className:`mr-2 h-4 w-4`}),`Remove`]})]})]}),H&&(0,O.jsxs)(b,{variant:`destructive`,className:`mt-4`,children:[(0,O.jsx)(C,{className:`h-4 w-4`}),(0,O.jsx)(S,{children:H})]})]})}),(0,O.jsxs)(l,{children:[(0,O.jsxs)(p,{children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(v,{className:`h-4 w-4 text-muted-foreground`}),(0,O.jsx)(f,{className:`text-base sm:text-lg`,children:`Personal Information`})]}),(0,O.jsx)(c,{children:`Update your name and view account details`})]}),(0,O.jsx)(x,{children:(0,O.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault(),R(null),I(!1);try{await t({name:N}),I(!0)}catch(e){R(e instanceof Error?e.message:String(e))}},className:`space-y-4`,children:[L&&(0,O.jsxs)(b,{variant:`destructive`,children:[(0,O.jsx)(C,{className:`h-4 w-4`}),(0,O.jsx)(S,{children:L})]}),F&&(0,O.jsxs)(b,{children:[(0,O.jsx)(m,{className:`h-4 w-4 text-green-600`}),(0,O.jsx)(S,{className:`text-green-800 dark:text-green-400`,children:`Profile updated successfully.`})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(_,{htmlFor:`profile-name`,children:`Name`}),(0,O.jsx)(h,{id:`profile-name`,type:`text`,value:N,onChange:e=>P(e.target.value),required:!0,"aria-required":`true`,disabled:n})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(_,{htmlFor:`profile-email`,children:`Email`}),(0,O.jsx)(h,{id:`profile-email`,type:`email`,value:e.email,disabled:!0,className:`bg-muted text-muted-foreground`}),(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Email cannot be changed.`})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(_,{children:`Role`}),(0,O.jsx)(h,{type:`text`,value:e.role??`member`,disabled:!0,className:`bg-muted text-muted-foreground`})]}),(0,O.jsx)(y,{type:`submit`,disabled:n,className:`w-full sm:w-auto`,children:n?`Saving…`:`Save Changes`})]})})]}),(0,O.jsx)(A,{changePassword:s,setInitialPassword:k,hasLocalPassword:j})]}):null}function A({changePassword:e,setInitialPassword:t,hasLocalPassword:n,highlight:r,onPasswordSet:i}){let[a,o]=(0,D.useState)(null),[u,d]=(0,D.useState)(``),[g,v]=(0,D.useState)(``),[w,T]=(0,D.useState)(``),[E,k]=(0,D.useState)(!1),[A,j]=(0,D.useState)(null),[M,N]=(0,D.useState)(null);(0,D.useEffect)(()=>{let e=!1;return n().then(t=>{e||o(t)}).catch(()=>{e||o(!1)}),()=>{e=!0}},[n]);let P=()=>{d(``),v(``),T(``)},F=async n=>{if(n.preventDefault(),j(null),N(null),g.length<8){j(`Password must be at least 8 characters`);return}if(g!==w){j(`Passwords do not match`);return}k(!0);try{if(a){if(!u){j(`Enter your current password`),k(!1);return}await e(u,g),N(`Password changed.`)}else await t(g),N(`Local password set. You can now sign in with email and password on this environment.`),o(!0),i?.();P()}catch(e){j(e instanceof Error?e.message:String(e))}finally{k(!1)}},I=a===null;return(0,O.jsxs)(l,{className:r?`ring-2 ring-amber-300 dark:ring-amber-700`:void 0,children:[(0,O.jsxs)(p,{children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(s,{className:`h-4 w-4 text-muted-foreground`}),(0,O.jsx)(f,{className:`text-base sm:text-lg`,children:a?`Change Password`:`Set Local Password`})]}),(0,O.jsx)(c,{children:a?`Update the password you use to sign in to this environment.`:`You signed in via single sign-on. Set a local password to also sign in with email and password on this environment.`})]}),(0,O.jsx)(x,{children:(0,O.jsxs)(`form`,{onSubmit:F,className:`space-y-4 max-w-md`,children:[a&&(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(_,{htmlFor:`current-password`,children:`Current password`}),(0,O.jsx)(h,{id:`current-password`,type:`password`,autoComplete:`current-password`,value:u,onChange:e=>d(e.target.value),disabled:E||I,required:!0})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(_,{htmlFor:`new-password`,children:a?`New password`:`Password`}),(0,O.jsx)(h,{id:`new-password`,type:`password`,autoComplete:`new-password`,value:g,onChange:e=>v(e.target.value),disabled:E||I,minLength:8,required:!0})]}),(0,O.jsxs)(`div`,{className:`space-y-2`,children:[(0,O.jsx)(_,{htmlFor:`confirm-password`,children:`Confirm password`}),(0,O.jsx)(h,{id:`confirm-password`,type:`password`,autoComplete:`new-password`,value:w,onChange:e=>T(e.target.value),disabled:E||I,minLength:8,required:!0})]}),A&&(0,O.jsxs)(b,{variant:`destructive`,children:[(0,O.jsx)(C,{className:`h-4 w-4`}),(0,O.jsx)(S,{children:A})]}),M&&(0,O.jsxs)(b,{children:[(0,O.jsx)(m,{className:`h-4 w-4`}),(0,O.jsx)(S,{children:M})]}),(0,O.jsx)(y,{type:`submit`,disabled:E||I,className:`w-full sm:w-auto`,children:E?`Saving…`:a?`Change password`:`Set password`})]})})]})}export{k as ProfilePage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./rolldown-runtime-CMxvf4Kt.js";import{_ as t,t as n}from"./vendor-react-DR370ovB.js";import{w as r}from"./framework-DoGxClbR.js";import{Bn as i,Bo as a,Fn as o,In as s,Jn as ee,Kn as te,Ln as c,Ma as ne,Oo as l,Pi as re,Qn as ie,Rn as u,Wo as ae,Xn as oe,Yn as se,_i as ce,at as le,ct as ue,en as d,in as f,it as de,ji as fe,lt as p,mr as m,ot as h,qn as pe,st as g,zi as me,zn as _}from"./ui-components-DeXgqLMc.js";import{r as v}from"./vendor-ui-utils-rQOI1gAo.js";import"./index-Bt0jFx__.js";var y=e(t(),1),b=n();function x(e){return e?e.replace(/^\/+/,``).match(/^forms\/([^/?#]+)/i)?.[1]??null:null}function S(e){return e.trim().toLowerCase().replace(/[^a-z0-9-_]+/g,`-`).replace(/^-+|-+$/g,``)}function C(){let e=r()?.getClient?.(),[t,n]=(0,y.useState)([]),[C,he]=(0,y.useState)([]),[w,T]=(0,y.useState)(!0),[E,D]=(0,y.useState)(null),[ge,O]=(0,y.useState)(!1),[k,A]=(0,y.useState)(``),[j,M]=(0,y.useState)(``),[N,P]=(0,y.useState)(!1),[_e,F]=(0,y.useState)(!1),[I,L]=(0,y.useState)(null),[R,z]=(0,y.useState)(``),[B,V]=(0,y.useState)(`thank-you`),[H,U]=(0,y.useState)(``),[W,G]=(0,y.useState)(``),[K,q]=(0,y.useState)(``),[J,Y]=(0,y.useState)(!1),X=async()=>{if(!e?.meta?.getItems){D(`meta.getItems is not available on this client`),T(!1);return}T(!0),D(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=x(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),he(a)}catch(e){D(e?.message??String(e))}finally{T(!1)}};(0,y.useEffect)(()=>{X()},[]);let ve=typeof window<`u`?window.location.origin:``,Z=e=>`${ve}/console/f/${e}`,ye=e=>`<iframe src="${Z(e)}" width="100%" height="640" frameborder="0" style="border:0;"></iframe>`,be=e=>`<iframe\n src={\`${Z(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(!k||!j)return;let t=C.find(e=>e.name===k);if(!t)return;let n=S(j);if(!n){v.error(`Invalid slug`);return}let r={...t.spec,sharing:{...t.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${n}`}};P(!0);try{await e.meta.saveItem(`view`,t.name,r),v.success(`Published ${t.name}`),O(!1),A(``),M(``),await X()}catch(e){v.error(`Publish failed: ${e?.message??e}`)}finally{P(!1)}},Se=e=>{L(e),z(e.slug);let t=e.spec?.submitBehavior;V(t?.kind??`thank-you`),U(t?.title??``),G(t?.message??``),q(t?.url??``),F(!0)},Ce=async()=>{if(!I)return;let t=S(R);if(!t){v.error(`Invalid slug`);return}let n;switch(B){case`thank-you`:n={kind:`thank-you`},H&&(n.title=H),W&&(n.message=W);break;case`redirect`:if(!K){v.error(`Redirect URL is required`);return}n={kind:`redirect`,url:K};break;case`continue`:case`next-record`:n={kind:B};break}let r={...I.spec,sharing:{...I.spec.sharing??{},enabled:!0,allowAnonymous:!0,publicLink:`/forms/${t}`},submitBehavior:n};Y(!0);try{await e.meta.saveItem(`view`,I.name,r),v.success(`Saved ${I.name}`),F(!1),L(null),await X()}catch(e){v.error(`Save failed: ${e?.message??e}`)}finally{Y(!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)(te,{children:[(0,b.jsxs)(se,{className:`flex flex-row items-start justify-between gap-4 space-y-0`,children:[(0,b.jsxs)(`div`,{children:[(0,b.jsxs)(oe,{className:`flex items-center gap-2`,children:[(0,b.jsx)(re,{className:`h-4 w-4`}),`Public Forms`]}),(0,b.jsx)(ee,{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)(m,{variant:`default`,size:`sm`,onClick:()=>O(!0),disabled:C.length===0,title:C.length===0?`No non-public FormViews available`:`Publish a FormView`,children:[(0,b.jsx)(me,{className:`h-3.5 w-3.5`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Publish form…`})]}),(0,b.jsxs)(m,{variant:`outline`,size:`sm`,onClick:X,disabled:w,children:[(0,b.jsx)(fe,{className:`h-3.5 w-3.5 ${w?`animate-spin`:``}`}),(0,b.jsx)(`span`,{className:`ml-1.5`,children:`Refresh`})]})]})]}),(0,b.jsxs)(pe,{children:[E&&(0,b.jsx)(`div`,{className:`mb-3 rounded-md border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive`,children:E}),!w&&!$&&(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)(de,{children:[(0,b.jsx)(ue,{children:(0,b.jsxs)(p,{children:[(0,b.jsx)(g,{children:`Name`}),(0,b.jsx)(g,{children:`Object`}),(0,b.jsx)(g,{children:`Slug`}),(0,b.jsx)(g,{children:`Public URL`}),(0,b.jsx)(g,{className:`text-right`,children:`Actions`})]})}),(0,b.jsx)(le,{children:t.map(e=>{let t=Z(e.slug);return(0,b.jsxs)(p,{children:[(0,b.jsx)(h,{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)(h,{children:e.object?(0,b.jsx)(ie,{variant:`secondary`,children:e.object}):(0,b.jsx)(`span`,{className:`text-muted-foreground`,children:`—`})}),(0,b.jsx)(h,{children:(0,b.jsx)(`code`,{className:`text-xs`,children:e.slug})}),(0,b.jsx)(h,{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)(l,{className:`h-3 w-3`})]})}),(0,b.jsx)(h,{className:`text-right`,children:(0,b.jsxs)(`div`,{className:`inline-flex gap-1`,children:[(0,b.jsx)(m,{variant:`ghost`,size:`sm`,title:`Copy URL`,onClick:()=>Q(`URL`,t),children:(0,b.jsx)(ne,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(m,{variant:`ghost`,size:`sm`,title:`Copy <iframe> embed`,onClick:()=>Q(`iframe snippet`,ye(e.slug)),children:(0,b.jsx)(ae,{className:`h-3.5 w-3.5`})}),(0,b.jsx)(m,{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)(m,{variant:`ghost`,size:`sm`,title:`Edit sharing & post-submit behavior`,onClick:()=>Se(e),children:(0,b.jsx)(ce,{className:`h-3.5 w-3.5`})})]})})]},e.name)})})]})]})]}),(0,b.jsx)(o,{open:ge,onOpenChange:O,children:(0,b.jsxs)(s,{className:`sm:max-w-md`,children:[(0,b.jsxs)(_,{children:[(0,b.jsx)(i,{children:`Publish a FormView`}),(0,b.jsxs)(c,{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)(f,{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:k,onChange:e=>A(e.target.value),children:[(0,b.jsx)(`option`,{value:``,children:`— Select a FormView —`}),C.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)(f,{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)(d,{id:`publish-slug`,placeholder:`contact-us`,value:j,onChange:e=>M(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)(m,{variant:`ghost`,onClick:()=>O(!1),disabled:N,children:`Cancel`}),(0,b.jsx)(m,{onClick:xe,disabled:N||!k||!j,children:N?`Publishing…`:`Publish`})]})]})}),(0,b.jsx)(o,{open:_e,onOpenChange:F,children:(0,b.jsxs)(s,{className:`sm:max-w-lg`,children:[(0,b.jsxs)(_,{children:[(0,b.jsx)(i,{children:I?`Edit ${I.label??I.name}`:`Edit form`}),(0,b.jsx)(c,{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)(f,{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)(d,{id:`edit-slug`,value:R,onChange:e=>z(e.target.value)})]})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(f,{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:B,onChange:e=>V(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)`})]})]}),B===`thank-you`&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(f,{htmlFor:`edit-tytitle`,children:`Title`}),(0,b.jsx)(d,{id:`edit-tytitle`,placeholder:`Thanks!`,value:H,onChange:e=>U(e.target.value)})]}),(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(f,{htmlFor:`edit-tymsg`,children:`Message`}),(0,b.jsx)(d,{id:`edit-tymsg`,placeholder:`Your submission has been received.`,value:W,onChange:e=>G(e.target.value)})]})]}),B===`redirect`&&(0,b.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,b.jsx)(f,{htmlFor:`edit-url`,children:`Redirect URL`}),(0,b.jsx)(d,{id:`edit-url`,type:`url`,placeholder:`https://example.com/thanks`,value:K,onChange:e=>q(e.target.value)})]})]}),(0,b.jsxs)(u,{children:[(0,b.jsx)(m,{variant:`ghost`,onClick:()=>F(!1),disabled:J,children:`Cancel`}),(0,b.jsx)(m,{onClick:Ce,disabled:J||!R,children:J?`Saving…`:`Save`})]})]})})]})}export{C as PublicFormsPage};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{pt as e}from"./framework-DoGxClbR.js";import{c as t}from"./vendor-objectstack-B2q1QmZh.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 listDrafts(e={}){let t=[];e.packageId&&t.push(`packageId=${encodeURIComponent(e.packageId)}`),e.type&&t.push(`type=${encodeURIComponent(e.type)}`);let n=t.length?`?${t.join(`&`)}`:``,r=`${this.base}/_drafts${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?.drafts??a?.data?.drafts??[]}async get(e,t,n={}){let r=n.state===`draft`?`?state=draft`:``,i=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}${r}`,a=await this.fetchImpl(i,{method:`GET`,headers:this.headers,cache:`no-store`});if(a.status===404)return null;if(!a.ok)throw await g(a);return await a.json()}async getDraft(e,t){return this.get(e,t,{state:`draft`})}async save(e,t,n,r={}){let i=[];r.force&&i.push(`force=true`),r.mode===`draft`&&i.push(`mode=draft`),r.packageId&&i.push(`package=${encodeURIComponent(r.packageId)}`);let a=i.length?`?${i.join(`&`)}`:``,o=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}${a}`,s={...this.headers,"Content-Type":`application/json`};r.ifMatch&&(s[`If-Match`]=r.ifMatch),r.actor&&(s[`X-Actor`]=r.actor);let c=await this.fetchImpl(o,{method:`PUT`,headers:s,body:JSON.stringify(n)});if(!c.ok)throw await g(c);return await c.json()}async publishDraft(e,t){let n=`${this.base}/${encodeURIComponent(e)}/${encodeURIComponent(t)}/publish`,r=await this.fetchImpl(n,{method:`POST`,headers:{...this.headers,"Content-Type":`application/json`,Accept:`application/json`},body:`{}`});if(!r.ok)throw await g(r);let i=await r.json().catch(()=>({}));return i?.data&&typeof i.data==`object`?i.data:i}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(e){this.client=new t({...e,logger:D()}),this.metadataCache=new n(e.cache),this.autoReconnect=e.autoReconnect??!0,this.maxReconnectAttempts=e.maxReconnectAttempts??3,this.reconnectDelay=e.reconnectDelay??1e3,this.baseUrl=e.baseUrl,this.token=e.token,this.fetchImpl=e.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 batchTransaction(e){let t=`${this.baseUrl}/api/v1/batch`,n=await fetch(t,{method:`POST`,headers:{"Content-Type":`application/json`,...this.getAuthHeaders()},body:JSON.stringify({operations:e})});if(!n.ok){let e=await n.json().catch(()=>({message:n.statusText}));throw new r(e.error||e.message||`Batch failed with status ${n.status}`,`BATCH_ERROR`,n.status)}return n.json()}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(t){if(!t)return{};let n={};if(t.$select&&(n.select=t.$select.includes(`id`)?t.$select:[`id`,...t.$select]),t.$filter!==void 0&&t.$filter!==null&&!(Array.isArray(t.$filter)?t.$filter.length===0:typeof t.$filter==`object`&&Object.keys(t.$filter).length===0))if(Array.isArray(t.$filter))if(t.$filter.length>0&&typeof t.$filter[0]==`object`&&!Array.isArray(t.$filter[0])&&t.$filter[0].field!==void 0){let e=t.$filter.map(e=>b(e)).filter(e=>e!==null);e.length===0||(e.length===1?n.filters=e[0]:n.filters=[`and`,...e])}else n.filters=t.$filter;else n.filters=e(t.$filter);return t.$orderby&&(Array.isArray(t.$orderby)?n.sort=t.$orderby.map(e=>{if(typeof e==`string`)return e;let t=e.field;return(e.order||`asc`)===`desc`?`-${t}`:t}):n.sort=Object.entries(t.$orderby).map(([e,t])=>t===`desc`?`-${e}`:e)),t.$skip!==void 0&&(n.skip=t.$skip),t.$top!==void 0&&(n.top=t.$top),n}async getObjectSchema(e){await this.connect();try{return await this.metadataCache.get(e,async()=>{let t=await this.client.meta.getItem(`object`,e);return t&&t.item?t.item:t})}catch(t){let n=t;throw w(n)?new i(e,{originalError:t}):t instanceof r?t:l(n,`getObjectSchema(${e})`)}}getClient(){return this.client}async getDiscovery(){try{return await this.connect(),this.client.discoveryInfo||null}catch{return null}}async listViewOverrides(e){await this.connect();try{let t=`view-overrides:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItems(e),n=Array.isArray(t?.items)?t.items:[],r={};for(let e of n){if(!e||typeof e!=`object`)continue;let t=e.name??e.id??e._name;typeof t==`string`&&t&&(r[t]=e)}return r})}catch{return{}}}async getView(e,t){await this.connect();try{let n=`view:${e}:${t}`;return await this.metadataCache.get(n,async()=>{let n=await this.client.meta.getItem(e,t);return n&&n.item?n.item:n??null})}catch{return null}}async updateViewConfig(e,t,n){await this.connect();try{let r={...n||{},object:n?.object||e,name:t},i=await this.client.meta.saveItem(`view`,t,r),a=`view:${e}:${t}`;return this.metadataCache.invalidate?.(a),this.metadataCache.invalidate?.(`view-overrides:${e}`),this.metadataCache.invalidate?.(`views:${e}`),i&&i.item?i.item:i??void 0}catch(e){throw e}}async listViews(e){await this.connect();try{let t=await this.client.meta.getItems(`view`),n=Array.isArray(t?.items)?t.items:Array.isArray(t)?t:[],r=new Set([`form`,`detail`]);return n.filter(t=>{if(!t)return!1;let n=t.list??t;if((n?.data?.object??n?.object??n?.objectName)!==e)return!1;let i=t.viewKind??n?.viewKind;return!(i&&r.has(i))}).map(e=>{let t=e.list??e;return t&&t.config&&typeof t.config==`object`?{...t.config,name:t.name??t.config.name,label:t.label??t.config.label,isDefault:!!t.isDefault}:t})}catch(e){return console.warn(`[OBJECTSTACKDataSource] listViews failed:`,e),[]}}async createView(e,t){await this.connect();let n=String(t?.name||``).trim();if(!n){let r=String(t?.label||e||`view`).toLowerCase().replace(/[^a-z0-9_]+/g,`_`).replace(/^_+|_+$/g,``).slice(0,40);(!r||/^[0-9]/.test(r))&&(r=r?`view_${r}`:`view`);let i=Date.now().toString(36);n=`${r}_${i}`}let r={...t,name:n,object:t?.object||e,data:t?.data||{provider:`object`,object:e}};try{let t=await this.client.meta.saveItem(`view`,n,r);return this.metadataCache.invalidate?.(`views:${e}`),t&&t.item?t.item:r}catch(e){throw e}}async updateView(e,t,n){await this.connect();let r={};try{let e=await this.client.meta.getItem(`view`,t);r=e&&(e.item||e)||{},r?.list&&(r=r.list)}catch{}let i={...r,...n,name:t,object:r?.object||r?.data?.object||e};try{let n=await this.client.meta.saveItem(`view`,t,i);return this.metadataCache.invalidate?.(`views:${e}`),this.metadataCache.invalidate?.(`view:${e}:${t}`),n&&n.item?n.item:i}catch(e){throw e}}async deleteView(e,t){await this.connect();try{let n=await this.client.meta.deleteItem(`view`,t);return this.metadataCache.invalidate?.(`views:${e}`),this.metadataCache.invalidate?.(`view:${e}:${t}`),{deleted:!!(n?.deleted??n?.reset??!0)}}catch(e){throw e}}async getApp(e){await this.connect();try{let t=`app:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`apps`,e);return t&&t.item?t.item:t??null})}catch{return null}}async getPage(e){await this.connect();try{let t=`page:${e}`;return await this.metadataCache.get(t,async()=>{let t=await this.client.meta.getItem(`pages`,e);return t&&t.item?t.item:t??null})}catch{return null}}async updateDashboard(e,t){await this.connect();try{let n=await this.client.meta.saveItem(`dashboard`,e,t);return this.metadataCache.invalidate?.(`dashboards`),this.metadataCache.invalidate?.(`dashboard:${e}`),n&&n.item?n.item:n??void 0}catch(e){throw e}}async aggregate(e,t){if(await this.connect(),t!=null&&(Array.isArray(t.groupBy)||Array.isArray(t.aggregations)||t.where!==void 0)){let n={};Array.isArray(t.groupBy)&&(n.groupBy=t.groupBy),Array.isArray(t.aggregations)&&(n.aggregations=t.aggregations),t.where!==void 0&&(n.where=t.where),typeof t.limit==`number`&&(n.limit=t.limit);let r=await this.client.data.query(e,n);return Array.isArray(r)?r:Array.isArray(r?.records)?r.records:Array.isArray(r?.data)?r.data:[]}try{let n=t.function===`count`?`count`:`${t.field}_${t.function}`,r={cube:e,measures:[n],dimensions:t.groupBy&&t.groupBy!==`_all`?[t.groupBy]:[]};t.filter&&(r.where=t.filter);let i=await this.client.analytics.query(r),a=Array.isArray(i)?i:i?.rows&&Array.isArray(i.rows)?i.rows:i?.data&&Array.isArray(i.data)?i.data:i?.data?.rows&&Array.isArray(i.data.rows)?i.data.rows:i?.results&&Array.isArray(i.results)?i.results:[];if(a.length>0&&a.every(e=>e==null?!0:!(n in e&&e[n]!=null||t.field in e&&e[t.field]!=null))){let n=(await this.find(e,t.filter?{$filter:t.filter}:void 0)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}return a.map(e=>{let r={...e};return n!==t.field&&n in r&&(r[t.field]=r[n],delete r[n]),r})}catch{let n=(await this.find(e,t.filter?{$filter:t.filter}:void 0)).data||[];return n.length===0?[]:this.aggregateClientSide(n,t)}}async queryDataset(e,t){await this.connect();let n=`${(this.baseUrl||``).replace(/\/$/,``)}/api/v1/analytics/dataset/query`,r=typeof e==`string`?{datasetName:e,selection:t}:{dataset:e,selection:t},i=await this.fetchImpl(n,{method:`POST`,headers:{"Content-Type":`application/json`,...this.token?{Authorization:`Bearer ${this.token}`}:{}},body:JSON.stringify(r)});if(!i.ok){let e=``;try{let t=await i.json();e=t?.message||t?.error||JSON.stringify(t)}catch{}throw Error(`Dataset query failed: ${i.status} ${i.statusText}${e?` — ${e}`:``}`)}let a=await i.json(),o=a&&typeof a==`object`&&`success`in a&&`data`in a?a.data:a;return{rows:Array.isArray(o?.rows)?o.rows:Array.isArray(o)?o:[],fields:Array.isArray(o?.fields)?o.fields:[]}}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};
|