@b3dotfun/sdk 0.1.68 → 0.1.69-alpha.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/dist/cjs/anyspend/platform/client.d.ts +35 -0
- package/dist/cjs/anyspend/platform/client.js +158 -0
- package/dist/cjs/anyspend/platform/errors.d.ts +38 -0
- package/dist/cjs/anyspend/platform/errors.js +77 -0
- package/dist/cjs/anyspend/platform/index.d.ts +87 -0
- package/dist/cjs/anyspend/platform/index.js +85 -0
- package/dist/cjs/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/cjs/anyspend/platform/resources/analytics.js +12 -0
- package/dist/cjs/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/cjs/anyspend/platform/resources/checkout-sessions.js +27 -0
- package/dist/cjs/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/cjs/anyspend/platform/resources/customers.js +34 -0
- package/dist/cjs/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/cjs/anyspend/platform/resources/discount-codes.js +31 -0
- package/dist/cjs/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/cjs/anyspend/platform/resources/events.js +16 -0
- package/dist/cjs/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/cjs/anyspend/platform/resources/notifications.js +27 -0
- package/dist/cjs/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/cjs/anyspend/platform/resources/organization.js +15 -0
- package/dist/cjs/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/cjs/anyspend/platform/resources/payment-links.js +49 -0
- package/dist/cjs/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/cjs/anyspend/platform/resources/products.js +31 -0
- package/dist/cjs/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/cjs/anyspend/platform/resources/transactions.js +25 -0
- package/dist/cjs/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/cjs/anyspend/platform/resources/webhooks.js +33 -0
- package/dist/cjs/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/cjs/anyspend/platform/resources/widgets.js +31 -0
- package/dist/cjs/anyspend/platform/types.d.ts +478 -0
- package/dist/cjs/anyspend/platform/types.js +5 -0
- package/dist/cjs/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/cjs/anyspend/platform/utils/idempotency.js +17 -0
- package/dist/cjs/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/cjs/anyspend/platform/utils/pagination.js +22 -0
- package/dist/cjs/anyspend/react/components/AnySpend.d.ts +5 -1
- package/dist/cjs/anyspend/react/components/AnySpend.js +127 -16
- package/dist/cjs/anyspend/react/components/AnySpendCustom.js +4 -4
- package/dist/cjs/anyspend/react/components/AnySpendCustomExactIn.js +2 -2
- package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
- package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
- package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
- package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +2 -2
- package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
- package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -2
- package/dist/cjs/anyspend/react/components/checkout/CryptoPayPanel.js +1 -1
- package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
- package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +48 -16
- package/dist/cjs/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/cjs/anyspend/react/components/checkout/KycGate.js +203 -0
- package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
- package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.js +145 -0
- package/dist/cjs/anyspend/react/components/common/CryptoPaymentMethod.js +1 -1
- package/dist/cjs/anyspend/react/components/common/FeeDetailPanel.js +1 -1
- package/dist/cjs/anyspend/react/components/common/FiatPaymentMethod.js +2 -2
- package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -1
- package/dist/cjs/anyspend/react/components/common/PointsDetailPanel.js +1 -1
- package/dist/cjs/anyspend/react/components/common/RecipientSelection.js +1 -1
- package/dist/cjs/anyspend/react/components/index.d.ts +1 -1
- package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/cjs/anyspend/react/hooks/index.js +1 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
- package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +14 -0
- package/dist/cjs/anyspend/react/hooks/useKycStatus.d.ts +47 -0
- package/dist/cjs/anyspend/react/hooks/useKycStatus.js +124 -0
- package/dist/cjs/anyspend/services/anyspend.d.ts +4 -1
- package/dist/cjs/anyspend/services/anyspend.js +3 -1
- package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
- package/dist/cjs/global-account/react/components/ManageAccount/HomeActions.js +1 -1
- package/dist/cjs/global-account/react/components/ManageAccount/channels/TelegramChannel.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -5
- package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +21 -24
- package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
- package/dist/cjs/global-account/react/hooks/useAuth.js +1 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +3 -1
- package/dist/cjs/global-account/react/hooks/useAuthentication.js +94 -24
- package/dist/cjs/global-account/react/hooks/useGetAllTWSigners.js +2 -1
- package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/cjs/global-account/react/stores/useModalStore.js +2 -0
- package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/dist/cjs/global-account/react/utils/createWagmiConfig.js +17 -0
- package/dist/esm/anyspend/platform/client.d.ts +35 -0
- package/dist/esm/anyspend/platform/client.js +153 -0
- package/dist/esm/anyspend/platform/errors.d.ts +38 -0
- package/dist/esm/anyspend/platform/errors.js +67 -0
- package/dist/esm/anyspend/platform/index.d.ts +87 -0
- package/dist/esm/anyspend/platform/index.js +75 -0
- package/dist/esm/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/esm/anyspend/platform/resources/analytics.js +8 -0
- package/dist/esm/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/esm/anyspend/platform/resources/checkout-sessions.js +23 -0
- package/dist/esm/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/esm/anyspend/platform/resources/customers.js +30 -0
- package/dist/esm/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/esm/anyspend/platform/resources/discount-codes.js +27 -0
- package/dist/esm/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/esm/anyspend/platform/resources/events.js +12 -0
- package/dist/esm/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/esm/anyspend/platform/resources/notifications.js +23 -0
- package/dist/esm/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/esm/anyspend/platform/resources/organization.js +11 -0
- package/dist/esm/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/esm/anyspend/platform/resources/payment-links.js +45 -0
- package/dist/esm/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/esm/anyspend/platform/resources/products.js +27 -0
- package/dist/esm/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/esm/anyspend/platform/resources/transactions.js +21 -0
- package/dist/esm/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/esm/anyspend/platform/resources/webhooks.js +29 -0
- package/dist/esm/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/esm/anyspend/platform/resources/widgets.js +27 -0
- package/dist/esm/anyspend/platform/types.d.ts +478 -0
- package/dist/esm/anyspend/platform/types.js +4 -0
- package/dist/esm/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/esm/anyspend/platform/utils/idempotency.js +14 -0
- package/dist/esm/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/esm/anyspend/platform/utils/pagination.js +19 -0
- package/dist/esm/anyspend/react/components/AnySpend.d.ts +5 -1
- package/dist/esm/anyspend/react/components/AnySpend.js +128 -17
- package/dist/esm/anyspend/react/components/AnySpendCustom.js +4 -4
- package/dist/esm/anyspend/react/components/AnySpendCustomExactIn.js +2 -2
- package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
- package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
- package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
- package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +2 -2
- package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
- package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -2
- package/dist/esm/anyspend/react/components/checkout/CryptoPayPanel.js +1 -1
- package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
- package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +50 -18
- package/dist/esm/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/esm/anyspend/react/components/checkout/KycGate.js +167 -0
- package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
- package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.js +142 -0
- package/dist/esm/anyspend/react/components/common/CryptoPaymentMethod.js +1 -1
- package/dist/esm/anyspend/react/components/common/FeeDetailPanel.js +1 -1
- package/dist/esm/anyspend/react/components/common/FiatPaymentMethod.js +2 -2
- package/dist/esm/anyspend/react/components/common/OrderDetails.js +1 -1
- package/dist/esm/anyspend/react/components/common/PointsDetailPanel.js +1 -1
- package/dist/esm/anyspend/react/components/common/RecipientSelection.js +1 -1
- package/dist/esm/anyspend/react/components/index.d.ts +1 -1
- package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/esm/anyspend/react/hooks/index.js +1 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
- package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +14 -0
- package/dist/esm/anyspend/react/hooks/useKycStatus.d.ts +47 -0
- package/dist/esm/anyspend/react/hooks/useKycStatus.js +117 -0
- package/dist/esm/anyspend/services/anyspend.d.ts +4 -1
- package/dist/esm/anyspend/services/anyspend.js +3 -1
- package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
- package/dist/esm/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
- package/dist/esm/global-account/react/components/ManageAccount/HomeActions.js +1 -1
- package/dist/esm/global-account/react/components/ManageAccount/channels/TelegramChannel.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -5
- package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +21 -24
- package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
- package/dist/esm/global-account/react/hooks/useAuth.js +2 -2
- package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +3 -1
- package/dist/esm/global-account/react/hooks/useAuthentication.js +94 -24
- package/dist/esm/global-account/react/hooks/useGetAllTWSigners.js +2 -1
- package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/esm/global-account/react/stores/useModalStore.js +2 -0
- package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/dist/esm/global-account/react/utils/createWagmiConfig.js +16 -0
- package/dist/styles/index.css +1 -1
- package/dist/types/anyspend/platform/client.d.ts +35 -0
- package/dist/types/anyspend/platform/errors.d.ts +38 -0
- package/dist/types/anyspend/platform/index.d.ts +87 -0
- package/dist/types/anyspend/platform/resources/analytics.d.ts +7 -0
- package/dist/types/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
- package/dist/types/anyspend/platform/resources/customers.d.ts +19 -0
- package/dist/types/anyspend/platform/resources/discount-codes.d.ts +29 -0
- package/dist/types/anyspend/platform/resources/events.d.ts +14 -0
- package/dist/types/anyspend/platform/resources/notifications.d.ts +18 -0
- package/dist/types/anyspend/platform/resources/organization.d.ts +17 -0
- package/dist/types/anyspend/platform/resources/payment-links.d.ts +21 -0
- package/dist/types/anyspend/platform/resources/products.d.ts +27 -0
- package/dist/types/anyspend/platform/resources/transactions.d.ts +11 -0
- package/dist/types/anyspend/platform/resources/webhooks.d.ts +14 -0
- package/dist/types/anyspend/platform/resources/widgets.d.ts +38 -0
- package/dist/types/anyspend/platform/types.d.ts +478 -0
- package/dist/types/anyspend/platform/utils/idempotency.d.ts +4 -0
- package/dist/types/anyspend/platform/utils/pagination.d.ts +12 -0
- package/dist/types/anyspend/react/components/AnySpend.d.ts +5 -1
- package/dist/types/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
- package/dist/types/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
- package/dist/types/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
- package/dist/types/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
- package/dist/types/anyspend/react/components/checkout/KycGate.d.ts +11 -0
- package/dist/types/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
- package/dist/types/anyspend/react/components/index.d.ts +1 -1
- package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
- package/dist/types/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
- package/dist/types/anyspend/react/hooks/useKycStatus.d.ts +47 -0
- package/dist/types/anyspend/services/anyspend.d.ts +4 -1
- package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
- package/dist/types/global-account/react/hooks/useAuthentication.d.ts +3 -1
- package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
- package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +18 -0
- package/package.json +7 -1
- package/src/anyspend/docs/checkout-sessions.md +20 -3
- package/src/anyspend/platform/client.ts +198 -0
- package/src/anyspend/platform/errors.ts +92 -0
- package/src/anyspend/platform/index.ts +129 -0
- package/src/anyspend/platform/resources/analytics.ts +10 -0
- package/src/anyspend/platform/resources/checkout-sessions.ts +36 -0
- package/src/anyspend/platform/resources/customers.ts +54 -0
- package/src/anyspend/platform/resources/discount-codes.ts +63 -0
- package/src/anyspend/platform/resources/events.ts +22 -0
- package/src/anyspend/platform/resources/notifications.ts +37 -0
- package/src/anyspend/platform/resources/organization.ts +24 -0
- package/src/anyspend/platform/resources/payment-links.ts +74 -0
- package/src/anyspend/platform/resources/products.ts +59 -0
- package/src/anyspend/platform/resources/transactions.ts +33 -0
- package/src/anyspend/platform/resources/webhooks.ts +47 -0
- package/src/anyspend/platform/resources/widgets.ts +63 -0
- package/src/anyspend/platform/types.ts +532 -0
- package/src/anyspend/platform/utils/idempotency.ts +15 -0
- package/src/anyspend/platform/utils/pagination.ts +32 -0
- package/src/anyspend/react/components/AnySpend.tsx +152 -18
- package/src/anyspend/react/components/AnySpendCustom.tsx +4 -4
- package/src/anyspend/react/components/AnySpendCustomExactIn.tsx +2 -2
- package/src/anyspend/react/components/checkout/AnySpendCheckout.tsx +81 -18
- package/src/anyspend/react/components/checkout/AnySpendCheckoutTrigger.tsx +4 -0
- package/src/anyspend/react/components/checkout/CheckoutPaymentPanel.tsx +8 -0
- package/src/anyspend/react/components/checkout/CryptoPayPanel.tsx +4 -13
- package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +86 -17
- package/src/anyspend/react/components/checkout/KycGate.tsx +387 -0
- package/src/anyspend/react/components/checkout/VariablePricingInput.tsx +247 -0
- package/src/anyspend/react/components/common/CryptoPaymentMethod.tsx +1 -1
- package/src/anyspend/react/components/common/FeeDetailPanel.tsx +1 -1
- package/src/anyspend/react/components/common/FiatPaymentMethod.tsx +2 -2
- package/src/anyspend/react/components/common/OrderDetails.tsx +1 -1
- package/src/anyspend/react/components/common/PointsDetailPanel.tsx +1 -1
- package/src/anyspend/react/components/common/RecipientSelection.tsx +1 -1
- package/src/anyspend/react/components/index.ts +1 -0
- package/src/anyspend/react/hooks/index.ts +1 -0
- package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +17 -0
- package/src/anyspend/react/hooks/useKycStatus.ts +150 -0
- package/src/anyspend/services/anyspend.ts +7 -0
- package/src/global-account/react/components/B3DynamicModal.tsx +0 -2
- package/src/global-account/react/components/ManageAccount/BottomNavigation.tsx +7 -7
- package/src/global-account/react/components/ManageAccount/HomeActions.tsx +2 -2
- package/src/global-account/react/components/ManageAccount/ManageAccount.tsx +7 -7
- package/src/global-account/react/components/ManageAccount/channels/TelegramChannel.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/SignIn.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +13 -5
- package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +1 -1
- package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +35 -25
- package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +1 -1
- package/src/global-account/react/hooks/useAuth.ts +2 -2
- package/src/global-account/react/hooks/useAuthentication.ts +92 -27
- package/src/global-account/react/hooks/useGetAllTWSigners.tsx +2 -1
- package/src/global-account/react/stores/useModalStore.ts +6 -0
- package/src/global-account/react/utils/createWagmiConfig.tsx +18 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface KycStatusResponse {
|
|
2
|
+
kycRequired: boolean;
|
|
3
|
+
status: "not_verified" | "pending" | "completed" | "approved" | "declined" | "needs_review" | "expired";
|
|
4
|
+
inquiry?: {
|
|
5
|
+
inquiryId: string;
|
|
6
|
+
sessionToken: string;
|
|
7
|
+
};
|
|
8
|
+
config?: {
|
|
9
|
+
templateId: string;
|
|
10
|
+
environment: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
interface KycInquiryResponse {
|
|
14
|
+
inquiryId: string;
|
|
15
|
+
sessionToken: string;
|
|
16
|
+
}
|
|
17
|
+
interface KycVerifyResponse {
|
|
18
|
+
status: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Returns cached wallet auth headers without triggering a wallet signature prompt.
|
|
22
|
+
* Returns undefined if no valid cache exists for the given address.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getCachedWalletHeaders(address: string): Record<string, string> | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Returns a function that builds the wallet-signature auth headers.
|
|
27
|
+
* Caches signatures for 4 minutes (server allows 5-minute window).
|
|
28
|
+
*/
|
|
29
|
+
export declare function useWalletAuthHeaders(): {
|
|
30
|
+
address: `0x${string}` | undefined;
|
|
31
|
+
getHeaders: () => Promise<Record<string, string>>;
|
|
32
|
+
};
|
|
33
|
+
export declare function useKycStatus(enabled?: boolean): {
|
|
34
|
+
kycStatus: KycStatusResponse | null;
|
|
35
|
+
isLoadingKycStatus: boolean;
|
|
36
|
+
kycStatusError: Error | null;
|
|
37
|
+
refetchKycStatus: (options?: import("@tanstack/react-query").RefetchOptions) => Promise<import("@tanstack/react-query").QueryObserverResult<KycStatusResponse, Error>>;
|
|
38
|
+
};
|
|
39
|
+
export declare function useCreateKycInquiry(): {
|
|
40
|
+
createInquiry: import("@tanstack/react-query").UseMutateAsyncFunction<KycInquiryResponse, Error, void, unknown>;
|
|
41
|
+
isCreatingInquiry: boolean;
|
|
42
|
+
};
|
|
43
|
+
export declare function useVerifyKyc(): {
|
|
44
|
+
verifyKyc: import("@tanstack/react-query").UseMutateAsyncFunction<KycVerifyResponse, Error, string, unknown>;
|
|
45
|
+
isVerifying: boolean;
|
|
46
|
+
};
|
|
47
|
+
export {};
|
|
@@ -6,7 +6,7 @@ export declare const anyspendService: {
|
|
|
6
6
|
getTokenList: (chainId: number, query: string) => Promise<components["schemas"]["Token"][]>;
|
|
7
7
|
getToken: (chainId: number, tokenAddress: string) => Promise<components["schemas"]["Token"]>;
|
|
8
8
|
getQuote: (req: GetQuoteRequest, partnerId?: string) => Promise<GetQuoteResponse>;
|
|
9
|
-
createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, }: {
|
|
9
|
+
createOrder: ({ recipientAddress, type, srcChain, dstChain, srcTokenAddress, dstTokenAddress, srcAmount, payload, onramp, metadata, creatorAddress, partnerId, clientReferenceId, visitorData, callbackMetadata, feeOnTop, kycWalletHeaders, }: {
|
|
10
10
|
recipientAddress: string;
|
|
11
11
|
type: string;
|
|
12
12
|
srcChain: number;
|
|
@@ -22,6 +22,9 @@ export declare const anyspendService: {
|
|
|
22
22
|
clientReferenceId?: string;
|
|
23
23
|
visitorData?: VisitorData;
|
|
24
24
|
callbackMetadata?: Record<string, unknown>;
|
|
25
|
+
feeOnTop?: boolean;
|
|
26
|
+
/** Wallet signature auth headers for KYC lookup (stripe-web2 orders only). */
|
|
27
|
+
kycWalletHeaders?: Record<string, string>;
|
|
25
28
|
}) => Promise<{
|
|
26
29
|
success: boolean;
|
|
27
30
|
message: string;
|
|
@@ -19,5 +19,5 @@ interface LoginStepContainerProps {
|
|
|
19
19
|
partnerId?: string;
|
|
20
20
|
}
|
|
21
21
|
export declare function LoginStepContainer({ children, partnerId }: LoginStepContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
-
export declare function LoginStep({ onSuccess, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare function LoginStep({ onSuccess, chain }: LoginStepProps): import("react/jsx-runtime").JSX.Element | null;
|
|
23
23
|
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Wallet } from "thirdweb/wallets";
|
|
2
2
|
import { preAuthenticate } from "thirdweb/wallets/in-app";
|
|
3
|
-
export declare function useAuthentication(partnerId: string
|
|
3
|
+
export declare function useAuthentication(partnerId: string, { skipAutoConnect }?: {
|
|
4
|
+
skipAutoConnect?: boolean;
|
|
5
|
+
}): {
|
|
4
6
|
logout: (callback?: () => void) => Promise<void>;
|
|
5
7
|
isAuthenticated: boolean;
|
|
6
8
|
isReady: boolean;
|
|
@@ -657,6 +657,10 @@ interface ModalState {
|
|
|
657
657
|
setLinkingState: (isLinking: boolean, method?: string | null) => void;
|
|
658
658
|
/** Function to update closable property of current content without adding to history */
|
|
659
659
|
setClosable: (closable: boolean) => void;
|
|
660
|
+
/** Whether a third-party iframe (e.g. Persona KYC) is currently active over the modal */
|
|
661
|
+
personaActive: boolean;
|
|
662
|
+
/** Function to mark a third-party iframe as active/inactive */
|
|
663
|
+
setPersonaActive: (active: boolean) => void;
|
|
660
664
|
}
|
|
661
665
|
/**
|
|
662
666
|
* Zustand store for managing modal state
|
|
@@ -25,3 +25,21 @@ export declare function createWagmiConfig(options: CreateWagmiConfigOptions): im
|
|
|
25
25
|
}, {
|
|
26
26
|
"thirdweb:lastChainId": number;
|
|
27
27
|
}>)[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a cached wagmi config for the given partnerId.
|
|
30
|
+
* Use this instead of calling createWagmiConfig() directly inside React components or hooks
|
|
31
|
+
* to avoid registering duplicate EventEmitter listeners on every render.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getCachedWagmiConfig(options: CreateWagmiConfigOptions): import("wagmi").Config<readonly [import("viem").Chain, ...import("viem").Chain[]], {
|
|
34
|
+
[k: string]: import("viem").HttpTransport<undefined, false>;
|
|
35
|
+
}, (CreateConnectorFn | CreateConnectorFn<import("thirdweb/dist/types/adapters/eip1193").EIP1193Provider | undefined, {
|
|
36
|
+
connect<withCapabilities extends boolean = false>(parameters?: import("@thirdweb-dev/wagmi-adapter").ConnectionOptions<withCapabilities> | undefined): Promise<{
|
|
37
|
+
accounts: withCapabilities extends true ? readonly {
|
|
38
|
+
address: `0x${string}`;
|
|
39
|
+
capabilities: Record<string, unknown>;
|
|
40
|
+
}[] : readonly `0x${string}`[];
|
|
41
|
+
chainId: number;
|
|
42
|
+
}>;
|
|
43
|
+
}, {
|
|
44
|
+
"thirdweb:lastChainId": number;
|
|
45
|
+
}>)[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@b3dotfun/sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.69-alpha.0",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"react-native": "./dist/cjs/index.native.js",
|
|
@@ -55,6 +55,11 @@
|
|
|
55
55
|
"import": "./dist/esm/anyspend/constants.js",
|
|
56
56
|
"require": "./dist/cjs/anyspend/constants.js"
|
|
57
57
|
},
|
|
58
|
+
"./anyspend/platform": {
|
|
59
|
+
"types": "./dist/types/anyspend/platform/index.d.ts",
|
|
60
|
+
"import": "./dist/esm/anyspend/platform/index.js",
|
|
61
|
+
"require": "./dist/cjs/anyspend/platform/index.js"
|
|
62
|
+
},
|
|
58
63
|
"./anyspend/services/*": {
|
|
59
64
|
"types": "./dist/types/anyspend/services/*.d.ts",
|
|
60
65
|
"import": "./dist/esm/anyspend/services/*.js",
|
|
@@ -324,6 +329,7 @@
|
|
|
324
329
|
"js-cookie": "3.0.5",
|
|
325
330
|
"lucide-react": "0.424.0",
|
|
326
331
|
"motion": "^12.23.11",
|
|
332
|
+
"persona": "^5.7.0",
|
|
327
333
|
"qrcode.react": "4.2.0",
|
|
328
334
|
"react-easy-crop": "^5.5.3",
|
|
329
335
|
"react-intersection-observer": "9.16.0",
|
|
@@ -29,7 +29,7 @@ Session creation is instant (DB-only, no external calls). The order is created s
|
|
|
29
29
|
## Session Status Lifecycle
|
|
30
30
|
|
|
31
31
|
```
|
|
32
|
-
open --> processing --> complete
|
|
32
|
+
open --> processing --> complete (verified)
|
|
33
33
|
|
|
|
34
34
|
└--> expired
|
|
35
35
|
```
|
|
@@ -37,10 +37,27 @@ open --> processing --> complete
|
|
|
37
37
|
| Status | When |
|
|
38
38
|
|--------|------|
|
|
39
39
|
| `open` | Created, waiting for order/payment |
|
|
40
|
-
| `processing` |
|
|
41
|
-
| `complete` | Order
|
|
40
|
+
| `processing` | Client reported payment, waiting for server-side verification |
|
|
41
|
+
| `complete` | Order verified on-chain by the anyspend-service callback |
|
|
42
42
|
| `expired` | TTL expired, payment failed, or manually expired |
|
|
43
43
|
|
|
44
|
+
## Server-Side Payment Verification
|
|
45
|
+
|
|
46
|
+
Checkout sessions use server-side verification to prevent spoofed completions. The client `/complete` endpoint only transitions a session to `processing` — it does **not** trigger side effects (webhooks, customer creation, discount usage, etc.).
|
|
47
|
+
|
|
48
|
+
The anyspend-service verifies the payment on-chain and sends a callback to the platform's internal endpoint, which finalizes the session to `complete` and runs all side effects. This ensures that webhooks and merchant integrations are only triggered by verified payments.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
Client calls /complete --> session: "processing"
|
|
52
|
+
|
|
|
53
|
+
anyspend-service verifies --> internal callback --> session: "complete" + side effects
|
|
54
|
+
on-chain (order.executed)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Verified sessions include `verified_at` and `verified_by` fields in the session object, providing an audit trail of server-verified completions.
|
|
58
|
+
|
|
59
|
+
**No SDK changes required** — the SDK already passes `checkoutSessionId` in `callbackMetadata` when creating orders, so the verification pipeline works automatically.
|
|
60
|
+
|
|
44
61
|
## API
|
|
45
62
|
|
|
46
63
|
### `POST /checkout-sessions` — Create Session
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core HTTP client for the AnySpend Platform API.
|
|
3
|
+
* Handles authentication, retries, error parsing, and idempotency.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { parseApiError, type ApiErrorResponse } from "./errors";
|
|
7
|
+
import { generateIdempotencyKey } from "./utils/idempotency";
|
|
8
|
+
|
|
9
|
+
export interface ClientConfig {
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
timeout?: number;
|
|
12
|
+
maxRetries?: number;
|
|
13
|
+
idempotencyKeyGenerator?: () => string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const DEFAULT_BASE_URL = "https://platform-api.anyspend.com/api/v1";
|
|
17
|
+
const DEFAULT_TIMEOUT = 30000;
|
|
18
|
+
const DEFAULT_MAX_RETRIES = 3;
|
|
19
|
+
|
|
20
|
+
export class HttpClient {
|
|
21
|
+
private apiKey: string;
|
|
22
|
+
private baseUrl: string;
|
|
23
|
+
private timeout: number;
|
|
24
|
+
private maxRetries: number;
|
|
25
|
+
private generateIdempotencyKey: () => string;
|
|
26
|
+
|
|
27
|
+
constructor(apiKey: string, config: ClientConfig = {}) {
|
|
28
|
+
this.apiKey = apiKey;
|
|
29
|
+
this.baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
|
|
30
|
+
this.timeout = config.timeout || DEFAULT_TIMEOUT;
|
|
31
|
+
this.maxRetries = config.maxRetries || DEFAULT_MAX_RETRIES;
|
|
32
|
+
this.generateIdempotencyKey = config.idempotencyKeyGenerator || generateIdempotencyKey;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async get<T>(path: string, params?: object): Promise<T> {
|
|
36
|
+
const url = this.buildUrl(path, params);
|
|
37
|
+
return this.request<T>("GET", url);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async post<T>(path: string, body?: object): Promise<T> {
|
|
41
|
+
const url = this.buildUrl(path);
|
|
42
|
+
return this.request<T>("POST", url, body);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async patch<T>(path: string, body: object): Promise<T> {
|
|
46
|
+
const url = this.buildUrl(path);
|
|
47
|
+
return this.request<T>("PATCH", url, body);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async delete<T>(path: string, body?: object): Promise<T> {
|
|
51
|
+
const url = this.buildUrl(path);
|
|
52
|
+
return this.request<T>("DELETE", url, body);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async postFormData<T>(path: string, formData: FormData): Promise<T> {
|
|
56
|
+
const url = this.buildUrl(path);
|
|
57
|
+
return this.requestRaw<T>("POST", url, formData);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private buildUrl(path: string, params?: object): string {
|
|
61
|
+
const url = new URL(`${this.baseUrl}${path}`);
|
|
62
|
+
if (params) {
|
|
63
|
+
for (const [key, value] of Object.entries(params as Record<string, unknown>)) {
|
|
64
|
+
if (value !== undefined && value !== null) url.searchParams.set(key, String(value));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return url.toString();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private async request<T>(method: string, url: string, body?: object): Promise<T> {
|
|
71
|
+
const headers: Record<string, string> = {
|
|
72
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
73
|
+
"Content-Type": "application/json",
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// Auto-generate idempotency key for POST/PATCH
|
|
77
|
+
if (method === "POST" || method === "PATCH") {
|
|
78
|
+
headers["Idempotency-Key"] = this.generateIdempotencyKey();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return this.executeWithRetry<T>(method, url, headers, body ? JSON.stringify(body) : undefined);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private async requestRaw<T>(method: string, url: string, body: FormData): Promise<T> {
|
|
85
|
+
const headers: Record<string, string> = {
|
|
86
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return this.executeWithRetry<T>(method, url, headers, body);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private async executeWithRetry<T>(
|
|
93
|
+
method: string,
|
|
94
|
+
url: string,
|
|
95
|
+
headers: Record<string, string>,
|
|
96
|
+
body?: string | FormData,
|
|
97
|
+
): Promise<T> {
|
|
98
|
+
let lastError: Error | undefined;
|
|
99
|
+
|
|
100
|
+
for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
|
|
101
|
+
try {
|
|
102
|
+
const controller = new AbortController();
|
|
103
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
104
|
+
|
|
105
|
+
const response = await fetch(url, {
|
|
106
|
+
method,
|
|
107
|
+
headers,
|
|
108
|
+
body,
|
|
109
|
+
signal: controller.signal,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
clearTimeout(timeoutId);
|
|
113
|
+
|
|
114
|
+
if (response.ok) {
|
|
115
|
+
// Handle CSV/text responses
|
|
116
|
+
const contentType = response.headers.get("Content-Type") || "";
|
|
117
|
+
if (contentType.includes("text/csv")) {
|
|
118
|
+
return (await response.text()) as unknown as T;
|
|
119
|
+
}
|
|
120
|
+
return (await response.json()) as T;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Parse error response
|
|
124
|
+
const errorBody = (await response.json().catch(() => ({
|
|
125
|
+
error: { type: "api_error", code: "internal_error", message: "Unknown error" },
|
|
126
|
+
}))) as ApiErrorResponse;
|
|
127
|
+
|
|
128
|
+
const error = parseApiError(response.status, errorBody, response.headers);
|
|
129
|
+
|
|
130
|
+
// Don't retry 4xx errors (except 429 rate limits)
|
|
131
|
+
if (response.status < 500 && response.status !== 429) {
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// For 429, wait the specified retry-after time
|
|
136
|
+
if (response.status === 429) {
|
|
137
|
+
const retryAfter = parseInt(response.headers.get("Retry-After") || "1", 10);
|
|
138
|
+
await this.sleep(retryAfter * 1000);
|
|
139
|
+
lastError = error;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// For 5xx, retry with exponential backoff
|
|
144
|
+
lastError = error;
|
|
145
|
+
if (attempt < this.maxRetries) {
|
|
146
|
+
await this.sleep(Math.pow(2, attempt) * 1000);
|
|
147
|
+
}
|
|
148
|
+
} catch (err) {
|
|
149
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
150
|
+
lastError = new Error(`Request timed out after ${this.timeout}ms`);
|
|
151
|
+
} else if (err instanceof Error && "type" in err) {
|
|
152
|
+
// Already a parsed ApiError, re-throw
|
|
153
|
+
throw err;
|
|
154
|
+
} else {
|
|
155
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (attempt < this.maxRetries) {
|
|
159
|
+
await this.sleep(Math.pow(2, attempt) * 1000);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
throw lastError || new Error("Request failed after retries");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
private sleep(ms: number): Promise<void> {
|
|
168
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Static HTTP client for unauthenticated requests (quick-pay).
|
|
174
|
+
*/
|
|
175
|
+
export class StaticHttpClient {
|
|
176
|
+
static async post<T>(baseUrl: string, path: string, body: Record<string, unknown>): Promise<T> {
|
|
177
|
+
const url = `${baseUrl.replace(/\/$/, "")}${path}`;
|
|
178
|
+
const controller = new AbortController();
|
|
179
|
+
const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
|
|
180
|
+
const response = await fetch(url, {
|
|
181
|
+
method: "POST",
|
|
182
|
+
headers: { "Content-Type": "application/json" },
|
|
183
|
+
body: JSON.stringify(body),
|
|
184
|
+
signal: controller.signal,
|
|
185
|
+
});
|
|
186
|
+
clearTimeout(timeoutId);
|
|
187
|
+
|
|
188
|
+
if (response.ok) {
|
|
189
|
+
return (await response.json()) as T;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const errorBody = (await response.json().catch(() => ({
|
|
193
|
+
error: { type: "api_error", code: "internal_error", message: "Unknown error" },
|
|
194
|
+
}))) as ApiErrorResponse;
|
|
195
|
+
|
|
196
|
+
throw parseApiError(response.status, errorBody, response.headers);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed error classes for the AnySpend Platform API client.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ApiErrorResponse {
|
|
6
|
+
error: {
|
|
7
|
+
type: string;
|
|
8
|
+
code: string;
|
|
9
|
+
message: string;
|
|
10
|
+
param?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class ApiError extends Error {
|
|
15
|
+
readonly type: string;
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly status: number;
|
|
18
|
+
readonly param?: string;
|
|
19
|
+
|
|
20
|
+
constructor(status: number, body: ApiErrorResponse) {
|
|
21
|
+
super(body.error.message);
|
|
22
|
+
this.name = "ApiError";
|
|
23
|
+
this.type = body.error.type;
|
|
24
|
+
this.code = body.error.code;
|
|
25
|
+
this.status = status;
|
|
26
|
+
this.param = body.error.param;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class AuthenticationError extends ApiError {
|
|
31
|
+
constructor(status: number, body: ApiErrorResponse) {
|
|
32
|
+
super(status, body);
|
|
33
|
+
this.name = "AuthenticationError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class PermissionError extends ApiError {
|
|
38
|
+
constructor(status: number, body: ApiErrorResponse) {
|
|
39
|
+
super(status, body);
|
|
40
|
+
this.name = "PermissionError";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class RateLimitError extends ApiError {
|
|
45
|
+
readonly retryAfter: number;
|
|
46
|
+
|
|
47
|
+
constructor(status: number, body: ApiErrorResponse, retryAfter: number) {
|
|
48
|
+
super(status, body);
|
|
49
|
+
this.name = "RateLimitError";
|
|
50
|
+
this.retryAfter = retryAfter;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export class NotFoundError extends ApiError {
|
|
55
|
+
constructor(status: number, body: ApiErrorResponse) {
|
|
56
|
+
super(status, body);
|
|
57
|
+
this.name = "NotFoundError";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class IdempotencyError extends ApiError {
|
|
62
|
+
constructor(status: number, body: ApiErrorResponse) {
|
|
63
|
+
super(status, body);
|
|
64
|
+
this.name = "IdempotencyError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Parse an API error response into the appropriate typed error class.
|
|
70
|
+
*/
|
|
71
|
+
export function parseApiError(status: number, body: ApiErrorResponse, headers?: Headers): ApiError {
|
|
72
|
+
const type = body.error?.type;
|
|
73
|
+
|
|
74
|
+
if (status === 401 || type === "authentication_error") {
|
|
75
|
+
return new AuthenticationError(status, body);
|
|
76
|
+
}
|
|
77
|
+
if (status === 403 || type === "permission_error") {
|
|
78
|
+
return new PermissionError(status, body);
|
|
79
|
+
}
|
|
80
|
+
if (status === 429 || type === "rate_limit_error") {
|
|
81
|
+
const retryAfter = parseInt(headers?.get("Retry-After") || "60", 10);
|
|
82
|
+
return new RateLimitError(status, body, retryAfter);
|
|
83
|
+
}
|
|
84
|
+
if (status === 404 || type === "not_found_error") {
|
|
85
|
+
return new NotFoundError(status, body);
|
|
86
|
+
}
|
|
87
|
+
if (type === "idempotency_error") {
|
|
88
|
+
return new IdempotencyError(status, body);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return new ApiError(status, body);
|
|
92
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AnySpend Platform API Client
|
|
3
|
+
*
|
|
4
|
+
* A headless TypeScript client for the AnySpend Platform REST API.
|
|
5
|
+
* Works in any runtime with `fetch` (Node.js, browsers, Cloudflare Workers, Deno, Bun).
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { AnySpendPlatformClient } from '@b3dotfun/sdk/anyspend/platform';
|
|
10
|
+
*
|
|
11
|
+
* const platform = new AnySpendPlatformClient('asp_your_api_key_here');
|
|
12
|
+
*
|
|
13
|
+
* // Create a payment link
|
|
14
|
+
* const link = await platform.paymentLinks.create({
|
|
15
|
+
* name: 'Summer Sale',
|
|
16
|
+
* amount: '10000000',
|
|
17
|
+
* token_address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
|
|
18
|
+
* chain_id: 8453,
|
|
19
|
+
* recipient_address: '0x...',
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* // Quick pay (no API key needed)
|
|
23
|
+
* const quickLink = await AnySpendPlatformClient.quickPay({
|
|
24
|
+
* recipient_address: '0x...',
|
|
25
|
+
* amount: '5000000',
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import { HttpClient, StaticHttpClient, DEFAULT_BASE_URL, type ClientConfig } from "./client";
|
|
31
|
+
import { PaymentLinksResource } from "./resources/payment-links";
|
|
32
|
+
import { ProductsResource } from "./resources/products";
|
|
33
|
+
import { CustomersResource } from "./resources/customers";
|
|
34
|
+
import { TransactionsResource } from "./resources/transactions";
|
|
35
|
+
import { CheckoutSessionsResource } from "./resources/checkout-sessions";
|
|
36
|
+
import { WebhooksResource } from "./resources/webhooks";
|
|
37
|
+
import { DiscountCodesResource } from "./resources/discount-codes";
|
|
38
|
+
import { NotificationsResource } from "./resources/notifications";
|
|
39
|
+
import { WidgetsResource } from "./resources/widgets";
|
|
40
|
+
import { OrganizationResource } from "./resources/organization";
|
|
41
|
+
import { AnalyticsResource } from "./resources/analytics";
|
|
42
|
+
import { EventsResource } from "./resources/events";
|
|
43
|
+
import type { QuickPayParams, PaymentLink } from "./types";
|
|
44
|
+
|
|
45
|
+
export class AnySpendPlatformClient {
|
|
46
|
+
private client: HttpClient;
|
|
47
|
+
|
|
48
|
+
/** Payment Links - Create, manage, and track payment links */
|
|
49
|
+
readonly paymentLinks: PaymentLinksResource;
|
|
50
|
+
|
|
51
|
+
/** Products - Manage your product catalog */
|
|
52
|
+
readonly products: ProductsResource;
|
|
53
|
+
|
|
54
|
+
/** Customers - Manage customer records */
|
|
55
|
+
readonly customers: CustomersResource;
|
|
56
|
+
|
|
57
|
+
/** Transactions - View transaction history and stats */
|
|
58
|
+
readonly transactions: TransactionsResource;
|
|
59
|
+
|
|
60
|
+
/** Checkout Sessions - Server-side checkout management */
|
|
61
|
+
readonly checkoutSessions: CheckoutSessionsResource;
|
|
62
|
+
|
|
63
|
+
/** Webhooks - Configure webhook endpoints */
|
|
64
|
+
readonly webhooks: WebhooksResource;
|
|
65
|
+
|
|
66
|
+
/** Discount Codes - Create and validate discounts */
|
|
67
|
+
readonly discountCodes: DiscountCodesResource;
|
|
68
|
+
|
|
69
|
+
/** Notifications - Email and Telegram settings */
|
|
70
|
+
readonly notifications: NotificationsResource;
|
|
71
|
+
|
|
72
|
+
/** Widgets - Embeddable widget configurations */
|
|
73
|
+
readonly widgets: WidgetsResource;
|
|
74
|
+
|
|
75
|
+
/** Organization - Org settings and defaults */
|
|
76
|
+
readonly organization: OrganizationResource;
|
|
77
|
+
|
|
78
|
+
/** Analytics - Revenue and conversion analytics */
|
|
79
|
+
readonly analytics: AnalyticsResource;
|
|
80
|
+
|
|
81
|
+
/** Events - API audit trail */
|
|
82
|
+
readonly events: EventsResource;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Create a new AnySpend Platform API client.
|
|
86
|
+
*
|
|
87
|
+
* @param apiKey - Your API key (starts with `asp_`)
|
|
88
|
+
* @param config - Optional configuration
|
|
89
|
+
*/
|
|
90
|
+
constructor(apiKey: string, config?: ClientConfig) {
|
|
91
|
+
this.client = new HttpClient(apiKey, config);
|
|
92
|
+
|
|
93
|
+
this.paymentLinks = new PaymentLinksResource(this.client);
|
|
94
|
+
this.products = new ProductsResource(this.client);
|
|
95
|
+
this.customers = new CustomersResource(this.client);
|
|
96
|
+
this.transactions = new TransactionsResource(this.client);
|
|
97
|
+
this.checkoutSessions = new CheckoutSessionsResource(this.client);
|
|
98
|
+
this.webhooks = new WebhooksResource(this.client);
|
|
99
|
+
this.discountCodes = new DiscountCodesResource(this.client);
|
|
100
|
+
this.notifications = new NotificationsResource(this.client);
|
|
101
|
+
this.widgets = new WidgetsResource(this.client);
|
|
102
|
+
this.organization = new OrganizationResource(this.client);
|
|
103
|
+
this.analytics = new AnalyticsResource(this.client);
|
|
104
|
+
this.events = new EventsResource(this.client);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Create a quick payment link without authentication.
|
|
109
|
+
* Rate limited to 5 requests per minute per IP.
|
|
110
|
+
*
|
|
111
|
+
* @param params - Quick pay parameters
|
|
112
|
+
* @param baseUrl - Optional API base URL (defaults to production)
|
|
113
|
+
*/
|
|
114
|
+
static async quickPay(params: QuickPayParams, baseUrl: string = DEFAULT_BASE_URL): Promise<PaymentLink> {
|
|
115
|
+
return StaticHttpClient.post<PaymentLink>(baseUrl, "/quick-pay", params as unknown as Record<string, unknown>);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Re-export types and errors
|
|
120
|
+
export type { ClientConfig } from "./client";
|
|
121
|
+
export {
|
|
122
|
+
ApiError,
|
|
123
|
+
AuthenticationError,
|
|
124
|
+
PermissionError,
|
|
125
|
+
RateLimitError,
|
|
126
|
+
NotFoundError,
|
|
127
|
+
IdempotencyError,
|
|
128
|
+
} from "./errors";
|
|
129
|
+
export type * from "./types";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { HttpClient } from "../client";
|
|
2
|
+
import type { AnalyticsOverview } from "../types";
|
|
3
|
+
|
|
4
|
+
export class AnalyticsResource {
|
|
5
|
+
constructor(private client: HttpClient) {}
|
|
6
|
+
|
|
7
|
+
async overview(period?: "7d" | "30d" | "90d" | "all"): Promise<AnalyticsOverview> {
|
|
8
|
+
return this.client.get<AnalyticsOverview>("/analytics/overview", period !== undefined ? { period } : undefined);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HttpClient } from "../client";
|
|
2
|
+
import { autoPaginate } from "../utils/pagination";
|
|
3
|
+
import type { CheckoutSession, ListResponse, CreateCheckoutSessionParams, PaginationParams } from "../types";
|
|
4
|
+
|
|
5
|
+
export interface ListCheckoutSessionsParams extends PaginationParams {
|
|
6
|
+
status?: "open" | "processing" | "completed" | "expired" | "failed";
|
|
7
|
+
payment_link_id?: string;
|
|
8
|
+
from?: number;
|
|
9
|
+
to?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class CheckoutSessionsResource {
|
|
13
|
+
constructor(private client: HttpClient) {}
|
|
14
|
+
|
|
15
|
+
async list(params?: ListCheckoutSessionsParams): Promise<ListResponse<CheckoutSession>> {
|
|
16
|
+
return this.client.get<ListResponse<CheckoutSession>>("/checkout-sessions", params);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async *listAutoPaginate(params?: Omit<ListCheckoutSessionsParams, "page">): AsyncGenerator<CheckoutSession> {
|
|
20
|
+
yield* autoPaginate<CheckoutSession>((page, limit) => this.list({ ...params, page, limit }), {
|
|
21
|
+
limit: params?.limit,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async create(params: CreateCheckoutSessionParams): Promise<CheckoutSession> {
|
|
26
|
+
return this.client.post<CheckoutSession>("/checkout-sessions", params);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async get(id: string): Promise<CheckoutSession> {
|
|
30
|
+
return this.client.get<CheckoutSession>(`/checkout-sessions/${id}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async expire(id: string): Promise<CheckoutSession> {
|
|
34
|
+
return this.client.post<CheckoutSession>(`/checkout-sessions/${id}/expire`);
|
|
35
|
+
}
|
|
36
|
+
}
|