@roadmapsh/scoop
Version:
NodeJS sdk for Scoop
2 lines (1 loc) • 3.41 kB
JavaScript
"use strict";var b=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames,m=Object.getOwnPropertySymbols;var l=Object.prototype.hasOwnProperty,f=Object.prototype.propertyIsEnumerable;var y=(t,s,e)=>s in t?b(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)&&y(t,e,s[e]);if(m)for(var e of m(s))f.call(s,e)&&y(t,e,s[e]);return t};var S=(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&&f.call(t,o)&&(e[o]=t[o]);return e};var q=(t,s)=>{for(var e in s)b(t,e,{get:s[e],enumerable:!0})},v=(t,s,e,o)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of E(s))!l.call(t,n)&&n!==e&&b(t,n,{get:()=>s[n],enumerable:!(o=O(s,n))||o.enumerable});return t};var w=t=>v(b({},"__esModule",{value:!0}),t);var r=(t,s,e)=>new Promise((o,n)=>{var u=a=>{try{p(e.next(a))}catch(h){n(h)}},i=a=>{try{p(e.throw(a))}catch(h){n(h)}},p=a=>a.done?o(a.value):Promise.resolve(a.value).then(u,i);p((e=e.apply(t,s)).next())});var A={};q(A,{Scoop:()=>g});module.exports=w(A);var T=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 d=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=S(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 R=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 P="https://scoop-api.roadmap.sh",g=class{constructor(s,e={endpoint:P}){this.key=s;this.config=e;this.subscribers=new d(this);this.emails=new R(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 T(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)})}};0&&(module.exports={Scoop});