@explorins/pers-sdk-react-native 1.3.2 → 1.5.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.
Files changed (94) hide show
  1. package/README.md +276 -123
  2. package/dist/hooks/index.d.ts +10 -0
  3. package/dist/hooks/index.d.ts.map +1 -1
  4. package/dist/hooks/index.js +8 -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 +118 -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/useTransactionSigner.d.ts +73 -0
  36. package/dist/hooks/useTransactionSigner.d.ts.map +1 -0
  37. package/dist/hooks/useTransactionSigner.js +216 -0
  38. package/dist/hooks/useTransactions.d.ts +45 -3
  39. package/dist/hooks/useTransactions.d.ts.map +1 -1
  40. package/dist/hooks/useTransactions.js +149 -39
  41. package/dist/hooks/useUserStatus.d.ts +9 -0
  42. package/dist/hooks/useUserStatus.d.ts.map +1 -0
  43. package/dist/hooks/useUserStatus.js +57 -0
  44. package/dist/hooks/useUsers.d.ts +17 -0
  45. package/dist/hooks/useUsers.d.ts.map +1 -0
  46. package/dist/hooks/useUsers.js +120 -0
  47. package/dist/hooks/useWeb3.d.ts +69 -6
  48. package/dist/hooks/useWeb3.d.ts.map +1 -1
  49. package/dist/hooks/useWeb3.js +177 -17
  50. package/dist/index.d.ts +6 -4
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +31540 -794
  53. package/dist/index.js.map +1 -1
  54. package/dist/polyfills/index.d.ts +1 -1
  55. package/dist/polyfills/index.d.ts.map +1 -1
  56. package/dist/polyfills/index.js +155 -9
  57. package/dist/polyfills/web3-polyfills.d.ts +7 -0
  58. package/dist/polyfills/web3-polyfills.d.ts.map +1 -0
  59. package/dist/polyfills/web3-polyfills.js +85 -0
  60. package/dist/providers/PersSDKProvider.d.ts +28 -18
  61. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  62. package/dist/providers/PersSDKProvider.js +63 -129
  63. package/dist/providers/react-native-auth-provider.d.ts +19 -64
  64. package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
  65. package/dist/providers/react-native-auth-provider.js +57 -175
  66. package/package.json +177 -157
  67. package/src/hooks/index.ts +13 -1
  68. package/src/hooks/useAnalytics.ts +150 -0
  69. package/src/hooks/useAuth.ts +286 -27
  70. package/src/hooks/useBusiness.ts +193 -30
  71. package/src/hooks/useCampaigns.ts +121 -43
  72. package/src/hooks/useDonations.ts +68 -0
  73. package/src/hooks/useFiles.ts +160 -0
  74. package/src/hooks/usePurchases.ts +69 -0
  75. package/src/hooks/useRedemptions.ts +135 -68
  76. package/src/hooks/useTenants.ts +77 -0
  77. package/src/hooks/useTokens.ts +189 -21
  78. package/src/hooks/useTransactionSigner.ts +287 -0
  79. package/src/hooks/useTransactions.ts +163 -41
  80. package/src/hooks/useUserStatus.ts +65 -0
  81. package/src/hooks/useUsers.ts +133 -0
  82. package/src/hooks/useWeb3.ts +201 -21
  83. package/src/index.ts +22 -17
  84. package/src/polyfills/index.ts +163 -10
  85. package/src/polyfills/web3-polyfills.ts +98 -0
  86. package/src/providers/PersSDKProvider.tsx +114 -178
  87. package/src/providers/react-native-auth-provider.ts +65 -208
  88. package/dist/index.esm.js +0 -1057
  89. package/dist/index.esm.js.map +0 -1
  90. package/dist/polyfills/index.simple.d.ts +0 -2
  91. package/dist/polyfills/index.simple.d.ts.map +0 -1
  92. package/dist/polyfills/index.simple.js +0 -17
  93. package/src/polyfills/index.simple.ts +0 -22
  94. package/src/types/external-modules.d.ts +0 -13
@@ -1,64 +1,218 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
+ /**
4
+ * React hook for business operations in the PERS SDK
5
+ *
6
+ * Provides methods for fetching, creating, and managing businesses within the platform.
7
+ * Includes both public business queries and administrative operations.
8
+ *
9
+ * @returns Business hook with methods for business management
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * function BusinessesComponent() {
14
+ * const {
15
+ * getActiveBusinesses,
16
+ * getBusinessById,
17
+ * createBusiness
18
+ * } = useBusiness();
19
+ *
20
+ * const loadBusinesses = async () => {
21
+ * try {
22
+ * const businesses = await getActiveBusinesses();
23
+ * console.log('Active businesses:', businesses);
24
+ * } catch (error) {
25
+ * console.error('Failed to load businesses:', error);
26
+ * }
27
+ * };
28
+ *
29
+ * return (
30
+ * <div>
31
+ * <button onClick={loadBusinesses}>Load Businesses</button>
32
+ * </div>
33
+ * );
34
+ * }
35
+ * ```
36
+ */
3
37
  export const useBusiness = () => {
4
- const { business, isInitialized } = usePersSDK();
38
+ const { sdk, isInitialized } = usePersSDK();
39
+ /**
40
+ * Retrieves all currently active businesses in the system
41
+ *
42
+ * @returns Promise resolving to array of active businesses
43
+ * @throws Error if SDK is not initialized
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const { getActiveBusinesses } = useBusiness();
48
+ * const businesses = await getActiveBusinesses();
49
+ * console.log('Active businesses:', businesses);
50
+ * ```
51
+ */
5
52
  const getActiveBusinesses = useCallback(async () => {
6
- if (!isInitialized) {
53
+ if (!isInitialized || !sdk) {
7
54
  throw new Error('SDK not initialized. Call initialize() first.');
8
55
  }
9
- if (!business?.getActiveBusinesses) {
10
- console.warn('getActiveBusinesses method not available');
11
- return [];
56
+ try {
57
+ const result = await sdk.businesses.getActiveBusinesses();
58
+ console.log('Active businesses fetched successfully:', result);
59
+ return result;
60
+ }
61
+ catch (error) {
62
+ console.error('Failed to fetch active businesses:', error);
63
+ throw error;
64
+ }
65
+ }, [sdk, isInitialized]);
66
+ /**
67
+ * Retrieves all available business types/categories
68
+ *
69
+ * @returns Promise resolving to array of business types
70
+ * @throws Error if SDK is not initialized
71
+ *
72
+ * @example
73
+ * ```typescript
74
+ * const { getBusinessTypes } = useBusiness();
75
+ * const types = await getBusinessTypes();
76
+ * console.log('Business types:', types);
77
+ * ```
78
+ */
79
+ const getBusinessTypes = useCallback(async () => {
80
+ if (!isInitialized || !sdk) {
81
+ throw new Error('SDK not initialized. Call initialize() first.');
82
+ }
83
+ try {
84
+ const result = await sdk.businesses.getBusinessTypes();
85
+ console.log('Business types fetched successfully:', result);
86
+ return result;
87
+ }
88
+ catch (error) {
89
+ console.error('Failed to fetch business types:', error);
90
+ throw error;
91
+ }
92
+ }, [sdk, isInitialized]);
93
+ const getBusinessById = useCallback(async (businessId) => {
94
+ if (!isInitialized || !sdk) {
95
+ throw new Error('SDK not initialized. Call initialize() first.');
12
96
  }
13
97
  try {
14
- const result = await business.getActiveBusinesses();
15
- console.log(' Active businesses fetched successfully:', result);
98
+ const result = await sdk.businesses.getBusinessById(businessId);
99
+ console.log('Business fetched successfully:', result);
16
100
  return result;
17
101
  }
18
102
  catch (error) {
19
- console.error('Failed to fetch active businesses:', error);
103
+ console.error('Failed to fetch business:', error);
20
104
  throw error;
21
105
  }
22
- }, [business]);
23
- const getAllBusinessTypes = useCallback(async () => {
24
- if (!isInitialized) {
106
+ }, [sdk, isInitialized]);
107
+ const getBusinesses = useCallback(async () => {
108
+ if (!isInitialized || !sdk) {
25
109
  throw new Error('SDK not initialized. Call initialize() first.');
26
110
  }
27
- if (!business?.getAllBusinessTypes) {
28
- console.warn('getAllBusinessTypes method not available');
29
- return [];
111
+ try {
112
+ const result = await sdk.businesses.getBusinesses();
113
+ console.log('All businesses fetched successfully:', result);
114
+ return result;
115
+ }
116
+ catch (error) {
117
+ console.error('Failed to fetch all businesses:', error);
118
+ throw error;
119
+ }
120
+ }, [sdk, isInitialized]);
121
+ const getBusinessByAccount = useCallback(async (accountAddress) => {
122
+ if (!isInitialized || !sdk) {
123
+ throw new Error('SDK not initialized. Call initialize() first.');
30
124
  }
31
125
  try {
32
- const result = await business.getAllBusinessTypes();
33
- console.log('Business types fetched successfully:', result);
126
+ const result = await sdk.businesses.getBusinessByAccount(accountAddress);
127
+ console.log('Business by account fetched successfully:', result);
34
128
  return result;
35
129
  }
36
130
  catch (error) {
37
- console.error('Failed to fetch business types:', error);
131
+ console.error('Failed to fetch business by account:', error);
38
132
  throw error;
39
133
  }
40
- }, [business]);
41
- const getBusinessById = useCallback(async (businessId) => {
42
- if (!isInitialized) {
134
+ }, [sdk, isInitialized]);
135
+ const getBusinessesByType = useCallback(async (typeId) => {
136
+ if (!isInitialized || !sdk) {
43
137
  throw new Error('SDK not initialized. Call initialize() first.');
44
138
  }
45
- if (!business?.getBusinessById) {
46
- throw new Error('getBusinessById method not available');
139
+ try {
140
+ const result = await sdk.businesses.getBusinessesByType(typeId);
141
+ console.log('Businesses by type fetched successfully:', result);
142
+ return result;
143
+ }
144
+ catch (error) {
145
+ console.error('Failed to fetch businesses by type:', error);
146
+ throw error;
147
+ }
148
+ }, [sdk, isInitialized]);
149
+ // Admin methods
150
+ /**
151
+ * Creates a new business (Admin operation)
152
+ *
153
+ * @param displayName - The display name for the new business
154
+ * @returns Promise resolving to the created business data
155
+ * @throws Error if SDK is not initialized or user lacks permissions
156
+ *
157
+ * @example
158
+ * ```typescript
159
+ * const { createBusiness } = useBusiness();
160
+ * const business = await createBusiness('My Coffee Shop');
161
+ * console.log('Business created:', business);
162
+ * ```
163
+ */
164
+ const createBusiness = useCallback(async (displayName) => {
165
+ if (!isInitialized || !sdk) {
166
+ throw new Error('SDK not initialized. Call initialize() first.');
167
+ }
168
+ try {
169
+ const result = await sdk.businesses.createBusiness(displayName);
170
+ console.log('Business created successfully:', result);
171
+ return result;
172
+ }
173
+ catch (error) {
174
+ console.error('Failed to create business:', error);
175
+ throw error;
176
+ }
177
+ }, [sdk, isInitialized]);
178
+ const updateBusiness = useCallback(async (businessId, businessData) => {
179
+ if (!isInitialized || !sdk) {
180
+ throw new Error('SDK not initialized. Call initialize() first.');
181
+ }
182
+ try {
183
+ const result = await sdk.businesses.updateBusiness(businessId, businessData);
184
+ console.log('Business updated successfully:', result);
185
+ return result;
186
+ }
187
+ catch (error) {
188
+ console.error('Failed to update business:', error);
189
+ throw error;
190
+ }
191
+ }, [sdk, isInitialized]);
192
+ const toggleBusinessStatus = useCallback(async (businessId, toggleData) => {
193
+ if (!isInitialized || !sdk) {
194
+ throw new Error('SDK not initialized. Call initialize() first.');
47
195
  }
48
196
  try {
49
- const result = await business.getBusinessById(businessId);
50
- console.log('Business fetched successfully:', result);
197
+ const result = await sdk.businesses.toggleBusinessStatus(businessId, toggleData);
198
+ console.log('Business status toggled successfully:', result);
51
199
  return result;
52
200
  }
53
201
  catch (error) {
54
- console.error('Failed to fetch business:', error);
202
+ console.error('Failed to toggle business status:', error);
55
203
  throw error;
56
204
  }
57
- }, [business]);
205
+ }, [sdk, isInitialized]);
58
206
  return {
59
207
  getActiveBusinesses,
60
- getAllBusinessTypes,
208
+ getBusinessTypes,
209
+ getBusinesses,
61
210
  getBusinessById,
62
- isAvailable: isInitialized && !!business,
211
+ getBusinessByAccount,
212
+ getBusinessesByType,
213
+ createBusiness,
214
+ updateBusiness,
215
+ toggleBusinessStatus,
216
+ isAvailable: isInitialized && !!sdk?.businesses,
63
217
  };
64
218
  };
@@ -1,8 +1,15 @@
1
+ import type { CampaignClaimRequestDTO, CampaignDTO, CampaignClaimDTO, CampaignTriggerDTO } from '@explorins/pers-shared';
1
2
  export declare const useCampaigns: () => {
2
- getActiveCampaigns: () => Promise<any>;
3
- getCampaignById: (campaignId: string) => Promise<any>;
4
- claimCampaign: (request: any) => Promise<any>;
5
- getClaimsForLoggedUser: () => Promise<any>;
3
+ getActiveCampaigns: () => Promise<CampaignDTO[]>;
4
+ getCampaignById: (campaignId: string) => Promise<CampaignDTO | null>;
5
+ claimCampaign: (request: CampaignClaimRequestDTO) => Promise<CampaignClaimDTO | null>;
6
+ getUserClaims: () => Promise<CampaignClaimDTO[]>;
7
+ getCampaignTriggers: () => Promise<CampaignTriggerDTO[]>;
8
+ getAllCampaigns: (active?: boolean) => Promise<CampaignDTO[]>;
9
+ getCampaignClaims: () => Promise<CampaignClaimDTO[]>;
10
+ getCampaignClaimsByUserId: (userId: string) => Promise<CampaignClaimDTO[]>;
11
+ getCampaignClaimsByBusinessId: (businessId: string) => Promise<CampaignClaimDTO[]>;
6
12
  isAvailable: boolean;
7
13
  };
14
+ export type CampaignHook = ReturnType<typeof useCampaigns>;
8
15
  //# sourceMappingURL=useCampaigns.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCampaigns.d.ts","sourceRoot":"","sources":["../../src/hooks/useCampaigns.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY;;kCAsBgC,MAAM;6BAkBX,GAAG;;;CAoDtD,CAAC"}
1
+ {"version":3,"file":"useCampaigns.d.ts","sourceRoot":"","sources":["../../src/hooks/useCampaigns.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,uBAAuB,EACvB,WAAW,EACX,gBAAgB,EAChB,kBAAkB,EAInB,MAAM,wBAAwB,CAAC;AAEhC,eAAO,MAAM,YAAY;8BAG0B,QAAQ,WAAW,EAAE,CAAC;kCAehB,MAAM,KAAG,QAAQ,WAAW,GAAG,IAAI,CAAC;6BAezC,uBAAuB,KAAG,QAAQ,gBAAgB,GAAG,IAAI,CAAC;yBAmBhE,QAAQ,gBAAgB,EAAE,CAAC;+BAmBrB,QAAQ,kBAAkB,EAAE,CAAC;+BAgB3B,OAAO,KAAG,QAAQ,WAAW,EAAE,CAAC;6BAepC,QAAQ,gBAAgB,EAAE,CAAC;wCAed,MAAM,KAAG,QAAQ,gBAAgB,EAAE,CAAC;gDAe5B,MAAM,KAAG,QAAQ,gBAAgB,EAAE,CAAC;;CA2B1G,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC"}
@@ -1,90 +1,152 @@
1
1
  import { useCallback } from 'react';
2
2
  import { usePersSDK } from '../providers/PersSDKProvider';
3
3
  export const useCampaigns = () => {
4
- const { campaigns, isInitialized, isAuthenticated } = usePersSDK();
4
+ const { sdk, isInitialized, isAuthenticated } = usePersSDK();
5
5
  const getActiveCampaigns = useCallback(async () => {
6
- if (!isInitialized) {
6
+ if (!isInitialized || !sdk) {
7
7
  throw new Error('SDK not initialized. Call initialize() first.');
8
8
  }
9
- if (!campaigns?.getActiveCampaigns) {
10
- console.warn('getActiveCampaigns method not available');
11
- return [];
12
- }
13
9
  try {
14
- const result = await campaigns.getActiveCampaigns();
15
- console.log('Active campaigns fetched successfully:', result);
10
+ const result = await sdk.campaigns.getActiveCampaigns();
11
+ console.log('Active campaigns fetched successfully:', result);
16
12
  return result;
17
13
  }
18
14
  catch (error) {
19
- console.error('Failed to fetch active campaigns:', error);
15
+ console.error('Failed to fetch active campaigns:', error);
20
16
  throw error;
21
17
  }
22
- }, [campaigns]);
18
+ }, [sdk, isInitialized]);
23
19
  const getCampaignById = useCallback(async (campaignId) => {
24
- if (!isInitialized) {
20
+ if (!isInitialized || !sdk) {
25
21
  throw new Error('SDK not initialized. Call initialize() first.');
26
22
  }
27
- if (!campaigns?.getCampaignById) {
28
- throw new Error('getCampaignById method not available');
29
- }
30
23
  try {
31
- const result = await campaigns.getCampaignById(campaignId);
32
- console.log('Campaign fetched successfully:', result);
24
+ const result = await sdk.campaigns.getCampaignById(campaignId);
25
+ console.log('Campaign fetched successfully:', result);
33
26
  return result;
34
27
  }
35
28
  catch (error) {
36
- console.error('Failed to fetch campaign:', error);
29
+ console.error('Failed to fetch campaign:', error);
37
30
  throw error;
38
31
  }
39
- }, [campaigns]);
32
+ }, [sdk, isInitialized]);
40
33
  const claimCampaign = useCallback(async (request) => {
41
- if (!isInitialized) {
34
+ if (!isInitialized || !sdk) {
42
35
  throw new Error('SDK not initialized. Call initialize() first.');
43
36
  }
44
37
  if (!isAuthenticated) {
45
38
  throw new Error('SDK not authenticated. claimCampaign requires authentication.');
46
39
  }
47
- if (!campaigns?.claimCampaign) {
48
- throw new Error('claimCampaign method not available');
49
- }
50
40
  try {
51
- console.log('🔄 Claiming campaign with request:', request);
52
- const result = await campaigns.claimCampaign(request);
53
- console.log('Campaign claimed successfully:', result);
41
+ console.log('Claiming campaign with request:', request);
42
+ const result = await sdk.campaigns.claimCampaign(request);
43
+ console.log('Campaign claimed successfully:', result);
54
44
  return result;
55
45
  }
56
46
  catch (error) {
57
- console.error('Failed to claim campaign:', error);
47
+ console.error('Failed to claim campaign:', error);
58
48
  throw error;
59
49
  }
60
- }, [isInitialized, isAuthenticated, campaigns]);
61
- const getClaimsForLoggedUser = useCallback(async () => {
62
- if (!isInitialized) {
50
+ }, [sdk, isInitialized, isAuthenticated]);
51
+ const getUserClaims = useCallback(async () => {
52
+ if (!isInitialized || !sdk) {
63
53
  throw new Error('SDK not initialized. Call initialize() first.');
64
54
  }
65
55
  if (!isAuthenticated) {
66
- console.warn('SDK not authenticated. getClaimsForLoggedUser requires authentication.');
56
+ console.warn('SDK not authenticated. getUserClaims requires authentication.');
67
57
  return [];
68
58
  }
69
- if (!campaigns?.getClaimsForLoggedUser) {
70
- console.warn('getClaimsForLoggedUser method not available');
71
- return [];
59
+ try {
60
+ const result = await sdk.campaigns.getUserClaims();
61
+ console.log('User claims fetched successfully:', result);
62
+ return result;
63
+ }
64
+ catch (error) {
65
+ console.error('Failed to fetch user claims:', error);
66
+ throw error;
67
+ }
68
+ }, [sdk, isInitialized, isAuthenticated]);
69
+ const getCampaignTriggers = useCallback(async () => {
70
+ if (!isInitialized || !sdk) {
71
+ throw new Error('SDK not initialized. Call initialize() first.');
72
+ }
73
+ try {
74
+ const result = await sdk.campaigns.getCampaignTriggers();
75
+ console.log('Campaign triggers fetched successfully:', result);
76
+ return result;
77
+ }
78
+ catch (error) {
79
+ console.error('Failed to fetch campaign triggers:', error);
80
+ throw error;
81
+ }
82
+ }, [sdk, isInitialized]);
83
+ // Admin methods
84
+ const getAllCampaigns = useCallback(async (active) => {
85
+ if (!isInitialized || !sdk) {
86
+ throw new Error('SDK not initialized. Call initialize() first.');
87
+ }
88
+ try {
89
+ const result = await sdk.campaigns.getAllCampaigns(active);
90
+ console.log('All campaigns fetched successfully:', result);
91
+ return result;
92
+ }
93
+ catch (error) {
94
+ console.error('Failed to fetch all campaigns:', error);
95
+ throw error;
96
+ }
97
+ }, [sdk, isInitialized]);
98
+ const getCampaignClaims = useCallback(async () => {
99
+ if (!isInitialized || !sdk) {
100
+ throw new Error('SDK not initialized. Call initialize() first.');
101
+ }
102
+ try {
103
+ const result = await sdk.campaigns.getCampaignClaims();
104
+ console.log('Campaign claims fetched successfully:', result);
105
+ return result;
106
+ }
107
+ catch (error) {
108
+ console.error('Failed to fetch campaign claims:', error);
109
+ throw error;
110
+ }
111
+ }, [sdk, isInitialized]);
112
+ const getCampaignClaimsByUserId = useCallback(async (userId) => {
113
+ if (!isInitialized || !sdk) {
114
+ throw new Error('SDK not initialized. Call initialize() first.');
115
+ }
116
+ try {
117
+ const result = await sdk.campaigns.getCampaignClaimsByUserId(userId);
118
+ console.log('Campaign claims by user ID fetched successfully:', result);
119
+ return result;
120
+ }
121
+ catch (error) {
122
+ console.error('Failed to fetch campaign claims by user ID:', error);
123
+ throw error;
124
+ }
125
+ }, [sdk, isInitialized]);
126
+ const getCampaignClaimsByBusinessId = useCallback(async (businessId) => {
127
+ if (!isInitialized || !sdk) {
128
+ throw new Error('SDK not initialized. Call initialize() first.');
72
129
  }
73
130
  try {
74
- const result = await campaigns.getClaimsForLoggedUser();
75
- console.log(' User claims fetched successfully:', result);
131
+ const result = await sdk.campaigns.getCampaignClaimsByBusinessId(businessId);
132
+ console.log('Campaign claims by business ID fetched successfully:', result);
76
133
  return result;
77
134
  }
78
135
  catch (error) {
79
- console.error('Failed to fetch user claims:', error);
136
+ console.error('Failed to fetch campaign claims by business ID:', error);
80
137
  throw error;
81
138
  }
82
- }, [isInitialized, isAuthenticated, campaigns]);
139
+ }, [sdk, isInitialized]);
83
140
  return {
84
141
  getActiveCampaigns,
85
142
  getCampaignById,
86
143
  claimCampaign,
87
- getClaimsForLoggedUser,
88
- isAvailable: isInitialized && !!campaigns,
144
+ getUserClaims,
145
+ getCampaignTriggers,
146
+ getAllCampaigns,
147
+ getCampaignClaims,
148
+ getCampaignClaimsByUserId,
149
+ getCampaignClaimsByBusinessId,
150
+ isAvailable: isInitialized && !!sdk?.campaigns,
89
151
  };
90
152
  };
@@ -0,0 +1,33 @@
1
+ import type { DonationTypeDTO } from '@explorins/pers-shared';
2
+ /**
3
+ * React hook for donation operations in the PERS SDK
4
+ *
5
+ * Provides methods for managing donations and donation types within the platform.
6
+ * Supports retrieving available donation categories and types.
7
+ *
8
+ * @returns Donation hook with methods for donation management
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * function DonationsComponent() {
13
+ * const { getDonationTypes } = useDonations();
14
+ *
15
+ * const loadDonationTypes = async () => {
16
+ * try {
17
+ * const types = await getDonationTypes();
18
+ * console.log('Available donation types:', types);
19
+ * } catch (error) {
20
+ * console.error('Failed to load donation types:', error);
21
+ * }
22
+ * };
23
+ *
24
+ * return <button onClick={loadDonationTypes}>Load Donation Types</button>;
25
+ * }
26
+ * ```
27
+ */
28
+ export declare const useDonations: () => {
29
+ getDonationTypes: () => Promise<DonationTypeDTO[]>;
30
+ isAvailable: boolean;
31
+ };
32
+ export type DonationHook = ReturnType<typeof useDonations>;
33
+ //# sourceMappingURL=useDonations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDonations.d.ts","sourceRoot":"","sources":["../../src/hooks/useDonations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,YAAY;4BAgBwB,QAAQ,eAAe,EAAE,CAAC;;CAmB1E,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ /**
4
+ * React hook for donation operations in the PERS SDK
5
+ *
6
+ * Provides methods for managing donations and donation types within the platform.
7
+ * Supports retrieving available donation categories and types.
8
+ *
9
+ * @returns Donation hook with methods for donation management
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * function DonationsComponent() {
14
+ * const { getDonationTypes } = useDonations();
15
+ *
16
+ * const loadDonationTypes = async () => {
17
+ * try {
18
+ * const types = await getDonationTypes();
19
+ * console.log('Available donation types:', types);
20
+ * } catch (error) {
21
+ * console.error('Failed to load donation types:', error);
22
+ * }
23
+ * };
24
+ *
25
+ * return <button onClick={loadDonationTypes}>Load Donation Types</button>;
26
+ * }
27
+ * ```
28
+ */
29
+ export const useDonations = () => {
30
+ const { sdk, isInitialized } = usePersSDK();
31
+ /**
32
+ * Retrieves all available donation types in the system
33
+ *
34
+ * @returns Promise resolving to array of donation types
35
+ * @throws Error if SDK is not initialized
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const { getDonationTypes } = useDonations();
40
+ * const types = await getDonationTypes();
41
+ * console.log('Donation types:', types.map(t => t.name));
42
+ * ```
43
+ */
44
+ const getDonationTypes = useCallback(async () => {
45
+ if (!isInitialized || !sdk) {
46
+ throw new Error('SDK not initialized. Call initialize() first.');
47
+ }
48
+ try {
49
+ const result = await sdk.donations.getDonationTypes();
50
+ console.log('Donation types fetched successfully:', result);
51
+ return result;
52
+ }
53
+ catch (error) {
54
+ console.error('Failed to fetch donation types:', error);
55
+ throw error;
56
+ }
57
+ }, [sdk, isInitialized]);
58
+ return {
59
+ getDonationTypes,
60
+ isAvailable: isInitialized && !!sdk?.donations,
61
+ };
62
+ };
@@ -0,0 +1,50 @@
1
+ import type { SignedUrlRequest, FileUploadEntityType } from '@explorins/pers-sdk';
2
+ /**
3
+ * React hook for file operations in the PERS SDK
4
+ *
5
+ * Provides methods for generating signed URLs for file uploads and downloads,
6
+ * media optimization, and secure file access. Supports various entity types
7
+ * and customizable expiration times.
8
+ *
9
+ * @returns File hook with methods for file management
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * function FileUploadComponent() {
14
+ * const { getSignedPutUrl, getSignedGetUrl, optimizeMedia } = useFiles();
15
+ *
16
+ * const uploadFile = async (entityId: string, file: File) => {
17
+ * try {
18
+ * const uploadUrl = await getSignedPutUrl(
19
+ * entityId,
20
+ * 'profile',
21
+ * 'jpg'
22
+ * );
23
+ *
24
+ * // Upload file to the signed URL
25
+ * await fetch(uploadUrl, {
26
+ * method: 'PUT',
27
+ * body: file
28
+ * });
29
+ *
30
+ * // Get download URL
31
+ * const downloadUrl = await getSignedGetUrl(entityId, 'profile');
32
+ * console.log('File uploaded, download URL:', downloadUrl);
33
+ * } catch (error) {
34
+ * console.error('File upload failed:', error);
35
+ * }
36
+ * };
37
+ *
38
+ * return <input type="file" onChange={(e) => uploadFile('user-123', e.target.files[0])} />;
39
+ * }
40
+ * ```
41
+ */
42
+ export declare const useFiles: () => {
43
+ getSignedPutUrl: (entityId: string, entityType: FileUploadEntityType, fileExtension: string) => Promise<string>;
44
+ getSignedGetUrl: (entityId: string, entityType: FileUploadEntityType, expireSeconds?: number) => Promise<string>;
45
+ getSignedUrl: (request: SignedUrlRequest) => Promise<string>;
46
+ optimizeMedia: (url: string, width?: number, height?: number) => Promise<string>;
47
+ isAvailable: boolean;
48
+ };
49
+ export type FileHook = ReturnType<typeof useFiles>;
50
+ //# sourceMappingURL=useFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFiles.d.ts","sourceRoot":"","sources":["../../src/hooks/useFiles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,oBAAoB,EACrB,MAAM,qBAAqB,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,QAAQ;gCAoBP,MAAM,cACJ,oBAAoB,iBACjB,MAAM,KACpB,QAAQ,MAAM,CAAC;gCAgCN,MAAM,cACJ,oBAAoB,kBAChB,MAAM,KACrB,QAAQ,MAAM,CAAC;4BAe+B,gBAAgB,KAAG,QAAQ,MAAM,CAAC;yBAerC,MAAM,UAAU,MAAM,WAAW,MAAM,KAAG,QAAQ,MAAM,CAAC;;CAsBxG,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC"}