@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.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +542 -0
  3. package/dist/chunk-saezhne8.js +14 -0
  4. package/dist/chunk-saezhne8.js.map +9 -0
  5. package/dist/client.d.ts +430 -0
  6. package/dist/errors/api.d.ts +178 -0
  7. package/dist/errors/base.d.ts +47 -0
  8. package/dist/errors/configuration.d.ts +49 -0
  9. package/dist/errors/index.d.ts +13 -0
  10. package/dist/errors/network.d.ts +69 -0
  11. package/dist/errors/validation.d.ts +57 -0
  12. package/dist/http/auth.d.ts +39 -0
  13. package/dist/http/client.d.ts +149 -0
  14. package/dist/http/hooks.d.ts +90 -0
  15. package/dist/http/index.d.ts +10 -0
  16. package/dist/http/resource.d.ts +100 -0
  17. package/dist/http/sse.d.ts +36 -0
  18. package/dist/http/url.d.ts +51 -0
  19. package/dist/index.d.ts +64 -0
  20. package/dist/index.js +16039 -0
  21. package/dist/index.js.map +120 -0
  22. package/dist/resources/admin/admin.d.ts +92 -0
  23. package/dist/resources/admin/index.d.ts +10 -0
  24. package/dist/resources/admin/schemas.d.ts +23 -0
  25. package/dist/resources/admin/types.d.ts +29 -0
  26. package/dist/resources/bounces/bounces.d.ts +262 -0
  27. package/dist/resources/bounces/index.d.ts +10 -0
  28. package/dist/resources/bounces/schemas.d.ts +86 -0
  29. package/dist/resources/bounces/types.d.ts +37 -0
  30. package/dist/resources/campaigns/campaigns.d.ts +339 -0
  31. package/dist/resources/campaigns/index.d.ts +10 -0
  32. package/dist/resources/campaigns/schemas.d.ts +374 -0
  33. package/dist/resources/campaigns/types.d.ts +111 -0
  34. package/dist/resources/dashboard/dashboard.d.ts +73 -0
  35. package/dist/resources/dashboard/index.d.ts +10 -0
  36. package/dist/resources/dashboard/schemas.d.ts +55 -0
  37. package/dist/resources/dashboard/types.d.ts +22 -0
  38. package/dist/resources/import/import.d.ts +215 -0
  39. package/dist/resources/import/index.d.ts +10 -0
  40. package/dist/resources/import/schemas.d.ts +109 -0
  41. package/dist/resources/import/types.d.ts +72 -0
  42. package/dist/resources/lists/index.d.ts +10 -0
  43. package/dist/resources/lists/lists.d.ts +180 -0
  44. package/dist/resources/lists/schemas.d.ts +176 -0
  45. package/dist/resources/lists/types.d.ts +56 -0
  46. package/dist/resources/maintenance/index.d.ts +10 -0
  47. package/dist/resources/maintenance/maintenance.d.ts +92 -0
  48. package/dist/resources/maintenance/schemas.d.ts +36 -0
  49. package/dist/resources/maintenance/types.d.ts +31 -0
  50. package/dist/resources/media/index.d.ts +10 -0
  51. package/dist/resources/media/media.d.ts +198 -0
  52. package/dist/resources/media/schemas.d.ts +48 -0
  53. package/dist/resources/media/types.d.ts +48 -0
  54. package/dist/resources/public/index.d.ts +10 -0
  55. package/dist/resources/public/public.d.ts +111 -0
  56. package/dist/resources/public/schemas.d.ts +52 -0
  57. package/dist/resources/public/types.d.ts +30 -0
  58. package/dist/resources/settings/index.d.ts +10 -0
  59. package/dist/resources/settings/schemas.d.ts +374 -0
  60. package/dist/resources/settings/settings.d.ts +106 -0
  61. package/dist/resources/settings/types.d.ts +78 -0
  62. package/dist/resources/subscribers/index.d.ts +10 -0
  63. package/dist/resources/subscribers/schemas.d.ts +360 -0
  64. package/dist/resources/subscribers/subscribers.d.ts +308 -0
  65. package/dist/resources/subscribers/types.d.ts +113 -0
  66. package/dist/resources/templates/index.d.ts +10 -0
  67. package/dist/resources/templates/schemas.d.ts +110 -0
  68. package/dist/resources/templates/templates.d.ts +225 -0
  69. package/dist/resources/templates/types.d.ts +45 -0
  70. package/dist/resources/tx/index.d.ts +10 -0
  71. package/dist/resources/tx/schemas.d.ts +67 -0
  72. package/dist/resources/tx/tx.d.ts +167 -0
  73. package/dist/resources/tx/types.d.ts +88 -0
  74. package/dist/schemas/common.d.ts +48 -0
  75. package/dist/schemas/index.d.ts +6 -0
  76. package/dist/testing/errors.d.ts +25 -0
  77. package/dist/testing/factories/bounce.d.ts +43 -0
  78. package/dist/testing/factories/campaign.d.ts +43 -0
  79. package/dist/testing/factories/common.d.ts +54 -0
  80. package/dist/testing/factories/index.d.ts +12 -0
  81. package/dist/testing/factories/list.d.ts +43 -0
  82. package/dist/testing/factories/media.d.ts +40 -0
  83. package/dist/testing/factories/subscriber.d.ts +43 -0
  84. package/dist/testing/factories/template.d.ts +40 -0
  85. package/dist/testing/index.d.ts +39 -0
  86. package/dist/testing/index.js +573 -0
  87. package/dist/testing/index.js.map +32 -0
  88. package/dist/testing/mock-client.d.ts +119 -0
  89. package/dist/testing/mock-function.d.ts +28 -0
  90. package/dist/testing/resources/admin.d.ts +20 -0
  91. package/dist/testing/resources/bounces.d.ts +22 -0
  92. package/dist/testing/resources/campaigns.d.ts +31 -0
  93. package/dist/testing/resources/dashboard.d.ts +17 -0
  94. package/dist/testing/resources/import.d.ts +19 -0
  95. package/dist/testing/resources/index.d.ts +18 -0
  96. package/dist/testing/resources/lists.d.ts +24 -0
  97. package/dist/testing/resources/maintenance.d.ts +18 -0
  98. package/dist/testing/resources/media.d.ts +21 -0
  99. package/dist/testing/resources/public.d.ts +18 -0
  100. package/dist/testing/resources/settings.d.ts +19 -0
  101. package/dist/testing/resources/subscribers.d.ts +33 -0
  102. package/dist/testing/resources/templates.d.ts +24 -0
  103. package/dist/testing/resources/tx.d.ts +16 -0
  104. package/dist/testing/types.d.ts +138 -0
  105. package/dist/types/config.d.ts +59 -0
  106. package/dist/types/index.d.ts +7 -0
  107. package/dist/types/pagination.d.ts +37 -0
  108. package/package.json +97 -0
@@ -0,0 +1,339 @@
1
+ /**
2
+ * Campaigns resource for managing email campaigns.
3
+ *
4
+ * @module resources/campaigns
5
+ */
6
+ import { APIResource } from "../../http/resource";
7
+ import type { Campaign, CampaignStats, AnalyticsData, LinkAnalytics, AnalyticsType, CampaignContentType, CreateCampaignRequest, UpdateCampaignRequest, ListCampaignsOptions, ListCampaignsResponse, SendTestRequest, ArchiveRequest, GetAnalyticsOptions, PreviewResponse, PreviewOptions, CampaignStatus } from "./types";
8
+ import type { PagedAsyncIterableIterator } from "../../types/pagination";
9
+ /**
10
+ * Resource for managing email campaigns in listmonk.
11
+ *
12
+ * Provides methods for CRUD operations, status management, pagination,
13
+ * preview generation, analytics, test sending, and archive management.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // Access via client
18
+ * const campaign = await client.campaigns.create({
19
+ * name: 'Weekly Newsletter',
20
+ * subject: 'This Week in Tech',
21
+ * lists: [1, 2],
22
+ * body: '<h1>Hello!</h1>',
23
+ * content_type: 'html',
24
+ * });
25
+ * ```
26
+ */
27
+ export declare class CampaignsResource extends APIResource {
28
+ /**
29
+ * Creates a new campaign.
30
+ *
31
+ * The campaign is created in `draft` status and can be edited
32
+ * before starting or scheduling.
33
+ *
34
+ * @param data - Campaign data
35
+ * @returns The created campaign
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const campaign = await client.campaigns.create({
40
+ * name: 'Weekly Newsletter',
41
+ * subject: 'This Week in Tech',
42
+ * lists: [1, 2],
43
+ * body: '<h1>Hello {{ .Subscriber.FirstName }}!</h1>',
44
+ * content_type: 'html',
45
+ * template_id: 1,
46
+ * tags: ['newsletter', 'weekly'],
47
+ * });
48
+ * ```
49
+ */
50
+ create(data: CreateCampaignRequest): Promise<Campaign>;
51
+ /**
52
+ * Retrieves a campaign by ID.
53
+ *
54
+ * @param id - Campaign ID
55
+ * @param options - Optional query parameters
56
+ * @param options.no_body - Exclude body field from response
57
+ * @returns The campaign
58
+ * @throws {ListmonkNotFoundError} If campaign not found
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const campaign = await client.campaigns.retrieve(123);
63
+ * console.log(campaign.name, campaign.status);
64
+ * ```
65
+ */
66
+ retrieve(id: number, options?: {
67
+ no_body?: boolean;
68
+ }): Promise<Campaign>;
69
+ /**
70
+ * Updates an existing campaign.
71
+ *
72
+ * All fields are optional - only provided fields are updated.
73
+ * Note: Only draft, scheduled, or paused campaigns can be fully updated.
74
+ * Running campaigns can only update tags and archive_meta.
75
+ *
76
+ * @param id - Campaign ID
77
+ * @param data - Updated campaign data
78
+ * @returns The updated campaign
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const updated = await client.campaigns.update(123, {
83
+ * subject: 'Updated Subject Line',
84
+ * tags: ['newsletter', 'updated'],
85
+ * });
86
+ * ```
87
+ */
88
+ update(id: number, data: UpdateCampaignRequest): Promise<Campaign>;
89
+ /**
90
+ * Deletes a campaign by ID.
91
+ *
92
+ * @param id - Campaign ID
93
+ * @throws {ListmonkNotFoundError} If campaign not found
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * await client.campaigns.remove(123);
98
+ * ```
99
+ */
100
+ remove(id: number): Promise<void>;
101
+ /**
102
+ * Lists campaigns with pagination and filtering.
103
+ *
104
+ * @param options - Query options
105
+ * @returns Paginated campaign response
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * const page = await client.campaigns.list({
110
+ * status: ['running', 'scheduled'],
111
+ * order_by: 'created_at',
112
+ * order: 'DESC',
113
+ * per_page: 50,
114
+ * });
115
+ * console.log(`Found ${page.total} campaigns`);
116
+ * ```
117
+ */
118
+ list(options?: ListCampaignsOptions): Promise<ListCampaignsResponse>;
119
+ /**
120
+ * Returns an async iterator over all campaigns matching the options.
121
+ *
122
+ * Pages are fetched on-demand as you iterate. The iterator also
123
+ * provides a `byPage()` method for page-level iteration.
124
+ *
125
+ * @param options - Query options (page is ignored, starts from 1)
126
+ * @returns Async iterator over campaigns
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * // Iterate over all campaigns
131
+ * for await (const campaign of client.campaigns.listAll()) {
132
+ * console.log(campaign.name, campaign.status);
133
+ * }
134
+ *
135
+ * // Iterate over pages
136
+ * for await (const page of client.campaigns.listAll().byPage()) {
137
+ * console.log(`Page ${page.page} has ${page.results.length} items`);
138
+ * }
139
+ * ```
140
+ */
141
+ listAll(options?: Omit<ListCampaignsOptions, "page">): PagedAsyncIterableIterator<Campaign, ListCampaignsResponse>;
142
+ /**
143
+ * Changes the status of a campaign.
144
+ *
145
+ * Valid transitions:
146
+ * - `draft` -> `scheduled` (requires send_at), `running`
147
+ * - `scheduled` -> `draft`, `running`
148
+ * - `running` -> `paused`, `cancelled`
149
+ * - `paused` -> `running`
150
+ *
151
+ * @param id - Campaign ID
152
+ * @param status - Target status
153
+ * @param options - Additional options (send_at required for 'scheduled')
154
+ * @returns The updated campaign
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * // Start a campaign immediately
159
+ * await client.campaigns.updateStatus(123, 'running');
160
+ *
161
+ * // Schedule for later
162
+ * await client.campaigns.updateStatus(123, 'scheduled', {
163
+ * send_at: '2026-02-01T10:00:00Z',
164
+ * });
165
+ *
166
+ * // Pause a running campaign
167
+ * await client.campaigns.updateStatus(123, 'paused');
168
+ *
169
+ * // Resume a paused campaign
170
+ * await client.campaigns.updateStatus(123, 'running');
171
+ * ```
172
+ */
173
+ updateStatus(id: number, status: Exclude<CampaignStatus, "finished">, options?: {
174
+ send_at?: string;
175
+ }): Promise<Campaign>;
176
+ /**
177
+ * Generates an HTML preview of the campaign.
178
+ *
179
+ * @param id - Campaign ID
180
+ * @param options - Preview options
181
+ * @param options.subscriber_id - Subscriber ID for personalization
182
+ * @param options.data - Custom template data
183
+ * @returns The preview response with rendered HTML
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // Basic preview
188
+ * const preview = await client.campaigns.preview(123);
189
+ * console.log(preview.body);
190
+ *
191
+ * // Preview with subscriber personalization
192
+ * const personalized = await client.campaigns.preview(123, {
193
+ * subscriber_id: 456,
194
+ * });
195
+ *
196
+ * // Preview with custom template data
197
+ * const custom = await client.campaigns.preview(123, {
198
+ * data: {
199
+ * Subscriber: { FirstName: 'John' },
200
+ * },
201
+ * });
202
+ * ```
203
+ */
204
+ preview(id: number, options?: PreviewOptions): Promise<PreviewResponse>;
205
+ /**
206
+ * Generates a plain text preview of the campaign.
207
+ *
208
+ * @param id - Campaign ID
209
+ * @returns The preview response with plain text content
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * const textPreview = await client.campaigns.previewText(123);
214
+ * console.log(textPreview.body);
215
+ * ```
216
+ */
217
+ previewText(id: number): Promise<PreviewResponse>;
218
+ /**
219
+ * Retrieves real-time statistics for running campaigns.
220
+ *
221
+ * @param ids - Campaign IDs to get stats for
222
+ * @returns Array of campaign statistics
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const stats = await client.campaigns.getRunningStats([1, 2, 3]);
227
+ * for (const stat of stats) {
228
+ * const progress = (stat.sent / stat.to_send * 100).toFixed(1);
229
+ * console.log(`${stat.name}: ${progress}% (${stat.rate} msg/s)`);
230
+ * }
231
+ * ```
232
+ */
233
+ getRunningStats(ids: number[]): Promise<CampaignStats[]>;
234
+ /**
235
+ * Retrieves analytics data for campaigns.
236
+ *
237
+ * @param type - Analytics type ('views', 'clicks', 'links', 'bounces')
238
+ * @param options - Query options
239
+ * @returns Analytics data (time-series for views/clicks/bounces, per-URL for links)
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * // Get view counts over time
244
+ * const views = await client.campaigns.getAnalytics('views', {
245
+ * id: [123],
246
+ * from: '2026-01-01T00:00:00Z',
247
+ * to: '2026-01-31T23:59:59Z',
248
+ * });
249
+ *
250
+ * // Get per-link click breakdown
251
+ * const links = await client.campaigns.getAnalytics('links', {
252
+ * id: [123],
253
+ * });
254
+ * for (const link of links) {
255
+ * console.log(`${link.url}: ${link.count} clicks`);
256
+ * }
257
+ * ```
258
+ */
259
+ getAnalytics(type: AnalyticsType, options?: GetAnalyticsOptions): Promise<AnalyticsData[] | LinkAnalytics[]>;
260
+ /**
261
+ * Sends a test campaign to specified email addresses.
262
+ *
263
+ * @param id - Campaign ID
264
+ * @param options - Test send options
265
+ * @param options.subscribers - Email addresses to send test to
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * await client.campaigns.sendTest(123, {
270
+ * subscribers: ['test1@example.com', 'test2@example.com'],
271
+ * });
272
+ * ```
273
+ */
274
+ sendTest(id: number, options: SendTestRequest): Promise<void>;
275
+ /**
276
+ * Archives or unarchives a campaign to/from the public archive.
277
+ *
278
+ * @param id - Campaign ID
279
+ * @param archive - Whether to archive (true) or unarchive (false)
280
+ * @param options - Additional archive options
281
+ * @returns The updated campaign
282
+ *
283
+ * @example
284
+ * ```typescript
285
+ * // Archive a campaign
286
+ * await client.campaigns.archive(123, true, {
287
+ * archive_slug: 'january-newsletter',
288
+ * archive_template_id: 2,
289
+ * });
290
+ *
291
+ * // Unarchive a campaign
292
+ * await client.campaigns.archive(123, false);
293
+ * ```
294
+ */
295
+ archive(id: number, archive?: boolean, options?: Omit<ArchiveRequest, "archive">): Promise<Campaign>;
296
+ /**
297
+ * Converts campaign content between formats.
298
+ *
299
+ * Note: Conversions are best-effort. Some formatting may be lost,
300
+ * especially when converting from rich formats to plain text.
301
+ *
302
+ * @param id - Campaign ID
303
+ * @param to - Target content format
304
+ * @returns The converted content
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * // Convert markdown to HTML
309
+ * const html = await client.campaigns.convertContent(123, 'html');
310
+ * console.log(html.body);
311
+ *
312
+ * // Convert to plain text
313
+ * const plain = await client.campaigns.convertContent(123, 'plain');
314
+ * ```
315
+ */
316
+ convertContent(id: number, to: CampaignContentType): Promise<PreviewResponse>;
317
+ /**
318
+ * Deletes multiple campaigns by ID.
319
+ *
320
+ * @param ids - Campaign IDs to delete
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * await client.campaigns.deleteMany([1, 2, 3]);
325
+ * ```
326
+ */
327
+ deleteMany(ids: number[]): Promise<void>;
328
+ /**
329
+ * Deletes campaigns matching a SQL-style query.
330
+ *
331
+ * @param query - SQL-style query expression
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * await client.campaigns.deleteByQuery("campaigns.status = 'draft'");
336
+ * ```
337
+ */
338
+ deleteByQuery(query: string): Promise<void>;
339
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Campaigns resource module.
3
+ *
4
+ * Provides complete campaign lifecycle management for the listmonk API.
5
+ *
6
+ * @module resources/campaigns
7
+ */
8
+ export { CampaignsResource } from "./campaigns";
9
+ export type { Campaign, CampaignStatus, CampaignType, CampaignContentType, AnalyticsType, Header, CampaignList, CampaignStats, AnalyticsData, LinkAnalytics, CreateCampaignRequest, UpdateCampaignRequest, ListCampaignsOptions, ListCampaignsResponse, UpdateStatusRequest, SendTestRequest, ArchiveRequest, GetAnalyticsOptions, PreviewResponse, PreviewOptions, BulkDeleteByQueryRequest, } from "./types";
10
+ export { CampaignStatusSchema, CampaignTypeSchema, CampaignContentTypeSchema, AnalyticsTypeSchema, HeaderSchema, CampaignListSchema, CampaignSchema, CampaignStatsSchema, AnalyticsDataSchema, LinkAnalyticsSchema, CreateCampaignRequestSchema, UpdateCampaignRequestSchema, ListCampaignsOptionsSchema, ListCampaignsResponseSchema, UpdateStatusRequestSchema, SendTestRequestSchema, ArchiveRequestSchema, GetAnalyticsOptionsSchema, PreviewResponseSchema, PreviewOptionsSchema, BulkDeleteByQueryRequestSchema, } from "./schemas";