@webority/mobile-core 0.0.26 → 0.0.28
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 +69 -1
- package/lib/commonjs/api/retry.js +17 -1
- package/lib/commonjs/api/userClient.js +1 -1
- package/lib/commonjs/auth/authStore.js +49 -16
- package/lib/commonjs/config/index.js +8 -2
- package/lib/commonjs/formatters/currency.js +2 -1
- package/lib/commonjs/formatters/date.js +5 -6
- package/lib/commonjs/formatters/dateMath.js +2 -1
- package/lib/commonjs/formatters/intlCache.js +37 -0
- package/lib/commonjs/formatters/number.js +4 -3
- package/lib/commonjs/index.js +7 -0
- package/lib/commonjs/initSDK.js +1 -1
- package/lib/commonjs/network/networkStatus.js +40 -2
- package/lib/commonjs/push/index.js +18 -0
- package/lib/commonjs/push/push.js +177 -15
- package/lib/commonjs/push/task.js +43 -0
- package/lib/commonjs/utils/base64.js +24 -0
- package/lib/module/api/retry.js +17 -1
- package/lib/module/api/userClient.js +2 -2
- package/lib/module/auth/authStore.js +49 -16
- package/lib/module/config/index.js +7 -1
- package/lib/module/formatters/currency.js +2 -1
- package/lib/module/formatters/date.js +5 -6
- package/lib/module/formatters/dateMath.js +2 -1
- package/lib/module/formatters/intlCache.js +30 -0
- package/lib/module/formatters/number.js +4 -3
- package/lib/module/index.js +2 -0
- package/lib/module/initSDK.js +2 -2
- package/lib/module/network/networkStatus.js +37 -0
- package/lib/module/push/index.js +1 -1
- package/lib/module/push/push.js +170 -15
- package/lib/module/push/task.js +38 -0
- package/lib/module/utils/base64.js +19 -0
- package/lib/typescript/commonjs/config/index.d.ts +6 -0
- package/lib/typescript/commonjs/formatters/intlCache.d.ts +6 -0
- package/lib/typescript/commonjs/index.d.ts +1 -0
- package/lib/typescript/commonjs/initSDK.d.ts +1 -1
- package/lib/typescript/commonjs/network/networkStatus.d.ts +6 -0
- package/lib/typescript/commonjs/push/index.d.ts +2 -2
- package/lib/typescript/commonjs/push/push.d.ts +88 -0
- package/lib/typescript/commonjs/push/task.d.ts +15 -0
- package/lib/typescript/commonjs/utils/base64.d.ts +7 -0
- package/lib/typescript/module/config/index.d.ts +6 -0
- package/lib/typescript/module/formatters/intlCache.d.ts +6 -0
- package/lib/typescript/module/index.d.ts +1 -0
- package/lib/typescript/module/initSDK.d.ts +1 -1
- package/lib/typescript/module/network/networkStatus.d.ts +6 -0
- package/lib/typescript/module/push/index.d.ts +2 -2
- package/lib/typescript/module/push/push.d.ts +88 -0
- package/lib/typescript/module/push/task.d.ts +15 -0
- package/lib/typescript/module/utils/base64.d.ts +7 -0
- package/package.json +15 -1
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ import { openDatabase } from '@webority/mobile-core/sqlite';
|
|
|
30
30
|
import { downloadFile } from '@webority/mobile-core/download';
|
|
31
31
|
import { shareFile } from '@webority/mobile-core/share';
|
|
32
32
|
import { initPush, enablePush, usePush } from '@webority/mobile-core/push';
|
|
33
|
+
import { definePushActionTask } from '@webority/mobile-core/push/task';
|
|
33
34
|
import { compressImage } from '@webority/mobile-core/compressor';
|
|
34
35
|
```
|
|
35
36
|
|
|
@@ -43,7 +44,74 @@ the native token (`Fcm` on Android, `Apns` on iOS) and the bundle id to `registe
|
|
|
43
44
|
re-registers when the token changes; `disablePush` calls `unregister`. `onOpen` receives the
|
|
44
45
|
tapped notification's data as strings, including the tap that launched the app. `usePush` gives a
|
|
45
46
|
settings switch its `status` and `enabled`. The library does not remember the switch: an app that
|
|
46
|
-
keeps push on calls `enablePush` at each start.
|
|
47
|
+
keeps push on calls `enablePush` at each start. `setBadgeCount(count)` sets the app icon badge.
|
|
48
|
+
|
|
49
|
+
### Notification buttons
|
|
50
|
+
|
|
51
|
+
A push names a category; the category's buttons are registered on the phone. Register them at
|
|
52
|
+
every start, with the same ids on both platforms:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { setCategories, notifyLocal } from '@webority/mobile-core/push';
|
|
56
|
+
|
|
57
|
+
await setCategories([
|
|
58
|
+
{
|
|
59
|
+
id: 'approval',
|
|
60
|
+
actions: [
|
|
61
|
+
{ id: 'approve', title: 'Approve', opensApp: false },
|
|
62
|
+
{ id: 'reject', title: 'Reject', destructive: true }
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: 'reply',
|
|
67
|
+
actions: [
|
|
68
|
+
{
|
|
69
|
+
id: 'reply',
|
|
70
|
+
title: 'Reply',
|
|
71
|
+
opensApp: false,
|
|
72
|
+
textInput: { submitTitle: 'Send', placeholder: 'Write a reply' }
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
]);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`opensApp` defaults to true; `destructive` and `authenticationRequired` (unlock first) are iOS
|
|
80
|
+
only. A button tap arrives as `{ actionId, userText, data, notificationId }`: `userText` is the
|
|
81
|
+
reply text, `data` the push data as strings, `notificationId` the notification's identifier on
|
|
82
|
+
the phone. A plain tap still goes to `onOpen`; a button tap with no handler opens like a plain tap.
|
|
83
|
+
|
|
84
|
+
To receive button taps in every app state, the killed app included, call `definePushActionTask`
|
|
85
|
+
once at module scope in the entry file, before the root component registers. It needs
|
|
86
|
+
`expo-task-manager`, an optional peer (`npx expo install expo-task-manager`), so it lives on its
|
|
87
|
+
own path:
|
|
88
|
+
|
|
89
|
+
```js
|
|
90
|
+
// index.js
|
|
91
|
+
import { definePushActionTask } from '@webority/mobile-core/push/task';
|
|
92
|
+
import { notifyLocal } from '@webority/mobile-core/push';
|
|
93
|
+
|
|
94
|
+
definePushActionTask(async ({ actionId, userText, data }) => {
|
|
95
|
+
try {
|
|
96
|
+
await settle(actionId, userText, data);
|
|
97
|
+
} catch {
|
|
98
|
+
await notifyLocal({ title: 'Could not approve', body: 'Open the app to try again.' });
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The handler's promise is awaited, so its request can finish before the background work ends.
|
|
104
|
+
`onAction(handler)` from `/push` sets the same handler for taps while JavaScript is running and
|
|
105
|
+
returns a function that removes it. A response reported twice within ten seconds (the launch read,
|
|
106
|
+
the listener and the Android task can each report it) runs once.
|
|
107
|
+
|
|
108
|
+
- **Android:** the background notification task runs the handler for a button tap on a
|
|
109
|
+
backgrounded or killed app. Buttons appear only on notifications expo-notifications draws (for
|
|
110
|
+
example `notifyLocal`). An app that draws its own notifications natively from data-only pushes
|
|
111
|
+
must build each button's intent with expo's `NotificationsService.createNotificationResponseIntent`,
|
|
112
|
+
so the tap reaches this handler.
|
|
113
|
+
- **iOS:** a button with `opensApp: false` launches the app in the background; the response
|
|
114
|
+
reaches the listener `definePushActionTask` sets up. The task is not registered on iOS.
|
|
47
115
|
|
|
48
116
|
Storage and network status stay on the main barrel but load no package on their own. Wire them at
|
|
49
117
|
startup with `setStorageImplementation` and `setNetworkStatusImplementation` if you want them.
|
|
@@ -16,10 +16,26 @@ exports.isRetryableStatus = exports.attachRetry = void 0;
|
|
|
16
16
|
*/
|
|
17
17
|
const isRetryableStatus = status => typeof status === 'number' && (status === 429 || status >= 500 && status <= 599);
|
|
18
18
|
exports.isRetryableStatus = isRetryableStatus;
|
|
19
|
+
const IDEMPOTENT_METHODS = new Set(['get', 'head', 'options', 'put', 'delete']);
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The same reasoning reaches status codes on a write. A 500 on a POST or PATCH
|
|
23
|
+
* can follow a partial commit, so replaying it can duplicate the record; only
|
|
24
|
+
* 429 and 503 say the server refused the request before doing the work. A
|
|
25
|
+
* request that knows its write is safe to repeat passes its own `shouldRetry`.
|
|
26
|
+
*/
|
|
27
|
+
const isRetryableFailure = error => {
|
|
28
|
+
const status = error.response?.status;
|
|
29
|
+
if (!isRetryableStatus(status)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const method = (error.config?.method ?? 'get').toLowerCase();
|
|
33
|
+
return IDEMPOTENT_METHODS.has(method) || status === 429 || status === 503;
|
|
34
|
+
};
|
|
19
35
|
const DEFAULT_POLICY = {
|
|
20
36
|
retries: 3,
|
|
21
37
|
retryDelayMs: attempt => attempt <= 1 ? 0 : 2 ** attempt * 1000,
|
|
22
|
-
shouldRetry:
|
|
38
|
+
shouldRetry: isRetryableFailure,
|
|
23
39
|
onRetry: () => undefined
|
|
24
40
|
};
|
|
25
41
|
const waitOrAbort = (delay, signal) => new Promise(resolve => {
|
|
@@ -157,7 +157,7 @@ userClient.interceptors.request.use(async config => {
|
|
|
157
157
|
// Reject before any network call when the device is known to be offline.
|
|
158
158
|
// Unknown connectivity (netinfo not installed, or undetermined) is treated
|
|
159
159
|
// as online — never block a request on an unavailable probe.
|
|
160
|
-
const network = await (0, _networkStatus.
|
|
160
|
+
const network = await (0, _networkStatus.getLastKnownNetworkStatus)();
|
|
161
161
|
if (network.isConnected === false) {
|
|
162
162
|
_index2.Logger.warn(`Request blocked: device is offline. URL: ${config.url}`);
|
|
163
163
|
return Promise.reject(new RequestOfflineError());
|
|
@@ -87,6 +87,24 @@ const expoSecureStoreBackend = {
|
|
|
87
87
|
}
|
|
88
88
|
};
|
|
89
89
|
const resolveBackend = () => backend ?? expoSecureStoreBackend;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Every request reads the access token, and a secure-store read is a native
|
|
93
|
+
* keychain/keystore decrypt. Reads are therefore served from memory, written
|
|
94
|
+
* through by `storeToken` and dropped by `removeToken`. `generation` moves on
|
|
95
|
+
* every write, removal and backend swap, so a read that started before one of
|
|
96
|
+
* those cannot cache the value it saw.
|
|
97
|
+
*/
|
|
98
|
+
const memo = new Map();
|
|
99
|
+
let generation = 0;
|
|
100
|
+
const forget = key => {
|
|
101
|
+
generation += 1;
|
|
102
|
+
if (key === undefined) {
|
|
103
|
+
memo.clear();
|
|
104
|
+
} else {
|
|
105
|
+
memo.delete(key);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
90
108
|
const requireBackend = op => {
|
|
91
109
|
const b = resolveBackend();
|
|
92
110
|
if (!b) {
|
|
@@ -104,6 +122,7 @@ const requireBackend = op => {
|
|
|
104
122
|
*/
|
|
105
123
|
const setKeychainImplementation = impl => {
|
|
106
124
|
backend = impl;
|
|
125
|
+
forget();
|
|
107
126
|
};
|
|
108
127
|
|
|
109
128
|
/**
|
|
@@ -114,6 +133,7 @@ const storeToken = async (key, token, expiry) => {
|
|
|
114
133
|
// Never log the token or expiry values: Logger forwards to whatever remote
|
|
115
134
|
// sink the app wired (Crashlytics/Sentry), so a token here leaves the device.
|
|
116
135
|
_index.Logger.info(`Storing token for key: ${key}`);
|
|
136
|
+
forget(key);
|
|
117
137
|
try {
|
|
118
138
|
const data = JSON.stringify({
|
|
119
139
|
token,
|
|
@@ -122,8 +142,14 @@ const storeToken = async (key, token, expiry) => {
|
|
|
122
142
|
await requireBackend('store a token').setGenericPassword('token', data, {
|
|
123
143
|
service: key
|
|
124
144
|
});
|
|
145
|
+
forget(key);
|
|
146
|
+
memo.set(key, {
|
|
147
|
+
token,
|
|
148
|
+
expiry
|
|
149
|
+
});
|
|
125
150
|
_index.Logger.info(`Token stored successfully for key: ${key}`);
|
|
126
151
|
} catch (error) {
|
|
152
|
+
forget(key);
|
|
127
153
|
// Log AND rethrow. Swallowing this told the caller the token was persisted
|
|
128
154
|
// when it was not, so an app would show a signed-in user holding a token
|
|
129
155
|
// that never reached the keychain — the session then dies at the next
|
|
@@ -162,6 +188,10 @@ const parseTokenData = credentials => {
|
|
|
162
188
|
* Retrieve token and check if expired.
|
|
163
189
|
*/
|
|
164
190
|
const getToken = async key => {
|
|
191
|
+
if (memo.has(key)) {
|
|
192
|
+
return memo.get(key) ?? null;
|
|
193
|
+
}
|
|
194
|
+
const seen = generation;
|
|
165
195
|
try {
|
|
166
196
|
const credentials = await requireBackend('read a token').getGenericPassword({
|
|
167
197
|
service: key
|
|
@@ -170,24 +200,24 @@ const getToken = async key => {
|
|
|
170
200
|
// token, and every authenticated request, image and download asks for one.
|
|
171
201
|
// Warning here put three info lines and a warning into the log, and into the
|
|
172
202
|
// remote crash sink, on every one of those calls.
|
|
173
|
-
|
|
174
|
-
|
|
203
|
+
let value = null;
|
|
204
|
+
if (credentials) {
|
|
205
|
+
const parsedData = parseTokenData(credentials);
|
|
206
|
+
if (parsedData) {
|
|
207
|
+
value = {
|
|
208
|
+
token: parsedData.token,
|
|
209
|
+
expiry: parsedData.expiry
|
|
210
|
+
};
|
|
211
|
+
} else {
|
|
212
|
+
// Something IS stored and it is not a token. That is corruption worth
|
|
213
|
+
// hearing about, and it is a different event from having no token.
|
|
214
|
+
_index.Logger.warn(`Stored credentials for key "${key}" are not a valid token; ignoring them.`);
|
|
215
|
+
}
|
|
175
216
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// Something IS stored and it is not a token. That is corruption worth
|
|
179
|
-
// hearing about, and it is a different event from having no token.
|
|
180
|
-
_index.Logger.warn(`Stored credentials for key "${key}" are not a valid token; ignoring them.`);
|
|
181
|
-
return null;
|
|
217
|
+
if (seen === generation) {
|
|
218
|
+
memo.set(key, value);
|
|
182
219
|
}
|
|
183
|
-
|
|
184
|
-
token,
|
|
185
|
-
expiry
|
|
186
|
-
} = parsedData;
|
|
187
|
-
return {
|
|
188
|
-
token,
|
|
189
|
-
expiry
|
|
190
|
-
};
|
|
220
|
+
return value;
|
|
191
221
|
} catch (error) {
|
|
192
222
|
const message = error instanceof Error ? error.message : String(error);
|
|
193
223
|
// Both spellings matter. Android throws "Key permanently invalidated" when
|
|
@@ -211,6 +241,7 @@ const getToken = async key => {
|
|
|
211
241
|
*/
|
|
212
242
|
exports.getToken = getToken;
|
|
213
243
|
const removeToken = async key => {
|
|
244
|
+
forget(key);
|
|
214
245
|
try {
|
|
215
246
|
await requireBackend('remove a token').resetGenericPassword({
|
|
216
247
|
service: key
|
|
@@ -226,6 +257,8 @@ const removeToken = async key => {
|
|
|
226
257
|
return;
|
|
227
258
|
}
|
|
228
259
|
_index.Logger.error(`Failed to remove token for key: ${key}`, error);
|
|
260
|
+
} finally {
|
|
261
|
+
forget(key);
|
|
229
262
|
}
|
|
230
263
|
};
|
|
231
264
|
exports.removeToken = removeToken;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.getConfig = void 0;
|
|
6
|
+
exports.getConfig = exports.DEFAULT_LOG_LEVEL = void 0;
|
|
7
7
|
exports.getConfigValue = getConfigValue;
|
|
8
8
|
exports.setConfig = exports.resetConfig = void 0;
|
|
9
9
|
/**
|
|
@@ -11,10 +11,16 @@ exports.setConfig = exports.resetConfig = void 0;
|
|
|
11
11
|
* Provides a flexible way to inject configuration without hard dependencies
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
+
/**
|
|
15
|
+
* Info lines (each token refresh, each unauthorised URL) reach the device log
|
|
16
|
+
* and any remote sink, so a release build that sets nothing logs warnings and
|
|
17
|
+
* errors only.
|
|
18
|
+
*/
|
|
19
|
+
const DEFAULT_LOG_LEVEL = exports.DEFAULT_LOG_LEVEL = __DEV__ ? 'info' : 'warn';
|
|
14
20
|
const DEFAULT_CONFIG = {
|
|
15
21
|
baseUrl: null,
|
|
16
22
|
loggingEnabled: true,
|
|
17
|
-
logLevel:
|
|
23
|
+
logLevel: DEFAULT_LOG_LEVEL,
|
|
18
24
|
environment: 'Development',
|
|
19
25
|
country: 'in',
|
|
20
26
|
appId: null,
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatCurrency = void 0;
|
|
7
|
+
var _intlCache = require("./intlCache.js");
|
|
7
8
|
const hasIntlNumber = () => typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
|
|
8
9
|
const indianGroupingFallback = (n, fractionDigits) => {
|
|
9
10
|
// Indian numbering: 1,23,45,678.90 (last 3 digits, then groups of 2).
|
|
@@ -41,7 +42,7 @@ const formatCurrency = (amount, options = {}) => {
|
|
|
41
42
|
const minFrac = minimumFractionDigits ?? (Number.isInteger(amount) ? 0 : 2);
|
|
42
43
|
if (hasIntlNumber()) {
|
|
43
44
|
try {
|
|
44
|
-
const formatted =
|
|
45
|
+
const formatted = (0, _intlCache.numberFormat)(locale, {
|
|
45
46
|
style: 'currency',
|
|
46
47
|
currency,
|
|
47
48
|
minimumFractionDigits: minFrac,
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatTime = exports.formatRelativeTime = exports.formatDateTime = exports.formatDate = void 0;
|
|
7
|
+
var _intlCache = require("./intlCache.js");
|
|
7
8
|
const toDate = value => {
|
|
8
9
|
if (value instanceof Date) {
|
|
9
10
|
return Number.isNaN(value.getTime()) ? null : value;
|
|
@@ -52,7 +53,7 @@ const formatDate = (value, style = 'medium', locale = 'en-IN') => {
|
|
|
52
53
|
}
|
|
53
54
|
if (hasIntl()) {
|
|
54
55
|
try {
|
|
55
|
-
return
|
|
56
|
+
return (0, _intlCache.dateTimeFormat)(locale, {
|
|
56
57
|
dateStyle: style
|
|
57
58
|
}).format(d);
|
|
58
59
|
} catch {
|
|
@@ -73,7 +74,7 @@ const formatTime = (value, style = 'short', locale = 'en-IN') => {
|
|
|
73
74
|
}
|
|
74
75
|
if (hasIntl()) {
|
|
75
76
|
try {
|
|
76
|
-
return
|
|
77
|
+
return (0, _intlCache.dateTimeFormat)(locale, {
|
|
77
78
|
timeStyle: style
|
|
78
79
|
}).format(d);
|
|
79
80
|
} catch {
|
|
@@ -94,7 +95,7 @@ const formatDateTime = (value, dateStyle = 'medium', timeStyle = 'short', locale
|
|
|
94
95
|
}
|
|
95
96
|
if (hasIntl()) {
|
|
96
97
|
try {
|
|
97
|
-
return
|
|
98
|
+
return (0, _intlCache.dateTimeFormat)(locale, {
|
|
98
99
|
dateStyle,
|
|
99
100
|
timeStyle
|
|
100
101
|
}).format(d);
|
|
@@ -152,9 +153,7 @@ const formatRelativeTime = (value, base = new Date(), locale = 'en-IN') => {
|
|
|
152
153
|
const Rtf = hasIntl() ? Intl.RelativeTimeFormat : undefined;
|
|
153
154
|
if (typeof Rtf === 'function') {
|
|
154
155
|
try {
|
|
155
|
-
return
|
|
156
|
-
numeric: 'auto'
|
|
157
|
-
}).format(amount, unit);
|
|
156
|
+
return (0, _intlCache.relativeTimeFormat)(Rtf, locale).format(amount, unit);
|
|
158
157
|
} catch {
|
|
159
158
|
/* fall through */
|
|
160
159
|
}
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.startOfDay = exports.isSameDay = exports.isDateBefore = exports.isDateAfter = exports.formatTimeInZone = exports.formatTimeInWindowsZone = exports.formatTime12h = exports.formatDatePattern = exports.formatDateISO = exports.formatDateDDMMMYYYY = exports.diffMs = exports.addDays = void 0;
|
|
7
|
+
var _intlCache = require("./intlCache.js");
|
|
7
8
|
var _windowsToIanaTable = require("./windowsToIanaTable.js");
|
|
8
9
|
const toDate = value => {
|
|
9
10
|
if (value instanceof Date) {
|
|
@@ -277,7 +278,7 @@ const formatTimeInZone = (value, ianaTimeZone) => {
|
|
|
277
278
|
// answer available, not a genuine timezone conversion.
|
|
278
279
|
return formatTime12h(d);
|
|
279
280
|
}
|
|
280
|
-
const parts =
|
|
281
|
+
const parts = (0, _intlCache.dateTimeFormat)('en-US', {
|
|
281
282
|
timeZone: ianaTimeZone,
|
|
282
283
|
hour: 'numeric',
|
|
283
284
|
minute: '2-digit',
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.relativeTimeFormat = exports.numberFormat = exports.dateTimeFormat = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Building an Intl formatter costs far more than using one (and on Hermes for
|
|
9
|
+
* Android it goes through ICU over JNI), while list rows and slider frames call
|
|
10
|
+
* the formatters many times with the same arguments. Formatters are therefore
|
|
11
|
+
* built once per locale and options. The limit only guards against unbounded
|
|
12
|
+
* input such as arbitrary time zones; real apps use a handful of keys.
|
|
13
|
+
*/
|
|
14
|
+
const LIMIT = 100;
|
|
15
|
+
const cached = (cache, key, create) => {
|
|
16
|
+
let formatter = cache.get(key);
|
|
17
|
+
if (formatter === undefined) {
|
|
18
|
+
formatter = create();
|
|
19
|
+
if (cache.size >= LIMIT) {
|
|
20
|
+
cache.clear();
|
|
21
|
+
}
|
|
22
|
+
cache.set(key, formatter);
|
|
23
|
+
}
|
|
24
|
+
return formatter;
|
|
25
|
+
};
|
|
26
|
+
const numberFormats = new Map();
|
|
27
|
+
const dateTimeFormats = new Map();
|
|
28
|
+
const relativeTimeFormats = new Map();
|
|
29
|
+
const numberFormat = (locale, options = {}) => cached(numberFormats, `${locale}|${JSON.stringify(options)}`, () => new Intl.NumberFormat(locale, options));
|
|
30
|
+
exports.numberFormat = numberFormat;
|
|
31
|
+
const dateTimeFormat = (locale, options) => cached(dateTimeFormats, `${locale}|${JSON.stringify(options)}`, () => new Intl.DateTimeFormat(locale, options));
|
|
32
|
+
exports.dateTimeFormat = dateTimeFormat;
|
|
33
|
+
const relativeTimeFormat = (RelativeTimeFormat, locale) => cached(relativeTimeFormats, locale, () => new RelativeTimeFormat(locale, {
|
|
34
|
+
numeric: 'auto'
|
|
35
|
+
}));
|
|
36
|
+
exports.relativeTimeFormat = relativeTimeFormat;
|
|
37
|
+
//# sourceMappingURL=intlCache.js.map
|
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.formatPercent = exports.formatNumber = exports.formatCompactNumber = void 0;
|
|
7
|
+
var _intlCache = require("./intlCache.js");
|
|
7
8
|
const hasIntlNumber = () => typeof Intl !== 'undefined' && typeof Intl.NumberFormat === 'function';
|
|
8
9
|
|
|
9
10
|
/**
|
|
@@ -20,7 +21,7 @@ const formatNumber = (value, fractionDigits, locale = 'en-IN') => {
|
|
|
20
21
|
opts.minimumFractionDigits = fractionDigits;
|
|
21
22
|
opts.maximumFractionDigits = fractionDigits;
|
|
22
23
|
}
|
|
23
|
-
return
|
|
24
|
+
return (0, _intlCache.numberFormat)(locale, opts).format(value);
|
|
24
25
|
} catch {
|
|
25
26
|
/* fall through */
|
|
26
27
|
}
|
|
@@ -40,7 +41,7 @@ const formatPercent = (value, fractionDigits = 0, asRatio = true, locale = 'en-I
|
|
|
40
41
|
const ratio = asRatio ? value : value / 100;
|
|
41
42
|
if (hasIntlNumber()) {
|
|
42
43
|
try {
|
|
43
|
-
return
|
|
44
|
+
return (0, _intlCache.numberFormat)(locale, {
|
|
44
45
|
style: 'percent',
|
|
45
46
|
minimumFractionDigits: fractionDigits,
|
|
46
47
|
maximumFractionDigits: fractionDigits
|
|
@@ -63,7 +64,7 @@ const formatCompactNumber = (value, locale = 'en-IN') => {
|
|
|
63
64
|
}
|
|
64
65
|
if (hasIntlNumber()) {
|
|
65
66
|
try {
|
|
66
|
-
return
|
|
67
|
+
return (0, _intlCache.numberFormat)(locale, {
|
|
67
68
|
notation: 'compact',
|
|
68
69
|
maximumFractionDigits: 1
|
|
69
70
|
}).format(value);
|
package/lib/commonjs/index.js
CHANGED
|
@@ -117,6 +117,12 @@ Object.defineProperty(exports, "diffMs", {
|
|
|
117
117
|
return _index3.diffMs;
|
|
118
118
|
}
|
|
119
119
|
});
|
|
120
|
+
Object.defineProperty(exports, "encodeBase64", {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () {
|
|
123
|
+
return _base.encodeBase64;
|
|
124
|
+
}
|
|
125
|
+
});
|
|
120
126
|
Object.defineProperty(exports, "formatCompactNumber", {
|
|
121
127
|
enumerable: true,
|
|
122
128
|
get: function () {
|
|
@@ -630,6 +636,7 @@ var _initUserAuth = require("./initUserAuth.js");
|
|
|
630
636
|
var _index4 = require("./logger/index.js");
|
|
631
637
|
var _index5 = require("./network/index.js");
|
|
632
638
|
var _index6 = require("./storage/index.js");
|
|
639
|
+
var _base = require("./utils/base64.js");
|
|
633
640
|
var _index7 = require("./validators/index.js");
|
|
634
641
|
var _index8 = require("./versionCheck/index.js");
|
|
635
642
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
package/lib/commonjs/initSDK.js
CHANGED
|
@@ -39,7 +39,7 @@ const initWebority = config => {
|
|
|
39
39
|
(0, _index.setConfig)({
|
|
40
40
|
baseUrl: config.baseUrl,
|
|
41
41
|
loggingEnabled: config.loggingEnabled ?? true,
|
|
42
|
-
logLevel: config.logLevel ||
|
|
42
|
+
logLevel: config.logLevel || _index.DEFAULT_LOG_LEVEL,
|
|
43
43
|
environment: config.environment || 'Development',
|
|
44
44
|
country: (config.country || 'in').toLowerCase(),
|
|
45
45
|
appId: config.appId ?? null,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.useNetworkStatus = exports.setNetworkStatusImplementation = exports.getNetworkStatus = exports.addNetworkStatusListener = void 0;
|
|
6
|
+
exports.useNetworkStatus = exports.setNetworkStatusImplementation = exports.getNetworkStatus = exports.getLastKnownNetworkStatus = exports.addNetworkStatusListener = void 0;
|
|
7
7
|
var ExpoNetwork = _interopRequireWildcard(require("expo-network"));
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _index = require("../logger/index.js");
|
|
@@ -23,6 +23,13 @@ const DEFAULT_STATUS = {
|
|
|
23
23
|
* One backend also means one behaviour, rather than each app choosing.
|
|
24
24
|
*/
|
|
25
25
|
let override = null;
|
|
26
|
+
let lastKnown = null;
|
|
27
|
+
let stopFollowing = null;
|
|
28
|
+
const stopFollowingNetwork = () => {
|
|
29
|
+
stopFollowing?.();
|
|
30
|
+
stopFollowing = null;
|
|
31
|
+
lastKnown = null;
|
|
32
|
+
};
|
|
26
33
|
|
|
27
34
|
/**
|
|
28
35
|
* Replace the backend. Intended for TESTS and for the showcase, which uses it
|
|
@@ -31,6 +38,7 @@ let override = null;
|
|
|
31
38
|
*/
|
|
32
39
|
const setNetworkStatusImplementation = impl => {
|
|
33
40
|
override = impl;
|
|
41
|
+
stopFollowingNetwork();
|
|
34
42
|
};
|
|
35
43
|
exports.setNetworkStatusImplementation = setNetworkStatusImplementation;
|
|
36
44
|
const resolveNetInfo = () => override ?? expoNetworkBackend;
|
|
@@ -103,11 +111,41 @@ const addNetworkStatusListener = listener => {
|
|
|
103
111
|
return ni.addEventListener(state => listener(normalize(state)));
|
|
104
112
|
};
|
|
105
113
|
|
|
114
|
+
/**
|
|
115
|
+
* The connectivity the HTTP client checks before every request. One listener,
|
|
116
|
+
* attached on first use, keeps it current, so a request costs no native probe:
|
|
117
|
+
* one probe seeds the value and the listener's events replace it.
|
|
118
|
+
*/
|
|
119
|
+
exports.addNetworkStatusListener = addNetworkStatusListener;
|
|
120
|
+
const getLastKnownNetworkStatus = async () => {
|
|
121
|
+
if (!stopFollowing) {
|
|
122
|
+
try {
|
|
123
|
+
stopFollowing = addNetworkStatusListener(status => {
|
|
124
|
+
lastKnown = status;
|
|
125
|
+
});
|
|
126
|
+
} catch (error) {
|
|
127
|
+
_index.Logger.error('[network] could not follow network changes', error);
|
|
128
|
+
return getNetworkStatus();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (lastKnown) {
|
|
132
|
+
return lastKnown;
|
|
133
|
+
}
|
|
134
|
+
const following = stopFollowing;
|
|
135
|
+
const probed = await getNetworkStatus();
|
|
136
|
+
if (stopFollowing !== following) {
|
|
137
|
+
return probed;
|
|
138
|
+
}
|
|
139
|
+
// An event that arrived during the probe is newer than the probe.
|
|
140
|
+
lastKnown ??= probed;
|
|
141
|
+
return lastKnown;
|
|
142
|
+
};
|
|
143
|
+
|
|
106
144
|
/**
|
|
107
145
|
* React hook that returns the current network status and re-renders on change.
|
|
108
146
|
* Reports an optimistic online default when NetInfo is not installed.
|
|
109
147
|
*/
|
|
110
|
-
exports.
|
|
148
|
+
exports.getLastKnownNetworkStatus = getLastKnownNetworkStatus;
|
|
111
149
|
const useNetworkStatus = () => {
|
|
112
150
|
const [status, setStatus] = (0, _react.useState)(DEFAULT_STATUS);
|
|
113
151
|
(0, _react.useEffect)(() => {
|
|
@@ -21,12 +21,30 @@ Object.defineProperty(exports, "initPush", {
|
|
|
21
21
|
return _push.initPush;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "notifyLocal", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _push.notifyLocal;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "onAction", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _push.onAction;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
24
36
|
Object.defineProperty(exports, "setBadgeCount", {
|
|
25
37
|
enumerable: true,
|
|
26
38
|
get: function () {
|
|
27
39
|
return _push.setBadgeCount;
|
|
28
40
|
}
|
|
29
41
|
});
|
|
42
|
+
Object.defineProperty(exports, "setCategories", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _push.setCategories;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
30
48
|
Object.defineProperty(exports, "setPushImplementation", {
|
|
31
49
|
enumerable: true,
|
|
32
50
|
get: function () {
|