@develemail/sdk 0.1.0 → 0.4.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/README.md ADDED
@@ -0,0 +1,157 @@
1
+ # @develemail/sdk
2
+
3
+ Node.js/TypeScript client SDK for the DevelEmail transactional email API. Zero runtime dependencies — uses the global `fetch` API (Node >= 18).
4
+
5
+ ## Quickstart
6
+
7
+ ```ts
8
+ import { DevelEmail } from '@develemail/sdk';
9
+
10
+ const client = new DevelEmail({
11
+ apiKey: 'your-api-key',
12
+ baseUrl: 'https://your-develemail-instance.com',
13
+ });
14
+
15
+ // Send an email
16
+ const { id, status } = await client.emails.send({
17
+ from: 'hello@yourdomain.com',
18
+ to: 'user@example.com',
19
+ subject: 'Welcome!',
20
+ html: '<h1>Hello!</h1>',
21
+ });
22
+
23
+ // Check delivery status
24
+ const email = await client.emails.get(id);
25
+ console.log(email.status); // 'queued' | 'delivered' | ...
26
+ ```
27
+
28
+ ## Batch send
29
+
30
+ ```ts
31
+ const result = await client.emails.batch([
32
+ {
33
+ from: 'hello@yourdomain.com',
34
+ to: 'a@example.com',
35
+ subject: 'Hi',
36
+ text: 'Hello A',
37
+ },
38
+ {
39
+ from: 'hello@yourdomain.com',
40
+ to: 'b@example.com',
41
+ subject: 'Hi',
42
+ text: 'Hello B',
43
+ },
44
+ ]);
45
+
46
+ console.log(result.created); // 2
47
+ console.log(result.errors); // 0
48
+ ```
49
+
50
+ ## Attachments
51
+
52
+ Pass a `Buffer`/`Uint8Array` for `content` and the SDK base64-encodes it for
53
+ you — or pass an already-base64 `string` directly. Server caps: max 10
54
+ attachments per email, 5 MiB per file, 7 MiB combined decoded size.
55
+
56
+ ```ts
57
+ import { readFile } from 'node:fs/promises';
58
+
59
+ const csv = await readFile('export.csv');
60
+
61
+ await client.emails.send({
62
+ from: 'hello@yourdomain.com',
63
+ to: 'user@example.com',
64
+ subject: 'Your export is ready',
65
+ text: 'Attached: export.csv',
66
+ attachments: [
67
+ { filename: 'export.csv', content: csv, contentType: 'text/csv' },
68
+ ],
69
+ });
70
+ ```
71
+
72
+ ## Automatic retry + idempotency
73
+
74
+ Sends automatically retry on network errors, 5xx, and 429 responses with exponential backoff. Each send generates a unique `Idempotency-Key` header so retries never produce duplicate emails.
75
+
76
+ ```ts
77
+ // Custom retry count (default: 3)
78
+ const client = new DevelEmail({
79
+ apiKey: 'your-api-key',
80
+ baseUrl: 'https://your-instance.com',
81
+ maxRetries: 5,
82
+ });
83
+
84
+ // Supply your own idempotency key
85
+ await client.emails.send(
86
+ {
87
+ from: 'hello@yourdomain.com',
88
+ to: 'user@example.com',
89
+ subject: 'Hi',
90
+ text: 'Hello',
91
+ },
92
+ { idempotencyKey: 'order-confirmation-12345' },
93
+ );
94
+ ```
95
+
96
+ ## Error handling
97
+
98
+ ```ts
99
+ import { DevelEmail, DevelEmailError } from '@develemail/sdk';
100
+
101
+ try {
102
+ await client.emails.send({ ... });
103
+ } catch (err) {
104
+ if (err instanceof DevelEmailError) {
105
+ console.log(err.status); // HTTP status code
106
+ console.log(err.code); // 'quota_exceeded', 'domain_not_verified', etc.
107
+ console.log(err.message); // Human-readable message
108
+ }
109
+ }
110
+ ```
111
+
112
+ ## Domains & Templates
113
+
114
+ ```ts
115
+ const domains = await client.domains.list();
116
+ const domain = await client.domains.get('domain-id');
117
+
118
+ const templates = await client.templates.list();
119
+ const template = await client.templates.get('template-id');
120
+ ```
121
+
122
+ ## SMS
123
+
124
+ ```ts
125
+ const { id, status } = await client.sms.send({
126
+ to: '+15551234567',
127
+ from: '+15557654321',
128
+ body: 'Your order has shipped!',
129
+ });
130
+
131
+ // Or render an SMS template (created via the API) server-side
132
+ await client.sms.send({
133
+ to: '+15551234567',
134
+ templateName: 'otp-code',
135
+ variables: { code: '482913' },
136
+ });
137
+
138
+ const message = await client.sms.get(id);
139
+ console.log(message.status); // 'queued' | 'delivered' | ...
140
+
141
+ const { data, nextCursor } = await client.sms.list({
142
+ status: 'delivered',
143
+ limit: 25,
144
+ });
145
+ ```
146
+
147
+ ## Webhook verification
148
+
149
+ ```ts
150
+ import { verifyWebhookSignature } from '@develemail/sdk';
151
+
152
+ const valid = await verifyWebhookSignature(
153
+ rawBody,
154
+ signatureHeader,
155
+ webhookSecret,
156
+ );
157
+ ```