@djangocfg/ext-payments 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/README.md +206 -0
- package/dist/chunk-5KY6HVXF.js +2593 -0
- package/dist/hooks.cjs +2666 -0
- package/dist/hooks.d.cts +186 -0
- package/dist/hooks.d.ts +186 -0
- package/dist/hooks.js +1 -0
- package/dist/index.cjs +2590 -0
- package/dist/index.d.cts +1287 -0
- package/dist/index.d.ts +1287 -0
- package/dist/index.js +1 -0
- package/package.json +79 -0
- package/src/api/generated/ext_payments/_utils/fetchers/ext_payments__payments.ts +408 -0
- package/src/api/generated/ext_payments/_utils/fetchers/index.ts +28 -0
- package/src/api/generated/ext_payments/_utils/hooks/ext_payments__payments.ts +147 -0
- package/src/api/generated/ext_payments/_utils/hooks/index.ts +28 -0
- package/src/api/generated/ext_payments/_utils/schemas/Balance.schema.ts +23 -0
- package/src/api/generated/ext_payments/_utils/schemas/Currency.schema.ts +28 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaginatedPaymentListList.schema.ts +24 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaymentDetail.schema.ts +44 -0
- package/src/api/generated/ext_payments/_utils/schemas/PaymentList.schema.ts +28 -0
- package/src/api/generated/ext_payments/_utils/schemas/Transaction.schema.ts +28 -0
- package/src/api/generated/ext_payments/_utils/schemas/index.ts +24 -0
- package/src/api/generated/ext_payments/api-instance.ts +131 -0
- package/src/api/generated/ext_payments/client.ts +301 -0
- package/src/api/generated/ext_payments/enums.ts +64 -0
- package/src/api/generated/ext_payments/errors.ts +116 -0
- package/src/api/generated/ext_payments/ext_payments__payments/client.ts +118 -0
- package/src/api/generated/ext_payments/ext_payments__payments/index.ts +2 -0
- package/src/api/generated/ext_payments/ext_payments__payments/models.ts +135 -0
- package/src/api/generated/ext_payments/http.ts +103 -0
- package/src/api/generated/ext_payments/index.ts +273 -0
- package/src/api/generated/ext_payments/logger.ts +259 -0
- package/src/api/generated/ext_payments/retry.ts +175 -0
- package/src/api/generated/ext_payments/schema.json +850 -0
- package/src/api/generated/ext_payments/storage.ts +161 -0
- package/src/api/generated/ext_payments/validation-events.ts +133 -0
- package/src/api/index.ts +9 -0
- package/src/config.ts +20 -0
- package/src/contexts/BalancesContext.tsx +62 -0
- package/src/contexts/CurrenciesContext.tsx +63 -0
- package/src/contexts/OverviewContext.tsx +173 -0
- package/src/contexts/PaymentsContext.tsx +121 -0
- package/src/contexts/PaymentsExtensionProvider.tsx +55 -0
- package/src/contexts/README.md +201 -0
- package/src/contexts/RootPaymentsContext.tsx +65 -0
- package/src/contexts/index.ts +45 -0
- package/src/contexts/types.ts +40 -0
- package/src/hooks/index.ts +20 -0
- package/src/index.ts +36 -0
- package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +92 -0
- package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +291 -0
- package/src/layouts/PaymentsLayout/components/PaymentDetailsDialog.tsx +290 -0
- package/src/layouts/PaymentsLayout/components/index.ts +2 -0
- package/src/layouts/PaymentsLayout/events.ts +47 -0
- package/src/layouts/PaymentsLayout/index.ts +16 -0
- package/src/layouts/PaymentsLayout/types.ts +6 -0
- package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +128 -0
- package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +142 -0
- package/src/layouts/PaymentsLayout/views/overview/components/index.ts +2 -0
- package/src/layouts/PaymentsLayout/views/overview/index.tsx +20 -0
- package/src/layouts/PaymentsLayout/views/payments/components/PaymentsList.tsx +277 -0
- package/src/layouts/PaymentsLayout/views/payments/components/index.ts +1 -0
- package/src/layouts/PaymentsLayout/views/payments/index.tsx +17 -0
- package/src/layouts/PaymentsLayout/views/transactions/components/TransactionsList.tsx +273 -0
- package/src/layouts/PaymentsLayout/views/transactions/components/index.ts +1 -0
- package/src/layouts/PaymentsLayout/views/transactions/index.tsx +17 -0
- package/src/utils/logger.ts +9 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1287 @@
|
|
|
1
|
+
import { ConsolaInstance } from 'consola';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { z, ZodError } from 'zod';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Current payment status
|
|
7
|
+
* * `pending` - Pending
|
|
8
|
+
* * `confirming` - Confirming
|
|
9
|
+
* * `confirmed` - Confirmed
|
|
10
|
+
* * `completed` - Completed
|
|
11
|
+
* * `partially_paid` - Partially Paid
|
|
12
|
+
* * `failed` - Failed
|
|
13
|
+
* * `expired` - Expired
|
|
14
|
+
* * `cancelled` - Cancelled
|
|
15
|
+
*/
|
|
16
|
+
declare enum PaymentDetailStatus {
|
|
17
|
+
PENDING = "pending",
|
|
18
|
+
CONFIRMING = "confirming",
|
|
19
|
+
CONFIRMED = "confirmed",
|
|
20
|
+
COMPLETED = "completed",
|
|
21
|
+
PARTIALLY_PAID = "partially_paid",
|
|
22
|
+
FAILED = "failed",
|
|
23
|
+
EXPIRED = "expired",
|
|
24
|
+
CANCELLED = "cancelled"
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Current payment status
|
|
28
|
+
* * `pending` - Pending
|
|
29
|
+
* * `confirming` - Confirming
|
|
30
|
+
* * `confirmed` - Confirmed
|
|
31
|
+
* * `completed` - Completed
|
|
32
|
+
* * `partially_paid` - Partially Paid
|
|
33
|
+
* * `failed` - Failed
|
|
34
|
+
* * `expired` - Expired
|
|
35
|
+
* * `cancelled` - Cancelled
|
|
36
|
+
*/
|
|
37
|
+
declare enum PaymentListStatus {
|
|
38
|
+
PENDING = "pending",
|
|
39
|
+
CONFIRMING = "confirming",
|
|
40
|
+
CONFIRMED = "confirmed",
|
|
41
|
+
COMPLETED = "completed",
|
|
42
|
+
PARTIALLY_PAID = "partially_paid",
|
|
43
|
+
FAILED = "failed",
|
|
44
|
+
EXPIRED = "expired",
|
|
45
|
+
CANCELLED = "cancelled"
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Type of transaction
|
|
49
|
+
* * `deposit` - Deposit
|
|
50
|
+
* * `withdrawal` - Withdrawal
|
|
51
|
+
* * `payment` - Payment
|
|
52
|
+
* * `refund` - Refund
|
|
53
|
+
* * `fee` - Fee
|
|
54
|
+
* * `bonus` - Bonus
|
|
55
|
+
* * `adjustment` - Adjustment
|
|
56
|
+
*/
|
|
57
|
+
declare enum TransactionTransactionType {
|
|
58
|
+
DEPOSIT = "deposit",
|
|
59
|
+
WITHDRAWAL = "withdrawal",
|
|
60
|
+
PAYMENT = "payment",
|
|
61
|
+
REFUND = "refund",
|
|
62
|
+
FEE = "fee",
|
|
63
|
+
BONUS = "bonus",
|
|
64
|
+
ADJUSTMENT = "adjustment"
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
type enums_PaymentDetailStatus = PaymentDetailStatus;
|
|
68
|
+
declare const enums_PaymentDetailStatus: typeof PaymentDetailStatus;
|
|
69
|
+
type enums_PaymentListStatus = PaymentListStatus;
|
|
70
|
+
declare const enums_PaymentListStatus: typeof PaymentListStatus;
|
|
71
|
+
type enums_TransactionTransactionType = TransactionTransactionType;
|
|
72
|
+
declare const enums_TransactionTransactionType: typeof TransactionTransactionType;
|
|
73
|
+
declare namespace enums {
|
|
74
|
+
export { enums_PaymentDetailStatus as PaymentDetailStatus, enums_PaymentListStatus as PaymentListStatus, enums_TransactionTransactionType as TransactionTransactionType };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* User balance serializer.
|
|
79
|
+
*
|
|
80
|
+
* Response model (includes read-only fields).
|
|
81
|
+
*/
|
|
82
|
+
interface Balance$1 {
|
|
83
|
+
/** Current balance in USD */
|
|
84
|
+
balance_usd: string;
|
|
85
|
+
balance_display: string;
|
|
86
|
+
/** Total amount deposited (lifetime) */
|
|
87
|
+
total_deposited: string;
|
|
88
|
+
/** Total amount withdrawn (lifetime) */
|
|
89
|
+
total_withdrawn: string;
|
|
90
|
+
/** When the last transaction occurred */
|
|
91
|
+
last_transaction_at?: string | null;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* Response model (includes read-only fields).
|
|
96
|
+
*/
|
|
97
|
+
interface PaginatedPaymentListList$1 {
|
|
98
|
+
/** Total number of items across all pages */
|
|
99
|
+
count: number;
|
|
100
|
+
/** Current page number (1-based) */
|
|
101
|
+
page: number;
|
|
102
|
+
/** Total number of pages */
|
|
103
|
+
pages: number;
|
|
104
|
+
/** Number of items per page */
|
|
105
|
+
page_size: number;
|
|
106
|
+
/** Whether there is a next page */
|
|
107
|
+
has_next: boolean;
|
|
108
|
+
/** Whether there is a previous page */
|
|
109
|
+
has_previous: boolean;
|
|
110
|
+
/** Next page number (null if no next page) */
|
|
111
|
+
next_page?: number | null;
|
|
112
|
+
/** Previous page number (null if no previous page) */
|
|
113
|
+
previous_page?: number | null;
|
|
114
|
+
/** Array of items for current page */
|
|
115
|
+
results: Array<PaymentList$1>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Detailed payment information.
|
|
119
|
+
*
|
|
120
|
+
* Response model (includes read-only fields).
|
|
121
|
+
*/
|
|
122
|
+
interface PaymentDetail$1 {
|
|
123
|
+
/** Unique identifier for this record */
|
|
124
|
+
id: string;
|
|
125
|
+
/** Internal payment identifier (PAY_YYYYMMDDHHMMSS_UUID) */
|
|
126
|
+
internal_payment_id: string;
|
|
127
|
+
/** Payment amount in USD */
|
|
128
|
+
amount_usd: string;
|
|
129
|
+
currency_code: string;
|
|
130
|
+
currency_name: string;
|
|
131
|
+
currency_token: string;
|
|
132
|
+
currency_network: string;
|
|
133
|
+
/** Amount to pay in cryptocurrency */
|
|
134
|
+
pay_amount?: string | null;
|
|
135
|
+
/** Actual amount received in cryptocurrency */
|
|
136
|
+
actual_amount?: string | null;
|
|
137
|
+
/** Actual amount received in USD */
|
|
138
|
+
actual_amount_usd?: string | null;
|
|
139
|
+
/** Current payment status
|
|
140
|
+
|
|
141
|
+
* `pending` - Pending
|
|
142
|
+
* `confirming` - Confirming
|
|
143
|
+
* `confirmed` - Confirmed
|
|
144
|
+
* `completed` - Completed
|
|
145
|
+
* `partially_paid` - Partially Paid
|
|
146
|
+
* `failed` - Failed
|
|
147
|
+
* `expired` - Expired
|
|
148
|
+
* `cancelled` - Cancelled */
|
|
149
|
+
status: PaymentDetailStatus;
|
|
150
|
+
status_display: string;
|
|
151
|
+
/** Cryptocurrency payment address */
|
|
152
|
+
pay_address?: string | null;
|
|
153
|
+
/** Get QR code URL. */
|
|
154
|
+
qr_code_url?: string | null;
|
|
155
|
+
/** Payment page URL (if provided by provider) */
|
|
156
|
+
payment_url?: string | null;
|
|
157
|
+
/** Blockchain transaction hash */
|
|
158
|
+
transaction_hash?: string | null;
|
|
159
|
+
/** Get blockchain explorer link. */
|
|
160
|
+
explorer_link?: string | null;
|
|
161
|
+
/** Number of blockchain confirmations */
|
|
162
|
+
confirmations_count: number;
|
|
163
|
+
/** When this payment expires (typically 30 minutes) */
|
|
164
|
+
expires_at?: string | null;
|
|
165
|
+
/** When this payment was completed */
|
|
166
|
+
completed_at?: string | null;
|
|
167
|
+
/** When this record was created */
|
|
168
|
+
created_at: string;
|
|
169
|
+
is_completed: boolean;
|
|
170
|
+
is_failed: boolean;
|
|
171
|
+
is_expired: boolean;
|
|
172
|
+
/** Payment description */
|
|
173
|
+
description: string;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Payment list item (lighter than detail).
|
|
177
|
+
*
|
|
178
|
+
* Response model (includes read-only fields).
|
|
179
|
+
*/
|
|
180
|
+
interface PaymentList$1 {
|
|
181
|
+
/** Unique identifier for this record */
|
|
182
|
+
id: string;
|
|
183
|
+
/** Internal payment identifier (PAY_YYYYMMDDHHMMSS_UUID) */
|
|
184
|
+
internal_payment_id: string;
|
|
185
|
+
/** Payment amount in USD */
|
|
186
|
+
amount_usd: string;
|
|
187
|
+
currency_code: string;
|
|
188
|
+
currency_token: string;
|
|
189
|
+
/** Current payment status
|
|
190
|
+
|
|
191
|
+
* `pending` - Pending
|
|
192
|
+
* `confirming` - Confirming
|
|
193
|
+
* `confirmed` - Confirmed
|
|
194
|
+
* `completed` - Completed
|
|
195
|
+
* `partially_paid` - Partially Paid
|
|
196
|
+
* `failed` - Failed
|
|
197
|
+
* `expired` - Expired
|
|
198
|
+
* `cancelled` - Cancelled */
|
|
199
|
+
status: PaymentListStatus;
|
|
200
|
+
status_display: string;
|
|
201
|
+
/** When this record was created */
|
|
202
|
+
created_at: string;
|
|
203
|
+
/** When this payment was completed */
|
|
204
|
+
completed_at?: string | null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
declare namespace models {
|
|
208
|
+
export type { Balance$1 as Balance, PaginatedPaymentListList$1 as PaginatedPaymentListList, PaymentDetail$1 as PaymentDetail, PaymentList$1 as PaymentList };
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* API endpoints for Payments.
|
|
213
|
+
*/
|
|
214
|
+
declare class ExtPaymentsPayments {
|
|
215
|
+
private client;
|
|
216
|
+
constructor(client: any);
|
|
217
|
+
/**
|
|
218
|
+
* Get user balance
|
|
219
|
+
*
|
|
220
|
+
* Get current user balance and transaction statistics
|
|
221
|
+
*/
|
|
222
|
+
balanceRetrieve(): Promise<Balance$1>;
|
|
223
|
+
/**
|
|
224
|
+
* Get available currencies
|
|
225
|
+
*
|
|
226
|
+
* Returns list of available currencies with token+network info
|
|
227
|
+
*/
|
|
228
|
+
currenciesList(): Promise<any>;
|
|
229
|
+
paymentsList(page?: number, page_size?: number): Promise<PaginatedPaymentListList$1>;
|
|
230
|
+
paymentsList(params?: {
|
|
231
|
+
page?: number;
|
|
232
|
+
page_size?: number;
|
|
233
|
+
}): Promise<PaginatedPaymentListList$1>;
|
|
234
|
+
/**
|
|
235
|
+
* ViewSet for payment operations. Endpoints: - GET /payments/ - List
|
|
236
|
+
* user's payments - GET /payments/{id}/ - Get payment details - POST
|
|
237
|
+
* /payments/create/ - Create new payment - GET /payments/{id}/status/ -
|
|
238
|
+
* Check payment status - POST /payments/{id}/confirm/ - Confirm payment
|
|
239
|
+
*/
|
|
240
|
+
paymentsRetrieve(id: string): Promise<PaymentDetail$1>;
|
|
241
|
+
/**
|
|
242
|
+
* POST /api/v1/payments/{id}/confirm/ Confirm payment (user clicked "I
|
|
243
|
+
* have paid"). Checks status with provider and creates transaction if
|
|
244
|
+
* completed.
|
|
245
|
+
*/
|
|
246
|
+
paymentsConfirmCreate(id: string): Promise<PaymentList$1>;
|
|
247
|
+
/**
|
|
248
|
+
* GET /api/v1/payments/{id}/status/?refresh=true Check payment status
|
|
249
|
+
* (with optional refresh from provider). Query params: - refresh: boolean
|
|
250
|
+
* (default: false) - Force refresh from provider
|
|
251
|
+
*/
|
|
252
|
+
paymentsStatusRetrieve(id: string): Promise<PaymentList$1[]>;
|
|
253
|
+
/**
|
|
254
|
+
* POST /api/v1/payments/create/ Create new payment. Request body: {
|
|
255
|
+
* "amount_usd": "100.00", "currency_code": "USDTTRC20", "description":
|
|
256
|
+
* "Optional description" }
|
|
257
|
+
*/
|
|
258
|
+
paymentsCreateCreate(): Promise<PaymentList$1>;
|
|
259
|
+
transactionsList(limit?: number, offset?: number, type?: string): Promise<any>;
|
|
260
|
+
transactionsList(params?: {
|
|
261
|
+
limit?: number;
|
|
262
|
+
offset?: number;
|
|
263
|
+
type?: string;
|
|
264
|
+
}): Promise<any>;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* HTTP Client Adapter Pattern
|
|
269
|
+
*
|
|
270
|
+
* Allows switching between fetch/axios/httpx without changing generated code.
|
|
271
|
+
* Provides unified interface for making HTTP requests.
|
|
272
|
+
*/
|
|
273
|
+
interface HttpRequest {
|
|
274
|
+
method: string;
|
|
275
|
+
url: string;
|
|
276
|
+
headers?: Record<string, string>;
|
|
277
|
+
body?: any;
|
|
278
|
+
params?: Record<string, any>;
|
|
279
|
+
/** FormData for file uploads (multipart/form-data) */
|
|
280
|
+
formData?: FormData;
|
|
281
|
+
}
|
|
282
|
+
interface HttpResponse<T = any> {
|
|
283
|
+
data: T;
|
|
284
|
+
status: number;
|
|
285
|
+
statusText: string;
|
|
286
|
+
headers: Record<string, string>;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* HTTP Client Adapter Interface.
|
|
290
|
+
* Implement this to use custom HTTP clients (axios, httpx, etc.)
|
|
291
|
+
*/
|
|
292
|
+
interface HttpClientAdapter {
|
|
293
|
+
request<T = any>(request: HttpRequest): Promise<HttpResponse<T>>;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Default Fetch API adapter.
|
|
297
|
+
* Uses native browser fetch() with proper error handling.
|
|
298
|
+
*/
|
|
299
|
+
declare class FetchAdapter implements HttpClientAdapter {
|
|
300
|
+
request<T = any>(request: HttpRequest): Promise<HttpResponse<T>>;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* API Logger with Consola
|
|
305
|
+
* Beautiful console logging for API requests and responses
|
|
306
|
+
*
|
|
307
|
+
* Installation:
|
|
308
|
+
* npm install consola
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Request log data
|
|
313
|
+
*/
|
|
314
|
+
interface RequestLog {
|
|
315
|
+
method: string;
|
|
316
|
+
url: string;
|
|
317
|
+
headers?: Record<string, string>;
|
|
318
|
+
body?: any;
|
|
319
|
+
timestamp: number;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Response log data
|
|
323
|
+
*/
|
|
324
|
+
interface ResponseLog {
|
|
325
|
+
status: number;
|
|
326
|
+
statusText: string;
|
|
327
|
+
data?: any;
|
|
328
|
+
duration: number;
|
|
329
|
+
timestamp: number;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Error log data
|
|
333
|
+
*/
|
|
334
|
+
interface ErrorLog {
|
|
335
|
+
message: string;
|
|
336
|
+
statusCode?: number;
|
|
337
|
+
fieldErrors?: Record<string, string[]>;
|
|
338
|
+
duration: number;
|
|
339
|
+
timestamp: number;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* Logger configuration
|
|
343
|
+
*/
|
|
344
|
+
interface LoggerConfig {
|
|
345
|
+
/** Enable logging */
|
|
346
|
+
enabled: boolean;
|
|
347
|
+
/** Log requests */
|
|
348
|
+
logRequests: boolean;
|
|
349
|
+
/** Log responses */
|
|
350
|
+
logResponses: boolean;
|
|
351
|
+
/** Log errors */
|
|
352
|
+
logErrors: boolean;
|
|
353
|
+
/** Log request/response bodies */
|
|
354
|
+
logBodies: boolean;
|
|
355
|
+
/** Log headers (excluding sensitive ones) */
|
|
356
|
+
logHeaders: boolean;
|
|
357
|
+
/** Custom consola instance */
|
|
358
|
+
consola?: ConsolaInstance;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* API Logger class
|
|
362
|
+
*/
|
|
363
|
+
declare class APILogger {
|
|
364
|
+
private config;
|
|
365
|
+
private consola;
|
|
366
|
+
constructor(config?: Partial<LoggerConfig>);
|
|
367
|
+
/**
|
|
368
|
+
* Enable logging
|
|
369
|
+
*/
|
|
370
|
+
enable(): void;
|
|
371
|
+
/**
|
|
372
|
+
* Disable logging
|
|
373
|
+
*/
|
|
374
|
+
disable(): void;
|
|
375
|
+
/**
|
|
376
|
+
* Update configuration
|
|
377
|
+
*/
|
|
378
|
+
setConfig(config: Partial<LoggerConfig>): void;
|
|
379
|
+
/**
|
|
380
|
+
* Filter sensitive headers
|
|
381
|
+
*/
|
|
382
|
+
private filterHeaders;
|
|
383
|
+
/**
|
|
384
|
+
* Log request
|
|
385
|
+
*/
|
|
386
|
+
logRequest(request: RequestLog): void;
|
|
387
|
+
/**
|
|
388
|
+
* Log response
|
|
389
|
+
*/
|
|
390
|
+
logResponse(request: RequestLog, response: ResponseLog): void;
|
|
391
|
+
/**
|
|
392
|
+
* Log error
|
|
393
|
+
*/
|
|
394
|
+
logError(request: RequestLog, error: ErrorLog): void;
|
|
395
|
+
/**
|
|
396
|
+
* Log general info
|
|
397
|
+
*/
|
|
398
|
+
info(message: string, ...args: any[]): void;
|
|
399
|
+
/**
|
|
400
|
+
* Log warning
|
|
401
|
+
*/
|
|
402
|
+
warn(message: string, ...args: any[]): void;
|
|
403
|
+
/**
|
|
404
|
+
* Log error
|
|
405
|
+
*/
|
|
406
|
+
error(message: string, ...args: any[]): void;
|
|
407
|
+
/**
|
|
408
|
+
* Log debug
|
|
409
|
+
*/
|
|
410
|
+
debug(message: string, ...args: any[]): void;
|
|
411
|
+
/**
|
|
412
|
+
* Log success
|
|
413
|
+
*/
|
|
414
|
+
success(message: string, ...args: any[]): void;
|
|
415
|
+
/**
|
|
416
|
+
* Create a sub-logger with prefix
|
|
417
|
+
*/
|
|
418
|
+
withTag(tag: string): ConsolaInstance;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Retry Configuration and Utilities
|
|
423
|
+
*
|
|
424
|
+
* Provides automatic retry logic for failed HTTP requests using p-retry.
|
|
425
|
+
* Retries only on network errors and server errors (5xx), not client errors (4xx).
|
|
426
|
+
*/
|
|
427
|
+
/**
|
|
428
|
+
* Information about a failed retry attempt.
|
|
429
|
+
*/
|
|
430
|
+
interface FailedAttemptInfo {
|
|
431
|
+
/** The error that caused the failure */
|
|
432
|
+
error: Error;
|
|
433
|
+
/** The attempt number (1-indexed) */
|
|
434
|
+
attemptNumber: number;
|
|
435
|
+
/** Number of retries left */
|
|
436
|
+
retriesLeft: number;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Retry configuration options.
|
|
440
|
+
*
|
|
441
|
+
* Uses exponential backoff with jitter by default to avoid thundering herd.
|
|
442
|
+
*/
|
|
443
|
+
interface RetryConfig {
|
|
444
|
+
/**
|
|
445
|
+
* Maximum number of retry attempts.
|
|
446
|
+
* @default 3
|
|
447
|
+
*/
|
|
448
|
+
retries?: number;
|
|
449
|
+
/**
|
|
450
|
+
* Exponential backoff factor.
|
|
451
|
+
* @default 2
|
|
452
|
+
*/
|
|
453
|
+
factor?: number;
|
|
454
|
+
/**
|
|
455
|
+
* Minimum wait time between retries (ms).
|
|
456
|
+
* @default 1000
|
|
457
|
+
*/
|
|
458
|
+
minTimeout?: number;
|
|
459
|
+
/**
|
|
460
|
+
* Maximum wait time between retries (ms).
|
|
461
|
+
* @default 60000
|
|
462
|
+
*/
|
|
463
|
+
maxTimeout?: number;
|
|
464
|
+
/**
|
|
465
|
+
* Add randomness to wait times (jitter).
|
|
466
|
+
* Helps avoid thundering herd problem.
|
|
467
|
+
* @default true
|
|
468
|
+
*/
|
|
469
|
+
randomize?: boolean;
|
|
470
|
+
/**
|
|
471
|
+
* Callback called on each failed attempt.
|
|
472
|
+
*/
|
|
473
|
+
onFailedAttempt?: (info: FailedAttemptInfo) => void;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Default retry configuration.
|
|
477
|
+
*/
|
|
478
|
+
declare const DEFAULT_RETRY_CONFIG: Required<RetryConfig>;
|
|
479
|
+
/**
|
|
480
|
+
* Determine if an error should trigger a retry.
|
|
481
|
+
*
|
|
482
|
+
* Retries on:
|
|
483
|
+
* - Network errors (connection refused, timeout, etc.)
|
|
484
|
+
* - Server errors (5xx status codes)
|
|
485
|
+
* - Rate limiting (429 status code)
|
|
486
|
+
*
|
|
487
|
+
* Does NOT retry on:
|
|
488
|
+
* - Client errors (4xx except 429)
|
|
489
|
+
* - Authentication errors (401, 403)
|
|
490
|
+
* - Not found (404)
|
|
491
|
+
*
|
|
492
|
+
* @param error - The error to check
|
|
493
|
+
* @returns true if should retry, false otherwise
|
|
494
|
+
*/
|
|
495
|
+
declare function shouldRetry(error: any): boolean;
|
|
496
|
+
/**
|
|
497
|
+
* Wrap a function with retry logic.
|
|
498
|
+
*
|
|
499
|
+
* @param fn - Async function to retry
|
|
500
|
+
* @param config - Retry configuration
|
|
501
|
+
* @returns Result of the function
|
|
502
|
+
*
|
|
503
|
+
* @example
|
|
504
|
+
* ```typescript
|
|
505
|
+
* const result = await withRetry(
|
|
506
|
+
* async () => fetch('https://api.example.com/users'),
|
|
507
|
+
* { retries: 5, minTimeout: 2000 }
|
|
508
|
+
* );
|
|
509
|
+
* ```
|
|
510
|
+
*/
|
|
511
|
+
declare function withRetry<T>(fn: () => Promise<T>, config?: RetryConfig): Promise<T>;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Async API client for Django CFG API.
|
|
515
|
+
*
|
|
516
|
+
* Usage:
|
|
517
|
+
* ```typescript
|
|
518
|
+
* const client = new APIClient('https://api.example.com');
|
|
519
|
+
* const users = await client.users.list();
|
|
520
|
+
* const post = await client.posts.create(newPost);
|
|
521
|
+
*
|
|
522
|
+
* // Custom HTTP adapter (e.g., Axios)
|
|
523
|
+
* const client = new APIClient('https://api.example.com', {
|
|
524
|
+
* httpClient: new AxiosAdapter()
|
|
525
|
+
* });
|
|
526
|
+
* ```
|
|
527
|
+
*/
|
|
528
|
+
declare class APIClient {
|
|
529
|
+
private baseUrl;
|
|
530
|
+
private httpClient;
|
|
531
|
+
private logger;
|
|
532
|
+
private retryConfig;
|
|
533
|
+
ext_payments_payments: ExtPaymentsPayments;
|
|
534
|
+
constructor(baseUrl: string, options?: {
|
|
535
|
+
httpClient?: HttpClientAdapter;
|
|
536
|
+
loggerConfig?: Partial<LoggerConfig>;
|
|
537
|
+
retryConfig?: RetryConfig;
|
|
538
|
+
});
|
|
539
|
+
/**
|
|
540
|
+
* Get CSRF token from cookies (for SessionAuthentication).
|
|
541
|
+
*
|
|
542
|
+
* Returns null if cookie doesn't exist (JWT-only auth).
|
|
543
|
+
*/
|
|
544
|
+
getCsrfToken(): string | null;
|
|
545
|
+
/**
|
|
546
|
+
* Make HTTP request with Django CSRF and session handling.
|
|
547
|
+
* Automatically retries on network errors and 5xx server errors.
|
|
548
|
+
*/
|
|
549
|
+
request<T>(method: string, path: string, options?: {
|
|
550
|
+
params?: Record<string, any>;
|
|
551
|
+
body?: any;
|
|
552
|
+
formData?: FormData;
|
|
553
|
+
headers?: Record<string, string>;
|
|
554
|
+
}): Promise<T>;
|
|
555
|
+
/**
|
|
556
|
+
* Internal request method (without retry wrapper).
|
|
557
|
+
* Used by request() method with optional retry logic.
|
|
558
|
+
*/
|
|
559
|
+
private _makeRequest;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
/**
|
|
563
|
+
* Storage adapters for cross-platform token storage.
|
|
564
|
+
*
|
|
565
|
+
* Supports:
|
|
566
|
+
* - LocalStorage (browser)
|
|
567
|
+
* - Cookies (SSR/browser)
|
|
568
|
+
* - Memory (Node.js/Electron/testing)
|
|
569
|
+
*/
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* Storage adapter interface for cross-platform token storage.
|
|
573
|
+
*/
|
|
574
|
+
interface StorageAdapter {
|
|
575
|
+
getItem(key: string): string | null;
|
|
576
|
+
setItem(key: string, value: string): void;
|
|
577
|
+
removeItem(key: string): void;
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* LocalStorage adapter with safe try-catch for browser environments.
|
|
581
|
+
* Works in modern browsers with localStorage support.
|
|
582
|
+
*
|
|
583
|
+
* Note: This adapter uses window.localStorage and should only be used in browser/client environments.
|
|
584
|
+
* For server-side usage, use MemoryStorageAdapter or CookieStorageAdapter instead.
|
|
585
|
+
*/
|
|
586
|
+
declare class LocalStorageAdapter implements StorageAdapter {
|
|
587
|
+
private logger?;
|
|
588
|
+
constructor(logger?: APILogger);
|
|
589
|
+
getItem(key: string): string | null;
|
|
590
|
+
setItem(key: string, value: string): void;
|
|
591
|
+
removeItem(key: string): void;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Cookie-based storage adapter for SSR and browser environments.
|
|
595
|
+
* Useful for Next.js, Nuxt.js, and other SSR frameworks.
|
|
596
|
+
*/
|
|
597
|
+
declare class CookieStorageAdapter implements StorageAdapter {
|
|
598
|
+
private logger?;
|
|
599
|
+
constructor(logger?: APILogger);
|
|
600
|
+
getItem(key: string): string | null;
|
|
601
|
+
setItem(key: string, value: string): void;
|
|
602
|
+
removeItem(key: string): void;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* In-memory storage adapter for Node.js, Electron, and testing environments.
|
|
606
|
+
* Data is stored in RAM and cleared when process exits.
|
|
607
|
+
*/
|
|
608
|
+
declare class MemoryStorageAdapter implements StorageAdapter {
|
|
609
|
+
private storage;
|
|
610
|
+
private logger?;
|
|
611
|
+
constructor(logger?: APILogger);
|
|
612
|
+
getItem(key: string): string | null;
|
|
613
|
+
setItem(key: string, value: string): void;
|
|
614
|
+
removeItem(key: string): void;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Zod schema for Balance
|
|
619
|
+
*
|
|
620
|
+
* This schema provides runtime validation and type inference.
|
|
621
|
+
* * User balance serializer.
|
|
622
|
+
* */
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* User balance serializer.
|
|
626
|
+
*/
|
|
627
|
+
declare const BalanceSchema: z.ZodObject<{
|
|
628
|
+
balance_usd: z.ZodString;
|
|
629
|
+
balance_display: z.ZodString;
|
|
630
|
+
total_deposited: z.ZodString;
|
|
631
|
+
total_withdrawn: z.ZodString;
|
|
632
|
+
last_transaction_at: z.ZodNullable<z.ZodISODateTime>;
|
|
633
|
+
}, z.core.$strip>;
|
|
634
|
+
/**
|
|
635
|
+
* Infer TypeScript type from Zod schema
|
|
636
|
+
*/
|
|
637
|
+
type Balance = z.infer<typeof BalanceSchema>;
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Zod schema for Currency
|
|
641
|
+
*
|
|
642
|
+
* This schema provides runtime validation and type inference.
|
|
643
|
+
* * Currency list serializer.
|
|
644
|
+
* */
|
|
645
|
+
|
|
646
|
+
/**
|
|
647
|
+
* Currency list serializer.
|
|
648
|
+
*/
|
|
649
|
+
declare const CurrencySchema: z.ZodObject<{
|
|
650
|
+
code: z.ZodString;
|
|
651
|
+
name: z.ZodString;
|
|
652
|
+
token: z.ZodString;
|
|
653
|
+
network: z.ZodNullable<z.ZodString>;
|
|
654
|
+
display_name: z.ZodString;
|
|
655
|
+
symbol: z.ZodString;
|
|
656
|
+
decimal_places: z.ZodInt;
|
|
657
|
+
is_active: z.ZodBoolean;
|
|
658
|
+
min_amount_usd: z.ZodString;
|
|
659
|
+
sort_order: z.ZodInt;
|
|
660
|
+
}, z.core.$strip>;
|
|
661
|
+
/**
|
|
662
|
+
* Infer TypeScript type from Zod schema
|
|
663
|
+
*/
|
|
664
|
+
type Currency = z.infer<typeof CurrencySchema>;
|
|
665
|
+
|
|
666
|
+
declare const PaginatedPaymentListListSchema: z.ZodObject<{
|
|
667
|
+
count: z.ZodInt;
|
|
668
|
+
page: z.ZodInt;
|
|
669
|
+
pages: z.ZodInt;
|
|
670
|
+
page_size: z.ZodInt;
|
|
671
|
+
has_next: z.ZodBoolean;
|
|
672
|
+
has_previous: z.ZodBoolean;
|
|
673
|
+
next_page: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
|
|
674
|
+
previous_page: z.ZodOptional<z.ZodNullable<z.ZodInt>>;
|
|
675
|
+
results: z.ZodArray<z.ZodObject<{
|
|
676
|
+
id: z.ZodString;
|
|
677
|
+
internal_payment_id: z.ZodString;
|
|
678
|
+
amount_usd: z.ZodString;
|
|
679
|
+
currency_code: z.ZodString;
|
|
680
|
+
currency_token: z.ZodString;
|
|
681
|
+
status: z.ZodEnum<typeof PaymentListStatus>;
|
|
682
|
+
status_display: z.ZodString;
|
|
683
|
+
created_at: z.ZodISODateTime;
|
|
684
|
+
completed_at: z.ZodNullable<z.ZodISODateTime>;
|
|
685
|
+
}, z.core.$strip>>;
|
|
686
|
+
}, z.core.$strip>;
|
|
687
|
+
/**
|
|
688
|
+
* Infer TypeScript type from Zod schema
|
|
689
|
+
*/
|
|
690
|
+
type PaginatedPaymentListList = z.infer<typeof PaginatedPaymentListListSchema>;
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Zod schema for PaymentDetail
|
|
694
|
+
*
|
|
695
|
+
* This schema provides runtime validation and type inference.
|
|
696
|
+
* * Detailed payment information.
|
|
697
|
+
* */
|
|
698
|
+
|
|
699
|
+
/**
|
|
700
|
+
* Detailed payment information.
|
|
701
|
+
*/
|
|
702
|
+
declare const PaymentDetailSchema: z.ZodObject<{
|
|
703
|
+
id: z.ZodString;
|
|
704
|
+
internal_payment_id: z.ZodString;
|
|
705
|
+
amount_usd: z.ZodString;
|
|
706
|
+
currency_code: z.ZodString;
|
|
707
|
+
currency_name: z.ZodString;
|
|
708
|
+
currency_token: z.ZodString;
|
|
709
|
+
currency_network: z.ZodString;
|
|
710
|
+
pay_amount: z.ZodNullable<z.ZodString>;
|
|
711
|
+
actual_amount: z.ZodNullable<z.ZodString>;
|
|
712
|
+
actual_amount_usd: z.ZodNullable<z.ZodString>;
|
|
713
|
+
status: z.ZodEnum<typeof PaymentDetailStatus>;
|
|
714
|
+
status_display: z.ZodString;
|
|
715
|
+
pay_address: z.ZodNullable<z.ZodString>;
|
|
716
|
+
qr_code_url: z.ZodNullable<z.ZodString>;
|
|
717
|
+
payment_url: z.ZodNullable<z.ZodURL>;
|
|
718
|
+
transaction_hash: z.ZodNullable<z.ZodString>;
|
|
719
|
+
explorer_link: z.ZodNullable<z.ZodString>;
|
|
720
|
+
confirmations_count: z.ZodInt;
|
|
721
|
+
expires_at: z.ZodNullable<z.ZodISODateTime>;
|
|
722
|
+
completed_at: z.ZodNullable<z.ZodISODateTime>;
|
|
723
|
+
created_at: z.ZodISODateTime;
|
|
724
|
+
is_completed: z.ZodBoolean;
|
|
725
|
+
is_failed: z.ZodBoolean;
|
|
726
|
+
is_expired: z.ZodBoolean;
|
|
727
|
+
description: z.ZodString;
|
|
728
|
+
}, z.core.$strip>;
|
|
729
|
+
/**
|
|
730
|
+
* Infer TypeScript type from Zod schema
|
|
731
|
+
*/
|
|
732
|
+
type PaymentDetail = z.infer<typeof PaymentDetailSchema>;
|
|
733
|
+
|
|
734
|
+
/**
|
|
735
|
+
* Zod schema for PaymentList
|
|
736
|
+
*
|
|
737
|
+
* This schema provides runtime validation and type inference.
|
|
738
|
+
* * Payment list item (lighter than detail).
|
|
739
|
+
* */
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* Payment list item (lighter than detail).
|
|
743
|
+
*/
|
|
744
|
+
declare const PaymentListSchema: z.ZodObject<{
|
|
745
|
+
id: z.ZodString;
|
|
746
|
+
internal_payment_id: z.ZodString;
|
|
747
|
+
amount_usd: z.ZodString;
|
|
748
|
+
currency_code: z.ZodString;
|
|
749
|
+
currency_token: z.ZodString;
|
|
750
|
+
status: z.ZodEnum<typeof PaymentListStatus>;
|
|
751
|
+
status_display: z.ZodString;
|
|
752
|
+
created_at: z.ZodISODateTime;
|
|
753
|
+
completed_at: z.ZodNullable<z.ZodISODateTime>;
|
|
754
|
+
}, z.core.$strip>;
|
|
755
|
+
/**
|
|
756
|
+
* Infer TypeScript type from Zod schema
|
|
757
|
+
*/
|
|
758
|
+
type PaymentList = z.infer<typeof PaymentListSchema>;
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Zod schema for Transaction
|
|
762
|
+
*
|
|
763
|
+
* This schema provides runtime validation and type inference.
|
|
764
|
+
* * Transaction serializer.
|
|
765
|
+
* */
|
|
766
|
+
|
|
767
|
+
/**
|
|
768
|
+
* Transaction serializer.
|
|
769
|
+
*/
|
|
770
|
+
declare const TransactionSchema: z.ZodObject<{
|
|
771
|
+
id: z.ZodString;
|
|
772
|
+
transaction_type: z.ZodEnum<typeof TransactionTransactionType>;
|
|
773
|
+
type_display: z.ZodString;
|
|
774
|
+
amount_usd: z.ZodString;
|
|
775
|
+
amount_display: z.ZodString;
|
|
776
|
+
balance_after: z.ZodString;
|
|
777
|
+
payment_id: z.ZodNullable<z.ZodString>;
|
|
778
|
+
description: z.ZodString;
|
|
779
|
+
created_at: z.ZodISODateTime;
|
|
780
|
+
}, z.core.$strip>;
|
|
781
|
+
/**
|
|
782
|
+
* Infer TypeScript type from Zod schema
|
|
783
|
+
*/
|
|
784
|
+
type Transaction = z.infer<typeof TransactionSchema>;
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Zod Schemas - Runtime validation and type inference
|
|
788
|
+
*
|
|
789
|
+
* Auto-generated from OpenAPI specification.
|
|
790
|
+
* Provides runtime validation for API requests and responses.
|
|
791
|
+
*
|
|
792
|
+
* Usage:
|
|
793
|
+
* ```typescript
|
|
794
|
+
* import { UserSchema } from './schemas'
|
|
795
|
+
*
|
|
796
|
+
* // Validate data
|
|
797
|
+
* const user = UserSchema.parse(data)
|
|
798
|
+
*
|
|
799
|
+
* // Type inference
|
|
800
|
+
* type User = z.infer<typeof UserSchema>
|
|
801
|
+
* ```
|
|
802
|
+
*/
|
|
803
|
+
|
|
804
|
+
type index$1_Balance = Balance;
|
|
805
|
+
declare const index$1_BalanceSchema: typeof BalanceSchema;
|
|
806
|
+
type index$1_Currency = Currency;
|
|
807
|
+
declare const index$1_CurrencySchema: typeof CurrencySchema;
|
|
808
|
+
type index$1_PaginatedPaymentListList = PaginatedPaymentListList;
|
|
809
|
+
declare const index$1_PaginatedPaymentListListSchema: typeof PaginatedPaymentListListSchema;
|
|
810
|
+
type index$1_PaymentDetail = PaymentDetail;
|
|
811
|
+
declare const index$1_PaymentDetailSchema: typeof PaymentDetailSchema;
|
|
812
|
+
type index$1_PaymentList = PaymentList;
|
|
813
|
+
declare const index$1_PaymentListSchema: typeof PaymentListSchema;
|
|
814
|
+
type index$1_Transaction = Transaction;
|
|
815
|
+
declare const index$1_TransactionSchema: typeof TransactionSchema;
|
|
816
|
+
declare namespace index$1 {
|
|
817
|
+
export { type index$1_Balance as Balance, index$1_BalanceSchema as BalanceSchema, type index$1_Currency as Currency, index$1_CurrencySchema as CurrencySchema, type index$1_PaginatedPaymentListList as PaginatedPaymentListList, index$1_PaginatedPaymentListListSchema as PaginatedPaymentListListSchema, type index$1_PaymentDetail as PaymentDetail, index$1_PaymentDetailSchema as PaymentDetailSchema, type index$1_PaymentList as PaymentList, index$1_PaymentListSchema as PaymentListSchema, type index$1_Transaction as Transaction, index$1_TransactionSchema as TransactionSchema };
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Zod Validation Events - Browser CustomEvent integration
|
|
822
|
+
*
|
|
823
|
+
* Dispatches browser CustomEvents when Zod validation fails, allowing
|
|
824
|
+
* React/frontend apps to listen and handle validation errors globally.
|
|
825
|
+
*
|
|
826
|
+
* @example
|
|
827
|
+
* ```typescript
|
|
828
|
+
* // In your React app
|
|
829
|
+
* window.addEventListener('zod-validation-error', (event) => {
|
|
830
|
+
* const { operation, path, method, error, response } = event.detail;
|
|
831
|
+
* console.error(`Validation failed for ${method} ${path}`, error);
|
|
832
|
+
* // Show toast notification, log to Sentry, etc.
|
|
833
|
+
* });
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Validation error event detail
|
|
839
|
+
*/
|
|
840
|
+
interface ValidationErrorDetail {
|
|
841
|
+
/** Operation/function name that failed validation */
|
|
842
|
+
operation: string;
|
|
843
|
+
/** API endpoint path */
|
|
844
|
+
path: string;
|
|
845
|
+
/** HTTP method */
|
|
846
|
+
method: string;
|
|
847
|
+
/** Zod validation error */
|
|
848
|
+
error: ZodError;
|
|
849
|
+
/** Raw response data that failed validation */
|
|
850
|
+
response: any;
|
|
851
|
+
/** Timestamp of the error */
|
|
852
|
+
timestamp: Date;
|
|
853
|
+
}
|
|
854
|
+
/**
|
|
855
|
+
* Custom event type for Zod validation errors
|
|
856
|
+
*/
|
|
857
|
+
type ValidationErrorEvent = CustomEvent<ValidationErrorDetail>;
|
|
858
|
+
/**
|
|
859
|
+
* Dispatch a Zod validation error event.
|
|
860
|
+
*
|
|
861
|
+
* Only dispatches in browser environment (when window is defined).
|
|
862
|
+
* Safe to call in Node.js/SSR - will be a no-op.
|
|
863
|
+
*
|
|
864
|
+
* @param detail - Validation error details
|
|
865
|
+
*/
|
|
866
|
+
declare function dispatchValidationError(detail: ValidationErrorDetail): void;
|
|
867
|
+
/**
|
|
868
|
+
* Add a global listener for Zod validation errors.
|
|
869
|
+
*
|
|
870
|
+
* @param callback - Function to call when validation error occurs
|
|
871
|
+
* @returns Cleanup function to remove the listener
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* ```typescript
|
|
875
|
+
* const cleanup = onValidationError(({ operation, error }) => {
|
|
876
|
+
* toast.error(`Validation failed in ${operation}`);
|
|
877
|
+
* logToSentry(error);
|
|
878
|
+
* });
|
|
879
|
+
*
|
|
880
|
+
* // Later, remove listener
|
|
881
|
+
* cleanup();
|
|
882
|
+
* ```
|
|
883
|
+
*/
|
|
884
|
+
declare function onValidationError(callback: (detail: ValidationErrorDetail) => void): () => void;
|
|
885
|
+
/**
|
|
886
|
+
* Format Zod error for logging/display.
|
|
887
|
+
*
|
|
888
|
+
* @param error - Zod validation error
|
|
889
|
+
* @returns Formatted error message
|
|
890
|
+
*/
|
|
891
|
+
declare function formatZodError(error: ZodError): string;
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Get user balance
|
|
895
|
+
*
|
|
896
|
+
* @method GET
|
|
897
|
+
* @path /cfg/payments/balance/
|
|
898
|
+
*/
|
|
899
|
+
declare function getPaymentsBalanceRetrieve(client?: any): Promise<Balance>;
|
|
900
|
+
/**
|
|
901
|
+
* Get available currencies
|
|
902
|
+
*
|
|
903
|
+
* @method GET
|
|
904
|
+
* @path /cfg/payments/currencies/
|
|
905
|
+
*/
|
|
906
|
+
declare function getPaymentsCurrenciesList(client?: any): Promise<any>;
|
|
907
|
+
/**
|
|
908
|
+
* API operation
|
|
909
|
+
*
|
|
910
|
+
* @method GET
|
|
911
|
+
* @path /cfg/payments/payments/
|
|
912
|
+
*/
|
|
913
|
+
declare function getPaymentsPaymentsList(params?: {
|
|
914
|
+
page?: number;
|
|
915
|
+
page_size?: number;
|
|
916
|
+
}, client?: any): Promise<PaginatedPaymentListList>;
|
|
917
|
+
/**
|
|
918
|
+
* API operation
|
|
919
|
+
*
|
|
920
|
+
* @method GET
|
|
921
|
+
* @path /cfg/payments/payments/{id}/
|
|
922
|
+
*/
|
|
923
|
+
declare function getPaymentsPaymentsRetrieve(id: string, client?: any): Promise<PaymentDetail>;
|
|
924
|
+
/**
|
|
925
|
+
* API operation
|
|
926
|
+
*
|
|
927
|
+
* @method POST
|
|
928
|
+
* @path /cfg/payments/payments/{id}/confirm/
|
|
929
|
+
*/
|
|
930
|
+
declare function createPaymentsPaymentsConfirmCreate(id: string, client?: any): Promise<PaymentList>;
|
|
931
|
+
/**
|
|
932
|
+
* API operation
|
|
933
|
+
*
|
|
934
|
+
* @method GET
|
|
935
|
+
* @path /cfg/payments/payments/{id}/status/
|
|
936
|
+
*/
|
|
937
|
+
declare function getPaymentsPaymentsStatusRetrieve(id: string, client?: any): Promise<PaymentList>;
|
|
938
|
+
/**
|
|
939
|
+
* API operation
|
|
940
|
+
*
|
|
941
|
+
* @method POST
|
|
942
|
+
* @path /cfg/payments/payments/create/
|
|
943
|
+
*/
|
|
944
|
+
declare function createPaymentsPaymentsCreateCreate(client?: any): Promise<PaymentList>;
|
|
945
|
+
/**
|
|
946
|
+
* Get user transactions
|
|
947
|
+
*
|
|
948
|
+
* @method GET
|
|
949
|
+
* @path /cfg/payments/transactions/
|
|
950
|
+
*/
|
|
951
|
+
declare function getPaymentsTransactionsList(params?: {
|
|
952
|
+
limit?: number;
|
|
953
|
+
offset?: number;
|
|
954
|
+
type?: string;
|
|
955
|
+
}, client?: any): Promise<any>;
|
|
956
|
+
|
|
957
|
+
/**
|
|
958
|
+
* Typed Fetchers - Universal API functions
|
|
959
|
+
*
|
|
960
|
+
* Auto-generated from OpenAPI specification.
|
|
961
|
+
* These functions work in any JavaScript environment.
|
|
962
|
+
*
|
|
963
|
+
* Features:
|
|
964
|
+
* - Runtime validation with Zod
|
|
965
|
+
* - Type-safe parameters and responses
|
|
966
|
+
* - Works with any data-fetching library (SWR, React Query, etc)
|
|
967
|
+
* - Server Component compatible
|
|
968
|
+
*
|
|
969
|
+
* Usage:
|
|
970
|
+
* ```typescript
|
|
971
|
+
* import * as fetchers from './fetchers'
|
|
972
|
+
*
|
|
973
|
+
* // Direct usage
|
|
974
|
+
* const user = await fetchers.getUser(1)
|
|
975
|
+
*
|
|
976
|
+
* // With SWR
|
|
977
|
+
* const { data } = useSWR('user-1', () => fetchers.getUser(1))
|
|
978
|
+
*
|
|
979
|
+
* // With React Query
|
|
980
|
+
* const { data } = useQuery(['user', 1], () => fetchers.getUser(1))
|
|
981
|
+
* ```
|
|
982
|
+
*/
|
|
983
|
+
|
|
984
|
+
declare const index_createPaymentsPaymentsConfirmCreate: typeof createPaymentsPaymentsConfirmCreate;
|
|
985
|
+
declare const index_createPaymentsPaymentsCreateCreate: typeof createPaymentsPaymentsCreateCreate;
|
|
986
|
+
declare const index_getPaymentsBalanceRetrieve: typeof getPaymentsBalanceRetrieve;
|
|
987
|
+
declare const index_getPaymentsCurrenciesList: typeof getPaymentsCurrenciesList;
|
|
988
|
+
declare const index_getPaymentsPaymentsList: typeof getPaymentsPaymentsList;
|
|
989
|
+
declare const index_getPaymentsPaymentsRetrieve: typeof getPaymentsPaymentsRetrieve;
|
|
990
|
+
declare const index_getPaymentsPaymentsStatusRetrieve: typeof getPaymentsPaymentsStatusRetrieve;
|
|
991
|
+
declare const index_getPaymentsTransactionsList: typeof getPaymentsTransactionsList;
|
|
992
|
+
declare namespace index {
|
|
993
|
+
export { index_createPaymentsPaymentsConfirmCreate as createPaymentsPaymentsConfirmCreate, index_createPaymentsPaymentsCreateCreate as createPaymentsPaymentsCreateCreate, index_getPaymentsBalanceRetrieve as getPaymentsBalanceRetrieve, index_getPaymentsCurrenciesList as getPaymentsCurrenciesList, index_getPaymentsPaymentsList as getPaymentsPaymentsList, index_getPaymentsPaymentsRetrieve as getPaymentsPaymentsRetrieve, index_getPaymentsPaymentsStatusRetrieve as getPaymentsPaymentsStatusRetrieve, index_getPaymentsTransactionsList as getPaymentsTransactionsList };
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Global API Instance - Singleton configuration
|
|
998
|
+
*
|
|
999
|
+
* This module provides a global API instance that can be configured once
|
|
1000
|
+
* and used throughout your application.
|
|
1001
|
+
*
|
|
1002
|
+
* Usage:
|
|
1003
|
+
* ```typescript
|
|
1004
|
+
* // Configure once (e.g., in your app entry point)
|
|
1005
|
+
* import { configureAPI } from './api-instance'
|
|
1006
|
+
*
|
|
1007
|
+
* configureAPI({
|
|
1008
|
+
* baseUrl: 'https://api.example.com',
|
|
1009
|
+
* token: 'your-jwt-token'
|
|
1010
|
+
* })
|
|
1011
|
+
*
|
|
1012
|
+
* // Then use fetchers and hooks anywhere without configuration
|
|
1013
|
+
* import { getUsers } from './fetchers'
|
|
1014
|
+
* const users = await getUsers({ page: 1 })
|
|
1015
|
+
* ```
|
|
1016
|
+
*
|
|
1017
|
+
* For SSR or multiple instances:
|
|
1018
|
+
* ```typescript
|
|
1019
|
+
* import { API } from './index'
|
|
1020
|
+
* import { getUsers } from './fetchers'
|
|
1021
|
+
*
|
|
1022
|
+
* const api = new API('https://api.example.com')
|
|
1023
|
+
* const users = await getUsers({ page: 1 }, api)
|
|
1024
|
+
* ```
|
|
1025
|
+
*/
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* Get the global API instance
|
|
1029
|
+
* @throws Error if API is not configured
|
|
1030
|
+
*/
|
|
1031
|
+
declare function getAPIInstance(): API;
|
|
1032
|
+
/**
|
|
1033
|
+
* Check if API is configured
|
|
1034
|
+
*/
|
|
1035
|
+
declare function isAPIConfigured(): boolean;
|
|
1036
|
+
/**
|
|
1037
|
+
* Configure the global API instance
|
|
1038
|
+
*
|
|
1039
|
+
* @param baseUrl - Base URL for the API
|
|
1040
|
+
* @param options - Optional configuration (storage, retry, logger)
|
|
1041
|
+
*
|
|
1042
|
+
* @example
|
|
1043
|
+
* ```typescript
|
|
1044
|
+
* configureAPI({
|
|
1045
|
+
* baseUrl: 'https://api.example.com',
|
|
1046
|
+
* token: 'jwt-token',
|
|
1047
|
+
* options: {
|
|
1048
|
+
* retryConfig: { maxRetries: 3 },
|
|
1049
|
+
* loggerConfig: { enabled: true }
|
|
1050
|
+
* }
|
|
1051
|
+
* })
|
|
1052
|
+
* ```
|
|
1053
|
+
*/
|
|
1054
|
+
declare function configureAPI(config: {
|
|
1055
|
+
baseUrl: string;
|
|
1056
|
+
token?: string;
|
|
1057
|
+
refreshToken?: string;
|
|
1058
|
+
options?: APIOptions;
|
|
1059
|
+
}): API;
|
|
1060
|
+
/**
|
|
1061
|
+
* Reconfigure the global API instance with new settings
|
|
1062
|
+
* Useful for updating tokens or base URL
|
|
1063
|
+
*/
|
|
1064
|
+
declare function reconfigureAPI(updates: {
|
|
1065
|
+
baseUrl?: string;
|
|
1066
|
+
token?: string;
|
|
1067
|
+
refreshToken?: string;
|
|
1068
|
+
}): API;
|
|
1069
|
+
/**
|
|
1070
|
+
* Clear tokens from the global API instance
|
|
1071
|
+
*/
|
|
1072
|
+
declare function clearAPITokens(): void;
|
|
1073
|
+
/**
|
|
1074
|
+
* Reset the global API instance
|
|
1075
|
+
* Useful for testing or logout scenarios
|
|
1076
|
+
*/
|
|
1077
|
+
declare function resetAPI(): void;
|
|
1078
|
+
|
|
1079
|
+
/**
|
|
1080
|
+
* API Error Classes
|
|
1081
|
+
*
|
|
1082
|
+
* Typed error classes with Django REST Framework support.
|
|
1083
|
+
*/
|
|
1084
|
+
/**
|
|
1085
|
+
* HTTP API Error with DRF field-specific validation errors.
|
|
1086
|
+
*
|
|
1087
|
+
* Usage:
|
|
1088
|
+
* ```typescript
|
|
1089
|
+
* try {
|
|
1090
|
+
* await api.users.create(userData);
|
|
1091
|
+
* } catch (error) {
|
|
1092
|
+
* if (error instanceof APIError) {
|
|
1093
|
+
* if (error.isValidationError) {
|
|
1094
|
+
* console.log('Field errors:', error.fieldErrors);
|
|
1095
|
+
* // { "email": ["Email already exists"], "username": ["Required"] }
|
|
1096
|
+
* }
|
|
1097
|
+
* }
|
|
1098
|
+
* }
|
|
1099
|
+
* ```
|
|
1100
|
+
*/
|
|
1101
|
+
declare class APIError extends Error {
|
|
1102
|
+
statusCode: number;
|
|
1103
|
+
statusText: string;
|
|
1104
|
+
response: any;
|
|
1105
|
+
url: string;
|
|
1106
|
+
constructor(statusCode: number, statusText: string, response: any, url: string, message?: string);
|
|
1107
|
+
/**
|
|
1108
|
+
* Get error details from response.
|
|
1109
|
+
* DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
|
|
1110
|
+
*/
|
|
1111
|
+
get details(): Record<string, any> | null;
|
|
1112
|
+
/**
|
|
1113
|
+
* Get field-specific validation errors from DRF.
|
|
1114
|
+
* Returns: { "field_name": ["error1", "error2"], ... }
|
|
1115
|
+
*/
|
|
1116
|
+
get fieldErrors(): Record<string, string[]> | null;
|
|
1117
|
+
/**
|
|
1118
|
+
* Get single error message from DRF.
|
|
1119
|
+
* Checks for "detail", "message", or first field error.
|
|
1120
|
+
*/
|
|
1121
|
+
get errorMessage(): string;
|
|
1122
|
+
get isValidationError(): boolean;
|
|
1123
|
+
get isAuthError(): boolean;
|
|
1124
|
+
get isPermissionError(): boolean;
|
|
1125
|
+
get isNotFoundError(): boolean;
|
|
1126
|
+
get isServerError(): boolean;
|
|
1127
|
+
}
|
|
1128
|
+
/**
|
|
1129
|
+
* Network Error (connection failed, timeout, etc.)
|
|
1130
|
+
*/
|
|
1131
|
+
declare class NetworkError extends Error {
|
|
1132
|
+
url: string;
|
|
1133
|
+
originalError?: Error;
|
|
1134
|
+
constructor(message: string, url: string, originalError?: Error);
|
|
1135
|
+
}
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Django CFG API - API Client with JWT Management
|
|
1139
|
+
*
|
|
1140
|
+
* Usage:
|
|
1141
|
+
* ```typescript
|
|
1142
|
+
* import { API } from './api';
|
|
1143
|
+
*
|
|
1144
|
+
* const api = new API('https://api.example.com');
|
|
1145
|
+
*
|
|
1146
|
+
* // Set JWT token
|
|
1147
|
+
* api.setToken('your-jwt-token', 'refresh-token');
|
|
1148
|
+
*
|
|
1149
|
+
* // Use API
|
|
1150
|
+
* const posts = await api.posts.list();
|
|
1151
|
+
* const user = await api.users.retrieve(1);
|
|
1152
|
+
*
|
|
1153
|
+
* // Check authentication
|
|
1154
|
+
* if (api.isAuthenticated()) {
|
|
1155
|
+
* // ...
|
|
1156
|
+
* }
|
|
1157
|
+
*
|
|
1158
|
+
* // Custom storage with logging (for Electron/Node.js)
|
|
1159
|
+
* import { MemoryStorageAdapter, APILogger } from './storage';
|
|
1160
|
+
* const logger = new APILogger({ enabled: true, logLevel: 'debug' });
|
|
1161
|
+
* const api = new API('https://api.example.com', {
|
|
1162
|
+
* storage: new MemoryStorageAdapter(logger),
|
|
1163
|
+
* loggerConfig: { enabled: true, logLevel: 'debug' }
|
|
1164
|
+
* });
|
|
1165
|
+
*
|
|
1166
|
+
* // Get OpenAPI schema
|
|
1167
|
+
* const schema = api.getSchema();
|
|
1168
|
+
* ```
|
|
1169
|
+
*/
|
|
1170
|
+
|
|
1171
|
+
declare const TOKEN_KEY = "auth_token";
|
|
1172
|
+
declare const REFRESH_TOKEN_KEY = "refresh_token";
|
|
1173
|
+
interface APIOptions {
|
|
1174
|
+
/** Custom storage adapter (defaults to LocalStorageAdapter) */
|
|
1175
|
+
storage?: StorageAdapter;
|
|
1176
|
+
/** Retry configuration for failed requests */
|
|
1177
|
+
retryConfig?: RetryConfig;
|
|
1178
|
+
/** Logger configuration */
|
|
1179
|
+
loggerConfig?: Partial<LoggerConfig>;
|
|
1180
|
+
}
|
|
1181
|
+
declare class API {
|
|
1182
|
+
private baseUrl;
|
|
1183
|
+
private _client;
|
|
1184
|
+
private _token;
|
|
1185
|
+
private _refreshToken;
|
|
1186
|
+
private storage;
|
|
1187
|
+
private options?;
|
|
1188
|
+
ext_payments_payments: ExtPaymentsPayments;
|
|
1189
|
+
constructor(baseUrl: string, options?: APIOptions);
|
|
1190
|
+
private _loadTokensFromStorage;
|
|
1191
|
+
private _reinitClients;
|
|
1192
|
+
private _injectAuthHeader;
|
|
1193
|
+
/**
|
|
1194
|
+
* Get current JWT token
|
|
1195
|
+
*/
|
|
1196
|
+
getToken(): string | null;
|
|
1197
|
+
/**
|
|
1198
|
+
* Get current refresh token
|
|
1199
|
+
*/
|
|
1200
|
+
getRefreshToken(): string | null;
|
|
1201
|
+
/**
|
|
1202
|
+
* Set JWT token and refresh token
|
|
1203
|
+
* @param token - JWT access token
|
|
1204
|
+
* @param refreshToken - JWT refresh token (optional)
|
|
1205
|
+
*/
|
|
1206
|
+
setToken(token: string, refreshToken?: string): void;
|
|
1207
|
+
/**
|
|
1208
|
+
* Clear all tokens
|
|
1209
|
+
*/
|
|
1210
|
+
clearTokens(): void;
|
|
1211
|
+
/**
|
|
1212
|
+
* Check if user is authenticated
|
|
1213
|
+
*/
|
|
1214
|
+
isAuthenticated(): boolean;
|
|
1215
|
+
/**
|
|
1216
|
+
* Update base URL and reinitialize clients
|
|
1217
|
+
* @param url - New base URL
|
|
1218
|
+
*/
|
|
1219
|
+
setBaseUrl(url: string): void;
|
|
1220
|
+
/**
|
|
1221
|
+
* Get current base URL
|
|
1222
|
+
*/
|
|
1223
|
+
getBaseUrl(): string;
|
|
1224
|
+
/**
|
|
1225
|
+
* Get OpenAPI schema path
|
|
1226
|
+
* @returns Path to the OpenAPI schema JSON file
|
|
1227
|
+
*
|
|
1228
|
+
* Note: The OpenAPI schema is available in the schema.json file.
|
|
1229
|
+
* You can load it dynamically using:
|
|
1230
|
+
* ```typescript
|
|
1231
|
+
* const schema = await fetch('./schema.json').then(r => r.json());
|
|
1232
|
+
* // or using fs in Node.js:
|
|
1233
|
+
* // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
|
|
1234
|
+
* ```
|
|
1235
|
+
*/
|
|
1236
|
+
getSchemaPath(): string;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
/**
|
|
1240
|
+
* Payments Extension API
|
|
1241
|
+
*
|
|
1242
|
+
* Pre-configured API instance with shared authentication
|
|
1243
|
+
*/
|
|
1244
|
+
|
|
1245
|
+
declare const apiPayments: API;
|
|
1246
|
+
|
|
1247
|
+
/**
|
|
1248
|
+
* Payments Layout (v2.0 - Simplified)
|
|
1249
|
+
*
|
|
1250
|
+
* Simplified layout with 3 tabs: Overview, Payments, Transactions
|
|
1251
|
+
* Removed: API Keys, Tariffs (deprecated in v2.0)
|
|
1252
|
+
*/
|
|
1253
|
+
|
|
1254
|
+
interface PaymentsLayoutProps {
|
|
1255
|
+
children?: React.ReactNode;
|
|
1256
|
+
}
|
|
1257
|
+
declare const PaymentsLayout: React.FC<PaymentsLayoutProps>;
|
|
1258
|
+
|
|
1259
|
+
/**
|
|
1260
|
+
* Payments Layout Types (v2.0 - Simplified)
|
|
1261
|
+
*/
|
|
1262
|
+
type PaymentTab = 'overview' | 'payments' | 'transactions';
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Payment Events System (v2.0 - Simplified)
|
|
1266
|
+
*
|
|
1267
|
+
* Event-based communication for dialogs using DOM events
|
|
1268
|
+
* Removed: API Keys events (deprecated)
|
|
1269
|
+
*/
|
|
1270
|
+
declare const PAYMENT_EVENTS: {
|
|
1271
|
+
readonly OPEN_CREATE_PAYMENT_DIALOG: "payments:open-create-payment";
|
|
1272
|
+
readonly OPEN_PAYMENT_DETAILS_DIALOG: "payments:open-payment-details";
|
|
1273
|
+
readonly CLOSE_DIALOG: "payments:close-dialog";
|
|
1274
|
+
};
|
|
1275
|
+
type PaymentEvent = {
|
|
1276
|
+
type: 'OPEN_CREATE_PAYMENT';
|
|
1277
|
+
} | {
|
|
1278
|
+
type: 'OPEN_PAYMENT_DETAILS';
|
|
1279
|
+
id: string;
|
|
1280
|
+
} | {
|
|
1281
|
+
type: 'CLOSE_DIALOG';
|
|
1282
|
+
};
|
|
1283
|
+
declare const openCreatePaymentDialog: () => void;
|
|
1284
|
+
declare const openPaymentDetailsDialog: (id: string) => void;
|
|
1285
|
+
declare const closePaymentsDialog: () => void;
|
|
1286
|
+
|
|
1287
|
+
export { API, APIClient, APIError, APILogger, type APIOptions, type Balance, BalanceSchema, CookieStorageAdapter, type Currency, CurrencySchema, DEFAULT_RETRY_CONFIG, enums as Enums, type ErrorLog, models as ExtPaymentsPaymentsTypes, type FailedAttemptInfo, FetchAdapter, index as Fetchers, type HttpClientAdapter, type HttpRequest, type HttpResponse, LocalStorageAdapter, type LoggerConfig, MemoryStorageAdapter, NetworkError, PAYMENT_EVENTS, type PaginatedPaymentListList, PaginatedPaymentListListSchema, type PaymentDetail, PaymentDetailSchema, type PaymentEvent, type PaymentList, PaymentListSchema, type PaymentTab, PaymentsLayout, type PaymentsLayoutProps, REFRESH_TOKEN_KEY, type RequestLog, type ResponseLog, type RetryConfig, index$1 as Schemas, type StorageAdapter, TOKEN_KEY, type Transaction, TransactionSchema, type ValidationErrorDetail, type ValidationErrorEvent, apiPayments, clearAPITokens, closePaymentsDialog, configureAPI, createPaymentsPaymentsConfirmCreate, createPaymentsPaymentsCreateCreate, dispatchValidationError, formatZodError, getAPIInstance, getPaymentsBalanceRetrieve, getPaymentsCurrenciesList, getPaymentsPaymentsList, getPaymentsPaymentsRetrieve, getPaymentsPaymentsStatusRetrieve, getPaymentsTransactionsList, isAPIConfigured, onValidationError, openCreatePaymentDialog, openPaymentDetailsDialog, reconfigureAPI, resetAPI, shouldRetry, withRetry };
|