@nehorai/credits 1.0.2 → 1.3.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 (134) hide show
  1. package/dist/adapters/index.cjs +463 -0
  2. package/dist/adapters/index.cjs.map +1 -0
  3. package/dist/adapters/index.d.cts +66 -0
  4. package/dist/adapters/index.d.ts +66 -3
  5. package/dist/adapters/index.js +435 -1
  6. package/dist/adapters/index.js.map +1 -1
  7. package/dist/auth/index.cjs +96 -0
  8. package/dist/auth/index.cjs.map +1 -0
  9. package/dist/auth/{api-key.d.ts → index.d.cts} +9 -6
  10. package/dist/auth/index.d.ts +37 -5
  11. package/dist/auth/index.js +65 -7
  12. package/dist/auth/index.js.map +1 -1
  13. package/dist/core/index.cjs +522 -0
  14. package/dist/core/index.cjs.map +1 -0
  15. package/dist/core/index.d.cts +119 -0
  16. package/dist/core/index.d.ts +115 -25
  17. package/dist/core/index.js +475 -27
  18. package/dist/core/index.js.map +1 -1
  19. package/dist/{core/deferred.d.ts → deferred-C7rrRfkm.d.cts} +7 -6
  20. package/dist/{core/deferred.js → deferred-C7rrRfkm.d.ts} +23 -29
  21. package/dist/index.cjs +2506 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.cts +437 -0
  24. package/dist/index.d.ts +429 -49
  25. package/dist/index.js +2399 -62
  26. package/dist/index.js.map +1 -1
  27. package/dist/repository/index.cjs +816 -0
  28. package/dist/repository/index.cjs.map +1 -0
  29. package/dist/repository/{memory/index.d.ts → index.d.cts} +35 -5
  30. package/dist/repository/index.d.ts +97 -7
  31. package/dist/repository/index.js +783 -10
  32. package/dist/repository/index.js.map +1 -1
  33. package/dist/sdk/index.cjs +608 -0
  34. package/dist/sdk/index.cjs.map +1 -0
  35. package/dist/sdk/index.d.cts +495 -0
  36. package/dist/sdk/index.d.ts +491 -9
  37. package/dist/sdk/index.js +568 -12
  38. package/dist/sdk/index.js.map +1 -1
  39. package/dist/service/index.cjs +670 -0
  40. package/dist/service/index.cjs.map +1 -0
  41. package/dist/service/{credits-service.d.ts → index.d.cts} +9 -7
  42. package/dist/service/index.d.ts +141 -3
  43. package/dist/service/index.js +641 -1
  44. package/dist/service/index.js.map +1 -1
  45. package/dist/{core/types.d.ts → types-BBxIWHK2.d.cts} +25 -35
  46. package/dist/types-BBxIWHK2.d.ts +277 -0
  47. package/dist/types-D1vdeBcA.d.cts +305 -0
  48. package/dist/{auth/types.d.ts → types-OZU3I5OM.d.cts} +5 -4
  49. package/dist/types-OZU3I5OM.d.ts +32 -0
  50. package/dist/{repository/types.d.ts → types-aJsyv8df.d.ts} +35 -13
  51. package/package.json +14 -13
  52. package/dist/adapters/generic.d.ts +0 -18
  53. package/dist/adapters/generic.d.ts.map +0 -1
  54. package/dist/adapters/generic.js +0 -147
  55. package/dist/adapters/generic.js.map +0 -1
  56. package/dist/adapters/index.d.ts.map +0 -1
  57. package/dist/adapters/types.d.ts +0 -45
  58. package/dist/adapters/types.d.ts.map +0 -1
  59. package/dist/adapters/types.js +0 -8
  60. package/dist/adapters/types.js.map +0 -1
  61. package/dist/auth/api-key.d.ts.map +0 -1
  62. package/dist/auth/api-key.js +0 -94
  63. package/dist/auth/api-key.js.map +0 -1
  64. package/dist/auth/index.d.ts.map +0 -1
  65. package/dist/auth/types.d.ts.map +0 -1
  66. package/dist/auth/types.js +0 -2
  67. package/dist/auth/types.js.map +0 -1
  68. package/dist/config/costs.d.ts +0 -61
  69. package/dist/config/costs.d.ts.map +0 -1
  70. package/dist/config/costs.js +0 -86
  71. package/dist/config/costs.js.map +0 -1
  72. package/dist/config/index.d.ts +0 -165
  73. package/dist/config/index.d.ts.map +0 -1
  74. package/dist/config/index.js +0 -286
  75. package/dist/config/index.js.map +0 -1
  76. package/dist/core/deferred.d.ts.map +0 -1
  77. package/dist/core/deferred.js.map +0 -1
  78. package/dist/core/errors.d.ts +0 -78
  79. package/dist/core/errors.d.ts.map +0 -1
  80. package/dist/core/errors.js +0 -110
  81. package/dist/core/errors.js.map +0 -1
  82. package/dist/core/index.d.ts.map +0 -1
  83. package/dist/core/operations.d.ts +0 -36
  84. package/dist/core/operations.d.ts.map +0 -1
  85. package/dist/core/operations.js +0 -87
  86. package/dist/core/operations.js.map +0 -1
  87. package/dist/core/types.d.ts.map +0 -1
  88. package/dist/core/types.js +0 -93
  89. package/dist/core/types.js.map +0 -1
  90. package/dist/index.d.ts.map +0 -1
  91. package/dist/notifications/index.d.ts +0 -76
  92. package/dist/notifications/index.d.ts.map +0 -1
  93. package/dist/notifications/index.js +0 -182
  94. package/dist/notifications/index.js.map +0 -1
  95. package/dist/repository/index.d.ts.map +0 -1
  96. package/dist/repository/memory/index.d.ts.map +0 -1
  97. package/dist/repository/memory/index.js +0 -518
  98. package/dist/repository/memory/index.js.map +0 -1
  99. package/dist/repository/types.d.ts.map +0 -1
  100. package/dist/repository/types.js +0 -39
  101. package/dist/repository/types.js.map +0 -1
  102. package/dist/repository/utils.d.ts +0 -22
  103. package/dist/repository/utils.d.ts.map +0 -1
  104. package/dist/repository/utils.js +0 -40
  105. package/dist/repository/utils.js.map +0 -1
  106. package/dist/sdk/admin-client.d.ts +0 -146
  107. package/dist/sdk/admin-client.d.ts.map +0 -1
  108. package/dist/sdk/admin-client.js +0 -196
  109. package/dist/sdk/admin-client.js.map +0 -1
  110. package/dist/sdk/client.d.ts +0 -144
  111. package/dist/sdk/client.d.ts.map +0 -1
  112. package/dist/sdk/client.js +0 -247
  113. package/dist/sdk/client.js.map +0 -1
  114. package/dist/sdk/errors.d.ts +0 -91
  115. package/dist/sdk/errors.d.ts.map +0 -1
  116. package/dist/sdk/errors.js +0 -185
  117. package/dist/sdk/errors.js.map +0 -1
  118. package/dist/sdk/index.d.ts.map +0 -1
  119. package/dist/sdk/types.d.ts +0 -110
  120. package/dist/sdk/types.d.ts.map +0 -1
  121. package/dist/sdk/types.js +0 -20
  122. package/dist/sdk/types.js.map +0 -1
  123. package/dist/service/credits-service.d.ts.map +0 -1
  124. package/dist/service/credits-service.js +0 -372
  125. package/dist/service/credits-service.js.map +0 -1
  126. package/dist/service/index.d.ts.map +0 -1
  127. package/dist/utils/error-utils.d.ts +0 -48
  128. package/dist/utils/error-utils.d.ts.map +0 -1
  129. package/dist/utils/error-utils.js +0 -57
  130. package/dist/utils/error-utils.js.map +0 -1
  131. package/dist/utils/index.d.ts +0 -54
  132. package/dist/utils/index.d.ts.map +0 -1
  133. package/dist/utils/index.js +0 -72
  134. package/dist/utils/index.js.map +0 -1
@@ -0,0 +1,495 @@
1
+ import { b as PortableUserCredits, g as CreditCheckResult } from '../types-BBxIWHK2.cjs';
2
+ export { c as CreditReservation, S as SubscriptionTier } from '../types-BBxIWHK2.cjs';
3
+
4
+ /**
5
+ * SDK types for the credits system
6
+ *
7
+ * These types are used by the client SDKs for REST API consumption.
8
+ */
9
+
10
+ /**
11
+ * Configuration for CreditsClient
12
+ */
13
+ interface CreditsClientConfig {
14
+ /** Base URL of the credits API (e.g., "https://api.example.com") */
15
+ baseUrl: string;
16
+ /** Function to get the auth token for session-based auth */
17
+ getAuthToken?: () => Promise<string>;
18
+ /** Optional custom fetch function for testing */
19
+ fetch?: typeof fetch;
20
+ }
21
+ /**
22
+ * Configuration for AdminCreditsClient
23
+ */
24
+ interface AdminCreditsClientConfig {
25
+ /** Base URL of the credits API */
26
+ baseUrl: string;
27
+ /** Admin API key */
28
+ apiKey: string;
29
+ /** Optional custom fetch function for testing */
30
+ fetch?: typeof fetch;
31
+ }
32
+ /**
33
+ * Result of a credit reservation
34
+ */
35
+ interface ReservationResult {
36
+ /** The reservation ID */
37
+ reservationId: string;
38
+ /** Amount of credits reserved */
39
+ amount: number;
40
+ /** When the reservation expires (ISO 8601) */
41
+ expiresAt: string;
42
+ }
43
+ /**
44
+ * Pagination options for API requests
45
+ */
46
+ interface PaginationOptions {
47
+ /** Page number (1-indexed) */
48
+ page?: number;
49
+ /** Number of items per page */
50
+ limit?: number;
51
+ }
52
+ /**
53
+ * Usage history entry
54
+ */
55
+ interface UsageHistoryEntry {
56
+ /** Unique ID of the usage log */
57
+ id: string;
58
+ /** Type of operation */
59
+ operationType: string;
60
+ /** AI provider used */
61
+ provider: string;
62
+ /** Credits consumed */
63
+ creditsUsed: number;
64
+ /** Whether the operation was successful */
65
+ success: boolean;
66
+ /** Error message if unsuccessful */
67
+ errorMessage?: string;
68
+ /** ID of the related resource */
69
+ resourceId?: string;
70
+ /** Type of the related resource */
71
+ resourceType?: string;
72
+ /** When the operation occurred (ISO 8601) */
73
+ createdAt: string;
74
+ }
75
+ /**
76
+ * Response from usage history endpoint
77
+ */
78
+ interface UsageHistoryResponse {
79
+ /** List of usage entries */
80
+ entries: UsageHistoryEntry[];
81
+ /** Whether there are more results */
82
+ hasMore: boolean;
83
+ /** Total count (if available) */
84
+ total?: number;
85
+ }
86
+ /**
87
+ * Generic API response wrapper
88
+ */
89
+ interface ApiResponse<T> {
90
+ success: boolean;
91
+ data?: T;
92
+ error?: {
93
+ code: string;
94
+ message: string;
95
+ details?: unknown;
96
+ };
97
+ }
98
+ /**
99
+ * SDK error codes
100
+ */
101
+ declare const SDKErrorCode: {
102
+ readonly NETWORK_ERROR: "NETWORK_ERROR";
103
+ readonly AUTHENTICATION_ERROR: "AUTHENTICATION_ERROR";
104
+ readonly AUTHORIZATION_ERROR: "AUTHORIZATION_ERROR";
105
+ readonly INSUFFICIENT_CREDITS: "INSUFFICIENT_CREDITS";
106
+ readonly RESERVATION_NOT_FOUND: "RESERVATION_NOT_FOUND";
107
+ readonly RESERVATION_EXPIRED: "RESERVATION_EXPIRED";
108
+ readonly VALIDATION_ERROR: "VALIDATION_ERROR";
109
+ readonly SERVER_ERROR: "SERVER_ERROR";
110
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
111
+ };
112
+ type SDKErrorCodeType = (typeof SDKErrorCode)[keyof typeof SDKErrorCode];
113
+
114
+ /**
115
+ * CreditsClient - REST API client for the credits system
116
+ *
117
+ * Provides a type-safe interface for consuming credits API endpoints
118
+ * from external services or other applications.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const client = new CreditsClient({
123
+ * baseUrl: process.env.CREDITS_API_URL,
124
+ * getAuthToken: async () => session.accessToken,
125
+ * });
126
+ *
127
+ * // Check if user has sufficient credits
128
+ * const check = await client.checkAvailability("story_generation");
129
+ * if (!check.hasCredits) {
130
+ * console.log("Insufficient credits");
131
+ * return;
132
+ * }
133
+ *
134
+ * // Two-phase commit pattern
135
+ * const reservation = await client.reserve("story_generation");
136
+ * try {
137
+ * const result = await doExpensiveWork();
138
+ * await client.commit(reservation.reservationId);
139
+ * return result;
140
+ * } catch (error) {
141
+ * await client.release(reservation.reservationId);
142
+ * throw error;
143
+ * }
144
+ * ```
145
+ */
146
+
147
+ declare class CreditsClient {
148
+ private readonly baseUrl;
149
+ private readonly getAuthToken?;
150
+ private readonly fetchFn;
151
+ constructor(config: CreditsClientConfig);
152
+ /**
153
+ * Make an authenticated request to the API
154
+ */
155
+ private request;
156
+ /**
157
+ * Get the current user's credit balance
158
+ *
159
+ * @returns User's credit information
160
+ * @throws AuthenticationError if not authenticated
161
+ */
162
+ getBalance(): Promise<PortableUserCredits>;
163
+ /**
164
+ * Check if the user has sufficient credits for an operation
165
+ *
166
+ * @param operationType - Type of operation to check
167
+ * @param customCost - Optional custom cost to check against
168
+ * @returns Credit availability status
169
+ * @throws AuthenticationError if not authenticated
170
+ */
171
+ checkAvailability(operationType: string, customCost?: number): Promise<CreditCheckResult>;
172
+ /**
173
+ * Reserve credits for an operation
174
+ *
175
+ * This is the first step in the two-phase commit pattern.
176
+ * Reserved credits are held for 5 minutes before expiring.
177
+ *
178
+ * @param operationType - Type of operation
179
+ * @param options - Optional reservation options
180
+ * @returns Reservation details including ID and expiry
181
+ * @throws InsufficientCreditsError if not enough credits
182
+ * @throws AuthenticationError if not authenticated
183
+ */
184
+ reserve(operationType: string, options?: {
185
+ customCost?: number;
186
+ resourceId?: string;
187
+ resourceType?: string;
188
+ }): Promise<ReservationResult>;
189
+ /**
190
+ * Commit a reservation (deduct credits)
191
+ *
192
+ * This is the second step in the two-phase commit pattern.
193
+ * Call this after your operation succeeds.
194
+ *
195
+ * @param reservationId - ID of the reservation to commit
196
+ * @throws ReservationNotFoundError if reservation doesn't exist
197
+ * @throws ReservationExpiredError if reservation has expired
198
+ * @throws AuthenticationError if not authenticated
199
+ */
200
+ commit(reservationId: string): Promise<void>;
201
+ /**
202
+ * Release a reservation (refund credits)
203
+ *
204
+ * Call this if your operation fails after reserving credits.
205
+ *
206
+ * @param reservationId - ID of the reservation to release
207
+ * @throws ReservationNotFoundError if reservation doesn't exist
208
+ * @throws AuthenticationError if not authenticated
209
+ */
210
+ release(reservationId: string): Promise<void>;
211
+ /**
212
+ * Get usage history for the current user
213
+ *
214
+ * @param options - Optional pagination options
215
+ * @returns Paginated list of usage entries
216
+ * @throws AuthenticationError if not authenticated
217
+ */
218
+ getHistory(options?: PaginationOptions): Promise<UsageHistoryResponse>;
219
+ /**
220
+ * Get the available credits (balance + bonus - reserved)
221
+ *
222
+ * Convenience method that calculates available credits from balance.
223
+ *
224
+ * @returns Number of available credits
225
+ * @throws AuthenticationError if not authenticated
226
+ */
227
+ getAvailableCredits(): Promise<number>;
228
+ /**
229
+ * Execute an operation with automatic credit handling
230
+ *
231
+ * This is a convenience method that handles the full two-phase commit
232
+ * pattern automatically.
233
+ *
234
+ * @param operationType - Type of operation
235
+ * @param operation - The operation to execute
236
+ * @param options - Optional reservation options
237
+ * @returns Result of the operation
238
+ * @throws InsufficientCreditsError if not enough credits
239
+ * @throws AuthenticationError if not authenticated
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const result = await client.withCredits(
244
+ * "story_generation",
245
+ * async () => {
246
+ * return generateStory(data);
247
+ * }
248
+ * );
249
+ * ```
250
+ */
251
+ withCredits<T>(operationType: string, operation: () => Promise<T>, options?: {
252
+ customCost?: number;
253
+ resourceId?: string;
254
+ resourceType?: string;
255
+ }): Promise<T>;
256
+ }
257
+
258
+ /**
259
+ * AdminCreditsClient - Admin REST API client for the credits system
260
+ *
261
+ * Provides administrative access to the credits system for managing
262
+ * user credits, configurations, and subscriptions.
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * const adminClient = new AdminCreditsClient({
267
+ * baseUrl: process.env.CREDITS_API_URL,
268
+ * apiKey: process.env.CREDITS_ADMIN_API_KEY,
269
+ * });
270
+ *
271
+ * // Add credits to a user
272
+ * await adminClient.addCredits("user-123", 100, "Support credit grant");
273
+ *
274
+ * // Update subscription tier
275
+ * await adminClient.updateSubscription("user-123", "premium", "2027-01-01T00:00:00Z");
276
+ *
277
+ * // Update operation costs
278
+ * await adminClient.updateCosts({
279
+ * story_generation: 8,
280
+ * image_generation: 12,
281
+ * });
282
+ * ```
283
+ */
284
+
285
+ /**
286
+ * Credits configuration returned by the API
287
+ */
288
+ interface CreditsConfig {
289
+ operationCosts: Record<string, number>;
290
+ tierConfigs: Record<string, {
291
+ monthlyLimit: number;
292
+ features: string[];
293
+ }>;
294
+ }
295
+ /**
296
+ * Response from listing users
297
+ */
298
+ interface ListUsersResponse {
299
+ users: Array<{
300
+ userId: string;
301
+ balance: number;
302
+ bonusCredits?: number;
303
+ tier: string;
304
+ monthlyUsed?: number;
305
+ }>;
306
+ hasMore: boolean;
307
+ total?: number;
308
+ }
309
+ /**
310
+ * Options for listing users
311
+ */
312
+ interface ListUsersOptions {
313
+ page?: number;
314
+ limit?: number;
315
+ tier?: string;
316
+ search?: string;
317
+ }
318
+ declare class AdminCreditsClient {
319
+ private readonly baseUrl;
320
+ private readonly apiKey;
321
+ private readonly fetchFn;
322
+ constructor(config: AdminCreditsClientConfig);
323
+ /**
324
+ * Make an authenticated admin request to the API
325
+ */
326
+ private request;
327
+ /**
328
+ * Get a specific user's credits
329
+ *
330
+ * @param userId - ID of the user
331
+ * @returns User's credit information
332
+ * @throws AuthorizationError if API key is invalid
333
+ */
334
+ getUserCredits(userId: string): Promise<PortableUserCredits>;
335
+ /**
336
+ * Add credits to a user's account
337
+ *
338
+ * Credits are added to bonusCredits, which don't expire on monthly reset.
339
+ *
340
+ * @param userId - ID of the user
341
+ * @param amount - Amount of credits to add
342
+ * @param description - Reason for adding credits
343
+ * @throws AuthorizationError if API key is invalid
344
+ */
345
+ addCredits(userId: string, amount: number, description: string): Promise<void>;
346
+ /**
347
+ * Update a user's subscription tier
348
+ *
349
+ * @param userId - ID of the user
350
+ * @param tier - New subscription tier
351
+ * @param expiresAt - Optional expiration date (ISO 8601)
352
+ * @throws AuthorizationError if API key is invalid
353
+ */
354
+ updateSubscription(userId: string, tier: string, expiresAt?: string): Promise<void>;
355
+ /**
356
+ * Get the current credits configuration
357
+ *
358
+ * @returns Credits system configuration
359
+ * @throws AuthorizationError if API key is invalid
360
+ */
361
+ getConfig(): Promise<CreditsConfig>;
362
+ /**
363
+ * Update operation costs
364
+ *
365
+ * @param costs - New operation costs (operation type -> cost)
366
+ * @throws AuthorizationError if API key is invalid
367
+ */
368
+ updateCosts(costs: Record<string, number>): Promise<void>;
369
+ /**
370
+ * List all users with their credits
371
+ *
372
+ * @param options - Pagination and filtering options
373
+ * @returns Paginated list of users
374
+ * @throws AuthorizationError if API key is invalid
375
+ */
376
+ listUsers(options?: ListUsersOptions): Promise<ListUsersResponse>;
377
+ /**
378
+ * Deduct credits from a user's account
379
+ *
380
+ * @param userId - ID of the user
381
+ * @param amount - Amount of credits to deduct
382
+ * @param description - Reason for deducting credits
383
+ * @throws AuthorizationError if API key is invalid
384
+ */
385
+ deductCredits(userId: string, amount: number, description: string): Promise<void>;
386
+ /**
387
+ * Get usage statistics for a user
388
+ *
389
+ * @param userId - ID of the user
390
+ * @param options - Optional date range
391
+ * @returns Usage statistics
392
+ * @throws AuthorizationError if API key is invalid
393
+ */
394
+ getUserStats(userId: string, options?: {
395
+ startDate?: string;
396
+ endDate?: string;
397
+ }): Promise<{
398
+ totalCreditsUsed: number;
399
+ operationBreakdown: Record<string, number>;
400
+ successRate: number;
401
+ }>;
402
+ }
403
+
404
+ /**
405
+ * SDK error classes
406
+ *
407
+ * Provides typed error handling for SDK operations.
408
+ */
409
+
410
+ /**
411
+ * Base error class for SDK errors
412
+ */
413
+ declare class CreditsSDKError extends Error {
414
+ readonly code: SDKErrorCodeType;
415
+ readonly details?: Record<string, unknown>;
416
+ readonly statusCode?: number;
417
+ constructor(message: string, code: SDKErrorCodeType, options?: {
418
+ details?: Record<string, unknown>;
419
+ statusCode?: number;
420
+ cause?: Error;
421
+ });
422
+ /**
423
+ * Check if this is a specific error type
424
+ */
425
+ is(code: SDKErrorCodeType): boolean;
426
+ /**
427
+ * Create a JSON representation for logging
428
+ */
429
+ toJSON(): Record<string, unknown>;
430
+ }
431
+ /**
432
+ * Error thrown when a network request fails
433
+ */
434
+ declare class NetworkError extends CreditsSDKError {
435
+ constructor(message: string, cause?: Error);
436
+ }
437
+ /**
438
+ * Error thrown when authentication fails
439
+ */
440
+ declare class AuthenticationError extends CreditsSDKError {
441
+ constructor(message?: string);
442
+ }
443
+ /**
444
+ * Error thrown when authorization fails
445
+ */
446
+ declare class AuthorizationError extends CreditsSDKError {
447
+ constructor(message?: string);
448
+ }
449
+ /**
450
+ * Error thrown when credits are insufficient
451
+ */
452
+ declare class InsufficientCreditsError extends CreditsSDKError {
453
+ readonly available: number;
454
+ readonly required: number;
455
+ constructor(available: number, required: number);
456
+ }
457
+ /**
458
+ * Error thrown when a reservation is not found
459
+ */
460
+ declare class ReservationNotFoundError extends CreditsSDKError {
461
+ readonly reservationId: string;
462
+ constructor(reservationId: string);
463
+ }
464
+ /**
465
+ * Error thrown when a reservation has expired
466
+ */
467
+ declare class ReservationExpiredError extends CreditsSDKError {
468
+ readonly reservationId: string;
469
+ constructor(reservationId: string);
470
+ }
471
+ /**
472
+ * Error thrown for validation failures
473
+ */
474
+ declare class ValidationError extends CreditsSDKError {
475
+ readonly field?: string;
476
+ constructor(message: string, field?: string);
477
+ }
478
+ /**
479
+ * Error thrown for server errors
480
+ */
481
+ declare class ServerError extends CreditsSDKError {
482
+ constructor(message?: string);
483
+ }
484
+ /**
485
+ * Parse an API error response into the appropriate SDK error
486
+ */
487
+ declare function parseApiError(statusCode: number, body: {
488
+ error?: {
489
+ code?: string;
490
+ message?: string;
491
+ details?: unknown;
492
+ };
493
+ }): CreditsSDKError;
494
+
495
+ export { AdminCreditsClient, type AdminCreditsClientConfig, type ApiResponse, AuthenticationError, AuthorizationError, CreditCheckResult, CreditsClient, type CreditsClientConfig, type CreditsConfig, CreditsSDKError, InsufficientCreditsError, type ListUsersOptions, type ListUsersResponse, NetworkError, type PaginationOptions, ReservationExpiredError, ReservationNotFoundError, type ReservationResult, SDKErrorCode, type SDKErrorCodeType, ServerError, type UsageHistoryEntry, type UsageHistoryResponse, PortableUserCredits as UserCredits, ValidationError, parseApiError };