@cedros/pay-react 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1731 -0
- package/dist/CedrosContext-B3iCqN6e.js +11 -0
- package/dist/CedrosContext-vX9uqZKp.mjs +1796 -0
- package/dist/ar-LVoQZTFI.js +1 -0
- package/dist/ar-w27mU-4x.mjs +19 -0
- package/dist/bn-BR5Cv1T4.js +1 -0
- package/dist/bn-Ba_k3Kex.mjs +19 -0
- package/dist/components/CedrosPay.d.ts +54 -0
- package/dist/components/CedrosPay.d.ts.map +1 -0
- package/dist/components/CryptoButton.d.ts +26 -0
- package/dist/components/CryptoButton.d.ts.map +1 -0
- package/dist/components/PaymentModal.d.ts +28 -0
- package/dist/components/PaymentModal.d.ts.map +1 -0
- package/dist/components/ProductPrice.d.ts +56 -0
- package/dist/components/ProductPrice.d.ts.map +1 -0
- package/dist/components/PurchaseButton.d.ts +52 -0
- package/dist/components/PurchaseButton.d.ts.map +1 -0
- package/dist/components/StripeButton.d.ts +27 -0
- package/dist/components/StripeButton.d.ts.map +1 -0
- package/dist/context/CedrosContext.d.ts +46 -0
- package/dist/context/CedrosContext.d.ts.map +1 -0
- package/dist/context/ThemeContext.d.ts +30 -0
- package/dist/context/ThemeContext.d.ts.map +1 -0
- package/dist/context/index.d.ts +3 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/crypto-only.d.ts +33 -0
- package/dist/crypto-only.d.ts.map +1 -0
- package/dist/crypto-only.js +1 -0
- package/dist/crypto-only.mjs +35 -0
- package/dist/de-CoZiPFN7.mjs +19 -0
- package/dist/de-pQxy-oD1.js +1 -0
- package/dist/en-CSsJl3nf.mjs +19 -0
- package/dist/en-D-uY3ltT.js +1 -0
- package/dist/es-BWGIBp2f.mjs +19 -0
- package/dist/es-D24cg8dD.js +1 -0
- package/dist/fil-BOBft9G-.js +1 -0
- package/dist/fil-Czo27xmj.mjs +19 -0
- package/dist/fr-Ct9ub8Fa.js +1 -0
- package/dist/fr-DQ-2ThBv.mjs +19 -0
- package/dist/he-DpV1WnBQ.mjs +19 -0
- package/dist/he-DtQqRKRq.js +1 -0
- package/dist/hooks/usePaymentMode.d.ts +39 -0
- package/dist/hooks/usePaymentMode.d.ts.map +1 -0
- package/dist/hooks/useRefundVerification.d.ts +30 -0
- package/dist/hooks/useRefundVerification.d.ts.map +1 -0
- package/dist/hooks/useStripeCheckout.d.ts +20 -0
- package/dist/hooks/useStripeCheckout.d.ts.map +1 -0
- package/dist/hooks/useX402Payment.d.ts +24 -0
- package/dist/hooks/useX402Payment.d.ts.map +1 -0
- package/dist/i18n/index.d.ts +107 -0
- package/dist/i18n/index.d.ts.map +1 -0
- package/dist/i18n/useTranslation.d.ts +55 -0
- package/dist/i18n/useTranslation.d.ts.map +1 -0
- package/dist/id-BJMqsu19.mjs +19 -0
- package/dist/id-CiM2mL7C.js +1 -0
- package/dist/in-BxgxKLQH.mjs +19 -0
- package/dist/in-Bzcjmxcc.js +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +626 -0
- package/dist/it-Blb_pIJl.js +1 -0
- package/dist/it-DZFFPALf.mjs +19 -0
- package/dist/jp-9NHyIuwY.js +1 -0
- package/dist/jp-ZExTrlHK.mjs +19 -0
- package/dist/kr-DHX3i4Ht.mjs +19 -0
- package/dist/kr-DvzJ-0yX.js +1 -0
- package/dist/managers/ManagerCache.d.ts +49 -0
- package/dist/managers/ManagerCache.d.ts.map +1 -0
- package/dist/managers/RouteDiscoveryManager.d.ts +72 -0
- package/dist/managers/RouteDiscoveryManager.d.ts.map +1 -0
- package/dist/managers/StripeManager.d.ts +110 -0
- package/dist/managers/StripeManager.d.ts.map +1 -0
- package/dist/managers/WalletManager.d.ts +150 -0
- package/dist/managers/WalletManager.d.ts.map +1 -0
- package/dist/managers/X402Manager.d.ts +176 -0
- package/dist/managers/X402Manager.d.ts.map +1 -0
- package/dist/ms-BOAu5pUB.js +1 -0
- package/dist/ms-Cv1fdIi2.mjs +19 -0
- package/dist/nl-BmGonsKb.mjs +19 -0
- package/dist/nl-WHh_DfO8.js +1 -0
- package/dist/pa-B7kIhZCF.js +1 -0
- package/dist/pa-BfwcJIar.mjs +19 -0
- package/dist/pay-react.css +1 -0
- package/dist/pl-DE5IB9xv.mjs +19 -0
- package/dist/pl-H0hBKdvF.js +1 -0
- package/dist/pt-CLzkqDzf.mjs +19 -0
- package/dist/pt-DwGrViQ3.js +1 -0
- package/dist/ru-CB2m0UDT.js +1 -0
- package/dist/ru-DM6-oUR0.mjs +19 -0
- package/dist/stripe-only.d.ts +31 -0
- package/dist/stripe-only.d.ts.map +1 -0
- package/dist/stripe-only.js +1 -0
- package/dist/stripe-only.mjs +33 -0
- package/dist/styles-D3XGpsqb.js +1 -0
- package/dist/styles-zgmHs6Hs.mjs +1601 -0
- package/dist/ta-A5HnrGb5.mjs +19 -0
- package/dist/ta-CAS197uN.js +1 -0
- package/dist/telemetry.d.ts +27 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +1 -0
- package/dist/telemetry.mjs +127 -0
- package/dist/testing/__tests__/providers.test.d.ts +10 -0
- package/dist/testing/__tests__/providers.test.d.ts.map +1 -0
- package/dist/testing/helpers.d.ts +242 -0
- package/dist/testing/helpers.d.ts.map +1 -0
- package/dist/testing/index.d.ts +12 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +1 -0
- package/dist/testing/index.mjs +374 -0
- package/dist/testing/mocks.d.ts +225 -0
- package/dist/testing/mocks.d.ts.map +1 -0
- package/dist/testing/providers.d.ts +89 -0
- package/dist/testing/providers.d.ts.map +1 -0
- package/dist/th-3fbB3Ytp.mjs +19 -0
- package/dist/th-Cpz2cFcg.js +1 -0
- package/dist/tr-BrgfFFdq.mjs +19 -0
- package/dist/tr-hQrEFk86.js +1 -0
- package/dist/types/componentOptions.d.ts +138 -0
- package/dist/types/componentOptions.d.ts.map +1 -0
- package/dist/types/errors.d.ts +213 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/index.d.ts +248 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/uk-0hFun_g_.mjs +19 -0
- package/dist/uk-DrK2Sv8C.js +1 -0
- package/dist/ur-CaOjJXai.mjs +19 -0
- package/dist/ur-D5-7mN9a.js +1 -0
- package/dist/utils/__tests__/cspHelper.test.d.ts +9 -0
- package/dist/utils/__tests__/cspHelper.test.d.ts.map +1 -0
- package/dist/utils/__tests__/fetchWithTimeout.test.d.ts +11 -0
- package/dist/utils/__tests__/fetchWithTimeout.test.d.ts.map +1 -0
- package/dist/utils/cartHelpers.d.ts +105 -0
- package/dist/utils/cartHelpers.d.ts.map +1 -0
- package/dist/utils/circuitBreaker.d.ts +112 -0
- package/dist/utils/circuitBreaker.d.ts.map +1 -0
- package/dist/utils/couponHelpers.d.ts +50 -0
- package/dist/utils/couponHelpers.d.ts.map +1 -0
- package/dist/utils/cspHelper.d.ts +162 -0
- package/dist/utils/cspHelper.d.ts.map +1 -0
- package/dist/utils/deprecation.d.ts +128 -0
- package/dist/utils/deprecation.d.ts.map +1 -0
- package/dist/utils/errorHandling.d.ts +30 -0
- package/dist/utils/errorHandling.d.ts.map +1 -0
- package/dist/utils/errorMessages.d.ts +47 -0
- package/dist/utils/errorMessages.d.ts.map +1 -0
- package/dist/utils/errorParser.d.ts +37 -0
- package/dist/utils/errorParser.d.ts.map +1 -0
- package/dist/utils/eventEmitter.d.ts +119 -0
- package/dist/utils/eventEmitter.d.ts.map +1 -0
- package/dist/utils/exponentialBackoff.d.ts +104 -0
- package/dist/utils/exponentialBackoff.d.ts.map +1 -0
- package/dist/utils/fetchWithTimeout.d.ts +13 -0
- package/dist/utils/fetchWithTimeout.d.ts.map +1 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +76 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/modalStyles.d.ts +13 -0
- package/dist/utils/modalStyles.d.ts.map +1 -0
- package/dist/utils/rateLimiter.d.ts +88 -0
- package/dist/utils/rateLimiter.d.ts.map +1 -0
- package/dist/utils/requestDeduplication.d.ts +124 -0
- package/dist/utils/requestDeduplication.d.ts.map +1 -0
- package/dist/utils/securityValidation.d.ts +75 -0
- package/dist/utils/securityValidation.d.ts.map +1 -0
- package/dist/utils/solanaCheck.d.ts +10 -0
- package/dist/utils/solanaCheck.d.ts.map +1 -0
- package/dist/utils/telemetry.d.ts +277 -0
- package/dist/utils/telemetry.d.ts.map +1 -0
- package/dist/utils/tokenMintValidator.d.ts +77 -0
- package/dist/utils/tokenMintValidator.d.ts.map +1 -0
- package/dist/utils/uuid.d.ts +13 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/validateConfig.d.ts +13 -0
- package/dist/utils/validateConfig.d.ts.map +1 -0
- package/dist/utils/walletDetection.d.ts +6 -0
- package/dist/utils/walletDetection.d.ts.map +1 -0
- package/dist/utils/walletPool.d.ts +57 -0
- package/dist/utils/walletPool.d.ts.map +1 -0
- package/dist/uuid-C0iMjdcc.js +1 -0
- package/dist/uuid-UlzrVY8Y.mjs +17 -0
- package/dist/vn-0nlIZFLP.mjs +19 -0
- package/dist/vn-B_iut9YL.js +1 -0
- package/dist/walletDetection-JZR3UCOa.mjs +27 -0
- package/dist/walletDetection-bNmV5ItZ.js +1 -0
- package/dist/zh-B4Endr1F.mjs +19 -0
- package/dist/zh-PR82dCHr.js +1 -0
- package/package.json +139 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Circuit Breaker Pattern Implementation
|
|
3
|
+
*
|
|
4
|
+
* Prevents cascading failures by "opening the circuit" when a service is failing,
|
|
5
|
+
* giving it time to recover before attempting requests again.
|
|
6
|
+
*
|
|
7
|
+
* States:
|
|
8
|
+
* - CLOSED: Normal operation, requests pass through
|
|
9
|
+
* - OPEN: Service is failing, requests fail immediately
|
|
10
|
+
* - HALF_OPEN: Testing if service has recovered
|
|
11
|
+
*
|
|
12
|
+
* Flow:
|
|
13
|
+
* 1. CLOSED → OPEN: After N consecutive failures
|
|
14
|
+
* 2. OPEN → HALF_OPEN: After timeout expires
|
|
15
|
+
* 3. HALF_OPEN → CLOSED: If request succeeds
|
|
16
|
+
* 4. HALF_OPEN → OPEN: If request fails
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const breaker = createCircuitBreaker({ failureThreshold: 5, timeout: 30000 });
|
|
21
|
+
*
|
|
22
|
+
* const result = await breaker.execute(async () => {
|
|
23
|
+
* return await fetch('/api/payment');
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare enum CircuitState {
|
|
28
|
+
CLOSED = "CLOSED",
|
|
29
|
+
OPEN = "OPEN",
|
|
30
|
+
HALF_OPEN = "HALF_OPEN"
|
|
31
|
+
}
|
|
32
|
+
export interface CircuitBreakerConfig {
|
|
33
|
+
/** Number of consecutive failures before opening circuit */
|
|
34
|
+
failureThreshold: number;
|
|
35
|
+
/** Time in ms to wait before attempting recovery (OPEN → HALF_OPEN) */
|
|
36
|
+
timeout: number;
|
|
37
|
+
/** Optional name for logging/debugging */
|
|
38
|
+
name?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface CircuitBreakerStats {
|
|
41
|
+
state: CircuitState;
|
|
42
|
+
failures: number;
|
|
43
|
+
successes: number;
|
|
44
|
+
rejections: number;
|
|
45
|
+
lastFailureTime: number | null;
|
|
46
|
+
lastSuccessTime: number | null;
|
|
47
|
+
}
|
|
48
|
+
export interface CircuitBreaker {
|
|
49
|
+
/** Execute a function with circuit breaker protection */
|
|
50
|
+
execute: <T>(fn: () => Promise<T>) => Promise<T>;
|
|
51
|
+
/** Get current circuit state */
|
|
52
|
+
getState: () => CircuitState;
|
|
53
|
+
/** Get circuit breaker statistics */
|
|
54
|
+
getStats: () => CircuitBreakerStats;
|
|
55
|
+
/** Manually reset circuit to CLOSED state */
|
|
56
|
+
reset: () => void;
|
|
57
|
+
/** Manually trip circuit to OPEN state */
|
|
58
|
+
trip: () => void;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Error thrown when circuit breaker is OPEN
|
|
62
|
+
*/
|
|
63
|
+
export declare class CircuitBreakerOpenError extends Error {
|
|
64
|
+
constructor(message: string);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Create a circuit breaker instance
|
|
68
|
+
*
|
|
69
|
+
* @param config - Circuit breaker configuration
|
|
70
|
+
* @returns Circuit breaker instance
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const paymentBreaker = createCircuitBreaker({
|
|
75
|
+
* failureThreshold: 5,
|
|
76
|
+
* timeout: 30000,
|
|
77
|
+
* name: 'payment-service',
|
|
78
|
+
* });
|
|
79
|
+
*
|
|
80
|
+
* try {
|
|
81
|
+
* const result = await paymentBreaker.execute(async () => {
|
|
82
|
+
* return await createPaymentSession();
|
|
83
|
+
* });
|
|
84
|
+
* } catch (error) {
|
|
85
|
+
* if (error instanceof CircuitBreakerOpenError) {
|
|
86
|
+
* console.error('Payment service is down, please try again later');
|
|
87
|
+
* }
|
|
88
|
+
* }
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare function createCircuitBreaker(config: CircuitBreakerConfig): CircuitBreaker;
|
|
92
|
+
/**
|
|
93
|
+
* Preset circuit breaker configurations
|
|
94
|
+
*/
|
|
95
|
+
export declare const CIRCUIT_BREAKER_PRESETS: {
|
|
96
|
+
/** Strict: Opens quickly (3 failures), long timeout (60s) */
|
|
97
|
+
readonly STRICT: {
|
|
98
|
+
readonly failureThreshold: 3;
|
|
99
|
+
readonly timeout: 60000;
|
|
100
|
+
};
|
|
101
|
+
/** Standard: Balanced settings (5 failures, 30s timeout) */
|
|
102
|
+
readonly STANDARD: {
|
|
103
|
+
readonly failureThreshold: 5;
|
|
104
|
+
readonly timeout: 30000;
|
|
105
|
+
};
|
|
106
|
+
/** Lenient: Tolerates more failures (10 failures, 15s timeout) */
|
|
107
|
+
readonly LENIENT: {
|
|
108
|
+
readonly failureThreshold: 10;
|
|
109
|
+
readonly timeout: 15000;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
//# sourceMappingURL=circuitBreaker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"circuitBreaker.d.ts","sourceRoot":"","sources":["../../src/utils/circuitBreaker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAIH,oBAAY,YAAY;IACtB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,SAAS,cAAc;CACxB;AAED,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,gBAAgB,EAAE,MAAM,CAAC;IACzB,uEAAuE;IACvE,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,YAAY,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED,MAAM,WAAW,cAAc;IAC7B,yDAAyD;IACzD,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACjD,gCAAgC;IAChC,QAAQ,EAAE,MAAM,YAAY,CAAC;IAC7B,qCAAqC;IACrC,QAAQ,EAAE,MAAM,mBAAmB,CAAC;IACpC,6CAA6C;IAC7C,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,0CAA0C;IAC1C,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,oBAAoB,GAAG,cAAc,CA6IjF;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB;IAClC,6DAA6D;;;;;IAE7D,4DAA4D;;;;;IAE5D,kEAAkE;;;;;CAE1D,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { SettlementResponse } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Parse coupon codes from metadata
|
|
4
|
+
*
|
|
5
|
+
* Parses comma-separated coupon codes from the coupon_codes field
|
|
6
|
+
*
|
|
7
|
+
* @param metadata - Metadata object from settlement response or cart callback
|
|
8
|
+
* @returns Array of coupon codes that were applied
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* // Multiple coupons
|
|
12
|
+
* parseCouponCodes({ coupon_codes: "SITE10,CRYPTO5AUTO,SAVE20" })
|
|
13
|
+
* // Returns: ["SITE10", "CRYPTO5AUTO", "SAVE20"]
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* // Single coupon
|
|
17
|
+
* parseCouponCodes({ coupon_codes: "SAVE20" })
|
|
18
|
+
* // Returns: ["SAVE20"]
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // No coupons applied
|
|
22
|
+
* parseCouponCodes({})
|
|
23
|
+
* // Returns: []
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseCouponCodes(metadata?: Record<string, string | undefined> | SettlementResponse["metadata"]): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Format coupon codes for display
|
|
28
|
+
*
|
|
29
|
+
* @param coupons - Array of coupon codes
|
|
30
|
+
* @param separator - Separator string (default: ", ")
|
|
31
|
+
* @returns Formatted string
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* formatCouponCodes(["SITE10", "CRYPTO5AUTO", "SAVE20"])
|
|
35
|
+
* // Returns: "SITE10, CRYPTO5AUTO, SAVE20"
|
|
36
|
+
*/
|
|
37
|
+
export declare function formatCouponCodes(coupons: string[], separator?: string): string;
|
|
38
|
+
/**
|
|
39
|
+
* Calculate total discount percentage
|
|
40
|
+
*
|
|
41
|
+
* @param originalAmount - Original price before discounts
|
|
42
|
+
* @param discountedAmount - Final price after discounts
|
|
43
|
+
* @returns Discount percentage (0-100)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* calculateDiscountPercentage(100, 75)
|
|
47
|
+
* // Returns: 25.0
|
|
48
|
+
*/
|
|
49
|
+
export declare function calculateDiscountPercentage(originalAmount: number, discountedAmount: number): number;
|
|
50
|
+
//# sourceMappingURL=couponHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"couponHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/couponHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,kBAAkB,CAAC,UAAU,CAAC,GAC7E,MAAM,EAAE,CASV;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EAAE,EACjB,SAAS,GAAE,MAAa,GACvB,MAAM,CAER;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,2BAA2B,CACzC,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAIR"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { SolanaCluster } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* CSP generation options
|
|
4
|
+
*/
|
|
5
|
+
export interface CSPConfig {
|
|
6
|
+
/**
|
|
7
|
+
* Solana network cluster
|
|
8
|
+
* Determines which Solana RPC endpoints to include
|
|
9
|
+
*/
|
|
10
|
+
solanaCluster?: SolanaCluster;
|
|
11
|
+
/**
|
|
12
|
+
* Custom Solana RPC endpoint URL
|
|
13
|
+
* If provided, this domain will be added to connect-src
|
|
14
|
+
* @example "https://mainnet.helius-rpc.com"
|
|
15
|
+
*/
|
|
16
|
+
solanaEndpoint?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Additional custom RPC providers
|
|
19
|
+
* Common providers: Helius, QuickNode, Alchemy, Ankr
|
|
20
|
+
* @example ["https://*.helius-rpc.com", "https://*.quicknode.pro"]
|
|
21
|
+
*/
|
|
22
|
+
customRpcProviders?: string[];
|
|
23
|
+
/**
|
|
24
|
+
* Whether to include 'unsafe-inline' and 'unsafe-eval' in script-src
|
|
25
|
+
* Required for some frameworks (Next.js, etc.)
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
allowUnsafeScripts?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Additional domains to include in script-src
|
|
31
|
+
* @example ["https://cdn.example.com"]
|
|
32
|
+
*/
|
|
33
|
+
additionalScriptSrc?: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Additional domains to include in connect-src
|
|
36
|
+
* @example ["https://api.example.com"]
|
|
37
|
+
*/
|
|
38
|
+
additionalConnectSrc?: string[];
|
|
39
|
+
/**
|
|
40
|
+
* Additional domains to include in frame-src
|
|
41
|
+
* @example ["https://embed.example.com"]
|
|
42
|
+
*/
|
|
43
|
+
additionalFrameSrc?: string[];
|
|
44
|
+
/**
|
|
45
|
+
* Whether to include Stripe directives
|
|
46
|
+
* Set to false if only using crypto payments
|
|
47
|
+
* @default true
|
|
48
|
+
*/
|
|
49
|
+
includeStripe?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Generated CSP directives
|
|
53
|
+
*/
|
|
54
|
+
export interface CSPDirectives {
|
|
55
|
+
scriptSrc: string[];
|
|
56
|
+
connectSrc: string[];
|
|
57
|
+
frameSrc: string[];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* CSP output format for different frameworks
|
|
61
|
+
*/
|
|
62
|
+
export type CSPFormat = 'header' | 'meta' | 'nextjs' | 'helmet' | 'nginx' | 'directives';
|
|
63
|
+
/**
|
|
64
|
+
* Generate CSP directives for Cedros Pay
|
|
65
|
+
*
|
|
66
|
+
* @param config - CSP configuration options
|
|
67
|
+
* @returns Object containing script-src, connect-src, and frame-src arrays
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* const directives = generateCSPDirectives({
|
|
72
|
+
* solanaCluster: 'mainnet-beta',
|
|
73
|
+
* solanaEndpoint: 'https://mainnet.helius-rpc.com',
|
|
74
|
+
* allowUnsafeScripts: true, // Required for Next.js
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function generateCSPDirectives(config?: CSPConfig): CSPDirectives;
|
|
79
|
+
/**
|
|
80
|
+
* Format CSP directives for different frameworks and environments
|
|
81
|
+
*
|
|
82
|
+
* @param directives - CSP directives from generateCSPDirectives()
|
|
83
|
+
* @param format - Output format
|
|
84
|
+
* @returns Formatted CSP string or object
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```typescript
|
|
88
|
+
* const directives = generateCSPDirectives({ solanaCluster: 'mainnet-beta' });
|
|
89
|
+
*
|
|
90
|
+
* // HTTP Header format
|
|
91
|
+
* const header = formatCSP(directives, 'header');
|
|
92
|
+
* // "script-src 'self' https://js.stripe.com; connect-src 'self' ..."
|
|
93
|
+
*
|
|
94
|
+
* // Next.js config format
|
|
95
|
+
* const nextjs = formatCSP(directives, 'nextjs');
|
|
96
|
+
*
|
|
97
|
+
* // Express helmet format
|
|
98
|
+
* const helmet = formatCSP(directives, 'helmet');
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function formatCSP(directives: CSPDirectives, format?: CSPFormat): string | Record<string, string[]>;
|
|
102
|
+
/**
|
|
103
|
+
* Generate CSP string for Cedros Pay (convenience function)
|
|
104
|
+
*
|
|
105
|
+
* Combines generateCSPDirectives() and formatCSP() into a single call.
|
|
106
|
+
*
|
|
107
|
+
* @param config - CSP configuration options
|
|
108
|
+
* @param format - Output format (default: 'header')
|
|
109
|
+
* @returns Formatted CSP string or object
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* // Quick CSP generation for HTTP headers
|
|
114
|
+
* const csp = generateCSP({
|
|
115
|
+
* solanaCluster: 'mainnet-beta',
|
|
116
|
+
* solanaEndpoint: 'https://mainnet.helius-rpc.com',
|
|
117
|
+
* allowUnsafeScripts: true,
|
|
118
|
+
* });
|
|
119
|
+
* // "script-src 'self' 'unsafe-inline' 'unsafe-eval' https://js.stripe.com; ..."
|
|
120
|
+
*
|
|
121
|
+
* // For Express helmet
|
|
122
|
+
* const helmetCSP = generateCSP({ solanaCluster: 'mainnet-beta' }, 'helmet');
|
|
123
|
+
* app.use(helmet.contentSecurityPolicy({ directives: helmetCSP }));
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function generateCSP(config?: CSPConfig, format?: CSPFormat): string | Record<string, string[]>;
|
|
127
|
+
/**
|
|
128
|
+
* Common RPC provider patterns for convenience
|
|
129
|
+
*/
|
|
130
|
+
export declare const RPC_PROVIDERS: {
|
|
131
|
+
readonly HELIUS: "https://*.helius-rpc.com";
|
|
132
|
+
readonly QUICKNODE: "https://*.quicknode.pro";
|
|
133
|
+
readonly ALCHEMY: "https://*.alchemy.com";
|
|
134
|
+
readonly ANKR: "https://rpc.ankr.com";
|
|
135
|
+
readonly TRITON: "https://*.rpcpool.com";
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Preset CSP configurations for common scenarios
|
|
139
|
+
*/
|
|
140
|
+
export declare const CSP_PRESETS: {
|
|
141
|
+
/**
|
|
142
|
+
* Mainnet production with custom RPC (recommended)
|
|
143
|
+
*/
|
|
144
|
+
readonly MAINNET_CUSTOM_RPC: (rpcEndpoint: string) => CSPConfig;
|
|
145
|
+
/**
|
|
146
|
+
* Mainnet with Next.js (requires unsafe-inline/eval)
|
|
147
|
+
*/
|
|
148
|
+
readonly MAINNET_NEXTJS: (rpcEndpoint?: string) => CSPConfig;
|
|
149
|
+
/**
|
|
150
|
+
* Devnet for testing
|
|
151
|
+
*/
|
|
152
|
+
readonly DEVNET: () => CSPConfig;
|
|
153
|
+
/**
|
|
154
|
+
* Crypto-only payments (no Stripe)
|
|
155
|
+
*/
|
|
156
|
+
readonly CRYPTO_ONLY: (rpcEndpoint?: string) => CSPConfig;
|
|
157
|
+
/**
|
|
158
|
+
* Stripe-only payments (no Solana)
|
|
159
|
+
*/
|
|
160
|
+
readonly STRIPE_ONLY: () => CSPConfig;
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=cspHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cspHelper.d.ts","sourceRoot":"","sources":["../../src/utils/cspHelper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,aAAa,CAAC,EAAE,aAAa,CAAC;IAE9B;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE9B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE/B;;;OAGG;IACH,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAEhC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE9B;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,SAAS,GACjB,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,YAAY,CAAC;AA+BjB;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,GAAE,SAAc,GAAG,aAAa,CAmE3E;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,SAAS,CACvB,UAAU,EAAE,aAAa,EACzB,MAAM,GAAE,SAAoB,GAC3B,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CA4CnC;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,WAAW,CACzB,MAAM,GAAE,SAAc,EACtB,MAAM,GAAE,SAAoB,GAC3B,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAGnC;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;CAMhB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,WAAW;IACtB;;OAEG;+CAC+B,MAAM,KAAG,SAAS;IAMpD;;OAEG;4CAC4B,MAAM,KAAG,SAAS;IAMjD;;OAEG;2BACS,SAAS;IAKrB;;OAEG;yCACyB,MAAM,KAAG,SAAS;IAM9C;;OAEG;gCACc,SAAS;CAMlB,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deprecation utilities for managing API lifecycle
|
|
3
|
+
*
|
|
4
|
+
* Provides helpers for marking APIs as deprecated with clear migration paths.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Deprecation severity levels
|
|
8
|
+
*/
|
|
9
|
+
export declare enum DeprecationLevel {
|
|
10
|
+
/** Soft warning - API works but has a better alternative */
|
|
11
|
+
WARNING = "warning",
|
|
12
|
+
/** Notice - API will be removed in next major version */
|
|
13
|
+
NOTICE = "notice",
|
|
14
|
+
/** Critical - API will be removed soon, migration urgent */
|
|
15
|
+
CRITICAL = "critical"
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Deprecation metadata
|
|
19
|
+
*/
|
|
20
|
+
export interface DeprecationInfo {
|
|
21
|
+
/** What is being deprecated */
|
|
22
|
+
feature: string;
|
|
23
|
+
/** Why it's deprecated */
|
|
24
|
+
reason: string;
|
|
25
|
+
/** What to use instead */
|
|
26
|
+
replacement?: string;
|
|
27
|
+
/** Version when it will be removed */
|
|
28
|
+
removalVersion?: string;
|
|
29
|
+
/** Additional migration notes */
|
|
30
|
+
migrationGuide?: string;
|
|
31
|
+
/** Severity level */
|
|
32
|
+
level: DeprecationLevel;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Log a deprecation warning (once per session)
|
|
36
|
+
*
|
|
37
|
+
* @param info - Deprecation details
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* logDeprecation({
|
|
42
|
+
* feature: 'StripeManager class export',
|
|
43
|
+
* reason: 'Direct class imports create breaking changes',
|
|
44
|
+
* replacement: 'Use IStripeManager interface from context',
|
|
45
|
+
* removalVersion: '3.0.0',
|
|
46
|
+
* level: DeprecationLevel.NOTICE
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function logDeprecation(info: DeprecationInfo): void;
|
|
51
|
+
/**
|
|
52
|
+
* Mark a function as deprecated with automatic warnings
|
|
53
|
+
*
|
|
54
|
+
* @param fn - Function to deprecate
|
|
55
|
+
* @param info - Deprecation details
|
|
56
|
+
* @returns Wrapped function that logs deprecation warnings
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* export const oldFunction = deprecate(
|
|
61
|
+
* (x: number) => x * 2,
|
|
62
|
+
* {
|
|
63
|
+
* feature: 'oldFunction',
|
|
64
|
+
* reason: 'Use the new API instead',
|
|
65
|
+
* replacement: 'newFunction',
|
|
66
|
+
* removalVersion: '3.0.0',
|
|
67
|
+
* level: DeprecationLevel.NOTICE
|
|
68
|
+
* }
|
|
69
|
+
* );
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function deprecate<T extends (...args: any[]) => any>(fn: T, info: DeprecationInfo): T;
|
|
73
|
+
/**
|
|
74
|
+
* Mark a class as deprecated
|
|
75
|
+
*
|
|
76
|
+
* Returns a Proxy that logs deprecation warnings on construction
|
|
77
|
+
*
|
|
78
|
+
* @param Class - Class to deprecate
|
|
79
|
+
* @param info - Deprecation details
|
|
80
|
+
* @returns Proxied class that warns on instantiation
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* export const OldManager = deprecateClass(
|
|
85
|
+
* OldManagerImpl,
|
|
86
|
+
* {
|
|
87
|
+
* feature: 'OldManager class',
|
|
88
|
+
* reason: 'Use interface from context instead',
|
|
89
|
+
* replacement: 'useCedrosContext().manager',
|
|
90
|
+
* removalVersion: '3.0.0',
|
|
91
|
+
* level: DeprecationLevel.CRITICAL
|
|
92
|
+
* }
|
|
93
|
+
* );
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function deprecateClass<T extends new (...args: any[]) => any>(Class: T, info: DeprecationInfo): T;
|
|
97
|
+
/**
|
|
98
|
+
* Create a deprecation notice for an export
|
|
99
|
+
*
|
|
100
|
+
* Use this to create a deprecated re-export that warns users
|
|
101
|
+
*
|
|
102
|
+
* @param value - Value to re-export
|
|
103
|
+
* @param info - Deprecation details
|
|
104
|
+
* @returns Proxied value that warns on access
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* // In index.ts
|
|
109
|
+
* export const DeprecatedExport = deprecateExport(
|
|
110
|
+
* ActualImplementation,
|
|
111
|
+
* {
|
|
112
|
+
* feature: 'DeprecatedExport',
|
|
113
|
+
* reason: 'Moved to new package',
|
|
114
|
+
* replacement: '@new-package/export',
|
|
115
|
+
* removalVersion: '3.0.0',
|
|
116
|
+
* level: DeprecationLevel.NOTICE
|
|
117
|
+
* }
|
|
118
|
+
* );
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function deprecateExport<T>(value: T, info: DeprecationInfo): T;
|
|
122
|
+
/**
|
|
123
|
+
* Reset deprecation warnings (useful for testing)
|
|
124
|
+
*
|
|
125
|
+
* @internal
|
|
126
|
+
*/
|
|
127
|
+
export declare function resetDeprecationWarnings(): void;
|
|
128
|
+
//# sourceMappingURL=deprecation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deprecation.d.ts","sourceRoot":"","sources":["../../src/utils/deprecation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,oBAAY,gBAAgB;IAC1B,4DAA4D;IAC5D,OAAO,YAAY;IACnB,yDAAyD;IACzD,MAAM,WAAW;IACjB,4DAA4D;IAC5D,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iCAAiC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,qBAAqB;IACrB,KAAK,EAAE,gBAAgB,CAAC;CACzB;AAKD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAmC1D;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,wBAAgB,SAAS,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACzD,EAAE,EAAE,CAAC,EACL,IAAI,EAAE,eAAe,GACpB,CAAC,CAMH;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,wBAAgB,cAAc,CAAC,CAAC,SAAS,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAClE,KAAK,EAAE,CAAC,EACR,IAAI,EAAE,eAAe,GACpB,CAAC,CAQH;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,eAAe,GAAG,CAAC,CA2BrE;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format error into user-friendly message string
|
|
3
|
+
*
|
|
4
|
+
* Consolidates the repetitive `error instanceof Error ? error.message : fallback`
|
|
5
|
+
* pattern used throughout the codebase into a single utility.
|
|
6
|
+
*
|
|
7
|
+
* @param error - The error to format (can be Error, string, or unknown type)
|
|
8
|
+
* @param fallback - Fallback message if error cannot be converted to string
|
|
9
|
+
* @returns User-friendly error message string
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* formatError(new Error('Failed'), 'Unknown error') // Returns: 'Failed'
|
|
13
|
+
* formatError('Custom error', 'Unknown error') // Returns: 'Custom error'
|
|
14
|
+
* formatError(null, 'Unknown error') // Returns: 'Unknown error'
|
|
15
|
+
*/
|
|
16
|
+
export declare function formatError(error: unknown, fallback: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Parse error response from failed HTTP requests
|
|
19
|
+
*
|
|
20
|
+
* Shared utility for consistent error handling across managers.
|
|
21
|
+
* Tries JSON parsing first, falls back to plain text if that fails.
|
|
22
|
+
* Supports both standard error responses and X402Response verification errors.
|
|
23
|
+
*
|
|
24
|
+
* @param response - The failed HTTP response
|
|
25
|
+
* @param defaultMessage - Fallback message if parsing fails
|
|
26
|
+
* @param parseVerificationError - If true, handle X402Response verification errors with detailed mapping
|
|
27
|
+
* @returns User-friendly error message
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseErrorResponse(response: Response, defaultMessage: string, parseVerificationError?: boolean): Promise<string>;
|
|
30
|
+
//# sourceMappingURL=errorHandling.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorHandling.d.ts","sourceRoot":"","sources":["../../src/utils/errorHandling.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQpE;AAgBD;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,QAAQ,EAAE,QAAQ,EAClB,cAAc,EAAE,MAAM,EACtB,sBAAsB,GAAE,OAAe,GACtC,OAAO,CAAC,MAAM,CAAC,CAwBjB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User-Friendly Error Messages
|
|
3
|
+
*
|
|
4
|
+
* Provides contextual, actionable error messages for all payment error codes.
|
|
5
|
+
* Messages are designed to:
|
|
6
|
+
* - Be clear and non-technical
|
|
7
|
+
* - Provide actionable next steps
|
|
8
|
+
* - Avoid embarrassing the business
|
|
9
|
+
* - Enable user self-service
|
|
10
|
+
* - Support internationalization
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* User-friendly error message with actionable guidance
|
|
14
|
+
*/
|
|
15
|
+
export interface ErrorMessage {
|
|
16
|
+
/** Short user-friendly message */
|
|
17
|
+
message: string;
|
|
18
|
+
/** Actionable next steps for the user */
|
|
19
|
+
action?: string;
|
|
20
|
+
/** Support-friendly technical detail (optional, for error reporting) */
|
|
21
|
+
technicalHint?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Error message map: error code string -> User-friendly message with actions
|
|
25
|
+
*
|
|
26
|
+
* Translation key format: `errors.{error_code}.{message|action}`
|
|
27
|
+
* Example: errors.insufficient_funds_token.message
|
|
28
|
+
*
|
|
29
|
+
* Note: Uses string keys instead of enum to avoid circular dependency with types/errors.ts
|
|
30
|
+
*/
|
|
31
|
+
export declare const ERROR_MESSAGES: Record<string, ErrorMessage>;
|
|
32
|
+
/**
|
|
33
|
+
* Get user-friendly error message for an error code string
|
|
34
|
+
*
|
|
35
|
+
* @param code - Payment error code (as string)
|
|
36
|
+
* @returns User-friendly error message with action
|
|
37
|
+
*/
|
|
38
|
+
export declare function getUserFriendlyError(code: string): ErrorMessage;
|
|
39
|
+
/**
|
|
40
|
+
* Format error for display to user
|
|
41
|
+
*
|
|
42
|
+
* @param code - Payment error code (as string)
|
|
43
|
+
* @param includeAction - Whether to include the action guidance (default: true)
|
|
44
|
+
* @returns Formatted error string
|
|
45
|
+
*/
|
|
46
|
+
export declare function formatUserError(code: string, includeAction?: boolean): string;
|
|
47
|
+
//# sourceMappingURL=errorMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMessages.d.ts","sourceRoot":"","sources":["../../src/utils/errorMessages.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAkTvD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAM/D;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,GAAE,OAAc,GAAG,MAAM,CAMnF"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { PaymentError } from '../types/errors';
|
|
2
|
+
/**
|
|
3
|
+
* Parse JSON error response from backend API
|
|
4
|
+
*
|
|
5
|
+
* Expects structured error format from backend:
|
|
6
|
+
* {
|
|
7
|
+
* error: {
|
|
8
|
+
* code: "insufficient_funds_token",
|
|
9
|
+
* message: "Insufficient token balance",
|
|
10
|
+
* retryable: false,
|
|
11
|
+
* details?: { ... }
|
|
12
|
+
* }
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* @param response - Fetch Response object
|
|
16
|
+
* @returns PaymentError with structured error information
|
|
17
|
+
*/
|
|
18
|
+
export declare function parseErrorResponse(response: Response): Promise<PaymentError>;
|
|
19
|
+
/**
|
|
20
|
+
* Check if an error is retryable
|
|
21
|
+
*
|
|
22
|
+
* Convenience function to check if an error (of any type) is retryable.
|
|
23
|
+
*
|
|
24
|
+
* @param error - Error to check
|
|
25
|
+
* @returns true if error is a PaymentError and is retryable
|
|
26
|
+
*/
|
|
27
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Get user-friendly error message
|
|
30
|
+
*
|
|
31
|
+
* Extracts a user-friendly message from any error type.
|
|
32
|
+
*
|
|
33
|
+
* @param error - Error to extract message from
|
|
34
|
+
* @returns User-friendly error message
|
|
35
|
+
*/
|
|
36
|
+
export declare function getUserErrorMessage(error: unknown): string;
|
|
37
|
+
//# sourceMappingURL=errorParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorParser.d.ts","sourceRoot":"","sources":["../../src/utils/errorParser.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAwC,MAAM,iBAAiB,CAAC;AAErF;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,CA8BlF;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAExD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAU1D"}
|