@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
@@ -30,8 +30,11 @@ jest.mock('@explorins/pers-sdk/core', () => {
30
30
  };
31
31
  const MockPersSDK = jest.fn().mockImplementation(() => {
32
32
  const events = createMockEventEmitter();
33
+ let currentLocale = null;
33
34
  mockSdkInstance = {
34
35
  events,
36
+ getLocale: jest.fn(() => currentLocale),
37
+ setLocale: jest.fn((next) => { currentLocale = next ? next.toLowerCase() : null; }),
35
38
  auth: {
36
39
  ensureValidToken: jest.fn().mockResolvedValue(true)
37
40
  },
@@ -119,6 +122,36 @@ describe('PersSDKProvider', () => {
119
122
  expect(PersSDK).toHaveBeenCalledTimes(1);
120
123
  });
121
124
  });
125
+ describe('locale', () => {
126
+ it('exposes a null locale until one is set', async () => {
127
+ let capturedContext = null;
128
+ render(_jsx(PersSDKProvider, { config: { apiProjectKey: 'test-project' }, children: _jsx(TestConsumer, { onContext: (ctx) => { capturedContext = ctx; } }) }));
129
+ await waitFor(() => expect(capturedContext?.isInitialized).toBe(true));
130
+ expect(capturedContext.locale).toBeNull();
131
+ });
132
+ it('passes the configured locale through to the SDK config', async () => {
133
+ const { PersSDK } = require('@explorins/pers-sdk/core');
134
+ render(_jsx(PersSDKProvider, { config: { apiProjectKey: 'test-project', locale: 'auto' }, children: _jsx("div", {}) }));
135
+ await waitFor(() => expect(PersSDK).toHaveBeenCalledTimes(1));
136
+ expect(PersSDK.mock.calls[0][1]).toMatchObject({ locale: 'auto' });
137
+ });
138
+ it('setLocale updates the SDK and the context so consumers re-render', async () => {
139
+ let capturedContext = null;
140
+ render(_jsx(PersSDKProvider, { config: { apiProjectKey: 'test-project' }, children: _jsx(TestConsumer, { onContext: (ctx) => { capturedContext = ctx; } }) }));
141
+ await waitFor(() => expect(capturedContext?.isInitialized).toBe(true));
142
+ act(() => { capturedContext.setLocale('ar-SA'); });
143
+ await waitFor(() => expect(capturedContext?.locale).toBe('ar-sa'));
144
+ expect(mockSdkInstance.setLocale).toHaveBeenCalledWith('ar-SA');
145
+ act(() => { capturedContext.setLocale(null); });
146
+ await waitFor(() => expect(capturedContext?.locale).toBeNull());
147
+ });
148
+ it('setLocale throws before the SDK is initialized', async () => {
149
+ let capturedContext = null;
150
+ render(_jsx(PersSDKProvider, { children: _jsx(TestConsumer, { onContext: (ctx) => { capturedContext = ctx; } }) }));
151
+ await waitFor(() => expect(capturedContext).not.toBeNull());
152
+ expect(() => capturedContext.setLocale('de')).toThrow('SDK not initialized');
153
+ });
154
+ });
122
155
  describe('event handling', () => {
123
156
  it('should set user on session_restored event', async () => {
124
157
  let capturedContext = null;
@@ -1,4 +1,4 @@
1
- import type { BusinessDTO, BusinessTypeDTO, BusinessUpdateRequestDTO, BusinessToggleActiveRequestDTO, PaginatedResponseDTO, BusinessFilterOptions } from '@explorins/pers-sdk';
1
+ import type { BusinessDTO, BusinessCreateRequestDTO, BusinessTypeDTO, BusinessUpdateRequestDTO, BusinessToggleActiveRequestDTO, PaginatedResponseDTO, BusinessFilterOptions } from '@explorins/pers-sdk';
2
2
  export type { BusinessFilterOptions } from '@explorins/pers-sdk';
3
3
  /**
4
4
  * React hook for business operations in the PERS SDK
@@ -41,7 +41,7 @@ export declare const useBusiness: () => {
41
41
  getBusinessById: (businessId: string) => Promise<BusinessDTO | null>;
42
42
  getBusinessByAccount: (accountAddress: string) => Promise<BusinessDTO>;
43
43
  getBusinessesByType: (typeId: string) => Promise<PaginatedResponseDTO<BusinessDTO>>;
44
- createBusiness: (displayName: string) => Promise<BusinessDTO>;
44
+ createBusiness: (dto: BusinessCreateRequestDTO) => Promise<BusinessDTO>;
45
45
  updateBusiness: (businessId: string, businessData: BusinessUpdateRequestDTO) => Promise<BusinessDTO>;
46
46
  toggleBusinessStatus: (businessId: string, toggleData: BusinessToggleActiveRequestDTO) => Promise<BusinessDTO>;
47
47
  isAvailable: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useBusiness.d.ts","sourceRoot":"","sources":["../../src/hooks/useBusiness.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,wBAAwB,EAAE,8BAA8B,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAG/K,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,WAAW;+BAgB4B,QAAQ,qBAAqB,WAAW,CAAC,CAAC;4BA2B7C,QAAQ,qBAAqB,eAAe,CAAC,CAAC;8BAsD1C,qBAAqB,KAAG,QAAQ,qBAAqB,WAAW,CAAC,CAAC;kCAxC9D,MAAM,KAAG,QAAQ,WAAW,GAAG,IAAI,CAAC;2CAsD3B,MAAM,KAAG,QAAQ,WAAW,CAAC;kCActC,MAAM,KAAG,QAAQ,qBAAqB,WAAW,CAAC,CAAC;kCA6BnD,MAAM,KAAG,QAAQ,WAAW,CAAC;iCAc9B,MAAM,gBAAgB,wBAAwB,KAAG,QAAQ,WAAW,CAAC;uCAc/D,MAAM,cAAc,8BAA8B,KAAG,QAAQ,WAAW,CAAC;;CA0BtI,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC"}
1
+ {"version":3,"file":"useBusiness.d.ts","sourceRoot":"","sources":["../../src/hooks/useBusiness.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,wBAAwB,EAAE,eAAe,EAAE,wBAAwB,EAAE,8BAA8B,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGzM,YAAY,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,WAAW;+BAgB4B,QAAQ,qBAAqB,WAAW,CAAC,CAAC;4BA2B7C,QAAQ,qBAAqB,eAAe,CAAC,CAAC;8BAsD1C,qBAAqB,KAAG,QAAQ,qBAAqB,WAAW,CAAC,CAAC;kCAxC9D,MAAM,KAAG,QAAQ,WAAW,GAAG,IAAI,CAAC;2CAsD3B,MAAM,KAAG,QAAQ,WAAW,CAAC;kCActC,MAAM,KAAG,QAAQ,qBAAqB,WAAW,CAAC,CAAC;0BA6B3D,wBAAwB,KAAG,QAAQ,WAAW,CAAC;iCAcxC,MAAM,gBAAgB,wBAAwB,KAAG,QAAQ,WAAW,CAAC;uCAc/D,MAAM,cAAc,8BAA8B,KAAG,QAAQ,WAAW,CAAC;;CA0BtI,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC"}
@@ -181,12 +181,12 @@ export const useBusiness = () => {
181
181
  * console.log('Business created:', business);
182
182
  * ```
183
183
  */
184
- const createBusiness = useCallback(async (displayName) => {
184
+ const createBusiness = useCallback(async (dto) => {
185
185
  if (!isInitialized || !sdk) {
186
186
  throw new Error('SDK not initialized. Call initialize() first.');
187
187
  }
188
188
  try {
189
- const result = await sdk.businesses.createBusiness(displayName);
189
+ const result = await sdk.businesses.createBusiness(dto);
190
190
  return result;
191
191
  }
192
192
  catch (error) {
@@ -5,7 +5,7 @@ import type { TokenMetadata } from '@explorins/pers-sdk';
5
5
  * Automatically handles IPFS URLs by resolving them to HTTPS via tenant's gateway.
6
6
  * Non-IPFS URLs are returned as-is. Handles loading and error states.
7
7
  *
8
- * Uses sdk.tenants for IPFS resolution (lightweight, no Web3 deps).
8
+ * Uses sdk.ipfs for IPFS resolution (lightweight, no Web3 deps).
9
9
  *
10
10
  * @param url - The URL to resolve (can be ipfs://, https://, or undefined)
11
11
  * @returns Object with resolved URL, loading state, and error
@@ -34,7 +34,7 @@ export declare function useResolvedUrl(url: string | undefined | null): {
34
34
  * Handles IPFS resolution automatically and returns parsed metadata
35
35
  * with all nested IPFS URLs already resolved to HTTPS.
36
36
  *
37
- * Uses sdk.tenants for metadata fetching (lightweight, no Web3 deps).
37
+ * Uses sdk.ipfs for metadata fetching (lightweight, no Web3 deps).
38
38
  *
39
39
  * @param metadataUri - The metadata URI to fetch (can be ipfs:// or https://)
40
40
  * @returns Object with metadata, loading state, error, and refresh function
@@ -59,7 +59,7 @@ export declare function useResolvedUrl(url: string | undefined | null): {
59
59
  * ```
60
60
  */
61
61
  export declare function useMetadata(metadataUri: string | undefined | null): {
62
- /** Parsed metadata with resolved IPFS URLs (imageUrl, animationUrl, etc.) */
62
+ /** Parsed metadata with resolved IPFS URLs (imageUrl, animationUrl, etc.), localized for the current locale */
63
63
  metadata: TokenMetadata | null;
64
64
  /** Whether fetch is in progress */
65
65
  isLoading: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"useIPFSUrl.d.ts","sourceRoot":"","sources":["../../src/hooks/useIPFSUrl.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;;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;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE;IAAE,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GAAG,IAAI,GAAG,SAAS;IAIlG,yCAAyC;;IAEzC,kCAAkC;;IAElC,oCAAoC;;IAEpC,qDAAqD;;IAErD,iDAAiD;;IAEjD,wDAAwD;;IAExD,gCAAgC;;EAGnC"}
@@ -6,7 +6,7 @@ import { usePersSDK } from '../providers/PersSDKProvider';
6
6
  * Automatically handles IPFS URLs by resolving them to HTTPS via tenant's gateway.
7
7
  * Non-IPFS URLs are returned as-is. Handles loading and error states.
8
8
  *
9
- * Uses sdk.tenants for IPFS resolution (lightweight, no Web3 deps).
9
+ * Uses sdk.ipfs for IPFS resolution (lightweight, no Web3 deps).
10
10
  *
11
11
  * @param url - The URL to resolve (can be ipfs://, https://, or undefined)
12
12
  * @returns Object with resolved URL, loading state, and error
@@ -38,7 +38,7 @@ export function useResolvedUrl(url) {
38
38
  }
39
39
  setIsLoading(true);
40
40
  setError(null);
41
- sdk.tenants.resolveIpfsUrl(url)
41
+ sdk.ipfs.resolveUrl(url)
42
42
  .then((resolved) => {
43
43
  setResolvedUrl(resolved);
44
44
  })
@@ -65,7 +65,7 @@ export function useResolvedUrl(url) {
65
65
  * Handles IPFS resolution automatically and returns parsed metadata
66
66
  * with all nested IPFS URLs already resolved to HTTPS.
67
67
  *
68
- * Uses sdk.tenants for metadata fetching (lightweight, no Web3 deps).
68
+ * Uses sdk.ipfs for metadata fetching (lightweight, no Web3 deps).
69
69
  *
70
70
  * @param metadataUri - The metadata URI to fetch (can be ipfs:// or https://)
71
71
  * @returns Object with metadata, loading state, error, and refresh function
@@ -90,7 +90,7 @@ export function useResolvedUrl(url) {
90
90
  * ```
91
91
  */
92
92
  export function useMetadata(metadataUri) {
93
- const { sdk, isInitialized } = usePersSDK();
93
+ const { sdk, isInitialized, locale } = usePersSDK();
94
94
  const [metadata, setMetadata] = useState(null);
95
95
  const [isLoading, setIsLoading] = useState(false);
96
96
  const [error, setError] = useState(null);
@@ -102,7 +102,7 @@ export function useMetadata(metadataUri) {
102
102
  setIsLoading(true);
103
103
  setError(null);
104
104
  try {
105
- const result = await sdk.tenants.fetchAndProcessMetadata(metadataUri);
105
+ const result = await sdk.ipfs.fetchMetadata(metadataUri);
106
106
  setMetadata(result);
107
107
  }
108
108
  catch (err) {
@@ -112,12 +112,12 @@ export function useMetadata(metadataUri) {
112
112
  finally {
113
113
  setIsLoading(false);
114
114
  }
115
- }, [metadataUri, isInitialized, sdk]);
115
+ }, [metadataUri, isInitialized, sdk, locale]);
116
116
  useEffect(() => {
117
117
  fetchMetadata();
118
118
  }, [fetchMetadata]);
119
119
  return {
120
- /** Parsed metadata with resolved IPFS URLs (imageUrl, animationUrl, etc.) */
120
+ /** Parsed metadata with resolved IPFS URLs (imageUrl, animationUrl, etc.), localized for the current locale */
121
121
  metadata,
122
122
  /** Whether fetch is in progress */
123
123
  isLoading,
@@ -148,7 +148,7 @@ export const useWeb3 = () => {
148
148
  * Converts an ipfs:// URL to an HTTPS URL using the tenant's configured IPFS gateway.
149
149
  * Non-IPFS URLs are returned unchanged.
150
150
  *
151
- * Note: Uses sdk.tenants for IPFS resolution (chain-agnostic).
151
+ * Note: Uses sdk.ipfs for IPFS resolution (chain-agnostic).
152
152
  *
153
153
  * @param url - IPFS URL to resolve (ipfs://...)
154
154
  * @returns Promise resolving to HTTP gateway URL
@@ -165,7 +165,7 @@ export const useWeb3 = () => {
165
165
  throw new Error('SDK not initialized. Call initialize() first.');
166
166
  }
167
167
  try {
168
- const result = await sdk.tenants.resolveIpfsUrl(url);
168
+ const result = await sdk.ipfs.resolveUrl(url);
169
169
  return result;
170
170
  }
171
171
  catch (error) {
@@ -176,7 +176,7 @@ export const useWeb3 = () => {
176
176
  /**
177
177
  * Fetch and process token metadata from a URI
178
178
  *
179
- * Note: Uses sdk.tenants for metadata fetching (chain-agnostic IPFS).
179
+ * Note: Uses sdk.ipfs for metadata fetching (chain-agnostic IPFS).
180
180
  *
181
181
  * @param tokenUri - Token URI to fetch metadata from
182
182
  * @returns Promise resolving to processed metadata or null
@@ -186,7 +186,7 @@ export const useWeb3 = () => {
186
186
  throw new Error('SDK not initialized. Call initialize() first.');
187
187
  }
188
188
  try {
189
- const result = await sdk.tenants.fetchAndProcessMetadata(tokenUri);
189
+ const result = await sdk.ipfs.fetchMetadata(tokenUri);
190
190
  return result;
191
191
  }
192
192
  catch (error) {