@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
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Templates resource for managing email templates.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/templates
|
|
5
|
+
*/
|
|
6
|
+
import { APIResource } from "../../http/resource";
|
|
7
|
+
import type { Template, TemplatePreview, CreateTemplateRequest, UpdateTemplateRequest, ListTemplatesOptions, LivePreviewRequest } from "./types";
|
|
8
|
+
import type { PagedAsyncIterableIterator } from "../../types/pagination";
|
|
9
|
+
/**
|
|
10
|
+
* Resource for managing email templates in listmonk.
|
|
11
|
+
*
|
|
12
|
+
* Provides methods for CRUD operations, listing, preview generation,
|
|
13
|
+
* default template management, and bulk deletion.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Access via client
|
|
18
|
+
* const template = await client.templates.create({
|
|
19
|
+
* name: 'Newsletter Template',
|
|
20
|
+
* body: '<html>{{ template "content" . }}</html>',
|
|
21
|
+
* type: 'campaign',
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class TemplatesResource extends APIResource {
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new template.
|
|
28
|
+
*
|
|
29
|
+
* @param data - Template data
|
|
30
|
+
* @returns The created template
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Create a campaign template
|
|
35
|
+
* const template = await client.templates.create({
|
|
36
|
+
* name: 'Weekly Newsletter',
|
|
37
|
+
* type: 'campaign',
|
|
38
|
+
* body: `
|
|
39
|
+
* <html>
|
|
40
|
+
* <body>
|
|
41
|
+
* <h1>{{ .Campaign.Name }}</h1>
|
|
42
|
+
* {{ template "content" . }}
|
|
43
|
+
* <p><a href="{{ .UnsubscribeURL }}">Unsubscribe</a></p>
|
|
44
|
+
* </body>
|
|
45
|
+
* </html>
|
|
46
|
+
* `,
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Create a transactional template (requires subject)
|
|
50
|
+
* const txTemplate = await client.templates.create({
|
|
51
|
+
* name: 'Order Confirmation',
|
|
52
|
+
* type: 'tx',
|
|
53
|
+
* subject: 'Your Order #{{ .Tx.Data.order_id }}',
|
|
54
|
+
* body: '<html><body>Thank you for your order!</body></html>',
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
create(data: CreateTemplateRequest): Promise<Template>;
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves a template by ID.
|
|
61
|
+
*
|
|
62
|
+
* @param id - Template ID
|
|
63
|
+
* @returns The template
|
|
64
|
+
* @throws {ListmonkNotFoundError} If template not found
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const template = await client.templates.retrieve(1);
|
|
69
|
+
* console.log(template.name, template.type);
|
|
70
|
+
* console.log(`Default: ${template.is_default}`);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
retrieve(id: number): Promise<Template>;
|
|
74
|
+
/**
|
|
75
|
+
* Updates an existing template.
|
|
76
|
+
*
|
|
77
|
+
* All fields are optional - only provided fields are updated.
|
|
78
|
+
*
|
|
79
|
+
* @param id - Template ID
|
|
80
|
+
* @param data - Updated template data
|
|
81
|
+
* @returns The updated template
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const updated = await client.templates.update(1, {
|
|
86
|
+
* name: 'Updated Newsletter Template',
|
|
87
|
+
* body: '<html><body>New content {{ template "content" . }}</body></html>',
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
update(id: number, data: UpdateTemplateRequest): Promise<Template>;
|
|
92
|
+
/**
|
|
93
|
+
* Deletes a template by ID.
|
|
94
|
+
*
|
|
95
|
+
* Note: Templates referenced by active campaigns cannot be deleted.
|
|
96
|
+
*
|
|
97
|
+
* @param id - Template ID
|
|
98
|
+
* @throws {ListmonkNotFoundError} If template not found
|
|
99
|
+
* @throws {ListmonkApiError} If template is in use (409 Conflict)
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* await client.templates.remove(5);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
remove(id: number): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Lists all templates.
|
|
109
|
+
*
|
|
110
|
+
* Note: The listmonk templates API returns all templates at once
|
|
111
|
+
* without pagination.
|
|
112
|
+
*
|
|
113
|
+
* @param options - Query options
|
|
114
|
+
* @param options.no_body - Exclude body field from response
|
|
115
|
+
* @returns Array of templates
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // List all templates
|
|
120
|
+
* const templates = await client.templates.list();
|
|
121
|
+
* console.log(`Found ${templates.length} templates`);
|
|
122
|
+
*
|
|
123
|
+
* // List without body content (lighter response)
|
|
124
|
+
* const lightTemplates = await client.templates.list({ no_body: true });
|
|
125
|
+
* for (const template of lightTemplates) {
|
|
126
|
+
* console.log(`${template.name} (${template.type})`);
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
list(options?: ListTemplatesOptions): Promise<Template[]>;
|
|
131
|
+
/**
|
|
132
|
+
* Returns an async iterator over all templates.
|
|
133
|
+
*
|
|
134
|
+
* Note: Since the templates API doesn't support pagination, this
|
|
135
|
+
* iterator yields all templates in a single batch. The `byPage()`
|
|
136
|
+
* method yields a single "page" containing all templates.
|
|
137
|
+
*
|
|
138
|
+
* This method is provided for API consistency with other resources.
|
|
139
|
+
*
|
|
140
|
+
* @param options - Query options
|
|
141
|
+
* @returns Async iterator over templates
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* // Iterate over all templates
|
|
146
|
+
* for await (const template of client.templates.listAll()) {
|
|
147
|
+
* console.log(template.name);
|
|
148
|
+
* }
|
|
149
|
+
*
|
|
150
|
+
* // Iterate by "page" (single page for templates)
|
|
151
|
+
* for await (const templates of client.templates.listAll().byPage()) {
|
|
152
|
+
* console.log(`Templates in batch: ${templates.length}`);
|
|
153
|
+
* }
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
listAll(options?: ListTemplatesOptions): PagedAsyncIterableIterator<Template, Template[]>;
|
|
157
|
+
/**
|
|
158
|
+
* Generates a preview of a template.
|
|
159
|
+
*
|
|
160
|
+
* @param id - Template ID for stored template preview
|
|
161
|
+
* @returns The preview response with rendered HTML
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* // Preview a stored template
|
|
166
|
+
* const preview = await client.templates.preview(1);
|
|
167
|
+
* console.log(preview.body);
|
|
168
|
+
* ```
|
|
169
|
+
*/
|
|
170
|
+
preview(id: number): Promise<TemplatePreview>;
|
|
171
|
+
/**
|
|
172
|
+
* Generates a live preview from template content.
|
|
173
|
+
*
|
|
174
|
+
* @param id - Must be null for live preview
|
|
175
|
+
* @param options - Live preview options
|
|
176
|
+
* @returns The preview response with rendered HTML
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* // Live preview (without saving)
|
|
181
|
+
* const livePreview = await client.templates.preview(null, {
|
|
182
|
+
* template_type: 'campaign',
|
|
183
|
+
* body: '<html>{{ template "content" . }}</html>',
|
|
184
|
+
* });
|
|
185
|
+
* console.log(livePreview.body);
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
preview(id: null, options: LivePreviewRequest): Promise<TemplatePreview>;
|
|
189
|
+
/**
|
|
190
|
+
* Sets a template as the default template for new campaigns.
|
|
191
|
+
*
|
|
192
|
+
* Note: Only one template can be the default at a time.
|
|
193
|
+
* Setting a new default automatically removes the previous default.
|
|
194
|
+
*
|
|
195
|
+
* @param id - Template ID
|
|
196
|
+
* @returns The updated template with is_default: true
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const defaultTemplate = await client.templates.setDefault(2);
|
|
201
|
+
* console.log(`${defaultTemplate.name} is now the default template`);
|
|
202
|
+
*
|
|
203
|
+
* // Find current default
|
|
204
|
+
* const templates = await client.templates.list();
|
|
205
|
+
* const currentDefault = templates.find(t => t.is_default);
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
setDefault(id: number): Promise<Template>;
|
|
209
|
+
/**
|
|
210
|
+
* Deletes multiple templates by ID.
|
|
211
|
+
*
|
|
212
|
+
* Note: The listmonk API does not support bulk template deletion,
|
|
213
|
+
* so this method deletes templates sequentially. If any deletion
|
|
214
|
+
* fails (e.g., template is in use), the error is thrown immediately
|
|
215
|
+
* and remaining templates are not deleted.
|
|
216
|
+
*
|
|
217
|
+
* @param ids - Template IDs to delete
|
|
218
|
+
*
|
|
219
|
+
* @example
|
|
220
|
+
* ```typescript
|
|
221
|
+
* await client.templates.deleteMany([3, 4, 5]);
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
deleteMany(ids: number[]): Promise<void>;
|
|
225
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for templates module.
|
|
3
|
+
*
|
|
4
|
+
* All types are inferred from Zod schemas to ensure runtime
|
|
5
|
+
* validation matches compile-time types.
|
|
6
|
+
*
|
|
7
|
+
* @module resources/templates/types
|
|
8
|
+
*/
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
import type { TemplateTypeSchema, TemplateSchema, TemplatePreviewSchema, CreateTemplateRequestSchema, UpdateTemplateRequestSchema, ListTemplatesOptionsSchema, LivePreviewRequestSchema, ListTemplatesResponseSchema } from "./schemas";
|
|
11
|
+
/**
|
|
12
|
+
* Template type.
|
|
13
|
+
* - `campaign`: Standard campaign email templates
|
|
14
|
+
* - `campaign_visual`: Visual drag-and-drop editor templates
|
|
15
|
+
* - `tx`: Transactional email templates
|
|
16
|
+
*/
|
|
17
|
+
export type TemplateType = z.infer<typeof TemplateTypeSchema>;
|
|
18
|
+
/**
|
|
19
|
+
* Complete template entity.
|
|
20
|
+
*/
|
|
21
|
+
export type Template = z.infer<typeof TemplateSchema>;
|
|
22
|
+
/**
|
|
23
|
+
* Template preview response.
|
|
24
|
+
*/
|
|
25
|
+
export type TemplatePreview = z.infer<typeof TemplatePreviewSchema>;
|
|
26
|
+
/**
|
|
27
|
+
* Request to create a new template (input type).
|
|
28
|
+
*/
|
|
29
|
+
export type CreateTemplateRequest = z.input<typeof CreateTemplateRequestSchema>;
|
|
30
|
+
/**
|
|
31
|
+
* Request to update an existing template (input type).
|
|
32
|
+
*/
|
|
33
|
+
export type UpdateTemplateRequest = z.input<typeof UpdateTemplateRequestSchema>;
|
|
34
|
+
/**
|
|
35
|
+
* Options for listing templates (input type).
|
|
36
|
+
*/
|
|
37
|
+
export type ListTemplatesOptions = z.input<typeof ListTemplatesOptionsSchema>;
|
|
38
|
+
/**
|
|
39
|
+
* Request for live template preview (input type).
|
|
40
|
+
*/
|
|
41
|
+
export type LivePreviewRequest = z.input<typeof LivePreviewRequestSchema>;
|
|
42
|
+
/**
|
|
43
|
+
* Response for listing all templates.
|
|
44
|
+
*/
|
|
45
|
+
export type ListTemplatesResponse = z.infer<typeof ListTemplatesResponseSchema>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transactional resource module.
|
|
3
|
+
*
|
|
4
|
+
* Provides transactional email sending capabilities for the listmonk API.
|
|
5
|
+
*
|
|
6
|
+
* @module resources/tx
|
|
7
|
+
*/
|
|
8
|
+
export { TransactionalResource } from "./tx";
|
|
9
|
+
export type { SubscriberMode, TransactionalContentType, TransactionalAttachment, TransactionalRequest, SendTransactionalRequestInput, } from "./types";
|
|
10
|
+
export { SubscriberModeSchema, TransactionalContentTypeSchema, SendTransactionalRequestSchema, TransactionalResponseSchema, } from "./schemas";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for transactional module requests and responses.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/tx/schemas
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
/**
|
|
8
|
+
* Subscriber resolution mode for transactional messages.
|
|
9
|
+
*
|
|
10
|
+
* - `default`: Recipients MUST exist in subscriber database
|
|
11
|
+
* - `fallback`: Attempt lookup, send anyway if not found
|
|
12
|
+
* - `external`: No database lookup, send to any email
|
|
13
|
+
*/
|
|
14
|
+
export declare const SubscriberModeSchema: z.ZodEnum<{
|
|
15
|
+
default: "default";
|
|
16
|
+
external: "external";
|
|
17
|
+
fallback: "fallback";
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Content type for transactional messages.
|
|
21
|
+
*
|
|
22
|
+
* - `html`: HTML content (default)
|
|
23
|
+
* - `markdown`: Markdown rendered to HTML
|
|
24
|
+
* - `plain`: Plain text
|
|
25
|
+
*/
|
|
26
|
+
export declare const TransactionalContentTypeSchema: z.ZodEnum<{
|
|
27
|
+
html: "html";
|
|
28
|
+
markdown: "markdown";
|
|
29
|
+
plain: "plain";
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Request schema for sending transactional messages.
|
|
33
|
+
*
|
|
34
|
+
* Validates that:
|
|
35
|
+
* - template_id is a positive integer (required)
|
|
36
|
+
* - At least one recipient is provided
|
|
37
|
+
* - Email addresses are valid format
|
|
38
|
+
* - Subscriber IDs are positive integers
|
|
39
|
+
*/
|
|
40
|
+
export declare const SendTransactionalRequestSchema: z.ZodObject<{
|
|
41
|
+
template_id: z.ZodNumber;
|
|
42
|
+
subscriber_email: z.ZodOptional<z.ZodString>;
|
|
43
|
+
subscriber_id: z.ZodOptional<z.ZodNumber>;
|
|
44
|
+
subscriber_emails: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
45
|
+
subscriber_ids: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
46
|
+
subscriber_mode: z.ZodOptional<z.ZodEnum<{
|
|
47
|
+
default: "default";
|
|
48
|
+
external: "external";
|
|
49
|
+
fallback: "fallback";
|
|
50
|
+
}>>;
|
|
51
|
+
from_email: z.ZodOptional<z.ZodString>;
|
|
52
|
+
subject: z.ZodOptional<z.ZodString>;
|
|
53
|
+
data: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
54
|
+
headers: z.ZodOptional<z.ZodArray<z.ZodRecord<z.ZodString, z.ZodString>>>;
|
|
55
|
+
content_type: z.ZodOptional<z.ZodEnum<{
|
|
56
|
+
html: "html";
|
|
57
|
+
markdown: "markdown";
|
|
58
|
+
plain: "plain";
|
|
59
|
+
}>>;
|
|
60
|
+
messenger: z.ZodOptional<z.ZodString>;
|
|
61
|
+
attachments: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
62
|
+
}, z.core.$strip>;
|
|
63
|
+
/**
|
|
64
|
+
* Response schema for transactional send.
|
|
65
|
+
* The API returns { data: true } on success.
|
|
66
|
+
*/
|
|
67
|
+
export declare const TransactionalResponseSchema: z.ZodBoolean;
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transactional resource for sending application-triggered emails.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/tx
|
|
5
|
+
*/
|
|
6
|
+
import { APIResource } from "../../http/resource";
|
|
7
|
+
import type { TransactionalRequest } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Resource for sending transactional messages via listmonk.
|
|
10
|
+
*
|
|
11
|
+
* Transactional messages are application-triggered emails like welcome emails,
|
|
12
|
+
* order confirmations, password resets, and other automated communications.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Send to an existing subscriber
|
|
17
|
+
* await client.tx.send({
|
|
18
|
+
* template_id: 2,
|
|
19
|
+
* subscriber_email: 'user@example.com',
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Send with template data
|
|
23
|
+
* await client.tx.send({
|
|
24
|
+
* template_id: 2,
|
|
25
|
+
* subscriber_email: 'user@example.com',
|
|
26
|
+
* data: {
|
|
27
|
+
* order_id: '12345',
|
|
28
|
+
* total: '$99.99',
|
|
29
|
+
* },
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // Send to external recipient (not in subscriber database)
|
|
33
|
+
* await client.tx.send({
|
|
34
|
+
* template_id: 2,
|
|
35
|
+
* subscriber_mode: 'external',
|
|
36
|
+
* subscriber_emails: ['guest@example.com'],
|
|
37
|
+
* data: { name: 'Guest User' },
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class TransactionalResource extends APIResource {
|
|
42
|
+
/**
|
|
43
|
+
* Sends a transactional message.
|
|
44
|
+
*
|
|
45
|
+
* @param request - The transactional message request
|
|
46
|
+
* @returns `true` on success
|
|
47
|
+
* @throws {ListmonkValidationError} If request validation fails
|
|
48
|
+
* @throws {ListmonkNotFoundError} If template not found
|
|
49
|
+
* @throws {ListmonkApiError} If subscriber not found (default mode), messenger not configured, etc.
|
|
50
|
+
*
|
|
51
|
+
* @example Send to a subscriber by email
|
|
52
|
+
* ```typescript
|
|
53
|
+
* await client.tx.send({
|
|
54
|
+
* template_id: 2,
|
|
55
|
+
* subscriber_email: 'user@example.com',
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Send to a subscriber by ID
|
|
60
|
+
* ```typescript
|
|
61
|
+
* await client.tx.send({
|
|
62
|
+
* template_id: 2,
|
|
63
|
+
* subscriber_id: 123,
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example Send to multiple subscribers
|
|
68
|
+
* ```typescript
|
|
69
|
+
* await client.tx.send({
|
|
70
|
+
* template_id: 2,
|
|
71
|
+
* subscriber_emails: ['user1@example.com', 'user2@example.com'],
|
|
72
|
+
* });
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example Send with template variables
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // Variables are accessible via {{ .Tx.Data.* }} in the template
|
|
78
|
+
* await client.tx.send({
|
|
79
|
+
* template_id: 2,
|
|
80
|
+
* subscriber_email: 'user@example.com',
|
|
81
|
+
* data: {
|
|
82
|
+
* order_id: '12345',
|
|
83
|
+
* total: '$99.99',
|
|
84
|
+
* items: ['Product A', 'Product B'],
|
|
85
|
+
* },
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* @example Send to external recipient (not in subscriber database)
|
|
90
|
+
* ```typescript
|
|
91
|
+
* await client.tx.send({
|
|
92
|
+
* template_id: 2,
|
|
93
|
+
* subscriber_mode: 'external',
|
|
94
|
+
* subscriber_emails: ['guest@example.com'],
|
|
95
|
+
* data: { name: 'Guest User' },
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* @example Send with fallback mode (try lookup, send anyway if not found)
|
|
100
|
+
* ```typescript
|
|
101
|
+
* await client.tx.send({
|
|
102
|
+
* template_id: 2,
|
|
103
|
+
* subscriber_mode: 'fallback',
|
|
104
|
+
* subscriber_emails: ['maybe-subscriber@example.com'],
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* @example Customize message properties
|
|
109
|
+
* ```typescript
|
|
110
|
+
* await client.tx.send({
|
|
111
|
+
* template_id: 2,
|
|
112
|
+
* subscriber_email: 'user@example.com',
|
|
113
|
+
* subject: 'Urgent: Your Order Has Shipped!',
|
|
114
|
+
* from_email: 'shipping@example.com',
|
|
115
|
+
* content_type: 'html',
|
|
116
|
+
* headers: [
|
|
117
|
+
* { 'X-Priority': '1' },
|
|
118
|
+
* { 'X-Campaign-ID': 'order-confirmation' },
|
|
119
|
+
* ],
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*
|
|
123
|
+
* @example Send with file attachments (Browser)
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const file = new File([pdfContent], 'invoice.pdf', { type: 'application/pdf' });
|
|
126
|
+
* await client.tx.send({
|
|
127
|
+
* template_id: 2,
|
|
128
|
+
* subscriber_email: 'user@example.com',
|
|
129
|
+
* attachments: [file],
|
|
130
|
+
* });
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @example Send with file attachments (Node.js)
|
|
134
|
+
* ```typescript
|
|
135
|
+
* import { readFileSync } from 'fs';
|
|
136
|
+
* await client.tx.send({
|
|
137
|
+
* template_id: 2,
|
|
138
|
+
* subscriber_email: 'user@example.com',
|
|
139
|
+
* attachments: [
|
|
140
|
+
* { filename: 'invoice.pdf', content: readFileSync('./invoice.pdf') },
|
|
141
|
+
* ],
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @example Send via alternative messenger
|
|
146
|
+
* ```typescript
|
|
147
|
+
* await client.tx.send({
|
|
148
|
+
* template_id: 2,
|
|
149
|
+
* subscriber_email: 'user@example.com',
|
|
150
|
+
* messenger: 'sms',
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
send(request: TransactionalRequest): Promise<boolean>;
|
|
155
|
+
/**
|
|
156
|
+
* Sends a transactional message with file attachments using multipart/form-data.
|
|
157
|
+
*
|
|
158
|
+
* @internal
|
|
159
|
+
*/
|
|
160
|
+
private sendWithAttachments;
|
|
161
|
+
/**
|
|
162
|
+
* Converts a TransactionalAttachment to a Blob suitable for FormData.
|
|
163
|
+
*
|
|
164
|
+
* @internal
|
|
165
|
+
*/
|
|
166
|
+
private toFormDataFile;
|
|
167
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for transactional module.
|
|
3
|
+
*
|
|
4
|
+
* All types are inferred from Zod schemas to ensure runtime
|
|
5
|
+
* validation matches compile-time types.
|
|
6
|
+
*
|
|
7
|
+
* @module resources/tx/types
|
|
8
|
+
*/
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
import type { SubscriberModeSchema, TransactionalContentTypeSchema, SendTransactionalRequestSchema } from "./schemas";
|
|
11
|
+
/**
|
|
12
|
+
* Subscriber resolution mode for transactional messages.
|
|
13
|
+
*
|
|
14
|
+
* - `default`: Recipients MUST exist in subscriber database
|
|
15
|
+
* - `fallback`: Attempt lookup, send anyway if not found
|
|
16
|
+
* - `external`: No database lookup, send to any email
|
|
17
|
+
*/
|
|
18
|
+
export type SubscriberMode = z.infer<typeof SubscriberModeSchema>;
|
|
19
|
+
/**
|
|
20
|
+
* Content type for transactional messages.
|
|
21
|
+
*
|
|
22
|
+
* - `html`: HTML content (default)
|
|
23
|
+
* - `markdown`: Markdown rendered to HTML
|
|
24
|
+
* - `plain`: Plain text
|
|
25
|
+
*/
|
|
26
|
+
export type TransactionalContentType = z.infer<typeof TransactionalContentTypeSchema>;
|
|
27
|
+
/**
|
|
28
|
+
* Attachment type for transactional messages.
|
|
29
|
+
*
|
|
30
|
+
* Supports multiple patterns for cross-runtime compatibility:
|
|
31
|
+
* - `File`: Web API File (browser, Node 20+, Bun, Deno)
|
|
32
|
+
* - `Blob`: Web API Blob (browser, Node 22+, Bun, Deno)
|
|
33
|
+
* - Object with filename and content: Node.js Buffer/Uint8Array pattern
|
|
34
|
+
*
|
|
35
|
+
* @example Browser (File API)
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const file = new File([pdfContent], 'invoice.pdf', { type: 'application/pdf' });
|
|
38
|
+
* await client.tx.send({ template_id: 1, subscriber_email: '...', attachments: [file] });
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* @example Node.js (Buffer pattern)
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import { readFileSync } from 'fs';
|
|
44
|
+
* const attachment = { filename: 'invoice.pdf', content: readFileSync('./invoice.pdf') };
|
|
45
|
+
* await client.tx.send({ template_id: 1, subscriber_email: '...', attachments: [attachment] });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export type TransactionalAttachment = File | Blob | {
|
|
49
|
+
filename: string;
|
|
50
|
+
content: Buffer | Uint8Array;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Input type for sending a transactional message.
|
|
54
|
+
*
|
|
55
|
+
* This is the user-facing input type that accepts TransactionalAttachment[].
|
|
56
|
+
*/
|
|
57
|
+
export interface TransactionalRequest {
|
|
58
|
+
/** ID of the transactional template to use (required) */
|
|
59
|
+
template_id: number;
|
|
60
|
+
/** Single recipient email address */
|
|
61
|
+
subscriber_email?: string;
|
|
62
|
+
/** Single recipient subscriber ID */
|
|
63
|
+
subscriber_id?: number;
|
|
64
|
+
/** Multiple recipient email addresses */
|
|
65
|
+
subscriber_emails?: string[];
|
|
66
|
+
/** Multiple recipient subscriber IDs */
|
|
67
|
+
subscriber_ids?: number[];
|
|
68
|
+
/** How to resolve recipients in the subscriber database */
|
|
69
|
+
subscriber_mode?: SubscriberMode;
|
|
70
|
+
/** Override sender email address */
|
|
71
|
+
from_email?: string;
|
|
72
|
+
/** Override template subject line */
|
|
73
|
+
subject?: string;
|
|
74
|
+
/** Template variables accessible via {{ .Tx.Data.* }} */
|
|
75
|
+
data?: Record<string, unknown>;
|
|
76
|
+
/** Custom email headers */
|
|
77
|
+
headers?: Array<Record<string, string>>;
|
|
78
|
+
/** Message content type */
|
|
79
|
+
content_type?: TransactionalContentType;
|
|
80
|
+
/** Delivery channel (default: "email") */
|
|
81
|
+
messenger?: string;
|
|
82
|
+
/** File attachments */
|
|
83
|
+
attachments?: TransactionalAttachment[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Internal type inferred from the Zod schema (for validation).
|
|
87
|
+
*/
|
|
88
|
+
export type SendTransactionalRequestInput = z.input<typeof SendTransactionalRequestSchema>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Zod schemas used across multiple resource modules.
|
|
3
|
+
*
|
|
4
|
+
* These schemas represent common validation patterns that are duplicated
|
|
5
|
+
* across the codebase. Centralizing them ensures consistency and provides
|
|
6
|
+
* a single source of truth.
|
|
7
|
+
*
|
|
8
|
+
* @module schemas/common
|
|
9
|
+
*/
|
|
10
|
+
import { z } from "zod";
|
|
11
|
+
/**
|
|
12
|
+
* Validates a positive integer ID.
|
|
13
|
+
*
|
|
14
|
+
* Used for entity IDs throughout the API (subscriber_id, list_id, etc.).
|
|
15
|
+
*/
|
|
16
|
+
export declare const PositiveIdSchema: z.ZodNumber;
|
|
17
|
+
/**
|
|
18
|
+
* Validates an array of positive integer IDs for bulk operations.
|
|
19
|
+
*
|
|
20
|
+
* Used by bulk delete endpoints across subscribers, lists, campaigns, bounces.
|
|
21
|
+
*/
|
|
22
|
+
export declare const BulkDeleteIdsSchema: z.ZodArray<z.ZodNumber>;
|
|
23
|
+
/**
|
|
24
|
+
* Response schema for delete and similar operations that return `true`.
|
|
25
|
+
*
|
|
26
|
+
* The listmonk API returns `{ data: true }` for successful delete operations.
|
|
27
|
+
* The HttpClient unwraps this to just `true`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const DeleteResponseSchema: z.ZodLiteral<true>;
|
|
30
|
+
/**
|
|
31
|
+
* Bounce type classification.
|
|
32
|
+
*
|
|
33
|
+
* - `hard`: Permanent delivery failure (invalid address, domain doesn't exist)
|
|
34
|
+
* - `soft`: Temporary delivery failure (mailbox full, server unavailable)
|
|
35
|
+
*/
|
|
36
|
+
export declare const BounceTypeSchema: z.ZodEnum<{
|
|
37
|
+
hard: "hard";
|
|
38
|
+
soft: "soft";
|
|
39
|
+
}>;
|
|
40
|
+
/**
|
|
41
|
+
* Embedded campaign reference within a bounce record.
|
|
42
|
+
*
|
|
43
|
+
* Used by both subscribers (for bounce history) and bounces modules.
|
|
44
|
+
*/
|
|
45
|
+
export declare const BounceCampaignSchema: z.ZodObject<{
|
|
46
|
+
id: z.ZodNumber;
|
|
47
|
+
name: z.ZodString;
|
|
48
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when an unconfigured mock function is called.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```typescript
|
|
6
|
+
* const mockClient = new MockListmonkClient();
|
|
7
|
+
*
|
|
8
|
+
* // This throws MockNotConfiguredError
|
|
9
|
+
* await mockClient.subscribers.get(1);
|
|
10
|
+
* // Error: Mock method 'subscribers.get' was called but not configured.
|
|
11
|
+
* // Configure with: mockClient.subscribers.get.mockResolvedValue(...)
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class MockNotConfiguredError extends Error {
|
|
15
|
+
readonly name: "MockNotConfiguredError";
|
|
16
|
+
/**
|
|
17
|
+
* The name of the method that was called without configuration.
|
|
18
|
+
*/
|
|
19
|
+
readonly methodName: string;
|
|
20
|
+
/**
|
|
21
|
+
* The resource name (e.g., 'subscribers', 'campaigns').
|
|
22
|
+
*/
|
|
23
|
+
readonly resourceName: string;
|
|
24
|
+
constructor(resourceName: string, methodName: string);
|
|
25
|
+
}
|