@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,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import resource for bulk subscriber import from CSV/ZIP files.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/import
|
|
5
|
+
*/
|
|
6
|
+
import { APIResource } from "../../http/resource";
|
|
7
|
+
import type { ImportFileInput, ImportOptions, ImportConfig, ImportStatus } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Resource for bulk subscriber import in listmonk.
|
|
10
|
+
*
|
|
11
|
+
* Provides methods for uploading CSV/ZIP files and managing import jobs.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* // Start import (Browser)
|
|
16
|
+
* const file = new File([csvContent], 'subscribers.csv');
|
|
17
|
+
* const config = await client.import.start(file, {
|
|
18
|
+
* mode: 'subscribe',
|
|
19
|
+
* delimiter: ',',
|
|
20
|
+
* lists: [1, 2],
|
|
21
|
+
* });
|
|
22
|
+
*
|
|
23
|
+
* // Start import (Node.js)
|
|
24
|
+
* const config = await client.import.start(
|
|
25
|
+
* { filename: 'subscribers.csv', content: readFileSync('./subscribers.csv') },
|
|
26
|
+
* { mode: 'subscribe', delimiter: ',', lists: [1] }
|
|
27
|
+
* );
|
|
28
|
+
*
|
|
29
|
+
* // Poll for completion
|
|
30
|
+
* let status = await client.import.getStatus();
|
|
31
|
+
* while (status.status === 'processing') {
|
|
32
|
+
* await new Promise(r => setTimeout(r, 1000));
|
|
33
|
+
* status = await client.import.getStatus();
|
|
34
|
+
* }
|
|
35
|
+
*
|
|
36
|
+
* // Check logs
|
|
37
|
+
* const logs = await client.import.getLogs();
|
|
38
|
+
* console.log(logs);
|
|
39
|
+
*
|
|
40
|
+
* // Cancel if needed
|
|
41
|
+
* await client.import.cancel();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class ImportResource extends APIResource {
|
|
45
|
+
/**
|
|
46
|
+
* Starts a bulk subscriber import from a CSV or ZIP file.
|
|
47
|
+
*
|
|
48
|
+
* Supports two input patterns:
|
|
49
|
+
* - **Browser**: File objects (filename automatically extracted from file.name)
|
|
50
|
+
* - **Node.js/Bun**: Object with `{ filename, content }` where content is Buffer/Uint8Array
|
|
51
|
+
*
|
|
52
|
+
* @param file - File to import (File object or { filename, content } object)
|
|
53
|
+
* @param options - Import configuration options
|
|
54
|
+
* @returns The import configuration as echoed by the server
|
|
55
|
+
* @throws {ListmonkValidationError} If input is invalid (plain Blob, empty file, missing filename, invalid extension)
|
|
56
|
+
* @throws {ListmonkApiError} If server rejects the request (invalid lists, malformed CSV)
|
|
57
|
+
*
|
|
58
|
+
* @example Browser (File API)
|
|
59
|
+
* ```typescript
|
|
60
|
+
* // From a file input element
|
|
61
|
+
* const file = fileInput.files[0];
|
|
62
|
+
* const config = await client.import.start(file, {
|
|
63
|
+
* mode: 'subscribe',
|
|
64
|
+
* delimiter: ',',
|
|
65
|
+
* lists: [1, 2],
|
|
66
|
+
* });
|
|
67
|
+
* console.log(`Import started in ${config.mode} mode`);
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* @example Node.js (Buffer pattern)
|
|
71
|
+
* ```typescript
|
|
72
|
+
* import { readFileSync } from 'fs';
|
|
73
|
+
*
|
|
74
|
+
* const config = await client.import.start(
|
|
75
|
+
* { filename: 'subscribers.csv', content: readFileSync('./subscribers.csv') },
|
|
76
|
+
* {
|
|
77
|
+
* mode: 'subscribe',
|
|
78
|
+
* delimiter: ',',
|
|
79
|
+
* lists: [1],
|
|
80
|
+
* overwrite: true,
|
|
81
|
+
* subscriptionStatus: 'confirmed',
|
|
82
|
+
* }
|
|
83
|
+
* );
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @example Blocklist mode
|
|
87
|
+
* ```typescript
|
|
88
|
+
* await client.import.start(file, {
|
|
89
|
+
* mode: 'blocklist',
|
|
90
|
+
* delimiter: ',',
|
|
91
|
+
* });
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
start(file: ImportFileInput, options: ImportOptions): Promise<ImportConfig>;
|
|
95
|
+
/**
|
|
96
|
+
* Gets the current import status.
|
|
97
|
+
*
|
|
98
|
+
* Use this method to poll for import progress and detect completion.
|
|
99
|
+
*
|
|
100
|
+
* @returns The current import status
|
|
101
|
+
*
|
|
102
|
+
* @example Basic status check
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const status = await client.import.getStatus();
|
|
105
|
+
* console.log(`Status: ${status.status}`);
|
|
106
|
+
* console.log(`Progress: ${status.imported}/${status.total}`);
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @example Polling for completion
|
|
110
|
+
* ```typescript
|
|
111
|
+
* await client.import.start(file, options);
|
|
112
|
+
*
|
|
113
|
+
* let status = await client.import.getStatus();
|
|
114
|
+
* while (status.status === 'processing' || status.status === 'importing') {
|
|
115
|
+
* const percent = status.total > 0
|
|
116
|
+
* ? Math.round((status.imported / status.total) * 100)
|
|
117
|
+
* : 0;
|
|
118
|
+
* console.log(`Progress: ${percent}%`);
|
|
119
|
+
*
|
|
120
|
+
* await new Promise(r => setTimeout(r, 2000));
|
|
121
|
+
* status = await client.import.getStatus();
|
|
122
|
+
* }
|
|
123
|
+
*
|
|
124
|
+
* console.log(`Finished: ${status.imported} records imported`);
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
getStatus(): Promise<ImportStatus>;
|
|
128
|
+
/**
|
|
129
|
+
* Gets the import logs.
|
|
130
|
+
*
|
|
131
|
+
* Logs are parsed from the raw newline-separated string into an array
|
|
132
|
+
* of log entries for easier processing.
|
|
133
|
+
*
|
|
134
|
+
* @returns Array of log entry strings
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* const logs = await client.import.getLogs();
|
|
139
|
+
*
|
|
140
|
+
* for (const entry of logs) {
|
|
141
|
+
* console.log(entry);
|
|
142
|
+
* }
|
|
143
|
+
* // Output:
|
|
144
|
+
* // 2024-01-15 10:30:00 Starting import of subscribers.csv
|
|
145
|
+
* // 2024-01-15 10:30:01 Processing 1000 records
|
|
146
|
+
* // 2024-01-15 10:30:05 Row 523: Invalid email format skipped
|
|
147
|
+
* // 2024-01-15 10:30:15 Import completed: 999 imported, 1 skipped
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @example Filter for errors
|
|
151
|
+
* ```typescript
|
|
152
|
+
* const logs = await client.import.getLogs();
|
|
153
|
+
* const errors = logs.filter(line =>
|
|
154
|
+
* line.toLowerCase().includes('error') ||
|
|
155
|
+
* line.toLowerCase().includes('skipped')
|
|
156
|
+
* );
|
|
157
|
+
* console.log('Issues:', errors);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
getLogs(): Promise<string[]>;
|
|
161
|
+
/**
|
|
162
|
+
* Cancels the active import.
|
|
163
|
+
*
|
|
164
|
+
* This operation is idempotent - calling it when no import is running
|
|
165
|
+
* will not throw an error.
|
|
166
|
+
*
|
|
167
|
+
* @returns `true` if an import was cancelled or no import was running
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* // Cancel active import
|
|
172
|
+
* const cancelled = await client.import.cancel();
|
|
173
|
+
* console.log('Cancelled:', cancelled); // true
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @example Idempotent behavior
|
|
177
|
+
* ```typescript
|
|
178
|
+
* // Safe to call even if no import is running
|
|
179
|
+
* await client.import.cancel(); // No error
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
cancel(): Promise<boolean>;
|
|
183
|
+
/**
|
|
184
|
+
* Validates file input.
|
|
185
|
+
*
|
|
186
|
+
* @internal
|
|
187
|
+
* @throws {ListmonkValidationError} If input is invalid
|
|
188
|
+
*/
|
|
189
|
+
private validateFileInput;
|
|
190
|
+
/**
|
|
191
|
+
* Extracts filename from input.
|
|
192
|
+
*
|
|
193
|
+
* @internal
|
|
194
|
+
* @param input - Upload input
|
|
195
|
+
* @returns Filename string
|
|
196
|
+
*/
|
|
197
|
+
private getFilename;
|
|
198
|
+
/**
|
|
199
|
+
* Converts input to a Blob/File suitable for FormData.
|
|
200
|
+
*
|
|
201
|
+
* @internal
|
|
202
|
+
* @param input - Upload input
|
|
203
|
+
* @param filename - Filename to use
|
|
204
|
+
* @returns Blob or File for FormData
|
|
205
|
+
*/
|
|
206
|
+
private toFormDataFile;
|
|
207
|
+
/**
|
|
208
|
+
* Maps SDK options to API params format.
|
|
209
|
+
*
|
|
210
|
+
* @internal
|
|
211
|
+
* @param options - SDK options (camelCase)
|
|
212
|
+
* @returns API params (snake_case where needed)
|
|
213
|
+
*/
|
|
214
|
+
private buildParams;
|
|
215
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Import resource module.
|
|
3
|
+
*
|
|
4
|
+
* Provides bulk subscriber import from CSV/ZIP files for the listmonk API.
|
|
5
|
+
*
|
|
6
|
+
* @module resources/import
|
|
7
|
+
*/
|
|
8
|
+
export { ImportResource } from "./import";
|
|
9
|
+
export type { ImportMode, ImportOptions, ImportParams, ImportStatus, ImportConfig, ImportFileInput, ImportFileObject, } from "./types";
|
|
10
|
+
export { ImportModeSchema, ImportOptionsSchema, ImportParamsSchema, ImportStatusSchema, ImportConfigSchema, ImportFileObjectSchema, ImportLogsResponseSchema, DeleteImportResponseSchema, parseImportLogs, } from "./schemas";
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for import-related requests and responses.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/import/schemas
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
/**
|
|
8
|
+
* Import mode controlling import behavior.
|
|
9
|
+
*
|
|
10
|
+
* - `subscribe`: Add subscribers to specified lists
|
|
11
|
+
* - `blocklist`: Add email addresses to blocklist
|
|
12
|
+
*/
|
|
13
|
+
export declare const ImportModeSchema: z.ZodEnum<{
|
|
14
|
+
subscribe: "subscribe";
|
|
15
|
+
blocklist: "blocklist";
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* SDK-facing configuration for starting an import.
|
|
19
|
+
*
|
|
20
|
+
* Uses camelCase per TypeScript conventions. Mapped to API format internally.
|
|
21
|
+
*/
|
|
22
|
+
export declare const ImportOptionsSchema: z.ZodObject<{
|
|
23
|
+
mode: z.ZodEnum<{
|
|
24
|
+
subscribe: "subscribe";
|
|
25
|
+
blocklist: "blocklist";
|
|
26
|
+
}>;
|
|
27
|
+
delimiter: z.ZodString;
|
|
28
|
+
lists: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
29
|
+
overwrite: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
30
|
+
subscriptionStatus: z.ZodOptional<z.ZodString>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
/**
|
|
33
|
+
* Object pattern for file input in Node.js.
|
|
34
|
+
*
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare const ImportFileObjectSchema: z.ZodObject<{
|
|
38
|
+
filename: z.ZodString;
|
|
39
|
+
content: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
40
|
+
}, z.core.$strip>;
|
|
41
|
+
/**
|
|
42
|
+
* API request params field format (snake_case).
|
|
43
|
+
*
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export declare const ImportParamsSchema: z.ZodObject<{
|
|
47
|
+
mode: z.ZodEnum<{
|
|
48
|
+
subscribe: "subscribe";
|
|
49
|
+
blocklist: "blocklist";
|
|
50
|
+
}>;
|
|
51
|
+
delim: z.ZodString;
|
|
52
|
+
lists: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
53
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
subscription_status: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
/**
|
|
57
|
+
* Current state of an import operation.
|
|
58
|
+
*/
|
|
59
|
+
export declare const ImportStatusSchema: z.ZodObject<{
|
|
60
|
+
name: z.ZodString;
|
|
61
|
+
total: z.ZodNumber;
|
|
62
|
+
imported: z.ZodNumber;
|
|
63
|
+
status: z.ZodString;
|
|
64
|
+
}, z.core.$strip>;
|
|
65
|
+
/**
|
|
66
|
+
* Configuration echo returned from successful import start.
|
|
67
|
+
*
|
|
68
|
+
* Note: This is the direct API response from POST, not wrapped in { data: ... }.
|
|
69
|
+
*/
|
|
70
|
+
export declare const ImportConfigSchema: z.ZodObject<{
|
|
71
|
+
mode: z.ZodEnum<{
|
|
72
|
+
subscribe: "subscribe";
|
|
73
|
+
blocklist: "blocklist";
|
|
74
|
+
}>;
|
|
75
|
+
delim: z.ZodString;
|
|
76
|
+
lists: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
77
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
/**
|
|
80
|
+
* Response from cancel operation.
|
|
81
|
+
*
|
|
82
|
+
* The API may return `true` or the status object after cancellation.
|
|
83
|
+
*/
|
|
84
|
+
export declare const DeleteImportResponseSchema: z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
|
|
85
|
+
name: z.ZodString;
|
|
86
|
+
total: z.ZodNumber;
|
|
87
|
+
imported: z.ZodNumber;
|
|
88
|
+
status: z.ZodString;
|
|
89
|
+
}, z.core.$strip>]>;
|
|
90
|
+
/**
|
|
91
|
+
* Raw API response for logs endpoint.
|
|
92
|
+
*
|
|
93
|
+
* Logs are returned as a single string with newline separators.
|
|
94
|
+
*/
|
|
95
|
+
export declare const ImportLogsResponseSchema: z.ZodString;
|
|
96
|
+
/**
|
|
97
|
+
* Parses raw log string from API into an array of log entries.
|
|
98
|
+
*
|
|
99
|
+
* @param raw - Raw log string from API (newline-separated)
|
|
100
|
+
* @returns Array of log entry strings
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const raw = "2024-01-15 10:30:00 Started\n2024-01-15 10:30:01 Finished\n";
|
|
105
|
+
* const logs = parseImportLogs(raw);
|
|
106
|
+
* // logs = ["2024-01-15 10:30:00 Started", "2024-01-15 10:30:01 Finished"]
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function parseImportLogs(raw: string): string[];
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for import module.
|
|
3
|
+
*
|
|
4
|
+
* All types are inferred from Zod schemas to ensure runtime
|
|
5
|
+
* validation matches compile-time types.
|
|
6
|
+
*
|
|
7
|
+
* @module resources/import/types
|
|
8
|
+
*/
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
import type { ImportModeSchema, ImportOptionsSchema, ImportParamsSchema, ImportStatusSchema, ImportConfigSchema, ImportFileObjectSchema } from "./schemas";
|
|
11
|
+
/**
|
|
12
|
+
* Import mode enum type.
|
|
13
|
+
*
|
|
14
|
+
* - `"subscribe"`: Add subscribers to specified lists
|
|
15
|
+
* - `"blocklist"`: Add email addresses to blocklist
|
|
16
|
+
*/
|
|
17
|
+
export type ImportMode = z.infer<typeof ImportModeSchema>;
|
|
18
|
+
/**
|
|
19
|
+
* SDK-facing import options (input type for API consumers).
|
|
20
|
+
*
|
|
21
|
+
* Uses camelCase per TypeScript conventions. `overwrite` is optional
|
|
22
|
+
* and defaults to `false` when not provided.
|
|
23
|
+
*/
|
|
24
|
+
export type ImportOptions = z.input<typeof ImportOptionsSchema>;
|
|
25
|
+
/**
|
|
26
|
+
* API wire format for import params (snake_case).
|
|
27
|
+
*
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
export type ImportParams = z.infer<typeof ImportParamsSchema>;
|
|
31
|
+
/**
|
|
32
|
+
* Current state of an import operation.
|
|
33
|
+
*/
|
|
34
|
+
export type ImportStatus = z.infer<typeof ImportStatusSchema>;
|
|
35
|
+
/**
|
|
36
|
+
* Configuration echo returned from successful import start.
|
|
37
|
+
*/
|
|
38
|
+
export type ImportConfig = z.infer<typeof ImportConfigSchema>;
|
|
39
|
+
/**
|
|
40
|
+
* Node.js pattern for file upload: { filename, content }.
|
|
41
|
+
*/
|
|
42
|
+
export type ImportFileObject = z.infer<typeof ImportFileObjectSchema>;
|
|
43
|
+
/**
|
|
44
|
+
* Input for import file upload.
|
|
45
|
+
*
|
|
46
|
+
* Supports:
|
|
47
|
+
* - Web API: File objects (filename extracted from file.name)
|
|
48
|
+
* - Node.js/Bun: Object with filename and Buffer/Uint8Array content
|
|
49
|
+
*
|
|
50
|
+
* NOTE: Plain Blob objects are NOT supported because they lack a filename.
|
|
51
|
+
* Use File (which extends Blob) or { filename, content } pattern instead.
|
|
52
|
+
*
|
|
53
|
+
* @example Browser (File API)
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const file = new File([csvContent], 'subscribers.csv', { type: 'text/csv' });
|
|
56
|
+
* await client.import.start(file, options);
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* @example Node.js (Buffer pattern)
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { readFileSync } from 'fs';
|
|
62
|
+
*
|
|
63
|
+
* await client.import.start({
|
|
64
|
+
* filename: 'subscribers.csv',
|
|
65
|
+
* content: readFileSync('./subscribers.csv'),
|
|
66
|
+
* }, options);
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export type ImportFileInput = File | {
|
|
70
|
+
filename: string;
|
|
71
|
+
content: Buffer | Uint8Array;
|
|
72
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lists resource module.
|
|
3
|
+
*
|
|
4
|
+
* Provides complete mailing list management for the listmonk API.
|
|
5
|
+
*
|
|
6
|
+
* @module resources/lists
|
|
7
|
+
*/
|
|
8
|
+
export { ListsResource } from "./lists";
|
|
9
|
+
export type { List, PublicList, ListType, ListOptin, ListStatus, CreateListRequest, UpdateListRequest, ListListsOptions, ListListsResponse, BulkDeleteByQueryRequest, } from "./types";
|
|
10
|
+
export { ListSchema, PublicListSchema, ListTypeSchema, ListOptinSchema, ListStatusSchema, CreateListRequestSchema, UpdateListRequestSchema, ListListsOptionsSchema, ListListsResponseSchema, BulkDeleteByQueryRequestSchema, } from "./schemas";
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lists resource for managing mailing lists.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/lists
|
|
5
|
+
*/
|
|
6
|
+
import { APIResource } from "../../http/resource";
|
|
7
|
+
import type { List, PublicList, CreateListRequest, UpdateListRequest, ListListsOptions, ListListsResponse } from "./types";
|
|
8
|
+
import type { PagedAsyncIterableIterator } from "../../types/pagination";
|
|
9
|
+
/**
|
|
10
|
+
* Resource for managing mailing lists in listmonk.
|
|
11
|
+
*
|
|
12
|
+
* Provides methods for CRUD operations, pagination, filtering,
|
|
13
|
+
* bulk deletion, and public lists access.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Access via client
|
|
18
|
+
* const list = await client.lists.create({
|
|
19
|
+
* name: 'Newsletter',
|
|
20
|
+
* type: 'public',
|
|
21
|
+
* optin: 'double',
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class ListsResource extends APIResource {
|
|
26
|
+
/**
|
|
27
|
+
* Creates a new mailing list.
|
|
28
|
+
*
|
|
29
|
+
* @param data - List data
|
|
30
|
+
* @returns The created list
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const list = await client.lists.create({
|
|
35
|
+
* name: 'Newsletter Subscribers',
|
|
36
|
+
* type: 'public',
|
|
37
|
+
* optin: 'double',
|
|
38
|
+
* tags: ['newsletter', 'weekly'],
|
|
39
|
+
* description: 'Weekly newsletter subscribers',
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
create(data: CreateListRequest): Promise<List>;
|
|
44
|
+
/**
|
|
45
|
+
* Retrieves a list by ID.
|
|
46
|
+
*
|
|
47
|
+
* @param id - List ID
|
|
48
|
+
* @returns The list
|
|
49
|
+
* @throws {ListmonkNotFoundError} If list not found
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const list = await client.lists.retrieve(1);
|
|
54
|
+
* console.log(list.name);
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
retrieve(id: number): Promise<List>;
|
|
58
|
+
/**
|
|
59
|
+
* Updates an existing list.
|
|
60
|
+
*
|
|
61
|
+
* All fields are optional - only provided fields are updated.
|
|
62
|
+
* Note: The `tags` array replaces existing tags entirely.
|
|
63
|
+
*
|
|
64
|
+
* @param id - List ID
|
|
65
|
+
* @param data - Updated list data
|
|
66
|
+
* @returns The updated list
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* const updated = await client.lists.update(1, {
|
|
71
|
+
* name: 'Weekly Newsletter',
|
|
72
|
+
* status: 'active',
|
|
73
|
+
* tags: ['newsletter', 'weekly', 'featured'],
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
update(id: number, data: UpdateListRequest): Promise<List>;
|
|
78
|
+
/**
|
|
79
|
+
* Deletes a list by ID.
|
|
80
|
+
*
|
|
81
|
+
* Note: Deleting a list removes all subscriber associations
|
|
82
|
+
* (subscribers are unsubscribed from the list, not deleted).
|
|
83
|
+
*
|
|
84
|
+
* @param id - List ID
|
|
85
|
+
* @throws {ListmonkNotFoundError} If list not found
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* await client.lists.remove(1);
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
remove(id: number): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Lists mailing lists with pagination and filtering.
|
|
95
|
+
*
|
|
96
|
+
* @param options - Query options
|
|
97
|
+
* @returns Paginated list response
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* const page = await client.lists.list({
|
|
102
|
+
* page: 1,
|
|
103
|
+
* per_page: 50,
|
|
104
|
+
* status: 'active',
|
|
105
|
+
* type: 'public',
|
|
106
|
+
* order_by: 'created_at',
|
|
107
|
+
* order: 'DESC',
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
list(options?: ListListsOptions): Promise<ListListsResponse>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns an async iterator over all lists matching the options.
|
|
114
|
+
*
|
|
115
|
+
* Pages are fetched on-demand as you iterate. The iterator also
|
|
116
|
+
* provides a `byPage()` method for page-level iteration.
|
|
117
|
+
*
|
|
118
|
+
* @param options - Query options (page is ignored, starts from 1)
|
|
119
|
+
* @returns Async iterator over lists
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Iterate over all lists
|
|
124
|
+
* for await (const list of client.lists.listAll()) {
|
|
125
|
+
* console.log(list.name);
|
|
126
|
+
* }
|
|
127
|
+
*
|
|
128
|
+
* // Iterate over pages
|
|
129
|
+
* for await (const page of client.lists.listAll().byPage()) {
|
|
130
|
+
* console.log(`Page ${page.page} has ${page.results.length} items`);
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
listAll(options?: Omit<ListListsOptions, "page">): PagedAsyncIterableIterator<List, ListListsResponse>;
|
|
135
|
+
/**
|
|
136
|
+
* Deletes multiple lists by ID.
|
|
137
|
+
*
|
|
138
|
+
* Note: Lists the user doesn't have "manage" permission for
|
|
139
|
+
* are silently ignored (not an error).
|
|
140
|
+
*
|
|
141
|
+
* @param ids - List IDs to delete
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* await client.lists.deleteMany([1, 2, 3]);
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
deleteMany(ids: number[]): Promise<void>;
|
|
149
|
+
/**
|
|
150
|
+
* Deletes lists matching a SQL-style query.
|
|
151
|
+
*
|
|
152
|
+
* Note: Lists the user doesn't have "manage" permission for
|
|
153
|
+
* are silently ignored (not an error).
|
|
154
|
+
*
|
|
155
|
+
* @param query - SQL-style query expression
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* await client.lists.deleteByQuery("lists.status = 'archived'");
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
deleteByQuery(query: string): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Retrieves public, active lists for subscription forms.
|
|
165
|
+
*
|
|
166
|
+
* This endpoint does NOT require authentication.
|
|
167
|
+
* Returns only `uuid` and `name` fields for security.
|
|
168
|
+
*
|
|
169
|
+
* @returns Array of public lists with minimal data
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const publicLists = await client.lists.getPublic();
|
|
174
|
+
* for (const list of publicLists) {
|
|
175
|
+
* console.log(`${list.name} (${list.uuid})`);
|
|
176
|
+
* }
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
getPublic(): Promise<PublicList[]>;
|
|
180
|
+
}
|