@emmanuel-nike/ark-notify-js 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +53 -4
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  JavaScript SDK for [Ark Notify](https://github.com/ark-notify/ark-notify) — real-time pub/sub, presence, SSE streaming, and platform management.
4
4
 
5
- - **Core API** (`ark-notify-js`) — imperative client, WebSocket, and SSE classes for any JavaScript environment
5
+ - **Core API** (`ark-notify-js`) — imperative client, WebSocket, SSE, and server-side stream classes for any JavaScript environment
6
6
  - **React bindings** (`ark-notify-js/react`) — hooks and provider for React 18+ applications
7
7
 
8
8
  ## Install
@@ -15,10 +15,14 @@ For React apps, `react` 18+ is a peer dependency.
15
15
 
16
16
  ### Node.js / AdonisJS (server)
17
17
 
18
- Use the `/server` subpath for `serverAuthUrl` webhook helpers:
18
+ Use the `/server` subpath for `serverAuthUrl` webhook helpers and the server-side event stream:
19
19
 
20
20
  ```ts
21
- import { handleServerAuth, parseServerAuthRequest } from '@emmanuel-nike/ark-notify-js/server'
21
+ import {
22
+ handleServerAuth,
23
+ parseServerAuthRequest,
24
+ ArkNotifyServerStream,
25
+ } from '@emmanuel-nike/ark-notify-js/server'
22
26
  import { ArkNotifyClient, fetchConnectionToken } from '@emmanuel-nike/ark-notify-js'
23
27
  ```
24
28
 
@@ -323,6 +327,50 @@ const response = await handleServerAuth({
323
327
 
324
328
  Or build a response directly with `createAuthorizedServerAuthResponse()`.
325
329
 
330
+ ## Server stream (backend)
331
+
332
+ Subscribe to channel events from your application backend over SSE. Unlike client SSE (`ArkNotifySSE`), the server stream uses app credentials (`X-App-Key` / `X-App-Secret`) — not connection tokens — and does not require per-channel HMAC tokens for private channels.
333
+
334
+ Use this when a backend service needs to react to realtime events (webhooks, workers, sync jobs) without maintaining a WebSocket client.
335
+
336
+ ```ts
337
+ import { ArkNotifyServerStream } from '@emmanuel-nike/ark-notify-js/server'
338
+
339
+ const stream = new ArkNotifyServerStream({
340
+ appKey: process.env.ARK_APP_KEY!,
341
+ credentials: {
342
+ appKey: process.env.ARK_APP_KEY!,
343
+ secret: process.env.ARK_APP_SECRET!,
344
+ },
345
+ channels: ['room-1', 'orders'],
346
+ history: true, // optional — replay recent messages on connect
347
+ })
348
+
349
+ stream.on('connected', (msg) => {
350
+ console.log('Subscribed to', msg.channels, msg.connection_id)
351
+ })
352
+
353
+ stream.on('event', (msg) => {
354
+ console.log(msg.channel, msg.event, msg.data)
355
+ })
356
+
357
+ stream.bind('orders', 'order.created', (data) => {
358
+ console.log('New order', data)
359
+ })
360
+
361
+ await stream.connect()
362
+
363
+ // later
364
+ stream.disconnect()
365
+ ```
366
+
367
+ **Notes:**
368
+
369
+ - Backend-only — never use app credentials in browser code.
370
+ - Uses `fetch` with a streaming SSE parser (not `EventSource`), so custom auth headers are supported.
371
+ - Failed auth before the stream opens throws `ArkNotifyError` (same as other REST calls).
372
+ - Stream lifecycle events: `connected`, `event`, `presence`, `message`, `error`, `close`.
373
+
326
374
  ## API coverage
327
375
 
328
376
 
@@ -340,6 +388,7 @@ Or build a response directly with `createAuthorizedServerAuthResponse()`.
340
388
  | Publish (client) | `useChannel`, `ArkNotifyConnection` | `.publish()` |
341
389
  | Presence | `usePresence`, `ArkNotifyConnection` | `.presenceEnter()`, `.presenceUpdate()`, … |
342
390
  | SSE stream | `useSSE`, `ArkNotifySSE` | `.connect()` |
391
+ | Server stream (backend) | `ArkNotifyServerStream` | `.connect()`, `.bind()`, `.bindAll()` |
343
392
  | Private channels | `onPrivateChannelAuth` callback | — |
344
393
  | Auto-reconnect | `useConnection` | `autoReconnect: true` |
345
394
  | Heartbeat | `ArkNotifyConnection` | Server ping auto-replied |
@@ -361,7 +410,7 @@ try {
361
410
  }
362
411
  ```
363
412
 
364
- WebSocket errors are emitted via `connection.on('error', …)` or the `useConnection` state.
413
+ WebSocket errors are emitted via `connection.on('error', …)` or the `useConnection` state. Server stream connection errors are emitted via `stream.on('error', …)`; failed auth before the stream opens throws `ArkNotifyError`.
365
414
 
366
415
  ## License
367
416
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@emmanuel-nike/ark-notify-js",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "JavaScript SDK for Ark Notify — real-time pub/sub, presence, and platform management",
5
5
  "license": "MIT",
6
6
  "type": "module",