@topmail/sdk 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +141 -0
  2. package/package.json +5 -2
package/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # @topmail/sdk
2
+
3
+ Official TypeScript SDK for the [TopMail](https://topmail.so) API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @topmail/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { TopMail } from '@topmail/sdk';
15
+
16
+ const topmail = new TopMail('tm_live_your_api_key');
17
+
18
+ // Send an email
19
+ await topmail.email.send({
20
+ from_email: 'you@example.com',
21
+ to: 'recipient@example.com',
22
+ subject: 'Hello from TopMail',
23
+ html: '<h1>Welcome!</h1>',
24
+ });
25
+ ```
26
+
27
+ ## Resources
28
+
29
+ | Resource | Methods |
30
+ |----------|---------|
31
+ | `topmail.contacts` | `list` `get` `create` `update` `delete` |
32
+ | `topmail.lists` | `list` `get` `create` `update` `delete` |
33
+ | `topmail.lists.members` | `list` `add` `remove` |
34
+ | `topmail.email` | `send` `batch` `batchStatus` `messageStatus` |
35
+ | `topmail.campaigns` | `list` |
36
+ | `topmail.templates` | `list` |
37
+ | `topmail.tags` | `list` `get` `create` `update` `delete` |
38
+ | `topmail.tags.contacts` | `list` `add` `remove` |
39
+ | `topmail.segments` | `list` `get` `create` `update` `delete` `contacts` `estimate` |
40
+ | `topmail.automations` | `list` `get` `create` `update` `delete` `trigger` |
41
+ | `topmail.automations.steps` | `list` `get` `create` `update` `delete` |
42
+ | `topmail.automations.runs` | `list` `cancel` |
43
+ | `topmail.domains` | `list` `get` `create` `delete` `verify` |
44
+ | `topmail.suppressions` | `list` `add` `remove` |
45
+ | `topmail.webhooks` | `list` `create` `delete` |
46
+ | `topmail.tracking` | `productView` |
47
+ | `topmail.conversions` | `create` |
48
+ | `topmail.health` | `check` |
49
+
50
+ ## Examples
51
+
52
+ ### Contacts
53
+
54
+ ```typescript
55
+ // List contacts
56
+ const { data, pagination } = await topmail.contacts.list({ limit: 50 });
57
+
58
+ // Create a contact
59
+ const { data: contact } = await topmail.contacts.create({
60
+ email: 'jane@example.com',
61
+ first_name: 'Jane',
62
+ last_name: 'Doe',
63
+ });
64
+
65
+ // Update a contact
66
+ await topmail.contacts.update(contact.id, {
67
+ first_name: 'Janet',
68
+ });
69
+ ```
70
+
71
+ ### Lists
72
+
73
+ ```typescript
74
+ // Create a list
75
+ const { data: list } = await topmail.lists.create({
76
+ name: 'Newsletter Subscribers',
77
+ });
78
+
79
+ // Add contacts to a list
80
+ await topmail.lists.members.add(list.id, [contact.id]);
81
+ ```
82
+
83
+ ### Tags
84
+
85
+ ```typescript
86
+ // Create and apply a tag
87
+ const { data: tag } = await topmail.tags.create({ name: 'VIP' });
88
+ await topmail.tags.contacts.add(tag.id, [contact.id]);
89
+ ```
90
+
91
+ ### Automations
92
+
93
+ ```typescript
94
+ // Trigger an automation
95
+ await topmail.automations.trigger(automationId, {
96
+ contact_id: contact.id,
97
+ });
98
+ ```
99
+
100
+ ## Sandbox Mode
101
+
102
+ API keys starting with `tm_test_` activate sandbox mode. Check with:
103
+
104
+ ```typescript
105
+ const topmail = new TopMail('tm_test_your_key');
106
+ console.log(topmail.isSandbox); // true
107
+ ```
108
+
109
+ ## Error Handling
110
+
111
+ ```typescript
112
+ import { TopMail, TopMailError, RateLimitError } from '@topmail/sdk';
113
+
114
+ try {
115
+ await topmail.contacts.get('nonexistent');
116
+ } catch (err) {
117
+ if (err instanceof RateLimitError) {
118
+ console.log(`Rate limited. Retry after ${err.retryAfter}s`);
119
+ } else if (err instanceof TopMailError) {
120
+ console.log(err.message, err.code, err.statusCode);
121
+ }
122
+ }
123
+ ```
124
+
125
+ Error classes: `TopMailError`, `ValidationError`, `AuthenticationError`, `ForbiddenError`, `NotFoundError`, `RateLimitError`, `ServerError`.
126
+
127
+ ## Configuration
128
+
129
+ ```typescript
130
+ const topmail = new TopMail('tm_live_key', {
131
+ baseUrl: 'https://api.topmail.so/api', // default
132
+ });
133
+ ```
134
+
135
+ ## Requirements
136
+
137
+ - Node.js >= 18
138
+
139
+ ## License
140
+
141
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topmail/sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Official TypeScript SDK for the TopMail API",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -45,6 +45,9 @@
45
45
  "typescript": "^5.4.0",
46
46
  "vitest": "^2.0.0"
47
47
  },
48
- "files": ["dist"],
48
+ "files": [
49
+ "dist",
50
+ "README.md"
51
+ ],
49
52
  "license": "MIT"
50
53
  }