@maloma/listmonk 1.0.0 → 1.0.1

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 (107) hide show
  1. package/README.md +14 -8
  2. package/dist/index.d.ts +5917 -63
  3. package/dist/index.js +765 -14271
  4. package/dist/testing/index.d.ts +900 -38
  5. package/dist/testing/index.js +1 -5
  6. package/package.json +38 -59
  7. package/dist/chunk-saezhne8.js +0 -14
  8. package/dist/chunk-saezhne8.js.map +0 -9
  9. package/dist/client.d.ts +0 -430
  10. package/dist/errors/api.d.ts +0 -178
  11. package/dist/errors/base.d.ts +0 -47
  12. package/dist/errors/configuration.d.ts +0 -49
  13. package/dist/errors/index.d.ts +0 -13
  14. package/dist/errors/network.d.ts +0 -69
  15. package/dist/errors/validation.d.ts +0 -57
  16. package/dist/http/auth.d.ts +0 -39
  17. package/dist/http/client.d.ts +0 -149
  18. package/dist/http/hooks.d.ts +0 -90
  19. package/dist/http/index.d.ts +0 -10
  20. package/dist/http/resource.d.ts +0 -100
  21. package/dist/http/sse.d.ts +0 -36
  22. package/dist/http/url.d.ts +0 -51
  23. package/dist/index.js.map +0 -120
  24. package/dist/resources/admin/admin.d.ts +0 -92
  25. package/dist/resources/admin/index.d.ts +0 -10
  26. package/dist/resources/admin/schemas.d.ts +0 -23
  27. package/dist/resources/admin/types.d.ts +0 -29
  28. package/dist/resources/bounces/bounces.d.ts +0 -262
  29. package/dist/resources/bounces/index.d.ts +0 -10
  30. package/dist/resources/bounces/schemas.d.ts +0 -86
  31. package/dist/resources/bounces/types.d.ts +0 -37
  32. package/dist/resources/campaigns/campaigns.d.ts +0 -339
  33. package/dist/resources/campaigns/index.d.ts +0 -10
  34. package/dist/resources/campaigns/schemas.d.ts +0 -374
  35. package/dist/resources/campaigns/types.d.ts +0 -111
  36. package/dist/resources/dashboard/dashboard.d.ts +0 -73
  37. package/dist/resources/dashboard/index.d.ts +0 -10
  38. package/dist/resources/dashboard/schemas.d.ts +0 -55
  39. package/dist/resources/dashboard/types.d.ts +0 -22
  40. package/dist/resources/import/import.d.ts +0 -215
  41. package/dist/resources/import/index.d.ts +0 -10
  42. package/dist/resources/import/schemas.d.ts +0 -109
  43. package/dist/resources/import/types.d.ts +0 -72
  44. package/dist/resources/lists/index.d.ts +0 -10
  45. package/dist/resources/lists/lists.d.ts +0 -180
  46. package/dist/resources/lists/schemas.d.ts +0 -176
  47. package/dist/resources/lists/types.d.ts +0 -56
  48. package/dist/resources/maintenance/index.d.ts +0 -10
  49. package/dist/resources/maintenance/maintenance.d.ts +0 -92
  50. package/dist/resources/maintenance/schemas.d.ts +0 -36
  51. package/dist/resources/maintenance/types.d.ts +0 -31
  52. package/dist/resources/media/index.d.ts +0 -10
  53. package/dist/resources/media/media.d.ts +0 -198
  54. package/dist/resources/media/schemas.d.ts +0 -48
  55. package/dist/resources/media/types.d.ts +0 -48
  56. package/dist/resources/public/index.d.ts +0 -10
  57. package/dist/resources/public/public.d.ts +0 -111
  58. package/dist/resources/public/schemas.d.ts +0 -52
  59. package/dist/resources/public/types.d.ts +0 -30
  60. package/dist/resources/settings/index.d.ts +0 -10
  61. package/dist/resources/settings/schemas.d.ts +0 -374
  62. package/dist/resources/settings/settings.d.ts +0 -106
  63. package/dist/resources/settings/types.d.ts +0 -78
  64. package/dist/resources/subscribers/index.d.ts +0 -10
  65. package/dist/resources/subscribers/schemas.d.ts +0 -360
  66. package/dist/resources/subscribers/subscribers.d.ts +0 -308
  67. package/dist/resources/subscribers/types.d.ts +0 -113
  68. package/dist/resources/templates/index.d.ts +0 -10
  69. package/dist/resources/templates/schemas.d.ts +0 -110
  70. package/dist/resources/templates/templates.d.ts +0 -225
  71. package/dist/resources/templates/types.d.ts +0 -45
  72. package/dist/resources/tx/index.d.ts +0 -10
  73. package/dist/resources/tx/schemas.d.ts +0 -67
  74. package/dist/resources/tx/tx.d.ts +0 -167
  75. package/dist/resources/tx/types.d.ts +0 -88
  76. package/dist/schemas/common.d.ts +0 -48
  77. package/dist/schemas/index.d.ts +0 -6
  78. package/dist/testing/errors.d.ts +0 -25
  79. package/dist/testing/factories/bounce.d.ts +0 -43
  80. package/dist/testing/factories/campaign.d.ts +0 -43
  81. package/dist/testing/factories/common.d.ts +0 -54
  82. package/dist/testing/factories/index.d.ts +0 -12
  83. package/dist/testing/factories/list.d.ts +0 -43
  84. package/dist/testing/factories/media.d.ts +0 -40
  85. package/dist/testing/factories/subscriber.d.ts +0 -43
  86. package/dist/testing/factories/template.d.ts +0 -40
  87. package/dist/testing/index.js.map +0 -32
  88. package/dist/testing/mock-client.d.ts +0 -119
  89. package/dist/testing/mock-function.d.ts +0 -28
  90. package/dist/testing/resources/admin.d.ts +0 -20
  91. package/dist/testing/resources/bounces.d.ts +0 -22
  92. package/dist/testing/resources/campaigns.d.ts +0 -31
  93. package/dist/testing/resources/dashboard.d.ts +0 -17
  94. package/dist/testing/resources/import.d.ts +0 -19
  95. package/dist/testing/resources/index.d.ts +0 -18
  96. package/dist/testing/resources/lists.d.ts +0 -24
  97. package/dist/testing/resources/maintenance.d.ts +0 -18
  98. package/dist/testing/resources/media.d.ts +0 -21
  99. package/dist/testing/resources/public.d.ts +0 -18
  100. package/dist/testing/resources/settings.d.ts +0 -19
  101. package/dist/testing/resources/subscribers.d.ts +0 -33
  102. package/dist/testing/resources/templates.d.ts +0 -24
  103. package/dist/testing/resources/tx.d.ts +0 -16
  104. package/dist/testing/types.d.ts +0 -138
  105. package/dist/types/config.d.ts +0 -59
  106. package/dist/types/index.d.ts +0 -7
  107. package/dist/types/pagination.d.ts +0 -37
@@ -1,178 +0,0 @@
1
- /**
2
- * API error classes for HTTP response failures.
3
- *
4
- * Provides a hierarchy of errors for different HTTP status codes,
5
- * with a factory method for automatic error type selection.
6
- *
7
- * @module errors/api
8
- */
9
- import { ListmonkError } from "./base";
10
- /**
11
- * Base error for all HTTP API failures (4xx and 5xx responses).
12
- *
13
- * Contains the HTTP status code, response body, request ID,
14
- * and endpoint information for debugging.
15
- *
16
- * @example
17
- * ```typescript
18
- * try {
19
- * await client.subscribers.get(123);
20
- * } catch (error) {
21
- * if (error instanceof ListmonkApiError) {
22
- * console.error(`API error ${error.status}:`, error.message);
23
- * console.error('Request ID:', error.requestId);
24
- * }
25
- * }
26
- * ```
27
- */
28
- export declare class ListmonkApiError extends ListmonkError {
29
- readonly name: string;
30
- /**
31
- * HTTP status code of the response.
32
- */
33
- readonly status: number;
34
- /**
35
- * Parsed response body.
36
- */
37
- readonly body: unknown;
38
- /**
39
- * The API endpoint that failed.
40
- */
41
- readonly endpoint: string;
42
- /**
43
- * The X-Request-ID header value, if present.
44
- * Useful for correlating with server logs.
45
- */
46
- readonly requestId?: string;
47
- /**
48
- * The response headers.
49
- */
50
- readonly headers?: Headers;
51
- /**
52
- * Creates a new API error.
53
- *
54
- * @param message - Human-readable error message
55
- * @param status - HTTP status code
56
- * @param body - Parsed response body
57
- * @param endpoint - The API endpoint that failed
58
- * @param requestId - Optional X-Request-ID value
59
- * @param headers - Optional response headers
60
- */
61
- constructor(message: string, status: number, body: unknown, endpoint: string, requestId?: string, headers?: Headers);
62
- /**
63
- * Creates the appropriate error subclass based on HTTP status code.
64
- *
65
- * @param response - The fetch Response object
66
- * @param body - Parsed response body
67
- * @param endpoint - The API endpoint that was called
68
- * @returns The appropriate ListmonkApiError subclass
69
- */
70
- static fromResponse(response: Response, body: unknown, endpoint: string): ListmonkApiError;
71
- }
72
- /**
73
- * Error thrown for HTTP 400 Bad Request responses.
74
- *
75
- * Indicates the request was malformed or contained invalid data.
76
- */
77
- export declare class ListmonkBadRequestError extends ListmonkApiError {
78
- readonly name: string;
79
- readonly status: number;
80
- /**
81
- * Creates a new bad request error.
82
- *
83
- * @param message - Error message
84
- * @param body - Response body with validation details
85
- * @param endpoint - The API endpoint
86
- * @param requestId - Optional X-Request-ID
87
- * @param headers - Optional response headers
88
- */
89
- constructor(message: string, body: unknown, endpoint: string, requestId?: string, headers?: Headers);
90
- }
91
- /**
92
- * Error thrown for HTTP 401 Unauthorized responses.
93
- *
94
- * Indicates the request lacked valid authentication credentials.
95
- */
96
- export declare class ListmonkAuthenticationError extends ListmonkApiError {
97
- readonly name: string;
98
- readonly status: number;
99
- /**
100
- * Creates a new authentication error.
101
- *
102
- * @param message - Error message
103
- * @param endpoint - The API endpoint
104
- * @param requestId - Optional X-Request-ID
105
- * @param headers - Optional response headers
106
- */
107
- constructor(message: string, endpoint: string, requestId?: string, headers?: Headers);
108
- }
109
- /**
110
- * Error thrown for HTTP 403 Forbidden responses.
111
- *
112
- * Indicates the authenticated user lacks permission for the requested action.
113
- */
114
- export declare class ListmonkPermissionDeniedError extends ListmonkApiError {
115
- readonly name: string;
116
- readonly status: number;
117
- /**
118
- * Creates a new permission denied error.
119
- *
120
- * @param message - Error message
121
- * @param endpoint - The API endpoint
122
- * @param requestId - Optional X-Request-ID
123
- * @param headers - Optional response headers
124
- */
125
- constructor(message: string, endpoint: string, requestId?: string, headers?: Headers);
126
- }
127
- /**
128
- * Error thrown for HTTP 404 Not Found responses.
129
- *
130
- * Indicates the requested resource does not exist.
131
- */
132
- export declare class ListmonkNotFoundError extends ListmonkApiError {
133
- readonly name: string;
134
- readonly status: number;
135
- /**
136
- * Creates a new not found error.
137
- *
138
- * @param message - Error message
139
- * @param endpoint - The API endpoint
140
- * @param requestId - Optional X-Request-ID
141
- * @param headers - Optional response headers
142
- */
143
- constructor(message: string, endpoint: string, requestId?: string, headers?: Headers);
144
- }
145
- /**
146
- * Error thrown for HTTP 429 Too Many Requests responses.
147
- *
148
- * Indicates the rate limit has been exceeded. Check the `retryAfter`
149
- * property for the recommended wait time before retrying.
150
- */
151
- export declare class ListmonkRateLimitError extends ListmonkApiError {
152
- readonly name: string;
153
- readonly status: number;
154
- /**
155
- * Seconds to wait before retrying (from Retry-After header).
156
- * Capped at 60 seconds per SDK requirements.
157
- */
158
- readonly retryAfter?: number;
159
- /**
160
- * Creates a new rate limit error.
161
- *
162
- * @param message - Error message
163
- * @param body - Response body
164
- * @param endpoint - The API endpoint
165
- * @param retryAfter - Seconds to wait before retrying (capped at 60)
166
- * @param requestId - Optional X-Request-ID
167
- * @param headers - Optional response headers
168
- */
169
- constructor(message: string, body: unknown, endpoint: string, retryAfter?: number, requestId?: string, headers?: Headers);
170
- }
171
- /**
172
- * Error thrown for HTTP 5xx Server Error responses.
173
- *
174
- * Indicates a server-side error. These errors are typically retryable.
175
- */
176
- export declare class ListmonkInternalServerError extends ListmonkApiError {
177
- readonly name: string;
178
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * Base error class for all listmonk SDK errors.
3
- *
4
- * All SDK-specific errors extend this class, enabling unified error handling
5
- * via `instanceof ListmonkError`.
6
- *
7
- * @example
8
- * ```typescript
9
- * try {
10
- * await client.subscribers.get(123);
11
- * } catch (error) {
12
- * if (error instanceof ListmonkError) {
13
- * console.error('SDK error:', error.message);
14
- * }
15
- * }
16
- * ```
17
- *
18
- * @module errors/base
19
- */
20
- /**
21
- * Abstract base class for all listmonk SDK errors.
22
- *
23
- * Provides proper prototype chain maintenance and stack trace capture
24
- * for all SDK error types.
25
- */
26
- export declare abstract class ListmonkError extends Error {
27
- /**
28
- * The name of the error class.
29
- * Must be overridden by subclasses to provide a unique identifier.
30
- */
31
- abstract readonly name: string;
32
- /**
33
- * The underlying cause of this error, if any.
34
- * Useful for error chaining when wrapping lower-level errors.
35
- */
36
- readonly cause?: unknown;
37
- /**
38
- * Creates a new ListmonkError instance.
39
- *
40
- * @param message - Human-readable error message
41
- * @param options - Optional error options
42
- * @param options.cause - The underlying error that caused this error
43
- */
44
- constructor(message: string, options?: {
45
- cause?: unknown;
46
- });
47
- }
@@ -1,49 +0,0 @@
1
- /**
2
- * Configuration error for invalid SDK options.
3
- *
4
- * Thrown when the SDK is initialized with invalid configuration,
5
- * such as missing credentials or invalid URLs.
6
- *
7
- * @module errors/configuration
8
- */
9
- import { ListmonkError } from "./base";
10
- /**
11
- * Error thrown when SDK configuration is invalid.
12
- *
13
- * Common scenarios:
14
- * - Missing or invalid URL
15
- * - HTTP URL instead of HTTPS
16
- * - Missing authentication credentials
17
- * - Invalid timeout or retry values
18
- *
19
- * @example
20
- * ```typescript
21
- * try {
22
- * const client = new Listmonk({
23
- * url: 'http://example.com', // HTTP not allowed
24
- * auth: { username: 'user', password: 'pass' },
25
- * });
26
- * } catch (error) {
27
- * if (error instanceof ListmonkConfigurationError) {
28
- * console.error(`Config error in ${error.field}:`, error.message);
29
- * }
30
- * }
31
- * ```
32
- */
33
- export declare class ListmonkConfigurationError extends ListmonkError {
34
- readonly name: string;
35
- /**
36
- * The configuration field that caused the error, if identifiable.
37
- */
38
- readonly field?: string;
39
- /**
40
- * Creates a new configuration error.
41
- *
42
- * @param message - Description of the configuration problem
43
- * @param options - Optional additional details
44
- * @param options.field - The specific field that is invalid
45
- */
46
- constructor(message: string, options?: {
47
- field?: string;
48
- });
49
- }
@@ -1,13 +0,0 @@
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";
@@ -1,69 +0,0 @@
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
- }
@@ -1,57 +0,0 @@
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
- }
@@ -1,39 +0,0 @@
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;
@@ -1,149 +0,0 @@
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
- }
@@ -1,90 +0,0 @@
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;