@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,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payment Lifecycle Event Emitter
|
|
3
|
+
*
|
|
4
|
+
* Provides browser-native CustomEvent emission for payment lifecycle tracking.
|
|
5
|
+
* Enables integration with analytics platforms (Google Analytics, Mixpanel, etc.)
|
|
6
|
+
* outside the React component tree.
|
|
7
|
+
*
|
|
8
|
+
* Events:
|
|
9
|
+
* - cedros:payment:start - Payment attempt initiated (button clicked)
|
|
10
|
+
* - cedros:wallet:connect - Wallet connection initiated
|
|
11
|
+
* - cedros:wallet:connected - Wallet successfully connected
|
|
12
|
+
* - cedros:wallet:error - Wallet connection failed
|
|
13
|
+
* - cedros:payment:processing - Payment transaction in progress
|
|
14
|
+
* - cedros:payment:success - Payment completed successfully
|
|
15
|
+
* - cedros:payment:error - Payment failed
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Payment method type
|
|
19
|
+
*/
|
|
20
|
+
export type PaymentMethod = 'stripe' | 'crypto';
|
|
21
|
+
/**
|
|
22
|
+
* Wallet provider type
|
|
23
|
+
*/
|
|
24
|
+
export type WalletProvider = 'phantom' | 'solflare' | 'backpack' | string;
|
|
25
|
+
/**
|
|
26
|
+
* Base event detail interface
|
|
27
|
+
*/
|
|
28
|
+
interface BaseEventDetail {
|
|
29
|
+
timestamp: number;
|
|
30
|
+
method: PaymentMethod;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Payment start event detail
|
|
34
|
+
*/
|
|
35
|
+
export interface PaymentStartDetail extends BaseEventDetail {
|
|
36
|
+
resource?: string;
|
|
37
|
+
itemCount?: number;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Wallet connect event detail
|
|
41
|
+
*/
|
|
42
|
+
export interface WalletConnectDetail {
|
|
43
|
+
timestamp: number;
|
|
44
|
+
wallet: WalletProvider;
|
|
45
|
+
publicKey?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Wallet error event detail
|
|
49
|
+
*/
|
|
50
|
+
export interface WalletErrorDetail {
|
|
51
|
+
timestamp: number;
|
|
52
|
+
wallet?: WalletProvider;
|
|
53
|
+
error: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Payment processing event detail
|
|
57
|
+
*/
|
|
58
|
+
export interface PaymentProcessingDetail extends BaseEventDetail {
|
|
59
|
+
resource?: string;
|
|
60
|
+
itemCount?: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Payment success event detail
|
|
64
|
+
*/
|
|
65
|
+
export interface PaymentSuccessDetail extends BaseEventDetail {
|
|
66
|
+
transactionId: string;
|
|
67
|
+
resource?: string;
|
|
68
|
+
itemCount?: number;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Payment error event detail
|
|
72
|
+
*/
|
|
73
|
+
export interface PaymentErrorDetail extends BaseEventDetail {
|
|
74
|
+
error: string;
|
|
75
|
+
resource?: string;
|
|
76
|
+
itemCount?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Event name constants
|
|
80
|
+
*/
|
|
81
|
+
export declare const CEDROS_EVENTS: {
|
|
82
|
+
readonly PAYMENT_START: "cedros:payment:start";
|
|
83
|
+
readonly WALLET_CONNECT: "cedros:wallet:connect";
|
|
84
|
+
readonly WALLET_CONNECTED: "cedros:wallet:connected";
|
|
85
|
+
readonly WALLET_ERROR: "cedros:wallet:error";
|
|
86
|
+
readonly PAYMENT_PROCESSING: "cedros:payment:processing";
|
|
87
|
+
readonly PAYMENT_SUCCESS: "cedros:payment:success";
|
|
88
|
+
readonly PAYMENT_ERROR: "cedros:payment:error";
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Emit payment start event
|
|
92
|
+
*/
|
|
93
|
+
export declare function emitPaymentStart(method: PaymentMethod, resource?: string, itemCount?: number): void;
|
|
94
|
+
/**
|
|
95
|
+
* Emit wallet connect event (connection initiated)
|
|
96
|
+
*/
|
|
97
|
+
export declare function emitWalletConnect(wallet: WalletProvider): void;
|
|
98
|
+
/**
|
|
99
|
+
* Emit wallet connected event (connection successful)
|
|
100
|
+
*/
|
|
101
|
+
export declare function emitWalletConnected(wallet: WalletProvider, publicKey: string): void;
|
|
102
|
+
/**
|
|
103
|
+
* Emit wallet error event
|
|
104
|
+
*/
|
|
105
|
+
export declare function emitWalletError(error: string, wallet?: WalletProvider): void;
|
|
106
|
+
/**
|
|
107
|
+
* Emit payment processing event
|
|
108
|
+
*/
|
|
109
|
+
export declare function emitPaymentProcessing(method: PaymentMethod, resource?: string, itemCount?: number): void;
|
|
110
|
+
/**
|
|
111
|
+
* Emit payment success event
|
|
112
|
+
*/
|
|
113
|
+
export declare function emitPaymentSuccess(method: PaymentMethod, transactionId: string, resource?: string, itemCount?: number): void;
|
|
114
|
+
/**
|
|
115
|
+
* Emit payment error event
|
|
116
|
+
*/
|
|
117
|
+
export declare function emitPaymentError(method: PaymentMethod, error: string, resource?: string, itemCount?: number): void;
|
|
118
|
+
export {};
|
|
119
|
+
//# sourceMappingURL=eventEmitter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventEmitter.d.ts","sourceRoot":"","sources":["../../src/utils/eventEmitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;AAE1E;;GAEG;AACH,UAAU,eAAe;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,aAAa,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,uBAAwB,SAAQ,eAAe;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;CAQhB,CAAC;AAsBX;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,aAAa,EACrB,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAK9D;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,cAAc,EACtB,SAAS,EAAE,MAAM,GAChB,IAAI,CAMN;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc,GAAG,IAAI,CAM5E;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI,CAON;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,MAAM,EACrB,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI,CAQN;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,MAAM,GACjB,IAAI,CAQN"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exponential Backoff and Retry Logic
|
|
3
|
+
*
|
|
4
|
+
* Implements retry logic with exponential backoff for failed requests.
|
|
5
|
+
* Prevents hammering failing services and gives them time to recover.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Exponential delay with jitter
|
|
9
|
+
* - Configurable max retries and max delay
|
|
10
|
+
* - Automatic retry for retryable errors
|
|
11
|
+
* - Respects Retry-After header (429 responses)
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const result = await retryWithBackoff(
|
|
16
|
+
* async () => await fetch('/api/payment'),
|
|
17
|
+
* { maxRetries: 3, initialDelayMs: 1000 }
|
|
18
|
+
* );
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export interface RetryConfig {
|
|
22
|
+
/** Maximum number of retry attempts (default: 3) */
|
|
23
|
+
maxRetries?: number;
|
|
24
|
+
/** Initial delay in milliseconds (default: 1000) */
|
|
25
|
+
initialDelayMs?: number;
|
|
26
|
+
/** Backoff multiplier (default: 2) */
|
|
27
|
+
backoffFactor?: number;
|
|
28
|
+
/** Maximum delay in milliseconds (default: 30000) */
|
|
29
|
+
maxDelayMs?: number;
|
|
30
|
+
/** Add random jitter to prevent thundering herd (default: true) */
|
|
31
|
+
jitter?: boolean;
|
|
32
|
+
/** Custom function to determine if error is retryable */
|
|
33
|
+
shouldRetry?: (error: Error, attempt: number) => boolean;
|
|
34
|
+
/** Optional name for logging */
|
|
35
|
+
name?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface RetryStats {
|
|
38
|
+
attempts: number;
|
|
39
|
+
totalDelay: number;
|
|
40
|
+
lastError: Error | null;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Retry a function with exponential backoff
|
|
44
|
+
*
|
|
45
|
+
* @param fn - Async function to retry
|
|
46
|
+
* @param config - Retry configuration
|
|
47
|
+
* @returns Promise that resolves with function result
|
|
48
|
+
* @throws Last error if all retries fail
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Retry payment creation with default config
|
|
53
|
+
* const session = await retryWithBackoff(
|
|
54
|
+
* async () => await createPaymentSession(),
|
|
55
|
+
* { name: 'create-session' }
|
|
56
|
+
* );
|
|
57
|
+
*
|
|
58
|
+
* // Custom retry policy
|
|
59
|
+
* const result = await retryWithBackoff(
|
|
60
|
+
* async () => await fetchQuote(),
|
|
61
|
+
* {
|
|
62
|
+
* maxRetries: 5,
|
|
63
|
+
* initialDelayMs: 500,
|
|
64
|
+
* backoffFactor: 1.5,
|
|
65
|
+
* shouldRetry: (error) => error.message.includes('TEMP'),
|
|
66
|
+
* }
|
|
67
|
+
* );
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export declare function retryWithBackoff<T>(fn: () => Promise<T>, config?: RetryConfig): Promise<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Preset retry configurations
|
|
73
|
+
*/
|
|
74
|
+
export declare const RETRY_PRESETS: {
|
|
75
|
+
/** Quick retries for transient errors (3 retries, 1s initial, 2x backoff) */
|
|
76
|
+
readonly QUICK: {
|
|
77
|
+
readonly maxRetries: 3;
|
|
78
|
+
readonly initialDelayMs: 1000;
|
|
79
|
+
readonly backoffFactor: 2;
|
|
80
|
+
readonly maxDelayMs: 10000;
|
|
81
|
+
};
|
|
82
|
+
/** Standard retries (3 retries, 2s initial, 2x backoff) */
|
|
83
|
+
readonly STANDARD: {
|
|
84
|
+
readonly maxRetries: 3;
|
|
85
|
+
readonly initialDelayMs: 2000;
|
|
86
|
+
readonly backoffFactor: 2;
|
|
87
|
+
readonly maxDelayMs: 30000;
|
|
88
|
+
};
|
|
89
|
+
/** Aggressive retries for critical operations (5 retries, 500ms initial) */
|
|
90
|
+
readonly AGGRESSIVE: {
|
|
91
|
+
readonly maxRetries: 5;
|
|
92
|
+
readonly initialDelayMs: 500;
|
|
93
|
+
readonly backoffFactor: 1.5;
|
|
94
|
+
readonly maxDelayMs: 15000;
|
|
95
|
+
};
|
|
96
|
+
/** Patient retries for slow backends (5 retries, 5s initial) */
|
|
97
|
+
readonly PATIENT: {
|
|
98
|
+
readonly maxRetries: 5;
|
|
99
|
+
readonly initialDelayMs: 5000;
|
|
100
|
+
readonly backoffFactor: 2;
|
|
101
|
+
readonly maxDelayMs: 60000;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=exponentialBackoff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exponentialBackoff.d.ts","sourceRoot":"","sources":["../../src/utils/exponentialBackoff.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,MAAM,WAAW,WAAW;IAC1B,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,sCAAsC;IACtC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qDAAqD;IACrD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,mEAAmE;IACnE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,yDAAyD;IACzD,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC;IACzD,gCAAgC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,KAAK,GAAG,IAAI,CAAC;CACzB;AA8ED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,MAAM,GAAE,WAAgB,GACvB,OAAO,CAAC,CAAC,CAAC,CAuDZ;AAED;;GAEG;AACH,eAAO,MAAM,aAAa;IACxB,6EAA6E;;;;;;;IAO7E,2DAA2D;;;;;;;IAO3D,4EAA4E;;;;;;;IAO5E,gEAAgE;;;;;;;CAOxD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default timeout for HTTP requests (30 seconds)
|
|
3
|
+
*/
|
|
4
|
+
export declare const DEFAULT_FETCH_TIMEOUT_MS = 30000;
|
|
5
|
+
/**
|
|
6
|
+
* Fetch with timeout utility
|
|
7
|
+
*
|
|
8
|
+
* Wraps fetch() with an AbortController to enforce timeout
|
|
9
|
+
* Properly handles external AbortSignals while adding timeout functionality
|
|
10
|
+
* Default timeout: 30 seconds
|
|
11
|
+
*/
|
|
12
|
+
export declare function fetchWithTimeout(url: string, options?: RequestInit, timeoutMs?: number): Promise<Response>;
|
|
13
|
+
//# sourceMappingURL=fetchWithTimeout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetchWithTimeout.d.ts","sourceRoot":"","sources":["../../src/utils/fetchWithTimeout.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,wBAAwB,QAAQ,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CACpC,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,WAAgB,EACzB,SAAS,GAAE,MAAiC,GAC3C,OAAO,CAAC,QAAQ,CAAC,CA8CnB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { validateConfig } from './validateConfig';
|
|
2
|
+
export { parseCouponCodes, formatCouponCodes, calculateDiscountPercentage } from './couponHelpers';
|
|
3
|
+
export { isCartCheckout, normalizeCartItems, type NormalizedCartItem } from './cartHelpers';
|
|
4
|
+
export { formatError, parseErrorResponse } from './errorHandling';
|
|
5
|
+
export { ERROR_MESSAGES, getUserFriendlyError, formatUserError, type ErrorMessage, } from './errorMessages';
|
|
6
|
+
export { deduplicateRequest, createDedupedClickHandler, isButtonInCooldown, setButtonCooldown, isDuplicateRequest, markRequestProcessed, getInFlightRequest, trackInFlightRequest, clearDeduplicationCache, getDeduplicationStats, DEFAULT_COOLDOWN_MS, DEFAULT_DEDUP_WINDOW_MS, } from './requestDeduplication';
|
|
7
|
+
export { getModalCloseButtonStyles } from './modalStyles';
|
|
8
|
+
export { createWalletPool, WalletPool } from './walletPool';
|
|
9
|
+
export { CEDROS_EVENTS, emitPaymentStart, emitWalletConnect, emitWalletConnected, emitWalletError, emitPaymentProcessing, emitPaymentSuccess, emitPaymentError, type PaymentMethod, type WalletProvider, type PaymentStartDetail, type WalletConnectDetail, type WalletErrorDetail, type PaymentProcessingDetail, type PaymentSuccessDetail, type PaymentErrorDetail, } from './eventEmitter';
|
|
10
|
+
export { parseErrorResponse as parseStructuredErrorResponse, isRetryableError, getUserErrorMessage, } from './errorParser';
|
|
11
|
+
export { createRateLimiter, RATE_LIMITER_PRESETS, type RateLimiter, type RateLimiterConfig, } from './rateLimiter';
|
|
12
|
+
export { createCircuitBreaker, CircuitState, CircuitBreakerOpenError, CIRCUIT_BREAKER_PRESETS, type CircuitBreaker, type CircuitBreakerConfig, type CircuitBreakerStats, } from './circuitBreaker';
|
|
13
|
+
export { retryWithBackoff, RETRY_PRESETS, type RetryConfig, type RetryStats, } from './exponentialBackoff';
|
|
14
|
+
export { generateCSP, generateCSPDirectives, formatCSP, RPC_PROVIDERS, CSP_PRESETS, type CSPConfig, type CSPDirectives, type CSPFormat, } from './cspHelper';
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,2BAA2B,EAAE,MAAM,iBAAiB,CAAC;AACnG,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC5F,OAAO,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,eAAe,EACf,KAAK,YAAY,GAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,EACf,qBAAqB,EACrB,kBAAkB,EAClB,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GACxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,kBAAkB,IAAI,4BAA4B,EAClD,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,KAAK,WAAW,EAChB,KAAK,iBAAiB,GACvB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,uBAAuB,EACvB,KAAK,cAAc,EACnB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,KAAK,WAAW,EAChB,KAAK,UAAU,GAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,SAAS,EACT,aAAa,EACb,WAAW,EACX,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,SAAS,GACf,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured logging with configurable log levels
|
|
3
|
+
*
|
|
4
|
+
* Supports filtering logs by severity level to control verbosity.
|
|
5
|
+
* Production deployments should use LogLevel.ERROR or LogLevel.WARN.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Log severity levels (lowest to highest)
|
|
9
|
+
*/
|
|
10
|
+
export declare enum LogLevel {
|
|
11
|
+
DEBUG = 0,// Detailed debug information
|
|
12
|
+
INFO = 1,// Informational messages
|
|
13
|
+
WARN = 2,// Warning messages
|
|
14
|
+
ERROR = 3,// Error messages
|
|
15
|
+
SILENT = 4
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Logger configuration
|
|
19
|
+
*/
|
|
20
|
+
export interface LoggerConfig {
|
|
21
|
+
level: LogLevel;
|
|
22
|
+
prefix?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Structured logger with level-based filtering
|
|
26
|
+
*/
|
|
27
|
+
export declare class Logger {
|
|
28
|
+
private config;
|
|
29
|
+
constructor(config: LoggerConfig);
|
|
30
|
+
/**
|
|
31
|
+
* Update the log level dynamically
|
|
32
|
+
*/
|
|
33
|
+
setLevel(level: LogLevel): void;
|
|
34
|
+
/**
|
|
35
|
+
* Get the current log level
|
|
36
|
+
*/
|
|
37
|
+
getLevel(): LogLevel;
|
|
38
|
+
/**
|
|
39
|
+
* Debug-level logging (most verbose)
|
|
40
|
+
* Use for detailed debugging information
|
|
41
|
+
*/
|
|
42
|
+
debug(...args: unknown[]): void;
|
|
43
|
+
/**
|
|
44
|
+
* Info-level logging
|
|
45
|
+
* Use for general informational messages
|
|
46
|
+
*/
|
|
47
|
+
info(...args: unknown[]): void;
|
|
48
|
+
/**
|
|
49
|
+
* Warning-level logging
|
|
50
|
+
* Use for potentially problematic situations
|
|
51
|
+
*/
|
|
52
|
+
warn(...args: unknown[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Error-level logging
|
|
55
|
+
* Use for error conditions
|
|
56
|
+
*/
|
|
57
|
+
error(...args: unknown[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* Internal log method with formatting
|
|
60
|
+
*/
|
|
61
|
+
private log;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Get or create the default logger instance
|
|
65
|
+
*/
|
|
66
|
+
export declare function getLogger(): Logger;
|
|
67
|
+
/**
|
|
68
|
+
* Set the global logger instance
|
|
69
|
+
* Called by CedrosProvider to apply user configuration
|
|
70
|
+
*/
|
|
71
|
+
export declare function setLogger(logger: Logger): void;
|
|
72
|
+
/**
|
|
73
|
+
* Create a new logger instance with custom configuration
|
|
74
|
+
*/
|
|
75
|
+
export declare function createLogger(config: LoggerConfig): Logger;
|
|
76
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,IAAI,CAAI,6BAA6B;IAC1C,IAAI,IAAI,CAAK,yBAAyB;IACtC,IAAI,IAAI,CAAK,mBAAmB;IAChC,KAAK,IAAI,CAAI,iBAAiB;IAC9B,MAAM,IAAI;CACX;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAe;gBAEjB,MAAM,EAAE,YAAY;IAIhC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B;;OAEG;IACH,QAAQ,IAAI,QAAQ;IAIpB;;;OAGG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/B;;;OAGG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM9B;;;OAGG;IACH,IAAI,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM9B;;;OAGG;IACH,KAAK,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,IAAI;IAM/B;;OAEG;IACH,OAAO,CAAC,GAAG;CAKZ;AAkBD;;GAEG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAQlC;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAE9C;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAEzD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Shared modal UI utilities
|
|
4
|
+
*
|
|
5
|
+
* Provides consistent styling for modal components to avoid duplication
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Get styles for modal close button (×)
|
|
9
|
+
* @param surfaceText - Text color from theme tokens
|
|
10
|
+
* @returns CSS properties for close button
|
|
11
|
+
*/
|
|
12
|
+
export declare function getModalCloseButtonStyles(surfaceText: string): CSSProperties;
|
|
13
|
+
//# sourceMappingURL=modalStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modalStyles.d.ts","sourceRoot":"","sources":["../../src/utils/modalStyles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE3C;;;;GAIG;AAEH;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAW5E"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rate Limiter - Token Bucket Algorithm
|
|
3
|
+
*
|
|
4
|
+
* Prevents spamming backend with payment requests by enforcing
|
|
5
|
+
* a maximum number of requests per time window.
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Token bucket algorithm (allows bursts, enforces long-term rate)
|
|
9
|
+
* - Automatic token refill over time
|
|
10
|
+
* - Thread-safe (uses timestamps, not intervals)
|
|
11
|
+
* - Memory efficient (no timers or intervals)
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* const limiter = createRateLimiter({ maxRequests: 10, windowMs: 60000 });
|
|
16
|
+
*
|
|
17
|
+
* if (limiter.tryConsume()) {
|
|
18
|
+
* await makePaymentRequest();
|
|
19
|
+
* } else {
|
|
20
|
+
* console.error('Rate limit exceeded');
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export interface RateLimiterConfig {
|
|
25
|
+
/** Maximum number of requests allowed per time window */
|
|
26
|
+
maxRequests: number;
|
|
27
|
+
/** Time window in milliseconds */
|
|
28
|
+
windowMs: number;
|
|
29
|
+
}
|
|
30
|
+
export interface RateLimiter {
|
|
31
|
+
/** Try to consume a token. Returns true if request is allowed, false if rate limited */
|
|
32
|
+
tryConsume: () => boolean;
|
|
33
|
+
/** Get remaining tokens available */
|
|
34
|
+
getAvailableTokens: () => number;
|
|
35
|
+
/** Get time until next token refill (in ms) */
|
|
36
|
+
getTimeUntilRefill: () => number;
|
|
37
|
+
/** Reset the rate limiter (useful for testing or manual override) */
|
|
38
|
+
reset: () => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates a rate limiter using token bucket algorithm
|
|
42
|
+
*
|
|
43
|
+
* @param config - Rate limiter configuration
|
|
44
|
+
* @returns Rate limiter instance
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Allow 5 payment requests per minute
|
|
49
|
+
* const paymentLimiter = createRateLimiter({
|
|
50
|
+
* maxRequests: 5,
|
|
51
|
+
* windowMs: 60000
|
|
52
|
+
* });
|
|
53
|
+
*
|
|
54
|
+
* async function handlePayment() {
|
|
55
|
+
* if (!paymentLimiter.tryConsume()) {
|
|
56
|
+
* throw new Error('Rate limit exceeded. Please wait before trying again.');
|
|
57
|
+
* }
|
|
58
|
+
* await processPayment();
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
export declare function createRateLimiter(config: RateLimiterConfig): RateLimiter;
|
|
63
|
+
/**
|
|
64
|
+
* Preset rate limiter configurations for common use cases
|
|
65
|
+
*/
|
|
66
|
+
export declare const RATE_LIMITER_PRESETS: {
|
|
67
|
+
/** 10 requests per minute - recommended for payment requests */
|
|
68
|
+
readonly PAYMENT: {
|
|
69
|
+
readonly maxRequests: 10;
|
|
70
|
+
readonly windowMs: 60000;
|
|
71
|
+
};
|
|
72
|
+
/** 30 requests per minute - for quote fetching */
|
|
73
|
+
readonly QUOTE: {
|
|
74
|
+
readonly maxRequests: 30;
|
|
75
|
+
readonly windowMs: 60000;
|
|
76
|
+
};
|
|
77
|
+
/** 5 requests per minute - strict limit for sensitive operations */
|
|
78
|
+
readonly STRICT: {
|
|
79
|
+
readonly maxRequests: 5;
|
|
80
|
+
readonly windowMs: 60000;
|
|
81
|
+
};
|
|
82
|
+
/** 100 requests per minute - permissive for UI interactions */
|
|
83
|
+
readonly PERMISSIVE: {
|
|
84
|
+
readonly maxRequests: 100;
|
|
85
|
+
readonly windowMs: 60000;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
//# sourceMappingURL=rateLimiter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rateLimiter.d.ts","sourceRoot":"","sources":["../../src/utils/rateLimiter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,MAAM,WAAW,iBAAiB;IAChC,yDAAyD;IACzD,WAAW,EAAE,MAAM,CAAC;IACpB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,wFAAwF;IACxF,UAAU,EAAE,MAAM,OAAO,CAAC;IAC1B,qCAAqC;IACrC,kBAAkB,EAAE,MAAM,MAAM,CAAC;IACjC,+CAA+C;IAC/C,kBAAkB,EAAE,MAAM,MAAM,CAAC;IACjC,qEAAqE;IACrE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW,CA8ExE;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB;IAC/B,gEAAgE;;;;;IAEhE,kDAAkD;;;;;IAElD,oEAAoE;;;;;IAEpE,+DAA+D;;;;;CAEvD,CAAC"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Request Deduplication Utilities
|
|
3
|
+
*
|
|
4
|
+
* Prevents duplicate API calls when users rapidly click payment buttons.
|
|
5
|
+
* Includes:
|
|
6
|
+
* - Request deduplication (prevents same request ID from firing multiple times)
|
|
7
|
+
* - Button cooldown (0.2s timeout to prevent accidental double-clicks)
|
|
8
|
+
* - In-flight request tracking
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Default cooldown period (200ms = 0.2s)
|
|
12
|
+
* Prevents accidental double-clicks while not feeling laggy
|
|
13
|
+
*/
|
|
14
|
+
export declare const DEFAULT_COOLDOWN_MS = 200;
|
|
15
|
+
/**
|
|
16
|
+
* Default deduplication window (2 seconds)
|
|
17
|
+
* Prevents identical requests within this time window
|
|
18
|
+
*/
|
|
19
|
+
export declare const DEFAULT_DEDUP_WINDOW_MS = 2000;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a button is currently in cooldown
|
|
22
|
+
*
|
|
23
|
+
* @param buttonId - Unique button identifier
|
|
24
|
+
* @returns true if button is in cooldown, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
export declare function isButtonInCooldown(buttonId: string): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Set button cooldown
|
|
29
|
+
*
|
|
30
|
+
* @param buttonId - Unique button identifier
|
|
31
|
+
* @param cooldownMs - Cooldown duration in milliseconds (default: 200ms)
|
|
32
|
+
*/
|
|
33
|
+
export declare function setButtonCooldown(buttonId: string, cooldownMs?: number): void;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a request is a duplicate
|
|
36
|
+
*
|
|
37
|
+
* @param requestId - Unique request identifier
|
|
38
|
+
* @param windowMs - Deduplication window in milliseconds (default: 2000ms)
|
|
39
|
+
* @returns true if request is a duplicate, false otherwise
|
|
40
|
+
*/
|
|
41
|
+
export declare function isDuplicateRequest(requestId: string, windowMs?: number): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Mark a request as processed
|
|
44
|
+
*
|
|
45
|
+
* @param requestId - Unique request identifier
|
|
46
|
+
*/
|
|
47
|
+
export declare function markRequestProcessed(requestId: string): void;
|
|
48
|
+
/**
|
|
49
|
+
* Check if a request is currently in flight
|
|
50
|
+
*
|
|
51
|
+
* @param requestId - Unique request identifier
|
|
52
|
+
* @returns Promise if request is in flight, null otherwise
|
|
53
|
+
*/
|
|
54
|
+
export declare function getInFlightRequest<T>(requestId: string): Promise<T> | null;
|
|
55
|
+
/**
|
|
56
|
+
* Track an in-flight request
|
|
57
|
+
*
|
|
58
|
+
* @param requestId - Unique request identifier
|
|
59
|
+
* @param promise - Promise representing the request
|
|
60
|
+
* @returns The same promise (for chaining)
|
|
61
|
+
*/
|
|
62
|
+
export declare function trackInFlightRequest<T>(requestId: string, promise: Promise<T>): Promise<T>;
|
|
63
|
+
/**
|
|
64
|
+
* Deduplicate a request
|
|
65
|
+
*
|
|
66
|
+
* Combines duplicate detection, in-flight tracking, and request execution.
|
|
67
|
+
* If an identical request is already in flight, returns the existing promise.
|
|
68
|
+
* If the request was recently completed, blocks it.
|
|
69
|
+
*
|
|
70
|
+
* @param requestId - Unique request identifier
|
|
71
|
+
* @param executor - Function that executes the request
|
|
72
|
+
* @param options - Deduplication options
|
|
73
|
+
* @returns Promise with request result
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* const result = await deduplicateRequest(
|
|
78
|
+
* `stripe-session-${resourceId}`,
|
|
79
|
+
* () => createStripeSession(resourceId)
|
|
80
|
+
* );
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function deduplicateRequest<T>(requestId: string, executor: () => Promise<T>, options?: {
|
|
84
|
+
windowMs?: number;
|
|
85
|
+
throwOnDuplicate?: boolean;
|
|
86
|
+
}): Promise<T>;
|
|
87
|
+
/**
|
|
88
|
+
* Create a deduplicated button click handler
|
|
89
|
+
*
|
|
90
|
+
* Wraps a click handler with deduplication and cooldown protection.
|
|
91
|
+
*
|
|
92
|
+
* @param buttonId - Unique button identifier
|
|
93
|
+
* @param handler - Original click handler
|
|
94
|
+
* @param options - Deduplication options
|
|
95
|
+
* @returns Wrapped click handler
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* const handleClick = createDedupedClickHandler(
|
|
100
|
+
* 'pay-button-stripe',
|
|
101
|
+
* async () => {
|
|
102
|
+
* const session = await createStripeSession(resourceId);
|
|
103
|
+
* window.location.href = session.url;
|
|
104
|
+
* }
|
|
105
|
+
* );
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export declare function createDedupedClickHandler(buttonId: string, handler: () => Promise<void> | void, options?: {
|
|
109
|
+
cooldownMs?: number;
|
|
110
|
+
deduplicationWindowMs?: number;
|
|
111
|
+
}): () => Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Clear all deduplication caches (for testing)
|
|
114
|
+
*/
|
|
115
|
+
export declare function clearDeduplicationCache(): void;
|
|
116
|
+
/**
|
|
117
|
+
* Get deduplication stats (for debugging)
|
|
118
|
+
*/
|
|
119
|
+
export declare function getDeduplicationStats(): {
|
|
120
|
+
cachedRequests: number;
|
|
121
|
+
inFlightRequests: number;
|
|
122
|
+
activeCooldowns: number;
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=requestDeduplication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requestDeduplication.d.ts","sourceRoot":"","sources":["../../src/utils/requestDeduplication.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAsBH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAE5C;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAc5D;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,GAAE,MAA4B,GAAG,IAAI,CAGlG;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAgC,GAAG,OAAO,CAezG;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAE5D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,IAAI,CAE1E;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAY1F;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC1B,OAAO,GAAE;IACP,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CACvB,GACL,OAAO,CAAC,CAAC,CAAC,CAuBZ;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,EACnC,OAAO,GAAE;IACP,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAC3B,GACL,MAAM,OAAO,CAAC,IAAI,CAAC,CAmCrB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,IAAI,CAI9C;AAED;;GAEG;AACH,wBAAgB,qBAAqB;;;;EAMpC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Security Validation Utilities
|
|
3
|
+
*
|
|
4
|
+
* Provides runtime security checks and recommendations for Cedros Pay deployments.
|
|
5
|
+
* Helps developers identify potential security issues during development.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Security check result
|
|
9
|
+
*/
|
|
10
|
+
export interface SecurityCheckResult {
|
|
11
|
+
passed: boolean;
|
|
12
|
+
severity: 'info' | 'warning' | 'error';
|
|
13
|
+
message: string;
|
|
14
|
+
recommendation?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Security validation report
|
|
18
|
+
*/
|
|
19
|
+
export interface SecurityReport {
|
|
20
|
+
checks: SecurityCheckResult[];
|
|
21
|
+
overallStatus: 'secure' | 'warnings' | 'vulnerable';
|
|
22
|
+
summary: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Run all security checks and generate a report
|
|
26
|
+
*
|
|
27
|
+
* @returns Security validation report with all checks
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { validateSecurity } from '@cedros/pay-react';
|
|
32
|
+
*
|
|
33
|
+
* const report = validateSecurity();
|
|
34
|
+
* console.log(report.summary);
|
|
35
|
+
*
|
|
36
|
+
* if (report.overallStatus === 'vulnerable') {
|
|
37
|
+
* console.error('Security issues detected:');
|
|
38
|
+
* report.checks.forEach(check => {
|
|
39
|
+
* if (!check.passed) {
|
|
40
|
+
* console.error(`- ${check.message}`);
|
|
41
|
+
* if (check.recommendation) {
|
|
42
|
+
* console.error(` Recommendation: ${check.recommendation}`);
|
|
43
|
+
* }
|
|
44
|
+
* }
|
|
45
|
+
* });
|
|
46
|
+
* }
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateSecurity(): SecurityReport;
|
|
50
|
+
/**
|
|
51
|
+
* Log security report to console (development only)
|
|
52
|
+
*
|
|
53
|
+
* @param report - Security report from validateSecurity()
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* import { validateSecurity, logSecurityReport } from '@cedros/pay-react';
|
|
58
|
+
*
|
|
59
|
+
* const report = validateSecurity();
|
|
60
|
+
* logSecurityReport(report);
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function logSecurityReport(report: SecurityReport): void;
|
|
64
|
+
/**
|
|
65
|
+
* Security recommendations for production deployment
|
|
66
|
+
*/
|
|
67
|
+
export declare const SECURITY_RECOMMENDATIONS: {
|
|
68
|
+
readonly CSP: "Use generateCSP() from @cedros/pay-react to generate Content Security Policy headers";
|
|
69
|
+
readonly HTTPS: "Always serve payment pages over HTTPS in production";
|
|
70
|
+
readonly PACKAGE_UPDATES: "Keep @stripe/stripe-js and @cedros/pay-react updated for security patches";
|
|
71
|
+
readonly AUDIT: "Run npm audit regularly to check for known vulnerabilities";
|
|
72
|
+
readonly MONITORING: "Monitor Stripe security advisories and apply updates promptly";
|
|
73
|
+
readonly NO_SRI: "Do NOT use SRI hashes for Stripe.js - use CSP instead";
|
|
74
|
+
};
|
|
75
|
+
//# sourceMappingURL=securityValidation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"securityValidation.d.ts","sourceRoot":"","sources":["../../src/utils/securityValidation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,mBAAmB,EAAE,CAAC;IAC9B,aAAa,EAAE,QAAQ,GAAG,UAAU,GAAG,YAAY,CAAC;IACpD,OAAO,EAAE,MAAM,CAAC;CACjB;AAuID;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,gBAAgB,IAAI,cAAc,CAgCjD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAmB9D;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;;;;;CAO3B,CAAC"}
|