@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,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for list-related requests and responses.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/lists/schemas
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
/**
|
|
8
|
+
* List visibility type.
|
|
9
|
+
* - `public`: List can be shown on public subscription forms
|
|
10
|
+
* - `private`: List is internal only, not visible to subscribers
|
|
11
|
+
*/
|
|
12
|
+
export declare const ListTypeSchema: z.ZodEnum<{
|
|
13
|
+
public: "public";
|
|
14
|
+
private: "private";
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Opt-in confirmation mode.
|
|
18
|
+
* - `single`: Subscribers are added immediately without confirmation
|
|
19
|
+
* - `double`: Subscribers must confirm via email before being added
|
|
20
|
+
*/
|
|
21
|
+
export declare const ListOptinSchema: z.ZodEnum<{
|
|
22
|
+
single: "single";
|
|
23
|
+
double: "double";
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* List availability status.
|
|
27
|
+
* - `active`: List is fully operational and visible in selectors
|
|
28
|
+
* - `archived`: List is hidden from UI selectors but retains data
|
|
29
|
+
*/
|
|
30
|
+
export declare const ListStatusSchema: z.ZodEnum<{
|
|
31
|
+
active: "active";
|
|
32
|
+
archived: "archived";
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Complete list entity returned from authenticated endpoints.
|
|
36
|
+
*/
|
|
37
|
+
export declare const ListSchema: z.ZodObject<{
|
|
38
|
+
id: z.ZodNumber;
|
|
39
|
+
uuid: z.ZodString;
|
|
40
|
+
name: z.ZodString;
|
|
41
|
+
type: z.ZodEnum<{
|
|
42
|
+
public: "public";
|
|
43
|
+
private: "private";
|
|
44
|
+
}>;
|
|
45
|
+
optin: z.ZodEnum<{
|
|
46
|
+
single: "single";
|
|
47
|
+
double: "double";
|
|
48
|
+
}>;
|
|
49
|
+
status: z.ZodEnum<{
|
|
50
|
+
active: "active";
|
|
51
|
+
archived: "archived";
|
|
52
|
+
}>;
|
|
53
|
+
tags: z.ZodArray<z.ZodString>;
|
|
54
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
55
|
+
subscriber_count: z.ZodOptional<z.ZodNumber>;
|
|
56
|
+
created_at: z.ZodString;
|
|
57
|
+
updated_at: z.ZodString;
|
|
58
|
+
}, z.core.$strip>;
|
|
59
|
+
/**
|
|
60
|
+
* Minimal list entity returned from the public endpoint (no auth required).
|
|
61
|
+
* Used for public subscription forms.
|
|
62
|
+
*/
|
|
63
|
+
export declare const PublicListSchema: z.ZodObject<{
|
|
64
|
+
uuid: z.ZodString;
|
|
65
|
+
name: z.ZodString;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
/**
|
|
68
|
+
* Request to create a new list.
|
|
69
|
+
*/
|
|
70
|
+
export declare const CreateListRequestSchema: z.ZodObject<{
|
|
71
|
+
name: z.ZodString;
|
|
72
|
+
type: z.ZodEnum<{
|
|
73
|
+
public: "public";
|
|
74
|
+
private: "private";
|
|
75
|
+
}>;
|
|
76
|
+
optin: z.ZodEnum<{
|
|
77
|
+
single: "single";
|
|
78
|
+
double: "double";
|
|
79
|
+
}>;
|
|
80
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
81
|
+
active: "active";
|
|
82
|
+
archived: "archived";
|
|
83
|
+
}>>;
|
|
84
|
+
tags: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodString>>>;
|
|
85
|
+
description: z.ZodOptional<z.ZodString>;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
/**
|
|
88
|
+
* Request to update an existing list.
|
|
89
|
+
* All fields are optional for partial updates.
|
|
90
|
+
*/
|
|
91
|
+
export declare const UpdateListRequestSchema: z.ZodObject<{
|
|
92
|
+
name: z.ZodOptional<z.ZodString>;
|
|
93
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
94
|
+
public: "public";
|
|
95
|
+
private: "private";
|
|
96
|
+
}>>;
|
|
97
|
+
optin: z.ZodOptional<z.ZodEnum<{
|
|
98
|
+
single: "single";
|
|
99
|
+
double: "double";
|
|
100
|
+
}>>;
|
|
101
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
102
|
+
active: "active";
|
|
103
|
+
archived: "archived";
|
|
104
|
+
}>>;
|
|
105
|
+
tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
106
|
+
description: z.ZodOptional<z.ZodString>;
|
|
107
|
+
}, z.core.$strip>;
|
|
108
|
+
/**
|
|
109
|
+
* Options for listing and filtering lists.
|
|
110
|
+
*/
|
|
111
|
+
export declare const ListListsOptionsSchema: z.ZodObject<{
|
|
112
|
+
query: z.ZodOptional<z.ZodString>;
|
|
113
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
114
|
+
active: "active";
|
|
115
|
+
archived: "archived";
|
|
116
|
+
}>>;
|
|
117
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
118
|
+
public: "public";
|
|
119
|
+
private: "private";
|
|
120
|
+
}>>;
|
|
121
|
+
optin: z.ZodOptional<z.ZodEnum<{
|
|
122
|
+
single: "single";
|
|
123
|
+
double: "double";
|
|
124
|
+
}>>;
|
|
125
|
+
tag: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
126
|
+
minimal: z.ZodOptional<z.ZodBoolean>;
|
|
127
|
+
order_by: z.ZodOptional<z.ZodEnum<{
|
|
128
|
+
name: "name";
|
|
129
|
+
created_at: "created_at";
|
|
130
|
+
updated_at: "updated_at";
|
|
131
|
+
status: "status";
|
|
132
|
+
}>>;
|
|
133
|
+
order: z.ZodOptional<z.ZodEnum<{
|
|
134
|
+
ASC: "ASC";
|
|
135
|
+
DESC: "DESC";
|
|
136
|
+
}>>;
|
|
137
|
+
page: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
138
|
+
per_page: z.ZodDefault<z.ZodOptional<z.ZodUnion<readonly [z.ZodNumber, z.ZodLiteral<"all">]>>>;
|
|
139
|
+
}, z.core.$strip>;
|
|
140
|
+
/**
|
|
141
|
+
* Request for query-based bulk deletion.
|
|
142
|
+
*/
|
|
143
|
+
export declare const BulkDeleteByQueryRequestSchema: z.ZodObject<{
|
|
144
|
+
query: z.ZodString;
|
|
145
|
+
}, z.core.$strip>;
|
|
146
|
+
export { BulkDeleteIdsSchema } from "../../schemas";
|
|
147
|
+
/**
|
|
148
|
+
* Paginated response from the list endpoint.
|
|
149
|
+
*/
|
|
150
|
+
export declare const ListListsResponseSchema: z.ZodObject<{
|
|
151
|
+
results: z.ZodArray<z.ZodObject<{
|
|
152
|
+
id: z.ZodNumber;
|
|
153
|
+
uuid: z.ZodString;
|
|
154
|
+
name: z.ZodString;
|
|
155
|
+
type: z.ZodEnum<{
|
|
156
|
+
public: "public";
|
|
157
|
+
private: "private";
|
|
158
|
+
}>;
|
|
159
|
+
optin: z.ZodEnum<{
|
|
160
|
+
single: "single";
|
|
161
|
+
double: "double";
|
|
162
|
+
}>;
|
|
163
|
+
status: z.ZodEnum<{
|
|
164
|
+
active: "active";
|
|
165
|
+
archived: "archived";
|
|
166
|
+
}>;
|
|
167
|
+
tags: z.ZodArray<z.ZodString>;
|
|
168
|
+
description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
169
|
+
subscriber_count: z.ZodOptional<z.ZodNumber>;
|
|
170
|
+
created_at: z.ZodString;
|
|
171
|
+
updated_at: z.ZodString;
|
|
172
|
+
}, z.core.$strip>>;
|
|
173
|
+
total: z.ZodNumber;
|
|
174
|
+
per_page: z.ZodNumber;
|
|
175
|
+
page: z.ZodNumber;
|
|
176
|
+
}, z.core.$strip>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for lists module.
|
|
3
|
+
*
|
|
4
|
+
* All types are inferred from Zod schemas to ensure runtime
|
|
5
|
+
* validation matches compile-time types.
|
|
6
|
+
*
|
|
7
|
+
* @module resources/lists/types
|
|
8
|
+
*/
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
import type { ListSchema, PublicListSchema, ListTypeSchema, ListOptinSchema, ListStatusSchema, CreateListRequestSchema, UpdateListRequestSchema, ListListsOptionsSchema, ListListsResponseSchema, BulkDeleteByQueryRequestSchema } from "./schemas";
|
|
11
|
+
/**
|
|
12
|
+
* List visibility type.
|
|
13
|
+
* - `public`: List can be shown on public subscription forms
|
|
14
|
+
* - `private`: List is internal only, not visible to subscribers
|
|
15
|
+
*/
|
|
16
|
+
export type ListType = z.infer<typeof ListTypeSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* Opt-in confirmation mode.
|
|
19
|
+
* - `single`: Subscribers are added immediately without confirmation
|
|
20
|
+
* - `double`: Subscribers must confirm via email before being added
|
|
21
|
+
*/
|
|
22
|
+
export type ListOptin = z.infer<typeof ListOptinSchema>;
|
|
23
|
+
/**
|
|
24
|
+
* List availability status.
|
|
25
|
+
* - `active`: List is fully operational and visible in selectors
|
|
26
|
+
* - `archived`: List is hidden from UI selectors but retains data
|
|
27
|
+
*/
|
|
28
|
+
export type ListStatus = z.infer<typeof ListStatusSchema>;
|
|
29
|
+
/**
|
|
30
|
+
* Complete list entity.
|
|
31
|
+
*/
|
|
32
|
+
export type List = z.infer<typeof ListSchema>;
|
|
33
|
+
/**
|
|
34
|
+
* Minimal list entity for public endpoint.
|
|
35
|
+
*/
|
|
36
|
+
export type PublicList = z.infer<typeof PublicListSchema>;
|
|
37
|
+
/**
|
|
38
|
+
* Request to create a new list (input type).
|
|
39
|
+
*/
|
|
40
|
+
export type CreateListRequest = z.input<typeof CreateListRequestSchema>;
|
|
41
|
+
/**
|
|
42
|
+
* Request to update an existing list (input type).
|
|
43
|
+
*/
|
|
44
|
+
export type UpdateListRequest = z.input<typeof UpdateListRequestSchema>;
|
|
45
|
+
/**
|
|
46
|
+
* Options for listing lists (input type).
|
|
47
|
+
*/
|
|
48
|
+
export type ListListsOptions = z.input<typeof ListListsOptionsSchema>;
|
|
49
|
+
/**
|
|
50
|
+
* Request for query-based bulk deletion (input type).
|
|
51
|
+
*/
|
|
52
|
+
export type BulkDeleteByQueryRequest = z.input<typeof BulkDeleteByQueryRequestSchema>;
|
|
53
|
+
/**
|
|
54
|
+
* Paginated list of lists response.
|
|
55
|
+
*/
|
|
56
|
+
export type ListListsResponse = z.infer<typeof ListListsResponseSchema>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maintenance resource module.
|
|
3
|
+
*
|
|
4
|
+
* Provides garbage collection and cleanup operations for the listmonk API.
|
|
5
|
+
*
|
|
6
|
+
* @module resources/maintenance
|
|
7
|
+
*/
|
|
8
|
+
export { MaintenanceResource } from "./maintenance";
|
|
9
|
+
export type { SubscriberGcType, AnalyticsGcType, GcCountResult, GcAnalyticsResult, } from "./types";
|
|
10
|
+
export { SubscriberGcTypeSchema, AnalyticsGcTypeSchema, GcCountResultSchema, GcAnalyticsResultSchema, Rfc3339DateSchema, } from "./schemas";
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maintenance resource for cleanup operations.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/maintenance
|
|
5
|
+
*/
|
|
6
|
+
import { APIResource } from "../../http/resource";
|
|
7
|
+
import type { SubscriberGcType, AnalyticsGcType, GcCountResult, GcAnalyticsResult } from "./types";
|
|
8
|
+
/**
|
|
9
|
+
* Resource for maintenance and cleanup operations on listmonk.
|
|
10
|
+
*
|
|
11
|
+
* Provides garbage collection methods for removing old data,
|
|
12
|
+
* blocklisted subscribers, orphan records, and analytics data.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* // Delete blocklisted subscribers
|
|
17
|
+
* const result = await client.maintenance.gcSubscribers('blocklisted');
|
|
18
|
+
* console.log(`Deleted ${result.count} subscribers`);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare class MaintenanceResource extends APIResource {
|
|
22
|
+
/**
|
|
23
|
+
* Deletes subscribers by type (garbage collection).
|
|
24
|
+
*
|
|
25
|
+
* @param type - Type of subscribers to delete
|
|
26
|
+
* - `blocklisted`: Delete all blocklisted subscribers
|
|
27
|
+
* - `orphan`: Delete subscribers not in any list
|
|
28
|
+
* @returns Result with count of deleted records
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* // Delete blocklisted subscribers
|
|
33
|
+
* const blocklisted = await client.maintenance.gcSubscribers('blocklisted');
|
|
34
|
+
* console.log(`Deleted ${blocklisted.count} blocklisted subscribers`);
|
|
35
|
+
*
|
|
36
|
+
* // Delete orphan subscribers
|
|
37
|
+
* const orphans = await client.maintenance.gcSubscribers('orphan');
|
|
38
|
+
* console.log(`Deleted ${orphans.count} orphan subscribers`);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
gcSubscribers(type: SubscriberGcType): Promise<GcCountResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes unconfirmed subscriptions older than a given date.
|
|
44
|
+
*
|
|
45
|
+
* Removes subscription records that were never confirmed
|
|
46
|
+
* (double opt-in pending).
|
|
47
|
+
*
|
|
48
|
+
* @param beforeDate - RFC3339 timestamp (delete records older than this)
|
|
49
|
+
* @returns Result with count of deleted records
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* // Delete unconfirmed subscriptions older than 3 months
|
|
54
|
+
* const cutoffDate = new Date();
|
|
55
|
+
* cutoffDate.setMonth(cutoffDate.getMonth() - 3);
|
|
56
|
+
*
|
|
57
|
+
* const result = await client.maintenance.gcSubscriptions(
|
|
58
|
+
* cutoffDate.toISOString()
|
|
59
|
+
* );
|
|
60
|
+
* console.log(`Deleted ${result.count} unconfirmed subscriptions`);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
gcSubscriptions(beforeDate: string): Promise<GcCountResult>;
|
|
64
|
+
/**
|
|
65
|
+
* Deletes analytics data older than a given date.
|
|
66
|
+
*
|
|
67
|
+
* Note: Returns `true` on success, not a count.
|
|
68
|
+
*
|
|
69
|
+
* @param type - Type of analytics to delete
|
|
70
|
+
* - `all`: Delete all analytics data
|
|
71
|
+
* - `views`: Delete campaign view records only
|
|
72
|
+
* - `clicks`: Delete link click records only
|
|
73
|
+
* @param beforeDate - RFC3339 timestamp (delete records older than this)
|
|
74
|
+
* @returns `true` on success
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* // Delete all analytics older than 1 year
|
|
79
|
+
* const cutoffDate = new Date();
|
|
80
|
+
* cutoffDate.setFullYear(cutoffDate.getFullYear() - 1);
|
|
81
|
+
*
|
|
82
|
+
* await client.maintenance.gcAnalytics('all', cutoffDate.toISOString());
|
|
83
|
+
*
|
|
84
|
+
* // Delete only view records
|
|
85
|
+
* await client.maintenance.gcAnalytics('views', cutoffDate.toISOString());
|
|
86
|
+
*
|
|
87
|
+
* // Delete only click records
|
|
88
|
+
* await client.maintenance.gcAnalytics('clicks', cutoffDate.toISOString());
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
gcAnalytics(type: AnalyticsGcType, beforeDate: string): Promise<GcAnalyticsResult>;
|
|
92
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for maintenance-related requests and responses.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/maintenance/schemas
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
/**
|
|
8
|
+
* Subscriber garbage collection type.
|
|
9
|
+
*/
|
|
10
|
+
export declare const SubscriberGcTypeSchema: z.ZodEnum<{
|
|
11
|
+
blocklisted: "blocklisted";
|
|
12
|
+
orphan: "orphan";
|
|
13
|
+
}>;
|
|
14
|
+
/**
|
|
15
|
+
* Analytics garbage collection type.
|
|
16
|
+
*/
|
|
17
|
+
export declare const AnalyticsGcTypeSchema: z.ZodEnum<{
|
|
18
|
+
all: "all";
|
|
19
|
+
views: "views";
|
|
20
|
+
clicks: "clicks";
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
* GC result with count of deleted records.
|
|
24
|
+
* Used by gcSubscribers and gcSubscriptions.
|
|
25
|
+
*/
|
|
26
|
+
export declare const GcCountResultSchema: z.ZodObject<{
|
|
27
|
+
count: z.ZodNumber;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
/**
|
|
30
|
+
* GC result for analytics (returns true, not count).
|
|
31
|
+
*/
|
|
32
|
+
export declare const GcAnalyticsResultSchema: z.ZodLiteral<true>;
|
|
33
|
+
/**
|
|
34
|
+
* RFC3339 date validation for maintenance operations.
|
|
35
|
+
*/
|
|
36
|
+
export declare const Rfc3339DateSchema: z.ZodString;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript types for maintenance module.
|
|
3
|
+
*
|
|
4
|
+
* All types are inferred from Zod schemas to ensure runtime
|
|
5
|
+
* validation matches compile-time types.
|
|
6
|
+
*
|
|
7
|
+
* @module resources/maintenance/types
|
|
8
|
+
*/
|
|
9
|
+
import type { z } from "zod";
|
|
10
|
+
import type { SubscriberGcTypeSchema, AnalyticsGcTypeSchema, GcCountResultSchema, GcAnalyticsResultSchema } from "./schemas";
|
|
11
|
+
/**
|
|
12
|
+
* Subscriber garbage collection type.
|
|
13
|
+
* - `blocklisted`: Delete blocklisted subscribers
|
|
14
|
+
* - `orphan`: Delete subscribers not in any list
|
|
15
|
+
*/
|
|
16
|
+
export type SubscriberGcType = z.infer<typeof SubscriberGcTypeSchema>;
|
|
17
|
+
/**
|
|
18
|
+
* Analytics garbage collection type.
|
|
19
|
+
* - `all`: Delete all analytics data
|
|
20
|
+
* - `views`: Delete campaign view records only
|
|
21
|
+
* - `clicks`: Delete link click records only
|
|
22
|
+
*/
|
|
23
|
+
export type AnalyticsGcType = z.infer<typeof AnalyticsGcTypeSchema>;
|
|
24
|
+
/**
|
|
25
|
+
* GC result with count of deleted records.
|
|
26
|
+
*/
|
|
27
|
+
export type GcCountResult = z.infer<typeof GcCountResultSchema>;
|
|
28
|
+
/**
|
|
29
|
+
* GC result for analytics (always true on success).
|
|
30
|
+
*/
|
|
31
|
+
export type GcAnalyticsResult = z.infer<typeof GcAnalyticsResultSchema>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media resource module.
|
|
3
|
+
*
|
|
4
|
+
* Provides media file upload and management for the listmonk API.
|
|
5
|
+
*
|
|
6
|
+
* @module resources/media
|
|
7
|
+
*/
|
|
8
|
+
export { MediaResource } from "./media";
|
|
9
|
+
export type { Media, MediaUploadInput, MediaUploadObject } from "./types";
|
|
10
|
+
export { MediaSchema, MediaUploadObjectSchema, ListMediaResponseSchema, DeleteResponseSchema, } from "./schemas";
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media resource for managing media files (images, PDFs, etc.).
|
|
3
|
+
*
|
|
4
|
+
* @module resources/media
|
|
5
|
+
*/
|
|
6
|
+
import { APIResource } from "../../http/resource";
|
|
7
|
+
import type { Media, MediaUploadInput } from "./types";
|
|
8
|
+
import type { PagedAsyncIterableIterator } from "../../types/pagination";
|
|
9
|
+
/**
|
|
10
|
+
* Resource for managing media files in listmonk.
|
|
11
|
+
*
|
|
12
|
+
* Provides methods for uploading, listing, retrieving, and deleting
|
|
13
|
+
* media files (images, PDFs, etc.) for use as campaign assets.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Upload a file (Browser)
|
|
18
|
+
* const file = new File([content], 'hero.jpg', { type: 'image/jpeg' });
|
|
19
|
+
* const media = await client.media.upload(file);
|
|
20
|
+
*
|
|
21
|
+
* // Upload a file (Node.js)
|
|
22
|
+
* const media = await client.media.upload({
|
|
23
|
+
* filename: 'hero.jpg',
|
|
24
|
+
* content: readFileSync('./hero.jpg'),
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // Use in campaign
|
|
28
|
+
* const campaign = await client.campaigns.create({
|
|
29
|
+
* name: 'Newsletter',
|
|
30
|
+
* body: `<img src="${media.url}" />`,
|
|
31
|
+
* // ...
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare class MediaResource extends APIResource {
|
|
36
|
+
/**
|
|
37
|
+
* Uploads a media file.
|
|
38
|
+
*
|
|
39
|
+
* Supports two input patterns:
|
|
40
|
+
* - **Browser**: File objects (filename automatically extracted from file.name)
|
|
41
|
+
* - **Node.js/Bun**: Object with `{ filename, content }` where content is Buffer/Uint8Array
|
|
42
|
+
*
|
|
43
|
+
* @param input - File to upload (File object or { filename, content } object)
|
|
44
|
+
* @returns The uploaded media file metadata
|
|
45
|
+
* @throws {ListmonkValidationError} If input is invalid (plain Blob, empty file, missing filename)
|
|
46
|
+
* @throws {ListmonkApiError} If server rejects the upload (file too large, unsupported type)
|
|
47
|
+
*
|
|
48
|
+
* @example Browser (File API)
|
|
49
|
+
* ```typescript
|
|
50
|
+
* // From a file input element
|
|
51
|
+
* const file = fileInput.files[0];
|
|
52
|
+
* const media = await client.media.upload(file);
|
|
53
|
+
* console.log(`Uploaded: ${media.url}`);
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Node.js (Buffer pattern)
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { readFileSync } from 'fs';
|
|
59
|
+
*
|
|
60
|
+
* const media = await client.media.upload({
|
|
61
|
+
* filename: 'campaign-hero.jpg',
|
|
62
|
+
* content: readFileSync('./hero.jpg'),
|
|
63
|
+
* });
|
|
64
|
+
* console.log(`Thumbnail: ${media.thumb_url}`);
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example Programmatic file creation
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const file = new File(
|
|
70
|
+
* [JSON.stringify({ data: 'test' })],
|
|
71
|
+
* 'data.json',
|
|
72
|
+
* { type: 'application/json' }
|
|
73
|
+
* );
|
|
74
|
+
* const media = await client.media.upload(file);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
upload(input: MediaUploadInput): Promise<Media>;
|
|
78
|
+
/**
|
|
79
|
+
* Validates upload input.
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
82
|
+
* @throws {ListmonkValidationError} If input is invalid
|
|
83
|
+
*/
|
|
84
|
+
private validateUploadInput;
|
|
85
|
+
/**
|
|
86
|
+
* Extracts filename from input.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
* @param input - Upload input
|
|
90
|
+
* @returns Filename string
|
|
91
|
+
*/
|
|
92
|
+
private getFilename;
|
|
93
|
+
/**
|
|
94
|
+
* Converts input to a Blob/File suitable for FormData.
|
|
95
|
+
*
|
|
96
|
+
* @internal
|
|
97
|
+
* @param input - Upload input
|
|
98
|
+
* @param filename - Filename to use
|
|
99
|
+
* @returns Blob or File for FormData
|
|
100
|
+
*/
|
|
101
|
+
private toFormDataFile;
|
|
102
|
+
/**
|
|
103
|
+
* Lists all media files.
|
|
104
|
+
*
|
|
105
|
+
* Note: The listmonk media API returns all files at once without pagination.
|
|
106
|
+
*
|
|
107
|
+
* @returns Array of all media files
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const allMedia = await client.media.list();
|
|
112
|
+
* console.log(`Total: ${allMedia.length} files`);
|
|
113
|
+
*
|
|
114
|
+
* // Filter by content type (client-side)
|
|
115
|
+
* const images = allMedia.filter(m => m.content_type.startsWith('image/'));
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
list(): Promise<Media[]>;
|
|
119
|
+
/**
|
|
120
|
+
* Returns an async iterator over all media files.
|
|
121
|
+
*
|
|
122
|
+
* Note: Since the media API doesn't support pagination, this
|
|
123
|
+
* iterator yields all files in a single batch. The `byPage()`
|
|
124
|
+
* method yields a single "page" containing all files.
|
|
125
|
+
*
|
|
126
|
+
* This method is provided for API consistency with other resources.
|
|
127
|
+
*
|
|
128
|
+
* @returns Async iterator over media files
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* // Iterate over all media
|
|
133
|
+
* for await (const file of client.media.listAll()) {
|
|
134
|
+
* console.log(file.filename);
|
|
135
|
+
* }
|
|
136
|
+
*
|
|
137
|
+
* // Iterate by "page" (single page for media)
|
|
138
|
+
* for await (const batch of client.media.listAll().byPage()) {
|
|
139
|
+
* console.log(`Files in batch: ${batch.length}`);
|
|
140
|
+
* }
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
listAll(): PagedAsyncIterableIterator<Media, Media[]>;
|
|
144
|
+
/**
|
|
145
|
+
* Retrieves a media file by ID.
|
|
146
|
+
*
|
|
147
|
+
* @param id - Media file ID
|
|
148
|
+
* @returns The media file metadata
|
|
149
|
+
* @throws {ListmonkNotFoundError} If media file not found
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const media = await client.media.retrieve(42);
|
|
154
|
+
* console.log(`File: ${media.filename}`);
|
|
155
|
+
* console.log(`Type: ${media.content_type}`);
|
|
156
|
+
* console.log(`URL: ${media.url}`);
|
|
157
|
+
* console.log(`Metadata: ${JSON.stringify(media.meta)}`);
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
retrieve(id: number): Promise<Media>;
|
|
161
|
+
/**
|
|
162
|
+
* Deletes a media file by ID.
|
|
163
|
+
*
|
|
164
|
+
* Note: References to this media in campaigns/templates will become broken links.
|
|
165
|
+
*
|
|
166
|
+
* @param id - Media file ID
|
|
167
|
+
* @returns `true` on successful deletion (Gap 1: returns boolean, not void)
|
|
168
|
+
* @throws {ListmonkNotFoundError} If media file not found
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```typescript
|
|
172
|
+
* const deleted = await client.media.remove(42);
|
|
173
|
+
* console.log(`Deleted: ${deleted}`); // true
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
remove(id: number): Promise<boolean>;
|
|
177
|
+
/**
|
|
178
|
+
* Deletes multiple media files by ID.
|
|
179
|
+
*
|
|
180
|
+
* Note: The listmonk API does not support bulk media deletion,
|
|
181
|
+
* so this method deletes files sequentially. If any deletion fails,
|
|
182
|
+
* the error is thrown immediately and remaining files are not deleted
|
|
183
|
+
* (fail-fast behavior per spec).
|
|
184
|
+
*
|
|
185
|
+
* @param ids - Media file IDs to delete
|
|
186
|
+
* @throws {ListmonkNotFoundError} If any media file not found (fail-fast)
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* // Delete multiple files
|
|
191
|
+
* await client.media.deleteMany([1, 2, 3]);
|
|
192
|
+
*
|
|
193
|
+
* // Empty array is a no-op (no API calls)
|
|
194
|
+
* await client.media.deleteMany([]);
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
197
|
+
deleteMany(ids: number[]): Promise<void>;
|
|
198
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod schemas for media-related requests and responses.
|
|
3
|
+
*
|
|
4
|
+
* @module resources/media/schemas
|
|
5
|
+
*/
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
/**
|
|
8
|
+
* Complete media entity returned from API.
|
|
9
|
+
*
|
|
10
|
+
* Represents an uploaded media file (image, PDF, etc.) with metadata.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MediaSchema: z.ZodObject<{
|
|
13
|
+
id: z.ZodNumber;
|
|
14
|
+
uuid: z.ZodString;
|
|
15
|
+
filename: z.ZodString;
|
|
16
|
+
created_at: z.ZodString;
|
|
17
|
+
thumb_url: z.ZodNullable<z.ZodString>;
|
|
18
|
+
url: z.ZodString;
|
|
19
|
+
content_type: z.ZodString;
|
|
20
|
+
provider: z.ZodString;
|
|
21
|
+
meta: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
22
|
+
}, z.core.$strip>;
|
|
23
|
+
/**
|
|
24
|
+
* Schema for validating Node.js { filename, content } upload pattern.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare const MediaUploadObjectSchema: z.ZodObject<{
|
|
29
|
+
filename: z.ZodString;
|
|
30
|
+
content: z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
/**
|
|
33
|
+
* Response for listing all media files.
|
|
34
|
+
* Note: Unlike paginated endpoints, media returns a simple array.
|
|
35
|
+
* The HttpClient automatically unwraps { data: [...] }.
|
|
36
|
+
*/
|
|
37
|
+
export declare const ListMediaResponseSchema: z.ZodArray<z.ZodObject<{
|
|
38
|
+
id: z.ZodNumber;
|
|
39
|
+
uuid: z.ZodString;
|
|
40
|
+
filename: z.ZodString;
|
|
41
|
+
created_at: z.ZodString;
|
|
42
|
+
thumb_url: z.ZodNullable<z.ZodString>;
|
|
43
|
+
url: z.ZodString;
|
|
44
|
+
content_type: z.ZodString;
|
|
45
|
+
provider: z.ZodString;
|
|
46
|
+
meta: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
47
|
+
}, z.core.$strip>>;
|
|
48
|
+
export { DeleteResponseSchema } from "../../schemas";
|