shipmail 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 ShipMail
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,223 @@
1
+ # ShipMail TypeScript SDK
2
+
3
+ Official TypeScript SDK for the [ShipMail](https://shipmail.to) API. Zero runtime dependencies.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install shipmail
9
+ # or
10
+ bun add shipmail
11
+ ```
12
+
13
+ Requires Node.js 18+ (uses native `fetch` and `crypto`).
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import ShipMail from "shipmail";
19
+
20
+ const client = new ShipMail("sm_live_...");
21
+
22
+ // Create a domain
23
+ const domain = await client.domains.create({ name: "example.com" });
24
+
25
+ // Send an email
26
+ const message = await client.messages.send({
27
+ mailbox_id: "mbx_...",
28
+ to: [{ address: "user@example.com" }],
29
+ subject: "Hello",
30
+ body_text: "Hi there",
31
+ });
32
+ ```
33
+
34
+ ## Configuration
35
+
36
+ ```typescript
37
+ import { ShipMailClient } from "shipmail";
38
+
39
+ const client = new ShipMailClient({
40
+ apiKey: "sm_live_...",
41
+ baseUrl: "https://api.shipmail.to/v1", // default
42
+ maxRetries: 2, // default, retries on 5xx and 429
43
+ timeout: 30_000, // default, in milliseconds
44
+ });
45
+ ```
46
+
47
+ ## Resources
48
+
49
+ ### Domains
50
+
51
+ ```typescript
52
+ const domain = await client.domains.create({ name: "example.com" });
53
+ const domains = await client.domains.list({ limit: 10 });
54
+ const domain = await client.domains.get("dom_...");
55
+ const updated = await client.domains.update("dom_...", { catch_all_mailbox_id: "mbx_..." });
56
+ await client.domains.delete("dom_...");
57
+ const result = await client.domains.verify("dom_...");
58
+ ```
59
+
60
+ ### Mailboxes
61
+
62
+ ```typescript
63
+ const mailbox = await client.mailboxes.create({
64
+ domain_id: "dom_...",
65
+ address: "hello",
66
+ display_name: "Hello",
67
+ });
68
+ const mailboxes = await client.mailboxes.list({ domain_id: "dom_..." });
69
+ const mailbox = await client.mailboxes.get("mbx_...");
70
+ const updated = await client.mailboxes.update("mbx_...", { display_name: "New Name" });
71
+ await client.mailboxes.delete("mbx_...");
72
+
73
+ // Avatar
74
+ const avatar = await client.mailboxes.uploadAvatar("mbx_...", imageBuffer, "image/png");
75
+ await client.mailboxes.deleteAvatar("mbx_...");
76
+ ```
77
+
78
+ ### Messages
79
+
80
+ ```typescript
81
+ const message = await client.messages.send({
82
+ mailbox_id: "mbx_...",
83
+ to: [{ address: "user@example.com", name: "User" }],
84
+ cc: [{ address: "cc@example.com" }],
85
+ subject: "Hello",
86
+ body_html: "<p>Hi there</p>",
87
+ body_text: "Hi there",
88
+ });
89
+
90
+ const message = await client.messages.get("msg_...");
91
+ ```
92
+
93
+ ### Threads
94
+
95
+ ```typescript
96
+ const threads = await client.threads.list({ mailbox_id: "mbx_..." });
97
+ const thread = await client.threads.get("thd_...");
98
+ const reply = await client.threads.reply("thd_...", {
99
+ body_text: "Thanks for your email",
100
+ to: [{ address: "user@example.com" }],
101
+ });
102
+ ```
103
+
104
+ ### Webhooks
105
+
106
+ ```typescript
107
+ const webhook = await client.webhooks.create({
108
+ url: "https://example.com/webhook",
109
+ events: ["message.received", "message.sent"],
110
+ description: "My webhook",
111
+ });
112
+ // webhook.secret is only available at creation time
113
+
114
+ const webhooks = await client.webhooks.list();
115
+ const webhook = await client.webhooks.get("whk_...");
116
+ const updated = await client.webhooks.update("whk_...", { active: false });
117
+ await client.webhooks.delete("whk_...");
118
+
119
+ const rotated = await client.webhooks.rotateSecret("whk_...");
120
+ const test = await client.webhooks.test("whk_...");
121
+ const deliveries = await client.webhooks.listDeliveries("whk_...");
122
+ ```
123
+
124
+ ### Status
125
+
126
+ ```typescript
127
+ const status = await client.status.get();
128
+ ```
129
+
130
+ ## Pagination
131
+
132
+ List methods return a paginated response with cursor-based pagination:
133
+
134
+ ```typescript
135
+ const page = await client.domains.list({ limit: 10 });
136
+ console.log(page.data); // Domain[]
137
+ console.log(page.pagination); // { next_cursor, has_more }
138
+
139
+ // Fetch next page
140
+ if (page.pagination.has_more) {
141
+ const next = await client.domains.list({
142
+ cursor: page.pagination.next_cursor,
143
+ limit: 10,
144
+ });
145
+ }
146
+ ```
147
+
148
+ Auto-pagination iterates through all pages automatically:
149
+
150
+ ```typescript
151
+ for await (const domain of client.domains.listAutoPaginating({ limit: 25 })) {
152
+ console.log(domain.name);
153
+ }
154
+ ```
155
+
156
+ ## Webhook Verification
157
+
158
+ Verify incoming webhook signatures without instantiating a client:
159
+
160
+ ```typescript
161
+ import { verifyWebhook, WebhookVerificationError } from "shipmail";
162
+
163
+ try {
164
+ const event = verifyWebhook(rawBody, request.headers, webhookSecret);
165
+ console.log(event.event_type); // e.g., "message.received"
166
+ console.log(event.data);
167
+ } catch (err) {
168
+ if (err instanceof WebhookVerificationError) {
169
+ return new Response("Invalid signature", { status: 401 });
170
+ }
171
+ }
172
+ ```
173
+
174
+ ## Error Handling
175
+
176
+ The SDK throws typed errors that map to API error responses:
177
+
178
+ ```typescript
179
+ import {
180
+ ShipMailError,
181
+ AuthenticationError,
182
+ AuthorizationError,
183
+ ValidationError,
184
+ NotFoundError,
185
+ RateLimitError,
186
+ ConflictError,
187
+ InternalServerError,
188
+ ConnectionError,
189
+ } from "shipmail";
190
+
191
+ try {
192
+ await client.domains.create({ name: "" });
193
+ } catch (err) {
194
+ if (err instanceof ValidationError) {
195
+ console.log(err.message); // Error message
196
+ console.log(err.details); // Field-level validation errors
197
+ }
198
+ if (err instanceof RateLimitError) {
199
+ console.log(err.retryAfter); // Seconds to wait
200
+ }
201
+ if (err instanceof ShipMailError) {
202
+ console.log(err.status); // HTTP status code
203
+ console.log(err.type); // Error type string
204
+ console.log(err.requestId); // Request ID for support
205
+ console.log(err.retryable); // Whether the request can be retried
206
+ }
207
+ }
208
+ ```
209
+
210
+ ## Retries
211
+
212
+ The SDK automatically retries on 5xx errors and 429 (rate limit) responses with exponential backoff and jitter. Configure with `maxRetries` (default: 2, meaning up to 3 total attempts).
213
+
214
+ ```typescript
215
+ const client = new ShipMailClient({
216
+ apiKey: "sm_live_...",
217
+ maxRetries: 0, // Disable retries
218
+ });
219
+ ```
220
+
221
+ ## License
222
+
223
+ MIT