@webority/mobile-core 0.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +39 -0
  3. package/android/build.gradle +65 -0
  4. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/AppSignatureHelper.kt +57 -0
  5. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModule.kt +20 -0
  6. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverModuleImpl.kt +146 -0
  7. package/android/src/newarch/java/com/webority/mobilecore/smsretriever/SmsRetrieverPackage.kt +33 -0
  8. package/lib/commonjs/api/baseUrl.js +34 -0
  9. package/lib/commonjs/api/curl.js +109 -0
  10. package/lib/commonjs/api/publicClient.js +73 -0
  11. package/lib/commonjs/api/retry.js +75 -0
  12. package/lib/commonjs/api/tokenRefresh.js +205 -0
  13. package/lib/commonjs/api/userClient.js +255 -0
  14. package/lib/commonjs/auth/authStore.js +232 -0
  15. package/lib/commonjs/auth/index.js +44 -0
  16. package/lib/commonjs/auth/jwt.js +112 -0
  17. package/lib/commonjs/config/index.js +66 -0
  18. package/lib/commonjs/deepLink/index.js +286 -0
  19. package/lib/commonjs/download/adapters/expoFs.js +69 -0
  20. package/lib/commonjs/download/adapters/shared.js +13 -0
  21. package/lib/commonjs/download/index.js +250 -0
  22. package/lib/commonjs/formatters/currency.js +69 -0
  23. package/lib/commonjs/formatters/date.js +168 -0
  24. package/lib/commonjs/formatters/dateMath.js +310 -0
  25. package/lib/commonjs/formatters/index.js +246 -0
  26. package/lib/commonjs/formatters/initials.js +32 -0
  27. package/lib/commonjs/formatters/number.js +88 -0
  28. package/lib/commonjs/formatters/phone.js +369 -0
  29. package/lib/commonjs/formatters/windowsToIanaTable.js +164 -0
  30. package/lib/commonjs/geolocation/adapters/expoLocation.js +126 -0
  31. package/lib/commonjs/geolocation/index.js +355 -0
  32. package/lib/commonjs/index.js +630 -0
  33. package/lib/commonjs/initSDK.js +66 -0
  34. package/lib/commonjs/initUserAuth.js +37 -0
  35. package/lib/commonjs/logger/index.js +291 -0
  36. package/lib/commonjs/network/index.js +31 -0
  37. package/lib/commonjs/network/networkStatus.js +133 -0
  38. package/lib/commonjs/package.json +1 -0
  39. package/lib/commonjs/permissions/calendar.js +14 -0
  40. package/lib/commonjs/permissions/camera.js +14 -0
  41. package/lib/commonjs/permissions/contacts.js +10 -0
  42. package/lib/commonjs/permissions/index.js +133 -0
  43. package/lib/commonjs/permissions/location.js +14 -0
  44. package/lib/commonjs/permissions/mediaLibrary.js +10 -0
  45. package/lib/commonjs/permissions/notifications.js +10 -0
  46. package/lib/commonjs/permissions/photos.js +14 -0
  47. package/lib/commonjs/phone/countries.js +265 -0
  48. package/lib/commonjs/share/index.js +70 -0
  49. package/lib/commonjs/smsRetriever/index.js +91 -0
  50. package/lib/commonjs/specs/NativeSmsRetriever.js +15 -0
  51. package/lib/commonjs/sqlite/adapters/expo.js +53 -0
  52. package/lib/commonjs/sqlite/index.js +604 -0
  53. package/lib/commonjs/storage/index.js +214 -0
  54. package/lib/commonjs/types/globals.d.js +6 -0
  55. package/lib/commonjs/utils/imageCompression.js +389 -0
  56. package/lib/commonjs/utils/index.js +19 -0
  57. package/lib/commonjs/validators/index.js +227 -0
  58. package/lib/commonjs/versionCheck/index.js +419 -0
  59. package/lib/module/api/baseUrl.js +30 -0
  60. package/lib/module/api/curl.js +104 -0
  61. package/lib/module/api/publicClient.js +69 -0
  62. package/lib/module/api/retry.js +69 -0
  63. package/lib/module/api/tokenRefresh.js +192 -0
  64. package/lib/module/api/userClient.js +233 -0
  65. package/lib/module/auth/authStore.js +224 -0
  66. package/lib/module/auth/index.js +5 -0
  67. package/lib/module/auth/jwt.js +106 -0
  68. package/lib/module/config/index.js +58 -0
  69. package/lib/module/deepLink/index.js +280 -0
  70. package/lib/module/download/adapters/expoFs.js +64 -0
  71. package/lib/module/download/adapters/shared.js +8 -0
  72. package/lib/module/download/index.js +242 -0
  73. package/lib/module/formatters/currency.js +64 -0
  74. package/lib/module/formatters/date.js +160 -0
  75. package/lib/module/formatters/dateMath.js +294 -0
  76. package/lib/module/formatters/index.js +9 -0
  77. package/lib/module/formatters/initials.js +27 -0
  78. package/lib/module/formatters/number.js +81 -0
  79. package/lib/module/formatters/phone.js +302 -0
  80. package/lib/module/formatters/windowsToIanaTable.js +160 -0
  81. package/lib/module/geolocation/adapters/expoLocation.js +121 -0
  82. package/lib/module/geolocation/index.js +347 -0
  83. package/lib/module/index.js +54 -0
  84. package/lib/module/initSDK.js +61 -0
  85. package/lib/module/initUserAuth.js +33 -0
  86. package/lib/module/logger/index.js +285 -0
  87. package/lib/module/network/index.js +4 -0
  88. package/lib/module/network/networkStatus.js +124 -0
  89. package/lib/module/package.json +1 -0
  90. package/lib/module/permissions/calendar.js +15 -0
  91. package/lib/module/permissions/camera.js +15 -0
  92. package/lib/module/permissions/contacts.js +11 -0
  93. package/lib/module/permissions/index.js +128 -0
  94. package/lib/module/permissions/location.js +15 -0
  95. package/lib/module/permissions/mediaLibrary.js +11 -0
  96. package/lib/module/permissions/notifications.js +11 -0
  97. package/lib/module/permissions/photos.js +15 -0
  98. package/lib/module/phone/countries.js +261 -0
  99. package/lib/module/share/index.js +64 -0
  100. package/lib/module/smsRetriever/index.js +86 -0
  101. package/lib/module/specs/NativeSmsRetriever.js +13 -0
  102. package/lib/module/sqlite/adapters/expo.js +48 -0
  103. package/lib/module/sqlite/index.js +594 -0
  104. package/lib/module/storage/index.js +208 -0
  105. package/lib/module/types/globals.d.js +10 -0
  106. package/lib/module/utils/imageCompression.js +383 -0
  107. package/lib/module/utils/index.js +4 -0
  108. package/lib/module/validators/index.js +205 -0
  109. package/lib/module/versionCheck/index.js +413 -0
  110. package/lib/typescript/commonjs/api/baseUrl.d.ts +20 -0
  111. package/lib/typescript/commonjs/api/curl.d.ts +18 -0
  112. package/lib/typescript/commonjs/api/publicClient.d.ts +11 -0
  113. package/lib/typescript/commonjs/api/retry.d.ts +27 -0
  114. package/lib/typescript/commonjs/api/tokenRefresh.d.ts +43 -0
  115. package/lib/typescript/commonjs/api/userClient.d.ts +37 -0
  116. package/lib/typescript/commonjs/auth/authStore.d.ts +79 -0
  117. package/lib/typescript/commonjs/auth/index.d.ts +5 -0
  118. package/lib/typescript/commonjs/auth/jwt.d.ts +31 -0
  119. package/lib/typescript/commonjs/config/index.d.ts +55 -0
  120. package/lib/typescript/commonjs/deepLink/index.d.ts +54 -0
  121. package/lib/typescript/commonjs/download/adapters/expoFs.d.ts +38 -0
  122. package/lib/typescript/commonjs/download/adapters/shared.d.ts +3 -0
  123. package/lib/typescript/commonjs/download/index.d.ts +86 -0
  124. package/lib/typescript/commonjs/formatters/currency.d.ts +24 -0
  125. package/lib/typescript/commonjs/formatters/date.d.ts +22 -0
  126. package/lib/typescript/commonjs/formatters/dateMath.d.ts +88 -0
  127. package/lib/typescript/commonjs/formatters/index.d.ts +10 -0
  128. package/lib/typescript/commonjs/formatters/initials.d.ts +11 -0
  129. package/lib/typescript/commonjs/formatters/number.d.ts +15 -0
  130. package/lib/typescript/commonjs/formatters/phone.d.ts +133 -0
  131. package/lib/typescript/commonjs/formatters/windowsToIanaTable.d.ts +18 -0
  132. package/lib/typescript/commonjs/geolocation/adapters/expoLocation.d.ts +42 -0
  133. package/lib/typescript/commonjs/geolocation/index.d.ts +90 -0
  134. package/lib/typescript/commonjs/index.d.ts +54 -0
  135. package/lib/typescript/commonjs/initSDK.d.ts +72 -0
  136. package/lib/typescript/commonjs/initUserAuth.d.ts +41 -0
  137. package/lib/typescript/commonjs/logger/index.d.ts +81 -0
  138. package/lib/typescript/commonjs/network/index.d.ts +3 -0
  139. package/lib/typescript/commonjs/network/networkStatus.d.ts +43 -0
  140. package/lib/typescript/commonjs/package.json +1 -0
  141. package/lib/typescript/commonjs/permissions/calendar.d.ts +2 -0
  142. package/lib/typescript/commonjs/permissions/camera.d.ts +2 -0
  143. package/lib/typescript/commonjs/permissions/contacts.d.ts +2 -0
  144. package/lib/typescript/commonjs/permissions/index.d.ts +48 -0
  145. package/lib/typescript/commonjs/permissions/location.d.ts +2 -0
  146. package/lib/typescript/commonjs/permissions/mediaLibrary.d.ts +2 -0
  147. package/lib/typescript/commonjs/permissions/notifications.d.ts +2 -0
  148. package/lib/typescript/commonjs/permissions/photos.d.ts +2 -0
  149. package/lib/typescript/commonjs/phone/countries.d.ts +13 -0
  150. package/lib/typescript/commonjs/share/index.d.ts +29 -0
  151. package/lib/typescript/commonjs/smsRetriever/index.d.ts +30 -0
  152. package/lib/typescript/commonjs/specs/NativeSmsRetriever.d.ts +15 -0
  153. package/lib/typescript/commonjs/sqlite/adapters/expo.d.ts +30 -0
  154. package/lib/typescript/commonjs/sqlite/index.d.ts +113 -0
  155. package/lib/typescript/commonjs/storage/index.d.ts +64 -0
  156. package/lib/typescript/commonjs/utils/imageCompression.d.ts +152 -0
  157. package/lib/typescript/commonjs/utils/index.d.ts +3 -0
  158. package/lib/typescript/commonjs/validators/index.d.ts +51 -0
  159. package/lib/typescript/commonjs/versionCheck/index.d.ts +80 -0
  160. package/lib/typescript/module/api/baseUrl.d.ts +20 -0
  161. package/lib/typescript/module/api/curl.d.ts +18 -0
  162. package/lib/typescript/module/api/publicClient.d.ts +11 -0
  163. package/lib/typescript/module/api/retry.d.ts +27 -0
  164. package/lib/typescript/module/api/tokenRefresh.d.ts +43 -0
  165. package/lib/typescript/module/api/userClient.d.ts +37 -0
  166. package/lib/typescript/module/auth/authStore.d.ts +79 -0
  167. package/lib/typescript/module/auth/index.d.ts +5 -0
  168. package/lib/typescript/module/auth/jwt.d.ts +31 -0
  169. package/lib/typescript/module/config/index.d.ts +55 -0
  170. package/lib/typescript/module/deepLink/index.d.ts +54 -0
  171. package/lib/typescript/module/download/adapters/expoFs.d.ts +38 -0
  172. package/lib/typescript/module/download/adapters/shared.d.ts +3 -0
  173. package/lib/typescript/module/download/index.d.ts +86 -0
  174. package/lib/typescript/module/formatters/currency.d.ts +24 -0
  175. package/lib/typescript/module/formatters/date.d.ts +22 -0
  176. package/lib/typescript/module/formatters/dateMath.d.ts +88 -0
  177. package/lib/typescript/module/formatters/index.d.ts +10 -0
  178. package/lib/typescript/module/formatters/initials.d.ts +11 -0
  179. package/lib/typescript/module/formatters/number.d.ts +15 -0
  180. package/lib/typescript/module/formatters/phone.d.ts +133 -0
  181. package/lib/typescript/module/formatters/windowsToIanaTable.d.ts +18 -0
  182. package/lib/typescript/module/geolocation/adapters/expoLocation.d.ts +42 -0
  183. package/lib/typescript/module/geolocation/index.d.ts +90 -0
  184. package/lib/typescript/module/index.d.ts +54 -0
  185. package/lib/typescript/module/initSDK.d.ts +72 -0
  186. package/lib/typescript/module/initUserAuth.d.ts +41 -0
  187. package/lib/typescript/module/logger/index.d.ts +81 -0
  188. package/lib/typescript/module/network/index.d.ts +3 -0
  189. package/lib/typescript/module/network/networkStatus.d.ts +43 -0
  190. package/lib/typescript/module/package.json +1 -0
  191. package/lib/typescript/module/permissions/calendar.d.ts +2 -0
  192. package/lib/typescript/module/permissions/camera.d.ts +2 -0
  193. package/lib/typescript/module/permissions/contacts.d.ts +2 -0
  194. package/lib/typescript/module/permissions/index.d.ts +48 -0
  195. package/lib/typescript/module/permissions/location.d.ts +2 -0
  196. package/lib/typescript/module/permissions/mediaLibrary.d.ts +2 -0
  197. package/lib/typescript/module/permissions/notifications.d.ts +2 -0
  198. package/lib/typescript/module/permissions/photos.d.ts +2 -0
  199. package/lib/typescript/module/phone/countries.d.ts +13 -0
  200. package/lib/typescript/module/share/index.d.ts +29 -0
  201. package/lib/typescript/module/smsRetriever/index.d.ts +30 -0
  202. package/lib/typescript/module/specs/NativeSmsRetriever.d.ts +15 -0
  203. package/lib/typescript/module/sqlite/adapters/expo.d.ts +30 -0
  204. package/lib/typescript/module/sqlite/index.d.ts +113 -0
  205. package/lib/typescript/module/storage/index.d.ts +64 -0
  206. package/lib/typescript/module/utils/imageCompression.d.ts +152 -0
  207. package/lib/typescript/module/utils/index.d.ts +3 -0
  208. package/lib/typescript/module/validators/index.d.ts +51 -0
  209. package/lib/typescript/module/versionCheck/index.d.ts +80 -0
  210. package/package.json +298 -0
  211. package/src/specs/NativeSmsRetriever.ts +16 -0
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.initUserAuth = void 0;
7
+ var _userClient = require("./api/userClient.js");
8
+ var _index = require("./logger/index.js");
9
+ /** The tokens a refresh response carries, with their expiry timestamps. */
10
+
11
+ /**
12
+ * How the library calls the app's refresh endpoint. The call goes through
13
+ * `publicClient`, and the new tokens are stored under the library's own keys.
14
+ */
15
+
16
+ /**
17
+ * Wire the user client to the app: the Redux store it dispatches `logout` to,
18
+ * and the refresh endpoint it calls when an access token expires or a request
19
+ * answers 401. Only a 400 or 401 from that endpoint, or a missing or expired
20
+ * refresh token, logs out; a network error, timeout or 5xx keeps the session.
21
+ *
22
+ * @example
23
+ * initUserAuth(store, { logout, refresh: { path: '/Account/RefreshToken' } });
24
+ */
25
+ const initUserAuth = (store, options) => {
26
+ if (!store) {
27
+ throw new Error('Redux store is required for user package initialization');
28
+ }
29
+ if (!options.logout || !options.refresh?.path) {
30
+ throw new Error('initUserAuth needs a logout action and refresh.path');
31
+ }
32
+ (0, _userClient.injectStore)(store);
33
+ (0, _userClient.injectUserAuth)(options);
34
+ _index.Logger.info('[@webority/mobile-core] user auth wired to the store');
35
+ };
36
+ exports.initUserAuth = initUserAuth;
37
+ //# sourceMappingURL=initUserAuth.js.map
@@ -0,0 +1,291 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setRemoteLogger = exports.setDeviceContext = exports.getDeviceContext = exports.configureLogger = exports.Logger = void 0;
7
+ var _index = require("../config/index.js");
8
+ // ANSI color codes
9
+ const Colors = {
10
+ RESET: '\x1b[0m',
11
+ BLUE: '\x1b[34m',
12
+ YELLOW: '\x1b[33m',
13
+ RED_BOLD: '\x1b[31;1m'
14
+ };
15
+ const LogLevels = {
16
+ INFO: {
17
+ level: 'info',
18
+ color: Colors.BLUE
19
+ },
20
+ WARN: {
21
+ level: 'warn',
22
+ color: Colors.YELLOW
23
+ },
24
+ ERROR: {
25
+ level: 'error',
26
+ color: Colors.RED_BOLD
27
+ }
28
+ };
29
+
30
+ // Check if a specific log level is allowed
31
+ const isLogLevelAllowed = level => {
32
+ const levels = ['info', 'warn', 'error'];
33
+ const current = (0, _index.getConfigValue)('logLevel', 'info');
34
+ return levels.indexOf(level) >= levels.indexOf(current);
35
+ };
36
+ const isEnabled = () => (0, _index.getConfigValue)('loggingEnabled', true);
37
+
38
+ /**
39
+ * Optional remote sink. Apps wire this via `setRemoteLogger()` to forward errors
40
+ * and breadcrumbs to Crashlytics, Sentry, Bugsnag, etc. — without making the
41
+ * library depend on any of them.
42
+ *
43
+ * Every method is optional; the library calls only what the adapter implements.
44
+ */
45
+
46
+ let remote = null;
47
+
48
+ /**
49
+ * Inject a remote logger adapter (e.g. Firebase Crashlytics, Sentry).
50
+ * Pass `null` to detach. Safe to call before or after `initWebority`.
51
+ */
52
+ const setRemoteLogger = impl => {
53
+ remote = impl;
54
+ };
55
+ exports.setRemoteLogger = setRemoteLogger;
56
+ const safe = fn => {
57
+ if (!fn) {
58
+ return;
59
+ }
60
+ try {
61
+ fn();
62
+ } catch {
63
+ /* never let the remote sink break the caller */
64
+ }
65
+ };
66
+ const toErrorObject = input => {
67
+ if (input instanceof Error) {
68
+ return input;
69
+ }
70
+ if (typeof input === 'string') {
71
+ return new Error(input);
72
+ }
73
+ try {
74
+ return new Error(JSON.stringify(input));
75
+ } catch {
76
+ return new Error(String(input));
77
+ }
78
+ };
79
+
80
+ /**
81
+ * Device / app context attached once at boot (platform, OS version, app version,
82
+ * build number, device model, etc). Merged into every `recordError` context so
83
+ * every crash carries it without every call site repeating it.
84
+ */
85
+
86
+ let deviceContext = null;
87
+ const normalizeAttributeValue = value => {
88
+ if (value === null || value === undefined) {
89
+ return null;
90
+ }
91
+ if (typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
92
+ return value;
93
+ }
94
+ return String(value);
95
+ };
96
+
97
+ /**
98
+ * Set (or clear, with `null`) the device/app context merged into every
99
+ * `recordError` call. Each key is also forwarded to `remote.setAttribute`
100
+ * once, at the moment it is set.
101
+ */
102
+ const setDeviceContext = context => {
103
+ deviceContext = context;
104
+ if (context) {
105
+ for (const [key, value] of Object.entries(context)) {
106
+ safe(() => remote?.setAttribute?.(key, normalizeAttributeValue(value)));
107
+ }
108
+ }
109
+ };
110
+ exports.setDeviceContext = setDeviceContext;
111
+ const getDeviceContext = () => deviceContext;
112
+
113
+ /** Tuning knobs for screen history and duplicate-error suppression. */
114
+ exports.getDeviceContext = getDeviceContext;
115
+ const DEFAULT_LOGGER_OPTIONS = {
116
+ dedupeWindowMs: 5000,
117
+ dedupeMaxPerWindow: 1,
118
+ screenHistoryLimit: 20
119
+ };
120
+ let loggerOptions = {
121
+ ...DEFAULT_LOGGER_OPTIONS
122
+ };
123
+
124
+ /** Configure dedupe window/threshold and screen history size. Merges with current options. */
125
+ const configureLogger = options => {
126
+ loggerOptions = {
127
+ ...loggerOptions,
128
+ ...options
129
+ };
130
+ if (screenHistory.length > loggerOptions.screenHistoryLimit) {
131
+ screenHistory = screenHistory.slice(screenHistory.length - loggerOptions.screenHistoryLimit);
132
+ }
133
+ };
134
+ exports.configureLogger = configureLogger;
135
+ let currentScreen = null;
136
+ let screenHistory = [];
137
+ const dedupeMap = new Map();
138
+ const MAX_DEDUPE_ENTRIES = 200;
139
+ const dedupeKeyFor = err => {
140
+ const firstFrame = err.stack?.split('\n')[1]?.trim();
141
+ return firstFrame ? `${err.message}::${firstFrame}` : err.message;
142
+ };
143
+ const capDedupeMap = () => {
144
+ while (dedupeMap.size > MAX_DEDUPE_ENTRIES) {
145
+ const oldestKey = dedupeMap.keys().next().value;
146
+ if (oldestKey === undefined) {
147
+ return;
148
+ }
149
+ dedupeMap.delete(oldestKey);
150
+ }
151
+ };
152
+ const shouldForward = key => {
153
+ if (loggerOptions.dedupeWindowMs <= 0) {
154
+ return {
155
+ forward: true
156
+ };
157
+ }
158
+ const now = Date.now();
159
+ const entry = dedupeMap.get(key);
160
+ if (!entry || now - entry.windowStart >= loggerOptions.dedupeWindowMs) {
161
+ const suppressedCount = entry?.suppressedCount ?? 0;
162
+ dedupeMap.set(key, {
163
+ windowStart: now,
164
+ count: 1,
165
+ suppressedCount: 0
166
+ });
167
+ capDedupeMap();
168
+ return suppressedCount > 0 ? {
169
+ forward: true,
170
+ suppressedCount
171
+ } : {
172
+ forward: true
173
+ };
174
+ }
175
+ entry.count += 1;
176
+ if (entry.count > loggerOptions.dedupeMaxPerWindow) {
177
+ entry.suppressedCount += 1;
178
+ return {
179
+ forward: false
180
+ };
181
+ }
182
+ return {
183
+ forward: true
184
+ };
185
+ };
186
+ const buildErrorContext = (context, suppressedCount) => {
187
+ const merged = {
188
+ ...deviceContext
189
+ };
190
+ if (currentScreen !== null) {
191
+ merged.screen = currentScreen;
192
+ }
193
+ if (suppressedCount) {
194
+ merged.suppressedCount = suppressedCount;
195
+ }
196
+ return {
197
+ ...merged,
198
+ ...context
199
+ };
200
+ };
201
+ const forwardErrorToRemote = (err, context) => {
202
+ const key = dedupeKeyFor(err);
203
+ const {
204
+ forward,
205
+ suppressedCount
206
+ } = shouldForward(key);
207
+ if (!forward) {
208
+ return;
209
+ }
210
+ safe(() => remote?.recordError?.(err, buildErrorContext(context, suppressedCount)));
211
+ };
212
+ const logInfo = (message, ...optionalParams) => {
213
+ if (!isEnabled() || !isLogLevelAllowed(LogLevels.INFO.level)) {
214
+ return;
215
+ }
216
+ console.info(`${LogLevels.INFO.color}[INFO]: ${message}${Colors.RESET}`, ...optionalParams);
217
+ safe(() => remote?.log?.('info', message, optionalParams));
218
+ };
219
+ const logWarning = (message, ...optionalParams) => {
220
+ if (!isEnabled() || !isLogLevelAllowed(LogLevels.WARN.level)) {
221
+ return;
222
+ }
223
+ console.warn(`${LogLevels.WARN.color}[WARNING]: ${message}${Colors.RESET}`, ...optionalParams);
224
+ safe(() => remote?.log?.('warn', message, optionalParams));
225
+ };
226
+ const logError = (message, ...optionalParams) => {
227
+ if (isEnabled() && isLogLevelAllowed(LogLevels.ERROR.level)) {
228
+ console.error(`${LogLevels.ERROR.color}[ERROR]: ${message}${Colors.RESET}`, ...optionalParams);
229
+ }
230
+ // Always forward errors to the remote sink — even when console logging is muted —
231
+ // so production crash reporting still works with `loggingEnabled: false`.
232
+ safe(() => remote?.log?.('error', message, optionalParams));
233
+ // First optional param is treated as the underlying error if it looks like one.
234
+ const candidate = optionalParams[0];
235
+ if (candidate !== undefined) {
236
+ forwardErrorToRemote(toErrorObject(candidate), {
237
+ source: 'Logger.error',
238
+ message
239
+ });
240
+ }
241
+ };
242
+ const breadcrumb = (message, data) => {
243
+ if (isEnabled() && isLogLevelAllowed('info')) {
244
+ console.info(`${Colors.BLUE}[BREADCRUMB]: ${message}${Colors.RESET}`, data ?? '');
245
+ }
246
+ safe(() => remote?.breadcrumb?.(message, data));
247
+ };
248
+ const recordError = (error, context) => {
249
+ const err = toErrorObject(error);
250
+ if (isEnabled() && isLogLevelAllowed('error')) {
251
+ console.error(`${Colors.RED_BOLD}[RECORDED]: ${err.message}${Colors.RESET}`, context ?? '');
252
+ }
253
+ forwardErrorToRemote(err, context);
254
+ };
255
+ const setUser = (id, attrs) => {
256
+ safe(() => remote?.setUser?.(id, attrs));
257
+ };
258
+ const setAttribute = (key, value) => {
259
+ safe(() => remote?.setAttribute?.(key, value));
260
+ };
261
+
262
+ /**
263
+ * Record the active screen as a breadcrumb and remember it for subsequent
264
+ * `recordError` context. Re-tracking the same screen name is a no-op.
265
+ */
266
+ const trackScreen = (name, params) => {
267
+ if (name === currentScreen) {
268
+ return;
269
+ }
270
+ currentScreen = name;
271
+ screenHistory.push(name);
272
+ if (screenHistory.length > loggerOptions.screenHistoryLimit) {
273
+ screenHistory = screenHistory.slice(screenHistory.length - loggerOptions.screenHistoryLimit);
274
+ }
275
+ breadcrumb(`Screen: ${name}`, params);
276
+ };
277
+ const getCurrentScreen = () => currentScreen;
278
+ const getScreenHistory = () => [...screenHistory];
279
+ const Logger = exports.Logger = {
280
+ info: logInfo,
281
+ warn: logWarning,
282
+ error: logError,
283
+ breadcrumb,
284
+ recordError,
285
+ setUser,
286
+ setAttribute,
287
+ trackScreen,
288
+ getCurrentScreen,
289
+ getScreenHistory
290
+ };
291
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "addNetworkStatusListener", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _networkStatus.addNetworkStatusListener;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "getNetworkStatus", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _networkStatus.getNetworkStatus;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "setNetworkStatusImplementation", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _networkStatus.setNetworkStatusImplementation;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "useNetworkStatus", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _networkStatus.useNetworkStatus;
28
+ }
29
+ });
30
+ var _networkStatus = require("./networkStatus.js");
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useNetworkStatus = exports.setNetworkStatusImplementation = exports.getNetworkStatus = exports.addNetworkStatusListener = void 0;
7
+ var ExpoNetwork = _interopRequireWildcard(require("expo-network"));
8
+ var _react = require("react");
9
+ var _index = require("../logger/index.js");
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
11
+ const DEFAULT_STATUS = {
12
+ isConnected: true,
13
+ isInternetReachable: null,
14
+ type: 'unknown'
15
+ };
16
+ /**
17
+ * expo-network is imported directly, not resolved through a seam.
18
+ *
19
+ * `expo` is a REQUIRED peer of this package, so every consumer has the Expo
20
+ * modules by construction and the static-require problem that forced the old
21
+ * injection design does not arise. An app wires nothing: connectivity works
22
+ * because the library uses Expo, which is the point of the Expo-first policy.
23
+ * One backend also means one behaviour, rather than each app choosing.
24
+ */
25
+ let override = null;
26
+
27
+ /**
28
+ * Replace the backend. Intended for TESTS and for the showcase, which uses it
29
+ * to reach error paths that a healthy device never takes; it is not the way an
30
+ * app is meant to configure the library. Pass `null` to restore expo-network.
31
+ */
32
+ const setNetworkStatusImplementation = impl => {
33
+ override = impl;
34
+ };
35
+ exports.setNetworkStatusImplementation = setNetworkStatusImplementation;
36
+ const resolveNetInfo = () => override ?? expoNetworkBackend;
37
+
38
+ /**
39
+ * expo-network in the shape this module already speaks.
40
+ *
41
+ * The conversion is not cosmetic: expo reports its type as an UPPERCASE enum
42
+ * where this module's vocabulary is lowercase, marks every field optional, and
43
+ * returns an EventSubscription where an unsubscribe function is expected.
44
+ */
45
+ const expoNetworkBackend = {
46
+ fetch: async () => {
47
+ const state = await ExpoNetwork.getNetworkStateAsync();
48
+ return {
49
+ isConnected: state?.isConnected !== false,
50
+ isInternetReachable: state?.isInternetReachable ?? null,
51
+ type: state?.type ? String(state.type).toLowerCase() : undefined
52
+ };
53
+ },
54
+ addEventListener: cb => {
55
+ const subscription = ExpoNetwork.addNetworkStateListener(state => {
56
+ cb({
57
+ isConnected: state?.isConnected !== false,
58
+ isInternetReachable: state?.isInternetReachable ?? null,
59
+ type: state?.type ? String(state.type).toLowerCase() : undefined
60
+ });
61
+ });
62
+ return () => subscription.remove();
63
+ }
64
+ };
65
+ const normalize = state => {
66
+ if (!state) {
67
+ return DEFAULT_STATUS;
68
+ }
69
+ return {
70
+ isConnected: state.isConnected !== false,
71
+ isInternetReachable: state.isInternetReachable,
72
+ type: state.type ?? 'unknown'
73
+ };
74
+ };
75
+
76
+ /**
77
+ * Imperative one-shot fetch of current network status. Resolves to the default
78
+ * online status when NetInfo is unavailable so callers never crash.
79
+ */
80
+ const getNetworkStatus = async () => {
81
+ const ni = resolveNetInfo();
82
+ if (!ni) {
83
+ return DEFAULT_STATUS;
84
+ }
85
+ try {
86
+ const state = await ni.fetch();
87
+ return normalize(state);
88
+ } catch (error) {
89
+ _index.Logger.error('[network] getNetworkStatus failed', error);
90
+ return DEFAULT_STATUS;
91
+ }
92
+ };
93
+
94
+ /**
95
+ * Subscribe to network status changes. Returns an unsubscribe function.
96
+ */
97
+ exports.getNetworkStatus = getNetworkStatus;
98
+ const addNetworkStatusListener = listener => {
99
+ const ni = resolveNetInfo();
100
+ if (!ni) {
101
+ return () => undefined;
102
+ }
103
+ return ni.addEventListener(state => listener(normalize(state)));
104
+ };
105
+
106
+ /**
107
+ * React hook that returns the current network status and re-renders on change.
108
+ * Reports an optimistic online default when NetInfo is not installed.
109
+ */
110
+ exports.addNetworkStatusListener = addNetworkStatusListener;
111
+ const useNetworkStatus = () => {
112
+ const [status, setStatus] = (0, _react.useState)(DEFAULT_STATUS);
113
+ (0, _react.useEffect)(() => {
114
+ let mounted = true;
115
+ void getNetworkStatus().then(s => {
116
+ if (mounted) {
117
+ setStatus(s);
118
+ }
119
+ });
120
+ const unsubscribe = addNetworkStatusListener(s => {
121
+ if (mounted) {
122
+ setStatus(s);
123
+ }
124
+ });
125
+ return () => {
126
+ mounted = false;
127
+ unsubscribe();
128
+ };
129
+ }, []);
130
+ return status;
131
+ };
132
+ exports.useNetworkStatus = useNetworkStatus;
133
+ //# sourceMappingURL=networkStatus.js.map
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _index = require("./index.js");
4
+ /** The one place `expo-calendar` is named. Import only if you use calendar/reminders. */
5
+ const m = require('expo-calendar');
6
+ (0, _index.registerPermissionAdapter)('calendar', {
7
+ check: m.getCalendarPermissionsAsync,
8
+ request: m.requestCalendarPermissionsAsync
9
+ });
10
+ (0, _index.registerPermissionAdapter)('reminders', {
11
+ check: m.getRemindersPermissionsAsync,
12
+ request: m.requestRemindersPermissionsAsync
13
+ });
14
+ //# sourceMappingURL=calendar.js.map
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _index = require("./index.js");
4
+ /** The one place `expo-camera` is named. Import only if you use camera/microphone. */
5
+ const m = require('expo-camera');
6
+ (0, _index.registerPermissionAdapter)('camera', {
7
+ check: m.getCameraPermissionsAsync,
8
+ request: m.requestCameraPermissionsAsync
9
+ });
10
+ (0, _index.registerPermissionAdapter)('microphone', {
11
+ check: m.getMicrophonePermissionsAsync,
12
+ request: m.requestMicrophonePermissionsAsync
13
+ });
14
+ //# sourceMappingURL=camera.js.map
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ var _index = require("./index.js");
4
+ /** The one place `expo-contacts` is named. Import only if you use contacts. */
5
+ const m = require('expo-contacts');
6
+ (0, _index.registerPermissionAdapter)('contacts', {
7
+ check: m.getPermissionsAsync,
8
+ request: m.requestPermissionsAsync
9
+ });
10
+ //# sourceMappingURL=contacts.js.map
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.setPermissionsImplementation = exports.registerPermissionAdapter = exports.Permissions = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _index = require("../logger/index.js");
9
+ // Android only — legacy WRITE_EXTERNAL_STORAGE
10
+
11
+ /** The shared response shape every Expo permission function returns. */
12
+
13
+ let backend = null;
14
+
15
+ /**
16
+ * Inject a custom permissions backend at runtime. Pass `null` to reset to the
17
+ * default per-kind Expo resolution.
18
+ *
19
+ * Two legitimate reasons to call this: tests/the showcase reaching a denied,
20
+ * blocked or unavailable path a healthy device never takes; and an app that
21
+ * genuinely needs `bluetooth` or `storage`, which no Expo module covers.
22
+ */
23
+ const setPermissionsImplementation = impl => {
24
+ backend = impl;
25
+ };
26
+
27
+ /**
28
+ * Populated by the per-package entry points (`./camera`, `./photos`, …), never
29
+ * by this file. This module names NO Expo package — Metro resolves every
30
+ * literal require() reachable from the static import graph regardless of
31
+ * which switch branch would have run, so naming seven packages here would
32
+ * make each one a mandatory install for every consumer, whichever kinds they
33
+ * actually use. An app wires only the kinds it needs:
34
+ *
35
+ * import '@webority/mobile-core/permissions/camera';
36
+ * import '@webority/mobile-core/permissions/location';
37
+ *
38
+ * `bluetooth` and `storage` have no Expo module and are never registered here
39
+ * — they resolve through `setPermissionsImplementation` only.
40
+ */
41
+ exports.setPermissionsImplementation = setPermissionsImplementation;
42
+ const registry = new Map();
43
+
44
+ /** Called by the per-package entry points to register their kind(s). Not for app code. */
45
+ const registerPermissionAdapter = (kind, fns) => {
46
+ registry.set(kind, fns);
47
+ };
48
+ exports.registerPermissionAdapter = registerPermissionAdapter;
49
+ const resolveExpoModule = kind => registry.get(kind) ?? null;
50
+ const toStatus = response => {
51
+ if (!response) {
52
+ return 'unavailable';
53
+ }
54
+ if (response.accessPrivileges === 'limited') {
55
+ return 'limited';
56
+ }
57
+ if (response.status === 'granted') {
58
+ return 'granted';
59
+ }
60
+ if (response.status === 'denied') {
61
+ return response.canAskAgain ? 'denied' : 'blocked';
62
+ }
63
+ // 'undetermined' — never asked yet. Treated as 'denied' so callers using
64
+ // Permissions.ensure() correctly trigger a request() rather than stalling.
65
+ return 'denied';
66
+ };
67
+ const checkPermission = async kind => {
68
+ if (backend) {
69
+ return backend.check(kind);
70
+ }
71
+ const fns = resolveExpoModule(kind);
72
+ if (!fns) {
73
+ return 'unavailable';
74
+ }
75
+ try {
76
+ return toStatus(await fns.check());
77
+ } catch (error) {
78
+ _index.Logger.error(`[permissions] check(${kind}) failed`, error);
79
+ return 'unavailable';
80
+ }
81
+ };
82
+ const requestPermission = async kind => {
83
+ if (backend) {
84
+ return backend.request(kind);
85
+ }
86
+ const fns = resolveExpoModule(kind);
87
+ if (!fns) {
88
+ return 'unavailable';
89
+ }
90
+ try {
91
+ return toStatus(await fns.request());
92
+ } catch (error) {
93
+ _index.Logger.error(`[permissions] request(${kind}) failed`, error);
94
+ return 'unavailable';
95
+ }
96
+ };
97
+ const openAppSettings = async () => {
98
+ try {
99
+ await _reactNative.Linking.openSettings();
100
+ return true;
101
+ } catch (error) {
102
+ _index.Logger.error('[permissions] openAppSettings failed', error);
103
+ return false;
104
+ }
105
+ };
106
+
107
+ /**
108
+ * Cross-platform permissions wrapper. Maps an abstract `PermissionKind`
109
+ * (camera, photos, location, notifications, …) to whichever Expo adapter an
110
+ * app has registered by importing that kind's entry point — expo-camera,
111
+ * expo-image-picker, expo-location, expo-contacts, expo-calendar,
112
+ * expo-notifications, expo-media-library. An app imports only the entry
113
+ * points for the kinds it actually asks for.
114
+ */
115
+ const Permissions = exports.Permissions = {
116
+ check: checkPermission,
117
+ request: requestPermission,
118
+ /** Convenience: returns true when the permission is `granted` or `limited`. */
119
+ isAuthorized: async kind => {
120
+ const s = await checkPermission(kind);
121
+ return s === 'granted' || s === 'limited';
122
+ },
123
+ /** Convenience: check, and request only if not yet granted. */
124
+ ensure: async kind => {
125
+ const s = await checkPermission(kind);
126
+ if (s === 'granted' || s === 'limited' || s === 'blocked' || s === 'unavailable') {
127
+ return s;
128
+ }
129
+ return requestPermission(kind);
130
+ },
131
+ openSettings: openAppSettings
132
+ };
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _index = require("./index.js");
4
+ /** The one place `expo-location` is named. Import only if you use location/locationAlways. */
5
+ const m = require('expo-location');
6
+ (0, _index.registerPermissionAdapter)('location', {
7
+ check: m.getForegroundPermissionsAsync,
8
+ request: m.requestForegroundPermissionsAsync
9
+ });
10
+ (0, _index.registerPermissionAdapter)('locationAlways', {
11
+ check: m.getBackgroundPermissionsAsync,
12
+ request: m.requestBackgroundPermissionsAsync
13
+ });
14
+ //# sourceMappingURL=location.js.map
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ var _index = require("./index.js");
4
+ /** The one place `expo-media-library` is named. Import only if you use mediaLibrary. */
5
+ const m = require('expo-media-library');
6
+ (0, _index.registerPermissionAdapter)('mediaLibrary', {
7
+ check: m.getPermissionsAsync,
8
+ request: m.requestPermissionsAsync
9
+ });
10
+ //# sourceMappingURL=mediaLibrary.js.map