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