@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,92 +1,47 @@
1
1
  import type { PersAuthProvider } from '@explorins/pers-sdk/core';
2
- /**
3
- * Storage strategy for different types of data
4
- */
5
- export declare enum StorageStrategy {
6
- /** Use AsyncStorage for general app data */
7
- ASYNC_STORAGE = "async_storage",
8
- /** Use Keychain for sensitive tokens (when available) */
9
- KEYCHAIN = "keychain",
10
- /** Use in-memory storage (fallback) */
11
- MEMORY = "memory"
12
- }
13
2
  /**
14
3
  * Configuration options for React Native Auth Provider
15
4
  */
16
5
  export interface ReactNativeAuthConfig {
17
- /** Storage strategy for access tokens */
18
- accessTokenStrategy?: StorageStrategy;
19
- /** Storage strategy for refresh tokens */
20
- refreshTokenStrategy?: StorageStrategy;
6
+ /** Use secure storage (Keychain) for tokens when available */
7
+ useSecureStorage?: boolean;
21
8
  /** Custom key prefix for storage */
22
9
  keyPrefix?: string;
23
10
  /** Enable debug logging */
24
11
  debug?: boolean;
25
12
  }
26
13
  /**
27
- * Base React Native Authentication Provider
28
- *
29
- * This serves as a blueprint for native implementations and can be extended
30
- * by consuming applications to integrate with their specific auth systems.
14
+ * React Native Authentication Provider
31
15
  *
32
- * Features:
33
- * - Multiple storage strategies (AsyncStorage, Keychain, Memory)
34
- * - Configurable security levels per token type
35
- * - Cross-platform compatibility (iOS/Android/Web)
36
- * - Blueprint for native iOS/Android implementations
16
+ * Simple, unified implementation for React Native apps with:
17
+ * - AsyncStorage for basic token storage
18
+ * - Keychain integration for secure storage (when available)
19
+ * - Automatic fallback to AsyncStorage if Keychain is unavailable
20
+ * - Cross-platform compatibility (iOS/Android/Expo)
37
21
  */
38
- export declare abstract class BaseReactNativeAuthProvider implements PersAuthProvider {
39
- abstract readonly authType: 'admin' | 'user';
40
- abstract getProjectKey(): Promise<string | null>;
41
- abstract onTokenExpired(): Promise<void>;
42
- protected readonly config: Required<ReactNativeAuthConfig>;
43
- protected readonly ACCESS_TOKEN_KEY: string;
44
- protected readonly REFRESH_TOKEN_KEY: string;
45
- protected readonly PROJECT_KEY_KEY: string;
22
+ export declare class ReactNativeAuthProvider implements PersAuthProvider {
23
+ readonly authType: 'user';
24
+ private readonly config;
25
+ private readonly ACCESS_TOKEN_KEY;
26
+ private readonly REFRESH_TOKEN_KEY;
27
+ private readonly projectKey;
46
28
  private memoryStorage;
47
29
  constructor(projectKey: string, config?: ReactNativeAuthConfig);
30
+ getProjectKey(): Promise<string | null>;
48
31
  getToken(): Promise<string | null>;
49
32
  setAccessToken(token: string): Promise<void>;
50
33
  setRefreshToken(token: string): Promise<void>;
51
34
  getRefreshToken(): Promise<string | null>;
52
35
  clearTokens(): Promise<void>;
36
+ onTokenExpired(): Promise<void>;
53
37
  hasValidToken(): boolean;
54
38
  hasRefreshToken(): boolean;
55
- hasValidTokenAsync(): Promise<boolean>;
56
- hasRefreshTokenAsync(): Promise<boolean>;
57
- setToken(token: string): void;
58
- clearToken(): void;
59
- protected storeValue(key: string, value: string, strategy: StorageStrategy): Promise<void>;
60
- protected getStoredValue(key: string, strategy: StorageStrategy): Promise<string | null>;
61
- protected removeStoredValue(key: string, strategy: StorageStrategy): Promise<void>;
39
+ private storeValue;
40
+ private getStoredValue;
41
+ private removeStoredValue;
62
42
  private isKeychainAvailable;
63
43
  private storeInKeychain;
64
44
  private getFromKeychain;
65
45
  private removeFromKeychain;
66
46
  }
67
- /**
68
- * React Native Authentication Provider
69
- *
70
- * A ready-to-use implementation for basic use cases.
71
- * Uses AsyncStorage for access tokens and Keychain for refresh tokens (when available).
72
- */
73
- export declare class ReactNativeAuthProvider extends BaseReactNativeAuthProvider {
74
- private projectKey;
75
- readonly authType: 'user';
76
- constructor(projectKey: string, config?: ReactNativeAuthConfig);
77
- getProjectKey(): Promise<string | null>;
78
- onTokenExpired(): Promise<void>;
79
- }
80
- /**
81
- * Secure React Native Authentication Provider
82
- *
83
- * Maximum security implementation using Keychain for all sensitive data.
84
- */
85
- export declare class SecureReactNativeAuthProvider extends BaseReactNativeAuthProvider {
86
- private projectKey;
87
- readonly authType: 'user';
88
- constructor(projectKey: string, config?: Omit<ReactNativeAuthConfig, 'accessTokenStrategy' | 'refreshTokenStrategy'>);
89
- getProjectKey(): Promise<string | null>;
90
- onTokenExpired(): Promise<void>;
91
- }
92
47
  //# sourceMappingURL=react-native-auth-provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-native-auth-provider.d.ts","sourceRoot":"","sources":["../../src/providers/react-native-auth-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAGjE;;GAEG;AACH,oBAAY,eAAe;IACzB,4CAA4C;IAC5C,aAAa,kBAAkB;IAC/B,yDAAyD;IACzD,QAAQ,aAAa;IACrB,uCAAuC;IACvC,MAAM,WAAW;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,yCAAyC;IACzC,mBAAmB,CAAC,EAAE,eAAe,CAAC;IACtC,0CAA0C;IAC1C,oBAAoB,CAAC,EAAE,eAAe,CAAC;IACvC,oCAAoC;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;G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wB,YAAW,gBAAgB;IAC9D,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAU;IAEnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IAGpC,OAAO,CAAC,aAAa,CAAkC;gBAGrD,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,qBAA0B;IA4B9B,aAAa,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIvC,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIlC,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5C,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7C,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAIzC,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAW5B,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IASrC,aAAa,IAAI,OAAO;IAIxB,eAAe,IAAI,OAAO;YAKZ,UAAU;YAcV,cAAc;YAcd,iBAAiB;YAgBjB,mBAAmB;YASnB,eAAe;YAKf,eAAe;YAMf,kBAAkB;CAIjC"}
@@ -1,40 +1,25 @@
1
1
  import AsyncStorage from '@react-native-async-storage/async-storage';
2
2
  /**
3
- * Storage strategy for different types of data
4
- */
5
- export var StorageStrategy;
6
- (function (StorageStrategy) {
7
- /** Use AsyncStorage for general app data */
8
- StorageStrategy["ASYNC_STORAGE"] = "async_storage";
9
- /** Use Keychain for sensitive tokens (when available) */
10
- StorageStrategy["KEYCHAIN"] = "keychain";
11
- /** Use in-memory storage (fallback) */
12
- StorageStrategy["MEMORY"] = "memory";
13
- })(StorageStrategy || (StorageStrategy = {}));
14
- /**
15
- * Base React Native Authentication Provider
16
- *
17
- * This serves as a blueprint for native implementations and can be extended
18
- * by consuming applications to integrate with their specific auth systems.
3
+ * React Native Authentication Provider
19
4
  *
20
- * Features:
21
- * - Multiple storage strategies (AsyncStorage, Keychain, Memory)
22
- * - Configurable security levels per token type
23
- * - Cross-platform compatibility (iOS/Android/Web)
24
- * - Blueprint for native iOS/Android implementations
5
+ * Simple, unified implementation for React Native apps with:
6
+ * - AsyncStorage for basic token storage
7
+ * - Keychain integration for secure storage (when available)
8
+ * - Automatic fallback to AsyncStorage if Keychain is unavailable
9
+ * - Cross-platform compatibility (iOS/Android/Expo)
25
10
  */
26
- export class BaseReactNativeAuthProvider {
11
+ export class ReactNativeAuthProvider {
27
12
  constructor(projectKey, config = {}) {
13
+ this.authType = 'user';
28
14
  // In-memory fallback storage
29
15
  this.memoryStorage = new Map();
30
- // Validate projectKey
31
16
  if (!projectKey || typeof projectKey !== 'string') {
32
17
  throw new Error('ReactNativeAuthProvider: projectKey is required and must be a string');
33
18
  }
19
+ this.projectKey = projectKey;
34
20
  // Set default configuration
35
21
  this.config = {
36
- accessTokenStrategy: StorageStrategy.ASYNC_STORAGE,
37
- refreshTokenStrategy: StorageStrategy.KEYCHAIN,
22
+ useSecureStorage: true, // Default to secure storage when available
38
23
  keyPrefix: `pers_${projectKey.slice(0, 8)}`,
39
24
  debug: false,
40
25
  ...config
@@ -42,151 +27,106 @@ export class BaseReactNativeAuthProvider {
42
27
  // Create storage keys
43
28
  this.ACCESS_TOKEN_KEY = `${this.config.keyPrefix}_access_token`;
44
29
  this.REFRESH_TOKEN_KEY = `${this.config.keyPrefix}_refresh_token`;
45
- this.PROJECT_KEY_KEY = `${this.config.keyPrefix}_project_key`;
46
30
  if (this.config.debug) {
47
- console.log('🔧 ReactNativeAuthProvider initialized with config:', this.config);
31
+ console.log('ReactNativeAuthProvider initialized:', {
32
+ projectKey: projectKey.slice(0, 8) + '...',
33
+ useSecureStorage: this.config.useSecureStorage
34
+ });
48
35
  }
49
36
  }
50
- // Core token management methods
37
+ async getProjectKey() {
38
+ return this.projectKey;
39
+ }
51
40
  async getToken() {
52
- return this.getStoredValue(this.ACCESS_TOKEN_KEY, this.config.accessTokenStrategy);
41
+ return this.getStoredValue(this.ACCESS_TOKEN_KEY);
53
42
  }
54
43
  async setAccessToken(token) {
55
- await this.storeValue(this.ACCESS_TOKEN_KEY, token, this.config.accessTokenStrategy);
44
+ await this.storeValue(this.ACCESS_TOKEN_KEY, token);
56
45
  if (this.config.debug) {
57
- console.log('Access token stored securely');
46
+ console.log('Access token stored securely');
58
47
  }
59
48
  }
60
49
  async setRefreshToken(token) {
61
- await this.storeValue(this.REFRESH_TOKEN_KEY, token, this.config.refreshTokenStrategy);
50
+ await this.storeValue(this.REFRESH_TOKEN_KEY, token);
62
51
  if (this.config.debug) {
63
- console.log('Refresh token stored securely');
52
+ console.log('Refresh token stored securely');
64
53
  }
65
54
  }
66
55
  async getRefreshToken() {
67
- return this.getStoredValue(this.REFRESH_TOKEN_KEY, this.config.refreshTokenStrategy);
56
+ return this.getStoredValue(this.REFRESH_TOKEN_KEY);
68
57
  }
69
58
  async clearTokens() {
70
59
  await Promise.all([
71
- this.removeStoredValue(this.ACCESS_TOKEN_KEY, this.config.accessTokenStrategy),
72
- this.removeStoredValue(this.REFRESH_TOKEN_KEY, this.config.refreshTokenStrategy)
60
+ this.removeStoredValue(this.ACCESS_TOKEN_KEY),
61
+ this.removeStoredValue(this.REFRESH_TOKEN_KEY)
73
62
  ]);
74
63
  if (this.config.debug) {
75
- console.log('All tokens cleared from storage');
64
+ console.log('All tokens cleared from storage');
76
65
  }
77
66
  }
67
+ async onTokenExpired() {
68
+ if (this.config.debug) {
69
+ console.warn('ReactNativeAuthProvider: Token expired - implement refresh logic in your app');
70
+ }
71
+ // Clear expired tokens
72
+ await this.clearTokens();
73
+ }
78
74
  // Token validation methods
79
75
  hasValidToken() {
80
- // Synchronous check - for async check use hasValidTokenAsync()
81
76
  return true; // Actual validation happens in getToken()
82
77
  }
83
78
  hasRefreshToken() {
84
- // Synchronous check - for async check use hasRefreshTokenAsync()
85
79
  return true; // Actual validation happens in getRefreshToken()
86
80
  }
87
- // Async token validation methods
88
- async hasValidTokenAsync() {
89
- const token = await this.getToken();
90
- return !!token;
91
- }
92
- async hasRefreshTokenAsync() {
93
- const refreshToken = await this.getRefreshToken();
94
- return !!refreshToken;
95
- }
96
- // Legacy methods for backward compatibility
97
- setToken(token) {
98
- this.setAccessToken(token).catch(error => {
99
- console.error('Legacy setToken failed:', error);
100
- });
101
- }
102
- clearToken() {
103
- this.clearTokens().catch(error => {
104
- console.error('Legacy clearToken failed:', error);
105
- });
106
- }
107
- // Protected storage implementation methods
108
- async storeValue(key, value, strategy) {
81
+ // Storage implementation methods
82
+ async storeValue(key, value) {
109
83
  try {
110
- switch (strategy) {
111
- case StorageStrategy.KEYCHAIN:
112
- // Try Keychain first, fallback to AsyncStorage
113
- if (await this.isKeychainAvailable()) {
114
- await this.storeInKeychain(key, value);
115
- }
116
- else {
117
- await AsyncStorage.setItem(key, value);
118
- }
119
- break;
120
- case StorageStrategy.ASYNC_STORAGE:
121
- await AsyncStorage.setItem(key, value);
122
- break;
123
- case StorageStrategy.MEMORY:
124
- default:
125
- this.memoryStorage.set(key, value);
126
- break;
84
+ if (this.config.useSecureStorage && await this.isKeychainAvailable()) {
85
+ await this.storeInKeychain(key, value);
86
+ }
87
+ else {
88
+ await AsyncStorage.setItem(key, value);
127
89
  }
128
90
  }
129
91
  catch (error) {
130
- console.error(`Failed to store value with strategy ${strategy}:`, error);
92
+ console.error(`Failed to store value for key ${key}:`, error);
131
93
  // Fallback to memory storage
132
94
  this.memoryStorage.set(key, value);
133
95
  }
134
96
  }
135
- async getStoredValue(key, strategy) {
97
+ async getStoredValue(key) {
136
98
  try {
137
- switch (strategy) {
138
- case StorageStrategy.KEYCHAIN:
139
- // Try Keychain first, fallback to AsyncStorage
140
- if (await this.isKeychainAvailable()) {
141
- return await this.getFromKeychain(key);
142
- }
143
- else {
144
- return await AsyncStorage.getItem(key);
145
- }
146
- case StorageStrategy.ASYNC_STORAGE:
147
- return await AsyncStorage.getItem(key);
148
- case StorageStrategy.MEMORY:
149
- default:
150
- return this.memoryStorage.get(key) || null;
99
+ if (this.config.useSecureStorage && await this.isKeychainAvailable()) {
100
+ return await this.getFromKeychain(key);
101
+ }
102
+ else {
103
+ return await AsyncStorage.getItem(key);
151
104
  }
152
105
  }
153
106
  catch (error) {
154
- console.warn(`Failed to get value with strategy ${strategy}:`, error);
107
+ console.warn(`Failed to get value for key ${key}:`, error);
155
108
  // Fallback to memory storage
156
109
  return this.memoryStorage.get(key) || null;
157
110
  }
158
111
  }
159
- async removeStoredValue(key, strategy) {
112
+ async removeStoredValue(key) {
160
113
  try {
161
- switch (strategy) {
162
- case StorageStrategy.KEYCHAIN:
163
- // Try Keychain first, fallback to AsyncStorage
164
- if (await this.isKeychainAvailable()) {
165
- await this.removeFromKeychain(key);
166
- }
167
- else {
168
- await AsyncStorage.removeItem(key);
169
- }
170
- break;
171
- case StorageStrategy.ASYNC_STORAGE:
172
- await AsyncStorage.removeItem(key);
173
- break;
174
- case StorageStrategy.MEMORY:
175
- default:
176
- this.memoryStorage.delete(key);
177
- break;
114
+ if (this.config.useSecureStorage && await this.isKeychainAvailable()) {
115
+ await this.removeFromKeychain(key);
116
+ }
117
+ else {
118
+ await AsyncStorage.removeItem(key);
178
119
  }
179
120
  }
180
121
  catch (error) {
181
- console.error(`Failed to remove value with strategy ${strategy}:`, error);
182
- // Ensure memory fallback is also cleared
183
- this.memoryStorage.delete(key);
122
+ console.error(`Failed to remove value for key ${key}:`, error);
184
123
  }
124
+ // Ensure memory fallback is also cleared
125
+ this.memoryStorage.delete(key);
185
126
  }
186
127
  // Keychain helper methods
187
128
  async isKeychainAvailable() {
188
129
  try {
189
- // Check if react-native-keychain is available
190
130
  const Keychain = require('react-native-keychain');
191
131
  return !!Keychain && typeof Keychain.setInternetCredentials === 'function';
192
132
  }
@@ -208,61 +148,3 @@ export class BaseReactNativeAuthProvider {
208
148
  await Keychain.resetInternetCredentials(key);
209
149
  }
210
150
  }
211
- /**
212
- * React Native Authentication Provider
213
- *
214
- * A ready-to-use implementation for basic use cases.
215
- * Uses AsyncStorage for access tokens and Keychain for refresh tokens (when available).
216
- */
217
- export class ReactNativeAuthProvider extends BaseReactNativeAuthProvider {
218
- constructor(projectKey, config = {}) {
219
- // Validate projectKey
220
- if (!projectKey || typeof projectKey !== 'string') {
221
- throw new Error('ReactNativeAuthProvider: projectKey is required and must be a string');
222
- }
223
- super(projectKey, {
224
- accessTokenStrategy: StorageStrategy.ASYNC_STORAGE,
225
- refreshTokenStrategy: StorageStrategy.KEYCHAIN,
226
- debug: false,
227
- ...config
228
- });
229
- this.projectKey = projectKey;
230
- this.authType = 'user';
231
- }
232
- async getProjectKey() {
233
- return this.projectKey;
234
- }
235
- async onTokenExpired() {
236
- if (this.config.debug) {
237
- console.warn('ReactNativeAuthProvider: Token expired - no refresh logic implemented');
238
- }
239
- }
240
- }
241
- /**
242
- * Secure React Native Authentication Provider
243
- *
244
- * Maximum security implementation using Keychain for all sensitive data.
245
- */
246
- export class SecureReactNativeAuthProvider extends BaseReactNativeAuthProvider {
247
- constructor(projectKey, config = {}) {
248
- // Validate projectKey
249
- if (!projectKey || typeof projectKey !== 'string') {
250
- throw new Error('SecureReactNativeAuthProvider: projectKey is required and must be a string');
251
- }
252
- super(projectKey, {
253
- ...config,
254
- accessTokenStrategy: StorageStrategy.KEYCHAIN,
255
- refreshTokenStrategy: StorageStrategy.KEYCHAIN,
256
- });
257
- this.projectKey = projectKey;
258
- this.authType = 'user';
259
- }
260
- async getProjectKey() {
261
- return this.projectKey;
262
- }
263
- async onTokenExpired() {
264
- if (this.config.debug) {
265
- console.warn('SecureReactNativeAuthProvider: Token expired - implement refresh logic');
266
- }
267
- }
268
- }