import{b7 as t,cb as o,c4 as r}from"./flowdrop.es.js?v=1.8.1";let n=null;function e(t){n=t}function a(){return n}async function i(e,a,i,s={}){if(!n)throw new Error("Endpoint configuration not set. Call setEndpointConfig() first.");const w=t(n,a,i),d=o(n,e),f=r(n,e),c=await fetch(w,{method:d,headers:f,...s}),l=c.headers.get("content-type"),p=l?.includes("application/json");if(!c.ok){let t=`HTTP ${c.status}: ${c.statusText}`;if(p)try{const o=await c.json();t=o.error||o.message||t}catch{}else try{const o=await c.text();t=`${t}. Server returned: ${o.substring(0,200).trim()}...`}catch{}throw new Error(t)}return await c.json()}const s={async getNodes(t){if(!n)throw new Error("Endpoint configuration not set");const o=new URLSearchParams;t?.category&&o.append("category",t.category),t?.search&&o.append("search",t.search),t?.limit&&o.append("limit",t.limit.toString()),t?.offset&&o.append("offset",t.offset.toString());return(await i("nodes.list",n.endpoints.nodes.list+"?"+o.toString())).data||[]},async getNode(t){if(!n)throw new Error("Endpoint configuration not set");const o=await i("nodes.get",n.endpoints.nodes.get,{id:t});if(!o.data)throw new Error("Node not found");return o.data}},w={async getWorkflows(t){if(!n)throw new Error("Endpoint configuration not set");const o=new URLSearchParams;t?.search&&o.append("search",t.search),t?.limit&&o.append("limit",t.limit.toString()),t?.offset&&o.append("offset",t.offset.toString());return(await i("workflows.list",n.endpoints.workflows.list+"?"+o.toString())).data||[]},async getWorkflow(t){if(!n)throw new Error("Endpoint configuration not set");const o=await i("workflows.get",n.endpoints.workflows.get,{id:t});if(!o.data)throw new Error("Workflow not found");return o.data},async createWorkflow(t){if(!n)throw new Error("Endpoint configuration not set");const o=(n.transformWorkflowPayload??(t=>t))(t),r=await i("workflows.create",n.endpoints.workflows.create,void 0,{method:"POST",body:JSON.stringify(o)});if(!r.data)throw new Error("Failed to create workflow");return r.data},async updateWorkflow(t,o){if(!n)throw new Error("Endpoint configuration not set");const r=(n.transformWorkflowPayload??(t=>t))(o),e=await i("workflows.update",n.endpoints.workflows.update,{id:t},{method:"PUT",body:JSON.stringify(r)});if(!e.data)throw new Error("Failed to update workflow");return e.data},async deleteWorkflow(t){if(!n)throw new Error("Endpoint configuration not set");await i("workflows.delete",n.endpoints.workflows.delete,{id:t},{method:"DELETE"})},async saveWorkflow(t){if(!!(t.id&&t.id.length>0))return this.updateWorkflow(t.id,t);{const{id:o,...r}=t;return this.createWorkflow(r)}}},d={nodes:s,workflows:w};export{d as api,a as getEndpointConfig,s as nodeApi,e as setEndpointConfig,w as workflowApi};
//# sourceMappingURL=flowdrop-api.js.map
