beeper-inbox-react 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,8 +2,9 @@
2
2
 
3
3
  React embeddable inbox widget for Beeper.
4
4
 
5
- The widget resolves the realtime Convex backend from Beeper's `/widget/config` endpoint.
6
- Host apps do not pass a `convexUrl`.
5
+ The widget gets its realtime endpoint from Beeper's `/widget/config` endpoint: a WebSocket
6
+ (`realtime: { kind: "ws", url }`) on the current backend, or a Convex URL on older deployments.
7
+ Host apps pass neither. Without one, or if the socket fails, the inbox polls every 15 s.
7
8
 
8
9
  ## Public API
9
10
 
@@ -29,11 +30,11 @@ The provider talks to **two** origins:
29
30
 
30
31
  If you override `baseUrl`, it must be an origin serving Beeper widget REST routes.
31
32
 
32
- In this repo’s current backend architecture, that override points at the Convex HTTP deployment (`…convex.site`) and must support CORS preflight on `/api/v1/`.
33
+ In this repo that is the public API (`api.<domain>`, the `beeper-api` Worker), which handles CORS preflight on `/api/v1/` and serves the realtime socket at `/api/v1/projects/:projectId/widget/inbox/ws`.
33
34
 
34
35
  ### Why `POST /api/beeper/widget-session` runs often
35
36
 
36
- That call **mints** the short-lived `x-beeper-session-token`. It runs when there is no token yet, before inbox/read actions, and when refreshing an expiring session. If it runs in a tight loop, the mint endpoint is probably failing (check **503** / JSON `error` and server env `BEEPER_SERVER_KEY`, `CONVEX_SITE_URL`).
37
+ That call **mints** the short-lived `x-beeper-session-token`. It runs when there is no token yet, before inbox/read actions, and when refreshing an expiring session. If it runs in a tight loop, the mint endpoint is probably failing (check **503** / JSON `error` and server env `BEEPER_SERVER_KEY`).
37
38
 
38
39
  ## Install
39
40
 
@@ -137,7 +138,7 @@ It serves only the dashboard's own project. Configure server env:
137
138
 
138
139
  - `BEEPER_SERVER_KEY` — project API key with `widget:session:create` or `ingest:write`
139
140
  - `BEEPER_PROJECT_ID` (or `VITE_BEEPER_PROJECT_ID`) — the project it mints for; the request body is ignored
140
- - `CONVEX_SITE_URL` or `VITE_CONVEX_SITE_URL` — only needed by the server-side session proxy in this repo
141
+ - The API service binding `API` (or `API_URL` in local dev) — how the route reaches the Beeper API
141
142
 
142
143
  ### `BeeperInboxBell`
143
144
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,19 @@
1
- import { type CSSProperties, type ReactNode, type RefObject } from "react";
2
- export type BeeperInboxTheme = "light" | "dark" | "system";
3
- export interface BeeperInboxCustomization {
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { CSSProperties, RefObject, ReactNode } from 'react';
3
+
4
+ /**
5
+ * The WebSocket realtime client, kept free of runtime imports so the React
6
+ * widget can bundle it without pulling in `beeper-sdk` or `convex`.
7
+ */
8
+
9
+ /** The subset of a Convex client the inbox subscribes through. */
10
+ interface InboxRealtimeClient {
11
+ onUpdate(query: string, args: Record<string, unknown>, onResult: (result: unknown) => void, onError: (error: Error) => void): () => void;
12
+ close(): void | Promise<void>;
13
+ }
14
+
15
+ type BeeperInboxTheme = "light" | "dark" | "system";
16
+ interface BeeperInboxCustomization {
4
17
  accentColor?: string;
5
18
  radius?: number;
6
19
  fontScale?: number;
@@ -15,19 +28,19 @@ export interface BeeperInboxCustomization {
15
28
  * One tab of the panel. `kind` limits it to items whose `metadata.kind` is one
16
29
  * of these; omit it for an "all" tab. The tab's badge counts its kinds' unread.
17
30
  */
18
- export interface BeeperInboxTab {
31
+ interface BeeperInboxTab {
19
32
  key: string;
20
33
  label: string;
21
34
  kind?: string | string[];
22
35
  }
23
- export interface BeeperInboxSubscriber {
36
+ interface BeeperInboxSubscriber {
24
37
  subscriberId: string;
25
38
  displayName?: string;
26
39
  email?: string;
27
40
  avatarUrl?: string;
28
41
  metadata?: Record<string, unknown>;
29
42
  }
30
- export interface BeeperInboxPushRegistration {
43
+ interface BeeperInboxPushRegistration {
31
44
  token?: string;
32
45
  platform?: "web" | "ios" | "android";
33
46
  deviceLabel?: string;
@@ -35,7 +48,7 @@ export interface BeeperInboxPushRegistration {
35
48
  autoRegister?: boolean;
36
49
  autoUnregister?: boolean;
37
50
  }
38
- export interface BeeperInboxProviderProps {
51
+ interface BeeperInboxProviderProps {
39
52
  /**
40
53
  * Optional advanced override for the Beeper Widget API origin.
41
54
  * Defaults to the hosted Beeper API. Most host apps should not pass this.
@@ -75,7 +88,7 @@ export interface BeeperInboxProviderProps {
75
88
  defaultTab?: string;
76
89
  children: ReactNode;
77
90
  }
78
- export type BeeperInboxEvent = {
91
+ type BeeperInboxEvent = {
79
92
  type: "session.refresh.start";
80
93
  projectId: string;
81
94
  subscriberId: string;
@@ -140,6 +153,12 @@ interface InboxItem {
140
153
  actionUrl?: string;
141
154
  }
142
155
  interface WidgetConfig {
156
+ /** Realtime over the backend's WebSocket (current backend). Preferred. */
157
+ realtime?: {
158
+ kind: "ws";
159
+ url: string;
160
+ };
161
+ /** Realtime over a Convex subscription (older deployments). */
143
162
  convexUrl?: string;
144
163
  modeDefault: BeeperInboxTheme;
145
164
  accentColor: string;
@@ -189,6 +208,22 @@ interface BeeperInboxContextValue {
189
208
  /** Attach to the open button so the panel can anchor under it. */
190
209
  triggerRef: RefObject<HTMLElement | null>;
191
210
  }
211
+ type RealtimeSource = {
212
+ kind: "ws" | "convex";
213
+ url: string;
214
+ };
215
+ /** The config's realtime endpoint: the WebSocket when offered, else Convex. */
216
+ declare function pickRealtimeSource(config: Partial<WidgetConfig>): RealtimeSource | null;
217
+ /**
218
+ * One socket per subscription. The list view applies pushed items to its
219
+ * page; the unread-only view (bell without a panel) reloads its counts.
220
+ */
221
+ declare function createWidgetSocketClient(url: string, publishableKey: string, loaders: {
222
+ current: {
223
+ head: () => Promise<unknown>;
224
+ unread: () => Promise<unknown>;
225
+ };
226
+ }): InboxRealtimeClient;
192
227
  declare function parseTokenExpiryMs(token: string): number | null;
193
228
  declare function isSessionExpiringSoon(expiresAt: number | null, now?: number): boolean;
194
229
  declare function tabKinds(tab: BeeperInboxTab | undefined): string[];
@@ -196,20 +231,20 @@ declare function tabKinds(tab: BeeperInboxTab | undefined): string[];
196
231
  declare function countTabUnread(tab: BeeperInboxTab, unreadCount: number, unreadByKind: Record<string, number>): number;
197
232
  /** `&kind=` for the active tab and `&unreadKind=` for every tab's badge. */
198
233
  declare function buildKindsQuery(activeKinds: string[], unreadKinds: string[]): string;
199
- export declare function BeeperInboxProvider({ baseUrl, projectId, publishableKey, sessionToken, getSessionToken, sessionEndpoint, sessionRequestHeaders, persistSession, subscriber, theme, customization, push, actionLinkTarget, onActionClick, pollIntervalMs, onEvent, tabs, defaultTab, children, }: BeeperInboxProviderProps): import("react/jsx-runtime").JSX.Element;
234
+ declare function BeeperInboxProvider({ baseUrl, projectId, publishableKey, sessionToken, getSessionToken, sessionEndpoint, sessionRequestHeaders, persistSession, subscriber, theme, customization, push, actionLinkTarget, onActionClick, pollIntervalMs, onEvent, tabs, defaultTab, children, }: BeeperInboxProviderProps): react_jsx_runtime.JSX.Element;
200
235
  /**
201
236
  * The inbox state and actions. A component using it keeps the item list
202
237
  * loaded while mounted (a custom panel needs `items`); for a badge alone, use
203
238
  * `useBeeperInboxUnreadCount`, which doesn't.
204
239
  */
205
- export declare function useBeeperInbox(): BeeperInboxContextValue;
240
+ declare function useBeeperInbox(): BeeperInboxContextValue;
206
241
  /** Unread counts only: doesn't make the provider load the item list. */
207
- export declare function useBeeperInboxUnreadCount(): {
242
+ declare function useBeeperInboxUnreadCount(): {
208
243
  unreadCount: number;
209
244
  unreadByKind: Record<string, number>;
210
245
  tabUnreadCount: (tab: BeeperInboxTab) => number;
211
246
  };
212
- export type BeeperInboxBellRenderProps = {
247
+ type BeeperInboxBellRenderProps = {
213
248
  unreadCount: number;
214
249
  open: boolean;
215
250
  toggle: () => void;
@@ -217,7 +252,7 @@ export type BeeperInboxBellRenderProps = {
217
252
  fontScale: number;
218
253
  triggerRef: RefObject<HTMLElement | null>;
219
254
  };
220
- export interface BeeperInboxBellProps {
255
+ interface BeeperInboxBellProps {
221
256
  /**
222
257
  * `bell` — icon + optional count badge (default).
223
258
  * `minimal` — text label + count pill (previous default look).
@@ -232,22 +267,24 @@ export interface BeeperInboxBellProps {
232
267
  /** Full control over the trigger; not wrapped in an extra button. */
233
268
  renderTrigger?: (props: BeeperInboxBellRenderProps) => ReactNode;
234
269
  }
235
- export declare function BeeperInboxBell({ variant, label, className, style, "aria-label": ariaLabel, renderTrigger, }: BeeperInboxBellProps): import("react/jsx-runtime").JSX.Element;
236
- export interface BeeperInboxPanelProps {
270
+ declare function BeeperInboxBell({ variant, label, className, style, "aria-label": ariaLabel, renderTrigger, }: BeeperInboxBellProps): react_jsx_runtime.JSX.Element;
271
+ interface BeeperInboxPanelProps {
237
272
  /**
238
273
  * `anchor` — fixed under the bell / `triggerRef` (default).
239
274
  * `fixed-bottom-end` — previous viewport corner placement (e.g. floating widget).
240
275
  */
241
276
  placement?: "anchor" | "fixed-bottom-end";
242
277
  }
243
- export declare function BeeperInboxPanel({ placement, }?: BeeperInboxPanelProps): import("react/jsx-runtime").JSX.Element | null;
244
- export declare const __internal: {
278
+ declare function BeeperInboxPanel({ placement, }?: BeeperInboxPanelProps): react_jsx_runtime.JSX.Element | null;
279
+ declare const __internal: {
245
280
  DEFAULT_BEEPER_WIDGET_API_BASE_URL: string;
246
281
  tabKinds: typeof tabKinds;
247
282
  countTabUnread: typeof countTabUnread;
248
283
  buildKindsQuery: typeof buildKindsQuery;
249
284
  parseTokenExpiryMs: typeof parseTokenExpiryMs;
250
285
  isSessionExpiringSoon: typeof isSessionExpiringSoon;
286
+ pickRealtimeSource: typeof pickRealtimeSource;
287
+ createWidgetSocketClient: typeof createWidgetSocketClient;
251
288
  };
252
- export {};
253
- //# sourceMappingURL=index.d.ts.map
289
+
290
+ export { BeeperInboxBell, type BeeperInboxBellProps, type BeeperInboxBellRenderProps, type BeeperInboxCustomization, type BeeperInboxEvent, BeeperInboxPanel, type BeeperInboxPanelProps, BeeperInboxProvider, type BeeperInboxProviderProps, type BeeperInboxPushRegistration, type BeeperInboxSubscriber, type BeeperInboxTab, type BeeperInboxTheme, __internal, useBeeperInbox, useBeeperInboxUnreadCount };