@solytude/listmonk 1.0.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 +21 -0
- package/README.md +542 -0
- package/dist/chunk-saezhne8.js +14 -0
- package/dist/chunk-saezhne8.js.map +9 -0
- package/dist/client.d.ts +430 -0
- package/dist/errors/api.d.ts +178 -0
- package/dist/errors/base.d.ts +47 -0
- package/dist/errors/configuration.d.ts +49 -0
- package/dist/errors/index.d.ts +13 -0
- package/dist/errors/network.d.ts +69 -0
- package/dist/errors/validation.d.ts +57 -0
- package/dist/http/auth.d.ts +39 -0
- package/dist/http/client.d.ts +149 -0
- package/dist/http/hooks.d.ts +90 -0
- package/dist/http/index.d.ts +10 -0
- package/dist/http/resource.d.ts +100 -0
- package/dist/http/sse.d.ts +36 -0
- package/dist/http/url.d.ts +51 -0
- package/dist/index.d.ts +64 -0
- package/dist/index.js +16039 -0
- package/dist/index.js.map +120 -0
- package/dist/resources/admin/admin.d.ts +92 -0
- package/dist/resources/admin/index.d.ts +10 -0
- package/dist/resources/admin/schemas.d.ts +23 -0
- package/dist/resources/admin/types.d.ts +29 -0
- package/dist/resources/bounces/bounces.d.ts +262 -0
- package/dist/resources/bounces/index.d.ts +10 -0
- package/dist/resources/bounces/schemas.d.ts +86 -0
- package/dist/resources/bounces/types.d.ts +37 -0
- package/dist/resources/campaigns/campaigns.d.ts +339 -0
- package/dist/resources/campaigns/index.d.ts +10 -0
- package/dist/resources/campaigns/schemas.d.ts +374 -0
- package/dist/resources/campaigns/types.d.ts +111 -0
- package/dist/resources/dashboard/dashboard.d.ts +73 -0
- package/dist/resources/dashboard/index.d.ts +10 -0
- package/dist/resources/dashboard/schemas.d.ts +55 -0
- package/dist/resources/dashboard/types.d.ts +22 -0
- package/dist/resources/import/import.d.ts +215 -0
- package/dist/resources/import/index.d.ts +10 -0
- package/dist/resources/import/schemas.d.ts +109 -0
- package/dist/resources/import/types.d.ts +72 -0
- package/dist/resources/lists/index.d.ts +10 -0
- package/dist/resources/lists/lists.d.ts +180 -0
- package/dist/resources/lists/schemas.d.ts +176 -0
- package/dist/resources/lists/types.d.ts +56 -0
- package/dist/resources/maintenance/index.d.ts +10 -0
- package/dist/resources/maintenance/maintenance.d.ts +92 -0
- package/dist/resources/maintenance/schemas.d.ts +36 -0
- package/dist/resources/maintenance/types.d.ts +31 -0
- package/dist/resources/media/index.d.ts +10 -0
- package/dist/resources/media/media.d.ts +198 -0
- package/dist/resources/media/schemas.d.ts +48 -0
- package/dist/resources/media/types.d.ts +48 -0
- package/dist/resources/public/index.d.ts +10 -0
- package/dist/resources/public/public.d.ts +111 -0
- package/dist/resources/public/schemas.d.ts +52 -0
- package/dist/resources/public/types.d.ts +30 -0
- package/dist/resources/settings/index.d.ts +10 -0
- package/dist/resources/settings/schemas.d.ts +374 -0
- package/dist/resources/settings/settings.d.ts +106 -0
- package/dist/resources/settings/types.d.ts +78 -0
- package/dist/resources/subscribers/index.d.ts +10 -0
- package/dist/resources/subscribers/schemas.d.ts +360 -0
- package/dist/resources/subscribers/subscribers.d.ts +308 -0
- package/dist/resources/subscribers/types.d.ts +113 -0
- package/dist/resources/templates/index.d.ts +10 -0
- package/dist/resources/templates/schemas.d.ts +110 -0
- package/dist/resources/templates/templates.d.ts +225 -0
- package/dist/resources/templates/types.d.ts +45 -0
- package/dist/resources/tx/index.d.ts +10 -0
- package/dist/resources/tx/schemas.d.ts +67 -0
- package/dist/resources/tx/tx.d.ts +167 -0
- package/dist/resources/tx/types.d.ts +88 -0
- package/dist/schemas/common.d.ts +48 -0
- package/dist/schemas/index.d.ts +6 -0
- package/dist/testing/errors.d.ts +25 -0
- package/dist/testing/factories/bounce.d.ts +43 -0
- package/dist/testing/factories/campaign.d.ts +43 -0
- package/dist/testing/factories/common.d.ts +54 -0
- package/dist/testing/factories/index.d.ts +12 -0
- package/dist/testing/factories/list.d.ts +43 -0
- package/dist/testing/factories/media.d.ts +40 -0
- package/dist/testing/factories/subscriber.d.ts +43 -0
- package/dist/testing/factories/template.d.ts +40 -0
- package/dist/testing/index.d.ts +39 -0
- package/dist/testing/index.js +573 -0
- package/dist/testing/index.js.map +32 -0
- package/dist/testing/mock-client.d.ts +119 -0
- package/dist/testing/mock-function.d.ts +28 -0
- package/dist/testing/resources/admin.d.ts +20 -0
- package/dist/testing/resources/bounces.d.ts +22 -0
- package/dist/testing/resources/campaigns.d.ts +31 -0
- package/dist/testing/resources/dashboard.d.ts +17 -0
- package/dist/testing/resources/import.d.ts +19 -0
- package/dist/testing/resources/index.d.ts +18 -0
- package/dist/testing/resources/lists.d.ts +24 -0
- package/dist/testing/resources/maintenance.d.ts +18 -0
- package/dist/testing/resources/media.d.ts +21 -0
- package/dist/testing/resources/public.d.ts +18 -0
- package/dist/testing/resources/settings.d.ts +19 -0
- package/dist/testing/resources/subscribers.d.ts +33 -0
- package/dist/testing/resources/templates.d.ts +24 -0
- package/dist/testing/resources/tx.d.ts +16 -0
- package/dist/testing/types.d.ts +138 -0
- package/dist/types/config.d.ts +59 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/pagination.d.ts +37 -0
- package/package.json +97 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main Listmonk client class.
|
|
3
|
+
*
|
|
4
|
+
* The primary entry point for the SDK. Validates configuration,
|
|
5
|
+
* creates the HTTP client, and provides access to resource modules.
|
|
6
|
+
*
|
|
7
|
+
* @module client
|
|
8
|
+
*/
|
|
9
|
+
import { HttpClient } from "./http/client";
|
|
10
|
+
import type { ClientOptionsInput } from "./types/config";
|
|
11
|
+
import { SubscribersResource } from "./resources/subscribers";
|
|
12
|
+
import { ListsResource } from "./resources/lists";
|
|
13
|
+
import { CampaignsResource } from "./resources/campaigns";
|
|
14
|
+
import { TemplatesResource } from "./resources/templates";
|
|
15
|
+
import { TransactionalResource } from "./resources/tx";
|
|
16
|
+
import { MediaResource } from "./resources/media";
|
|
17
|
+
import { ImportResource } from "./resources/import";
|
|
18
|
+
import { BouncesResource } from "./resources/bounces";
|
|
19
|
+
import { SettingsResource } from "./resources/settings";
|
|
20
|
+
import { DashboardResource } from "./resources/dashboard";
|
|
21
|
+
import { AdminResource } from "./resources/admin";
|
|
22
|
+
import { MaintenanceResource } from "./resources/maintenance";
|
|
23
|
+
import { PublicResource } from "./resources/public";
|
|
24
|
+
import type { ServerHealth, ServerConfig } from "./resources/settings/types";
|
|
25
|
+
/**
|
|
26
|
+
* Listmonk SDK client for interacting with the listmonk API.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* import { Listmonk } from '@solytude/listmonk';
|
|
31
|
+
*
|
|
32
|
+
* const client = new Listmonk({
|
|
33
|
+
* url: 'https://listmonk.example.com',
|
|
34
|
+
* auth: {
|
|
35
|
+
* username: 'admin',
|
|
36
|
+
* password: 'secret',
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // Use resource modules (to be added in subsequent specs)
|
|
41
|
+
* // const subscribers = await client.subscribers.list();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class Listmonk {
|
|
45
|
+
/** @internal The underlying HTTP client */
|
|
46
|
+
private readonly _httpClient;
|
|
47
|
+
/**
|
|
48
|
+
* Subscribers resource for managing subscriber lifecycle.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Create a subscriber
|
|
53
|
+
* const subscriber = await client.subscribers.create({
|
|
54
|
+
* email: 'john@example.com',
|
|
55
|
+
* name: 'John Doe',
|
|
56
|
+
* status: 'enabled',
|
|
57
|
+
* });
|
|
58
|
+
*
|
|
59
|
+
* // List subscribers
|
|
60
|
+
* for await (const sub of client.subscribers.listAll()) {
|
|
61
|
+
* console.log(sub.email);
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
readonly subscribers: SubscribersResource;
|
|
66
|
+
/**
|
|
67
|
+
* Lists resource for managing mailing lists.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Create a list
|
|
72
|
+
* const list = await client.lists.create({
|
|
73
|
+
* name: 'Newsletter',
|
|
74
|
+
* type: 'public',
|
|
75
|
+
* optin: 'double',
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* // List all lists
|
|
79
|
+
* for await (const l of client.lists.listAll()) {
|
|
80
|
+
* console.log(l.name);
|
|
81
|
+
* }
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
readonly lists: ListsResource;
|
|
85
|
+
/**
|
|
86
|
+
* Campaigns resource for managing email campaigns.
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* // Create a campaign
|
|
91
|
+
* const campaign = await client.campaigns.create({
|
|
92
|
+
* name: 'Weekly Newsletter',
|
|
93
|
+
* subject: 'This Week in Tech',
|
|
94
|
+
* lists: [1],
|
|
95
|
+
* body: '<h1>Hello!</h1>',
|
|
96
|
+
* content_type: 'html',
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Start the campaign
|
|
100
|
+
* await client.campaigns.updateStatus(campaign.id, 'running');
|
|
101
|
+
*
|
|
102
|
+
* // List all campaigns
|
|
103
|
+
* for await (const c of client.campaigns.listAll()) {
|
|
104
|
+
* console.log(c.name, c.status);
|
|
105
|
+
* }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
readonly campaigns: CampaignsResource;
|
|
109
|
+
/**
|
|
110
|
+
* Templates resource for managing email templates.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* // Create a template
|
|
115
|
+
* const template = await client.templates.create({
|
|
116
|
+
* name: 'Newsletter Template',
|
|
117
|
+
* type: 'campaign',
|
|
118
|
+
* body: '<html>{{ template "content" . }}</html>',
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
121
|
+
* // List all templates
|
|
122
|
+
* for await (const t of client.templates.listAll()) {
|
|
123
|
+
* console.log(t.name, t.is_default);
|
|
124
|
+
* }
|
|
125
|
+
*
|
|
126
|
+
* // Set as default
|
|
127
|
+
* await client.templates.setDefault(template.id);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
readonly templates: TemplatesResource;
|
|
131
|
+
/**
|
|
132
|
+
* Transactional resource for sending application-triggered emails.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* // Send to an existing subscriber
|
|
137
|
+
* await client.tx.send({
|
|
138
|
+
* template_id: 2,
|
|
139
|
+
* subscriber_email: 'user@example.com',
|
|
140
|
+
* });
|
|
141
|
+
*
|
|
142
|
+
* // Send with template data
|
|
143
|
+
* await client.tx.send({
|
|
144
|
+
* template_id: 2,
|
|
145
|
+
* subscriber_email: 'user@example.com',
|
|
146
|
+
* data: {
|
|
147
|
+
* order_id: '12345',
|
|
148
|
+
* total: '$99.99',
|
|
149
|
+
* },
|
|
150
|
+
* });
|
|
151
|
+
*
|
|
152
|
+
* // Send to external recipient
|
|
153
|
+
* await client.tx.send({
|
|
154
|
+
* template_id: 2,
|
|
155
|
+
* subscriber_mode: 'external',
|
|
156
|
+
* subscriber_emails: ['guest@example.com'],
|
|
157
|
+
* });
|
|
158
|
+
*
|
|
159
|
+
* // Send with file attachment
|
|
160
|
+
* await client.tx.send({
|
|
161
|
+
* template_id: 2,
|
|
162
|
+
* subscriber_email: 'user@example.com',
|
|
163
|
+
* attachments: [
|
|
164
|
+
* { filename: 'invoice.pdf', content: pdfBuffer },
|
|
165
|
+
* ],
|
|
166
|
+
* });
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
readonly tx: TransactionalResource;
|
|
170
|
+
/**
|
|
171
|
+
* Media resource for managing media files (images, PDFs, etc.).
|
|
172
|
+
*
|
|
173
|
+
* @example
|
|
174
|
+
* ```typescript
|
|
175
|
+
* // Upload a file (Browser)
|
|
176
|
+
* const file = new File([content], 'hero.jpg', { type: 'image/jpeg' });
|
|
177
|
+
* const media = await client.media.upload(file);
|
|
178
|
+
* console.log(`URL: ${media.url}`);
|
|
179
|
+
*
|
|
180
|
+
* // Upload a file (Node.js)
|
|
181
|
+
* import { readFileSync } from 'fs';
|
|
182
|
+
* const media = await client.media.upload({
|
|
183
|
+
* filename: 'hero.jpg',
|
|
184
|
+
* content: readFileSync('./hero.jpg'),
|
|
185
|
+
* });
|
|
186
|
+
*
|
|
187
|
+
* // List all media
|
|
188
|
+
* const allMedia = await client.media.list();
|
|
189
|
+
*
|
|
190
|
+
* // Delete media
|
|
191
|
+
* const deleted = await client.media.remove(42);
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
readonly media: MediaResource;
|
|
195
|
+
/**
|
|
196
|
+
* Import resource for bulk subscriber import from CSV/ZIP files.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* // Start import (Browser)
|
|
201
|
+
* const file = new File([csvContent], 'subscribers.csv');
|
|
202
|
+
* await client.import.start(file, {
|
|
203
|
+
* mode: 'subscribe',
|
|
204
|
+
* delimiter: ',',
|
|
205
|
+
* lists: [1, 2],
|
|
206
|
+
* });
|
|
207
|
+
*
|
|
208
|
+
* // Start import (Node.js)
|
|
209
|
+
* import { readFileSync } from 'fs';
|
|
210
|
+
* await client.import.start(
|
|
211
|
+
* { filename: 'subscribers.csv', content: readFileSync('./subscribers.csv') },
|
|
212
|
+
* { mode: 'subscribe', delimiter: ',', lists: [1] }
|
|
213
|
+
* );
|
|
214
|
+
*
|
|
215
|
+
* // Poll for completion
|
|
216
|
+
* let status = await client.import.getStatus();
|
|
217
|
+
* while (status.status === 'processing') {
|
|
218
|
+
* await new Promise(r => setTimeout(r, 1000));
|
|
219
|
+
* status = await client.import.getStatus();
|
|
220
|
+
* }
|
|
221
|
+
*
|
|
222
|
+
* // Check logs
|
|
223
|
+
* const logs = await client.import.getLogs();
|
|
224
|
+
*
|
|
225
|
+
* // Cancel if needed
|
|
226
|
+
* await client.import.cancel();
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
readonly import: ImportResource;
|
|
230
|
+
/**
|
|
231
|
+
* Bounces resource for managing email bounce records.
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* // List bounces with filtering
|
|
236
|
+
* const bounces = await client.bounces.list({
|
|
237
|
+
* campaign_id: 5,
|
|
238
|
+
* order_by: 'created_at',
|
|
239
|
+
* order: 'desc',
|
|
240
|
+
* });
|
|
241
|
+
*
|
|
242
|
+
* // Iterate all bounces
|
|
243
|
+
* for await (const bounce of client.bounces.listAll()) {
|
|
244
|
+
* if (bounce.type === 'hard') {
|
|
245
|
+
* console.log(`Hard bounce: ${bounce.email}`);
|
|
246
|
+
* }
|
|
247
|
+
* }
|
|
248
|
+
*
|
|
249
|
+
* // Delete a specific bounce
|
|
250
|
+
* await client.bounces.remove(123);
|
|
251
|
+
*
|
|
252
|
+
* // Blocklist all bounced subscribers
|
|
253
|
+
* await client.bounces.blocklistBounced();
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
readonly bounces: BouncesResource;
|
|
257
|
+
/**
|
|
258
|
+
* Settings resource for managing server settings.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```typescript
|
|
262
|
+
* // Get all settings
|
|
263
|
+
* const settings = await client.settings.getAll();
|
|
264
|
+
* console.log(settings['app.site_name']);
|
|
265
|
+
*
|
|
266
|
+
* // Update settings
|
|
267
|
+
* const result = await client.settings.update({
|
|
268
|
+
* 'app.site_name': 'My Newsletter',
|
|
269
|
+
* ...settings,
|
|
270
|
+
* });
|
|
271
|
+
*
|
|
272
|
+
* // Test SMTP configuration
|
|
273
|
+
* const logs = await client.settings.testSmtp({
|
|
274
|
+
* host: 'smtp.example.com',
|
|
275
|
+
* port: 587,
|
|
276
|
+
* auth_protocol: 'login',
|
|
277
|
+
* username: 'user',
|
|
278
|
+
* password: 'pass',
|
|
279
|
+
* tls_type: 'STARTTLS',
|
|
280
|
+
* email: 'test@example.com',
|
|
281
|
+
* });
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
readonly settings: SettingsResource;
|
|
285
|
+
/**
|
|
286
|
+
* Dashboard resource for retrieving statistics.
|
|
287
|
+
*
|
|
288
|
+
* @example
|
|
289
|
+
* ```typescript
|
|
290
|
+
* // Get dashboard counts
|
|
291
|
+
* const counts = await client.dashboard.getCounts();
|
|
292
|
+
* console.log(`Total subscribers: ${counts.subscribers.total}`);
|
|
293
|
+
*
|
|
294
|
+
* // Get chart data
|
|
295
|
+
* const charts = await client.dashboard.getCharts();
|
|
296
|
+
* for (const point of charts.link_clicks) {
|
|
297
|
+
* console.log(`${point.date}: ${point.count} clicks`);
|
|
298
|
+
* }
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
readonly dashboard: DashboardResource;
|
|
302
|
+
/**
|
|
303
|
+
* Admin resource for server administration.
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* ```typescript
|
|
307
|
+
* // Reload application
|
|
308
|
+
* await client.admin.reload();
|
|
309
|
+
*
|
|
310
|
+
* // Get logs
|
|
311
|
+
* const logs = await client.admin.getLogs();
|
|
312
|
+
*
|
|
313
|
+
* // Stream events
|
|
314
|
+
* for await (const event of client.admin.getEventStream()) {
|
|
315
|
+
* console.log(event.type, event.message);
|
|
316
|
+
* }
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
readonly admin: AdminResource;
|
|
320
|
+
/**
|
|
321
|
+
* Maintenance resource for cleanup operations.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* ```typescript
|
|
325
|
+
* // Delete blocklisted subscribers
|
|
326
|
+
* const result = await client.maintenance.gcSubscribers('blocklisted');
|
|
327
|
+
* console.log(`Deleted ${result.count} subscribers`);
|
|
328
|
+
*
|
|
329
|
+
* // Delete old analytics
|
|
330
|
+
* await client.maintenance.gcAnalytics('all', '2025-01-01T00:00:00Z');
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
readonly maintenance: MaintenanceResource;
|
|
334
|
+
/**
|
|
335
|
+
* Public resource for unauthenticated endpoints.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```typescript
|
|
339
|
+
* // Get public lists
|
|
340
|
+
* const lists = await client.public.getLists();
|
|
341
|
+
*
|
|
342
|
+
* // Submit subscription
|
|
343
|
+
* const result = await client.public.subscribe({
|
|
344
|
+
* email: 'user@example.com',
|
|
345
|
+
* list_uuids: [lists[0].uuid],
|
|
346
|
+
* });
|
|
347
|
+
*
|
|
348
|
+
* // Get CAPTCHA challenge
|
|
349
|
+
* const challenge = await client.public.getCaptchaChallenge();
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
readonly public: PublicResource;
|
|
353
|
+
/**
|
|
354
|
+
* Creates a new Listmonk client.
|
|
355
|
+
*
|
|
356
|
+
* @param options - Client configuration options
|
|
357
|
+
* @throws {ListmonkConfigurationError} If options are invalid
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* const client = new Listmonk({
|
|
362
|
+
* url: 'https://listmonk.example.com',
|
|
363
|
+
* auth: { username: 'admin', password: 'secret' },
|
|
364
|
+
* timeout: 60_000, // Optional, default 30s
|
|
365
|
+
* maxRetries: 5, // Optional, default 3
|
|
366
|
+
* debug: true, // Optional, default false
|
|
367
|
+
* });
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
constructor(options: ClientOptionsInput);
|
|
371
|
+
/**
|
|
372
|
+
* Gets the underlying HTTP client.
|
|
373
|
+
* For internal use by resource modules.
|
|
374
|
+
* @internal
|
|
375
|
+
*/
|
|
376
|
+
get httpClient(): HttpClient;
|
|
377
|
+
/**
|
|
378
|
+
* Checks server health (authenticated endpoint).
|
|
379
|
+
*
|
|
380
|
+
* Returns `true` if the server is healthy and reachable.
|
|
381
|
+
* Throws an error on network failure or authentication issues.
|
|
382
|
+
*
|
|
383
|
+
* @returns `true` if server is healthy
|
|
384
|
+
* @throws {ListmonkApiError} On API errors
|
|
385
|
+
* @throws {ListmonkNetworkError} On network failures
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* const healthy = await client.health();
|
|
390
|
+
* console.log(`Server healthy: ${healthy}`); // true
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
health(): Promise<ServerHealth>;
|
|
394
|
+
/**
|
|
395
|
+
* Checks server health (public endpoint, no authentication).
|
|
396
|
+
*
|
|
397
|
+
* Useful for health checks before authentication is configured
|
|
398
|
+
* or for public monitoring systems.
|
|
399
|
+
*
|
|
400
|
+
* @returns `true` if server is healthy
|
|
401
|
+
* @throws {ListmonkNetworkError} On network failures
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* const healthy = await client.publicHealth();
|
|
406
|
+
* console.log(`Server reachable: ${healthy}`); // true
|
|
407
|
+
* ```
|
|
408
|
+
*/
|
|
409
|
+
publicHealth(): Promise<ServerHealth>;
|
|
410
|
+
/**
|
|
411
|
+
* Retrieves server configuration and capabilities.
|
|
412
|
+
*
|
|
413
|
+
* Returns information about the server version, enabled features,
|
|
414
|
+
* available updates, and runtime configuration.
|
|
415
|
+
*
|
|
416
|
+
* @returns Server configuration object
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```typescript
|
|
420
|
+
* const config = await client.getConfig();
|
|
421
|
+
* console.log(`Version: ${config.version}`);
|
|
422
|
+
* console.log(`Needs restart: ${config.needs_restart}`);
|
|
423
|
+
*
|
|
424
|
+
* if (config.update?.is_new) {
|
|
425
|
+
* console.log(`Update available: ${config.update.release_version}`);
|
|
426
|
+
* }
|
|
427
|
+
* ```
|
|
428
|
+
*/
|
|
429
|
+
getConfig(): Promise<ServerConfig>;
|
|
430
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* API error classes for HTTP response failures.
|
|
3
|
+
*
|
|
4
|
+
* Provides a hierarchy of errors for different HTTP status codes,
|
|
5
|
+
* with a factory method for automatic error type selection.
|
|
6
|
+
*
|
|
7
|
+
* @module errors/api
|
|
8
|
+
*/
|
|
9
|
+
import { ListmonkError } from "./base";
|
|
10
|
+
/**
|
|
11
|
+
* Base error for all HTTP API failures (4xx and 5xx responses).
|
|
12
|
+
*
|
|
13
|
+
* Contains the HTTP status code, response body, request ID,
|
|
14
|
+
* and endpoint information for debugging.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* try {
|
|
19
|
+
* await client.subscribers.get(123);
|
|
20
|
+
* } catch (error) {
|
|
21
|
+
* if (error instanceof ListmonkApiError) {
|
|
22
|
+
* console.error(`API error ${error.status}:`, error.message);
|
|
23
|
+
* console.error('Request ID:', error.requestId);
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare class ListmonkApiError extends ListmonkError {
|
|
29
|
+
readonly name: string;
|
|
30
|
+
/**
|
|
31
|
+
* HTTP status code of the response.
|
|
32
|
+
*/
|
|
33
|
+
readonly status: number;
|
|
34
|
+
/**
|
|
35
|
+
* Parsed response body.
|
|
36
|
+
*/
|
|
37
|
+
readonly body: unknown;
|
|
38
|
+
/**
|
|
39
|
+
* The API endpoint that failed.
|
|
40
|
+
*/
|
|
41
|
+
readonly endpoint: string;
|
|
42
|
+
/**
|
|
43
|
+
* The X-Request-ID header value, if present.
|
|
44
|
+
* Useful for correlating with server logs.
|
|
45
|
+
*/
|
|
46
|
+
readonly requestId?: string;
|
|
47
|
+
/**
|
|
48
|
+
* The response headers.
|
|
49
|
+
*/
|
|
50
|
+
readonly headers?: Headers;
|
|
51
|
+
/**
|
|
52
|
+
* Creates a new API error.
|
|
53
|
+
*
|
|
54
|
+
* @param message - Human-readable error message
|
|
55
|
+
* @param status - HTTP status code
|
|
56
|
+
* @param body - Parsed response body
|
|
57
|
+
* @param endpoint - The API endpoint that failed
|
|
58
|
+
* @param requestId - Optional X-Request-ID value
|
|
59
|
+
* @param headers - Optional response headers
|
|
60
|
+
*/
|
|
61
|
+
constructor(message: string, status: number, body: unknown, endpoint: string, requestId?: string, headers?: Headers);
|
|
62
|
+
/**
|
|
63
|
+
* Creates the appropriate error subclass based on HTTP status code.
|
|
64
|
+
*
|
|
65
|
+
* @param response - The fetch Response object
|
|
66
|
+
* @param body - Parsed response body
|
|
67
|
+
* @param endpoint - The API endpoint that was called
|
|
68
|
+
* @returns The appropriate ListmonkApiError subclass
|
|
69
|
+
*/
|
|
70
|
+
static fromResponse(response: Response, body: unknown, endpoint: string): ListmonkApiError;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Error thrown for HTTP 400 Bad Request responses.
|
|
74
|
+
*
|
|
75
|
+
* Indicates the request was malformed or contained invalid data.
|
|
76
|
+
*/
|
|
77
|
+
export declare class ListmonkBadRequestError extends ListmonkApiError {
|
|
78
|
+
readonly name: string;
|
|
79
|
+
readonly status: number;
|
|
80
|
+
/**
|
|
81
|
+
* Creates a new bad request error.
|
|
82
|
+
*
|
|
83
|
+
* @param message - Error message
|
|
84
|
+
* @param body - Response body with validation details
|
|
85
|
+
* @param endpoint - The API endpoint
|
|
86
|
+
* @param requestId - Optional X-Request-ID
|
|
87
|
+
* @param headers - Optional response headers
|
|
88
|
+
*/
|
|
89
|
+
constructor(message: string, body: unknown, endpoint: string, requestId?: string, headers?: Headers);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Error thrown for HTTP 401 Unauthorized responses.
|
|
93
|
+
*
|
|
94
|
+
* Indicates the request lacked valid authentication credentials.
|
|
95
|
+
*/
|
|
96
|
+
export declare class ListmonkAuthenticationError extends ListmonkApiError {
|
|
97
|
+
readonly name: string;
|
|
98
|
+
readonly status: number;
|
|
99
|
+
/**
|
|
100
|
+
* Creates a new authentication error.
|
|
101
|
+
*
|
|
102
|
+
* @param message - Error message
|
|
103
|
+
* @param endpoint - The API endpoint
|
|
104
|
+
* @param requestId - Optional X-Request-ID
|
|
105
|
+
* @param headers - Optional response headers
|
|
106
|
+
*/
|
|
107
|
+
constructor(message: string, endpoint: string, requestId?: string, headers?: Headers);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Error thrown for HTTP 403 Forbidden responses.
|
|
111
|
+
*
|
|
112
|
+
* Indicates the authenticated user lacks permission for the requested action.
|
|
113
|
+
*/
|
|
114
|
+
export declare class ListmonkPermissionDeniedError extends ListmonkApiError {
|
|
115
|
+
readonly name: string;
|
|
116
|
+
readonly status: number;
|
|
117
|
+
/**
|
|
118
|
+
* Creates a new permission denied error.
|
|
119
|
+
*
|
|
120
|
+
* @param message - Error message
|
|
121
|
+
* @param endpoint - The API endpoint
|
|
122
|
+
* @param requestId - Optional X-Request-ID
|
|
123
|
+
* @param headers - Optional response headers
|
|
124
|
+
*/
|
|
125
|
+
constructor(message: string, endpoint: string, requestId?: string, headers?: Headers);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Error thrown for HTTP 404 Not Found responses.
|
|
129
|
+
*
|
|
130
|
+
* Indicates the requested resource does not exist.
|
|
131
|
+
*/
|
|
132
|
+
export declare class ListmonkNotFoundError extends ListmonkApiError {
|
|
133
|
+
readonly name: string;
|
|
134
|
+
readonly status: number;
|
|
135
|
+
/**
|
|
136
|
+
* Creates a new not found error.
|
|
137
|
+
*
|
|
138
|
+
* @param message - Error message
|
|
139
|
+
* @param endpoint - The API endpoint
|
|
140
|
+
* @param requestId - Optional X-Request-ID
|
|
141
|
+
* @param headers - Optional response headers
|
|
142
|
+
*/
|
|
143
|
+
constructor(message: string, endpoint: string, requestId?: string, headers?: Headers);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Error thrown for HTTP 429 Too Many Requests responses.
|
|
147
|
+
*
|
|
148
|
+
* Indicates the rate limit has been exceeded. Check the `retryAfter`
|
|
149
|
+
* property for the recommended wait time before retrying.
|
|
150
|
+
*/
|
|
151
|
+
export declare class ListmonkRateLimitError extends ListmonkApiError {
|
|
152
|
+
readonly name: string;
|
|
153
|
+
readonly status: number;
|
|
154
|
+
/**
|
|
155
|
+
* Seconds to wait before retrying (from Retry-After header).
|
|
156
|
+
* Capped at 60 seconds per SDK requirements.
|
|
157
|
+
*/
|
|
158
|
+
readonly retryAfter?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Creates a new rate limit error.
|
|
161
|
+
*
|
|
162
|
+
* @param message - Error message
|
|
163
|
+
* @param body - Response body
|
|
164
|
+
* @param endpoint - The API endpoint
|
|
165
|
+
* @param retryAfter - Seconds to wait before retrying (capped at 60)
|
|
166
|
+
* @param requestId - Optional X-Request-ID
|
|
167
|
+
* @param headers - Optional response headers
|
|
168
|
+
*/
|
|
169
|
+
constructor(message: string, body: unknown, endpoint: string, retryAfter?: number, requestId?: string, headers?: Headers);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Error thrown for HTTP 5xx Server Error responses.
|
|
173
|
+
*
|
|
174
|
+
* Indicates a server-side error. These errors are typically retryable.
|
|
175
|
+
*/
|
|
176
|
+
export declare class ListmonkInternalServerError extends ListmonkApiError {
|
|
177
|
+
readonly name: string;
|
|
178
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all listmonk SDK errors.
|
|
3
|
+
*
|
|
4
|
+
* All SDK-specific errors extend this class, enabling unified error handling
|
|
5
|
+
* via `instanceof ListmonkError`.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* try {
|
|
10
|
+
* await client.subscribers.get(123);
|
|
11
|
+
* } catch (error) {
|
|
12
|
+
* if (error instanceof ListmonkError) {
|
|
13
|
+
* console.error('SDK error:', error.message);
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* @module errors/base
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Abstract base class for all listmonk SDK errors.
|
|
22
|
+
*
|
|
23
|
+
* Provides proper prototype chain maintenance and stack trace capture
|
|
24
|
+
* for all SDK error types.
|
|
25
|
+
*/
|
|
26
|
+
export declare abstract class ListmonkError extends Error {
|
|
27
|
+
/**
|
|
28
|
+
* The name of the error class.
|
|
29
|
+
* Must be overridden by subclasses to provide a unique identifier.
|
|
30
|
+
*/
|
|
31
|
+
abstract readonly name: string;
|
|
32
|
+
/**
|
|
33
|
+
* The underlying cause of this error, if any.
|
|
34
|
+
* Useful for error chaining when wrapping lower-level errors.
|
|
35
|
+
*/
|
|
36
|
+
readonly cause?: unknown;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new ListmonkError instance.
|
|
39
|
+
*
|
|
40
|
+
* @param message - Human-readable error message
|
|
41
|
+
* @param options - Optional error options
|
|
42
|
+
* @param options.cause - The underlying error that caused this error
|
|
43
|
+
*/
|
|
44
|
+
constructor(message: string, options?: {
|
|
45
|
+
cause?: unknown;
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration error for invalid SDK options.
|
|
3
|
+
*
|
|
4
|
+
* Thrown when the SDK is initialized with invalid configuration,
|
|
5
|
+
* such as missing credentials or invalid URLs.
|
|
6
|
+
*
|
|
7
|
+
* @module errors/configuration
|
|
8
|
+
*/
|
|
9
|
+
import { ListmonkError } from "./base";
|
|
10
|
+
/**
|
|
11
|
+
* Error thrown when SDK configuration is invalid.
|
|
12
|
+
*
|
|
13
|
+
* Common scenarios:
|
|
14
|
+
* - Missing or invalid URL
|
|
15
|
+
* - HTTP URL instead of HTTPS
|
|
16
|
+
* - Missing authentication credentials
|
|
17
|
+
* - Invalid timeout or retry values
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* try {
|
|
22
|
+
* const client = new Listmonk({
|
|
23
|
+
* url: 'http://example.com', // HTTP not allowed
|
|
24
|
+
* auth: { username: 'user', password: 'pass' },
|
|
25
|
+
* });
|
|
26
|
+
* } catch (error) {
|
|
27
|
+
* if (error instanceof ListmonkConfigurationError) {
|
|
28
|
+
* console.error(`Config error in ${error.field}:`, error.message);
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class ListmonkConfigurationError extends ListmonkError {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
/**
|
|
36
|
+
* The configuration field that caused the error, if identifiable.
|
|
37
|
+
*/
|
|
38
|
+
readonly field?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Creates a new configuration error.
|
|
41
|
+
*
|
|
42
|
+
* @param message - Description of the configuration problem
|
|
43
|
+
* @param options - Optional additional details
|
|
44
|
+
* @param options.field - The specific field that is invalid
|
|
45
|
+
*/
|
|
46
|
+
constructor(message: string, options?: {
|
|
47
|
+
field?: string;
|
|
48
|
+
});
|
|
49
|
+
}
|