hubmail 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
class C extends Error{status;details;constructor(
|
|
2
|
+
class C extends Error{status;details;constructor(z,j,q){super(z);this.name="HubMailError",this.status=j,this.details=q}}class G{apiKey;baseUrl;constructor(z={}){let j=z.apiKey??process.env.HUBMAIL_KEY;if(!j)throw Error("HubMail API key is required. Provide it in the constructor or set the HUBMAIL_KEY environment variable.");this.apiKey=j,this.baseUrl=(z.baseUrl??"https://hubmail.space").replace(/\/$/,"")}async send(z){let j=await fetch(`${this.baseUrl}/api/v1/send`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(z)}),q=await j.json();if(!j.ok){let B=q;throw new C(B.error||"Failed to send email",j.status,B.details)}return q}async schedule(z){let j=await fetch(`${this.baseUrl}/api/v1/schedule`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(z)}),q=await j.json();if(!j.ok){let B=q;throw new C(B.error||"Failed to schedule email",j.status,B.details)}return q}async listMailbooks(){let z=await fetch(`${this.baseUrl}/api/v1/mailbooks`,{method:"GET",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}),j=await z.json();if(!z.ok){let q=j;throw new C(q.error||"Failed to list mailbooks",z.status,q.details)}return j}async listContacts(z){let j=await fetch(`${this.baseUrl}/api/v1/mailbooks/${z}/contacts`,{method:"GET",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}),q=await j.json();if(!j.ok){let B=q;throw new C(B.error||"Failed to list contacts",j.status,B.details)}return q}async addContact(z,j){let q=await fetch(`${this.baseUrl}/api/v1/mailbooks/${z}/contacts`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(j)}),B=await q.json();if(!q.ok){let F=B;throw new C(F.error||"Failed to add contact",q.status,F.details)}return B}}var L=G;export{L as default,C as HubMailError,G as HubMail};
|