@solana/connector 0.1.6 → 0.1.8

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 (50) hide show
  1. package/README.md +122 -44
  2. package/dist/{chunk-VMSZJPR5.mjs → chunk-6F6M6L7R.mjs} +152 -173
  3. package/dist/chunk-6F6M6L7R.mjs.map +1 -0
  4. package/dist/{chunk-NQXK7PGX.js → chunk-AOIXHVRH.js} +82 -235
  5. package/dist/chunk-AOIXHVRH.js.map +1 -0
  6. package/dist/chunk-DSUCH44G.js +678 -0
  7. package/dist/chunk-DSUCH44G.js.map +1 -0
  8. package/dist/{chunk-JUZVCBAI.js → chunk-FTXIXM43.js} +240 -271
  9. package/dist/chunk-FTXIXM43.js.map +1 -0
  10. package/dist/{chunk-QKVL45F6.mjs → chunk-G575OAT4.mjs} +73 -218
  11. package/dist/chunk-G575OAT4.mjs.map +1 -0
  12. package/dist/chunk-J7DHGLW6.mjs +638 -0
  13. package/dist/chunk-J7DHGLW6.mjs.map +1 -0
  14. package/dist/{chunk-ULUYX23Q.js → chunk-K3BNIGPX.js} +1023 -404
  15. package/dist/chunk-K3BNIGPX.js.map +1 -0
  16. package/dist/{chunk-3STZXVXD.mjs → chunk-TTOKQAPX.mjs} +998 -388
  17. package/dist/chunk-TTOKQAPX.mjs.map +1 -0
  18. package/dist/compat.d.mts +1 -1
  19. package/dist/compat.d.ts +1 -1
  20. package/dist/compat.js +40 -39
  21. package/dist/compat.js.map +1 -1
  22. package/dist/compat.mjs +39 -38
  23. package/dist/compat.mjs.map +1 -1
  24. package/dist/headless.d.mts +540 -152
  25. package/dist/headless.d.ts +540 -152
  26. package/dist/headless.js +226 -190
  27. package/dist/headless.mjs +3 -3
  28. package/dist/index.d.mts +8 -6
  29. package/dist/index.d.ts +8 -6
  30. package/dist/index.js +286 -218
  31. package/dist/index.mjs +4 -4
  32. package/dist/react.d.mts +283 -16
  33. package/dist/react.d.ts +283 -16
  34. package/dist/react.js +60 -28
  35. package/dist/react.mjs +2 -2
  36. package/dist/{wallet-standard-shim--YcrQNRt.d.ts → standard-shim-CT49DM5l.d.mts} +72 -252
  37. package/dist/{wallet-standard-shim-Dx7H8Ctf.d.mts → standard-shim-D9guL5fz.d.ts} +72 -252
  38. package/dist/{transaction-signer-D9d8nxwb.d.mts → transaction-signer-T-KVQFi8.d.mts} +2 -2
  39. package/dist/{transaction-signer-D9d8nxwb.d.ts → transaction-signer-T-KVQFi8.d.ts} +2 -2
  40. package/package.json +3 -3
  41. package/dist/chunk-3STZXVXD.mjs.map +0 -1
  42. package/dist/chunk-I64FD2EH.js +0 -312
  43. package/dist/chunk-I64FD2EH.js.map +0 -1
  44. package/dist/chunk-JUZVCBAI.js.map +0 -1
  45. package/dist/chunk-NQXK7PGX.js.map +0 -1
  46. package/dist/chunk-QKVL45F6.mjs.map +0 -1
  47. package/dist/chunk-QL3IT3TS.mjs +0 -299
  48. package/dist/chunk-QL3IT3TS.mjs.map +0 -1
  49. package/dist/chunk-ULUYX23Q.js.map +0 -1
  50. package/dist/chunk-VMSZJPR5.mjs.map +0 -1
package/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: @solana/connector
2
+ title: '@solana/connector'
3
3
  description: Production-ready wallet connector for Solana applications
4
4
  ---
5
5
 
@@ -30,7 +30,7 @@ npm install @solana/connector
30
30
  pnpm add @solana/connector
31
31
  # or
32
32
  yarn add @solana/connector
33
- # or
33
+ # or
34
34
  bun add @solana/connector
35
35
  ```
36
36
 
@@ -671,6 +671,7 @@ const config = getDefaultConfig({
671
671
  ```
672
672
 
673
673
  Your `.env` file (no `NEXT_PUBLIC_` prefix):
674
+
674
675
  ```
675
676
  SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=your-key
676
677
  ```
@@ -708,12 +709,12 @@ https://raw.githubusercontent.com/.../token-logo.png
708
709
 
709
710
  ### Common Proxy Options
710
711
 
711
- | Service | Configuration |
712
- |---------|---------------|
713
- | **Next.js Image** | `imageProxy: '/_next/image?w=64&q=75&url='` |
714
- | **Cloudflare** | `imageProxy: '/cdn-cgi/image/width=64,quality=75/'` |
715
- | **imgproxy** | `imageProxy: 'https://imgproxy.example.com/insecure/fill/64/64/'` |
716
- | **Custom API** | `imageProxy: '/api/image-proxy?url='` |
712
+ | Service | Configuration |
713
+ | ----------------- | ----------------------------------------------------------------- |
714
+ | **Next.js Image** | `imageProxy: '/_next/image?w=64&q=75&url='` |
715
+ | **Cloudflare** | `imageProxy: '/cdn-cgi/image/width=64,quality=75/'` |
716
+ | **imgproxy** | `imageProxy: 'https://imgproxy.example.com/insecure/fill/64/64/'` |
717
+ | **Custom API** | `imageProxy: '/api/image-proxy?url='` |
717
718
 
718
719
  ### Custom Proxy API Route (Next.js Example)
719
720
 
@@ -790,14 +791,12 @@ function validateUrl(urlString: string): URL | null {
790
791
 
791
792
  // Check if hostname is in the allowlist
792
793
  function isAllowedDomain(hostname: string): boolean {
793
- return ALLOWED_DOMAINS.some(
794
- (domain) => hostname === domain || hostname.endsWith(`.${domain}`)
795
- );
794
+ return ALLOWED_DOMAINS.some(domain => hostname === domain || hostname.endsWith(`.${domain}`));
796
795
  }
797
796
 
798
797
  export async function GET(request: NextRequest) {
799
798
  const urlParam = request.nextUrl.searchParams.get('url');
800
-
799
+
801
800
  // (1) Ensure URL exists and parses correctly with http/https
802
801
  if (!urlParam) {
803
802
  return new NextResponse('Missing URL parameter', { status: 400 });
@@ -829,7 +828,7 @@ export async function GET(request: NextRequest) {
829
828
  try {
830
829
  const response = await fetch(parsedUrl.toString());
831
830
  const buffer = await response.arrayBuffer();
832
-
831
+
833
832
  return new NextResponse(buffer, {
834
833
  headers: {
835
834
  'Content-Type': response.headers.get('Content-Type') || 'image/png',
@@ -850,16 +849,17 @@ The `useTokens()` hook fetches token prices from CoinGecko. CoinGecko has rate l
850
849
 
851
850
  ### Rate Limits (as of 2024)
852
851
 
853
- | Tier | Rate Limit | API Key Required |
854
- |------|------------|------------------|
855
- | **Free (Public)** | 10-30 requests/minute | No |
856
- | **Demo** | 30 requests/minute | Yes (free) |
857
- | **Analyst** | 500 requests/minute | Yes (paid) |
858
- | **Pro** | 1000+ requests/minute | Yes (paid) |
852
+ | Tier | Rate Limit | API Key Required |
853
+ | ----------------- | --------------------- | ---------------- |
854
+ | **Free (Public)** | 10-30 requests/minute | No |
855
+ | **Demo** | 30 requests/minute | Yes (free) |
856
+ | **Analyst** | 500 requests/minute | Yes (paid) |
857
+ | **Pro** | 1000+ requests/minute | Yes (paid) |
859
858
 
860
859
  ### Handling Rate Limits
861
860
 
862
861
  ConnectorKit automatically handles rate limits with:
862
+
863
863
  - **Exponential backoff**: Retries with increasing delays
864
864
  - **Jitter**: Random delay added to prevent thundering herd
865
865
  - **Retry-After header**: Honors server-specified wait times
@@ -887,16 +887,16 @@ const config = getDefaultConfig({
887
887
  coingecko: {
888
888
  // API key for higher rate limits (optional)
889
889
  apiKey: process.env.COINGECKO_API_KEY,
890
-
890
+
891
891
  // Set to true if using a Pro API key (default: false for Demo keys)
892
892
  isPro: false,
893
-
893
+
894
894
  // Maximum retry attempts on 429 (default: 3)
895
895
  maxRetries: 3,
896
-
896
+
897
897
  // Base delay for exponential backoff in ms (default: 1000)
898
898
  baseDelay: 1000,
899
-
899
+
900
900
  // Maximum total timeout in ms (default: 30000)
901
901
  maxTimeout: 30000,
902
902
  },
@@ -911,6 +911,85 @@ Token prices are cached for 60 seconds to minimize API calls. The retry logic on
911
911
 
912
912
  ## Advanced Usage
913
913
 
914
+ ### Error Handling with `tryCatch`
915
+
916
+ ConnectorKit exports a `tryCatch` utility for consistent async error handling:
917
+
918
+ ```typescript
919
+ import { tryCatch } from '@solana/connector/headless';
920
+
921
+ // Instead of try/catch blocks
922
+ async function sendTransaction() {
923
+ const { data: signature, error } = await tryCatch(signer.signAndSendTransaction(transaction));
924
+
925
+ if (error) {
926
+ console.error('Transaction failed:', error.message);
927
+ return;
928
+ }
929
+
930
+ console.log('Transaction sent:', signature);
931
+ }
932
+ ```
933
+
934
+ The `tryCatch` utility returns a `Result<T, E>` type that's either a success with `data` or a failure with `error`:
935
+
936
+ ```typescript
937
+ interface Success<T> {
938
+ data: T;
939
+ error: null;
940
+ }
941
+
942
+ interface Failure<E> {
943
+ data: null;
944
+ error: E;
945
+ }
946
+ ```
947
+
948
+ Also available: `tryCatchSync` for synchronous operations, and `isSuccess`/`isFailure` type guards.
949
+
950
+ ### Cache Invalidation with Query Keys
951
+
952
+ For advanced cache management, ConnectorKit exports query key generators:
953
+
954
+ ```typescript
955
+ import {
956
+ getBalanceQueryKey,
957
+ getTokensQueryKey,
958
+ getTransactionsQueryKey,
959
+ invalidateSharedQuery,
960
+ } from '@solana/connector/react';
961
+
962
+ // After sending a transaction, invalidate relevant caches
963
+ async function sendAndRefresh() {
964
+ await sendTransaction();
965
+
966
+ // Invalidate balance and tokens (they share the same cache)
967
+ const balanceKey = getBalanceQueryKey(rpcUrl, address);
968
+ if (balanceKey) invalidateSharedQuery(balanceKey);
969
+
970
+ // Invalidate transactions
971
+ const txKey = getTransactionsQueryKey({ rpcUrl, address, clusterId });
972
+ if (txKey) invalidateSharedQuery(txKey);
973
+ }
974
+ ```
975
+
976
+ ### Configuration Validation
977
+
978
+ Configuration is validated at runtime using Zod schemas. For manual validation:
979
+
980
+ ```typescript
981
+ import { validateConfigOptions } from '@solana/connector/headless';
982
+
983
+ const result = validateConfigOptions({
984
+ appName: 'My App',
985
+ network: 'mainnet',
986
+ });
987
+
988
+ if (!result.success) {
989
+ console.error('Validation errors:', result.error.issues);
990
+ }
991
+ ```
992
+
914
993
  ### Headless Client (Vue, Svelte, Vanilla JS)
915
994
 
916
995
  Use `ConnectorClient` for non-React frameworks:
@@ -1007,35 +1086,34 @@ import { useConnector, useAccount } from '@solana/connector/react';
1007
1086
 
1008
1087
  ### Hooks
1009
1088
 
1010
- | Hook | Description | Returns |
1011
- |------|-------------|---------|
1012
- | `useConnector()` | Main wallet connection hook | `{ wallets, selectedWallet, accounts, connected, connecting, select, disconnect }` |
1013
- | `useAccount()` | Account management hook | `{ address, formatted, copy, copied, accounts, selectAccount }` |
1014
- | `useCluster()` | Network/cluster management hook | `{ cluster, clusters, setCluster, isMainnet, isDevnet, rpcUrl }` |
1015
- | `useWalletInfo()` | Wallet metadata hook | `{ name, icon, wallet, connecting }` |
1016
- | `useTransactionSigner()` | Legacy transaction signer (web3.js) | `{ signer, ready, address, capabilities }` |
1017
- | `useKitTransactionSigner()` | Modern transaction signer (@solana/kit) | `{ signer, ready, address }` |
1018
- | `useBalance()` | SOL balance hook | `{ solBalance, isLoading, refetch }` |
1019
- | `useTokens()` | SPL tokens hook | `{ tokens, isLoading, refetch }` |
1020
- | `useTransactions()` | Transaction history hook | `{ transactions, isLoading, refetch }` |
1089
+ | Hook | Description | Returns |
1090
+ | --------------------------- | --------------------------------------- | ---------------------------------------------------------------------------------- |
1091
+ | `useConnector()` | Main wallet connection hook | `{ wallets, selectedWallet, accounts, connected, connecting, select, disconnect }` |
1092
+ | `useAccount()` | Account management hook | `{ address, formatted, copy, copied, accounts, selectAccount }` |
1093
+ | `useCluster()` | Network/cluster management hook | `{ cluster, clusters, setCluster, isMainnet, isDevnet, rpcUrl }` |
1094
+ | `useWalletInfo()` | Wallet metadata hook | `{ name, icon, wallet, connecting }` |
1095
+ | `useTransactionSigner()` | Legacy transaction signer (web3.js) | `{ signer, ready, address, capabilities }` |
1096
+ | `useKitTransactionSigner()` | Modern transaction signer (@solana/kit) | `{ signer, ready, address }` |
1097
+ | `useBalance()` | SOL balance hook | `{ solBalance, isLoading, refetch }` |
1098
+ | `useTokens()` | SPL tokens hook | `{ tokens, isLoading, refetch }` |
1099
+ | `useTransactions()` | Transaction history hook | `{ transactions, isLoading, refetch }` |
1021
1100
 
1022
1101
  ### Configuration Functions
1023
1102
 
1024
- | Function | Description |
1025
- |----------|-------------|
1026
- | `getDefaultConfig(options)` | Create default connector configuration |
1103
+ | Function | Description |
1104
+ | --------------------------------- | ------------------------------------------ |
1105
+ | `getDefaultConfig(options)` | Create default connector configuration |
1027
1106
  | `getDefaultMobileConfig(options)` | Create mobile wallet adapter configuration |
1028
- | `createConfig(options)` | Create unified config for ConnectorKit + Armadura |
1029
1107
 
1030
1108
  ### Utility Functions
1031
1109
 
1032
- | Function | Description |
1033
- |----------|-------------|
1034
- | `formatAddress(address, options?)` | Format Solana address |
1035
- | `formatSOL(lamports, options?)` | Format SOL amount |
1036
- | `copyAddressToClipboard(address)` | Copy address to clipboard |
1110
+ | Function | Description |
1111
+ | --------------------------------------- | ----------------------------------- |
1112
+ | `formatAddress(address, options?)` | Format Solana address |
1113
+ | `formatSOL(lamports, options?)` | Format SOL amount |
1114
+ | `copyAddressToClipboard(address)` | Copy address to clipboard |
1037
1115
  | `getTransactionUrl(cluster, signature)` | Get Solana Explorer transaction URL |
1038
- | `getAddressUrl(cluster, address)` | Get Solana Explorer address URL |
1116
+ | `getAddressUrl(cluster, address)` | Get Solana Explorer address URL |
1039
1117
 
1040
1118
  ---
1041
1119