@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,205 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Generic validators returning `boolean`. All accept `null`/`undefined` safely.
5
+ *
6
+ * Tradeoff: regexes are pragmatic, not RFC-strict. They reject the things real users
7
+ * typo and accept the long tail of legitimate inputs. For RFC-grade validation use
8
+ * a dedicated library at the boundary.
9
+ */
10
+
11
+ const RE_EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
12
+ const RE_INDIAN_MOBILE = /^[6-9]\d{9}$/;
13
+ const RE_NUMERIC = /^-?\d+(?:\.\d+)?$/;
14
+ const RE_INTEGER = /^-?\d+$/;
15
+ const RE_ALPHANUMERIC = /^[a-zA-Z0-9]+$/;
16
+ const RE_PINCODE_IN = /^[1-9]\d{5}$/;
17
+ const RE_PAN = /^[A-Z]{5}\d{4}[A-Z]$/;
18
+ const RE_GSTIN = /^\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/;
19
+ // UIDAI issues no Aadhaar number starting 0 or 1.
20
+ const RE_AADHAAR = /^[2-9]\d{11}$/;
21
+ const RE_IFSC = /^[A-Z]{4}0[A-Z0-9]{6}$/;
22
+ const RE_HEX_COLOR = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/;
23
+ const asString = v => {
24
+ if (typeof v === 'string') {
25
+ return v.trim();
26
+ }
27
+ return null;
28
+ };
29
+ export const isNonEmpty = value => {
30
+ const s = asString(value);
31
+ return !!s && s.length > 0;
32
+ };
33
+ export const isEmail = value => {
34
+ const s = asString(value);
35
+ return !!s && RE_EMAIL.test(s);
36
+ };
37
+
38
+ /**
39
+ * Validate an Indian mobile number. Accepts:
40
+ * - 10-digit number starting with 6-9
41
+ * - Optional `+91` or `91` country code prefix
42
+ */
43
+ export const isIndianMobile = value => {
44
+ const s = asString(value);
45
+ if (!s) {
46
+ return false;
47
+ }
48
+ const digits = s.replace(/\D/g, '');
49
+ const tail = digits.startsWith('91') && digits.length === 12 ? digits.slice(2) : digits;
50
+ return RE_INDIAN_MOBILE.test(tail);
51
+ };
52
+
53
+ /**
54
+ * Generic phone validator: 7–15 digits, optional `+` prefix.
55
+ * Use `isIndianMobile` when you specifically need an Indian mobile number.
56
+ */
57
+ export const isPhone = value => {
58
+ const s = asString(value);
59
+ if (!s) {
60
+ return false;
61
+ }
62
+ const digits = s.replace(/[^\d+]/g, '').replace(/^\+/, '');
63
+ return digits.length >= 7 && digits.length <= 15 && /^\d+$/.test(digits);
64
+ };
65
+ export const isUrl = value => {
66
+ const s = asString(value);
67
+ if (!s) {
68
+ return false;
69
+ }
70
+ try {
71
+ // URL constructor is available on Hermes & JSC.
72
+
73
+ new URL(s);
74
+ return /^https?:\/\//i.test(s) || /^[a-z][a-z0-9+\-.]*:\/\//i.test(s);
75
+ } catch {
76
+ return false;
77
+ }
78
+ };
79
+ export const isNumeric = value => {
80
+ if (typeof value === 'number') {
81
+ return Number.isFinite(value);
82
+ }
83
+ const s = asString(value);
84
+ return !!s && RE_NUMERIC.test(s);
85
+ };
86
+ export const isInteger = value => {
87
+ if (typeof value === 'number') {
88
+ return Number.isInteger(value);
89
+ }
90
+ const s = asString(value);
91
+ return !!s && RE_INTEGER.test(s);
92
+ };
93
+ export const isAlphanumeric = value => {
94
+ const s = asString(value);
95
+ return !!s && RE_ALPHANUMERIC.test(s);
96
+ };
97
+ /**
98
+ * Common password complexity check. Defaults to 8+ chars,
99
+ * one uppercase, one lowercase, one digit.
100
+ */
101
+ export const isStrongPassword = (value, rules = {}) => {
102
+ if (typeof value !== 'string') {
103
+ return false;
104
+ }
105
+ const {
106
+ minLength = 8,
107
+ requireUppercase = true,
108
+ requireLowercase = true,
109
+ requireNumber = true,
110
+ requireSymbol = false
111
+ } = rules;
112
+ if (value.length < minLength) {
113
+ return false;
114
+ }
115
+ if (requireUppercase && !/[A-Z]/.test(value)) {
116
+ return false;
117
+ }
118
+ if (requireLowercase && !/[a-z]/.test(value)) {
119
+ return false;
120
+ }
121
+ if (requireNumber && !/\d/.test(value)) {
122
+ return false;
123
+ }
124
+ if (requireSymbol && !/[^A-Za-z0-9]/.test(value)) {
125
+ return false;
126
+ }
127
+ return true;
128
+ };
129
+ export const isIndianPincode = value => {
130
+ const s = asString(value);
131
+ return !!s && RE_PINCODE_IN.test(s);
132
+ };
133
+ export const isPan = value => {
134
+ const s = asString(value);
135
+ return !!s && RE_PAN.test(s.toUpperCase());
136
+ };
137
+ const BASE_36 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
138
+
139
+ /**
140
+ * The GSTN check character: each of the first fourteen characters' base-36
141
+ * value times a weight alternating 1 and 2, the product's quotient and
142
+ * remainder by 36 summed; the check character makes the total a multiple of 36.
143
+ */
144
+ const gstinCheckCharacter = gstin => {
145
+ let sum = 0;
146
+ for (let i = 0; i < 14; i += 1) {
147
+ const product = BASE_36.indexOf(gstin[i]) * (i % 2 === 0 ? 1 : 2);
148
+ sum += Math.floor(product / 36) + product % 36;
149
+ }
150
+ return BASE_36[(36 - sum % 36) % 36];
151
+ };
152
+ export const isGstin = value => {
153
+ const s = asString(value)?.toUpperCase();
154
+ return !!s && RE_GSTIN.test(s) && s[14] === gstinCheckCharacter(s);
155
+ };
156
+ 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]];
157
+ 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]];
158
+
159
+ /** Verhoeff (dihedral group D5): valid when the running product over the reversed digits is 0. */
160
+ const isVerhoeffValid = digits => {
161
+ let check = 0;
162
+ for (let i = 0; i < digits.length; i += 1) {
163
+ const digit = Number(digits[digits.length - 1 - i]);
164
+ check = VERHOEFF_D[check][VERHOEFF_P[i % 8][digit]];
165
+ }
166
+ return check === 0;
167
+ };
168
+
169
+ /**
170
+ * The same rules the Webority servers apply: spaces and hyphens stripped (as
171
+ * printed on the card), twelve digits, no leading 0 or 1, and a correct
172
+ * Verhoeff check digit.
173
+ */
174
+ export const isAadhaar = value => {
175
+ const s = asString(value);
176
+ if (!s) {
177
+ return false;
178
+ }
179
+ const digits = s.replace(/[\s-]/g, '');
180
+ return RE_AADHAAR.test(digits) && isVerhoeffValid(digits);
181
+ };
182
+ export const isIfsc = value => {
183
+ const s = asString(value);
184
+ return !!s && RE_IFSC.test(s.toUpperCase());
185
+ };
186
+ export const isHexColor = value => {
187
+ const s = asString(value);
188
+ return !!s && RE_HEX_COLOR.test(s);
189
+ };
190
+ export const isBetween = (value, min, max, inclusive = true) => {
191
+ const n = typeof value === 'number' ? value : Number(asString(value));
192
+ if (!Number.isFinite(n)) {
193
+ return false;
194
+ }
195
+ return inclusive ? n >= min && n <= max : n > min && n < max;
196
+ };
197
+ export const minLength = (value, length) => {
198
+ const s = asString(value);
199
+ return !!s && s.length >= length;
200
+ };
201
+ export const maxLength = (value, length) => {
202
+ const s = asString(value);
203
+ return s == null ? true : s.length <= length;
204
+ };
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,413 @@
1
+ "use strict";
2
+
3
+ import * as Application from 'expo-application';
4
+ import { useEffect, useState } from 'react';
5
+ // Type-only — erased at compile time; react-native stays lazily required below.
6
+
7
+ import { getConfigValue } from "../config/index.js";
8
+ import { Logger } from "../logger/index.js";
9
+
10
+ /**
11
+ * Minimal device-info shape we depend on.
12
+ *
13
+ * This is a LAST RESORT, not the primary path. `Platform.OS` already gives the
14
+ * platform, and every Webority app carries its own store id and version in
15
+ * `appsettings.Compiled.json` — so `setConfig({ appId, appVersion })` covers
16
+ * both remaining values without a native module. The injector below exists for
17
+ * apps that would rather hand us a `react-native-device-info` instance than
18
+ * wire two config keys.
19
+ */
20
+
21
+ /**
22
+ * expo-application, read at call time.
23
+ *
24
+ * `applicationId` and `nativeApplicationVersion` are module CONSTANTS rather
25
+ * than functions, so they are read inside the accessors rather than captured
26
+ * here — capturing would snapshot them before the native module has
27
+ * initialised.
28
+ *
29
+ * `setConfig({ appId, appVersion })` still WINS over this: a Webority app
30
+ * already carries both in appsettings.Compiled.json, and config is checked
31
+ * first. This is the fallback for an app that would rather read its identity
32
+ * from the binary it is actually running, which is the one place the two can
33
+ * disagree.
34
+ */
35
+ const expoApplicationBackend = {
36
+ getBundleId: () => Application.applicationId ?? '',
37
+ getVersion: () => Application.nativeApplicationVersion ?? ''
38
+ };
39
+
40
+ /** Only what a test or the showcase injected; null means use expo-application. */
41
+ let deviceInfo = null;
42
+
43
+ /**
44
+ * Supply the app identity from a native module instead of config.
45
+ * Prefer `setConfig({ appId, appVersion })` — it needs no native dependency.
46
+ * Pass `null` to clear.
47
+ */
48
+ export const setDeviceInfoImplementation = impl => {
49
+ deviceInfo = impl;
50
+ };
51
+ const missing = (what, configKey) => {
52
+ 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.');
53
+ Logger.error(err.message);
54
+ return err;
55
+ };
56
+
57
+ // Platform comes from React Native itself; there has never been a reason to
58
+ // cross a native module boundary for it.
59
+ const getSystemName = () => {
60
+ const {
61
+ Platform
62
+ } = require('react-native');
63
+ return Platform.OS;
64
+ };
65
+ const getBundleId = () => {
66
+ const fromConfig = getConfigValue('appId');
67
+ if (fromConfig) {
68
+ return fromConfig;
69
+ }
70
+ const fromDevice = (deviceInfo ?? expoApplicationBackend).getBundleId();
71
+ if (fromDevice) {
72
+ return fromDevice;
73
+ }
74
+ throw missing('store identifier', 'appId');
75
+ };
76
+ const getVersion = () => {
77
+ const fromConfig = getConfigValue('appVersion');
78
+ if (fromConfig) {
79
+ return fromConfig;
80
+ }
81
+ const fromDevice = (deviceInfo ?? expoApplicationBackend).getVersion();
82
+ if (fromDevice) {
83
+ return fromDevice;
84
+ }
85
+ throw missing('version', 'appVersion');
86
+ };
87
+
88
+ // Constants
89
+ const MAX_RETRIES = 3;
90
+ const RETRY_DELAY = 3000; // 3 seconds
91
+
92
+ const getCountry = () => getConfigValue('country', 'in').toLowerCase();
93
+ // Utility function to parse and coerce version to a valid format
94
+ const parseVersion = version => {
95
+ Logger.info(`Parsing version: ${version}`);
96
+ const coercedVersion = version.replace(/[^0-9.]/g, '');
97
+ const versionParts = coercedVersion.split('.').map(Number);
98
+ return {
99
+ major: versionParts[0] || 0,
100
+ minor: versionParts[1] || 0,
101
+ patch: versionParts[2] || 0,
102
+ prerelease: version.includes('-') ? version.split('-')[1] ?? '' : ''
103
+ };
104
+ };
105
+
106
+ // Utility function to compare two versions loosely
107
+ const diffLoose = (version1, version2) => {
108
+ Logger.info(`Comparing versions: ${version1} and ${version2}`);
109
+ if (version1 === version2) {
110
+ return null;
111
+ }
112
+ const v1 = parseVersion(version1);
113
+ const v2 = parseVersion(version2);
114
+ if (v1.major < v2.major) {
115
+ return 'major';
116
+ }
117
+ if (v1.major > v2.major) {
118
+ return null;
119
+ }
120
+ if (v1.minor < v2.minor) {
121
+ return 'minor';
122
+ }
123
+ if (v1.minor > v2.minor) {
124
+ return null;
125
+ }
126
+ if (v1.patch < v2.patch) {
127
+ return 'patch';
128
+ }
129
+ if (v1.patch > v2.patch) {
130
+ return null;
131
+ }
132
+ if (v1.prerelease && !v2.prerelease) {
133
+ return 'prerelease';
134
+ }
135
+ if (!v1.prerelease && v2.prerelease) {
136
+ return null;
137
+ }
138
+ if (v1.prerelease < v2.prerelease) {
139
+ return 'prerelease';
140
+ }
141
+ if (v1.prerelease > v2.prerelease) {
142
+ return null;
143
+ }
144
+ return null;
145
+ };
146
+
147
+ // Function to compare current version with the latest version
148
+ const versionCompare = (currentVersion, latestVersion) => {
149
+ Logger.info(`Comparing current version: ${currentVersion} with latest version: ${latestVersion}`);
150
+ if (!latestVersion) {
151
+ return {
152
+ needsUpdate: false,
153
+ updateType: null,
154
+ notice: 'Error: could not get latest version'
155
+ };
156
+ }
157
+ try {
158
+ const updateType = diffLoose(currentVersion, latestVersion);
159
+ return {
160
+ needsUpdate: !!updateType,
161
+ updateType
162
+ };
163
+ } catch (e) {
164
+ const message = e instanceof Error ? e.message : String(e);
165
+ Logger.error(`Error comparing versions: ${message}`);
166
+ const needsUpdate = currentVersion !== latestVersion && latestVersion > currentVersion;
167
+ const updateType = needsUpdate ? 'minor' : null;
168
+ return {
169
+ needsUpdate,
170
+ updateType,
171
+ notice: message.replace(/^Invalid Version:/, 'Not a valid version:')
172
+ };
173
+ }
174
+ };
175
+
176
+ // Function to fetch version details from Google Play Store
177
+ const fetchAndroidVersion = async url => {
178
+ Logger.info(`Fetching Android version from URL: ${url}`);
179
+ let response;
180
+ try {
181
+ response = await fetch(url, {
182
+ headers: {
183
+ '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',
184
+ 'sec-fetch-site': 'same-origin'
185
+ }
186
+ });
187
+ } catch (error) {
188
+ const message = error instanceof Error ? error.message : String(error);
189
+ Logger.error(`Error fetching data from Google Play Store: ${message}`);
190
+ throw new Error('Error fetching data from Google Play Store.');
191
+ }
192
+ if (!response.ok) {
193
+ if (response.status === 404) {
194
+ Logger.error('App with app ID not found in Google Play.');
195
+ throw new Error(`App with app ID not found in Google Play.`);
196
+ }
197
+ Logger.error(`Error fetching data: ${response.statusText}`);
198
+ throw new Error(response.statusText);
199
+ }
200
+ const text = await response.text();
201
+
202
+ // Primary regex pattern for current Play Store format
203
+ let versionMatch = text.match(/\[\[\[['"]((\d+\.)+\d+)['"]\]\],/);
204
+
205
+ // Alternate patterns as fallbacks
206
+ if (!versionMatch) {
207
+ // Fallback 1: Look for version in "current version" text
208
+ versionMatch = text.match(/Current Version[^\d]+((\d+\.)+\d+)/i);
209
+ }
210
+ if (!versionMatch) {
211
+ // Fallback 2: Look for itemprop="softwareVersion"
212
+ versionMatch = text.match(/itemprop="softwareVersion"[^>]*>((\d+\.)+\d+)</i);
213
+ }
214
+ if (!versionMatch) {
215
+ // Fallback 3: Try a more generic pattern for version numbers
216
+ const allVersions = text.match(/(\d+\.\d+(\.\d+)?)/g);
217
+ // If we found multiple version-like strings, use the first one
218
+ versionMatch = allVersions && allVersions.length > 0 ? [null, allVersions[0]] : null;
219
+ }
220
+ const version = versionMatch ? versionMatch[1] ?? null : null;
221
+ if (!version) {
222
+ Logger.warn('Could not extract version from Play Store. Using fallback method.');
223
+ }
224
+ const notesMatch = text.match(/<div itemprop="description">(.*?)<\/div>/);
225
+ const notes = notesMatch ? notesMatch[1] ?? '' : '';
226
+ return {
227
+ version,
228
+ releasedAt: new Date().toISOString(),
229
+ notes,
230
+ url,
231
+ lastChecked: new Date().toISOString()
232
+ };
233
+ };
234
+ // Function to fetch version details from Apple App Store
235
+ const fetchIosVersion = async url => {
236
+ Logger.info(`Fetching iOS version from URL: ${url}`);
237
+ let response;
238
+ try {
239
+ response = await fetch(url);
240
+ } catch {
241
+ Logger.error('Error connecting to iTunes.');
242
+ throw new Error('Error connecting to iTunes.');
243
+ }
244
+ const data = await response.json();
245
+ if (!data || !('results' in data)) {
246
+ Logger.error('Unknown error connecting to iTunes.');
247
+ throw new Error('Unknown error connecting to iTunes.');
248
+ }
249
+ if (!data.results.length) {
250
+ Logger.error('App for this bundle ID not found.');
251
+ throw new Error('App for this bundle ID not found.');
252
+ }
253
+ const result = data.results[0];
254
+ return {
255
+ version: result.version || null,
256
+ released: result.currentVersionReleaseDate || result.releaseDate || null,
257
+ notes: result.releaseNotes || '',
258
+ url: result.trackViewUrl || result.artistViewUrl || result.sellerUrl || null,
259
+ country: getCountry(),
260
+ lastChecked: new Date().toISOString()
261
+ };
262
+ };
263
+
264
+ // Function to lookup version based on platform
265
+ const lookupVersion = async (platform, identifier) => {
266
+ Logger.info(`Looking up version for platform: ${platform}, identifier: ${identifier}`);
267
+ const country = getCountry();
268
+ 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}`;
269
+ return platform === 'ios' ? fetchIosVersion(url) : fetchAndroidVersion(url);
270
+ };
271
+
272
+ /**
273
+ * Check for new version with retry logic
274
+ */
275
+ const checkForUpdates = async () => {
276
+ const platform = getSystemName().toLowerCase();
277
+ const identifier = getBundleId();
278
+ const currentVersion = getVersion();
279
+
280
+ // Implement retry mechanism
281
+ let retryCount = 0;
282
+ let lastError = null;
283
+ while (retryCount <= MAX_RETRIES) {
284
+ try {
285
+ Logger.info(`Checking if new version is available (attempt ${retryCount + 1}/${MAX_RETRIES + 1})`);
286
+ Logger.info(`Platform: ${platform}, identifier: ${identifier}, current version: ${currentVersion}`);
287
+ const latestVersionInfo = await lookupVersion(platform, identifier);
288
+ const comparison = versionCompare(currentVersion, latestVersionInfo.version);
289
+ return {
290
+ isNewVersionAvailable: comparison.needsUpdate,
291
+ updateType: comparison.updateType,
292
+ url: latestVersionInfo.url
293
+ };
294
+ } catch (error) {
295
+ lastError = error;
296
+ const message = error instanceof Error ? error.message : String(error);
297
+ Logger.error(`Error checking version (attempt ${retryCount + 1}/${MAX_RETRIES + 1}): ${message}`);
298
+
299
+ // If we've reached max retries, throw the last error
300
+ if (retryCount === MAX_RETRIES) {
301
+ throw error;
302
+ }
303
+
304
+ // Otherwise, wait and retry
305
+ retryCount++;
306
+ Logger.info(`Retrying version check in ${RETRY_DELAY}ms...`);
307
+ await new Promise(resolve => setTimeout(resolve, RETRY_DELAY));
308
+ }
309
+ }
310
+
311
+ // This should never be reached due to the throw above, but just in case
312
+ throw lastError instanceof Error ? lastError : new Error('Failed to check for updates after multiple attempts');
313
+ };
314
+
315
+ /**
316
+ * Get fallback store URL based on platform
317
+ */
318
+ const getFallbackStoreUrl = () => {
319
+ const platform = getSystemName().toLowerCase();
320
+ const bundleId = getBundleId();
321
+ const country = getCountry();
322
+ return platform === 'ios' ? `https://apps.apple.com/${country}/app/${bundleId}` : `https://play.google.com/store/apps/details?id=${bundleId}&hl=${country}`;
323
+ };
324
+ // Version check functionality
325
+ export const VersionCheck = {
326
+ isNewVersionAvailable: async () => {
327
+ return checkForUpdates();
328
+ },
329
+ openUpdateUrl: async url => {
330
+ const {
331
+ Linking
332
+ } = require('react-native');
333
+ try {
334
+ if (url) {
335
+ Logger.info(`Opening app store URL: ${url}`);
336
+ await Linking.openURL(url);
337
+ } else {
338
+ const fallbackUrl = getFallbackStoreUrl();
339
+ Logger.info(`Opening fallback store URL: ${fallbackUrl}`);
340
+ await Linking.openURL(fallbackUrl);
341
+ }
342
+ return true;
343
+ } catch (error) {
344
+ const message = error instanceof Error ? error.message : String(error);
345
+ Logger.error(`Failed to open store URL: ${message}`);
346
+
347
+ // Try with fallback URL if the original failed
348
+ try {
349
+ if (url) {
350
+ // Only try fallback if we were using a specific URL before
351
+ const fallbackUrl = getFallbackStoreUrl();
352
+ Logger.info(`Trying fallback store URL: ${fallbackUrl}`);
353
+ await Linking.openURL(fallbackUrl);
354
+ return true;
355
+ }
356
+ } catch (fallbackError) {
357
+ const fbMessage = fallbackError instanceof Error ? fallbackError.message : String(fallbackError);
358
+ Logger.error(`Failed to open fallback URL: ${fbMessage}`);
359
+ }
360
+ return false;
361
+ }
362
+ },
363
+ getFallbackStoreUrl
364
+ };
365
+
366
+ /**
367
+ * Custom hook to check for required app updates.
368
+ *
369
+ * @param isAppReady - Whether the app is ready to perform the check
370
+ * @param environment - The app environment (defaults to the one in config)
371
+ */
372
+ export const useVersionCheck = (isAppReady, environment = getConfigValue('environment', 'Development')) => {
373
+ const [updateInfo, setUpdateInfo] = useState({
374
+ isUpdateRequired: false,
375
+ updateUrl: null
376
+ });
377
+ useEffect(() => {
378
+ let isMounted = true;
379
+ const checkVersion = async () => {
380
+ try {
381
+ // All retry logic is handled in the VersionCheck module
382
+ const {
383
+ isNewVersionAvailable,
384
+ url
385
+ } = await VersionCheck.isNewVersionAvailable();
386
+ if (isNewVersionAvailable && isMounted) {
387
+ Logger.info('Update required. URL:', url || 'Not available yet');
388
+ setUpdateInfo({
389
+ isUpdateRequired: true,
390
+ updateUrl: url
391
+ });
392
+ } else if (isMounted) {
393
+ Logger.info('App is up to date');
394
+ }
395
+ } catch (error) {
396
+ Logger.error('Error checking app version:', error);
397
+ }
398
+ };
399
+
400
+ // Only run version check in Production environment when app is ready
401
+ if (isAppReady && environment === 'Production') {
402
+ void checkVersion();
403
+ }
404
+ return () => {
405
+ isMounted = false;
406
+ };
407
+ }, [isAppReady, environment]);
408
+ return updateInfo;
409
+ };
410
+
411
+ // Export for backward compatibility
412
+ export default VersionCheck;
413
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,20 @@
1
+ import type { AxiosInstance } from 'axios';
2
+ /**
3
+ * Resolves `baseURL` PER REQUEST rather than at module evaluation.
4
+ *
5
+ * `axios.create({ baseURL: getConfigValue('baseUrl') })` reads the value once,
6
+ * when the module is first imported — which happens the moment anything touches
7
+ * the package barrel, long before an app's startup code can call `setConfig`.
8
+ * The result was a client permanently pinned to `undefined` and a `setConfig`
9
+ * that appeared to do nothing, with no error anywhere: requests just went to a
10
+ * relative URL.
11
+ *
12
+ * A consumer cannot fix that by ordering its own imports, because the import
13
+ * that loses the race is usually one it never wrote. So the clients stop
14
+ * capturing the value and ask for it per request instead.
15
+ *
16
+ * An explicit per-request `baseURL` still wins, which is what keeps a one-off
17
+ * call to a different host possible.
18
+ */
19
+ export declare const applyConfiguredBaseUrl: (client: AxiosInstance) => void;
20
+ //# sourceMappingURL=baseUrl.d.ts.map
@@ -0,0 +1,18 @@
1
+ import type { AxiosRequestConfig } from 'axios';
2
+ /**
3
+ * Builds a copy-pasteable curl command for a request, with every credential
4
+ * replaced by a placeholder.
5
+ *
6
+ * The redaction is the point, not a nicety. An unredacted version of this in a
7
+ * consumer app put `Authorization: Bearer <token>` and the login request's
8
+ * plaintext password into the device console of a *release* staging build.
9
+ * A curl line is worth having; a curl line that has to be trusted not to be
10
+ * enabled in the wrong build is not.
11
+ */
12
+ export declare const buildCurl: (config: AxiosRequestConfig) => string;
13
+ /**
14
+ * Logs the curl equivalent of a request. Never throws: a failure to describe a
15
+ * request must not be able to fail the request itself.
16
+ */
17
+ export declare const logCurl: (config: AxiosRequestConfig) => void;
18
+ //# sourceMappingURL=curl.d.ts.map
@@ -0,0 +1,11 @@
1
+ import { type AxiosInstance } from 'axios';
2
+ /**
3
+ * Public Axios Client
4
+ * - Base URL: Set your public API base URL.
5
+ * - No Authorization header is attached.
6
+ * - Includes timeout configuration and error handling.
7
+ * - Handles specific HTTP status codes.
8
+ */
9
+ declare const publicClient: AxiosInstance;
10
+ export default publicClient;
11
+ //# sourceMappingURL=publicClient.d.ts.map
@@ -0,0 +1,27 @@
1
+ import type { AxiosError, AxiosInstance } from 'axios';
2
+ export interface RetryPolicy {
3
+ retries?: number;
4
+ /** `attempt` is 1-based: 1 is the first retry, not the original request. */
5
+ retryDelayMs?: (attempt: number) => number;
6
+ shouldRetry?: (error: AxiosError) => boolean;
7
+ onRetry?: (attempt: number, error: AxiosError) => void;
8
+ }
9
+ declare module 'axios' {
10
+ interface AxiosRequestConfig {
11
+ /** `false` opts a single request out of retrying; an object overrides the client policy. */
12
+ retry?: boolean | RetryPolicy;
13
+ }
14
+ }
15
+ /**
16
+ * Status-based ONLY, deliberately: a bare network error (no `error.response`)
17
+ * is never retryable. Both clients carry non-idempotent requests, login and OTP
18
+ * on the public one and every write on the user one, and a broken connection
19
+ * says nothing about whether the request reached the server. Retrying can
20
+ * therefore create a second session, or a duplicate record, that the user never
21
+ * sees. A generic network-error retry rule is not a substitute: it decides on
22
+ * the transport alone and never looks at the HTTP method, so it retries POSTs
23
+ * as readily as GETs.
24
+ */
25
+ export declare const isRetryableStatus: (status: number | undefined) => boolean;
26
+ export declare const attachRetry: (client: AxiosInstance, policy?: RetryPolicy) => void;
27
+ //# sourceMappingURL=retry.d.ts.map