@oxyhq/core 1.0.0

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 (277) hide show
  1. package/README.md +50 -0
  2. package/dist/cjs/AuthManager.js +361 -0
  3. package/dist/cjs/CrossDomainAuth.js +258 -0
  4. package/dist/cjs/HttpService.js +618 -0
  5. package/dist/cjs/OxyServices.base.js +263 -0
  6. package/dist/cjs/OxyServices.errors.js +22 -0
  7. package/dist/cjs/OxyServices.js +63 -0
  8. package/dist/cjs/constants/version.js +16 -0
  9. package/dist/cjs/crypto/index.js +20 -0
  10. package/dist/cjs/crypto/keyManager.js +887 -0
  11. package/dist/cjs/crypto/polyfill.js +64 -0
  12. package/dist/cjs/crypto/recoveryPhrase.js +169 -0
  13. package/dist/cjs/crypto/signatureService.js +296 -0
  14. package/dist/cjs/i18n/index.js +73 -0
  15. package/dist/cjs/i18n/locales/ar-SA.json +120 -0
  16. package/dist/cjs/i18n/locales/ca-ES.json +120 -0
  17. package/dist/cjs/i18n/locales/de-DE.json +120 -0
  18. package/dist/cjs/i18n/locales/en-US.json +956 -0
  19. package/dist/cjs/i18n/locales/es-ES.json +944 -0
  20. package/dist/cjs/i18n/locales/fr-FR.json +120 -0
  21. package/dist/cjs/i18n/locales/it-IT.json +120 -0
  22. package/dist/cjs/i18n/locales/ja-JP.json +119 -0
  23. package/dist/cjs/i18n/locales/ko-KR.json +120 -0
  24. package/dist/cjs/i18n/locales/locales/ar-SA.json +120 -0
  25. package/dist/cjs/i18n/locales/locales/ca-ES.json +120 -0
  26. package/dist/cjs/i18n/locales/locales/de-DE.json +120 -0
  27. package/dist/cjs/i18n/locales/locales/en-US.json +956 -0
  28. package/dist/cjs/i18n/locales/locales/es-ES.json +944 -0
  29. package/dist/cjs/i18n/locales/locales/fr-FR.json +120 -0
  30. package/dist/cjs/i18n/locales/locales/it-IT.json +120 -0
  31. package/dist/cjs/i18n/locales/locales/ja-JP.json +119 -0
  32. package/dist/cjs/i18n/locales/locales/ko-KR.json +120 -0
  33. package/dist/cjs/i18n/locales/locales/pt-PT.json +120 -0
  34. package/dist/cjs/i18n/locales/locales/zh-CN.json +120 -0
  35. package/dist/cjs/i18n/locales/pt-PT.json +120 -0
  36. package/dist/cjs/i18n/locales/zh-CN.json +120 -0
  37. package/dist/cjs/index.js +153 -0
  38. package/dist/cjs/mixins/OxyServices.analytics.js +49 -0
  39. package/dist/cjs/mixins/OxyServices.assets.js +380 -0
  40. package/dist/cjs/mixins/OxyServices.auth.js +259 -0
  41. package/dist/cjs/mixins/OxyServices.developer.js +97 -0
  42. package/dist/cjs/mixins/OxyServices.devices.js +116 -0
  43. package/dist/cjs/mixins/OxyServices.features.js +309 -0
  44. package/dist/cjs/mixins/OxyServices.fedcm.js +435 -0
  45. package/dist/cjs/mixins/OxyServices.karma.js +108 -0
  46. package/dist/cjs/mixins/OxyServices.language.js +154 -0
  47. package/dist/cjs/mixins/OxyServices.location.js +43 -0
  48. package/dist/cjs/mixins/OxyServices.payment.js +158 -0
  49. package/dist/cjs/mixins/OxyServices.popup.js +371 -0
  50. package/dist/cjs/mixins/OxyServices.privacy.js +162 -0
  51. package/dist/cjs/mixins/OxyServices.redirect.js +345 -0
  52. package/dist/cjs/mixins/OxyServices.security.js +81 -0
  53. package/dist/cjs/mixins/OxyServices.user.js +355 -0
  54. package/dist/cjs/mixins/OxyServices.utility.js +156 -0
  55. package/dist/cjs/mixins/index.js +79 -0
  56. package/dist/cjs/mixins/mixinHelpers.js +53 -0
  57. package/dist/cjs/models/interfaces.js +20 -0
  58. package/dist/cjs/models/session.js +2 -0
  59. package/dist/cjs/shared/index.js +70 -0
  60. package/dist/cjs/shared/utils/colorUtils.js +153 -0
  61. package/dist/cjs/shared/utils/debugUtils.js +73 -0
  62. package/dist/cjs/shared/utils/errorUtils.js +183 -0
  63. package/dist/cjs/shared/utils/index.js +49 -0
  64. package/dist/cjs/shared/utils/networkUtils.js +183 -0
  65. package/dist/cjs/shared/utils/themeUtils.js +106 -0
  66. package/dist/cjs/utils/apiUtils.js +61 -0
  67. package/dist/cjs/utils/asyncUtils.js +194 -0
  68. package/dist/cjs/utils/cache.js +226 -0
  69. package/dist/cjs/utils/deviceManager.js +205 -0
  70. package/dist/cjs/utils/errorUtils.js +154 -0
  71. package/dist/cjs/utils/index.js +26 -0
  72. package/dist/cjs/utils/languageUtils.js +165 -0
  73. package/dist/cjs/utils/loggerUtils.js +126 -0
  74. package/dist/cjs/utils/platform.js +144 -0
  75. package/dist/cjs/utils/requestUtils.js +209 -0
  76. package/dist/cjs/utils/sessionUtils.js +181 -0
  77. package/dist/cjs/utils/validationUtils.js +173 -0
  78. package/dist/esm/AuthManager.js +356 -0
  79. package/dist/esm/CrossDomainAuth.js +253 -0
  80. package/dist/esm/HttpService.js +614 -0
  81. package/dist/esm/OxyServices.base.js +259 -0
  82. package/dist/esm/OxyServices.errors.js +17 -0
  83. package/dist/esm/OxyServices.js +59 -0
  84. package/dist/esm/constants/version.js +13 -0
  85. package/dist/esm/crypto/index.js +13 -0
  86. package/dist/esm/crypto/keyManager.js +850 -0
  87. package/dist/esm/crypto/polyfill.js +61 -0
  88. package/dist/esm/crypto/recoveryPhrase.js +132 -0
  89. package/dist/esm/crypto/signatureService.js +259 -0
  90. package/dist/esm/i18n/index.js +69 -0
  91. package/dist/esm/i18n/locales/ar-SA.json +120 -0
  92. package/dist/esm/i18n/locales/ca-ES.json +120 -0
  93. package/dist/esm/i18n/locales/de-DE.json +120 -0
  94. package/dist/esm/i18n/locales/en-US.json +956 -0
  95. package/dist/esm/i18n/locales/es-ES.json +944 -0
  96. package/dist/esm/i18n/locales/fr-FR.json +120 -0
  97. package/dist/esm/i18n/locales/it-IT.json +120 -0
  98. package/dist/esm/i18n/locales/ja-JP.json +119 -0
  99. package/dist/esm/i18n/locales/ko-KR.json +120 -0
  100. package/dist/esm/i18n/locales/locales/ar-SA.json +120 -0
  101. package/dist/esm/i18n/locales/locales/ca-ES.json +120 -0
  102. package/dist/esm/i18n/locales/locales/de-DE.json +120 -0
  103. package/dist/esm/i18n/locales/locales/en-US.json +956 -0
  104. package/dist/esm/i18n/locales/locales/es-ES.json +944 -0
  105. package/dist/esm/i18n/locales/locales/fr-FR.json +120 -0
  106. package/dist/esm/i18n/locales/locales/it-IT.json +120 -0
  107. package/dist/esm/i18n/locales/locales/ja-JP.json +119 -0
  108. package/dist/esm/i18n/locales/locales/ko-KR.json +120 -0
  109. package/dist/esm/i18n/locales/locales/pt-PT.json +120 -0
  110. package/dist/esm/i18n/locales/locales/zh-CN.json +120 -0
  111. package/dist/esm/i18n/locales/pt-PT.json +120 -0
  112. package/dist/esm/i18n/locales/zh-CN.json +120 -0
  113. package/dist/esm/index.js +55 -0
  114. package/dist/esm/mixins/OxyServices.analytics.js +46 -0
  115. package/dist/esm/mixins/OxyServices.assets.js +377 -0
  116. package/dist/esm/mixins/OxyServices.auth.js +256 -0
  117. package/dist/esm/mixins/OxyServices.developer.js +94 -0
  118. package/dist/esm/mixins/OxyServices.devices.js +113 -0
  119. package/dist/esm/mixins/OxyServices.features.js +306 -0
  120. package/dist/esm/mixins/OxyServices.fedcm.js +433 -0
  121. package/dist/esm/mixins/OxyServices.karma.js +105 -0
  122. package/dist/esm/mixins/OxyServices.language.js +118 -0
  123. package/dist/esm/mixins/OxyServices.location.js +40 -0
  124. package/dist/esm/mixins/OxyServices.payment.js +155 -0
  125. package/dist/esm/mixins/OxyServices.popup.js +369 -0
  126. package/dist/esm/mixins/OxyServices.privacy.js +159 -0
  127. package/dist/esm/mixins/OxyServices.redirect.js +343 -0
  128. package/dist/esm/mixins/OxyServices.security.js +78 -0
  129. package/dist/esm/mixins/OxyServices.user.js +352 -0
  130. package/dist/esm/mixins/OxyServices.utility.js +153 -0
  131. package/dist/esm/mixins/index.js +76 -0
  132. package/dist/esm/mixins/mixinHelpers.js +48 -0
  133. package/dist/esm/models/interfaces.js +17 -0
  134. package/dist/esm/models/session.js +1 -0
  135. package/dist/esm/shared/index.js +31 -0
  136. package/dist/esm/shared/utils/colorUtils.js +143 -0
  137. package/dist/esm/shared/utils/debugUtils.js +65 -0
  138. package/dist/esm/shared/utils/errorUtils.js +170 -0
  139. package/dist/esm/shared/utils/index.js +15 -0
  140. package/dist/esm/shared/utils/networkUtils.js +173 -0
  141. package/dist/esm/shared/utils/themeUtils.js +98 -0
  142. package/dist/esm/utils/apiUtils.js +55 -0
  143. package/dist/esm/utils/asyncUtils.js +179 -0
  144. package/dist/esm/utils/cache.js +218 -0
  145. package/dist/esm/utils/deviceManager.js +168 -0
  146. package/dist/esm/utils/errorUtils.js +146 -0
  147. package/dist/esm/utils/index.js +7 -0
  148. package/dist/esm/utils/languageUtils.js +158 -0
  149. package/dist/esm/utils/loggerUtils.js +115 -0
  150. package/dist/esm/utils/platform.js +102 -0
  151. package/dist/esm/utils/requestUtils.js +203 -0
  152. package/dist/esm/utils/sessionUtils.js +171 -0
  153. package/dist/esm/utils/validationUtils.js +153 -0
  154. package/dist/types/AuthManager.d.ts +143 -0
  155. package/dist/types/CrossDomainAuth.d.ts +160 -0
  156. package/dist/types/HttpService.d.ts +163 -0
  157. package/dist/types/OxyServices.base.d.ts +126 -0
  158. package/dist/types/OxyServices.d.ts +81 -0
  159. package/dist/types/OxyServices.errors.d.ts +11 -0
  160. package/dist/types/constants/version.d.ts +13 -0
  161. package/dist/types/crypto/index.d.ts +11 -0
  162. package/dist/types/crypto/keyManager.d.ts +189 -0
  163. package/dist/types/crypto/polyfill.d.ts +11 -0
  164. package/dist/types/crypto/recoveryPhrase.d.ts +58 -0
  165. package/dist/types/crypto/signatureService.d.ts +86 -0
  166. package/dist/types/i18n/index.d.ts +3 -0
  167. package/dist/types/index.d.ts +50 -0
  168. package/dist/types/mixins/OxyServices.analytics.d.ts +66 -0
  169. package/dist/types/mixins/OxyServices.assets.d.ts +135 -0
  170. package/dist/types/mixins/OxyServices.auth.d.ts +186 -0
  171. package/dist/types/mixins/OxyServices.developer.d.ts +99 -0
  172. package/dist/types/mixins/OxyServices.devices.d.ts +96 -0
  173. package/dist/types/mixins/OxyServices.features.d.ts +228 -0
  174. package/dist/types/mixins/OxyServices.fedcm.d.ts +200 -0
  175. package/dist/types/mixins/OxyServices.karma.d.ts +85 -0
  176. package/dist/types/mixins/OxyServices.language.d.ts +81 -0
  177. package/dist/types/mixins/OxyServices.location.d.ts +64 -0
  178. package/dist/types/mixins/OxyServices.payment.d.ts +111 -0
  179. package/dist/types/mixins/OxyServices.popup.d.ts +205 -0
  180. package/dist/types/mixins/OxyServices.privacy.d.ts +122 -0
  181. package/dist/types/mixins/OxyServices.redirect.d.ts +245 -0
  182. package/dist/types/mixins/OxyServices.security.d.ts +78 -0
  183. package/dist/types/mixins/OxyServices.user.d.ts +182 -0
  184. package/dist/types/mixins/OxyServices.utility.d.ts +93 -0
  185. package/dist/types/mixins/index.d.ts +30 -0
  186. package/dist/types/mixins/mixinHelpers.d.ts +31 -0
  187. package/dist/types/models/interfaces.d.ts +415 -0
  188. package/dist/types/models/session.d.ts +27 -0
  189. package/dist/types/shared/index.d.ts +28 -0
  190. package/dist/types/shared/utils/colorUtils.d.ts +104 -0
  191. package/dist/types/shared/utils/debugUtils.d.ts +48 -0
  192. package/dist/types/shared/utils/errorUtils.d.ts +97 -0
  193. package/dist/types/shared/utils/index.d.ts +13 -0
  194. package/dist/types/shared/utils/networkUtils.d.ts +139 -0
  195. package/dist/types/shared/utils/themeUtils.d.ts +90 -0
  196. package/dist/types/utils/apiUtils.d.ts +53 -0
  197. package/dist/types/utils/asyncUtils.d.ts +58 -0
  198. package/dist/types/utils/cache.d.ts +127 -0
  199. package/dist/types/utils/deviceManager.d.ts +65 -0
  200. package/dist/types/utils/errorUtils.d.ts +46 -0
  201. package/dist/types/utils/index.d.ts +6 -0
  202. package/dist/types/utils/languageUtils.d.ts +37 -0
  203. package/dist/types/utils/loggerUtils.d.ts +48 -0
  204. package/dist/types/utils/platform.d.ts +40 -0
  205. package/dist/types/utils/requestUtils.d.ts +123 -0
  206. package/dist/types/utils/sessionUtils.d.ts +54 -0
  207. package/dist/types/utils/validationUtils.d.ts +85 -0
  208. package/package.json +84 -0
  209. package/src/AuthManager.ts +436 -0
  210. package/src/CrossDomainAuth.ts +307 -0
  211. package/src/HttpService.ts +752 -0
  212. package/src/OxyServices.base.ts +334 -0
  213. package/src/OxyServices.errors.ts +26 -0
  214. package/src/OxyServices.ts +129 -0
  215. package/src/constants/version.ts +15 -0
  216. package/src/crypto/index.ts +25 -0
  217. package/src/crypto/keyManager.ts +962 -0
  218. package/src/crypto/polyfill.ts +70 -0
  219. package/src/crypto/recoveryPhrase.ts +166 -0
  220. package/src/crypto/signatureService.ts +323 -0
  221. package/src/i18n/index.ts +75 -0
  222. package/src/i18n/locales/ar-SA.json +120 -0
  223. package/src/i18n/locales/ca-ES.json +120 -0
  224. package/src/i18n/locales/de-DE.json +120 -0
  225. package/src/i18n/locales/en-US.json +956 -0
  226. package/src/i18n/locales/es-ES.json +944 -0
  227. package/src/i18n/locales/fr-FR.json +120 -0
  228. package/src/i18n/locales/it-IT.json +120 -0
  229. package/src/i18n/locales/ja-JP.json +119 -0
  230. package/src/i18n/locales/ko-KR.json +120 -0
  231. package/src/i18n/locales/pt-PT.json +120 -0
  232. package/src/i18n/locales/zh-CN.json +120 -0
  233. package/src/index.ts +153 -0
  234. package/src/mixins/OxyServices.analytics.ts +53 -0
  235. package/src/mixins/OxyServices.assets.ts +412 -0
  236. package/src/mixins/OxyServices.auth.ts +358 -0
  237. package/src/mixins/OxyServices.developer.ts +114 -0
  238. package/src/mixins/OxyServices.devices.ts +119 -0
  239. package/src/mixins/OxyServices.features.ts +428 -0
  240. package/src/mixins/OxyServices.fedcm.ts +494 -0
  241. package/src/mixins/OxyServices.karma.ts +111 -0
  242. package/src/mixins/OxyServices.language.ts +127 -0
  243. package/src/mixins/OxyServices.location.ts +46 -0
  244. package/src/mixins/OxyServices.payment.ts +163 -0
  245. package/src/mixins/OxyServices.popup.ts +443 -0
  246. package/src/mixins/OxyServices.privacy.ts +182 -0
  247. package/src/mixins/OxyServices.redirect.ts +397 -0
  248. package/src/mixins/OxyServices.security.ts +103 -0
  249. package/src/mixins/OxyServices.user.ts +392 -0
  250. package/src/mixins/OxyServices.utility.ts +191 -0
  251. package/src/mixins/index.ts +91 -0
  252. package/src/mixins/mixinHelpers.ts +69 -0
  253. package/src/models/interfaces.ts +511 -0
  254. package/src/models/session.ts +30 -0
  255. package/src/shared/index.ts +82 -0
  256. package/src/shared/utils/colorUtils.ts +155 -0
  257. package/src/shared/utils/debugUtils.ts +73 -0
  258. package/src/shared/utils/errorUtils.ts +181 -0
  259. package/src/shared/utils/index.ts +59 -0
  260. package/src/shared/utils/networkUtils.ts +248 -0
  261. package/src/shared/utils/themeUtils.ts +115 -0
  262. package/src/types/bip39.d.ts +32 -0
  263. package/src/types/buffer.d.ts +97 -0
  264. package/src/types/color.d.ts +20 -0
  265. package/src/types/elliptic.d.ts +62 -0
  266. package/src/utils/apiUtils.ts +88 -0
  267. package/src/utils/asyncUtils.ts +252 -0
  268. package/src/utils/cache.ts +264 -0
  269. package/src/utils/deviceManager.ts +198 -0
  270. package/src/utils/errorUtils.ts +216 -0
  271. package/src/utils/index.ts +21 -0
  272. package/src/utils/languageUtils.ts +174 -0
  273. package/src/utils/loggerUtils.ts +153 -0
  274. package/src/utils/platform.ts +117 -0
  275. package/src/utils/requestUtils.ts +237 -0
  276. package/src/utils/sessionUtils.ts +206 -0
  277. package/src/utils/validationUtils.ts +174 -0
@@ -0,0 +1,146 @@
1
+ import { logger } from './loggerUtils';
2
+ /**
3
+ * Error handling utilities for consistent error processing
4
+ */
5
+ /**
6
+ * Common error codes
7
+ */
8
+ export const ErrorCodes = {
9
+ // Authentication errors
10
+ UNAUTHORIZED: 'UNAUTHORIZED',
11
+ FORBIDDEN: 'FORBIDDEN',
12
+ INVALID_TOKEN: 'INVALID_TOKEN',
13
+ MISSING_TOKEN: 'MISSING_TOKEN',
14
+ // Validation errors
15
+ VALIDATION_ERROR: 'VALIDATION_ERROR',
16
+ BAD_REQUEST: 'BAD_REQUEST',
17
+ MISSING_PARAMETER: 'MISSING_PARAMETER',
18
+ INVALID_FORMAT: 'INVALID_FORMAT',
19
+ // Resource errors
20
+ NOT_FOUND: 'NOT_FOUND',
21
+ ALREADY_EXISTS: 'ALREADY_EXISTS',
22
+ CONFLICT: 'CONFLICT',
23
+ // Server errors
24
+ INTERNAL_ERROR: 'INTERNAL_ERROR',
25
+ SERVICE_UNAVAILABLE: 'SERVICE_UNAVAILABLE',
26
+ TIMEOUT: 'TIMEOUT',
27
+ // Network errors
28
+ NETWORK_ERROR: 'NETWORK_ERROR',
29
+ CONNECTION_FAILED: 'CONNECTION_FAILED'
30
+ };
31
+ /**
32
+ * Create a standardized API error
33
+ */
34
+ export function createApiError(message, code = ErrorCodes.INTERNAL_ERROR, status = 500, details) {
35
+ return {
36
+ message,
37
+ code,
38
+ status,
39
+ details
40
+ };
41
+ }
42
+ /**
43
+ * Handle common HTTP errors and convert to ApiError
44
+ */
45
+ export function handleHttpError(error) {
46
+ // If it's already an ApiError, ensure it has a non-empty message
47
+ if (error && typeof error === 'object' && 'code' in error && 'status' in error) {
48
+ const apiError = error;
49
+ // Ensure message is not empty
50
+ if (!apiError.message || !apiError.message.trim()) {
51
+ return {
52
+ ...apiError,
53
+ message: apiError.message || 'An error occurred',
54
+ };
55
+ }
56
+ return apiError;
57
+ }
58
+ // Handle AbortError (timeout or cancelled requests)
59
+ if (error instanceof Error && error.name === 'AbortError') {
60
+ return createApiError('Request timeout or cancelled', ErrorCodes.TIMEOUT, 0);
61
+ }
62
+ // Handle TypeError (network failures, CORS, etc.)
63
+ if (error instanceof TypeError) {
64
+ // Check if it's a network-related TypeError
65
+ if (error.message.includes('fetch') || error.message.includes('network') || error.message.includes('Failed to fetch')) {
66
+ return createApiError('Network error - failed to connect to server', ErrorCodes.NETWORK_ERROR, 0);
67
+ }
68
+ return createApiError(error.message || 'Network error occurred', ErrorCodes.NETWORK_ERROR, 0);
69
+ }
70
+ // Handle fetch Response errors - check if it has response property with status
71
+ if (error && typeof error === 'object' && 'response' in error) {
72
+ const fetchError = error;
73
+ const status = fetchError.response?.status || fetchError.status;
74
+ if (status) {
75
+ return createApiError(fetchError.message || `HTTP ${status} error`, getErrorCodeFromStatus(status), status);
76
+ }
77
+ }
78
+ // Handle standard errors
79
+ if (error instanceof Error) {
80
+ // Check for common error patterns
81
+ if (error.message.includes('timeout') || error.message.includes('aborted')) {
82
+ return createApiError('Request timeout', ErrorCodes.TIMEOUT, 0);
83
+ }
84
+ if (error.message.includes('network') || error.message.includes('fetch')) {
85
+ return createApiError(error.message || 'Network error occurred', ErrorCodes.NETWORK_ERROR, 0);
86
+ }
87
+ return createApiError(error.message || 'Unknown error occurred', ErrorCodes.INTERNAL_ERROR, 500);
88
+ }
89
+ // Handle other errors - ensure we always return a non-empty message
90
+ const errorString = error ? String(error) : '';
91
+ const message = errorString.trim() || 'Unknown error occurred';
92
+ return createApiError(message, ErrorCodes.INTERNAL_ERROR, 500);
93
+ }
94
+ /**
95
+ * Get error code from HTTP status
96
+ * Exported for use in other modules
97
+ */
98
+ export function getErrorCodeFromStatus(status) {
99
+ switch (status) {
100
+ case 400:
101
+ return ErrorCodes.BAD_REQUEST;
102
+ case 401:
103
+ return ErrorCodes.UNAUTHORIZED;
104
+ case 403:
105
+ return ErrorCodes.FORBIDDEN;
106
+ case 404:
107
+ return ErrorCodes.NOT_FOUND;
108
+ case 409:
109
+ return ErrorCodes.CONFLICT;
110
+ case 422:
111
+ return ErrorCodes.VALIDATION_ERROR;
112
+ case 500:
113
+ return ErrorCodes.INTERNAL_ERROR;
114
+ case 503:
115
+ return ErrorCodes.SERVICE_UNAVAILABLE;
116
+ default:
117
+ return ErrorCodes.INTERNAL_ERROR;
118
+ }
119
+ }
120
+ /**
121
+ * Validate required fields and throw error if missing
122
+ */
123
+ export function validateRequiredFields(data, fields) {
124
+ const missing = fields.filter(field => !data[field]);
125
+ if (missing.length > 0) {
126
+ throw createApiError(`Missing required fields: ${missing.join(', ')}`, ErrorCodes.MISSING_PARAMETER, 400);
127
+ }
128
+ }
129
+ /**
130
+ * Safe error logging with context
131
+ */
132
+ export function logError(error, context) {
133
+ if (error instanceof Error) {
134
+ logger.error(error.message, {
135
+ component: context || 'errorUtils',
136
+ method: 'logError',
137
+ stack: error.stack,
138
+ });
139
+ }
140
+ else {
141
+ logger.error(String(error), {
142
+ component: context || 'errorUtils',
143
+ method: 'logError',
144
+ });
145
+ }
146
+ }
@@ -0,0 +1,7 @@
1
+ export { DeviceManager } from './deviceManager';
2
+ // Request utilities
3
+ export { RequestDeduplicator, RequestQueue, SimpleLogger } from './requestUtils';
4
+ // Cache utilities
5
+ export { TTLCache, createCache, registerCacheForCleanup, unregisterCacheFromCleanup } from './cache';
6
+ // Session utilities
7
+ export { normalizeSession, sortSessions, deduplicateSessions, deduplicateSessionsByUserId, normalizeAndSortSessions, mergeSessions, sessionsEqual, sessionsArraysEqual } from './sessionUtils';
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Language utilities for OxyServices
3
+ * Provides access to supported languages and language metadata
4
+ */
5
+ // Supported languages with their metadata
6
+ export const SUPPORTED_LANGUAGES = [
7
+ {
8
+ id: 'en-US',
9
+ name: 'English',
10
+ nativeName: 'English',
11
+ flag: '🇺🇸',
12
+ icon: 'translate',
13
+ color: '#007AFF',
14
+ },
15
+ {
16
+ id: 'es-ES',
17
+ name: 'Spanish',
18
+ nativeName: 'Español',
19
+ flag: '🇪🇸',
20
+ icon: 'translate',
21
+ color: '#FF3B30',
22
+ },
23
+ {
24
+ id: 'ca-ES',
25
+ name: 'Catalan',
26
+ nativeName: 'Català',
27
+ flag: '🇪🇸',
28
+ icon: 'translate',
29
+ color: '#0CA678',
30
+ },
31
+ {
32
+ id: 'fr-FR',
33
+ name: 'French',
34
+ nativeName: 'Français',
35
+ flag: '🇫🇷',
36
+ icon: 'translate',
37
+ color: '#5856D6',
38
+ },
39
+ {
40
+ id: 'de-DE',
41
+ name: 'German',
42
+ nativeName: 'Deutsch',
43
+ flag: '🇩🇪',
44
+ icon: 'translate',
45
+ color: '#FF9500',
46
+ },
47
+ {
48
+ id: 'it-IT',
49
+ name: 'Italian',
50
+ nativeName: 'Italiano',
51
+ flag: '🇮🇹',
52
+ icon: 'translate',
53
+ color: '#34C759',
54
+ },
55
+ {
56
+ id: 'pt-PT',
57
+ name: 'Portuguese',
58
+ nativeName: 'Português',
59
+ flag: '🇵🇹',
60
+ icon: 'translate',
61
+ color: '#AF52DE',
62
+ },
63
+ {
64
+ id: 'ja-JP',
65
+ name: 'Japanese',
66
+ nativeName: '日本語',
67
+ flag: '🇯🇵',
68
+ icon: 'translate',
69
+ color: '#FF2D92',
70
+ },
71
+ {
72
+ id: 'ko-KR',
73
+ name: 'Korean',
74
+ nativeName: '한국어',
75
+ flag: '🇰🇷',
76
+ icon: 'translate',
77
+ color: '#32D74B',
78
+ },
79
+ {
80
+ id: 'zh-CN',
81
+ name: 'Chinese',
82
+ nativeName: '中文',
83
+ flag: '🇨🇳',
84
+ icon: 'translate',
85
+ color: '#FF9F0A',
86
+ },
87
+ {
88
+ id: 'ar-SA',
89
+ name: 'Arabic',
90
+ nativeName: 'العربية',
91
+ flag: '🇸🇦',
92
+ icon: 'translate',
93
+ color: '#30B0C7',
94
+ },
95
+ ];
96
+ const FALLBACK_LANGUAGE = 'en-US';
97
+ /**
98
+ * Get language metadata by language code
99
+ * @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
100
+ * @returns Language metadata or null if not found
101
+ */
102
+ export function getLanguageMetadata(languageCode) {
103
+ if (!languageCode)
104
+ return null;
105
+ // Direct match
106
+ const exactMatch = SUPPORTED_LANGUAGES.find(lang => lang.id === languageCode);
107
+ if (exactMatch)
108
+ return exactMatch;
109
+ // Try to match base language code (e.g., 'en' matches 'en-US')
110
+ const baseCode = languageCode.split('-')[0];
111
+ const baseMatch = SUPPORTED_LANGUAGES.find(lang => lang.id.startsWith(baseCode + '-'));
112
+ if (baseMatch)
113
+ return baseMatch;
114
+ return null;
115
+ }
116
+ /**
117
+ * Get language name by language code
118
+ * @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
119
+ * @returns Language name (e.g., 'English') or the code if not found
120
+ */
121
+ export function getLanguageName(languageCode) {
122
+ const metadata = getLanguageMetadata(languageCode);
123
+ return metadata?.name || languageCode || FALLBACK_LANGUAGE;
124
+ }
125
+ /**
126
+ * Get native language name by language code
127
+ * @param languageCode - BCP-47 language code (e.g., 'en-US', 'es-ES')
128
+ * @returns Native language name (e.g., 'Español') or the code if not found
129
+ */
130
+ export function getNativeLanguageName(languageCode) {
131
+ const metadata = getLanguageMetadata(languageCode);
132
+ return metadata?.nativeName || languageCode || FALLBACK_LANGUAGE;
133
+ }
134
+ /**
135
+ * Normalize language code to BCP-47 format
136
+ * @param lang - Language code (may be short like 'en' or full like 'en-US')
137
+ * @returns Normalized BCP-47 language code
138
+ */
139
+ export function normalizeLanguageCode(lang) {
140
+ if (!lang)
141
+ return FALLBACK_LANGUAGE;
142
+ if (lang.includes('-'))
143
+ return lang;
144
+ const map = {
145
+ en: 'en-US',
146
+ es: 'es-ES',
147
+ ca: 'ca-ES',
148
+ fr: 'fr-FR',
149
+ de: 'de-DE',
150
+ it: 'it-IT',
151
+ pt: 'pt-PT',
152
+ ja: 'ja-JP',
153
+ ko: 'ko-KR',
154
+ zh: 'zh-CN',
155
+ ar: 'ar-SA',
156
+ };
157
+ return map[lang] || lang;
158
+ }
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Centralized logging utilities for consistent logging across the application
3
+ */
4
+ export var LogLevel;
5
+ (function (LogLevel) {
6
+ LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
7
+ LogLevel[LogLevel["INFO"] = 1] = "INFO";
8
+ LogLevel[LogLevel["WARN"] = 2] = "WARN";
9
+ LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
10
+ LogLevel[LogLevel["NONE"] = 4] = "NONE";
11
+ })(LogLevel || (LogLevel = {}));
12
+ class Logger {
13
+ constructor() {
14
+ this.level = LogLevel.INFO;
15
+ this.isDevelopment = process.env.NODE_ENV === 'development';
16
+ }
17
+ setLevel(level) {
18
+ this.level = level;
19
+ }
20
+ shouldLog(level) {
21
+ return level >= this.level;
22
+ }
23
+ formatMessage(level, message, context) {
24
+ const timestamp = new Date().toISOString();
25
+ const contextStr = context ? ` [${Object.entries(context).map(([k, v]) => `${k}:${v}`).join(', ')}]` : '';
26
+ return `[${timestamp}] ${level}${contextStr}: ${message}`;
27
+ }
28
+ debug(message, context, ...args) {
29
+ if (this.shouldLog(LogLevel.DEBUG)) {
30
+ const formattedMessage = this.formatMessage('DEBUG', message, context);
31
+ if (this.isDevelopment) {
32
+ console.log(formattedMessage, ...args);
33
+ }
34
+ }
35
+ }
36
+ info(message, context, ...args) {
37
+ if (this.shouldLog(LogLevel.INFO)) {
38
+ const formattedMessage = this.formatMessage('INFO', message, context);
39
+ console.log(formattedMessage, ...args);
40
+ }
41
+ }
42
+ warn(message, context, ...args) {
43
+ if (this.shouldLog(LogLevel.WARN)) {
44
+ const formattedMessage = this.formatMessage('WARN', message, context);
45
+ console.warn(formattedMessage, ...args);
46
+ }
47
+ }
48
+ error(message, error, context, ...args) {
49
+ if (this.shouldLog(LogLevel.ERROR)) {
50
+ const formattedMessage = this.formatMessage('ERROR', message, context);
51
+ if (error) {
52
+ console.error(formattedMessage, error, ...args);
53
+ }
54
+ else {
55
+ console.error(formattedMessage, ...args);
56
+ }
57
+ }
58
+ }
59
+ // Specialized logging methods for common patterns
60
+ auth(message, context, ...args) {
61
+ this.info(`🔐 ${message}`, { ...context, category: 'auth' }, ...args);
62
+ }
63
+ api(message, context, ...args) {
64
+ this.info(`🌐 ${message}`, { ...context, category: 'api' }, ...args);
65
+ }
66
+ session(message, context, ...args) {
67
+ this.info(`📱 ${message}`, { ...context, category: 'session' }, ...args);
68
+ }
69
+ user(message, context, ...args) {
70
+ this.info(`👤 ${message}`, { ...context, category: 'user' }, ...args);
71
+ }
72
+ device(message, context, ...args) {
73
+ this.info(`📱 ${message}`, { ...context, category: 'device' }, ...args);
74
+ }
75
+ payment(message, context, ...args) {
76
+ this.info(`💳 ${message}`, { ...context, category: 'payment' }, ...args);
77
+ }
78
+ // Performance logging
79
+ performance(operation, duration, context) {
80
+ const level = duration > 1000 ? LogLevel.WARN : LogLevel.INFO;
81
+ const message = `⏱️ ${operation} completed in ${duration}ms`;
82
+ if (level === LogLevel.WARN) {
83
+ this.warn(message, { ...context, category: 'performance', duration });
84
+ }
85
+ else {
86
+ this.info(message, { ...context, category: 'performance', duration });
87
+ }
88
+ }
89
+ // Error logging with stack trace
90
+ errorWithStack(message, error, context) {
91
+ this.error(message, error, { ...context, stack: error.stack });
92
+ }
93
+ // Group related log messages
94
+ group(label, fn) {
95
+ if (this.isDevelopment && this.shouldLog(LogLevel.DEBUG)) {
96
+ console.group(label);
97
+ fn();
98
+ console.groupEnd();
99
+ }
100
+ else {
101
+ fn();
102
+ }
103
+ }
104
+ }
105
+ // Create singleton instance
106
+ export const logger = new Logger();
107
+ // Convenience functions for common logging patterns
108
+ export const logAuth = (message, context, ...args) => logger.auth(message, context, ...args);
109
+ export const logApi = (message, context, ...args) => logger.api(message, context, ...args);
110
+ export const logSession = (message, context, ...args) => logger.session(message, context, ...args);
111
+ export const logUser = (message, context, ...args) => logger.user(message, context, ...args);
112
+ export const logDevice = (message, context, ...args) => logger.device(message, context, ...args);
113
+ export const logPayment = (message, context, ...args) => logger.payment(message, context, ...args);
114
+ export const logError = (message, error, context, ...args) => logger.error(message, error, context, ...args);
115
+ export const logPerformance = (operation, duration, context) => logger.performance(operation, duration, context);
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Platform Detection Utility
3
+ *
4
+ * Provides platform detection WITHOUT importing from 'react-native'.
5
+ * This allows core modules to be used in web/Node.js environments
6
+ * without bundlers failing on react-native imports.
7
+ */
8
+ /**
9
+ * Detect the current platform without importing react-native
10
+ *
11
+ * Detection order:
12
+ * 1. Check for React Native's Platform object on globalThis (set by RN runtime)
13
+ * 2. Check for Node.js environment
14
+ * 3. Check for browser environment
15
+ * 4. Fall back to 'unknown'
16
+ */
17
+ function detectPlatform() {
18
+ // Check if React Native Platform is available globally (set by RN runtime)
19
+ // This avoids static imports while still detecting RN environment
20
+ const rnPlatform = globalThis.__REACT_NATIVE_PLATFORM__;
21
+ if (rnPlatform) {
22
+ return rnPlatform;
23
+ }
24
+ // Check navigator.product for React Native
25
+ if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
26
+ // We're in React Native but Platform wasn't set globally
27
+ // Try to get OS from userAgent or default to 'unknown'
28
+ return 'unknown';
29
+ }
30
+ // Check for Node.js environment
31
+ if (typeof process !== 'undefined' && process.versions?.node) {
32
+ return 'web'; // Treat Node.js as 'web' for compatibility (no native features)
33
+ }
34
+ // Check for browser/web environment
35
+ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
36
+ return 'web';
37
+ }
38
+ return 'unknown';
39
+ }
40
+ // Cache the platform detection result
41
+ let cachedPlatform = null;
42
+ /**
43
+ * Get the current platform OS
44
+ * Safe to call from any environment (web, Node.js, React Native)
45
+ */
46
+ export function getPlatformOS() {
47
+ if (cachedPlatform === null) {
48
+ cachedPlatform = detectPlatform();
49
+ }
50
+ return cachedPlatform;
51
+ }
52
+ /**
53
+ * Check if running on web platform (browser or Node.js)
54
+ */
55
+ export function isWeb() {
56
+ return getPlatformOS() === 'web';
57
+ }
58
+ /**
59
+ * Check if running in a native app (iOS or Android)
60
+ */
61
+ export function isNative() {
62
+ const os = getPlatformOS();
63
+ return os === 'ios' || os === 'android';
64
+ }
65
+ /**
66
+ * Check if running on iOS
67
+ */
68
+ export function isIOS() {
69
+ return getPlatformOS() === 'ios';
70
+ }
71
+ /**
72
+ * Check if running on Android
73
+ */
74
+ export function isAndroid() {
75
+ return getPlatformOS() === 'android';
76
+ }
77
+ /**
78
+ * Set the platform OS explicitly
79
+ * Called by React Native entry point to register the platform
80
+ * This allows lazy detection in environments where react-native is available
81
+ */
82
+ export function setPlatformOS(os) {
83
+ cachedPlatform = os;
84
+ globalThis.__REACT_NATIVE_PLATFORM__ = os;
85
+ }
86
+ /**
87
+ * Try to initialize platform from react-native if available
88
+ * This is called lazily when needed, avoiding top-level imports
89
+ */
90
+ export async function initPlatformFromReactNative() {
91
+ if (cachedPlatform !== null && cachedPlatform !== 'unknown') {
92
+ return; // Already initialized
93
+ }
94
+ try {
95
+ // Dynamic import to avoid bundler issues
96
+ const { Platform } = await import('react-native');
97
+ setPlatformOS(Platform.OS);
98
+ }
99
+ catch {
100
+ // react-native not available, use detected platform
101
+ }
102
+ }