@webority/mobile-core 0.0.29 → 0.2.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 (242) hide show
  1. package/README.md +32 -0
  2. package/lib/commonjs/api/baseUrl.js +1 -34
  3. package/lib/commonjs/api/clientHeaders.js +1 -0
  4. package/lib/commonjs/api/curl.js +1 -109
  5. package/lib/commonjs/api/minAppVersion.js +1 -0
  6. package/lib/commonjs/api/multipart.js +1 -21
  7. package/lib/commonjs/api/publicClient.js +1 -79
  8. package/lib/commonjs/api/requestDefaults.js +1 -0
  9. package/lib/commonjs/api/responseBodyText.js +1 -0
  10. package/lib/commonjs/api/retry.js +1 -91
  11. package/lib/commonjs/api/tokenRefresh.js +1 -205
  12. package/lib/commonjs/api/userClient.js +1 -265
  13. package/lib/commonjs/auth/authStore.js +1 -265
  14. package/lib/commonjs/auth/index.js +1 -44
  15. package/lib/commonjs/auth/jwt.js +1 -112
  16. package/lib/commonjs/config/index.js +1 -72
  17. package/lib/commonjs/deepLink/index.js +1 -286
  18. package/lib/commonjs/download/adapters/expoFs.js +1 -69
  19. package/lib/commonjs/download/adapters/shared.js +1 -13
  20. package/lib/commonjs/download/index.js +1 -250
  21. package/lib/commonjs/errors/extractApiError.js +1 -0
  22. package/lib/commonjs/errors/index.js +1 -0
  23. package/lib/commonjs/formatters/currency.js +1 -70
  24. package/lib/commonjs/formatters/date.js +1 -167
  25. package/lib/commonjs/formatters/dateMath.js +1 -311
  26. package/lib/commonjs/formatters/formatConfig.js +1 -0
  27. package/lib/commonjs/formatters/house.js +1 -0
  28. package/lib/commonjs/formatters/index.js +1 -246
  29. package/lib/commonjs/formatters/initials.js +1 -32
  30. package/lib/commonjs/formatters/intlCache.js +1 -37
  31. package/lib/commonjs/formatters/number.js +1 -89
  32. package/lib/commonjs/formatters/phone.js +1 -369
  33. package/lib/commonjs/formatters/windowsToIanaTable.js +1 -164
  34. package/lib/commonjs/geolocation/adapters/expoLocation.js +1 -126
  35. package/lib/commonjs/geolocation/index.js +1 -355
  36. package/lib/commonjs/index.js +1 -644
  37. package/lib/commonjs/initSDK.js +1 -66
  38. package/lib/commonjs/initUserAuth.js +1 -37
  39. package/lib/commonjs/logger/crashlytics.js +1 -0
  40. package/lib/commonjs/logger/index.js +1 -301
  41. package/lib/commonjs/logger/redact.js +1 -50
  42. package/lib/commonjs/network/index.js +1 -31
  43. package/lib/commonjs/network/networkStatus.js +1 -171
  44. package/lib/commonjs/permissions/calendar.js +1 -14
  45. package/lib/commonjs/permissions/camera.js +1 -14
  46. package/lib/commonjs/permissions/contacts.js +1 -10
  47. package/lib/commonjs/permissions/index.js +1 -133
  48. package/lib/commonjs/permissions/location.js +1 -14
  49. package/lib/commonjs/permissions/mediaLibrary.js +1 -10
  50. package/lib/commonjs/permissions/notifications.js +1 -10
  51. package/lib/commonjs/permissions/photos.js +1 -14
  52. package/lib/commonjs/phone/countries.js +1 -265
  53. package/lib/commonjs/push/index.js +1 -61
  54. package/lib/commonjs/push/push.js +1 -468
  55. package/lib/commonjs/push/status.js +1 -0
  56. package/lib/commonjs/push/task.js +1 -43
  57. package/lib/commonjs/query/apiBaseQuery.js +1 -0
  58. package/lib/commonjs/query/createAppApi.js +1 -0
  59. package/lib/commonjs/query/index.js +1 -0
  60. package/lib/commonjs/query/listeners.js +1 -0
  61. package/lib/commonjs/query/paging.js +1 -0
  62. package/lib/commonjs/query/tags.js +1 -0
  63. package/lib/commonjs/redux/errorToastMiddleware.js +1 -0
  64. package/lib/commonjs/redux/index.js +1 -0
  65. package/lib/commonjs/redux/rootReducer.js +1 -0
  66. package/lib/commonjs/redux/serializableCheck.js +1 -0
  67. package/lib/commonjs/secureScreen/index.js +1 -0
  68. package/lib/commonjs/share/index.js +1 -70
  69. package/lib/commonjs/smsRetriever/index.js +1 -91
  70. package/lib/commonjs/specs/NativeSmsRetriever.js +1 -15
  71. package/lib/commonjs/sqlite/adapters/expo.js +1 -53
  72. package/lib/commonjs/sqlite/index.js +1 -604
  73. package/lib/commonjs/storage/index.js +1 -214
  74. package/lib/commonjs/types/axios.js +1 -4
  75. package/lib/commonjs/types/globals.d.js +1 -6
  76. package/lib/commonjs/utils/base64.js +1 -24
  77. package/lib/commonjs/utils/imageCompression.js +1 -389
  78. package/lib/commonjs/utils/index.js +1 -19
  79. package/lib/commonjs/validators/index.js +1 -227
  80. package/lib/commonjs/versionCheck/buildNumber.js +1 -0
  81. package/lib/commonjs/versionCheck/index.js +1 -419
  82. package/lib/module/api/baseUrl.js +1 -30
  83. package/lib/module/api/clientHeaders.js +1 -0
  84. package/lib/module/api/curl.js +1 -104
  85. package/lib/module/api/minAppVersion.js +1 -0
  86. package/lib/module/api/multipart.js +1 -16
  87. package/lib/module/api/publicClient.js +1 -75
  88. package/lib/module/api/requestDefaults.js +1 -0
  89. package/lib/module/api/responseBodyText.js +1 -0
  90. package/lib/module/api/retry.js +1 -85
  91. package/lib/module/api/tokenRefresh.js +1 -192
  92. package/lib/module/api/userClient.js +1 -243
  93. package/lib/module/auth/authStore.js +1 -257
  94. package/lib/module/auth/index.js +1 -5
  95. package/lib/module/auth/jwt.js +1 -106
  96. package/lib/module/config/index.js +1 -64
  97. package/lib/module/deepLink/index.js +1 -280
  98. package/lib/module/download/adapters/expoFs.js +1 -64
  99. package/lib/module/download/adapters/shared.js +1 -8
  100. package/lib/module/download/index.js +1 -242
  101. package/lib/module/errors/extractApiError.js +1 -0
  102. package/lib/module/errors/index.js +1 -0
  103. package/lib/module/formatters/currency.js +1 -65
  104. package/lib/module/formatters/date.js +1 -159
  105. package/lib/module/formatters/dateMath.js +1 -295
  106. package/lib/module/formatters/formatConfig.js +1 -0
  107. package/lib/module/formatters/house.js +1 -0
  108. package/lib/module/formatters/index.js +1 -9
  109. package/lib/module/formatters/initials.js +1 -27
  110. package/lib/module/formatters/intlCache.js +1 -30
  111. package/lib/module/formatters/number.js +1 -82
  112. package/lib/module/formatters/phone.js +1 -302
  113. package/lib/module/formatters/windowsToIanaTable.js +1 -160
  114. package/lib/module/geolocation/adapters/expoLocation.js +1 -121
  115. package/lib/module/geolocation/index.js +1 -347
  116. package/lib/module/index.js +1 -57
  117. package/lib/module/initSDK.js +1 -61
  118. package/lib/module/initUserAuth.js +1 -33
  119. package/lib/module/logger/crashlytics.js +1 -0
  120. package/lib/module/logger/index.js +1 -295
  121. package/lib/module/logger/redact.js +1 -44
  122. package/lib/module/network/index.js +1 -4
  123. package/lib/module/network/networkStatus.js +1 -161
  124. package/lib/module/permissions/calendar.js +1 -15
  125. package/lib/module/permissions/camera.js +1 -15
  126. package/lib/module/permissions/contacts.js +1 -11
  127. package/lib/module/permissions/index.js +1 -128
  128. package/lib/module/permissions/location.js +1 -15
  129. package/lib/module/permissions/mediaLibrary.js +1 -11
  130. package/lib/module/permissions/notifications.js +1 -11
  131. package/lib/module/permissions/photos.js +1 -15
  132. package/lib/module/phone/countries.js +1 -261
  133. package/lib/module/push/index.js +1 -4
  134. package/lib/module/push/push.js +1 -452
  135. package/lib/module/push/status.js +1 -0
  136. package/lib/module/push/task.js +1 -38
  137. package/lib/module/query/apiBaseQuery.js +1 -0
  138. package/lib/module/query/createAppApi.js +1 -0
  139. package/lib/module/query/index.js +1 -0
  140. package/lib/module/query/listeners.js +1 -0
  141. package/lib/module/query/paging.js +1 -0
  142. package/lib/module/query/tags.js +1 -0
  143. package/lib/module/redux/errorToastMiddleware.js +1 -0
  144. package/lib/module/redux/index.js +1 -0
  145. package/lib/module/redux/rootReducer.js +1 -0
  146. package/lib/module/redux/serializableCheck.js +1 -0
  147. package/lib/module/secureScreen/index.js +1 -0
  148. package/lib/module/share/index.js +1 -64
  149. package/lib/module/smsRetriever/index.js +1 -86
  150. package/lib/module/specs/NativeSmsRetriever.js +1 -13
  151. package/lib/module/sqlite/adapters/expo.js +1 -48
  152. package/lib/module/sqlite/index.js +1 -594
  153. package/lib/module/storage/index.js +1 -208
  154. package/lib/module/types/axios.js +1 -4
  155. package/lib/module/types/globals.d.js +1 -10
  156. package/lib/module/utils/base64.js +1 -19
  157. package/lib/module/utils/imageCompression.js +1 -383
  158. package/lib/module/utils/index.js +1 -4
  159. package/lib/module/validators/index.js +1 -205
  160. package/lib/module/versionCheck/buildNumber.js +1 -0
  161. package/lib/module/versionCheck/index.js +1 -413
  162. package/lib/typescript/commonjs/api/clientHeaders.d.ts +25 -0
  163. package/lib/typescript/commonjs/api/minAppVersion.d.ts +24 -0
  164. package/lib/typescript/commonjs/api/requestDefaults.d.ts +21 -0
  165. package/lib/typescript/commonjs/api/responseBodyText.d.ts +6 -0
  166. package/lib/typescript/commonjs/api/retry.d.ts +23 -9
  167. package/lib/typescript/commonjs/api/tokenRefresh.d.ts +14 -2
  168. package/lib/typescript/commonjs/api/userClient.d.ts +1 -1
  169. package/lib/typescript/commonjs/auth/authStore.d.ts +76 -0
  170. package/lib/typescript/commonjs/auth/index.d.ts +2 -2
  171. package/lib/typescript/commonjs/config/index.d.ts +31 -2
  172. package/lib/typescript/commonjs/errors/extractApiError.d.ts +69 -0
  173. package/lib/typescript/commonjs/errors/index.d.ts +3 -0
  174. package/lib/typescript/commonjs/formatters/currency.d.ts +22 -7
  175. package/lib/typescript/commonjs/formatters/date.d.ts +13 -13
  176. package/lib/typescript/commonjs/formatters/dateMath.d.ts +4 -2
  177. package/lib/typescript/commonjs/formatters/formatConfig.d.ts +48 -0
  178. package/lib/typescript/commonjs/formatters/house.d.ts +143 -0
  179. package/lib/typescript/commonjs/formatters/index.d.ts +4 -0
  180. package/lib/typescript/commonjs/formatters/number.d.ts +15 -5
  181. package/lib/typescript/commonjs/index.d.ts +26 -8
  182. package/lib/typescript/commonjs/initSDK.d.ts +18 -6
  183. package/lib/typescript/commonjs/initUserAuth.d.ts +29 -0
  184. package/lib/typescript/commonjs/logger/crashlytics.d.ts +31 -0
  185. package/lib/typescript/commonjs/logger/index.d.ts +17 -0
  186. package/lib/typescript/commonjs/push/index.d.ts +3 -1
  187. package/lib/typescript/commonjs/push/push.d.ts +1 -1
  188. package/lib/typescript/commonjs/push/status.d.ts +9 -0
  189. package/lib/typescript/commonjs/query/apiBaseQuery.d.ts +55 -0
  190. package/lib/typescript/commonjs/query/createAppApi.d.ts +21 -0
  191. package/lib/typescript/commonjs/query/index.d.ts +9 -0
  192. package/lib/typescript/commonjs/query/listeners.d.ts +11 -0
  193. package/lib/typescript/commonjs/query/paging.d.ts +42 -0
  194. package/lib/typescript/commonjs/query/tags.d.ts +31 -0
  195. package/lib/typescript/commonjs/redux/errorToastMiddleware.d.ts +51 -0
  196. package/lib/typescript/commonjs/redux/index.d.ts +6 -0
  197. package/lib/typescript/commonjs/redux/rootReducer.d.ts +19 -0
  198. package/lib/typescript/commonjs/redux/serializableCheck.d.ts +14 -0
  199. package/lib/typescript/commonjs/secureScreen/index.d.ts +25 -0
  200. package/lib/typescript/commonjs/versionCheck/buildNumber.d.ts +14 -0
  201. package/lib/typescript/commonjs/versionCheck/index.d.ts +28 -17
  202. package/lib/typescript/module/api/clientHeaders.d.ts +25 -0
  203. package/lib/typescript/module/api/minAppVersion.d.ts +24 -0
  204. package/lib/typescript/module/api/requestDefaults.d.ts +21 -0
  205. package/lib/typescript/module/api/responseBodyText.d.ts +6 -0
  206. package/lib/typescript/module/api/retry.d.ts +23 -9
  207. package/lib/typescript/module/api/tokenRefresh.d.ts +14 -2
  208. package/lib/typescript/module/api/userClient.d.ts +1 -1
  209. package/lib/typescript/module/auth/authStore.d.ts +76 -0
  210. package/lib/typescript/module/auth/index.d.ts +2 -2
  211. package/lib/typescript/module/config/index.d.ts +31 -2
  212. package/lib/typescript/module/errors/extractApiError.d.ts +69 -0
  213. package/lib/typescript/module/errors/index.d.ts +3 -0
  214. package/lib/typescript/module/formatters/currency.d.ts +22 -7
  215. package/lib/typescript/module/formatters/date.d.ts +13 -13
  216. package/lib/typescript/module/formatters/dateMath.d.ts +4 -2
  217. package/lib/typescript/module/formatters/formatConfig.d.ts +48 -0
  218. package/lib/typescript/module/formatters/house.d.ts +143 -0
  219. package/lib/typescript/module/formatters/index.d.ts +4 -0
  220. package/lib/typescript/module/formatters/number.d.ts +15 -5
  221. package/lib/typescript/module/index.d.ts +26 -8
  222. package/lib/typescript/module/initSDK.d.ts +18 -6
  223. package/lib/typescript/module/initUserAuth.d.ts +29 -0
  224. package/lib/typescript/module/logger/crashlytics.d.ts +31 -0
  225. package/lib/typescript/module/logger/index.d.ts +17 -0
  226. package/lib/typescript/module/push/index.d.ts +3 -1
  227. package/lib/typescript/module/push/push.d.ts +1 -1
  228. package/lib/typescript/module/push/status.d.ts +9 -0
  229. package/lib/typescript/module/query/apiBaseQuery.d.ts +55 -0
  230. package/lib/typescript/module/query/createAppApi.d.ts +21 -0
  231. package/lib/typescript/module/query/index.d.ts +9 -0
  232. package/lib/typescript/module/query/listeners.d.ts +11 -0
  233. package/lib/typescript/module/query/paging.d.ts +42 -0
  234. package/lib/typescript/module/query/tags.d.ts +31 -0
  235. package/lib/typescript/module/redux/errorToastMiddleware.d.ts +51 -0
  236. package/lib/typescript/module/redux/index.d.ts +6 -0
  237. package/lib/typescript/module/redux/rootReducer.d.ts +19 -0
  238. package/lib/typescript/module/redux/serializableCheck.d.ts +14 -0
  239. package/lib/typescript/module/secureScreen/index.d.ts +25 -0
  240. package/lib/typescript/module/versionCheck/buildNumber.d.ts +14 -0
  241. package/lib/typescript/module/versionCheck/index.d.ts +28 -17
  242. package/package.json +52 -5
@@ -1,227 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.minLength = exports.maxLength = exports.isUrl = exports.isStrongPassword = exports.isPhone = exports.isPan = exports.isNumeric = exports.isNonEmpty = exports.isInteger = exports.isIndianPincode = exports.isIndianMobile = exports.isIfsc = exports.isHexColor = exports.isGstin = exports.isEmail = exports.isBetween = exports.isAlphanumeric = exports.isAadhaar = void 0;
7
- /**
8
- * Generic validators returning `boolean`. All accept `null`/`undefined` safely.
9
- *
10
- * Tradeoff: regexes are pragmatic, not RFC-strict. They reject the things real users
11
- * typo and accept the long tail of legitimate inputs. For RFC-grade validation use
12
- * a dedicated library at the boundary.
13
- */
14
-
15
- const RE_EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
16
- const RE_INDIAN_MOBILE = /^[6-9]\d{9}$/;
17
- const RE_NUMERIC = /^-?\d+(?:\.\d+)?$/;
18
- const RE_INTEGER = /^-?\d+$/;
19
- const RE_ALPHANUMERIC = /^[a-zA-Z0-9]+$/;
20
- const RE_PINCODE_IN = /^[1-9]\d{5}$/;
21
- const RE_PAN = /^[A-Z]{5}\d{4}[A-Z]$/;
22
- const RE_GSTIN = /^\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/;
23
- // UIDAI issues no Aadhaar number starting 0 or 1.
24
- const RE_AADHAAR = /^[2-9]\d{11}$/;
25
- const RE_IFSC = /^[A-Z]{4}0[A-Z0-9]{6}$/;
26
- const RE_HEX_COLOR = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
27
- const asString = v => {
28
- if (typeof v === 'string') {
29
- return v.trim();
30
- }
31
- return null;
32
- };
33
- const isNonEmpty = value => {
34
- const s = asString(value);
35
- return !!s && s.length > 0;
36
- };
37
- exports.isNonEmpty = isNonEmpty;
38
- const isEmail = value => {
39
- const s = asString(value);
40
- return !!s && RE_EMAIL.test(s);
41
- };
42
-
43
- /**
44
- * Validate an Indian mobile number. Accepts:
45
- * - 10-digit number starting with 6-9
46
- * - Optional `+91` or `91` country code prefix
47
- */
48
- exports.isEmail = isEmail;
49
- const isIndianMobile = value => {
50
- const s = asString(value);
51
- if (!s) {
52
- return false;
53
- }
54
- const digits = s.replace(/\D/g, '');
55
- const tail = digits.startsWith('91') && digits.length === 12 ? digits.slice(2) : digits;
56
- return RE_INDIAN_MOBILE.test(tail);
57
- };
58
-
59
- /**
60
- * Generic phone validator: 7–15 digits, optional `+` prefix.
61
- * Use `isIndianMobile` when you specifically need an Indian mobile number.
62
- */
63
- exports.isIndianMobile = isIndianMobile;
64
- const isPhone = value => {
65
- const s = asString(value);
66
- if (!s) {
67
- return false;
68
- }
69
- const digits = s.replace(/[^\d+]/g, '').replace(/^\+/, '');
70
- return digits.length >= 7 && digits.length <= 15 && /^\d+$/.test(digits);
71
- };
72
- exports.isPhone = isPhone;
73
- const isUrl = value => {
74
- const s = asString(value);
75
- if (!s) {
76
- return false;
77
- }
78
- try {
79
- // URL constructor is available on Hermes & JSC.
80
-
81
- new URL(s);
82
- return /^https?:\/\//i.test(s) || /^[a-z][a-z0-9+\-.]*:\/\//i.test(s);
83
- } catch {
84
- return false;
85
- }
86
- };
87
- exports.isUrl = isUrl;
88
- const isNumeric = value => {
89
- if (typeof value === 'number') {
90
- return Number.isFinite(value);
91
- }
92
- const s = asString(value);
93
- return !!s && RE_NUMERIC.test(s);
94
- };
95
- exports.isNumeric = isNumeric;
96
- const isInteger = value => {
97
- if (typeof value === 'number') {
98
- return Number.isInteger(value);
99
- }
100
- const s = asString(value);
101
- return !!s && RE_INTEGER.test(s);
102
- };
103
- exports.isInteger = isInteger;
104
- const isAlphanumeric = value => {
105
- const s = asString(value);
106
- return !!s && RE_ALPHANUMERIC.test(s);
107
- };
108
- exports.isAlphanumeric = isAlphanumeric;
109
- /**
110
- * Common password complexity check. Defaults to 8+ chars,
111
- * one uppercase, one lowercase, one digit.
112
- */
113
- const isStrongPassword = (value, rules = {}) => {
114
- if (typeof value !== 'string') {
115
- return false;
116
- }
117
- const {
118
- minLength = 8,
119
- requireUppercase = true,
120
- requireLowercase = true,
121
- requireNumber = true,
122
- requireSymbol = false
123
- } = rules;
124
- if (value.length < minLength) {
125
- return false;
126
- }
127
- if (requireUppercase && !/[A-Z]/.test(value)) {
128
- return false;
129
- }
130
- if (requireLowercase && !/[a-z]/.test(value)) {
131
- return false;
132
- }
133
- if (requireNumber && !/\d/.test(value)) {
134
- return false;
135
- }
136
- if (requireSymbol && !/[^A-Za-z0-9]/.test(value)) {
137
- return false;
138
- }
139
- return true;
140
- };
141
- exports.isStrongPassword = isStrongPassword;
142
- const isIndianPincode = value => {
143
- const s = asString(value);
144
- return !!s && RE_PINCODE_IN.test(s);
145
- };
146
- exports.isIndianPincode = isIndianPincode;
147
- const isPan = value => {
148
- const s = asString(value);
149
- return !!s && RE_PAN.test(s.toUpperCase());
150
- };
151
- exports.isPan = isPan;
152
- const BASE_36 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
153
-
154
- /**
155
- * The GSTN check character: each of the first fourteen characters' base-36
156
- * value times a weight alternating 1 and 2, the product's quotient and
157
- * remainder by 36 summed; the check character makes the total a multiple of 36.
158
- */
159
- const gstinCheckCharacter = gstin => {
160
- let sum = 0;
161
- for (let i = 0; i < 14; i += 1) {
162
- const product = BASE_36.indexOf(gstin[i]) * (i % 2 === 0 ? 1 : 2);
163
- sum += Math.floor(product / 36) + product % 36;
164
- }
165
- return BASE_36[(36 - sum % 36) % 36];
166
- };
167
- const isGstin = value => {
168
- const s = asString(value)?.toUpperCase();
169
- return !!s && RE_GSTIN.test(s) && s[14] === gstinCheckCharacter(s);
170
- };
171
- exports.isGstin = isGstin;
172
- const VERHOEFF_D = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 0, 6, 7, 8, 9, 5], [2, 3, 4, 0, 1, 7, 8, 9, 5, 6], [3, 4, 0, 1, 2, 8, 9, 5, 6, 7], [4, 0, 1, 2, 3, 9, 5, 6, 7, 8], [5, 9, 8, 7, 6, 0, 4, 3, 2, 1], [6, 5, 9, 8, 7, 1, 0, 4, 3, 2], [7, 6, 5, 9, 8, 2, 1, 0, 4, 3], [8, 7, 6, 5, 9, 3, 2, 1, 0, 4], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]];
173
- const VERHOEFF_P = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 5, 7, 6, 2, 8, 3, 0, 9, 4], [5, 8, 0, 3, 7, 9, 6, 1, 4, 2], [8, 9, 1, 6, 0, 4, 3, 5, 2, 7], [9, 4, 5, 3, 1, 2, 6, 8, 7, 0], [4, 2, 8, 6, 5, 7, 3, 9, 0, 1], [2, 7, 9, 3, 8, 0, 6, 4, 1, 5], [7, 0, 4, 6, 9, 1, 3, 2, 5, 8]];
174
-
175
- /** Verhoeff (dihedral group D5): valid when the running product over the reversed digits is 0. */
176
- const isVerhoeffValid = digits => {
177
- let check = 0;
178
- for (let i = 0; i < digits.length; i += 1) {
179
- const digit = Number(digits[digits.length - 1 - i]);
180
- check = VERHOEFF_D[check][VERHOEFF_P[i % 8][digit]];
181
- }
182
- return check === 0;
183
- };
184
-
185
- /**
186
- * The same rules the Webority servers apply: spaces and hyphens stripped (as
187
- * printed on the card), twelve digits, no leading 0 or 1, and a correct
188
- * Verhoeff check digit.
189
- */
190
- const isAadhaar = value => {
191
- const s = asString(value);
192
- if (!s) {
193
- return false;
194
- }
195
- const digits = s.replace(/[\s-]/g, '');
196
- return RE_AADHAAR.test(digits) && isVerhoeffValid(digits);
197
- };
198
- exports.isAadhaar = isAadhaar;
199
- const isIfsc = value => {
200
- const s = asString(value);
201
- return !!s && RE_IFSC.test(s.toUpperCase());
202
- };
203
- exports.isIfsc = isIfsc;
204
- const isHexColor = value => {
205
- const s = asString(value);
206
- return !!s && RE_HEX_COLOR.test(s);
207
- };
208
- exports.isHexColor = isHexColor;
209
- const isBetween = (value, min, max, inclusive = true) => {
210
- const n = typeof value === 'number' ? value : Number(asString(value));
211
- if (!Number.isFinite(n)) {
212
- return false;
213
- }
214
- return inclusive ? n >= min && n <= max : n > min && n < max;
215
- };
216
- exports.isBetween = isBetween;
217
- const minLength = (value, length) => {
218
- const s = asString(value);
219
- return !!s && s.length >= length;
220
- };
221
- exports.minLength = minLength;
222
- const maxLength = (value, length) => {
223
- const s = asString(value);
224
- return s == null ? true : s.length <= length;
225
- };
226
- exports.maxLength = maxLength;
227
- //# sourceMappingURL=index.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.minLength=exports.maxLength=exports.isUrl=exports.isStrongPassword=exports.isPhone=exports.isPan=exports.isNumeric=exports.isNonEmpty=exports.isInteger=exports.isIndianPincode=exports.isIndianMobile=exports.isIfsc=exports.isHexColor=exports.isGstin=exports.isEmail=exports.isBetween=exports.isAlphanumeric=exports.isAadhaar=void 0;const RE_EMAIL=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,RE_INDIAN_MOBILE=/^[6-9]\d{9}$/,RE_NUMERIC=/^-?\d+(?:\.\d+)?$/,RE_INTEGER=/^-?\d+$/,RE_ALPHANUMERIC=/^[a-zA-Z0-9]+$/,RE_PINCODE_IN=/^[1-9]\d{5}$/,RE_PAN=/^[A-Z]{5}\d{4}[A-Z]$/,RE_GSTIN=/^\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/,RE_AADHAAR=/^[2-9]\d{11}$/,RE_IFSC=/^[A-Z]{4}0[A-Z0-9]{6}$/,RE_HEX_COLOR=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,asString=t=>"string"==typeof t?t.trim():null,isNonEmpty=t=>{const s=asString(t);return!!s&&s.length>0};exports.isNonEmpty=isNonEmpty;const isEmail=t=>{const s=asString(t);return!!s&&RE_EMAIL.test(s)};exports.isEmail=isEmail;const isIndianMobile=t=>{const s=asString(t);if(!s)return!1;const e=s.replace(/\D/g,""),r=e.startsWith("91")&&12===e.length?e.slice(2):e;return RE_INDIAN_MOBILE.test(r)};exports.isIndianMobile=isIndianMobile;const isPhone=t=>{const s=asString(t);if(!s)return!1;const e=s.replace(/[^\d+]/g,"").replace(/^\+/,"");return e.length>=7&&e.length<=15&&/^\d+$/.test(e)};exports.isPhone=isPhone;const isUrl=t=>{const s=asString(t);if(!s)return!1;try{return new URL(s),/^https?:\/\//i.test(s)||/^[a-z][a-z0-9+\-.]*:\/\//i.test(s)}catch{return!1}};exports.isUrl=isUrl;const isNumeric=t=>{if("number"==typeof t)return Number.isFinite(t);const s=asString(t);return!!s&&RE_NUMERIC.test(s)};exports.isNumeric=isNumeric;const isInteger=t=>{if("number"==typeof t)return Number.isInteger(t);const s=asString(t);return!!s&&RE_INTEGER.test(s)};exports.isInteger=isInteger;const isAlphanumeric=t=>{const s=asString(t);return!!s&&RE_ALPHANUMERIC.test(s)};exports.isAlphanumeric=isAlphanumeric;const isStrongPassword=(t,s={})=>{if("string"!=typeof t)return!1;const{minLength:e=8,requireUppercase:r=!0,requireLowercase:n=!0,requireNumber:i=!0,requireSymbol:o=!1}=s;return!(t.length<e)&&(!(r&&!/[A-Z]/.test(t))&&(!(n&&!/[a-z]/.test(t))&&(!(i&&!/\d/.test(t))&&!(o&&!/[^A-Za-z0-9]/.test(t)))))};exports.isStrongPassword=isStrongPassword;const isIndianPincode=t=>{const s=asString(t);return!!s&&RE_PINCODE_IN.test(s)};exports.isIndianPincode=isIndianPincode;const isPan=t=>{const s=asString(t);return!!s&&RE_PAN.test(s.toUpperCase())};exports.isPan=isPan;const BASE_36="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",gstinCheckCharacter=t=>{let s=0;for(let e=0;e<14;e+=1){const r=BASE_36.indexOf(t[e])*(e%2==0?1:2);s+=Math.floor(r/36)+r%36}return BASE_36[(36-s%36)%36]},isGstin=t=>{const s=asString(t)?.toUpperCase();return!!s&&RE_GSTIN.test(s)&&s[14]===gstinCheckCharacter(s)};exports.isGstin=isGstin;const VERHOEFF_D=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],VERHOEFF_P=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],isVerhoeffValid=t=>{let s=0;for(let e=0;e<t.length;e+=1){const r=Number(t[t.length-1-e]);s=VERHOEFF_D[s][VERHOEFF_P[e%8][r]]}return 0===s},isAadhaar=t=>{const s=asString(t);if(!s)return!1;const e=s.replace(/[\s-]/g,"");return RE_AADHAAR.test(e)&&isVerhoeffValid(e)};exports.isAadhaar=isAadhaar;const isIfsc=t=>{const s=asString(t);return!!s&&RE_IFSC.test(s.toUpperCase())};exports.isIfsc=isIfsc;const isHexColor=t=>{const s=asString(t);return!!s&&RE_HEX_COLOR.test(s)};exports.isHexColor=isHexColor;const isBetween=(t,s,e,r=!0)=>{const n="number"==typeof t?t:Number(asString(t));return!!Number.isFinite(n)&&(r?n>=s&&n<=e:n>s&&n<e)};exports.isBetween=isBetween;const minLength=(t,s)=>{const e=asString(t);return!!e&&e.length>=s};exports.minLength=minLength;const maxLength=(t,s)=>{const e=asString(t);return null==e||e.length<=s};exports.maxLength=maxLength;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.parseBuildNumber=exports.isBuildBelowMinimum=void 0;const parseBuildNumber=e=>{if("number"==typeof e)return Number.isSafeInteger(e)&&e>=0?e:null;if("string"!=typeof e)return null;const r=e.trim();if(!/^\d+$/.test(r))return null;const u=Number(r);return Number.isSafeInteger(u)?u:null};exports.parseBuildNumber=parseBuildNumber;const isBuildBelowMinimum=(e,r)=>null!==r&&e<r;exports.isBuildBelowMinimum=isBuildBelowMinimum;
@@ -1,419 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useVersionCheck = exports.setDeviceInfoImplementation = exports.default = exports.VersionCheck = void 0;
7
- var Application = _interopRequireWildcard(require("expo-application"));
8
- var _react = require("react");
9
- var _index = require("../config/index.js");
10
- var _index2 = require("../logger/index.js");
11
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
- // Type-only — erased at compile time; react-native stays lazily required below.
13
-
14
- /**
15
- * Minimal device-info shape we depend on.
16
- *
17
- * This is a LAST RESORT, not the primary path. `Platform.OS` already gives the
18
- * platform, and every Webority app carries its own store id and version in
19
- * `appsettings.Compiled.json` — so `setConfig({ appId, appVersion })` covers
20
- * both remaining values without a native module. The injector below exists for
21
- * apps that would rather hand us a `react-native-device-info` instance than
22
- * wire two config keys.
23
- */
24
-
25
- /**
26
- * expo-application, read at call time.
27
- *
28
- * `applicationId` and `nativeApplicationVersion` are module CONSTANTS rather
29
- * than functions, so they are read inside the accessors rather than captured
30
- * here — capturing would snapshot them before the native module has
31
- * initialised.
32
- *
33
- * `setConfig({ appId, appVersion })` still WINS over this: a Webority app
34
- * already carries both in appsettings.Compiled.json, and config is checked
35
- * first. This is the fallback for an app that would rather read its identity
36
- * from the binary it is actually running, which is the one place the two can
37
- * disagree.
38
- */
39
- const expoApplicationBackend = {
40
- getBundleId: () => Application.applicationId ?? '',
41
- getVersion: () => Application.nativeApplicationVersion ?? ''
42
- };
43
-
44
- /** Only what a test or the showcase injected; null means use expo-application. */
45
- let deviceInfo = null;
46
-
47
- /**
48
- * Supply the app identity from a native module instead of config.
49
- * Prefer `setConfig({ appId, appVersion })` — it needs no native dependency.
50
- * Pass `null` to clear.
51
- */
52
- const setDeviceInfoImplementation = impl => {
53
- deviceInfo = impl;
54
- };
55
- exports.setDeviceInfoImplementation = setDeviceInfoImplementation;
56
- const missing = (what, configKey) => {
57
- const err = new Error(`[VersionCheck] the app's ${what} is not available. Call ` + `setConfig({ ${configKey}: '...' }) — every Webority app already has this value in ` + 'appsettings.Compiled.json — or setDeviceInfoImplementation() with a native provider.');
58
- _index2.Logger.error(err.message);
59
- return err;
60
- };
61
-
62
- // Platform comes from React Native itself; there has never been a reason to
63
- // cross a native module boundary for it.
64
- const getSystemName = () => {
65
- const {
66
- Platform
67
- } = require('react-native');
68
- return Platform.OS;
69
- };
70
- const getBundleId = () => {
71
- const fromConfig = (0, _index.getConfigValue)('appId');
72
- if (fromConfig) {
73
- return fromConfig;
74
- }
75
- const fromDevice = (deviceInfo ?? expoApplicationBackend).getBundleId();
76
- if (fromDevice) {
77
- return fromDevice;
78
- }
79
- throw missing('store identifier', 'appId');
80
- };
81
- const getVersion = () => {
82
- const fromConfig = (0, _index.getConfigValue)('appVersion');
83
- if (fromConfig) {
84
- return fromConfig;
85
- }
86
- const fromDevice = (deviceInfo ?? expoApplicationBackend).getVersion();
87
- if (fromDevice) {
88
- return fromDevice;
89
- }
90
- throw missing('version', 'appVersion');
91
- };
92
-
93
- // Constants
94
- const MAX_RETRIES = 3;
95
- const RETRY_DELAY = 3000; // 3 seconds
96
-
97
- const getCountry = () => (0, _index.getConfigValue)('country', 'in').toLowerCase();
98
- // Utility function to parse and coerce version to a valid format
99
- const parseVersion = version => {
100
- _index2.Logger.info(`Parsing version: ${version}`);
101
- const coercedVersion = version.replace(/[^0-9.]/g, '');
102
- const versionParts = coercedVersion.split('.').map(Number);
103
- return {
104
- major: versionParts[0] || 0,
105
- minor: versionParts[1] || 0,
106
- patch: versionParts[2] || 0,
107
- prerelease: version.includes('-') ? version.split('-')[1] ?? '' : ''
108
- };
109
- };
110
-
111
- // Utility function to compare two versions loosely
112
- const diffLoose = (version1, version2) => {
113
- _index2.Logger.info(`Comparing versions: ${version1} and ${version2}`);
114
- if (version1 === version2) {
115
- return null;
116
- }
117
- const v1 = parseVersion(version1);
118
- const v2 = parseVersion(version2);
119
- if (v1.major < v2.major) {
120
- return 'major';
121
- }
122
- if (v1.major > v2.major) {
123
- return null;
124
- }
125
- if (v1.minor < v2.minor) {
126
- return 'minor';
127
- }
128
- if (v1.minor > v2.minor) {
129
- return null;
130
- }
131
- if (v1.patch < v2.patch) {
132
- return 'patch';
133
- }
134
- if (v1.patch > v2.patch) {
135
- return null;
136
- }
137
- if (v1.prerelease && !v2.prerelease) {
138
- return 'prerelease';
139
- }
140
- if (!v1.prerelease && v2.prerelease) {
141
- return null;
142
- }
143
- if (v1.prerelease < v2.prerelease) {
144
- return 'prerelease';
145
- }
146
- if (v1.prerelease > v2.prerelease) {
147
- return null;
148
- }
149
- return null;
150
- };
151
-
152
- // Function to compare current version with the latest version
153
- const versionCompare = (currentVersion, latestVersion) => {
154
- _index2.Logger.info(`Comparing current version: ${currentVersion} with latest version: ${latestVersion}`);
155
- if (!latestVersion) {
156
- return {
157
- needsUpdate: false,
158
- updateType: null,
159
- notice: 'Error: could not get latest version'
160
- };
161
- }
162
- try {
163
- const updateType = diffLoose(currentVersion, latestVersion);
164
- return {
165
- needsUpdate: !!updateType,
166
- updateType
167
- };
168
- } catch (e) {
169
- const message = e instanceof Error ? e.message : String(e);
170
- _index2.Logger.error(`Error comparing versions: ${message}`);
171
- const needsUpdate = currentVersion !== latestVersion && latestVersion > currentVersion;
172
- const updateType = needsUpdate ? 'minor' : null;
173
- return {
174
- needsUpdate,
175
- updateType,
176
- notice: message.replace(/^Invalid Version:/, 'Not a valid version:')
177
- };
178
- }
179
- };
180
-
181
- // Function to fetch version details from Google Play Store
182
- const fetchAndroidVersion = async url => {
183
- _index2.Logger.info(`Fetching Android version from URL: ${url}`);
184
- let response;
185
- try {
186
- response = await fetch(url, {
187
- headers: {
188
- 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.96 Mobile Safari/537.36',
189
- 'sec-fetch-site': 'same-origin'
190
- }
191
- });
192
- } catch (error) {
193
- const message = error instanceof Error ? error.message : String(error);
194
- _index2.Logger.error(`Error fetching data from Google Play Store: ${message}`);
195
- throw new Error('Error fetching data from Google Play Store.');
196
- }
197
- if (!response.ok) {
198
- if (response.status === 404) {
199
- _index2.Logger.error('App with app ID not found in Google Play.');
200
- throw new Error(`App with app ID not found in Google Play.`);
201
- }
202
- _index2.Logger.error(`Error fetching data: ${response.statusText}`);
203
- throw new Error(response.statusText);
204
- }
205
- const text = await response.text();
206
-
207
- // Primary regex pattern for current Play Store format
208
- let versionMatch = text.match(/\[\[\[['"]((\d+\.)+\d+)['"]\]\],/);
209
-
210
- // Alternate patterns as fallbacks
211
- if (!versionMatch) {
212
- // Fallback 1: Look for version in "current version" text
213
- versionMatch = text.match(/Current Version[^\d]+((\d+\.)+\d+)/i);
214
- }
215
- if (!versionMatch) {
216
- // Fallback 2: Look for itemprop="softwareVersion"
217
- versionMatch = text.match(/itemprop="softwareVersion"[^>]*>((\d+\.)+\d+)</i);
218
- }
219
- if (!versionMatch) {
220
- // Fallback 3: Try a more generic pattern for version numbers
221
- const allVersions = text.match(/(\d+\.\d+(\.\d+)?)/g);
222
- // If we found multiple version-like strings, use the first one
223
- versionMatch = allVersions && allVersions.length > 0 ? [null, allVersions[0]] : null;
224
- }
225
- const version = versionMatch ? versionMatch[1] ?? null : null;
226
- if (!version) {
227
- _index2.Logger.warn('Could not extract version from Play Store. Using fallback method.');
228
- }
229
- const notesMatch = text.match(/<div itemprop="description">(.*?)<\/div>/);
230
- const notes = notesMatch ? notesMatch[1] ?? '' : '';
231
- return {
232
- version,
233
- releasedAt: new Date().toISOString(),
234
- notes,
235
- url,
236
- lastChecked: new Date().toISOString()
237
- };
238
- };
239
- // Function to fetch version details from Apple App Store
240
- const fetchIosVersion = async url => {
241
- _index2.Logger.info(`Fetching iOS version from URL: ${url}`);
242
- let response;
243
- try {
244
- response = await fetch(url);
245
- } catch {
246
- _index2.Logger.error('Error connecting to iTunes.');
247
- throw new Error('Error connecting to iTunes.');
248
- }
249
- const data = await response.json();
250
- if (!data || !('results' in data)) {
251
- _index2.Logger.error('Unknown error connecting to iTunes.');
252
- throw new Error('Unknown error connecting to iTunes.');
253
- }
254
- if (!data.results.length) {
255
- _index2.Logger.error('App for this bundle ID not found.');
256
- throw new Error('App for this bundle ID not found.');
257
- }
258
- const result = data.results[0];
259
- return {
260
- version: result.version || null,
261
- released: result.currentVersionReleaseDate || result.releaseDate || null,
262
- notes: result.releaseNotes || '',
263
- url: result.trackViewUrl || result.artistViewUrl || result.sellerUrl || null,
264
- country: getCountry(),
265
- lastChecked: new Date().toISOString()
266
- };
267
- };
268
-
269
- // Function to lookup version based on platform
270
- const lookupVersion = async (platform, identifier) => {
271
- _index2.Logger.info(`Looking up version for platform: ${platform}, identifier: ${identifier}`);
272
- const country = getCountry();
273
- const url = platform === 'ios' ? `https://itunes.apple.com/lookup?bundleId=${identifier}&country=${country}&_=${new Date().valueOf()}` : `https://play.google.com/store/apps/details?id=${identifier}&hl=${country}`;
274
- return platform === 'ios' ? fetchIosVersion(url) : fetchAndroidVersion(url);
275
- };
276
-
277
- /**
278
- * Check for new version with retry logic
279
- */
280
- const checkForUpdates = async () => {
281
- const platform = getSystemName().toLowerCase();
282
- const identifier = getBundleId();
283
- const currentVersion = getVersion();
284
-
285
- // Implement retry mechanism
286
- let retryCount = 0;
287
- let lastError = null;
288
- while (retryCount <= MAX_RETRIES) {
289
- try {
290
- _index2.Logger.info(`Checking if new version is available (attempt ${retryCount + 1}/${MAX_RETRIES + 1})`);
291
- _index2.Logger.info(`Platform: ${platform}, identifier: ${identifier}, current version: ${currentVersion}`);
292
- const latestVersionInfo = await lookupVersion(platform, identifier);
293
- const comparison = versionCompare(currentVersion, latestVersionInfo.version);
294
- return {
295
- isNewVersionAvailable: comparison.needsUpdate,
296
- updateType: comparison.updateType,
297
- url: latestVersionInfo.url
298
- };
299
- } catch (error) {
300
- lastError = error;
301
- const message = error instanceof Error ? error.message : String(error);
302
- _index2.Logger.error(`Error checking version (attempt ${retryCount + 1}/${MAX_RETRIES + 1}): ${message}`);
303
-
304
- // If we've reached max retries, throw the last error
305
- if (retryCount === MAX_RETRIES) {
306
- throw error;
307
- }
308
-
309
- // Otherwise, wait and retry
310
- retryCount++;
311
- _index2.Logger.info(`Retrying version check in ${RETRY_DELAY}ms...`);
312
- await new Promise(resolve => setTimeout(resolve, RETRY_DELAY));
313
- }
314
- }
315
-
316
- // This should never be reached due to the throw above, but just in case
317
- throw lastError instanceof Error ? lastError : new Error('Failed to check for updates after multiple attempts');
318
- };
319
-
320
- /**
321
- * Get fallback store URL based on platform
322
- */
323
- const getFallbackStoreUrl = () => {
324
- const platform = getSystemName().toLowerCase();
325
- const bundleId = getBundleId();
326
- const country = getCountry();
327
- return platform === 'ios' ? `https://apps.apple.com/${country}/app/${bundleId}` : `https://play.google.com/store/apps/details?id=${bundleId}&hl=${country}`;
328
- };
329
- // Version check functionality
330
- const VersionCheck = exports.VersionCheck = {
331
- isNewVersionAvailable: async () => {
332
- return checkForUpdates();
333
- },
334
- openUpdateUrl: async url => {
335
- const {
336
- Linking
337
- } = require('react-native');
338
- try {
339
- if (url) {
340
- _index2.Logger.info(`Opening app store URL: ${url}`);
341
- await Linking.openURL(url);
342
- } else {
343
- const fallbackUrl = getFallbackStoreUrl();
344
- _index2.Logger.info(`Opening fallback store URL: ${fallbackUrl}`);
345
- await Linking.openURL(fallbackUrl);
346
- }
347
- return true;
348
- } catch (error) {
349
- const message = error instanceof Error ? error.message : String(error);
350
- _index2.Logger.error(`Failed to open store URL: ${message}`);
351
-
352
- // Try with fallback URL if the original failed
353
- try {
354
- if (url) {
355
- // Only try fallback if we were using a specific URL before
356
- const fallbackUrl = getFallbackStoreUrl();
357
- _index2.Logger.info(`Trying fallback store URL: ${fallbackUrl}`);
358
- await Linking.openURL(fallbackUrl);
359
- return true;
360
- }
361
- } catch (fallbackError) {
362
- const fbMessage = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
363
- _index2.Logger.error(`Failed to open fallback URL: ${fbMessage}`);
364
- }
365
- return false;
366
- }
367
- },
368
- getFallbackStoreUrl
369
- };
370
-
371
- /**
372
- * Custom hook to check for required app updates.
373
- *
374
- * @param isAppReady - Whether the app is ready to perform the check
375
- * @param environment - The app environment (defaults to the one in config)
376
- */
377
- const useVersionCheck = (isAppReady, environment = (0, _index.getConfigValue)('environment', 'Development')) => {
378
- const [updateInfo, setUpdateInfo] = (0, _react.useState)({
379
- isUpdateRequired: false,
380
- updateUrl: null
381
- });
382
- (0, _react.useEffect)(() => {
383
- let isMounted = true;
384
- const checkVersion = async () => {
385
- try {
386
- // All retry logic is handled in the VersionCheck module
387
- const {
388
- isNewVersionAvailable,
389
- url
390
- } = await VersionCheck.isNewVersionAvailable();
391
- if (isNewVersionAvailable && isMounted) {
392
- _index2.Logger.info('Update required. URL:', url || 'Not available yet');
393
- setUpdateInfo({
394
- isUpdateRequired: true,
395
- updateUrl: url
396
- });
397
- } else if (isMounted) {
398
- _index2.Logger.info('App is up to date');
399
- }
400
- } catch (error) {
401
- _index2.Logger.error('Error checking app version:', error);
402
- }
403
- };
404
-
405
- // Only run version check in Production environment when app is ready
406
- if (isAppReady && environment === 'Production') {
407
- void checkVersion();
408
- }
409
- return () => {
410
- isMounted = false;
411
- };
412
- }, [isAppReady, environment]);
413
- return updateInfo;
414
- };
415
-
416
- // Export for backward compatibility
417
- exports.useVersionCheck = useVersionCheck;
418
- var _default = exports.default = VersionCheck;
419
- //# sourceMappingURL=index.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.VersionCheck=void 0,Object.defineProperty(exports,"isBuildBelowMinimum",{enumerable:!0,get:function(){return _buildNumber.isBuildBelowMinimum}}),Object.defineProperty(exports,"parseBuildNumber",{enumerable:!0,get:function(){return _buildNumber.parseBuildNumber}}),exports.useVersionCheck=exports.setDeviceInfoImplementation=void 0;var Application=_interopRequireWildcard(require("expo-application")),_react=require("react"),_minAppVersion=require("../api/minAppVersion.js"),_index=require("../config/index.js"),_index2=require("../logger/index.js"),_buildNumber=require("./buildNumber.js");function _interopRequireWildcard(e,r){if("function"==typeof WeakMap)var i=new WeakMap,t=new WeakMap;return(_interopRequireWildcard=function(e,r){if(!r&&e&&e.__esModule)return e;var n,o,l={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return l;if(n=r?t:i){if(n.has(e))return n.get(e);n.set(e,l)}for(const r in e)"default"!==r&&{}.hasOwnProperty.call(e,r)&&((o=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,r))&&(o.get||o.set)?n(l,r,o):l[r]=e[r]);return l})(e,r)}const expoApplicationBackend={getBundleId:()=>Application.applicationId??"",getVersion:()=>Application.nativeApplicationVersion??"",getBuildNumber:()=>Application.nativeBuildVersion??""};let deviceInfo=null;const setDeviceInfoImplementation=e=>{deviceInfo=e};exports.setDeviceInfoImplementation=setDeviceInfoImplementation;const missing=(e,r)=>{const i=new Error(`[VersionCheck] the app's ${e} is not available. Call setConfig({ ${r}: ... }) — every Webority app already has this value in appsettings.Compiled.json — or setDeviceInfoImplementation() with a native provider.`);return _index2.Logger.error(i.message),i},getSystemName=()=>{const{Platform:e}=require("react-native");return e.OS},getBundleId=()=>{const e=(0,_index.getConfigValue)("appId");if(e)return e;const r=(deviceInfo??expoApplicationBackend).getBundleId();if(r)return r;throw missing("store identifier","appId")},getBuildNumber=()=>{const e=(0,_buildNumber.parseBuildNumber)((0,_index.getConfigValue)("appBuild"));if(null!==e)return e;const r=(0,_buildNumber.parseBuildNumber)(deviceInfo?.getBuildNumber?.()??expoApplicationBackend.getBuildNumber());if(null!==r)return r;throw missing("build number","appBuild")},getCountry=()=>(0,_index.getConfigValue)("country","in").toLowerCase(),subscribeMinimum=e=>(0,_minAppVersion.addMinAppVersionListener)(()=>e()),getFallbackStoreUrl=()=>{const e=getSystemName().toLowerCase(),r=getCountry();if("ios"===e){const e=(0,_index.getConfigValue)("appStoreId");return e?`https://apps.apple.com/${r}/app/id${e}`:`https://apps.apple.com/${r}/app/${getBundleId()}`}return`https://play.google.com/store/apps/details?id=${getBundleId()}&hl=${r}`},storeUrlOrNull=()=>{try{return getFallbackStoreUrl()}catch{return null}},checkForUpdates=()=>{const e=(0,_buildNumber.isBuildBelowMinimum)(getBuildNumber(),(0,_minAppVersion.getMinAppVersion)());return{isNewVersionAvailable:e,updateType:e?"major":null,url:e?storeUrlOrNull():null}},VersionCheck=exports.VersionCheck={isNewVersionAvailable:async()=>checkForUpdates(),openUpdateUrl:async e=>{const{Linking:r}=require("react-native");try{if(e)_index2.Logger.info(`Opening app store URL: ${e}`),await r.openURL(e);else{const e=getFallbackStoreUrl();_index2.Logger.info(`Opening fallback store URL: ${e}`),await r.openURL(e)}return!0}catch(i){const t=i instanceof Error?i.message:String(i);_index2.Logger.error(`Failed to open store URL: ${t}`);try{if(e){const e=getFallbackStoreUrl();return _index2.Logger.info(`Trying fallback store URL: ${e}`),await r.openURL(e),!0}}catch(e){const r=e instanceof Error?e.message:String(e);_index2.Logger.error(`Failed to open fallback URL: ${r}`)}return!1}},getFallbackStoreUrl:getFallbackStoreUrl},NOT_REQUIRED={isUpdateRequired:!1,updateUrl:null},useVersionCheck=(e,r=(0,_index.getConfigValue)("environment","Development"))=>{const i=(0,_react.useSyncExternalStore)(subscribeMinimum,_minAppVersion.getMinAppVersion,_minAppVersion.getMinAppVersion);return(0,_react.useMemo)(()=>{if(!e||"Production"!==r||null===i)return NOT_REQUIRED;try{if(!(0,_buildNumber.isBuildBelowMinimum)(getBuildNumber(),i))return NOT_REQUIRED}catch{return NOT_REQUIRED}return{isUpdateRequired:!0,updateUrl:storeUrlOrNull()}},[e,r,i])};exports.useVersionCheck=useVersionCheck;var _default=exports.default=VersionCheck;