@webority/mobile-core 0.0.29 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -0
- package/lib/commonjs/api/baseUrl.js +1 -34
- package/lib/commonjs/api/clientHeaders.js +1 -0
- package/lib/commonjs/api/curl.js +1 -109
- package/lib/commonjs/api/minAppVersion.js +1 -0
- package/lib/commonjs/api/multipart.js +1 -21
- package/lib/commonjs/api/publicClient.js +1 -79
- package/lib/commonjs/api/requestDefaults.js +1 -0
- 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/errors/extractApiError.js +1 -0
- package/lib/commonjs/errors/index.js +1 -0
- 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/formatConfig.js +1 -0
- package/lib/commonjs/formatters/house.js +1 -0
- 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 -468
- package/lib/commonjs/push/status.js +1 -0
- package/lib/commonjs/push/task.js +1 -43
- package/lib/commonjs/query/apiBaseQuery.js +1 -0
- package/lib/commonjs/query/createAppApi.js +1 -0
- package/lib/commonjs/query/index.js +1 -0
- package/lib/commonjs/query/listeners.js +1 -0
- package/lib/commonjs/query/paging.js +1 -0
- package/lib/commonjs/query/tags.js +1 -0
- package/lib/commonjs/redux/errorToastMiddleware.js +1 -0
- package/lib/commonjs/redux/index.js +1 -0
- package/lib/commonjs/redux/rootReducer.js +1 -0
- package/lib/commonjs/redux/serializableCheck.js +1 -0
- 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/buildNumber.js +1 -0
- package/lib/commonjs/versionCheck/index.js +1 -419
- package/lib/module/api/baseUrl.js +1 -30
- package/lib/module/api/clientHeaders.js +1 -0
- package/lib/module/api/curl.js +1 -104
- package/lib/module/api/minAppVersion.js +1 -0
- package/lib/module/api/multipart.js +1 -16
- package/lib/module/api/publicClient.js +1 -75
- package/lib/module/api/requestDefaults.js +1 -0
- 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/errors/extractApiError.js +1 -0
- package/lib/module/errors/index.js +1 -0
- 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/formatConfig.js +1 -0
- package/lib/module/formatters/house.js +1 -0
- 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 -452
- package/lib/module/push/status.js +1 -0
- package/lib/module/push/task.js +1 -38
- package/lib/module/query/apiBaseQuery.js +1 -0
- package/lib/module/query/createAppApi.js +1 -0
- package/lib/module/query/index.js +1 -0
- package/lib/module/query/listeners.js +1 -0
- package/lib/module/query/paging.js +1 -0
- package/lib/module/query/tags.js +1 -0
- package/lib/module/redux/errorToastMiddleware.js +1 -0
- package/lib/module/redux/index.js +1 -0
- package/lib/module/redux/rootReducer.js +1 -0
- package/lib/module/redux/serializableCheck.js +1 -0
- 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/buildNumber.js +1 -0
- package/lib/module/versionCheck/index.js +1 -413
- package/lib/typescript/commonjs/api/clientHeaders.d.ts +25 -0
- package/lib/typescript/commonjs/api/minAppVersion.d.ts +24 -0
- package/lib/typescript/commonjs/api/requestDefaults.d.ts +21 -0
- package/lib/typescript/commonjs/api/responseBodyText.d.ts +6 -0
- package/lib/typescript/commonjs/api/retry.d.ts +23 -9
- package/lib/typescript/commonjs/api/tokenRefresh.d.ts +14 -2
- package/lib/typescript/commonjs/api/userClient.d.ts +1 -1
- package/lib/typescript/commonjs/auth/authStore.d.ts +76 -0
- package/lib/typescript/commonjs/auth/index.d.ts +2 -2
- package/lib/typescript/commonjs/config/index.d.ts +31 -2
- package/lib/typescript/commonjs/errors/extractApiError.d.ts +69 -0
- package/lib/typescript/commonjs/errors/index.d.ts +3 -0
- package/lib/typescript/commonjs/formatters/currency.d.ts +22 -7
- package/lib/typescript/commonjs/formatters/date.d.ts +13 -13
- package/lib/typescript/commonjs/formatters/dateMath.d.ts +4 -2
- package/lib/typescript/commonjs/formatters/formatConfig.d.ts +48 -0
- package/lib/typescript/commonjs/formatters/house.d.ts +143 -0
- package/lib/typescript/commonjs/formatters/index.d.ts +4 -0
- package/lib/typescript/commonjs/formatters/number.d.ts +15 -5
- package/lib/typescript/commonjs/index.d.ts +26 -8
- package/lib/typescript/commonjs/initSDK.d.ts +18 -6
- package/lib/typescript/commonjs/initUserAuth.d.ts +29 -0
- package/lib/typescript/commonjs/logger/crashlytics.d.ts +31 -0
- package/lib/typescript/commonjs/logger/index.d.ts +17 -0
- package/lib/typescript/commonjs/push/index.d.ts +3 -1
- package/lib/typescript/commonjs/push/push.d.ts +1 -1
- package/lib/typescript/commonjs/push/status.d.ts +9 -0
- package/lib/typescript/commonjs/query/apiBaseQuery.d.ts +55 -0
- package/lib/typescript/commonjs/query/createAppApi.d.ts +21 -0
- package/lib/typescript/commonjs/query/index.d.ts +9 -0
- package/lib/typescript/commonjs/query/listeners.d.ts +11 -0
- package/lib/typescript/commonjs/query/paging.d.ts +42 -0
- package/lib/typescript/commonjs/query/tags.d.ts +31 -0
- package/lib/typescript/commonjs/redux/errorToastMiddleware.d.ts +51 -0
- package/lib/typescript/commonjs/redux/index.d.ts +6 -0
- package/lib/typescript/commonjs/redux/rootReducer.d.ts +19 -0
- package/lib/typescript/commonjs/redux/serializableCheck.d.ts +14 -0
- package/lib/typescript/commonjs/secureScreen/index.d.ts +25 -0
- package/lib/typescript/commonjs/versionCheck/buildNumber.d.ts +14 -0
- package/lib/typescript/commonjs/versionCheck/index.d.ts +28 -17
- package/lib/typescript/module/api/clientHeaders.d.ts +25 -0
- package/lib/typescript/module/api/minAppVersion.d.ts +24 -0
- package/lib/typescript/module/api/requestDefaults.d.ts +21 -0
- package/lib/typescript/module/api/responseBodyText.d.ts +6 -0
- package/lib/typescript/module/api/retry.d.ts +23 -9
- package/lib/typescript/module/api/tokenRefresh.d.ts +14 -2
- package/lib/typescript/module/api/userClient.d.ts +1 -1
- package/lib/typescript/module/auth/authStore.d.ts +76 -0
- package/lib/typescript/module/auth/index.d.ts +2 -2
- package/lib/typescript/module/config/index.d.ts +31 -2
- package/lib/typescript/module/errors/extractApiError.d.ts +69 -0
- package/lib/typescript/module/errors/index.d.ts +3 -0
- package/lib/typescript/module/formatters/currency.d.ts +22 -7
- package/lib/typescript/module/formatters/date.d.ts +13 -13
- package/lib/typescript/module/formatters/dateMath.d.ts +4 -2
- package/lib/typescript/module/formatters/formatConfig.d.ts +48 -0
- package/lib/typescript/module/formatters/house.d.ts +143 -0
- package/lib/typescript/module/formatters/index.d.ts +4 -0
- package/lib/typescript/module/formatters/number.d.ts +15 -5
- package/lib/typescript/module/index.d.ts +26 -8
- package/lib/typescript/module/initSDK.d.ts +18 -6
- package/lib/typescript/module/initUserAuth.d.ts +29 -0
- package/lib/typescript/module/logger/crashlytics.d.ts +31 -0
- package/lib/typescript/module/logger/index.d.ts +17 -0
- package/lib/typescript/module/push/index.d.ts +3 -1
- package/lib/typescript/module/push/push.d.ts +1 -1
- package/lib/typescript/module/push/status.d.ts +9 -0
- package/lib/typescript/module/query/apiBaseQuery.d.ts +55 -0
- package/lib/typescript/module/query/createAppApi.d.ts +21 -0
- package/lib/typescript/module/query/index.d.ts +9 -0
- package/lib/typescript/module/query/listeners.d.ts +11 -0
- package/lib/typescript/module/query/paging.d.ts +42 -0
- package/lib/typescript/module/query/tags.d.ts +31 -0
- package/lib/typescript/module/redux/errorToastMiddleware.d.ts +51 -0
- package/lib/typescript/module/redux/index.d.ts +6 -0
- package/lib/typescript/module/redux/rootReducer.d.ts +19 -0
- package/lib/typescript/module/redux/serializableCheck.d.ts +14 -0
- package/lib/typescript/module/secureScreen/index.d.ts +25 -0
- package/lib/typescript/module/versionCheck/buildNumber.d.ts +14 -0
- package/lib/typescript/module/versionCheck/index.d.ts +28 -17
- package/package.json +52 -5
|
@@ -1,205 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";const RE_EMAIL=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,RE_INDIAN_MOBILE=/^[6-9]\d{9}$/,RE_NUMERIC=/^-?\d+(?:\.\d+)?$/,RE_INTEGER=/^-?\d+$/,RE_ALPHANUMERIC=/^[a-zA-Z0-9]+$/,RE_PINCODE_IN=/^[1-9]\d{5}$/,RE_PAN=/^[A-Z]{5}\d{4}[A-Z]$/,RE_GSTIN=/^\d{2}[A-Z]{5}\d{4}[A-Z][1-9A-Z]Z[0-9A-Z]$/,RE_AADHAAR=/^[2-9]\d{11}$/,RE_IFSC=/^[A-Z]{4}0[A-Z0-9]{6}$/,RE_HEX_COLOR=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,asString=t=>"string"==typeof t?t.trim():null;export const isNonEmpty=t=>{const e=asString(t);return!!e&&e.length>0};export const isEmail=t=>{const e=asString(t);return!!e&&RE_EMAIL.test(e)};export const isIndianMobile=t=>{const e=asString(t);if(!e)return!1;const r=e.replace(/\D/g,""),n=r.startsWith("91")&&12===r.length?r.slice(2):r;return RE_INDIAN_MOBILE.test(n)};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&&RE_NUMERIC.test(e)};export const isInteger=t=>{if("number"==typeof t)return Number.isInteger(t);const e=asString(t);return!!e&&RE_INTEGER.test(e)};export const isAlphanumeric=t=>{const e=asString(t);return!!e&&RE_ALPHANUMERIC.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:i=!1}=e;return!(t.length<r)&&(!(n&&!/[A-Z]/.test(t))&&(!(s&&!/[a-z]/.test(t))&&(!(o&&!/\d/.test(t))&&!(i&&!/[^A-Za-z0-9]/.test(t)))))};export const isIndianPincode=t=>{const e=asString(t);return!!e&&RE_PINCODE_IN.test(e)};export const isPan=t=>{const e=asString(t);return!!e&&RE_PAN.test(e.toUpperCase())};const BASE_36="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",gstinCheckCharacter=t=>{let e=0;for(let r=0;r<14;r+=1){const n=BASE_36.indexOf(t[r])*(r%2==0?1:2);e+=Math.floor(n/36)+n%36}return BASE_36[(36-e%36)%36]};export const isGstin=t=>{const e=asString(t)?.toUpperCase();return!!e&&RE_GSTIN.test(e)&&e[14]===gstinCheckCharacter(e)};const VERHOEFF_D=[[0,1,2,3,4,5,6,7,8,9],[1,2,3,4,0,6,7,8,9,5],[2,3,4,0,1,7,8,9,5,6],[3,4,0,1,2,8,9,5,6,7],[4,0,1,2,3,9,5,6,7,8],[5,9,8,7,6,0,4,3,2,1],[6,5,9,8,7,1,0,4,3,2],[7,6,5,9,8,2,1,0,4,3],[8,7,6,5,9,3,2,1,0,4],[9,8,7,6,5,4,3,2,1,0]],VERHOEFF_P=[[0,1,2,3,4,5,6,7,8,9],[1,5,7,6,2,8,3,0,9,4],[5,8,0,3,7,9,6,1,4,2],[8,9,1,6,0,4,3,5,2,7],[9,4,5,3,1,2,6,8,7,0],[4,2,8,6,5,7,3,9,0,1],[2,7,9,3,8,0,6,4,1,5],[7,0,4,6,9,1,3,2,5,8]],isVerhoeffValid=t=>{let e=0;for(let r=0;r<t.length;r+=1){const n=Number(t[t.length-1-r]);e=VERHOEFF_D[e][VERHOEFF_P[r%8][n]]}return 0===e};export const isAadhaar=t=>{const e=asString(t);if(!e)return!1;const r=e.replace(/[\s-]/g,"");return RE_AADHAAR.test(r)&&isVerhoeffValid(r)};export const isIfsc=t=>{const e=asString(t);return!!e&&RE_IFSC.test(e.toUpperCase())};export const isHexColor=t=>{const e=asString(t);return!!e&&RE_HEX_COLOR.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";export const parseBuildNumber=e=>{if("number"==typeof e)return Number.isSafeInteger(e)&&e>=0?e:null;if("string"!=typeof e)return null;const r=e.trim();if(!/^\d+$/.test(r))return null;const t=Number(r);return Number.isSafeInteger(t)?t:null};export const isBuildBelowMinimum=(e,r)=>null!==r&&e<r;
|
|
@@ -1,413 +1 @@
|
|
|
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
|
|
1
|
+
"use strict";import*as Application from"expo-application";import{useMemo,useSyncExternalStore}from"react";import{addMinAppVersionListener,getMinAppVersion}from"../api/minAppVersion.js";import{getConfigValue}from"../config/index.js";import{Logger}from"../logger/index.js";import{isBuildBelowMinimum,parseBuildNumber}from"./buildNumber.js";const expoApplicationBackend={getBundleId:()=>Application.applicationId??"",getVersion:()=>Application.nativeApplicationVersion??"",getBuildNumber:()=>Application.nativeBuildVersion??""};let deviceInfo=null;export const setDeviceInfoImplementation=e=>{deviceInfo=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 Logger.error(t.message),t},getSystemName=()=>{const{Platform:e}=require("react-native");return e.OS},getBundleId=()=>{const e=getConfigValue("appId");if(e)return e;const r=(deviceInfo??expoApplicationBackend).getBundleId();if(r)return r;throw missing("store identifier","appId")},getBuildNumber=()=>{const e=parseBuildNumber(getConfigValue("appBuild"));if(null!==e)return e;const r=parseBuildNumber(deviceInfo?.getBuildNumber?.()??expoApplicationBackend.getBuildNumber());if(null!==r)return r;throw missing("build number","appBuild")},getCountry=()=>getConfigValue("country","in").toLowerCase(),subscribeMinimum=e=>addMinAppVersionListener(()=>e()),getFallbackStoreUrl=()=>{const e=getSystemName().toLowerCase(),r=getCountry();if("ios"===e){const e=getConfigValue("appStoreId");return e?`https://apps.apple.com/${r}/app/id${e}`:`https://apps.apple.com/${r}/app/${getBundleId()}`}return`https://play.google.com/store/apps/details?id=${getBundleId()}&hl=${r}`},storeUrlOrNull=()=>{try{return getFallbackStoreUrl()}catch{return null}},checkForUpdates=()=>{const e=isBuildBelowMinimum(getBuildNumber(),getMinAppVersion());return{isNewVersionAvailable:e,updateType:e?"major":null,url:e?storeUrlOrNull():null}};export const VersionCheck={isNewVersionAvailable:async()=>checkForUpdates(),openUpdateUrl:async e=>{const{Linking:r}=require("react-native");try{if(e)Logger.info(`Opening app store URL: ${e}`),await r.openURL(e);else{const e=getFallbackStoreUrl();Logger.info(`Opening fallback store URL: ${e}`),await r.openURL(e)}return!0}catch(t){const i=t instanceof Error?t.message:String(t);Logger.error(`Failed to open store URL: ${i}`);try{if(e){const e=getFallbackStoreUrl();return Logger.info(`Trying fallback store URL: ${e}`),await r.openURL(e),!0}}catch(e){const r=e instanceof Error?e.message:String(e);Logger.error(`Failed to open fallback URL: ${r}`)}return!1}},getFallbackStoreUrl:getFallbackStoreUrl};const NOT_REQUIRED={isUpdateRequired:!1,updateUrl:null};export const useVersionCheck=(e,r=getConfigValue("environment","Development"))=>{const t=useSyncExternalStore(subscribeMinimum,getMinAppVersion,getMinAppVersion);return useMemo(()=>{if(!e||"Production"!==r||null===t)return NOT_REQUIRED;try{if(!isBuildBelowMinimum(getBuildNumber(),t))return NOT_REQUIRED}catch{return NOT_REQUIRED}return{isUpdateRequired:!0,updateUrl:storeUrlOrNull()}},[e,r,t])};export default VersionCheck;export{isBuildBelowMinimum,parseBuildNumber}from"./buildNumber.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
export declare const CLIENT_BUILD_HEADER = "X-Client-Build";
|
|
3
|
+
export declare const CLIENT_KIND_HEADER = "X-Client-Kind";
|
|
4
|
+
export declare const ACCOUNT_ID_HEADER = "X-Account-Id";
|
|
5
|
+
/** The server picks session rules and the minimum version per kind; the names match its enum. */
|
|
6
|
+
export type ClientKind = 'Browser' | 'MobileApp';
|
|
7
|
+
export declare const CLIENT_KIND: ClientKind;
|
|
8
|
+
/** `<appVersion>+<commit>`, `<appVersion>` when no commit was stamped, `null` before init. */
|
|
9
|
+
export declare const getClientBuild: () => string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Stamps X-Client-Kind and X-Client-Build on every request. A value the app
|
|
12
|
+
* already set (a default header, or a per-request one) wins, so an app that
|
|
13
|
+
* wired them by hand keeps working unchanged.
|
|
14
|
+
*/
|
|
15
|
+
export declare const applyClientHeaders: (client: AxiosInstance) => void;
|
|
16
|
+
export type AccountIdProvider = () => string | null | undefined | Promise<string | null | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Sets X-Account-Id from the app's provider on every send, overwriting, so a
|
|
19
|
+
* request replayed after a refresh or an account switch carries the current
|
|
20
|
+
* account rather than the one it first went out with. `null` sends none.
|
|
21
|
+
*/
|
|
22
|
+
export declare const applyAccountIdHeader: (headers: {
|
|
23
|
+
set: (name: string, value: string) => unknown;
|
|
24
|
+
}, provider: AccountIdProvider | undefined) => Promise<void>;
|
|
25
|
+
//# sourceMappingURL=clientHeaders.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
* The lowest internal build number (the integer `VERSION_INTERNAL`) the API
|
|
4
|
+
* still serves for this client kind. The API sends it on every response,
|
|
5
|
+
* errors included; cross-origin it is readable only when the API lists it in
|
|
6
|
+
* `Access-Control-Expose-Headers`.
|
|
7
|
+
*/
|
|
8
|
+
export declare const MIN_APP_VERSION_HEADER = "X-Min-App-Version";
|
|
9
|
+
export type MinAppVersionListener = (minAppVersion: number) => void;
|
|
10
|
+
/** The floor the API last named, or `null` before any response carried one. */
|
|
11
|
+
export declare const getMinAppVersion: () => number | null;
|
|
12
|
+
/**
|
|
13
|
+
* Called with the floor whenever it changes, and at once with the known floor
|
|
14
|
+
* when one has already arrived, so a late subscriber misses nothing. Returns
|
|
15
|
+
* the unsubscribe function. The versionCheck module is the one subscriber an
|
|
16
|
+
* app normally needs.
|
|
17
|
+
*/
|
|
18
|
+
export declare const addMinAppVersionListener: (listener: MinAppVersionListener) => (() => void);
|
|
19
|
+
/**
|
|
20
|
+
* Reads the floor off every response the client receives, a rejected one too:
|
|
21
|
+
* a 426 Upgrade Required is exactly the case the floor exists for.
|
|
22
|
+
*/
|
|
23
|
+
export declare const readMinAppVersion: (client: AxiosInstance) => void;
|
|
24
|
+
//# sourceMappingURL=minAppVersion.d.ts.map
|