@explorins/pers-sdk-react-native 2.3.7 → 2.3.8

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 (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1266 -1244
  3. package/dist/__tests__/PersSDKProvider.test.js +33 -0
  4. package/dist/hooks/useBusiness.d.ts +2 -2
  5. package/dist/hooks/useBusiness.d.ts.map +1 -1
  6. package/dist/hooks/useBusiness.js +2 -2
  7. package/dist/hooks/useIPFSUrl.d.ts +3 -3
  8. package/dist/hooks/useIPFSUrl.d.ts.map +1 -1
  9. package/dist/hooks/useIPFSUrl.js +7 -7
  10. package/dist/hooks/useWeb3.js +4 -4
  11. package/dist/index.js +2400 -487
  12. package/dist/index.js.map +1 -1
  13. package/dist/providers/PersSDKProvider.d.ts +4 -0
  14. package/dist/providers/PersSDKProvider.d.ts.map +1 -1
  15. package/dist/providers/PersSDKProvider.js +14 -0
  16. package/dist/providers/react-native-http-client.d.ts +2 -0
  17. package/dist/providers/react-native-http-client.d.ts.map +1 -1
  18. package/dist/providers/react-native-http-client.js +5 -2
  19. package/dist/storage/rn-secure-storage.d.ts.map +1 -1
  20. package/dist/storage/rn-secure-storage.js +21 -8
  21. package/package.json +3 -3
  22. package/src/__tests__/PersSDKProvider.test.tsx +484 -420
  23. package/src/__tests__/setup.ts +40 -40
  24. package/src/hooks/index.ts +60 -60
  25. package/src/hooks/useAnalytics.ts +327 -327
  26. package/src/hooks/useAuth.ts +265 -265
  27. package/src/hooks/useBookings.ts +191 -191
  28. package/src/hooks/useBusiness.ts +251 -251
  29. package/src/hooks/useCampaigns.ts +500 -500
  30. package/src/hooks/useDonations.ts +66 -66
  31. package/src/hooks/useEvents.ts +372 -372
  32. package/src/hooks/useFiles.ts +155 -155
  33. package/src/hooks/useIPFSUrl.ts +192 -192
  34. package/src/hooks/usePurchases.ts +65 -65
  35. package/src/hooks/useRedemptions.ts +467 -467
  36. package/src/hooks/useTenants.ts +72 -72
  37. package/src/hooks/useTokenBalances.ts +385 -385
  38. package/src/hooks/useTokens.ts +313 -313
  39. package/src/hooks/useTransactionSigner.ts +611 -611
  40. package/src/hooks/useTransactions.ts +299 -299
  41. package/src/hooks/useTriggerSources.ts +301 -301
  42. package/src/hooks/useUserStatus.ts +61 -61
  43. package/src/hooks/useUsers.ts +167 -167
  44. package/src/hooks/useWeb3.ts +355 -355
  45. package/src/index.ts +777 -777
  46. package/src/polyfills/index.ts +160 -160
  47. package/src/polyfills/web3-polyfills.ts +97 -97
  48. package/src/providers/PersSDKProvider.tsx +393 -374
  49. package/src/providers/react-native-auth-provider.ts +110 -110
  50. package/src/providers/react-native-http-client.ts +150 -145
  51. package/src/providers/rn-dpop-provider.ts +190 -190
  52. package/src/storage/async-storage-token-storage.ts +185 -185
  53. package/src/storage/rn-secure-storage.ts +182 -170
  54. package/src/types/react-native-globals.d.ts +45 -45
  55. package/src/utils/index.ts +8 -8
  56. package/src/utils/platform-detection.ts +86 -86
  57. package/dist/index-CzLxqePZ.js +0 -7717
  58. package/dist/index-CzLxqePZ.js.map +0 -1
@@ -1,156 +1,156 @@
1
- import { useCallback } from 'react';
2
- import { usePersSDK } from '../providers/PersSDKProvider';
3
- import type {
4
- SignedUrlRequest,
5
- FileUploadEntityType
6
- } from '@explorins/pers-sdk';
7
-
8
- /**
9
- * React hook for file operations in the PERS SDK
10
- *
11
- * Provides methods for generating signed URLs for file uploads and downloads,
12
- * media optimization, and secure file access. Supports various entity types
13
- * and customizable expiration times.
14
- *
15
- * @returns File hook with methods for file management
16
- *
17
- * @example
18
- * ```typescript
19
- * function FileUploadComponent() {
20
- * const { getSignedPutUrl, getSignedGetUrl, optimizeMedia } = useFiles();
21
- *
22
- * const uploadFile = async (entityId: string, file: File) => {
23
- * try {
24
- * const uploadUrl = await getSignedPutUrl(
25
- * entityId,
26
- * 'profile',
27
- * 'jpg'
28
- * );
29
- *
30
- * // Upload file to the signed URL
31
- * await fetch(uploadUrl, {
32
- * method: 'PUT',
33
- * body: file
34
- * });
35
- *
36
- * // Get download URL
37
- * const downloadUrl = await getSignedGetUrl(entityId, 'profile');
38
- * console.log('File uploaded, download URL:', downloadUrl);
39
- * } catch (error) {
40
- * console.error('File upload failed:', error);
41
- * }
42
- * };
43
- *
44
- * return <input type="file" onChange={(e) => uploadFile('user-123', e.target.files[0])} />;
45
- * }
46
- * ```
47
- */
48
- export const useFiles = () => {
49
- const { sdk, isInitialized } = usePersSDK();
50
-
51
- /**
52
- * Generates a signed URL for uploading files to cloud storage
53
- *
54
- * @param entityId - Unique identifier of the entity the file belongs to
55
- * @param entityType - Type of entity ('profile', 'business', 'campaign', etc.)
56
- * @param fileExtension - File extension without the dot (e.g., 'jpg', 'png')
57
- * @returns Promise resolving to signed upload URL
58
- * @throws Error if SDK is not initialized
59
- *
60
- * @example
61
- * ```typescript
62
- * const { getSignedPutUrl } = useFiles();
63
- * const uploadUrl = await getSignedPutUrl('user-123', 'profile', 'jpg');
64
- * // Use uploadUrl with PUT request to upload file
65
- * ```
66
- */
67
- const getSignedPutUrl = useCallback(async (
68
- entityId: string,
69
- entityType: FileUploadEntityType,
70
- fileExtension: string
71
- ): Promise<string> => {
72
- if (!isInitialized || !sdk) {
73
- throw new Error('SDK not initialized. Call initialize() first.');
74
- }
75
-
76
- try {
77
- const result = await sdk.files.getSignedPutUrl(entityId, entityType, fileExtension);
78
- return result;
79
- } catch (error) {
80
- console.error('Failed to generate signed put URL:', error);
81
- throw error;
82
- }
83
- }, [sdk, isInitialized]);
84
-
85
- /**
86
- * Generates a signed URL for downloading files from cloud storage
87
- *
88
- * @param entityId - Unique identifier of the entity the file belongs to
89
- * @param entityType - Type of entity ('profile', 'business', 'campaign', etc.)
90
- * @param expireSeconds - Optional expiration time in seconds (default varies by implementation)
91
- * @returns Promise resolving to signed download URL
92
- * @throws Error if SDK is not initialized
93
- *
94
- * @example
95
- * ```typescript
96
- * const { getSignedGetUrl } = useFiles();
97
- * const downloadUrl = await getSignedGetUrl('user-123', 'profile', 3600); // 1 hour expiry
98
- * // Use downloadUrl to display or download the file
99
- * ```
100
- */
101
- const getSignedGetUrl = useCallback(async (
102
- entityId: string,
103
- entityType: FileUploadEntityType,
104
- expireSeconds?: number
105
- ): Promise<string> => {
106
- if (!isInitialized || !sdk) {
107
- throw new Error('SDK not initialized. Call initialize() first.');
108
- }
109
-
110
- try {
111
- const result = await sdk.files.getSignedGetUrl(entityId, entityType, expireSeconds);
112
- return result;
113
- } catch (error) {
114
- console.error('Failed to generate signed get URL:', error);
115
- throw error;
116
- }
117
- }, [sdk, isInitialized]);
118
-
119
- const getSignedUrl = useCallback(async (request: SignedUrlRequest): Promise<string> => {
120
- if (!isInitialized || !sdk) {
121
- throw new Error('SDK not initialized. Call initialize() first.');
122
- }
123
-
124
- try {
125
- const result = await sdk.files.getSignedUrl(request);
126
- return result;
127
- } catch (error) {
128
- console.error('Failed to generate signed URL:', error);
129
- throw error;
130
- }
131
- }, [sdk, isInitialized]);
132
-
133
- const optimizeMedia = useCallback(async (url: string, width?: number, height?: number): Promise<string> => {
134
- if (!isInitialized || !sdk) {
135
- throw new Error('SDK not initialized. Call initialize() first.');
136
- }
137
-
138
- try {
139
- const result = await sdk.files.optimizeMedia(url, width, height);
140
- return result;
141
- } catch (error) {
142
- console.error('Failed to optimize media:', error);
143
- throw error;
144
- }
145
- }, [sdk, isInitialized]);
146
-
147
- return {
148
- getSignedPutUrl,
149
- getSignedGetUrl,
150
- getSignedUrl,
151
- optimizeMedia,
152
- isAvailable: isInitialized && !!sdk?.files,
153
- };
154
- };
155
-
1
+ import { useCallback } from 'react';
2
+ import { usePersSDK } from '../providers/PersSDKProvider';
3
+ import type {
4
+ SignedUrlRequest,
5
+ FileUploadEntityType
6
+ } from '@explorins/pers-sdk';
7
+
8
+ /**
9
+ * React hook for file operations in the PERS SDK
10
+ *
11
+ * Provides methods for generating signed URLs for file uploads and downloads,
12
+ * media optimization, and secure file access. Supports various entity types
13
+ * and customizable expiration times.
14
+ *
15
+ * @returns File hook with methods for file management
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * function FileUploadComponent() {
20
+ * const { getSignedPutUrl, getSignedGetUrl, optimizeMedia } = useFiles();
21
+ *
22
+ * const uploadFile = async (entityId: string, file: File) => {
23
+ * try {
24
+ * const uploadUrl = await getSignedPutUrl(
25
+ * entityId,
26
+ * 'profile',
27
+ * 'jpg'
28
+ * );
29
+ *
30
+ * // Upload file to the signed URL
31
+ * await fetch(uploadUrl, {
32
+ * method: 'PUT',
33
+ * body: file
34
+ * });
35
+ *
36
+ * // Get download URL
37
+ * const downloadUrl = await getSignedGetUrl(entityId, 'profile');
38
+ * console.log('File uploaded, download URL:', downloadUrl);
39
+ * } catch (error) {
40
+ * console.error('File upload failed:', error);
41
+ * }
42
+ * };
43
+ *
44
+ * return <input type="file" onChange={(e) => uploadFile('user-123', e.target.files[0])} />;
45
+ * }
46
+ * ```
47
+ */
48
+ export const useFiles = () => {
49
+ const { sdk, isInitialized } = usePersSDK();
50
+
51
+ /**
52
+ * Generates a signed URL for uploading files to cloud storage
53
+ *
54
+ * @param entityId - Unique identifier of the entity the file belongs to
55
+ * @param entityType - Type of entity ('profile', 'business', 'campaign', etc.)
56
+ * @param fileExtension - File extension without the dot (e.g., 'jpg', 'png')
57
+ * @returns Promise resolving to signed upload URL
58
+ * @throws Error if SDK is not initialized
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const { getSignedPutUrl } = useFiles();
63
+ * const uploadUrl = await getSignedPutUrl('user-123', 'profile', 'jpg');
64
+ * // Use uploadUrl with PUT request to upload file
65
+ * ```
66
+ */
67
+ const getSignedPutUrl = useCallback(async (
68
+ entityId: string,
69
+ entityType: FileUploadEntityType,
70
+ fileExtension: string
71
+ ): Promise<string> => {
72
+ if (!isInitialized || !sdk) {
73
+ throw new Error('SDK not initialized. Call initialize() first.');
74
+ }
75
+
76
+ try {
77
+ const result = await sdk.files.getSignedPutUrl(entityId, entityType, fileExtension);
78
+ return result;
79
+ } catch (error) {
80
+ console.error('Failed to generate signed put URL:', error);
81
+ throw error;
82
+ }
83
+ }, [sdk, isInitialized]);
84
+
85
+ /**
86
+ * Generates a signed URL for downloading files from cloud storage
87
+ *
88
+ * @param entityId - Unique identifier of the entity the file belongs to
89
+ * @param entityType - Type of entity ('profile', 'business', 'campaign', etc.)
90
+ * @param expireSeconds - Optional expiration time in seconds (default varies by implementation)
91
+ * @returns Promise resolving to signed download URL
92
+ * @throws Error if SDK is not initialized
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * const { getSignedGetUrl } = useFiles();
97
+ * const downloadUrl = await getSignedGetUrl('user-123', 'profile', 3600); // 1 hour expiry
98
+ * // Use downloadUrl to display or download the file
99
+ * ```
100
+ */
101
+ const getSignedGetUrl = useCallback(async (
102
+ entityId: string,
103
+ entityType: FileUploadEntityType,
104
+ expireSeconds?: number
105
+ ): Promise<string> => {
106
+ if (!isInitialized || !sdk) {
107
+ throw new Error('SDK not initialized. Call initialize() first.');
108
+ }
109
+
110
+ try {
111
+ const result = await sdk.files.getSignedGetUrl(entityId, entityType, expireSeconds);
112
+ return result;
113
+ } catch (error) {
114
+ console.error('Failed to generate signed get URL:', error);
115
+ throw error;
116
+ }
117
+ }, [sdk, isInitialized]);
118
+
119
+ const getSignedUrl = useCallback(async (request: SignedUrlRequest): Promise<string> => {
120
+ if (!isInitialized || !sdk) {
121
+ throw new Error('SDK not initialized. Call initialize() first.');
122
+ }
123
+
124
+ try {
125
+ const result = await sdk.files.getSignedUrl(request);
126
+ return result;
127
+ } catch (error) {
128
+ console.error('Failed to generate signed URL:', error);
129
+ throw error;
130
+ }
131
+ }, [sdk, isInitialized]);
132
+
133
+ const optimizeMedia = useCallback(async (url: string, width?: number, height?: number): Promise<string> => {
134
+ if (!isInitialized || !sdk) {
135
+ throw new Error('SDK not initialized. Call initialize() first.');
136
+ }
137
+
138
+ try {
139
+ const result = await sdk.files.optimizeMedia(url, width, height);
140
+ return result;
141
+ } catch (error) {
142
+ console.error('Failed to optimize media:', error);
143
+ throw error;
144
+ }
145
+ }, [sdk, isInitialized]);
146
+
147
+ return {
148
+ getSignedPutUrl,
149
+ getSignedGetUrl,
150
+ getSignedUrl,
151
+ optimizeMedia,
152
+ isAvailable: isInitialized && !!sdk?.files,
153
+ };
154
+ };
155
+
156
156
  export type FileHook = ReturnType<typeof useFiles>;