@webority/mobile-core 0.0.29 → 0.2.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 (242) hide show
  1. package/README.md +32 -0
  2. package/lib/commonjs/api/baseUrl.js +1 -34
  3. package/lib/commonjs/api/clientHeaders.js +1 -0
  4. package/lib/commonjs/api/curl.js +1 -109
  5. package/lib/commonjs/api/minAppVersion.js +1 -0
  6. package/lib/commonjs/api/multipart.js +1 -21
  7. package/lib/commonjs/api/publicClient.js +1 -79
  8. package/lib/commonjs/api/requestDefaults.js +1 -0
  9. package/lib/commonjs/api/responseBodyText.js +1 -0
  10. package/lib/commonjs/api/retry.js +1 -91
  11. package/lib/commonjs/api/tokenRefresh.js +1 -205
  12. package/lib/commonjs/api/userClient.js +1 -265
  13. package/lib/commonjs/auth/authStore.js +1 -265
  14. package/lib/commonjs/auth/index.js +1 -44
  15. package/lib/commonjs/auth/jwt.js +1 -112
  16. package/lib/commonjs/config/index.js +1 -72
  17. package/lib/commonjs/deepLink/index.js +1 -286
  18. package/lib/commonjs/download/adapters/expoFs.js +1 -69
  19. package/lib/commonjs/download/adapters/shared.js +1 -13
  20. package/lib/commonjs/download/index.js +1 -250
  21. package/lib/commonjs/errors/extractApiError.js +1 -0
  22. package/lib/commonjs/errors/index.js +1 -0
  23. package/lib/commonjs/formatters/currency.js +1 -70
  24. package/lib/commonjs/formatters/date.js +1 -167
  25. package/lib/commonjs/formatters/dateMath.js +1 -311
  26. package/lib/commonjs/formatters/formatConfig.js +1 -0
  27. package/lib/commonjs/formatters/house.js +1 -0
  28. package/lib/commonjs/formatters/index.js +1 -246
  29. package/lib/commonjs/formatters/initials.js +1 -32
  30. package/lib/commonjs/formatters/intlCache.js +1 -37
  31. package/lib/commonjs/formatters/number.js +1 -89
  32. package/lib/commonjs/formatters/phone.js +1 -369
  33. package/lib/commonjs/formatters/windowsToIanaTable.js +1 -164
  34. package/lib/commonjs/geolocation/adapters/expoLocation.js +1 -126
  35. package/lib/commonjs/geolocation/index.js +1 -355
  36. package/lib/commonjs/index.js +1 -644
  37. package/lib/commonjs/initSDK.js +1 -66
  38. package/lib/commonjs/initUserAuth.js +1 -37
  39. package/lib/commonjs/logger/crashlytics.js +1 -0
  40. package/lib/commonjs/logger/index.js +1 -301
  41. package/lib/commonjs/logger/redact.js +1 -50
  42. package/lib/commonjs/network/index.js +1 -31
  43. package/lib/commonjs/network/networkStatus.js +1 -171
  44. package/lib/commonjs/permissions/calendar.js +1 -14
  45. package/lib/commonjs/permissions/camera.js +1 -14
  46. package/lib/commonjs/permissions/contacts.js +1 -10
  47. package/lib/commonjs/permissions/index.js +1 -133
  48. package/lib/commonjs/permissions/location.js +1 -14
  49. package/lib/commonjs/permissions/mediaLibrary.js +1 -10
  50. package/lib/commonjs/permissions/notifications.js +1 -10
  51. package/lib/commonjs/permissions/photos.js +1 -14
  52. package/lib/commonjs/phone/countries.js +1 -265
  53. package/lib/commonjs/push/index.js +1 -61
  54. package/lib/commonjs/push/push.js +1 -468
  55. package/lib/commonjs/push/status.js +1 -0
  56. package/lib/commonjs/push/task.js +1 -43
  57. package/lib/commonjs/query/apiBaseQuery.js +1 -0
  58. package/lib/commonjs/query/createAppApi.js +1 -0
  59. package/lib/commonjs/query/index.js +1 -0
  60. package/lib/commonjs/query/listeners.js +1 -0
  61. package/lib/commonjs/query/paging.js +1 -0
  62. package/lib/commonjs/query/tags.js +1 -0
  63. package/lib/commonjs/redux/errorToastMiddleware.js +1 -0
  64. package/lib/commonjs/redux/index.js +1 -0
  65. package/lib/commonjs/redux/rootReducer.js +1 -0
  66. package/lib/commonjs/redux/serializableCheck.js +1 -0
  67. package/lib/commonjs/secureScreen/index.js +1 -0
  68. package/lib/commonjs/share/index.js +1 -70
  69. package/lib/commonjs/smsRetriever/index.js +1 -91
  70. package/lib/commonjs/specs/NativeSmsRetriever.js +1 -15
  71. package/lib/commonjs/sqlite/adapters/expo.js +1 -53
  72. package/lib/commonjs/sqlite/index.js +1 -604
  73. package/lib/commonjs/storage/index.js +1 -214
  74. package/lib/commonjs/types/axios.js +1 -4
  75. package/lib/commonjs/types/globals.d.js +1 -6
  76. package/lib/commonjs/utils/base64.js +1 -24
  77. package/lib/commonjs/utils/imageCompression.js +1 -389
  78. package/lib/commonjs/utils/index.js +1 -19
  79. package/lib/commonjs/validators/index.js +1 -227
  80. package/lib/commonjs/versionCheck/buildNumber.js +1 -0
  81. package/lib/commonjs/versionCheck/index.js +1 -419
  82. package/lib/module/api/baseUrl.js +1 -30
  83. package/lib/module/api/clientHeaders.js +1 -0
  84. package/lib/module/api/curl.js +1 -104
  85. package/lib/module/api/minAppVersion.js +1 -0
  86. package/lib/module/api/multipart.js +1 -16
  87. package/lib/module/api/publicClient.js +1 -75
  88. package/lib/module/api/requestDefaults.js +1 -0
  89. package/lib/module/api/responseBodyText.js +1 -0
  90. package/lib/module/api/retry.js +1 -85
  91. package/lib/module/api/tokenRefresh.js +1 -192
  92. package/lib/module/api/userClient.js +1 -243
  93. package/lib/module/auth/authStore.js +1 -257
  94. package/lib/module/auth/index.js +1 -5
  95. package/lib/module/auth/jwt.js +1 -106
  96. package/lib/module/config/index.js +1 -64
  97. package/lib/module/deepLink/index.js +1 -280
  98. package/lib/module/download/adapters/expoFs.js +1 -64
  99. package/lib/module/download/adapters/shared.js +1 -8
  100. package/lib/module/download/index.js +1 -242
  101. package/lib/module/errors/extractApiError.js +1 -0
  102. package/lib/module/errors/index.js +1 -0
  103. package/lib/module/formatters/currency.js +1 -65
  104. package/lib/module/formatters/date.js +1 -159
  105. package/lib/module/formatters/dateMath.js +1 -295
  106. package/lib/module/formatters/formatConfig.js +1 -0
  107. package/lib/module/formatters/house.js +1 -0
  108. package/lib/module/formatters/index.js +1 -9
  109. package/lib/module/formatters/initials.js +1 -27
  110. package/lib/module/formatters/intlCache.js +1 -30
  111. package/lib/module/formatters/number.js +1 -82
  112. package/lib/module/formatters/phone.js +1 -302
  113. package/lib/module/formatters/windowsToIanaTable.js +1 -160
  114. package/lib/module/geolocation/adapters/expoLocation.js +1 -121
  115. package/lib/module/geolocation/index.js +1 -347
  116. package/lib/module/index.js +1 -57
  117. package/lib/module/initSDK.js +1 -61
  118. package/lib/module/initUserAuth.js +1 -33
  119. package/lib/module/logger/crashlytics.js +1 -0
  120. package/lib/module/logger/index.js +1 -295
  121. package/lib/module/logger/redact.js +1 -44
  122. package/lib/module/network/index.js +1 -4
  123. package/lib/module/network/networkStatus.js +1 -161
  124. package/lib/module/permissions/calendar.js +1 -15
  125. package/lib/module/permissions/camera.js +1 -15
  126. package/lib/module/permissions/contacts.js +1 -11
  127. package/lib/module/permissions/index.js +1 -128
  128. package/lib/module/permissions/location.js +1 -15
  129. package/lib/module/permissions/mediaLibrary.js +1 -11
  130. package/lib/module/permissions/notifications.js +1 -11
  131. package/lib/module/permissions/photos.js +1 -15
  132. package/lib/module/phone/countries.js +1 -261
  133. package/lib/module/push/index.js +1 -4
  134. package/lib/module/push/push.js +1 -452
  135. package/lib/module/push/status.js +1 -0
  136. package/lib/module/push/task.js +1 -38
  137. package/lib/module/query/apiBaseQuery.js +1 -0
  138. package/lib/module/query/createAppApi.js +1 -0
  139. package/lib/module/query/index.js +1 -0
  140. package/lib/module/query/listeners.js +1 -0
  141. package/lib/module/query/paging.js +1 -0
  142. package/lib/module/query/tags.js +1 -0
  143. package/lib/module/redux/errorToastMiddleware.js +1 -0
  144. package/lib/module/redux/index.js +1 -0
  145. package/lib/module/redux/rootReducer.js +1 -0
  146. package/lib/module/redux/serializableCheck.js +1 -0
  147. package/lib/module/secureScreen/index.js +1 -0
  148. package/lib/module/share/index.js +1 -64
  149. package/lib/module/smsRetriever/index.js +1 -86
  150. package/lib/module/specs/NativeSmsRetriever.js +1 -13
  151. package/lib/module/sqlite/adapters/expo.js +1 -48
  152. package/lib/module/sqlite/index.js +1 -594
  153. package/lib/module/storage/index.js +1 -208
  154. package/lib/module/types/axios.js +1 -4
  155. package/lib/module/types/globals.d.js +1 -10
  156. package/lib/module/utils/base64.js +1 -19
  157. package/lib/module/utils/imageCompression.js +1 -383
  158. package/lib/module/utils/index.js +1 -4
  159. package/lib/module/validators/index.js +1 -205
  160. package/lib/module/versionCheck/buildNumber.js +1 -0
  161. package/lib/module/versionCheck/index.js +1 -413
  162. package/lib/typescript/commonjs/api/clientHeaders.d.ts +25 -0
  163. package/lib/typescript/commonjs/api/minAppVersion.d.ts +24 -0
  164. package/lib/typescript/commonjs/api/requestDefaults.d.ts +21 -0
  165. package/lib/typescript/commonjs/api/responseBodyText.d.ts +6 -0
  166. package/lib/typescript/commonjs/api/retry.d.ts +23 -9
  167. package/lib/typescript/commonjs/api/tokenRefresh.d.ts +14 -2
  168. package/lib/typescript/commonjs/api/userClient.d.ts +1 -1
  169. package/lib/typescript/commonjs/auth/authStore.d.ts +76 -0
  170. package/lib/typescript/commonjs/auth/index.d.ts +2 -2
  171. package/lib/typescript/commonjs/config/index.d.ts +31 -2
  172. package/lib/typescript/commonjs/errors/extractApiError.d.ts +69 -0
  173. package/lib/typescript/commonjs/errors/index.d.ts +3 -0
  174. package/lib/typescript/commonjs/formatters/currency.d.ts +22 -7
  175. package/lib/typescript/commonjs/formatters/date.d.ts +13 -13
  176. package/lib/typescript/commonjs/formatters/dateMath.d.ts +4 -2
  177. package/lib/typescript/commonjs/formatters/formatConfig.d.ts +48 -0
  178. package/lib/typescript/commonjs/formatters/house.d.ts +143 -0
  179. package/lib/typescript/commonjs/formatters/index.d.ts +4 -0
  180. package/lib/typescript/commonjs/formatters/number.d.ts +15 -5
  181. package/lib/typescript/commonjs/index.d.ts +26 -8
  182. package/lib/typescript/commonjs/initSDK.d.ts +18 -6
  183. package/lib/typescript/commonjs/initUserAuth.d.ts +29 -0
  184. package/lib/typescript/commonjs/logger/crashlytics.d.ts +31 -0
  185. package/lib/typescript/commonjs/logger/index.d.ts +17 -0
  186. package/lib/typescript/commonjs/push/index.d.ts +3 -1
  187. package/lib/typescript/commonjs/push/push.d.ts +1 -1
  188. package/lib/typescript/commonjs/push/status.d.ts +9 -0
  189. package/lib/typescript/commonjs/query/apiBaseQuery.d.ts +55 -0
  190. package/lib/typescript/commonjs/query/createAppApi.d.ts +21 -0
  191. package/lib/typescript/commonjs/query/index.d.ts +9 -0
  192. package/lib/typescript/commonjs/query/listeners.d.ts +11 -0
  193. package/lib/typescript/commonjs/query/paging.d.ts +42 -0
  194. package/lib/typescript/commonjs/query/tags.d.ts +31 -0
  195. package/lib/typescript/commonjs/redux/errorToastMiddleware.d.ts +51 -0
  196. package/lib/typescript/commonjs/redux/index.d.ts +6 -0
  197. package/lib/typescript/commonjs/redux/rootReducer.d.ts +19 -0
  198. package/lib/typescript/commonjs/redux/serializableCheck.d.ts +14 -0
  199. package/lib/typescript/commonjs/secureScreen/index.d.ts +25 -0
  200. package/lib/typescript/commonjs/versionCheck/buildNumber.d.ts +14 -0
  201. package/lib/typescript/commonjs/versionCheck/index.d.ts +28 -17
  202. package/lib/typescript/module/api/clientHeaders.d.ts +25 -0
  203. package/lib/typescript/module/api/minAppVersion.d.ts +24 -0
  204. package/lib/typescript/module/api/requestDefaults.d.ts +21 -0
  205. package/lib/typescript/module/api/responseBodyText.d.ts +6 -0
  206. package/lib/typescript/module/api/retry.d.ts +23 -9
  207. package/lib/typescript/module/api/tokenRefresh.d.ts +14 -2
  208. package/lib/typescript/module/api/userClient.d.ts +1 -1
  209. package/lib/typescript/module/auth/authStore.d.ts +76 -0
  210. package/lib/typescript/module/auth/index.d.ts +2 -2
  211. package/lib/typescript/module/config/index.d.ts +31 -2
  212. package/lib/typescript/module/errors/extractApiError.d.ts +69 -0
  213. package/lib/typescript/module/errors/index.d.ts +3 -0
  214. package/lib/typescript/module/formatters/currency.d.ts +22 -7
  215. package/lib/typescript/module/formatters/date.d.ts +13 -13
  216. package/lib/typescript/module/formatters/dateMath.d.ts +4 -2
  217. package/lib/typescript/module/formatters/formatConfig.d.ts +48 -0
  218. package/lib/typescript/module/formatters/house.d.ts +143 -0
  219. package/lib/typescript/module/formatters/index.d.ts +4 -0
  220. package/lib/typescript/module/formatters/number.d.ts +15 -5
  221. package/lib/typescript/module/index.d.ts +26 -8
  222. package/lib/typescript/module/initSDK.d.ts +18 -6
  223. package/lib/typescript/module/initUserAuth.d.ts +29 -0
  224. package/lib/typescript/module/logger/crashlytics.d.ts +31 -0
  225. package/lib/typescript/module/logger/index.d.ts +17 -0
  226. package/lib/typescript/module/push/index.d.ts +3 -1
  227. package/lib/typescript/module/push/push.d.ts +1 -1
  228. package/lib/typescript/module/push/status.d.ts +9 -0
  229. package/lib/typescript/module/query/apiBaseQuery.d.ts +55 -0
  230. package/lib/typescript/module/query/createAppApi.d.ts +21 -0
  231. package/lib/typescript/module/query/index.d.ts +9 -0
  232. package/lib/typescript/module/query/listeners.d.ts +11 -0
  233. package/lib/typescript/module/query/paging.d.ts +42 -0
  234. package/lib/typescript/module/query/tags.d.ts +31 -0
  235. package/lib/typescript/module/redux/errorToastMiddleware.d.ts +51 -0
  236. package/lib/typescript/module/redux/index.d.ts +6 -0
  237. package/lib/typescript/module/redux/rootReducer.d.ts +19 -0
  238. package/lib/typescript/module/redux/serializableCheck.d.ts +14 -0
  239. package/lib/typescript/module/secureScreen/index.d.ts +25 -0
  240. package/lib/typescript/module/versionCheck/buildNumber.d.ts +14 -0
  241. package/lib/typescript/module/versionCheck/index.d.ts +28 -17
  242. package/package.json +52 -5
@@ -1,468 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.usePush = exports.toPushAction = exports.toNotificationActions = exports.setPushImplementation = exports.setCategories = exports.setBadgeCount = exports.routeTaskPayload = exports.resolveModules = exports.onAction = exports.notifyLocal = exports.initPush = exports.enablePush = exports.disablePush = void 0;
7
- var _react = require("react");
8
- var _reactNative = require("react-native");
9
- var _index = require("../logger/index.js");
10
- /** A button on a notification category. */
11
-
12
- /** A set of buttons a push names through its category id. */
13
-
14
- /** A button tap on a notification. */
15
-
16
- /** The slice of expo-notifications this module calls, so the optional peer stays untyped at build. */
17
-
18
- let override = null;
19
-
20
- /** Expo modules resolved once; null when push cannot work in this build. */
21
- let resolved;
22
-
23
- /**
24
- * Replace the native modules. For tests and the showcase, to reach paths a
25
- * real device never takes; an injected backend is taken on trust, Expo Go
26
- * included. Pass `null` to restore expo-notifications.
27
- */
28
- const setPushImplementation = impl => {
29
- override = impl;
30
- };
31
-
32
- /**
33
- * The only place expo-notifications and expo-application are named. Expo Go is
34
- * checked first because expo-notifications refuses remote push there and its
35
- * import throws on Android. Exported for `./task`; not on the `/push` entry.
36
- */
37
- exports.setPushImplementation = setPushImplementation;
38
- const resolveModules = () => {
39
- if (override) {
40
- return override;
41
- }
42
- if (resolved !== undefined) {
43
- return resolved;
44
- }
45
- try {
46
- const expo = require('expo');
47
- if (expo.isRunningInExpoGo()) {
48
- resolved = null;
49
- return resolved;
50
- }
51
- const notifications = require('expo-notifications');
52
- const application = require('expo-application');
53
- resolved = {
54
- notifications,
55
- applicationId: application.applicationId
56
- };
57
- } catch (error) {
58
- _index.Logger.warn('[push] expo-notifications is not available; push is off', error);
59
- resolved = null;
60
- }
61
- return resolved;
62
- };
63
- exports.resolveModules = resolveModules;
64
- let state = {
65
- status: 'unknown',
66
- enabled: false
67
- };
68
- const subscribers = new Set();
69
- const setState = next => {
70
- state = {
71
- ...state,
72
- ...next
73
- };
74
- for (const notify of subscribers) {
75
- notify();
76
- }
77
- };
78
- let config = null;
79
- let channelsReady = Promise.resolve();
80
- let tokenSubscription = null;
81
- let actionHandler = null;
82
- let listening = false;
83
- /** Responses that arrived before anything could handle them, e.g. the launching tap before initPush. */
84
- const pendingResponses = [];
85
- /** Response key to when it was routed. */
86
- const routedAt = new Map();
87
-
88
- /**
89
- * The cold-start read, the live listener and, on Android, the background task
90
- * can each report the same response a moment apart.
91
- */
92
- const REPEAT_WINDOW_MS = 10_000;
93
- const requireConfig = () => {
94
- if (!config) {
95
- throw new Error('[@webority/mobile-core] call initPush before enablePush or disablePush.');
96
- }
97
- return config;
98
- };
99
- const toPermissionStatus = response => {
100
- if (response.granted) {
101
- return 'granted';
102
- }
103
- return response.status === 'denied' ? 'denied' : 'unknown';
104
- };
105
-
106
- /** Push data travels as strings; iOS can hand back numbers or objects for top-level keys. */
107
- const toStringData = data => {
108
- const out = {};
109
- for (const [key, value] of Object.entries(data ?? {})) {
110
- if (value === null || value === undefined) {
111
- continue;
112
- }
113
- out[key] = typeof value === 'object' ? JSON.stringify(value) : String(value);
114
- }
115
- return out;
116
- };
117
- const contentData = response => {
118
- const content = response.notification.request.content;
119
- if (content.data) {
120
- return toStringData(content.data);
121
- }
122
- if (typeof content.dataString === 'string') {
123
- try {
124
- return toStringData(JSON.parse(content.dataString));
125
- } catch (error) {
126
- _index.Logger.error('[push] notification data is not JSON', error);
127
- }
128
- }
129
- return {};
130
- };
131
-
132
- /**
133
- * expo-notifications fills iOS `content.data` only from a `body` object, but our
134
- * servers send raw APNs with the app's keys at the top level beside `aps`.
135
- */
136
- const triggerData = response => {
137
- const trigger = response.notification.request.trigger;
138
- const extra = {
139
- ...(trigger?.remoteMessage?.data ?? {})
140
- };
141
- for (const [key, value] of Object.entries(trigger?.payload ?? {})) {
142
- // A `body` object is what expo already turned into content.data.
143
- if (key === 'aps' || key === 'body' && typeof value === 'object') {
144
- continue;
145
- }
146
- extra[key] = value;
147
- }
148
- return toStringData(extra);
149
- };
150
-
151
- /** The push's own data merged over the raw remote payload's keys, so content.data wins a conflict. */
152
- const responseData = response => ({
153
- ...triggerData(response),
154
- ...contentData(response)
155
- });
156
- const toPushAction = response => ({
157
- actionId: response.actionIdentifier,
158
- ...(response.userText ? {
159
- userText: response.userText
160
- } : {}),
161
- data: responseData(response),
162
- notificationId: response.notification.request.identifier
163
- });
164
- exports.toPushAction = toPushAction;
165
- const toNotificationActions = actions => actions.map(action => ({
166
- identifier: action.id,
167
- buttonTitle: action.title,
168
- ...(action.textInput ? {
169
- textInput: {
170
- submitButtonTitle: action.textInput.submitTitle,
171
- placeholder: action.textInput.placeholder
172
- }
173
- } : {}),
174
- options: {
175
- opensAppToForeground: action.opensApp ?? true,
176
- isDestructive: action.destructive ?? false,
177
- isAuthenticationRequired: action.authenticationRequired ?? false
178
- }
179
- }));
180
-
181
- /**
182
- * Sends a button tap to the action handler and a plain tap to `onOpen`. A
183
- * button tap with no action handler opens like a plain tap. Resolves once the
184
- * handler has finished, so a background task stays alive for its request.
185
- */
186
- exports.toNotificationActions = toNotificationActions;
187
- const routeResponse = async (m, response) => {
188
- const key = `${response.notification.request.identifier}:${response.actionIdentifier}`;
189
- const last = routedAt.get(key);
190
- if (last !== undefined && Date.now() - last < REPEAT_WINDOW_MS) {
191
- return;
192
- }
193
- const isAction = response.actionIdentifier !== m.DEFAULT_ACTION_IDENTIFIER;
194
- if (isAction && actionHandler) {
195
- routedAt.set(key, Date.now());
196
- try {
197
- await actionHandler(toPushAction(response));
198
- } catch (error) {
199
- _index.Logger.error('[push] onAction threw', error);
200
- }
201
- return;
202
- }
203
- if (!config) {
204
- pendingResponses.push(response);
205
- return;
206
- }
207
- routedAt.set(key, Date.now());
208
- try {
209
- config.onOpen(responseData(response));
210
- } catch (error) {
211
- _index.Logger.error('[push] onOpen threw', error);
212
- }
213
- };
214
- const drainPending = async m => {
215
- const queued = pendingResponses.splice(0);
216
- for (const response of queued) {
217
- await routeResponse(m, response);
218
- }
219
- };
220
-
221
- /** Follows taps and button taps, including the one that launched the app. Wired once per process. */
222
- const listenForResponses = m => {
223
- if (listening) {
224
- return;
225
- }
226
- listening = true;
227
- m.addNotificationResponseReceivedListener(response => {
228
- void routeResponse(m, response);
229
- });
230
- void m.getLastNotificationResponseAsync().then(async response => {
231
- if (response) {
232
- await routeResponse(m, response);
233
- }
234
- return m.clearLastNotificationResponseAsync?.();
235
- }).catch(error => _index.Logger.error('[push] reading the launch notification failed', error));
236
- };
237
-
238
- /** The payload of the background notification task: routes button taps, ignores received pushes. */
239
- const routeTaskPayload = async payload => {
240
- const mods = resolveModules();
241
- const response = payload;
242
- if (!mods || typeof response?.actionIdentifier !== 'string' || typeof response.notification?.request?.identifier !== 'string') {
243
- return;
244
- }
245
- await routeResponse(mods.notifications, response);
246
- };
247
- exports.routeTaskPayload = routeTaskPayload;
248
- const createChannels = async (m, channels) => {
249
- for (const channel of channels) {
250
- try {
251
- await m.setNotificationChannelAsync(channel.id, {
252
- name: channel.name,
253
- importance: channel.importance === 'high' ? m.AndroidImportance.HIGH : m.AndroidImportance.DEFAULT
254
- });
255
- } catch (error) {
256
- _index.Logger.error(`[push] creating channel ${channel.id} failed`, error);
257
- }
258
- }
259
- };
260
- const toDevice = async (token, applicationId) => {
261
- const platform = token.type === 'android' ? 'Fcm' : token.type === 'ios' ? 'Apns' : null;
262
- if (!platform || typeof token.data !== 'string') {
263
- return null;
264
- }
265
- if (!applicationId) {
266
- throw new Error('[@webority/mobile-core] push needs the app bundle id from expo-application.');
267
- }
268
- const installationId = await requireConfig().getInstallationId();
269
- return {
270
- installationId,
271
- platform,
272
- token: token.data,
273
- appId: applicationId
274
- };
275
- };
276
-
277
- /**
278
- * Wires push at startup: the foreground handler, Android channels, and tap
279
- * handling, including the tap that launched the app. Calling it again only
280
- * replaces the config.
281
- */
282
- const initPush = next => {
283
- const first = config === null;
284
- config = next;
285
- if (!first) {
286
- return;
287
- }
288
- const mods = resolveModules();
289
- if (!mods) {
290
- setState({
291
- status: 'unavailable'
292
- });
293
- return;
294
- }
295
- const m = mods.notifications;
296
- m.setNotificationHandler({
297
- handleNotification: async () => {
298
- const show = config?.showInForeground?.() ?? true;
299
- return {
300
- shouldShowBanner: show,
301
- shouldShowList: show,
302
- shouldPlaySound: show && (config?.playSoundInForeground?.() ?? true),
303
- shouldSetBadge: true
304
- };
305
- }
306
- });
307
- if (_reactNative.Platform.OS === 'android' && next.androidChannels?.length) {
308
- channelsReady = createChannels(m, next.androidChannels);
309
- }
310
- listenForResponses(m);
311
- void drainPending(m);
312
- void m.getPermissionsAsync().then(response => setState({
313
- status: toPermissionStatus(response)
314
- })).catch(error => _index.Logger.error('[push] permission check failed', error));
315
- };
316
-
317
- /**
318
- * Asks for permission, reads the native device token and registers it through
319
- * `config.register`, then re-registers whenever the OS rotates the token.
320
- */
321
- exports.initPush = initPush;
322
- const enablePush = async () => {
323
- requireConfig();
324
- const mods = resolveModules();
325
- if (!mods) {
326
- setState({
327
- status: 'unavailable'
328
- });
329
- return 'unavailable';
330
- }
331
- const m = mods.notifications;
332
-
333
- // Android 13 shows the permission prompt only once a channel exists.
334
- await channelsReady;
335
- let permission = await m.getPermissionsAsync();
336
- if (!permission.granted) {
337
- permission = await m.requestPermissionsAsync();
338
- }
339
- if (!permission.granted) {
340
- setState({
341
- status: 'denied'
342
- });
343
- return 'denied';
344
- }
345
- const device = await toDevice(await m.getDevicePushTokenAsync(), mods.applicationId);
346
- if (!device) {
347
- setState({
348
- status: 'unavailable'
349
- });
350
- return 'unavailable';
351
- }
352
- await requireConfig().register(device);
353
- tokenSubscription?.remove();
354
- tokenSubscription = m.addPushTokenListener(token => {
355
- void toDevice(token, mods.applicationId).then(next => next ? requireConfig().register(next) : undefined).catch(error => _index.Logger.error('[push] re-registering a new token failed', error));
356
- });
357
- setState({
358
- status: 'granted',
359
- enabled: true
360
- });
361
- return 'granted';
362
- };
363
-
364
- /**
365
- * Unregisters the device through `config.unregister` and stops following token
366
- * changes. Taps on notifications already delivered still reach `onOpen`.
367
- */
368
- exports.enablePush = enablePush;
369
- const disablePush = async () => {
370
- const current = requireConfig();
371
- // Stop following token changes first, so a failed unregister cannot re-register the phone.
372
- tokenSubscription?.remove();
373
- tokenSubscription = null;
374
- setState({
375
- enabled: false
376
- });
377
- await current.unregister(await current.getInstallationId());
378
- };
379
-
380
- /** Sets the app icon badge; a no-op where push is unavailable or the launcher has no badge. */
381
- exports.disablePush = disablePush;
382
- const setBadgeCount = async count => {
383
- const mods = resolveModules();
384
- if (!mods) {
385
- return;
386
- }
387
- await mods.notifications.setBadgeCountAsync(count);
388
- };
389
-
390
- /**
391
- * Registers the button sets a push can name by category id. Call it at every
392
- * start, with the same ids on both platforms. On Android the buttons show only
393
- * on notifications expo-notifications draws, such as `notifyLocal`.
394
- */
395
- exports.setBadgeCount = setBadgeCount;
396
- const setCategories = async categories => {
397
- const mods = resolveModules();
398
- if (!mods) {
399
- return;
400
- }
401
- for (const category of categories) {
402
- await mods.notifications.setNotificationCategoryAsync(category.id, toNotificationActions(category.actions));
403
- }
404
- };
405
-
406
- /**
407
- * Handles button taps while JavaScript is running; a plain tap still goes to
408
- * `onOpen`. For taps on a killed app use `definePushActionTask` from
409
- * `/push/task`, which sets this handler too. Returns a function that removes it.
410
- */
411
- exports.setCategories = setCategories;
412
- const onAction = handler => {
413
- actionHandler = handler;
414
- const mods = resolveModules();
415
- if (mods) {
416
- listenForResponses(mods.notifications);
417
- void drainPending(mods.notifications);
418
- }
419
- return () => {
420
- if (actionHandler === handler) {
421
- actionHandler = null;
422
- }
423
- };
424
- };
425
-
426
- /** Shows a notification from the phone itself, for example when a button's request failed. */
427
- exports.onAction = onAction;
428
- const notifyLocal = async ({
429
- title,
430
- body,
431
- data
432
- }) => {
433
- const mods = resolveModules();
434
- if (!mods) {
435
- return;
436
- }
437
- await mods.notifications.scheduleNotificationAsync({
438
- content: {
439
- title,
440
- body,
441
- data: data ?? {}
442
- },
443
- trigger: null
444
- });
445
- };
446
- exports.notifyLocal = notifyLocal;
447
- const subscribe = notify => {
448
- subscribers.add(notify);
449
- return () => {
450
- subscribers.delete(notify);
451
- };
452
- };
453
- const getSnapshot = () => state;
454
- const enable = async () => {
455
- await enablePush();
456
- };
457
-
458
- /** Push status for a settings switch, re-rendering when it changes. */
459
- const usePush = () => {
460
- const snapshot = (0, _react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
461
- return {
462
- ...snapshot,
463
- enable,
464
- disable: disablePush
465
- };
466
- };
467
- exports.usePush = usePush;
468
- //# sourceMappingURL=push.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.usePush=exports.toPushAction=exports.toNotificationActions=exports.setPushImplementation=exports.setCategories=exports.setBadgeCount=exports.routeTaskPayload=exports.resolveModules=exports.onAction=exports.notifyLocal=exports.initPush=exports.enablePush=exports.disablePush=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../logger/index.js");let resolved,override=null;const setPushImplementation=e=>{override=e};exports.setPushImplementation=setPushImplementation;const resolveModules=()=>{if(override)return override;if(void 0!==resolved)return resolved;try{if(require("expo").isRunningInExpoGo())return resolved=null,resolved;const e=require("expo-notifications"),t=require("expo-application");resolved={notifications:e,applicationId:t.applicationId}}catch(e){_index.Logger.warn("[push] expo-notifications is not available; push is off",e),resolved=null}return resolved};exports.resolveModules=resolveModules;let state={status:"unknown",enabled:!1};const subscribers=new Set,setState=e=>{state={...state,...e};for(const e of subscribers)e()};let config=null,channelsReady=Promise.resolve(),tokenSubscription=null,actionHandler=null,listening=!1;const pendingResponses=[],routedAt=new Map,REPEAT_WINDOW_MS=1e4,requireConfig=()=>{if(!config)throw new Error("[@webority/mobile-core] call initPush before enablePush or disablePush.");return config},toPermissionStatus=e=>e.granted?"granted":"denied"===e.status?"denied":"unknown",toStringData=e=>{const t={};for(const[n,o]of Object.entries(e??{}))null!=o&&(t[n]="object"==typeof o?JSON.stringify(o):String(o));return t},contentData=e=>{const t=e.notification.request.content;if(t.data)return toStringData(t.data);if("string"==typeof t.dataString)try{return toStringData(JSON.parse(t.dataString))}catch(e){_index.Logger.error("[push] notification data is not JSON",e)}return{}},triggerData=e=>{const t=e.notification.request.trigger,n={...t?.remoteMessage?.data??{}};for(const[e,o]of Object.entries(t?.payload??{}))"aps"===e||"body"===e&&"object"==typeof o||(n[e]=o);return toStringData(n)},responseData=e=>({...triggerData(e),...contentData(e)}),toPushAction=e=>({actionId:e.actionIdentifier,...e.userText?{userText:e.userText}:{},data:responseData(e),notificationId:e.notification.request.identifier});exports.toPushAction=toPushAction;const toNotificationActions=e=>e.map(e=>({identifier:e.id,buttonTitle:e.title,...e.textInput?{textInput:{submitButtonTitle:e.textInput.submitTitle,placeholder:e.textInput.placeholder}}:{},options:{opensAppToForeground:e.opensApp??!0,isDestructive:e.destructive??!1,isAuthenticationRequired:e.authenticationRequired??!1}}));exports.toNotificationActions=toNotificationActions;const routeResponse=async(e,t)=>{const n=`${t.notification.request.identifier}:${t.actionIdentifier}`,o=routedAt.get(n);if(void 0!==o&&Date.now()-o<1e4)return;if(t.actionIdentifier!==e.DEFAULT_ACTION_IDENTIFIER&&actionHandler){routedAt.set(n,Date.now());try{await actionHandler(toPushAction(t))}catch(e){_index.Logger.error("[push] onAction threw",e)}}else if(config){routedAt.set(n,Date.now());try{config.onOpen(responseData(t))}catch(e){_index.Logger.error("[push] onOpen threw",e)}}else pendingResponses.push(t)},drainPending=async e=>{const t=pendingResponses.splice(0);for(const n of t)await routeResponse(e,n)},listenForResponses=e=>{listening||(listening=!0,e.addNotificationResponseReceivedListener(t=>{routeResponse(e,t)}),e.getLastNotificationResponseAsync().then(async t=>(t&&await routeResponse(e,t),e.clearLastNotificationResponseAsync?.())).catch(e=>_index.Logger.error("[push] reading the launch notification failed",e)))},routeTaskPayload=async e=>{const t=resolveModules(),n=e;t&&"string"==typeof n?.actionIdentifier&&"string"==typeof n.notification?.request?.identifier&&await routeResponse(t.notifications,n)};exports.routeTaskPayload=routeTaskPayload;const createChannels=async(e,t)=>{for(const n of t)try{await e.setNotificationChannelAsync(n.id,{name:n.name,importance:"high"===n.importance?e.AndroidImportance.HIGH:e.AndroidImportance.DEFAULT})}catch(e){_index.Logger.error(`[push] creating channel ${n.id} failed`,e)}},toDevice=async(e,t)=>{const n="android"===e.type?"Fcm":"ios"===e.type?"Apns":null;if(!n||"string"!=typeof e.data)return null;if(!t)throw new Error("[@webority/mobile-core] push needs the app bundle id from expo-application.");return{installationId:await requireConfig().getInstallationId(),platform:n,token:e.data,appId:t}},initPush=e=>{const t=null===config;if(config=e,!t)return;const n=resolveModules();if(!n)return void setState({status:"unavailable"});const o=n.notifications;o.setNotificationHandler({handleNotification:async()=>{const e=config?.showInForeground?.()??!0;return{shouldShowBanner:e,shouldShowList:e,shouldPlaySound:e&&(config?.playSoundInForeground?.()??!0),shouldSetBadge:!0}}}),"android"===_reactNative.Platform.OS&&e.androidChannels?.length&&(channelsReady=createChannels(o,e.androidChannels)),listenForResponses(o),drainPending(o),o.getPermissionsAsync().then(e=>setState({status:toPermissionStatus(e)})).catch(e=>_index.Logger.error("[push] permission check failed",e))};exports.initPush=initPush;let registering=null,registeredKey=null;const registerOnce=e=>{const t=JSON.stringify(e);if(registering?.key===t)return registering.promise;const n=requireConfig().register(e).then(()=>{registeredKey=t}).finally(()=>{registering?.promise===n&&(registering=null)});return registering={key:t,promise:n},n},enablePush=async()=>{requireConfig();const e=resolveModules();if(!e)return setState({status:"unavailable"}),"unavailable";const t=e.notifications;await channelsReady;let n=await t.getPermissionsAsync();if(n.granted||(n=await t.requestPermissionsAsync()),!n.granted)return setState({status:"denied"}),"denied";const o=await toDevice(await t.getDevicePushTokenAsync(),e.applicationId);return o?(await registerOnce(o),tokenSubscription?.remove(),tokenSubscription=t.addPushTokenListener(t=>{toDevice(t,e.applicationId).then(e=>e&&JSON.stringify(e)!==registeredKey?registerOnce(e):void 0).catch(e=>_index.Logger.error("[push] re-registering a new token failed",e))}),setState({status:"granted",enabled:!0}),"granted"):(setState({status:"unavailable"}),"unavailable")};exports.enablePush=enablePush;const disablePush=async()=>{const e=requireConfig();tokenSubscription?.remove(),tokenSubscription=null,registeredKey=null,setState({enabled:!1}),await e.unregister(await e.getInstallationId())};exports.disablePush=disablePush;const setBadgeCount=async e=>{const t=resolveModules();t&&await t.notifications.setBadgeCountAsync(e)};exports.setBadgeCount=setBadgeCount;const setCategories=async e=>{const t=resolveModules();if(t)for(const n of e)await t.notifications.setNotificationCategoryAsync(n.id,toNotificationActions(n.actions))};exports.setCategories=setCategories;const onAction=e=>{actionHandler=e;const t=resolveModules();return t&&(listenForResponses(t.notifications),drainPending(t.notifications)),()=>{actionHandler===e&&(actionHandler=null)}};exports.onAction=onAction;const notifyLocal=async({title:e,body:t,data:n})=>{const o=resolveModules();o&&await o.notifications.scheduleNotificationAsync({content:{title:e,body:t,data:n??{}},trigger:null})};exports.notifyLocal=notifyLocal;const subscribe=e=>(subscribers.add(e),()=>{subscribers.delete(e)}),getSnapshot=()=>state,enable=async()=>{await enablePush()},usePush=()=>({...(0,_react.useSyncExternalStore)(subscribe,getSnapshot,getSnapshot),enable:enable,disable:disablePush});exports.usePush=usePush;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.PUSH_STATUS=void 0;const PUSH_STATUS=exports.PUSH_STATUS={unknown:"unknown",granted:"granted",denied:"denied",unavailable:"unavailable"};
@@ -1,43 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.definePushActionTask = void 0;
7
- var _reactNative = require("react-native");
8
- var _index = require("../logger/index.js");
9
- var _push = require("./push.js");
10
- const PUSH_ACTION_TASK = 'webority-push-action';
11
- /**
12
- * Handles notification button taps in every app state, the killed app
13
- * included. Call it once at module scope in the app's entry file (index.js),
14
- * before the root component registers: a tap on a killed app starts the
15
- * JavaScript bundle without the UI, so nothing later in the app runs.
16
- *
17
- * Android runs the handler from a background notification task
18
- * (expo-task-manager). iOS has no such task for button taps: it launches the
19
- * app in the background and the response reaches the listener this sets up.
20
- * The handler's promise is awaited, so a request it makes can finish first.
21
- */
22
- const definePushActionTask = handler => {
23
- (0, _push.onAction)(handler);
24
- const mods = (0, _push.resolveModules)();
25
- if (!mods || _reactNative.Platform.OS !== 'android') {
26
- return;
27
- }
28
- /** The one place `expo-task-manager` is named. Import `/push/task` only if you use button taps. */
29
- const taskManager = require('expo-task-manager');
30
- taskManager.defineTask(PUSH_ACTION_TASK, async ({
31
- data,
32
- error
33
- }) => {
34
- if (error) {
35
- _index.Logger.error('[push] the notification task failed', error);
36
- return;
37
- }
38
- await (0, _push.routeTaskPayload)(data);
39
- });
40
- void mods.notifications.registerTaskAsync(PUSH_ACTION_TASK).catch(registerError => _index.Logger.error('[push] registering the notification task failed', registerError));
41
- };
42
- exports.definePushActionTask = definePushActionTask;
43
- //# sourceMappingURL=task.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.definePushActionTask=void 0;var _reactNative=require("react-native"),_index=require("../logger/index.js"),_push=require("./push.js");const PUSH_ACTION_TASK="webority-push-action",definePushActionTask=e=>{(0,_push.onAction)(e);const i=(0,_push.resolveModules)();if(!i||"android"!==_reactNative.Platform.OS)return;require("expo-task-manager").defineTask(PUSH_ACTION_TASK,async({data:e,error:i})=>{i?_index.Logger.error("[push] the notification task failed",i):await(0,_push.routeTaskPayload)(e)}),i.notifications.registerTaskAsync(PUSH_ACTION_TASK).catch(e=>_index.Logger.error("[push] registering the notification task failed",e))};exports.definePushActionTask=definePushActionTask;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createApiBaseQuery=void 0;var _axios=_interopRequireDefault(require("axios")),_index=require("../errors/index.js");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}const createApiBaseQuery=({client:e,publicClient:t})=>async(r,{signal:s},a)=>{const i="string"==typeof r?{url:r}:r,u=i.silent??a?.silent??!1;if(i.public&&!t)throw new Error(`createApiBaseQuery: "${i.url}" is marked public but no publicClient was passed.`);const n=i.public?t:e,o={url:i.url,method:i.method??"GET",data:i.data,params:i.params,headers:i.headers,responseType:i.responseType,timeout:i.timeout,signal:s};try{const e=await n.request(o);return{data:e.data,meta:{silent:u,status:e.status}}}catch(e){const t=(0,_index.extractApiError)(e),r=_axios.default.isCancel(e);return{error:t,meta:{silent:u||r,status:t.status}}}};exports.createApiBaseQuery=createApiBaseQuery;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createAppApi=exports.APP_API_DEFAULTS=void 0;var _react=require("@reduxjs/toolkit/query/react");const APP_API_DEFAULTS=exports.APP_API_DEFAULTS={keepUnusedDataFor:60,refetchOnReconnect:!0,refetchOnFocus:!0},createAppApi=e=>(0,_react.createApi)({...APP_API_DEFAULTS,...e});exports.createAppApi=createAppApi;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"APP_API_DEFAULTS",{enumerable:!0,get:function(){return _createAppApi.APP_API_DEFAULTS}}),Object.defineProperty(exports,"LIST_TAG_ID",{enumerable:!0,get:function(){return _tags.LIST_TAG_ID}}),Object.defineProperty(exports,"buildListQuery",{enumerable:!0,get:function(){return _paging.buildListQuery}}),Object.defineProperty(exports,"createApiBaseQuery",{enumerable:!0,get:function(){return _apiBaseQuery.createApiBaseQuery}}),Object.defineProperty(exports,"createAppApi",{enumerable:!0,get:function(){return _createAppApi.createAppApi}}),Object.defineProperty(exports,"getNextPageParam",{enumerable:!0,get:function(){return _paging.getNextPageParam}}),Object.defineProperty(exports,"getPreviousPageParam",{enumerable:!0,get:function(){return _paging.getPreviousPageParam}}),Object.defineProperty(exports,"hasNextPage",{enumerable:!0,get:function(){return _paging.hasNextPage}}),Object.defineProperty(exports,"hasPreviousPage",{enumerable:!0,get:function(){return _paging.hasPreviousPage}}),Object.defineProperty(exports,"itemTag",{enumerable:!0,get:function(){return _tags.itemTag}}),Object.defineProperty(exports,"listTag",{enumerable:!0,get:function(){return _tags.listTag}}),Object.defineProperty(exports,"providesList",{enumerable:!0,get:function(){return _tags.providesList}}),Object.defineProperty(exports,"providesPagedList",{enumerable:!0,get:function(){return _tags.providesPagedList}}),Object.defineProperty(exports,"setupApiListeners",{enumerable:!0,get:function(){return _listeners.setupApiListeners}});var _apiBaseQuery=require("./apiBaseQuery.js"),_createAppApi=require("./createAppApi.js"),_listeners=require("./listeners.js"),_paging=require("./paging.js"),_tags=require("./tags.js");
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setupApiListeners=void 0;var _query=require("@reduxjs/toolkit/query"),_reactNative=require("react-native"),_index=require("../network/index.js");const setupApiListeners=e=>(0,_query.setupListeners)(e,(e,{onFocus:t,onFocusLost:r,onOnline:s,onOffline:i})=>{let n="active"===_reactNative.AppState.currentState;const o=_reactNative.AppState.addEventListener("change",s=>{const i="active"===s;i!==n&&(n=i,e(i?t():r()))});let u=!0;const a=(0,_index.addNetworkStatusListener)(({isConnected:t})=>{t!==u&&(u=t,e(t?s():i()))});return()=>{o.remove(),a()}});exports.setupApiListeners=setupApiListeners;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.hasPreviousPage=exports.hasNextPage=exports.getPreviousPageParam=exports.getNextPageParam=exports.buildListQuery=void 0;const buildListQuery=({page:e,pageSize:a,sortBy:r,sortOrder:t,filters:s})=>{const o={},put=(e,a)=>{null!=a&&""!==a&&(o[e]=a)};put("page",e),put("pageSize",a),put("sortBy",r),put("sortOrder",t);for(const[e,a]of Object.entries(s??{})){if("page"===e||"pageSize"===e||"sortBy"===e||"sortOrder"===e)throw new Error(`buildListQuery: filter "${e}" collides with a paging parameter.`);put(e,a)}return o};exports.buildListQuery=buildListQuery;const hasNextPage=e=>e.page<e.totalPages;exports.hasNextPage=hasNextPage;const hasPreviousPage=e=>e.page>1;exports.hasPreviousPage=hasPreviousPage;const getNextPageParam=e=>hasNextPage(e)?e.page+1:void 0;exports.getNextPageParam=getNextPageParam;const getPreviousPageParam=e=>hasPreviousPage(e)?e.page-1:void 0;exports.getPreviousPageParam=getPreviousPageParam;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.listTag=exports.itemTag=exports.LIST_TAG_ID=void 0,exports.providesList=providesList,exports.providesPagedList=providesPagedList;const LIST_TAG_ID=exports.LIST_TAG_ID="LIST",byPublicId=t=>t.publicId,listTag=t=>({type:t,id:LIST_TAG_ID});exports.listTag=listTag;const itemTag=(t,e)=>({type:t,id:e});function providesList(t,e,i){const s=i??byPublicId;return[listTag(t),...(e??[]).map(e=>itemTag(t,s(e)))]}function providesPagedList(t,e){const i=e??byPublicId;return e=>providesList(t,e?.items,i)}exports.itemTag=itemTag;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.errorToastMiddleware=errorToastMiddleware,exports.isSilentRejection=void 0;var _extractApiError=require("../errors/extractApiError.js");const isDict=e=>"object"==typeof e&&null!==e&&!Array.isArray(e),hasSilent=e=>isDict(e)&&!0===e.silent,isSilentRejection=e=>hasSilent(e)||hasSilent(e.arg)||isDict(e.arg)&&hasSilent(e.arg.originalArgs)||hasSilent(e.baseQueryMeta);function errorToastMiddleware(e){const{showToast:t,ignoreCodes:r=[],ignoreStatuses:i=[401],dedupeMs:s=4e3,onRejected:o}=e,n=new Map;return e=>a=>c=>{const l=a(c);if(!isDict(c)||!isDict(c.meta))return l;const u=c.meta;if("rejected"!==u.requestStatus||!0===u.aborted||!0===u.condition)return l;const d=(0,_extractApiError.extractApiError)(!0===u.rejectedWithValue?c.payload:c.error);if(d.code===_extractApiError.REQUEST_CANCELED_CODE)return l;const p=o?.(c,d,e);if("silent"===p||isSilentRejection(u))return l;if("toast"!==p){if(null!==d.code&&r.includes(d.code))return l;if(i.includes(d.status))return l}return(e=>{if(s<=0)return!0;const t=Date.now();for(const[e,r]of n)t-r>=s&&n.delete(e);return!n.has(e)&&(n.set(e,t),!0)})(d.message)&&t(d.message,d),l}}exports.isSilentRejection=isSilentRejection;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"SERIALIZABLE_IGNORED_ACTION_PATHS",{enumerable:!0,get:function(){return _serializableCheck.SERIALIZABLE_IGNORED_ACTION_PATHS}}),Object.defineProperty(exports,"createRootReducer",{enumerable:!0,get:function(){return _rootReducer.createRootReducer}}),Object.defineProperty(exports,"errorToastMiddleware",{enumerable:!0,get:function(){return _errorToastMiddleware.errorToastMiddleware}}),Object.defineProperty(exports,"isSilentRejection",{enumerable:!0,get:function(){return _errorToastMiddleware.isSilentRejection}}),Object.defineProperty(exports,"resetState",{enumerable:!0,get:function(){return _rootReducer.resetState}});var _errorToastMiddleware=require("./errorToastMiddleware.js"),_rootReducer=require("./rootReducer.js"),_serializableCheck=require("./serializableCheck.js");
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.createRootReducer=createRootReducer,exports.resetState=void 0;var _toolkit=require("@reduxjs/toolkit");const resetState=exports.resetState=(0,_toolkit.createAction)("app/resetState");function createRootReducer(e,t={}){const r=(0,_toolkit.combineReducers)(e),o=t.preserve??[];return(e,t)=>{if(void 0!==e&&resetState.match(t)){const s={};for(const t of o)s[t]=e[t];return r(s,t)}return r(e,t)}}
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SERIALIZABLE_IGNORED_ACTION_PATHS=void 0;const SERIALIZABLE_IGNORED_ACTION_PATHS=exports.SERIALIZABLE_IGNORED_ACTION_PATHS=["meta.arg","meta.baseQueryMeta"];
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.useSecureScreen=void 0;var _react=require("react"),_reactNative=require("react-native"),_index=require("../logger/index.js");const screenCapture=()=>require("expo-screen-capture"),report=e=>r=>{_index.Logger.error(`[@webority/mobile-core] useSecureScreen could not ${e}.`,r)};let nextKey=0,appSwitcherHolders=0;const useSecureScreen=(e={})=>{const{focused:r=!0}=e,t=(0,_react.useRef)(null);null===t.current&&(nextKey+=1,t.current=`webority-secure-screen-${nextKey}`),(0,_react.useEffect)(()=>{if(!r)return;const e=t.current,c=screenCapture();c.preventScreenCaptureAsync(e).catch(report("block screen capture"));const s="ios"===_reactNative.Platform.OS;return s&&(appSwitcherHolders+=1,1===appSwitcherHolders&&c.enableAppSwitcherProtectionAsync().catch(report("hide the app switcher snapshot"))),()=>{c.allowScreenCaptureAsync(e).catch(report("release screen capture")),s&&(appSwitcherHolders-=1,0===appSwitcherHolders&&c.disableAppSwitcherProtectionAsync().catch(report("restore the app switcher snapshot")))}},[r])};exports.useSecureScreen=useSecureScreen;
@@ -1,70 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.shareFile = exports.ShareError = void 0;
7
- /**
8
- * Opens a downloaded file through the system share sheet, where the person picks
9
- * a viewer or saves it. A separate entry point because it names expo-sharing, an
10
- * optional peer: Metro resolves every require reachable from an import, so keeping
11
- * it off the main barrel and off `/download` lets an app skip the package when it
12
- * never opens files.
13
- *
14
- * The share sheet rather than `Linking.openURL`: Android 7 and later refuse a
15
- * `file://` link, and a `content://` link sent through Linking carries no read
16
- * grant, so the OS-open route never reached a viewer there.
17
- */
18
-
19
- const PREFIX = '[@webority/mobile-core]';
20
- /** The one place `expo-sharing` is named, and only this subpath reaches it. */
21
- const sharing = () => require('expo-sharing');
22
-
23
- // iOS picks the apps it offers from the UTI, not the MIME type.
24
- const UTIS = {
25
- 'application/pdf': 'com.adobe.pdf',
26
- 'text/plain': 'public.plain-text',
27
- 'text/csv': 'public.comma-separated-values-text',
28
- 'image/jpeg': 'public.jpeg',
29
- 'image/png': 'public.png'
30
- };
31
- class ShareError extends Error {
32
- constructor(code, message) {
33
- super(`${PREFIX} ${message}`);
34
- this.name = 'ShareError';
35
- this.code = code;
36
- // Babel's class transform can drop the prototype link, which makes
37
- // `instanceof ShareError` false in the transpiled build.
38
- Object.setPrototypeOf(this, ShareError.prototype);
39
- }
40
- }
41
- exports.ShareError = ShareError;
42
- const HAS_SCHEME = /^[a-z][a-z0-9+.-]*:/i;
43
-
44
- /**
45
- * Hands a local file (the `path` `downloadFile` returns) to the share sheet.
46
- * A bare path is given a `file://` scheme. Rejects with `ShareError`: `unavailable`
47
- * when the device has no share sheet, `failed` when the sheet could not open the file.
48
- */
49
- const shareFile = async (path, options = {}) => {
50
- const url = HAS_SCHEME.test(path) ? path : `file://${path}`;
51
- const m = sharing();
52
- if (!(await m.isAvailableAsync())) {
53
- throw new ShareError('unavailable', `Sharing is not available on this device, so ${url} cannot be opened.`);
54
- }
55
- const {
56
- mimeType,
57
- dialogTitle
58
- } = options;
59
- try {
60
- await m.shareAsync(url, {
61
- mimeType,
62
- UTI: mimeType ? UTIS[mimeType] : undefined,
63
- dialogTitle
64
- });
65
- } catch (error) {
66
- throw new ShareError('failed', `${url}${mimeType ? ` (${mimeType})` : ''} could not be shared: ${error instanceof Error ? error.message : String(error)}`);
67
- }
68
- };
69
- exports.shareFile = shareFile;
70
- //# sourceMappingURL=index.js.map
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.shareFile=exports.ShareError=void 0;const PREFIX="[@webority/mobile-core]",sharing=()=>require("expo-sharing"),UTIS={"application/pdf":"com.adobe.pdf","text/plain":"public.plain-text","text/csv":"public.comma-separated-values-text","image/jpeg":"public.jpeg","image/png":"public.png"};class ShareError extends Error{constructor(e,r){super(`${PREFIX} ${r}`),this.name="ShareError",this.code=e,Object.setPrototypeOf(this,ShareError.prototype)}}exports.ShareError=ShareError;const HAS_SCHEME=/^[a-z][a-z0-9+.-]*:/i,shareFile=async(e,r={})=>{const a=HAS_SCHEME.test(e)?e:`file://${e}`,t=sharing();if(!await t.isAvailableAsync())throw new ShareError("unavailable",`Sharing is not available on this device, so ${a} cannot be opened.`);const{mimeType:o,dialogTitle:i}=r;try{await t.shareAsync(a,{mimeType:o,UTI:o?UTIS[o]:void 0,dialogTitle:i})}catch(e){throw new ShareError("failed",`${a}${o?` (${o})`:""} could not be shared: ${e instanceof Error?e.message:String(e)}`)}};exports.shareFile=shareFile;