@sdkrouter/payments 0.1.2

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,1289 @@
1
+ "use client";
2
+ import { createConsola } from 'consola';
3
+ import pRetry, { AbortError } from 'p-retry';
4
+ import { z } from 'zod';
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
13
+
14
+ // src/_api/generated/payments/storage.ts
15
+ var LocalStorageAdapter = class {
16
+ constructor(logger) {
17
+ __publicField(this, "logger");
18
+ this.logger = logger;
19
+ }
20
+ getItem(key) {
21
+ try {
22
+ if (typeof window !== "undefined" && window.localStorage) {
23
+ const value = localStorage.getItem(key);
24
+ this.logger?.debug(`LocalStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
25
+ return value;
26
+ }
27
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
28
+ } catch (error) {
29
+ this.logger?.error("LocalStorage.getItem failed:", error);
30
+ }
31
+ return null;
32
+ }
33
+ setItem(key, value) {
34
+ try {
35
+ if (typeof window !== "undefined" && window.localStorage) {
36
+ localStorage.setItem(key, value);
37
+ this.logger?.debug(`LocalStorage.setItem("${key}"): success`);
38
+ } else {
39
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
40
+ }
41
+ } catch (error) {
42
+ this.logger?.error("LocalStorage.setItem failed:", error);
43
+ }
44
+ }
45
+ removeItem(key) {
46
+ try {
47
+ if (typeof window !== "undefined" && window.localStorage) {
48
+ localStorage.removeItem(key);
49
+ this.logger?.debug(`LocalStorage.removeItem("${key}"): success`);
50
+ } else {
51
+ this.logger?.warn("LocalStorage not available: window.localStorage is undefined");
52
+ }
53
+ } catch (error) {
54
+ this.logger?.error("LocalStorage.removeItem failed:", error);
55
+ }
56
+ }
57
+ };
58
+ var MemoryStorageAdapter = class {
59
+ constructor(logger) {
60
+ __publicField(this, "storage", /* @__PURE__ */ new Map());
61
+ __publicField(this, "logger");
62
+ this.logger = logger;
63
+ }
64
+ getItem(key) {
65
+ const value = this.storage.get(key) || null;
66
+ this.logger?.debug(`MemoryStorage.getItem("${key}"): ${value ? "found" : "not found"}`);
67
+ return value;
68
+ }
69
+ setItem(key, value) {
70
+ this.storage.set(key, value);
71
+ this.logger?.debug(`MemoryStorage.setItem("${key}"): success`);
72
+ }
73
+ removeItem(key) {
74
+ this.storage.delete(key);
75
+ this.logger?.debug(`MemoryStorage.removeItem("${key}"): success`);
76
+ }
77
+ };
78
+
79
+ // src/_api/generated/payments/enums.ts
80
+ var enums_exports = {};
81
+ __export(enums_exports, {
82
+ CustomerInvoiceDetailStatus: () => CustomerInvoiceDetailStatus,
83
+ CustomerTransactionResponseTransactionType: () => CustomerTransactionResponseTransactionType,
84
+ CustomerWithdrawalResponseStatus: () => CustomerWithdrawalResponseStatus
85
+ });
86
+ var CustomerInvoiceDetailStatus = /* @__PURE__ */ ((CustomerInvoiceDetailStatus2) => {
87
+ CustomerInvoiceDetailStatus2["CREATED"] = "created";
88
+ CustomerInvoiceDetailStatus2["WAITING"] = "waiting";
89
+ CustomerInvoiceDetailStatus2["PAID"] = "paid";
90
+ CustomerInvoiceDetailStatus2["EXPIRED"] = "expired";
91
+ CustomerInvoiceDetailStatus2["UNDERPAID"] = "underpaid";
92
+ CustomerInvoiceDetailStatus2["OVERPAID"] = "overpaid";
93
+ CustomerInvoiceDetailStatus2["CANCELLED"] = "cancelled";
94
+ return CustomerInvoiceDetailStatus2;
95
+ })(CustomerInvoiceDetailStatus || {});
96
+ var CustomerTransactionResponseTransactionType = /* @__PURE__ */ ((CustomerTransactionResponseTransactionType2) => {
97
+ CustomerTransactionResponseTransactionType2["DEPOSIT"] = "deposit";
98
+ CustomerTransactionResponseTransactionType2["WITHDRAWAL"] = "withdrawal";
99
+ CustomerTransactionResponseTransactionType2["REFUND"] = "refund";
100
+ CustomerTransactionResponseTransactionType2["FEE"] = "fee";
101
+ CustomerTransactionResponseTransactionType2["ADJUSTMENT"] = "adjustment";
102
+ return CustomerTransactionResponseTransactionType2;
103
+ })(CustomerTransactionResponseTransactionType || {});
104
+ var CustomerWithdrawalResponseStatus = /* @__PURE__ */ ((CustomerWithdrawalResponseStatus2) => {
105
+ CustomerWithdrawalResponseStatus2["PENDING"] = "pending";
106
+ CustomerWithdrawalResponseStatus2["APPROVED"] = "approved";
107
+ CustomerWithdrawalResponseStatus2["PROCESSING"] = "processing";
108
+ CustomerWithdrawalResponseStatus2["COMPLETED"] = "completed";
109
+ CustomerWithdrawalResponseStatus2["REJECTED"] = "rejected";
110
+ CustomerWithdrawalResponseStatus2["CANCELLED"] = "cancelled";
111
+ return CustomerWithdrawalResponseStatus2;
112
+ })(CustomerWithdrawalResponseStatus || {});
113
+
114
+ // src/_api/generated/payments/payments__api__payments/client.ts
115
+ var PaymentsPayments = class {
116
+ constructor(client) {
117
+ __publicField(this, "client");
118
+ this.client = client;
119
+ }
120
+ /**
121
+ * Mixin for views that need owner-scoped queries. Supports both API key
122
+ * auth and JWT auth. Use in payment admin views to get projects/keys for
123
+ * the current owner.
124
+ */
125
+ async balanceRetrieve() {
126
+ const response = await this.client.request("GET", "/api/payments/balance/");
127
+ return response;
128
+ }
129
+ /**
130
+ * GET /customer/balance/ — customer balance (always 200).
131
+ */
132
+ async customerBalanceRetrieve() {
133
+ const response = await this.client.request("GET", "/api/payments/customer/balance/");
134
+ return response;
135
+ }
136
+ /**
137
+ * GET /customer/invoices/ — payment history.
138
+ */
139
+ async customerInvoicesList(...args) {
140
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
141
+ let params;
142
+ if (isParamsObject) {
143
+ params = args[0];
144
+ } else {
145
+ params = { ordering: args[0], page: args[1], page_size: args[2], search: args[3] };
146
+ }
147
+ const response = await this.client.request("GET", "/api/payments/customer/invoices/", { params });
148
+ return response;
149
+ }
150
+ /**
151
+ * GET /customer/invoices/{id}/ — invoice detail.
152
+ */
153
+ async customerInvoicesRetrieve(id) {
154
+ const response = await this.client.request("GET", `/api/payments/customer/invoices/${id}/`);
155
+ return response;
156
+ }
157
+ /**
158
+ * GET /customer/profile/ — customer profile (always 200).
159
+ */
160
+ async customerProfileRetrieve() {
161
+ const response = await this.client.request("GET", "/api/payments/customer/profile/");
162
+ return response;
163
+ }
164
+ /**
165
+ * GET /customer/transactions/ — transaction history.
166
+ */
167
+ async customerTransactionsList(...args) {
168
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
169
+ let params;
170
+ if (isParamsObject) {
171
+ params = args[0];
172
+ } else {
173
+ params = { ordering: args[0], page: args[1], page_size: args[2], search: args[3] };
174
+ }
175
+ const response = await this.client.request("GET", "/api/payments/customer/transactions/", { params });
176
+ return response;
177
+ }
178
+ /**
179
+ * GET /customer/withdrawals/ — withdrawals list.
180
+ */
181
+ async customerWithdrawalsList(...args) {
182
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
183
+ let params;
184
+ if (isParamsObject) {
185
+ params = args[0];
186
+ } else {
187
+ params = { ordering: args[0], page: args[1], page_size: args[2], search: args[3] };
188
+ }
189
+ const response = await this.client.request("GET", "/api/payments/customer/withdrawals/", { params });
190
+ return response;
191
+ }
192
+ /**
193
+ * POST /customer/withdrawals/create/ — create withdrawal.
194
+ */
195
+ async customerWithdrawalsCreateCreate(data) {
196
+ const response = await this.client.request("POST", "/api/payments/customer/withdrawals/create/", { body: data });
197
+ return response;
198
+ }
199
+ async invoicesList(...args) {
200
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
201
+ let params;
202
+ if (isParamsObject) {
203
+ params = args[0];
204
+ } else {
205
+ params = { ordering: args[0], page: args[1], page_size: args[2], search: args[3] };
206
+ }
207
+ const response = await this.client.request("GET", "/api/payments/invoices/", { params });
208
+ return response;
209
+ }
210
+ async invoicesRetrieve(id) {
211
+ const response = await this.client.request("GET", `/api/payments/invoices/${id}/`);
212
+ return response;
213
+ }
214
+ async invoicesCancelCreate(id) {
215
+ const response = await this.client.request("POST", `/api/payments/invoices/${id}/cancel/`);
216
+ return response;
217
+ }
218
+ async invoicesStatusRetrieve(id) {
219
+ const response = await this.client.request("GET", `/api/payments/invoices/${id}/status/`);
220
+ return response;
221
+ }
222
+ /**
223
+ * Mixin for views that need owner-scoped queries. Supports both API key
224
+ * auth and JWT auth. Use in payment admin views to get projects/keys for
225
+ * the current owner.
226
+ */
227
+ async invoicesCreateCreate(data) {
228
+ const response = await this.client.request("POST", "/api/payments/invoices/create/", { body: data });
229
+ return response;
230
+ }
231
+ async linksList(...args) {
232
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
233
+ let params;
234
+ if (isParamsObject) {
235
+ params = args[0];
236
+ } else {
237
+ params = { ordering: args[0], page: args[1], page_size: args[2], search: args[3] };
238
+ }
239
+ const response = await this.client.request("GET", "/api/payments/links/", { params });
240
+ return response;
241
+ }
242
+ /**
243
+ * Mixin for views that need owner-scoped queries. Supports both API key
244
+ * auth and JWT auth. Use in payment admin views to get projects/keys for
245
+ * the current owner.
246
+ */
247
+ async linksCreateCreate(data) {
248
+ const response = await this.client.request("POST", "/api/payments/links/create/", { body: data });
249
+ return response;
250
+ }
251
+ /**
252
+ * GET /invoices/{id}/status/ — public polling endpoint.
253
+ */
254
+ async publicInvoicesStatusRetrieve(id) {
255
+ const response = await this.client.request("GET", `/api/payments/public/invoices/${id}/status/`);
256
+ return response;
257
+ }
258
+ /**
259
+ * GET /links/{id}/ — public.
260
+ */
261
+ async publicLinksRetrieve(id) {
262
+ const response = await this.client.request("GET", `/api/payments/public/links/${id}/`);
263
+ return response;
264
+ }
265
+ /**
266
+ * POST /links/{id}/pay/ — public.
267
+ */
268
+ async publicLinksPayCreate(id, data) {
269
+ const response = await this.client.request("POST", `/api/payments/public/links/${id}/pay/`, { body: data });
270
+ return response;
271
+ }
272
+ async transactionsList(...args) {
273
+ const isParamsObject = args.length === 1 && typeof args[0] === "object" && args[0] !== null && !Array.isArray(args[0]);
274
+ let params;
275
+ if (isParamsObject) {
276
+ params = args[0];
277
+ } else {
278
+ params = { ordering: args[0], page: args[1], page_size: args[2], search: args[3] };
279
+ }
280
+ const response = await this.client.request("GET", "/api/payments/transactions/", { params });
281
+ return response;
282
+ }
283
+ /**
284
+ * Mixin for views that need owner-scoped queries. Supports both API key
285
+ * auth and JWT auth. Use in payment admin views to get projects/keys for
286
+ * the current owner.
287
+ */
288
+ async withdrawalsCreate(data) {
289
+ const response = await this.client.request("POST", "/api/payments/withdrawals/", { body: data });
290
+ return response;
291
+ }
292
+ async withdrawalsRetrieve(id) {
293
+ const response = await this.client.request("GET", `/api/payments/withdrawals/${id}/`);
294
+ return response;
295
+ }
296
+ async withdrawalsCancelCreate(id) {
297
+ const response = await this.client.request("POST", `/api/payments/withdrawals/${id}/cancel/`);
298
+ return response;
299
+ }
300
+ };
301
+
302
+ // src/_api/generated/payments/http.ts
303
+ var FetchAdapter = class {
304
+ async request(request) {
305
+ const { method, url, headers, body, params, formData, binaryBody } = request;
306
+ let finalUrl = url;
307
+ if (params) {
308
+ const searchParams = new URLSearchParams();
309
+ Object.entries(params).forEach(([key, value]) => {
310
+ if (value !== null && value !== void 0) {
311
+ searchParams.append(key, String(value));
312
+ }
313
+ });
314
+ const queryString = searchParams.toString();
315
+ if (queryString) {
316
+ finalUrl = url.includes("?") ? `${url}&${queryString}` : `${url}?${queryString}`;
317
+ }
318
+ }
319
+ const finalHeaders = { ...headers };
320
+ let requestBody;
321
+ if (formData) {
322
+ requestBody = formData;
323
+ } else if (binaryBody) {
324
+ finalHeaders["Content-Type"] = "application/octet-stream";
325
+ requestBody = binaryBody;
326
+ } else if (body) {
327
+ finalHeaders["Content-Type"] = "application/json";
328
+ requestBody = JSON.stringify(body);
329
+ }
330
+ const response = await fetch(finalUrl, {
331
+ method,
332
+ headers: finalHeaders,
333
+ body: requestBody,
334
+ credentials: "include"
335
+ // Include Django session cookies
336
+ });
337
+ let data = null;
338
+ const contentType = response.headers.get("content-type");
339
+ if (response.status !== 204 && contentType?.includes("application/json")) {
340
+ data = await response.json();
341
+ } else if (response.status !== 204) {
342
+ data = await response.text();
343
+ }
344
+ const responseHeaders = {};
345
+ response.headers.forEach((value, key) => {
346
+ responseHeaders[key] = value;
347
+ });
348
+ return {
349
+ data,
350
+ status: response.status,
351
+ statusText: response.statusText,
352
+ headers: responseHeaders
353
+ };
354
+ }
355
+ };
356
+
357
+ // src/_api/generated/payments/errors.ts
358
+ var APIError = class extends Error {
359
+ constructor(statusCode, statusText, response, url, message) {
360
+ super(message || `HTTP ${statusCode}: ${statusText}`);
361
+ this.statusCode = statusCode;
362
+ this.statusText = statusText;
363
+ this.response = response;
364
+ this.url = url;
365
+ this.name = "APIError";
366
+ }
367
+ /**
368
+ * Get error details from response.
369
+ * DRF typically returns: { "detail": "Error message" } or { "field": ["error1", "error2"] }
370
+ */
371
+ get details() {
372
+ if (typeof this.response === "object" && this.response !== null) {
373
+ return this.response;
374
+ }
375
+ return null;
376
+ }
377
+ /**
378
+ * Get field-specific validation errors from DRF.
379
+ * Returns: { "field_name": ["error1", "error2"], ... }
380
+ */
381
+ get fieldErrors() {
382
+ const details = this.details;
383
+ if (!details) return null;
384
+ const fieldErrors = {};
385
+ for (const [key, value] of Object.entries(details)) {
386
+ if (Array.isArray(value)) {
387
+ fieldErrors[key] = value;
388
+ }
389
+ }
390
+ return Object.keys(fieldErrors).length > 0 ? fieldErrors : null;
391
+ }
392
+ /**
393
+ * Get single error message from DRF.
394
+ * Checks for "detail", "message", or first field error.
395
+ */
396
+ get errorMessage() {
397
+ const details = this.details;
398
+ if (!details) return this.message;
399
+ if (details.detail) {
400
+ return Array.isArray(details.detail) ? details.detail.join(", ") : String(details.detail);
401
+ }
402
+ if (details.error) {
403
+ return String(details.error);
404
+ }
405
+ if (details.message) {
406
+ return String(details.message);
407
+ }
408
+ const fieldErrors = this.fieldErrors;
409
+ if (fieldErrors) {
410
+ const firstField = Object.keys(fieldErrors)[0];
411
+ if (firstField) {
412
+ return `${firstField}: ${fieldErrors[firstField]?.join(", ")}`;
413
+ }
414
+ }
415
+ return this.message;
416
+ }
417
+ // Helper methods for common HTTP status codes
418
+ get isValidationError() {
419
+ return this.statusCode === 400;
420
+ }
421
+ get isAuthError() {
422
+ return this.statusCode === 401;
423
+ }
424
+ get isPermissionError() {
425
+ return this.statusCode === 403;
426
+ }
427
+ get isNotFoundError() {
428
+ return this.statusCode === 404;
429
+ }
430
+ get isServerError() {
431
+ return this.statusCode >= 500 && this.statusCode < 600;
432
+ }
433
+ };
434
+ var NetworkError = class extends Error {
435
+ constructor(message, url, originalError) {
436
+ super(message);
437
+ this.url = url;
438
+ this.originalError = originalError;
439
+ this.name = "NetworkError";
440
+ }
441
+ };
442
+ var DEFAULT_CONFIG = {
443
+ enabled: true,
444
+ logRequests: true,
445
+ logResponses: true,
446
+ logErrors: true,
447
+ logBodies: true,
448
+ logHeaders: false
449
+ };
450
+ var SENSITIVE_HEADERS = [
451
+ "authorization",
452
+ "cookie",
453
+ "set-cookie",
454
+ "x-api-key",
455
+ "x-csrf-token"
456
+ ];
457
+ var APILogger = class {
458
+ constructor(config = {}) {
459
+ __publicField(this, "config");
460
+ __publicField(this, "consola");
461
+ this.config = { ...DEFAULT_CONFIG, ...config };
462
+ this.consola = config.consola || createConsola({
463
+ level: this.config.enabled ? 4 : 0
464
+ });
465
+ }
466
+ /**
467
+ * Enable logging
468
+ */
469
+ enable() {
470
+ this.config.enabled = true;
471
+ }
472
+ /**
473
+ * Disable logging
474
+ */
475
+ disable() {
476
+ this.config.enabled = false;
477
+ }
478
+ /**
479
+ * Update configuration
480
+ */
481
+ setConfig(config) {
482
+ this.config = { ...this.config, ...config };
483
+ }
484
+ /**
485
+ * Filter sensitive headers
486
+ */
487
+ filterHeaders(headers) {
488
+ if (!headers) return {};
489
+ const filtered = {};
490
+ Object.keys(headers).forEach((key) => {
491
+ const lowerKey = key.toLowerCase();
492
+ if (SENSITIVE_HEADERS.includes(lowerKey)) {
493
+ filtered[key] = "***";
494
+ } else {
495
+ filtered[key] = headers[key] || "";
496
+ }
497
+ });
498
+ return filtered;
499
+ }
500
+ /**
501
+ * Log request
502
+ */
503
+ logRequest(request) {
504
+ if (!this.config.enabled || !this.config.logRequests) return;
505
+ const { method, url, headers, body } = request;
506
+ this.consola.start(`${method} ${url}`);
507
+ if (this.config.logHeaders && headers) {
508
+ this.consola.debug("Headers:", this.filterHeaders(headers));
509
+ }
510
+ if (this.config.logBodies && body) {
511
+ this.consola.debug("Body:", body);
512
+ }
513
+ }
514
+ /**
515
+ * Log response
516
+ */
517
+ logResponse(request, response) {
518
+ if (!this.config.enabled || !this.config.logResponses) return;
519
+ const { method, url } = request;
520
+ const { status, statusText, data, duration } = response;
521
+ this.consola.success(
522
+ `${method} ${url} ${status} ${statusText} (${duration}ms)`
523
+ );
524
+ if (this.config.logBodies && data) {
525
+ this.consola.debug("Response:", data);
526
+ }
527
+ }
528
+ /**
529
+ * Log error
530
+ */
531
+ logError(request, error) {
532
+ if (!this.config.enabled || !this.config.logErrors) return;
533
+ const { method, url } = request;
534
+ const { message, statusCode, fieldErrors, duration } = error;
535
+ this.consola.error(
536
+ `${method} ${url} ${statusCode || "Network"} Error (${duration}ms)`
537
+ );
538
+ this.consola.error("Message:", message);
539
+ if (fieldErrors && Object.keys(fieldErrors).length > 0) {
540
+ this.consola.error("Field Errors:");
541
+ Object.entries(fieldErrors).forEach(([field, errors]) => {
542
+ errors.forEach((err) => {
543
+ this.consola.error(` \u2022 ${field}: ${err}`);
544
+ });
545
+ });
546
+ }
547
+ }
548
+ /**
549
+ * Log general info
550
+ */
551
+ info(message, ...args) {
552
+ if (!this.config.enabled) return;
553
+ this.consola.info(message, ...args);
554
+ }
555
+ /**
556
+ * Log warning
557
+ */
558
+ warn(message, ...args) {
559
+ if (!this.config.enabled) return;
560
+ this.consola.warn(message, ...args);
561
+ }
562
+ /**
563
+ * Log error
564
+ */
565
+ error(message, ...args) {
566
+ if (!this.config.enabled) return;
567
+ this.consola.error(message, ...args);
568
+ }
569
+ /**
570
+ * Log debug
571
+ */
572
+ debug(message, ...args) {
573
+ if (!this.config.enabled) return;
574
+ this.consola.debug(message, ...args);
575
+ }
576
+ /**
577
+ * Log success
578
+ */
579
+ success(message, ...args) {
580
+ if (!this.config.enabled) return;
581
+ this.consola.success(message, ...args);
582
+ }
583
+ /**
584
+ * Create a sub-logger with prefix
585
+ */
586
+ withTag(tag) {
587
+ return this.consola.withTag(tag);
588
+ }
589
+ };
590
+ new APILogger();
591
+ var DEFAULT_RETRY_CONFIG = {
592
+ retries: 3,
593
+ factor: 2,
594
+ minTimeout: 1e3,
595
+ maxTimeout: 6e4,
596
+ randomize: true,
597
+ onFailedAttempt: () => {
598
+ }
599
+ };
600
+ function shouldRetry(error) {
601
+ if (error instanceof NetworkError) {
602
+ return true;
603
+ }
604
+ if (error instanceof APIError) {
605
+ const status = error.statusCode;
606
+ if (status >= 500 && status < 600) {
607
+ return true;
608
+ }
609
+ if (status === 429) {
610
+ return true;
611
+ }
612
+ return false;
613
+ }
614
+ return true;
615
+ }
616
+ async function withRetry(fn, config) {
617
+ const finalConfig = { ...DEFAULT_RETRY_CONFIG, ...config };
618
+ return pRetry(
619
+ async () => {
620
+ try {
621
+ return await fn();
622
+ } catch (error) {
623
+ if (!shouldRetry(error)) {
624
+ throw new AbortError(error);
625
+ }
626
+ throw error;
627
+ }
628
+ },
629
+ {
630
+ retries: finalConfig.retries,
631
+ factor: finalConfig.factor,
632
+ minTimeout: finalConfig.minTimeout,
633
+ maxTimeout: finalConfig.maxTimeout,
634
+ randomize: finalConfig.randomize,
635
+ onFailedAttempt: finalConfig.onFailedAttempt ? (error) => {
636
+ const pRetryError = error;
637
+ finalConfig.onFailedAttempt({
638
+ error: pRetryError,
639
+ attemptNumber: pRetryError.attemptNumber,
640
+ retriesLeft: pRetryError.retriesLeft
641
+ });
642
+ } : void 0
643
+ }
644
+ );
645
+ }
646
+
647
+ // src/_api/generated/payments/client.ts
648
+ var APIClient = class {
649
+ constructor(baseUrl, options) {
650
+ __publicField(this, "baseUrl");
651
+ __publicField(this, "httpClient");
652
+ __publicField(this, "logger", null);
653
+ __publicField(this, "retryConfig", null);
654
+ __publicField(this, "tokenGetter", null);
655
+ // Sub-clients
656
+ __publicField(this, "payments_payments");
657
+ this.baseUrl = baseUrl.replace(/\/$/, "");
658
+ this.httpClient = options?.httpClient || new FetchAdapter();
659
+ this.tokenGetter = options?.tokenGetter || null;
660
+ if (options?.loggerConfig !== void 0) {
661
+ this.logger = new APILogger(options.loggerConfig);
662
+ }
663
+ if (options?.retryConfig !== void 0) {
664
+ this.retryConfig = options.retryConfig;
665
+ }
666
+ this.payments_payments = new PaymentsPayments(this);
667
+ }
668
+ /**
669
+ * Get CSRF token from cookies (for SessionAuthentication).
670
+ *
671
+ * Returns null if cookie doesn't exist (JWT-only auth).
672
+ */
673
+ getCsrfToken() {
674
+ const name = "csrftoken";
675
+ const value = `; ${document.cookie}`;
676
+ const parts = value.split(`; ${name}=`);
677
+ if (parts.length === 2) {
678
+ return parts.pop()?.split(";").shift() || null;
679
+ }
680
+ return null;
681
+ }
682
+ /**
683
+ * Get the base URL for building streaming/download URLs.
684
+ */
685
+ getBaseUrl() {
686
+ return this.baseUrl;
687
+ }
688
+ /**
689
+ * Get JWT token for URL authentication (used in streaming endpoints).
690
+ * Returns null if no token getter is configured or no token is available.
691
+ */
692
+ getToken() {
693
+ return this.tokenGetter ? this.tokenGetter() : null;
694
+ }
695
+ /**
696
+ * Make HTTP request with Django CSRF and session handling.
697
+ * Automatically retries on network errors and 5xx server errors.
698
+ */
699
+ async request(method, path, options) {
700
+ if (this.retryConfig) {
701
+ return withRetry(() => this._makeRequest(method, path, options), {
702
+ ...this.retryConfig,
703
+ onFailedAttempt: (info) => {
704
+ if (this.logger) {
705
+ this.logger.warn(
706
+ `Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} for ${method} ${path}: ${info.error.message}`
707
+ );
708
+ }
709
+ this.retryConfig?.onFailedAttempt?.(info);
710
+ }
711
+ });
712
+ }
713
+ return this._makeRequest(method, path, options);
714
+ }
715
+ /**
716
+ * Internal request method (without retry wrapper).
717
+ * Used by request() method with optional retry logic.
718
+ */
719
+ async _makeRequest(method, path, options) {
720
+ const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
721
+ const startTime = Date.now();
722
+ const headers = {
723
+ ...options?.headers || {}
724
+ };
725
+ if (!options?.formData && !options?.binaryBody && !headers["Content-Type"]) {
726
+ headers["Content-Type"] = "application/json";
727
+ }
728
+ if (this.logger) {
729
+ this.logger.logRequest({
730
+ method,
731
+ url,
732
+ headers,
733
+ body: options?.formData || options?.body,
734
+ timestamp: startTime
735
+ });
736
+ }
737
+ try {
738
+ const response = await this.httpClient.request({
739
+ method,
740
+ url,
741
+ headers,
742
+ params: options?.params,
743
+ body: options?.body,
744
+ formData: options?.formData,
745
+ binaryBody: options?.binaryBody
746
+ });
747
+ const duration = Date.now() - startTime;
748
+ if (response.status >= 400) {
749
+ const error = new APIError(
750
+ response.status,
751
+ response.statusText,
752
+ response.data,
753
+ url
754
+ );
755
+ if (this.logger) {
756
+ this.logger.logError(
757
+ {
758
+ method,
759
+ url,
760
+ headers,
761
+ body: options?.formData || options?.body,
762
+ timestamp: startTime
763
+ },
764
+ {
765
+ message: error.message,
766
+ statusCode: response.status,
767
+ duration,
768
+ timestamp: Date.now()
769
+ }
770
+ );
771
+ }
772
+ throw error;
773
+ }
774
+ if (this.logger) {
775
+ this.logger.logResponse(
776
+ {
777
+ method,
778
+ url,
779
+ headers,
780
+ body: options?.formData || options?.body,
781
+ timestamp: startTime
782
+ },
783
+ {
784
+ status: response.status,
785
+ statusText: response.statusText,
786
+ data: response.data,
787
+ duration,
788
+ timestamp: Date.now()
789
+ }
790
+ );
791
+ }
792
+ return response.data;
793
+ } catch (error) {
794
+ const duration = Date.now() - startTime;
795
+ if (error instanceof APIError) {
796
+ throw error;
797
+ }
798
+ let possiblyCors = false;
799
+ if (error instanceof TypeError && typeof window !== "undefined") {
800
+ try {
801
+ const isCrossOrigin = (() => {
802
+ try {
803
+ return new URL(url).origin !== window.location.origin;
804
+ } catch {
805
+ return false;
806
+ }
807
+ })();
808
+ if (isCrossOrigin) {
809
+ const entries = performance.getEntriesByName(url, "resource");
810
+ if (entries.length > 0) {
811
+ const last = entries[entries.length - 1];
812
+ possiblyCors = "responseStatus" in last && last.responseStatus === 0;
813
+ }
814
+ }
815
+ } catch {
816
+ }
817
+ }
818
+ if (this.logger) {
819
+ this.logger.error(`\u26A0\uFE0F Network Error: ${method} ${url}`);
820
+ this.logger.error(` \u2192 ${error instanceof Error ? error.message : String(error)}`);
821
+ if (possiblyCors) {
822
+ this.logger.error(` \u2192 Possibly blocked by CORS policy (configure CORS on the server)`);
823
+ }
824
+ }
825
+ if (typeof window !== "undefined") {
826
+ try {
827
+ window.dispatchEvent(new CustomEvent("network-error", {
828
+ detail: {
829
+ url,
830
+ method,
831
+ error: error instanceof Error ? error.message : String(error),
832
+ possibly_cors: possiblyCors,
833
+ timestamp: /* @__PURE__ */ new Date()
834
+ },
835
+ bubbles: true,
836
+ cancelable: false
837
+ }));
838
+ } catch {
839
+ }
840
+ }
841
+ const networkError = error instanceof Error ? new NetworkError(error.message, url, error) : new NetworkError("Unknown error", url);
842
+ if (this.logger) {
843
+ this.logger.logError(
844
+ {
845
+ method,
846
+ url,
847
+ headers,
848
+ body: options?.formData || options?.body,
849
+ timestamp: startTime
850
+ },
851
+ {
852
+ message: networkError.message,
853
+ duration,
854
+ timestamp: Date.now()
855
+ }
856
+ );
857
+ }
858
+ throw networkError;
859
+ }
860
+ }
861
+ };
862
+ z.object({
863
+ balance_usd: z.string(),
864
+ total_deposited: z.string(),
865
+ total_withdrawn: z.string(),
866
+ last_transaction_at: z.string().datetime({ offset: true }).nullable()
867
+ });
868
+ z.object({
869
+ balance_usd: z.string(),
870
+ total_deposited: z.string(),
871
+ total_withdrawn: z.string(),
872
+ last_transaction_at: z.string().datetime({ offset: true }).nullable()
873
+ });
874
+ var CustomerInvoiceDetailSchema = z.object({
875
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
876
+ amount_usd: z.string(),
877
+ pay_amount: z.string(),
878
+ actual_amount: z.string().nullable(),
879
+ pay_address: z.string(),
880
+ coin: z.string(),
881
+ network: z.string(),
882
+ exchange: z.string(),
883
+ status: z.nativeEnum(CustomerInvoiceDetailStatus),
884
+ tx_id: z.string().nullable(),
885
+ confirm_times: z.string(),
886
+ description: z.string(),
887
+ expires_at: z.string().datetime({ offset: true }),
888
+ completed_at: z.string().datetime({ offset: true }).nullable(),
889
+ created_at: z.string().datetime({ offset: true })
890
+ });
891
+ z.object({
892
+ invoice_id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
893
+ amount_usd: z.string(),
894
+ pay_amount: z.string(),
895
+ pay_address: z.string(),
896
+ coin: z.string(),
897
+ network: z.string(),
898
+ exchange: z.string(),
899
+ status: z.string(),
900
+ expires_at: z.string().datetime({ offset: true })
901
+ });
902
+ var CustomerTransactionResponseSchema = z.object({
903
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
904
+ transaction_type: z.nativeEnum(CustomerTransactionResponseTransactionType),
905
+ amount_usd: z.string(),
906
+ balance_after: z.string(),
907
+ invoice: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable(),
908
+ withdrawal: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable(),
909
+ description: z.string(),
910
+ created_at: z.string().datetime({ offset: true })
911
+ });
912
+ z.object({
913
+ amount_usd: z.string(),
914
+ network: z.string().min(1),
915
+ wallet_address: z.string().min(1).max(255)
916
+ });
917
+ var CustomerWithdrawalResponseSchema = z.object({
918
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
919
+ amount_usd: z.string(),
920
+ fee_usd: z.string(),
921
+ final_amount_usd: z.string(),
922
+ network: z.string(),
923
+ wallet_address: z.string(),
924
+ status: z.nativeEnum(CustomerWithdrawalResponseStatus),
925
+ tx_id: z.string().nullable(),
926
+ created_at: z.string().datetime({ offset: true })
927
+ });
928
+ z.object({
929
+ amount_usd: z.string(),
930
+ network: z.string().min(1).optional(),
931
+ exchange: z.string().min(1).nullable().optional(),
932
+ description: z.string().optional(),
933
+ customer_id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
934
+ project_slug: z.string().min(1)
935
+ });
936
+ var InvoiceDetailSchema = z.object({
937
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
938
+ project: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
939
+ customer: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
940
+ amount_usd: z.string(),
941
+ pay_amount: z.string(),
942
+ actual_amount: z.string().nullable(),
943
+ pay_address: z.string(),
944
+ coin: z.string(),
945
+ network: z.string(),
946
+ exchange: z.string(),
947
+ status: z.nativeEnum(CustomerInvoiceDetailStatus),
948
+ tx_id: z.string().nullable(),
949
+ confirm_times: z.string(),
950
+ description: z.string(),
951
+ expires_at: z.string().datetime({ offset: true }),
952
+ completed_at: z.string().datetime({ offset: true }).nullable(),
953
+ created_at: z.string().datetime({ offset: true })
954
+ });
955
+ z.object({
956
+ invoice_id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
957
+ amount_usd: z.string(),
958
+ pay_amount: z.string(),
959
+ pay_address: z.string(),
960
+ coin: z.string(),
961
+ network: z.string(),
962
+ exchange: z.string(),
963
+ status: z.string(),
964
+ expires_at: z.string().datetime({ offset: true })
965
+ });
966
+ z.object({
967
+ invoice_id: z.string(),
968
+ status: z.string(),
969
+ confirm_times: z.number().int(),
970
+ actual_amount: z.string().nullable(),
971
+ tx_id: z.string().nullable(),
972
+ completed_at: z.string().datetime({ offset: true }).nullable()
973
+ });
974
+ z.object({
975
+ count: z.number().int(),
976
+ page: z.number().int(),
977
+ pages: z.number().int(),
978
+ page_size: z.number().int(),
979
+ has_next: z.boolean(),
980
+ has_previous: z.boolean(),
981
+ next_page: z.number().int().nullable().optional(),
982
+ previous_page: z.number().int().nullable().optional(),
983
+ results: z.array(CustomerInvoiceDetailSchema)
984
+ });
985
+ z.object({
986
+ count: z.number().int(),
987
+ page: z.number().int(),
988
+ pages: z.number().int(),
989
+ page_size: z.number().int(),
990
+ has_next: z.boolean(),
991
+ has_previous: z.boolean(),
992
+ next_page: z.number().int().nullable().optional(),
993
+ previous_page: z.number().int().nullable().optional(),
994
+ results: z.array(CustomerTransactionResponseSchema)
995
+ });
996
+ z.object({
997
+ count: z.number().int(),
998
+ page: z.number().int(),
999
+ pages: z.number().int(),
1000
+ page_size: z.number().int(),
1001
+ has_next: z.boolean(),
1002
+ has_previous: z.boolean(),
1003
+ next_page: z.number().int().nullable().optional(),
1004
+ previous_page: z.number().int().nullable().optional(),
1005
+ results: z.array(CustomerWithdrawalResponseSchema)
1006
+ });
1007
+ z.object({
1008
+ count: z.number().int(),
1009
+ page: z.number().int(),
1010
+ pages: z.number().int(),
1011
+ page_size: z.number().int(),
1012
+ has_next: z.boolean(),
1013
+ has_previous: z.boolean(),
1014
+ next_page: z.number().int().nullable().optional(),
1015
+ previous_page: z.number().int().nullable().optional(),
1016
+ results: z.array(InvoiceDetailSchema)
1017
+ });
1018
+ var PaymentLinkSchema = z.object({
1019
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1020
+ project: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1021
+ title: z.string().max(200),
1022
+ description: z.string().optional(),
1023
+ amount_usd: z.string().nullable().optional(),
1024
+ network: z.string().max(20).optional(),
1025
+ exchange: z.string().max(20).optional(),
1026
+ is_active: z.boolean().optional(),
1027
+ success_url: z.string().max(200).optional(),
1028
+ metadata: z.record(z.string(), z.any()).optional(),
1029
+ total_payments: z.number().int(),
1030
+ total_collected_usd: z.string(),
1031
+ pay_url: z.string(),
1032
+ created_at: z.string().datetime({ offset: true })
1033
+ });
1034
+
1035
+ // src/_api/generated/payments/_utils/schemas/PaginatedPaymentLinkList.schema.ts
1036
+ z.object({
1037
+ count: z.number().int(),
1038
+ page: z.number().int(),
1039
+ pages: z.number().int(),
1040
+ page_size: z.number().int(),
1041
+ has_next: z.boolean(),
1042
+ has_previous: z.boolean(),
1043
+ next_page: z.number().int().nullable().optional(),
1044
+ previous_page: z.number().int().nullable().optional(),
1045
+ results: z.array(PaymentLinkSchema)
1046
+ });
1047
+ var TransactionSchema = z.object({
1048
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1049
+ transaction_type: z.nativeEnum(CustomerTransactionResponseTransactionType),
1050
+ amount_usd: z.string(),
1051
+ balance_after: z.string(),
1052
+ invoice: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable(),
1053
+ withdrawal: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i).nullable(),
1054
+ description: z.string(),
1055
+ created_at: z.string().datetime({ offset: true })
1056
+ });
1057
+
1058
+ // src/_api/generated/payments/_utils/schemas/PaginatedTransactionList.schema.ts
1059
+ z.object({
1060
+ count: z.number().int(),
1061
+ page: z.number().int(),
1062
+ pages: z.number().int(),
1063
+ page_size: z.number().int(),
1064
+ has_next: z.boolean(),
1065
+ has_previous: z.boolean(),
1066
+ next_page: z.number().int().nullable().optional(),
1067
+ previous_page: z.number().int().nullable().optional(),
1068
+ results: z.array(TransactionSchema)
1069
+ });
1070
+ z.object({
1071
+ title: z.string().min(1).max(200),
1072
+ description: z.string().optional(),
1073
+ amount_usd: z.string().nullable().optional(),
1074
+ network: z.string().min(1).optional(),
1075
+ exchange: z.string().min(1).optional(),
1076
+ success_url: z.string().optional(),
1077
+ project_slug: z.string().min(1),
1078
+ metadata: z.record(z.string(), z.any()).optional()
1079
+ });
1080
+ z.object({
1081
+ email: z.email().nullable().optional(),
1082
+ name: z.string().optional(),
1083
+ amount_usd: z.string().nullable().optional(),
1084
+ external_id: z.string().min(1).nullable().optional()
1085
+ });
1086
+ z.object({
1087
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1088
+ title: z.string(),
1089
+ description: z.string(),
1090
+ amount_usd: z.string().nullable(),
1091
+ network: z.string(),
1092
+ exchange: z.string(),
1093
+ success_url: z.string()
1094
+ });
1095
+ z.object({
1096
+ invoice_id: z.string(),
1097
+ status: z.string(),
1098
+ confirm_times: z.string().nullable(),
1099
+ tx_id: z.string().nullable(),
1100
+ completed_at: z.string().datetime({ offset: true }).nullable()
1101
+ });
1102
+ z.object({
1103
+ id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1104
+ project: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1105
+ customer: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1106
+ amount_usd: z.string(),
1107
+ fee_usd: z.string(),
1108
+ final_amount_usd: z.string(),
1109
+ network: z.string(),
1110
+ wallet_address: z.string(),
1111
+ status: z.nativeEnum(CustomerWithdrawalResponseStatus),
1112
+ tx_id: z.string().nullable(),
1113
+ created_at: z.string().datetime({ offset: true })
1114
+ });
1115
+ z.object({
1116
+ amount_usd: z.string(),
1117
+ network: z.string().min(1),
1118
+ wallet_address: z.string().min(1).max(255),
1119
+ customer_id: z.string().regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i),
1120
+ project_slug: z.string().min(1)
1121
+ });
1122
+
1123
+ // src/_api/generated/payments/index.ts
1124
+ var TOKEN_KEY = "auth_token";
1125
+ var REFRESH_TOKEN_KEY = "refresh_token";
1126
+ function detectLocale() {
1127
+ try {
1128
+ if (typeof document !== "undefined") {
1129
+ const match = document.cookie.match(/(?:^|;\s*)NEXT_LOCALE=([^;]*)/);
1130
+ if (match) return match[1];
1131
+ }
1132
+ if (typeof navigator !== "undefined" && navigator.language) {
1133
+ return navigator.language;
1134
+ }
1135
+ } catch {
1136
+ }
1137
+ return null;
1138
+ }
1139
+ var API = class {
1140
+ constructor(baseUrl, options) {
1141
+ __publicField(this, "baseUrl");
1142
+ __publicField(this, "_client");
1143
+ __publicField(this, "_token", null);
1144
+ __publicField(this, "_refreshToken", null);
1145
+ __publicField(this, "_locale", null);
1146
+ __publicField(this, "storage");
1147
+ __publicField(this, "options");
1148
+ // Sub-clients
1149
+ __publicField(this, "payments_payments");
1150
+ this.baseUrl = baseUrl;
1151
+ this.options = options;
1152
+ const logger = options?.loggerConfig ? new APILogger(options.loggerConfig) : void 0;
1153
+ this.storage = options?.storage || new LocalStorageAdapter(logger);
1154
+ this._locale = options?.locale || null;
1155
+ this._loadTokensFromStorage();
1156
+ this._client = new APIClient(this.baseUrl, {
1157
+ httpClient: this.options?.httpClient,
1158
+ retryConfig: this.options?.retryConfig,
1159
+ loggerConfig: this.options?.loggerConfig,
1160
+ tokenGetter: () => this.getToken()
1161
+ });
1162
+ this._injectAuthHeader();
1163
+ this.payments_payments = this._client.payments_payments;
1164
+ }
1165
+ _loadTokensFromStorage() {
1166
+ this._token = this.storage.getItem(TOKEN_KEY);
1167
+ this._refreshToken = this.storage.getItem(REFRESH_TOKEN_KEY);
1168
+ }
1169
+ _reinitClients() {
1170
+ this._client = new APIClient(this.baseUrl, {
1171
+ httpClient: this.options?.httpClient,
1172
+ retryConfig: this.options?.retryConfig,
1173
+ loggerConfig: this.options?.loggerConfig,
1174
+ tokenGetter: () => this.getToken()
1175
+ });
1176
+ this._injectAuthHeader();
1177
+ this.payments_payments = this._client.payments_payments;
1178
+ }
1179
+ _injectAuthHeader() {
1180
+ const originalRequest = this._client.request.bind(this._client);
1181
+ this._client.request = async (method, path, options) => {
1182
+ const token = this.getToken();
1183
+ const locale = this._locale || detectLocale();
1184
+ const mergedOptions = {
1185
+ ...options,
1186
+ headers: {
1187
+ ...options?.headers || {},
1188
+ ...token ? { "Authorization": `Bearer ${token}` } : {},
1189
+ ...locale ? { "Accept-Language": locale } : {}
1190
+ }
1191
+ };
1192
+ return originalRequest(method, path, mergedOptions);
1193
+ };
1194
+ }
1195
+ /**
1196
+ * Get current JWT token
1197
+ */
1198
+ getToken() {
1199
+ return this.storage.getItem(TOKEN_KEY);
1200
+ }
1201
+ /**
1202
+ * Get current refresh token
1203
+ */
1204
+ getRefreshToken() {
1205
+ return this.storage.getItem(REFRESH_TOKEN_KEY);
1206
+ }
1207
+ /**
1208
+ * Set JWT token and refresh token
1209
+ * @param token - JWT access token
1210
+ * @param refreshToken - JWT refresh token (optional)
1211
+ */
1212
+ setToken(token, refreshToken) {
1213
+ this._token = token;
1214
+ this.storage.setItem(TOKEN_KEY, token);
1215
+ if (refreshToken) {
1216
+ this._refreshToken = refreshToken;
1217
+ this.storage.setItem(REFRESH_TOKEN_KEY, refreshToken);
1218
+ }
1219
+ this._reinitClients();
1220
+ }
1221
+ /**
1222
+ * Clear all tokens
1223
+ */
1224
+ clearTokens() {
1225
+ this._token = null;
1226
+ this._refreshToken = null;
1227
+ this.storage.removeItem(TOKEN_KEY);
1228
+ this.storage.removeItem(REFRESH_TOKEN_KEY);
1229
+ this._reinitClients();
1230
+ }
1231
+ /**
1232
+ * Check if user is authenticated
1233
+ */
1234
+ isAuthenticated() {
1235
+ return !!this.getToken();
1236
+ }
1237
+ /**
1238
+ * Update base URL and reinitialize clients
1239
+ * @param url - New base URL
1240
+ */
1241
+ setBaseUrl(url) {
1242
+ this.baseUrl = url;
1243
+ this._reinitClients();
1244
+ }
1245
+ /**
1246
+ * Get current base URL
1247
+ */
1248
+ getBaseUrl() {
1249
+ return this.baseUrl;
1250
+ }
1251
+ /**
1252
+ * Set locale for Accept-Language header
1253
+ * @param locale - Locale string (e.g. 'en', 'ko', 'ru') or null to clear
1254
+ */
1255
+ setLocale(locale) {
1256
+ this._locale = locale;
1257
+ }
1258
+ /**
1259
+ * Get current locale
1260
+ */
1261
+ getLocale() {
1262
+ return this._locale;
1263
+ }
1264
+ /**
1265
+ * Get OpenAPI schema path
1266
+ * @returns Path to the OpenAPI schema JSON file
1267
+ *
1268
+ * Note: The OpenAPI schema is available in the schema.json file.
1269
+ * You can load it dynamically using:
1270
+ * ```typescript
1271
+ * const schema = await fetch('./schema.json').then(r => r.json());
1272
+ * // or using fs in Node.js:
1273
+ * // const schema = JSON.parse(fs.readFileSync('./schema.json', 'utf-8'));
1274
+ * ```
1275
+ */
1276
+ getSchemaPath() {
1277
+ return "./schema.json";
1278
+ }
1279
+ };
1280
+
1281
+ // src/_api/BaseClient.ts
1282
+ var storage = new MemoryStorageAdapter();
1283
+ function createPaymentsApi(baseUrl) {
1284
+ return new API(baseUrl, { storage });
1285
+ }
1286
+
1287
+ export { API, MemoryStorageAdapter, createPaymentsApi, enums_exports };
1288
+ //# sourceMappingURL=chunk-4QQBPIIT.mjs.map
1289
+ //# sourceMappingURL=chunk-4QQBPIIT.mjs.map