@webority/mobile-core 0.163.0 → 0.164.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/android/src/newarch/java/com/webority/mobilecore/smsretriever/AppSignatureHelper.kt +2 -2
- package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModuleImpl.kt +2 -2
- package/lib/commonjs/api/tokenRefresh.js +1 -1
- package/lib/commonjs/versionCheck/index.js +1 -1
- package/lib/module/api/tokenRefresh.js +1 -1
- package/lib/module/versionCheck/index.js +1 -1
- package/lib/typescript/commonjs/api/baseUrl.d.ts +1 -1
- package/lib/typescript/commonjs/config/index.d.ts +1 -1
- package/lib/typescript/commonjs/formatters/currency.d.ts +1 -1
- package/lib/typescript/commonjs/formatters/dateMath.d.ts +9 -9
- package/lib/typescript/commonjs/formatters/number.d.ts +1 -1
- package/lib/typescript/commonjs/formatters/windowsToIanaTable.d.ts +3 -3
- package/lib/typescript/commonjs/geolocation/adapters/expoLocation.d.ts +1 -1
- package/lib/typescript/commonjs/initUserAuth.d.ts +1 -1
- package/lib/typescript/commonjs/permissions/index.d.ts +1 -1
- package/lib/typescript/commonjs/smsRetriever/index.d.ts +2 -2
- package/lib/typescript/commonjs/specs/NativeSmsRetriever.d.ts +1 -1
- package/lib/typescript/commonjs/sqlite/index.d.ts +1 -1
- package/lib/typescript/commonjs/storage/index.d.ts +1 -1
- package/lib/typescript/commonjs/validators/index.d.ts +1 -1
- package/lib/typescript/commonjs/versionCheck/index.d.ts +1 -1
- package/lib/typescript/module/api/baseUrl.d.ts +1 -1
- package/lib/typescript/module/config/index.d.ts +1 -1
- package/lib/typescript/module/formatters/currency.d.ts +1 -1
- package/lib/typescript/module/formatters/dateMath.d.ts +9 -9
- package/lib/typescript/module/formatters/number.d.ts +1 -1
- package/lib/typescript/module/formatters/windowsToIanaTable.d.ts +3 -3
- package/lib/typescript/module/geolocation/adapters/expoLocation.d.ts +1 -1
- package/lib/typescript/module/initUserAuth.d.ts +1 -1
- package/lib/typescript/module/permissions/index.d.ts +1 -1
- package/lib/typescript/module/smsRetriever/index.d.ts +2 -2
- package/lib/typescript/module/specs/NativeSmsRetriever.d.ts +1 -1
- package/lib/typescript/module/sqlite/index.d.ts +1 -1
- package/lib/typescript/module/storage/index.d.ts +1 -1
- package/lib/typescript/module/validators/index.d.ts +1 -1
- package/lib/typescript/module/versionCheck/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/specs/NativeSmsRetriever.ts +1 -1
package/README.md
CHANGED
|
@@ -229,6 +229,8 @@ const entityTag = entityTagOf(response);
|
|
|
229
229
|
await userClient.put(`/leaves/${id}`, body, withIfMatch(versionOf(response.data, entityTag)));
|
|
230
230
|
```
|
|
231
231
|
|
|
232
|
+
An endpoint's `transformResponse(data, meta)` reads the same ETag from `meta.entityTag`, and its `transformErrorResponse(error, meta)` reads it on a failure. A save that returns a new version is therefore read in the save's own endpoint, with no refetch. `entityTag` is the strong ETag without quotes, and it is undefined for a weak or missing one.
|
|
233
|
+
|
|
232
234
|
### Notification buttons
|
|
233
235
|
|
|
234
236
|
A push names a category; the category's buttons are registered on the phone. Register them at
|
|
@@ -8,10 +8,10 @@ import java.security.MessageDigest
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* The 11-character app-signature hash the SMS Retriever API matches against
|
|
11
|
-
* an incoming message
|
|
11
|
+
* an incoming message: the backend appends this same hash so Play Services
|
|
12
12
|
* knows which app to hand the SMS to, with no SMS permission granted.
|
|
13
13
|
* Algorithm is Google's own (SHA-256 of "<packageName> <signature>", first 9
|
|
14
|
-
* bytes, base64 NO_PADDING/NO_WRAP, first 11 chars)
|
|
14
|
+
* bytes, base64 NO_PADDING/NO_WRAP, first 11 chars); not our own scheme.
|
|
15
15
|
*/
|
|
16
16
|
class AppSignatureHelper(private val context: ReactApplicationContext) {
|
|
17
17
|
companion object {
|
package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModuleImpl.kt
CHANGED
|
@@ -20,7 +20,7 @@ private enum class SmsErrorType { TIMEOUT, SERVICE_UNAVAILABLE, UNKNOWN_ERROR }
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Wraps the Play Services SMS Retriever API. Emits the raw SMS text on
|
|
23
|
-
* success
|
|
23
|
+
* success. OTP extraction is a JS-side concern (see smsRetriever/index.ts),
|
|
24
24
|
* since the expected format varies per backend and this module's only job
|
|
25
25
|
* is retrieving the message with no SMS permission required.
|
|
26
26
|
*/
|
|
@@ -124,7 +124,7 @@ class SmsRetrieverModuleImpl(private val reactContext: ReactApplicationContext)
|
|
|
124
124
|
try {
|
|
125
125
|
reactContext.unregisterReceiver(receiver)
|
|
126
126
|
} catch (e: IllegalArgumentException) {
|
|
127
|
-
// Already unregistered
|
|
127
|
+
// Already unregistered: not an error, the OS may have torn it down first.
|
|
128
128
|
} finally {
|
|
129
129
|
isRegistered = false
|
|
130
130
|
isListening = false
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.waitForSessionReplacement=exports.storeReplacementSession=exports.sessionDetailOf=exports.sessionCodeOf=exports.resetRefreshState=exports.refreshAccessToken=exports.queueBehindRefresh=exports.isSessionEnd=exports.isRefreshInFlight=exports.injectUserAuth=exports.injectStore=exports.getRefreshPath=exports.getErrorMessage=exports.getAccountIdProvider=exports.endSessionAndLogout=exports.dispatchLogout=exports.currentTokenIfReplaced=exports.beginSessionReplacement=exports.SessionEndedError=exports.SESSION_REVOKED_CODE=exports.SESSION_EXPIRED_CODE=void 0;var _axios=_interopRequireDefault(require("axios")),_authStore=require("../auth/authStore.js"),_index=require("../logger/index.js"),_guards=require("../utils/guards.js"),_publicClient=_interopRequireDefault(require("./publicClient.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const SESSION_REVOKED_CODE=exports.SESSION_REVOKED_CODE="session_revoked",SESSION_EXPIRED_CODE=exports.SESSION_EXPIRED_CODE="session_expired";class SessionEndedError extends Error{constructor(e){super(e),this.name="SessionEndedError",Object.setPrototypeOf(this,SessionEndedError.prototype)}}let store,auth;exports.SessionEndedError=SessionEndedError;const injectStore=e=>{store=e??void 0};exports.injectStore=injectStore;const injectUserAuth=e=>{auth=e};exports.injectUserAuth=injectUserAuth;let refreshTokenPromise=null,failedQueue=[];const processQueue=(e,s=null)=>{failedQueue.forEach(({resolve:r,reject:t})=>{e?t(e):null!==s&&r(s)}),failedQueue=[]},resetRefreshState=()=>{refreshTokenPromise=null,processQueue(new SessionEndedError("[@webority/mobile-core] Session ended"))};exports.resetRefreshState=resetRefreshState;const getErrorMessage=e=>e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";exports.getErrorMessage=getErrorMessage;const requireAuth=()=>{if(!store||!auth)throw new Error("User package store is not initialized. Call initUserAuth first.");return{store:store,auth:auth}},getAccountIdProvider=()=>auth?.accountId;exports.getAccountIdProvider=getAccountIdProvider;const getRefreshPath=()=>auth?.refresh.path;exports.getRefreshPath=getRefreshPath;const dispatchLogout=async()=>{const e=requireAuth();await e.store.dispatch(e.auth.logout())};exports.dispatchLogout=dispatchLogout;const endSessionAndLogout=async(e,s,r=null)=>{await(0,_authStore.clearSession)(e,{code:s,detail:r}),await dispatchLogout()};exports.endSessionAndLogout=endSessionAndLogout;const sessionCodeOf=e=>{const s=(0,_guards.isRecord)(e)?e.code:void 0;return s===SESSION_REVOKED_CODE||s===SESSION_EXPIRED_CODE?s:null};exports.sessionCodeOf=sessionCodeOf;const sessionDetailOf=e=>{if(null===sessionCodeOf(e)||!(0,_guards.isRecord)(e))return null;const s=e.detail;return"string"==typeof s&&""!==s?s:null};exports.sessionDetailOf=sessionDetailOf;const isRefreshInFlight=()=>null!==refreshTokenPromise;exports.isRefreshInFlight=isRefreshInFlight;let replacementCount=0,replacementSettled=Promise.resolve(),settleReplacement=null;const beginSessionReplacement=()=>{0===replacementCount&&(replacementSettled=new Promise(e=>{settleReplacement=e})),replacementCount+=1;let e=!1;return()=>{e||(e=!0,replacementCount-=1,0===replacementCount&&(settleReplacement?.(),settleReplacement=null))}};exports.beginSessionReplacement=beginSessionReplacement;const waitForSessionReplacement=()=>0===replacementCount?Promise.resolve():replacementSettled;exports.waitForSessionReplacement=waitForSessionReplacement;const currentTokenIfReplaced=async e=>{const s=(await(0,_authStore.getToken)(_authStore.ACCESS_TOKEN_KEY))?.token??null;return null!==s&&s!==e?s:null};exports.currentTokenIfReplaced=currentTokenIfReplaced;const queueBehindRefresh=()=>new Promise((e,s)=>{failedQueue.push({resolve:e,reject:s})});exports.queueBehindRefresh=queueBehindRefresh;const isSessionEnd=e=>e instanceof SessionEndedError||_axios.default.isAxiosError(e)&&(400===e.response?.status||401===e.response?.status);exports.isSessionEnd=isSessionEnd;const asString=(e,s)=>{if("string"!=typeof e||""===e)throw new Error(`The refresh response has no "${s}".`);return e},readWeborityTokens=e=>{const s=(0,_guards.isRecord)(e)?e:{};return{accessToken:asString(s.accessToken,"accessToken"),accessTokenExpiry:
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.waitForSessionReplacement=exports.storeReplacementSession=exports.sessionDetailOf=exports.sessionCodeOf=exports.resetRefreshState=exports.refreshAccessToken=exports.queueBehindRefresh=exports.isSessionEnd=exports.isRefreshInFlight=exports.injectUserAuth=exports.injectStore=exports.getRefreshPath=exports.getErrorMessage=exports.getAccountIdProvider=exports.endSessionAndLogout=exports.dispatchLogout=exports.currentTokenIfReplaced=exports.beginSessionReplacement=exports.SessionEndedError=exports.SESSION_REVOKED_CODE=exports.SESSION_EXPIRED_CODE=void 0;var _axios=_interopRequireDefault(require("axios")),_authStore=require("../auth/authStore.js"),_index=require("../logger/index.js"),_guards=require("../utils/guards.js"),_publicClient=_interopRequireDefault(require("./publicClient.js"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const SESSION_REVOKED_CODE=exports.SESSION_REVOKED_CODE="session_revoked",SESSION_EXPIRED_CODE=exports.SESSION_EXPIRED_CODE="session_expired";class SessionEndedError extends Error{constructor(e){super(e),this.name="SessionEndedError",Object.setPrototypeOf(this,SessionEndedError.prototype)}}let store,auth;exports.SessionEndedError=SessionEndedError;const injectStore=e=>{store=e??void 0};exports.injectStore=injectStore;const injectUserAuth=e=>{auth=e};exports.injectUserAuth=injectUserAuth;let refreshTokenPromise=null,failedQueue=[];const processQueue=(e,s=null)=>{failedQueue.forEach(({resolve:r,reject:t})=>{e?t(e):null!==s&&r(s)}),failedQueue=[]},resetRefreshState=()=>{refreshTokenPromise=null,processQueue(new SessionEndedError("[@webority/mobile-core] Session ended"))};exports.resetRefreshState=resetRefreshState;const getErrorMessage=e=>e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";exports.getErrorMessage=getErrorMessage;const requireAuth=()=>{if(!store||!auth)throw new Error("User package store is not initialized. Call initUserAuth first.");return{store:store,auth:auth}},getAccountIdProvider=()=>auth?.accountId;exports.getAccountIdProvider=getAccountIdProvider;const getRefreshPath=()=>auth?.refresh.path;exports.getRefreshPath=getRefreshPath;const dispatchLogout=async()=>{const e=requireAuth();await e.store.dispatch(e.auth.logout())};exports.dispatchLogout=dispatchLogout;const endSessionAndLogout=async(e,s,r=null)=>{await(0,_authStore.clearSession)(e,{code:s,detail:r}),await dispatchLogout()};exports.endSessionAndLogout=endSessionAndLogout;const sessionCodeOf=e=>{const s=(0,_guards.isRecord)(e)?e.code:void 0;return s===SESSION_REVOKED_CODE||s===SESSION_EXPIRED_CODE?s:null};exports.sessionCodeOf=sessionCodeOf;const sessionDetailOf=e=>{if(null===sessionCodeOf(e)||!(0,_guards.isRecord)(e))return null;const s=e.detail;return"string"==typeof s&&""!==s?s:null};exports.sessionDetailOf=sessionDetailOf;const isRefreshInFlight=()=>null!==refreshTokenPromise;exports.isRefreshInFlight=isRefreshInFlight;let replacementCount=0,replacementSettled=Promise.resolve(),settleReplacement=null;const beginSessionReplacement=()=>{0===replacementCount&&(replacementSettled=new Promise(e=>{settleReplacement=e})),replacementCount+=1;let e=!1;return()=>{e||(e=!0,replacementCount-=1,0===replacementCount&&(settleReplacement?.(),settleReplacement=null))}};exports.beginSessionReplacement=beginSessionReplacement;const waitForSessionReplacement=()=>0===replacementCount?Promise.resolve():replacementSettled;exports.waitForSessionReplacement=waitForSessionReplacement;const currentTokenIfReplaced=async e=>{const s=(await(0,_authStore.getToken)(_authStore.ACCESS_TOKEN_KEY))?.token??null;return null!==s&&s!==e?s:null};exports.currentTokenIfReplaced=currentTokenIfReplaced;const queueBehindRefresh=()=>new Promise((e,s)=>{failedQueue.push({resolve:e,reject:s})});exports.queueBehindRefresh=queueBehindRefresh;const isSessionEnd=e=>e instanceof SessionEndedError||_axios.default.isAxiosError(e)&&(400===e.response?.status||401===e.response?.status);exports.isSessionEnd=isSessionEnd;const asString=(e,s)=>{if("string"!=typeof e||""===e)throw new Error(`The refresh response has no "${s}".`);return e},asDate=(e,s)=>{const r=asString(e,s);if(Number.isNaN(Date.parse(r)))throw new Error(`The refresh response's "${s}" is not a date.`);return r},readWeborityTokens=e=>{const s=(0,_guards.isRecord)(e)?e:{};return{accessToken:asString(s.accessToken,"accessToken"),accessTokenExpiry:asDate(s.accessTokenExpiresDateTimeUtc,"accessTokenExpiresDateTimeUtc"),refreshToken:asString(s.refreshToken,"refreshToken"),refreshTokenExpiry:asDate(s.refreshTokenExpiresDateTimeUtc,"refreshTokenExpiresDateTimeUtc")}};class ReplacementTokensMissingError extends Error{constructor(e){super(`A session-replacing response carried no tokens: ${e}`),this.name="ReplacementTokensMissingError",Object.setPrototypeOf(this,ReplacementTokensMissingError.prototype)}}const storeReplacementSession=async e=>{let s;try{s=(auth?.refresh.readTokens??readWeborityTokens)(e)}catch(e){throw new ReplacementTokensMissingError(getErrorMessage(e))}await(0,_authStore.storeToken)(_authStore.ACCESS_TOKEN_KEY,s.accessToken,s.accessTokenExpiry),await(0,_authStore.storeToken)(_authStore.REFRESH_TOKEN_KEY,s.refreshToken,s.refreshTokenExpiry)};exports.storeReplacementSession=storeReplacementSession;const callRefreshEndpoint=async e=>{const s=await(0,_authStore.getToken)(_authStore.REFRESH_TOKEN_KEY);if(!s?.token)throw new SessionEndedError("No refresh token available");if(Date.parse(s.expiry)<=Date.now())throw new SessionEndedError("Refresh token expired");const r=await(0,_authStore.getToken)(_authStore.ACCESS_TOKEN_KEY),t={accessToken:r?.token??null,refreshToken:s.token},o=e.body?await e.body(t):t,n=e.headers?await e.headers():void 0;_index.Logger.info("Refreshing the access token");const{data:i}=await _publicClient.default.post(e.path,o,{...n?{headers:n}:{},skipErrorLog:!0}),a=(e.readTokens??readWeborityTokens)(i);if(await waitForSessionReplacement(),(await(0,_authStore.getToken)(_authStore.REFRESH_TOKEN_KEY))?.token!==s.token){const e=(await(0,_authStore.getToken)(_authStore.ACCESS_TOKEN_KEY))?.token;if(e)return _index.Logger.info("Keeping the session that replaced this one during the refresh"),e}return await(0,_authStore.storeToken)(_authStore.ACCESS_TOKEN_KEY,a.accessToken,a.accessTokenExpiry),await(0,_authStore.storeToken)(_authStore.REFRESH_TOKEN_KEY,a.refreshToken,a.refreshTokenExpiry),_index.Logger.info("Access token refreshed"),a.accessToken},endReason=e=>_axios.default.isAxiosError(e)?sessionCodeOf(e.response?.data)??`status ${e.response?.status}`:getErrorMessage(e),refreshAccessToken=()=>{if(refreshTokenPromise)return refreshTokenPromise;const e=(async()=>{let e=null;try{const{refresh:s}=requireAuth().auth;e=(await(0,_authStore.getToken)(_authStore.ACCESS_TOKEN_KEY))?.token??null;const r=await callRefreshEndpoint(s);return processQueue(null,r),r}catch(s){if(isSessionEnd(s)){await waitForSessionReplacement();let s=null;try{s=await currentTokenIfReplaced(e)}catch(e){_index.Logger.error("Reading the stored token after a failed refresh failed:",getErrorMessage(e))}if(s)return _index.Logger.info("The session was replaced during the refresh; continuing with the new one"),processQueue(null,s),s}const r=isSessionEnd(s);if(r)_index.Logger.info("Session ended, the refresh was refused:",endReason(s));else{const e=_axios.default.isAxiosError(s)?s.response?.data:void 0;_index.Logger.error("Token refresh failed:",e??getErrorMessage(s))}if(processQueue(s,null),r){const e=_axios.default.isAxiosError(s)&&401===s.response?.status,r=e?sessionCodeOf(s.response?.data):null,t=e?sessionDetailOf(s.response?.data):null;await endSessionAndLogout("rejected",r,t)}throw s}})().finally(()=>{refreshTokenPromise===e&&(refreshTokenPromise=null)});return refreshTokenPromise=e,e};exports.refreshAccessToken=refreshAccessToken;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.VersionCheck=void 0,Object.defineProperty(exports,"isBuildBelowMinimum",{enumerable:!0,get:function(){return _buildNumber.isBuildBelowMinimum}}),Object.defineProperty(exports,"parseBuildNumber",{enumerable:!0,get:function(){return _buildNumber.parseBuildNumber}}),Object.defineProperty(exports,"readAppBuild",{enumerable:!0,get:function(){return _appBuild.readAppBuild}}),exports.useVersionCheck=exports.setDeviceInfoImplementation=void 0;var _react=require("react"),_minAppVersion=require("../api/minAppVersion.js"),_index=require("../config/index.js"),_index2=require("../logger/index.js"),_appBuild=require("./appBuild.js"),_buildNumber=require("./buildNumber.js");const setDeviceInfoImplementation=e=>{(0,_appBuild.setDeviceInfo)(e)};exports.setDeviceInfoImplementation=setDeviceInfoImplementation;const missing=(e,r)=>{const t=new Error(`[VersionCheck] the app's ${e} is not available. Call setConfig({ ${r}: ... })
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.VersionCheck=void 0,Object.defineProperty(exports,"isBuildBelowMinimum",{enumerable:!0,get:function(){return _buildNumber.isBuildBelowMinimum}}),Object.defineProperty(exports,"parseBuildNumber",{enumerable:!0,get:function(){return _buildNumber.parseBuildNumber}}),Object.defineProperty(exports,"readAppBuild",{enumerable:!0,get:function(){return _appBuild.readAppBuild}}),exports.useVersionCheck=exports.setDeviceInfoImplementation=void 0;var _react=require("react"),_minAppVersion=require("../api/minAppVersion.js"),_index=require("../config/index.js"),_index2=require("../logger/index.js"),_appBuild=require("./appBuild.js"),_buildNumber=require("./buildNumber.js");const setDeviceInfoImplementation=e=>{(0,_appBuild.setDeviceInfo)(e)};exports.setDeviceInfoImplementation=setDeviceInfoImplementation;const missing=(e,r)=>{const t=new Error(`[VersionCheck] the app's ${e} is not available. Call setConfig({ ${r}: ... }). Every Webority app already has this value in appsettings.Compiled.json, or setDeviceInfoImplementation() with a native provider.`);return _index2.Logger.error(t.message),t},getSystemName=()=>{const{Platform:e}=require("react-native");return e.OS},getBundleId=()=>{const e=(0,_index.getConfigValue)("appId");if(e)return e;const r=((0,_appBuild.getDeviceInfo)()??_appBuild.expoApplicationBackend).getBundleId();if(r)return r;throw missing("store identifier","appId")},getBuildNumber=()=>{const e=(0,_appBuild.readAppBuild)();if(null!==e)return e;throw missing("build number","appBuild")},getCountry=()=>(0,_index.getConfigValue)("country","in").toLowerCase(),subscribeMinimum=e=>(0,_minAppVersion.addMinAppVersionListener)(()=>e()),getFallbackStoreUrl=()=>{const e=getSystemName().toLowerCase(),r=getCountry();if("ios"===e){const e=(0,_index.getConfigValue)("appStoreId");return e?`https://apps.apple.com/${r}/app/id${e}`:`https://apps.apple.com/${r}/app/${getBundleId()}`}return`https://play.google.com/store/apps/details?id=${getBundleId()}&hl=${r}`},storeUrlOrNull=()=>{try{return getFallbackStoreUrl()}catch{return null}},checkForUpdates=()=>{const e=(0,_buildNumber.isBuildBelowMinimum)(getBuildNumber(),(0,_minAppVersion.getMinAppVersion)());return{isNewVersionAvailable:e,updateType:e?"major":null,url:e?storeUrlOrNull():null}},VersionCheck=exports.VersionCheck={isNewVersionAvailable:async()=>checkForUpdates(),openUpdateUrl:async e=>{const{Linking:r}=require("react-native");try{if(e)_index2.Logger.info(`Opening app store URL: ${e}`),await r.openURL(e);else{const e=getFallbackStoreUrl();_index2.Logger.info(`Opening fallback store URL: ${e}`),await r.openURL(e)}return!0}catch(t){const i=t instanceof Error?t.message:String(t);_index2.Logger.error(`Failed to open store URL: ${i}`);try{if(e){const e=getFallbackStoreUrl();return _index2.Logger.info(`Trying fallback store URL: ${e}`),await r.openURL(e),!0}}catch(e){const r=e instanceof Error?e.message:String(e);_index2.Logger.error(`Failed to open fallback URL: ${r}`)}return!1}},getFallbackStoreUrl:getFallbackStoreUrl},NOT_REQUIRED={isUpdateRequired:!1,updateUrl:null},useVersionCheck=(e,r=(0,_index.getConfigValue)("environment","Development"))=>{const t=(0,_react.useSyncExternalStore)(subscribeMinimum,_minAppVersion.getMinAppVersion,_minAppVersion.getMinAppVersion);return(0,_react.useMemo)(()=>{if(!e||"Production"!==r||null===t)return NOT_REQUIRED;try{if(!(0,_buildNumber.isBuildBelowMinimum)(getBuildNumber(),t))return NOT_REQUIRED}catch{return NOT_REQUIRED}return{isUpdateRequired:!0,updateUrl:storeUrlOrNull()}},[e,r,t])};exports.useVersionCheck=useVersionCheck;var _default=exports.default=VersionCheck;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import axios from"axios";import{ACCESS_TOKEN_KEY,clearSession,getToken,REFRESH_TOKEN_KEY,storeToken}from"../auth/authStore.js";import{Logger}from"../logger/index.js";import{isRecord}from"../utils/guards.js";import publicClient from"./publicClient.js";export const SESSION_REVOKED_CODE="session_revoked";export const SESSION_EXPIRED_CODE="session_expired";export class SessionEndedError extends Error{constructor(e){super(e),this.name="SessionEndedError",Object.setPrototypeOf(this,SessionEndedError.prototype)}}let store,auth;export const injectStore=e=>{store=e??void 0};export const injectUserAuth=e=>{auth=e};let refreshTokenPromise=null,failedQueue=[];const processQueue=(e,
|
|
1
|
+
"use strict";import axios from"axios";import{ACCESS_TOKEN_KEY,clearSession,getToken,REFRESH_TOKEN_KEY,storeToken}from"../auth/authStore.js";import{Logger}from"../logger/index.js";import{isRecord}from"../utils/guards.js";import publicClient from"./publicClient.js";export const SESSION_REVOKED_CODE="session_revoked";export const SESSION_EXPIRED_CODE="session_expired";export class SessionEndedError extends Error{constructor(e){super(e),this.name="SessionEndedError",Object.setPrototypeOf(this,SessionEndedError.prototype)}}let store,auth;export const injectStore=e=>{store=e??void 0};export const injectUserAuth=e=>{auth=e};let refreshTokenPromise=null,failedQueue=[];const processQueue=(e,s=null)=>{failedQueue.forEach(({resolve:r,reject:o})=>{e?o(e):null!==s&&r(s)}),failedQueue=[]};export const resetRefreshState=()=>{refreshTokenPromise=null,processQueue(new SessionEndedError("[@webority/mobile-core] Session ended"))};export const getErrorMessage=e=>e instanceof Error?e.message:"string"==typeof e?e:"Unknown error";const requireAuth=()=>{if(!store||!auth)throw new Error("User package store is not initialized. Call initUserAuth first.");return{store:store,auth:auth}};export const getAccountIdProvider=()=>auth?.accountId;export const getRefreshPath=()=>auth?.refresh.path;export const dispatchLogout=async()=>{const e=requireAuth();await e.store.dispatch(e.auth.logout())};export const endSessionAndLogout=async(e,s,r=null)=>{await clearSession(e,{code:s,detail:r}),await dispatchLogout()};export const sessionCodeOf=e=>{const s=isRecord(e)?e.code:void 0;return"session_revoked"===s||"session_expired"===s?s:null};export const sessionDetailOf=e=>{if(null===sessionCodeOf(e)||!isRecord(e))return null;const s=e.detail;return"string"==typeof s&&""!==s?s:null};export const isRefreshInFlight=()=>null!==refreshTokenPromise;let replacementCount=0,replacementSettled=Promise.resolve(),settleReplacement=null;export const beginSessionReplacement=()=>{0===replacementCount&&(replacementSettled=new Promise(e=>{settleReplacement=e})),replacementCount+=1;let e=!1;return()=>{e||(e=!0,replacementCount-=1,0===replacementCount&&(settleReplacement?.(),settleReplacement=null))}};export const waitForSessionReplacement=()=>0===replacementCount?Promise.resolve():replacementSettled;export const currentTokenIfReplaced=async e=>{const s=(await getToken(ACCESS_TOKEN_KEY))?.token??null;return null!==s&&s!==e?s:null};export const queueBehindRefresh=()=>new Promise((e,s)=>{failedQueue.push({resolve:e,reject:s})});export const isSessionEnd=e=>e instanceof SessionEndedError||axios.isAxiosError(e)&&(400===e.response?.status||401===e.response?.status);const asString=(e,s)=>{if("string"!=typeof e||""===e)throw new Error(`The refresh response has no "${s}".`);return e},asDate=(e,s)=>{const r=asString(e,s);if(Number.isNaN(Date.parse(r)))throw new Error(`The refresh response's "${s}" is not a date.`);return r},readWeborityTokens=e=>{const s=isRecord(e)?e:{};return{accessToken:asString(s.accessToken,"accessToken"),accessTokenExpiry:asDate(s.accessTokenExpiresDateTimeUtc,"accessTokenExpiresDateTimeUtc"),refreshToken:asString(s.refreshToken,"refreshToken"),refreshTokenExpiry:asDate(s.refreshTokenExpiresDateTimeUtc,"refreshTokenExpiresDateTimeUtc")}};class ReplacementTokensMissingError extends Error{constructor(e){super(`A session-replacing response carried no tokens: ${e}`),this.name="ReplacementTokensMissingError",Object.setPrototypeOf(this,ReplacementTokensMissingError.prototype)}}export const storeReplacementSession=async e=>{let s;try{s=(auth?.refresh.readTokens??readWeborityTokens)(e)}catch(e){throw new ReplacementTokensMissingError(getErrorMessage(e))}await storeToken(ACCESS_TOKEN_KEY,s.accessToken,s.accessTokenExpiry),await storeToken(REFRESH_TOKEN_KEY,s.refreshToken,s.refreshTokenExpiry)};const callRefreshEndpoint=async e=>{const s=await getToken(REFRESH_TOKEN_KEY);if(!s?.token)throw new SessionEndedError("No refresh token available");if(Date.parse(s.expiry)<=Date.now())throw new SessionEndedError("Refresh token expired");const r=await getToken(ACCESS_TOKEN_KEY),o={accessToken:r?.token??null,refreshToken:s.token},t=e.body?await e.body(o):o,n=e.headers?await e.headers():void 0;Logger.info("Refreshing the access token");const{data:i}=await publicClient.post(e.path,t,{...n?{headers:n}:{},skipErrorLog:!0}),a=(e.readTokens??readWeborityTokens)(i);if(await waitForSessionReplacement(),(await getToken(REFRESH_TOKEN_KEY))?.token!==s.token){const e=(await getToken(ACCESS_TOKEN_KEY))?.token;if(e)return Logger.info("Keeping the session that replaced this one during the refresh"),e}return await storeToken(ACCESS_TOKEN_KEY,a.accessToken,a.accessTokenExpiry),await storeToken(REFRESH_TOKEN_KEY,a.refreshToken,a.refreshTokenExpiry),Logger.info("Access token refreshed"),a.accessToken},endReason=e=>axios.isAxiosError(e)?sessionCodeOf(e.response?.data)??`status ${e.response?.status}`:getErrorMessage(e);export const refreshAccessToken=()=>{if(refreshTokenPromise)return refreshTokenPromise;const e=(async()=>{let e=null;try{const{refresh:s}=requireAuth().auth;e=(await getToken(ACCESS_TOKEN_KEY))?.token??null;const r=await callRefreshEndpoint(s);return processQueue(null,r),r}catch(s){if(isSessionEnd(s)){await waitForSessionReplacement();let s=null;try{s=await currentTokenIfReplaced(e)}catch(e){Logger.error("Reading the stored token after a failed refresh failed:",getErrorMessage(e))}if(s)return Logger.info("The session was replaced during the refresh; continuing with the new one"),processQueue(null,s),s}const r=isSessionEnd(s);if(r)Logger.info("Session ended, the refresh was refused:",endReason(s));else{const e=axios.isAxiosError(s)?s.response?.data:void 0;Logger.error("Token refresh failed:",e??getErrorMessage(s))}if(processQueue(s,null),r){const e=axios.isAxiosError(s)&&401===s.response?.status,r=e?sessionCodeOf(s.response?.data):null,o=e?sessionDetailOf(s.response?.data):null;await endSessionAndLogout("rejected",r,o)}throw s}})().finally(()=>{refreshTokenPromise===e&&(refreshTokenPromise=null)});return refreshTokenPromise=e,e};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";import{useMemo,useSyncExternalStore}from"react";import{addMinAppVersionListener,getMinAppVersion}from"../api/minAppVersion.js";import{getConfigValue}from"../config/index.js";import{Logger}from"../logger/index.js";import{expoApplicationBackend,getDeviceInfo,readAppBuild,setDeviceInfo}from"./appBuild.js";import{isBuildBelowMinimum}from"./buildNumber.js";export const setDeviceInfoImplementation=e=>{setDeviceInfo(e)};const missing=(e,r)=>{const t=new Error(`[VersionCheck] the app's ${e} is not available. Call setConfig({ ${r}: ... })
|
|
1
|
+
"use strict";import{useMemo,useSyncExternalStore}from"react";import{addMinAppVersionListener,getMinAppVersion}from"../api/minAppVersion.js";import{getConfigValue}from"../config/index.js";import{Logger}from"../logger/index.js";import{expoApplicationBackend,getDeviceInfo,readAppBuild,setDeviceInfo}from"./appBuild.js";import{isBuildBelowMinimum}from"./buildNumber.js";export const setDeviceInfoImplementation=e=>{setDeviceInfo(e)};const missing=(e,r)=>{const t=new Error(`[VersionCheck] the app's ${e} is not available. Call setConfig({ ${r}: ... }). Every Webority app already has this value in appsettings.Compiled.json, or setDeviceInfoImplementation() with a native provider.`);return Logger.error(t.message),t},getSystemName=()=>{const{Platform:e}=require("react-native");return e.OS},getBundleId=()=>{const e=getConfigValue("appId");if(e)return e;const r=(getDeviceInfo()??expoApplicationBackend).getBundleId();if(r)return r;throw missing("store identifier","appId")},getBuildNumber=()=>{const e=readAppBuild();if(null!==e)return e;throw missing("build number","appBuild")},getCountry=()=>getConfigValue("country","in").toLowerCase(),subscribeMinimum=e=>addMinAppVersionListener(()=>e()),getFallbackStoreUrl=()=>{const e=getSystemName().toLowerCase(),r=getCountry();if("ios"===e){const e=getConfigValue("appStoreId");return e?`https://apps.apple.com/${r}/app/id${e}`:`https://apps.apple.com/${r}/app/${getBundleId()}`}return`https://play.google.com/store/apps/details?id=${getBundleId()}&hl=${r}`},storeUrlOrNull=()=>{try{return getFallbackStoreUrl()}catch{return null}},checkForUpdates=()=>{const e=isBuildBelowMinimum(getBuildNumber(),getMinAppVersion());return{isNewVersionAvailable:e,updateType:e?"major":null,url:e?storeUrlOrNull():null}};export const VersionCheck={isNewVersionAvailable:async()=>checkForUpdates(),openUpdateUrl:async e=>{const{Linking:r}=require("react-native");try{if(e)Logger.info(`Opening app store URL: ${e}`),await r.openURL(e);else{const e=getFallbackStoreUrl();Logger.info(`Opening fallback store URL: ${e}`),await r.openURL(e)}return!0}catch(t){const o=t instanceof Error?t.message:String(t);Logger.error(`Failed to open store URL: ${o}`);try{if(e){const e=getFallbackStoreUrl();return Logger.info(`Trying fallback store URL: ${e}`),await r.openURL(e),!0}}catch(e){const r=e instanceof Error?e.message:String(e);Logger.error(`Failed to open fallback URL: ${r}`)}return!1}},getFallbackStoreUrl:getFallbackStoreUrl};const NOT_REQUIRED={isUpdateRequired:!1,updateUrl:null};export const useVersionCheck=(e,r=getConfigValue("environment","Development"))=>{const t=useSyncExternalStore(subscribeMinimum,getMinAppVersion,getMinAppVersion);return useMemo(()=>{if(!e||"Production"!==r||null===t)return NOT_REQUIRED;try{if(!isBuildBelowMinimum(getBuildNumber(),t))return NOT_REQUIRED}catch{return NOT_REQUIRED}return{isUpdateRequired:!0,updateUrl:storeUrlOrNull()}},[e,r,t])};export default VersionCheck;export{readAppBuild}from"./appBuild.js";export{isBuildBelowMinimum,parseBuildNumber}from"./buildNumber.js";
|
|
@@ -3,7 +3,7 @@ import type { AxiosInstance } from "axios";
|
|
|
3
3
|
* Resolves `baseURL` PER REQUEST rather than at module evaluation.
|
|
4
4
|
*
|
|
5
5
|
* `axios.create({ baseURL: getConfigValue('baseUrl') })` reads the value once,
|
|
6
|
-
* when the module is first imported
|
|
6
|
+
* when the module is first imported, which happens the moment anything touches
|
|
7
7
|
* the package barrel, long before an app's startup code can call `setConfig`.
|
|
8
8
|
* The result was a client permanently pinned to `undefined` and a `setConfig`
|
|
9
9
|
* that appeared to do nothing, with no error anywhere: requests just went to a
|
|
@@ -19,7 +19,7 @@ export interface Config {
|
|
|
19
19
|
*/
|
|
20
20
|
country: string;
|
|
21
21
|
/**
|
|
22
|
-
* The app's store identifier
|
|
22
|
+
* The app's store identifier (Android package name / iOS bundle id). Every
|
|
23
23
|
* Webority app already has this in its `appsettings.Compiled.json`, so the
|
|
24
24
|
* version-check module reads it from here rather than crossing the native
|
|
25
25
|
* bridge for a value the app already knows.
|
|
@@ -11,7 +11,7 @@ export interface FormatCurrencyOptions extends Omit<Intl.NumberFormatOptions, "s
|
|
|
11
11
|
minimumFractionDigits?: number | undefined;
|
|
12
12
|
/** Maximum fraction digits. Defaults to the currency's own. */
|
|
13
13
|
maximumFractionDigits?: number | undefined;
|
|
14
|
-
/** Strip the currency symbol
|
|
14
|
+
/** Strip the currency symbol. Useful when the symbol is rendered separately. */
|
|
15
15
|
stripSymbol?: boolean | undefined;
|
|
16
16
|
/**
|
|
17
17
|
* What a missing amount prints. Defaults to the configured placeholder once the app has
|
|
@@ -27,24 +27,24 @@ export declare const startOfDay: (value: DateInput) => Date | null;
|
|
|
27
27
|
*/
|
|
28
28
|
export declare const addDays: (value: DateInput | null | undefined, count: number) => Date | null;
|
|
29
29
|
/**
|
|
30
|
-
* Small dayjs/moment-style token formatter
|
|
30
|
+
* Small dayjs/moment-style token formatter: YYYY/YY, MMMM/MMM/MM/M,
|
|
31
31
|
* DD/D, dddd/ddd, HH/H (24h), hh/h (12h), mm/m, ss/s, A/a (upper/lower AM/PM).
|
|
32
32
|
* Everything else in the pattern (spaces, commas, colons) passes through
|
|
33
33
|
* literally. Hand-rolled rather than a dependency because the date
|
|
34
|
-
* formatting needs are a small, closed token set, not general i18n
|
|
34
|
+
* formatting needs are a small, closed token set, not general i18n; for
|
|
35
35
|
* genuinely locale-aware output, `formatDate`/`formatTime` (Intl-backed, in
|
|
36
36
|
* `./date`) are the ones to reach for; this is for matching an exact
|
|
37
37
|
* existing pattern (a legacy display string, an API's expected shape).
|
|
38
38
|
*
|
|
39
39
|
* `utc: true` reads every field from the UTC calendar/clock instead of the
|
|
40
|
-
* device's local one
|
|
40
|
+
* device's local one. See `formatDateDDMMMYYYY`'s note on why this isn't
|
|
41
41
|
* cosmetic.
|
|
42
42
|
*/
|
|
43
43
|
export declare const formatDatePattern: (value: DateInput, pattern: string, options?: {
|
|
44
44
|
utc?: boolean | undefined;
|
|
45
45
|
}) => string;
|
|
46
46
|
/**
|
|
47
|
-
* `DD MMM, YYYY
|
|
47
|
+
* `DD MMM, YYYY`: zero-padded day, short month, comma, year (e.g.
|
|
48
48
|
* `05 Sep, 2025`). A specific legacy pattern some apps already display,
|
|
49
49
|
* not the recommended convention: `formatDate` (the Intl `style`-based
|
|
50
50
|
* formatter in `./date`) is the one to reach for in new code. This exists so
|
|
@@ -52,7 +52,7 @@ export declare const formatDatePattern: (value: DateInput, pattern: string, opti
|
|
|
52
52
|
* without a visible change.
|
|
53
53
|
*
|
|
54
54
|
* `utc: true` reads the calendar day from the UTC fields instead of the
|
|
55
|
-
* device's local ones
|
|
55
|
+
* device's local ones, matching `dayjs.utc(x).format(...)`, not
|
|
56
56
|
* `dayjs(x).format(...)`. The two disagree whenever local time has crossed a
|
|
57
57
|
* day boundary UTC hasn't yet (or vice versa), so this is not a cosmetic
|
|
58
58
|
* option; pass it only to match a call site that was genuinely UTC-explicit.
|
|
@@ -63,26 +63,26 @@ export declare const formatDateDDMMMYYYY: (value: DateInput, options?: {
|
|
|
63
63
|
/** `YYYY-MM-DD`, in the device's local timezone. */
|
|
64
64
|
export declare const formatDateISO: (value: DateInput) => string;
|
|
65
65
|
/**
|
|
66
|
-
* `hh:mm A` in the device's local timezone
|
|
66
|
+
* `hh:mm A` in the device's local timezone: zero-padded 12-hour clock,
|
|
67
67
|
* uppercase AM/PM (e.g. `09:30 PM`).
|
|
68
68
|
*/
|
|
69
69
|
export declare const formatTime12h: (value: DateInput) => string;
|
|
70
70
|
/**
|
|
71
71
|
* `hh:mm a` (zero-padded 12-hour, lowercase am/pm) of the given instant as
|
|
72
|
-
* seen in `ianaTimeZone` (e.g. `Asia/Kolkata`)
|
|
72
|
+
* seen in `ianaTimeZone` (e.g. `Asia/Kolkata`), not the device's own
|
|
73
73
|
* timezone. Reads the hour/minute/period through `Intl.DateTimeFormat`'s
|
|
74
74
|
* `formatToParts` rather than its assembled string, because the assembled
|
|
75
75
|
* string's spacing before AM/PM varies by JS engine (some insert a narrow
|
|
76
76
|
* no-break space, U+202F, instead of a plain space) and isn't reliably
|
|
77
77
|
* zero-padded either. Throws if `ianaTimeZone` isn't a timezone Intl
|
|
78
|
-
* recognises
|
|
78
|
+
* recognises: the same failure mode as handing dayjs.tz() a bad zone name.
|
|
79
79
|
*/
|
|
80
80
|
export declare const formatTimeInZone: (value: DateInput, ianaTimeZone: string) => string;
|
|
81
81
|
/**
|
|
82
82
|
* Same as {@link formatTimeInZone}, but for a .NET-style Windows timezone ID
|
|
83
83
|
* (e.g. `"India Standard Time"`) rather than an IANA one. .NET's own
|
|
84
84
|
* `TimeZoneInfo` API only knows Windows IDs, so a backend built on it hands
|
|
85
|
-
* these to clients directly
|
|
85
|
+
* these to clients directly. `Intl`, by contrast, only recognises IANA
|
|
86
86
|
* names, so the ID has to be translated before it can be used here. Throws
|
|
87
87
|
* if `windowsTimeZoneId` has no known IANA mapping.
|
|
88
88
|
*/
|
|
@@ -15,7 +15,7 @@ export declare function formatNumber(value: number | null | undefined, fractionD
|
|
|
15
15
|
export declare function formatPercent(value: number | string | null | undefined, options?: FormatPercentOptions): string;
|
|
16
16
|
/**
|
|
17
17
|
* Intl percent output. Pass `asRatio: false` if the input is already on the
|
|
18
|
-
* 0
|
|
18
|
+
* 0 to 100 scale.
|
|
19
19
|
*/
|
|
20
20
|
export declare function formatPercent(value: number | null | undefined, fractionDigits: number | undefined, asRatio?: boolean, locale?: string): string;
|
|
21
21
|
/**
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* Windows zone, generated from CLDR's `windowsZones.xml` (the same
|
|
4
4
|
* upstream source the retired `windows-iana` npm package derived its own
|
|
5
5
|
* table from). Only the `territory="001"` (world-default) row is kept per
|
|
6
|
-
* Windows zone
|
|
6
|
+
* Windows zone. `formatTimeInWindowsZone` only ever reads the first IANA
|
|
7
7
|
* candidate, and CLDR's `001` row is exactly that default candidate, so
|
|
8
8
|
* per-country territory variants (`US`, `CA`, `ZZ`, …) carry no information
|
|
9
9
|
* this table's one caller uses.
|
|
10
10
|
*
|
|
11
11
|
* Regenerate with `node packages/core/scripts/generate-windows-to-iana-table.mjs
|
|
12
12
|
* <path-to-windowsZones.xml>` (CLDR: `common/supplemental/windowsZones.xml` in
|
|
13
|
-
* https://github.com/unicode-org/cldr) whenever CLDR adds/renames a zone
|
|
14
|
-
*
|
|
13
|
+
* https://github.com/unicode-org/cldr) whenever CLDR adds/renames a zone.
|
|
14
|
+
* This is a committed, static table; nothing fetches CLDR at build or test
|
|
15
15
|
* time.
|
|
16
16
|
*/
|
|
17
17
|
export declare const WINDOWS_TO_IANA: Readonly<Record<string, string>>;
|
|
@@ -34,7 +34,7 @@ export interface ExpoLocationLike {
|
|
|
34
34
|
* subscription later. So the adapter mints its own id immediately and stores
|
|
35
35
|
* the subscription against it on arrival. `clearWatch` called during that
|
|
36
36
|
* window records the id as cancelled, and the subscription is removed the
|
|
37
|
-
* moment it lands
|
|
37
|
+
* moment it lands. Without that, a screen that unmounts before the watch
|
|
38
38
|
* starts leaks a live GPS listener for the rest of the session, which is a
|
|
39
39
|
* battery drain nobody would attribute to this code.
|
|
40
40
|
*/
|
|
@@ -28,7 +28,7 @@ export interface TokenRefreshConfig {
|
|
|
28
28
|
headers?: (() => Record<string, string> | Promise<Record<string, string>>) | undefined;
|
|
29
29
|
/**
|
|
30
30
|
* Reads the new tokens from the response body. Defaults to the Webority API's
|
|
31
|
-
* `{ accessToken,
|
|
31
|
+
* `{ accessToken, accessTokenExpiresDateTimeUtc, refreshToken, refreshTokenExpiresDateTimeUtc }`.
|
|
32
32
|
*/
|
|
33
33
|
readTokens?: ((data: unknown) => TokenRefreshResult) | undefined;
|
|
34
34
|
}
|
|
@@ -38,7 +38,7 @@ declare const openAppSettings: () => Promise<boolean>;
|
|
|
38
38
|
/**
|
|
39
39
|
* Cross-platform permissions wrapper. Maps an abstract `PermissionKind`
|
|
40
40
|
* (camera, photos, location, notifications, …) to whichever Expo adapter an
|
|
41
|
-
* app has registered by importing that kind's entry point
|
|
41
|
+
* app has registered by importing that kind's entry point: expo-camera,
|
|
42
42
|
* expo-image-picker, expo-location, expo-contacts, expo-calendar,
|
|
43
43
|
* expo-notifications, expo-media-library. An app imports only the entry
|
|
44
44
|
* points for the kinds it actually asks for.
|
|
@@ -12,14 +12,14 @@ export interface SmsRetrieverBackend {
|
|
|
12
12
|
/** Test-only injection point. Pass `null` to reset to the native module. */
|
|
13
13
|
export declare const setSmsRetrieverImplementation: (impl: SmsRetrieverBackend | null) => void;
|
|
14
14
|
/**
|
|
15
|
-
* The Play Services SMS Retriever API
|
|
15
|
+
* The Play Services SMS Retriever API, which auto-reads an incoming OTP SMS with
|
|
16
16
|
* no SMS permission, matched by an 11-character app-signature hash
|
|
17
17
|
* (`getAppHash`) the backend appends to the message. Android only; every
|
|
18
18
|
* method is safe to call on iOS and resolves/reports unavailable rather than
|
|
19
19
|
* throwing, so a caller doesn't need a platform check at every call site.
|
|
20
20
|
* A native listener that fails to start is reported through `onError` as `UNKNOWN_ERROR`; without an `onError` it throws.
|
|
21
21
|
*
|
|
22
|
-
* OTP extraction is left to the caller
|
|
22
|
+
* OTP extraction is left to the caller: `onMessage` receives the raw SMS
|
|
23
23
|
* text, since the expected OTP format (digit count, prefix) is a backend
|
|
24
24
|
* concern, not this module's.
|
|
25
25
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TurboModule } from "react-native";
|
|
2
2
|
/**
|
|
3
|
-
* Android-only
|
|
3
|
+
* Android-only. The Play Services SMS Retriever API has no iOS equivalent.
|
|
4
4
|
* The JS wrapper in `smsRetriever/index.ts` never touches this module on
|
|
5
5
|
* iOS, so `getEnforcing` only ever runs on Android, where autolinking has
|
|
6
6
|
* registered `SmsRetrieverPackage`.
|
|
@@ -21,7 +21,7 @@ export interface SqliteDriver {
|
|
|
21
21
|
}) => Promise<SqliteDatabase>;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Test/showcase-only injection point
|
|
24
|
+
* Test/showcase-only injection point; see the module header. Not a way to
|
|
25
25
|
* pick an alternate real driver; `@webority/mobile-core` always
|
|
26
26
|
* resolves expo-sqlite when nothing is injected. Pass `null` to clear it.
|
|
27
27
|
*/
|
|
@@ -14,7 +14,7 @@ interface AsyncStorageLike {
|
|
|
14
14
|
* pairs, and `setMany` takes a Record where `multiSet` took pairs. The v1
|
|
15
15
|
* names are still what `expo-sqlite/kv-store` and AsyncStorage 2 expose.
|
|
16
16
|
*
|
|
17
|
-
* Declaring only one set is not a compile error and not a runtime error
|
|
17
|
+
* Declaring only one set is not a compile error and not a runtime error; it
|
|
18
18
|
* silently falls through to the per-key loop below. Apps pin
|
|
19
19
|
* AsyncStorage 3, so recognising only the v1 names put every consumer on N
|
|
20
20
|
* round-trips per batch with nothing to notice.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
export declare const isNonEmpty: (value: unknown) => boolean;
|
|
9
9
|
export declare const isEmail: (value: unknown) => boolean;
|
|
10
10
|
/**
|
|
11
|
-
* Generic phone validator: 7
|
|
11
|
+
* Generic phone validator: 7 to 15 digits, optional `+` prefix.
|
|
12
12
|
* Use `isIndianMobile` from `@webority/mobile-core/india` when you specifically need an Indian mobile number.
|
|
13
13
|
*/
|
|
14
14
|
export declare const isPhone: (value: unknown) => boolean;
|
|
@@ -2,7 +2,7 @@ import { type Environment } from "../config";
|
|
|
2
2
|
import { type DeviceInfoLike } from "./appBuild";
|
|
3
3
|
/**
|
|
4
4
|
* Supply the app identity from a native module instead of config.
|
|
5
|
-
* Prefer `setConfig({ appId, appBuild })
|
|
5
|
+
* Prefer `setConfig({ appId, appBuild })`. It needs no native dependency.
|
|
6
6
|
* Pass `null` to clear.
|
|
7
7
|
*/
|
|
8
8
|
export declare const setDeviceInfoImplementation: (impl: DeviceInfoLike | null) => void;
|
|
@@ -3,7 +3,7 @@ import type { AxiosInstance } from "axios";
|
|
|
3
3
|
* Resolves `baseURL` PER REQUEST rather than at module evaluation.
|
|
4
4
|
*
|
|
5
5
|
* `axios.create({ baseURL: getConfigValue('baseUrl') })` reads the value once,
|
|
6
|
-
* when the module is first imported
|
|
6
|
+
* when the module is first imported, which happens the moment anything touches
|
|
7
7
|
* the package barrel, long before an app's startup code can call `setConfig`.
|
|
8
8
|
* The result was a client permanently pinned to `undefined` and a `setConfig`
|
|
9
9
|
* that appeared to do nothing, with no error anywhere: requests just went to a
|
|
@@ -19,7 +19,7 @@ export interface Config {
|
|
|
19
19
|
*/
|
|
20
20
|
country: string;
|
|
21
21
|
/**
|
|
22
|
-
* The app's store identifier
|
|
22
|
+
* The app's store identifier (Android package name / iOS bundle id). Every
|
|
23
23
|
* Webority app already has this in its `appsettings.Compiled.json`, so the
|
|
24
24
|
* version-check module reads it from here rather than crossing the native
|
|
25
25
|
* bridge for a value the app already knows.
|
|
@@ -11,7 +11,7 @@ export interface FormatCurrencyOptions extends Omit<Intl.NumberFormatOptions, "s
|
|
|
11
11
|
minimumFractionDigits?: number | undefined;
|
|
12
12
|
/** Maximum fraction digits. Defaults to the currency's own. */
|
|
13
13
|
maximumFractionDigits?: number | undefined;
|
|
14
|
-
/** Strip the currency symbol
|
|
14
|
+
/** Strip the currency symbol. Useful when the symbol is rendered separately. */
|
|
15
15
|
stripSymbol?: boolean | undefined;
|
|
16
16
|
/**
|
|
17
17
|
* What a missing amount prints. Defaults to the configured placeholder once the app has
|
|
@@ -27,24 +27,24 @@ export declare const startOfDay: (value: DateInput) => Date | null;
|
|
|
27
27
|
*/
|
|
28
28
|
export declare const addDays: (value: DateInput | null | undefined, count: number) => Date | null;
|
|
29
29
|
/**
|
|
30
|
-
* Small dayjs/moment-style token formatter
|
|
30
|
+
* Small dayjs/moment-style token formatter: YYYY/YY, MMMM/MMM/MM/M,
|
|
31
31
|
* DD/D, dddd/ddd, HH/H (24h), hh/h (12h), mm/m, ss/s, A/a (upper/lower AM/PM).
|
|
32
32
|
* Everything else in the pattern (spaces, commas, colons) passes through
|
|
33
33
|
* literally. Hand-rolled rather than a dependency because the date
|
|
34
|
-
* formatting needs are a small, closed token set, not general i18n
|
|
34
|
+
* formatting needs are a small, closed token set, not general i18n; for
|
|
35
35
|
* genuinely locale-aware output, `formatDate`/`formatTime` (Intl-backed, in
|
|
36
36
|
* `./date`) are the ones to reach for; this is for matching an exact
|
|
37
37
|
* existing pattern (a legacy display string, an API's expected shape).
|
|
38
38
|
*
|
|
39
39
|
* `utc: true` reads every field from the UTC calendar/clock instead of the
|
|
40
|
-
* device's local one
|
|
40
|
+
* device's local one. See `formatDateDDMMMYYYY`'s note on why this isn't
|
|
41
41
|
* cosmetic.
|
|
42
42
|
*/
|
|
43
43
|
export declare const formatDatePattern: (value: DateInput, pattern: string, options?: {
|
|
44
44
|
utc?: boolean | undefined;
|
|
45
45
|
}) => string;
|
|
46
46
|
/**
|
|
47
|
-
* `DD MMM, YYYY
|
|
47
|
+
* `DD MMM, YYYY`: zero-padded day, short month, comma, year (e.g.
|
|
48
48
|
* `05 Sep, 2025`). A specific legacy pattern some apps already display,
|
|
49
49
|
* not the recommended convention: `formatDate` (the Intl `style`-based
|
|
50
50
|
* formatter in `./date`) is the one to reach for in new code. This exists so
|
|
@@ -52,7 +52,7 @@ export declare const formatDatePattern: (value: DateInput, pattern: string, opti
|
|
|
52
52
|
* without a visible change.
|
|
53
53
|
*
|
|
54
54
|
* `utc: true` reads the calendar day from the UTC fields instead of the
|
|
55
|
-
* device's local ones
|
|
55
|
+
* device's local ones, matching `dayjs.utc(x).format(...)`, not
|
|
56
56
|
* `dayjs(x).format(...)`. The two disagree whenever local time has crossed a
|
|
57
57
|
* day boundary UTC hasn't yet (or vice versa), so this is not a cosmetic
|
|
58
58
|
* option; pass it only to match a call site that was genuinely UTC-explicit.
|
|
@@ -63,26 +63,26 @@ export declare const formatDateDDMMMYYYY: (value: DateInput, options?: {
|
|
|
63
63
|
/** `YYYY-MM-DD`, in the device's local timezone. */
|
|
64
64
|
export declare const formatDateISO: (value: DateInput) => string;
|
|
65
65
|
/**
|
|
66
|
-
* `hh:mm A` in the device's local timezone
|
|
66
|
+
* `hh:mm A` in the device's local timezone: zero-padded 12-hour clock,
|
|
67
67
|
* uppercase AM/PM (e.g. `09:30 PM`).
|
|
68
68
|
*/
|
|
69
69
|
export declare const formatTime12h: (value: DateInput) => string;
|
|
70
70
|
/**
|
|
71
71
|
* `hh:mm a` (zero-padded 12-hour, lowercase am/pm) of the given instant as
|
|
72
|
-
* seen in `ianaTimeZone` (e.g. `Asia/Kolkata`)
|
|
72
|
+
* seen in `ianaTimeZone` (e.g. `Asia/Kolkata`), not the device's own
|
|
73
73
|
* timezone. Reads the hour/minute/period through `Intl.DateTimeFormat`'s
|
|
74
74
|
* `formatToParts` rather than its assembled string, because the assembled
|
|
75
75
|
* string's spacing before AM/PM varies by JS engine (some insert a narrow
|
|
76
76
|
* no-break space, U+202F, instead of a plain space) and isn't reliably
|
|
77
77
|
* zero-padded either. Throws if `ianaTimeZone` isn't a timezone Intl
|
|
78
|
-
* recognises
|
|
78
|
+
* recognises: the same failure mode as handing dayjs.tz() a bad zone name.
|
|
79
79
|
*/
|
|
80
80
|
export declare const formatTimeInZone: (value: DateInput, ianaTimeZone: string) => string;
|
|
81
81
|
/**
|
|
82
82
|
* Same as {@link formatTimeInZone}, but for a .NET-style Windows timezone ID
|
|
83
83
|
* (e.g. `"India Standard Time"`) rather than an IANA one. .NET's own
|
|
84
84
|
* `TimeZoneInfo` API only knows Windows IDs, so a backend built on it hands
|
|
85
|
-
* these to clients directly
|
|
85
|
+
* these to clients directly. `Intl`, by contrast, only recognises IANA
|
|
86
86
|
* names, so the ID has to be translated before it can be used here. Throws
|
|
87
87
|
* if `windowsTimeZoneId` has no known IANA mapping.
|
|
88
88
|
*/
|
|
@@ -15,7 +15,7 @@ export declare function formatNumber(value: number | null | undefined, fractionD
|
|
|
15
15
|
export declare function formatPercent(value: number | string | null | undefined, options?: FormatPercentOptions): string;
|
|
16
16
|
/**
|
|
17
17
|
* Intl percent output. Pass `asRatio: false` if the input is already on the
|
|
18
|
-
* 0
|
|
18
|
+
* 0 to 100 scale.
|
|
19
19
|
*/
|
|
20
20
|
export declare function formatPercent(value: number | null | undefined, fractionDigits: number | undefined, asRatio?: boolean, locale?: string): string;
|
|
21
21
|
/**
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
* Windows zone, generated from CLDR's `windowsZones.xml` (the same
|
|
4
4
|
* upstream source the retired `windows-iana` npm package derived its own
|
|
5
5
|
* table from). Only the `territory="001"` (world-default) row is kept per
|
|
6
|
-
* Windows zone
|
|
6
|
+
* Windows zone. `formatTimeInWindowsZone` only ever reads the first IANA
|
|
7
7
|
* candidate, and CLDR's `001` row is exactly that default candidate, so
|
|
8
8
|
* per-country territory variants (`US`, `CA`, `ZZ`, …) carry no information
|
|
9
9
|
* this table's one caller uses.
|
|
10
10
|
*
|
|
11
11
|
* Regenerate with `node packages/core/scripts/generate-windows-to-iana-table.mjs
|
|
12
12
|
* <path-to-windowsZones.xml>` (CLDR: `common/supplemental/windowsZones.xml` in
|
|
13
|
-
* https://github.com/unicode-org/cldr) whenever CLDR adds/renames a zone
|
|
14
|
-
*
|
|
13
|
+
* https://github.com/unicode-org/cldr) whenever CLDR adds/renames a zone.
|
|
14
|
+
* This is a committed, static table; nothing fetches CLDR at build or test
|
|
15
15
|
* time.
|
|
16
16
|
*/
|
|
17
17
|
export declare const WINDOWS_TO_IANA: Readonly<Record<string, string>>;
|
|
@@ -34,7 +34,7 @@ export interface ExpoLocationLike {
|
|
|
34
34
|
* subscription later. So the adapter mints its own id immediately and stores
|
|
35
35
|
* the subscription against it on arrival. `clearWatch` called during that
|
|
36
36
|
* window records the id as cancelled, and the subscription is removed the
|
|
37
|
-
* moment it lands
|
|
37
|
+
* moment it lands. Without that, a screen that unmounts before the watch
|
|
38
38
|
* starts leaks a live GPS listener for the rest of the session, which is a
|
|
39
39
|
* battery drain nobody would attribute to this code.
|
|
40
40
|
*/
|
|
@@ -28,7 +28,7 @@ export interface TokenRefreshConfig {
|
|
|
28
28
|
headers?: (() => Record<string, string> | Promise<Record<string, string>>) | undefined;
|
|
29
29
|
/**
|
|
30
30
|
* Reads the new tokens from the response body. Defaults to the Webority API's
|
|
31
|
-
* `{ accessToken,
|
|
31
|
+
* `{ accessToken, accessTokenExpiresDateTimeUtc, refreshToken, refreshTokenExpiresDateTimeUtc }`.
|
|
32
32
|
*/
|
|
33
33
|
readTokens?: ((data: unknown) => TokenRefreshResult) | undefined;
|
|
34
34
|
}
|
|
@@ -38,7 +38,7 @@ declare const openAppSettings: () => Promise<boolean>;
|
|
|
38
38
|
/**
|
|
39
39
|
* Cross-platform permissions wrapper. Maps an abstract `PermissionKind`
|
|
40
40
|
* (camera, photos, location, notifications, …) to whichever Expo adapter an
|
|
41
|
-
* app has registered by importing that kind's entry point
|
|
41
|
+
* app has registered by importing that kind's entry point: expo-camera,
|
|
42
42
|
* expo-image-picker, expo-location, expo-contacts, expo-calendar,
|
|
43
43
|
* expo-notifications, expo-media-library. An app imports only the entry
|
|
44
44
|
* points for the kinds it actually asks for.
|
|
@@ -12,14 +12,14 @@ export interface SmsRetrieverBackend {
|
|
|
12
12
|
/** Test-only injection point. Pass `null` to reset to the native module. */
|
|
13
13
|
export declare const setSmsRetrieverImplementation: (impl: SmsRetrieverBackend | null) => void;
|
|
14
14
|
/**
|
|
15
|
-
* The Play Services SMS Retriever API
|
|
15
|
+
* The Play Services SMS Retriever API, which auto-reads an incoming OTP SMS with
|
|
16
16
|
* no SMS permission, matched by an 11-character app-signature hash
|
|
17
17
|
* (`getAppHash`) the backend appends to the message. Android only; every
|
|
18
18
|
* method is safe to call on iOS and resolves/reports unavailable rather than
|
|
19
19
|
* throwing, so a caller doesn't need a platform check at every call site.
|
|
20
20
|
* A native listener that fails to start is reported through `onError` as `UNKNOWN_ERROR`; without an `onError` it throws.
|
|
21
21
|
*
|
|
22
|
-
* OTP extraction is left to the caller
|
|
22
|
+
* OTP extraction is left to the caller: `onMessage` receives the raw SMS
|
|
23
23
|
* text, since the expected OTP format (digit count, prefix) is a backend
|
|
24
24
|
* concern, not this module's.
|
|
25
25
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { TurboModule } from "react-native";
|
|
2
2
|
/**
|
|
3
|
-
* Android-only
|
|
3
|
+
* Android-only. The Play Services SMS Retriever API has no iOS equivalent.
|
|
4
4
|
* The JS wrapper in `smsRetriever/index.ts` never touches this module on
|
|
5
5
|
* iOS, so `getEnforcing` only ever runs on Android, where autolinking has
|
|
6
6
|
* registered `SmsRetrieverPackage`.
|
|
@@ -21,7 +21,7 @@ export interface SqliteDriver {
|
|
|
21
21
|
}) => Promise<SqliteDatabase>;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
-
* Test/showcase-only injection point
|
|
24
|
+
* Test/showcase-only injection point; see the module header. Not a way to
|
|
25
25
|
* pick an alternate real driver; `@webority/mobile-core` always
|
|
26
26
|
* resolves expo-sqlite when nothing is injected. Pass `null` to clear it.
|
|
27
27
|
*/
|
|
@@ -14,7 +14,7 @@ interface AsyncStorageLike {
|
|
|
14
14
|
* pairs, and `setMany` takes a Record where `multiSet` took pairs. The v1
|
|
15
15
|
* names are still what `expo-sqlite/kv-store` and AsyncStorage 2 expose.
|
|
16
16
|
*
|
|
17
|
-
* Declaring only one set is not a compile error and not a runtime error
|
|
17
|
+
* Declaring only one set is not a compile error and not a runtime error; it
|
|
18
18
|
* silently falls through to the per-key loop below. Apps pin
|
|
19
19
|
* AsyncStorage 3, so recognising only the v1 names put every consumer on N
|
|
20
20
|
* round-trips per batch with nothing to notice.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
export declare const isNonEmpty: (value: unknown) => boolean;
|
|
9
9
|
export declare const isEmail: (value: unknown) => boolean;
|
|
10
10
|
/**
|
|
11
|
-
* Generic phone validator: 7
|
|
11
|
+
* Generic phone validator: 7 to 15 digits, optional `+` prefix.
|
|
12
12
|
* Use `isIndianMobile` from `@webority/mobile-core/india` when you specifically need an Indian mobile number.
|
|
13
13
|
*/
|
|
14
14
|
export declare const isPhone: (value: unknown) => boolean;
|
|
@@ -2,7 +2,7 @@ import { type Environment } from "../config/index.js";
|
|
|
2
2
|
import { type DeviceInfoLike } from "./appBuild.js";
|
|
3
3
|
/**
|
|
4
4
|
* Supply the app identity from a native module instead of config.
|
|
5
|
-
* Prefer `setConfig({ appId, appBuild })
|
|
5
|
+
* Prefer `setConfig({ appId, appBuild })`. It needs no native dependency.
|
|
6
6
|
* Pass `null` to clear.
|
|
7
7
|
*/
|
|
8
8
|
export declare const setDeviceInfoImplementation: (impl: DeviceInfoLike | null) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webority/mobile-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.164.0",
|
|
4
4
|
"description": "Platform layer for Webority React Native apps: HTTP clients, auth/token storage, config, logging, formatters, validators, network status, permissions, storage, version checks and over-the-air updates. No UI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -399,7 +399,7 @@
|
|
|
399
399
|
}
|
|
400
400
|
},
|
|
401
401
|
"dependencies": {
|
|
402
|
-
"@webority/api-contract": "0.
|
|
402
|
+
"@webority/api-contract": "0.164.0",
|
|
403
403
|
"axios": "^1.19.0",
|
|
404
404
|
"libphonenumber-js": "^1.12.41"
|
|
405
405
|
},
|
|
@@ -2,7 +2,7 @@ import type { TurboModule } from "react-native";
|
|
|
2
2
|
import { TurboModuleRegistry } from "react-native";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Android-only
|
|
5
|
+
* Android-only. The Play Services SMS Retriever API has no iOS equivalent.
|
|
6
6
|
* The JS wrapper in `smsRetriever/index.ts` never touches this module on
|
|
7
7
|
* iOS, so `getEnforcing` only ever runs on Android, where autolinking has
|
|
8
8
|
* registered `SmsRetrieverPackage`.
|