@webority-technologies/mobile-core 0.0.1
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 +15 -0
- package/lib/commonjs/api/publicClient.js +80 -0
- package/lib/commonjs/api/userClient.js +368 -0
- package/lib/commonjs/auth/authStore.js +155 -0
- package/lib/commonjs/auth/index.js +44 -0
- package/lib/commonjs/auth/jwt.js +88 -0
- package/lib/commonjs/config/index.js +65 -0
- package/lib/commonjs/formatters/currency.js +69 -0
- package/lib/commonjs/formatters/date.js +168 -0
- package/lib/commonjs/formatters/index.js +77 -0
- package/lib/commonjs/formatters/initials.js +32 -0
- package/lib/commonjs/formatters/number.js +88 -0
- package/lib/commonjs/formatters/phone.js +67 -0
- package/lib/commonjs/index.js +383 -0
- package/lib/commonjs/initSDK.js +45 -0
- package/lib/commonjs/initUserAuth.js +38 -0
- package/lib/commonjs/logger/index.js +137 -0
- package/lib/commonjs/network/index.js +25 -0
- package/lib/commonjs/network/networkStatus.js +98 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/permissions/index.js +200 -0
- package/lib/commonjs/storage/index.js +193 -0
- package/lib/commonjs/utils/imageCompression.js +75 -0
- package/lib/commonjs/utils/index.js +13 -0
- package/lib/commonjs/validators/index.js +193 -0
- package/lib/commonjs/versionCheck/index.js +395 -0
- package/lib/module/api/publicClient.js +76 -0
- package/lib/module/api/userClient.js +360 -0
- package/lib/module/auth/authStore.js +148 -0
- package/lib/module/auth/index.js +5 -0
- package/lib/module/auth/jwt.js +82 -0
- package/lib/module/config/index.js +57 -0
- package/lib/module/formatters/currency.js +64 -0
- package/lib/module/formatters/date.js +160 -0
- package/lib/module/formatters/index.js +8 -0
- package/lib/module/formatters/initials.js +27 -0
- package/lib/module/formatters/number.js +81 -0
- package/lib/module/formatters/phone.js +61 -0
- package/lib/module/index.js +30 -0
- package/lib/module/initSDK.js +40 -0
- package/lib/module/initUserAuth.js +34 -0
- package/lib/module/logger/index.js +133 -0
- package/lib/module/network/index.js +4 -0
- package/lib/module/network/networkStatus.js +91 -0
- package/lib/module/package.json +1 -0
- package/lib/module/permissions/index.js +197 -0
- package/lib/module/storage/index.js +189 -0
- package/lib/module/utils/imageCompression.js +69 -0
- package/lib/module/utils/index.js +4 -0
- package/lib/module/validators/index.js +171 -0
- package/lib/module/versionCheck/index.js +390 -0
- package/lib/typescript/commonjs/api/publicClient.d.ts +11 -0
- package/lib/typescript/commonjs/api/userClient.d.ts +49 -0
- package/lib/typescript/commonjs/auth/authStore.d.ts +43 -0
- package/lib/typescript/commonjs/auth/index.d.ts +5 -0
- package/lib/typescript/commonjs/auth/jwt.d.ts +31 -0
- package/lib/typescript/commonjs/config/index.d.ts +49 -0
- package/lib/typescript/commonjs/formatters/currency.d.ts +24 -0
- package/lib/typescript/commonjs/formatters/date.d.ts +22 -0
- package/lib/typescript/commonjs/formatters/index.d.ts +8 -0
- package/lib/typescript/commonjs/formatters/initials.d.ts +11 -0
- package/lib/typescript/commonjs/formatters/number.d.ts +15 -0
- package/lib/typescript/commonjs/formatters/phone.d.ts +13 -0
- package/lib/typescript/commonjs/index.d.ts +30 -0
- package/lib/typescript/commonjs/initSDK.d.ts +40 -0
- package/lib/typescript/commonjs/initUserAuth.d.ts +22 -0
- package/lib/typescript/commonjs/logger/index.d.ts +42 -0
- package/lib/typescript/commonjs/network/index.d.ts +3 -0
- package/lib/typescript/commonjs/network/networkStatus.d.ts +27 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/permissions/index.d.ts +20 -0
- package/lib/typescript/commonjs/storage/index.d.ts +42 -0
- package/lib/typescript/commonjs/utils/imageCompression.d.ts +31 -0
- package/lib/typescript/commonjs/utils/index.d.ts +3 -0
- package/lib/typescript/commonjs/validators/index.d.ts +46 -0
- package/lib/typescript/commonjs/versionCheck/index.d.ts +80 -0
- package/lib/typescript/module/api/publicClient.d.ts +11 -0
- package/lib/typescript/module/api/userClient.d.ts +49 -0
- package/lib/typescript/module/auth/authStore.d.ts +43 -0
- package/lib/typescript/module/auth/index.d.ts +5 -0
- package/lib/typescript/module/auth/jwt.d.ts +31 -0
- package/lib/typescript/module/config/index.d.ts +49 -0
- package/lib/typescript/module/formatters/currency.d.ts +24 -0
- package/lib/typescript/module/formatters/date.d.ts +22 -0
- package/lib/typescript/module/formatters/index.d.ts +8 -0
- package/lib/typescript/module/formatters/initials.d.ts +11 -0
- package/lib/typescript/module/formatters/number.d.ts +15 -0
- package/lib/typescript/module/formatters/phone.d.ts +13 -0
- package/lib/typescript/module/index.d.ts +30 -0
- package/lib/typescript/module/initSDK.d.ts +40 -0
- package/lib/typescript/module/initUserAuth.d.ts +22 -0
- package/lib/typescript/module/logger/index.d.ts +42 -0
- package/lib/typescript/module/network/index.d.ts +3 -0
- package/lib/typescript/module/network/networkStatus.d.ts +27 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/permissions/index.d.ts +20 -0
- package/lib/typescript/module/storage/index.d.ts +42 -0
- package/lib/typescript/module/utils/imageCompression.d.ts +31 -0
- package/lib/typescript/module/utils/index.d.ts +3 -0
- package/lib/typescript/module/validators/index.d.ts +46 -0
- package/lib/typescript/module/versionCheck/index.d.ts +80 -0
- package/package.json +112 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const hasIntlNumber = () => typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
|
|
4
|
+
const indianGroupingFallback = (n, fractionDigits) => {
|
|
5
|
+
// Indian numbering: 1,23,45,678.90 (last 3 digits, then groups of 2).
|
|
6
|
+
const sign = n < 0 ? '-' : '';
|
|
7
|
+
const abs = Math.abs(n);
|
|
8
|
+
const fixed = abs.toFixed(fractionDigits);
|
|
9
|
+
const [intPart, decPart] = fixed.split('.');
|
|
10
|
+
const last3 = intPart.length > 3 ? intPart.slice(-3) : intPart;
|
|
11
|
+
const rest = intPart.length > 3 ? intPart.slice(0, -3) : '';
|
|
12
|
+
const grouped = rest ? rest.replace(/\B(?=(\d{2})+(?!\d))/g, ',') + ',' + last3 : last3;
|
|
13
|
+
return sign + grouped + (decPart ? `.${decPart}` : '');
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Format an amount as currency. Defaults to **INR** with Indian numbering (`en-IN`),
|
|
18
|
+
* which matches the standard convention across Webority projects.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* formatCurrency(150000) // ₹1,50,000
|
|
22
|
+
* formatCurrency(1234.5) // ₹1,234.50
|
|
23
|
+
* formatCurrency(99, { currency: 'USD', locale: 'en-US' }) // $99.00
|
|
24
|
+
* formatCurrency(150000, { stripSymbol: true }) // 1,50,000
|
|
25
|
+
*/
|
|
26
|
+
export const formatCurrency = (amount, options = {}) => {
|
|
27
|
+
if (amount == null || Number.isNaN(amount)) {
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
const {
|
|
31
|
+
currency = 'INR',
|
|
32
|
+
locale = 'en-IN',
|
|
33
|
+
minimumFractionDigits,
|
|
34
|
+
maximumFractionDigits = 2,
|
|
35
|
+
stripSymbol = false
|
|
36
|
+
} = options;
|
|
37
|
+
const minFrac = minimumFractionDigits ?? (Number.isInteger(amount) ? 0 : 2);
|
|
38
|
+
if (hasIntlNumber()) {
|
|
39
|
+
try {
|
|
40
|
+
const formatted = new Intl.NumberFormat(locale, {
|
|
41
|
+
style: 'currency',
|
|
42
|
+
currency,
|
|
43
|
+
minimumFractionDigits: minFrac,
|
|
44
|
+
maximumFractionDigits
|
|
45
|
+
}).format(amount);
|
|
46
|
+
if (!stripSymbol) {
|
|
47
|
+
return formatted;
|
|
48
|
+
}
|
|
49
|
+
// Strip currency code/symbol while keeping digits, separators and sign.
|
|
50
|
+
return formatted.replace(/[^\d,.\s\-+]/g, '').trim();
|
|
51
|
+
} catch {
|
|
52
|
+
/* fall through to fallback */
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const numeric = indianGroupingFallback(amount, minFrac);
|
|
56
|
+
if (stripSymbol) {
|
|
57
|
+
return numeric;
|
|
58
|
+
}
|
|
59
|
+
if (currency === 'INR') {
|
|
60
|
+
return `₹${numeric}`;
|
|
61
|
+
}
|
|
62
|
+
return `${currency} ${numeric}`;
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=currency.js.map
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const toDate = value => {
|
|
4
|
+
if (value instanceof Date) {
|
|
5
|
+
return Number.isNaN(value.getTime()) ? null : value;
|
|
6
|
+
}
|
|
7
|
+
const d = new Date(value);
|
|
8
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
9
|
+
};
|
|
10
|
+
const hasIntl = () => typeof Intl !== 'undefined' && typeof Intl.DateTimeFormat === 'function';
|
|
11
|
+
const PAD = n => n < 10 ? `0${n}` : `${n}`;
|
|
12
|
+
const fallbackDate = (d, style) => {
|
|
13
|
+
const day = PAD(d.getDate());
|
|
14
|
+
const monthShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
|
|
15
|
+
const monthLong = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];
|
|
16
|
+
const year = d.getFullYear();
|
|
17
|
+
const weekdayLong = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];
|
|
18
|
+
switch (style) {
|
|
19
|
+
case 'short':
|
|
20
|
+
return `${day}/${PAD(d.getMonth() + 1)}/${year}`;
|
|
21
|
+
case 'long':
|
|
22
|
+
return `${day} ${monthLong} ${year}`;
|
|
23
|
+
case 'full':
|
|
24
|
+
return `${weekdayLong}, ${day} ${monthLong} ${year}`;
|
|
25
|
+
case 'medium':
|
|
26
|
+
default:
|
|
27
|
+
return `${day} ${monthShort} ${year}`;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const fallbackTime = (d, style) => {
|
|
31
|
+
const hh = PAD(d.getHours());
|
|
32
|
+
const mm = PAD(d.getMinutes());
|
|
33
|
+
if (style === 'short') {
|
|
34
|
+
return `${hh}:${mm}`;
|
|
35
|
+
}
|
|
36
|
+
const ss = PAD(d.getSeconds());
|
|
37
|
+
return `${hh}:${mm}:${ss}`;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Locale-aware date formatter. Defaults to `'medium'` style and `'en-IN'` locale,
|
|
42
|
+
* matching the Indian-locale convention used across Webority apps.
|
|
43
|
+
*/
|
|
44
|
+
export const formatDate = (value, style = 'medium', locale = 'en-IN') => {
|
|
45
|
+
const d = toDate(value);
|
|
46
|
+
if (!d) {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
if (hasIntl()) {
|
|
50
|
+
try {
|
|
51
|
+
return new Intl.DateTimeFormat(locale, {
|
|
52
|
+
dateStyle: style
|
|
53
|
+
}).format(d);
|
|
54
|
+
} catch {
|
|
55
|
+
/* fall through to fallback */
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return fallbackDate(d, style);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Locale-aware time formatter (24-hour fallback when Intl is unavailable).
|
|
63
|
+
*/
|
|
64
|
+
export const formatTime = (value, style = 'short', locale = 'en-IN') => {
|
|
65
|
+
const d = toDate(value);
|
|
66
|
+
if (!d) {
|
|
67
|
+
return '';
|
|
68
|
+
}
|
|
69
|
+
if (hasIntl()) {
|
|
70
|
+
try {
|
|
71
|
+
return new Intl.DateTimeFormat(locale, {
|
|
72
|
+
timeStyle: style
|
|
73
|
+
}).format(d);
|
|
74
|
+
} catch {
|
|
75
|
+
/* fall through */
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return fallbackTime(d, style);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Combined date + time formatter.
|
|
83
|
+
*/
|
|
84
|
+
export const formatDateTime = (value, dateStyle = 'medium', timeStyle = 'short', locale = 'en-IN') => {
|
|
85
|
+
const d = toDate(value);
|
|
86
|
+
if (!d) {
|
|
87
|
+
return '';
|
|
88
|
+
}
|
|
89
|
+
if (hasIntl()) {
|
|
90
|
+
try {
|
|
91
|
+
return new Intl.DateTimeFormat(locale, {
|
|
92
|
+
dateStyle,
|
|
93
|
+
timeStyle
|
|
94
|
+
}).format(d);
|
|
95
|
+
} catch {
|
|
96
|
+
/* fall through */
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return `${fallbackDate(d, dateStyle)}, ${fallbackTime(d, timeStyle)}`;
|
|
100
|
+
};
|
|
101
|
+
const SECOND = 1000;
|
|
102
|
+
const MINUTE = 60 * SECOND;
|
|
103
|
+
const HOUR = 60 * MINUTE;
|
|
104
|
+
const DAY = 24 * HOUR;
|
|
105
|
+
const WEEK = 7 * DAY;
|
|
106
|
+
const MONTH = 30 * DAY;
|
|
107
|
+
const YEAR = 365 * DAY;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Returns a humanized relative-time string (e.g. "5 minutes ago", "in 3 days").
|
|
111
|
+
* Uses `Intl.RelativeTimeFormat` when available; otherwise a sensible English fallback.
|
|
112
|
+
*/
|
|
113
|
+
export const formatRelativeTime = (value, base = new Date(), locale = 'en-IN') => {
|
|
114
|
+
const target = toDate(value);
|
|
115
|
+
const now = toDate(base);
|
|
116
|
+
if (!target || !now) {
|
|
117
|
+
return '';
|
|
118
|
+
}
|
|
119
|
+
const diffMs = target.getTime() - now.getTime();
|
|
120
|
+
const abs = Math.abs(diffMs);
|
|
121
|
+
let unit;
|
|
122
|
+
let amount;
|
|
123
|
+
if (abs < MINUTE) {
|
|
124
|
+
unit = 'second';
|
|
125
|
+
amount = Math.round(diffMs / SECOND);
|
|
126
|
+
} else if (abs < HOUR) {
|
|
127
|
+
unit = 'minute';
|
|
128
|
+
amount = Math.round(diffMs / MINUTE);
|
|
129
|
+
} else if (abs < DAY) {
|
|
130
|
+
unit = 'hour';
|
|
131
|
+
amount = Math.round(diffMs / HOUR);
|
|
132
|
+
} else if (abs < WEEK) {
|
|
133
|
+
unit = 'day';
|
|
134
|
+
amount = Math.round(diffMs / DAY);
|
|
135
|
+
} else if (abs < MONTH) {
|
|
136
|
+
unit = 'week';
|
|
137
|
+
amount = Math.round(diffMs / WEEK);
|
|
138
|
+
} else if (abs < YEAR) {
|
|
139
|
+
unit = 'month';
|
|
140
|
+
amount = Math.round(diffMs / MONTH);
|
|
141
|
+
} else {
|
|
142
|
+
unit = 'year';
|
|
143
|
+
amount = Math.round(diffMs / YEAR);
|
|
144
|
+
}
|
|
145
|
+
const Rtf = Intl.RelativeTimeFormat;
|
|
146
|
+
if (typeof Rtf === 'function') {
|
|
147
|
+
try {
|
|
148
|
+
return new Rtf(locale, {
|
|
149
|
+
numeric: 'auto'
|
|
150
|
+
}).format(amount, unit);
|
|
151
|
+
} catch {
|
|
152
|
+
/* fall through */
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const past = amount < 0;
|
|
156
|
+
const n = Math.abs(amount);
|
|
157
|
+
const u = n === 1 ? unit : `${unit}s`;
|
|
158
|
+
return past ? `${n} ${u} ago` : `in ${n} ${u}`;
|
|
159
|
+
};
|
|
160
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export { formatCurrency } from "./currency.js";
|
|
4
|
+
export { formatDate, formatDateTime, formatRelativeTime, formatTime } from "./date.js";
|
|
5
|
+
export { getInitials } from "./initials.js";
|
|
6
|
+
export { formatCompactNumber, formatNumber, formatPercent } from "./number.js";
|
|
7
|
+
export { formatPhone, normalizePhone } from "./phone.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns up to `maxChars` uppercase initials from a name.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* getInitials('Navneet Singh') // 'NS'
|
|
8
|
+
* getInitials('mary anne lee', 3) // 'MAL'
|
|
9
|
+
* getInitials('navneet') // 'NA'
|
|
10
|
+
* getInitials(' ') // ''
|
|
11
|
+
*/
|
|
12
|
+
export const getInitials = (name, maxChars = 2) => {
|
|
13
|
+
if (!name) {
|
|
14
|
+
return '';
|
|
15
|
+
}
|
|
16
|
+
const trimmed = name.trim();
|
|
17
|
+
if (!trimmed) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
const parts = trimmed.split(/\s+/);
|
|
21
|
+
if (parts.length === 1) {
|
|
22
|
+
const single = parts[0] ?? '';
|
|
23
|
+
return single.slice(0, maxChars).toUpperCase();
|
|
24
|
+
}
|
|
25
|
+
return parts.slice(0, maxChars).map(p => (p[0] ?? '').toUpperCase()).join('');
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=initials.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const hasIntlNumber = () => typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Locale-aware number formatter. Defaults to `'en-IN'` (Indian grouping).
|
|
7
|
+
*/
|
|
8
|
+
export const formatNumber = (value, fractionDigits, locale = 'en-IN') => {
|
|
9
|
+
if (value == null || Number.isNaN(value)) {
|
|
10
|
+
return '';
|
|
11
|
+
}
|
|
12
|
+
if (hasIntlNumber()) {
|
|
13
|
+
try {
|
|
14
|
+
const opts = {};
|
|
15
|
+
if (fractionDigits != null) {
|
|
16
|
+
opts.minimumFractionDigits = fractionDigits;
|
|
17
|
+
opts.maximumFractionDigits = fractionDigits;
|
|
18
|
+
}
|
|
19
|
+
return new Intl.NumberFormat(locale, opts).format(value);
|
|
20
|
+
} catch {
|
|
21
|
+
/* fall through */
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return fractionDigits != null ? value.toFixed(fractionDigits) : String(value);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Format a 0–1 ratio (or 0–100 percent) as a percent string.
|
|
29
|
+
* Pass `asRatio: false` if your input is already on the 0–100 scale.
|
|
30
|
+
*/
|
|
31
|
+
export const formatPercent = (value, fractionDigits = 0, asRatio = true, locale = 'en-IN') => {
|
|
32
|
+
if (value == null || Number.isNaN(value)) {
|
|
33
|
+
return '';
|
|
34
|
+
}
|
|
35
|
+
const ratio = asRatio ? value : value / 100;
|
|
36
|
+
if (hasIntlNumber()) {
|
|
37
|
+
try {
|
|
38
|
+
return new Intl.NumberFormat(locale, {
|
|
39
|
+
style: 'percent',
|
|
40
|
+
minimumFractionDigits: fractionDigits,
|
|
41
|
+
maximumFractionDigits: fractionDigits
|
|
42
|
+
}).format(ratio);
|
|
43
|
+
} catch {
|
|
44
|
+
/* fall through */
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return `${(ratio * 100).toFixed(fractionDigits)}%`;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Format a number compactly (1.2K, 3.4M, 1.5L, 2.3Cr).
|
|
52
|
+
* Defaults to Indian compact notation via `'en-IN'` locale (lakh / crore).
|
|
53
|
+
*/
|
|
54
|
+
export const formatCompactNumber = (value, locale = 'en-IN') => {
|
|
55
|
+
if (value == null || Number.isNaN(value)) {
|
|
56
|
+
return '';
|
|
57
|
+
}
|
|
58
|
+
if (hasIntlNumber()) {
|
|
59
|
+
try {
|
|
60
|
+
return new Intl.NumberFormat(locale, {
|
|
61
|
+
notation: 'compact',
|
|
62
|
+
maximumFractionDigits: 1
|
|
63
|
+
}).format(value);
|
|
64
|
+
} catch {
|
|
65
|
+
/* fall through */
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const abs = Math.abs(value);
|
|
69
|
+
const sign = value < 0 ? '-' : '';
|
|
70
|
+
if (abs >= 1e7) {
|
|
71
|
+
return `${sign}${(abs / 1e7).toFixed(1)}Cr`;
|
|
72
|
+
}
|
|
73
|
+
if (abs >= 1e5) {
|
|
74
|
+
return `${sign}${(abs / 1e5).toFixed(1)}L`;
|
|
75
|
+
}
|
|
76
|
+
if (abs >= 1e3) {
|
|
77
|
+
return `${sign}${(abs / 1e3).toFixed(1)}K`;
|
|
78
|
+
}
|
|
79
|
+
return `${value}`;
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=number.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Strip everything except digits and a leading `+` (preserved if present).
|
|
5
|
+
*/
|
|
6
|
+
export const normalizePhone = input => {
|
|
7
|
+
if (!input) {
|
|
8
|
+
return '';
|
|
9
|
+
}
|
|
10
|
+
const trimmed = input.trim();
|
|
11
|
+
const hasPlus = trimmed.startsWith('+');
|
|
12
|
+
const digits = trimmed.replace(/\D/g, '');
|
|
13
|
+
return hasPlus ? `+${digits}` : digits;
|
|
14
|
+
};
|
|
15
|
+
const groupIndianMobile = digits => {
|
|
16
|
+
// Indian mobile is 10 digits: format as `XXXXX XXXXX`.
|
|
17
|
+
if (digits.length !== 10) {
|
|
18
|
+
return digits;
|
|
19
|
+
}
|
|
20
|
+
return `${digits.slice(0, 5)} ${digits.slice(5)}`;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Format a phone number for human display.
|
|
25
|
+
*
|
|
26
|
+
* - Indian mobile (10 digits) → `XXXXX XXXXX`
|
|
27
|
+
* - With `+91` country code → `+91 XXXXX XXXXX`
|
|
28
|
+
* - Other inputs are returned as `+CC NNNN NNNN…` best-effort grouping.
|
|
29
|
+
*/
|
|
30
|
+
export const formatPhone = (input, defaultCountryCode = '+91') => {
|
|
31
|
+
if (!input) {
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
const normalized = normalizePhone(input);
|
|
35
|
+
if (!normalized) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Already starts with +
|
|
40
|
+
if (normalized.startsWith('+')) {
|
|
41
|
+
const rest = normalized.slice(1);
|
|
42
|
+
// Indian
|
|
43
|
+
if (rest.startsWith('91') && rest.length === 12) {
|
|
44
|
+
return `+91 ${groupIndianMobile(rest.slice(2))}`;
|
|
45
|
+
}
|
|
46
|
+
// Generic — split country code (first 1–3 digits) and group the rest in 4s.
|
|
47
|
+
const ccLen = rest.length > 11 ? 3 : rest.length > 10 ? 2 : 1;
|
|
48
|
+
const cc = rest.slice(0, ccLen);
|
|
49
|
+
const number = rest.slice(ccLen);
|
|
50
|
+
const grouped = number.replace(/(.{4})(?=.)/g, '$1 ').trim();
|
|
51
|
+
return `+${cc} ${grouped}`.trim();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// No country code; assume default if length matches Indian mobile.
|
|
55
|
+
if (normalized.length === 10) {
|
|
56
|
+
return `${defaultCountryCode} ${groupIndianMobile(normalized)}`;
|
|
57
|
+
}
|
|
58
|
+
// Otherwise just return groups of 4.
|
|
59
|
+
return normalized.replace(/(.{4})(?=.)/g, '$1 ').trim();
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=phone.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// API clients
|
|
4
|
+
export { default as publicClient } from "./api/publicClient.js";
|
|
5
|
+
export { default as userClient, injectAuthActions, injectStore, RequestOfflineError, SESSION_TERMINATION_CODES } from "./api/userClient.js";
|
|
6
|
+
// Auth / token storage
|
|
7
|
+
export { getToken, removeToken, setKeychainImplementation, storeToken } from "./auth/authStore.js";
|
|
8
|
+
export { decodeJWT, getJWTExpiry, isJWTExpired } from "./auth/jwt.js";
|
|
9
|
+
// Configuration
|
|
10
|
+
export { getConfig, getConfigValue, resetConfig, setConfig } from "./config/index.js";
|
|
11
|
+
// Formatters
|
|
12
|
+
export { formatCompactNumber, formatCurrency, formatDate, formatDateTime, formatNumber, formatPercent, formatPhone, formatRelativeTime, formatTime, getInitials, normalizePhone } from "./formatters/index.js";
|
|
13
|
+
// Initialization
|
|
14
|
+
export { initWebority } from "./initSDK.js";
|
|
15
|
+
export { initUserAuth } from "./initUserAuth.js";
|
|
16
|
+
// Logger
|
|
17
|
+
export { Logger, setRemoteLogger } from "./logger/index.js";
|
|
18
|
+
// Network status (the NetworkStatusBanner UI lives in @webority-technologies/mobile-ui)
|
|
19
|
+
export { addNetworkStatusListener, getNetworkStatus, useNetworkStatus } from "./network/index.js";
|
|
20
|
+
// Permissions
|
|
21
|
+
export { Permissions } from "./permissions/index.js";
|
|
22
|
+
// Storage
|
|
23
|
+
export { Storage, setStorageImplementation } from "./storage/index.js";
|
|
24
|
+
// Media utils
|
|
25
|
+
export { compressImage } from "./utils/index.js";
|
|
26
|
+
// Validators
|
|
27
|
+
export { isAadhaar, isAlphanumeric, isBetween, isEmail, isGstin, isHexColor, isIfsc, isIndianMobile, isIndianPincode, isInteger, isNonEmpty, isNumeric, isPan, isPhone, isStrongPassword, isUrl, maxLength, minLength } from "./validators/index.js";
|
|
28
|
+
// Version check (the ForceUpdateDialog UI lives in @webority-technologies/mobile-ui)
|
|
29
|
+
export { setDeviceInfoImplementation, useVersionCheck, VersionCheck } from "./versionCheck/index.js";
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simple initialization API for Webority packages
|
|
5
|
+
* One function to configure everything needed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { setConfig } from "./config/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* Initialize Webority packages with your project configuration.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Basic setup
|
|
14
|
+
* initWebority({
|
|
15
|
+
* baseUrl: 'https://api.myapp.com'
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* // Full configuration
|
|
20
|
+
* initWebority({
|
|
21
|
+
* baseUrl: 'https://api.myapp.com',
|
|
22
|
+
* loggingEnabled: __DEV__,
|
|
23
|
+
* logLevel: 'warn',
|
|
24
|
+
* environment: __DEV__ ? 'Development' : 'Production'
|
|
25
|
+
* });
|
|
26
|
+
*/
|
|
27
|
+
export const initWebority = config => {
|
|
28
|
+
if (!config.baseUrl) {
|
|
29
|
+
throw new Error('baseUrl is required for Webority packages initialization');
|
|
30
|
+
}
|
|
31
|
+
setConfig({
|
|
32
|
+
baseUrl: config.baseUrl,
|
|
33
|
+
loggingEnabled: config.loggingEnabled ?? true,
|
|
34
|
+
logLevel: config.logLevel || 'info',
|
|
35
|
+
environment: config.environment || 'Development',
|
|
36
|
+
country: (config.country || 'in').toLowerCase()
|
|
37
|
+
});
|
|
38
|
+
console.log('✅ Webority packages initialized successfully');
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=initSDK.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simple initialization API for Webority User package
|
|
5
|
+
* Easy setup for Redux integration
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { injectAuthActions, injectStore } from "./api/userClient.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Auth action creators required by the user package.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initialize user package with Redux store and auth actions.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* import store from './store';
|
|
19
|
+
* import { logout, refreshToken } from './actions/authActions';
|
|
20
|
+
*
|
|
21
|
+
* initUserAuth(store, { logout, refreshToken });
|
|
22
|
+
*/
|
|
23
|
+
export const initUserAuth = (store, authActions) => {
|
|
24
|
+
if (!store) {
|
|
25
|
+
throw new Error('Redux store is required for user package initialization');
|
|
26
|
+
}
|
|
27
|
+
if (!authActions.logout || !authActions.refreshToken) {
|
|
28
|
+
throw new Error('Both logout and refreshToken actions are required');
|
|
29
|
+
}
|
|
30
|
+
injectStore(store);
|
|
31
|
+
injectAuthActions(authActions);
|
|
32
|
+
console.log('✅ Webority User package initialized with Redux');
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=initUserAuth.js.map
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { getConfigValue } from "../config/index.js";
|
|
4
|
+
|
|
5
|
+
// ANSI color codes
|
|
6
|
+
const Colors = {
|
|
7
|
+
RESET: '\x1b[0m',
|
|
8
|
+
BLUE: '\x1b[34m',
|
|
9
|
+
YELLOW: '\x1b[33m',
|
|
10
|
+
RED_BOLD: '\x1b[31;1m'
|
|
11
|
+
};
|
|
12
|
+
const LogLevels = {
|
|
13
|
+
INFO: {
|
|
14
|
+
level: 'info',
|
|
15
|
+
color: Colors.BLUE
|
|
16
|
+
},
|
|
17
|
+
WARN: {
|
|
18
|
+
level: 'warn',
|
|
19
|
+
color: Colors.YELLOW
|
|
20
|
+
},
|
|
21
|
+
ERROR: {
|
|
22
|
+
level: 'error',
|
|
23
|
+
color: Colors.RED_BOLD
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
// Check if a specific log level is allowed
|
|
28
|
+
const isLogLevelAllowed = level => {
|
|
29
|
+
const levels = ['info', 'warn', 'error'];
|
|
30
|
+
const current = getConfigValue('logLevel', 'info');
|
|
31
|
+
return levels.indexOf(level) >= levels.indexOf(current);
|
|
32
|
+
};
|
|
33
|
+
const isEnabled = () => getConfigValue('loggingEnabled', true);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Optional remote sink. Apps wire this via `setRemoteLogger()` to forward errors
|
|
37
|
+
* and breadcrumbs to Crashlytics, Sentry, Bugsnag, etc. — without making the
|
|
38
|
+
* library depend on any of them.
|
|
39
|
+
*
|
|
40
|
+
* Every method is optional; the library calls only what the adapter implements.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
let remote = null;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Inject a remote logger adapter (e.g. Firebase Crashlytics, Sentry).
|
|
47
|
+
* Pass `null` to detach. Safe to call before or after `initWebority`.
|
|
48
|
+
*/
|
|
49
|
+
export const setRemoteLogger = impl => {
|
|
50
|
+
remote = impl;
|
|
51
|
+
};
|
|
52
|
+
const safe = fn => {
|
|
53
|
+
if (!fn) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
fn();
|
|
58
|
+
} catch {
|
|
59
|
+
/* never let the remote sink break the caller */
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const toErrorObject = input => {
|
|
63
|
+
if (input instanceof Error) {
|
|
64
|
+
return input;
|
|
65
|
+
}
|
|
66
|
+
if (typeof input === 'string') {
|
|
67
|
+
return new Error(input);
|
|
68
|
+
}
|
|
69
|
+
try {
|
|
70
|
+
return new Error(JSON.stringify(input));
|
|
71
|
+
} catch {
|
|
72
|
+
return new Error(String(input));
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const logInfo = (message, ...optionalParams) => {
|
|
76
|
+
if (!isEnabled() || !isLogLevelAllowed(LogLevels.INFO.level)) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
console.info(`${LogLevels.INFO.color}[INFO]: ${message}${Colors.RESET}`, ...optionalParams);
|
|
80
|
+
safe(() => remote?.log?.('info', message, optionalParams));
|
|
81
|
+
};
|
|
82
|
+
const logWarning = (message, ...optionalParams) => {
|
|
83
|
+
if (!isEnabled() || !isLogLevelAllowed(LogLevels.WARN.level)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
console.warn(`${LogLevels.WARN.color}[WARNING]: ${message}${Colors.RESET}`, ...optionalParams);
|
|
87
|
+
safe(() => remote?.log?.('warn', message, optionalParams));
|
|
88
|
+
};
|
|
89
|
+
const logError = (message, ...optionalParams) => {
|
|
90
|
+
if (isEnabled() && isLogLevelAllowed(LogLevels.ERROR.level)) {
|
|
91
|
+
console.error(`${LogLevels.ERROR.color}[ERROR]: ${message}${Colors.RESET}`, ...optionalParams);
|
|
92
|
+
}
|
|
93
|
+
// Always forward errors to the remote sink — even when console logging is muted —
|
|
94
|
+
// so production crash reporting still works with `loggingEnabled: false`.
|
|
95
|
+
safe(() => remote?.log?.('error', message, optionalParams));
|
|
96
|
+
// First optional param is treated as the underlying error if it looks like one.
|
|
97
|
+
const candidate = optionalParams[0];
|
|
98
|
+
if (candidate !== undefined) {
|
|
99
|
+
safe(() => remote?.recordError?.(toErrorObject(candidate), {
|
|
100
|
+
source: 'Logger.error',
|
|
101
|
+
message
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const breadcrumb = (message, data) => {
|
|
106
|
+
if (isEnabled() && isLogLevelAllowed('info')) {
|
|
107
|
+
console.info(`${Colors.BLUE}[BREADCRUMB]: ${message}${Colors.RESET}`, data ?? '');
|
|
108
|
+
}
|
|
109
|
+
safe(() => remote?.breadcrumb?.(message, data));
|
|
110
|
+
};
|
|
111
|
+
const recordError = (error, context) => {
|
|
112
|
+
const err = toErrorObject(error);
|
|
113
|
+
if (isEnabled() && isLogLevelAllowed('error')) {
|
|
114
|
+
console.error(`${Colors.RED_BOLD}[RECORDED]: ${err.message}${Colors.RESET}`, context ?? '');
|
|
115
|
+
}
|
|
116
|
+
safe(() => remote?.recordError?.(err, context));
|
|
117
|
+
};
|
|
118
|
+
const setUser = (id, attrs) => {
|
|
119
|
+
safe(() => remote?.setUser?.(id, attrs));
|
|
120
|
+
};
|
|
121
|
+
const setAttribute = (key, value) => {
|
|
122
|
+
safe(() => remote?.setAttribute?.(key, value));
|
|
123
|
+
};
|
|
124
|
+
export const Logger = {
|
|
125
|
+
info: logInfo,
|
|
126
|
+
warn: logWarning,
|
|
127
|
+
error: logError,
|
|
128
|
+
breadcrumb,
|
|
129
|
+
recordError,
|
|
130
|
+
setUser,
|
|
131
|
+
setAttribute
|
|
132
|
+
};
|
|
133
|
+
//# sourceMappingURL=index.js.map
|