@microcosmmoney/auth-react 2.2.1 → 2.2.2

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.
@@ -4,6 +4,13 @@ exports.useApiQuery = useApiQuery;
4
4
  // AI-generated · AI-managed · AI-maintained
5
5
  const react_1 = require("react");
6
6
  const microcosm_context_1 = require("../microcosm-context");
7
+ /** Safely unwrap API response data: if `raw` is a `{success, data}` wrapper, extract `data` */
8
+ function unwrapData(raw) {
9
+ if (raw && typeof raw === 'object' && !Array.isArray(raw) && 'success' in raw && 'data' in raw) {
10
+ return raw.data;
11
+ }
12
+ return raw;
13
+ }
7
14
  function useApiQuery(options) {
8
15
  const api = (0, microcosm_context_1.useMicrocosmApi)();
9
16
  const { getAccessToken } = (0, microcosm_context_1.useMicrocosmContext)();
@@ -31,7 +38,8 @@ function useApiQuery(options) {
31
38
  setLoading(true);
32
39
  const res = await api.get(options.path);
33
40
  if (mountedRef.current) {
34
- setData(options.select ? options.select(res.data) : res.data);
41
+ const raw = unwrapData(res.data);
42
+ setData(options.select ? options.select(raw) : raw);
35
43
  setError(null);
36
44
  }
37
45
  }
@@ -7,6 +7,7 @@ function useAuctionBids(auctionId, options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: `/auction-solana/auction/${auctionId}/bids`,
9
9
  skip: auctionId === undefined || auctionId === null,
10
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.bids ?? []),
10
11
  refetchInterval: options?.refetchInterval ?? 30000,
11
12
  });
12
13
  }
@@ -18,7 +18,9 @@ function useAuctionHistory(params) {
18
18
  setLoading(true);
19
19
  const res = await api.get(`/auction-solana/history?page=${page}&page_size=${pageSize}`);
20
20
  if (mountedRef.current) {
21
- setData(res.data);
21
+ const raw = res.data;
22
+ const unwrapped = raw && typeof raw === 'object' && !Array.isArray(raw) && 'success' in raw && 'data' in raw ? raw.data : raw;
23
+ setData(unwrapped);
22
24
  setError(null);
23
25
  }
24
26
  }
@@ -19,6 +19,7 @@ function useAuctions(options) {
19
19
  const path = qs ? `/auction-solana/active?${qs}` : '/auction-solana/active';
20
20
  return (0, use_api_query_1.useApiQuery)({
21
21
  path,
22
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.auctions ?? []),
22
23
  refetchInterval: options?.refetchInterval ?? 60000,
23
24
  });
24
25
  }
@@ -6,6 +6,7 @@ const use_api_query_1 = require("./use-api-query");
6
6
  function useDashboardMiningHistory(days = 30, options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: `/dashboard/stats/mining-history?days=${days}`,
9
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.records ?? raw?.history ?? []),
9
10
  refetchInterval: options?.refetchInterval ?? 300000,
10
11
  });
11
12
  }
@@ -6,6 +6,7 @@ const use_api_query_1 = require("./use-api-query");
6
6
  function useMCCMiningHistory(days = 30, options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: `/reincarnation/mining-history?days=${days}`,
9
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.records ?? raw?.history ?? []),
9
10
  refetchInterval: options?.refetchInterval ?? 300000,
10
11
  });
11
12
  }
@@ -7,6 +7,7 @@ function useMyBids(options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: '/auction-solana/my-bids',
9
9
  requireAuth: true,
10
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.bids ?? []),
10
11
  refetchInterval: options?.refetchInterval ?? 0,
11
12
  });
12
13
  }
@@ -10,6 +10,7 @@ function useNotifications(options) {
10
10
  const qs = params.toString();
11
11
  return (0, use_api_query_1.useApiQuery)({
12
12
  path: `/notifications${qs ? `?${qs}` : ''}`,
13
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.notifications ?? []),
13
14
  refetchInterval: options?.refetchInterval ?? 30000,
14
15
  });
15
16
  }
@@ -8,6 +8,7 @@ function useOrganizationTree(rootId, options) {
8
8
  return (0, use_api_query_1.useApiQuery)({
9
9
  path,
10
10
  requireAuth: true,
11
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.tree ?? raw?.nodes ?? []),
11
12
  refetchInterval: options?.refetchInterval ?? 120000,
12
13
  });
13
14
  }
@@ -7,6 +7,7 @@ function useOrganizations(options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: '/organizations',
9
9
  requireAuth: true,
10
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.organizations ?? []),
10
11
  refetchInterval: options?.refetchInterval ?? 120000,
11
12
  });
12
13
  }
@@ -12,6 +12,7 @@ function useProposals(options) {
12
12
  return (0, use_api_query_1.useApiQuery)({
13
13
  path: `/voting/proposals${qs}`,
14
14
  requireAuth: true,
15
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.proposals ?? []),
15
16
  refetchInterval: options?.refetchInterval ?? 0,
16
17
  });
17
18
  }
@@ -6,6 +6,7 @@ const use_api_query_1 = require("./use-api-query");
6
6
  function useTechTreeConfig(options) {
7
7
  return (0, use_api_query_1.useApiQuery)({
8
8
  path: '/tech-tree/config',
9
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.nodes ?? raw?.config ?? []),
9
10
  refetchInterval: options?.refetchInterval ?? 300000,
10
11
  });
11
12
  }
@@ -14,6 +14,7 @@ function useTerritories(options) {
14
14
  return (0, use_api_query_1.useApiQuery)({
15
15
  path: `/territories${qs}`,
16
16
  requireAuth: true,
17
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.territories ?? raw?.data ?? []),
17
18
  refetchInterval: options?.refetchInterval ?? 0,
18
19
  });
19
20
  }
@@ -10,6 +10,7 @@ function useTerritoryMembers(id, options) {
10
10
  path: `/territories/${id}/members?page=${page}&page_size=${pageSize}`,
11
11
  requireAuth: true,
12
12
  skip: !id,
13
+ select: (raw) => Array.isArray(raw) ? raw : (raw?.members ?? []),
13
14
  refetchInterval: options?.refetchInterval ?? 0,
14
15
  });
15
16
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microcosmmoney/auth-react",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "description": "Microcosm OAuth 2.0 React/Next.js adapter",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -26,7 +26,7 @@
26
26
  "react-dom": ">=18.0.0"
27
27
  },
28
28
  "dependencies": {
29
- "@microcosmmoney/auth-core": "^2.2.1"
29
+ "@microcosmmoney/auth-core": "file:../auth-core"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/react": "^18.0.0",