@djangocfg/ext-payments 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +206 -0
  2. package/dist/chunk-5KY6HVXF.js +2593 -0
  3. package/dist/hooks.cjs +2666 -0
  4. package/dist/hooks.d.cts +186 -0
  5. package/dist/hooks.d.ts +186 -0
  6. package/dist/hooks.js +1 -0
  7. package/dist/index.cjs +2590 -0
  8. package/dist/index.d.cts +1287 -0
  9. package/dist/index.d.ts +1287 -0
  10. package/dist/index.js +1 -0
  11. package/package.json +79 -0
  12. package/src/api/generated/ext_payments/_utils/fetchers/ext_payments__payments.ts +408 -0
  13. package/src/api/generated/ext_payments/_utils/fetchers/index.ts +28 -0
  14. package/src/api/generated/ext_payments/_utils/hooks/ext_payments__payments.ts +147 -0
  15. package/src/api/generated/ext_payments/_utils/hooks/index.ts +28 -0
  16. package/src/api/generated/ext_payments/_utils/schemas/Balance.schema.ts +23 -0
  17. package/src/api/generated/ext_payments/_utils/schemas/Currency.schema.ts +28 -0
  18. package/src/api/generated/ext_payments/_utils/schemas/PaginatedPaymentListList.schema.ts +24 -0
  19. package/src/api/generated/ext_payments/_utils/schemas/PaymentDetail.schema.ts +44 -0
  20. package/src/api/generated/ext_payments/_utils/schemas/PaymentList.schema.ts +28 -0
  21. package/src/api/generated/ext_payments/_utils/schemas/Transaction.schema.ts +28 -0
  22. package/src/api/generated/ext_payments/_utils/schemas/index.ts +24 -0
  23. package/src/api/generated/ext_payments/api-instance.ts +131 -0
  24. package/src/api/generated/ext_payments/client.ts +301 -0
  25. package/src/api/generated/ext_payments/enums.ts +64 -0
  26. package/src/api/generated/ext_payments/errors.ts +116 -0
  27. package/src/api/generated/ext_payments/ext_payments__payments/client.ts +118 -0
  28. package/src/api/generated/ext_payments/ext_payments__payments/index.ts +2 -0
  29. package/src/api/generated/ext_payments/ext_payments__payments/models.ts +135 -0
  30. package/src/api/generated/ext_payments/http.ts +103 -0
  31. package/src/api/generated/ext_payments/index.ts +273 -0
  32. package/src/api/generated/ext_payments/logger.ts +259 -0
  33. package/src/api/generated/ext_payments/retry.ts +175 -0
  34. package/src/api/generated/ext_payments/schema.json +850 -0
  35. package/src/api/generated/ext_payments/storage.ts +161 -0
  36. package/src/api/generated/ext_payments/validation-events.ts +133 -0
  37. package/src/api/index.ts +9 -0
  38. package/src/config.ts +20 -0
  39. package/src/contexts/BalancesContext.tsx +62 -0
  40. package/src/contexts/CurrenciesContext.tsx +63 -0
  41. package/src/contexts/OverviewContext.tsx +173 -0
  42. package/src/contexts/PaymentsContext.tsx +121 -0
  43. package/src/contexts/PaymentsExtensionProvider.tsx +55 -0
  44. package/src/contexts/README.md +201 -0
  45. package/src/contexts/RootPaymentsContext.tsx +65 -0
  46. package/src/contexts/index.ts +45 -0
  47. package/src/contexts/types.ts +40 -0
  48. package/src/hooks/index.ts +20 -0
  49. package/src/index.ts +36 -0
  50. package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +92 -0
  51. package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +291 -0
  52. package/src/layouts/PaymentsLayout/components/PaymentDetailsDialog.tsx +290 -0
  53. package/src/layouts/PaymentsLayout/components/index.ts +2 -0
  54. package/src/layouts/PaymentsLayout/events.ts +47 -0
  55. package/src/layouts/PaymentsLayout/index.ts +16 -0
  56. package/src/layouts/PaymentsLayout/types.ts +6 -0
  57. package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +128 -0
  58. package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +142 -0
  59. package/src/layouts/PaymentsLayout/views/overview/components/index.ts +2 -0
  60. package/src/layouts/PaymentsLayout/views/overview/index.tsx +20 -0
  61. package/src/layouts/PaymentsLayout/views/payments/components/PaymentsList.tsx +277 -0
  62. package/src/layouts/PaymentsLayout/views/payments/components/index.ts +1 -0
  63. package/src/layouts/PaymentsLayout/views/payments/index.tsx +17 -0
  64. package/src/layouts/PaymentsLayout/views/transactions/components/TransactionsList.tsx +273 -0
  65. package/src/layouts/PaymentsLayout/views/transactions/components/index.ts +1 -0
  66. package/src/layouts/PaymentsLayout/views/transactions/index.tsx +17 -0
  67. package/src/utils/logger.ts +9 -0
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Zod schema for Balance
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * * User balance serializer.
6
+ * */
7
+ import { z } from 'zod'
8
+
9
+ /**
10
+ * User balance serializer.
11
+ */
12
+ export const BalanceSchema = z.object({
13
+ balance_usd: z.string(),
14
+ balance_display: z.string(),
15
+ total_deposited: z.string(),
16
+ total_withdrawn: z.string(),
17
+ last_transaction_at: z.iso.datetime().nullable(),
18
+ })
19
+
20
+ /**
21
+ * Infer TypeScript type from Zod schema
22
+ */
23
+ export type Balance = z.infer<typeof BalanceSchema>
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Zod schema for Currency
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * * Currency list serializer.
6
+ * */
7
+ import { z } from 'zod'
8
+
9
+ /**
10
+ * Currency list serializer.
11
+ */
12
+ export const CurrencySchema = z.object({
13
+ code: z.string(),
14
+ name: z.string(),
15
+ token: z.string(),
16
+ network: z.string().nullable(),
17
+ display_name: z.string(),
18
+ symbol: z.string(),
19
+ decimal_places: z.int(),
20
+ is_active: z.boolean(),
21
+ min_amount_usd: z.string(),
22
+ sort_order: z.int(),
23
+ })
24
+
25
+ /**
26
+ * Infer TypeScript type from Zod schema
27
+ */
28
+ export type Currency = z.infer<typeof CurrencySchema>
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Zod schema for PaginatedPaymentListList
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * */
6
+ import { z } from 'zod'
7
+ import { PaymentListSchema } from './PaymentList.schema'
8
+
9
+ export const PaginatedPaymentListListSchema = z.object({
10
+ count: z.int(),
11
+ page: z.int(),
12
+ pages: z.int(),
13
+ page_size: z.int(),
14
+ has_next: z.boolean(),
15
+ has_previous: z.boolean(),
16
+ next_page: z.int().nullable().optional(),
17
+ previous_page: z.int().nullable().optional(),
18
+ results: z.array(PaymentListSchema),
19
+ })
20
+
21
+ /**
22
+ * Infer TypeScript type from Zod schema
23
+ */
24
+ export type PaginatedPaymentListList = z.infer<typeof PaginatedPaymentListListSchema>
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Zod schema for PaymentDetail
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * * Detailed payment information.
6
+ * */
7
+ import { z } from 'zod'
8
+ import * as Enums from '../../enums'
9
+
10
+ /**
11
+ * Detailed payment information.
12
+ */
13
+ export const PaymentDetailSchema = z.object({
14
+ 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),
15
+ internal_payment_id: z.string(),
16
+ amount_usd: z.string(),
17
+ currency_code: z.string(),
18
+ currency_name: z.string(),
19
+ currency_token: z.string(),
20
+ currency_network: z.string(),
21
+ pay_amount: z.string().nullable(),
22
+ actual_amount: z.string().nullable(),
23
+ actual_amount_usd: z.string().nullable(),
24
+ status: z.nativeEnum(Enums.PaymentDetailStatus),
25
+ status_display: z.string(),
26
+ pay_address: z.string().nullable(),
27
+ qr_code_url: z.string().nullable(),
28
+ payment_url: z.url().nullable(),
29
+ transaction_hash: z.string().nullable(),
30
+ explorer_link: z.string().nullable(),
31
+ confirmations_count: z.int(),
32
+ expires_at: z.iso.datetime().nullable(),
33
+ completed_at: z.iso.datetime().nullable(),
34
+ created_at: z.iso.datetime(),
35
+ is_completed: z.boolean(),
36
+ is_failed: z.boolean(),
37
+ is_expired: z.boolean(),
38
+ description: z.string(),
39
+ })
40
+
41
+ /**
42
+ * Infer TypeScript type from Zod schema
43
+ */
44
+ export type PaymentDetail = z.infer<typeof PaymentDetailSchema>
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Zod schema for PaymentList
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * * Payment list item (lighter than detail).
6
+ * */
7
+ import { z } from 'zod'
8
+ import * as Enums from '../../enums'
9
+
10
+ /**
11
+ * Payment list item (lighter than detail).
12
+ */
13
+ export const PaymentListSchema = z.object({
14
+ 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),
15
+ internal_payment_id: z.string(),
16
+ amount_usd: z.string(),
17
+ currency_code: z.string(),
18
+ currency_token: z.string(),
19
+ status: z.nativeEnum(Enums.PaymentListStatus),
20
+ status_display: z.string(),
21
+ created_at: z.iso.datetime(),
22
+ completed_at: z.iso.datetime().nullable(),
23
+ })
24
+
25
+ /**
26
+ * Infer TypeScript type from Zod schema
27
+ */
28
+ export type PaymentList = z.infer<typeof PaymentListSchema>
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Zod schema for Transaction
3
+ *
4
+ * This schema provides runtime validation and type inference.
5
+ * * Transaction serializer.
6
+ * */
7
+ import { z } from 'zod'
8
+ import * as Enums from '../../enums'
9
+
10
+ /**
11
+ * Transaction serializer.
12
+ */
13
+ export const TransactionSchema = z.object({
14
+ 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),
15
+ transaction_type: z.nativeEnum(Enums.TransactionTransactionType),
16
+ type_display: z.string(),
17
+ amount_usd: z.string(),
18
+ amount_display: z.string(),
19
+ balance_after: z.string(),
20
+ payment_id: z.string().nullable(),
21
+ description: z.string(),
22
+ created_at: z.iso.datetime(),
23
+ })
24
+
25
+ /**
26
+ * Infer TypeScript type from Zod schema
27
+ */
28
+ export type Transaction = z.infer<typeof TransactionSchema>
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Zod Schemas - Runtime validation and type inference
3
+ *
4
+ * Auto-generated from OpenAPI specification.
5
+ * Provides runtime validation for API requests and responses.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import { UserSchema } from './schemas'
10
+ *
11
+ * // Validate data
12
+ * const user = UserSchema.parse(data)
13
+ *
14
+ * // Type inference
15
+ * type User = z.infer<typeof UserSchema>
16
+ * ```
17
+ */
18
+
19
+ export * from './Balance.schema'
20
+ export * from './Currency.schema'
21
+ export * from './PaginatedPaymentListList.schema'
22
+ export * from './PaymentDetail.schema'
23
+ export * from './PaymentList.schema'
24
+ export * from './Transaction.schema'
@@ -0,0 +1,131 @@
1
+ /**
2
+ * Global API Instance - Singleton configuration
3
+ *
4
+ * This module provides a global API instance that can be configured once
5
+ * and used throughout your application.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * // Configure once (e.g., in your app entry point)
10
+ * import { configureAPI } from './api-instance'
11
+ *
12
+ * configureAPI({
13
+ * baseUrl: 'https://api.example.com',
14
+ * token: 'your-jwt-token'
15
+ * })
16
+ *
17
+ * // Then use fetchers and hooks anywhere without configuration
18
+ * import { getUsers } from './fetchers'
19
+ * const users = await getUsers({ page: 1 })
20
+ * ```
21
+ *
22
+ * For SSR or multiple instances:
23
+ * ```typescript
24
+ * import { API } from './index'
25
+ * import { getUsers } from './fetchers'
26
+ *
27
+ * const api = new API('https://api.example.com')
28
+ * const users = await getUsers({ page: 1 }, api)
29
+ * ```
30
+ */
31
+
32
+ import { API, type APIOptions } from './index'
33
+
34
+ let globalAPI: API | null = null
35
+
36
+ /**
37
+ * Get the global API instance
38
+ * @throws Error if API is not configured
39
+ */
40
+ export function getAPIInstance(): API {
41
+ if (!globalAPI) {
42
+ throw new Error(
43
+ 'API not configured. Call configureAPI() with your base URL before using fetchers or hooks.\n\n' +
44
+ 'Example:\n' +
45
+ ' import { configureAPI } from "./api-instance"\n' +
46
+ ' configureAPI({ baseUrl: "https://api.example.com" })'
47
+ )
48
+ }
49
+ return globalAPI
50
+ }
51
+
52
+ /**
53
+ * Check if API is configured
54
+ */
55
+ export function isAPIConfigured(): boolean {
56
+ return globalAPI !== null
57
+ }
58
+
59
+ /**
60
+ * Configure the global API instance
61
+ *
62
+ * @param baseUrl - Base URL for the API
63
+ * @param options - Optional configuration (storage, retry, logger)
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * configureAPI({
68
+ * baseUrl: 'https://api.example.com',
69
+ * token: 'jwt-token',
70
+ * options: {
71
+ * retryConfig: { maxRetries: 3 },
72
+ * loggerConfig: { enabled: true }
73
+ * }
74
+ * })
75
+ * ```
76
+ */
77
+ export function configureAPI(config: {
78
+ baseUrl: string
79
+ token?: string
80
+ refreshToken?: string
81
+ options?: APIOptions
82
+ }): API {
83
+ globalAPI = new API(config.baseUrl, config.options)
84
+
85
+ if (config.token) {
86
+ globalAPI.setToken(config.token, config.refreshToken)
87
+ }
88
+
89
+ return globalAPI
90
+ }
91
+
92
+ /**
93
+ * Reconfigure the global API instance with new settings
94
+ * Useful for updating tokens or base URL
95
+ */
96
+ export function reconfigureAPI(updates: {
97
+ baseUrl?: string
98
+ token?: string
99
+ refreshToken?: string
100
+ }): API {
101
+ const instance = getAPIInstance()
102
+
103
+ if (updates.baseUrl) {
104
+ instance.setBaseUrl(updates.baseUrl)
105
+ }
106
+
107
+ if (updates.token) {
108
+ instance.setToken(updates.token, updates.refreshToken)
109
+ }
110
+
111
+ return instance
112
+ }
113
+
114
+ /**
115
+ * Clear tokens from the global API instance
116
+ */
117
+ export function clearAPITokens(): void {
118
+ const instance = getAPIInstance()
119
+ instance.clearTokens()
120
+ }
121
+
122
+ /**
123
+ * Reset the global API instance
124
+ * Useful for testing or logout scenarios
125
+ */
126
+ export function resetAPI(): void {
127
+ if (globalAPI) {
128
+ globalAPI.clearTokens()
129
+ }
130
+ globalAPI = null
131
+ }
@@ -0,0 +1,301 @@
1
+ import { ExtPaymentsPayments } from "./ext_payments__payments";
2
+ import { HttpClientAdapter, FetchAdapter } from "./http";
3
+ import { APIError, NetworkError } from "./errors";
4
+ import { APILogger, type LoggerConfig } from "./logger";
5
+ import { withRetry, type RetryConfig } from "./retry";
6
+
7
+
8
+ /**
9
+ * Async API client for Django CFG API.
10
+ *
11
+ * Usage:
12
+ * ```typescript
13
+ * const client = new APIClient('https://api.example.com');
14
+ * const users = await client.users.list();
15
+ * const post = await client.posts.create(newPost);
16
+ *
17
+ * // Custom HTTP adapter (e.g., Axios)
18
+ * const client = new APIClient('https://api.example.com', {
19
+ * httpClient: new AxiosAdapter()
20
+ * });
21
+ * ```
22
+ */
23
+ export class APIClient {
24
+ private baseUrl: string;
25
+ private httpClient: HttpClientAdapter;
26
+ private logger: APILogger | null = null;
27
+ private retryConfig: RetryConfig | null = null;
28
+
29
+ // Sub-clients
30
+ public ext_payments_payments: ExtPaymentsPayments;
31
+
32
+ constructor(
33
+ baseUrl: string,
34
+ options?: {
35
+ httpClient?: HttpClientAdapter;
36
+ loggerConfig?: Partial<LoggerConfig>;
37
+ retryConfig?: RetryConfig;
38
+ }
39
+ ) {
40
+ this.baseUrl = baseUrl.replace(/\/$/, '');
41
+ this.httpClient = options?.httpClient || new FetchAdapter();
42
+
43
+ // Initialize logger if config provided
44
+ if (options?.loggerConfig !== undefined) {
45
+ this.logger = new APILogger(options.loggerConfig);
46
+ }
47
+
48
+ // Store retry configuration
49
+ if (options?.retryConfig !== undefined) {
50
+ this.retryConfig = options.retryConfig;
51
+ }
52
+
53
+ // Initialize sub-clients
54
+ this.ext_payments_payments = new ExtPaymentsPayments(this);
55
+ }
56
+
57
+ /**
58
+ * Get CSRF token from cookies (for SessionAuthentication).
59
+ *
60
+ * Returns null if cookie doesn't exist (JWT-only auth).
61
+ */
62
+ getCsrfToken(): string | null {
63
+ const name = 'csrftoken';
64
+ const value = `; ${document.cookie}`;
65
+ const parts = value.split(`; ${name}=`);
66
+ if (parts.length === 2) {
67
+ return parts.pop()?.split(';').shift() || null;
68
+ }
69
+ return null;
70
+ }
71
+
72
+ /**
73
+ * Make HTTP request with Django CSRF and session handling.
74
+ * Automatically retries on network errors and 5xx server errors.
75
+ */
76
+ async request<T>(
77
+ method: string,
78
+ path: string,
79
+ options?: {
80
+ params?: Record<string, any>;
81
+ body?: any;
82
+ formData?: FormData;
83
+ headers?: Record<string, string>;
84
+ }
85
+ ): Promise<T> {
86
+ // Wrap request in retry logic if configured
87
+ if (this.retryConfig) {
88
+ return withRetry(() => this._makeRequest<T>(method, path, options), {
89
+ ...this.retryConfig,
90
+ onFailedAttempt: (info) => {
91
+ // Log retry attempts
92
+ if (this.logger) {
93
+ this.logger.warn(
94
+ `Retry attempt ${info.attemptNumber}/${info.retriesLeft + info.attemptNumber} ` +
95
+ `for ${method} ${path}: ${info.error.message}`
96
+ );
97
+ }
98
+ // Call user's onFailedAttempt if provided
99
+ this.retryConfig?.onFailedAttempt?.(info);
100
+ },
101
+ });
102
+ }
103
+
104
+ // No retry configured, make request directly
105
+ return this._makeRequest<T>(method, path, options);
106
+ }
107
+
108
+ /**
109
+ * Internal request method (without retry wrapper).
110
+ * Used by request() method with optional retry logic.
111
+ */
112
+ private async _makeRequest<T>(
113
+ method: string,
114
+ path: string,
115
+ options?: {
116
+ params?: Record<string, any>;
117
+ body?: any;
118
+ formData?: FormData;
119
+ headers?: Record<string, string>;
120
+ }
121
+ ): Promise<T> {
122
+ // Build URL - handle both absolute and relative paths
123
+ // When baseUrl is empty (static builds), path is used as-is (relative to current origin)
124
+ const url = this.baseUrl ? `${this.baseUrl}${path}` : path;
125
+ const startTime = Date.now();
126
+
127
+ // Build headers - start with custom headers from options
128
+ const headers: Record<string, string> = {
129
+ ...(options?.headers || {})
130
+ };
131
+
132
+ // Don't set Content-Type for FormData (browser will set it with boundary)
133
+ if (!options?.formData && !headers['Content-Type']) {
134
+ headers['Content-Type'] = 'application/json';
135
+ }
136
+
137
+ // CSRF not needed - SessionAuthentication not enabled in DRF config
138
+ // Your API uses JWT/Token authentication (no CSRF required)
139
+
140
+ // Log request
141
+ if (this.logger) {
142
+ this.logger.logRequest({
143
+ method,
144
+ url: url,
145
+ headers,
146
+ body: options?.formData || options?.body,
147
+ timestamp: startTime,
148
+ });
149
+ }
150
+
151
+ try {
152
+ // Make request via HTTP adapter
153
+ const response = await this.httpClient.request<T>({
154
+ method,
155
+ url: url,
156
+ headers,
157
+ params: options?.params,
158
+ body: options?.body,
159
+ formData: options?.formData,
160
+ });
161
+
162
+ const duration = Date.now() - startTime;
163
+
164
+ // Check for HTTP errors
165
+ if (response.status >= 400) {
166
+ const error = new APIError(
167
+ response.status,
168
+ response.statusText,
169
+ response.data,
170
+ url
171
+ );
172
+
173
+ // Log error
174
+ if (this.logger) {
175
+ this.logger.logError(
176
+ {
177
+ method,
178
+ url: url,
179
+ headers,
180
+ body: options?.formData || options?.body,
181
+ timestamp: startTime,
182
+ },
183
+ {
184
+ message: error.message,
185
+ statusCode: response.status,
186
+ duration,
187
+ timestamp: Date.now(),
188
+ }
189
+ );
190
+ }
191
+
192
+ throw error;
193
+ }
194
+
195
+ // Log successful response
196
+ if (this.logger) {
197
+ this.logger.logResponse(
198
+ {
199
+ method,
200
+ url: url,
201
+ headers,
202
+ body: options?.formData || options?.body,
203
+ timestamp: startTime,
204
+ },
205
+ {
206
+ status: response.status,
207
+ statusText: response.statusText,
208
+ data: response.data,
209
+ duration,
210
+ timestamp: Date.now(),
211
+ }
212
+ );
213
+ }
214
+
215
+ return response.data as T;
216
+ } catch (error) {
217
+ const duration = Date.now() - startTime;
218
+
219
+ // Re-throw APIError as-is
220
+ if (error instanceof APIError) {
221
+ throw error;
222
+ }
223
+
224
+ // Detect CORS errors and dispatch event
225
+ const isCORSError = error instanceof TypeError &&
226
+ (error.message.toLowerCase().includes('cors') ||
227
+ error.message.toLowerCase().includes('failed to fetch') ||
228
+ error.message.toLowerCase().includes('network request failed'));
229
+
230
+ // Log specific error type first
231
+ if (this.logger) {
232
+ if (isCORSError) {
233
+ this.logger.error(`🚫 CORS Error: ${method} ${url}`);
234
+ this.logger.error(` → ${error instanceof Error ? error.message : String(error)}`);
235
+ this.logger.error(` → Configure security_domains parameter on the server`);
236
+ } else {
237
+ this.logger.error(`⚠️ Network Error: ${method} ${url}`);
238
+ this.logger.error(` → ${error instanceof Error ? error.message : String(error)}`);
239
+ }
240
+ }
241
+
242
+ // Dispatch browser events
243
+ if (typeof window !== 'undefined') {
244
+ try {
245
+ if (isCORSError) {
246
+ // Dispatch CORS-specific error event
247
+ window.dispatchEvent(new CustomEvent('cors-error', {
248
+ detail: {
249
+ url: url,
250
+ method: method,
251
+ error: error instanceof Error ? error.message : String(error),
252
+ timestamp: new Date(),
253
+ },
254
+ bubbles: true,
255
+ cancelable: false,
256
+ }));
257
+ } else {
258
+ // Dispatch generic network error event
259
+ window.dispatchEvent(new CustomEvent('network-error', {
260
+ detail: {
261
+ url: url,
262
+ method: method,
263
+ error: error instanceof Error ? error.message : String(error),
264
+ timestamp: new Date(),
265
+ },
266
+ bubbles: true,
267
+ cancelable: false,
268
+ }));
269
+ }
270
+ } catch (eventError) {
271
+ // Silently fail - event dispatch should never crash the app
272
+ }
273
+ }
274
+
275
+ // Wrap other errors as NetworkError
276
+ const networkError = error instanceof Error
277
+ ? new NetworkError(error.message, url, error)
278
+ : new NetworkError('Unknown error', url);
279
+
280
+ // Detailed logging via logger.logError
281
+ if (this.logger) {
282
+ this.logger.logError(
283
+ {
284
+ method,
285
+ url: url,
286
+ headers,
287
+ body: options?.formData || options?.body,
288
+ timestamp: startTime,
289
+ },
290
+ {
291
+ message: networkError.message,
292
+ duration,
293
+ timestamp: Date.now(),
294
+ }
295
+ );
296
+ }
297
+
298
+ throw networkError;
299
+ }
300
+ }
301
+ }
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Current payment status
3
+ * * `pending` - Pending
4
+ * * `confirming` - Confirming
5
+ * * `confirmed` - Confirmed
6
+ * * `completed` - Completed
7
+ * * `partially_paid` - Partially Paid
8
+ * * `failed` - Failed
9
+ * * `expired` - Expired
10
+ * * `cancelled` - Cancelled
11
+ */
12
+ export enum PaymentDetailStatus {
13
+ PENDING = "pending",
14
+ CONFIRMING = "confirming",
15
+ CONFIRMED = "confirmed",
16
+ COMPLETED = "completed",
17
+ PARTIALLY_PAID = "partially_paid",
18
+ FAILED = "failed",
19
+ EXPIRED = "expired",
20
+ CANCELLED = "cancelled",
21
+ }
22
+
23
+ /**
24
+ * Current payment status
25
+ * * `pending` - Pending
26
+ * * `confirming` - Confirming
27
+ * * `confirmed` - Confirmed
28
+ * * `completed` - Completed
29
+ * * `partially_paid` - Partially Paid
30
+ * * `failed` - Failed
31
+ * * `expired` - Expired
32
+ * * `cancelled` - Cancelled
33
+ */
34
+ export enum PaymentListStatus {
35
+ PENDING = "pending",
36
+ CONFIRMING = "confirming",
37
+ CONFIRMED = "confirmed",
38
+ COMPLETED = "completed",
39
+ PARTIALLY_PAID = "partially_paid",
40
+ FAILED = "failed",
41
+ EXPIRED = "expired",
42
+ CANCELLED = "cancelled",
43
+ }
44
+
45
+ /**
46
+ * Type of transaction
47
+ * * `deposit` - Deposit
48
+ * * `withdrawal` - Withdrawal
49
+ * * `payment` - Payment
50
+ * * `refund` - Refund
51
+ * * `fee` - Fee
52
+ * * `bonus` - Bonus
53
+ * * `adjustment` - Adjustment
54
+ */
55
+ export enum TransactionTransactionType {
56
+ DEPOSIT = "deposit",
57
+ WITHDRAWAL = "withdrawal",
58
+ PAYMENT = "payment",
59
+ REFUND = "refund",
60
+ FEE = "fee",
61
+ BONUS = "bonus",
62
+ ADJUSTMENT = "adjustment",
63
+ }
64
+