@savers_app/react-native-sandbox-sdk 1.2.6

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 (212) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +556 -0
  3. package/lib/module/@types/@react-native-async-storage__async-storage.d.js +2 -0
  4. package/lib/module/@types/@react-native-async-storage__async-storage.d.js.map +1 -0
  5. package/lib/module/@types/@react-native-community__geolocation.d.js +2 -0
  6. package/lib/module/@types/@react-native-community__geolocation.d.js.map +1 -0
  7. package/lib/module/@types/react-native-aes-gcm-crypto.d.js +2 -0
  8. package/lib/module/@types/react-native-aes-gcm-crypto.d.js.map +1 -0
  9. package/lib/module/@types/react-native-device-info.d.js +2 -0
  10. package/lib/module/@types/react-native-device-info.d.js.map +1 -0
  11. package/lib/module/core/runtime.js +70 -0
  12. package/lib/module/core/runtime.js.map +1 -0
  13. package/lib/module/data/models/apiResponse.js +19 -0
  14. package/lib/module/data/models/apiResponse.js.map +1 -0
  15. package/lib/module/data/models/onboardingModel.js +67 -0
  16. package/lib/module/data/models/onboardingModel.js.map +1 -0
  17. package/lib/module/data/models/tokenModel.js +25 -0
  18. package/lib/module/data/models/tokenModel.js.map +1 -0
  19. package/lib/module/data/network/apiClient.js +109 -0
  20. package/lib/module/data/network/apiClient.js.map +1 -0
  21. package/lib/module/data/network/apiEndpoints.js +7 -0
  22. package/lib/module/data/network/apiEndpoints.js.map +1 -0
  23. package/lib/module/data/network/apiExceptionHandler.js +16 -0
  24. package/lib/module/data/network/apiExceptionHandler.js.map +1 -0
  25. package/lib/module/data/network/apiRepository.js +84 -0
  26. package/lib/module/data/network/apiRepository.js.map +1 -0
  27. package/lib/module/data/network/apiService.js +102 -0
  28. package/lib/module/data/network/apiService.js.map +1 -0
  29. package/lib/module/data/network/dataTypeUtils.js +77 -0
  30. package/lib/module/data/network/dataTypeUtils.js.map +1 -0
  31. package/lib/module/data/network/interceptors/authInterceptor.js +72 -0
  32. package/lib/module/data/network/interceptors/authInterceptor.js.map +1 -0
  33. package/lib/module/data/network/interceptors/errorInterceptor.js +15 -0
  34. package/lib/module/data/network/interceptors/errorInterceptor.js.map +1 -0
  35. package/lib/module/data/network/interceptors/loggingInterceptor.js +17 -0
  36. package/lib/module/data/network/interceptors/loggingInterceptor.js.map +1 -0
  37. package/lib/module/data/network/interceptors/networkInterceptor.js +22 -0
  38. package/lib/module/data/network/interceptors/networkInterceptor.js.map +1 -0
  39. package/lib/module/data/network/interceptors/retryInterceptor.js +22 -0
  40. package/lib/module/data/network/interceptors/retryInterceptor.js.map +1 -0
  41. package/lib/module/data/storage/asyncStorageManager.js +50 -0
  42. package/lib/module/data/storage/asyncStorageManager.js.map +1 -0
  43. package/lib/module/data/storage/deviceIdManager.js +45 -0
  44. package/lib/module/data/storage/deviceIdManager.js.map +1 -0
  45. package/lib/module/data/storage/keysManager.js +70 -0
  46. package/lib/module/data/storage/keysManager.js.map +1 -0
  47. package/lib/module/data/storage/locationManager.js +30 -0
  48. package/lib/module/data/storage/locationManager.js.map +1 -0
  49. package/lib/module/data/storage/reactRefManager.js +22 -0
  50. package/lib/module/data/storage/reactRefManager.js.map +1 -0
  51. package/lib/module/data/storage/sessionManager.js +12 -0
  52. package/lib/module/data/storage/sessionManager.js.map +1 -0
  53. package/lib/module/data/storage/storageKeys.js +7 -0
  54. package/lib/module/data/storage/storageKeys.js.map +1 -0
  55. package/lib/module/data/storage/storageManager.js +76 -0
  56. package/lib/module/data/storage/storageManager.js.map +1 -0
  57. package/lib/module/index.js +20 -0
  58. package/lib/module/index.js.map +1 -0
  59. package/lib/module/package.json +1 -0
  60. package/lib/module/services/device/location.js +47 -0
  61. package/lib/module/services/device/location.js.map +1 -0
  62. package/lib/module/services/navigation/dialPad.js +29 -0
  63. package/lib/module/services/navigation/dialPad.js.map +1 -0
  64. package/lib/module/services/navigation/goBackNavigation.js +19 -0
  65. package/lib/module/services/navigation/goBackNavigation.js.map +1 -0
  66. package/lib/module/services/navigation/openBrowser.js +8 -0
  67. package/lib/module/services/navigation/openBrowser.js.map +1 -0
  68. package/lib/module/services/navigation/openMap.js +42 -0
  69. package/lib/module/services/navigation/openMap.js.map +1 -0
  70. package/lib/module/services/permissions/permissionManager.js +28 -0
  71. package/lib/module/services/permissions/permissionManager.js.map +1 -0
  72. package/lib/module/services/url/urlGenerator.js +94 -0
  73. package/lib/module/services/url/urlGenerator.js.map +1 -0
  74. package/lib/module/services/webview/messageHandler.js +72 -0
  75. package/lib/module/services/webview/messageHandler.js.map +1 -0
  76. package/lib/module/utils/config.js +34 -0
  77. package/lib/module/utils/config.js.map +1 -0
  78. package/lib/module/utils/dependencyManager.js +51 -0
  79. package/lib/module/utils/dependencyManager.js.map +1 -0
  80. package/lib/module/utils/encryption.js +63 -0
  81. package/lib/module/utils/encryption.js.map +1 -0
  82. package/lib/module/utils/errors.js +9 -0
  83. package/lib/module/utils/errors.js.map +1 -0
  84. package/lib/module/utils/logger.js +14 -0
  85. package/lib/module/utils/logger.js.map +1 -0
  86. package/lib/module/utils/platformManager.js +14 -0
  87. package/lib/module/utils/platformManager.js.map +1 -0
  88. package/lib/module/utils/validator.js +26 -0
  89. package/lib/module/utils/validator.js.map +1 -0
  90. package/lib/typescript/package.json +1 -0
  91. package/lib/typescript/src/core/runtime.d.ts +11 -0
  92. package/lib/typescript/src/core/runtime.d.ts.map +1 -0
  93. package/lib/typescript/src/data/models/apiResponse.d.ts +9 -0
  94. package/lib/typescript/src/data/models/apiResponse.d.ts.map +1 -0
  95. package/lib/typescript/src/data/models/onboardingModel.d.ts +24 -0
  96. package/lib/typescript/src/data/models/onboardingModel.d.ts.map +1 -0
  97. package/lib/typescript/src/data/models/tokenModel.d.ts +15 -0
  98. package/lib/typescript/src/data/models/tokenModel.d.ts.map +1 -0
  99. package/lib/typescript/src/data/network/apiClient.d.ts +17 -0
  100. package/lib/typescript/src/data/network/apiClient.d.ts.map +1 -0
  101. package/lib/typescript/src/data/network/apiEndpoints.d.ts +5 -0
  102. package/lib/typescript/src/data/network/apiEndpoints.d.ts.map +1 -0
  103. package/lib/typescript/src/data/network/apiExceptionHandler.d.ts +3 -0
  104. package/lib/typescript/src/data/network/apiExceptionHandler.d.ts.map +1 -0
  105. package/lib/typescript/src/data/network/apiRepository.d.ts +21 -0
  106. package/lib/typescript/src/data/network/apiRepository.d.ts.map +1 -0
  107. package/lib/typescript/src/data/network/apiService.d.ts +25 -0
  108. package/lib/typescript/src/data/network/apiService.d.ts.map +1 -0
  109. package/lib/typescript/src/data/network/dataTypeUtils.d.ts +10 -0
  110. package/lib/typescript/src/data/network/dataTypeUtils.d.ts.map +1 -0
  111. package/lib/typescript/src/data/network/interceptors/authInterceptor.d.ts +15 -0
  112. package/lib/typescript/src/data/network/interceptors/authInterceptor.d.ts.map +1 -0
  113. package/lib/typescript/src/data/network/interceptors/errorInterceptor.d.ts +4 -0
  114. package/lib/typescript/src/data/network/interceptors/errorInterceptor.d.ts.map +1 -0
  115. package/lib/typescript/src/data/network/interceptors/loggingInterceptor.d.ts +5 -0
  116. package/lib/typescript/src/data/network/interceptors/loggingInterceptor.d.ts.map +1 -0
  117. package/lib/typescript/src/data/network/interceptors/networkInterceptor.d.ts +4 -0
  118. package/lib/typescript/src/data/network/interceptors/networkInterceptor.d.ts.map +1 -0
  119. package/lib/typescript/src/data/network/interceptors/retryInterceptor.d.ts +7 -0
  120. package/lib/typescript/src/data/network/interceptors/retryInterceptor.d.ts.map +1 -0
  121. package/lib/typescript/src/data/storage/asyncStorageManager.d.ts +13 -0
  122. package/lib/typescript/src/data/storage/asyncStorageManager.d.ts.map +1 -0
  123. package/lib/typescript/src/data/storage/deviceIdManager.d.ts +2 -0
  124. package/lib/typescript/src/data/storage/deviceIdManager.d.ts.map +1 -0
  125. package/lib/typescript/src/data/storage/keysManager.d.ts +29 -0
  126. package/lib/typescript/src/data/storage/keysManager.d.ts.map +1 -0
  127. package/lib/typescript/src/data/storage/locationManager.d.ts +21 -0
  128. package/lib/typescript/src/data/storage/locationManager.d.ts.map +1 -0
  129. package/lib/typescript/src/data/storage/reactRefManager.d.ts +11 -0
  130. package/lib/typescript/src/data/storage/reactRefManager.d.ts.map +1 -0
  131. package/lib/typescript/src/data/storage/sessionManager.d.ts +3 -0
  132. package/lib/typescript/src/data/storage/sessionManager.d.ts.map +1 -0
  133. package/lib/typescript/src/data/storage/storageKeys.d.ts +5 -0
  134. package/lib/typescript/src/data/storage/storageKeys.d.ts.map +1 -0
  135. package/lib/typescript/src/data/storage/storageManager.d.ts +16 -0
  136. package/lib/typescript/src/data/storage/storageManager.d.ts.map +1 -0
  137. package/lib/typescript/src/index.d.ts +18 -0
  138. package/lib/typescript/src/index.d.ts.map +1 -0
  139. package/lib/typescript/src/services/device/location.d.ts +8 -0
  140. package/lib/typescript/src/services/device/location.d.ts.map +1 -0
  141. package/lib/typescript/src/services/navigation/dialPad.d.ts +3 -0
  142. package/lib/typescript/src/services/navigation/dialPad.d.ts.map +1 -0
  143. package/lib/typescript/src/services/navigation/goBackNavigation.d.ts +3 -0
  144. package/lib/typescript/src/services/navigation/goBackNavigation.d.ts.map +1 -0
  145. package/lib/typescript/src/services/navigation/openBrowser.d.ts +2 -0
  146. package/lib/typescript/src/services/navigation/openBrowser.d.ts.map +1 -0
  147. package/lib/typescript/src/services/navigation/openMap.d.ts +2 -0
  148. package/lib/typescript/src/services/navigation/openMap.d.ts.map +1 -0
  149. package/lib/typescript/src/services/permissions/permissionManager.d.ts +4 -0
  150. package/lib/typescript/src/services/permissions/permissionManager.d.ts.map +1 -0
  151. package/lib/typescript/src/services/url/urlGenerator.d.ts +44 -0
  152. package/lib/typescript/src/services/url/urlGenerator.d.ts.map +1 -0
  153. package/lib/typescript/src/services/webview/messageHandler.d.ts +2 -0
  154. package/lib/typescript/src/services/webview/messageHandler.d.ts.map +1 -0
  155. package/lib/typescript/src/utils/config.d.ts +5 -0
  156. package/lib/typescript/src/utils/config.d.ts.map +1 -0
  157. package/lib/typescript/src/utils/dependencyManager.d.ts +31 -0
  158. package/lib/typescript/src/utils/dependencyManager.d.ts.map +1 -0
  159. package/lib/typescript/src/utils/encryption.d.ts +5 -0
  160. package/lib/typescript/src/utils/encryption.d.ts.map +1 -0
  161. package/lib/typescript/src/utils/errors.d.ts +4 -0
  162. package/lib/typescript/src/utils/errors.d.ts.map +1 -0
  163. package/lib/typescript/src/utils/logger.d.ts +6 -0
  164. package/lib/typescript/src/utils/logger.d.ts.map +1 -0
  165. package/lib/typescript/src/utils/platformManager.d.ts +4 -0
  166. package/lib/typescript/src/utils/platformManager.d.ts.map +1 -0
  167. package/lib/typescript/src/utils/validator.d.ts +4 -0
  168. package/lib/typescript/src/utils/validator.d.ts.map +1 -0
  169. package/package.json +184 -0
  170. package/src/@types/@react-native-async-storage__async-storage.d.ts +7 -0
  171. package/src/@types/@react-native-community__geolocation.d.ts +18 -0
  172. package/src/@types/react-native-aes-gcm-crypto.d.ts +22 -0
  173. package/src/@types/react-native-device-info.d.ts +3 -0
  174. package/src/core/runtime.ts +84 -0
  175. package/src/data/models/apiResponse.ts +28 -0
  176. package/src/data/models/onboardingModel.ts +97 -0
  177. package/src/data/models/tokenModel.ts +43 -0
  178. package/src/data/network/apiClient.ts +148 -0
  179. package/src/data/network/apiEndpoints.ts +4 -0
  180. package/src/data/network/apiExceptionHandler.ts +16 -0
  181. package/src/data/network/apiRepository.ts +130 -0
  182. package/src/data/network/apiService.ts +113 -0
  183. package/src/data/network/dataTypeUtils.ts +78 -0
  184. package/src/data/network/interceptors/authInterceptor.ts +86 -0
  185. package/src/data/network/interceptors/errorInterceptor.ts +13 -0
  186. package/src/data/network/interceptors/loggingInterceptor.ts +16 -0
  187. package/src/data/network/interceptors/networkInterceptor.ts +20 -0
  188. package/src/data/network/interceptors/retryInterceptor.ts +24 -0
  189. package/src/data/storage/asyncStorageManager.ts +56 -0
  190. package/src/data/storage/deviceIdManager.ts +46 -0
  191. package/src/data/storage/keysManager.ts +89 -0
  192. package/src/data/storage/locationManager.ts +39 -0
  193. package/src/data/storage/reactRefManager.ts +25 -0
  194. package/src/data/storage/sessionManager.ts +11 -0
  195. package/src/data/storage/storageKeys.ts +4 -0
  196. package/src/data/storage/storageManager.ts +83 -0
  197. package/src/index.tsx +17 -0
  198. package/src/services/device/location.ts +51 -0
  199. package/src/services/navigation/dialPad.ts +39 -0
  200. package/src/services/navigation/goBackNavigation.ts +19 -0
  201. package/src/services/navigation/openBrowser.ts +6 -0
  202. package/src/services/navigation/openMap.ts +53 -0
  203. package/src/services/permissions/permissionManager.ts +33 -0
  204. package/src/services/url/urlGenerator.ts +140 -0
  205. package/src/services/webview/messageHandler.ts +45 -0
  206. package/src/utils/config.ts +35 -0
  207. package/src/utils/dependencyManager.ts +82 -0
  208. package/src/utils/encryption.ts +96 -0
  209. package/src/utils/errors.ts +6 -0
  210. package/src/utils/logger.ts +11 -0
  211. package/src/utils/platformManager.ts +14 -0
  212. package/src/utils/validator.ts +29 -0
@@ -0,0 +1,130 @@
1
+ // Services / API clients
2
+ import { ApiClient } from './apiClient';
3
+
4
+ // Types / Models
5
+ import type { ApiResponse } from '../models/apiResponse';
6
+ import { apiError, apiSuccess } from '../models/apiResponse';
7
+
8
+ // Storage
9
+ import {
10
+ get as storageGet,
11
+ save as storageSave,
12
+ } from '../storage/storageManager';
13
+
14
+ export enum CacheStrategy {
15
+ cache = 'cache',
16
+ cacheOnly = 'cacheOnly',
17
+ network = 'network',
18
+ normal = 'normal',
19
+ }
20
+
21
+ export class ApiRepository {
22
+ private readonly apiClient: ApiClient;
23
+
24
+ constructor(apiClient: ApiClient) {
25
+ this.apiClient = apiClient;
26
+ }
27
+
28
+ async *getData<T>(
29
+ endpoint: string,
30
+ opts?: {
31
+ cacheStrategy?: CacheStrategy;
32
+ params?: Record<string, any>;
33
+ storageKeyPrefix?: string;
34
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
35
+ body?: any;
36
+ }
37
+ ): AsyncGenerator<ApiResponse<T | null>, void, unknown> {
38
+ const cacheStrategy = opts?.cacheStrategy ?? CacheStrategy.normal;
39
+ const cacheKey =
40
+ (opts?.storageKeyPrefix ?? '') +
41
+ endpoint +
42
+ JSON.stringify({
43
+ params: opts?.params ?? {},
44
+ method: opts?.method ?? 'GET',
45
+ body: opts?.body ?? null,
46
+ });
47
+
48
+ if (cacheStrategy === CacheStrategy.cache) {
49
+ const cached = await storageGet(cacheKey);
50
+ if (cached !== null && cached !== undefined) {
51
+ yield apiSuccess<T>(cached as T, 'Data fetched from cache', true);
52
+ } else {
53
+ const res = await this.fetchFromNetwork<T>(
54
+ endpoint,
55
+ opts?.params,
56
+ cacheKey,
57
+ opts?.method,
58
+ opts?.body
59
+ );
60
+ yield res;
61
+ }
62
+ return;
63
+ }
64
+
65
+ if (cacheStrategy === CacheStrategy.cacheOnly) {
66
+ const cached = await storageGet(cacheKey);
67
+ if (cached !== null && cached !== undefined) {
68
+ yield apiSuccess<T>(cached as T, 'Data fetched from cache', true);
69
+ } else {
70
+ yield apiError('No cached data found') as ApiResponse<T | null>;
71
+ }
72
+ return;
73
+ }
74
+
75
+ if (cacheStrategy === CacheStrategy.network) {
76
+ const res = await this.fetchFromNetwork<T>(
77
+ endpoint,
78
+ opts?.params,
79
+ cacheKey,
80
+ opts?.method,
81
+ opts?.body
82
+ );
83
+ yield res;
84
+ return;
85
+ }
86
+
87
+ const cached = await storageGet(cacheKey);
88
+ if (cached !== null && cached !== undefined) {
89
+ yield apiSuccess<T>(cached as T, 'Data fetched from cache', true);
90
+ }
91
+ const res = await this.fetchFromNetwork<T>(
92
+ endpoint,
93
+ opts?.params,
94
+ cacheKey,
95
+ opts?.method,
96
+ opts?.body
97
+ );
98
+ yield res;
99
+ }
100
+
101
+ private async fetchFromNetwork<T>(
102
+ endpoint: string,
103
+ params?: Record<string, any>,
104
+ cacheKey?: string,
105
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE',
106
+ body?: any
107
+ ): Promise<ApiResponse<T | null>> {
108
+ try {
109
+ const m = (method || 'GET').toUpperCase();
110
+ let response: any;
111
+ if (m === 'POST') {
112
+ response = await this.apiClient.post(endpoint, body, params);
113
+ } else if (m === 'PUT') {
114
+ response = await this.apiClient.put(endpoint, body, params);
115
+ } else if (m === 'DELETE') {
116
+ response = await this.apiClient.delete(endpoint, body, params);
117
+ } else {
118
+ response = await this.apiClient.get(endpoint, params);
119
+ }
120
+ const data = response?.data ?? null;
121
+ const message = response?.message ?? response?.statusText ?? 'No message';
122
+ if (data !== null && cacheKey) {
123
+ await storageSave(cacheKey, data);
124
+ }
125
+ return apiSuccess<T>(data, message, false);
126
+ } catch (e) {
127
+ return apiError(`Network request failed: ${e}`) as ApiResponse<T | null>;
128
+ }
129
+ }
130
+ }
@@ -0,0 +1,113 @@
1
+ // Utilities
2
+ import { logger } from '../../utils/logger';
3
+
4
+ // Types / Models
5
+ import type { ApiResponse } from '../models/apiResponse';
6
+ import {
7
+ type OnBoardingData,
8
+ onBoardingDataFromJson,
9
+ } from '../models/onboardingModel';
10
+ import {
11
+ type TokenResponse,
12
+ tokenResponseFromJson,
13
+ } from '../models/tokenModel';
14
+
15
+ // Storage
16
+ import { clearAll as storageClearAll } from '../storage/storageManager';
17
+
18
+ // API
19
+ import { ApiEndpoints } from './apiEndpoints';
20
+ import { ApiRepository, CacheStrategy } from './apiRepository';
21
+ import { Environment, ApiClient } from './apiClient';
22
+
23
+ export class ApiService {
24
+ private repository: ApiRepository;
25
+
26
+ constructor(environment: Environment = Environment.production) {
27
+ const apiClient = new ApiClient(environment);
28
+ this.repository = new ApiRepository(apiClient);
29
+ logger.info(`ApiService initialized with environment: ${environment}`);
30
+ }
31
+
32
+ /**
33
+ * Get onboarding data using GenericRepository with stream
34
+ */
35
+ async *getOnBoarding(opts?: {
36
+ cacheStrategy?: CacheStrategy;
37
+ }): AsyncGenerator<ApiResponse<OnBoardingData | null>, void, unknown> {
38
+ const generator = this.repository.getData<any>(ApiEndpoints.onboarding, {
39
+ cacheStrategy: opts?.cacheStrategy ?? CacheStrategy.normal,
40
+ });
41
+
42
+ for await (const response of generator) {
43
+ if (response.status === true && response.data) {
44
+ try {
45
+ const parsedData = onBoardingDataFromJson(response.data);
46
+ yield {
47
+ ...response,
48
+ data: parsedData,
49
+ };
50
+ } catch (e) {
51
+ yield {
52
+ status: false,
53
+ message: `Failed to parse onboarding data: ${e}`,
54
+ data: null,
55
+ fromCache: response.fromCache,
56
+ };
57
+ }
58
+ } else {
59
+ yield {
60
+ status: false,
61
+ message: response.message ?? 'Failed to load onboarding data',
62
+ data: null,
63
+ fromCache: response.fromCache,
64
+ };
65
+ }
66
+ }
67
+ }
68
+
69
+ async *getNonce({
70
+ cacheStrategy = CacheStrategy.network,
71
+ extUserId = '',
72
+ partnerCode = '',
73
+ }): AsyncGenerator<TokenResponse, void, unknown> {
74
+ const generator = this.repository.getData<any>(ApiEndpoints.get_nonce, {
75
+ cacheStrategy,
76
+ method: 'POST',
77
+ body: {
78
+ extUserId,
79
+ partnerCode,
80
+ },
81
+ });
82
+
83
+ for await (const response of generator) {
84
+ if (response.data) {
85
+ try {
86
+ yield tokenResponseFromJson(response.data);
87
+ } catch (e) {
88
+ yield {
89
+ token: null,
90
+ statusCode: null,
91
+ error: `Failed to parse nonce: ${e}`,
92
+ messages: null,
93
+ };
94
+ }
95
+ } else {
96
+ yield {
97
+ token: null,
98
+ statusCode: null,
99
+ error: response.message ?? 'Failed to load nonce',
100
+ messages: null,
101
+ };
102
+ }
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Clear all cached data
108
+ */
109
+ async clearCache(): Promise<void> {
110
+ await storageClearAll();
111
+ logger.info('Cache cleared');
112
+ }
113
+ }
@@ -0,0 +1,78 @@
1
+ export function parseToString(value: any): string | null {
2
+ if (value === null || value === undefined) return null;
3
+ if (typeof value === 'string') return value;
4
+ if (typeof value === 'number') return String(value);
5
+ if (typeof value === 'boolean') return String(value);
6
+ return String(value);
7
+ }
8
+
9
+ export function parseToInt(value: any): number | null {
10
+ if (value === null || value === undefined) return null;
11
+ if (typeof value === 'number') return Math.trunc(value);
12
+ if (typeof value === 'string') {
13
+ const n = Number(value);
14
+ if (!Number.isNaN(n)) return Math.trunc(n);
15
+ }
16
+ return null;
17
+ }
18
+
19
+ export function parseToDouble(value: any): number | null {
20
+ if (value === null || value === undefined) return null;
21
+ if (typeof value === 'number') return value;
22
+ if (typeof value === 'string') {
23
+ const n = Number(value);
24
+ if (!Number.isNaN(n)) return n;
25
+ }
26
+ return null;
27
+ }
28
+
29
+ export function parseToBool(value: any): boolean | null {
30
+ if (value === null || value === undefined) return null;
31
+ if (typeof value === 'boolean') return value;
32
+ if (typeof value === 'number') return value === 1;
33
+ if (typeof value === 'string') {
34
+ const v = value.toLowerCase();
35
+ if (v === 'true' || v === '1' || v === 'yes') return true;
36
+ if (v === 'false' || v === '0' || v === 'no') return false;
37
+ }
38
+ return null;
39
+ }
40
+
41
+ export function parseToMap(value: any): Record<string, any> | null {
42
+ if (value === null || value === undefined) return null;
43
+ if (typeof value === 'object' && !Array.isArray(value)) {
44
+ return { ...value };
45
+ }
46
+ return null;
47
+ }
48
+
49
+ export function parseToList(value: any): any[] | null {
50
+ if (Array.isArray(value)) return value;
51
+ return null;
52
+ }
53
+
54
+ export function parseToStringList(value: any): string[] | null {
55
+ if (!Array.isArray(value)) return null;
56
+ const out: string[] = [];
57
+ for (const item of value) {
58
+ const s = parseToString(item);
59
+ if (s !== null) out.push(s);
60
+ }
61
+ return out;
62
+ }
63
+
64
+ export function isNullOrEmpty(value: any): boolean {
65
+ if (value === null || value === undefined) return true;
66
+ if (typeof value === 'string') return value.length === 0;
67
+ if (Array.isArray(value)) return value.length === 0;
68
+ if (typeof value === 'object') return Object.keys(value).length === 0;
69
+ return false;
70
+ }
71
+
72
+ export function safeParseForModel(data: any): any {
73
+ if (data === null || data === undefined) return null;
74
+ if (typeof data === 'object' && !Array.isArray(data)) {
75
+ return { ...data };
76
+ }
77
+ return data;
78
+ }
@@ -0,0 +1,86 @@
1
+ /* eslint-disable no-unreachable */
2
+
3
+ // Utilities
4
+ import { logger } from '../../../utils/logger';
5
+
6
+ export class AuthInterceptor {
7
+ private static readonly xApiKey = 'x-api-key';
8
+ private static readonly oauthSubIdKey = 'oauthSubId';
9
+ private static readonly bodyMethods = new Set(['POST', 'PUT', 'PATCH']);
10
+ private static readonly excludedApis = new Set<string>();
11
+
12
+ async onRequest(options: any): Promise<any> {
13
+ try {
14
+ if (this.shouldExcludeApi(options.url)) {
15
+ return options;
16
+ }
17
+
18
+ this.addApiKeyHeader(
19
+ options,
20
+ AuthInterceptor.xApiKey,
21
+ '3xqpYp6CPn899166YXbEB1YLJIhfdj08BbCdfQdg'
22
+ );
23
+
24
+ const userId = await this.getCurrentUserId();
25
+ if (userId) {
26
+ this.addAuthenticationData(options, userId);
27
+ }
28
+ } catch (e) {
29
+ logger.error('AuthInterceptor error:', e);
30
+ }
31
+
32
+ return options;
33
+ }
34
+
35
+ private addAuthenticationData(options: any, userId: string) {
36
+ const method = (options.method || 'GET').toUpperCase();
37
+
38
+ if (AuthInterceptor.bodyMethods.has(method)) {
39
+ this.addToQueryParametersAndBody(options, userId);
40
+ } else {
41
+ this.addToQueryParameters(options, userId);
42
+ }
43
+ }
44
+
45
+ private addToQueryParameters(options: any, userId: string) {
46
+ options.params = options.params || {};
47
+ options.params[AuthInterceptor.oauthSubIdKey] = userId;
48
+ }
49
+
50
+ private addToQueryParametersAndBody(options: any, userId: string) {
51
+ this.addToQueryParameters(options, userId);
52
+ this.addToRequestBody(options, userId);
53
+ }
54
+
55
+ private addToRequestBody(options: any, userId: string) {
56
+ if (options.body instanceof FormData) {
57
+ options.body.append(AuthInterceptor.oauthSubIdKey, userId);
58
+ } else if (typeof options.body === 'object' && options.body !== null) {
59
+ options.body[AuthInterceptor.oauthSubIdKey] = userId;
60
+ }
61
+ }
62
+
63
+ private addApiKeyHeader(options: any, key: string, value: string) {
64
+ options.headers = options.headers || {};
65
+ options.headers[key] = value;
66
+ }
67
+
68
+ private shouldExcludeApi(apiPath: string): boolean {
69
+ if (!apiPath) return false;
70
+ for (const excludedPath of AuthInterceptor.excludedApis) {
71
+ if (apiPath.includes(excludedPath)) {
72
+ return true;
73
+ }
74
+ }
75
+ return false;
76
+ }
77
+
78
+ private async getCurrentUserId(): Promise<string | null> {
79
+ try {
80
+ return null;
81
+ } catch (e) {
82
+ logger.error('Failed to get current user ID:', e);
83
+ return null;
84
+ }
85
+ }
86
+ }
@@ -0,0 +1,13 @@
1
+ // Utilities / Helpers
2
+ import { getErrorMessage } from '../apiExceptionHandler';
3
+
4
+ export class ErrorInterceptor {
5
+ onError(err: any, handler: any) {
6
+ const unifiedMessage = getErrorMessage(err?.status, err?.type);
7
+ const newError = {
8
+ ...err,
9
+ error: unifiedMessage,
10
+ };
11
+ handler.reject(newError);
12
+ }
13
+ }
@@ -0,0 +1,16 @@
1
+ // Utilities
2
+ import { logger } from '../../../utils/logger';
3
+
4
+ export class LoggingInterceptor {
5
+ onRequest(options: any) {
6
+ logger.info(`➡️ [REQUEST] ${options.method} ${options.url}`);
7
+ logger.info('Headers:', options.headers);
8
+ logger.info('Body:', options.body);
9
+ return options;
10
+ }
11
+
12
+ onResponse(response: any) {
13
+ logger.info(`✅ [RESPONSE] ${response.status}:`, response.data);
14
+ return response;
15
+ }
16
+ }
@@ -0,0 +1,20 @@
1
+ // Third-party libraries
2
+ import NetInfo from '@react-native-community/netinfo';
3
+
4
+ // Utilities / Helpers
5
+ import { noInternetError } from '../apiExceptionHandler';
6
+
7
+ export class NetworkInterceptor {
8
+ async onRequest(options: any): Promise<any> {
9
+ const state = await NetInfo.fetch();
10
+ if (!state.isConnected) {
11
+ throw {
12
+ requestOptions: options,
13
+ type: 'connectionError',
14
+ error: noInternetError(),
15
+ message: noInternetError(), // Unified message
16
+ };
17
+ }
18
+ return options;
19
+ }
20
+ }
@@ -0,0 +1,24 @@
1
+ export class RetryInterceptor {
2
+ private readonly retries: number;
3
+
4
+ constructor(retries: number = 1) {
5
+ this.retries = retries;
6
+ }
7
+
8
+ async onError(err: any, handler: any): Promise<any> {
9
+ const attempt = err.config?.retry_attempt ?? 0;
10
+
11
+ if (attempt < this.retries && this.shouldRetry(err)) {
12
+ // Retry logic implementation depends on the HTTP client (axios/fetch)
13
+ // This is a placeholder for the logic
14
+ return handler.next(err);
15
+ }
16
+ return handler.next(err);
17
+ }
18
+
19
+ private shouldRetry(err: any): boolean {
20
+ // Check for timeout or network errors
21
+ // Placeholder logic
22
+ return err.code === 'ECONNABORTED' || err.message?.includes('timeout');
23
+ }
24
+ }
@@ -0,0 +1,56 @@
1
+ // Utilities / Helpers
2
+ import { resolveNativeDependencies } from '../../utils/dependencyManager';
3
+
4
+ function ensureStorage() {
5
+ const { AsyncStorage } = resolveNativeDependencies();
6
+ if (!AsyncStorage) throw new Error('ASYNC_STORAGE_NOT_AVAILABLE');
7
+ return AsyncStorage as any;
8
+ }
9
+
10
+ export async function storageGet(key: string): Promise<string | null> {
11
+ const storage = ensureStorage();
12
+ return storage.getItem(key);
13
+ }
14
+
15
+ export async function storageSet(key: string, value: string): Promise<void> {
16
+ const storage = ensureStorage();
17
+ await storage.setItem(key, value);
18
+ }
19
+
20
+ export async function storageRemove(key: string): Promise<void> {
21
+ const storage = ensureStorage();
22
+ if (typeof storage.removeItem === 'function') {
23
+ await storage.removeItem(key);
24
+ return;
25
+ }
26
+ throw new Error('ASYNC_STORAGE_REMOVE_NOT_SUPPORTED');
27
+ }
28
+
29
+ export async function storageGetJSON<T>(key: string): Promise<T | undefined> {
30
+ const raw = await storageGet(key);
31
+ if (!raw) return undefined;
32
+ try {
33
+ return JSON.parse(raw) as T;
34
+ } catch {
35
+ return undefined;
36
+ }
37
+ }
38
+
39
+ export async function storageSetJSON(
40
+ key: string,
41
+ value: unknown
42
+ ): Promise<void> {
43
+ await storageSet(key, JSON.stringify(value));
44
+ }
45
+
46
+ export function createStorageNamespace(ns: string) {
47
+ const prefix = ns ? `${ns}:` : '';
48
+ return {
49
+ get: (key: string) => storageGet(prefix + key),
50
+ set: (key: string, value: string) => storageSet(prefix + key, value),
51
+ remove: (key: string) => storageRemove(prefix + key),
52
+ getJSON: <T>(key: string) => storageGetJSON<T>(prefix + key),
53
+ setJSON: (key: string, value: unknown) =>
54
+ storageSetJSON(prefix + key, value),
55
+ };
56
+ }
@@ -0,0 +1,46 @@
1
+ // Storage Utilities
2
+ import { storageGet, storageSet } from './asyncStorageManager';
3
+ import { SDK_DEVICE_ID } from './storageKeys';
4
+
5
+ // Utilities / Helpers
6
+ import { resolveNativeDependencies } from '../../utils/dependencyManager';
7
+
8
+ let cachedDeviceId: string | null = null;
9
+
10
+ async function getFromStorage(): Promise<string | null> {
11
+ const key = SDK_DEVICE_ID;
12
+ try {
13
+ const existing = await storageGet(key);
14
+ return existing ?? null;
15
+ } catch {
16
+ return null;
17
+ }
18
+ }
19
+
20
+ async function saveToStorage(id: string): Promise<void> {
21
+ const key = SDK_DEVICE_ID;
22
+ try {
23
+ await storageSet(key, id);
24
+ } catch {}
25
+ }
26
+
27
+ export async function getDeviceId(): Promise<string> {
28
+ if (cachedDeviceId) return cachedDeviceId;
29
+ const stored = await getFromStorage();
30
+ if (stored) {
31
+ cachedDeviceId = stored;
32
+ return stored;
33
+ }
34
+ try {
35
+ const { DeviceInfo } = resolveNativeDependencies();
36
+ if (DeviceInfo?.getUniqueId) {
37
+ const uniqueId = await DeviceInfo.getUniqueId();
38
+ cachedDeviceId = uniqueId;
39
+ await saveToStorage(uniqueId);
40
+ return uniqueId;
41
+ }
42
+ } catch {}
43
+ throw new Error(
44
+ 'DEVICE_ID_UNAVAILABLE: install react-native-device-info or provide a custom id'
45
+ );
46
+ }
@@ -0,0 +1,89 @@
1
+ class KeysManager {
2
+ private apiKey: string | null = null;
3
+ private encryptionKey: string | null = null;
4
+ private pRefCode: string | null = null;
5
+ private authMode: string | null = null;
6
+
7
+ setApiKey(apiKey: string): void {
8
+ this.apiKey = apiKey;
9
+ }
10
+
11
+ getApiKey(): string | null {
12
+ return this.apiKey ?? null;
13
+ }
14
+
15
+ setEncryptionKey(encryptionKey: string): void {
16
+ this.encryptionKey = encryptionKey;
17
+ }
18
+
19
+ getEncryptionKey(): string | null {
20
+ return this.encryptionKey ?? null;
21
+ }
22
+
23
+ setPRefCode(pRefCode: string): void {
24
+ this.pRefCode = pRefCode;
25
+ }
26
+
27
+ getPRefCode(): string | null {
28
+ return this.pRefCode ?? null;
29
+ }
30
+
31
+ setAuthMode(authMode: string): void {
32
+ this.authMode = authMode;
33
+ }
34
+
35
+ getAuthMode(): string | null {
36
+ return this.authMode ?? null;
37
+ }
38
+ }
39
+
40
+ export const keysManager = new KeysManager();
41
+
42
+ export const setApiKey = async (apiKey: string): Promise<void> => {
43
+ keysManager.setApiKey(apiKey);
44
+ };
45
+
46
+ export async function getApiKey(): Promise<string> {
47
+ return keysManager.getApiKey() ?? '-';
48
+ }
49
+
50
+ export const setEncryptionKey = async (
51
+ encryptionKey: string
52
+ ): Promise<void> => {
53
+ keysManager.setEncryptionKey(encryptionKey);
54
+ };
55
+ export async function getEncryptionKey(): Promise<string> {
56
+ return keysManager.getEncryptionKey() ?? '-';
57
+ }
58
+
59
+ export function getApiKeySync(): string | null {
60
+ return keysManager.getApiKey();
61
+ }
62
+
63
+ export function getEncryptionKeySync(): string | null {
64
+ return keysManager.getEncryptionKey();
65
+ }
66
+
67
+ export const setPRefCode = async (pRefCode: string): Promise<void> => {
68
+ keysManager.setPRefCode(pRefCode);
69
+ };
70
+
71
+ export async function getPRefCode(): Promise<string> {
72
+ return keysManager.getPRefCode() ?? '-';
73
+ }
74
+
75
+ export function getPRefCodeSync(): string | null {
76
+ return keysManager.getPRefCode();
77
+ }
78
+
79
+ export const setAuthMode = async (authMode: string): Promise<void> => {
80
+ keysManager.setAuthMode(authMode);
81
+ };
82
+
83
+ export async function getAuthMode(): Promise<string> {
84
+ return keysManager.getAuthMode() ?? '-';
85
+ }
86
+
87
+ export function getAuthModeSync(): string | null {
88
+ return keysManager.getAuthMode();
89
+ }