@webority/mobile-core 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/android/build.gradle +65 -0
- package/android/src/newarch/java/com/webority/mobilecore/smsretriever/AppSignatureHelper.kt +57 -0
- package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModule.kt +20 -0
- package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModuleImpl.kt +146 -0
- package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverPackage.kt +33 -0
- package/lib/commonjs/api/baseUrl.js +34 -0
- package/lib/commonjs/api/curl.js +109 -0
- package/lib/commonjs/api/publicClient.js +73 -0
- package/lib/commonjs/api/retry.js +75 -0
- package/lib/commonjs/api/tokenRefresh.js +205 -0
- package/lib/commonjs/api/userClient.js +255 -0
- package/lib/commonjs/auth/authStore.js +232 -0
- package/lib/commonjs/auth/index.js +44 -0
- package/lib/commonjs/auth/jwt.js +112 -0
- package/lib/commonjs/config/index.js +66 -0
- package/lib/commonjs/deepLink/index.js +286 -0
- package/lib/commonjs/download/adapters/expoFs.js +69 -0
- package/lib/commonjs/download/adapters/shared.js +13 -0
- package/lib/commonjs/download/index.js +250 -0
- package/lib/commonjs/formatters/currency.js +69 -0
- package/lib/commonjs/formatters/date.js +168 -0
- package/lib/commonjs/formatters/dateMath.js +310 -0
- package/lib/commonjs/formatters/index.js +246 -0
- package/lib/commonjs/formatters/initials.js +32 -0
- package/lib/commonjs/formatters/number.js +88 -0
- package/lib/commonjs/formatters/phone.js +369 -0
- package/lib/commonjs/formatters/windowsToIanaTable.js +164 -0
- package/lib/commonjs/geolocation/adapters/expoLocation.js +126 -0
- package/lib/commonjs/geolocation/index.js +355 -0
- package/lib/commonjs/index.js +630 -0
- package/lib/commonjs/initSDK.js +66 -0
- package/lib/commonjs/initUserAuth.js +37 -0
- package/lib/commonjs/logger/index.js +291 -0
- package/lib/commonjs/network/index.js +31 -0
- package/lib/commonjs/network/networkStatus.js +133 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/permissions/calendar.js +14 -0
- package/lib/commonjs/permissions/camera.js +14 -0
- package/lib/commonjs/permissions/contacts.js +10 -0
- package/lib/commonjs/permissions/index.js +133 -0
- package/lib/commonjs/permissions/location.js +14 -0
- package/lib/commonjs/permissions/mediaLibrary.js +10 -0
- package/lib/commonjs/permissions/notifications.js +10 -0
- package/lib/commonjs/permissions/photos.js +14 -0
- package/lib/commonjs/phone/countries.js +265 -0
- package/lib/commonjs/share/index.js +70 -0
- package/lib/commonjs/smsRetriever/index.js +91 -0
- package/lib/commonjs/specs/NativeSmsRetriever.js +15 -0
- package/lib/commonjs/sqlite/adapters/expo.js +53 -0
- package/lib/commonjs/sqlite/index.js +604 -0
- package/lib/commonjs/storage/index.js +214 -0
- package/lib/commonjs/types/globals.d.js +6 -0
- package/lib/commonjs/utils/imageCompression.js +389 -0
- package/lib/commonjs/utils/index.js +19 -0
- package/lib/commonjs/validators/index.js +227 -0
- package/lib/commonjs/versionCheck/index.js +419 -0
- package/lib/module/api/baseUrl.js +30 -0
- package/lib/module/api/curl.js +104 -0
- package/lib/module/api/publicClient.js +69 -0
- package/lib/module/api/retry.js +69 -0
- package/lib/module/api/tokenRefresh.js +192 -0
- package/lib/module/api/userClient.js +233 -0
- package/lib/module/auth/authStore.js +224 -0
- package/lib/module/auth/index.js +5 -0
- package/lib/module/auth/jwt.js +106 -0
- package/lib/module/config/index.js +58 -0
- package/lib/module/deepLink/index.js +280 -0
- package/lib/module/download/adapters/expoFs.js +64 -0
- package/lib/module/download/adapters/shared.js +8 -0
- package/lib/module/download/index.js +242 -0
- package/lib/module/formatters/currency.js +64 -0
- package/lib/module/formatters/date.js +160 -0
- package/lib/module/formatters/dateMath.js +294 -0
- package/lib/module/formatters/index.js +9 -0
- package/lib/module/formatters/initials.js +27 -0
- package/lib/module/formatters/number.js +81 -0
- package/lib/module/formatters/phone.js +302 -0
- package/lib/module/formatters/windowsToIanaTable.js +160 -0
- package/lib/module/geolocation/adapters/expoLocation.js +121 -0
- package/lib/module/geolocation/index.js +347 -0
- package/lib/module/index.js +54 -0
- package/lib/module/initSDK.js +61 -0
- package/lib/module/initUserAuth.js +33 -0
- package/lib/module/logger/index.js +285 -0
- package/lib/module/network/index.js +4 -0
- package/lib/module/network/networkStatus.js +124 -0
- package/lib/module/package.json +1 -0
- package/lib/module/permissions/calendar.js +15 -0
- package/lib/module/permissions/camera.js +15 -0
- package/lib/module/permissions/contacts.js +11 -0
- package/lib/module/permissions/index.js +128 -0
- package/lib/module/permissions/location.js +15 -0
- package/lib/module/permissions/mediaLibrary.js +11 -0
- package/lib/module/permissions/notifications.js +11 -0
- package/lib/module/permissions/photos.js +15 -0
- package/lib/module/phone/countries.js +261 -0
- package/lib/module/share/index.js +64 -0
- package/lib/module/smsRetriever/index.js +86 -0
- package/lib/module/specs/NativeSmsRetriever.js +13 -0
- package/lib/module/sqlite/adapters/expo.js +48 -0
- package/lib/module/sqlite/index.js +594 -0
- package/lib/module/storage/index.js +208 -0
- package/lib/module/types/globals.d.js +10 -0
- package/lib/module/utils/imageCompression.js +383 -0
- package/lib/module/utils/index.js +4 -0
- package/lib/module/validators/index.js +205 -0
- package/lib/module/versionCheck/index.js +413 -0
- package/lib/typescript/commonjs/api/baseUrl.d.ts +20 -0
- package/lib/typescript/commonjs/api/curl.d.ts +18 -0
- package/lib/typescript/commonjs/api/publicClient.d.ts +11 -0
- package/lib/typescript/commonjs/api/retry.d.ts +27 -0
- package/lib/typescript/commonjs/api/tokenRefresh.d.ts +43 -0
- package/lib/typescript/commonjs/api/userClient.d.ts +37 -0
- package/lib/typescript/commonjs/auth/authStore.d.ts +79 -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 +55 -0
- package/lib/typescript/commonjs/deepLink/index.d.ts +54 -0
- package/lib/typescript/commonjs/download/adapters/expoFs.d.ts +38 -0
- package/lib/typescript/commonjs/download/adapters/shared.d.ts +3 -0
- package/lib/typescript/commonjs/download/index.d.ts +86 -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/dateMath.d.ts +88 -0
- package/lib/typescript/commonjs/formatters/index.d.ts +10 -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 +133 -0
- package/lib/typescript/commonjs/formatters/windowsToIanaTable.d.ts +18 -0
- package/lib/typescript/commonjs/geolocation/adapters/expoLocation.d.ts +42 -0
- package/lib/typescript/commonjs/geolocation/index.d.ts +90 -0
- package/lib/typescript/commonjs/index.d.ts +54 -0
- package/lib/typescript/commonjs/initSDK.d.ts +72 -0
- package/lib/typescript/commonjs/initUserAuth.d.ts +41 -0
- package/lib/typescript/commonjs/logger/index.d.ts +81 -0
- package/lib/typescript/commonjs/network/index.d.ts +3 -0
- package/lib/typescript/commonjs/network/networkStatus.d.ts +43 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/permissions/calendar.d.ts +2 -0
- package/lib/typescript/commonjs/permissions/camera.d.ts +2 -0
- package/lib/typescript/commonjs/permissions/contacts.d.ts +2 -0
- package/lib/typescript/commonjs/permissions/index.d.ts +48 -0
- package/lib/typescript/commonjs/permissions/location.d.ts +2 -0
- package/lib/typescript/commonjs/permissions/mediaLibrary.d.ts +2 -0
- package/lib/typescript/commonjs/permissions/notifications.d.ts +2 -0
- package/lib/typescript/commonjs/permissions/photos.d.ts +2 -0
- package/lib/typescript/commonjs/phone/countries.d.ts +13 -0
- package/lib/typescript/commonjs/share/index.d.ts +29 -0
- package/lib/typescript/commonjs/smsRetriever/index.d.ts +30 -0
- package/lib/typescript/commonjs/specs/NativeSmsRetriever.d.ts +15 -0
- package/lib/typescript/commonjs/sqlite/adapters/expo.d.ts +30 -0
- package/lib/typescript/commonjs/sqlite/index.d.ts +113 -0
- package/lib/typescript/commonjs/storage/index.d.ts +64 -0
- package/lib/typescript/commonjs/utils/imageCompression.d.ts +152 -0
- package/lib/typescript/commonjs/utils/index.d.ts +3 -0
- package/lib/typescript/commonjs/validators/index.d.ts +51 -0
- package/lib/typescript/commonjs/versionCheck/index.d.ts +80 -0
- package/lib/typescript/module/api/baseUrl.d.ts +20 -0
- package/lib/typescript/module/api/curl.d.ts +18 -0
- package/lib/typescript/module/api/publicClient.d.ts +11 -0
- package/lib/typescript/module/api/retry.d.ts +27 -0
- package/lib/typescript/module/api/tokenRefresh.d.ts +43 -0
- package/lib/typescript/module/api/userClient.d.ts +37 -0
- package/lib/typescript/module/auth/authStore.d.ts +79 -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 +55 -0
- package/lib/typescript/module/deepLink/index.d.ts +54 -0
- package/lib/typescript/module/download/adapters/expoFs.d.ts +38 -0
- package/lib/typescript/module/download/adapters/shared.d.ts +3 -0
- package/lib/typescript/module/download/index.d.ts +86 -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/dateMath.d.ts +88 -0
- package/lib/typescript/module/formatters/index.d.ts +10 -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 +133 -0
- package/lib/typescript/module/formatters/windowsToIanaTable.d.ts +18 -0
- package/lib/typescript/module/geolocation/adapters/expoLocation.d.ts +42 -0
- package/lib/typescript/module/geolocation/index.d.ts +90 -0
- package/lib/typescript/module/index.d.ts +54 -0
- package/lib/typescript/module/initSDK.d.ts +72 -0
- package/lib/typescript/module/initUserAuth.d.ts +41 -0
- package/lib/typescript/module/logger/index.d.ts +81 -0
- package/lib/typescript/module/network/index.d.ts +3 -0
- package/lib/typescript/module/network/networkStatus.d.ts +43 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/permissions/calendar.d.ts +2 -0
- package/lib/typescript/module/permissions/camera.d.ts +2 -0
- package/lib/typescript/module/permissions/contacts.d.ts +2 -0
- package/lib/typescript/module/permissions/index.d.ts +48 -0
- package/lib/typescript/module/permissions/location.d.ts +2 -0
- package/lib/typescript/module/permissions/mediaLibrary.d.ts +2 -0
- package/lib/typescript/module/permissions/notifications.d.ts +2 -0
- package/lib/typescript/module/permissions/photos.d.ts +2 -0
- package/lib/typescript/module/phone/countries.d.ts +13 -0
- package/lib/typescript/module/share/index.d.ts +29 -0
- package/lib/typescript/module/smsRetriever/index.d.ts +30 -0
- package/lib/typescript/module/specs/NativeSmsRetriever.d.ts +15 -0
- package/lib/typescript/module/sqlite/adapters/expo.d.ts +30 -0
- package/lib/typescript/module/sqlite/index.d.ts +113 -0
- package/lib/typescript/module/storage/index.d.ts +64 -0
- package/lib/typescript/module/utils/imageCompression.d.ts +152 -0
- package/lib/typescript/module/utils/index.d.ts +3 -0
- package/lib/typescript/module/validators/index.d.ts +51 -0
- package/lib/typescript/module/versionCheck/index.d.ts +80 -0
- package/package.json +298 -0
- package/src/specs/NativeSmsRetriever.ts +16 -0
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import * as ExpoLocation from 'expo-location';
|
|
4
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { Logger } from "../logger/index.js";
|
|
6
|
+
import { Permissions } from "../permissions/index.js";
|
|
7
|
+
// expo-location is a REQUIRED peer (unlike the other Expo permission
|
|
8
|
+
// packages, which are optional and registered only when an app opts in by
|
|
9
|
+
// importing their own entry point) — anything that reaches this module
|
|
10
|
+
// already forces Metro to resolve expo-location, so self-registering its
|
|
11
|
+
// permission kinds here costs nothing extra and makes Geolocation's
|
|
12
|
+
// permission gating work without a separate app-level import.
|
|
13
|
+
import "../permissions/location.js";
|
|
14
|
+
import { adaptExpoLocation } from "./adapters/expoLocation.js";
|
|
15
|
+
const PREFIX = '[@webority/mobile-core]';
|
|
16
|
+
export class GeolocationError extends Error {
|
|
17
|
+
constructor(code, message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.name = 'GeolocationError';
|
|
20
|
+
this.code = code;
|
|
21
|
+
// Babel downlevels `class extends Error`, which breaks `instanceof` for
|
|
22
|
+
// subclasses unless the prototype is restored explicitly.
|
|
23
|
+
Object.setPrototypeOf(this, GeolocationError.prototype);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Minimal shape of the native geolocation module we depend on. */
|
|
28
|
+
|
|
29
|
+
const DEFAULT_TIMEOUT_MS = 15000;
|
|
30
|
+
const DEFAULT_RETRIES = 1;
|
|
31
|
+
const DEFAULT_RETRY_DELAY_MS = 800;
|
|
32
|
+
|
|
33
|
+
/** Only what a test or the showcase injected; null means use expo-location. */
|
|
34
|
+
let backend = null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* expo-location is a required peer, so the JS module always resolves. What can
|
|
38
|
+
* be missing is the NATIVE side: an app that installed the package without
|
|
39
|
+
* running the native install gets a module whose calls are absent. Checking the
|
|
40
|
+
* two the adapter needs is what lets `isAvailable` mean something and makes the
|
|
41
|
+
* error below reachable.
|
|
42
|
+
*
|
|
43
|
+
* An INJECTED backend is taken on trust, like every other seam in this package.
|
|
44
|
+
*/
|
|
45
|
+
const hasNativeLocation = mod => typeof mod?.getCurrentPositionAsync === 'function' && typeof mod?.watchPositionAsync === 'function';
|
|
46
|
+
let expoBackend;
|
|
47
|
+
const resolveBackend = () => {
|
|
48
|
+
if (backend) {
|
|
49
|
+
return backend;
|
|
50
|
+
}
|
|
51
|
+
if (expoBackend === undefined) {
|
|
52
|
+
const mod = ExpoLocation;
|
|
53
|
+
expoBackend = hasNativeLocation(mod) ? adaptExpoLocation(mod) : null;
|
|
54
|
+
}
|
|
55
|
+
return expoBackend;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Replace the geolocation provider. Intended for TESTS and for the showcase,
|
|
60
|
+
* which injects a denying provider to demo the permission and services-off
|
|
61
|
+
* errors; an app gets expo-location without wiring anything. Pass `null` to
|
|
62
|
+
* restore it.
|
|
63
|
+
*/
|
|
64
|
+
export const setGeolocationImplementation = impl => {
|
|
65
|
+
backend = impl;
|
|
66
|
+
};
|
|
67
|
+
const requireBackend = op => {
|
|
68
|
+
const b = resolveBackend();
|
|
69
|
+
if (!b) {
|
|
70
|
+
throw new GeolocationError('unsupported', `${PREFIX} No geolocation provider is available; cannot ${op}. ` + 'expo-location did not load, which on a real build means the native ' + 'module was not linked.');
|
|
71
|
+
}
|
|
72
|
+
return b;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Android reports "location services are switched off" through the same code 2
|
|
77
|
+
* that also covers a genuine failure to fix a position, and the two need
|
|
78
|
+
* different handling: one is fixed by the user in system settings, the other is
|
|
79
|
+
* worth retrying. The message is the only signal that separates them.
|
|
80
|
+
*/
|
|
81
|
+
const SERVICES_OFF_PATTERN = /(location|gps)[^.]{0,40}(disabled|switched off|turned off|not enabled)|no location provider|settings_not_satisfied|location services (are |is )?off/i;
|
|
82
|
+
const toGeoError = raw => {
|
|
83
|
+
if (raw instanceof GeolocationError) {
|
|
84
|
+
return raw;
|
|
85
|
+
}
|
|
86
|
+
const native = raw ?? {};
|
|
87
|
+
const detail = typeof native.message === 'string' && native.message.length > 0 ? native.message : 'the provider gave no reason';
|
|
88
|
+
switch (native.code) {
|
|
89
|
+
case 1:
|
|
90
|
+
return new GeolocationError('permission-denied', `${PREFIX} Location permission was denied (${detail}). Request the ` + 'location permission before calling, or send the user to settings.');
|
|
91
|
+
case 2:
|
|
92
|
+
return SERVICES_OFF_PATTERN.test(detail) ? new GeolocationError('services-disabled', `${PREFIX} Location services are switched off (${detail}). Ask the user ` + 'to enable location in system settings; retrying will not help.') : new GeolocationError('position-unavailable', `${PREFIX} No position fix (${detail}).`);
|
|
93
|
+
case 3:
|
|
94
|
+
return new GeolocationError('timeout', `${PREFIX} Location request timed out (${detail}).`);
|
|
95
|
+
case 4:
|
|
96
|
+
case 5:
|
|
97
|
+
return new GeolocationError('services-disabled', `${PREFIX} Location services are unavailable on this device (${detail}). ` + 'Ask the user to enable location, or install Google Play services.');
|
|
98
|
+
default:
|
|
99
|
+
return new GeolocationError('position-unavailable', `${PREFIX} Location request failed (${detail}).`);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
const RETRYABLE = ['timeout', 'position-unavailable'];
|
|
103
|
+
const normalizeCoords = raw => {
|
|
104
|
+
const coords = raw?.coords;
|
|
105
|
+
if (!coords || !Number.isFinite(coords.latitude) || !Number.isFinite(coords.longitude)) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
latitude: coords.latitude,
|
|
110
|
+
longitude: coords.longitude,
|
|
111
|
+
// An absent radius is treated as infinitely bad rather than perfect, so a
|
|
112
|
+
// provider that omits it can never satisfy `minimumAccuracyM` by accident.
|
|
113
|
+
accuracy: Number.isFinite(coords.accuracy) ? coords.accuracy : Number.POSITIVE_INFINITY,
|
|
114
|
+
altitude: Number.isFinite(coords.altitude) ? coords.altitude : null,
|
|
115
|
+
heading: Number.isFinite(coords.heading) ? coords.heading : null,
|
|
116
|
+
speed: Number.isFinite(coords.speed) ? coords.speed : null
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
const normalizePosition = raw => {
|
|
120
|
+
const coords = normalizeCoords(raw);
|
|
121
|
+
if (!coords) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
coords,
|
|
126
|
+
timestamp: Number.isFinite(raw?.timestamp) ? raw?.timestamp : Date.now()
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
const toNativeOptions = options => {
|
|
130
|
+
const native = {
|
|
131
|
+
enableHighAccuracy: (options.accuracy ?? 'fine') === 'fine',
|
|
132
|
+
timeout: options.timeoutMs ?? DEFAULT_TIMEOUT_MS,
|
|
133
|
+
maximumAge: options.maximumAgeMs ?? 0
|
|
134
|
+
};
|
|
135
|
+
if (options.distanceFilterM !== undefined) {
|
|
136
|
+
native.distanceFilter = options.distanceFilterM;
|
|
137
|
+
}
|
|
138
|
+
return native;
|
|
139
|
+
};
|
|
140
|
+
const sleep = ms => new Promise(resolve => {
|
|
141
|
+
setTimeout(resolve, ms);
|
|
142
|
+
});
|
|
143
|
+
const ensureLocationPermission = async () => {
|
|
144
|
+
const status = await Permissions.ensure('location');
|
|
145
|
+
if (status === 'granted' || status === 'limited') {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (status === 'unavailable') {
|
|
149
|
+
Logger.warn(`${PREFIX} Location permission status is unavailable (expo-location is not installed, ` + 'or the check failed); attempting the location request anyway.');
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
throw new GeolocationError('permission-denied', `${PREFIX} Location permission is "${status}". Grant it before requesting a position` + (status === 'blocked' ? ', or call Permissions.openSettings() to let the user fix it.' : '.'));
|
|
153
|
+
};
|
|
154
|
+
const positionOnce = (b, options) => {
|
|
155
|
+
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
156
|
+
return new Promise((resolve, reject) => {
|
|
157
|
+
let settled = false;
|
|
158
|
+
// The native timeout is passed through as well, but a provider that never
|
|
159
|
+
// calls back at all would otherwise hang the caller forever.
|
|
160
|
+
const timer = setTimeout(() => {
|
|
161
|
+
if (settled) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
settled = true;
|
|
165
|
+
reject(new GeolocationError('timeout', `${PREFIX} Location request timed out after ${timeoutMs}ms. Raise timeoutMs, or use ` + "accuracy: 'coarse' where a network fix is good enough."));
|
|
166
|
+
}, timeoutMs);
|
|
167
|
+
const settle = run => {
|
|
168
|
+
if (settled) {
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
settled = true;
|
|
172
|
+
clearTimeout(timer);
|
|
173
|
+
run();
|
|
174
|
+
};
|
|
175
|
+
const onSuccess = raw => settle(() => {
|
|
176
|
+
const position = normalizePosition(raw);
|
|
177
|
+
if (!position) {
|
|
178
|
+
reject(new GeolocationError('position-unavailable', `${PREFIX} The provider returned a fix without usable coordinates.`));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const floor = options.minimumAccuracyM;
|
|
182
|
+
if (floor !== undefined && position.coords.accuracy > floor) {
|
|
183
|
+
reject(new GeolocationError('position-unavailable', `${PREFIX} Fix accuracy ${position.coords.accuracy}m is worse than the required ` + `${floor}m.`));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
resolve(position);
|
|
187
|
+
});
|
|
188
|
+
const onError = error => settle(() => reject(toGeoError(error)));
|
|
189
|
+
try {
|
|
190
|
+
b.getCurrentPosition(onSuccess, onError, toNativeOptions(options));
|
|
191
|
+
} catch (error) {
|
|
192
|
+
settle(() => reject(toGeoError(error)));
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
const getCurrentPosition = async (options = {}) => {
|
|
197
|
+
const b = requireBackend('get the current position');
|
|
198
|
+
await ensureLocationPermission();
|
|
199
|
+
const attempts = Math.max(0, Math.trunc(options.retries ?? DEFAULT_RETRIES)) + 1;
|
|
200
|
+
const retryDelayMs = options.retryDelayMs ?? DEFAULT_RETRY_DELAY_MS;
|
|
201
|
+
let lastError = null;
|
|
202
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
203
|
+
try {
|
|
204
|
+
return await positionOnce(b, options);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
const geoError = toGeoError(error);
|
|
207
|
+
if (!RETRYABLE.includes(geoError.code)) {
|
|
208
|
+
throw geoError;
|
|
209
|
+
}
|
|
210
|
+
lastError = geoError;
|
|
211
|
+
if (attempt < attempts - 1 && retryDelayMs > 0) {
|
|
212
|
+
await sleep(retryDelayMs);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
throw lastError ?? new GeolocationError('position-unavailable', `${PREFIX} Location request failed.`);
|
|
217
|
+
};
|
|
218
|
+
const watchPosition = (listener, options = {}) => {
|
|
219
|
+
const b = requireBackend('watch the position');
|
|
220
|
+
let cancelled = false;
|
|
221
|
+
let watchId = null;
|
|
222
|
+
const stop = () => {
|
|
223
|
+
if (cancelled) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
cancelled = true;
|
|
227
|
+
if (watchId !== null) {
|
|
228
|
+
b.clearWatch(watchId);
|
|
229
|
+
watchId = null;
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
const fail = error => {
|
|
233
|
+
const geoError = toGeoError(error);
|
|
234
|
+
Logger.error(geoError.message);
|
|
235
|
+
options.onError?.(geoError);
|
|
236
|
+
};
|
|
237
|
+
void ensureLocationPermission().then(() => {
|
|
238
|
+
// The caller can unsubscribe while the permission gate is still pending;
|
|
239
|
+
// registering afterwards would leak a watch nothing can clear.
|
|
240
|
+
if (cancelled) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
watchId = b.watchPosition(raw => {
|
|
244
|
+
if (cancelled) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const position = normalizePosition(raw);
|
|
248
|
+
if (!position) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const floor = options.minimumAccuracyM;
|
|
252
|
+
if (floor !== undefined && position.coords.accuracy > floor) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
listener(position);
|
|
256
|
+
}, error => {
|
|
257
|
+
if (!cancelled) {
|
|
258
|
+
fail(error);
|
|
259
|
+
}
|
|
260
|
+
}, toNativeOptions(options));
|
|
261
|
+
}).catch(fail);
|
|
262
|
+
return stop;
|
|
263
|
+
};
|
|
264
|
+
const isAvailable = () => resolveBackend() !== null;
|
|
265
|
+
export const Geolocation = {
|
|
266
|
+
getCurrentPosition,
|
|
267
|
+
watchPosition,
|
|
268
|
+
isAvailable
|
|
269
|
+
};
|
|
270
|
+
export const useCurrentPosition = (options = {}) => {
|
|
271
|
+
const {
|
|
272
|
+
enabled = true,
|
|
273
|
+
accuracy,
|
|
274
|
+
timeoutMs,
|
|
275
|
+
maximumAgeMs,
|
|
276
|
+
retries,
|
|
277
|
+
minimumAccuracyM,
|
|
278
|
+
retryDelayMs
|
|
279
|
+
} = options;
|
|
280
|
+
const [state, setState] = useState({
|
|
281
|
+
position: null,
|
|
282
|
+
error: null,
|
|
283
|
+
loading: enabled
|
|
284
|
+
});
|
|
285
|
+
const mountedRef = useRef(true);
|
|
286
|
+
// Identifies the in-flight request so a slow earlier fix cannot overwrite the
|
|
287
|
+
// result of a later refresh().
|
|
288
|
+
const requestRef = useRef(0);
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
mountedRef.current = true;
|
|
291
|
+
return () => {
|
|
292
|
+
mountedRef.current = false;
|
|
293
|
+
};
|
|
294
|
+
}, []);
|
|
295
|
+
|
|
296
|
+
// Every dependency is a primitive read off `options`, so an inline options
|
|
297
|
+
// object (the normal call shape) does not re-create this on every render.
|
|
298
|
+
const run = useCallback(() => {
|
|
299
|
+
requestRef.current += 1;
|
|
300
|
+
const token = requestRef.current;
|
|
301
|
+
setState(prev => prev.loading ? prev : {
|
|
302
|
+
...prev,
|
|
303
|
+
loading: true
|
|
304
|
+
});
|
|
305
|
+
const accept = next => {
|
|
306
|
+
if (mountedRef.current && requestRef.current === token) {
|
|
307
|
+
setState(next);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
getCurrentPosition({
|
|
311
|
+
accuracy,
|
|
312
|
+
timeoutMs,
|
|
313
|
+
maximumAgeMs,
|
|
314
|
+
retries,
|
|
315
|
+
minimumAccuracyM,
|
|
316
|
+
retryDelayMs
|
|
317
|
+
}).then(position => accept({
|
|
318
|
+
position,
|
|
319
|
+
error: null,
|
|
320
|
+
loading: false
|
|
321
|
+
}), error => accept({
|
|
322
|
+
position: null,
|
|
323
|
+
error: toGeoError(error),
|
|
324
|
+
loading: false
|
|
325
|
+
}));
|
|
326
|
+
}, [accuracy, timeoutMs, maximumAgeMs, retries, minimumAccuracyM, retryDelayMs]);
|
|
327
|
+
useEffect(() => {
|
|
328
|
+
if (!enabled) {
|
|
329
|
+
// Discard any in-flight request so its result cannot land after opting out.
|
|
330
|
+
requestRef.current += 1;
|
|
331
|
+
setState(prev => prev.loading || prev.position !== null || prev.error !== null ? {
|
|
332
|
+
position: null,
|
|
333
|
+
error: null,
|
|
334
|
+
loading: false
|
|
335
|
+
} : prev);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
run();
|
|
339
|
+
}, [enabled, run]);
|
|
340
|
+
return {
|
|
341
|
+
position: state.position,
|
|
342
|
+
error: state.error,
|
|
343
|
+
loading: state.loading,
|
|
344
|
+
refresh: run
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The main barrel deliberately does NOT re-export the modules that need a native
|
|
5
|
+
* package. Metro resolves requires statically, so anything reachable from here
|
|
6
|
+
* is resolved for every consumer, which would make an optional peer mandatory
|
|
7
|
+
* for anyone importing anything at all. Those live behind their own import
|
|
8
|
+
* paths instead:
|
|
9
|
+
*
|
|
10
|
+
* @webority/mobile-core/permissions per kind, its own Expo module
|
|
11
|
+
* @webority/mobile-core/compressor expo-image-manipulator + expo-file-system
|
|
12
|
+
* @webority/mobile-core/geolocation a geolocation provider
|
|
13
|
+
* @webority/mobile-core/sqlite expo-sqlite
|
|
14
|
+
* @webority/mobile-core/download a filesystem module
|
|
15
|
+
* @webority/mobile-core/share expo-sharing
|
|
16
|
+
* @webority/mobile-core/smsRetriever Android only, own TurboModule
|
|
17
|
+
*
|
|
18
|
+
* One more path is separate for size, not for a native package:
|
|
19
|
+
*
|
|
20
|
+
* @webority/mobile-core/phone/countries 245 English country names
|
|
21
|
+
*
|
|
22
|
+
* Token storage is the exception and IS on the main barrel, because the HTTP
|
|
23
|
+
* client reads the bearer token. It needs no optional peer: the backend is
|
|
24
|
+
* expo-secure-store, and `expo` is required anyway.
|
|
25
|
+
*/
|
|
26
|
+
// API clients
|
|
27
|
+
export { buildCurl, logCurl } from "./api/curl.js";
|
|
28
|
+
export { default as publicClient } from "./api/publicClient.js";
|
|
29
|
+
export { attachRetry, isRetryableStatus } from "./api/retry.js";
|
|
30
|
+
export { default as userClient, injectStore, injectUserAuth, RequestOfflineError, resetRefreshState, SESSION_TERMINATION_CODES } from "./api/userClient.js";
|
|
31
|
+
// Auth / token storage
|
|
32
|
+
export { ACCESS_TOKEN_KEY, getToken, REFRESH_TOKEN_KEY, removeToken, setKeychainImplementation, storeToken } from "./auth/authStore.js";
|
|
33
|
+
export { decodeJWT, getJWTExpiry, isJWTExpired } from "./auth/jwt.js";
|
|
34
|
+
// Configuration
|
|
35
|
+
export { getConfig, getConfigValue, resetConfig, setConfig } from "./config/index.js";
|
|
36
|
+
// Deep links
|
|
37
|
+
export { DeepLink, parseDeepLink, useDeepLink } from "./deepLink/index.js";
|
|
38
|
+
// Formatters
|
|
39
|
+
export { AsYouType, addDays, clampNationalNumber, countryFlagEmoji, detectPhoneCountry, diffMs, formatCompactNumber, formatCurrency, formatDate, formatDateDDMMMYYYY, formatDateISO, formatDatePattern, formatDateTime, formatNumber, formatPercent, formatPhone, formatPhoneAsTyped, formatRelativeTime, formatTime, formatTime12h, formatTimeInWindowsZone, formatTimeInZone, getCountries, getCountryCallingCode, getInitials, getPhoneCountries, isDateAfter, isDateBefore, isSameDay, isSupportedCountry, isValidNationalNumber, isValidPhoneNumber, maxNationalNumberLength, normalizePhone, parsePhoneNumber, parsePhoneNumberFromString, splitPhoneNumber, startOfDay, validatePhoneNumberLength } from "./formatters/index.js";
|
|
40
|
+
// Initialization
|
|
41
|
+
export { initWebority } from "./initSDK.js";
|
|
42
|
+
export { initUserAuth } from "./initUserAuth.js";
|
|
43
|
+
// Logger
|
|
44
|
+
export { configureLogger, getDeviceContext, Logger, setDeviceContext, setRemoteLogger } from "./logger/index.js";
|
|
45
|
+
// Network status (the NetworkStatusBanner UI lives in @webority/mobile-ui)
|
|
46
|
+
export { addNetworkStatusListener, getNetworkStatus, setNetworkStatusImplementation, useNetworkStatus } from "./network/index.js";
|
|
47
|
+
// Storage: the API and the seam. No native package is required; wire one with
|
|
48
|
+
// setStorageImplementation to get persistence.
|
|
49
|
+
export { isStorageAvailable, Storage, setStorageImplementation } from "./storage/index.js";
|
|
50
|
+
// Validators
|
|
51
|
+
export { isAadhaar, isAlphanumeric, isBetween, isEmail, isGstin, isHexColor, isIfsc, isIndianMobile, isIndianPincode, isInteger, isNonEmpty, isNumeric, isPan, isPhone, isStrongPassword, isUrl, maxLength, minLength } from "./validators/index.js";
|
|
52
|
+
// Version check (the ForceUpdateDialog UI lives in @webority/mobile-ui)
|
|
53
|
+
export { setDeviceInfoImplementation, useVersionCheck, VersionCheck } from "./versionCheck/index.js";
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Simple initialization API for Webority packages
|
|
5
|
+
* One function to configure everything needed
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { setKeychainImplementation } from "./auth/authStore.js";
|
|
9
|
+
import { setConfig } from "./config/index.js";
|
|
10
|
+
import { Logger } from "./logger/index.js";
|
|
11
|
+
import { setNetworkStatusImplementation } from "./network/networkStatus.js";
|
|
12
|
+
import { setStorageImplementation } from "./storage/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* Initialize Webority packages with your project configuration.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // Basic setup
|
|
18
|
+
* initWebority({
|
|
19
|
+
* baseUrl: 'https://api.myapp.com'
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* // Full configuration
|
|
24
|
+
* initWebority({
|
|
25
|
+
* baseUrl: 'https://api.myapp.com',
|
|
26
|
+
* loggingEnabled: __DEV__,
|
|
27
|
+
* logLevel: 'warn',
|
|
28
|
+
* environment: __DEV__ ? 'Development' : 'Production'
|
|
29
|
+
* });
|
|
30
|
+
*/
|
|
31
|
+
export const initWebority = config => {
|
|
32
|
+
if (!config.baseUrl) {
|
|
33
|
+
throw new Error('baseUrl is required for Webority packages initialization');
|
|
34
|
+
}
|
|
35
|
+
setConfig({
|
|
36
|
+
baseUrl: config.baseUrl,
|
|
37
|
+
loggingEnabled: config.loggingEnabled ?? true,
|
|
38
|
+
logLevel: config.logLevel || 'info',
|
|
39
|
+
environment: config.environment || 'Development',
|
|
40
|
+
country: (config.country || 'in').toLowerCase(),
|
|
41
|
+
appId: config.appId ?? null,
|
|
42
|
+
appVersion: config.appVersion ?? null,
|
|
43
|
+
logCurl: config.logCurl ?? false
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Only what the caller actually passed is wired. Calling a setter with
|
|
47
|
+
// `undefined` would reset a backend an app had already injected by hand,
|
|
48
|
+
// which is why each is guarded rather than passed straight through.
|
|
49
|
+
const backends = config.backends;
|
|
50
|
+
if (backends?.storage) {
|
|
51
|
+
setStorageImplementation(backends.storage);
|
|
52
|
+
}
|
|
53
|
+
if (backends?.keychain) {
|
|
54
|
+
setKeychainImplementation(backends.keychain);
|
|
55
|
+
}
|
|
56
|
+
if (backends?.network) {
|
|
57
|
+
setNetworkStatusImplementation(backends.network);
|
|
58
|
+
}
|
|
59
|
+
Logger.info('[@webority/mobile-core] initialized');
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=initSDK.js.map
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { injectStore, injectUserAuth } from "./api/userClient.js";
|
|
4
|
+
import { Logger } from "./logger/index.js";
|
|
5
|
+
|
|
6
|
+
/** The tokens a refresh response carries, with their expiry timestamps. */
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* How the library calls the app's refresh endpoint. The call goes through
|
|
10
|
+
* `publicClient`, and the new tokens are stored under the library's own keys.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wire the user client to the app: the Redux store it dispatches `logout` to,
|
|
15
|
+
* and the refresh endpoint it calls when an access token expires or a request
|
|
16
|
+
* answers 401. Only a 400 or 401 from that endpoint, or a missing or expired
|
|
17
|
+
* refresh token, logs out; a network error, timeout or 5xx keeps the session.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* initUserAuth(store, { logout, refresh: { path: '/Account/RefreshToken' } });
|
|
21
|
+
*/
|
|
22
|
+
export const initUserAuth = (store, options) => {
|
|
23
|
+
if (!store) {
|
|
24
|
+
throw new Error('Redux store is required for user package initialization');
|
|
25
|
+
}
|
|
26
|
+
if (!options.logout || !options.refresh?.path) {
|
|
27
|
+
throw new Error('initUserAuth needs a logout action and refresh.path');
|
|
28
|
+
}
|
|
29
|
+
injectStore(store);
|
|
30
|
+
injectUserAuth(options);
|
|
31
|
+
Logger.info('[@webority/mobile-core] user auth wired to the store');
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=initUserAuth.js.map
|