@compass-labs/widgets 0.1.4 → 0.1.6

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/index.d.mts CHANGED
@@ -326,8 +326,12 @@ interface WalletAdapter {
326
326
 
327
327
  interface CompassProviderProps {
328
328
  children: ReactNode;
329
- /** Compass API key - required for all API calls */
330
- apiKey: string;
329
+ /**
330
+ * Compass API key - optional when using server-side API routes.
331
+ * If not provided, all API calls will go through /api/compass/* routes.
332
+ * @deprecated Use server-side API routes instead for better security.
333
+ */
334
+ apiKey?: string;
331
335
  /** Default chain to use */
332
336
  defaultChain?: SupportedChain;
333
337
  /** Theme preset name, preset with overrides, or full theme object */
@@ -716,23 +720,27 @@ declare function useTheme(): ThemeContextValue;
716
720
  * Context value for the API context
717
721
  */
718
722
  interface ApiContextValue {
719
- /** The API key used to authenticate with Compass API */
723
+ /** The API key used to authenticate with Compass API (may be empty when using server-side routes) */
720
724
  apiKey: string;
721
- /** The Compass API SDK client instance */
725
+ /** The Compass API SDK client instance (may be a dummy when using server-side routes) */
722
726
  client: CompassApiSDK;
723
727
  }
724
728
  interface ApiProviderProps {
725
729
  children: ReactNode;
726
- apiKey: string;
730
+ /** API key - optional when using server-side routes */
731
+ apiKey?: string;
727
732
  /** Optional API base URL override */
728
733
  serverURL?: string;
729
734
  }
730
735
  /**
731
736
  * Provider component that manages the Compass API client.
737
+ * When apiKey is not provided, a minimal client is created but all
738
+ * data fetching should go through server-side /api/compass/* routes.
732
739
  */
733
740
  declare function ApiProvider({ children, apiKey, serverURL }: ApiProviderProps): react_jsx_runtime.JSX.Element;
734
741
  /**
735
742
  * Hook to access the Compass API client and API key.
743
+ * @deprecated When using server-side routes, prefer using fetch to /api/compass/* instead.
736
744
  */
737
745
  declare function useCompassApi(): ApiContextValue;
738
746
  declare const useEmbeddableApi: typeof useCompassApi;
package/dist/index.d.ts CHANGED
@@ -326,8 +326,12 @@ interface WalletAdapter {
326
326
 
327
327
  interface CompassProviderProps {
328
328
  children: ReactNode;
329
- /** Compass API key - required for all API calls */
330
- apiKey: string;
329
+ /**
330
+ * Compass API key - optional when using server-side API routes.
331
+ * If not provided, all API calls will go through /api/compass/* routes.
332
+ * @deprecated Use server-side API routes instead for better security.
333
+ */
334
+ apiKey?: string;
331
335
  /** Default chain to use */
332
336
  defaultChain?: SupportedChain;
333
337
  /** Theme preset name, preset with overrides, or full theme object */
@@ -716,23 +720,27 @@ declare function useTheme(): ThemeContextValue;
716
720
  * Context value for the API context
717
721
  */
718
722
  interface ApiContextValue {
719
- /** The API key used to authenticate with Compass API */
723
+ /** The API key used to authenticate with Compass API (may be empty when using server-side routes) */
720
724
  apiKey: string;
721
- /** The Compass API SDK client instance */
725
+ /** The Compass API SDK client instance (may be a dummy when using server-side routes) */
722
726
  client: CompassApiSDK;
723
727
  }
724
728
  interface ApiProviderProps {
725
729
  children: ReactNode;
726
- apiKey: string;
730
+ /** API key - optional when using server-side routes */
731
+ apiKey?: string;
727
732
  /** Optional API base URL override */
728
733
  serverURL?: string;
729
734
  }
730
735
  /**
731
736
  * Provider component that manages the Compass API client.
737
+ * When apiKey is not provided, a minimal client is created but all
738
+ * data fetching should go through server-side /api/compass/* routes.
732
739
  */
733
740
  declare function ApiProvider({ children, apiKey, serverURL }: ApiProviderProps): react_jsx_runtime.JSX.Element;
734
741
  /**
735
742
  * Hook to access the Compass API client and API key.
743
+ * @deprecated When using server-side routes, prefer using fetch to /api/compass/* instead.
736
744
  */
737
745
  declare function useCompassApi(): ApiContextValue;
738
746
  declare const useEmbeddableApi: typeof useCompassApi;
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var lucideReact = require('lucide-react');
9
9
 
10
10
  // src/provider/CompassProvider.tsx
11
11
  var ApiContext = react.createContext(null);
12
- function ApiProvider({ children, apiKey, serverURL }) {
12
+ function ApiProvider({ children, apiKey = "", serverURL }) {
13
13
  const client = react.useMemo(() => {
14
14
  return new apiSdk.CompassApiSDK({
15
15
  apiKeyAuth: apiKey,
@@ -2912,7 +2912,6 @@ function VaultCard({
2912
2912
  );
2913
2913
  }
2914
2914
  function useVaultsData(options = {}) {
2915
- const { client } = useEmbeddableApi();
2916
2915
  const { address } = useEmbeddableWallet();
2917
2916
  const { chainId } = useChain();
2918
2917
  const { sortBy = "apy_7d", assetFilter, minApy, minTvl } = options;
@@ -2920,14 +2919,19 @@ function useVaultsData(options = {}) {
2920
2919
  queryKey: ["vaults", chainId, sortBy, assetFilter, minApy, minTvl],
2921
2920
  queryFn: async () => {
2922
2921
  const assetSymbol = assetFilter && assetFilter.length === 1 ? assetFilter[0] : void 0;
2923
- const response = await client.earn.earnVaults({
2922
+ const params = new URLSearchParams({
2924
2923
  chain: chainId,
2925
2924
  orderBy: sortBy === "tvl" ? "tvl_usd" : sortBy,
2926
2925
  direction: "desc",
2927
- limit: 100,
2926
+ limit: "100",
2928
2927
  ...assetSymbol && { assetSymbol }
2929
2928
  });
2930
- let vaults = (response.vaults || []).map((v) => ({
2929
+ const response = await fetch(`/api/compass/vaults?${params}`);
2930
+ if (!response.ok) {
2931
+ throw new Error("Failed to fetch vaults");
2932
+ }
2933
+ const data = await response.json();
2934
+ let vaults = (data.vaults || []).map((v) => ({
2931
2935
  vaultAddress: v.vaultAddress,
2932
2936
  name: v.name || "Unknown Vault",
2933
2937
  assetSymbol: v.assetSymbol || "UNKNOWN",
@@ -2961,11 +2965,16 @@ function useVaultsData(options = {}) {
2961
2965
  queryKey: ["vaultPositions", chainId, address],
2962
2966
  queryFn: async () => {
2963
2967
  if (!address) return [];
2964
- const response = await client.earn.earnPositions({
2968
+ const params = new URLSearchParams({
2965
2969
  chain: chainId,
2966
2970
  owner: address
2967
2971
  });
2968
- return (response.vaults || []).map((p) => ({
2972
+ const response = await fetch(`/api/compass/positions?${params}`);
2973
+ if (!response.ok) {
2974
+ throw new Error("Failed to fetch positions");
2975
+ }
2976
+ const data = await response.json();
2977
+ return (data.vaults || []).map((p) => ({
2969
2978
  vaultAddress: p.vaultAddress,
2970
2979
  balance: p.balance || "0",
2971
2980
  pnl: p.pnl ? {
@@ -3246,17 +3255,19 @@ function VaultsList({
3246
3255
  ] });
3247
3256
  }
3248
3257
  function useAaveData(options = {}) {
3249
- const { client } = useEmbeddableApi();
3250
3258
  const { address } = useEmbeddableWallet();
3251
3259
  const { chainId } = useChain();
3252
3260
  const { assetFilter } = options;
3253
3261
  const marketsQuery = reactQuery.useQuery({
3254
3262
  queryKey: ["aaveMarkets", chainId, assetFilter],
3255
3263
  queryFn: async () => {
3256
- const response = await client.earn.earnAaveMarkets({
3257
- chain: chainId
3258
- });
3259
- const marketsDict = response.markets || {};
3264
+ const params = new URLSearchParams({ chain: chainId });
3265
+ const response = await fetch(`/api/compass/aave/markets?${params}`);
3266
+ if (!response.ok) {
3267
+ throw new Error("Failed to fetch Aave markets");
3268
+ }
3269
+ const data = await response.json();
3270
+ const marketsDict = data.markets || {};
3260
3271
  let markets = [];
3261
3272
  for (const [symbol, tokenData] of Object.entries(marketsDict)) {
3262
3273
  if (assetFilter && assetFilter.length > 0) {
@@ -3287,11 +3298,16 @@ function useAaveData(options = {}) {
3287
3298
  queryKey: ["aavePositions", chainId, address],
3288
3299
  queryFn: async () => {
3289
3300
  if (!address) return [];
3290
- const response = await client.earn.earnPositions({
3301
+ const params = new URLSearchParams({
3291
3302
  chain: chainId,
3292
3303
  owner: address
3293
3304
  });
3294
- return (response.aave || []).map((p) => ({
3305
+ const response = await fetch(`/api/compass/positions?${params}`);
3306
+ if (!response.ok) {
3307
+ throw new Error("Failed to fetch positions");
3308
+ }
3309
+ const data = await response.json();
3310
+ return (data.aave || []).map((p) => ({
3295
3311
  marketAddress: p.marketAddress || "",
3296
3312
  reserveSymbol: p.reserveSymbol || "",
3297
3313
  balance: p.balance || "0",
@@ -3532,7 +3548,6 @@ function AaveMarketsList({
3532
3548
  ] });
3533
3549
  }
3534
3550
  function usePendleData(options = {}) {
3535
- const { client } = useEmbeddableApi();
3536
3551
  const { address } = useEmbeddableWallet();
3537
3552
  const { chainId } = useChain();
3538
3553
  const { sortBy = "fixed_apy", assetFilter, minTvl } = options;
@@ -3541,15 +3556,20 @@ function usePendleData(options = {}) {
3541
3556
  queryFn: async () => {
3542
3557
  const underlyingSymbol = assetFilter && assetFilter.length === 1 ? assetFilter[0] : void 0;
3543
3558
  const orderBy = sortBy === "tvl" ? "tvl_usd" : "implied_apy";
3544
- const response = await client.earn.earnPendleMarkets({
3559
+ const params = new URLSearchParams({
3545
3560
  chain: chainId,
3546
3561
  orderBy,
3547
3562
  direction: "desc",
3548
- limit: 100,
3563
+ limit: "100",
3549
3564
  ...underlyingSymbol && { underlyingSymbol }
3550
3565
  });
3566
+ const response = await fetch(`/api/compass/pendle/markets?${params}`);
3567
+ if (!response.ok) {
3568
+ throw new Error("Failed to fetch Pendle markets");
3569
+ }
3570
+ const data = await response.json();
3551
3571
  const now = Date.now() / 1e3;
3552
- let markets = (response.markets || []).filter((m) => m.expiry && m.expiry > now).map((m) => ({
3572
+ let markets = (data.markets || []).filter((m) => m.expiry && m.expiry > now).map((m) => ({
3553
3573
  marketAddress: m.marketAddress || "",
3554
3574
  ptAddress: m.ptAddress || "",
3555
3575
  name: m.ptName || `PT-${m.underlyingSymbol || "UNKNOWN"}`,
@@ -3585,11 +3605,16 @@ function usePendleData(options = {}) {
3585
3605
  queryKey: ["pendlePositions", chainId, address],
3586
3606
  queryFn: async () => {
3587
3607
  if (!address) return [];
3588
- const response = await client.earn.earnPositions({
3608
+ const params = new URLSearchParams({
3589
3609
  chain: chainId,
3590
3610
  owner: address
3591
3611
  });
3592
- return (response.pendlePt || []).map((p) => ({
3612
+ const response = await fetch(`/api/compass/positions?${params}`);
3613
+ if (!response.ok) {
3614
+ throw new Error("Failed to fetch positions");
3615
+ }
3616
+ const data = await response.json();
3617
+ return (data.pendlePt || []).map((p) => ({
3593
3618
  marketAddress: p.marketAddress || "",
3594
3619
  balance: p.balance || "0",
3595
3620
  pnl: p.pnl ? {