UNPKG

meta-cloud-api

Version:
2 lines 2.99 kB
import {a,b as b$1}from'./chunk-VW3LGHTJ.js';var c="FlowAPI",w=false,p=new a(c,process.env.DEBUG==="true"||w),t=class extends b$1{constructor(o,e){super(o,e),p.log("FlowAPI initialized");}async listFlows(o){return this.sendJson("GET",`/${o}/flows`,this.config.REQUEST_TIMEOUT,null)}async createFlow(o,e){let s={name:e.name,categories:e.categories,...e.endpoint_uri&&{endpoint_uri:e.endpoint_uri},...e.clone_flow_id&&{clone_flow_id:e.clone_flow_id},...e.flow_json&&{flow_json:e.flow_json},...e.publish!==void 0&&{publish:e.publish}};return this.sendJson("POST",`/${o}/flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}async getFlow(o,e,s){let n=new URLSearchParams;e&&n.append("fields",e),s&&n.append("date_format",s);let r=n.toString()?`?${n.toString()}`:"";return this.sendJson("GET",`/${o}${r}`,this.config.REQUEST_TIMEOUT,null)}async getFlowPreview(o,e=false){let s=`preview.invalidate(${e})`;return this.getFlow(o,s)}async updateFlowMetadata(o,e){let s={...e.name&&{name:e.name},...e.categories&&{categories:e.categories},...e.endpoint_uri&&{endpoint_uri:e.endpoint_uri},...e.application_id&&{application_id:e.application_id}};return this.sendJson("POST",`/${o}`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}async deleteFlow(o){return this.sendJson("DELETE",`/${o}`,this.config.REQUEST_TIMEOUT,null)}async listAssets(o){return this.sendJson("GET",`/${o}/assets`,this.config.REQUEST_TIMEOUT,null)}async updateFlowJson(o,e){let s=new FormData,n;if(e.file instanceof Buffer)n=new globalThis.Blob([e.file]),s.append("file",n);else if(typeof e.file=="object"&&!(e.file instanceof Blob))try{n=new globalThis.Blob([JSON.stringify(e.file,null,2)],{type:"application/json"}),s.append("file",n);}catch{throw new Error("Failed to stringify JSON object for Flow JSON update.")}else if(e.file instanceof Blob)n=e.file,s.append("file",n);else throw new Error("Invalid file type provided for Flow JSON update. Must be a Buffer, JSON object, or Blob.");return s.append("asset_type","FLOW_JSON"),s.append("name",e.name||"flow.json"),this.sendFormData("POST",`/${o}/assets`,this.config.REQUEST_TIMEOUT,s)}async validateFlowJson(o,e){try{let s=await this.updateFlowJson(o,{file:e}),n=!s.validation_errors||s.validation_errors.length===0;return {...s,valid:n}}catch(s){throw p.error("Error during Flow JSON validation attempt:",s),s}}async publishFlow(o){return this.sendJson("POST",`/${o}/publish`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async deprecateFlow(o){return this.sendJson("POST",`/${o}/deprecate`,this.config.REQUEST_TIMEOUT,JSON.stringify({}))}async migrateFlows(o,e){let s={source_waba_id:e.source_waba_id,...e.source_flow_names&&{source_flow_names:e.source_flow_names}};return this.sendJson("POST",`/${o}/migrate_flows`,this.config.REQUEST_TIMEOUT,JSON.stringify(s))}};var i=(n=>(n.Ping="ping",n.Change="data_exchange",n.Error="error",n.All="*",n))(i||{});var b=t;export{t as a,i as b,b as c};//# sourceMappingURL=chunk-LGLRGXCE.js.map //# sourceMappingURL=chunk-LGLRGXCE.js.map