hubmail 1.0.7 → 1.0.9

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/README.md CHANGED
@@ -54,21 +54,18 @@ const options: SendEmailOptions = {
54
54
 
55
55
  ### Sending Emails
56
56
 
57
- Send a single email to one or multiple recipients.
57
+ Send a single email to one or multiple recipients. Supports both simple email strings and formatted addresses like `"Name <email@example.com>"` or objects `{ name: "Name", email: "email@example.com" }`.
58
58
 
59
59
  ```typescript
60
60
  try {
61
61
  const result = await hubmail.send({
62
- from: "sender@hubmail.space",
63
- to: ["recipient@example.com"],
62
+ from: "Acme <sender@hubmail.space>",
63
+ to: [{ name: "Recipient", email: "recipient@example.com" }],
64
64
  cc: ["manager@example.com"],
65
65
  bcc: ["archive@example.com"],
66
66
  subject: "Hello from HubMail",
67
67
  text: "This is a plain text email.",
68
68
  html: "<p>This is an <b>HTML</b> email.</p>",
69
- // Optional: Use a template
70
- // templateId: "tmpl_123456",
71
- // variables: { name: "Alice", orderId: "123" }
72
69
  });
73
70
 
74
71
  console.log("Email sent! ID:", result.id);
package/dist/index.d.ts CHANGED
@@ -1,14 +1,18 @@
1
+ export type Address = string | {
2
+ name?: string;
3
+ email: string;
4
+ };
1
5
  export interface SendEmailOptions {
2
- /** Sender email address (e.g., "sender@hubmail.space") */
3
- from: string;
6
+ /** Sender email address (e.g., "sender@hubmail.space" or "Acme <billing@hubfly.cloud>") */
7
+ from: Address;
4
8
  /** Primary recipient(s) */
5
- to: string | string[];
9
+ to: Address | Address[];
6
10
  /** Carbon copy recipient(s) */
7
- cc?: string | string[];
11
+ cc?: Address | Address[];
8
12
  /** Blind carbon copy recipient(s) */
9
- bcc?: string | string[];
13
+ bcc?: Address | Address[];
10
14
  /** Reply-to email address */
11
- replyTo?: string;
15
+ replyTo?: Address;
12
16
  /** Email subject line. Required if templateId is not provided. */
13
17
  subject?: string;
14
18
  /** Plain text version of the email */
@@ -28,7 +32,7 @@ export interface ScheduleEmailOptions {
28
32
  /** When the email should be sent (ISO string). Must be at least 5 min in future. */
29
33
  scheduledAt: string;
30
34
  /** Recipients. Required if mailbookId is not provided. */
31
- to?: string | string[];
35
+ to?: Address | Address[];
32
36
  /** Send to all contacts in this mailbook. */
33
37
  mailbookId?: string;
34
38
  /** Template to use for scheduling. */
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
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};
2
+ function L(j){if(typeof j==="string")return j;return j.name?`${j.name} <${j.email}>`:j.email}function J(j){if(Array.isArray(j))return j.map(L);return L(j)}class G extends Error{status;details;constructor(j,B,q){super(j);this.name="HubMailError",this.status=B,this.details=q}}class N{apiKey;baseUrl;constructor(j={}){let B=j.apiKey??process.env.HUBMAIL_KEY;if(!B)throw Error("HubMail API key is required. Provide it in the constructor or set the HUBMAIL_KEY environment variable.");this.apiKey=B,this.baseUrl=(j.baseUrl??"https://hubmail.space").replace(/\/$/,"")}async send(j){let B={...j,from:L(j.from),to:J(j.to),cc:j.cc?J(j.cc):void 0,bcc:j.bcc?J(j.bcc):void 0,replyTo:j.replyTo?L(j.replyTo):void 0},q=await fetch(`${this.baseUrl}/api/v1/send`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(B)}),C=await q.json();if(!q.ok){let F=C;throw new G(F.error||"Failed to send email",q.status,F.details)}return C}async schedule(j){let B={...j,to:j.to?J(j.to):void 0},q=await fetch(`${this.baseUrl}/api/v1/schedule`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(B)}),C=await q.json();if(!q.ok){let F=C;throw new G(F.error||"Failed to schedule email",q.status,F.details)}return C}async listMailbooks(){let j=await fetch(`${this.baseUrl}/api/v1/mailbooks`,{method:"GET",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}),B=await j.json();if(!j.ok){let q=B;throw new G(q.error||"Failed to list mailbooks",j.status,q.details)}return B}async listContacts(j){let B=await fetch(`${this.baseUrl}/api/v1/mailbooks/${j}/contacts`,{method:"GET",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"}}),q=await B.json();if(!B.ok){let C=q;throw new G(C.error||"Failed to list contacts",B.status,C.details)}return q}async addContact(j,B){let q=await fetch(`${this.baseUrl}/api/v1/mailbooks/${j}/contacts`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(B)}),C=await q.json();if(!q.ok){let F=C;throw new G(F.error||"Failed to add contact",q.status,F.details)}return C}}var P=N;export{P as default,G as HubMailError,N as HubMail};
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "main": "dist/index.js",
4
4
  "module": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
- "version": "1.0.7",
6
+ "version": "1.0.9",
7
7
  "type": "module",
8
8
  "files": [
9
9
  "dist"