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