@webority/mobile-core 0.0.23

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 (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/android/build.gradle +65 -0
  4. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/AppSignatureHelper.kt +57 -0
  5. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModule.kt +20 -0
  6. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModuleImpl.kt +146 -0
  7. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverPackage.kt +33 -0
  8. package/lib/commonjs/api/baseUrl.js +34 -0
  9. package/lib/commonjs/api/curl.js +109 -0
  10. package/lib/commonjs/api/publicClient.js +73 -0
  11. package/lib/commonjs/api/retry.js +75 -0
  12. package/lib/commonjs/api/tokenRefresh.js +205 -0
  13. package/lib/commonjs/api/userClient.js +255 -0
  14. package/lib/commonjs/auth/authStore.js +232 -0
  15. package/lib/commonjs/auth/index.js +44 -0
  16. package/lib/commonjs/auth/jwt.js +112 -0
  17. package/lib/commonjs/config/index.js +66 -0
  18. package/lib/commonjs/deepLink/index.js +286 -0
  19. package/lib/commonjs/download/adapters/expoFs.js +69 -0
  20. package/lib/commonjs/download/adapters/shared.js +13 -0
  21. package/lib/commonjs/download/index.js +250 -0
  22. package/lib/commonjs/formatters/currency.js +69 -0
  23. package/lib/commonjs/formatters/date.js +168 -0
  24. package/lib/commonjs/formatters/dateMath.js +310 -0
  25. package/lib/commonjs/formatters/index.js +246 -0
  26. package/lib/commonjs/formatters/initials.js +32 -0
  27. package/lib/commonjs/formatters/number.js +88 -0
  28. package/lib/commonjs/formatters/phone.js +369 -0
  29. package/lib/commonjs/formatters/windowsToIanaTable.js +164 -0
  30. package/lib/commonjs/geolocation/adapters/expoLocation.js +126 -0
  31. package/lib/commonjs/geolocation/index.js +355 -0
  32. package/lib/commonjs/index.js +630 -0
  33. package/lib/commonjs/initSDK.js +66 -0
  34. package/lib/commonjs/initUserAuth.js +37 -0
  35. package/lib/commonjs/logger/index.js +291 -0
  36. package/lib/commonjs/network/index.js +31 -0
  37. package/lib/commonjs/network/networkStatus.js +133 -0
  38. package/lib/commonjs/package.json +1 -0
  39. package/lib/commonjs/permissions/calendar.js +14 -0
  40. package/lib/commonjs/permissions/camera.js +14 -0
  41. package/lib/commonjs/permissions/contacts.js +10 -0
  42. package/lib/commonjs/permissions/index.js +133 -0
  43. package/lib/commonjs/permissions/location.js +14 -0
  44. package/lib/commonjs/permissions/mediaLibrary.js +10 -0
  45. package/lib/commonjs/permissions/notifications.js +10 -0
  46. package/lib/commonjs/permissions/photos.js +14 -0
  47. package/lib/commonjs/phone/countries.js +265 -0
  48. package/lib/commonjs/share/index.js +70 -0
  49. package/lib/commonjs/smsRetriever/index.js +91 -0
  50. package/lib/commonjs/specs/NativeSmsRetriever.js +15 -0
  51. package/lib/commonjs/sqlite/adapters/expo.js +53 -0
  52. package/lib/commonjs/sqlite/index.js +604 -0
  53. package/lib/commonjs/storage/index.js +214 -0
  54. package/lib/commonjs/types/globals.d.js +6 -0
  55. package/lib/commonjs/utils/imageCompression.js +389 -0
  56. package/lib/commonjs/utils/index.js +19 -0
  57. package/lib/commonjs/validators/index.js +227 -0
  58. package/lib/commonjs/versionCheck/index.js +419 -0
  59. package/lib/module/api/baseUrl.js +30 -0
  60. package/lib/module/api/curl.js +104 -0
  61. package/lib/module/api/publicClient.js +69 -0
  62. package/lib/module/api/retry.js +69 -0
  63. package/lib/module/api/tokenRefresh.js +192 -0
  64. package/lib/module/api/userClient.js +233 -0
  65. package/lib/module/auth/authStore.js +224 -0
  66. package/lib/module/auth/index.js +5 -0
  67. package/lib/module/auth/jwt.js +106 -0
  68. package/lib/module/config/index.js +58 -0
  69. package/lib/module/deepLink/index.js +280 -0
  70. package/lib/module/download/adapters/expoFs.js +64 -0
  71. package/lib/module/download/adapters/shared.js +8 -0
  72. package/lib/module/download/index.js +242 -0
  73. package/lib/module/formatters/currency.js +64 -0
  74. package/lib/module/formatters/date.js +160 -0
  75. package/lib/module/formatters/dateMath.js +294 -0
  76. package/lib/module/formatters/index.js +9 -0
  77. package/lib/module/formatters/initials.js +27 -0
  78. package/lib/module/formatters/number.js +81 -0
  79. package/lib/module/formatters/phone.js +302 -0
  80. package/lib/module/formatters/windowsToIanaTable.js +160 -0
  81. package/lib/module/geolocation/adapters/expoLocation.js +121 -0
  82. package/lib/module/geolocation/index.js +347 -0
  83. package/lib/module/index.js +54 -0
  84. package/lib/module/initSDK.js +61 -0
  85. package/lib/module/initUserAuth.js +33 -0
  86. package/lib/module/logger/index.js +285 -0
  87. package/lib/module/network/index.js +4 -0
  88. package/lib/module/network/networkStatus.js +124 -0
  89. package/lib/module/package.json +1 -0
  90. package/lib/module/permissions/calendar.js +15 -0
  91. package/lib/module/permissions/camera.js +15 -0
  92. package/lib/module/permissions/contacts.js +11 -0
  93. package/lib/module/permissions/index.js +128 -0
  94. package/lib/module/permissions/location.js +15 -0
  95. package/lib/module/permissions/mediaLibrary.js +11 -0
  96. package/lib/module/permissions/notifications.js +11 -0
  97. package/lib/module/permissions/photos.js +15 -0
  98. package/lib/module/phone/countries.js +261 -0
  99. package/lib/module/share/index.js +64 -0
  100. package/lib/module/smsRetriever/index.js +86 -0
  101. package/lib/module/specs/NativeSmsRetriever.js +13 -0
  102. package/lib/module/sqlite/adapters/expo.js +48 -0
  103. package/lib/module/sqlite/index.js +594 -0
  104. package/lib/module/storage/index.js +208 -0
  105. package/lib/module/types/globals.d.js +10 -0
  106. package/lib/module/utils/imageCompression.js +383 -0
  107. package/lib/module/utils/index.js +4 -0
  108. package/lib/module/validators/index.js +205 -0
  109. package/lib/module/versionCheck/index.js +413 -0
  110. package/lib/typescript/commonjs/api/baseUrl.d.ts +20 -0
  111. package/lib/typescript/commonjs/api/curl.d.ts +18 -0
  112. package/lib/typescript/commonjs/api/publicClient.d.ts +11 -0
  113. package/lib/typescript/commonjs/api/retry.d.ts +27 -0
  114. package/lib/typescript/commonjs/api/tokenRefresh.d.ts +43 -0
  115. package/lib/typescript/commonjs/api/userClient.d.ts +37 -0
  116. package/lib/typescript/commonjs/auth/authStore.d.ts +79 -0
  117. package/lib/typescript/commonjs/auth/index.d.ts +5 -0
  118. package/lib/typescript/commonjs/auth/jwt.d.ts +31 -0
  119. package/lib/typescript/commonjs/config/index.d.ts +55 -0
  120. package/lib/typescript/commonjs/deepLink/index.d.ts +54 -0
  121. package/lib/typescript/commonjs/download/adapters/expoFs.d.ts +38 -0
  122. package/lib/typescript/commonjs/download/adapters/shared.d.ts +3 -0
  123. package/lib/typescript/commonjs/download/index.d.ts +86 -0
  124. package/lib/typescript/commonjs/formatters/currency.d.ts +24 -0
  125. package/lib/typescript/commonjs/formatters/date.d.ts +22 -0
  126. package/lib/typescript/commonjs/formatters/dateMath.d.ts +88 -0
  127. package/lib/typescript/commonjs/formatters/index.d.ts +10 -0
  128. package/lib/typescript/commonjs/formatters/initials.d.ts +11 -0
  129. package/lib/typescript/commonjs/formatters/number.d.ts +15 -0
  130. package/lib/typescript/commonjs/formatters/phone.d.ts +133 -0
  131. package/lib/typescript/commonjs/formatters/windowsToIanaTable.d.ts +18 -0
  132. package/lib/typescript/commonjs/geolocation/adapters/expoLocation.d.ts +42 -0
  133. package/lib/typescript/commonjs/geolocation/index.d.ts +90 -0
  134. package/lib/typescript/commonjs/index.d.ts +54 -0
  135. package/lib/typescript/commonjs/initSDK.d.ts +72 -0
  136. package/lib/typescript/commonjs/initUserAuth.d.ts +41 -0
  137. package/lib/typescript/commonjs/logger/index.d.ts +81 -0
  138. package/lib/typescript/commonjs/network/index.d.ts +3 -0
  139. package/lib/typescript/commonjs/network/networkStatus.d.ts +43 -0
  140. package/lib/typescript/commonjs/package.json +1 -0
  141. package/lib/typescript/commonjs/permissions/calendar.d.ts +2 -0
  142. package/lib/typescript/commonjs/permissions/camera.d.ts +2 -0
  143. package/lib/typescript/commonjs/permissions/contacts.d.ts +2 -0
  144. package/lib/typescript/commonjs/permissions/index.d.ts +48 -0
  145. package/lib/typescript/commonjs/permissions/location.d.ts +2 -0
  146. package/lib/typescript/commonjs/permissions/mediaLibrary.d.ts +2 -0
  147. package/lib/typescript/commonjs/permissions/notifications.d.ts +2 -0
  148. package/lib/typescript/commonjs/permissions/photos.d.ts +2 -0
  149. package/lib/typescript/commonjs/phone/countries.d.ts +13 -0
  150. package/lib/typescript/commonjs/share/index.d.ts +29 -0
  151. package/lib/typescript/commonjs/smsRetriever/index.d.ts +30 -0
  152. package/lib/typescript/commonjs/specs/NativeSmsRetriever.d.ts +15 -0
  153. package/lib/typescript/commonjs/sqlite/adapters/expo.d.ts +30 -0
  154. package/lib/typescript/commonjs/sqlite/index.d.ts +113 -0
  155. package/lib/typescript/commonjs/storage/index.d.ts +64 -0
  156. package/lib/typescript/commonjs/utils/imageCompression.d.ts +152 -0
  157. package/lib/typescript/commonjs/utils/index.d.ts +3 -0
  158. package/lib/typescript/commonjs/validators/index.d.ts +51 -0
  159. package/lib/typescript/commonjs/versionCheck/index.d.ts +80 -0
  160. package/lib/typescript/module/api/baseUrl.d.ts +20 -0
  161. package/lib/typescript/module/api/curl.d.ts +18 -0
  162. package/lib/typescript/module/api/publicClient.d.ts +11 -0
  163. package/lib/typescript/module/api/retry.d.ts +27 -0
  164. package/lib/typescript/module/api/tokenRefresh.d.ts +43 -0
  165. package/lib/typescript/module/api/userClient.d.ts +37 -0
  166. package/lib/typescript/module/auth/authStore.d.ts +79 -0
  167. package/lib/typescript/module/auth/index.d.ts +5 -0
  168. package/lib/typescript/module/auth/jwt.d.ts +31 -0
  169. package/lib/typescript/module/config/index.d.ts +55 -0
  170. package/lib/typescript/module/deepLink/index.d.ts +54 -0
  171. package/lib/typescript/module/download/adapters/expoFs.d.ts +38 -0
  172. package/lib/typescript/module/download/adapters/shared.d.ts +3 -0
  173. package/lib/typescript/module/download/index.d.ts +86 -0
  174. package/lib/typescript/module/formatters/currency.d.ts +24 -0
  175. package/lib/typescript/module/formatters/date.d.ts +22 -0
  176. package/lib/typescript/module/formatters/dateMath.d.ts +88 -0
  177. package/lib/typescript/module/formatters/index.d.ts +10 -0
  178. package/lib/typescript/module/formatters/initials.d.ts +11 -0
  179. package/lib/typescript/module/formatters/number.d.ts +15 -0
  180. package/lib/typescript/module/formatters/phone.d.ts +133 -0
  181. package/lib/typescript/module/formatters/windowsToIanaTable.d.ts +18 -0
  182. package/lib/typescript/module/geolocation/adapters/expoLocation.d.ts +42 -0
  183. package/lib/typescript/module/geolocation/index.d.ts +90 -0
  184. package/lib/typescript/module/index.d.ts +54 -0
  185. package/lib/typescript/module/initSDK.d.ts +72 -0
  186. package/lib/typescript/module/initUserAuth.d.ts +41 -0
  187. package/lib/typescript/module/logger/index.d.ts +81 -0
  188. package/lib/typescript/module/network/index.d.ts +3 -0
  189. package/lib/typescript/module/network/networkStatus.d.ts +43 -0
  190. package/lib/typescript/module/package.json +1 -0
  191. package/lib/typescript/module/permissions/calendar.d.ts +2 -0
  192. package/lib/typescript/module/permissions/camera.d.ts +2 -0
  193. package/lib/typescript/module/permissions/contacts.d.ts +2 -0
  194. package/lib/typescript/module/permissions/index.d.ts +48 -0
  195. package/lib/typescript/module/permissions/location.d.ts +2 -0
  196. package/lib/typescript/module/permissions/mediaLibrary.d.ts +2 -0
  197. package/lib/typescript/module/permissions/notifications.d.ts +2 -0
  198. package/lib/typescript/module/permissions/photos.d.ts +2 -0
  199. package/lib/typescript/module/phone/countries.d.ts +13 -0
  200. package/lib/typescript/module/share/index.d.ts +29 -0
  201. package/lib/typescript/module/smsRetriever/index.d.ts +30 -0
  202. package/lib/typescript/module/specs/NativeSmsRetriever.d.ts +15 -0
  203. package/lib/typescript/module/sqlite/adapters/expo.d.ts +30 -0
  204. package/lib/typescript/module/sqlite/index.d.ts +113 -0
  205. package/lib/typescript/module/storage/index.d.ts +64 -0
  206. package/lib/typescript/module/utils/imageCompression.d.ts +152 -0
  207. package/lib/typescript/module/utils/index.d.ts +3 -0
  208. package/lib/typescript/module/validators/index.d.ts +51 -0
  209. package/lib/typescript/module/versionCheck/index.d.ts +80 -0
  210. package/package.json +298 -0
  211. package/src/specs/NativeSmsRetriever.ts +16 -0
@@ -0,0 +1,227 @@
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
@@ -0,0 +1,419 @@
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
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ import { getConfigValue } from "../config/index.js";
4
+
5
+ /**
6
+ * Resolves `baseURL` PER REQUEST rather than at module evaluation.
7
+ *
8
+ * `axios.create({ baseURL: getConfigValue('baseUrl') })` reads the value once,
9
+ * when the module is first imported — which happens the moment anything touches
10
+ * the package barrel, long before an app's startup code can call `setConfig`.
11
+ * The result was a client permanently pinned to `undefined` and a `setConfig`
12
+ * that appeared to do nothing, with no error anywhere: requests just went to a
13
+ * relative URL.
14
+ *
15
+ * A consumer cannot fix that by ordering its own imports, because the import
16
+ * that loses the race is usually one it never wrote. So the clients stop
17
+ * capturing the value and ask for it per request instead.
18
+ *
19
+ * An explicit per-request `baseURL` still wins, which is what keeps a one-off
20
+ * call to a different host possible.
21
+ */
22
+ export const applyConfiguredBaseUrl = client => {
23
+ client.interceptors.request.use(config => {
24
+ if (!config.baseURL) {
25
+ config.baseURL = getConfigValue('baseUrl') ?? undefined;
26
+ }
27
+ return config;
28
+ });
29
+ };
30
+ //# sourceMappingURL=baseUrl.js.map