UNPKG

@roadmapsh/scoop

Version:
2 lines (1 loc) 3 kB
var T=Object.defineProperty;var m=Object.getOwnPropertySymbols;var l=Object.prototype.hasOwnProperty,g=Object.prototype.propertyIsEnumerable;var h=(t,s,e)=>s in t?T(t,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[s]=e,c=(t,s)=>{for(var e in s||(s={}))l.call(s,e)&&h(t,e,s[e]);if(m)for(var e of m(s))g.call(s,e)&&h(t,e,s[e]);return t};var y=(t,s)=>{var e={};for(var o in t)l.call(t,o)&&s.indexOf(o)<0&&(e[o]=t[o]);if(t!=null&&m)for(var o of m(t))s.indexOf(o)<0&&g.call(t,o)&&(e[o]=t[o]);return e};var r=(t,s,e)=>new Promise((o,n)=>{var u=a=>{try{p(e.next(a))}catch(R){n(R)}},i=a=>{try{p(e.throw(a))}catch(R){n(R)}},p=a=>a.done?o(a.value):Promise.resolve(a.value).then(u,i);p((e=e.apply(t,s)).next())});var f=t=>{if(typeof t!="object"||t===null)return!1;let s=t;if(typeof s!="object"||s===null)return!1;let{message:e,status:o}=s;return typeof e=="string"&&typeof o=="number"};var b=class{constructor(s){this.scoop=s}assignTags(o){return r(this,arguments,function*(s,e={}){return yield this.scoop.patch("/v1-assign-tags",s,e)})}removeTags(o){return r(this,arguments,function*(s,e={}){return yield this.scoop.patch("/v1-remove-tags",s,e)})}subscribe(o){return r(this,arguments,function*(s,e={}){let p=s,{listId:n}=p,u=y(p,["listId"]);return yield this.scoop.post(`/v1-subscribe/${n}`,u,e)})}unsubscribe(o){return r(this,arguments,function*(s,e={}){return yield this.scoop.patch("/v1-unsubscribe-by-email",s,e)})}deleteByEmail(o){return r(this,arguments,function*(s,e={}){return yield this.scoop.patch("/v1-delete-subscriber-by-email",s,e)})}};var d=class{constructor(s){this.scoop=s}send(o){return r(this,arguments,function*(s,e={}){return yield this.scoop.post("/v1-send-email",s,e)})}};var O="https://scoop-api.roadmap.sh",S=class{constructor(s,e={endpoint:O}){this.key=s;this.config=e;this.subscribers=new b(this);this.emails=new d(this);if(!s)throw new Error("Missing API key. Please provide an API key.");this.headers=new Headers({"Content-Type":"application/json","X-Scoop-Api-Key":s})}fetchRequest(o){return r(this,arguments,function*(s,e={}){let n=yield fetch(`${this.config.endpoint}${s}`,e);if(!n.ok){let i=yield n.json();return f(i)?{data:null,error:i}:{data:null,error:i}}return{data:yield n.json(),error:null}})}post(n,u){return r(this,arguments,function*(s,e,o={}){let i=c({method:"POST",headers:this.headers,body:JSON.stringify(e)},o);return this.fetchRequest(s,i)})}get(o){return r(this,arguments,function*(s,e={}){let n=c({method:"GET",headers:this.headers},e);return this.fetchRequest(s,n)})}put(n,u){return r(this,arguments,function*(s,e,o={}){let i=c({method:"PUT",headers:this.headers,body:JSON.stringify(e)},o);return this.fetchRequest(s,i)})}patch(n,u){return r(this,arguments,function*(s,e,o={}){let i=c({method:"PATCH",headers:this.headers,body:JSON.stringify(e)},o);return this.fetchRequest(s,i)})}delete(s,e){return r(this,null,function*(){let o={method:"DELETE",headers:this.headers,body:JSON.stringify(e)};return this.fetchRequest(s,o)})}};export{S as Scoop};