@smoothsend/sdk 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.
@@ -0,0 +1,216 @@
1
+ /**
2
+ * Error handling system for SmoothSend SDK v2
3
+ * Provides typed error classes for different failure scenarios
4
+ *
5
+ * @remarks
6
+ * All SDK errors extend SmoothSendError for consistent error handling
7
+ * Use instanceof checks to handle specific error types
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * try {
12
+ * await sdk.transfer(request, wallet);
13
+ * } catch (error) {
14
+ * if (error instanceof AuthenticationError) {
15
+ * console.error('Invalid API key');
16
+ * } else if (error instanceof RateLimitError) {
17
+ * console.error('Rate limit exceeded');
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ /**
23
+ * Base error class for all SmoothSend SDK errors
24
+ *
25
+ * @remarks
26
+ * All SDK-specific errors extend this class
27
+ * Contains error code, HTTP status code, and additional details
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * throw new SmoothSendError(
32
+ * 'Something went wrong',
33
+ * 'CUSTOM_ERROR',
34
+ * 500,
35
+ * { additionalInfo: 'details' }
36
+ * );
37
+ * ```
38
+ */
39
+ export declare class SmoothSendError extends Error {
40
+ code: string;
41
+ statusCode?: number | undefined;
42
+ details?: any | undefined;
43
+ /**
44
+ * Creates a new SmoothSendError
45
+ *
46
+ * @param message - Human-readable error message
47
+ * @param code - Error code for programmatic handling
48
+ * @param statusCode - HTTP status code (if applicable)
49
+ * @param details - Additional error details
50
+ */
51
+ constructor(message: string, code: string, statusCode?: number | undefined, details?: any | undefined);
52
+ }
53
+ /**
54
+ * Authentication error - thrown when API key is invalid, missing, or expired
55
+ *
56
+ * @remarks
57
+ * HTTP Status Code: 401
58
+ * Indicates authentication failure with the proxy worker
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * try {
63
+ * await sdk.transfer(request, wallet);
64
+ * } catch (error) {
65
+ * if (error instanceof AuthenticationError) {
66
+ * console.error('Invalid API key:', error.message);
67
+ * console.log('Get a new key at:', error.details.suggestion);
68
+ * }
69
+ * }
70
+ * ```
71
+ */
72
+ export declare class AuthenticationError extends SmoothSendError {
73
+ /**
74
+ * Creates a new AuthenticationError
75
+ *
76
+ * @param message - Human-readable error message
77
+ * @param details - Additional error details
78
+ */
79
+ constructor(message: string, details?: any);
80
+ }
81
+ /**
82
+ * Rate limit error - thrown when request rate limit is exceeded
83
+ *
84
+ * @remarks
85
+ * HTTP Status Code: 429
86
+ * Contains rate limit details including reset time
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * try {
91
+ * await sdk.transfer(request, wallet);
92
+ * } catch (error) {
93
+ * if (error instanceof RateLimitError) {
94
+ * console.error('Rate limit exceeded');
95
+ * console.log(`Limit: ${error.limit}`);
96
+ * console.log(`Remaining: ${error.remaining}`);
97
+ * console.log(`Resets at: ${error.resetTime}`);
98
+ * }
99
+ * }
100
+ * ```
101
+ */
102
+ export declare class RateLimitError extends SmoothSendError {
103
+ limit: number;
104
+ remaining: number;
105
+ resetTime: string;
106
+ /**
107
+ * Creates a new RateLimitError
108
+ *
109
+ * @param message - Human-readable error message
110
+ * @param limit - Maximum requests allowed per period
111
+ * @param remaining - Remaining requests in current period
112
+ * @param resetTime - When the rate limit resets (ISO 8601 timestamp)
113
+ */
114
+ constructor(message: string, limit: number, remaining: number, resetTime: string);
115
+ }
116
+ /**
117
+ * Validation error - thrown when request parameters are invalid
118
+ *
119
+ * @remarks
120
+ * HTTP Status Code: 400
121
+ * Contains field name that failed validation
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * try {
126
+ * await sdk.transfer(request, wallet);
127
+ * } catch (error) {
128
+ * if (error instanceof ValidationError) {
129
+ * console.error(`Invalid ${error.field}:`, error.message);
130
+ * }
131
+ * }
132
+ * ```
133
+ */
134
+ export declare class ValidationError extends SmoothSendError {
135
+ field: string;
136
+ /**
137
+ * Creates a new ValidationError
138
+ *
139
+ * @param message - Human-readable error message
140
+ * @param field - Name of the field that failed validation
141
+ * @param details - Additional error details
142
+ */
143
+ constructor(message: string, field: string, details?: any);
144
+ }
145
+ /**
146
+ * Network error - thrown when network connectivity issues occur
147
+ *
148
+ * @remarks
149
+ * HTTP Status Code: 0 (no HTTP response)
150
+ * Indicates network connectivity problems
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * try {
155
+ * await sdk.transfer(request, wallet);
156
+ * } catch (error) {
157
+ * if (error instanceof NetworkError) {
158
+ * console.error('Network error:', error.message);
159
+ * console.log('Original error:', error.originalError);
160
+ * }
161
+ * }
162
+ * ```
163
+ */
164
+ export declare class NetworkError extends SmoothSendError {
165
+ originalError?: Error | undefined;
166
+ /**
167
+ * Creates a new NetworkError
168
+ *
169
+ * @param message - Human-readable error message
170
+ * @param originalError - Original error that caused the network failure
171
+ */
172
+ constructor(message: string, originalError?: Error | undefined);
173
+ }
174
+ /**
175
+ * Helper function to create appropriate error from HTTP response
176
+ *
177
+ * @remarks
178
+ * Parses HTTP error response and creates typed error object
179
+ * Used internally by HTTP client
180
+ *
181
+ * @param statusCode - HTTP status code
182
+ * @param errorData - Error response data from API
183
+ * @param defaultMessage - Default message if none provided in response
184
+ * @returns Typed error object
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const error = createErrorFromResponse(401, {
189
+ * error: 'Invalid API key',
190
+ * details: { field: 'apiKey' }
191
+ * });
192
+ * throw error;
193
+ * ```
194
+ */
195
+ export declare function createErrorFromResponse(statusCode: number, errorData: any, defaultMessage?: string): SmoothSendError;
196
+ /**
197
+ * Helper function to create network error from exception
198
+ *
199
+ * @remarks
200
+ * Wraps generic exceptions in NetworkError for consistent error handling
201
+ * Used internally by HTTP client
202
+ *
203
+ * @param error - Original error or exception
204
+ * @returns NetworkError instance
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * try {
209
+ * await fetch(url);
210
+ * } catch (error) {
211
+ * throw createNetworkError(error);
212
+ * }
213
+ * ```
214
+ */
215
+ export declare function createNetworkError(error: any): NetworkError;
216
+ //# source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