@explorins/pers-sdk-react-native 1.3.2 → 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.
Files changed (90) hide show
  1. package/README.md +276 -123
  2. package/dist/hooks/index.d.ts +8 -0
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.js +7 -0
  5. package/dist/hooks/useAnalytics.d.ts +96 -0
  6. package/dist/hooks/useAnalytics.d.ts.map +1 -0
  7. package/dist/hooks/useAnalytics.js +73 -0
  8. package/dist/hooks/useAuth.d.ts +52 -7
  9. package/dist/hooks/useAuth.d.ts.map +1 -1
  10. package/dist/hooks/useAuth.js +250 -3
  11. package/dist/hooks/useBusiness.d.ts +45 -3
  12. package/dist/hooks/useBusiness.d.ts.map +1 -1
  13. package/dist/hooks/useBusiness.js +182 -28
  14. package/dist/hooks/useCampaigns.d.ts +11 -4
  15. package/dist/hooks/useCampaigns.d.ts.map +1 -1
  16. package/dist/hooks/useCampaigns.js +101 -39
  17. package/dist/hooks/useDonations.d.ts +33 -0
  18. package/dist/hooks/useDonations.d.ts.map +1 -0
  19. package/dist/hooks/useDonations.js +62 -0
  20. package/dist/hooks/useFiles.d.ts +50 -0
  21. package/dist/hooks/useFiles.d.ts.map +1 -0
  22. package/dist/hooks/useFiles.js +140 -0
  23. package/dist/hooks/usePurchases.d.ts +9 -0
  24. package/dist/hooks/usePurchases.d.ts.map +1 -0
  25. package/dist/hooks/usePurchases.js +56 -0
  26. package/dist/hooks/useRedemptions.d.ts +10 -5
  27. package/dist/hooks/useRedemptions.d.ts.map +1 -1
  28. package/dist/hooks/useRedemptions.js +94 -66
  29. package/dist/hooks/useTenants.d.ts +10 -0
  30. package/dist/hooks/useTenants.d.ts.map +1 -0
  31. package/dist/hooks/useTenants.js +68 -0
  32. package/dist/hooks/useTokens.d.ts +36 -2
  33. package/dist/hooks/useTokens.d.ts.map +1 -1
  34. package/dist/hooks/useTokens.js +180 -19
  35. package/dist/hooks/useTransactions.d.ts +45 -3
  36. package/dist/hooks/useTransactions.d.ts.map +1 -1
  37. package/dist/hooks/useTransactions.js +152 -31
  38. package/dist/hooks/useUserStatus.d.ts +9 -0
  39. package/dist/hooks/useUserStatus.d.ts.map +1 -0
  40. package/dist/hooks/useUserStatus.js +57 -0
  41. package/dist/hooks/useUsers.d.ts +17 -0
  42. package/dist/hooks/useUsers.d.ts.map +1 -0
  43. package/dist/hooks/useUsers.js +120 -0
  44. package/dist/hooks/useWeb3.d.ts +69 -6
  45. package/dist/hooks/useWeb3.d.ts.map +1 -1
  46. package/dist/hooks/useWeb3.js +177 -17
  47. package/dist/index.d.ts +6 -4
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +12199 -796
  50. package/dist/index.js.map +1 -1
  51. package/dist/polyfills/index.d.ts +1 -1
  52. package/dist/polyfills/index.d.ts.map +1 -1
  53. package/dist/polyfills/index.js +155 -9
  54. package/dist/polyfills/web3-polyfills.d.ts +7 -0
  55. package/dist/polyfills/web3-polyfills.d.ts.map +1 -0
  56. package/dist/polyfills/web3-polyfills.js +85 -0
  57. package/dist/providers/PersSDKProvider.d.ts +28 -18
  58. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  59. package/dist/providers/PersSDKProvider.js +63 -129
  60. package/dist/providers/react-native-auth-provider.d.ts +19 -64
  61. package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
  62. package/dist/providers/react-native-auth-provider.js +57 -175
  63. package/package.json +171 -157
  64. package/src/hooks/index.ts +11 -1
  65. package/src/hooks/useAnalytics.ts +150 -0
  66. package/src/hooks/useAuth.ts +286 -27
  67. package/src/hooks/useBusiness.ts +193 -30
  68. package/src/hooks/useCampaigns.ts +121 -43
  69. package/src/hooks/useDonations.ts +68 -0
  70. package/src/hooks/useFiles.ts +160 -0
  71. package/src/hooks/usePurchases.ts +69 -0
  72. package/src/hooks/useRedemptions.ts +109 -68
  73. package/src/hooks/useTenants.ts +77 -0
  74. package/src/hooks/useTokens.ts +189 -21
  75. package/src/hooks/useTransactions.ts +170 -34
  76. package/src/hooks/useUserStatus.ts +65 -0
  77. package/src/hooks/useUsers.ts +133 -0
  78. package/src/hooks/useWeb3.ts +201 -21
  79. package/src/index.ts +21 -17
  80. package/src/polyfills/index.ts +163 -10
  81. package/src/polyfills/web3-polyfills.ts +98 -0
  82. package/src/providers/PersSDKProvider.tsx +114 -178
  83. package/src/providers/react-native-auth-provider.ts +65 -208
  84. package/dist/index.esm.js +0 -1057
  85. package/dist/index.esm.js.map +0 -1
  86. package/dist/polyfills/index.simple.d.ts +0 -2
  87. package/dist/polyfills/index.simple.d.ts.map +0 -1
  88. package/dist/polyfills/index.simple.js +0 -17
  89. package/src/polyfills/index.simple.ts +0 -22
  90. package/src/types/external-modules.d.ts +0 -13
@@ -1,48 +1,209 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ /**
4
+ * React hook for token operations in the PERS SDK
5
+ *
6
+ * Provides methods for fetching various types of tokens including credit, reward, and status tokens.
7
+ * Supports both general token queries and specific contract-based token retrieval.
8
+ *
9
+ * @returns Token hook with methods for token management
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * function TokensComponent() {
14
+ * const { getTokens, getActiveCreditToken, getRewardTokens } = useTokens();
15
+ *
16
+ * const loadTokens = async () => {
17
+ * try {
18
+ * const tokens = await getTokens();
19
+ * const creditToken = await getActiveCreditToken();
20
+ * console.log('Loaded tokens:', tokens);
21
+ * console.log('Active credit token:', creditToken);
22
+ * } catch (error) {
23
+ * console.error('Failed to load tokens:', error);
24
+ * }
25
+ * };
26
+ *
27
+ * return <button onClick={loadTokens}>Load Tokens</button>;
28
+ * }
29
+ * ```
30
+ */
3
31
  export const useTokens = () => {
4
- const { tokens, isInitialized, isAuthenticated } = usePersSDK();
32
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
5
33
  if (!isAuthenticated && isInitialized) {
6
34
  console.warn('SDK not authenticated. Some token operations may fail.');
7
35
  }
36
+ /**
37
+ * Retrieves all tokens available to the current user
38
+ *
39
+ * @returns Promise resolving to array of tokens
40
+ * @throws Error if SDK is not initialized
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const { getTokens } = useTokens();
45
+ * const tokens = await getTokens();
46
+ * console.log('Available tokens:', tokens);
47
+ * ```
48
+ */
8
49
  const getTokens = useCallback(async () => {
9
- if (!isInitialized) {
50
+ if (!isInitialized || !sdk) {
10
51
  throw new Error('SDK not initialized. Call initialize() first.');
11
52
  }
12
- if (!tokens?.getTokens) {
13
- console.warn('getTokens method not available');
14
- return [];
53
+ try {
54
+ const result = await sdk.tokens.getTokens();
55
+ console.log('Tokens fetched successfully:', result);
56
+ return result;
57
+ }
58
+ catch (error) {
59
+ console.error('Failed to fetch tokens:', error);
60
+ throw error;
61
+ }
62
+ }, [sdk, isInitialized]);
63
+ /**
64
+ * Retrieves the currently active credit token
65
+ *
66
+ * @returns Promise resolving to active credit token
67
+ * @throws Error if SDK is not initialized
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const { getActiveCreditToken } = useTokens();
72
+ * const creditToken = await getActiveCreditToken();
73
+ * console.log('Active credit token:', creditToken.name);
74
+ * ```
75
+ */
76
+ const getActiveCreditToken = useCallback(async () => {
77
+ if (!isInitialized || !sdk) {
78
+ throw new Error('SDK not initialized. Call initialize() first.');
79
+ }
80
+ try {
81
+ const result = await sdk.tokens.getActiveCreditToken();
82
+ console.log('Active credit token fetched successfully:', result);
83
+ return result;
84
+ }
85
+ catch (error) {
86
+ console.error('Failed to fetch active credit token:', error);
87
+ throw error;
88
+ }
89
+ }, [sdk, isInitialized]);
90
+ /**
91
+ * Retrieves all reward tokens available in the system
92
+ *
93
+ * @returns Promise resolving to array of reward tokens
94
+ * @throws Error if SDK is not initialized
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const { getRewardTokens } = useTokens();
99
+ * const rewardTokens = await getRewardTokens();
100
+ * console.log('Reward tokens:', rewardTokens);
101
+ * ```
102
+ */
103
+ const getRewardTokens = useCallback(async () => {
104
+ if (!isInitialized || !sdk) {
105
+ throw new Error('SDK not initialized. Call initialize() first.');
15
106
  }
16
107
  try {
17
- const result = await tokens.getTokens();
18
- console.log(' Tokens fetched successfully:', result);
108
+ const result = await sdk.tokens.getRewardTokens();
109
+ console.log('Reward tokens fetched successfully:', result);
19
110
  return result;
20
111
  }
21
112
  catch (error) {
22
- console.error('Failed to fetch tokens:', error);
113
+ console.error('Failed to fetch reward tokens:', error);
23
114
  throw error;
24
115
  }
25
- }, [tokens]);
26
- const getTokenById = useCallback(async (tokenId) => {
27
- if (!isInitialized) {
116
+ }, [sdk, isInitialized]);
117
+ /**
118
+ * Retrieves all available token types in the system
119
+ *
120
+ * @returns Promise resolving to array of token types
121
+ * @throws Error if SDK is not initialized
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const { getTokenTypes } = useTokens();
126
+ * const types = await getTokenTypes();
127
+ * console.log('Token types:', types);
128
+ * ```
129
+ */
130
+ const getTokenTypes = useCallback(async () => {
131
+ if (!isInitialized || !sdk) {
28
132
  throw new Error('SDK not initialized. Call initialize() first.');
29
133
  }
30
- if (!tokens?.getTokenById) {
31
- throw new Error('getTokenById method not available');
134
+ try {
135
+ const result = await sdk.tokens.getTokenTypes();
136
+ console.log('Token types fetched successfully:', result);
137
+ return result;
138
+ }
139
+ catch (error) {
140
+ console.error('Failed to fetch token types:', error);
141
+ throw error;
142
+ }
143
+ }, [sdk, isInitialized]);
144
+ /**
145
+ * Retrieves all status tokens (tokens that represent user status/achievements)
146
+ *
147
+ * @returns Promise resolving to array of status tokens
148
+ * @throws Error if SDK is not initialized
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const { getStatusTokens } = useTokens();
153
+ * const statusTokens = await getStatusTokens();
154
+ * console.log('Status tokens:', statusTokens);
155
+ * ```
156
+ */
157
+ const getStatusTokens = useCallback(async () => {
158
+ if (!isInitialized || !sdk) {
159
+ throw new Error('SDK not initialized. Call initialize() first.');
160
+ }
161
+ try {
162
+ const result = await sdk.tokens.getStatusTokens();
163
+ console.log('Status tokens fetched successfully:', result);
164
+ return result;
165
+ }
166
+ catch (error) {
167
+ console.error('Failed to fetch status tokens:', error);
168
+ throw error;
169
+ }
170
+ }, [sdk, isInitialized]);
171
+ /**
172
+ * Retrieves a specific token by its contract address and optional token ID
173
+ *
174
+ * @param contractAddress - The contract address of the token
175
+ * @param contractTokenId - Optional specific token ID within the contract
176
+ * @returns Promise resolving to the token data
177
+ * @throws Error if SDK is not initialized
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * const { getTokenByContract } = useTokens();
182
+ * const token = await getTokenByContract('0x123...', 'token-1');
183
+ * console.log('Token from contract:', token);
184
+ * ```
185
+ */
186
+ const getTokenByContract = useCallback(async (contractAddress, contractTokenId) => {
187
+ if (!isInitialized || !sdk) {
188
+ throw new Error('SDK not initialized. Call initialize() first.');
32
189
  }
33
190
  try {
34
- const result = await tokens.getTokenById(tokenId);
35
- console.log('Token fetched successfully:', result);
191
+ const result = await sdk.tokens.getTokenByContract(contractAddress, contractTokenId);
192
+ console.log('Token by contract fetched successfully:', result);
36
193
  return result;
37
194
  }
38
195
  catch (error) {
39
- console.error('Failed to fetch token:', error);
196
+ console.error('Failed to fetch token by contract:', error);
40
197
  throw error;
41
198
  }
42
- }, [tokens]);
199
+ }, [sdk, isInitialized]);
43
200
  return {
44
201
  getTokens,
45
- getTokenById,
46
- isAvailable: isInitialized && !!tokens,
202
+ getActiveCreditToken,
203
+ getRewardTokens,
204
+ getTokenTypes,
205
+ getStatusTokens,
206
+ getTokenByContract,
207
+ isAvailable: isInitialized && !!sdk?.tokens,
47
208
  };
48
209
  };
@@ -1,7 +1,49 @@
1
+ import type { TransactionRequestDTO, TransactionRequestResponseDTO, TransactionDTO } from '@explorins/pers-shared';
2
+ import type { TransactionPaginationParams } from '@explorins/pers-sdk/transaction';
3
+ /**
4
+ * React hook for transaction operations in the PERS SDK
5
+ *
6
+ * Provides comprehensive transaction management including creation, retrieval, history,
7
+ * and administrative operations. Supports pagination and CSV export functionality.
8
+ *
9
+ * @returns Transaction hook with methods for transaction management
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * function TransactionsComponent() {
14
+ * const {
15
+ * createTransaction,
16
+ * getUserTransactionHistory
17
+ * } = useTransactions();
18
+ *
19
+ * const handleCreateTransaction = async (request) => {
20
+ * try {
21
+ * const result = await createTransaction(request);
22
+ * console.log('Transaction created:', result);
23
+ * // Handle signature URL if returned
24
+ * } catch (error) {
25
+ * console.error('Transaction failed:', error);
26
+ * }
27
+ * };
28
+ *
29
+ * return (
30
+ * <div>
31
+ * <button onClick={() => handleCreateTransaction(transactionRequest)}>
32
+ * Create Transaction
33
+ * </button>
34
+ * </div>
35
+ * );
36
+ * }
37
+ * ```
38
+ */
1
39
  export declare const useTransactions: () => {
2
- createTransaction: (request: any) => Promise<any>;
3
- getTransactionById: (transactionId: string) => Promise<any>;
4
- getTransactionHistory: (filters?: any) => Promise<any>;
40
+ createTransaction: (request: TransactionRequestDTO) => Promise<TransactionRequestResponseDTO>;
41
+ getTransactionById: (transactionId: string) => Promise<TransactionDTO | null>;
42
+ getUserTransactionHistory: (type?: string) => Promise<TransactionDTO[]>;
43
+ getTenantTransactions: () => Promise<TransactionDTO[]>;
44
+ getPaginatedTransactions: (params: TransactionPaginationParams) => Promise<any>;
45
+ exportTransactionsCSV: () => Promise<Blob>;
5
46
  isAvailable: boolean;
6
47
  };
48
+ export type TransactionHook = ReturnType<typeof useTransactions>;
7
49
  //# sourceMappingURL=useTransactions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTransactions.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactions.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,eAAe;iCAO4B,GAAG;wCA+BI,MAAM;sCAkBR,GAAG;;CAyB/D,CAAC"}
1
+ {"version":3,"file":"useTransactions.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactions.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,qBAAqB,EACrB,6BAA6B,EAC7B,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAMnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,eAAe;iCA6B4B,qBAAqB,KAAG,QAAQ,6BAA6B,CAAC;wCA0CvD,MAAM,KAAG,QAAQ,cAAc,GAAG,IAAI,CAAC;uCA6BzC,MAAM,KAAW,QAAQ,cAAc,EAAE,CAAC;iCAejD,QAAQ,cAAc,EAAE,CAAC;uCAejB,2BAA2B,KAAG,QAAQ,GAAG,CAAC;iCAelD,QAAQ,IAAI,CAAC;;CAwBlE,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC"}
@@ -1,78 +1,199 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ /**
4
+ * React hook for transaction operations in the PERS SDK
5
+ *
6
+ * Provides comprehensive transaction management including creation, retrieval, history,
7
+ * and administrative operations. Supports pagination and CSV export functionality.
8
+ *
9
+ * @returns Transaction hook with methods for transaction management
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * function TransactionsComponent() {
14
+ * const {
15
+ * createTransaction,
16
+ * getUserTransactionHistory
17
+ * } = useTransactions();
18
+ *
19
+ * const handleCreateTransaction = async (request) => {
20
+ * try {
21
+ * const result = await createTransaction(request);
22
+ * console.log('Transaction created:', result);
23
+ * // Handle signature URL if returned
24
+ * } catch (error) {
25
+ * console.error('Transaction failed:', error);
26
+ * }
27
+ * };
28
+ *
29
+ * return (
30
+ * <div>
31
+ * <button onClick={() => handleCreateTransaction(transactionRequest)}>
32
+ * Create Transaction
33
+ * </button>
34
+ * </div>
35
+ * );
36
+ * }
37
+ * ```
38
+ */
3
39
  export const useTransactions = () => {
4
- const { transactions, isInitialized, isAuthenticated } = usePersSDK();
40
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
5
41
  if (!isAuthenticated && isInitialized) {
6
42
  console.warn('SDK not authenticated. Some transaction operations may fail.');
7
43
  }
44
+ /**
45
+ * Creates a new transaction in the system
46
+ *
47
+ * Automatically handles signature URLs by opening them in the device's browser.
48
+ * The transaction may require user approval through external wallet applications.
49
+ *
50
+ * @param request - Transaction request data including amount, recipient, etc.
51
+ * @returns Promise resolving to transaction response with potential actionable items
52
+ * @throws Error if SDK is not initialized
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const { createTransaction } = useTransactions();
57
+ * const request = {
58
+ * amount: '100',
59
+ * recipient: '0x123...',
60
+ * tokenId: 'token-123'
61
+ * };
62
+ * const result = await createTransaction(request);
63
+ * console.log('Transaction created:', result);
64
+ * ```
65
+ */
8
66
  const createTransaction = useCallback(async (request) => {
9
- if (!isInitialized) {
67
+ if (!isInitialized || !sdk) {
10
68
  throw new Error('SDK not initialized. Call initialize() first.');
11
69
  }
12
- if (!transactions?.createTransaction) {
13
- throw new Error('createTransaction method not available');
14
- }
15
70
  try {
16
- console.log('🔄 Creating transaction with request:', request);
17
- const result = await transactions.createTransaction(request);
18
- // React Native specific: Handle signature URLs
71
+ console.log('Creating transaction with request:', request);
72
+ const result = await sdk.transactions.createTransaction(request);
73
+ // Cross-platform: Handle signature URLs
19
74
  if (result?.actionable?.actionUrl) {
20
75
  try {
21
76
  const { Linking } = require('react-native');
22
- console.log('🔗 Opening signature URL:', result.actionable.actionUrl);
77
+ console.log('Opening signature URL:', result.actionable.actionUrl);
23
78
  await Linking.openURL(result.actionable.actionUrl);
24
79
  }
25
80
  catch (linkingError) {
26
- console.error('Failed to open signature URL:', linkingError);
81
+ console.error('Failed to open signature URL:', linkingError);
27
82
  }
28
83
  }
29
- console.log('Transaction created successfully:', result);
84
+ console.log('Transaction created successfully:', result);
30
85
  return result;
31
86
  }
32
87
  catch (error) {
33
- console.error('Failed to create transaction:', error);
88
+ console.error('Failed to create transaction:', error);
34
89
  throw error;
35
90
  }
36
- }, [transactions]);
91
+ }, [sdk, isInitialized]);
92
+ /**
93
+ * Retrieves a specific transaction by its ID
94
+ *
95
+ * @param transactionId - Unique identifier of the transaction
96
+ * @returns Promise resolving to transaction data or null if not found
97
+ * @throws Error if SDK is not initialized
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const { getTransactionById } = useTransactions();
102
+ * const transaction = await getTransactionById('txn-123');
103
+ * console.log('Transaction details:', transaction);
104
+ * ```
105
+ */
37
106
  const getTransactionById = useCallback(async (transactionId) => {
38
- if (!isInitialized) {
107
+ if (!isInitialized || !sdk) {
39
108
  throw new Error('SDK not initialized. Call initialize() first.');
40
109
  }
41
- if (!transactions?.getTransactionById) {
42
- throw new Error('getTransactionById method not available');
110
+ try {
111
+ const result = await sdk.transactions.getTransactionById(transactionId);
112
+ console.log('Transaction fetched successfully:', result);
113
+ return result;
114
+ }
115
+ catch (error) {
116
+ console.error('Failed to fetch transaction:', error);
117
+ throw error;
118
+ }
119
+ }, [sdk, isInitialized]);
120
+ /**
121
+ * Retrieves transaction history for the authenticated user, filtered by type
122
+ *
123
+ * @param type - Transaction type filter (defaults to 'all')
124
+ * @returns Promise resolving to array of user's transactions
125
+ * @throws Error if SDK is not initialized
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * const { getUserTransactionHistory } = useTransactions();
130
+ * const transactions = await getUserTransactionHistory('credit');
131
+ * console.log('Credit transactions:', transactions);
132
+ * ```
133
+ */
134
+ const getUserTransactionHistory = useCallback(async (type = 'all') => {
135
+ if (!isInitialized || !sdk) {
136
+ throw new Error('SDK not initialized. Call initialize() first.');
43
137
  }
44
138
  try {
45
- const result = await transactions.getTransactionById(transactionId);
46
- console.log('Transaction fetched successfully:', result);
139
+ const result = await sdk.transactions.getUserTransactionHistory(type);
140
+ console.log('Transaction history fetched successfully:', result);
47
141
  return result;
48
142
  }
49
143
  catch (error) {
50
- console.error('Failed to fetch transaction:', error);
144
+ console.error('Failed to fetch transaction history:', error);
51
145
  throw error;
52
146
  }
53
- }, [transactions]);
54
- const getTransactionHistory = useCallback(async (filters) => {
55
- if (!isInitialized) {
147
+ }, [sdk, isInitialized]);
148
+ const getTenantTransactions = useCallback(async () => {
149
+ if (!isInitialized || !sdk) {
56
150
  throw new Error('SDK not initialized. Call initialize() first.');
57
151
  }
58
- if (!transactions?.getTransactionHistory) {
59
- console.warn('getTransactionHistory method not available');
60
- return [];
152
+ try {
153
+ const result = await sdk.transactions.getTenantTransactions();
154
+ console.log('Tenant transactions fetched successfully:', result);
155
+ return result;
156
+ }
157
+ catch (error) {
158
+ console.error('Failed to fetch tenant transactions:', error);
159
+ throw error;
160
+ }
161
+ }, [sdk, isInitialized]);
162
+ const getPaginatedTransactions = useCallback(async (params) => {
163
+ if (!isInitialized || !sdk) {
164
+ throw new Error('SDK not initialized. Call initialize() first.');
165
+ }
166
+ try {
167
+ const result = await sdk.transactions.getPaginatedTransactions(params);
168
+ console.log('Paginated transactions fetched successfully:', result);
169
+ return result;
170
+ }
171
+ catch (error) {
172
+ console.error('Failed to fetch paginated transactions:', error);
173
+ throw error;
174
+ }
175
+ }, [sdk, isInitialized]);
176
+ const exportTransactionsCSV = useCallback(async () => {
177
+ if (!isInitialized || !sdk) {
178
+ throw new Error('SDK not initialized. Call initialize() first.');
61
179
  }
62
180
  try {
63
- const result = await transactions.getTransactionHistory(filters);
64
- console.log(' Transaction history fetched successfully:', result);
181
+ const result = await sdk.transactions.exportTransactionsCSV();
182
+ console.log('Transactions CSV exported successfully');
65
183
  return result;
66
184
  }
67
185
  catch (error) {
68
- console.error('Failed to fetch transaction history:', error);
186
+ console.error('Failed to export transactions CSV:', error);
69
187
  throw error;
70
188
  }
71
- }, [transactions]);
189
+ }, [sdk, isInitialized]);
72
190
  return {
73
191
  createTransaction,
74
192
  getTransactionById,
75
- getTransactionHistory,
76
- isAvailable: isInitialized && !!transactions,
193
+ getUserTransactionHistory,
194
+ getTenantTransactions,
195
+ getPaginatedTransactions,
196
+ exportTransactionsCSV,
197
+ isAvailable: isInitialized && !!sdk?.transactions,
77
198
  };
78
199
  };
@@ -0,0 +1,9 @@
1
+ import type { UserStatusTypeDTO } from '@explorins/pers-shared';
2
+ export declare const useUserStatus: () => {
3
+ getUserStatusTypes: () => Promise<UserStatusTypeDTO[]>;
4
+ getEarnedUserStatus: () => Promise<UserStatusTypeDTO[]>;
5
+ createUserStatusType: (userStatusType: UserStatusTypeDTO) => Promise<UserStatusTypeDTO>;
6
+ isAvailable: boolean;
7
+ };
8
+ export type UserStatusHook = ReturnType<typeof useUserStatus>;
9
+ //# sourceMappingURL=useUserStatus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUserStatus.d.ts","sourceRoot":"","sources":["../../src/hooks/useUserStatus.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,eAAO,MAAM,aAAa;8BAGyB,QAAQ,iBAAiB,EAAE,CAAC;+BAe3B,QAAQ,iBAAiB,EAAE,CAAC;2CAmBd,iBAAiB,KAAG,QAAQ,iBAAiB,CAAC;;CAqB/G,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ export const useUserStatus = () => {
4
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
5
+ const getUserStatusTypes = useCallback(async () => {
6
+ if (!isInitialized || !sdk) {
7
+ throw new Error('SDK not initialized. Call initialize() first.');
8
+ }
9
+ try {
10
+ const result = await sdk.userStatus.getUserStatusTypes();
11
+ console.log('User status types fetched successfully:', result);
12
+ return result;
13
+ }
14
+ catch (error) {
15
+ console.error('Failed to fetch user status types:', error);
16
+ throw error;
17
+ }
18
+ }, [sdk, isInitialized]);
19
+ const getEarnedUserStatus = useCallback(async () => {
20
+ if (!isInitialized || !sdk) {
21
+ throw new Error('SDK not initialized. Call initialize() first.');
22
+ }
23
+ if (!isAuthenticated) {
24
+ throw new Error('SDK not authenticated. getEarnedUserStatus requires authentication.');
25
+ }
26
+ try {
27
+ const result = await sdk.userStatus.getEarnedUserStatus();
28
+ console.log('Earned user status fetched successfully:', result);
29
+ return result;
30
+ }
31
+ catch (error) {
32
+ console.error('Failed to fetch earned user status:', error);
33
+ throw error;
34
+ }
35
+ }, [sdk, isInitialized, isAuthenticated]);
36
+ // Admin methods
37
+ const createUserStatusType = useCallback(async (userStatusType) => {
38
+ if (!isInitialized || !sdk) {
39
+ throw new Error('SDK not initialized. Call initialize() first.');
40
+ }
41
+ try {
42
+ const result = await sdk.userStatus.createUserStatusType(userStatusType);
43
+ console.log('User status type created successfully:', result);
44
+ return result;
45
+ }
46
+ catch (error) {
47
+ console.error('Failed to create user status type:', error);
48
+ throw error;
49
+ }
50
+ }, [sdk, isInitialized]);
51
+ return {
52
+ getUserStatusTypes,
53
+ getEarnedUserStatus,
54
+ createUserStatusType,
55
+ isAvailable: isInitialized && !!sdk?.userStatus,
56
+ };
57
+ };
@@ -0,0 +1,17 @@
1
+ import type { UserDTO, UserCreateRequestDTO } from '@explorins/pers-shared';
2
+ import type { UserPublicProfileDTO } from '@explorins/pers-sdk/user';
3
+ export declare const useUsers: () => {
4
+ getCurrentUser: () => Promise<UserDTO>;
5
+ updateCurrentUser: (userData: UserCreateRequestDTO) => Promise<UserDTO>;
6
+ getUserById: (userId: string) => Promise<UserDTO>;
7
+ getAllUsersPublic: (filter?: {
8
+ key: string;
9
+ value: string;
10
+ }) => Promise<UserPublicProfileDTO[]>;
11
+ getAllUsers: () => Promise<UserDTO[]>;
12
+ updateUser: (userId: string, userData: UserCreateRequestDTO) => Promise<UserDTO>;
13
+ toggleUserStatus: (user: UserDTO) => Promise<UserDTO>;
14
+ isAvailable: boolean;
15
+ };
16
+ export type UserHook = ReturnType<typeof useUsers>;
17
+ //# sourceMappingURL=useUsers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUsers.d.ts","sourceRoot":"","sources":["../../src/hooks/useUsers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAErE,eAAO,MAAM,QAAQ;0BAG0B,QAAQ,OAAO,CAAC;kCAkBN,oBAAoB,KAAG,QAAQ,OAAO,CAAC;0BAkB/C,MAAM,KAAG,QAAQ,OAAO,CAAC;iCAelB;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAG,QAAQ,oBAAoB,EAAE,CAAC;uBAgB5E,QAAQ,OAAO,EAAE,CAAC;yBAed,MAAM,YAAY,oBAAoB,KAAG,QAAQ,OAAO,CAAC;6BAerD,OAAO,KAAG,QAAQ,OAAO,CAAC;;CAyB7E,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC"}