@webority/mobile-core 0.0.29 → 0.1.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.
Files changed (139) hide show
  1. package/lib/commonjs/api/baseUrl.js +1 -34
  2. package/lib/commonjs/api/curl.js +1 -109
  3. package/lib/commonjs/api/multipart.js +1 -21
  4. package/lib/commonjs/api/publicClient.js +1 -79
  5. package/lib/commonjs/api/responseBodyText.js +1 -0
  6. package/lib/commonjs/api/retry.js +1 -91
  7. package/lib/commonjs/api/tokenRefresh.js +1 -205
  8. package/lib/commonjs/api/userClient.js +1 -265
  9. package/lib/commonjs/auth/authStore.js +1 -265
  10. package/lib/commonjs/auth/index.js +1 -44
  11. package/lib/commonjs/auth/jwt.js +1 -112
  12. package/lib/commonjs/config/index.js +1 -72
  13. package/lib/commonjs/deepLink/index.js +1 -286
  14. package/lib/commonjs/download/adapters/expoFs.js +1 -69
  15. package/lib/commonjs/download/adapters/shared.js +1 -13
  16. package/lib/commonjs/download/index.js +1 -250
  17. package/lib/commonjs/formatters/currency.js +1 -70
  18. package/lib/commonjs/formatters/date.js +1 -167
  19. package/lib/commonjs/formatters/dateMath.js +1 -311
  20. package/lib/commonjs/formatters/index.js +1 -246
  21. package/lib/commonjs/formatters/initials.js +1 -32
  22. package/lib/commonjs/formatters/intlCache.js +1 -37
  23. package/lib/commonjs/formatters/number.js +1 -89
  24. package/lib/commonjs/formatters/phone.js +1 -369
  25. package/lib/commonjs/formatters/windowsToIanaTable.js +1 -164
  26. package/lib/commonjs/geolocation/adapters/expoLocation.js +1 -126
  27. package/lib/commonjs/geolocation/index.js +1 -355
  28. package/lib/commonjs/index.js +1 -644
  29. package/lib/commonjs/initSDK.js +1 -66
  30. package/lib/commonjs/initUserAuth.js +1 -37
  31. package/lib/commonjs/logger/crashlytics.js +1 -0
  32. package/lib/commonjs/logger/index.js +1 -301
  33. package/lib/commonjs/logger/redact.js +1 -50
  34. package/lib/commonjs/network/index.js +1 -31
  35. package/lib/commonjs/network/networkStatus.js +1 -171
  36. package/lib/commonjs/permissions/calendar.js +1 -14
  37. package/lib/commonjs/permissions/camera.js +1 -14
  38. package/lib/commonjs/permissions/contacts.js +1 -10
  39. package/lib/commonjs/permissions/index.js +1 -133
  40. package/lib/commonjs/permissions/location.js +1 -14
  41. package/lib/commonjs/permissions/mediaLibrary.js +1 -10
  42. package/lib/commonjs/permissions/notifications.js +1 -10
  43. package/lib/commonjs/permissions/photos.js +1 -14
  44. package/lib/commonjs/phone/countries.js +1 -265
  45. package/lib/commonjs/push/index.js +1 -61
  46. package/lib/commonjs/push/push.js +1 -468
  47. package/lib/commonjs/push/status.js +1 -0
  48. package/lib/commonjs/push/task.js +1 -43
  49. package/lib/commonjs/secureScreen/index.js +1 -0
  50. package/lib/commonjs/share/index.js +1 -70
  51. package/lib/commonjs/smsRetriever/index.js +1 -91
  52. package/lib/commonjs/specs/NativeSmsRetriever.js +1 -15
  53. package/lib/commonjs/sqlite/adapters/expo.js +1 -53
  54. package/lib/commonjs/sqlite/index.js +1 -604
  55. package/lib/commonjs/storage/index.js +1 -214
  56. package/lib/commonjs/types/axios.js +1 -4
  57. package/lib/commonjs/types/globals.d.js +1 -6
  58. package/lib/commonjs/utils/base64.js +1 -24
  59. package/lib/commonjs/utils/imageCompression.js +1 -389
  60. package/lib/commonjs/utils/index.js +1 -19
  61. package/lib/commonjs/validators/index.js +1 -227
  62. package/lib/commonjs/versionCheck/index.js +1 -419
  63. package/lib/module/api/baseUrl.js +1 -30
  64. package/lib/module/api/curl.js +1 -104
  65. package/lib/module/api/multipart.js +1 -16
  66. package/lib/module/api/publicClient.js +1 -75
  67. package/lib/module/api/responseBodyText.js +1 -0
  68. package/lib/module/api/retry.js +1 -85
  69. package/lib/module/api/tokenRefresh.js +1 -192
  70. package/lib/module/api/userClient.js +1 -243
  71. package/lib/module/auth/authStore.js +1 -257
  72. package/lib/module/auth/index.js +1 -5
  73. package/lib/module/auth/jwt.js +1 -106
  74. package/lib/module/config/index.js +1 -64
  75. package/lib/module/deepLink/index.js +1 -280
  76. package/lib/module/download/adapters/expoFs.js +1 -64
  77. package/lib/module/download/adapters/shared.js +1 -8
  78. package/lib/module/download/index.js +1 -242
  79. package/lib/module/formatters/currency.js +1 -65
  80. package/lib/module/formatters/date.js +1 -159
  81. package/lib/module/formatters/dateMath.js +1 -295
  82. package/lib/module/formatters/index.js +1 -9
  83. package/lib/module/formatters/initials.js +1 -27
  84. package/lib/module/formatters/intlCache.js +1 -30
  85. package/lib/module/formatters/number.js +1 -82
  86. package/lib/module/formatters/phone.js +1 -302
  87. package/lib/module/formatters/windowsToIanaTable.js +1 -160
  88. package/lib/module/geolocation/adapters/expoLocation.js +1 -121
  89. package/lib/module/geolocation/index.js +1 -347
  90. package/lib/module/index.js +1 -57
  91. package/lib/module/initSDK.js +1 -61
  92. package/lib/module/initUserAuth.js +1 -33
  93. package/lib/module/logger/crashlytics.js +1 -0
  94. package/lib/module/logger/index.js +1 -295
  95. package/lib/module/logger/redact.js +1 -44
  96. package/lib/module/network/index.js +1 -4
  97. package/lib/module/network/networkStatus.js +1 -161
  98. package/lib/module/permissions/calendar.js +1 -15
  99. package/lib/module/permissions/camera.js +1 -15
  100. package/lib/module/permissions/contacts.js +1 -11
  101. package/lib/module/permissions/index.js +1 -128
  102. package/lib/module/permissions/location.js +1 -15
  103. package/lib/module/permissions/mediaLibrary.js +1 -11
  104. package/lib/module/permissions/notifications.js +1 -11
  105. package/lib/module/permissions/photos.js +1 -15
  106. package/lib/module/phone/countries.js +1 -261
  107. package/lib/module/push/index.js +1 -4
  108. package/lib/module/push/push.js +1 -452
  109. package/lib/module/push/status.js +1 -0
  110. package/lib/module/push/task.js +1 -38
  111. package/lib/module/secureScreen/index.js +1 -0
  112. package/lib/module/share/index.js +1 -64
  113. package/lib/module/smsRetriever/index.js +1 -86
  114. package/lib/module/specs/NativeSmsRetriever.js +1 -13
  115. package/lib/module/sqlite/adapters/expo.js +1 -48
  116. package/lib/module/sqlite/index.js +1 -594
  117. package/lib/module/storage/index.js +1 -208
  118. package/lib/module/types/axios.js +1 -4
  119. package/lib/module/types/globals.d.js +1 -10
  120. package/lib/module/utils/base64.js +1 -19
  121. package/lib/module/utils/imageCompression.js +1 -383
  122. package/lib/module/utils/index.js +1 -4
  123. package/lib/module/validators/index.js +1 -205
  124. package/lib/module/versionCheck/index.js +1 -413
  125. package/lib/typescript/commonjs/api/responseBodyText.d.ts +6 -0
  126. package/lib/typescript/commonjs/index.d.ts +5 -0
  127. package/lib/typescript/commonjs/logger/crashlytics.d.ts +31 -0
  128. package/lib/typescript/commonjs/push/index.d.ts +3 -1
  129. package/lib/typescript/commonjs/push/push.d.ts +1 -1
  130. package/lib/typescript/commonjs/push/status.d.ts +9 -0
  131. package/lib/typescript/commonjs/secureScreen/index.d.ts +25 -0
  132. package/lib/typescript/module/api/responseBodyText.d.ts +6 -0
  133. package/lib/typescript/module/index.d.ts +5 -0
  134. package/lib/typescript/module/logger/crashlytics.d.ts +31 -0
  135. package/lib/typescript/module/push/index.d.ts +3 -1
  136. package/lib/typescript/module/push/push.d.ts +1 -1
  137. package/lib/typescript/module/push/status.d.ts +9 -0
  138. package/lib/typescript/module/secureScreen/index.d.ts +25 -0
  139. package/package.json +23 -4
@@ -1,112 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isJWTExpired = exports.getJWTExpiry = exports.decodeJWT = void 0;
7
- var _index = require("../logger/index.js");
8
- /**
9
- * Standard claims plus arbitrary keys.
10
- * `sub`, `exp`, `iat`, `nbf` follow RFC 7519 conventions.
11
- */
12
-
13
- const base64UrlToBase64 = input => {
14
- const padded = input + '='.repeat((4 - input.length % 4) % 4);
15
- return padded.replace(/-/g, '+').replace(/_/g, '/');
16
- };
17
- const BASE64_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
18
-
19
- /**
20
- * Pure-JS base64, used only when the runtime has no `atob`.
21
- *
22
- * This used to be `require('buffer')`. That was a latent bundling failure for
23
- * every consumer: `buffer` is a Node builtin that React Native does not
24
- * provide, it was never declared as a dependency, and Metro resolves requires
25
- * STATICALLY — so sitting inside an unreached fallback branch did not save it.
26
- * The app still failed to bundle, with an error naming this file. It only went
27
- * unnoticed because the repo's own checks never bundle for a device.
28
- *
29
- * Decoding four base64 characters yields three bytes; the padding tells us how
30
- * many of those three are real.
31
- */
32
- const decodeBase64Fallback = input => {
33
- let out = '';
34
- for (let i = 0; i < input.length; i += 4) {
35
- const chunk = [0, 1, 2, 3].map(offset => BASE64_ALPHABET.indexOf(input[i + offset] ?? '='));
36
- const bits = Math.max(chunk[0], 0) << 18 | Math.max(chunk[1], 0) << 12 | Math.max(chunk[2], 0) << 6 | Math.max(chunk[3], 0);
37
- out += String.fromCharCode(bits >> 16 & 0xff);
38
- if (chunk[2] !== -1) {
39
- out += String.fromCharCode(bits >> 8 & 0xff);
40
- }
41
- if (chunk[3] !== -1) {
42
- out += String.fromCharCode(bits & 0xff);
43
- }
44
- }
45
- return out;
46
- };
47
- const decodeBase64 = input =>
48
- // Every RN runtime the library supports has `atob` (Hermes 0.71+), so the
49
- // fallback is a safety net rather than a path anyone is expected to take.
50
- typeof atob === 'function' ? atob(input) : decodeBase64Fallback(input);
51
- const utf8FromBinary = binary => {
52
- // Convert percent-encoded UTF-8 sequence so multi-byte chars survive.
53
- try {
54
- return decodeURIComponent(binary.split('').map(c => '%' + c.charCodeAt(0).toString(16).padStart(2, '0')).join(''));
55
- } catch {
56
- return binary;
57
- }
58
- };
59
-
60
- /**
61
- * Decode a JWT's payload claims. Does **not** verify the signature.
62
- *
63
- * @returns claims object on success, `null` if the token is malformed.
64
- */
65
- const decodeJWT = token => {
66
- if (!token || typeof token !== 'string') {
67
- return null;
68
- }
69
- const parts = token.split('.');
70
- if (parts.length !== 3) {
71
- _index.Logger.warn('[jwt] decodeJWT: token is not a valid JWT (expected 3 segments)');
72
- return null;
73
- }
74
- try {
75
- const payload = parts[1];
76
- const json = utf8FromBinary(decodeBase64(base64UrlToBase64(payload)));
77
- return JSON.parse(json);
78
- } catch (error) {
79
- _index.Logger.warn('[jwt] decodeJWT failed to parse payload', error);
80
- return null;
81
- }
82
- };
83
-
84
- /**
85
- * Returns true when the token is expired (or unparseable / missing `exp`).
86
- *
87
- * @param token JWT string
88
- * @param leewaySeconds amount of clock-skew tolerance to apply (default 30s)
89
- */
90
- exports.decodeJWT = decodeJWT;
91
- const isJWTExpired = (token, leewaySeconds = 30) => {
92
- const claims = decodeJWT(token);
93
- if (!claims || typeof claims.exp !== 'number') {
94
- return true;
95
- }
96
- const nowSeconds = Math.floor(Date.now() / 1000);
97
- return claims.exp <= nowSeconds + leewaySeconds;
98
- };
99
-
100
- /**
101
- * Returns the token's expiry as a Date, or `null` when no `exp` claim exists.
102
- */
103
- exports.isJWTExpired = isJWTExpired;
104
- const getJWTExpiry = token => {
105
- const claims = decodeJWT(token);
106
- if (!claims || typeof claims.exp !== 'number') {
107
- return null;
108
- }
109
- return new Date(claims.exp * 1000);
110
- };
111
- exports.getJWTExpiry = getJWTExpiry;
112
- //# sourceMappingURL=jwt.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.isJWTExpired=exports.getJWTExpiry=exports.decodeJWT=void 0;var _index=require("../logger/index.js");const base64UrlToBase64=e=>(e+"=".repeat((4-e.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),BASE64_ALPHABET="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",decodeBase64Fallback=e=>{let t="";for(let r=0;r<e.length;r+=4){const o=[0,1,2,3].map(t=>BASE64_ALPHABET.indexOf(e[r+t]??"=")),n=Math.max(o[0],0)<<18|Math.max(o[1],0)<<12|Math.max(o[2],0)<<6|Math.max(o[3],0);t+=String.fromCharCode(n>>16&255),-1!==o[2]&&(t+=String.fromCharCode(n>>8&255)),-1!==o[3]&&(t+=String.fromCharCode(255&n))}return t},decodeBase64=e=>"function"==typeof atob?atob(e):decodeBase64Fallback(e),utf8FromBinary=e=>{try{return decodeURIComponent(e.split("").map(e=>"%"+e.charCodeAt(0).toString(16).padStart(2,"0")).join(""))}catch{return e}},decodeJWT=e=>{if(!e||"string"!=typeof e)return null;const t=e.split(".");if(3!==t.length)return _index.Logger.warn("[jwt] decodeJWT: token is not a valid JWT (expected 3 segments)"),null;try{const e=t[1],r=utf8FromBinary(decodeBase64(base64UrlToBase64(e)));return JSON.parse(r)}catch(e){return _index.Logger.warn("[jwt] decodeJWT failed to parse payload",e),null}};exports.decodeJWT=decodeJWT;const isJWTExpired=(e,t=30)=>{const r=decodeJWT(e);if(!r||"number"!=typeof r.exp)return!0;const o=Math.floor(Date.now()/1e3);return r.exp<=o+t};exports.isJWTExpired=isJWTExpired;const getJWTExpiry=e=>{const t=decodeJWT(e);return t&&"number"==typeof t.exp?new Date(1e3*t.exp):null};exports.getJWTExpiry=getJWTExpiry;
@@ -1,72 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getConfig = exports.DEFAULT_LOG_LEVEL = void 0;
7
- exports.getConfigValue = getConfigValue;
8
- exports.setConfig = exports.resetConfig = void 0;
9
- /**
10
- * Configuration management for Webority packages
11
- * Provides a flexible way to inject configuration without hard dependencies
12
- */
13
-
14
- /**
15
- * Info lines (each token refresh, each unauthorised URL) reach the device log
16
- * and any remote sink, so a release build that sets nothing logs warnings and
17
- * errors only.
18
- */
19
- const DEFAULT_LOG_LEVEL = exports.DEFAULT_LOG_LEVEL = __DEV__ ? 'info' : 'warn';
20
- const DEFAULT_CONFIG = {
21
- baseUrl: null,
22
- loggingEnabled: true,
23
- logLevel: DEFAULT_LOG_LEVEL,
24
- environment: 'Development',
25
- country: 'in',
26
- appId: null,
27
- appVersion: null,
28
- logCurl: false
29
- };
30
- let globalConfig = {
31
- ...DEFAULT_CONFIG
32
- };
33
-
34
- /**
35
- * Set global configuration for all Webority packages
36
- */
37
- const setConfig = config => {
38
- globalConfig = {
39
- ...globalConfig,
40
- ...config
41
- };
42
- };
43
-
44
- /**
45
- * Get current configuration
46
- */
47
- exports.setConfig = setConfig;
48
- const getConfig = () => globalConfig;
49
-
50
- /**
51
- * Get a specific config value with optional fallback.
52
- * If the stored value is `null`, the fallback is returned (when provided).
53
- */
54
- exports.getConfig = getConfig;
55
- function getConfigValue(key, fallback) {
56
- const value = globalConfig[key];
57
- if (value !== null) {
58
- return value;
59
- }
60
- return fallback;
61
- }
62
-
63
- /**
64
- * Reset configuration to defaults
65
- */
66
- const resetConfig = () => {
67
- globalConfig = {
68
- ...DEFAULT_CONFIG
69
- };
70
- };
71
- exports.resetConfig = resetConfig;
72
- //# sourceMappingURL=index.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getConfig=exports.DEFAULT_LOG_LEVEL=void 0,exports.getConfigValue=getConfigValue,exports.setConfig=exports.resetConfig=void 0;const DEFAULT_LOG_LEVEL=exports.DEFAULT_LOG_LEVEL=__DEV__?"info":"warn",DEFAULT_CONFIG={baseUrl:null,loggingEnabled:!0,logLevel:DEFAULT_LOG_LEVEL,environment:"Development",country:"in",appId:null,appVersion:null,logCurl:!1};let globalConfig={...DEFAULT_CONFIG};const setConfig=o=>{globalConfig={...globalConfig,...o}};exports.setConfig=setConfig;const getConfig=()=>globalConfig;function getConfigValue(o,e){const n=globalConfig[o];return null!==n?n:e}exports.getConfig=getConfig;const resetConfig=()=>{globalConfig={...DEFAULT_CONFIG}};exports.resetConfig=resetConfig;
@@ -1,286 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useDeepLink = exports.parseDeepLink = exports.DeepLink = void 0;
7
- var _react = require("react");
8
- var _reactNative = require("react-native");
9
- var _index = require("../logger/index.js");
10
- const PREFIX = '[@webority/mobile-core]';
11
- const decodeSafe = value => {
12
- try {
13
- return decodeURIComponent(value.replace(/\+/g, ' '));
14
- } catch {
15
- return value;
16
- }
17
- };
18
- const parseQuery = raw => {
19
- const out = {};
20
- if (!raw) {
21
- return out;
22
- }
23
- for (const pair of raw.split('&')) {
24
- if (!pair) {
25
- continue;
26
- }
27
- const eq = pair.indexOf('=');
28
- const key = decodeSafe(eq >= 0 ? pair.slice(0, eq) : pair);
29
- if (!key) {
30
- continue;
31
- }
32
- out[key] = eq >= 0 ? decodeSafe(pair.slice(eq + 1)) : '';
33
- }
34
- return out;
35
- };
36
- const trimSlashes = value => value.replace(/^\/+/, '').replace(/\/+$/, '');
37
-
38
- /**
39
- * Parse a deep-link URL. Returns null for anything that is not a usable URL so
40
- * a hostile or truncated link can never throw on the native event path.
41
- */
42
- const parseDeepLink = url => {
43
- if (typeof url !== 'string') {
44
- return null;
45
- }
46
- const trimmed = url.trim();
47
- if (!trimmed || /\s/.test(trimmed)) {
48
- return null;
49
- }
50
- const withoutFragment = trimmed.split('#')[0] ?? '';
51
- const schemeEnd = withoutFragment.indexOf('://');
52
- let scheme = '';
53
- let rest = withoutFragment;
54
- if (schemeEnd >= 0) {
55
- const rawScheme = withoutFragment.slice(0, schemeEnd);
56
- if (!/^[a-zA-Z][a-zA-Z0-9+.-]*$/.test(rawScheme)) {
57
- return null;
58
- }
59
- scheme = rawScheme.toLowerCase();
60
- rest = withoutFragment.slice(schemeEnd + 3);
61
- }
62
- const queryStart = rest.indexOf('?');
63
- const rawPath = queryStart >= 0 ? rest.slice(0, queryStart) : rest;
64
- const query = parseQuery(queryStart >= 0 ? rest.slice(queryStart + 1) : '');
65
- let host = '';
66
- let pathPart = rawPath;
67
- if (scheme === 'http' || scheme === 'https') {
68
- const slash = rawPath.indexOf('/');
69
- host = slash >= 0 ? rawPath.slice(0, slash) : rawPath;
70
- pathPart = slash >= 0 ? rawPath.slice(slash + 1) : '';
71
- }
72
- const path = trimSlashes(pathPart);
73
- const segments = path ? path.split('/').filter(Boolean) : [];
74
- if (scheme && scheme !== 'http' && scheme !== 'https') {
75
- host = segments[0] ?? '';
76
- }
77
- return {
78
- url: trimmed,
79
- scheme,
80
- host,
81
- path,
82
- segments,
83
- query
84
- };
85
- };
86
- exports.parseDeepLink = parseDeepLink;
87
- const matchPattern = (pattern, segments) => {
88
- const patternSegments = trimSlashes(pattern).split('/').filter(Boolean);
89
- if (patternSegments.length !== segments.length) {
90
- return null;
91
- }
92
- const params = {};
93
- for (let i = 0; i < patternSegments.length; i += 1) {
94
- const p = patternSegments[i];
95
- const s = segments[i];
96
- if (p.startsWith(':')) {
97
- const name = p.slice(1);
98
- if (!name) {
99
- return null;
100
- }
101
- params[name] = s;
102
- } else if (p.toLowerCase() !== s.toLowerCase()) {
103
- return null;
104
- }
105
- }
106
- return params;
107
- };
108
- const matchRegExp = (pattern, path) => {
109
- // A /g or /y pattern carries lastIndex between calls, so the same link would
110
- // match on one dispatch and miss on the next.
111
- if (pattern.global || pattern.sticky) {
112
- pattern.lastIndex = 0;
113
- }
114
- const result = pattern.exec(path);
115
- if (!result) {
116
- return null;
117
- }
118
- const params = {};
119
- for (let i = 1; i < result.length; i += 1) {
120
- const group = result[i];
121
- if (group !== undefined) {
122
- params[String(i)] = group;
123
- }
124
- }
125
- for (const [name, value] of Object.entries(result.groups ?? {})) {
126
- if (value !== undefined) {
127
- params[name] = value;
128
- }
129
- }
130
- return params;
131
- };
132
- const matchRoute = (routes, link) => {
133
- for (const route of routes) {
134
- const params = typeof route.match === 'string' ? matchPattern(route.match, link.segments) : matchRegExp(route.match, link.path);
135
- if (params) {
136
- return {
137
- route,
138
- params
139
- };
140
- }
141
- }
142
- return null;
143
- };
144
- let config = null;
145
- let subscription = null;
146
- let started = false;
147
- let pending = null;
148
- let readyOverride = null;
149
- const isReady = () => {
150
- if (readyOverride !== null) {
151
- return readyOverride;
152
- }
153
- return config?.isReady?.() ?? true;
154
- };
155
- const isAuthenticated = () => config?.isAuthenticated?.() ?? true;
156
- const dispatch = link => {
157
- const active = config;
158
- if (!active) {
159
- return;
160
- }
161
- const matched = matchRoute(active.routes, link);
162
- if (!matched) {
163
- active.onUnmatched?.(link);
164
- return;
165
- }
166
- if (matched.route.requiresAuth && !isAuthenticated()) {
167
- pending = link;
168
- active.onUnauthenticated?.(link);
169
- return;
170
- }
171
- matched.route.handler(link, matched.params);
172
- };
173
- const flushPending = () => {
174
- const link = pending;
175
- if (!link) {
176
- return;
177
- }
178
- // Cleared BEFORE dispatch: a handler that navigates can re-enter this path,
179
- // and a link that fires twice is the classic deep-link duplicate-screen bug.
180
- pending = null;
181
- dispatch(link);
182
- };
183
- const configure = next => {
184
- if (!next || !Array.isArray(next.routes)) {
185
- throw new Error(`${PREFIX} DeepLink.configure() needs a config object with a "routes" array. ` + 'Pass { routes: [{ match: "order/:id", handler }] }.');
186
- }
187
- config = next;
188
- };
189
- const handleUrl = url => {
190
- if (!config) {
191
- _index.Logger.error(`${PREFIX} DeepLink received a URL before configure() was called; the link was dropped. ` + 'Call DeepLink.configure({ routes }) (or useDeepLink) during app start.');
192
- return;
193
- }
194
- const parsed = parseDeepLink(url);
195
- // A malformed URL still reaches the app through onUnmatched, with the raw
196
- // value in `url`, rather than vanishing.
197
- if (!parsed) {
198
- config.onUnmatched?.({
199
- url: typeof url === 'string' ? url : '',
200
- scheme: '',
201
- host: '',
202
- path: '',
203
- segments: [],
204
- query: {}
205
- });
206
- return;
207
- }
208
- const link = parsed;
209
- if (!isReady()) {
210
- pending = link;
211
- return;
212
- }
213
- dispatch(link);
214
- };
215
- const start = async () => {
216
- if (!config) {
217
- throw new Error(`${PREFIX} DeepLink.start() was called before configure(). ` + 'Call DeepLink.configure({ routes }) first, or use the useDeepLink() hook.');
218
- }
219
- if (started) {
220
- return;
221
- }
222
- started = true;
223
- // Subscribe before reading the cold-start URL so a link arriving during the
224
- // await is not lost.
225
- subscription = _reactNative.Linking.addEventListener('url', event => {
226
- handleUrl(event.url);
227
- });
228
- try {
229
- const initial = await _reactNative.Linking.getInitialURL();
230
- if (initial) {
231
- handleUrl(initial);
232
- }
233
- } catch (error) {
234
- _index.Logger.error(`${PREFIX} DeepLink could not read the cold-start URL`, error);
235
- }
236
- };
237
- const stop = () => {
238
- subscription?.remove?.();
239
- subscription = null;
240
- started = false;
241
- pending = null;
242
- readyOverride = null;
243
- };
244
- const setReady = ready => {
245
- readyOverride = ready;
246
- if (ready) {
247
- flushPending();
248
- }
249
- };
250
- const DeepLink = exports.DeepLink = {
251
- configure,
252
- start,
253
- stop,
254
- handleUrl,
255
- setReady,
256
- /** Replay the stashed link, once. Call after a successful login. */
257
- replayPending: flushPending,
258
- getPending: () => pending
259
- };
260
-
261
- /**
262
- * Configure and start the deep-link service for the lifetime of a component.
263
- * The stored config delegates to the latest render, so new route closures do
264
- * not tear down and re-subscribe the native listener.
265
- */
266
- const useDeepLink = deepLinkConfig => {
267
- const configRef = (0, _react.useRef)(deepLinkConfig);
268
- configRef.current = deepLinkConfig;
269
- (0, _react.useEffect)(() => {
270
- DeepLink.configure({
271
- get routes() {
272
- return configRef.current.routes;
273
- },
274
- isReady: () => configRef.current.isReady?.() ?? true,
275
- isAuthenticated: () => configRef.current.isAuthenticated?.() ?? true,
276
- onUnauthenticated: link => configRef.current.onUnauthenticated?.(link),
277
- onUnmatched: link => configRef.current.onUnmatched?.(link)
278
- });
279
- void DeepLink.start();
280
- return () => {
281
- DeepLink.stop();
282
- };
283
- }, []);
284
- };
285
- exports.useDeepLink = useDeepLink;
286
- //# sourceMappingURL=index.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useDeepLink=exports.parseDeepLink=exports.DeepLink=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../logger/index.js");const PREFIX="[@webority/mobile-core]",decodeSafe=e=>{try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return e}},parseQuery=e=>{const t={};if(!e)return t;for(const r of e.split("&")){if(!r)continue;const e=r.indexOf("="),n=decodeSafe(e>=0?r.slice(0,e):r);n&&(t[n]=e>=0?decodeSafe(r.slice(e+1)):"")}return t},trimSlashes=e=>e.replace(/^\/+/,"").replace(/\/+$/,""),parseDeepLink=e=>{if("string"!=typeof e)return null;const t=e.trim();if(!t||/\s/.test(t))return null;const r=t.split("#")[0]??"",n=r.indexOf("://");let i="",s=r;if(n>=0){const e=r.slice(0,n);if(!/^[a-zA-Z][a-zA-Z0-9+.-]*$/.test(e))return null;i=e.toLowerCase(),s=r.slice(n+3)}const o=s.indexOf("?"),a=o>=0?s.slice(0,o):s,c=parseQuery(o>=0?s.slice(o+1):"");let u="",l=a;if("http"===i||"https"===i){const e=a.indexOf("/");u=e>=0?a.slice(0,e):a,l=e>=0?a.slice(e+1):""}const d=trimSlashes(l),p=d?d.split("/").filter(Boolean):[];return i&&"http"!==i&&"https"!==i&&(u=p[0]??""),{url:t,scheme:i,host:u,path:d,segments:p,query:c}};exports.parseDeepLink=parseDeepLink;const matchPattern=(e,t)=>{const r=trimSlashes(e).split("/").filter(Boolean);if(r.length!==t.length)return null;const n={};for(let e=0;e<r.length;e+=1){const i=r[e],s=t[e];if(i.startsWith(":")){const e=i.slice(1);if(!e)return null;n[e]=s}else if(i.toLowerCase()!==s.toLowerCase())return null}return n},matchRegExp=(e,t)=>{(e.global||e.sticky)&&(e.lastIndex=0);const r=e.exec(t);if(!r)return null;const n={};for(let e=1;e<r.length;e+=1){const t=r[e];void 0!==t&&(n[String(e)]=t)}for(const[e,t]of Object.entries(r.groups??{}))void 0!==t&&(n[e]=t);return n},matchRoute=(e,t)=>{for(const r of e){const e="string"==typeof r.match?matchPattern(r.match,t.segments):matchRegExp(r.match,t.path);if(e)return{route:r,params:e}}return null};let config=null,subscription=null,started=!1,pending=null,readyOverride=null;const isReady=()=>null!==readyOverride?readyOverride:config?.isReady?.()??!0,isAuthenticated=()=>config?.isAuthenticated?.()??!0,dispatch=e=>{const t=config;if(!t)return;const r=matchRoute(t.routes,e);if(r)return r.route.requiresAuth&&!isAuthenticated()?(pending=e,void t.onUnauthenticated?.(e)):void r.route.handler(e,r.params);t.onUnmatched?.(e)},flushPending=()=>{const e=pending;e&&(pending=null,dispatch(e))},configure=e=>{if(!e||!Array.isArray(e.routes))throw new Error(`${PREFIX} DeepLink.configure() needs a config object with a "routes" array. Pass { routes: [{ match: "order/:id", handler }] }.`);config=e},handleUrl=e=>{if(!config)return void _index.Logger.error(`${PREFIX} DeepLink received a URL before configure() was called; the link was dropped. Call DeepLink.configure({ routes }) (or useDeepLink) during app start.`);const t=parseDeepLink(e);if(!t)return void config.onUnmatched?.({url:"string"==typeof e?e:"",scheme:"",host:"",path:"",segments:[],query:{}});const r=t;isReady()?dispatch(r):pending=r},start=async()=>{if(!config)throw new Error(`${PREFIX} DeepLink.start() was called before configure(). Call DeepLink.configure({ routes }) first, or use the useDeepLink() hook.`);if(!started){started=!0,subscription=_reactNative.Linking.addEventListener("url",e=>{handleUrl(e.url)});try{const e=await _reactNative.Linking.getInitialURL();e&&handleUrl(e)}catch(e){_index.Logger.error(`${PREFIX} DeepLink could not read the cold-start URL`,e)}}},stop=()=>{subscription?.remove?.(),subscription=null,started=!1,pending=null,readyOverride=null},setReady=e=>{readyOverride=e,e&&flushPending()},DeepLink=exports.DeepLink={configure:configure,start:start,stop:stop,handleUrl:handleUrl,setReady:setReady,replayPending:flushPending,getPending:()=>pending},useDeepLink=e=>{const t=(0,_react.useRef)(e);t.current=e,(0,_react.useEffect)(()=>(DeepLink.configure({get routes(){return t.current.routes},isReady:()=>t.current.isReady?.()??!0,isAuthenticated:()=>t.current.isAuthenticated?.()??!0,onUnauthenticated:e=>t.current.onUnauthenticated?.(e),onUnmatched:e=>t.current.onUnmatched?.(e)}),DeepLink.start(),()=>{DeepLink.stop()}),[])};exports.useDeepLink=useDeepLink;
@@ -1,69 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.adaptExpoFileSystem = void 0;
7
- /**
8
- * expo-file-system. Shape verified against 57.0.6, where the legacy function
9
- * API (`downloadAsync`, `getInfoAsync`) still exists on the main entry point
10
- * but every one of those functions THROWS at runtime; they now live behind
11
- * `expo-file-system/legacy`. This adapter therefore uses the class API only.
12
- *
13
- * The REQUIRE lives in the entry point beside this file, never here.
14
- */
15
-
16
- /**
17
- * expo reports a directory as a URI with a trailing slash, and the download
18
- * module joins a directory to a file name with a `/` of its own.
19
- */
20
- const asDirectoryPath = uri => uri.replace(/\/+$/, '');
21
- const adaptExpoFileSystem = mod => {
22
- const lib = mod?.default ?? mod;
23
- if (typeof lib?.File !== 'function' || typeof lib.File.prototype?.write !== 'function') {
24
- return null;
25
- }
26
- const {
27
- File,
28
- Directory,
29
- Paths
30
- } = lib;
31
- const documents = asDirectoryPath(Paths.document.uri);
32
- return {
33
- dirs: {
34
- documents,
35
- cache: asDirectoryPath(Paths.cache.uri),
36
- // expo exposes no public Downloads directory, so a "downloads" request
37
- // lands in the app's documents directory instead of the shared folder.
38
- downloads: documents
39
- },
40
- write: (path, bytes) => {
41
- const file = new File(path);
42
- file.create({
43
- intermediates: true,
44
- overwrite: true
45
- });
46
- file.write(bytes);
47
- return Promise.resolve();
48
- },
49
- exists: path => Promise.resolve(new File(path).exists),
50
- stat: path => Promise.resolve({
51
- size: new File(path).size
52
- }),
53
- unlink: path => {
54
- new File(path).delete();
55
- return Promise.resolve();
56
- },
57
- // The download module calls this for a directory that usually already
58
- // exists, so it must be idempotent rather than throw on the second run.
59
- mkdir: path => {
60
- new Directory(path).create({
61
- intermediates: true,
62
- idempotent: true
63
- });
64
- return Promise.resolve();
65
- }
66
- };
67
- };
68
- exports.adaptExpoFileSystem = adaptExpoFileSystem;
69
- //# sourceMappingURL=expoFs.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.adaptExpoFileSystem=void 0;const asDirectoryPath=e=>e.replace(/\/+$/,""),adaptExpoFileSystem=e=>{const t=e?.default??e;if("function"!=typeof t?.File||"function"!=typeof t.File.prototype?.write)return null;const{File:r,Directory:i,Paths:o}=t,s=asDirectoryPath(o.document.uri);return{dirs:{documents:s,cache:asDirectoryPath(o.cache.uri),downloads:s},write:(e,t)=>{const i=new r(e);return i.create({intermediates:!0,overwrite:!0}),i.write(t),Promise.resolve()},exists:e=>Promise.resolve(new r(e).exists),stat:e=>Promise.resolve({size:new r(e).size}),unlink:e=>(new r(e).delete(),Promise.resolve()),mkdir:e=>(new i(e).create({intermediates:!0,idempotent:!0}),Promise.resolve())}};exports.adaptExpoFileSystem=adaptExpoFileSystem;
@@ -1,13 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.asNumber = void 0;
7
- /** Coerce a driver-supplied size, which some report as a string. */
8
- const asNumber = value => {
9
- const n = typeof value === 'number' ? value : Number(value);
10
- return Number.isFinite(n) ? n : 0;
11
- };
12
- exports.asNumber = asNumber;
13
- //# sourceMappingURL=shared.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.asNumber=void 0;const asNumber=e=>{const r="number"==typeof e?e:Number(e);return Number.isFinite(r)?r:0};exports.asNumber=asNumber;