hubmail 1.0.2 → 1.0.4

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
@@ -1,15 +1,60 @@
1
- # hubmail
1
+ # HubMail SDK
2
2
 
3
- To install dependencies:
3
+ A TypeScript-friendly SDK for sending emails via the HubMail API.
4
+
5
+ ## Installation
4
6
 
5
7
  ```bash
6
- bun install
8
+ bun add hubmail
9
+ # or
10
+ npm install hubmail
7
11
  ```
8
12
 
9
- To run:
13
+ ## Usage
14
+
15
+ ### 1. Set up your API key
16
+ The SDK will automatically look for `HUBMAIL_KEY` in your environment variables.
10
17
 
11
18
  ```bash
12
- bun run index.ts
19
+ # .env
20
+ HUBMAIL_KEY=hm_your_api_key_here
13
21
  ```
14
22
 
15
- This project was created using `bun init` in bun v1.2.22. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
23
+ ### 2. Send an email
24
+
25
+ ```typescript
26
+ import { HubMail } from "hubmail";
27
+
28
+ const hubmail = new HubMail();
29
+
30
+ try {
31
+ const result = await hubmail.send({
32
+ from: "you@hubmail.space",
33
+ to: ["friend@example.com"],
34
+ subject: "Hello from HubMail",
35
+ text: "This is a test email.",
36
+ html: "<b>This is a test email.</b>",
37
+ });
38
+
39
+ console.log("Email sent! ID:", result.id);
40
+ } catch (error) {
41
+ console.error("Failed to send email:", error.message);
42
+ }
43
+ ```
44
+
45
+ ### Configuration Options
46
+
47
+ You can also pass configuration directly to the constructor:
48
+
49
+ ```typescript
50
+ const hubmail = new HubMail({
51
+ apiKey: "hm_custom_key",
52
+ });
53
+ ```
54
+
55
+ ## Features
56
+
57
+ - **TypeScript Friendly**: Full type support for all request and response structures.
58
+ - **Flexible Recipients**: Support for single or multiple recipients (To, CC, BCC).
59
+ - **Environment Driven**: Automatic detection of API keys from environment variables.
60
+ - **Bun Native**: Built for high performance with Bun and standard Web APIs.
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  // @bun
2
- console.log("Hello via Bun!");
2
+ class C extends Error{status;details;constructor(x,k,z){super(x);this.name="HubMailError",this.status=k,this.details=z}}class F{apiKey;baseUrl;constructor(x={}){let k=x.apiKey??process.env.HUBMAIL_KEY;if(!k)throw Error("HubMail API key is required. Provide it in the constructor or set the HUBMAIL_KEY environment variable.");this.apiKey=k,this.baseUrl=(x.baseUrl??"https://hubmail.space").replace(/\/$/,"")}async send(x){let k=await fetch(`${this.baseUrl}/api/v1/send`,{method:"POST",headers:{Authorization:`Bearer ${this.apiKey}`,"Content-Type":"application/json"},body:JSON.stringify(x)}),z=await k.json();if(!k.ok){let B=z;throw new C(B.error||"Failed to send email",k.status,B.details)}return z}}var J=F;export{J as default,C as HubMailError,F as HubMail};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "hubmail",
3
3
  "module": "index.ts",
4
- "version": "1.0.2",
4
+ "version": "1.0.4",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"