@b3dotfun/sdk 0.1.68-alpha.0 → 0.1.68-alpha.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (232) hide show
  1. package/dist/cjs/anyspend/platform/client.d.ts +35 -0
  2. package/dist/cjs/anyspend/platform/client.js +158 -0
  3. package/dist/cjs/anyspend/platform/errors.d.ts +38 -0
  4. package/dist/cjs/anyspend/platform/errors.js +77 -0
  5. package/dist/cjs/anyspend/platform/index.d.ts +87 -0
  6. package/dist/cjs/anyspend/platform/index.js +85 -0
  7. package/dist/cjs/anyspend/platform/resources/analytics.d.ts +7 -0
  8. package/dist/cjs/anyspend/platform/resources/analytics.js +12 -0
  9. package/dist/cjs/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  10. package/dist/cjs/anyspend/platform/resources/checkout-sessions.js +27 -0
  11. package/dist/cjs/anyspend/platform/resources/customers.d.ts +19 -0
  12. package/dist/cjs/anyspend/platform/resources/customers.js +34 -0
  13. package/dist/cjs/anyspend/platform/resources/discount-codes.d.ts +29 -0
  14. package/dist/cjs/anyspend/platform/resources/discount-codes.js +31 -0
  15. package/dist/cjs/anyspend/platform/resources/events.d.ts +14 -0
  16. package/dist/cjs/anyspend/platform/resources/events.js +16 -0
  17. package/dist/cjs/anyspend/platform/resources/notifications.d.ts +18 -0
  18. package/dist/cjs/anyspend/platform/resources/notifications.js +27 -0
  19. package/dist/cjs/anyspend/platform/resources/organization.d.ts +17 -0
  20. package/dist/cjs/anyspend/platform/resources/organization.js +15 -0
  21. package/dist/cjs/anyspend/platform/resources/payment-links.d.ts +21 -0
  22. package/dist/cjs/anyspend/platform/resources/payment-links.js +49 -0
  23. package/dist/cjs/anyspend/platform/resources/products.d.ts +27 -0
  24. package/dist/cjs/anyspend/platform/resources/products.js +31 -0
  25. package/dist/cjs/anyspend/platform/resources/transactions.d.ts +11 -0
  26. package/dist/cjs/anyspend/platform/resources/transactions.js +25 -0
  27. package/dist/cjs/anyspend/platform/resources/webhooks.d.ts +14 -0
  28. package/dist/cjs/anyspend/platform/resources/webhooks.js +33 -0
  29. package/dist/cjs/anyspend/platform/resources/widgets.d.ts +38 -0
  30. package/dist/cjs/anyspend/platform/resources/widgets.js +31 -0
  31. package/dist/cjs/anyspend/platform/types.d.ts +478 -0
  32. package/dist/cjs/anyspend/platform/types.js +5 -0
  33. package/dist/cjs/anyspend/platform/utils/idempotency.d.ts +4 -0
  34. package/dist/cjs/anyspend/platform/utils/idempotency.js +17 -0
  35. package/dist/cjs/anyspend/platform/utils/pagination.d.ts +12 -0
  36. package/dist/cjs/anyspend/platform/utils/pagination.js +22 -0
  37. package/dist/cjs/anyspend/react/components/AnySpend.d.ts +5 -1
  38. package/dist/cjs/anyspend/react/components/AnySpend.js +123 -12
  39. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
  40. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
  41. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
  42. package/dist/cjs/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +2 -2
  43. package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
  44. package/dist/cjs/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -2
  45. package/dist/cjs/anyspend/react/components/checkout/CryptoPayPanel.js +1 -1
  46. package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
  47. package/dist/cjs/anyspend/react/components/checkout/FiatCheckoutPanel.js +48 -16
  48. package/dist/cjs/anyspend/react/components/checkout/KycGate.d.ts +11 -0
  49. package/dist/cjs/anyspend/react/components/checkout/KycGate.js +203 -0
  50. package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  51. package/dist/cjs/anyspend/react/components/checkout/VariablePricingInput.js +145 -0
  52. package/dist/cjs/anyspend/react/components/index.d.ts +1 -1
  53. package/dist/cjs/anyspend/react/hooks/index.d.ts +1 -0
  54. package/dist/cjs/anyspend/react/hooks/index.js +1 -0
  55. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
  56. package/dist/cjs/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +14 -0
  57. package/dist/cjs/anyspend/react/hooks/useKycStatus.d.ts +47 -0
  58. package/dist/cjs/anyspend/react/hooks/useKycStatus.js +124 -0
  59. package/dist/cjs/anyspend/services/anyspend.d.ts +4 -1
  60. package/dist/cjs/anyspend/services/anyspend.js +3 -1
  61. package/dist/cjs/global-account/react/components/B3DynamicModal.js +1 -1
  62. package/dist/cjs/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
  63. package/dist/cjs/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  64. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -5
  65. package/dist/cjs/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
  66. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
  67. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStep.js +21 -24
  68. package/dist/cjs/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
  69. package/dist/cjs/global-account/react/hooks/useAuth.js +1 -1
  70. package/dist/cjs/global-account/react/hooks/useAuthentication.d.ts +3 -1
  71. package/dist/cjs/global-account/react/hooks/useAuthentication.js +82 -24
  72. package/dist/cjs/global-account/react/hooks/useGetAllTWSigners.js +2 -1
  73. package/dist/cjs/global-account/react/stores/useModalStore.d.ts +4 -0
  74. package/dist/cjs/global-account/react/stores/useModalStore.js +2 -0
  75. package/dist/cjs/global-account/react/utils/createWagmiConfig.d.ts +18 -0
  76. package/dist/cjs/global-account/react/utils/createWagmiConfig.js +17 -0
  77. package/dist/esm/anyspend/platform/client.d.ts +35 -0
  78. package/dist/esm/anyspend/platform/client.js +153 -0
  79. package/dist/esm/anyspend/platform/errors.d.ts +38 -0
  80. package/dist/esm/anyspend/platform/errors.js +67 -0
  81. package/dist/esm/anyspend/platform/index.d.ts +87 -0
  82. package/dist/esm/anyspend/platform/index.js +75 -0
  83. package/dist/esm/anyspend/platform/resources/analytics.d.ts +7 -0
  84. package/dist/esm/anyspend/platform/resources/analytics.js +8 -0
  85. package/dist/esm/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  86. package/dist/esm/anyspend/platform/resources/checkout-sessions.js +23 -0
  87. package/dist/esm/anyspend/platform/resources/customers.d.ts +19 -0
  88. package/dist/esm/anyspend/platform/resources/customers.js +30 -0
  89. package/dist/esm/anyspend/platform/resources/discount-codes.d.ts +29 -0
  90. package/dist/esm/anyspend/platform/resources/discount-codes.js +27 -0
  91. package/dist/esm/anyspend/platform/resources/events.d.ts +14 -0
  92. package/dist/esm/anyspend/platform/resources/events.js +12 -0
  93. package/dist/esm/anyspend/platform/resources/notifications.d.ts +18 -0
  94. package/dist/esm/anyspend/platform/resources/notifications.js +23 -0
  95. package/dist/esm/anyspend/platform/resources/organization.d.ts +17 -0
  96. package/dist/esm/anyspend/platform/resources/organization.js +11 -0
  97. package/dist/esm/anyspend/platform/resources/payment-links.d.ts +21 -0
  98. package/dist/esm/anyspend/platform/resources/payment-links.js +45 -0
  99. package/dist/esm/anyspend/platform/resources/products.d.ts +27 -0
  100. package/dist/esm/anyspend/platform/resources/products.js +27 -0
  101. package/dist/esm/anyspend/platform/resources/transactions.d.ts +11 -0
  102. package/dist/esm/anyspend/platform/resources/transactions.js +21 -0
  103. package/dist/esm/anyspend/platform/resources/webhooks.d.ts +14 -0
  104. package/dist/esm/anyspend/platform/resources/webhooks.js +29 -0
  105. package/dist/esm/anyspend/platform/resources/widgets.d.ts +38 -0
  106. package/dist/esm/anyspend/platform/resources/widgets.js +27 -0
  107. package/dist/esm/anyspend/platform/types.d.ts +478 -0
  108. package/dist/esm/anyspend/platform/types.js +4 -0
  109. package/dist/esm/anyspend/platform/utils/idempotency.d.ts +4 -0
  110. package/dist/esm/anyspend/platform/utils/idempotency.js +14 -0
  111. package/dist/esm/anyspend/platform/utils/pagination.d.ts +12 -0
  112. package/dist/esm/anyspend/platform/utils/pagination.js +19 -0
  113. package/dist/esm/anyspend/react/components/AnySpend.d.ts +5 -1
  114. package/dist/esm/anyspend/react/components/AnySpend.js +124 -13
  115. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
  116. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckout.js +55 -8
  117. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
  118. package/dist/esm/anyspend/react/components/checkout/AnySpendCheckoutTrigger.js +2 -2
  119. package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
  120. package/dist/esm/anyspend/react/components/checkout/CheckoutPaymentPanel.js +2 -2
  121. package/dist/esm/anyspend/react/components/checkout/CryptoPayPanel.js +1 -1
  122. package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
  123. package/dist/esm/anyspend/react/components/checkout/FiatCheckoutPanel.js +50 -18
  124. package/dist/esm/anyspend/react/components/checkout/KycGate.d.ts +11 -0
  125. package/dist/esm/anyspend/react/components/checkout/KycGate.js +167 -0
  126. package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  127. package/dist/esm/anyspend/react/components/checkout/VariablePricingInput.js +142 -0
  128. package/dist/esm/anyspend/react/components/index.d.ts +1 -1
  129. package/dist/esm/anyspend/react/hooks/index.d.ts +1 -0
  130. package/dist/esm/anyspend/react/hooks/index.js +1 -0
  131. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
  132. package/dist/esm/anyspend/react/hooks/useAnyspendCreateOnrampOrder.js +14 -0
  133. package/dist/esm/anyspend/react/hooks/useKycStatus.d.ts +47 -0
  134. package/dist/esm/anyspend/react/hooks/useKycStatus.js +117 -0
  135. package/dist/esm/anyspend/services/anyspend.d.ts +4 -1
  136. package/dist/esm/anyspend/services/anyspend.js +3 -1
  137. package/dist/esm/global-account/react/components/B3DynamicModal.js +1 -1
  138. package/dist/esm/global-account/react/components/ManageAccount/BottomNavigation.js +3 -3
  139. package/dist/esm/global-account/react/components/SignInWithB3/SignIn.js +1 -1
  140. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Flow.js +13 -5
  141. package/dist/esm/global-account/react/components/SignInWithB3/SignInWithB3Privy.js +1 -1
  142. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
  143. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStep.js +21 -24
  144. package/dist/esm/global-account/react/components/SignInWithB3/steps/LoginStepCustom.js +1 -1
  145. package/dist/esm/global-account/react/hooks/useAuth.js +2 -2
  146. package/dist/esm/global-account/react/hooks/useAuthentication.d.ts +3 -1
  147. package/dist/esm/global-account/react/hooks/useAuthentication.js +82 -24
  148. package/dist/esm/global-account/react/hooks/useGetAllTWSigners.js +2 -1
  149. package/dist/esm/global-account/react/stores/useModalStore.d.ts +4 -0
  150. package/dist/esm/global-account/react/stores/useModalStore.js +2 -0
  151. package/dist/esm/global-account/react/utils/createWagmiConfig.d.ts +18 -0
  152. package/dist/esm/global-account/react/utils/createWagmiConfig.js +16 -0
  153. package/dist/styles/index.css +1 -1
  154. package/dist/types/anyspend/platform/client.d.ts +35 -0
  155. package/dist/types/anyspend/platform/errors.d.ts +38 -0
  156. package/dist/types/anyspend/platform/index.d.ts +87 -0
  157. package/dist/types/anyspend/platform/resources/analytics.d.ts +7 -0
  158. package/dist/types/anyspend/platform/resources/checkout-sessions.d.ts +17 -0
  159. package/dist/types/anyspend/platform/resources/customers.d.ts +19 -0
  160. package/dist/types/anyspend/platform/resources/discount-codes.d.ts +29 -0
  161. package/dist/types/anyspend/platform/resources/events.d.ts +14 -0
  162. package/dist/types/anyspend/platform/resources/notifications.d.ts +18 -0
  163. package/dist/types/anyspend/platform/resources/organization.d.ts +17 -0
  164. package/dist/types/anyspend/platform/resources/payment-links.d.ts +21 -0
  165. package/dist/types/anyspend/platform/resources/products.d.ts +27 -0
  166. package/dist/types/anyspend/platform/resources/transactions.d.ts +11 -0
  167. package/dist/types/anyspend/platform/resources/webhooks.d.ts +14 -0
  168. package/dist/types/anyspend/platform/resources/widgets.d.ts +38 -0
  169. package/dist/types/anyspend/platform/types.d.ts +478 -0
  170. package/dist/types/anyspend/platform/utils/idempotency.d.ts +4 -0
  171. package/dist/types/anyspend/platform/utils/pagination.d.ts +12 -0
  172. package/dist/types/anyspend/react/components/AnySpend.d.ts +5 -1
  173. package/dist/types/anyspend/react/components/checkout/AnySpendCheckout.d.ts +14 -6
  174. package/dist/types/anyspend/react/components/checkout/AnySpendCheckoutTrigger.d.ts +3 -1
  175. package/dist/types/anyspend/react/components/checkout/CheckoutPaymentPanel.d.ts +5 -1
  176. package/dist/types/anyspend/react/components/checkout/FiatCheckoutPanel.d.ts +5 -1
  177. package/dist/types/anyspend/react/components/checkout/KycGate.d.ts +11 -0
  178. package/dist/types/anyspend/react/components/checkout/VariablePricingInput.d.ts +17 -0
  179. package/dist/types/anyspend/react/components/index.d.ts +1 -1
  180. package/dist/types/anyspend/react/hooks/index.d.ts +1 -0
  181. package/dist/types/anyspend/react/hooks/useAnyspendCreateOnrampOrder.d.ts +2 -0
  182. package/dist/types/anyspend/react/hooks/useKycStatus.d.ts +47 -0
  183. package/dist/types/anyspend/services/anyspend.d.ts +4 -1
  184. package/dist/types/global-account/react/components/SignInWithB3/steps/LoginStep.d.ts +1 -1
  185. package/dist/types/global-account/react/hooks/useAuthentication.d.ts +3 -1
  186. package/dist/types/global-account/react/stores/useModalStore.d.ts +4 -0
  187. package/dist/types/global-account/react/utils/createWagmiConfig.d.ts +18 -0
  188. package/package.json +7 -1
  189. package/src/anyspend/docs/checkout-sessions.md +20 -3
  190. package/src/anyspend/platform/client.ts +198 -0
  191. package/src/anyspend/platform/errors.ts +92 -0
  192. package/src/anyspend/platform/index.ts +129 -0
  193. package/src/anyspend/platform/resources/analytics.ts +10 -0
  194. package/src/anyspend/platform/resources/checkout-sessions.ts +36 -0
  195. package/src/anyspend/platform/resources/customers.ts +54 -0
  196. package/src/anyspend/platform/resources/discount-codes.ts +63 -0
  197. package/src/anyspend/platform/resources/events.ts +22 -0
  198. package/src/anyspend/platform/resources/notifications.ts +37 -0
  199. package/src/anyspend/platform/resources/organization.ts +24 -0
  200. package/src/anyspend/platform/resources/payment-links.ts +74 -0
  201. package/src/anyspend/platform/resources/products.ts +59 -0
  202. package/src/anyspend/platform/resources/transactions.ts +33 -0
  203. package/src/anyspend/platform/resources/webhooks.ts +47 -0
  204. package/src/anyspend/platform/resources/widgets.ts +63 -0
  205. package/src/anyspend/platform/types.ts +532 -0
  206. package/src/anyspend/platform/utils/idempotency.ts +15 -0
  207. package/src/anyspend/platform/utils/pagination.ts +32 -0
  208. package/src/anyspend/react/components/AnySpend.tsx +148 -14
  209. package/src/anyspend/react/components/checkout/AnySpendCheckout.tsx +81 -18
  210. package/src/anyspend/react/components/checkout/AnySpendCheckoutTrigger.tsx +4 -0
  211. package/src/anyspend/react/components/checkout/CheckoutPaymentPanel.tsx +8 -0
  212. package/src/anyspend/react/components/checkout/CryptoPayPanel.tsx +4 -13
  213. package/src/anyspend/react/components/checkout/FiatCheckoutPanel.tsx +86 -17
  214. package/src/anyspend/react/components/checkout/KycGate.tsx +387 -0
  215. package/src/anyspend/react/components/checkout/VariablePricingInput.tsx +247 -0
  216. package/src/anyspend/react/components/index.ts +1 -0
  217. package/src/anyspend/react/hooks/index.ts +1 -0
  218. package/src/anyspend/react/hooks/useAnyspendCreateOnrampOrder.ts +17 -0
  219. package/src/anyspend/react/hooks/useKycStatus.ts +150 -0
  220. package/src/anyspend/services/anyspend.ts +7 -0
  221. package/src/global-account/react/components/B3DynamicModal.tsx +0 -2
  222. package/src/global-account/react/components/ManageAccount/BottomNavigation.tsx +7 -7
  223. package/src/global-account/react/components/SignInWithB3/SignIn.tsx +1 -1
  224. package/src/global-account/react/components/SignInWithB3/SignInWithB3Flow.tsx +13 -5
  225. package/src/global-account/react/components/SignInWithB3/SignInWithB3Privy.tsx +1 -1
  226. package/src/global-account/react/components/SignInWithB3/steps/LoginStep.tsx +35 -25
  227. package/src/global-account/react/components/SignInWithB3/steps/LoginStepCustom.tsx +1 -1
  228. package/src/global-account/react/hooks/useAuth.ts +2 -2
  229. package/src/global-account/react/hooks/useAuthentication.ts +80 -27
  230. package/src/global-account/react/hooks/useGetAllTWSigners.tsx +2 -1
  231. package/src/global-account/react/stores/useModalStore.ts +6 -0
  232. package/src/global-account/react/utils/createWagmiConfig.tsx +18 -0
@@ -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
+ }>)[]>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createWagmiConfig = createWagmiConfig;
4
+ exports.getCachedWagmiConfig = getCachedWagmiConfig;
4
5
  const constants_1 = require("../../../shared/constants");
5
6
  const supported_1 = require("../../../shared/constants/chains/supported");
6
7
  const thirdweb_1 = require("../../../shared/utils/thirdweb");
@@ -30,3 +31,19 @@ function createWagmiConfig(options) {
30
31
  connectors: finalConnectors,
31
32
  });
32
33
  }
34
+ /** Module-level cache — wagmi configs must not be recreated on every render. */
35
+ const wagmiConfigCache = new Map();
36
+ /**
37
+ * Returns a cached wagmi config for the given partnerId.
38
+ * Use this instead of calling createWagmiConfig() directly inside React components or hooks
39
+ * to avoid registering duplicate EventEmitter listeners on every render.
40
+ */
41
+ function getCachedWagmiConfig(options) {
42
+ const key = options.partnerId;
43
+ let config = wagmiConfigCache.get(key);
44
+ if (!config) {
45
+ config = createWagmiConfig(options);
46
+ wagmiConfigCache.set(key, config);
47
+ }
48
+ return config;
49
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Core HTTP client for the AnySpend Platform API.
3
+ * Handles authentication, retries, error parsing, and idempotency.
4
+ */
5
+ export interface ClientConfig {
6
+ baseUrl?: string;
7
+ timeout?: number;
8
+ maxRetries?: number;
9
+ idempotencyKeyGenerator?: () => string;
10
+ }
11
+ export declare const DEFAULT_BASE_URL = "https://platform-api.anyspend.com/api/v1";
12
+ export declare class HttpClient {
13
+ private apiKey;
14
+ private baseUrl;
15
+ private timeout;
16
+ private maxRetries;
17
+ private generateIdempotencyKey;
18
+ constructor(apiKey: string, config?: ClientConfig);
19
+ get<T>(path: string, params?: object): Promise<T>;
20
+ post<T>(path: string, body?: object): Promise<T>;
21
+ patch<T>(path: string, body: object): Promise<T>;
22
+ delete<T>(path: string, body?: object): Promise<T>;
23
+ postFormData<T>(path: string, formData: FormData): Promise<T>;
24
+ private buildUrl;
25
+ private request;
26
+ private requestRaw;
27
+ private executeWithRetry;
28
+ private sleep;
29
+ }
30
+ /**
31
+ * Static HTTP client for unauthenticated requests (quick-pay).
32
+ */
33
+ export declare class StaticHttpClient {
34
+ static post<T>(baseUrl: string, path: string, body: Record<string, unknown>): Promise<T>;
35
+ }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * Core HTTP client for the AnySpend Platform API.
3
+ * Handles authentication, retries, error parsing, and idempotency.
4
+ */
5
+ import { parseApiError } from "./errors.js";
6
+ import { generateIdempotencyKey } from "./utils/idempotency.js";
7
+ export const DEFAULT_BASE_URL = "https://platform-api.anyspend.com/api/v1";
8
+ const DEFAULT_TIMEOUT = 30000;
9
+ const DEFAULT_MAX_RETRIES = 3;
10
+ export class HttpClient {
11
+ constructor(apiKey, config = {}) {
12
+ this.apiKey = apiKey;
13
+ this.baseUrl = (config.baseUrl || DEFAULT_BASE_URL).replace(/\/$/, "");
14
+ this.timeout = config.timeout || DEFAULT_TIMEOUT;
15
+ this.maxRetries = config.maxRetries || DEFAULT_MAX_RETRIES;
16
+ this.generateIdempotencyKey = config.idempotencyKeyGenerator || generateIdempotencyKey;
17
+ }
18
+ async get(path, params) {
19
+ const url = this.buildUrl(path, params);
20
+ return this.request("GET", url);
21
+ }
22
+ async post(path, body) {
23
+ const url = this.buildUrl(path);
24
+ return this.request("POST", url, body);
25
+ }
26
+ async patch(path, body) {
27
+ const url = this.buildUrl(path);
28
+ return this.request("PATCH", url, body);
29
+ }
30
+ async delete(path, body) {
31
+ const url = this.buildUrl(path);
32
+ return this.request("DELETE", url, body);
33
+ }
34
+ async postFormData(path, formData) {
35
+ const url = this.buildUrl(path);
36
+ return this.requestRaw("POST", url, formData);
37
+ }
38
+ buildUrl(path, params) {
39
+ const url = new URL(`${this.baseUrl}${path}`);
40
+ if (params) {
41
+ for (const [key, value] of Object.entries(params)) {
42
+ if (value !== undefined && value !== null)
43
+ url.searchParams.set(key, String(value));
44
+ }
45
+ }
46
+ return url.toString();
47
+ }
48
+ async request(method, url, body) {
49
+ const headers = {
50
+ Authorization: `Bearer ${this.apiKey}`,
51
+ "Content-Type": "application/json",
52
+ };
53
+ // Auto-generate idempotency key for POST/PATCH
54
+ if (method === "POST" || method === "PATCH") {
55
+ headers["Idempotency-Key"] = this.generateIdempotencyKey();
56
+ }
57
+ return this.executeWithRetry(method, url, headers, body ? JSON.stringify(body) : undefined);
58
+ }
59
+ async requestRaw(method, url, body) {
60
+ const headers = {
61
+ Authorization: `Bearer ${this.apiKey}`,
62
+ };
63
+ return this.executeWithRetry(method, url, headers, body);
64
+ }
65
+ async executeWithRetry(method, url, headers, body) {
66
+ let lastError;
67
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
68
+ try {
69
+ const controller = new AbortController();
70
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
71
+ const response = await fetch(url, {
72
+ method,
73
+ headers,
74
+ body,
75
+ signal: controller.signal,
76
+ });
77
+ clearTimeout(timeoutId);
78
+ if (response.ok) {
79
+ // Handle CSV/text responses
80
+ const contentType = response.headers.get("Content-Type") || "";
81
+ if (contentType.includes("text/csv")) {
82
+ return (await response.text());
83
+ }
84
+ return (await response.json());
85
+ }
86
+ // Parse error response
87
+ const errorBody = (await response.json().catch(() => ({
88
+ error: { type: "api_error", code: "internal_error", message: "Unknown error" },
89
+ })));
90
+ const error = parseApiError(response.status, errorBody, response.headers);
91
+ // Don't retry 4xx errors (except 429 rate limits)
92
+ if (response.status < 500 && response.status !== 429) {
93
+ throw error;
94
+ }
95
+ // For 429, wait the specified retry-after time
96
+ if (response.status === 429) {
97
+ const retryAfter = parseInt(response.headers.get("Retry-After") || "1", 10);
98
+ await this.sleep(retryAfter * 1000);
99
+ lastError = error;
100
+ continue;
101
+ }
102
+ // For 5xx, retry with exponential backoff
103
+ lastError = error;
104
+ if (attempt < this.maxRetries) {
105
+ await this.sleep(Math.pow(2, attempt) * 1000);
106
+ }
107
+ }
108
+ catch (err) {
109
+ if (err instanceof Error && err.name === "AbortError") {
110
+ lastError = new Error(`Request timed out after ${this.timeout}ms`);
111
+ }
112
+ else if (err instanceof Error && "type" in err) {
113
+ // Already a parsed ApiError, re-throw
114
+ throw err;
115
+ }
116
+ else {
117
+ lastError = err instanceof Error ? err : new Error(String(err));
118
+ }
119
+ if (attempt < this.maxRetries) {
120
+ await this.sleep(Math.pow(2, attempt) * 1000);
121
+ }
122
+ }
123
+ }
124
+ throw lastError || new Error("Request failed after retries");
125
+ }
126
+ sleep(ms) {
127
+ return new Promise(resolve => setTimeout(resolve, ms));
128
+ }
129
+ }
130
+ /**
131
+ * Static HTTP client for unauthenticated requests (quick-pay).
132
+ */
133
+ export class StaticHttpClient {
134
+ static async post(baseUrl, path, body) {
135
+ const url = `${baseUrl.replace(/\/$/, "")}${path}`;
136
+ const controller = new AbortController();
137
+ const timeoutId = setTimeout(() => controller.abort(), DEFAULT_TIMEOUT);
138
+ const response = await fetch(url, {
139
+ method: "POST",
140
+ headers: { "Content-Type": "application/json" },
141
+ body: JSON.stringify(body),
142
+ signal: controller.signal,
143
+ });
144
+ clearTimeout(timeoutId);
145
+ if (response.ok) {
146
+ return (await response.json());
147
+ }
148
+ const errorBody = (await response.json().catch(() => ({
149
+ error: { type: "api_error", code: "internal_error", message: "Unknown error" },
150
+ })));
151
+ throw parseApiError(response.status, errorBody, response.headers);
152
+ }
153
+ }
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Typed error classes for the AnySpend Platform API client.
3
+ */
4
+ export interface ApiErrorResponse {
5
+ error: {
6
+ type: string;
7
+ code: string;
8
+ message: string;
9
+ param?: string;
10
+ };
11
+ }
12
+ export declare class ApiError extends Error {
13
+ readonly type: string;
14
+ readonly code: string;
15
+ readonly status: number;
16
+ readonly param?: string;
17
+ constructor(status: number, body: ApiErrorResponse);
18
+ }
19
+ export declare class AuthenticationError extends ApiError {
20
+ constructor(status: number, body: ApiErrorResponse);
21
+ }
22
+ export declare class PermissionError extends ApiError {
23
+ constructor(status: number, body: ApiErrorResponse);
24
+ }
25
+ export declare class RateLimitError extends ApiError {
26
+ readonly retryAfter: number;
27
+ constructor(status: number, body: ApiErrorResponse, retryAfter: number);
28
+ }
29
+ export declare class NotFoundError extends ApiError {
30
+ constructor(status: number, body: ApiErrorResponse);
31
+ }
32
+ export declare class IdempotencyError extends ApiError {
33
+ constructor(status: number, body: ApiErrorResponse);
34
+ }
35
+ /**
36
+ * Parse an API error response into the appropriate typed error class.
37
+ */
38
+ export declare function parseApiError(status: number, body: ApiErrorResponse, headers?: Headers): ApiError;
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Typed error classes for the AnySpend Platform API client.
3
+ */
4
+ export class ApiError extends Error {
5
+ constructor(status, body) {
6
+ super(body.error.message);
7
+ this.name = "ApiError";
8
+ this.type = body.error.type;
9
+ this.code = body.error.code;
10
+ this.status = status;
11
+ this.param = body.error.param;
12
+ }
13
+ }
14
+ export class AuthenticationError extends ApiError {
15
+ constructor(status, body) {
16
+ super(status, body);
17
+ this.name = "AuthenticationError";
18
+ }
19
+ }
20
+ export class PermissionError extends ApiError {
21
+ constructor(status, body) {
22
+ super(status, body);
23
+ this.name = "PermissionError";
24
+ }
25
+ }
26
+ export class RateLimitError extends ApiError {
27
+ constructor(status, body, retryAfter) {
28
+ super(status, body);
29
+ this.name = "RateLimitError";
30
+ this.retryAfter = retryAfter;
31
+ }
32
+ }
33
+ export class NotFoundError extends ApiError {
34
+ constructor(status, body) {
35
+ super(status, body);
36
+ this.name = "NotFoundError";
37
+ }
38
+ }
39
+ export class IdempotencyError extends ApiError {
40
+ constructor(status, body) {
41
+ super(status, body);
42
+ this.name = "IdempotencyError";
43
+ }
44
+ }
45
+ /**
46
+ * Parse an API error response into the appropriate typed error class.
47
+ */
48
+ export function parseApiError(status, body, headers) {
49
+ const type = body.error?.type;
50
+ if (status === 401 || type === "authentication_error") {
51
+ return new AuthenticationError(status, body);
52
+ }
53
+ if (status === 403 || type === "permission_error") {
54
+ return new PermissionError(status, body);
55
+ }
56
+ if (status === 429 || type === "rate_limit_error") {
57
+ const retryAfter = parseInt(headers?.get("Retry-After") || "60", 10);
58
+ return new RateLimitError(status, body, retryAfter);
59
+ }
60
+ if (status === 404 || type === "not_found_error") {
61
+ return new NotFoundError(status, body);
62
+ }
63
+ if (type === "idempotency_error") {
64
+ return new IdempotencyError(status, body);
65
+ }
66
+ return new ApiError(status, body);
67
+ }
@@ -0,0 +1,87 @@
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 '../../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
+ import { type ClientConfig } from "./client";
30
+ import { PaymentLinksResource } from "./resources/payment-links";
31
+ import { ProductsResource } from "./resources/products";
32
+ import { CustomersResource } from "./resources/customers";
33
+ import { TransactionsResource } from "./resources/transactions";
34
+ import { CheckoutSessionsResource } from "./resources/checkout-sessions";
35
+ import { WebhooksResource } from "./resources/webhooks";
36
+ import { DiscountCodesResource } from "./resources/discount-codes";
37
+ import { NotificationsResource } from "./resources/notifications";
38
+ import { WidgetsResource } from "./resources/widgets";
39
+ import { OrganizationResource } from "./resources/organization";
40
+ import { AnalyticsResource } from "./resources/analytics";
41
+ import { EventsResource } from "./resources/events";
42
+ import type { QuickPayParams, PaymentLink } from "./types";
43
+ export declare class AnySpendPlatformClient {
44
+ private client;
45
+ /** Payment Links - Create, manage, and track payment links */
46
+ readonly paymentLinks: PaymentLinksResource;
47
+ /** Products - Manage your product catalog */
48
+ readonly products: ProductsResource;
49
+ /** Customers - Manage customer records */
50
+ readonly customers: CustomersResource;
51
+ /** Transactions - View transaction history and stats */
52
+ readonly transactions: TransactionsResource;
53
+ /** Checkout Sessions - Server-side checkout management */
54
+ readonly checkoutSessions: CheckoutSessionsResource;
55
+ /** Webhooks - Configure webhook endpoints */
56
+ readonly webhooks: WebhooksResource;
57
+ /** Discount Codes - Create and validate discounts */
58
+ readonly discountCodes: DiscountCodesResource;
59
+ /** Notifications - Email and Telegram settings */
60
+ readonly notifications: NotificationsResource;
61
+ /** Widgets - Embeddable widget configurations */
62
+ readonly widgets: WidgetsResource;
63
+ /** Organization - Org settings and defaults */
64
+ readonly organization: OrganizationResource;
65
+ /** Analytics - Revenue and conversion analytics */
66
+ readonly analytics: AnalyticsResource;
67
+ /** Events - API audit trail */
68
+ readonly events: EventsResource;
69
+ /**
70
+ * Create a new AnySpend Platform API client.
71
+ *
72
+ * @param apiKey - Your API key (starts with `asp_`)
73
+ * @param config - Optional configuration
74
+ */
75
+ constructor(apiKey: string, config?: ClientConfig);
76
+ /**
77
+ * Create a quick payment link without authentication.
78
+ * Rate limited to 5 requests per minute per IP.
79
+ *
80
+ * @param params - Quick pay parameters
81
+ * @param baseUrl - Optional API base URL (defaults to production)
82
+ */
83
+ static quickPay(params: QuickPayParams, baseUrl?: string): Promise<PaymentLink>;
84
+ }
85
+ export type { ClientConfig } from "./client";
86
+ export { ApiError, AuthenticationError, PermissionError, RateLimitError, NotFoundError, IdempotencyError, } from "./errors";
87
+ export type * from "./types";
@@ -0,0 +1,75 @@
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 '../../anyspend/platform/index.js';
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
+ import { HttpClient, StaticHttpClient, DEFAULT_BASE_URL } from "./client.js";
30
+ import { PaymentLinksResource } from "./resources/payment-links.js";
31
+ import { ProductsResource } from "./resources/products.js";
32
+ import { CustomersResource } from "./resources/customers.js";
33
+ import { TransactionsResource } from "./resources/transactions.js";
34
+ import { CheckoutSessionsResource } from "./resources/checkout-sessions.js";
35
+ import { WebhooksResource } from "./resources/webhooks.js";
36
+ import { DiscountCodesResource } from "./resources/discount-codes.js";
37
+ import { NotificationsResource } from "./resources/notifications.js";
38
+ import { WidgetsResource } from "./resources/widgets.js";
39
+ import { OrganizationResource } from "./resources/organization.js";
40
+ import { AnalyticsResource } from "./resources/analytics.js";
41
+ import { EventsResource } from "./resources/events.js";
42
+ export class AnySpendPlatformClient {
43
+ /**
44
+ * Create a new AnySpend Platform API client.
45
+ *
46
+ * @param apiKey - Your API key (starts with `asp_`)
47
+ * @param config - Optional configuration
48
+ */
49
+ constructor(apiKey, config) {
50
+ this.client = new HttpClient(apiKey, config);
51
+ this.paymentLinks = new PaymentLinksResource(this.client);
52
+ this.products = new ProductsResource(this.client);
53
+ this.customers = new CustomersResource(this.client);
54
+ this.transactions = new TransactionsResource(this.client);
55
+ this.checkoutSessions = new CheckoutSessionsResource(this.client);
56
+ this.webhooks = new WebhooksResource(this.client);
57
+ this.discountCodes = new DiscountCodesResource(this.client);
58
+ this.notifications = new NotificationsResource(this.client);
59
+ this.widgets = new WidgetsResource(this.client);
60
+ this.organization = new OrganizationResource(this.client);
61
+ this.analytics = new AnalyticsResource(this.client);
62
+ this.events = new EventsResource(this.client);
63
+ }
64
+ /**
65
+ * Create a quick payment link without authentication.
66
+ * Rate limited to 5 requests per minute per IP.
67
+ *
68
+ * @param params - Quick pay parameters
69
+ * @param baseUrl - Optional API base URL (defaults to production)
70
+ */
71
+ static async quickPay(params, baseUrl = DEFAULT_BASE_URL) {
72
+ return StaticHttpClient.post(baseUrl, "/quick-pay", params);
73
+ }
74
+ }
75
+ export { ApiError, AuthenticationError, PermissionError, RateLimitError, NotFoundError, IdempotencyError, } from "./errors.js";
@@ -0,0 +1,7 @@
1
+ import type { HttpClient } from "../client";
2
+ import type { AnalyticsOverview } from "../types";
3
+ export declare class AnalyticsResource {
4
+ private client;
5
+ constructor(client: HttpClient);
6
+ overview(period?: "7d" | "30d" | "90d" | "all"): Promise<AnalyticsOverview>;
7
+ }
@@ -0,0 +1,8 @@
1
+ export class AnalyticsResource {
2
+ constructor(client) {
3
+ this.client = client;
4
+ }
5
+ async overview(period) {
6
+ return this.client.get("/analytics/overview", period !== undefined ? { period } : undefined);
7
+ }
8
+ }
@@ -0,0 +1,17 @@
1
+ import type { HttpClient } from "../client";
2
+ import type { CheckoutSession, ListResponse, CreateCheckoutSessionParams, PaginationParams } from "../types";
3
+ export interface ListCheckoutSessionsParams extends PaginationParams {
4
+ status?: "open" | "processing" | "completed" | "expired" | "failed";
5
+ payment_link_id?: string;
6
+ from?: number;
7
+ to?: number;
8
+ }
9
+ export declare class CheckoutSessionsResource {
10
+ private client;
11
+ constructor(client: HttpClient);
12
+ list(params?: ListCheckoutSessionsParams): Promise<ListResponse<CheckoutSession>>;
13
+ listAutoPaginate(params?: Omit<ListCheckoutSessionsParams, "page">): AsyncGenerator<CheckoutSession>;
14
+ create(params: CreateCheckoutSessionParams): Promise<CheckoutSession>;
15
+ get(id: string): Promise<CheckoutSession>;
16
+ expire(id: string): Promise<CheckoutSession>;
17
+ }
@@ -0,0 +1,23 @@
1
+ import { autoPaginate } from "../utils/pagination.js";
2
+ export class CheckoutSessionsResource {
3
+ constructor(client) {
4
+ this.client = client;
5
+ }
6
+ async list(params) {
7
+ return this.client.get("/checkout-sessions", params);
8
+ }
9
+ async *listAutoPaginate(params) {
10
+ yield* autoPaginate((page, limit) => this.list({ ...params, page, limit }), {
11
+ limit: params?.limit,
12
+ });
13
+ }
14
+ async create(params) {
15
+ return this.client.post("/checkout-sessions", params);
16
+ }
17
+ async get(id) {
18
+ return this.client.get(`/checkout-sessions/${id}`);
19
+ }
20
+ async expire(id) {
21
+ return this.client.post(`/checkout-sessions/${id}/expire`);
22
+ }
23
+ }
@@ -0,0 +1,19 @@
1
+ import type { HttpClient } from "../client";
2
+ import type { Customer, Transaction, ListResponse, DeletedResponse, CreateCustomerParams, UpdateCustomerParams, ExportCustomersParams, PaginationParams } from "../types";
3
+ export interface ListCustomersParams extends PaginationParams {
4
+ search?: string;
5
+ sort?: "created_at" | "updated_at" | "total_paid" | "transaction_count";
6
+ order?: "asc" | "desc";
7
+ }
8
+ export declare class CustomersResource {
9
+ private client;
10
+ constructor(client: HttpClient);
11
+ list(params?: ListCustomersParams): Promise<ListResponse<Customer>>;
12
+ listAutoPaginate(params?: Omit<ListCustomersParams, "page">): AsyncGenerator<Customer>;
13
+ create(params: CreateCustomerParams): Promise<Customer>;
14
+ get(id: string): Promise<Customer>;
15
+ update(id: string, params: UpdateCustomerParams): Promise<Customer>;
16
+ delete(id: string): Promise<DeletedResponse>;
17
+ transactions(id: string, params?: PaginationParams): Promise<ListResponse<Transaction>>;
18
+ export(params?: ExportCustomersParams): Promise<string>;
19
+ }
@@ -0,0 +1,30 @@
1
+ import { autoPaginate } from "../utils/pagination.js";
2
+ export class CustomersResource {
3
+ constructor(client) {
4
+ this.client = client;
5
+ }
6
+ async list(params) {
7
+ return this.client.get("/customers", params);
8
+ }
9
+ async *listAutoPaginate(params) {
10
+ yield* autoPaginate((page, limit) => this.list({ ...params, page, limit }), { limit: params?.limit });
11
+ }
12
+ async create(params) {
13
+ return this.client.post("/customers", params);
14
+ }
15
+ async get(id) {
16
+ return this.client.get(`/customers/${id}`);
17
+ }
18
+ async update(id, params) {
19
+ return this.client.patch(`/customers/${id}`, params);
20
+ }
21
+ async delete(id) {
22
+ return this.client.delete(`/customers/${id}`);
23
+ }
24
+ async transactions(id, params) {
25
+ return this.client.get(`/customers/${id}/transactions`, params);
26
+ }
27
+ async export(params) {
28
+ return this.client.get("/customers/export", params);
29
+ }
30
+ }
@@ -0,0 +1,29 @@
1
+ import type { HttpClient } from "../client";
2
+ import type { DiscountCode, ListResponse, DeletedResponse, CreateDiscountCodeParams, BatchCreateDiscountCodesParams, ValidateDiscountResult, BatchCreateResult, PaginationParams } from "../types";
3
+ export interface ListDiscountCodesParams extends PaginationParams {
4
+ payment_link_id?: string;
5
+ active?: "true" | "false";
6
+ search?: string;
7
+ }
8
+ export interface UpdateDiscountCodeParams {
9
+ is_active?: boolean;
10
+ max_uses?: number;
11
+ min_order_amount?: string;
12
+ expires_at?: number;
13
+ }
14
+ export interface ValidateDiscountParams {
15
+ code: string;
16
+ payment_link_id?: string;
17
+ amount?: string;
18
+ }
19
+ export declare class DiscountCodesResource {
20
+ private client;
21
+ constructor(client: HttpClient);
22
+ list(params?: ListDiscountCodesParams): Promise<ListResponse<DiscountCode>>;
23
+ listAutoPaginate(params?: Omit<ListDiscountCodesParams, "page">): AsyncGenerator<DiscountCode>;
24
+ create(params: CreateDiscountCodeParams): Promise<DiscountCode>;
25
+ update(id: string, params: UpdateDiscountCodeParams): Promise<DiscountCode>;
26
+ delete(id: string): Promise<DeletedResponse>;
27
+ validate(params: ValidateDiscountParams): Promise<ValidateDiscountResult>;
28
+ batchCreate(params: BatchCreateDiscountCodesParams): Promise<BatchCreateResult>;
29
+ }