@microcosmmoney/auth-react 1.4.0 → 1.5.1

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.
@@ -1,8 +1,9 @@
1
- interface UseApiQueryOptions {
1
+ interface UseApiQueryOptions<T = any> {
2
2
  path: string;
3
3
  requireAuth?: boolean;
4
4
  refetchInterval?: number;
5
5
  skip?: boolean;
6
+ select?: (raw: any) => T;
6
7
  }
7
8
  export interface UseApiQueryResult<T> {
8
9
  data: T | null;
@@ -10,5 +11,5 @@ export interface UseApiQueryResult<T> {
10
11
  error: Error | null;
11
12
  refresh: () => Promise<void>;
12
13
  }
13
- export declare function useApiQuery<T = any>(options: UseApiQueryOptions): UseApiQueryResult<T>;
14
+ export declare function useApiQuery<T = any>(options: UseApiQueryOptions<T>): UseApiQueryResult<T>;
14
15
  export {};
@@ -22,7 +22,7 @@ function useApiQuery(options) {
22
22
  setLoading(true);
23
23
  const res = await api.get(options.path);
24
24
  if (mountedRef.current) {
25
- setData(res.data);
25
+ setData(options.select ? options.select(res.data) : res.data);
26
26
  setError(null);
27
27
  }
28
28
  }
@@ -10,5 +10,6 @@ function useBuybackHistory(options) {
10
10
  path: `/reincarnation/user-history?page=${page}&page_size=${pageSize}`,
11
11
  requireAuth: true,
12
12
  refetchInterval: options?.refetchInterval ?? 0,
13
+ select: (d) => Array.isArray(d) ? d : d?.records ?? [],
13
14
  });
14
15
  }
@@ -0,0 +1,12 @@
1
+ import type { FragmentBuyInput, FragmentizeInput, FragmentRedeemInput, FragmentBuyoutInitiateInput, FragmentBuyoutAcceptInput, FragmentBuyoutCompleteInput, FragmentBuyoutCancelInput } from '@microcosmmoney/auth-core';
2
+ export declare function useFragmentAction(): {
3
+ buy: (params: FragmentBuyInput) => Promise<any>;
4
+ fragmentize: (params: FragmentizeInput) => Promise<any>;
5
+ redeem: (params: FragmentRedeemInput) => Promise<any>;
6
+ initiateBuyout: (params: FragmentBuyoutInitiateInput) => Promise<any>;
7
+ acceptBuyout: (params: FragmentBuyoutAcceptInput) => Promise<any>;
8
+ completeBuyout: (params: FragmentBuyoutCompleteInput) => Promise<any>;
9
+ cancelBuyout: (params: FragmentBuyoutCancelInput) => Promise<any>;
10
+ loading: boolean;
11
+ error: Error | null;
12
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFragmentAction = useFragmentAction;
4
+ // AI-generated · AI-managed · AI-maintained
5
+ const react_1 = require("react");
6
+ const provider_1 = require("../provider");
7
+ function useFragmentAction() {
8
+ const { client, isAuthenticated } = (0, provider_1.useAuth)();
9
+ const [loading, setLoading] = (0, react_1.useState)(false);
10
+ const [error, setError] = (0, react_1.useState)(null);
11
+ const mountedRef = (0, react_1.useRef)(true);
12
+ const exec = (0, react_1.useCallback)(async (path, params) => {
13
+ if (!isAuthenticated)
14
+ throw new Error('Authentication required');
15
+ const api = client.getApiClient();
16
+ try {
17
+ setLoading(true);
18
+ setError(null);
19
+ const res = await api.post(path, params);
20
+ return res.data;
21
+ }
22
+ catch (err) {
23
+ const e = err instanceof Error ? err : new Error(String(err));
24
+ if (mountedRef.current)
25
+ setError(e);
26
+ throw e;
27
+ }
28
+ finally {
29
+ if (mountedRef.current)
30
+ setLoading(false);
31
+ }
32
+ }, [client, isAuthenticated]);
33
+ const buy = (0, react_1.useCallback)((params) => exec('/fragment/buy/prepare', params), [exec]);
34
+ const fragmentize = (0, react_1.useCallback)((params) => exec('/fragment/fragmentize/prepare', params), [exec]);
35
+ const redeem = (0, react_1.useCallback)((params) => exec('/fragment/redeem/prepare', params), [exec]);
36
+ const initiateBuyout = (0, react_1.useCallback)((params) => exec('/fragment/buyout/initiate/prepare', params), [exec]);
37
+ const acceptBuyout = (0, react_1.useCallback)((params) => exec('/fragment/buyout/accept/prepare', params), [exec]);
38
+ const completeBuyout = (0, react_1.useCallback)((params) => exec('/fragment/buyout/complete/prepare', params), [exec]);
39
+ const cancelBuyout = (0, react_1.useCallback)((params) => exec('/fragment/buyout/cancel/prepare', params), [exec]);
40
+ return { buy, fragmentize, redeem, initiateBuyout, acceptBuyout, completeBuyout, cancelBuyout, loading, error };
41
+ }
@@ -1,3 +1,3 @@
1
1
  export declare function useFragmentHoldings(wallet?: string, options?: {
2
2
  refetchInterval?: number;
3
- }): import("./use-api-query").UseApiQueryResult<any>;
3
+ }): import("./use-api-query").UseApiQueryResult<any[]>;
@@ -9,5 +9,6 @@ function useFragmentHoldings(wallet, options) {
9
9
  requireAuth: false,
10
10
  skip: !wallet,
11
11
  refetchInterval: options?.refetchInterval ?? 0,
12
+ select: (d) => Array.isArray(d) ? d : d?.holdings ?? [],
12
13
  });
13
14
  }
@@ -7,5 +7,6 @@ function useFragmentVaults(options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: '/fragment/vaults',
9
9
  refetchInterval: options?.refetchInterval ?? 120000,
10
+ select: (d) => Array.isArray(d) ? d : d?.vaults ?? [],
10
11
  });
11
12
  }
@@ -0,0 +1,10 @@
1
+ import type { LendingDepositInput, LendingWithdrawInput, LendingBorrowInput, LendingRepayInput, LendingLiquidateInput } from '@microcosmmoney/auth-core';
2
+ export declare function useLendingAction(): {
3
+ deposit: (params: LendingDepositInput) => Promise<any>;
4
+ withdraw: (params: LendingWithdrawInput) => Promise<any>;
5
+ borrow: (params: LendingBorrowInput) => Promise<any>;
6
+ repay: (params: LendingRepayInput) => Promise<any>;
7
+ liquidate: (params: LendingLiquidateInput) => Promise<any>;
8
+ loading: boolean;
9
+ error: Error | null;
10
+ };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useLendingAction = useLendingAction;
4
+ // AI-generated · AI-managed · AI-maintained
5
+ const react_1 = require("react");
6
+ const provider_1 = require("../provider");
7
+ function useLendingAction() {
8
+ const { client, isAuthenticated } = (0, provider_1.useAuth)();
9
+ const [loading, setLoading] = (0, react_1.useState)(false);
10
+ const [error, setError] = (0, react_1.useState)(null);
11
+ const mountedRef = (0, react_1.useRef)(true);
12
+ const exec = (0, react_1.useCallback)(async (path, params) => {
13
+ if (!isAuthenticated)
14
+ throw new Error('Authentication required');
15
+ const api = client.getApiClient();
16
+ try {
17
+ setLoading(true);
18
+ setError(null);
19
+ const res = await api.post(path, params);
20
+ return res.data;
21
+ }
22
+ catch (err) {
23
+ const e = err instanceof Error ? err : new Error(String(err));
24
+ if (mountedRef.current)
25
+ setError(e);
26
+ throw e;
27
+ }
28
+ finally {
29
+ if (mountedRef.current)
30
+ setLoading(false);
31
+ }
32
+ }, [client, isAuthenticated]);
33
+ const deposit = (0, react_1.useCallback)((params) => exec('/lending/deposit/prepare', params), [exec]);
34
+ const withdraw = (0, react_1.useCallback)((params) => exec('/lending/withdraw/prepare', params), [exec]);
35
+ const borrow = (0, react_1.useCallback)((params) => exec('/lending/borrow/prepare', params), [exec]);
36
+ const repay = (0, react_1.useCallback)((params) => exec('/lending/repay/prepare', params), [exec]);
37
+ const liquidate = (0, react_1.useCallback)((params) => exec('/lending/liquidate/prepare', params), [exec]);
38
+ return { deposit, withdraw, borrow, repay, liquidate, loading, error };
39
+ }
@@ -1,3 +1,3 @@
1
1
  export declare function useLendingLoans(wallet?: string, options?: {
2
2
  refetchInterval?: number;
3
- }): import("./use-api-query").UseApiQueryResult<any>;
3
+ }): import("./use-api-query").UseApiQueryResult<any[]>;
@@ -9,5 +9,6 @@ function useLendingLoans(wallet, options) {
9
9
  requireAuth: false,
10
10
  skip: !wallet,
11
11
  refetchInterval: options?.refetchInterval ?? 0,
12
+ select: (d) => Array.isArray(d) ? d : d?.loans ?? [],
12
13
  });
13
14
  }
@@ -8,5 +8,6 @@ function useMCCLocks(options) {
8
8
  path: '/mcc/locks',
9
9
  requireAuth: true,
10
10
  refetchInterval: options?.refetchInterval ?? 0,
11
+ select: (d) => Array.isArray(d) ? d : d?.locks ?? [],
11
12
  });
12
13
  }
@@ -15,5 +15,6 @@ function useMCDRewards(options) {
15
15
  path: `/mcd/rewards${qs}`,
16
16
  requireAuth: true,
17
17
  refetchInterval: options?.refetchInterval ?? 0,
18
+ select: (d) => Array.isArray(d) ? d : d?.records ?? [],
18
19
  });
19
20
  }
@@ -13,5 +13,6 @@ function useMCDTransactions(options) {
13
13
  path: `/mcd/transactions${qs}`,
14
14
  requireAuth: true,
15
15
  refetchInterval: options?.refetchInterval ?? 0,
16
+ select: (d) => Array.isArray(d) ? d : d?.records ?? [],
16
17
  });
17
18
  }
@@ -7,5 +7,6 @@ function usePriceHistory(range = '7D', options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: `/mcc/price/history?range=${range}`,
9
9
  refetchInterval: options?.refetchInterval ?? 300000,
10
+ select: (d) => Array.isArray(d) ? d : d?.records ?? [],
10
11
  });
11
12
  }
@@ -1,3 +1,3 @@
1
1
  export declare function useTerritoryNFTs(wallet?: string, options?: {
2
2
  refetchInterval?: number;
3
- }): import("./use-api-query").UseApiQueryResult<any>;
3
+ }): import("./use-api-query").UseApiQueryResult<any[]>;
@@ -8,5 +8,6 @@ function useTerritoryNFTs(wallet, options) {
8
8
  path: `/territory/nfts/${wallet}`,
9
9
  skip: !wallet,
10
10
  refetchInterval: options?.refetchInterval ?? 0,
11
+ select: (d) => Array.isArray(d) ? d : d?.nfts ?? [],
11
12
  });
12
13
  }
@@ -8,5 +8,6 @@ function useWallets(options) {
8
8
  path: '/wallets',
9
9
  requireAuth: true,
10
10
  refetchInterval: options?.refetchInterval ?? 0,
11
+ select: (d) => Array.isArray(d) ? d : d?.wallets ?? [],
11
12
  });
12
13
  }
package/dist/index.d.ts CHANGED
@@ -108,4 +108,6 @@ export { useOrganizationStats } from './hooks/use-organization-stats';
108
108
  export { useFragmentHoldings } from './hooks/use-fragment-holdings';
109
109
  export { useLendingLoans } from './hooks/use-lending-loans';
110
110
  export { useLendingLPBalance } from './hooks/use-lending-lp-balance';
111
- export type { MicrocosmAuthConfig, MicrocosmAPIConfig, User, AuthState, LoginOptions, MCDBalance, MCCBalance, MCCWalletBalance, MCCPrice, Wallet, TokenPortfolio, MCCLock, MiningRatio, MiningDistribution, BuybackQuote, BuybackRecord, Territory, TerritorySummary, TerritoryStats, TerritoryMember, Proposal, ProposalDetail, VoteResult, VotePower, AuctionBid, MCDTransaction, MCDReward, MiningRequest, MiningConfirmData, MiningRequestResult, MiningConfig, BuybackRecordInput, ReincarnationConfig, MCCHistoryRecord, CycleHistory, AuctionHistory, PaginatedResult, MCCStats, MiningStats, TechTreeNode, TechTree, TechTreeBonus, UserStats, Organization, OrganizationTreeNode, MiningRecord, MiningHistoryItem, PriceHistoryPoint, Auction, AuctionDetail, AuctionCreateInput, TerritoryIncome, TerritoryKPI, UserLevel, DashboardMarketSummary, DashboardUserSummary, PublicMiningRequest, UnitType, OrganizationSummary, TerritoryDetailedStats, ManagerIncomeRecord, TeamCustodySummary, } from '@microcosmmoney/auth-core';
111
+ export { useFragmentAction } from './hooks/use-fragment-action';
112
+ export { useLendingAction } from './hooks/use-lending-action';
113
+ export type { MicrocosmAuthConfig, MicrocosmAPIConfig, User, AuthState, LoginOptions, MCDBalance, MCCBalance, MCCWalletBalance, MCCPrice, Wallet, TokenPortfolio, MCCLock, MiningRatio, MiningDistribution, BuybackQuote, BuybackRecord, Territory, TerritorySummary, TerritoryStats, TerritoryMember, Proposal, ProposalDetail, VoteResult, VotePower, AuctionBid, MCDTransaction, MCDReward, MiningRequest, MiningConfirmData, MiningRequestResult, MiningConfig, BuybackRecordInput, ReincarnationConfig, MCCHistoryRecord, CycleHistory, AuctionHistory, PaginatedResult, MCCStats, MiningStats, TechTreeNode, TechTree, TechTreeBonus, UserStats, Organization, OrganizationTreeNode, MiningRecord, MiningHistoryItem, PriceHistoryPoint, Auction, AuctionDetail, AuctionCreateInput, TerritoryIncome, TerritoryKPI, UserLevel, DashboardMarketSummary, DashboardUserSummary, PublicMiningRequest, UnitType, OrganizationSummary, TerritoryDetailedStats, ManagerIncomeRecord, TeamCustodySummary, FragmentBuyInput, FragmentizeInput, FragmentRedeemInput, FragmentBuyoutInitiateInput, FragmentBuyoutAcceptInput, FragmentBuyoutCompleteInput, FragmentBuyoutCancelInput, LendingDepositInput, LendingWithdrawInput, LendingBorrowInput, LendingRepayInput, LendingLiquidateInput, } from '@microcosmmoney/auth-core';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useAuctionHistory = exports.useAuctionBid = exports.useAuctionCancel = exports.useTerritoryUpdate = exports.useBuybackAction = exports.usePublicMining = exports.useMiningAction = exports.useUserStats = exports.useAuctionDetail = exports.useMyBids = exports.useVotePower = exports.useProposalDetail = exports.useProposals = exports.useTerritoryMembers = exports.useTerritoryStats = exports.useTerritoryDetail = exports.useTerritorySummary = exports.useTerritories = exports.useBuybackHistory = exports.useBuybackQuote = exports.useMCDRewards = exports.useMCDTransactions = exports.useMiningDistribution = exports.useMiningRatio = exports.useMCCLocks = exports.useTokenPortfolio = exports.useWallets = exports.useDashboardSummary = exports.usePriceHistory = exports.useTechTree = exports.useOrganizations = exports.useAuctions = exports.useTerritoryNFTs = exports.useReincarnationPool = exports.useUserLevel = exports.useMiningRecords = exports.useMiningStats = exports.useMCDStats = exports.useMCCStats = exports.useMCCPrice = exports.useApiQuery = exports.useProfile = exports.useMCC = exports.useMCD = exports.RequireRole = exports.withAuth = exports.AuthCallback = exports.useAuth = exports.MicrocosmAuthProvider = exports.UserRank = void 0;
4
4
  exports.useBuybackFlow = exports.useMiningFlow = exports.useRefundDeposit = exports.useTeamCustody = exports.useAuctionEnd = exports.useProposalSettle = exports.useManagerIncome = exports.useTerritoryNFTMint = exports.useTerritoryDetailedStats = exports.useDashboardTerritoryStats = exports.useDashboardUserStats = exports.useMCCMiningHistory = exports.useLendingStats = exports.useFragmentConfig = exports.useAuctionConfig = exports.useDashboardMiningHistory = exports.usePlatformStats = exports.useMCCHolders = exports.useLendingPosition = exports.useLendingPool = exports.useFragmentVaultDetail = exports.useFragmentVaults = exports.useTerritoryDistributionPlan = exports.useTerritoryNameStatus = exports.useTerritoryNFTCollection = exports.useTechTreeBonus = exports.useTechTreeConfig = exports.useTechTreeAction = exports.useTerritoryQueue = exports.useTerritoryLeave = exports.useTerritoryJoin = exports.useStationQueue = exports.useStationLeave = exports.useStationJoin = exports.useAuctionBids = exports.useMultiWalletBalance = exports.useOrganizationSummary = exports.useOrganizationTree = exports.useMarketData = exports.useAuctionRefund = exports.useCreateAuction = exports.useTerritoryRanking = exports.useTerritoryKPI = exports.useTerritoryIncome = exports.useCycleHistory = exports.useReincarnationConfig = exports.useMiningHistory = exports.useMiningConfig = exports.useMCCHistory = exports.useVoteAction = void 0;
5
- exports.useLendingLPBalance = exports.useLendingLoans = exports.useFragmentHoldings = exports.useOrganizationStats = exports.useOrganizationMembers = exports.useOrganizationDetail = exports.useTerritoryUserStatus = exports.useTerritoryImage = exports.useTerritoryNFTAction = void 0;
5
+ exports.useLendingAction = exports.useFragmentAction = exports.useLendingLPBalance = exports.useLendingLoans = exports.useFragmentHoldings = exports.useOrganizationStats = exports.useOrganizationMembers = exports.useOrganizationDetail = exports.useTerritoryUserStatus = exports.useTerritoryImage = exports.useTerritoryNFTAction = void 0;
6
6
  // AI-generated · AI-managed · AI-maintained
7
7
  var auth_core_1 = require("@microcosmmoney/auth-core");
8
8
  Object.defineProperty(exports, "UserRank", { enumerable: true, get: function () { return auth_core_1.UserRank; } });
@@ -221,3 +221,7 @@ var use_lending_loans_1 = require("./hooks/use-lending-loans");
221
221
  Object.defineProperty(exports, "useLendingLoans", { enumerable: true, get: function () { return use_lending_loans_1.useLendingLoans; } });
222
222
  var use_lending_lp_balance_1 = require("./hooks/use-lending-lp-balance");
223
223
  Object.defineProperty(exports, "useLendingLPBalance", { enumerable: true, get: function () { return use_lending_lp_balance_1.useLendingLPBalance; } });
224
+ var use_fragment_action_1 = require("./hooks/use-fragment-action");
225
+ Object.defineProperty(exports, "useFragmentAction", { enumerable: true, get: function () { return use_fragment_action_1.useFragmentAction; } });
226
+ var use_lending_action_1 = require("./hooks/use-lending-action");
227
+ Object.defineProperty(exports, "useLendingAction", { enumerable: true, get: function () { return use_lending_action_1.useLendingAction; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microcosmmoney/auth-react",
3
- "version": "1.4.0",
3
+ "version": "1.5.1",
4
4
  "description": "Microcosm OAuth 2.0 React/Next.js adapter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,7 @@
24
24
  "react-dom": ">=18.0.0"
25
25
  },
26
26
  "dependencies": {
27
- "@microcosmmoney/auth-core": "^1.4.0"
27
+ "@microcosmmoney/auth-core": "^1.5.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/react": "^18.0.0",