beeper-inbox-native 0.1.2 → 0.1.4

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 CHANGED
@@ -19,6 +19,87 @@ the signed-in subscriber.
19
19
  </BeeperNativeInboxProvider>
20
20
  ```
21
21
 
22
+ ## Handling action presses
23
+
24
+ When a notification has an `actionUrl`, the built-in item shows an action button. By default,
25
+ pressing it opens the URL with `Linking.openURL`.
26
+
27
+ To route in-app instead (React Navigation, expo-router), pass `onActionPress` and return `false`
28
+ to skip the default:
29
+
30
+ ```tsx
31
+ <BeeperNativeInboxProvider
32
+ /* … */
33
+ onActionPress={({ actionUrl, item }) => {
34
+ if (actionUrl.startsWith("myapp://")) {
35
+ router.push(routeFromUrl(actionUrl));
36
+ return false; // handled: don't call Linking.openURL
37
+ }
38
+ // anything else (https links, say) falls through to Linking.openURL
39
+ }}
40
+ >
41
+ ```
42
+
43
+ - The handler can be `async`; resolving to `false` also skips the default.
44
+ - The press is recorded for click analytics either way, in the background. A failed recording
45
+ never blocks or cancels the action.
46
+ - If the handler throws, the URL is not opened and the error propagates, so a routing bug
47
+ surfaces instead of silently falling back to the browser.
48
+ - If no app on the device can open the URL, the press does nothing rather than crashing.
49
+
50
+ ## Building your own UI with `useBeeperInbox`
51
+
52
+ `useBeeperInbox()` gives any component inside the provider the live inbox state and its
53
+ actions, and re-renders when the inbox changes:
54
+
55
+ ```tsx
56
+ import { useBeeperInbox } from "beeper-inbox-native";
57
+
58
+ function InboxTabIcon() {
59
+ const { unreadCount } = useBeeperInbox();
60
+ return <TabIcon name="bell" badge={unreadCount || undefined} />;
61
+ }
62
+
63
+ function CustomInbox() {
64
+ const { items, loading, refreshing, errorMessage, refresh, markRead, markAllRead, handleActionPress } =
65
+ useBeeperInbox();
66
+
67
+ return (
68
+ <FlatList
69
+ data={items}
70
+ keyExtractor={(item) => item._id}
71
+ refreshing={refreshing}
72
+ onRefresh={() => refresh({ silent: true })}
73
+ renderItem={({ item }) => (
74
+ <Row
75
+ item={item}
76
+ onPress={() => markRead(item._id)}
77
+ onAction={() => handleActionPress(item)}
78
+ />
79
+ )}
80
+ />
81
+ );
82
+ }
83
+ ```
84
+
85
+ | Field | |
86
+ | --- | --- |
87
+ | `items`, `unreadCount` | Inbox contents and unread total |
88
+ | `loading`, `refreshing` | First load, and background refresh |
89
+ | `connectionState`, `errorMessage` | `"idle" \| "loading" \| "live" \| "error"`, and the last error |
90
+ | `subscriber` | The subscriber record, once loaded |
91
+ | `refresh({ silent? })` | Re-fetch now; `silent` skips the loading state |
92
+ | `markRead(id)`, `markAllRead()` | Mark items read (optimistic) |
93
+ | `registerPushToken(token, options)`, `unregisterPushToken(token)` | Manual push device management |
94
+ | `handleActionPress(item)` | Run an item's action exactly as the built-in button does, including `onActionPress` |
95
+
96
+ Use `handleActionPress` in custom rows rather than calling `Linking.openURL` yourself, so click
97
+ analytics and your `onActionPress` routing stay consistent with the built-in UI.
98
+
99
+ `useBeeperInbox` throws if it is used outside `BeeperNativeInboxProvider`.
100
+
101
+ ## Push tokens
102
+
22
103
  Use a native FCM token for both Android and iOS with the current Beeper push
23
104
  sender. Expo push tokens and raw APNs tokens require an additional provider
24
105
  integration.
package/dist/index.d.ts CHANGED
@@ -1,13 +1,45 @@
1
- import { type StyleProp, type TextStyle, type ViewStyle } from "react-native";
2
- import { type ReactNode } from "react";
3
- import type { InboxItemRecord, PushPlatform } from "beeper-sdk";
4
- export interface BeeperNativeSubscriber {
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { StyleProp, ViewStyle, TextStyle } from 'react-native';
3
+ import { ReactNode } from 'react';
4
+ import { SubscriberRecord, InboxItemRecord, PushPlatform } from 'beeper-sdk';
5
+
6
+ type InboxConnectionState = "idle" | "loading" | "live" | "error";
7
+ interface BeeperInboxCoreState {
8
+ subscriber: SubscriberRecord | null;
9
+ items: InboxItemRecord[];
10
+ unreadCount: number;
11
+ loading: boolean;
12
+ refreshing: boolean;
13
+ connectionState: InboxConnectionState;
14
+ errorMessage: string | null;
15
+ }
16
+ interface RegisterPushTokenOptions {
17
+ platform: PushPlatform;
18
+ deviceLabel?: string;
19
+ metadata?: Record<string, unknown>;
20
+ }
21
+
22
+ /** What `onActionPress` receives when an inbox item's action is pressed. */
23
+ interface BeeperNativeActionPress {
24
+ item: InboxItemRecord;
25
+ actionLabel?: string;
26
+ actionUrl: string;
27
+ }
28
+ /**
29
+ * Called when an inbox item's action is pressed, before the default behaviour.
30
+ * Return `false` (or resolve to `false`) to stop the package from opening the
31
+ * URL with `Linking.openURL` — e.g. after routing in-app with React Navigation or
32
+ * expo-router. Any other return value lets the default run.
33
+ */
34
+ type BeeperNativeActionPressHandler = (action: BeeperNativeActionPress) => boolean | void | Promise<boolean | void>;
35
+
36
+ interface BeeperNativeSubscriber {
5
37
  subscriberId: string;
6
38
  displayName?: string;
7
39
  email?: string;
8
40
  metadata?: Record<string, unknown>;
9
41
  }
10
- export interface BeeperNativePushRegistration {
42
+ interface BeeperNativePushRegistration {
11
43
  token?: string;
12
44
  platform?: Extract<PushPlatform, "ios" | "android">;
13
45
  deviceLabel?: string;
@@ -15,7 +47,7 @@ export interface BeeperNativePushRegistration {
15
47
  autoRegister?: boolean;
16
48
  autoUnregister?: boolean;
17
49
  }
18
- export interface BeeperNativeInboxProviderProps {
50
+ interface BeeperNativeInboxProviderProps {
19
51
  /**
20
52
  * Optional advanced override for the Beeper Widget API origin. Defaults to the
21
53
  * hosted Beeper API. Most host apps should not pass this.
@@ -29,24 +61,66 @@ export interface BeeperNativeInboxProviderProps {
29
61
  push?: BeeperNativePushRegistration;
30
62
  pollIntervalMs?: number;
31
63
  accentColor?: string;
64
+ /**
65
+ * Intercepts an inbox item's action press. Return `false` to skip the default
66
+ * `Linking.openURL`, e.g. to navigate in-app instead:
67
+ *
68
+ * ```tsx
69
+ * onActionPress={({ actionUrl }) => {
70
+ * if (actionUrl.startsWith("myapp://")) {
71
+ * router.push(toRoute(actionUrl));
72
+ * return false;
73
+ * }
74
+ * }}
75
+ * ```
76
+ */
77
+ onActionPress?: BeeperNativeActionPressHandler;
32
78
  children: ReactNode;
33
79
  }
34
- export declare function BeeperNativeInboxProvider({ baseUrl, projectId, publishableKey, sessionToken, refreshSessionToken, subscriber, push, pollIntervalMs, accentColor, children, }: BeeperNativeInboxProviderProps): import("react/jsx-runtime").JSX.Element;
35
- export declare function BeeperInboxBadge({ onPress, style, textStyle, }: {
80
+ /** What `useBeeperInbox()` returns: live inbox state plus the actions on it. */
81
+ interface BeeperNativeInbox extends BeeperInboxCoreState {
82
+ /** Re-fetches the inbox. `silent` skips the loading state. */
83
+ refresh: (options?: {
84
+ silent?: boolean;
85
+ }) => Promise<void>;
86
+ markRead: (inboxItemId: string) => Promise<void>;
87
+ markAllRead: () => Promise<void>;
88
+ registerPushToken: (token: string, options: RegisterPushTokenOptions) => Promise<void>;
89
+ unregisterPushToken: (token: string) => Promise<void>;
90
+ /**
91
+ * Performs an item's action exactly as the built-in item does: records the
92
+ * click, calls `onActionPress`, then opens the URL unless it returned `false`.
93
+ * Use it from custom item UIs so their analytics and routing stay consistent.
94
+ */
95
+ handleActionPress: (item: InboxItemRecord) => Promise<void>;
96
+ }
97
+ declare function BeeperNativeInboxProvider({ baseUrl, projectId, publishableKey, sessionToken, refreshSessionToken, subscriber, push, pollIntervalMs, accentColor, onActionPress, children, }: BeeperNativeInboxProviderProps): react_jsx_runtime.JSX.Element;
98
+ /**
99
+ * Live inbox state and actions, for building your own UI or showing the unread
100
+ * count elsewhere (a tab bar badge, say). Must be used inside
101
+ * `BeeperNativeInboxProvider`; re-renders when the inbox changes.
102
+ *
103
+ * ```tsx
104
+ * const { items, unreadCount, markRead, handleActionPress } = useBeeperInbox();
105
+ * ```
106
+ */
107
+ declare function useBeeperInbox(): BeeperNativeInbox;
108
+ declare function BeeperInboxBadge({ onPress, style, textStyle, }: {
36
109
  onPress?: () => void;
37
110
  style?: StyleProp<ViewStyle>;
38
111
  textStyle?: StyleProp<TextStyle>;
39
- }): import("react/jsx-runtime").JSX.Element;
40
- export declare function BeeperInboxItem({ item }: {
112
+ }): react_jsx_runtime.JSX.Element;
113
+ declare function BeeperInboxItem({ item }: {
41
114
  item: InboxItemRecord;
42
- }): import("react/jsx-runtime").JSX.Element;
43
- export declare function BeeperInboxList({ style, contentContainerStyle, }: {
115
+ }): react_jsx_runtime.JSX.Element;
116
+ declare function BeeperInboxList({ style, contentContainerStyle, }: {
44
117
  style?: StyleProp<ViewStyle>;
45
118
  contentContainerStyle?: StyleProp<ViewStyle>;
46
- }): import("react/jsx-runtime").JSX.Element;
47
- export declare function BeeperInboxPanel({ title, style, }: {
119
+ }): react_jsx_runtime.JSX.Element;
120
+ declare function BeeperInboxPanel({ title, style, }: {
48
121
  title?: string;
49
122
  style?: StyleProp<ViewStyle>;
50
- }): import("react/jsx-runtime").JSX.Element;
51
- export declare function BeeperInboxRefreshControl(): import("react/jsx-runtime").JSX.Element;
52
- //# sourceMappingURL=index.d.ts.map
123
+ }): react_jsx_runtime.JSX.Element;
124
+ declare function BeeperInboxRefreshControl(): react_jsx_runtime.JSX.Element;
125
+
126
+ export { BeeperInboxBadge, BeeperInboxItem, BeeperInboxList, BeeperInboxPanel, BeeperInboxRefreshControl, type BeeperNativeActionPress, type BeeperNativeActionPressHandler, type BeeperNativeInbox, BeeperNativeInboxProvider, type BeeperNativeInboxProviderProps, type BeeperNativePushRegistration, type BeeperNativeSubscriber, useBeeperInbox };
package/dist/index.js CHANGED
@@ -1,118 +1,421 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ActivityIndicator, FlatList, Linking, Pressable, StyleSheet, Text, View, } from "react-native";
3
- import { createContext, useContext, useEffect, useMemo, useSyncExternalStore, } from "react";
4
- import { BeeperInboxCore } from "beeper-inbox-core";
5
- import { BeeperWidgetClient } from "beeper-sdk/widget";
6
- const InboxContext = createContext(null);
7
- export function BeeperNativeInboxProvider({ baseUrl, projectId, publishableKey, sessionToken, refreshSessionToken, subscriber, push, pollIntervalMs, accentColor = "#f97316", children, }) {
8
- const client = useMemo(() => new BeeperWidgetClient({
9
- baseUrl,
10
- projectId,
11
- publishableKey,
12
- sessionToken,
13
- }), [baseUrl, projectId, publishableKey, sessionToken]);
14
- const core = useMemo(() => new BeeperInboxCore({
15
- client,
16
- subscriberId: subscriber.subscriberId,
17
- refreshSessionToken,
18
- pollIntervalMs,
19
- }), [client, pollIntervalMs, refreshSessionToken, subscriber.subscriberId]);
20
- const state = useSyncExternalStore((listener) => core.subscribe(listener), () => core.getState(), () => core.getState());
21
- useEffect(() => {
22
- void core.start().catch(() => undefined);
23
- return () => core.stop();
24
- }, [core]);
25
- useEffect(() => {
26
- if (!push?.token || push.autoRegister === false) {
27
- return;
28
- }
29
- void core
30
- .registerPushToken(push.token, {
31
- platform: push.platform ?? "android",
32
- deviceLabel: push.deviceLabel,
33
- metadata: push.metadata,
34
- })
35
- .catch(() => undefined);
36
- if (push.autoUnregister) {
37
- return () => {
38
- void core.unregisterPushToken(push.token);
39
- };
40
- }
41
- }, [core, push]);
42
- const value = useMemo(() => ({ core, state, accentColor }), [accentColor, core, state]);
43
- return _jsx(InboxContext.Provider, { value: value, children: children });
44
- }
45
- function useNativeInbox() {
46
- const context = useContext(InboxContext);
47
- if (!context) {
48
- throw new Error("Beeper inbox components must be inside BeeperNativeInboxProvider");
1
+ import { StyleSheet, View, Text, Pressable, ActivityIndicator, FlatList, Linking } from 'react-native';
2
+ import { createContext, useMemo, useSyncExternalStore, useEffect, useRef, useContext } from 'react';
3
+ import { BeeperApiError } from 'beeper-sdk';
4
+ import { BeeperWidgetClient } from 'beeper-sdk/widget';
5
+ import { jsx, jsxs } from 'react/jsx-runtime';
6
+
7
+ // src/index.tsx
8
+ var DEFAULT_POLL_INTERVAL_MS = 15e3;
9
+ var BeeperInboxCore = class {
10
+ client;
11
+ subscriberId;
12
+ refreshSessionToken;
13
+ pollIntervalMs;
14
+ listeners = /* @__PURE__ */ new Set();
15
+ state = {
16
+ subscriber: null,
17
+ items: [],
18
+ unreadCount: 0,
19
+ loading: false,
20
+ refreshing: false,
21
+ connectionState: "idle",
22
+ errorMessage: null
23
+ };
24
+ pollTimer = null;
25
+ started = false;
26
+ request = null;
27
+ constructor(options) {
28
+ if (!options.subscriberId.trim()) {
29
+ throw new Error("A subscriberId is required");
49
30
  }
50
- return context;
51
- }
52
- export function BeeperInboxBadge({ onPress, style, textStyle, }) {
53
- const { state, accentColor } = useNativeInbox();
54
- const content = (_jsx(View, { style: [styles.badge, { backgroundColor: accentColor }, style], children: _jsx(Text, { style: [styles.badgeText, textStyle], children: state.unreadCount > 99 ? "99+" : state.unreadCount }) }));
55
- return onPress ? _jsx(Pressable, { accessibilityRole: "button", onPress: onPress, children: content }) : content;
56
- }
57
- export function BeeperInboxItem({ item }) {
58
- const { core, accentColor } = useNativeInbox();
59
- async function onActionPress() {
60
- if (!item.actionUrl)
61
- return;
62
- await core.logActionClick(item, item.actionUrl, item.actionLabel);
63
- await Linking.openURL(item.actionUrl);
31
+ this.client = options.client;
32
+ this.subscriberId = options.subscriberId;
33
+ this.refreshSessionToken = options.refreshSessionToken;
34
+ this.pollIntervalMs = Math.max(5e3, options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);
35
+ }
36
+ getState() {
37
+ return this.state;
38
+ }
39
+ subscribe(listener) {
40
+ this.listeners.add(listener);
41
+ listener(this.state);
42
+ return () => this.listeners.delete(listener);
43
+ }
44
+ async start() {
45
+ if (this.started) {
46
+ return;
47
+ }
48
+ this.started = true;
49
+ await this.refresh();
50
+ }
51
+ stop() {
52
+ this.started = false;
53
+ this.clearPollTimer();
54
+ }
55
+ async refresh(options = {}) {
56
+ if (this.request) {
57
+ return this.request;
58
+ }
59
+ this.update({
60
+ ...options.silent ? { refreshing: true } : { loading: true },
61
+ connectionState: options.silent ? this.state.connectionState : "loading",
62
+ errorMessage: null
63
+ });
64
+ this.request = this.requestWithSessionRetry(async () => {
65
+ const result = await this.client.getInbox(this.subscriberId, 100);
66
+ this.update({
67
+ subscriber: result.subscriber,
68
+ items: result.items,
69
+ unreadCount: result.unreadCount,
70
+ connectionState: "live",
71
+ errorMessage: null
72
+ });
73
+ }).catch((error) => {
74
+ this.update({
75
+ connectionState: "error",
76
+ errorMessage: error instanceof Error ? error.message : "Inbox request failed"
77
+ });
78
+ throw error;
79
+ }).finally(() => {
80
+ this.request = null;
81
+ this.update({ loading: false, refreshing: false });
82
+ this.schedulePoll();
83
+ });
84
+ return this.request;
85
+ }
86
+ async markRead(inboxItemId) {
87
+ const previous = this.state;
88
+ const now = Date.now();
89
+ this.update({
90
+ items: this.state.items.map((item) => item._id === inboxItemId ? { ...item, readAt: item.readAt ?? now } : item),
91
+ unreadCount: Math.max(0, this.state.unreadCount - (this.state.items.some((item) => item._id === inboxItemId && !item.readAt) ? 1 : 0))
92
+ });
93
+ try {
94
+ await this.requestWithSessionRetry(() => this.client.markRead(this.subscriberId, [inboxItemId]));
95
+ await this.refresh({ silent: true });
96
+ } catch (error) {
97
+ this.state = previous;
98
+ this.emit();
99
+ throw error;
100
+ }
101
+ }
102
+ async markAllRead() {
103
+ const previous = this.state;
104
+ this.update({
105
+ items: this.state.items.map((item) => ({ ...item, readAt: item.readAt ?? Date.now() })),
106
+ unreadCount: 0
107
+ });
108
+ try {
109
+ await this.requestWithSessionRetry(() => this.client.markAllRead(this.subscriberId));
110
+ await this.refresh({ silent: true });
111
+ } catch (error) {
112
+ this.state = previous;
113
+ this.emit();
114
+ throw error;
115
+ }
116
+ }
117
+ async registerPushToken(token, options) {
118
+ const normalizedToken = token.trim();
119
+ if (!normalizedToken) {
120
+ throw new Error("A push token is required");
121
+ }
122
+ await this.requestWithSessionRetry(() => this.client.registerPushDevice({
123
+ subscriberId: this.subscriberId,
124
+ pushToken: normalizedToken,
125
+ ...options
126
+ }));
127
+ }
128
+ async unregisterPushToken(token) {
129
+ const normalizedToken = token.trim();
130
+ if (!normalizedToken) {
131
+ return;
64
132
  }
65
- return (_jsxs(View, { style: styles.item, children: [_jsx(Text, { style: styles.itemTitle, children: item.title ?? "Notification" }), _jsx(Text, { style: styles.itemBody, children: item.body }), _jsxs(View, { style: styles.itemFooter, children: [_jsx(Text, { style: styles.itemDate, children: new Date(item.createdAt).toLocaleString() }), !item.readAt ? (_jsx(Pressable, { accessibilityRole: "button", accessibilityLabel: "Mark notification as read", onPress: () => void core.markRead(item._id), children: _jsx(Text, { style: [styles.actionText, { color: accentColor }], children: "Mark read" }) })) : null, item.actionUrl ? (_jsx(Pressable, { accessibilityRole: "button", onPress: () => void onActionPress(), children: _jsx(Text, { style: [styles.actionText, { color: accentColor }], children: item.actionLabel ?? "Open" }) })) : null] })] }));
133
+ await this.requestWithSessionRetry(() => this.client.unregisterPushDevice({
134
+ subscriberId: this.subscriberId,
135
+ pushToken: normalizedToken
136
+ }));
137
+ }
138
+ async logActionClick(item, actionUrl, actionLabel) {
139
+ return this.requestWithSessionRetry(() => this.client.logActionClick({
140
+ subscriberId: this.subscriberId,
141
+ inboxItemId: item._id,
142
+ actionUrl,
143
+ actionLabel
144
+ }));
145
+ }
146
+ async requestWithSessionRetry(request) {
147
+ try {
148
+ return await request();
149
+ } catch (error) {
150
+ if (!(error instanceof BeeperApiError) || error.status !== 401 || !this.refreshSessionToken) {
151
+ throw error;
152
+ }
153
+ const nextToken = await this.refreshSessionToken();
154
+ this.client.updateSessionToken(nextToken);
155
+ return request();
156
+ }
157
+ }
158
+ update(patch) {
159
+ this.state = { ...this.state, ...patch };
160
+ this.emit();
161
+ }
162
+ emit() {
163
+ for (const listener of this.listeners) {
164
+ listener(this.state);
165
+ }
166
+ }
167
+ schedulePoll() {
168
+ if (!this.started || this.pollTimer) {
169
+ return;
170
+ }
171
+ this.pollTimer = setTimeout(() => {
172
+ this.pollTimer = null;
173
+ void this.refresh({ silent: true }).catch(() => void 0);
174
+ }, this.pollIntervalMs);
175
+ }
176
+ clearPollTimer() {
177
+ if (this.pollTimer) {
178
+ clearTimeout(this.pollTimer);
179
+ this.pollTimer = null;
180
+ }
181
+ }
182
+ };
183
+
184
+ // src/actionPress.ts
185
+ async function runActionPress(input) {
186
+ const actionUrl = input.item.actionUrl?.trim();
187
+ if (!actionUrl) {
188
+ return;
189
+ }
190
+ void input.logActionClick(input.item, actionUrl, input.item.actionLabel).catch(() => void 0);
191
+ const shouldOpen = await input.onActionPress?.({
192
+ item: input.item,
193
+ actionLabel: input.item.actionLabel,
194
+ actionUrl
195
+ }) !== false;
196
+ if (!shouldOpen) {
197
+ return;
198
+ }
199
+ try {
200
+ await input.openURL(actionUrl);
201
+ } catch {
202
+ }
66
203
  }
67
- export function BeeperInboxList({ style, contentContainerStyle, }) {
68
- const { state } = useNativeInbox();
69
- if (state.loading && state.items.length === 0) {
70
- return _jsx(ActivityIndicator, { accessibilityLabel: "Loading notifications", style: styles.loader });
204
+ var InboxContext = createContext(null);
205
+ function BeeperNativeInboxProvider({
206
+ baseUrl,
207
+ projectId,
208
+ publishableKey,
209
+ sessionToken,
210
+ refreshSessionToken,
211
+ subscriber,
212
+ push,
213
+ pollIntervalMs,
214
+ accentColor = "#f97316",
215
+ onActionPress,
216
+ children
217
+ }) {
218
+ const client = useMemo(
219
+ () => new BeeperWidgetClient({
220
+ baseUrl,
221
+ projectId,
222
+ publishableKey,
223
+ sessionToken
224
+ }),
225
+ [baseUrl, projectId, publishableKey, sessionToken]
226
+ );
227
+ const core = useMemo(
228
+ () => new BeeperInboxCore({
229
+ client,
230
+ subscriberId: subscriber.subscriberId,
231
+ refreshSessionToken,
232
+ pollIntervalMs
233
+ }),
234
+ [client, pollIntervalMs, refreshSessionToken, subscriber.subscriberId]
235
+ );
236
+ const state = useSyncExternalStore(
237
+ (listener) => core.subscribe(listener),
238
+ () => core.getState(),
239
+ () => core.getState()
240
+ );
241
+ useEffect(() => {
242
+ void core.start().catch(() => void 0);
243
+ return () => core.stop();
244
+ }, [core]);
245
+ useEffect(() => {
246
+ if (!push?.token || push.autoRegister === false) {
247
+ return;
71
248
  }
72
- if (state.errorMessage && state.items.length === 0) {
73
- return _jsx(Text, { accessibilityRole: "alert", style: styles.error, children: state.errorMessage });
249
+ void core.registerPushToken(push.token, {
250
+ platform: push.platform ?? "android",
251
+ deviceLabel: push.deviceLabel,
252
+ metadata: push.metadata
253
+ }).catch(() => void 0);
254
+ if (push.autoUnregister) {
255
+ return () => {
256
+ void core.unregisterPushToken(push.token);
257
+ };
74
258
  }
75
- if (state.items.length === 0) {
76
- return _jsx(Text, { style: styles.empty, children: "No notifications yet." });
259
+ }, [core, push]);
260
+ const onActionPressRef = useRef(onActionPress);
261
+ useEffect(() => {
262
+ onActionPressRef.current = onActionPress;
263
+ }, [onActionPress]);
264
+ const actions = useMemo(
265
+ () => ({
266
+ refresh: async (options) => {
267
+ await core.refresh(options);
268
+ },
269
+ markRead: async (inboxItemId) => {
270
+ await core.markRead(inboxItemId);
271
+ },
272
+ markAllRead: async () => {
273
+ await core.markAllRead();
274
+ },
275
+ registerPushToken: async (token, options) => {
276
+ await core.registerPushToken(token, options);
277
+ },
278
+ unregisterPushToken: async (token) => {
279
+ await core.unregisterPushToken(token);
280
+ },
281
+ handleActionPress: (item) => runActionPress({
282
+ item,
283
+ onActionPress: onActionPressRef.current,
284
+ logActionClick: (target, actionUrl, actionLabel) => core.logActionClick(target, actionUrl, actionLabel),
285
+ openURL: (url) => Linking.openURL(url)
286
+ })
287
+ }),
288
+ [core]
289
+ );
290
+ const value = useMemo(
291
+ () => ({ core, state, accentColor, actions }),
292
+ [accentColor, actions, core, state]
293
+ );
294
+ return /* @__PURE__ */ jsx(InboxContext.Provider, { value, children });
295
+ }
296
+ function useNativeInbox() {
297
+ const context = useContext(InboxContext);
298
+ if (!context) {
299
+ throw new Error("Beeper inbox components must be inside BeeperNativeInboxProvider");
300
+ }
301
+ return context;
302
+ }
303
+ function useBeeperInbox() {
304
+ const context = useContext(InboxContext);
305
+ if (!context) {
306
+ throw new Error("useBeeperInbox must be used inside BeeperNativeInboxProvider");
307
+ }
308
+ return { ...context.state, ...context.actions };
309
+ }
310
+ function BeeperInboxBadge({
311
+ onPress,
312
+ style,
313
+ textStyle
314
+ }) {
315
+ const { state, accentColor } = useNativeInbox();
316
+ const content = /* @__PURE__ */ jsx(View, { style: [styles.badge, { backgroundColor: accentColor }, style], children: /* @__PURE__ */ jsx(Text, { style: [styles.badgeText, textStyle], children: state.unreadCount > 99 ? "99+" : state.unreadCount }) });
317
+ return onPress ? /* @__PURE__ */ jsx(Pressable, { accessibilityRole: "button", onPress, children: content }) : content;
318
+ }
319
+ function BeeperInboxItem({ item }) {
320
+ const { core, accentColor, actions } = useNativeInbox();
321
+ return /* @__PURE__ */ jsxs(View, { style: styles.item, children: [
322
+ /* @__PURE__ */ jsx(Text, { style: styles.itemTitle, children: item.title ?? "Notification" }),
323
+ /* @__PURE__ */ jsx(Text, { style: styles.itemBody, children: item.body }),
324
+ /* @__PURE__ */ jsxs(View, { style: styles.itemFooter, children: [
325
+ /* @__PURE__ */ jsx(Text, { style: styles.itemDate, children: new Date(item.createdAt).toLocaleString() }),
326
+ !item.readAt ? /* @__PURE__ */ jsx(
327
+ Pressable,
328
+ {
329
+ accessibilityRole: "button",
330
+ accessibilityLabel: "Mark notification as read",
331
+ onPress: () => void core.markRead(item._id),
332
+ children: /* @__PURE__ */ jsx(Text, { style: [styles.actionText, { color: accentColor }], children: "Mark read" })
333
+ }
334
+ ) : null,
335
+ item.actionUrl ? /* @__PURE__ */ jsx(Pressable, { accessibilityRole: "button", onPress: () => void actions.handleActionPress(item), children: /* @__PURE__ */ jsx(Text, { style: [styles.actionText, { color: accentColor }], children: item.actionLabel ?? "Open" }) }) : null
336
+ ] })
337
+ ] });
338
+ }
339
+ function BeeperInboxList({
340
+ style,
341
+ contentContainerStyle
342
+ }) {
343
+ const { state } = useNativeInbox();
344
+ if (state.loading && state.items.length === 0) {
345
+ return /* @__PURE__ */ jsx(ActivityIndicator, { accessibilityLabel: "Loading notifications", style: styles.loader });
346
+ }
347
+ if (state.errorMessage && state.items.length === 0) {
348
+ return /* @__PURE__ */ jsx(Text, { accessibilityRole: "alert", style: styles.error, children: state.errorMessage });
349
+ }
350
+ if (state.items.length === 0) {
351
+ return /* @__PURE__ */ jsx(Text, { style: styles.empty, children: "No notifications yet." });
352
+ }
353
+ const renderItem = ({ item }) => /* @__PURE__ */ jsx(BeeperInboxItem, { item });
354
+ return /* @__PURE__ */ jsx(
355
+ FlatList,
356
+ {
357
+ accessibilityLabel: "Notifications",
358
+ data: state.items,
359
+ keyExtractor: (item) => item._id,
360
+ renderItem,
361
+ style,
362
+ contentContainerStyle
77
363
  }
78
- const renderItem = ({ item }) => _jsx(BeeperInboxItem, { item: item });
79
- return (_jsx(FlatList, { accessibilityLabel: "Notifications", data: state.items, keyExtractor: (item) => item._id, renderItem: renderItem, style: style, contentContainerStyle: contentContainerStyle }));
364
+ );
80
365
  }
81
- export function BeeperInboxPanel({ title = "Notifications", style, }) {
82
- const { core, state, accentColor } = useNativeInbox();
83
- return (_jsxs(View, { style: [styles.panel, style], children: [_jsxs(View, { style: styles.header, children: [_jsxs(View, { children: [_jsx(Text, { style: styles.title, children: title }), _jsxs(Text, { style: styles.subtitle, accessibilityLiveRegion: "polite", children: [state.unreadCount, " unread"] })] }), state.unreadCount > 0 ? (_jsx(Pressable, { accessibilityRole: "button", onPress: () => void core.markAllRead(), children: _jsx(Text, { style: [styles.actionText, { color: accentColor }], children: "Mark all read" }) })) : null] }), _jsx(BeeperInboxList, { contentContainerStyle: styles.listContent })] }));
366
+ function BeeperInboxPanel({
367
+ title = "Notifications",
368
+ style
369
+ }) {
370
+ const { core, state, accentColor } = useNativeInbox();
371
+ return /* @__PURE__ */ jsxs(View, { style: [styles.panel, style], children: [
372
+ /* @__PURE__ */ jsxs(View, { style: styles.header, children: [
373
+ /* @__PURE__ */ jsxs(View, { children: [
374
+ /* @__PURE__ */ jsx(Text, { style: styles.title, children: title }),
375
+ /* @__PURE__ */ jsxs(Text, { style: styles.subtitle, accessibilityLiveRegion: "polite", children: [
376
+ state.unreadCount,
377
+ " unread"
378
+ ] })
379
+ ] }),
380
+ state.unreadCount > 0 ? /* @__PURE__ */ jsx(Pressable, { accessibilityRole: "button", onPress: () => void core.markAllRead(), children: /* @__PURE__ */ jsx(Text, { style: [styles.actionText, { color: accentColor }], children: "Mark all read" }) }) : null
381
+ ] }),
382
+ /* @__PURE__ */ jsx(BeeperInboxList, { contentContainerStyle: styles.listContent })
383
+ ] });
84
384
  }
85
- export function BeeperInboxRefreshControl() {
86
- const { core, state } = useNativeInbox();
87
- return (_jsx(Pressable, { accessibilityRole: "button", onPress: () => void core.refresh({ silent: true }), children: _jsx(Text, { style: styles.actionText, children: state.refreshing ? "Refreshing..." : "Refresh" }) }));
385
+ function BeeperInboxRefreshControl() {
386
+ const { core, state } = useNativeInbox();
387
+ return /* @__PURE__ */ jsx(Pressable, { accessibilityRole: "button", onPress: () => void core.refresh({ silent: true }), children: /* @__PURE__ */ jsx(Text, { style: styles.actionText, children: state.refreshing ? "Refreshing..." : "Refresh" }) });
88
388
  }
89
- const styles = StyleSheet.create({
90
- panel: {
91
- backgroundColor: "#fffaf5",
92
- borderColor: "#eadbcc",
93
- borderRadius: 14,
94
- borderWidth: 1,
95
- padding: 14,
96
- },
97
- header: {
98
- alignItems: "center",
99
- flexDirection: "row",
100
- justifyContent: "space-between",
101
- marginBottom: 12,
102
- },
103
- title: { color: "#2b221d", fontSize: 18, fontWeight: "700" },
104
- subtitle: { color: "#7d685d", fontSize: 13, marginTop: 2 },
105
- listContent: { gap: 8 },
106
- item: { backgroundColor: "#fffdf9", borderColor: "#eadbcc", borderRadius: 10, borderWidth: 1, padding: 14 },
107
- itemTitle: { color: "#2b221d", fontSize: 15, fontWeight: "700", marginBottom: 5 },
108
- itemBody: { color: "#4e3c34", fontSize: 14, lineHeight: 21 },
109
- itemFooter: { alignItems: "center", flexDirection: "row", flexWrap: "wrap", gap: 12, marginTop: 10 },
110
- itemDate: { color: "#7d685d", flex: 1, fontSize: 12 },
111
- actionText: { fontSize: 13, fontWeight: "700", paddingVertical: 8 },
112
- badge: { alignItems: "center", borderRadius: 999, justifyContent: "center", minHeight: 24, minWidth: 24, paddingHorizontal: 7 },
113
- badgeText: { color: "#fff", fontSize: 12, fontWeight: "700" },
114
- loader: { padding: 24 },
115
- empty: { color: "#7d685d", padding: 24, textAlign: "center" },
116
- error: { color: "#a43d28", padding: 24, textAlign: "center" },
389
+ var styles = StyleSheet.create({
390
+ panel: {
391
+ backgroundColor: "#fffaf5",
392
+ borderColor: "#eadbcc",
393
+ borderRadius: 14,
394
+ borderWidth: 1,
395
+ padding: 14
396
+ },
397
+ header: {
398
+ alignItems: "center",
399
+ flexDirection: "row",
400
+ justifyContent: "space-between",
401
+ marginBottom: 12
402
+ },
403
+ title: { color: "#2b221d", fontSize: 18, fontWeight: "700" },
404
+ subtitle: { color: "#7d685d", fontSize: 13, marginTop: 2 },
405
+ listContent: { gap: 8 },
406
+ item: { backgroundColor: "#fffdf9", borderColor: "#eadbcc", borderRadius: 10, borderWidth: 1, padding: 14 },
407
+ itemTitle: { color: "#2b221d", fontSize: 15, fontWeight: "700", marginBottom: 5 },
408
+ itemBody: { color: "#4e3c34", fontSize: 14, lineHeight: 21 },
409
+ itemFooter: { alignItems: "center", flexDirection: "row", flexWrap: "wrap", gap: 12, marginTop: 10 },
410
+ itemDate: { color: "#7d685d", flex: 1, fontSize: 12 },
411
+ actionText: { fontSize: 13, fontWeight: "700", paddingVertical: 8 },
412
+ badge: { alignItems: "center", borderRadius: 999, justifyContent: "center", minHeight: 24, minWidth: 24, paddingHorizontal: 7 },
413
+ badgeText: { color: "#fff", fontSize: 12, fontWeight: "700" },
414
+ loader: { padding: 24 },
415
+ empty: { color: "#7d685d", padding: 24, textAlign: "center" },
416
+ error: { color: "#a43d28", padding: 24, textAlign: "center" }
117
417
  });
418
+
419
+ export { BeeperInboxBadge, BeeperInboxItem, BeeperInboxList, BeeperInboxPanel, BeeperInboxRefreshControl, BeeperNativeInboxProvider, useBeeperInbox };
420
+ //# sourceMappingURL=index.js.map
118
421
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,OAAO,EACP,SAAS,EACT,UAAU,EACV,IAAI,EACJ,IAAI,GAKL,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,aAAa,EACb,UAAU,EACV,SAAS,EACT,OAAO,EACP,oBAAoB,GAErB,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AA0CvD,MAAM,YAAY,GAAG,aAAa,CAAiC,IAAI,CAAC,CAAC;AAEzE,MAAM,UAAU,yBAAyB,CAAC,EACxC,OAAO,EACP,SAAS,EACT,cAAc,EACd,YAAY,EACZ,mBAAmB,EACnB,UAAU,EACV,IAAI,EACJ,cAAc,EACd,WAAW,GAAG,SAAS,EACvB,QAAQ,GACuB;IAC/B,MAAM,MAAM,GAAG,OAAO,CACpB,GAAG,EAAE,CACH,IAAI,kBAAkB,CAAC;QACrB,OAAO;QACP,SAAS;QACT,cAAc;QACd,YAAY;KACb,CAAC,EACJ,CAAC,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,CAAC,CACnD,CAAC;IACF,MAAM,IAAI,GAAG,OAAO,CAClB,GAAG,EAAE,CACH,IAAI,eAAe,CAAC;QAClB,MAAM;QACN,YAAY,EAAE,UAAU,CAAC,YAAY;QACrC,mBAAmB;QACnB,cAAc;KACf,CAAC,EACJ,CAAC,MAAM,EAAE,cAAc,EAAE,mBAAmB,EAAE,UAAU,CAAC,YAAY,CAAC,CACvE,CAAC;IACF,MAAM,KAAK,GAAG,oBAAoB,CAChC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC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,SAAA,EAAW,EAAA,EAAG;AAAA,EACnG,UAAU,EAAE,KAAA,EAAO,WAAW,IAAA,EAAM,CAAA,EAAG,UAAU,EAAA,EAAG;AAAA,EACpD,YAAY,EAAE,QAAA,EAAU,IAAI,UAAA,EAAY,KAAA,EAAO,iBAAiB,CAAA,EAAE;AAAA,EAClE,KAAA,EAAO,EAAE,UAAA,EAAY,QAAA,EAAU,YAAA,EAAc,GAAA,EAAK,cAAA,EAAgB,QAAA,EAAU,SAAA,EAAW,EAAA,EAAI,QAAA,EAAU,EAAA,EAAI,mBAAmB,CAAA,EAAE;AAAA,EAC9H,WAAW,EAAE,KAAA,EAAO,QAAQ,QAAA,EAAU,EAAA,EAAI,YAAY,KAAA,EAAM;AAAA,EAC5D,MAAA,EAAQ,EAAE,OAAA,EAAS,EAAA,EAAG;AAAA,EACtB,OAAO,EAAE,KAAA,EAAO,WAAW,OAAA,EAAS,EAAA,EAAI,WAAW,QAAA,EAAS;AAAA,EAC5D,OAAO,EAAE,KAAA,EAAO,WAAW,OAAA,EAAS,EAAA,EAAI,WAAW,QAAA;AACrD,CAAC,CAAA","file":"index.js","sourcesContent":["import { BeeperApiError } from \"beeper-sdk\";\nimport type {\n InboxItemRecord,\n PushPlatform,\n SubscriberRecord,\n} from \"beeper-sdk\";\nimport type { BeeperWidgetClient } from \"beeper-sdk/widget\";\n\nexport type InboxConnectionState = \"idle\" | \"loading\" | \"live\" | \"error\";\n\nexport interface BeeperInboxCoreState {\n subscriber: SubscriberRecord | null;\n items: InboxItemRecord[];\n unreadCount: number;\n loading: boolean;\n refreshing: boolean;\n connectionState: InboxConnectionState;\n errorMessage: string | null;\n}\n\nexport interface BeeperInboxCoreOptions {\n client: BeeperWidgetClient;\n subscriberId: string;\n refreshSessionToken?: () => Promise<string>;\n pollIntervalMs?: number;\n}\n\nexport interface RegisterPushTokenOptions {\n platform: PushPlatform;\n deviceLabel?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport type BeeperInboxCoreListener = (state: BeeperInboxCoreState) => void;\n\nconst DEFAULT_POLL_INTERVAL_MS = 15_000;\n\nexport class BeeperInboxCore {\n private readonly client: BeeperWidgetClient;\n private readonly subscriberId: string;\n private readonly refreshSessionToken?: () => Promise<string>;\n private readonly pollIntervalMs: number;\n private readonly listeners = new Set<BeeperInboxCoreListener>();\n private state: BeeperInboxCoreState = {\n subscriber: null,\n items: [],\n unreadCount: 0,\n loading: false,\n refreshing: false,\n connectionState: \"idle\",\n errorMessage: null,\n };\n private pollTimer: ReturnType<typeof setTimeout> | null = null;\n private started = false;\n private request: Promise<void> | null = null;\n\n constructor(options: BeeperInboxCoreOptions) {\n if (!options.subscriberId.trim()) {\n throw new Error(\"A subscriberId is required\");\n }\n this.client = options.client;\n this.subscriberId = options.subscriberId;\n this.refreshSessionToken = options.refreshSessionToken;\n this.pollIntervalMs = Math.max(5_000, options.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS);\n }\n\n getState() {\n return this.state;\n }\n\n subscribe(listener: BeeperInboxCoreListener) {\n this.listeners.add(listener);\n listener(this.state);\n return () => this.listeners.delete(listener);\n }\n\n async start() {\n if (this.started) {\n return;\n }\n this.started = true;\n await this.refresh();\n }\n\n stop() {\n this.started = false;\n this.clearPollTimer();\n }\n\n async refresh(options: { silent?: boolean } = {}) {\n if (this.request) {\n return this.request;\n }\n\n this.update({\n ...(options.silent ? { refreshing: true } : { loading: true }),\n connectionState: options.silent ? this.state.connectionState : \"loading\",\n errorMessage: null,\n });\n\n this.request = this.requestWithSessionRetry(async () => {\n const result = await this.client.getInbox(this.subscriberId, 100);\n this.update({\n subscriber: result.subscriber,\n items: result.items,\n unreadCount: result.unreadCount,\n connectionState: \"live\",\n errorMessage: null,\n });\n })\n .catch((error: unknown) => {\n this.update({\n connectionState: \"error\",\n errorMessage: error instanceof Error ? error.message : \"Inbox request failed\",\n });\n throw error;\n })\n .finally(() => {\n this.request = null;\n this.update({ loading: false, refreshing: false });\n this.schedulePoll();\n });\n\n return this.request;\n }\n\n async markRead(inboxItemId: string) {\n const previous = this.state;\n const now = Date.now();\n this.update({\n items: this.state.items.map((item) =>\n item._id === inboxItemId ? { ...item, readAt: item.readAt ?? now } : item,\n ),\n unreadCount: Math.max(\n 0,\n this.state.unreadCount -\n (this.state.items.some((item) => item._id === inboxItemId && !item.readAt) ? 1 : 0),\n ),\n });\n\n try {\n await this.requestWithSessionRetry(() =>\n this.client.markRead(this.subscriberId, [inboxItemId]),\n );\n await this.refresh({ silent: true });\n } catch (error) {\n this.state = previous;\n this.emit();\n throw error;\n }\n }\n\n async markAllRead() {\n const previous = this.state;\n this.update({\n items: this.state.items.map((item) => ({ ...item, readAt: item.readAt ?? Date.now() })),\n unreadCount: 0,\n });\n\n try {\n await this.requestWithSessionRetry(() => this.client.markAllRead(this.subscriberId));\n await this.refresh({ silent: true });\n } catch (error) {\n this.state = previous;\n this.emit();\n throw error;\n }\n }\n\n async registerPushToken(token: string, options: RegisterPushTokenOptions) {\n const normalizedToken = token.trim();\n if (!normalizedToken) {\n throw new Error(\"A push token is required\");\n }\n await this.requestWithSessionRetry(() =>\n this.client.registerPushDevice({\n subscriberId: this.subscriberId,\n pushToken: normalizedToken,\n ...options,\n }),\n );\n }\n\n async unregisterPushToken(token: string) {\n const normalizedToken = token.trim();\n if (!normalizedToken) {\n return;\n }\n await this.requestWithSessionRetry(() =>\n this.client.unregisterPushDevice({\n subscriberId: this.subscriberId,\n pushToken: normalizedToken,\n }),\n );\n }\n\n async logActionClick(item: InboxItemRecord, actionUrl: string, actionLabel?: string) {\n return this.requestWithSessionRetry(() =>\n this.client.logActionClick({\n subscriberId: this.subscriberId,\n inboxItemId: item._id,\n actionUrl,\n actionLabel,\n }),\n );\n }\n\n private async requestWithSessionRetry<T>(request: () => Promise<T>): Promise<T> {\n try {\n return await request();\n } catch (error) {\n if (!(error instanceof BeeperApiError) || error.status !== 401 || !this.refreshSessionToken) {\n throw error;\n }\n const nextToken = await this.refreshSessionToken();\n this.client.updateSessionToken(nextToken);\n return request();\n }\n }\n\n private update(patch: Partial<BeeperInboxCoreState>) {\n this.state = { ...this.state, ...patch };\n this.emit();\n }\n\n private emit() {\n for (const listener of this.listeners) {\n listener(this.state);\n }\n }\n\n private schedulePoll() {\n if (!this.started || this.pollTimer) {\n return;\n }\n this.pollTimer = setTimeout(() => {\n this.pollTimer = null;\n void this.refresh({ silent: true }).catch(() => undefined);\n }, this.pollIntervalMs);\n }\n\n private clearPollTimer() {\n if (this.pollTimer) {\n clearTimeout(this.pollTimer);\n this.pollTimer = null;\n }\n }\n}\n","import type { InboxItemRecord } from \"beeper-sdk\";\n\n/** What `onActionPress` receives when an inbox item's action is pressed. */\nexport interface BeeperNativeActionPress {\n item: InboxItemRecord;\n actionLabel?: string;\n actionUrl: string;\n}\n\n/**\n * Called when an inbox item's action is pressed, before the default behaviour.\n * Return `false` (or resolve to `false`) to stop the package from opening the\n * URL with `Linking.openURL` — e.g. after routing in-app with React Navigation or\n * expo-router. Any other return value lets the default run.\n */\nexport type BeeperNativeActionPressHandler = (\n action: BeeperNativeActionPress,\n) => boolean | void | Promise<boolean | void>;\n\n/**\n * Runs one action press: records the click, lets the host app intercept, then\n * opens the URL unless it declined. Kept free of react-native imports so it can\n * be tested in plain Node.\n */\nexport async function runActionPress(input: {\n item: InboxItemRecord;\n onActionPress?: BeeperNativeActionPressHandler;\n logActionClick: (item: InboxItemRecord, actionUrl: string, actionLabel?: string) => Promise<unknown>;\n openURL: (url: string) => Promise<unknown>;\n}): Promise<void> {\n const actionUrl = input.item.actionUrl?.trim();\n if (!actionUrl) {\n return;\n }\n\n // Click analytics are best-effort. They run alongside the action and must never\n // delay or cancel it: awaiting them first meant a network error or an expired\n // session left the user tapping a button that did nothing.\n void input\n .logActionClick(input.item, actionUrl, input.item.actionLabel)\n .catch(() => undefined);\n\n // A throwing handler propagates and the URL is not opened: that is a bug in the\n // host app and should surface, not be papered over by navigating anyway.\n const shouldOpen =\n (await input.onActionPress?.({\n item: input.item,\n actionLabel: input.item.actionLabel,\n actionUrl,\n })) !== false;\n\n if (!shouldOpen) {\n return;\n }\n\n try {\n await input.openURL(actionUrl);\n } catch {\n // No app can handle this URL scheme on the device. Nothing useful to do.\n }\n}\n","import {\n ActivityIndicator,\n FlatList,\n Linking,\n Pressable,\n StyleSheet,\n Text,\n View,\n type ListRenderItemInfo,\n type StyleProp,\n type TextStyle,\n type ViewStyle,\n} from \"react-native\";\nimport {\n createContext,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useSyncExternalStore,\n type ReactNode,\n} from \"react\";\nimport { BeeperInboxCore } from \"beeper-inbox-core\";\nimport type { BeeperInboxCoreState, RegisterPushTokenOptions } from \"beeper-inbox-core\";\nimport { BeeperWidgetClient } from \"beeper-sdk/widget\";\nimport type { InboxItemRecord, PushPlatform } from \"beeper-sdk\";\n\nimport { runActionPress, type BeeperNativeActionPressHandler } from \"./actionPress\";\n\nexport type { BeeperNativeActionPress, BeeperNativeActionPressHandler } from \"./actionPress\";\n\nexport interface BeeperNativeSubscriber {\n subscriberId: string;\n displayName?: string;\n email?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface BeeperNativePushRegistration {\n token?: string;\n platform?: Extract<PushPlatform, \"ios\" | \"android\">;\n deviceLabel?: string;\n metadata?: Record<string, unknown>;\n autoRegister?: boolean;\n autoUnregister?: boolean;\n}\n\nexport interface BeeperNativeInboxProviderProps {\n /**\n * Optional advanced override for the Beeper Widget API origin. Defaults to the\n * hosted Beeper API. Most host apps should not pass this.\n */\n baseUrl?: string;\n projectId: string;\n publishableKey: string;\n sessionToken: string;\n refreshSessionToken?: () => Promise<string>;\n subscriber: BeeperNativeSubscriber;\n push?: BeeperNativePushRegistration;\n pollIntervalMs?: number;\n accentColor?: string;\n /**\n * Intercepts an inbox item's action press. Return `false` to skip the default\n * `Linking.openURL`, e.g. to navigate in-app instead:\n *\n * ```tsx\n * onActionPress={({ actionUrl }) => {\n * if (actionUrl.startsWith(\"myapp://\")) {\n * router.push(toRoute(actionUrl));\n * return false;\n * }\n * }}\n * ```\n */\n onActionPress?: BeeperNativeActionPressHandler;\n children: ReactNode;\n}\n\n/** What `useBeeperInbox()` returns: live inbox state plus the actions on it. */\nexport interface BeeperNativeInbox extends BeeperInboxCoreState {\n /** Re-fetches the inbox. `silent` skips the loading state. */\n refresh: (options?: { silent?: boolean }) => Promise<void>;\n markRead: (inboxItemId: string) => Promise<void>;\n markAllRead: () => Promise<void>;\n registerPushToken: (token: string, options: RegisterPushTokenOptions) => Promise<void>;\n unregisterPushToken: (token: string) => Promise<void>;\n /**\n * Performs an item's action exactly as the built-in item does: records the\n * click, calls `onActionPress`, then opens the URL unless it returned `false`.\n * Use it from custom item UIs so their analytics and routing stay consistent.\n */\n handleActionPress: (item: InboxItemRecord) => Promise<void>;\n}\n\ntype NativeInboxActions = Omit<BeeperNativeInbox, keyof BeeperInboxCoreState>;\n\ninterface NativeInboxContextValue {\n core: BeeperInboxCore;\n state: BeeperInboxCoreState;\n accentColor: string;\n actions: NativeInboxActions;\n}\n\nconst InboxContext = createContext<NativeInboxContextValue | null>(null);\n\nexport function BeeperNativeInboxProvider({\n baseUrl,\n projectId,\n publishableKey,\n sessionToken,\n refreshSessionToken,\n subscriber,\n push,\n pollIntervalMs,\n accentColor = \"#f97316\",\n onActionPress,\n children,\n}: BeeperNativeInboxProviderProps) {\n const client = useMemo(\n () =>\n new BeeperWidgetClient({\n baseUrl,\n projectId,\n publishableKey,\n sessionToken,\n }),\n [baseUrl, projectId, publishableKey, sessionToken],\n );\n const core = useMemo(\n () =>\n new BeeperInboxCore({\n client,\n subscriberId: subscriber.subscriberId,\n refreshSessionToken,\n pollIntervalMs,\n }),\n [client, pollIntervalMs, refreshSessionToken, subscriber.subscriberId],\n );\n const state = useSyncExternalStore(\n (listener) => core.subscribe(listener),\n () => core.getState(),\n () => core.getState(),\n );\n\n useEffect(() => {\n void core.start().catch(() => undefined);\n return () => core.stop();\n }, [core]);\n\n useEffect(() => {\n if (!push?.token || push.autoRegister === false) {\n return;\n }\n void core\n .registerPushToken(push.token, {\n platform: push.platform ?? \"android\",\n deviceLabel: push.deviceLabel,\n metadata: push.metadata,\n })\n .catch(() => undefined);\n\n if (push.autoUnregister) {\n return () => {\n void core.unregisterPushToken(push.token!);\n };\n }\n }, [core, push]);\n\n // Read through a ref so an inline `onActionPress` arrow doesn't rebuild the\n // actions, and every consumer, on each render of the host component.\n const onActionPressRef = useRef(onActionPress);\n useEffect(() => {\n onActionPressRef.current = onActionPress;\n }, [onActionPress]);\n\n const actions = useMemo<NativeInboxActions>(\n () => ({\n refresh: async (options) => {\n await core.refresh(options);\n },\n markRead: async (inboxItemId) => {\n await core.markRead(inboxItemId);\n },\n markAllRead: async () => {\n await core.markAllRead();\n },\n registerPushToken: async (token, options) => {\n await core.registerPushToken(token, options);\n },\n unregisterPushToken: async (token) => {\n await core.unregisterPushToken(token);\n },\n handleActionPress: (item) =>\n runActionPress({\n item,\n onActionPress: onActionPressRef.current,\n logActionClick: (target, actionUrl, actionLabel) =>\n core.logActionClick(target, actionUrl, actionLabel),\n openURL: (url) => Linking.openURL(url),\n }),\n }),\n [core],\n );\n\n const value = useMemo(\n () => ({ core, state, accentColor, actions }),\n [accentColor, actions, core, state],\n );\n return <InboxContext.Provider value={value}>{children}</InboxContext.Provider>;\n}\n\nfunction useNativeInbox() {\n const context = useContext(InboxContext);\n if (!context) {\n throw new Error(\"Beeper inbox components must be inside BeeperNativeInboxProvider\");\n }\n return context;\n}\n\n/**\n * Live inbox state and actions, for building your own UI or showing the unread\n * count elsewhere (a tab bar badge, say). Must be used inside\n * `BeeperNativeInboxProvider`; re-renders when the inbox changes.\n *\n * ```tsx\n * const { items, unreadCount, markRead, handleActionPress } = useBeeperInbox();\n * ```\n */\nexport function useBeeperInbox(): BeeperNativeInbox {\n const context = useContext(InboxContext);\n if (!context) {\n throw new Error(\"useBeeperInbox must be used inside BeeperNativeInboxProvider\");\n }\n return { ...context.state, ...context.actions };\n}\n\nexport function BeeperInboxBadge({\n onPress,\n style,\n textStyle,\n}: {\n onPress?: () => void;\n style?: StyleProp<ViewStyle>;\n textStyle?: StyleProp<TextStyle>;\n}) {\n const { state, accentColor } = useNativeInbox();\n const content = (\n <View style={[styles.badge, { backgroundColor: accentColor }, style]}>\n <Text style={[styles.badgeText, textStyle]}>{state.unreadCount > 99 ? \"99+\" : state.unreadCount}</Text>\n </View>\n );\n return onPress ? <Pressable accessibilityRole=\"button\" onPress={onPress}>{content}</Pressable> : content;\n}\n\nexport function BeeperInboxItem({ item }: { item: InboxItemRecord }) {\n const { core, accentColor, actions } = useNativeInbox();\n\n return (\n <View style={styles.item}>\n <Text style={styles.itemTitle}>{item.title ?? \"Notification\"}</Text>\n <Text style={styles.itemBody}>{item.body}</Text>\n <View style={styles.itemFooter}>\n <Text style={styles.itemDate}>{new Date(item.createdAt).toLocaleString()}</Text>\n {!item.readAt ? (\n <Pressable\n accessibilityRole=\"button\"\n accessibilityLabel=\"Mark notification as read\"\n onPress={() => void core.markRead(item._id)}\n >\n <Text style={[styles.actionText, { color: accentColor }]}>Mark read</Text>\n </Pressable>\n ) : null}\n {item.actionUrl ? (\n <Pressable accessibilityRole=\"button\" onPress={() => void actions.handleActionPress(item)}>\n <Text style={[styles.actionText, { color: accentColor }]}>{item.actionLabel ?? \"Open\"}</Text>\n </Pressable>\n ) : null}\n </View>\n </View>\n );\n}\n\nexport function BeeperInboxList({\n style,\n contentContainerStyle,\n}: {\n style?: StyleProp<ViewStyle>;\n contentContainerStyle?: StyleProp<ViewStyle>;\n}) {\n const { state } = useNativeInbox();\n if (state.loading && state.items.length === 0) {\n return <ActivityIndicator accessibilityLabel=\"Loading notifications\" style={styles.loader} />;\n }\n if (state.errorMessage && state.items.length === 0) {\n return <Text accessibilityRole=\"alert\" style={styles.error}>{state.errorMessage}</Text>;\n }\n if (state.items.length === 0) {\n return <Text style={styles.empty}>No notifications yet.</Text>;\n }\n\n const renderItem = ({ item }: ListRenderItemInfo<InboxItemRecord>) => <BeeperInboxItem item={item} />;\n return (\n <FlatList\n accessibilityLabel=\"Notifications\"\n data={state.items}\n keyExtractor={(item) => item._id}\n renderItem={renderItem}\n style={style}\n contentContainerStyle={contentContainerStyle}\n />\n );\n}\n\nexport function BeeperInboxPanel({\n title = \"Notifications\",\n style,\n}: {\n title?: string;\n style?: StyleProp<ViewStyle>;\n}) {\n const { core, state, accentColor } = useNativeInbox();\n return (\n <View style={[styles.panel, style]}>\n <View style={styles.header}>\n <View>\n <Text style={styles.title}>{title}</Text>\n <Text style={styles.subtitle} accessibilityLiveRegion=\"polite\">\n {state.unreadCount} unread\n </Text>\n </View>\n {state.unreadCount > 0 ? (\n <Pressable accessibilityRole=\"button\" onPress={() => void core.markAllRead()}>\n <Text style={[styles.actionText, { color: accentColor }]}>Mark all read</Text>\n </Pressable>\n ) : null}\n </View>\n <BeeperInboxList contentContainerStyle={styles.listContent} />\n </View>\n );\n}\n\nexport function BeeperInboxRefreshControl() {\n const { core, state } = useNativeInbox();\n return (\n <Pressable accessibilityRole=\"button\" onPress={() => void core.refresh({ silent: true })}>\n <Text style={styles.actionText}>{state.refreshing ? \"Refreshing...\" : \"Refresh\"}</Text>\n </Pressable>\n );\n}\n\nconst styles = StyleSheet.create({\n panel: {\n backgroundColor: \"#fffaf5\",\n borderColor: \"#eadbcc\",\n borderRadius: 14,\n borderWidth: 1,\n padding: 14,\n },\n header: {\n alignItems: \"center\",\n flexDirection: \"row\",\n justifyContent: \"space-between\",\n marginBottom: 12,\n },\n title: { color: \"#2b221d\", fontSize: 18, fontWeight: \"700\" },\n subtitle: { color: \"#7d685d\", fontSize: 13, marginTop: 2 },\n listContent: { gap: 8 },\n item: { backgroundColor: \"#fffdf9\", borderColor: \"#eadbcc\", borderRadius: 10, borderWidth: 1, padding: 14 },\n itemTitle: { color: \"#2b221d\", fontSize: 15, fontWeight: \"700\", marginBottom: 5 },\n itemBody: { color: \"#4e3c34\", fontSize: 14, lineHeight: 21 },\n itemFooter: { alignItems: \"center\", flexDirection: \"row\", flexWrap: \"wrap\", gap: 12, marginTop: 10 },\n itemDate: { color: \"#7d685d\", flex: 1, fontSize: 12 },\n actionText: { fontSize: 13, fontWeight: \"700\", paddingVertical: 8 },\n badge: { alignItems: \"center\", borderRadius: 999, justifyContent: \"center\", minHeight: 24, minWidth: 24, paddingHorizontal: 7 },\n badgeText: { color: \"#fff\", fontSize: 12, fontWeight: \"700\" },\n loader: { padding: 24 },\n empty: { color: \"#7d685d\", padding: 24, textAlign: \"center\" },\n error: { color: \"#a43d28\", padding: 24, textAlign: \"center\" },\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "beeper-inbox-native",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -13,27 +13,32 @@
13
13
  "default": "./dist/index.js"
14
14
  }
15
15
  },
16
- "files": ["dist", "README.md"],
16
+ "files": [
17
+ "dist",
18
+ "README.md"
19
+ ],
17
20
  "sideEffects": false,
18
21
  "dependencies": {
19
- "beeper-inbox-core": "workspace:*",
20
- "beeper-sdk": "workspace:*"
22
+ "beeper-sdk": "^0.1.9"
21
23
  },
22
24
  "peerDependencies": {
23
25
  "react": ">=18",
24
26
  "react-native": ">=0.76"
25
27
  },
26
28
  "devDependencies": {
29
+ "@types/node": "^24.10.13",
27
30
  "@types/react": "^19.2.7",
28
31
  "react": "^19.2.3",
29
32
  "react-native": "^0.81.0",
30
- "typescript": "catalog:"
33
+ "tsup": "^8.5.1",
34
+ "typescript": "^5",
35
+ "beeper-inbox-core": "^0.1.0"
31
36
  },
32
37
  "scripts": {
33
- "build": "tsc -p tsconfig.build.json",
34
- "check-types": "tsc --noEmit",
38
+ "build": "tsup",
39
+ "check-types": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
35
40
  "clean": "rm -rf dist",
36
- "test": "node --test",
37
- "prepublishOnly": "pnpm run clean && pnpm run build && pnpm run check-types"
41
+ "test": "node --test --experimental-strip-types src/**/*.test.ts",
42
+ "check-dist": "node -e \"const fs=require('fs');for(const f of ['dist/index.js','dist/index.d.ts']){if(fs.readFileSync(f,'utf8').includes('beeper-inbox-core')){console.error(f+' references beeper-inbox-core, which is never published. It must be bundled, not imported.');process.exit(1)}}\""
38
43
  }
39
- }
44
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,SAAS,EACd,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAML,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEhE,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,4BAA4B;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC,YAAY,EAAE,KAAK,GAAG,SAAS,CAAC,CAAC;IACpD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,8BAA8B;IAC7C;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,EAAE,MAAM,CAAC;IACrB,mBAAmB,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,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