keplars 1.0.3
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 +227 -0
- package/dist/cjs/audiences.js +32 -0
- package/dist/cjs/audiences.js.map +1 -0
- package/dist/cjs/automations.js +32 -0
- package/dist/cjs/automations.js.map +1 -0
- package/dist/cjs/client.js +135 -0
- package/dist/cjs/client.js.map +1 -0
- package/dist/cjs/contacts.js +38 -0
- package/dist/cjs/contacts.js.map +1 -0
- package/dist/cjs/domains.js +34 -0
- package/dist/cjs/domains.js.map +1 -0
- package/dist/cjs/emails.js +101 -0
- package/dist/cjs/emails.js.map +1 -0
- package/dist/cjs/errors.js +87 -0
- package/dist/cjs/errors.js.map +1 -0
- package/dist/cjs/index.js +35 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.js +87 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/audiences.js +28 -0
- package/dist/esm/audiences.js.map +1 -0
- package/dist/esm/automations.js +28 -0
- package/dist/esm/automations.js.map +1 -0
- package/dist/esm/client.js +131 -0
- package/dist/esm/client.js.map +1 -0
- package/dist/esm/contacts.js +34 -0
- package/dist/esm/contacts.js.map +1 -0
- package/dist/esm/domains.js +30 -0
- package/dist/esm/domains.js.map +1 -0
- package/dist/esm/emails.js +97 -0
- package/dist/esm/emails.js.map +1 -0
- package/dist/esm/errors.js +72 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.js +76 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/audiences.d.ts +11 -0
- package/dist/types/audiences.d.ts.map +1 -0
- package/dist/types/automations.d.ts +11 -0
- package/dist/types/automations.d.ts.map +1 -0
- package/dist/types/client.d.ts +24 -0
- package/dist/types/client.d.ts.map +1 -0
- package/dist/types/contacts.d.ts +12 -0
- package/dist/types/contacts.d.ts.map +1 -0
- package/dist/types/domains.d.ts +22 -0
- package/dist/types/domains.d.ts.map +1 -0
- package/dist/types/emails.d.ts +16 -0
- package/dist/types/emails.d.ts.map +1 -0
- package/dist/types/errors.d.ts +48 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/types.d.ts +162 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +10 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +73 -0
package/README.md
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
# Keplars Email SDK for JavaScript/TypeScript
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript SDK for the Keplars Email API - modern transactional email service with priority-based delivery.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install keplars
|
|
9
|
+
# or
|
|
10
|
+
yarn add keplars
|
|
11
|
+
# or
|
|
12
|
+
bun add keplars
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { Keplars } from 'keplars';
|
|
19
|
+
|
|
20
|
+
const client = new Keplars({
|
|
21
|
+
apiKey: 'kms_<workspaceId>.live_<secret>'
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const response = await client.emails.sendInstant({
|
|
25
|
+
from: 'noreply@yourdomain.com',
|
|
26
|
+
to: 'user@example.com',
|
|
27
|
+
subject: 'Your verification code is 123456',
|
|
28
|
+
html: '<p>Your verification code is <strong>123456</strong></p>'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log('Job ID:', response.data.job_id);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Configuration
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
const client = new Keplars({
|
|
38
|
+
apiKey: 'your-api-key',
|
|
39
|
+
baseUrl: 'https://custom.api',
|
|
40
|
+
timeout: 30000,
|
|
41
|
+
maxRetries: 3,
|
|
42
|
+
retryDelay: 1000
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Environment Variables
|
|
47
|
+
|
|
48
|
+
- `KEPLARS_API_KEY` - Your API key
|
|
49
|
+
- `KEPLARS_BASE_URL` - Custom API base URL
|
|
50
|
+
|
|
51
|
+
### API Key Types
|
|
52
|
+
|
|
53
|
+
| Type | Format | Used for |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| Regular | `kms_<id>.live_<secret>` | Email sending |
|
|
56
|
+
| Admin | `kms_<id>.adm_<secret>` | Contacts, audiences, automations, domains |
|
|
57
|
+
|
|
58
|
+
## Email Sending
|
|
59
|
+
|
|
60
|
+
### Priority Levels
|
|
61
|
+
|
|
62
|
+
| Method | Delivery | Use case |
|
|
63
|
+
|---|---|---|
|
|
64
|
+
| `sendInstant` | 0–5 sec | OTPs, login codes, critical alerts |
|
|
65
|
+
| `sendHigh` | 0–30 sec | Transactional, notifications |
|
|
66
|
+
| `sendAsync` / `send` | 0–5 min | General transactional |
|
|
67
|
+
| `sendBulk` | Idle | Newsletters, marketing |
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
const response = await client.emails.sendInstant({
|
|
71
|
+
from: 'noreply@yourdomain.com',
|
|
72
|
+
to: [{ email: 'user@example.com', name: 'John Doe' }],
|
|
73
|
+
subject: 'Welcome!',
|
|
74
|
+
html: '<h1>Welcome aboard</h1>'
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
console.log(response.data.job_id);
|
|
78
|
+
console.log(response.data.priority);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Request Fields
|
|
82
|
+
|
|
83
|
+
| Field | Type | Required | Description |
|
|
84
|
+
|---|---|---|---|
|
|
85
|
+
| `to` | `string \| EmailRecipient[]` | Yes | Recipient(s) |
|
|
86
|
+
| `from` | `string` | Yes | Sender email |
|
|
87
|
+
| `subject` | `string` | Yes | Email subject |
|
|
88
|
+
| `html` | `string` | One of | HTML body |
|
|
89
|
+
| `text` | `string` | One of | Plain text body |
|
|
90
|
+
| `template_id` | `string` | One of | Template ID |
|
|
91
|
+
| `template_data` | `object` | No | Template variables |
|
|
92
|
+
| `cc` | `EmailRecipient[]` | No | CC recipients |
|
|
93
|
+
| `bcc` | `EmailRecipient[]` | No | BCC recipients |
|
|
94
|
+
| `reply_to` | `string` | No | Reply-to address |
|
|
95
|
+
| `custom_headers` | `object` | No | Custom email headers |
|
|
96
|
+
|
|
97
|
+
### Response Shape
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
{
|
|
101
|
+
success: true,
|
|
102
|
+
message: 'Email queued',
|
|
103
|
+
data: {
|
|
104
|
+
job_id: 'job_abc123',
|
|
105
|
+
priority: 'instant'
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Send with Template
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
const response = await client.emails.send({
|
|
114
|
+
from: 'noreply@yourdomain.com',
|
|
115
|
+
to: 'user@example.com',
|
|
116
|
+
subject: 'Password Reset',
|
|
117
|
+
template_id: 'tpl_reset_password',
|
|
118
|
+
template_data: {
|
|
119
|
+
name: 'John',
|
|
120
|
+
reset_link: 'https://example.com/reset/token123'
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Schedule Email
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
const response = await client.emails.schedule({
|
|
129
|
+
from: 'newsletter@yourdomain.com',
|
|
130
|
+
to: 'user@example.com',
|
|
131
|
+
subject: 'Your weekly digest',
|
|
132
|
+
html: '<p>Here is your weekly digest...</p>',
|
|
133
|
+
scheduled_for: '2026-06-01T09:00:00Z',
|
|
134
|
+
priority: 'bulk'
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Contacts (Admin API Key Required)
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
const adminClient = new Keplars({
|
|
142
|
+
apiKey: 'kms_<workspaceId>.adm_<secret>'
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await adminClient.contacts.add({
|
|
146
|
+
email: 'user@example.com',
|
|
147
|
+
name: 'John Doe',
|
|
148
|
+
audience_id: 'aud_abc123'
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const contact = await adminClient.contacts.get('user@example.com');
|
|
152
|
+
|
|
153
|
+
const contacts = await adminClient.contacts.list('aud_abc123', 1, 20);
|
|
154
|
+
|
|
155
|
+
await adminClient.contacts.update('user@example.com', { name: 'Jane Doe' });
|
|
156
|
+
|
|
157
|
+
await adminClient.contacts.delete('user@example.com');
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Audiences (Admin API Key Required)
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
const audience = await adminClient.audiences.create('Newsletter Subscribers', 'Main newsletter list');
|
|
164
|
+
|
|
165
|
+
const audiences = await adminClient.audiences.list(1, 20);
|
|
166
|
+
|
|
167
|
+
const audience = await adminClient.audiences.get('aud_abc123');
|
|
168
|
+
|
|
169
|
+
await adminClient.audiences.delete('aud_abc123');
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Automations (Admin API Key Required)
|
|
173
|
+
|
|
174
|
+
```typescript
|
|
175
|
+
const automations = await adminClient.automations.list();
|
|
176
|
+
|
|
177
|
+
const automation = await adminClient.automations.get('auto_abc123');
|
|
178
|
+
|
|
179
|
+
await adminClient.automations.enroll('auto_abc123', 'user@example.com');
|
|
180
|
+
|
|
181
|
+
await adminClient.automations.unenroll('auto_abc123', 'user@example.com');
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Domains (Admin API Key Required)
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
const domain = await adminClient.domains.add('mail.yourcompany.com');
|
|
188
|
+
|
|
189
|
+
const domains = await adminClient.domains.list();
|
|
190
|
+
|
|
191
|
+
const status = await adminClient.domains.getStatus('dom_abc123');
|
|
192
|
+
|
|
193
|
+
const result = await adminClient.domains.verify('dom_abc123');
|
|
194
|
+
|
|
195
|
+
const apiKey = await adminClient.domains.createApiKey({ domain_id: 'dom_abc123', name: 'Production Key' });
|
|
196
|
+
|
|
197
|
+
await adminClient.domains.delete('dom_abc123');
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Error Handling
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { Keplars, AuthenticationError, RateLimitError } from 'keplars';
|
|
204
|
+
|
|
205
|
+
try {
|
|
206
|
+
const response = await client.emails.sendInstant({ ... });
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (error instanceof AuthenticationError) {
|
|
209
|
+
console.error('Invalid API key');
|
|
210
|
+
} else if (error instanceof RateLimitError) {
|
|
211
|
+
console.error('Rate limited, retry after:', error.retryAfter);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## TypeScript Types
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
import type {
|
|
220
|
+
EmailRecipient,
|
|
221
|
+
SendEmailRequest,
|
|
222
|
+
SendEmailResponse,
|
|
223
|
+
Contact,
|
|
224
|
+
Audience,
|
|
225
|
+
Automation,
|
|
226
|
+
} from 'keplars';
|
|
227
|
+
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Audiences = void 0;
|
|
4
|
+
class Audiences {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async create(name, description) {
|
|
9
|
+
const { data } = await this.client.request('POST', '/api/v1/public/audiences/add-audience', { name, description });
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
async list(page, limit) {
|
|
13
|
+
const params = new URLSearchParams();
|
|
14
|
+
if (page)
|
|
15
|
+
params.append('page', page.toString());
|
|
16
|
+
if (limit)
|
|
17
|
+
params.append('limit', limit.toString());
|
|
18
|
+
const query = params.toString() ? `?${params.toString()}` : '';
|
|
19
|
+
const { data } = await this.client.request('GET', `/api/v1/public/audiences/get-audiences${query}`);
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
async get(id) {
|
|
23
|
+
const { data } = await this.client.request('GET', `/api/v1/public/audiences/get-audience?id=${encodeURIComponent(id)}`);
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
async delete(id) {
|
|
27
|
+
const { data } = await this.client.request('DELETE', `/api/v1/public/audiences/delete-audience?id=${encodeURIComponent(id)}`);
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Audiences = Audiences;
|
|
32
|
+
//# sourceMappingURL=audiences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audiences.js","sourceRoot":"","sources":["../../src/audiences.ts"],"names":[],"mappings":";;;AASA,MAAa,SAAS;IACpB,YAA6B,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAEhD,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,WAAoB;QAC7C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,MAAM,EACN,uCAAuC,EACvC,EAAE,IAAI,EAAE,WAAW,EAAE,CACtB,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,IAAa,EAAE,KAAc;QACtC,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,IAAI;YAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjD,IAAI,KAAK;YAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAE/D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,KAAK,EACL,yCAAyC,KAAK,EAAE,CACjD,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,KAAK,EACL,4CAA4C,kBAAkB,CAAC,EAAE,CAAC,EAAE,CACrE,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU;QACrB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,QAAQ,EACR,+CAA+C,kBAAkB,CAAC,EAAE,CAAC,EAAE,CACxE,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAxCD,8BAwCC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Automations = void 0;
|
|
4
|
+
class Automations {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async list(page, limit) {
|
|
9
|
+
const params = new URLSearchParams();
|
|
10
|
+
if (page)
|
|
11
|
+
params.append('page', page.toString());
|
|
12
|
+
if (limit)
|
|
13
|
+
params.append('limit', limit.toString());
|
|
14
|
+
const query = params.toString() ? `?${params.toString()}` : '';
|
|
15
|
+
const { data } = await this.client.request('GET', `/api/v1/public/automations/get-all${query}`);
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
async get(id) {
|
|
19
|
+
const { data } = await this.client.request('GET', `/api/v1/public/automations/get-automation/${encodeURIComponent(id)}`);
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
async enroll(id, email) {
|
|
23
|
+
const { data } = await this.client.request('POST', `/api/v1/public/automations/add-automation/${encodeURIComponent(id)}/enroll`, { email });
|
|
24
|
+
return data;
|
|
25
|
+
}
|
|
26
|
+
async unenroll(id, email) {
|
|
27
|
+
const { data } = await this.client.request('DELETE', `/api/v1/public/automations/delete-automation/${encodeURIComponent(id)}/subscribers`, { email });
|
|
28
|
+
return data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.Automations = Automations;
|
|
32
|
+
//# sourceMappingURL=automations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"automations.js","sourceRoot":"","sources":["../../src/automations.ts"],"names":[],"mappings":";;;AAGA,MAAa,WAAW;IACtB,YAA6B,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAEhD,KAAK,CAAC,IAAI,CAAC,IAAa,EAAE,KAAc;QACtC,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;QACrC,IAAI,IAAI;YAAE,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjD,IAAI,KAAK;YAAE,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;QACpD,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAE/D,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,KAAK,EACL,qCAAqC,KAAK,EAAE,CAC7C,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,EAAU;QAClB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,KAAK,EACL,6CAA6C,kBAAkB,CAAC,EAAE,CAAC,EAAE,CACtE,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,EAAU,EAAE,KAAa;QACpC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,MAAM,EACN,6CAA6C,kBAAkB,CAAC,EAAE,CAAC,SAAS,EAC5E,EAAE,KAAK,EAAE,CACV,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,EAAU,EAAE,KAAa;QACtC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,QAAQ,EACR,gDAAgD,kBAAkB,CAAC,EAAE,CAAC,cAAc,EACpF,EAAE,KAAK,EAAE,CACV,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAzCD,kCAyCC"}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Keplars = void 0;
|
|
4
|
+
const errors_1 = require("./errors");
|
|
5
|
+
const emails_1 = require("./emails");
|
|
6
|
+
const contacts_1 = require("./contacts");
|
|
7
|
+
const audiences_1 = require("./audiences");
|
|
8
|
+
const automations_1 = require("./automations");
|
|
9
|
+
const domains_1 = require("./domains");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const DEFAULT_BASE_URL = 'https://api.keplars.com';
|
|
12
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
13
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
14
|
+
const DEFAULT_RETRY_DELAY = 1000;
|
|
15
|
+
class Keplars {
|
|
16
|
+
constructor(config) {
|
|
17
|
+
if (!config.apiKey) {
|
|
18
|
+
throw new Error('API key is required');
|
|
19
|
+
}
|
|
20
|
+
this.validateApiKey(config.apiKey);
|
|
21
|
+
const baseUrl = config.baseUrl ||
|
|
22
|
+
(typeof process !== 'undefined' ? process.env.KEPLARS_BASE_URL : undefined) ||
|
|
23
|
+
DEFAULT_BASE_URL;
|
|
24
|
+
this.config = {
|
|
25
|
+
apiKey: config.apiKey,
|
|
26
|
+
baseUrl: baseUrl.replace(/\/$/, ''),
|
|
27
|
+
timeout: config.timeout || DEFAULT_TIMEOUT,
|
|
28
|
+
maxRetries: config.maxRetries ?? DEFAULT_MAX_RETRIES,
|
|
29
|
+
retryDelay: config.retryDelay || DEFAULT_RETRY_DELAY,
|
|
30
|
+
};
|
|
31
|
+
this.emails = new emails_1.Emails(this);
|
|
32
|
+
this.contacts = new contacts_1.Contacts(this);
|
|
33
|
+
this.audiences = new audiences_1.Audiences(this);
|
|
34
|
+
this.automations = new automations_1.Automations(this);
|
|
35
|
+
this.domains = new domains_1.Domains(this);
|
|
36
|
+
}
|
|
37
|
+
validateApiKey(apiKey) {
|
|
38
|
+
const apiKeyRegex = /^kms_[a-f0-9]+\.(live|adm)_[a-f0-9]+$/;
|
|
39
|
+
if (!apiKeyRegex.test(apiKey)) {
|
|
40
|
+
throw new Error('Invalid API key format. Expected: kms_<id>.live_<secret> or kms_<id>.adm_<secret>');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async request(method, path, body, retryCount = 0) {
|
|
44
|
+
const url = `${this.config.baseUrl}${path}`;
|
|
45
|
+
const controller = new AbortController();
|
|
46
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
47
|
+
try {
|
|
48
|
+
const response = await fetch(url, {
|
|
49
|
+
method,
|
|
50
|
+
headers: {
|
|
51
|
+
Authorization: `Bearer ${this.config.apiKey}`,
|
|
52
|
+
'Content-Type': 'application/json',
|
|
53
|
+
'User-Agent': '@keplars/email-sdk/1.0.0',
|
|
54
|
+
},
|
|
55
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
56
|
+
signal: controller.signal,
|
|
57
|
+
});
|
|
58
|
+
clearTimeout(timeoutId);
|
|
59
|
+
const rateLimitInfo = this.extractRateLimitInfo(response);
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
await this.handleErrorResponse(response, retryCount);
|
|
62
|
+
}
|
|
63
|
+
const data = (await response.json());
|
|
64
|
+
return { data, rateLimitInfo };
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
clearTimeout(timeoutId);
|
|
68
|
+
if (error instanceof errors_1.KeplarsError) {
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
if (this.isRetryableError(error) && retryCount < this.config.maxRetries) {
|
|
72
|
+
const delay = (0, utils_1.calculateExponentialBackoff)(retryCount, this.config.retryDelay);
|
|
73
|
+
await (0, utils_1.sleep)(delay);
|
|
74
|
+
return this.request(method, path, body, retryCount + 1);
|
|
75
|
+
}
|
|
76
|
+
throw new errors_1.NetworkError(`Network request failed: ${error instanceof Error ? error.message : 'Unknown error'}`, error instanceof Error ? error : new Error(String(error)));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
extractRateLimitInfo(response) {
|
|
80
|
+
const limit = response.headers.get('X-RateLimit-Limit');
|
|
81
|
+
const remaining = response.headers.get('X-RateLimit-Remaining');
|
|
82
|
+
const reset = response.headers.get('X-RateLimit-Reset');
|
|
83
|
+
if (limit && remaining && reset) {
|
|
84
|
+
return {
|
|
85
|
+
limit: parseInt(limit, 10),
|
|
86
|
+
remaining: parseInt(remaining, 10),
|
|
87
|
+
reset: parseInt(reset, 10),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
async handleErrorResponse(response, retryCount) {
|
|
93
|
+
let errorBody;
|
|
94
|
+
try {
|
|
95
|
+
errorBody = (await response.json());
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
throw new errors_1.KeplarsError(`HTTP ${response.status}: ${response.statusText}`, 'INTERNAL_ERROR', undefined, response.status);
|
|
99
|
+
}
|
|
100
|
+
const message = errorBody.message || `HTTP ${response.status}`;
|
|
101
|
+
switch (response.status) {
|
|
102
|
+
case 400:
|
|
103
|
+
throw new errors_1.ValidationError(message, undefined, undefined);
|
|
104
|
+
case 401:
|
|
105
|
+
throw new errors_1.AuthenticationError(message, undefined);
|
|
106
|
+
case 403:
|
|
107
|
+
throw new errors_1.AuthorizationError(message, undefined);
|
|
108
|
+
case 404:
|
|
109
|
+
throw new errors_1.NotFoundError(message, undefined);
|
|
110
|
+
case 409:
|
|
111
|
+
throw new errors_1.ConflictError(message, undefined);
|
|
112
|
+
case 429:
|
|
113
|
+
throw new errors_1.RateLimitError(message, 60, undefined);
|
|
114
|
+
case 500:
|
|
115
|
+
case 502:
|
|
116
|
+
case 503:
|
|
117
|
+
if (retryCount < this.config.maxRetries) {
|
|
118
|
+
const delay = (0, utils_1.calculateExponentialBackoff)(retryCount, this.config.retryDelay);
|
|
119
|
+
await (0, utils_1.sleep)(delay);
|
|
120
|
+
}
|
|
121
|
+
throw new errors_1.InternalError(message, undefined);
|
|
122
|
+
default:
|
|
123
|
+
throw new errors_1.KeplarsError(message, 'INTERNAL_ERROR', undefined, response.status);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
isRetryableError(error) {
|
|
127
|
+
if (error instanceof Error) {
|
|
128
|
+
const networkErrors = ['ECONNRESET', 'ETIMEDOUT', 'ENOTFOUND', 'AbortError'];
|
|
129
|
+
return networkErrors.some((errCode) => error.message.includes(errCode));
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.Keplars = Keplars;
|
|
135
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|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,CAAC,CAAC;YAC9C,KAAK,GAAG;gBACN,MAAM,IAAI,uBAAc,CAAC,OAAO,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;YACnD,KAAK,GAAG,CAAC;YACT,KAAK,GAAG,CAAC;YACT,KAAK,GAAG;gBACN,IAAI,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;oBACxC,MAAM,KAAK,GAAG,IAAA,mCAA2B,EAAC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;oBAC9E,MAAM,IAAA,aAAK,EAAC,KAAK,CAAC,CAAC;gBACrB,CAAC;gBACD,MAAM,IAAI,sBAAa,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;YAC9C;gBACE,MAAM,IAAI,qBAAY,CAAC,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAClF,CAAC;IACH,CAAC;IAEO,gBAAgB,CAAC,KAAc;QACrC,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;YAC3B,MAAM,aAAa,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;YAC7E,OAAO,aAAa,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1E,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAjKD,0BAiKC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Contacts = void 0;
|
|
4
|
+
class Contacts {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async add(params) {
|
|
9
|
+
const { data } = await this.client.request('POST', '/api/v1/public/contacts/add-contact', params);
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
async get(email) {
|
|
13
|
+
const { data } = await this.client.request('GET', `/api/v1/public/contacts/get-contact?email=${encodeURIComponent(email)}`);
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
async list(audienceId, page, limit) {
|
|
17
|
+
const params = new URLSearchParams();
|
|
18
|
+
if (audienceId)
|
|
19
|
+
params.append('audience_id', audienceId);
|
|
20
|
+
if (page)
|
|
21
|
+
params.append('page', page.toString());
|
|
22
|
+
if (limit)
|
|
23
|
+
params.append('limit', limit.toString());
|
|
24
|
+
const query = params.toString() ? `?${params.toString()}` : '';
|
|
25
|
+
const { data } = await this.client.request('GET', `/api/v1/public/contacts/get-contacts${query}`);
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
async update(email, params) {
|
|
29
|
+
const { data } = await this.client.request('PATCH', `/api/v1/public/contacts/update-contact?email=${encodeURIComponent(email)}`, params);
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
async delete(email) {
|
|
33
|
+
const { data } = await this.client.request('DELETE', `/api/v1/public/contacts/delete-contact?email=${encodeURIComponent(email)}`);
|
|
34
|
+
return data;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
exports.Contacts = Contacts;
|
|
38
|
+
//# sourceMappingURL=contacts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contacts.js","sourceRoot":"","sources":["../../src/contacts.ts"],"names":[],"mappings":";;;AAWA,MAAa,QAAQ;IACnB,YAA6B,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAEhD,KAAK,CAAC,GAAG,CAAC,MAAyB;QACjC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,MAAM,EACN,qCAAqC,EACrC,MAAM,CACP,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,KAAa;QACrB,MAAM,E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AE,CAC5E,CAAC;QACF,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtDD,4BAsDC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Domains = void 0;
|
|
4
|
+
class Domains {
|
|
5
|
+
constructor(client) {
|
|
6
|
+
this.client = client;
|
|
7
|
+
}
|
|
8
|
+
async add(domain) {
|
|
9
|
+
const { data } = await this.client.request('POST', '/api/v1/public/domains/add-domain', { domain });
|
|
10
|
+
return data;
|
|
11
|
+
}
|
|
12
|
+
async list() {
|
|
13
|
+
const { data } = await this.client.request('GET', '/api/v1/public/domains/get-domains');
|
|
14
|
+
return data;
|
|
15
|
+
}
|
|
16
|
+
async getStatus(domainId) {
|
|
17
|
+
const { data } = await this.client.request('GET', `/api/v1/public/domains/domain-status/${encodeURIComponent(domainId)}`);
|
|
18
|
+
return data;
|
|
19
|
+
}
|
|
20
|
+
async verify(domainId) {
|
|
21
|
+
const { data } = await this.client.request('POST', `/api/v1/public/domains/verify-domain/${encodeURIComponent(domainId)}`);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
async delete(domainId) {
|
|
25
|
+
const { data } = await this.client.request('DELETE', `/api/v1/public/domains/delete-domain/${encodeURIComponent(domainId)}`);
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
async createApiKey(params) {
|
|
29
|
+
const { data } = await this.client.request('POST', '/api/v1/public/domains/api-keys/create', params);
|
|
30
|
+
return data;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Domains = Domains;
|
|
34
|
+
//# sourceMappingURL=domains.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"domains.js","sourceRoot":"","sources":["../../src/domains.ts"],"names":[],"mappings":";;;AASA,MAAa,OAAO;IAClB,YAA6B,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAEh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0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Emails = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class Emails {
|
|
6
|
+
constructor(client) {
|
|
7
|
+
this.client = client;
|
|
8
|
+
}
|
|
9
|
+
async sendInstant(request) {
|
|
10
|
+
this.validateEmailRequest(request);
|
|
11
|
+
const { data } = await this.client.request('POST', '/api/v1/public/send-email/instant', request);
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
async sendHigh(request) {
|
|
15
|
+
this.validateEmailRequest(request);
|
|
16
|
+
const { data } = await this.client.request('POST', '/api/v1/public/send-email/high', request);
|
|
17
|
+
return data;
|
|
18
|
+
}
|
|
19
|
+
async sendAsync(request) {
|
|
20
|
+
this.validateEmailRequest(request);
|
|
21
|
+
const { data } = await this.client.request('POST', '/api/v1/public/send-email/async', request);
|
|
22
|
+
return data;
|
|
23
|
+
}
|
|
24
|
+
async sendBulk(request) {
|
|
25
|
+
this.validateEmailRequest(request);
|
|
26
|
+
const { data } = await this.client.request('POST', '/api/v1/public/send-email/bulk', request);
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
async send(request) {
|
|
30
|
+
return this.sendAsync(request);
|
|
31
|
+
}
|
|
32
|
+
async schedule(request) {
|
|
33
|
+
this.validateEmailRequest(request);
|
|
34
|
+
if (!request.scheduled_for) {
|
|
35
|
+
throw new Error('scheduled_for is required for scheduling emails');
|
|
36
|
+
}
|
|
37
|
+
(0, utils_1.validateScheduleDate)(request.scheduled_for);
|
|
38
|
+
const { data } = await this.client.request('POST', '/api/v1/public/send-email/schedule', request);
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
41
|
+
validateEmailRequest(request) {
|
|
42
|
+
if (!request.to) {
|
|
43
|
+
throw new Error('To recipient is required');
|
|
44
|
+
}
|
|
45
|
+
if (!request.from) {
|
|
46
|
+
throw new Error('From email is required');
|
|
47
|
+
}
|
|
48
|
+
if (!request.subject) {
|
|
49
|
+
throw new Error('Subject is required');
|
|
50
|
+
}
|
|
51
|
+
this.validateRecipientField(request.to, 'to');
|
|
52
|
+
if (request.cc) {
|
|
53
|
+
this.validateRecipientList(request.cc, 'cc');
|
|
54
|
+
}
|
|
55
|
+
if (request.bcc) {
|
|
56
|
+
this.validateRecipientList(request.bcc, 'bcc');
|
|
57
|
+
}
|
|
58
|
+
const hasContent = request.html || request.text;
|
|
59
|
+
const hasTemplate = request.template_id;
|
|
60
|
+
if (!hasContent && !hasTemplate) {
|
|
61
|
+
throw new Error('Either html/text or template_id is required');
|
|
62
|
+
}
|
|
63
|
+
if (hasContent && hasTemplate) {
|
|
64
|
+
throw new Error('Cannot use both content (html/text) and template_id');
|
|
65
|
+
}
|
|
66
|
+
if (request.subject.length > 998) {
|
|
67
|
+
throw new Error('Subject cannot exceed 998 characters');
|
|
68
|
+
}
|
|
69
|
+
if (request.html && request.html.length > 524288) {
|
|
70
|
+
throw new Error('HTML content cannot exceed 512KB');
|
|
71
|
+
}
|
|
72
|
+
if (request.text && request.text.length > 524288) {
|
|
73
|
+
throw new Error('Text content cannot exceed 512KB');
|
|
74
|
+
}
|
|
75
|
+
if (request.custom_headers && Object.keys(request.custom_headers).length > 50) {
|
|
76
|
+
throw new Error('Maximum 50 custom headers allowed');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
validateRecipientField(to, field) {
|
|
80
|
+
if (typeof to === 'string') {
|
|
81
|
+
if (!(0, utils_1.validateEmail)(to)) {
|
|
82
|
+
throw new Error(`Invalid email address in ${field}: ${to}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (Array.isArray(to)) {
|
|
86
|
+
this.validateRecipientList(to, field);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
validateRecipientList(recipients, field) {
|
|
90
|
+
if (recipients.length === 0) {
|
|
91
|
+
throw new Error(`${field} cannot be empty`);
|
|
92
|
+
}
|
|
93
|
+
for (const recipient of recipients) {
|
|
94
|
+
if (!(0, utils_1.validateEmail)(recipient.email)) {
|
|
95
|
+
throw new Error(`Invalid email address in ${field}: ${recipient.email}`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.Emails = Emails;
|
|
101
|
+
//# sourceMappingURL=emails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emails.js","sourceRoot":"","sources":["../../src/emails.ts"],"names":[],"mappings":";;;AAQA,mCAA8D;AAE9D,MAAa,MAAM;IACjB,YAA6B,MAAe;QAAf,WAAM,GAAN,MAAM,CAAS;IAAG,CAAC;IAEhD,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEnC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,MAAM,EACN,mCAAmC,EACnC,OAAO,CACR,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAyB;QACtC,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEnC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,MAAM,EACN,gCAAgC,EAChC,OAAO,CACR,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAyB;QACvC,IAAI,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAEnC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,OAAO,CACxC,MAAM,EACN,iCAAiC,EACjC,OAAO,CACR,CAAC;QAEF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAyB;QACtC,IAAI,CAAC,oBAAoB,CAAC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