@subscrypts/subscrypts-sdk-react 1.6.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 +2140 -0
- package/dist/components/buttons/SubscryptsButton.d.ts +19 -0
- package/dist/components/buttons/SubscryptsButton.d.ts.map +1 -0
- package/dist/components/buttons/index.d.ts +5 -0
- package/dist/components/buttons/index.d.ts.map +1 -0
- package/dist/components/checkout/CheckoutWizard.d.ts +22 -0
- package/dist/components/checkout/CheckoutWizard.d.ts.map +1 -0
- package/dist/components/checkout/ConfigurationStep.d.ts +15 -0
- package/dist/components/checkout/ConfigurationStep.d.ts.map +1 -0
- package/dist/components/checkout/TransactionStep.d.ts +15 -0
- package/dist/components/checkout/TransactionStep.d.ts.map +1 -0
- package/dist/components/checkout/index.d.ts +7 -0
- package/dist/components/checkout/index.d.ts.map +1 -0
- package/dist/components/guards/SubscriptionGuard.d.ts +25 -0
- package/dist/components/guards/SubscriptionGuard.d.ts.map +1 -0
- package/dist/components/guards/index.d.ts +5 -0
- package/dist/components/guards/index.d.ts.map +1 -0
- package/dist/components/index.d.ts +20 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/merchant/MerchantDashboard.d.ts +24 -0
- package/dist/components/merchant/MerchantDashboard.d.ts.map +1 -0
- package/dist/components/merchant/index.d.ts +6 -0
- package/dist/components/merchant/index.d.ts.map +1 -0
- package/dist/components/pricing/PlanCard.d.ts +45 -0
- package/dist/components/pricing/PlanCard.d.ts.map +1 -0
- package/dist/components/pricing/PricingTable.d.ts +68 -0
- package/dist/components/pricing/PricingTable.d.ts.map +1 -0
- package/dist/components/pricing/index.d.ts +10 -0
- package/dist/components/pricing/index.d.ts.map +1 -0
- package/dist/components/shared/ErrorDisplay.d.ts +34 -0
- package/dist/components/shared/ErrorDisplay.d.ts.map +1 -0
- package/dist/components/shared/LoadingSpinner.d.ts +5 -0
- package/dist/components/shared/LoadingSpinner.d.ts.map +1 -0
- package/dist/components/shared/Modal.d.ts +12 -0
- package/dist/components/shared/Modal.d.ts.map +1 -0
- package/dist/components/shared/NetworkSwitchPrompt.d.ts +33 -0
- package/dist/components/shared/NetworkSwitchPrompt.d.ts.map +1 -0
- package/dist/components/shared/SubscryptsErrorBoundary.d.ts +41 -0
- package/dist/components/shared/SubscryptsErrorBoundary.d.ts.map +1 -0
- package/dist/components/subscription/ConfirmDialog.d.ts +44 -0
- package/dist/components/subscription/ConfirmDialog.d.ts.map +1 -0
- package/dist/components/subscription/ManageSubscriptionModal.d.ts +35 -0
- package/dist/components/subscription/ManageSubscriptionModal.d.ts.map +1 -0
- package/dist/components/subscription/SubscriptionCard.d.ts +35 -0
- package/dist/components/subscription/SubscriptionCard.d.ts.map +1 -0
- package/dist/components/subscription/SubscriptionDashboard.d.ts +40 -0
- package/dist/components/subscription/SubscriptionDashboard.d.ts.map +1 -0
- package/dist/components/subscription/index.d.ts +12 -0
- package/dist/components/subscription/index.d.ts.map +1 -0
- package/dist/components/wallet/ConnectWalletModal.d.ts +29 -0
- package/dist/components/wallet/ConnectWalletModal.d.ts.map +1 -0
- package/dist/components/wallet/index.d.ts +6 -0
- package/dist/components/wallet/index.d.ts.map +1 -0
- package/dist/constants/index.d.ts +16 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/context/SubscryptsContext.d.ts +36 -0
- package/dist/context/SubscryptsContext.d.ts.map +1 -0
- package/dist/context/SubscryptsProvider.d.ts +28 -0
- package/dist/context/SubscryptsProvider.d.ts.map +1 -0
- package/dist/context/index.d.ts +7 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/contract/abis/Subscrypts.d.ts +2917 -0
- package/dist/contract/abis/Subscrypts.d.ts.map +1 -0
- package/dist/contract/abis/dexFactoryABI.d.ts +184 -0
- package/dist/contract/abis/dexFactoryABI.d.ts.map +1 -0
- package/dist/contract/abis/dexPairABI.d.ts +775 -0
- package/dist/contract/abis/dexPairABI.d.ts.map +1 -0
- package/dist/contract/abis/dexPositionManagerABI.d.ts +948 -0
- package/dist/contract/abis/dexPositionManagerABI.d.ts.map +1 -0
- package/dist/contract/abis/dexQuoterABI.d.ts +206 -0
- package/dist/contract/abis/dexQuoterABI.d.ts.map +1 -0
- package/dist/contract/abis/dexRouterABI.d.ts +439 -0
- package/dist/contract/abis/dexRouterABI.d.ts.map +1 -0
- package/dist/contract/abis/dexUSDCABI.d.ts +132 -0
- package/dist/contract/abis/dexUSDCABI.d.ts.map +1 -0
- package/dist/contract/abis/index.d.ts +15 -0
- package/dist/contract/abis/index.d.ts.map +1 -0
- package/dist/contract/config.d.ts +40 -0
- package/dist/contract/config.d.ts.map +1 -0
- package/dist/contract/index.d.ts +12 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/methods.d.ts +305 -0
- package/dist/contract/methods.d.ts.map +1 -0
- package/dist/hooks/events/index.d.ts +6 -0
- package/dist/hooks/events/index.d.ts.map +1 -0
- package/dist/hooks/events/useSubscryptsEvents.d.ts +63 -0
- package/dist/hooks/events/useSubscryptsEvents.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +12 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/merchant/index.d.ts +10 -0
- package/dist/hooks/merchant/index.d.ts.map +1 -0
- package/dist/hooks/merchant/useMerchantPlans.d.ts +30 -0
- package/dist/hooks/merchant/useMerchantPlans.d.ts.map +1 -0
- package/dist/hooks/merchant/useMerchantRevenue.d.ts +59 -0
- package/dist/hooks/merchant/useMerchantRevenue.d.ts.map +1 -0
- package/dist/hooks/merchant/useMerchantSubscribers.d.ts +54 -0
- package/dist/hooks/merchant/useMerchantSubscribers.d.ts.map +1 -0
- package/dist/hooks/plans/index.d.ts +12 -0
- package/dist/hooks/plans/index.d.ts.map +1 -0
- package/dist/hooks/plans/usePlan.d.ts +33 -0
- package/dist/hooks/plans/usePlan.d.ts.map +1 -0
- package/dist/hooks/plans/usePlans.d.ts +36 -0
- package/dist/hooks/plans/usePlans.d.ts.map +1 -0
- package/dist/hooks/plans/usePlansByMerchant.d.ts +35 -0
- package/dist/hooks/plans/usePlansByMerchant.d.ts.map +1 -0
- package/dist/hooks/pricing/index.d.ts +10 -0
- package/dist/hooks/pricing/index.d.ts.map +1 -0
- package/dist/hooks/pricing/usePlanPrice.d.ts +59 -0
- package/dist/hooks/pricing/usePlanPrice.d.ts.map +1 -0
- package/dist/hooks/pricing/useSUBSPrice.d.ts +39 -0
- package/dist/hooks/pricing/useSUBSPrice.d.ts.map +1 -0
- package/dist/hooks/subscriptions/index.d.ts +12 -0
- package/dist/hooks/subscriptions/index.d.ts.map +1 -0
- package/dist/hooks/subscriptions/useManageSubscription.d.ts +39 -0
- package/dist/hooks/subscriptions/useManageSubscription.d.ts.map +1 -0
- package/dist/hooks/subscriptions/useMySubscriptions.d.ts +53 -0
- package/dist/hooks/subscriptions/useMySubscriptions.d.ts.map +1 -0
- package/dist/hooks/subscriptions/useSubscribe.d.ts +58 -0
- package/dist/hooks/subscriptions/useSubscribe.d.ts.map +1 -0
- package/dist/hooks/subscriptions/useSubscriptionStatus.d.ts +34 -0
- package/dist/hooks/subscriptions/useSubscriptionStatus.d.ts.map +1 -0
- package/dist/hooks/tokens/index.d.ts +6 -0
- package/dist/hooks/tokens/index.d.ts.map +1 -0
- package/dist/hooks/tokens/useTokenBalance.d.ts +36 -0
- package/dist/hooks/tokens/useTokenBalance.d.ts.map +1 -0
- package/dist/hooks/wallet/index.d.ts +6 -0
- package/dist/hooks/wallet/index.d.ts.map +1 -0
- package/dist/hooks/wallet/useWallet.d.ts +40 -0
- package/dist/hooks/wallet/useWallet.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7850 -0
- package/dist/index.js.map +1 -0
- package/dist/services/cache.service.d.ts +89 -0
- package/dist/services/cache.service.d.ts.map +1 -0
- package/dist/services/index.d.ts +7 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/token.service.d.ts +43 -0
- package/dist/services/token.service.d.ts.map +1 -0
- package/dist/services/wallet.service.d.ts +46 -0
- package/dist/services/wallet.service.d.ts.map +1 -0
- package/dist/style.css +3 -0
- package/dist/styles.d.ts +2 -0
- package/dist/styles.d.ts.map +1 -0
- package/dist/types/component.types.d.ts +192 -0
- package/dist/types/component.types.d.ts.map +1 -0
- package/dist/types/contract.types.d.ts +81 -0
- package/dist/types/contract.types.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/subscription.types.d.ts +65 -0
- package/dist/types/subscription.types.d.ts.map +1 -0
- package/dist/types/wallet.types.d.ts +53 -0
- package/dist/types/wallet.types.d.ts.map +1 -0
- package/dist/utils/errorMessages.d.ts +44 -0
- package/dist/utils/errorMessages.d.ts.map +1 -0
- package/dist/utils/errors.d.ts +60 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/formatters.d.ts +44 -0
- package/dist/utils/formatters.d.ts.map +1 -0
- package/dist/utils/index.d.ts +10 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +80 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/permit.utils.d.ts +52 -0
- package/dist/utils/permit.utils.d.ts.map +1 -0
- package/dist/utils/subscriptionHelpers.d.ts +67 -0
- package/dist/utils/subscriptionHelpers.d.ts.map +1 -0
- package/dist/utils/subscriptionStatus.d.ts +48 -0
- package/dist/utils/subscriptionStatus.d.ts.map +1 -0
- package/dist/utils/validators.d.ts +76 -0
- package/dist/utils/validators.d.ts.map +1 -0
- package/dist/wallet/ExternalConnector.d.ts +32 -0
- package/dist/wallet/ExternalConnector.d.ts.map +1 -0
- package/dist/wallet/InjectedConnector.d.ts +55 -0
- package/dist/wallet/InjectedConnector.d.ts.map +1 -0
- package/dist/wallet/index.d.ts +9 -0
- package/dist/wallet/index.d.ts.map +1 -0
- package/dist/wallet/sessionStore.d.ts +28 -0
- package/dist/wallet/sessionStore.d.ts.map +1 -0
- package/dist/wallet/types.d.ts +66 -0
- package/dist/wallet/types.d.ts.map +1 -0
- package/package.json +99 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BrowserProvider, Signer } from 'ethers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Network configuration
|
|
5
|
+
*/
|
|
6
|
+
export interface NetworkConfig {
|
|
7
|
+
chainId: number;
|
|
8
|
+
name: string;
|
|
9
|
+
rpcUrl: string;
|
|
10
|
+
blockExplorer: string;
|
|
11
|
+
nativeCurrency: {
|
|
12
|
+
name: string;
|
|
13
|
+
symbol: string;
|
|
14
|
+
decimals: number;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Wallet connection state
|
|
19
|
+
*/
|
|
20
|
+
export interface WalletState {
|
|
21
|
+
address: string | null;
|
|
22
|
+
chainId: number | null;
|
|
23
|
+
isConnected: boolean;
|
|
24
|
+
isConnecting: boolean;
|
|
25
|
+
error: Error | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* External wallet configuration (for Wagmi/RainbowKit integration)
|
|
29
|
+
*/
|
|
30
|
+
export interface ExternalWalletConfig {
|
|
31
|
+
provider: BrowserProvider;
|
|
32
|
+
signer: Signer;
|
|
33
|
+
address: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Wallet provider type (browser extension)
|
|
37
|
+
*/
|
|
38
|
+
export interface EthereumProvider {
|
|
39
|
+
request: (args: {
|
|
40
|
+
method: string;
|
|
41
|
+
params?: unknown[];
|
|
42
|
+
}) => Promise<unknown>;
|
|
43
|
+
on: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
44
|
+
removeListener: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
45
|
+
isMetaMask?: boolean;
|
|
46
|
+
isCoinbaseWallet?: boolean;
|
|
47
|
+
}
|
|
48
|
+
declare global {
|
|
49
|
+
interface Window {
|
|
50
|
+
ethereum?: EthereumProvider;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=wallet.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.types.d.ts","sourceRoot":"","sources":["../../src/types/wallet.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,cAAc,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5E,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;IACnE,cAAc,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,KAAK,IAAI,CAAC;IAC/E,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,QAAQ,CAAC,EAAE,gBAAgB,CAAC;KAC7B;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error message mapping for human-readable blockchain errors.
|
|
3
|
+
*
|
|
4
|
+
* Maps ethers.js error codes and common blockchain errors
|
|
5
|
+
* to user-friendly messages with actionable suggestions.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Configuration for a user-facing error message
|
|
9
|
+
*/
|
|
10
|
+
export interface ErrorMessageConfig {
|
|
11
|
+
/** Short error title */
|
|
12
|
+
title: string;
|
|
13
|
+
/** User-friendly error description */
|
|
14
|
+
message: string;
|
|
15
|
+
/** Actionable suggestion for the user */
|
|
16
|
+
suggestion: string;
|
|
17
|
+
/** Whether the user can retry this operation */
|
|
18
|
+
isRetryable: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Map of known error codes to user-friendly messages.
|
|
22
|
+
* Covers ethers.js v6 error codes and common contract revert reasons.
|
|
23
|
+
*/
|
|
24
|
+
export declare const ERROR_CODE_MAP: Record<string, ErrorMessageConfig>;
|
|
25
|
+
/**
|
|
26
|
+
* Extract the error code from an unknown error object.
|
|
27
|
+
* Handles ethers.js errors, SubscryptsError, and generic errors.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getErrorCode(error: unknown): string;
|
|
30
|
+
/**
|
|
31
|
+
* Get a user-friendly error message for any error.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* try {
|
|
36
|
+
* await subscribe({ planId: '1', ... });
|
|
37
|
+
* } catch (err) {
|
|
38
|
+
* const { title, message, suggestion, isRetryable } = getErrorMessage(err);
|
|
39
|
+
* // Display to user
|
|
40
|
+
* }
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function getErrorMessage(error: unknown): ErrorMessageConfig;
|
|
44
|
+
//# sourceMappingURL=errorMessages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errorMessages.d.ts","sourceRoot":"","sources":["../../src/utils/errorMessages.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,sCAAsC;IACtC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,UAAU,EAAE,MAAM,CAAC;IACnB,gDAAgD;IAChD,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,kBAAkB,CA8F7D,CAAC;AAUF;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA2CnD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,kBAAkB,CAGlE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error classes for Subscrypts SDK
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Base error class for Subscrypts SDK
|
|
6
|
+
*/
|
|
7
|
+
export declare class SubscryptsError extends Error {
|
|
8
|
+
code: string;
|
|
9
|
+
details?: Record<string, unknown> | undefined;
|
|
10
|
+
constructor(code: string, message: string, details?: Record<string, unknown> | undefined);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Wallet connection errors
|
|
14
|
+
*/
|
|
15
|
+
export declare class WalletError extends SubscryptsError {
|
|
16
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Network errors
|
|
20
|
+
*/
|
|
21
|
+
export declare class NetworkError extends SubscryptsError {
|
|
22
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Contract interaction errors
|
|
26
|
+
*/
|
|
27
|
+
export declare class ContractError extends SubscryptsError {
|
|
28
|
+
constructor(message: string, details?: Record<string, unknown>);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Insufficient balance errors
|
|
32
|
+
*/
|
|
33
|
+
export declare class InsufficientBalanceError extends SubscryptsError {
|
|
34
|
+
required: bigint;
|
|
35
|
+
available: bigint;
|
|
36
|
+
token: 'SUBS' | 'USDC';
|
|
37
|
+
constructor(required: bigint, available: bigint, token: 'SUBS' | 'USDC');
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Transaction errors
|
|
41
|
+
*/
|
|
42
|
+
export declare class TransactionError extends SubscryptsError {
|
|
43
|
+
txHash?: string | undefined;
|
|
44
|
+
constructor(message: string, txHash?: string | undefined, details?: Record<string, unknown>);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Validation errors
|
|
48
|
+
*/
|
|
49
|
+
export declare class ValidationError extends SubscryptsError {
|
|
50
|
+
constructor(field: string, message: string);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Sanctions errors - thrown when address is sanctioned
|
|
54
|
+
*/
|
|
55
|
+
export declare class SanctionsError extends SubscryptsError {
|
|
56
|
+
readonly address: string;
|
|
57
|
+
readonly isMerchant: boolean;
|
|
58
|
+
constructor(address: string, isMerchant: boolean, details?: Record<string, unknown>);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/utils/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IAE/B,IAAI,EAAE,MAAM;IAEZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;gBAFjC,IAAI,EAAE,MAAM,EACnB,OAAO,EAAE,MAAM,EACR,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAA;CAM3C;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,eAAe;gBAClC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,eAAe;gBACnC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,eAAe;gBACpC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAI/D;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,eAAe;IAElD,QAAQ,EAAE,MAAM;IAChB,SAAS,EAAE,MAAM;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM;gBAFtB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,GAAG,MAAM;CAShC;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,eAAe;IACf,MAAM,CAAC,EAAE,MAAM;gBAAvC,OAAO,EAAE,MAAM,EAAS,MAAM,CAAC,EAAE,MAAM,YAAA,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAIvF;AAED;;GAEG;AACH,qBAAa,eAAgB,SAAQ,eAAe;gBACtC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAI3C;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,eAAe;IACjD,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,UAAU,EAAE,OAAO,CAAC;gBAExB,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;CAUpF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formatting utilities for numbers, dates, and addresses
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Format bigint token amount to human-readable string
|
|
6
|
+
*/
|
|
7
|
+
export declare function formatTokenAmount(amount: bigint, decimals: number, maxDecimals?: number): string;
|
|
8
|
+
/**
|
|
9
|
+
* Parse token amount from string to bigint
|
|
10
|
+
*/
|
|
11
|
+
export declare function parseTokenAmount(amount: string, decimals: number): bigint;
|
|
12
|
+
/**
|
|
13
|
+
* Format SUBS token amount (18 decimals)
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatSubs(amount: bigint): string;
|
|
16
|
+
/**
|
|
17
|
+
* Format USDC token amount (6 decimals)
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatUsdc(amount: bigint): string;
|
|
20
|
+
/**
|
|
21
|
+
* Format date for display
|
|
22
|
+
*/
|
|
23
|
+
export declare function formatDate(date: Date): string;
|
|
24
|
+
/**
|
|
25
|
+
* Format date with time
|
|
26
|
+
*/
|
|
27
|
+
export declare function formatDateTime(date: Date): string;
|
|
28
|
+
/**
|
|
29
|
+
* Format duration in seconds to human-readable string
|
|
30
|
+
*/
|
|
31
|
+
export declare function formatDuration(seconds: number): string;
|
|
32
|
+
/**
|
|
33
|
+
* Shorten address for display (0x1234...5678)
|
|
34
|
+
*/
|
|
35
|
+
export declare function shortenAddress(address: string, startChars?: number, endChars?: number): string;
|
|
36
|
+
/**
|
|
37
|
+
* Format percentage
|
|
38
|
+
*/
|
|
39
|
+
export declare function formatPercentage(value: number, decimals?: number): string;
|
|
40
|
+
/**
|
|
41
|
+
* Format a fiat (USD) price for display
|
|
42
|
+
*/
|
|
43
|
+
export declare function formatFiatPrice(amount: number, locale?: string): string;
|
|
44
|
+
//# sourceMappingURL=formatters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatters.d.ts","sourceRoot":"","sources":["../../src/utils/formatters.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,GAAE,MAAU,GAAG,MAAM,CASnG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzE;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAM7C;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAQjD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAetD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,GAAE,MAAU,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAKpG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAE5E;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,MAAgB,GAAG,MAAM,CAOhF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for @subscrypts/subscrypts-sdk-react
|
|
3
|
+
*/
|
|
4
|
+
export * from './errors';
|
|
5
|
+
export * from './validators';
|
|
6
|
+
export * from './formatters';
|
|
7
|
+
export * from './errorMessages';
|
|
8
|
+
export * from './subscriptionStatus';
|
|
9
|
+
export * from './subscriptionHelpers';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,sBAAsB,CAAC;AACrC,cAAc,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Subscrypts SDK Logger
|
|
3
|
+
*
|
|
4
|
+
* Configurable logging with three levels:
|
|
5
|
+
* - silent: No output (production)
|
|
6
|
+
* - info: User-friendly status messages
|
|
7
|
+
* - debug: Full developer debugging info
|
|
8
|
+
*/
|
|
9
|
+
export type LogLevel = 'silent' | 'info' | 'debug';
|
|
10
|
+
export interface LoggerConfig {
|
|
11
|
+
level: LogLevel;
|
|
12
|
+
prefix?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PerformanceMetric {
|
|
15
|
+
operation: string;
|
|
16
|
+
duration: number;
|
|
17
|
+
timestamp: number;
|
|
18
|
+
}
|
|
19
|
+
declare class SubscryptsLogger {
|
|
20
|
+
private level;
|
|
21
|
+
private prefix;
|
|
22
|
+
private performanceMetrics;
|
|
23
|
+
private correlationIdCounter;
|
|
24
|
+
configure(config: Partial<LoggerConfig>): void;
|
|
25
|
+
getLevel(): LogLevel;
|
|
26
|
+
/**
|
|
27
|
+
* Generate unique correlation ID for tracing related operations
|
|
28
|
+
*/
|
|
29
|
+
generateCorrelationId(): string;
|
|
30
|
+
/**
|
|
31
|
+
* Track performance of async operations (debug mode only)
|
|
32
|
+
*/
|
|
33
|
+
trackPerformance<T>(operation: string, fn: () => Promise<T>): Promise<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Get performance metrics (debug mode only)
|
|
36
|
+
*/
|
|
37
|
+
getPerformanceMetrics(): PerformanceMetric[];
|
|
38
|
+
/**
|
|
39
|
+
* Clear performance metrics
|
|
40
|
+
*/
|
|
41
|
+
clearMetrics(): void;
|
|
42
|
+
private shouldLog;
|
|
43
|
+
/**
|
|
44
|
+
* Debug level - detailed developer info
|
|
45
|
+
*/
|
|
46
|
+
debug(message: string, data?: unknown): void;
|
|
47
|
+
/**
|
|
48
|
+
* Info level - user-friendly status
|
|
49
|
+
*/
|
|
50
|
+
info(message: string, data?: unknown): void;
|
|
51
|
+
/**
|
|
52
|
+
* Warning - potential issues
|
|
53
|
+
*/
|
|
54
|
+
warn(message: string, data?: unknown): void;
|
|
55
|
+
/**
|
|
56
|
+
* Error - failures
|
|
57
|
+
*/
|
|
58
|
+
error(message: string, data?: unknown): void;
|
|
59
|
+
/**
|
|
60
|
+
* Success - completed operations
|
|
61
|
+
*/
|
|
62
|
+
success(message: string, data?: unknown): void;
|
|
63
|
+
/**
|
|
64
|
+
* Group logs together (debug only)
|
|
65
|
+
*/
|
|
66
|
+
group(label: string): void;
|
|
67
|
+
groupEnd(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Log a table of data (debug only)
|
|
70
|
+
*/
|
|
71
|
+
table(data: unknown): void;
|
|
72
|
+
}
|
|
73
|
+
export declare const logger: SubscryptsLogger;
|
|
74
|
+
/**
|
|
75
|
+
* Helper to format BigInt values for logging
|
|
76
|
+
* Converts BigInt to string to avoid JSON serialization issues
|
|
77
|
+
*/
|
|
78
|
+
export declare function formatLogValue(value: unknown): unknown;
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAUD,cAAM,gBAAgB;IACpB,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,MAAM,CAAkB;IAChC,OAAO,CAAC,kBAAkB,CAA2B;IACrD,OAAO,CAAC,oBAAoB,CAAK;IAEjC,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC;IAKvC,QAAQ,IAAI,QAAQ;IAIpB;;OAEG;IACH,qBAAqB,IAAI,MAAM;IAI/B;;OAEG;IACG,gBAAgB,CAAC,CAAC,EACtB,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC;IAqBb;;OAEG;IACH,qBAAqB,IAAI,iBAAiB,EAAE;IAI5C;;OAEG;IACH,YAAY,IAAI,IAAI;IAIpB,OAAO,CAAC,SAAS;IAOjB;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAMrC;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAMpC;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAMpC;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAMrC;;OAEG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAMvC;;OAEG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM;IAMnB,QAAQ;IAMR;;OAEG;IACH,KAAK,CAAC,IAAI,EAAE,OAAO;CAKpB;AAGD,eAAO,MAAM,MAAM,kBAAyB,CAAC;AAE7C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAetD"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* EIP-712 domain for PERMIT2 on Arbitrum One
|
|
5
|
+
*/
|
|
6
|
+
export declare const PERMIT2_DOMAIN: {
|
|
7
|
+
readonly name: "Permit2";
|
|
8
|
+
readonly chainId: 42161;
|
|
9
|
+
readonly verifyingContract: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* EIP-712 types for PERMIT2 PermitTransferFrom
|
|
13
|
+
*/
|
|
14
|
+
export declare const PERMIT2_TYPES: {
|
|
15
|
+
TokenPermissions: {
|
|
16
|
+
name: string;
|
|
17
|
+
type: string;
|
|
18
|
+
}[];
|
|
19
|
+
PermitTransferFrom: {
|
|
20
|
+
name: string;
|
|
21
|
+
type: string;
|
|
22
|
+
}[];
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Generate PERMIT2 signature for token transfer
|
|
26
|
+
*
|
|
27
|
+
* This function creates a valid EIP-712 signature that allows the spender
|
|
28
|
+
* to transfer tokens on behalf of the signer through PERMIT2.
|
|
29
|
+
*
|
|
30
|
+
* @param signer - Ethers signer (wallet) that will sign the permit
|
|
31
|
+
* @param tokenAddress - Address of the token to permit (e.g., USDC)
|
|
32
|
+
* @param amount - Amount of tokens to permit (in wei/token decimals)
|
|
33
|
+
* @param spender - Address that will be allowed to spend tokens (e.g., Subscrypts contract)
|
|
34
|
+
* @param deadline - Unix timestamp when the permit expires
|
|
35
|
+
* @returns Object containing the signature and nonce
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const { signature, nonce } = await generatePermit2Signature(
|
|
40
|
+
* signer,
|
|
41
|
+
* USDC_ADDRESS,
|
|
42
|
+
* parseUnits('100', 6), // 100 USDC
|
|
43
|
+
* SUBSCRYPTS_CONTRACT_ADDRESS,
|
|
44
|
+
* BigInt(Math.floor(Date.now() / 1000) + 1800) // 30 minutes
|
|
45
|
+
* );
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function generatePermit2Signature(signer: ethers.Signer, tokenAddress: string, amount: bigint, spender: string, deadline: bigint): Promise<{
|
|
49
|
+
signature: string;
|
|
50
|
+
nonce: string;
|
|
51
|
+
}>;
|
|
52
|
+
//# sourceMappingURL=permit.utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permit.utils.d.ts","sourceRoot":"","sources":["../../src/utils/permit.utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC;;GAEG;AACH,eAAO,MAAM,cAAc;;;;CAIjB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,aAAa;;;;;;;;;CAWzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,CAAC,MAAM,EACrB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAsC/C"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Subscription } from '../types';
|
|
2
|
+
import { SubscriptionState } from './subscriptionStatus';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Check if a subscription grants active access.
|
|
6
|
+
* Pure function - no blockchain calls.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* if (canAccess(subscription)) {
|
|
11
|
+
* showPremiumContent();
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function canAccess(subscription: Subscription | null): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a subscription payment is due (past nextPaymentDate).
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* if (isPaymentDue(subscription)) {
|
|
22
|
+
* triggerPaymentCollection();
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function isPaymentDue(subscription: Subscription, now?: Date): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Check if a subscription should be renewed.
|
|
29
|
+
* True when: payment is due AND auto-renewing AND has remaining cycles.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```typescript
|
|
33
|
+
* if (shouldRenew(subscription)) {
|
|
34
|
+
* processRenewalPayment();
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare function shouldRenew(subscription: Subscription, now?: Date): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Subscription health summary
|
|
41
|
+
*/
|
|
42
|
+
export interface SubscriptionHealth {
|
|
43
|
+
/** Normalized subscription state */
|
|
44
|
+
state: SubscriptionState;
|
|
45
|
+
/** Whether a payment is currently due */
|
|
46
|
+
isPaymentDue: boolean;
|
|
47
|
+
/** Whether the subscription should be renewed */
|
|
48
|
+
shouldRenew: boolean;
|
|
49
|
+
/** Days until expiry (null if expired or not found) */
|
|
50
|
+
daysUntilExpiry: number | null;
|
|
51
|
+
/** Remaining payment cycles */
|
|
52
|
+
cyclesRemaining: number;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get comprehensive subscription health summary.
|
|
56
|
+
* Combines status resolution with decision helpers.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* const health = getSubscriptionHealth(subscription);
|
|
61
|
+
* console.log(health.state); // 'active'
|
|
62
|
+
* console.log(health.isPaymentDue); // false
|
|
63
|
+
* console.log(health.daysUntilExpiry); // 25
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare function getSubscriptionHealth(subscription: Subscription | null, now?: Date): SubscriptionHealth;
|
|
67
|
+
//# sourceMappingURL=subscriptionHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptionHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/subscriptionHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAE9D;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,YAAY,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAIpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,YAAY,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO,CAExF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,YAAY,EAAE,YAAY,EAAE,GAAG,GAAE,IAAiB,GAAG,OAAO,CAMvF;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,oCAAoC;IACpC,KAAK,EAAE,iBAAiB,CAAC;IACzB,yCAAyC;IACzC,YAAY,EAAE,OAAO,CAAC;IACtB,iDAAiD;IACjD,WAAW,EAAE,OAAO,CAAC;IACrB,uDAAuD;IACvD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,+BAA+B;IAC/B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,YAAY,GAAG,IAAI,EACjC,GAAG,GAAE,IAAiB,GACrB,kBAAkB,CAUpB"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Subscription } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalized subscription states
|
|
5
|
+
*/
|
|
6
|
+
export type SubscriptionState = 'active' | 'expired' | 'expiring-soon' | 'cancelled' | 'not-found';
|
|
7
|
+
/**
|
|
8
|
+
* Input for resolving subscription status
|
|
9
|
+
*/
|
|
10
|
+
export interface ResolveStatusInput {
|
|
11
|
+
/** The subscription to evaluate (null if none exists) */
|
|
12
|
+
subscription: Subscription | null;
|
|
13
|
+
/** Reference time for comparison (defaults to now) */
|
|
14
|
+
now?: Date;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolved subscription status with computed fields
|
|
18
|
+
*/
|
|
19
|
+
export interface ResolvedStatus {
|
|
20
|
+
/** Normalized subscription state */
|
|
21
|
+
state: SubscriptionState;
|
|
22
|
+
/** Whether the subscription grants active access */
|
|
23
|
+
isActive: boolean;
|
|
24
|
+
/** Days until expiry (null if expired or not found) */
|
|
25
|
+
daysUntilExpiry: number | null;
|
|
26
|
+
/** Next payment date (null if not found) */
|
|
27
|
+
nextPaymentDate: Date | null;
|
|
28
|
+
/** Whether auto-renewal is enabled */
|
|
29
|
+
isAutoRenewing: boolean;
|
|
30
|
+
/** Remaining payment cycles */
|
|
31
|
+
remainingCycles: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolve the normalized status of a subscription.
|
|
35
|
+
*
|
|
36
|
+
* This is a pure function with no side effects or blockchain calls.
|
|
37
|
+
* It can be used in React components, Node.js scripts, AI agents, etc.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```typescript
|
|
41
|
+
* const status = resolveSubscriptionStatus({ subscription });
|
|
42
|
+
* if (status.state === 'expiring-soon') {
|
|
43
|
+
* showRenewalReminder();
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveSubscriptionStatus(input: ResolveStatusInput): ResolvedStatus;
|
|
48
|
+
//# sourceMappingURL=subscriptionStatus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscriptionStatus.d.ts","sourceRoot":"","sources":["../../src/utils/subscriptionStatus.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,SAAS,GACT,eAAe,GACf,WAAW,GACX,WAAW,CAAC;AAEhB;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,yDAAyD;IACzD,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,sDAAsD;IACtD,GAAG,CAAC,EAAE,IAAI,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,KAAK,EAAE,iBAAiB,CAAC;IACzB,oDAAoD;IACpD,QAAQ,EAAE,OAAO,CAAC;IAClB,uDAAuD;IACvD,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,4CAA4C;IAC5C,eAAe,EAAE,IAAI,GAAG,IAAI,CAAC;IAC7B,sCAAsC;IACtC,cAAc,EAAE,OAAO,CAAC;IACxB,+BAA+B;IAC/B,eAAe,EAAE,MAAM,CAAC;CACzB;AAKD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,kBAAkB,GAAG,cAAc,CAqEnF"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Contract } from 'ethers';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validate Ethereum address
|
|
5
|
+
*/
|
|
6
|
+
export declare function validateAddress(address: string, fieldName?: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Validate positive number
|
|
9
|
+
*/
|
|
10
|
+
export declare function validatePositiveNumber(value: number, fieldName?: string): void;
|
|
11
|
+
/**
|
|
12
|
+
* Validate positive bigint
|
|
13
|
+
*/
|
|
14
|
+
export declare function validatePositiveBigInt(value: bigint, fieldName?: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* Validate plan ID
|
|
17
|
+
*/
|
|
18
|
+
export declare function validatePlanId(planId: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Validate cycle limit
|
|
21
|
+
*/
|
|
22
|
+
export declare function validateCycleLimit(cycles: number): void;
|
|
23
|
+
/**
|
|
24
|
+
* Validate referral address for a plan
|
|
25
|
+
*
|
|
26
|
+
* Referral addresses must be existing subscribers to the same plan to receive
|
|
27
|
+
* referral bonuses. Invalid referrals are silently ignored by the contract
|
|
28
|
+
* (no error, no bonus applied).
|
|
29
|
+
*
|
|
30
|
+
* Contract requirement: facetSubscription.sol lines 196-198
|
|
31
|
+
*
|
|
32
|
+
* @param contract - Subscrypts contract instance
|
|
33
|
+
* @param planId - Plan ID to check
|
|
34
|
+
* @param referralAddress - Referral address to validate
|
|
35
|
+
* @returns true if referral is valid (subscribed to plan), false otherwise
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const isValid = await isValidReferral(contract, '1', '0x123...');
|
|
40
|
+
* if (!isValid) {
|
|
41
|
+
* console.warn('Referral address is not subscribed to this plan');
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare function isValidReferral(contract: Contract, planId: string | bigint, referralAddress: string): Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* Check if an address is sanctioned
|
|
48
|
+
*
|
|
49
|
+
* Pre-flight check before subscription creation to prevent wasted gas.
|
|
50
|
+
* Uses contract's subCheckSanctions method which queries Chainalysis oracle.
|
|
51
|
+
*
|
|
52
|
+
* **Fail-open pattern**: If the check fails (contract error, oracle unavailable),
|
|
53
|
+
* returns false for both addresses to allow the transaction. This prevents breaking
|
|
54
|
+
* existing integrations where sanctions checking might not be enabled.
|
|
55
|
+
*
|
|
56
|
+
* @param contract - Subscrypts contract instance
|
|
57
|
+
* @param merchantAddress - Merchant address to check
|
|
58
|
+
* @param subscriberAddress - Subscriber address to check
|
|
59
|
+
* @returns Promise<{ merchantSanctioned: boolean, subscriberSanctioned: boolean }>
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const result = await checkSanctions(contract, merchantAddr, subscriberAddr);
|
|
64
|
+
* if (result.merchantSanctioned) {
|
|
65
|
+
* throw new SanctionsError(merchantAddr, true);
|
|
66
|
+
* }
|
|
67
|
+
* if (result.subscriberSanctioned) {
|
|
68
|
+
* throw new SanctionsError(subscriberAddr, false);
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export declare function checkSanctions(contract: Contract, merchantAddress: string, subscriberAddress: string): Promise<{
|
|
73
|
+
merchantSanctioned: boolean;
|
|
74
|
+
subscriberSanctioned: boolean;
|
|
75
|
+
}>;
|
|
76
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/utils/validators.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAyB,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGzD;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAkB,GAAG,MAAM,CAWtF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,MAAgB,GAAG,IAAI,CAQvF;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,GAAE,MAAgB,GAAG,IAAI,CAQvF;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAInD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAUvD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,CAelB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,cAAc,CAClC,QAAQ,EAAE,QAAQ,EAClB,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,MAAM,GACxB,OAAO,CAAC;IAAE,kBAAkB,EAAE,OAAO,CAAC;IAAC,oBAAoB,EAAE,OAAO,CAAA;CAAE,CAAC,CAazE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WalletConnector, ConnectResult } from './types';
|
|
2
|
+
import { ExternalWalletConfig } from '../types';
|
|
3
|
+
|
|
4
|
+
export declare class ExternalConnector implements WalletConnector {
|
|
5
|
+
readonly id: "external";
|
|
6
|
+
readonly name = "External Provider";
|
|
7
|
+
readonly icon?: string;
|
|
8
|
+
private config;
|
|
9
|
+
private chainId;
|
|
10
|
+
constructor(config: ExternalWalletConfig, chainId: number);
|
|
11
|
+
/**
|
|
12
|
+
* External providers are always available (they're passed in by the app)
|
|
13
|
+
*/
|
|
14
|
+
isAvailable(): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Return the external provider/signer directly
|
|
17
|
+
*/
|
|
18
|
+
connect(): Promise<ConnectResult>;
|
|
19
|
+
/**
|
|
20
|
+
* External disconnect is a no-op (managed by the parent app)
|
|
21
|
+
*/
|
|
22
|
+
disconnect(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* External providers can always reconnect (already connected)
|
|
25
|
+
*/
|
|
26
|
+
reconnect(): Promise<ConnectResult | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Update the external config (called when externalProvider prop changes)
|
|
29
|
+
*/
|
|
30
|
+
updateConfig(config: ExternalWalletConfig, chainId: number): void;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=ExternalConnector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExternalConnector.d.ts","sourceRoot":"","sources":["../../src/wallet/ExternalConnector.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACzD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAEhD,qBAAa,iBAAkB,YAAW,eAAe;IACvD,QAAQ,CAAC,EAAE,EAAG,UAAU,CAAU;IAClC,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM;IAKzD;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC;IASvC;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAIjC;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAIhD;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;CAIlE"}
|