@djangocfg/ext-payments 1.0.19 → 1.0.21

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,1701 @@
1
+ 'use strict';
2
+
3
+ var useSWR = require('swr');
4
+ var consola = require('consola');
5
+ var zod = require('zod');
6
+ var pRetry = require('p-retry');
7
+
8
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
+
10
+ var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
11
+ var pRetry__default = /*#__PURE__*/_interopDefault(pRetry);
12
+
13
+ var BalanceSchema = zod.z.object({
14
+ balance_usd: zod.z.string(),
15
+ balance_display: zod.z.string(),
16
+ total_deposited: zod.z.string(),
17
+ total_withdrawn: zod.z.string(),
18
+ last_transaction_at: zod.z.string().datetime({ offset: true }).nullable()
19
+ });
20
+
21
+ // src/api/generated/ext_payments/enums.ts
22
+ var PaymentDetailStatus = /* @__PURE__ */ ((PaymentDetailStatus2) => {
23
+ PaymentDetailStatus2["PENDING"] = "pending";
24
+ PaymentDetailStatus2["CONFIRMING"] = "confirming";
25
+ PaymentDetailStatus2["CONFIRMED"] = "confirmed";
26
+ PaymentDetailStatus2["COMPLETED"] = "completed";
27
+ PaymentDetailStatus2["PARTIALLY_PAID"] = "partially_paid";
28
+ PaymentDetailStatus2["FAILED"] = "failed";
29
+ PaymentDetailStatus2["EXPIRED"] = "expired";
30
+ PaymentDetailStatus2["CANCELLED"] = "cancelled";
31
+ return PaymentDetailStatus2;
32
+ })(PaymentDetailStatus || {});
33
+ var PaymentListStatus = /* @__PURE__ */ ((PaymentListStatus2) => {
34
+ PaymentListStatus2["PENDING"] = "pending";
35
+ PaymentListStatus2["CONFIRMING"] = "confirming";
36
+ PaymentListStatus2["CONFIRMED"] = "confirmed";
37
+ PaymentListStatus2["COMPLETED"] = "completed";
38
+ PaymentListStatus2["PARTIALLY_PAID"] = "partially_paid";
39
+ PaymentListStatus2["FAILED"] = "failed";
40
+ PaymentListStatus2["EXPIRED"] = "expired";
41
+ PaymentListStatus2["CANCELLED"] = "cancelled";
42
+ return PaymentListStatus2;
43
+ })(PaymentListStatus || {});
44
+ var TransactionTransactionType = /* @__PURE__ */ ((TransactionTransactionType2) => {
45
+ TransactionTransactionType2["DEPOSIT"] = "deposit";
46
+ TransactionTransactionType2["WITHDRAWAL"] = "withdrawal";
47
+ TransactionTransactionType2["PAYMENT"] = "payment";
48
+ TransactionTransactionType2["REFUND"] = "refund";
49
+ TransactionTransactionType2["FEE"] = "fee";
50
+ TransactionTransactionType2["BONUS"] = "bonus";
51
+ TransactionTransactionType2["ADJUSTMENT"] = "adjustment";
52
+ return TransactionTransactionType2;
53
+ })(TransactionTransactionType || {});
54
+ var WithdrawalDetailStatus = /* @__PURE__ */ ((WithdrawalDetailStatus2) => {
55
+ WithdrawalDetailStatus2["PENDING"] = "pending";
56
+ WithdrawalDetailStatus2["APPROVED"] = "approved";
57
+ WithdrawalDetailStatus2["PROCESSING"] = "processing";
58
+ WithdrawalDetailStatus2["COMPLETED"] = "completed";
59
+ WithdrawalDetailStatus2["REJECTED"] = "rejected";
60
+ WithdrawalDetailStatus2["CANCELLED"] = "cancelled";
61
+ return WithdrawalDetailStatus2;
62
+ })(WithdrawalDetailStatus || {});
63
+ var WithdrawalListStatus = /* @__PURE__ */ ((WithdrawalListStatus2) => {
64
+ WithdrawalListStatus2["PENDING"] = "pending";
65
+ WithdrawalListStatus2["APPROVED"] = "approved";
66
+ WithdrawalListStatus2["PROCESSING"] = "processing";
67
+ WithdrawalListStatus2["COMPLETED"] = "completed";
68
+ WithdrawalListStatus2["REJECTED"] = "rejected";
69
+ WithdrawalListStatus2["CANCELLED"] = "cancelled";
70
+ return WithdrawalListStatus2;
71
+ })(WithdrawalListStatus || {});
72
+
73
+ // src/api/generated/ext_payments/_utils/schemas/PaymentList.schema.ts
74
+ var PaymentListSchema = zod.z.object({
75
+ id: zod.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
76
+ internal_payment_id: zod.z.string(),
77
+ amount_usd: zod.z.string(),
78
+ currency_code: zod.z.string(),
79
+ currency_token: zod.z.string(),
80
+ status: zod.z.nativeEnum(PaymentListStatus),
81
+ status_display: zod.z.string(),
82
+ created_at: zod.z.string().datetime({ offset: true }),
83
+ completed_at: zod.z.string().datetime({ offset: true }).nullable()
84
+ });
85
+
86
+ // src/api/generated/ext_payments/_utils/schemas/PaginatedPaymentListList.schema.ts
87
+ var PaginatedPaymentListListSchema = zod.z.object({
88
+ count: zod.z.int(),
89
+ page: zod.z.int(),
90
+ pages: zod.z.int(),
91
+ page_size: zod.z.int(),
92
+ has_next: zod.z.boolean(),
93
+ has_previous: zod.z.boolean(),
94
+ next_page: zod.z.int().nullable().optional(),
95
+ previous_page: zod.z.int().nullable().optional(),
96
+ results: zod.z.array(PaymentListSchema)
97
+ });
98
+ var WithdrawalListSchema = zod.z.object({
99
+ id: zod.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
100
+ internal_withdrawal_id: zod.z.string(),
101
+ amount_usd: zod.z.string(),
102
+ final_amount_usd: zod.z.string(),
103
+ currency_code: zod.z.string(),
104
+ currency_token: zod.z.string(),
105
+ status: zod.z.nativeEnum(WithdrawalListStatus),
106
+ status_display: zod.z.string(),
107
+ created_at: zod.z.string().datetime({ offset: true }),
108
+ completed_at: zod.z.string().datetime({ offset: true }).nullable()
109
+ });
110
+
111
+ // src/api/generated/ext_payments/_utils/schemas/PaginatedWithdrawalListList.schema.ts
112
+ var PaginatedWithdrawalListListSchema = zod.z.object({
113
+ count: zod.z.int(),
114
+ page: zod.z.int(),
115
+ pages: zod.z.int(),
116
+ page_size: zod.z.int(),
117
+ has_next: zod.z.boolean(),
118
+ has_previous: zod.z.boolean(),
119
+ next_page: zod.z.int().nullable().optional(),
120
+ previous_page: zod.z.int().nullable().optional(),
121
+ results: zod.z.array(WithdrawalListSchema)
122
+ });
123
+ var PaymentDetailSchema = zod.z.object({
124
+ id: zod.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
125
+ internal_payment_id: zod.z.string(),
126
+ amount_usd: zod.z.string(),
127
+ currency_code: zod.z.string(),
128
+ currency_name: zod.z.string(),
129
+ currency_token: zod.z.string(),
130
+ currency_network: zod.z.string(),
131
+ pay_amount: zod.z.string().nullable(),
132
+ actual_amount: zod.z.string().nullable(),
133
+ actual_amount_usd: zod.z.string().nullable(),
134
+ status: zod.z.nativeEnum(PaymentDetailStatus),
135
+ status_display: zod.z.string(),
136
+ pay_address: zod.z.string().nullable(),
137
+ qr_code_url: zod.z.string().nullable(),
138
+ payment_url: zod.z.union([zod.z.url(), zod.z.literal("")]).nullable(),
139
+ transaction_hash: zod.z.string().nullable(),
140
+ explorer_link: zod.z.string().nullable(),
141
+ confirmations_count: zod.z.int(),
142
+ expires_at: zod.z.string().datetime({ offset: true }).nullable(),
143
+ completed_at: zod.z.string().datetime({ offset: true }).nullable(),
144
+ created_at: zod.z.string().datetime({ offset: true }),
145
+ is_completed: zod.z.boolean(),
146
+ is_failed: zod.z.boolean(),
147
+ is_expired: zod.z.boolean(),
148
+ description: zod.z.string()
149
+ });
150
+
151
+ // src/api/generated/ext_payments/_utils/schemas/PaymentCreateResponse.schema.ts
152
+ var PaymentCreateResponseSchema = zod.z.object({
153
+ success: zod.z.boolean(),
154
+ payment: PaymentDetailSchema,
155
+ qr_code_url: zod.z.union([zod.z.url(), zod.z.literal("")]).nullable()
156
+ });
157
+ var WithdrawalDetailSchema = zod.z.object({
158
+ id: zod.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
159
+ internal_withdrawal_id: zod.z.string(),
160
+ amount_usd: zod.z.string(),
161
+ currency_code: zod.z.string(),
162
+ currency_name: zod.z.string(),
163
+ currency_token: zod.z.string(),
164
+ currency_network: zod.z.string(),
165
+ wallet_address: zod.z.string(),
166
+ network_fee_usd: zod.z.string(),
167
+ service_fee_usd: zod.z.string(),
168
+ total_fee_usd: zod.z.string(),
169
+ final_amount_usd: zod.z.string(),
170
+ crypto_amount: zod.z.string().nullable(),
171
+ status: zod.z.nativeEnum(WithdrawalDetailStatus),
172
+ status_display: zod.z.string(),
173
+ transaction_hash: zod.z.string().nullable(),
174
+ explorer_link: zod.z.string().nullable(),
175
+ admin_notes: zod.z.string(),
176
+ created_at: zod.z.string().datetime({ offset: true }),
177
+ approved_at: zod.z.string().datetime({ offset: true }).nullable(),
178
+ completed_at: zod.z.string().datetime({ offset: true }).nullable(),
179
+ rejected_at: zod.z.string().datetime({ offset: true }).nullable(),
180
+ cancelled_at: zod.z.string().datetime({ offset: true }).nullable()
181
+ });
182
+
183
+ // src/api/generated/ext_payments/_utils/schemas/WithdrawalCancelResponse.schema.ts
184
+ var WithdrawalCancelResponseSchema = zod.z.object({
185
+ success: zod.z.boolean(),
186
+ withdrawal: WithdrawalDetailSchema,
187
+ message: zod.z.string()
188
+ });
189
+ var WithdrawalCreateResponseSchema = zod.z.object({
190
+ success: zod.z.boolean(),
191
+ withdrawal: WithdrawalDetailSchema,
192
+ message: zod.z.string()
193
+ });
194
+
195
+ // src/api/generated/ext_payments/ext_payments__payments/client.ts
196
+ var ExtPaymentsPayments = class {
197
+ client;
198
+ constructor(client) {
199
+ this.client = client;
200
+ }
201
+ /**
202
+ * Get user balance
203
+ *
204
+ * Get current user balance and transaction statistics
205
+ */
206
+ async balanceRetrieve() {
207
+ const response = await this.client.request("GET", "/cfg/payments/balance/");
208
+ return response;
209
+ }
210
+ /**
211
+ * Get available currencies
212
+ *
213
+ * Returns list of available currencies with token+network info, popular
214
+ * first
215
+ */
216
+ async currenciesList() {
217
+ const response = await this.client.request("GET", "/cfg/payments/currencies/");
218
+ return response;
219
+ }
220
+ /**
221
+ * Get currency estimate
222
+ *
223
+ * Get estimated crypto amount for a given USD amount, including min amount
224
+ */
225
+ async currenciesEstimateRetrieve(...args) {
226
+ const code = args[0];
227
+ const isParamsObject = args.length === 2 && typeof args[1] === "object" && args[1] !== null && !Array.isArray(args[1]);
228
+ let params;
229
+ if (isParamsObject) {
230
+ params = args[1];
231
+ } else {
232
+ params = { amount: args[1] };
233
+ }
234
+ const response = await this.client.request("GET", `/cfg/payments/currencies/${code}/estimate/`, { params });
235
+ return response;
236
+ }
237
+ /**
238
+ * Get withdrawal estimate
239
+ *
240
+ * Get estimated crypto amount for withdrawal with fee breakdown
241
+ */
242
+ async currenciesWithdrawalEstimateRetrieve(...args) {
243
+ const code = args[0];
244
+ const isParamsObject = args.length === 2 && typeof args[1] === "object" && args[1] !== null && !Array.isArray(args[1]);
245
+ let params;
246
+ if (isParamsObject) {
247
+ params = args[1];
248
+ } else {
249
+ params = { amount: args[1] };
250
+ }
251
+ const response = await this.client.request("GET", `/cfg/payments/currencies/${code}/withdrawal-estimate/`, { params });
252
+ return response;
253
+ }
254
+ /**
255
+ * ViewSet for payment operations. Endpoints: - GET /payments/ - List
256
+ * user's payments - GET /payments/{id}/ - Get payment details - POST
257
+ * /payments/create/ - Create new payment - GET /payments/{id}/status/ -
258
+ * Check payment status - POST /payments/{id}/confirm/ - Confirm payment
259
+ */
260
+ async paymentsList(...args) {
261
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
262
+ let params;
263
+ if (isParamsObject) {
264
+ params = args[0];
265
+ } else {
266
+ params = { page: args[0], page_size: args[1] };
267
+ }
268
+ const response = await this.client.request("GET", "/cfg/payments/payments/", { params });
269
+ return response;
270
+ }
271
+ /**
272
+ * ViewSet for payment operations. Endpoints: - GET /payments/ - List
273
+ * user's payments - GET /payments/{id}/ - Get payment details - POST
274
+ * /payments/create/ - Create new payment - GET /payments/{id}/status/ -
275
+ * Check payment status - POST /payments/{id}/confirm/ - Confirm payment
276
+ */
277
+ async paymentsRetrieve(id) {
278
+ const response = await this.client.request("GET", `/cfg/payments/payments/${id}/`);
279
+ return response;
280
+ }
281
+ /**
282
+ * POST /api/v1/payments/{id}/confirm/ Confirm payment (user clicked "I
283
+ * have paid"). Checks status with provider and creates transaction if
284
+ * completed.
285
+ */
286
+ async paymentsConfirmCreate(id) {
287
+ const response = await this.client.request("POST", `/cfg/payments/payments/${id}/confirm/`);
288
+ return response;
289
+ }
290
+ /**
291
+ * GET /api/v1/payments/{id}/status/?refresh=true Check payment status
292
+ * (with optional refresh from provider). Query params: - refresh: boolean
293
+ * (default: false) - Force refresh from provider
294
+ */
295
+ async paymentsStatusRetrieve(id) {
296
+ const response = await this.client.request("GET", `/cfg/payments/payments/${id}/status/`);
297
+ return response.results || response;
298
+ }
299
+ /**
300
+ * Create payment
301
+ *
302
+ * Create a new payment with specified amount and currency
303
+ */
304
+ async paymentsCreateCreate(data) {
305
+ const response = await this.client.request("POST", "/cfg/payments/payments/create/", { body: data });
306
+ return response;
307
+ }
308
+ /**
309
+ * Get user transactions
310
+ *
311
+ * Get user transactions with pagination and filtering
312
+ */
313
+ async transactionsList(...args) {
314
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
315
+ let params;
316
+ if (isParamsObject) {
317
+ params = args[0];
318
+ } else {
319
+ params = { limit: args[0], offset: args[1], type: args[2] };
320
+ }
321
+ const response = await this.client.request("GET", "/cfg/payments/transactions/", { params });
322
+ return response;
323
+ }
324
+ /**
325
+ * ViewSet for withdrawal operations. Endpoints: - GET /withdrawals/ - List
326
+ * user's withdrawal requests - GET /withdrawals/{id}/ - Get withdrawal
327
+ * details - POST /withdrawals/create/ - Create withdrawal request - POST
328
+ * /withdrawals/{id}/cancel/ - Cancel pending withdrawal
329
+ */
330
+ async withdrawalsList(...args) {
331
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
332
+ let params;
333
+ if (isParamsObject) {
334
+ params = args[0];
335
+ } else {
336
+ params = { page: args[0], page_size: args[1] };
337
+ }
338
+ const response = await this.client.request("GET", "/cfg/payments/withdrawals/", { params });
339
+ return response;
340
+ }
341
+ /**
342
+ * ViewSet for withdrawal operations. Endpoints: - GET /withdrawals/ - List
343
+ * user's withdrawal requests - GET /withdrawals/{id}/ - Get withdrawal
344
+ * details - POST /withdrawals/create/ - Create withdrawal request - POST
345
+ * /withdrawals/{id}/cancel/ - Cancel pending withdrawal
346
+ */
347
+ async withdrawalsRetrieve(id) {
348
+ const response = await this.client.request("GET", `/cfg/payments/withdrawals/${id}/`);
349
+ return response;
350
+ }
351
+ /**
352
+ * Cancel withdrawal request
353
+ *
354
+ * Cancel a pending withdrawal request
355
+ */
356
+ async withdrawalsCancelCreate(id) {
357
+ const response = await this.client.request("POST", `/cfg/payments/withdrawals/${id}/cancel/`);
358
+ return response;
359
+ }
360
+ /**
361
+ * Create withdrawal request
362
+ *
363
+ * Create a new withdrawal request (requires admin approval)
364
+ */
365
+ async withdrawalsCreateCreate(data) {
366
+ const response = await this.client.request("POST", "/cfg/payments/withdrawals/create/", { body: data });
367
+ return response;
368
+ }
369
+ };
370
+
371
+ // src/api/generated/ext_payments/http.ts
372
+ var FetchAdapter = class {
373
+ async request(request) {
374
+ const { method, url, headers, body, params, formData, binaryBody } = request;
375
+ let finalUrl = url;
376
+ if (params) {
377
+ const searchParams = new URLSearchParams();
378
+ Object.entries(params).forEach(([key, value]) => {
379
+ if (value !== null && value !== void 0) {
380
+ searchParams.append(key, String(value));
381
+ }
382
+ });
383
+ const queryString = searchParams.toString();
384
+ if (queryString) {
385
+ finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
386
+ }
387
+ }
388
+ const finalHeaders = { ...headers };
389
+ let requestBody;
390
+ if (formData) {
391
+ requestBody = formData;
392
+ } else if (binaryBody) {
393
+ finalHeaders["Content-Type"] = "application/octet-stream";
394
+ requestBody = binaryBody;
395
+ } else if (body) {
396
+ finalHeaders["Content-Type"] = "application/json";
397
+ requestBody = JSON.stringify(body);
398
+ }
399
+ const response = await fetch(finalUrl, {
400
+ method,
401
+ headers: finalHeaders,
402
+ body: requestBody,
403
+ credentials: "include"
404
+ // Include Django session cookies
405
+ });
406
+ let data = null;
407
+ const contentType = response.headers.get("content-type");
408
+ if (response.status !== 204 && contentType?.includes("application/json")) {
409
+ data = await response.json();
410
+ } else if (response.status !== 204) {
411
+ data = await response.text();
412
+ }
413
+ const responseHeaders = {};
414
+ response.headers.forEach((value, key) => {
415
+ responseHeaders[key] = value;
416
+ });
417
+ return {
418
+ data,
419
+ status: response.status,
420
+ statusText: response.statusText,
421
+ headers: responseHeaders
422
+ };
423
+ }
424
+ };
425
+
426
+ // src/api/generated/ext_payments/errors.ts
427
+ var APIError = class extends Error {
428
+ constructor(statusCode, statusText, response, url, message) {
429
+ super(message || `HTTP ${statusCode}: ${statusText}`);
430
+ this.statusCode = statusCode;
431
+ this.statusText = statusText;
432
+ this.response = response;
433
+ this.url = url;
434
+ this.name = "APIError";
435
+ }
436
+ /**
437
+ * Get error details from response.
438
+ * DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
439
+ */
440
+ get details() {
441
+ if (typeof this.response === "object" && this.response !== null) {
442
+ return this.response;
443
+ }
444
+ return null;
445
+ }
446
+ /**
447
+ * Get field-specific validation errors from DRF.
448
+ * Returns: { "field_name": ["error1", "error2"], ... }
449
+ */
450
+ get fieldErrors() {
451
+ const details = this.details;
452
+ if (!details) return null;
453
+ const fieldErrors = {};
454
+ for (const [key, value] of Object.entries(details)) {
455
+ if (Array.isArray(value)) {
456
+ fieldErrors[key] = value;
457
+ }
458
+ }
459
+ return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
460
+ }
461
+ /**
462
+ * Get single error message from DRF.
463
+ * Checks for "detail", "message", or first field error.
464
+ */
465
+ get errorMessage() {
466
+ const details = this.details;
467
+ if (!details) return this.message;
468
+ if (details.detail) {
469
+ return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
470
+ }
471
+ if (details.message) {
472
+ return String(details.message);
473
+ }
474
+ const fieldErrors = this.fieldErrors;
475
+ if (fieldErrors) {
476
+ const firstField = Object.keys(fieldErrors)[0];
477
+ if (firstField) {
478
+ return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
479
+ }
480
+ }
481
+ return this.message;
482
+ }
483
+ // Helper methods for common HTTP status codes
484
+ get isValidationError() {
485
+ return this.statusCode === 400;
486
+ }
487
+ get isAuthError() {
488
+ return this.statusCode === 401;
489
+ }
490
+ get isPermissionError() {
491
+ return this.statusCode === 403;
492
+ }
493
+ get isNotFoundError() {
494
+ return this.statusCode === 404;
495
+ }
496
+ get isServerError() {
497
+ return this.statusCode >= 500 && this.statusCode < 600;
498
+ }
499
+ };
500
+ var NetworkError = class extends Error {
501
+ constructor(message, url, originalError) {
502
+ super(message);
503
+ this.url = url;
504
+ this.originalError = originalError;
505
+ this.name = "NetworkError";
506
+ }
507
+ };
508
+ var DEFAULT_CONFIG = {
509
+ enabled: process.env.NODE_ENV !== "production",
510
+ logRequests: true,
511
+ logResponses: true,
512
+ logErrors: true,
513
+ logBodies: true,
514
+ logHeaders: false
515
+ };
516
+ var SENSITIVE_HEADERS = [
517
+ "authorization",
518
+ "cookie",
519
+ "set-cookie",
520
+ "x-api-key",
521
+ "x-csrf-token"
522
+ ];
523
+ var APILogger = class {
524
+ config;
525
+ consola;
526
+ constructor(config = {}) {
527
+ this.config = { ...DEFAULT_CONFIG, ...config };
528
+ this.consola = config.consola || consola.createConsola({
529
+ level: this.config.enabled ? 4 : 0
530
+ });
531
+ }
532
+ /**
533
+ * Enable logging
534
+ */
535
+ enable() {
536
+ this.config.enabled = true;
537
+ }
538
+ /**
539
+ * Disable logging
540
+ */
541
+ disable() {
542
+ this.config.enabled = false;
543
+ }
544
+ /**
545
+ * Update configuration
546
+ */
547
+ setConfig(config) {
548
+ this.config = { ...this.config, ...config };
549
+ }
550
+ /**
551
+ * Filter sensitive headers
552
+ */
553
+ filterHeaders(headers) {
554
+ if (!headers) return {};
555
+ const filtered = {};
556
+ Object.keys(headers).forEach((key) => {
557
+ const lowerKey = key.toLowerCase();
558
+ if (SENSITIVE_HEADERS.includes(lowerKey)) {
559
+ filtered[key] = "***";
560
+ } else {
561
+ filtered[key] = headers[key] || "";
562
+ }
563
+ });
564
+ return filtered;
565
+ }
566
+ /**
567
+ * Log request
568
+ */
569
+ logRequest(request) {
570
+ if (!this.config.enabled || !this.config.logRequests) return;
571
+ const { method, url, headers, body } = request;
572
+ this.consola.start(`${method} ${url}`);
573
+ if (this.config.logHeaders && headers) {
574
+ this.consola.debug("Headers:", this.filterHeaders(headers));
575
+ }
576
+ if (this.config.logBodies && body) {
577
+ this.consola.debug("Body:", body);
578
+ }
579
+ }
580
+ /**
581
+ * Log response
582
+ */
583
+ logResponse(request, response) {
584
+ if (!this.config.enabled || !this.config.logResponses) return;
585
+ const { method, url } = request;
586
+ const { status, statusText, data, duration } = response;
587
+ this.consola.success(
588
+ `${method} ${url} ${status} ${statusText} (${duration}ms)`
589
+ );
590
+ if (this.config.logBodies && data) {
591
+ this.consola.debug("Response:", data);
592
+ }
593
+ }
594
+ /**
595
+ * Log error
596
+ */
597
+ logError(request, error) {
598
+ if (!this.config.enabled || !this.config.logErrors) return;
599
+ const { method, url } = request;
600
+ const { message, statusCode, fieldErrors, duration } = error;
601
+ this.consola.error(
602
+ `${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
603
+ );
604
+ this.consola.error("Message:", message);
605
+ if (fieldErrors && Object.keys(fieldErrors).length > 0) {
606
+ this.consola.error("Field Errors:");
607
+ Object.entries(fieldErrors).forEach(([field, errors]) => {
608
+ errors.forEach((err) => {
609
+ this.consola.error(` \u2022 ${field}: ${err}`);
610
+ });
611
+ });
612
+ }
613
+ }
614
+ /**
615
+ * Log general info
616
+ */
617
+ info(message, ...args) {
618
+ if (!this.config.enabled) return;
619
+ this.consola.info(message, ...args);
620
+ }
621
+ /**
622
+ * Log warning
623
+ */
624
+ warn(message, ...args) {
625
+ if (!this.config.enabled) return;
626
+ this.consola.warn(message, ...args);
627
+ }
628
+ /**
629
+ * Log error
630
+ */
631
+ error(message, ...args) {
632
+ if (!this.config.enabled) return;
633
+ this.consola.error(message, ...args);
634
+ }
635
+ /**
636
+ * Log debug
637
+ */
638
+ debug(message, ...args) {
639
+ if (!this.config.enabled) return;
640
+ this.consola.debug(message, ...args);
641
+ }
642
+ /**
643
+ * Log success
644
+ */
645
+ success(message, ...args) {
646
+ if (!this.config.enabled) return;
647
+ this.consola.success(message, ...args);
648
+ }
649
+ /**
650
+ * Create a sub-logger with prefix
651
+ */
652
+ withTag(tag) {
653
+ return this.consola.withTag(tag);
654
+ }
655
+ };
656
+ new APILogger();
657
+ var DEFAULT_RETRY_CONFIG = {
658
+ retries: 3,
659
+ factor: 2,
660
+ minTimeout: 1e3,
661
+ maxTimeout: 6e4,
662
+ randomize: true,
663
+ onFailedAttempt: () => {
664
+ }
665
+ };
666
+ function shouldRetry(error) {
667
+ if (error instanceof NetworkError) {
668
+ return true;
669
+ }
670
+ if (error instanceof APIError) {
671
+ const status = error.statusCode;
672
+ if (status >= 500 && status < 600) {
673
+ return true;
674
+ }
675
+ if (status === 429) {
676
+ return true;
677
+ }
678
+ return false;
679
+ }
680
+ return true;
681
+ }
682
+ async function withRetry(fn, config) {
683
+ const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
684
+ return pRetry__default.default(
685
+ async () => {
686
+ try {
687
+ return await fn();
688
+ } catch (error) {
689
+ if (!shouldRetry(error)) {
690
+ throw new pRetry.AbortError(error);
691
+ }
692
+ throw error;
693
+ }
694
+ },
695
+ {
696
+ retries: finalConfig.retries,
697
+ factor: finalConfig.factor,
698
+ minTimeout: finalConfig.minTimeout,
699
+ maxTimeout: finalConfig.maxTimeout,
700
+ randomize: finalConfig.randomize,
701
+ onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
702
+ const pRetryError = error;
703
+ finalConfig.onFailedAttempt({
704
+ error: pRetryError,
705
+ attemptNumber: pRetryError.attemptNumber,
706
+ retriesLeft: pRetryError.retriesLeft
707
+ });
708
+ } : void 0
709
+ }
710
+ );
711
+ }
712
+
713
+ // src/api/generated/ext_payments/client.ts
714
+ var APIClient = class {
715
+ baseUrl;
716
+ httpClient;
717
+ logger = null;
718
+ retryConfig = null;
719
+ tokenGetter = null;
720
+ // Sub-clients
721
+ ext_payments_payments;
722
+ constructor(baseUrl, options) {
723
+ this.baseUrl = baseUrl.replace(/\/$/, "");
724
+ this.httpClient = options?.httpClient || new FetchAdapter();
725
+ this.tokenGetter = options?.tokenGetter || null;
726
+ if (options?.loggerConfig !== void 0) {
727
+ this.logger = new APILogger(options.loggerConfig);
728
+ }
729
+ if (options?.retryConfig !== void 0) {
730
+ this.retryConfig = options.retryConfig;
731
+ }
732
+ this.ext_payments_payments = new ExtPaymentsPayments(this);
733
+ }
734
+ /**
735
+ * Get CSRF token from cookies (for SessionAuthentication).
736
+ *
737
+ * Returns null if cookie doesn't exist (JWT-only auth).
738
+ */
739
+ getCsrfToken() {
740
+ const name = "csrftoken";
741
+ const value = `; ${document.cookie}`;
742
+ const parts = value.split(`; ${name}=`);
743
+ if (parts.length === 2) {
744
+ return parts.pop()?.split(";").shift() || null;
745
+ }
746
+ return null;
747
+ }
748
+ /**
749
+ * Get the base URL for building streaming/download URLs.
750
+ */
751
+ getBaseUrl() {
752
+ return this.baseUrl;
753
+ }
754
+ /**
755
+ * Get JWT token for URL authentication (used in streaming endpoints).
756
+ * Returns null if no token getter is configured or no token is available.
757
+ */
758
+ getToken() {
759
+ return this.tokenGetter ? this.tokenGetter() : null;
760
+ }
761
+ /**
762
+ * Make HTTP request with Django CSRF and session handling.
763
+ * Automatically retries on network errors and 5xx server errors.
764
+ */
765
+ async request(method, path, options) {
766
+ if (this.retryConfig) {
767
+ return withRetry(() => this._makeRequest(method, path, options), {
768
+ ...this.retryConfig,
769
+ onFailedAttempt: (info) => {
770
+ if (this.logger) {
771
+ this.logger.warn(
772
+ `Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
773
+ );
774
+ }
775
+ this.retryConfig?.onFailedAttempt?.(info);
776
+ }
777
+ });
778
+ }
779
+ return this._makeRequest(method, path, options);
780
+ }
781
+ /**
782
+ * Internal request method (without retry wrapper).
783
+ * Used by request() method with optional retry logic.
784
+ */
785
+ async _makeRequest(method, path, options) {
786
+ const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
787
+ const startTime = Date.now();
788
+ const headers = {
789
+ ...options?.headers || {}
790
+ };
791
+ if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
792
+ headers["Content-Type"] = "application/json";
793
+ }
794
+ if (this.logger) {
795
+ this.logger.logRequest({
796
+ method,
797
+ url,
798
+ headers,
799
+ body: options?.formData || options?.body,
800
+ timestamp: startTime
801
+ });
802
+ }
803
+ try {
804
+ const response = await this.httpClient.request({
805
+ method,
806
+ url,
807
+ headers,
808
+ params: options?.params,
809
+ body: options?.body,
810
+ formData: options?.formData,
811
+ binaryBody: options?.binaryBody
812
+ });
813
+ const duration = Date.now() - startTime;
814
+ if (response.status >= 400) {
815
+ const error = new APIError(
816
+ response.status,
817
+ response.statusText,
818
+ response.data,
819
+ url
820
+ );
821
+ if (this.logger) {
822
+ this.logger.logError(
823
+ {
824
+ method,
825
+ url,
826
+ headers,
827
+ body: options?.formData || options?.body,
828
+ timestamp: startTime
829
+ },
830
+ {
831
+ message: error.message,
832
+ statusCode: response.status,
833
+ duration,
834
+ timestamp: Date.now()
835
+ }
836
+ );
837
+ }
838
+ throw error;
839
+ }
840
+ if (this.logger) {
841
+ this.logger.logResponse(
842
+ {
843
+ method,
844
+ url,
845
+ headers,
846
+ body: options?.formData || options?.body,
847
+ timestamp: startTime
848
+ },
849
+ {
850
+ status: response.status,
851
+ statusText: response.statusText,
852
+ data: response.data,
853
+ duration,
854
+ timestamp: Date.now()
855
+ }
856
+ );
857
+ }
858
+ return response.data;
859
+ } catch (error) {
860
+ const duration = Date.now() - startTime;
861
+ if (error instanceof APIError) {
862
+ throw error;
863
+ }
864
+ const isCORSError = error instanceof TypeError && (error.message.toLowerCase().includes("cors") || error.message.toLowerCase().includes("failed to fetch") || error.message.toLowerCase().includes("network request failed"));
865
+ if (this.logger) {
866
+ if (isCORSError) {
867
+ this.logger.error(`\u{1F6AB} CORS Error: ${method} ${url}`);
868
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
869
+ this.logger.error(` \u2192 Configure security_domains parameter on the server`);
870
+ } else {
871
+ this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
872
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
873
+ }
874
+ }
875
+ if (typeof window !== "undefined") {
876
+ try {
877
+ if (isCORSError) {
878
+ window.dispatchEvent(new CustomEvent("cors-error", {
879
+ detail: {
880
+ url,
881
+ method,
882
+ error: error instanceof Error ? error.message : String(error),
883
+ timestamp: /* @__PURE__ */ new Date()
884
+ },
885
+ bubbles: true,
886
+ cancelable: false
887
+ }));
888
+ } else {
889
+ window.dispatchEvent(new CustomEvent("network-error", {
890
+ detail: {
891
+ url,
892
+ method,
893
+ error: error instanceof Error ? error.message : String(error),
894
+ timestamp: /* @__PURE__ */ new Date()
895
+ },
896
+ bubbles: true,
897
+ cancelable: false
898
+ }));
899
+ }
900
+ } catch (eventError) {
901
+ }
902
+ }
903
+ const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
904
+ if (this.logger) {
905
+ this.logger.logError(
906
+ {
907
+ method,
908
+ url,
909
+ headers,
910
+ body: options?.formData || options?.body,
911
+ timestamp: startTime
912
+ },
913
+ {
914
+ message: networkError.message,
915
+ duration,
916
+ timestamp: Date.now()
917
+ }
918
+ );
919
+ }
920
+ throw networkError;
921
+ }
922
+ }
923
+ };
924
+
925
+ // src/api/generated/ext_payments/storage.ts
926
+ var LocalStorageAdapter = class {
927
+ logger;
928
+ constructor(logger) {
929
+ this.logger = logger;
930
+ }
931
+ getItem(key) {
932
+ try {
933
+ if (typeof window !== "undefined" && window.localStorage) {
934
+ const value = localStorage.getItem(key);
935
+ this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
936
+ return value;
937
+ }
938
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
939
+ } catch (error) {
940
+ this.logger?.error("LocalStorage.getItem failed:", error);
941
+ }
942
+ return null;
943
+ }
944
+ setItem(key, value) {
945
+ try {
946
+ if (typeof window !== "undefined" && window.localStorage) {
947
+ localStorage.setItem(key, value);
948
+ this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
949
+ } else {
950
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
951
+ }
952
+ } catch (error) {
953
+ this.logger?.error("LocalStorage.setItem failed:", error);
954
+ }
955
+ }
956
+ removeItem(key) {
957
+ try {
958
+ if (typeof window !== "undefined" && window.localStorage) {
959
+ localStorage.removeItem(key);
960
+ this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
961
+ } else {
962
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
963
+ }
964
+ } catch (error) {
965
+ this.logger?.error("LocalStorage.removeItem failed:", error);
966
+ }
967
+ }
968
+ };
969
+ zod.z.object({
970
+ code: zod.z.string(),
971
+ name: zod.z.string(),
972
+ token: zod.z.string(),
973
+ network: zod.z.string().nullable(),
974
+ display_name: zod.z.string(),
975
+ symbol: zod.z.string(),
976
+ decimal_places: zod.z.int(),
977
+ is_active: zod.z.boolean(),
978
+ min_amount_usd: zod.z.string(),
979
+ sort_order: zod.z.int()
980
+ });
981
+ zod.z.object({
982
+ amount_usd: zod.z.string(),
983
+ currency_code: zod.z.string().min(1).max(20),
984
+ description: zod.z.string().max(500).optional()
985
+ });
986
+ zod.z.object({
987
+ id: zod.z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
988
+ transaction_type: zod.z.nativeEnum(TransactionTransactionType),
989
+ type_display: zod.z.string(),
990
+ amount_usd: zod.z.string(),
991
+ amount_display: zod.z.string(),
992
+ balance_after: zod.z.string(),
993
+ payment_id: zod.z.string().nullable(),
994
+ description: zod.z.string(),
995
+ created_at: zod.z.string().datetime({ offset: true })
996
+ });
997
+ zod.z.object({
998
+ amount_usd: zod.z.string(),
999
+ currency_code: zod.z.string().min(1).max(20),
1000
+ wallet_address: zod.z.string().min(1).max(255)
1001
+ });
1002
+
1003
+ // src/api/generated/ext_payments/index.ts
1004
+ var TOKEN_KEY = "auth_token";
1005
+ var REFRESH_TOKEN_KEY = "refresh_token";
1006
+ var API = class {
1007
+ baseUrl;
1008
+ _client;
1009
+ _token = null;
1010
+ _refreshToken = null;
1011
+ storage;
1012
+ options;
1013
+ // Sub-clients
1014
+ ext_payments_payments;
1015
+ constructor(baseUrl, options) {
1016
+ this.baseUrl = baseUrl;
1017
+ this.options = options;
1018
+ const logger = options?.loggerConfig ? new APILogger(options.loggerConfig) : void 0;
1019
+ this.storage = options?.storage || new LocalStorageAdapter(logger);
1020
+ this._loadTokensFromStorage();
1021
+ this._client = new APIClient(this.baseUrl, {
1022
+ retryConfig: this.options?.retryConfig,
1023
+ loggerConfig: this.options?.loggerConfig,
1024
+ tokenGetter: () => this.getToken()
1025
+ });
1026
+ this._injectAuthHeader();
1027
+ this.ext_payments_payments = this._client.ext_payments_payments;
1028
+ }
1029
+ _loadTokensFromStorage() {
1030
+ this._token = this.storage.getItem(TOKEN_KEY);
1031
+ this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
1032
+ }
1033
+ _reinitClients() {
1034
+ this._client = new APIClient(this.baseUrl, {
1035
+ retryConfig: this.options?.retryConfig,
1036
+ loggerConfig: this.options?.loggerConfig,
1037
+ tokenGetter: () => this.getToken()
1038
+ });
1039
+ this._injectAuthHeader();
1040
+ this.ext_payments_payments = this._client.ext_payments_payments;
1041
+ }
1042
+ _injectAuthHeader() {
1043
+ const originalRequest = this._client.request.bind(this._client);
1044
+ this._client.request = async (method, path, options) => {
1045
+ const token = this.getToken();
1046
+ const mergedOptions = {
1047
+ ...options,
1048
+ headers: {
1049
+ ...options?.headers || {},
1050
+ ...token ? { "Authorization": `Bearer ${token}` } : {}
1051
+ }
1052
+ };
1053
+ return originalRequest(method, path, mergedOptions);
1054
+ };
1055
+ }
1056
+ /**
1057
+ * Get current JWT token
1058
+ */
1059
+ getToken() {
1060
+ return this.storage.getItem(TOKEN_KEY);
1061
+ }
1062
+ /**
1063
+ * Get current refresh token
1064
+ */
1065
+ getRefreshToken() {
1066
+ return this.storage.getItem(REFRESH_TOKEN_KEY);
1067
+ }
1068
+ /**
1069
+ * Set JWT token and refresh token
1070
+ * @param token - JWT access token
1071
+ * @param refreshToken - JWT refresh token (optional)
1072
+ */
1073
+ setToken(token, refreshToken) {
1074
+ this._token = token;
1075
+ this.storage.setItem(TOKEN_KEY, token);
1076
+ if (refreshToken) {
1077
+ this._refreshToken = refreshToken;
1078
+ this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
1079
+ }
1080
+ this._reinitClients();
1081
+ }
1082
+ /**
1083
+ * Clear all tokens
1084
+ */
1085
+ clearTokens() {
1086
+ this._token = null;
1087
+ this._refreshToken = null;
1088
+ this.storage.removeItem(TOKEN_KEY);
1089
+ this.storage.removeItem(REFRESH_TOKEN_KEY);
1090
+ this._reinitClients();
1091
+ }
1092
+ /**
1093
+ * Check if user is authenticated
1094
+ */
1095
+ isAuthenticated() {
1096
+ return !!this.getToken();
1097
+ }
1098
+ /**
1099
+ * Update base URL and reinitialize clients
1100
+ * @param url - New base URL
1101
+ */
1102
+ setBaseUrl(url) {
1103
+ this.baseUrl = url;
1104
+ this._reinitClients();
1105
+ }
1106
+ /**
1107
+ * Get current base URL
1108
+ */
1109
+ getBaseUrl() {
1110
+ return this.baseUrl;
1111
+ }
1112
+ /**
1113
+ * Get OpenAPI schema path
1114
+ * @returns Path to the OpenAPI schema JSON file
1115
+ *
1116
+ * Note: The OpenAPI schema is available in the schema.json file.
1117
+ * You can load it dynamically using:
1118
+ * ```typescript
1119
+ * const schema = await fetch('./schema.json').then(r => r.json());
1120
+ * // or using fs in Node.js:
1121
+ * // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
1122
+ * ```
1123
+ */
1124
+ getSchemaPath() {
1125
+ return "./schema.json";
1126
+ }
1127
+ };
1128
+
1129
+ // src/api/generated/ext_payments/api-instance.ts
1130
+ var globalAPI = null;
1131
+ var autoConfigAttempted = false;
1132
+ function tryAutoConfigureFromEnv() {
1133
+ if (autoConfigAttempted) return;
1134
+ autoConfigAttempted = true;
1135
+ if (globalAPI) return;
1136
+ if (typeof process === "undefined" || !process.env) return;
1137
+ const baseUrl = process.env.NEXT_PUBLIC_API_URL || process.env.VITE_API_URL || process.env.REACT_APP_API_URL || process.env.API_URL;
1138
+ if (baseUrl) {
1139
+ globalAPI = new API(baseUrl);
1140
+ }
1141
+ }
1142
+ function getAPIInstance() {
1143
+ tryAutoConfigureFromEnv();
1144
+ if (!globalAPI) {
1145
+ throw new Error(
1146
+ 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\nExample:\n import { configureAPI } from "./api-instance"\n configureAPI({ baseUrl: "https://api.example.com" })\n\nOr set environment variable: NEXT_PUBLIC_API_URL, VITE_API_URL, or REACT_APP_API_URL'
1147
+ );
1148
+ }
1149
+ return globalAPI;
1150
+ }
1151
+
1152
+ // src/api/generated/ext_payments/_utils/fetchers/ext_payments__payments.ts
1153
+ async function getPaymentsBalanceRetrieve(client) {
1154
+ const api = client || getAPIInstance();
1155
+ const response = await api.ext_payments_payments.balanceRetrieve();
1156
+ try {
1157
+ return BalanceSchema.parse(response);
1158
+ } catch (error) {
1159
+ consola.consola.error("\u274C Zod Validation Failed");
1160
+ consola.consola.box(`getPaymentsBalanceRetrieve
1161
+ Path: /cfg/payments/balance/
1162
+ Method: GET`);
1163
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1164
+ consola.consola.error("Validation Issues:");
1165
+ error.issues.forEach((issue, index) => {
1166
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1167
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1168
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1169
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1170
+ });
1171
+ }
1172
+ consola.consola.error("Response data:", response);
1173
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1174
+ try {
1175
+ const event = new CustomEvent("zod-validation-error", {
1176
+ detail: {
1177
+ operation: "getPaymentsBalanceRetrieve",
1178
+ path: "/cfg/payments/balance/",
1179
+ method: "GET",
1180
+ error,
1181
+ response,
1182
+ timestamp: /* @__PURE__ */ new Date()
1183
+ },
1184
+ bubbles: true,
1185
+ cancelable: false
1186
+ });
1187
+ window.dispatchEvent(event);
1188
+ } catch (eventError) {
1189
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1190
+ }
1191
+ }
1192
+ throw error;
1193
+ }
1194
+ }
1195
+ async function getPaymentsCurrenciesList(client) {
1196
+ const api = client || getAPIInstance();
1197
+ const response = await api.ext_payments_payments.currenciesList();
1198
+ return response;
1199
+ }
1200
+ async function getPaymentsCurrenciesEstimateRetrieve(code, params, client) {
1201
+ const api = client || getAPIInstance();
1202
+ const response = await api.ext_payments_payments.currenciesEstimateRetrieve(code, params?.amount);
1203
+ return response;
1204
+ }
1205
+ async function getPaymentsCurrenciesWithdrawalEstimateRetrieve(code, params, client) {
1206
+ const api = client || getAPIInstance();
1207
+ const response = await api.ext_payments_payments.currenciesWithdrawalEstimateRetrieve(code, params?.amount);
1208
+ return response;
1209
+ }
1210
+ async function getPaymentsPaymentsList(params, client) {
1211
+ const api = client || getAPIInstance();
1212
+ const response = await api.ext_payments_payments.paymentsList(params?.page, params?.page_size);
1213
+ try {
1214
+ return PaginatedPaymentListListSchema.parse(response);
1215
+ } catch (error) {
1216
+ consola.consola.error("\u274C Zod Validation Failed");
1217
+ consola.consola.box(`getPaymentsPaymentsList
1218
+ Path: /cfg/payments/payments/
1219
+ Method: GET`);
1220
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1221
+ consola.consola.error("Validation Issues:");
1222
+ error.issues.forEach((issue, index) => {
1223
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1224
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1225
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1226
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1227
+ });
1228
+ }
1229
+ consola.consola.error("Response data:", response);
1230
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1231
+ try {
1232
+ const event = new CustomEvent("zod-validation-error", {
1233
+ detail: {
1234
+ operation: "getPaymentsPaymentsList",
1235
+ path: "/cfg/payments/payments/",
1236
+ method: "GET",
1237
+ error,
1238
+ response,
1239
+ timestamp: /* @__PURE__ */ new Date()
1240
+ },
1241
+ bubbles: true,
1242
+ cancelable: false
1243
+ });
1244
+ window.dispatchEvent(event);
1245
+ } catch (eventError) {
1246
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1247
+ }
1248
+ }
1249
+ throw error;
1250
+ }
1251
+ }
1252
+ async function getPaymentsPaymentsRetrieve(id, client) {
1253
+ const api = client || getAPIInstance();
1254
+ const response = await api.ext_payments_payments.paymentsRetrieve(id);
1255
+ try {
1256
+ return PaymentDetailSchema.parse(response);
1257
+ } catch (error) {
1258
+ consola.consola.error("\u274C Zod Validation Failed");
1259
+ consola.consola.box(`getPaymentsPaymentsRetrieve
1260
+ Path: /cfg/payments/payments/{id}/
1261
+ Method: GET`);
1262
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1263
+ consola.consola.error("Validation Issues:");
1264
+ error.issues.forEach((issue, index) => {
1265
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1266
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1267
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1268
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1269
+ });
1270
+ }
1271
+ consola.consola.error("Response data:", response);
1272
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1273
+ try {
1274
+ const event = new CustomEvent("zod-validation-error", {
1275
+ detail: {
1276
+ operation: "getPaymentsPaymentsRetrieve",
1277
+ path: "/cfg/payments/payments/{id}/",
1278
+ method: "GET",
1279
+ error,
1280
+ response,
1281
+ timestamp: /* @__PURE__ */ new Date()
1282
+ },
1283
+ bubbles: true,
1284
+ cancelable: false
1285
+ });
1286
+ window.dispatchEvent(event);
1287
+ } catch (eventError) {
1288
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1289
+ }
1290
+ }
1291
+ throw error;
1292
+ }
1293
+ }
1294
+ async function createPaymentsPaymentsConfirmCreate(id, client) {
1295
+ const api = client || getAPIInstance();
1296
+ const response = await api.ext_payments_payments.paymentsConfirmCreate(id);
1297
+ try {
1298
+ return PaymentListSchema.parse(response);
1299
+ } catch (error) {
1300
+ consola.consola.error("\u274C Zod Validation Failed");
1301
+ consola.consola.box(`createPaymentsPaymentsConfirmCreate
1302
+ Path: /cfg/payments/payments/{id}/confirm/
1303
+ Method: POST`);
1304
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1305
+ consola.consola.error("Validation Issues:");
1306
+ error.issues.forEach((issue, index) => {
1307
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1308
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1309
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1310
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1311
+ });
1312
+ }
1313
+ consola.consola.error("Response data:", response);
1314
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1315
+ try {
1316
+ const event = new CustomEvent("zod-validation-error", {
1317
+ detail: {
1318
+ operation: "createPaymentsPaymentsConfirmCreate",
1319
+ path: "/cfg/payments/payments/{id}/confirm/",
1320
+ method: "POST",
1321
+ error,
1322
+ response,
1323
+ timestamp: /* @__PURE__ */ new Date()
1324
+ },
1325
+ bubbles: true,
1326
+ cancelable: false
1327
+ });
1328
+ window.dispatchEvent(event);
1329
+ } catch (eventError) {
1330
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1331
+ }
1332
+ }
1333
+ throw error;
1334
+ }
1335
+ }
1336
+ async function getPaymentsPaymentsStatusRetrieve(id, client) {
1337
+ const api = client || getAPIInstance();
1338
+ const response = await api.ext_payments_payments.paymentsStatusRetrieve(id);
1339
+ try {
1340
+ return PaymentListSchema.parse(response);
1341
+ } catch (error) {
1342
+ consola.consola.error("\u274C Zod Validation Failed");
1343
+ consola.consola.box(`getPaymentsPaymentsStatusRetrieve
1344
+ Path: /cfg/payments/payments/{id}/status/
1345
+ Method: GET`);
1346
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1347
+ consola.consola.error("Validation Issues:");
1348
+ error.issues.forEach((issue, index) => {
1349
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1350
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1351
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1352
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1353
+ });
1354
+ }
1355
+ consola.consola.error("Response data:", response);
1356
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1357
+ try {
1358
+ const event = new CustomEvent("zod-validation-error", {
1359
+ detail: {
1360
+ operation: "getPaymentsPaymentsStatusRetrieve",
1361
+ path: "/cfg/payments/payments/{id}/status/",
1362
+ method: "GET",
1363
+ error,
1364
+ response,
1365
+ timestamp: /* @__PURE__ */ new Date()
1366
+ },
1367
+ bubbles: true,
1368
+ cancelable: false
1369
+ });
1370
+ window.dispatchEvent(event);
1371
+ } catch (eventError) {
1372
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1373
+ }
1374
+ }
1375
+ throw error;
1376
+ }
1377
+ }
1378
+ async function createPaymentsPaymentsCreateCreate(data, client) {
1379
+ const api = client || getAPIInstance();
1380
+ const response = await api.ext_payments_payments.paymentsCreateCreate(data);
1381
+ try {
1382
+ return PaymentCreateResponseSchema.parse(response);
1383
+ } catch (error) {
1384
+ consola.consola.error("\u274C Zod Validation Failed");
1385
+ consola.consola.box(`createPaymentsPaymentsCreateCreate
1386
+ Path: /cfg/payments/payments/create/
1387
+ Method: POST`);
1388
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1389
+ consola.consola.error("Validation Issues:");
1390
+ error.issues.forEach((issue, index) => {
1391
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1392
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1393
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1394
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1395
+ });
1396
+ }
1397
+ consola.consola.error("Response data:", response);
1398
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1399
+ try {
1400
+ const event = new CustomEvent("zod-validation-error", {
1401
+ detail: {
1402
+ operation: "createPaymentsPaymentsCreateCreate",
1403
+ path: "/cfg/payments/payments/create/",
1404
+ method: "POST",
1405
+ error,
1406
+ response,
1407
+ timestamp: /* @__PURE__ */ new Date()
1408
+ },
1409
+ bubbles: true,
1410
+ cancelable: false
1411
+ });
1412
+ window.dispatchEvent(event);
1413
+ } catch (eventError) {
1414
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1415
+ }
1416
+ }
1417
+ throw error;
1418
+ }
1419
+ }
1420
+ async function getPaymentsTransactionsList(params, client) {
1421
+ const api = client || getAPIInstance();
1422
+ const response = await api.ext_payments_payments.transactionsList(params?.limit, params?.offset, params?.type);
1423
+ return response;
1424
+ }
1425
+ async function getPaymentsWithdrawalsList(params, client) {
1426
+ const api = client || getAPIInstance();
1427
+ const response = await api.ext_payments_payments.withdrawalsList(params?.page, params?.page_size);
1428
+ try {
1429
+ return PaginatedWithdrawalListListSchema.parse(response);
1430
+ } catch (error) {
1431
+ consola.consola.error("\u274C Zod Validation Failed");
1432
+ consola.consola.box(`getPaymentsWithdrawalsList
1433
+ Path: /cfg/payments/withdrawals/
1434
+ Method: GET`);
1435
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1436
+ consola.consola.error("Validation Issues:");
1437
+ error.issues.forEach((issue, index) => {
1438
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1439
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1440
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1441
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1442
+ });
1443
+ }
1444
+ consola.consola.error("Response data:", response);
1445
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1446
+ try {
1447
+ const event = new CustomEvent("zod-validation-error", {
1448
+ detail: {
1449
+ operation: "getPaymentsWithdrawalsList",
1450
+ path: "/cfg/payments/withdrawals/",
1451
+ method: "GET",
1452
+ error,
1453
+ response,
1454
+ timestamp: /* @__PURE__ */ new Date()
1455
+ },
1456
+ bubbles: true,
1457
+ cancelable: false
1458
+ });
1459
+ window.dispatchEvent(event);
1460
+ } catch (eventError) {
1461
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1462
+ }
1463
+ }
1464
+ throw error;
1465
+ }
1466
+ }
1467
+ async function getPaymentsWithdrawalsRetrieve(id, client) {
1468
+ const api = client || getAPIInstance();
1469
+ const response = await api.ext_payments_payments.withdrawalsRetrieve(id);
1470
+ try {
1471
+ return WithdrawalDetailSchema.parse(response);
1472
+ } catch (error) {
1473
+ consola.consola.error("\u274C Zod Validation Failed");
1474
+ consola.consola.box(`getPaymentsWithdrawalsRetrieve
1475
+ Path: /cfg/payments/withdrawals/{id}/
1476
+ Method: GET`);
1477
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1478
+ consola.consola.error("Validation Issues:");
1479
+ error.issues.forEach((issue, index) => {
1480
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1481
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1482
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1483
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1484
+ });
1485
+ }
1486
+ consola.consola.error("Response data:", response);
1487
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1488
+ try {
1489
+ const event = new CustomEvent("zod-validation-error", {
1490
+ detail: {
1491
+ operation: "getPaymentsWithdrawalsRetrieve",
1492
+ path: "/cfg/payments/withdrawals/{id}/",
1493
+ method: "GET",
1494
+ error,
1495
+ response,
1496
+ timestamp: /* @__PURE__ */ new Date()
1497
+ },
1498
+ bubbles: true,
1499
+ cancelable: false
1500
+ });
1501
+ window.dispatchEvent(event);
1502
+ } catch (eventError) {
1503
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1504
+ }
1505
+ }
1506
+ throw error;
1507
+ }
1508
+ }
1509
+ async function createPaymentsWithdrawalsCancelCreate(id, client) {
1510
+ const api = client || getAPIInstance();
1511
+ const response = await api.ext_payments_payments.withdrawalsCancelCreate(id);
1512
+ try {
1513
+ return WithdrawalCancelResponseSchema.parse(response);
1514
+ } catch (error) {
1515
+ consola.consola.error("\u274C Zod Validation Failed");
1516
+ consola.consola.box(`createPaymentsWithdrawalsCancelCreate
1517
+ Path: /cfg/payments/withdrawals/{id}/cancel/
1518
+ Method: POST`);
1519
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1520
+ consola.consola.error("Validation Issues:");
1521
+ error.issues.forEach((issue, index) => {
1522
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1523
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1524
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1525
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1526
+ });
1527
+ }
1528
+ consola.consola.error("Response data:", response);
1529
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1530
+ try {
1531
+ const event = new CustomEvent("zod-validation-error", {
1532
+ detail: {
1533
+ operation: "createPaymentsWithdrawalsCancelCreate",
1534
+ path: "/cfg/payments/withdrawals/{id}/cancel/",
1535
+ method: "POST",
1536
+ error,
1537
+ response,
1538
+ timestamp: /* @__PURE__ */ new Date()
1539
+ },
1540
+ bubbles: true,
1541
+ cancelable: false
1542
+ });
1543
+ window.dispatchEvent(event);
1544
+ } catch (eventError) {
1545
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1546
+ }
1547
+ }
1548
+ throw error;
1549
+ }
1550
+ }
1551
+ async function createPaymentsWithdrawalsCreateCreate(data, client) {
1552
+ const api = client || getAPIInstance();
1553
+ const response = await api.ext_payments_payments.withdrawalsCreateCreate(data);
1554
+ try {
1555
+ return WithdrawalCreateResponseSchema.parse(response);
1556
+ } catch (error) {
1557
+ consola.consola.error("\u274C Zod Validation Failed");
1558
+ consola.consola.box(`createPaymentsWithdrawalsCreateCreate
1559
+ Path: /cfg/payments/withdrawals/create/
1560
+ Method: POST`);
1561
+ if (error instanceof Error && "issues" in error && Array.isArray(error.issues)) {
1562
+ consola.consola.error("Validation Issues:");
1563
+ error.issues.forEach((issue, index) => {
1564
+ consola.consola.error(` ${index + 1}. ${issue.path.join(".") || "root"}`);
1565
+ consola.consola.error(` \u251C\u2500 Message: ${issue.message}`);
1566
+ if (issue.expected) consola.consola.error(` \u251C\u2500 Expected: ${issue.expected}`);
1567
+ if (issue.received) consola.consola.error(` \u2514\u2500 Received: ${issue.received}`);
1568
+ });
1569
+ }
1570
+ consola.consola.error("Response data:", response);
1571
+ if (typeof window !== "undefined" && error instanceof Error && "issues" in error) {
1572
+ try {
1573
+ const event = new CustomEvent("zod-validation-error", {
1574
+ detail: {
1575
+ operation: "createPaymentsWithdrawalsCreateCreate",
1576
+ path: "/cfg/payments/withdrawals/create/",
1577
+ method: "POST",
1578
+ error,
1579
+ response,
1580
+ timestamp: /* @__PURE__ */ new Date()
1581
+ },
1582
+ bubbles: true,
1583
+ cancelable: false
1584
+ });
1585
+ window.dispatchEvent(event);
1586
+ } catch (eventError) {
1587
+ consola.consola.warn("Failed to dispatch validation error event:", eventError);
1588
+ }
1589
+ }
1590
+ throw error;
1591
+ }
1592
+ }
1593
+
1594
+ // src/api/generated/ext_payments/_utils/hooks/ext_payments__payments.ts
1595
+ function usePaymentsBalanceRetrieve(client) {
1596
+ return useSWR__default.default(
1597
+ "cfg-payments-balance",
1598
+ () => getPaymentsBalanceRetrieve(client)
1599
+ );
1600
+ }
1601
+ function usePaymentsCurrenciesList(client) {
1602
+ return useSWR__default.default(
1603
+ "cfg-payments-currencies",
1604
+ () => getPaymentsCurrenciesList(client)
1605
+ );
1606
+ }
1607
+ function usePaymentsCurrenciesEstimateRetrieve(code, params, client) {
1608
+ return useSWR__default.default(
1609
+ ["cfg-payments-currencies-estimate", code],
1610
+ () => getPaymentsCurrenciesEstimateRetrieve(code, params, client)
1611
+ );
1612
+ }
1613
+ function usePaymentsCurrenciesWithdrawalEstimateRetrieve(code, params, client) {
1614
+ return useSWR__default.default(
1615
+ ["cfg-payments-currencies-withdrawal-estimate", code],
1616
+ () => getPaymentsCurrenciesWithdrawalEstimateRetrieve(code, params, client)
1617
+ );
1618
+ }
1619
+ function usePaymentsPaymentsList(params, client) {
1620
+ return useSWR__default.default(
1621
+ params ? ["cfg-payments-payments", params] : "cfg-payments-payments",
1622
+ () => getPaymentsPaymentsList(params, client)
1623
+ );
1624
+ }
1625
+ function usePaymentsPaymentsRetrieve(id, client) {
1626
+ return useSWR__default.default(
1627
+ ["cfg-payments-payment", id],
1628
+ () => getPaymentsPaymentsRetrieve(id, client)
1629
+ );
1630
+ }
1631
+ function useCreatePaymentsPaymentsConfirmCreate() {
1632
+ const { mutate } = useSWR.useSWRConfig();
1633
+ return async (id, client) => {
1634
+ const result = await createPaymentsPaymentsConfirmCreate(id, client);
1635
+ mutate("cfg-payments-payments-confirm");
1636
+ return result;
1637
+ };
1638
+ }
1639
+ function usePaymentsPaymentsStatusRetrieve(id, client) {
1640
+ return useSWR__default.default(
1641
+ ["cfg-payments-payments-statu", id],
1642
+ () => getPaymentsPaymentsStatusRetrieve(id, client)
1643
+ );
1644
+ }
1645
+ function useCreatePaymentsPaymentsCreateCreate() {
1646
+ const { mutate } = useSWR.useSWRConfig();
1647
+ return async (data, client) => {
1648
+ const result = await createPaymentsPaymentsCreateCreate(data, client);
1649
+ mutate("cfg-payments-payments");
1650
+ return result;
1651
+ };
1652
+ }
1653
+ function usePaymentsTransactionsList(params, client) {
1654
+ return useSWR__default.default(
1655
+ params ? ["cfg-payments-transactions", params] : "cfg-payments-transactions",
1656
+ () => getPaymentsTransactionsList(params, client)
1657
+ );
1658
+ }
1659
+ function usePaymentsWithdrawalsList(params, client) {
1660
+ return useSWR__default.default(
1661
+ params ? ["cfg-payments-withdrawals", params] : "cfg-payments-withdrawals",
1662
+ () => getPaymentsWithdrawalsList(params, client)
1663
+ );
1664
+ }
1665
+ function usePaymentsWithdrawalsRetrieve(id, client) {
1666
+ return useSWR__default.default(
1667
+ ["cfg-payments-withdrawal", id],
1668
+ () => getPaymentsWithdrawalsRetrieve(id, client)
1669
+ );
1670
+ }
1671
+ function useCreatePaymentsWithdrawalsCancelCreate() {
1672
+ const { mutate } = useSWR.useSWRConfig();
1673
+ return async (id, client) => {
1674
+ const result = await createPaymentsWithdrawalsCancelCreate(id, client);
1675
+ mutate("cfg-payments-withdrawals-cancel");
1676
+ return result;
1677
+ };
1678
+ }
1679
+ function useCreatePaymentsWithdrawalsCreateCreate() {
1680
+ const { mutate } = useSWR.useSWRConfig();
1681
+ return async (data, client) => {
1682
+ const result = await createPaymentsWithdrawalsCreateCreate(data, client);
1683
+ mutate("cfg-payments-withdrawals");
1684
+ return result;
1685
+ };
1686
+ }
1687
+
1688
+ exports.useCreatePaymentsPaymentsConfirmCreate = useCreatePaymentsPaymentsConfirmCreate;
1689
+ exports.useCreatePaymentsPaymentsCreateCreate = useCreatePaymentsPaymentsCreateCreate;
1690
+ exports.useCreatePaymentsWithdrawalsCancelCreate = useCreatePaymentsWithdrawalsCancelCreate;
1691
+ exports.useCreatePaymentsWithdrawalsCreateCreate = useCreatePaymentsWithdrawalsCreateCreate;
1692
+ exports.usePaymentsBalanceRetrieve = usePaymentsBalanceRetrieve;
1693
+ exports.usePaymentsCurrenciesEstimateRetrieve = usePaymentsCurrenciesEstimateRetrieve;
1694
+ exports.usePaymentsCurrenciesList = usePaymentsCurrenciesList;
1695
+ exports.usePaymentsCurrenciesWithdrawalEstimateRetrieve = usePaymentsCurrenciesWithdrawalEstimateRetrieve;
1696
+ exports.usePaymentsPaymentsList = usePaymentsPaymentsList;
1697
+ exports.usePaymentsPaymentsRetrieve = usePaymentsPaymentsRetrieve;
1698
+ exports.usePaymentsPaymentsStatusRetrieve = usePaymentsPaymentsStatusRetrieve;
1699
+ exports.usePaymentsTransactionsList = usePaymentsTransactionsList;
1700
+ exports.usePaymentsWithdrawalsList = usePaymentsWithdrawalsList;
1701
+ exports.usePaymentsWithdrawalsRetrieve = usePaymentsWithdrawalsRetrieve;