@solytude/listmonk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +542 -0
  3. package/dist/chunk-saezhne8.js +14 -0
  4. package/dist/chunk-saezhne8.js.map +9 -0
  5. package/dist/client.d.ts +430 -0
  6. package/dist/errors/api.d.ts +178 -0
  7. package/dist/errors/base.d.ts +47 -0
  8. package/dist/errors/configuration.d.ts +49 -0
  9. package/dist/errors/index.d.ts +13 -0
  10. package/dist/errors/network.d.ts +69 -0
  11. package/dist/errors/validation.d.ts +57 -0
  12. package/dist/http/auth.d.ts +39 -0
  13. package/dist/http/client.d.ts +149 -0
  14. package/dist/http/hooks.d.ts +90 -0
  15. package/dist/http/index.d.ts +10 -0
  16. package/dist/http/resource.d.ts +100 -0
  17. package/dist/http/sse.d.ts +36 -0
  18. package/dist/http/url.d.ts +51 -0
  19. package/dist/index.d.ts +64 -0
  20. package/dist/index.js +16039 -0
  21. package/dist/index.js.map +120 -0
  22. package/dist/resources/admin/admin.d.ts +92 -0
  23. package/dist/resources/admin/index.d.ts +10 -0
  24. package/dist/resources/admin/schemas.d.ts +23 -0
  25. package/dist/resources/admin/types.d.ts +29 -0
  26. package/dist/resources/bounces/bounces.d.ts +262 -0
  27. package/dist/resources/bounces/index.d.ts +10 -0
  28. package/dist/resources/bounces/schemas.d.ts +86 -0
  29. package/dist/resources/bounces/types.d.ts +37 -0
  30. package/dist/resources/campaigns/campaigns.d.ts +339 -0
  31. package/dist/resources/campaigns/index.d.ts +10 -0
  32. package/dist/resources/campaigns/schemas.d.ts +374 -0
  33. package/dist/resources/campaigns/types.d.ts +111 -0
  34. package/dist/resources/dashboard/dashboard.d.ts +73 -0
  35. package/dist/resources/dashboard/index.d.ts +10 -0
  36. package/dist/resources/dashboard/schemas.d.ts +55 -0
  37. package/dist/resources/dashboard/types.d.ts +22 -0
  38. package/dist/resources/import/import.d.ts +215 -0
  39. package/dist/resources/import/index.d.ts +10 -0
  40. package/dist/resources/import/schemas.d.ts +109 -0
  41. package/dist/resources/import/types.d.ts +72 -0
  42. package/dist/resources/lists/index.d.ts +10 -0
  43. package/dist/resources/lists/lists.d.ts +180 -0
  44. package/dist/resources/lists/schemas.d.ts +176 -0
  45. package/dist/resources/lists/types.d.ts +56 -0
  46. package/dist/resources/maintenance/index.d.ts +10 -0
  47. package/dist/resources/maintenance/maintenance.d.ts +92 -0
  48. package/dist/resources/maintenance/schemas.d.ts +36 -0
  49. package/dist/resources/maintenance/types.d.ts +31 -0
  50. package/dist/resources/media/index.d.ts +10 -0
  51. package/dist/resources/media/media.d.ts +198 -0
  52. package/dist/resources/media/schemas.d.ts +48 -0
  53. package/dist/resources/media/types.d.ts +48 -0
  54. package/dist/resources/public/index.d.ts +10 -0
  55. package/dist/resources/public/public.d.ts +111 -0
  56. package/dist/resources/public/schemas.d.ts +52 -0
  57. package/dist/resources/public/types.d.ts +30 -0
  58. package/dist/resources/settings/index.d.ts +10 -0
  59. package/dist/resources/settings/schemas.d.ts +374 -0
  60. package/dist/resources/settings/settings.d.ts +106 -0
  61. package/dist/resources/settings/types.d.ts +78 -0
  62. package/dist/resources/subscribers/index.d.ts +10 -0
  63. package/dist/resources/subscribers/schemas.d.ts +360 -0
  64. package/dist/resources/subscribers/subscribers.d.ts +308 -0
  65. package/dist/resources/subscribers/types.d.ts +113 -0
  66. package/dist/resources/templates/index.d.ts +10 -0
  67. package/dist/resources/templates/schemas.d.ts +110 -0
  68. package/dist/resources/templates/templates.d.ts +225 -0
  69. package/dist/resources/templates/types.d.ts +45 -0
  70. package/dist/resources/tx/index.d.ts +10 -0
  71. package/dist/resources/tx/schemas.d.ts +67 -0
  72. package/dist/resources/tx/tx.d.ts +167 -0
  73. package/dist/resources/tx/types.d.ts +88 -0
  74. package/dist/schemas/common.d.ts +48 -0
  75. package/dist/schemas/index.d.ts +6 -0
  76. package/dist/testing/errors.d.ts +25 -0
  77. package/dist/testing/factories/bounce.d.ts +43 -0
  78. package/dist/testing/factories/campaign.d.ts +43 -0
  79. package/dist/testing/factories/common.d.ts +54 -0
  80. package/dist/testing/factories/index.d.ts +12 -0
  81. package/dist/testing/factories/list.d.ts +43 -0
  82. package/dist/testing/factories/media.d.ts +40 -0
  83. package/dist/testing/factories/subscriber.d.ts +43 -0
  84. package/dist/testing/factories/template.d.ts +40 -0
  85. package/dist/testing/index.d.ts +39 -0
  86. package/dist/testing/index.js +573 -0
  87. package/dist/testing/index.js.map +32 -0
  88. package/dist/testing/mock-client.d.ts +119 -0
  89. package/dist/testing/mock-function.d.ts +28 -0
  90. package/dist/testing/resources/admin.d.ts +20 -0
  91. package/dist/testing/resources/bounces.d.ts +22 -0
  92. package/dist/testing/resources/campaigns.d.ts +31 -0
  93. package/dist/testing/resources/dashboard.d.ts +17 -0
  94. package/dist/testing/resources/import.d.ts +19 -0
  95. package/dist/testing/resources/index.d.ts +18 -0
  96. package/dist/testing/resources/lists.d.ts +24 -0
  97. package/dist/testing/resources/maintenance.d.ts +18 -0
  98. package/dist/testing/resources/media.d.ts +21 -0
  99. package/dist/testing/resources/public.d.ts +18 -0
  100. package/dist/testing/resources/settings.d.ts +19 -0
  101. package/dist/testing/resources/subscribers.d.ts +33 -0
  102. package/dist/testing/resources/templates.d.ts +24 -0
  103. package/dist/testing/resources/tx.d.ts +16 -0
  104. package/dist/testing/types.d.ts +138 -0
  105. package/dist/types/config.d.ts +59 -0
  106. package/dist/types/index.d.ts +7 -0
  107. package/dist/types/pagination.d.ts +37 -0
  108. package/package.json +97 -0
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Error class exports for the listmonk SDK.
3
+ *
4
+ * All SDK errors extend the base `ListmonkError` class, enabling
5
+ * unified error handling via `instanceof ListmonkError`.
6
+ *
7
+ * @module errors
8
+ */
9
+ export { ListmonkError } from "./base";
10
+ export { ListmonkApiError, ListmonkBadRequestError, ListmonkAuthenticationError, ListmonkPermissionDeniedError, ListmonkNotFoundError, ListmonkRateLimitError, ListmonkInternalServerError, } from "./api";
11
+ export { ListmonkValidationError } from "./validation";
12
+ export { ListmonkNetworkError, ListmonkTimeoutError } from "./network";
13
+ export { ListmonkConfigurationError } from "./configuration";
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Network-level errors for fetch failures.
3
+ *
4
+ * Thrown when network communication fails, including DNS resolution,
5
+ * connection errors, and request timeouts.
6
+ *
7
+ * @module errors/network
8
+ */
9
+ import { ListmonkError } from "./base";
10
+ /**
11
+ * Error thrown when a network-level failure occurs.
12
+ *
13
+ * This includes:
14
+ * - DNS resolution failures
15
+ * - Connection refused/reset
16
+ * - TLS/SSL errors
17
+ * - Other fetch-level failures
18
+ *
19
+ * Network errors are generally retryable.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * try {
24
+ * await client.subscribers.list();
25
+ * } catch (error) {
26
+ * if (error instanceof ListmonkNetworkError) {
27
+ * console.error('Network error:', error.message);
28
+ * console.error('Underlying cause:', error.cause);
29
+ * }
30
+ * }
31
+ * ```
32
+ */
33
+ export declare class ListmonkNetworkError extends ListmonkError {
34
+ readonly name: string;
35
+ }
36
+ /**
37
+ * Error thrown when a request times out.
38
+ *
39
+ * Extends ListmonkNetworkError as timeouts are a specific type
40
+ * of network failure. Includes the timeout value for debugging.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * try {
45
+ * await client.subscribers.list({ timeout: 5000 });
46
+ * } catch (error) {
47
+ * if (error instanceof ListmonkTimeoutError) {
48
+ * console.error(`Request timed out after ${error.timeout}ms`);
49
+ * }
50
+ * }
51
+ * ```
52
+ */
53
+ export declare class ListmonkTimeoutError extends ListmonkNetworkError {
54
+ readonly name: string;
55
+ /**
56
+ * The timeout value in milliseconds that was exceeded.
57
+ */
58
+ readonly timeout: number;
59
+ /**
60
+ * Creates a new timeout error.
61
+ *
62
+ * @param message - Description of the timeout
63
+ * @param timeout - The timeout value in milliseconds
64
+ * @param options - Optional error options
65
+ */
66
+ constructor(message: string, timeout: number, options?: {
67
+ cause?: unknown;
68
+ });
69
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Validation error for Zod schema failures.
3
+ *
4
+ * Thrown when API responses or request data fails Zod validation,
5
+ * indicating a mismatch between expected and actual data structures.
6
+ *
7
+ * @module errors/validation
8
+ */
9
+ import type { ZodError } from "zod";
10
+ import { ListmonkError } from "./base";
11
+ /**
12
+ * Error thrown when data validation fails.
13
+ *
14
+ * Contains the Zod error with detailed validation issues,
15
+ * the original invalid data, and the API endpoint if applicable.
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * try {
20
+ * await client.subscribers.get(123);
21
+ * } catch (error) {
22
+ * if (error instanceof ListmonkValidationError) {
23
+ * console.error('Validation failed:', error.zodError?.issues);
24
+ * console.error('Invalid data:', error.data);
25
+ * }
26
+ * }
27
+ * ```
28
+ */
29
+ export declare class ListmonkValidationError extends ListmonkError {
30
+ readonly name: string;
31
+ /**
32
+ * The Zod validation error with detailed issue information.
33
+ */
34
+ readonly zodError?: ZodError;
35
+ /**
36
+ * The data that failed validation.
37
+ */
38
+ readonly data?: unknown;
39
+ /**
40
+ * The API endpoint where validation failed, if applicable.
41
+ */
42
+ readonly endpoint?: string;
43
+ /**
44
+ * Creates a new validation error.
45
+ *
46
+ * @param message - Description of the validation failure
47
+ * @param options - Optional validation details
48
+ * @param options.zodError - The Zod error with detailed issues
49
+ * @param options.data - The data that failed validation
50
+ * @param options.endpoint - The API endpoint if this was a response validation
51
+ */
52
+ constructor(message: string, options?: {
53
+ zodError?: ZodError;
54
+ data?: unknown;
55
+ endpoint?: string;
56
+ });
57
+ }
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Basic Auth encoding utilities.
3
+ *
4
+ * Provides functions for encoding credentials for HTTP Basic Authentication.
5
+ *
6
+ * @module http/auth
7
+ */
8
+ /**
9
+ * Encodes username and password for Basic Auth.
10
+ *
11
+ * @param username - The username
12
+ * @param password - The password
13
+ * @returns Base64-encoded credentials string
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * const encoded = encodeBasicAuth('admin', 'secret');
18
+ * // Returns: 'YWRtaW46c2VjcmV0'
19
+ * ```
20
+ */
21
+ export declare function encodeBasicAuth(username: string, password: string): string;
22
+ /**
23
+ * Creates a complete Basic Auth header value.
24
+ *
25
+ * @param username - The username
26
+ * @param password - The password
27
+ * @returns Complete Authorization header value (e.g., "Basic YWRtaW46c2VjcmV0")
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const header = createAuthHeader('admin', 'secret');
32
+ * // Returns: 'Basic YWRtaW46c2VjcmV0'
33
+ *
34
+ * fetch(url, {
35
+ * headers: { Authorization: header }
36
+ * });
37
+ * ```
38
+ */
39
+ export declare function createAuthHeader(username: string, password: string): string;
@@ -0,0 +1,149 @@
1
+ /**
2
+ * HTTP client for making authenticated requests to listmonk.
3
+ *
4
+ * Handles authentication, retry logic, timeout, hooks, and error handling.
5
+ *
6
+ * @module http/client
7
+ */
8
+ import type { z } from "zod";
9
+ import type { RequestHook, ResponseHook, HttpMethod } from "./hooks";
10
+ import type { AuthCredentials, FetchLike } from "../types/config";
11
+ /**
12
+ * Options for individual HTTP requests.
13
+ */
14
+ export interface RequestOptions {
15
+ /** HTTP method */
16
+ method: HttpMethod;
17
+ /** API endpoint path (e.g., '/api/subscribers') */
18
+ path: string;
19
+ /** Request body (will be JSON-serialized) */
20
+ body?: unknown;
21
+ /** Query parameters */
22
+ query?: Record<string, unknown>;
23
+ /** Per-request timeout override in milliseconds */
24
+ timeout?: number;
25
+ /** User-provided abort signal */
26
+ signal?: AbortSignal;
27
+ /** Skip automatic retry for this request */
28
+ skipRetry?: boolean;
29
+ /**
30
+ * FormData for multipart requests (e.g., file attachments).
31
+ * When set, body is ignored and Content-Type is not set
32
+ * (browser/runtime will set it with proper boundary).
33
+ */
34
+ multipart?: FormData;
35
+ /**
36
+ * Skip authentication for this request.
37
+ * Used for public endpoints that don't require authorization.
38
+ */
39
+ skipAuth?: boolean;
40
+ }
41
+ /**
42
+ * HTTP client for the listmonk SDK.
43
+ *
44
+ * Provides authenticated HTTP requests with automatic retry,
45
+ * timeout handling, and extensibility hooks.
46
+ */
47
+ export declare class HttpClient {
48
+ private readonly baseUrl;
49
+ private readonly authHeader;
50
+ private readonly timeout;
51
+ private readonly maxRetries;
52
+ private readonly debug;
53
+ private readonly fetch;
54
+ private readonly requestHooks;
55
+ private readonly responseHooks;
56
+ private readonly retryConfig;
57
+ /**
58
+ * Creates a new HTTP client.
59
+ *
60
+ * @param options - Client configuration options
61
+ */
62
+ constructor(options: {
63
+ url: string;
64
+ auth: AuthCredentials;
65
+ timeout?: number;
66
+ maxRetries?: number;
67
+ debug?: boolean;
68
+ fetch?: FetchLike;
69
+ onRequest?: RequestHook;
70
+ onResponse?: ResponseHook;
71
+ });
72
+ /**
73
+ * Makes an HTTP request with retry, timeout, and validation.
74
+ *
75
+ * @param options - Request options
76
+ * @param schema - Zod schema for response validation
77
+ * @returns Validated response data
78
+ * @throws {ListmonkApiError} On API errors (4xx, 5xx)
79
+ * @throws {ListmonkNetworkError} On network failures
80
+ * @throws {ListmonkTimeoutError} On request timeout
81
+ * @throws {ListmonkValidationError} On response validation failure
82
+ */
83
+ request<T>(options: RequestOptions, schema?: z.ZodType<T>): Promise<T>;
84
+ /**
85
+ * Makes a raw HTTP request returning the Response object directly.
86
+ *
87
+ * Useful for streaming responses like SSE where you need access
88
+ * to the response body stream.
89
+ *
90
+ * @param options - Request options
91
+ * @returns The raw Response object
92
+ * @throws {ListmonkApiError} On API errors (4xx, 5xx)
93
+ * @throws {ListmonkNetworkError} On network failures
94
+ * @throws {ListmonkTimeoutError} On request timeout
95
+ */
96
+ requestRaw(options: RequestOptions): Promise<Response>;
97
+ /**
98
+ * Makes a fetch request with timeout handling.
99
+ * Uses AbortSignal.timeout() for cleaner timeout management (Node 17.3+).
100
+ */
101
+ private fetchWithTimeout;
102
+ /**
103
+ * Merges timeout and user abort signals.
104
+ * Uses AbortSignal.any() which is available in Node 20+ and handles
105
+ * cleanup automatically, avoiding memory leaks from event listeners.
106
+ */
107
+ private mergeSignals;
108
+ /**
109
+ * Parses response body as JSON.
110
+ */
111
+ private parseResponseBody;
112
+ /**
113
+ * Validates response data against a Zod schema.
114
+ */
115
+ private validateResponse;
116
+ /**
117
+ * Calculates backoff delay with jitter.
118
+ * Jitter is applied before capping to ensure the final delay never exceeds maxDelay.
119
+ */
120
+ private calculateBackoffDelay;
121
+ /**
122
+ * Checks if an error is retryable.
123
+ */
124
+ private isRetryableError;
125
+ /**
126
+ * Checks if an error is a fetch error (network issue).
127
+ */
128
+ private isFetchError;
129
+ /**
130
+ * Gets retry-after value in milliseconds from error.
131
+ */
132
+ private getRetryAfterMs;
133
+ /**
134
+ * Checks for deprecation headers and logs warnings.
135
+ */
136
+ private checkDeprecationHeaders;
137
+ /**
138
+ * Logs debug information with redaction.
139
+ */
140
+ private debugLog;
141
+ /**
142
+ * Redacts sensitive information from headers.
143
+ */
144
+ private redactHeaders;
145
+ /**
146
+ * Sleeps for the specified duration.
147
+ */
148
+ private sleep;
149
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Request and response hook types for extensibility.
3
+ *
4
+ * Hooks allow SDK users to observe and optionally modify requests,
5
+ * and observe responses for logging, metrics, or custom handling.
6
+ *
7
+ * @module http/hooks
8
+ */
9
+ /**
10
+ * HTTP methods supported by the SDK.
11
+ */
12
+ export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE";
13
+ /**
14
+ * Information about an outgoing request.
15
+ *
16
+ * Passed to request hooks before the request is sent.
17
+ */
18
+ export interface RequestInfo {
19
+ /** HTTP method */
20
+ readonly method: HttpMethod;
21
+ /** Full request URL */
22
+ readonly url: string;
23
+ /** Request headers (mutable for modification) */
24
+ readonly headers: Headers;
25
+ /** Request body (if applicable) */
26
+ readonly body?: unknown;
27
+ }
28
+ /**
29
+ * Information about a received response.
30
+ *
31
+ * Passed to response hooks after the response is received.
32
+ */
33
+ export interface ResponseInfo {
34
+ /** HTTP status code */
35
+ readonly status: number;
36
+ /** Response headers */
37
+ readonly headers: Headers;
38
+ /** Parsed response body */
39
+ readonly body: unknown;
40
+ /** X-Request-ID header value if present */
41
+ readonly requestId?: string;
42
+ /** Request duration in milliseconds */
43
+ readonly duration: number;
44
+ /** API endpoint that was called */
45
+ readonly endpoint: string;
46
+ }
47
+ /**
48
+ * Hook called before each request is sent.
49
+ *
50
+ * Can modify the request by returning a modified RequestInfo object.
51
+ * Return void or undefined to pass through unchanged.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const addTimingHeader: RequestHook = (info) => {
56
+ * info.headers.set('X-Request-Start', Date.now().toString());
57
+ * return info;
58
+ * };
59
+ * ```
60
+ */
61
+ export type RequestHook = (info: RequestInfo) => RequestInfo | undefined;
62
+ /**
63
+ * Hook called after each response is received.
64
+ *
65
+ * Observation only - cannot modify the response.
66
+ * Useful for logging, metrics, or error tracking.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const logResponse: ResponseHook = (info) => {
71
+ * console.log(`${info.endpoint}: ${info.status} (${info.duration}ms)`);
72
+ * };
73
+ * ```
74
+ */
75
+ export type ResponseHook = (info: ResponseInfo) => void;
76
+ /**
77
+ * Applies request hooks in sequence, accumulating modifications.
78
+ *
79
+ * @param hooks - Array of request hooks to apply
80
+ * @param info - Initial request info
81
+ * @returns Modified request info (or original if no modifications)
82
+ */
83
+ export declare function applyRequestHooks(hooks: RequestHook[], info: RequestInfo): RequestInfo;
84
+ /**
85
+ * Applies response hooks in sequence.
86
+ *
87
+ * @param hooks - Array of response hooks to apply
88
+ * @param info - Response info to observe
89
+ */
90
+ export declare function applyResponseHooks(hooks: ResponseHook[], info: ResponseInfo): void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * HTTP module exports.
3
+ *
4
+ * @module http
5
+ */
6
+ export { HttpClient, type RequestOptions } from "./client";
7
+ export { encodeBasicAuth, createAuthHeader } from "./auth";
8
+ export { normalizeBaseUrl, buildUrl, validateHttpsUrl } from "./url";
9
+ export { type HttpMethod, type RequestInfo, type ResponseInfo, type RequestHook, type ResponseHook, applyRequestHooks, applyResponseHooks, } from "./hooks";
10
+ export { APIResource, type ResourceRequestOptions } from "./resource";
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Base class for API resource modules.
3
+ *
4
+ * Provides convenience methods for HTTP requests that resource modules
5
+ * can use to interact with the listmonk API.
6
+ *
7
+ * @module http/resource
8
+ */
9
+ import type { z } from "zod";
10
+ import type { HttpClient, RequestOptions } from "./client";
11
+ /**
12
+ * Options for resource methods (excluding method and path).
13
+ */
14
+ export type ResourceRequestOptions = Omit<RequestOptions, "method" | "path">;
15
+ /**
16
+ * Abstract base class for all listmonk resource modules.
17
+ *
18
+ * Resource modules (subscribers, lists, campaigns, etc.) extend this class
19
+ * to get access to HTTP request methods.
20
+ *
21
+ * @example
22
+ * ```typescript
23
+ * class SubscribersResource extends APIResource {
24
+ * // Use different public method names to avoid shadowing protected methods
25
+ * async retrieve(id: number): Promise<Subscriber> {
26
+ * return this.get(`/api/subscribers/${id}`, SubscriberSchema);
27
+ * }
28
+ *
29
+ * async create(data: CreateSubscriber): Promise<Subscriber> {
30
+ * return this.post('/api/subscribers', SubscriberSchema, { body: data });
31
+ * }
32
+ *
33
+ * async list(options?: ListOptions): Promise<SubscriberPage> {
34
+ * return this.get('/api/subscribers', SubscriberPageSchema, { query: options });
35
+ * }
36
+ * }
37
+ * ```
38
+ *
39
+ * @remarks
40
+ * The protected methods (get, post, put, delete) should not be shadowed by
41
+ * public methods with the same name. Use alternative names like `retrieve`,
42
+ * `list`, `remove` for public CRUD methods.
43
+ */
44
+ export declare abstract class APIResource {
45
+ /**
46
+ * The HTTP client instance.
47
+ * @internal
48
+ */
49
+ protected readonly _client: HttpClient;
50
+ /**
51
+ * Creates a new resource instance.
52
+ *
53
+ * @param client - The HTTP client to use for requests
54
+ */
55
+ constructor(client: HttpClient);
56
+ /**
57
+ * Makes a GET request to the specified path.
58
+ *
59
+ * @param path - API endpoint path
60
+ * @param schema - Optional Zod schema for response validation
61
+ * @param options - Additional request options
62
+ * @returns Response data
63
+ */
64
+ protected get<T>(path: string, schema?: z.ZodType<T>, options?: ResourceRequestOptions): Promise<T>;
65
+ protected get<T>(path: string, options?: ResourceRequestOptions): Promise<T>;
66
+ /**
67
+ * Makes a POST request to the specified path.
68
+ *
69
+ * @param path - API endpoint path
70
+ * @param schema - Optional Zod schema for response validation
71
+ * @param options - Additional request options (including body)
72
+ * @returns Response data
73
+ */
74
+ protected post<T>(path: string, schema?: z.ZodType<T>, options?: ResourceRequestOptions): Promise<T>;
75
+ protected post<T>(path: string, options?: ResourceRequestOptions): Promise<T>;
76
+ /**
77
+ * Makes a PUT request to the specified path.
78
+ *
79
+ * @param path - API endpoint path
80
+ * @param schema - Optional Zod schema for response validation
81
+ * @param options - Additional request options (including body)
82
+ * @returns Response data
83
+ */
84
+ protected put<T>(path: string, schema?: z.ZodType<T>, options?: ResourceRequestOptions): Promise<T>;
85
+ protected put<T>(path: string, options?: ResourceRequestOptions): Promise<T>;
86
+ /**
87
+ * Makes a DELETE request to the specified path.
88
+ *
89
+ * @param path - API endpoint path
90
+ * @param schema - Optional Zod schema for response validation
91
+ * @param options - Additional request options
92
+ * @returns Response data
93
+ */
94
+ protected delete<T>(path: string, schema?: z.ZodType<T>, options?: ResourceRequestOptions): Promise<T>;
95
+ protected delete<T>(path: string, options?: ResourceRequestOptions): Promise<T>;
96
+ /**
97
+ * Resolves overloaded arguments for schema and options.
98
+ */
99
+ private resolveArgs;
100
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Server-Sent Events (SSE) streaming utilities.
3
+ *
4
+ * Provides AsyncGenerator-based SSE parsing for use with listmonk's
5
+ * real-time event stream endpoint.
6
+ *
7
+ * @module http/sse
8
+ */
9
+ import type { z } from "zod";
10
+ /**
11
+ * Options for SSE streaming.
12
+ */
13
+ export interface SSEOptions {
14
+ /** AbortSignal for cancellation */
15
+ signal?: AbortSignal;
16
+ }
17
+ /**
18
+ * Parses Server-Sent Events from a Response stream.
19
+ *
20
+ * This is a low-level utility that yields parsed and validated
21
+ * events from an SSE response body.
22
+ *
23
+ * @param response - The fetch Response with an SSE body stream
24
+ * @param schema - Zod schema for validating event data
25
+ * @yields Validated event objects
26
+ * @throws {ListmonkValidationError} If event data fails schema validation
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * const response = await client.requestRaw({ method: 'GET', path: '/api/events' });
31
+ * for await (const event of streamSSE(response, SSEEventSchema)) {
32
+ * console.log(event.type, event.message);
33
+ * }
34
+ * ```
35
+ */
36
+ export declare function streamSSE<T>(response: Response, schema: z.ZodType<T>): AsyncGenerator<T, void, undefined>;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * URL normalization and path building utilities.
3
+ *
4
+ * Provides functions for URL validation, normalization, and building
5
+ * complete request URLs with query parameters.
6
+ *
7
+ * @module http/url
8
+ */
9
+ /**
10
+ * Validates that a URL uses HTTPS.
11
+ *
12
+ * Throws ListmonkConfigurationError if the URL is invalid or uses HTTP.
13
+ *
14
+ * @param url - The URL to validate
15
+ * @throws {ListmonkConfigurationError} If URL is invalid or not HTTPS
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * validateHttpsUrl('https://listmonk.example.com'); // OK
20
+ * validateHttpsUrl('http://example.com'); // Throws
21
+ * ```
22
+ */
23
+ export declare function validateHttpsUrl(url: string): void;
24
+ /**
25
+ * Normalizes a base URL by removing trailing slashes.
26
+ *
27
+ * @param url - The URL to normalize
28
+ * @returns URL with trailing slashes removed
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * normalizeBaseUrl('https://example.com/'); // 'https://example.com'
33
+ * normalizeBaseUrl('https://example.com/api/'); // 'https://example.com/api'
34
+ * ```
35
+ */
36
+ export declare function normalizeBaseUrl(url: string): string;
37
+ /**
38
+ * Builds a complete URL from base URL, path, and optional query parameters.
39
+ *
40
+ * @param baseUrl - The base URL (should be normalized)
41
+ * @param path - The API path (e.g., '/api/subscribers')
42
+ * @param query - Optional query parameters
43
+ * @returns Complete URL string
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * buildUrl('https://api.example.com', '/subscribers', { page: 1 });
48
+ * // Returns: 'https://api.example.com/subscribers?page=1'
49
+ * ```
50
+ */
51
+ export declare function buildUrl(baseUrl: string, path: string, query?: Record<string, unknown>): string;