@cobbai/react-native-sdk 1.0.0-beta.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/CobbaiMobileRnSdk.podspec +22 -0
- package/LICENSE +32 -0
- package/README.md +386 -0
- package/dist/ChatPlaceholder.d.ts +13 -0
- package/dist/ChatPlaceholder.d.ts.map +1 -0
- package/dist/ChatPlaceholder.js +87 -0
- package/dist/CobbaiChatScreen.d.ts +4 -0
- package/dist/CobbaiChatScreen.d.ts.map +1 -0
- package/dist/CobbaiChatScreen.js +196 -0
- package/dist/CobbaiInAppBanner.d.ts +15 -0
- package/dist/CobbaiInAppBanner.d.ts.map +1 -0
- package/dist/CobbaiInAppBanner.js +159 -0
- package/dist/CobbaiLauncher.d.ts +19 -0
- package/dist/CobbaiLauncher.d.ts.map +1 -0
- package/dist/CobbaiLauncher.js +149 -0
- package/dist/CobbaiWebView.d.ts +28 -0
- package/dist/CobbaiWebView.d.ts.map +1 -0
- package/dist/CobbaiWebView.js +141 -0
- package/dist/adapters/expoAdapter.d.ts +85 -0
- package/dist/adapters/expoAdapter.d.ts.map +1 -0
- package/dist/adapters/expoAdapter.js +152 -0
- package/dist/adapters/firebaseAdapter.d.ts +41 -0
- package/dist/adapters/firebaseAdapter.d.ts.map +1 -0
- package/dist/adapters/firebaseAdapter.js +139 -0
- package/dist/adapters/iosRelayAdapter.d.ts +26 -0
- package/dist/adapters/iosRelayAdapter.d.ts.map +1 -0
- package/dist/adapters/iosRelayAdapter.js +101 -0
- package/dist/androidKeyboardFrame.d.ts +16 -0
- package/dist/androidKeyboardFrame.d.ts.map +1 -0
- package/dist/androidKeyboardFrame.js +34 -0
- package/dist/bridge/messages.d.ts +20 -0
- package/dist/bridge/messages.d.ts.map +1 -0
- package/dist/bridge/messages.js +20 -0
- package/dist/bridge/nativeEvent.d.ts +10 -0
- package/dist/bridge/nativeEvent.d.ts.map +1 -0
- package/dist/bridge/nativeEvent.js +15 -0
- package/dist/bridge/parser.d.ts +29 -0
- package/dist/bridge/parser.d.ts.map +1 -0
- package/dist/bridge/parser.js +109 -0
- package/dist/chatPresentation.d.ts +19 -0
- package/dist/chatPresentation.d.ts.map +1 -0
- package/dist/chatPresentation.js +51 -0
- package/dist/chatScreen/useInAppBannerQueue.d.ts +22 -0
- package/dist/chatScreen/useInAppBannerQueue.d.ts.map +1 -0
- package/dist/chatScreen/useInAppBannerQueue.js +60 -0
- package/dist/chatScreen/useKeyboardFrame.d.ts +14 -0
- package/dist/chatScreen/useKeyboardFrame.d.ts.map +1 -0
- package/dist/chatScreen/useKeyboardFrame.js +63 -0
- package/dist/chatScreen/useLauncherPresentation.d.ts +20 -0
- package/dist/chatScreen/useLauncherPresentation.d.ts.map +1 -0
- package/dist/chatScreen/useLauncherPresentation.js +76 -0
- package/dist/chatScreen/useNativeToWebSync.d.ts +17 -0
- package/dist/chatScreen/useNativeToWebSync.d.ts.map +1 -0
- package/dist/chatScreen/useNativeToWebSync.js +36 -0
- package/dist/chatScreen/usePushIntegration.d.ts +19 -0
- package/dist/chatScreen/usePushIntegration.d.ts.map +1 -0
- package/dist/chatScreen/usePushIntegration.js +129 -0
- package/dist/chatScreen/useReadyLifecycle.d.ts +33 -0
- package/dist/chatScreen/useReadyLifecycle.d.ts.map +1 -0
- package/dist/chatScreen/useReadyLifecycle.js +138 -0
- package/dist/chatScreen/useSheetPresentation.d.ts +25 -0
- package/dist/chatScreen/useSheetPresentation.d.ts.map +1 -0
- package/dist/chatScreen/useSheetPresentation.js +98 -0
- package/dist/chatUnavailable.d.ts +23 -0
- package/dist/chatUnavailable.d.ts.map +1 -0
- package/dist/chatUnavailable.js +36 -0
- package/dist/externalLinks.d.ts +4 -0
- package/dist/externalLinks.d.ts.map +1 -0
- package/dist/externalLinks.js +48 -0
- package/dist/host/buildHostHtml.d.ts +7 -0
- package/dist/host/buildHostHtml.d.ts.map +1 -0
- package/dist/host/buildHostHtml.js +101 -0
- package/dist/host/hostPageKey.d.ts +7 -0
- package/dist/host/hostPageKey.d.ts.map +1 -0
- package/dist/host/hostPageKey.js +18 -0
- package/dist/inAppBanner.d.ts +19 -0
- package/dist/inAppBanner.d.ts.map +1 -0
- package/dist/inAppBanner.js +42 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/launcher.d.ts +25 -0
- package/dist/launcher.d.ts.map +1 -0
- package/dist/launcher.js +55 -0
- package/dist/launcherGlyph.d.ts +2 -0
- package/dist/launcherGlyph.d.ts.map +1 -0
- package/dist/launcherGlyph.js +5 -0
- package/dist/openChatScreen.d.ts +13 -0
- package/dist/openChatScreen.d.ts.map +1 -0
- package/dist/openChatScreen.js +63 -0
- package/dist/push.d.ts +59 -0
- package/dist/push.d.ts.map +1 -0
- package/dist/push.js +309 -0
- package/dist/pushIntegration.d.ts +76 -0
- package/dist/pushIntegration.d.ts.map +1 -0
- package/dist/pushIntegration.js +244 -0
- package/dist/pushLogout.d.ts +57 -0
- package/dist/pushLogout.d.ts.map +1 -0
- package/dist/pushLogout.js +225 -0
- package/dist/types.d.ts +42 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/version.d.ts +8 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +10 -0
- package/ios/CobbaiPush.m +96 -0
- package/ios/CobbaiPushRelay.h +59 -0
- package/ios/CobbaiPushRelay.m +364 -0
- package/package.json +69 -0
- package/src/ChatPlaceholder.tsx +132 -0
- package/src/CobbaiChatScreen.tsx +348 -0
- package/src/CobbaiInAppBanner.tsx +237 -0
- package/src/CobbaiLauncher.tsx +223 -0
- package/src/CobbaiWebView.tsx +242 -0
- package/src/adapters/expoAdapter.ts +227 -0
- package/src/adapters/firebaseAdapter.ts +201 -0
- package/src/adapters/iosRelayAdapter.ts +137 -0
- package/src/androidKeyboardFrame.ts +56 -0
- package/src/bridge/messages.ts +24 -0
- package/src/bridge/nativeEvent.ts +12 -0
- package/src/bridge/parser.ts +159 -0
- package/src/chatPresentation.ts +73 -0
- package/src/chatScreen/useInAppBannerQueue.ts +91 -0
- package/src/chatScreen/useKeyboardFrame.ts +89 -0
- package/src/chatScreen/useLauncherPresentation.ts +121 -0
- package/src/chatScreen/useNativeToWebSync.ts +54 -0
- package/src/chatScreen/usePushIntegration.ts +191 -0
- package/src/chatScreen/useReadyLifecycle.ts +186 -0
- package/src/chatScreen/useSheetPresentation.ts +147 -0
- package/src/chatUnavailable.ts +58 -0
- package/src/externalLinks.ts +56 -0
- package/src/host/buildHostHtml.ts +117 -0
- package/src/host/hostPageKey.ts +17 -0
- package/src/inAppBanner.ts +58 -0
- package/src/index.ts +53 -0
- package/src/launcher.ts +79 -0
- package/src/launcherGlyph.ts +3 -0
- package/src/openChatScreen.ts +78 -0
- package/src/push.ts +424 -0
- package/src/pushIntegration.ts +338 -0
- package/src/pushLogout.ts +277 -0
- package/src/types.ts +46 -0
- package/src/version.ts +8 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.CobbaiWebView = CobbaiWebView;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const react_native_1 = require("react-native");
|
|
10
|
+
const react_native_webview_1 = __importDefault(require("react-native-webview"));
|
|
11
|
+
const parser_1 = require("./bridge/parser");
|
|
12
|
+
const messages_1 = require("./bridge/messages");
|
|
13
|
+
const externalLinks_1 = require("./externalLinks");
|
|
14
|
+
const buildHostHtml_1 = require("./host/buildHostHtml");
|
|
15
|
+
function CobbaiWebView(props) {
|
|
16
|
+
const { config, generation, initialSafeArea, onReady, onClose, onError, onNewMessage, onUnread, onPushTokenRegistered, onLauncherAppearance, onProcessGone, onWebViewRef, } = props;
|
|
17
|
+
const { baseUrl, chatId, authToken, userId, locale, metadata } = config;
|
|
18
|
+
const metadataKey = JSON.stringify(metadata !== null && metadata !== void 0 ? metadata : null);
|
|
19
|
+
const normalizedBaseUrl = (0, react_1.useMemo)(() => (0, buildHostHtml_1.normalizeBaseUrl)(baseUrl), [baseUrl]);
|
|
20
|
+
// Keyed on the values the page is built from, never on the `config` object: a new reference
|
|
21
|
+
// (inline literal, new callback, metadata rebuilt with the same values) must not rebuild the
|
|
22
|
+
// host page. A real change (token, user, locale, metadata content) still does.
|
|
23
|
+
const source = (0, react_1.useMemo)(() => ({
|
|
24
|
+
html: (0, buildHostHtml_1.buildHostHtml)({ baseUrl, chatId, authToken, userId, locale, metadata }, initialSafeArea),
|
|
25
|
+
baseUrl: normalizedBaseUrl,
|
|
26
|
+
}),
|
|
27
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- metadata is compared by content (metadataKey).
|
|
28
|
+
[baseUrl, chatId, authToken, userId, locale, metadataKey, initialSafeArea, normalizedBaseUrl]);
|
|
29
|
+
const openExternalUrl = (url) => {
|
|
30
|
+
void react_native_1.Linking.openURL(url).catch((error) => {
|
|
31
|
+
if (__DEV__) {
|
|
32
|
+
console.warn('[cobbai] Failed to open external URL', url, error);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
const handleOpenWindow = (event) => {
|
|
37
|
+
const { targetUrl } = event.nativeEvent;
|
|
38
|
+
if (!(0, externalLinks_1.isExternalOpenableUrl)(targetUrl)) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
openExternalUrl(targetUrl);
|
|
42
|
+
};
|
|
43
|
+
const handleShouldStartLoadWithRequest = (request) => {
|
|
44
|
+
if (request.isTopFrame === false) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if ((0, externalLinks_1.isHostDocumentUrl)(request.url, normalizedBaseUrl)) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
if ((0, externalLinks_1.isExternalOpenableUrl)(request.url)) {
|
|
51
|
+
openExternalUrl(request.url);
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
const handleMessage = (event) => {
|
|
56
|
+
if (!(0, externalLinks_1.isFromHostOrigin)(event.nativeEvent.url, normalizedBaseUrl)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const parsed = (0, parser_1.parseBridgeMessage)(event.nativeEvent.data);
|
|
60
|
+
if (!parsed)
|
|
61
|
+
return;
|
|
62
|
+
switch (parsed.type) {
|
|
63
|
+
case messages_1.WEB_TO_NATIVE_MESSAGES.READY:
|
|
64
|
+
onReady();
|
|
65
|
+
return;
|
|
66
|
+
case messages_1.WEB_TO_NATIVE_MESSAGES.CLOSE:
|
|
67
|
+
onClose();
|
|
68
|
+
return;
|
|
69
|
+
case messages_1.WEB_TO_NATIVE_MESSAGES.ERROR: {
|
|
70
|
+
const code = typeof parsed.payload.code === 'string' ? parsed.payload.code : 'chat_error';
|
|
71
|
+
const message = typeof parsed.payload.message === 'string'
|
|
72
|
+
? parsed.payload.message
|
|
73
|
+
: 'Chat failed to initialize';
|
|
74
|
+
onError({ code, message });
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
case messages_1.WEB_TO_NATIVE_MESSAGES.NEW_MESSAGE: {
|
|
78
|
+
const nextMessage = (0, parser_1.validateNewMessagePayload)(parsed.payload);
|
|
79
|
+
if (!nextMessage) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
onNewMessage(nextMessage);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
case messages_1.WEB_TO_NATIVE_MESSAGES.UNREAD: {
|
|
86
|
+
const unreadPayload = (0, parser_1.validateUnreadPayload)(parsed.payload);
|
|
87
|
+
if (!unreadPayload) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
onUnread(unreadPayload.total);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
case messages_1.WEB_TO_NATIVE_MESSAGES.PUSH_TOKEN_REGISTERED: {
|
|
94
|
+
const registration = (0, parser_1.validatePushTokenRegisteredPayload)(parsed.payload);
|
|
95
|
+
if (registration) {
|
|
96
|
+
onPushTokenRegistered(registration);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
case messages_1.WEB_TO_NATIVE_MESSAGES.LAUNCHER: {
|
|
101
|
+
const launcherAppearance = (0, parser_1.validateLauncherPayload)(parsed.payload);
|
|
102
|
+
if (!launcherAppearance) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
onLauncherAppearance(launcherAppearance);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
default:
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
return ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.container, children: (0, jsx_runtime_1.jsx)(react_native_webview_1.default, { ref: onWebViewRef, source: source, style: styles.webView, originWhitelist: ['*'], webviewDebuggingEnabled: __DEV__, onMessage: handleMessage, onOpenWindow: handleOpenWindow, onShouldStartLoadWithRequest: handleShouldStartLoadWithRequest, onRenderProcessGone: (event) => {
|
|
113
|
+
var _a;
|
|
114
|
+
const didCrash = (_a = event.nativeEvent) === null || _a === void 0 ? void 0 : _a.didCrash;
|
|
115
|
+
onProcessGone({
|
|
116
|
+
platform: 'android',
|
|
117
|
+
didCrash: typeof didCrash === 'boolean' ? didCrash : undefined,
|
|
118
|
+
});
|
|
119
|
+
}, onContentProcessDidTerminate: () => {
|
|
120
|
+
onProcessGone({ platform: 'ios' });
|
|
121
|
+
}, keyboardDisplayRequiresUserAction: false, automaticallyAdjustContentInsets: false, hideKeyboardAccessoryView: true, scrollEnabled: false, startInLoadingState: true, renderLoading: () => ((0, jsx_runtime_1.jsx)(react_native_1.View, { style: styles.loaderContainer, children: (0, jsx_runtime_1.jsx)(react_native_1.ActivityIndicator, { size: "large" }) })) }, generation) }));
|
|
122
|
+
}
|
|
123
|
+
const styles = react_native_1.StyleSheet.create({
|
|
124
|
+
container: {
|
|
125
|
+
position: 'absolute',
|
|
126
|
+
top: 0,
|
|
127
|
+
right: 0,
|
|
128
|
+
bottom: 0,
|
|
129
|
+
left: 0,
|
|
130
|
+
backgroundColor: 'transparent',
|
|
131
|
+
},
|
|
132
|
+
webView: {
|
|
133
|
+
flex: 1,
|
|
134
|
+
backgroundColor: 'transparent',
|
|
135
|
+
},
|
|
136
|
+
loaderContainer: {
|
|
137
|
+
flex: 1,
|
|
138
|
+
alignItems: 'center',
|
|
139
|
+
justifyContent: 'center',
|
|
140
|
+
},
|
|
141
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { CobbaiPushAdapter } from '../pushIntegration';
|
|
2
|
+
/** The fields of an `expo-notifications` notification the SDK reads. */
|
|
3
|
+
export type ExpoNotification = {
|
|
4
|
+
request: {
|
|
5
|
+
content: {
|
|
6
|
+
title?: string | null;
|
|
7
|
+
body?: string | null;
|
|
8
|
+
data?: unknown;
|
|
9
|
+
};
|
|
10
|
+
trigger?: unknown;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type ExpoNotificationResponse = {
|
|
14
|
+
notification: ExpoNotification;
|
|
15
|
+
};
|
|
16
|
+
export type ExpoNotificationBehavior = {
|
|
17
|
+
shouldShowBanner: boolean;
|
|
18
|
+
shouldShowList: boolean;
|
|
19
|
+
shouldPlaySound: boolean;
|
|
20
|
+
shouldSetBadge: boolean;
|
|
21
|
+
};
|
|
22
|
+
/** An `expo-notifications` handler (`setNotificationHandler`). */
|
|
23
|
+
export type ExpoNotificationHandler = {
|
|
24
|
+
handleNotification: (notification: ExpoNotification) => Promise<ExpoNotificationBehavior>;
|
|
25
|
+
handleSuccess?: (notificationId: string) => void;
|
|
26
|
+
handleError?: (notificationId: string, error: Error) => void;
|
|
27
|
+
};
|
|
28
|
+
type ExpoSubscription = {
|
|
29
|
+
remove(): void;
|
|
30
|
+
};
|
|
31
|
+
type ExpoPermissions = {
|
|
32
|
+
status: string;
|
|
33
|
+
granted: boolean;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* The part of `expo-notifications` the adapter uses. The app passes the module itself, so the SDK
|
|
37
|
+
* does not depend on Expo:
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import * as Notifications from 'expo-notifications';
|
|
41
|
+
* configureCobbaiPush({ adapter: expoAdapter(Notifications) });
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* Methods, not function properties: Expo's own signatures must stay assignable.
|
|
45
|
+
*/
|
|
46
|
+
export type ExpoNotificationsModule = {
|
|
47
|
+
getDevicePushTokenAsync(): Promise<{
|
|
48
|
+
type: string;
|
|
49
|
+
data: unknown;
|
|
50
|
+
}>;
|
|
51
|
+
addPushTokenListener(listener: (token: {
|
|
52
|
+
type: string;
|
|
53
|
+
data: unknown;
|
|
54
|
+
}) => void): ExpoSubscription;
|
|
55
|
+
addNotificationReceivedListener(listener: (notification: ExpoNotification) => void): ExpoSubscription;
|
|
56
|
+
addNotificationResponseReceivedListener(listener: (response: ExpoNotificationResponse) => void): ExpoSubscription;
|
|
57
|
+
getLastNotificationResponseAsync(): Promise<ExpoNotificationResponse | null>;
|
|
58
|
+
getPermissionsAsync(): Promise<ExpoPermissions>;
|
|
59
|
+
requestPermissionsAsync(): Promise<ExpoPermissions>;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The push data of a notification. For a push that does not come from Expo's push service, Expo
|
|
63
|
+
* puts the payload's own keys in the trigger, not in `content.data` (which holds Expo's `body`):
|
|
64
|
+
* Android `trigger.remoteMessage.data`, iPhone `trigger.payload`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function expoNotificationData(notification: ExpoNotification): unknown;
|
|
67
|
+
/**
|
|
68
|
+
* Push adapter for `expo-notifications` (Expo SDK 53+ development or production builds, not Expo
|
|
69
|
+
* Go), **Android only**: on iPhone the SDK's native relay handles Cobbai pushes.
|
|
70
|
+
* On both platforms, also wrap your notification handler with `withCobbaiHandler`.
|
|
71
|
+
*/
|
|
72
|
+
export declare function expoAdapter(notifications: ExpoNotificationsModule): CobbaiPushAdapter;
|
|
73
|
+
/**
|
|
74
|
+
* Wraps the app's `expo-notifications` handler: Expo keeps a single one, so the SDK must not replace
|
|
75
|
+
* it. Cobbai pushes get the SDK's decision: hidden while the chat shows them
|
|
76
|
+
* (connected, or its in-app banner), else the system notification. Everything else goes to the app's
|
|
77
|
+
* handler, or is not shown in the foreground when there is none (Expo's default).
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* Notifications.setNotificationHandler(withCobbaiHandler({ handleNotification: async () => ({ ... }) }));
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export declare function withCobbaiHandler(appHandler?: ExpoNotificationHandler): ExpoNotificationHandler;
|
|
84
|
+
export {};
|
|
85
|
+
//# sourceMappingURL=expoAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expoAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/expoAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,oBAAoB,CAAC;AAE5B,wEAAwE;AACxE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,EAAE;QACP,OAAO,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;YAAC,IAAI,CAAC,EAAE,OAAO,CAAA;SAAE,CAAC;QACzE,OAAO,CAAC,EAAE,OAAO,CAAC;KACnB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IAAE,YAAY,EAAE,gBAAgB,CAAA;CAAE,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG;IACrC,gBAAgB,EAAE,OAAO,CAAC;IAC1B,cAAc,EAAE,OAAO,CAAC;IACxB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,kEAAkE;AAClE,MAAM,MAAM,uBAAuB,GAAG;IACpC,kBAAkB,EAAE,CAAC,YAAY,EAAE,gBAAgB,KAAK,OAAO,CAAC,wBAAwB,CAAC,CAAC;IAC1F,aAAa,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,WAAW,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC9D,CAAC;AAEF,KAAK,gBAAgB,GAAG;IAAE,MAAM,IAAI,IAAI,CAAA;CAAE,CAAC;AAC3C,KAAK,eAAe,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE5D;;;;;;;;;;GAUG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,uBAAuB,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IACpE,oBAAoB,CAClB,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,GACzD,gBAAgB,CAAC;IACpB,+BAA+B,CAC7B,QAAQ,EAAE,CAAC,YAAY,EAAE,gBAAgB,KAAK,IAAI,GACjD,gBAAgB,CAAC;IACpB,uCAAuC,CACrC,QAAQ,EAAE,CAAC,QAAQ,EAAE,wBAAwB,KAAK,IAAI,GACrD,gBAAgB,CAAC;IACpB,gCAAgC,IAAI,OAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAAC;IAC7E,mBAAmB,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;IAChD,uBAAuB,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC;CACrD,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,gBAAgB,GAAG,OAAO,CAY5E;AAiBD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,aAAa,EAAE,uBAAuB,GAAG,iBAAiB,CA8ErF;AAgBD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,CAqB/F"}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expoNotificationData = expoNotificationData;
|
|
4
|
+
exports.expoAdapter = expoAdapter;
|
|
5
|
+
exports.withCobbaiHandler = withCobbaiHandler;
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const push_1 = require("../push");
|
|
8
|
+
/**
|
|
9
|
+
* The push data of a notification. For a push that does not come from Expo's push service, Expo
|
|
10
|
+
* puts the payload's own keys in the trigger, not in `content.data` (which holds Expo's `body`):
|
|
11
|
+
* Android `trigger.remoteMessage.data`, iPhone `trigger.payload`.
|
|
12
|
+
*/
|
|
13
|
+
function expoNotificationData(notification) {
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const trigger = notification.request.trigger;
|
|
16
|
+
const candidates = [
|
|
17
|
+
(_a = trigger === null || trigger === void 0 ? void 0 : trigger.remoteMessage) === null || _a === void 0 ? void 0 : _a.data,
|
|
18
|
+
trigger === null || trigger === void 0 ? void 0 : trigger.payload,
|
|
19
|
+
notification.request.content.data,
|
|
20
|
+
];
|
|
21
|
+
return ((_b = candidates.find((candidate) => (0, push_1.isCobbaiPush)(candidate))) !== null && _b !== void 0 ? _b : notification.request.content.data);
|
|
22
|
+
}
|
|
23
|
+
function toStatus(permissions) {
|
|
24
|
+
if (permissions.granted)
|
|
25
|
+
return 'granted';
|
|
26
|
+
return permissions.status === 'denied' ? 'denied' : 'not-asked';
|
|
27
|
+
}
|
|
28
|
+
function errorMessage(error) {
|
|
29
|
+
return error instanceof Error ? error.message : String(error);
|
|
30
|
+
}
|
|
31
|
+
function warn(message) {
|
|
32
|
+
if (__DEV__) {
|
|
33
|
+
console.warn(`[cobbai][push][expo] ${message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Push adapter for `expo-notifications` (Expo SDK 53+ development or production builds, not Expo
|
|
38
|
+
* Go), **Android only**: on iPhone the SDK's native relay handles Cobbai pushes.
|
|
39
|
+
* On both platforms, also wrap your notification handler with `withCobbaiHandler`.
|
|
40
|
+
*/
|
|
41
|
+
function expoAdapter(notifications) {
|
|
42
|
+
let handlers = null;
|
|
43
|
+
const reportToken = async () => {
|
|
44
|
+
try {
|
|
45
|
+
const token = await notifications.getDevicePushTokenAsync();
|
|
46
|
+
if (typeof token.data === 'string' && token.data) {
|
|
47
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.token({ token: token.data, provider: 'fcm' });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
warn(`token request failed: ${errorMessage(error)}`);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
name: 'expo',
|
|
56
|
+
start(nextHandlers) {
|
|
57
|
+
if (react_native_1.Platform.OS !== 'android') {
|
|
58
|
+
return () => { };
|
|
59
|
+
}
|
|
60
|
+
handlers = nextHandlers;
|
|
61
|
+
const subscriptions = [
|
|
62
|
+
notifications.addPushTokenListener((token) => {
|
|
63
|
+
if (typeof token.data === 'string' && token.data) {
|
|
64
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.token({ token: token.data, provider: 'fcm' });
|
|
65
|
+
}
|
|
66
|
+
}),
|
|
67
|
+
notifications.addNotificationReceivedListener((notification) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.foreground({
|
|
70
|
+
data: expoNotificationData(notification),
|
|
71
|
+
title: (_a = notification.request.content.title) !== null && _a !== void 0 ? _a : undefined,
|
|
72
|
+
body: (_b = notification.request.content.body) !== null && _b !== void 0 ? _b : undefined,
|
|
73
|
+
});
|
|
74
|
+
}),
|
|
75
|
+
notifications.addNotificationResponseReceivedListener((response) => {
|
|
76
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.tap(expoNotificationData(response.notification));
|
|
77
|
+
}),
|
|
78
|
+
];
|
|
79
|
+
notifications
|
|
80
|
+
.getLastNotificationResponseAsync()
|
|
81
|
+
.then((response) => {
|
|
82
|
+
if (response)
|
|
83
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.tap(expoNotificationData(response.notification));
|
|
84
|
+
})
|
|
85
|
+
.catch((error) => warn(`last notification response failed: ${errorMessage(error)}`));
|
|
86
|
+
notifications
|
|
87
|
+
.getPermissionsAsync()
|
|
88
|
+
.then((permissions) => {
|
|
89
|
+
const status = toStatus(permissions);
|
|
90
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.status(status);
|
|
91
|
+
if (status === 'granted')
|
|
92
|
+
return reportToken();
|
|
93
|
+
return undefined;
|
|
94
|
+
})
|
|
95
|
+
.catch((error) => warn(`permission check failed: ${errorMessage(error)}`));
|
|
96
|
+
return () => {
|
|
97
|
+
subscriptions.forEach((subscription) => subscription.remove());
|
|
98
|
+
handlers = null;
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
async requestPermission() {
|
|
102
|
+
if (react_native_1.Platform.OS !== 'android') {
|
|
103
|
+
return 'unavailable';
|
|
104
|
+
}
|
|
105
|
+
const status = toStatus(await notifications.requestPermissionsAsync());
|
|
106
|
+
if (status === 'granted') {
|
|
107
|
+
await reportToken();
|
|
108
|
+
}
|
|
109
|
+
return status;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
const HIDDEN = {
|
|
114
|
+
shouldShowBanner: false,
|
|
115
|
+
shouldShowList: false,
|
|
116
|
+
shouldPlaySound: false,
|
|
117
|
+
shouldSetBadge: false,
|
|
118
|
+
};
|
|
119
|
+
const SHOWN = {
|
|
120
|
+
shouldShowBanner: true,
|
|
121
|
+
shouldShowList: true,
|
|
122
|
+
shouldPlaySound: true,
|
|
123
|
+
shouldSetBadge: false,
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Wraps the app's `expo-notifications` handler: Expo keeps a single one, so the SDK must not replace
|
|
127
|
+
* it. Cobbai pushes get the SDK's decision: hidden while the chat shows them
|
|
128
|
+
* (connected, or its in-app banner), else the system notification. Everything else goes to the app's
|
|
129
|
+
* handler, or is not shown in the foreground when there is none (Expo's default).
|
|
130
|
+
*
|
|
131
|
+
* ```ts
|
|
132
|
+
* Notifications.setNotificationHandler(withCobbaiHandler({ handleNotification: async () => ({ ... }) }));
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
function withCobbaiHandler(appHandler) {
|
|
136
|
+
return {
|
|
137
|
+
handleNotification: async (notification) => {
|
|
138
|
+
const data = expoNotificationData(notification);
|
|
139
|
+
if (!(0, push_1.isCobbaiPush)(data)) {
|
|
140
|
+
return appHandler ? appHandler.handleNotification(notification) : HIDDEN;
|
|
141
|
+
}
|
|
142
|
+
const chatId = data.cobbai_chat_id;
|
|
143
|
+
const state = (0, push_1.getForegroundPresentationState)();
|
|
144
|
+
const chatShowsIt = state.mountedChatId !== null &&
|
|
145
|
+
state.mountedChatId === chatId &&
|
|
146
|
+
(state.connected || state.bannerEnabled);
|
|
147
|
+
return chatShowsIt ? HIDDEN : SHOWN;
|
|
148
|
+
},
|
|
149
|
+
handleSuccess: (notificationId) => { var _a; return (_a = appHandler === null || appHandler === void 0 ? void 0 : appHandler.handleSuccess) === null || _a === void 0 ? void 0 : _a.call(appHandler, notificationId); },
|
|
150
|
+
handleError: (notificationId, error) => { var _a; return (_a = appHandler === null || appHandler === void 0 ? void 0 : appHandler.handleError) === null || _a === void 0 ? void 0 : _a.call(appHandler, notificationId, error); },
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CobbaiPushAdapter } from '../pushIntegration';
|
|
2
|
+
/**
|
|
3
|
+
* The part of `@react-native-firebase/messaging` (modular API, v19+) the adapter uses. The app
|
|
4
|
+
* passes the module itself, so the SDK does not depend on Firebase:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import * as messaging from '@react-native-firebase/messaging';
|
|
8
|
+
* configureCobbaiPush({ adapter: firebaseAdapter(messaging) });
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Methods (not function properties) on purpose: the library's own signatures take more precise
|
|
12
|
+
* types and optional extra arguments, and must stay assignable.
|
|
13
|
+
*/
|
|
14
|
+
export type FirebaseMessagingModule<TMessaging = unknown> = {
|
|
15
|
+
getMessaging(): TMessaging;
|
|
16
|
+
getToken(messaging: TMessaging): Promise<string>;
|
|
17
|
+
onMessage(messaging: TMessaging, listener: (message: FirebaseRemoteMessage) => unknown): () => void;
|
|
18
|
+
onNotificationOpenedApp(messaging: TMessaging, listener: (message: FirebaseRemoteMessage) => unknown): () => void;
|
|
19
|
+
onTokenRefresh(messaging: TMessaging, listener: (token: string) => unknown): () => void;
|
|
20
|
+
getInitialNotification(messaging: TMessaging): Promise<FirebaseRemoteMessage | null>;
|
|
21
|
+
};
|
|
22
|
+
/** The fields of a Firebase `RemoteMessage` the adapter reads. */
|
|
23
|
+
export type FirebaseRemoteMessage = {
|
|
24
|
+
data?: {
|
|
25
|
+
[key: string]: string | object;
|
|
26
|
+
};
|
|
27
|
+
notification?: {
|
|
28
|
+
title?: string;
|
|
29
|
+
body?: string;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Push adapter for `@react-native-firebase/messaging`, **Android only**. On iPhone, Cobbai pushes go
|
|
34
|
+
* to APNs directly and Firebase ignores them: the SDK's native relay handles them,
|
|
35
|
+
* and this adapter does nothing there.
|
|
36
|
+
*
|
|
37
|
+
* It never sets Firebase's background message handler: that one belongs to the app, which returns
|
|
38
|
+
* early on `isCobbaiPush(message.data)`.
|
|
39
|
+
*/
|
|
40
|
+
export declare function firebaseAdapter<TMessaging>(firebase: FirebaseMessagingModule<TMessaging>): CobbaiPushAdapter;
|
|
41
|
+
//# sourceMappingURL=firebaseAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firebaseAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/firebaseAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,iBAAiB,EAGlB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,uBAAuB,CAAC,UAAU,GAAG,OAAO,IAAI;IAC1D,YAAY,IAAI,UAAU,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,SAAS,CACP,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,GACpD,MAAM,IAAI,CAAC;IACd,uBAAuB,CACrB,SAAS,EAAE,UAAU,EACrB,QAAQ,EAAE,CAAC,OAAO,EAAE,qBAAqB,KAAK,OAAO,GACpD,MAAM,IAAI,CAAC;IACd,cAAc,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,GAAG,MAAM,IAAI,CAAC;IACxF,sBAAsB,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC;CACtF,CAAC;AAEF,kEAAkE;AAClE,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IAC1C,YAAY,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAClD,CAAC;AAqCF;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,UAAU,EACxC,QAAQ,EAAE,uBAAuB,CAAC,UAAU,CAAC,GAC5C,iBAAiB,CAmHnB"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.firebaseAdapter = firebaseAdapter;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const POST_NOTIFICATIONS_API_LEVEL = 33;
|
|
6
|
+
function androidApiLevel() {
|
|
7
|
+
const version = react_native_1.Platform.Version;
|
|
8
|
+
return typeof version === 'number' ? version : Number.parseInt(String(version), 10);
|
|
9
|
+
}
|
|
10
|
+
function needsRuntimePermission() {
|
|
11
|
+
const apiLevel = androidApiLevel();
|
|
12
|
+
return Number.isFinite(apiLevel) && apiLevel >= POST_NOTIFICATIONS_API_LEVEL;
|
|
13
|
+
}
|
|
14
|
+
function errorMessage(error) {
|
|
15
|
+
if (error instanceof Error)
|
|
16
|
+
return error.message;
|
|
17
|
+
return typeof error === 'string' ? error : 'unknown error';
|
|
18
|
+
}
|
|
19
|
+
/** Firebase throws these when `google-services.json` is missing. */
|
|
20
|
+
function isFirebaseNotConfigured(error) {
|
|
21
|
+
const message = errorMessage(error).toLowerCase();
|
|
22
|
+
return (message.includes('firebase') &&
|
|
23
|
+
(message.includes('not configured') ||
|
|
24
|
+
message.includes('default app has not been created') ||
|
|
25
|
+
message.includes('default firebaseapp is not initialized') ||
|
|
26
|
+
message.includes('no firebase app')));
|
|
27
|
+
}
|
|
28
|
+
function warn(message) {
|
|
29
|
+
if (__DEV__) {
|
|
30
|
+
console.warn(`[cobbai][push][firebase] ${message}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Push adapter for `@react-native-firebase/messaging`, **Android only**. On iPhone, Cobbai pushes go
|
|
35
|
+
* to APNs directly and Firebase ignores them: the SDK's native relay handles them,
|
|
36
|
+
* and this adapter does nothing there.
|
|
37
|
+
*
|
|
38
|
+
* It never sets Firebase's background message handler: that one belongs to the app, which returns
|
|
39
|
+
* early on `isCobbaiPush(message.data)`.
|
|
40
|
+
*/
|
|
41
|
+
function firebaseAdapter(firebase) {
|
|
42
|
+
let handlers = null;
|
|
43
|
+
let messagingInstance = null;
|
|
44
|
+
/** Returns false when Firebase turned out not to be configured. */
|
|
45
|
+
const reportToken = async () => {
|
|
46
|
+
if (!handlers || messagingInstance === null)
|
|
47
|
+
return true;
|
|
48
|
+
try {
|
|
49
|
+
const token = await firebase.getToken(messagingInstance);
|
|
50
|
+
if (token && handlers) {
|
|
51
|
+
handlers.token({ token, provider: 'fcm' });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (isFirebaseNotConfigured(error)) {
|
|
56
|
+
warn('Firebase is not configured (android/app/google-services.json missing)');
|
|
57
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.status('unavailable');
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
warn(`token request failed: ${errorMessage(error)}`);
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
};
|
|
64
|
+
const readStatus = async () => {
|
|
65
|
+
if (!needsRuntimePermission())
|
|
66
|
+
return 'granted';
|
|
67
|
+
const granted = await react_native_1.PermissionsAndroid.check(react_native_1.PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
|
|
68
|
+
// Android tells "granted" or not; a refusal looks like "not asked" until the next request.
|
|
69
|
+
return granted ? 'granted' : 'not-asked';
|
|
70
|
+
};
|
|
71
|
+
return {
|
|
72
|
+
name: 'firebase',
|
|
73
|
+
start(nextHandlers) {
|
|
74
|
+
if (react_native_1.Platform.OS !== 'android') {
|
|
75
|
+
return () => { };
|
|
76
|
+
}
|
|
77
|
+
handlers = nextHandlers;
|
|
78
|
+
const unsubscribers = [];
|
|
79
|
+
try {
|
|
80
|
+
const messaging = firebase.getMessaging();
|
|
81
|
+
messagingInstance = messaging;
|
|
82
|
+
unsubscribers.push(firebase.onMessage(messaging, (message) => {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.foreground({
|
|
85
|
+
data: message.data,
|
|
86
|
+
title: (_a = message.notification) === null || _a === void 0 ? void 0 : _a.title,
|
|
87
|
+
body: (_b = message.notification) === null || _b === void 0 ? void 0 : _b.body,
|
|
88
|
+
});
|
|
89
|
+
}), firebase.onNotificationOpenedApp(messaging, (message) => {
|
|
90
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.tap(message.data);
|
|
91
|
+
}), firebase.onTokenRefresh(messaging, (token) => {
|
|
92
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.token({ token, provider: 'fcm' });
|
|
93
|
+
}));
|
|
94
|
+
firebase
|
|
95
|
+
.getInitialNotification(messaging)
|
|
96
|
+
.then((message) => {
|
|
97
|
+
if (message === null || message === void 0 ? void 0 : message.data)
|
|
98
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.tap(message.data);
|
|
99
|
+
})
|
|
100
|
+
.catch((error) => warn(`initial notification failed: ${errorMessage(error)}`));
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (isFirebaseNotConfigured(error)) {
|
|
104
|
+
warn('Firebase is not configured (android/app/google-services.json missing)');
|
|
105
|
+
nextHandlers.status('unavailable');
|
|
106
|
+
return () => { };
|
|
107
|
+
}
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
readStatus()
|
|
111
|
+
.then((status) => {
|
|
112
|
+
handlers === null || handlers === void 0 ? void 0 : handlers.status(status);
|
|
113
|
+
if (status === 'granted')
|
|
114
|
+
return reportToken();
|
|
115
|
+
return true;
|
|
116
|
+
})
|
|
117
|
+
.catch((error) => warn(`permission check failed: ${errorMessage(error)}`));
|
|
118
|
+
return () => {
|
|
119
|
+
unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
120
|
+
handlers = null;
|
|
121
|
+
messagingInstance = null;
|
|
122
|
+
};
|
|
123
|
+
},
|
|
124
|
+
async requestPermission() {
|
|
125
|
+
if (react_native_1.Platform.OS !== 'android') {
|
|
126
|
+
return 'unavailable';
|
|
127
|
+
}
|
|
128
|
+
let status = 'granted';
|
|
129
|
+
if (needsRuntimePermission()) {
|
|
130
|
+
const result = await react_native_1.PermissionsAndroid.request(react_native_1.PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS);
|
|
131
|
+
status = result === react_native_1.PermissionsAndroid.RESULTS.GRANTED ? 'granted' : 'denied';
|
|
132
|
+
}
|
|
133
|
+
if (status === 'granted' && !(await reportToken())) {
|
|
134
|
+
return 'unavailable';
|
|
135
|
+
}
|
|
136
|
+
return status;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type ForegroundPresentationState } from '../push';
|
|
2
|
+
import type { CobbaiPushAdapter, CobbaiPushStatus } from '../pushIntegration';
|
|
3
|
+
/** The native module of `ios/CobbaiPush.m`. */
|
|
4
|
+
export type NativeCobbaiPush = {
|
|
5
|
+
start(): Promise<{
|
|
6
|
+
token: string | null;
|
|
7
|
+
apnsEnvironment: 'sandbox' | 'production';
|
|
8
|
+
pendingTaps: unknown[];
|
|
9
|
+
inPlace: boolean;
|
|
10
|
+
status: CobbaiPushStatus;
|
|
11
|
+
}>;
|
|
12
|
+
setPresentationState(state: ForegroundPresentationState): void;
|
|
13
|
+
getPermissionStatus(): Promise<CobbaiPushStatus>;
|
|
14
|
+
requestPermission(): Promise<CobbaiPushStatus>;
|
|
15
|
+
reinstallRelay(): Promise<boolean>;
|
|
16
|
+
addListener(eventName: string): void;
|
|
17
|
+
removeListeners(count: number): void;
|
|
18
|
+
};
|
|
19
|
+
/** The iPhone relay's native module, or null (Android, or the pod not installed). */
|
|
20
|
+
export declare function getNativeCobbaiPush(): NativeCobbaiPush | null;
|
|
21
|
+
/**
|
|
22
|
+
* The SDK's own adapter on iPhone: token, taps (the launching one included) and
|
|
23
|
+
* foreground pushes come from the native relay, with no code in the app.
|
|
24
|
+
*/
|
|
25
|
+
export declare function iosRelayAdapter(native: NativeCobbaiPush): CobbaiPushAdapter;
|
|
26
|
+
//# sourceMappingURL=iosRelayAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iosRelayAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/iosRelayAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,2BAA2B,EACjC,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE9E,+CAA+C;AAC/C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,IAAI,OAAO,CAAC;QACf,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;QACrB,eAAe,EAAE,SAAS,GAAG,YAAY,CAAC;QAC1C,WAAW,EAAE,OAAO,EAAE,CAAC;QACvB,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,gBAAgB,CAAC;KAC1B,CAAC,CAAC;IACH,oBAAoB,CAAC,KAAK,EAAE,2BAA2B,GAAG,IAAI,CAAC;IAC/D,mBAAmB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACjD,iBAAiB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC/C,cAAc,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IACnC,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC,CAAC;AAMF,qFAAqF;AACrF,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,IAAI,CAG7D;AAwBD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,GAAG,iBAAiB,CA2E3E"}
|