@webority/mobile-core 0.0.28 → 0.1.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.
- package/lib/commonjs/api/baseUrl.js +1 -34
- package/lib/commonjs/api/curl.js +1 -109
- package/lib/commonjs/api/multipart.js +1 -21
- package/lib/commonjs/api/publicClient.js +1 -79
- package/lib/commonjs/api/responseBodyText.js +1 -0
- package/lib/commonjs/api/retry.js +1 -91
- package/lib/commonjs/api/tokenRefresh.js +1 -205
- package/lib/commonjs/api/userClient.js +1 -265
- package/lib/commonjs/auth/authStore.js +1 -265
- package/lib/commonjs/auth/index.js +1 -44
- package/lib/commonjs/auth/jwt.js +1 -112
- package/lib/commonjs/config/index.js +1 -72
- package/lib/commonjs/deepLink/index.js +1 -286
- package/lib/commonjs/download/adapters/expoFs.js +1 -69
- package/lib/commonjs/download/adapters/shared.js +1 -13
- package/lib/commonjs/download/index.js +1 -250
- package/lib/commonjs/formatters/currency.js +1 -70
- package/lib/commonjs/formatters/date.js +1 -167
- package/lib/commonjs/formatters/dateMath.js +1 -311
- package/lib/commonjs/formatters/index.js +1 -246
- package/lib/commonjs/formatters/initials.js +1 -32
- package/lib/commonjs/formatters/intlCache.js +1 -37
- package/lib/commonjs/formatters/number.js +1 -89
- package/lib/commonjs/formatters/phone.js +1 -369
- package/lib/commonjs/formatters/windowsToIanaTable.js +1 -164
- package/lib/commonjs/geolocation/adapters/expoLocation.js +1 -126
- package/lib/commonjs/geolocation/index.js +1 -355
- package/lib/commonjs/index.js +1 -644
- package/lib/commonjs/initSDK.js +1 -66
- package/lib/commonjs/initUserAuth.js +1 -37
- package/lib/commonjs/logger/crashlytics.js +1 -0
- package/lib/commonjs/logger/index.js +1 -301
- package/lib/commonjs/logger/redact.js +1 -50
- package/lib/commonjs/network/index.js +1 -31
- package/lib/commonjs/network/networkStatus.js +1 -171
- package/lib/commonjs/permissions/calendar.js +1 -14
- package/lib/commonjs/permissions/camera.js +1 -14
- package/lib/commonjs/permissions/contacts.js +1 -10
- package/lib/commonjs/permissions/index.js +1 -133
- package/lib/commonjs/permissions/location.js +1 -14
- package/lib/commonjs/permissions/mediaLibrary.js +1 -10
- package/lib/commonjs/permissions/notifications.js +1 -10
- package/lib/commonjs/permissions/photos.js +1 -14
- package/lib/commonjs/phone/countries.js +1 -265
- package/lib/commonjs/push/index.js +1 -61
- package/lib/commonjs/push/push.js +1 -443
- package/lib/commonjs/push/status.js +1 -0
- package/lib/commonjs/push/task.js +1 -43
- package/lib/commonjs/secureScreen/index.js +1 -0
- package/lib/commonjs/share/index.js +1 -70
- package/lib/commonjs/smsRetriever/index.js +1 -91
- package/lib/commonjs/specs/NativeSmsRetriever.js +1 -15
- package/lib/commonjs/sqlite/adapters/expo.js +1 -53
- package/lib/commonjs/sqlite/index.js +1 -604
- package/lib/commonjs/storage/index.js +1 -214
- package/lib/commonjs/types/axios.js +1 -4
- package/lib/commonjs/types/globals.d.js +1 -6
- package/lib/commonjs/utils/base64.js +1 -24
- package/lib/commonjs/utils/imageCompression.js +1 -389
- package/lib/commonjs/utils/index.js +1 -19
- package/lib/commonjs/validators/index.js +1 -227
- package/lib/commonjs/versionCheck/index.js +1 -419
- package/lib/module/api/baseUrl.js +1 -30
- package/lib/module/api/curl.js +1 -104
- package/lib/module/api/multipart.js +1 -16
- package/lib/module/api/publicClient.js +1 -75
- package/lib/module/api/responseBodyText.js +1 -0
- package/lib/module/api/retry.js +1 -85
- package/lib/module/api/tokenRefresh.js +1 -192
- package/lib/module/api/userClient.js +1 -243
- package/lib/module/auth/authStore.js +1 -257
- package/lib/module/auth/index.js +1 -5
- package/lib/module/auth/jwt.js +1 -106
- package/lib/module/config/index.js +1 -64
- package/lib/module/deepLink/index.js +1 -280
- package/lib/module/download/adapters/expoFs.js +1 -64
- package/lib/module/download/adapters/shared.js +1 -8
- package/lib/module/download/index.js +1 -242
- package/lib/module/formatters/currency.js +1 -65
- package/lib/module/formatters/date.js +1 -159
- package/lib/module/formatters/dateMath.js +1 -295
- package/lib/module/formatters/index.js +1 -9
- package/lib/module/formatters/initials.js +1 -27
- package/lib/module/formatters/intlCache.js +1 -30
- package/lib/module/formatters/number.js +1 -82
- package/lib/module/formatters/phone.js +1 -302
- package/lib/module/formatters/windowsToIanaTable.js +1 -160
- package/lib/module/geolocation/adapters/expoLocation.js +1 -121
- package/lib/module/geolocation/index.js +1 -347
- package/lib/module/index.js +1 -57
- package/lib/module/initSDK.js +1 -61
- package/lib/module/initUserAuth.js +1 -33
- package/lib/module/logger/crashlytics.js +1 -0
- package/lib/module/logger/index.js +1 -295
- package/lib/module/logger/redact.js +1 -44
- package/lib/module/network/index.js +1 -4
- package/lib/module/network/networkStatus.js +1 -161
- package/lib/module/permissions/calendar.js +1 -15
- package/lib/module/permissions/camera.js +1 -15
- package/lib/module/permissions/contacts.js +1 -11
- package/lib/module/permissions/index.js +1 -128
- package/lib/module/permissions/location.js +1 -15
- package/lib/module/permissions/mediaLibrary.js +1 -11
- package/lib/module/permissions/notifications.js +1 -11
- package/lib/module/permissions/photos.js +1 -15
- package/lib/module/phone/countries.js +1 -261
- package/lib/module/push/index.js +1 -4
- package/lib/module/push/push.js +1 -427
- package/lib/module/push/status.js +1 -0
- package/lib/module/push/task.js +1 -38
- package/lib/module/secureScreen/index.js +1 -0
- package/lib/module/share/index.js +1 -64
- package/lib/module/smsRetriever/index.js +1 -86
- package/lib/module/specs/NativeSmsRetriever.js +1 -13
- package/lib/module/sqlite/adapters/expo.js +1 -48
- package/lib/module/sqlite/index.js +1 -594
- package/lib/module/storage/index.js +1 -208
- package/lib/module/types/axios.js +1 -4
- package/lib/module/types/globals.d.js +1 -10
- package/lib/module/utils/base64.js +1 -19
- package/lib/module/utils/imageCompression.js +1 -383
- package/lib/module/utils/index.js +1 -4
- package/lib/module/validators/index.js +1 -205
- package/lib/module/versionCheck/index.js +1 -413
- package/lib/typescript/commonjs/api/responseBodyText.d.ts +6 -0
- package/lib/typescript/commonjs/index.d.ts +5 -0
- package/lib/typescript/commonjs/logger/crashlytics.d.ts +31 -0
- package/lib/typescript/commonjs/push/index.d.ts +3 -1
- package/lib/typescript/commonjs/push/push.d.ts +9 -1
- package/lib/typescript/commonjs/push/status.d.ts +9 -0
- package/lib/typescript/commonjs/secureScreen/index.d.ts +25 -0
- package/lib/typescript/module/api/responseBodyText.d.ts +6 -0
- package/lib/typescript/module/index.d.ts +5 -0
- package/lib/typescript/module/logger/crashlytics.d.ts +31 -0
- package/lib/typescript/module/push/index.d.ts +3 -1
- package/lib/typescript/module/push/push.d.ts +9 -1
- package/lib/typescript/module/push/status.d.ts +9 -0
- package/lib/typescript/module/secureScreen/index.d.ts +25 -0
- package/package.json +23 -4
|
@@ -1,205 +1 @@
|
|
|
1
|
-
"
|
|
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
|
|
1
|
+
const t=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,e=/^[6-9]\d{9}$/,r=/^-?\d+(?:\.\d+)?$/,n=/^-?\d+$/,s=/^[a-zA-Z0-9]+$/,o=/^[1-9]\d{5}$/,c=/^[A-Z]{5}\d{4}[A-Z]$/,i=/^\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/,u=/^[2-9]\d{11}$/,p=/^[A-Z]{4}0[A-Z0-9]{6}$/,a=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,asString=t=>"string"==typeof t?t.trim():null;export const isNonEmpty=t=>{const e=asString(t);return!!e&&e.length>0};export const isEmail=e=>{const r=asString(e);return!!r&&t.test(r)};export const isIndianMobile=t=>{const r=asString(t);if(!r)return!1;const n=r.replace(/\D/g,""),s=n.startsWith("91")&&12===n.length?n.slice(2):n;return e.test(s)};export const isPhone=t=>{const e=asString(t);if(!e)return!1;const r=e.replace(/[^\d+]/g,"").replace(/^\+/,"");return r.length>=7&&r.length<=15&&/^\d+$/.test(r)};export const isUrl=t=>{const e=asString(t);if(!e)return!1;try{return new URL(e),/^https?:\/\//i.test(e)||/^[a-z][a-z0-9+\-.]*:\/\//i.test(e)}catch{return!1}};export const isNumeric=t=>{if("number"==typeof t)return Number.isFinite(t);const e=asString(t);return!!e&&r.test(e)};export const isInteger=t=>{if("number"==typeof t)return Number.isInteger(t);const e=asString(t);return!!e&&n.test(e)};export const isAlphanumeric=t=>{const e=asString(t);return!!e&&s.test(e)};export const isStrongPassword=(t,e={})=>{if("string"!=typeof t)return!1;const{minLength:r=8,requireUppercase:n=!0,requireLowercase:s=!0,requireNumber:o=!0,requireSymbol:c=!1}=e;return!(t.length<r)&&(!(n&&!/[A-Z]/.test(t))&&(!(s&&!/[a-z]/.test(t))&&(!(o&&!/\d/.test(t))&&!(c&&!/[^A-Za-z0-9]/.test(t)))))};export const isIndianPincode=t=>{const e=asString(t);return!!e&&o.test(e)};export const isPan=t=>{const e=asString(t);return!!e&&c.test(e.toUpperCase())};const l="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";export const isGstin=t=>{const e=asString(t)?.toUpperCase();return!!e&&i.test(e)&&e[14]===(t=>{let e=0;for(let r=0;r<14;r+=1){const n=l.indexOf(t[r])*(r%2==0?1:2);e+=Math.floor(n/36)+n%36}return l[(36-e%36)%36]})(e)};const x=[[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]],f=[[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]];export const isAadhaar=t=>{const e=asString(t);if(!e)return!1;const r=e.replace(/[\s-]/g,"");return u.test(r)&&(t=>{let e=0;for(let r=0;r<t.length;r+=1){const n=Number(t[t.length-1-r]);e=x[e][f[r%8][n]]}return 0===e})(r)};export const isIfsc=t=>{const e=asString(t);return!!e&&p.test(e.toUpperCase())};export const isHexColor=t=>{const e=asString(t);return!!e&&a.test(e)};export const isBetween=(t,e,r,n=!0)=>{const s="number"==typeof t?t:Number(asString(t));return!!Number.isFinite(s)&&(n?s>=e&&s<=r:s>e&&s<r)};export const minLength=(t,e)=>{const r=asString(t);return!!r&&r.length>=e};export const maxLength=(t,e)=>{const r=asString(t);return null==r||r.length<=e};
|
|
@@ -1,413 +1 @@
|
|
|
1
|
-
"
|
|
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
|
|
1
|
+
import*as e from"expo-application";import{useEffect as r,useState as t}from"react";import{getConfigValue as n}from"../config/index.js";import{Logger as o}from"../logger/index.js";const i={getBundleId:()=>e.applicationId??"",getVersion:()=>e.nativeApplicationVersion??""};let a=null;export const setDeviceInfoImplementation=e=>{a=e};const missing=(e,r)=>{const t=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 o.error(t.message),t},getSystemName=()=>{const{Platform:e}=require("react-native");return e.OS},getBundleId=()=>{const e=n("appId");if(e)return e;const r=(a??i).getBundleId();if(r)return r;throw missing("store identifier","appId")},getCountry=()=>n("country","in").toLowerCase(),parseVersion=e=>{o.info(`Parsing version: ${e}`);const r=e.replace(/[^0-9.]/g,"").split(".").map(Number);return{major:r[0]||0,minor:r[1]||0,patch:r[2]||0,prerelease:e.includes("-")?e.split("-")[1]??"":""}},versionCompare=(e,r)=>{if(o.info(`Comparing current version: ${e} with latest version: ${r}`),!r)return{needsUpdate:!1,updateType:null,notice:"Error: could not get latest version"};try{const t=((e,r)=>{if(o.info(`Comparing versions: ${e} and ${r}`),e===r)return null;const t=parseVersion(e),n=parseVersion(r);return t.major<n.major?"major":t.major>n.major?null:t.minor<n.minor?"minor":t.minor>n.minor?null:t.patch<n.patch?"patch":t.patch>n.patch?null:t.prerelease&&!n.prerelease?"prerelease":!t.prerelease&&n.prerelease?null:t.prerelease<n.prerelease?"prerelease":(t.prerelease,n.prerelease,null)})(e,r);return{needsUpdate:!!t,updateType:t}}catch(t){const n=t instanceof Error?t.message:String(t);o.error(`Error comparing versions: ${n}`);const i=e!==r&&r>e;return{needsUpdate:i,updateType:i?"minor":null,notice:n.replace(/^Invalid Version:/,"Not a valid version:")}}},lookupVersion=async(e,r)=>{o.info(`Looking up version for platform: ${e}, identifier: ${r}`);const t=getCountry(),n="ios"===e?`https://itunes.apple.com/lookup?bundleId=${r}&country=${t}&_=${(new Date).valueOf()}`:`https://play.google.com/store/apps/details?id=${r}&hl=${t}`;return"ios"===e?(async e=>{let r;o.info(`Fetching iOS version from URL: ${e}`);try{r=await fetch(e)}catch{throw o.error("Error connecting to iTunes."),new Error("Error connecting to iTunes.")}const t=await r.json();if(!t||!("results"in t))throw o.error("Unknown error connecting to iTunes."),new Error("Unknown error connecting to iTunes.");if(!t.results.length)throw o.error("App for this bundle ID not found."),new Error("App for this bundle ID not found.");const n=t.results[0];return{version:n.version||null,released:n.currentVersionReleaseDate||n.releaseDate||null,notes:n.releaseNotes||"",url:n.trackViewUrl||n.artistViewUrl||n.sellerUrl||null,country:getCountry(),lastChecked:(new Date).toISOString()}})(n):(async e=>{let r;o.info(`Fetching Android version from URL: ${e}`);try{r=await fetch(e,{headers:{"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","sec-fetch-site":"same-origin"}})}catch(e){const r=e instanceof Error?e.message:String(e);throw o.error(`Error fetching data from Google Play Store: ${r}`),new Error("Error fetching data from Google Play Store.")}if(!r.ok){if(404===r.status)throw o.error("App with app ID not found in Google Play."),new Error("App with app ID not found in Google Play.");throw o.error(`Error fetching data: ${r.statusText}`),new Error(r.statusText)}const t=await r.text();let n=t.match(/\[\[\[['"]((\d+\.)+\d+)['"]\]\],/);if(n||(n=t.match(/Current Version[^\d]+((\d+\.)+\d+)/i)),n||(n=t.match(/itemprop="softwareVersion"[^>]*>((\d+\.)+\d+)</i)),!n){const e=t.match(/(\d+\.\d+(\.\d+)?)/g);n=e&&e.length>0?[null,e[0]]:null}const i=n?n[1]??null:null;i||o.warn("Could not extract version from Play Store. Using fallback method.");const a=t.match(/<div itemprop="description">(.*?)<\/div>/),s=a?a[1]??"":"";return{version:i,releasedAt:(new Date).toISOString(),notes:s,url:e,lastChecked:(new Date).toISOString()}})(n)},checkForUpdates=async()=>{const e=getSystemName().toLowerCase(),r=getBundleId(),t=(()=>{const e=n("appVersion");if(e)return e;const r=(a??i).getVersion();if(r)return r;throw missing("version","appVersion")})();let s=0,l=null;for(;s<=3;)try{o.info(`Checking if new version is available (attempt ${s+1}/4)`),o.info(`Platform: ${e}, identifier: ${r}, current version: ${t}`);const n=await lookupVersion(e,r),i=versionCompare(t,n.version);return{isNewVersionAvailable:i.needsUpdate,updateType:i.updateType,url:n.url}}catch(e){l=e;const r=e instanceof Error?e.message:String(e);if(o.error(`Error checking version (attempt ${s+1}/4): ${r}`),3===s)throw e;s++,o.info("Retrying version check in 3000ms..."),await new Promise(e=>setTimeout(e,3e3))}throw l instanceof Error?l:new Error("Failed to check for updates after multiple attempts")},getFallbackStoreUrl=()=>{const e=getSystemName().toLowerCase(),r=getBundleId(),t=getCountry();return"ios"===e?`https://apps.apple.com/${t}/app/${r}`:`https://play.google.com/store/apps/details?id=${r}&hl=${t}`};export const VersionCheck={isNewVersionAvailable:async()=>checkForUpdates(),openUpdateUrl:async e=>{const{Linking:r}=require("react-native");try{if(e)o.info(`Opening app store URL: ${e}`),await r.openURL(e);else{const e=getFallbackStoreUrl();o.info(`Opening fallback store URL: ${e}`),await r.openURL(e)}return!0}catch(t){const n=t instanceof Error?t.message:String(t);o.error(`Failed to open store URL: ${n}`);try{if(e){const e=getFallbackStoreUrl();return o.info(`Trying fallback store URL: ${e}`),await r.openURL(e),!0}}catch(e){const r=e instanceof Error?e.message:String(e);o.error(`Failed to open fallback URL: ${r}`)}return!1}},getFallbackStoreUrl:getFallbackStoreUrl};export const useVersionCheck=(e,i=n("environment","Development"))=>{const[a,s]=t({isUpdateRequired:!1,updateUrl:null});return r(()=>{let r=!0;return e&&"Production"===i&&(async()=>{try{const{isNewVersionAvailable:e,url:t}=await VersionCheck.isNewVersionAvailable();e&&r?(o.info("Update required. URL:",t||"Not available yet"),s({isUpdateRequired:!0,updateUrl:t})):r&&o.info("App is up to date")}catch(e){o.error("Error checking app version:",e)}})(),()=>{r=!1}},[e,i]),a};export default VersionCheck;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A failed response's body as log text. A JSON error body is an object, which a
|
|
3
|
+
* template string prints as "[object Object]"; binary bodies are named by size.
|
|
4
|
+
*/
|
|
5
|
+
export declare const responseBodyText: (body: unknown, fallback: string) => string;
|
|
6
|
+
//# sourceMappingURL=responseBodyText.d.ts.map
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* @webority/mobile-core/sqlite expo-sqlite
|
|
12
12
|
* @webority/mobile-core/download a filesystem module
|
|
13
13
|
* @webority/mobile-core/share expo-sharing
|
|
14
|
+
* @webority/mobile-core/secureScreen expo-screen-capture
|
|
14
15
|
* @webority/mobile-core/smsRetriever Android only, own TurboModule
|
|
15
16
|
*
|
|
16
17
|
* One more path is separate for size, not for a native package:
|
|
@@ -44,8 +45,12 @@ export type { TokenRefreshConfig, TokenRefreshResult, UserAuthOptions } from './
|
|
|
44
45
|
export { initUserAuth } from './initUserAuth';
|
|
45
46
|
export type { DeviceContext, LoggerOptions, LoggerType, RemoteLogger } from './logger';
|
|
46
47
|
export { configureLogger, getDeviceContext, Logger, setDeviceContext, setRemoteLogger } from './logger';
|
|
48
|
+
export type { CrashlyticsModule } from './logger/crashlytics';
|
|
49
|
+
export { crashlyticsRemoteLogger } from './logger/crashlytics';
|
|
47
50
|
export type { NetworkConnectionType, NetworkStatus, NetworkStatusLike, NetworkStatusListener } from './network';
|
|
48
51
|
export { addNetworkStatusListener, getNetworkStatus, setNetworkStatusImplementation, useNetworkStatus } from './network';
|
|
52
|
+
export type { PushStatus } from './push/status';
|
|
53
|
+
export { PUSH_STATUS } from './push/status';
|
|
49
54
|
export type { AsyncStorageLike, StorageApi } from './storage';
|
|
50
55
|
export { isStorageAvailable, Storage, setStorageImplementation } from './storage';
|
|
51
56
|
export { encodeBase64 } from './utils/base64';
|