UNPKG

meta-cloud-api

Version:
2 lines 1.27 kB
import {d,c}from'./chunk-JPGXONBQ.js';function y(c$1){let d$1=new d(c$1);return {webhook:async(e,t)=>{try{if(e.method==="GET"){let{"hub.mode":s,"hub.verify_token":n,"hub.challenge":r}=e.query,o=await d$1.processVerification(s||null,n||null,r||null);return Object.entries(o.headers).forEach(([a,h])=>{t.setHeader(a,h);}),t.status(o.status).send(o.body)}if(e.method==="POST"){let s=c(e.headers,e.url),n=new Request(s,{method:e.method,headers:e.headers,body:JSON.stringify(e.body)}),r=await d$1.processWebhook(n);return Object.entries(r.headers).forEach(([o,a])=>{t.setHeader(o,a);}),t.status(r.status).send(r.body)}return t.status(405).json({error:"Method Not Allowed"})}catch(s){return console.error("Webhook error:",s),t.status(500).json({error:"Internal Server Error"})}},flow:async(e,t)=>{try{let s=c(e.headers,e.url),n=new Request(s,{method:e.method,headers:e.headers,body:e.method==="POST"?JSON.stringify(e.body):void 0}),r=await d$1.processFlow(n);return Object.entries(r.headers).forEach(([o,a])=>{t.setHeader(o,a);}),t.status(r.status).send(r.body)}catch(s){return console.error("Flow error:",s),t.status(500).json({error:"Internal Server Error"})}},processor:d$1}}export{y as a};//# sourceMappingURL=chunk-YXZ4L2OK.js.map //# sourceMappingURL=chunk-YXZ4L2OK.js.map