🔥 DOC API NeyBee Core FlashNotify Ver 1

FlashNotify API Documentation

Version: 1.0.0
API Base URL: https://api.neybee.com
API Prefix: /api/flash-notify/v1
Status: Backend integration in development
Authentication: HMAC API Authentication + Registration Token
Source: ChatGPT


1. Overview

FlashNotify adalah layanan Universal Event-Driven Notification untuk mengirimkan notifikasi dari aplikasi NeyBee maupun aplikasi eksternal ke perangkat pengguna melalui Web Push.

Aplikasi pengirim tidak perlu terhubung langsung dengan browser Push Service. Aplikasi cukup mengirimkan event ke API NeyBee. FlashNotify akan memvalidasi identitas pengguna, menyimpan notifikasi, dan memproses pengiriman melalui Web Push.

Supported architecture

  • Multi-application.

  • Multi-client.

  • Multi-member.

  • Multi-device.

  • Browser Web Push.

  • Event-driven notification.

  • Idempotent event submission.

  • Redis-based delivery queue.

  • VAPID authentication.

Initial applications

Application Origin
nChat https://neychat.com
nEDC https://pay.nchat.cc

Setiap aplikasi mempunyai konfigurasi origin dan subscription sendiri. Subscription nChat tidak boleh digunakan untuk mengirim notifikasi nEDC, begitu pula sebaliknya.


2. API Authentication

Endpoint server-to-server menggunakan HMAC authentication melalui API Client Management NeyBee.

Required headers

Header Description
X-NeyBee-Public-Key API client public key
X-NeyBee-Timestamp Request timestamp
X-NeyBee-Nonce Unique request nonce
X-NeyBee-Signature HMAC signature
Content-Type application/json

Required scope

flash_notify

API client harus berstatus aktif dan memiliki scope tersebut.

Important

  • Jangan menempatkan private API key di JavaScript browser.

  • Jangan membuat signature sendiri dengan format yang berbeda dari implementasi HMAC API Client Management.

  • Gunakan mekanisme signing resmi yang sudah digunakan oleh integrasi NeyBee lainnya.

  • Request timestamp dan nonce wajib mengikuti validasi middleware API.


3. Member Identity

FlashNotify menggunakan Member Identity yang sudah terdaftar di API NeyBee.

Aplikasi tidak boleh menentukan member_ref sendiri.

Identitas member divalidasi berdasarkan:

  • API client.

  • Integration.

  • External member ID.

  • Status member identity.

  • Status member account.

  • Verified identity.

Internal member reference

Format:

integration_code:external_member_id

Contoh:

neybee:7

Format tersebut merupakan identitas internal FlashNotify. Developer cukup mengirim external_member_id; server akan membentuk member_ref secara otomatis.


4. API Endpoints

4.1 Submit Notification Event

Status: Available

POST /api/flash-notify/v1/events

Digunakan oleh aplikasi untuk mengirimkan event yang menghasilkan notifikasi.

Authentication: HMAC
Required scope: flash_notify

Request body

{
  "app_code": "nchat",
  "event_key": "order-123-payment-success",
  "event_type": "payment.success",
  "external_member_id": "7",
  "title": "Payment Successful",
  "body": "Your payment has been received.",
  "target_url": "https://neychat.com/orders/123",
  "icon_url": "https://neychat.com/icons/notification.png",
  "data": {
    "order_id": "123",
    "type": "payment"
  }
}

Field descriptions

Field Required Description
app_code Yes Registered application code
event_key Yes Unique event identifier for idempotency
event_type Yes Event category
external_member_id Yes Member ID from the originating application
title Yes Notification title
body Yes Notification message
target_url No Destination URL when notification is opened
icon_url No Notification icon
data No Additional JSON data

Accepted response

Representative response:

{
  "result": "accepted",
  "event_id": 101,
  "notification_id": 201,
  "event_status": "queued",
  "queue_status": "queued",
  "member_ref": "neybee:7"
}

The queue status indicates that the delivery job has been dispatched. It does not guarantee that the browser has received the notification.

Duplicate response

When the same event_key is submitted again for the same client and application, FlashNotify recognizes the event as a duplicate.

{
  "result": "duplicate",
  "event_id": 101,
  "notification_id": 201
}

The same event must not create a second notification.

Important: Use a stable event_key for each business event. Do not generate a new random key every time the application retries the same request.


4.2 Generate Browser Registration Token

Status: Available

POST /api/flash-notify/v1/subscription-tokens

Used by the application backend to authorize a browser to register its Web Push subscription.

Authentication: HMAC
Required scope: flash_notify

Request body

{
  "app_code": "nchat",
  "external_member_id": "7"
}

Field descriptions

Field Required Description
app_code Yes Registered application code
external_member_id Yes Existing verified member identity

Response

Representative response:

{
  "token": "ONE_TIME_REGISTRATION_TOKEN",
  "expires_in": 300,
  "app_code": "nchat"
}

The registration token:

  • Is generated by the API.

  • Is associated with one application and one member.

  • Expires after five minutes.

  • Can only be used once.

  • Must not be shared between different members.

The plain token is returned once. The server stores its hash.


4.3 Register Browser Subscription

Status: Available

POST /api/flash-notify/v1/subscriptions

Used by the browser to register a Web Push subscription.

Authentication: FlashNotify Registration Token.

Required headers

Content-Type: application/json
Origin: https://neychat.com
X-FlashNotify-Registration-Token: ONE_TIME_REGISTRATION_TOKEN

The Origin must match an allowed origin registered for the application associated with the token.

Request body

{
  "endpoint": "https://push-service.example/push/endpoint",
  "keys": {
    "p256dh": "BROWSER_PUBLIC_KEY",
    "auth": "BROWSER_AUTH_SECRET"
  },
  "content_encoding": "aes128gcm",
  "device_label": "Chrome Desktop"
}

Field descriptions

Field Required Description
endpoint Yes Browser Push Service endpoint
keys.p256dh Yes Browser subscription public key
keys.auth Yes Browser subscription authentication secret
content_encoding Yes aes128gcm
device_label No Human-readable device label

The API also records the browser user agent.

Security rules

  • HTTPS endpoints are required.

  • Push service hosts are validated.

  • Application origin must be allowed.

  • Registration token must be valid and unused.

  • The token is consumed during registration.

  • Duplicate endpoint registration for the same application is handled using the endpoint hash.

A browser must obtain a new registration token if its previous token has expired or has already been used.


4.4 Subscription CORS Preflight

Status: Available

OPTIONS /api/flash-notify/v1/subscriptions

Used by browsers before cross-origin subscription registration.

Allowed methods:

  • POST

  • OPTIONS

Allowed request headers:

  • Content-Type

  • X-FlashNotify-Registration-Token

Only registered application origins are accepted.


5. Browser Integration Flow

The following is the intended integration flow.

Step 1 — Obtain registration token

The authenticated application backend requests a registration token from FlashNotify.

Step 2 — Obtain VAPID public key

The browser needs the application's FlashNotify VAPID public key to subscribe to Web Push.

For v1.0.0, the public key must be supplied through the application's approved configuration until the public-config endpoint is implemented.

Never expose the VAPID private key.

Step 3 — Register Service Worker

Each application must host its own Service Worker on its own origin.

Example:

  • nChat: https://neychat.com/

  • nEDC: https://pay.nchat.cc/

The Service Worker must handle the browser push and notificationclick events.

Step 4 — Subscribe browser

Example JavaScript:

const registration = await navigator.serviceWorker.register(
    '/flash-notify-sw.js'
);

const subscription = await registration.pushManager.subscribe({
    userVisibleOnly: true,
    applicationServerKey: VAPID_PUBLIC_KEY
});

Step 5 — Register subscription

Convert the subscription object to JSON and send it to:

POST /api/flash-notify/v1/subscriptions

Include the registration token and the correct Origin header.

Step 6 — Send notification event

When a business event occurs, the application backend submits the event to:

POST /api/flash-notify/v1/events

FlashNotify resolves the member identity, stores the notification and queues the delivery job.


6. Notification Delivery Architecture

Application Backend
        |
        v
FlashNotify Event API
        |
        v
Validate Client & Member Identity
        |
        v
Store Event & Notification
        |
        v
Redis Queue: flash-notify
        |
        v
SendFlashNotifyPush Job
        |
        v
FlashNotify Push Delivery Service
        |
        v
Browser Push Service
        |
        v
Application Service Worker
        |
        v
User Device

Delivery isolation

Every delivery is scoped by:

  • client_id

  • application_id

  • member_ref

  • subscription_id

This ensures that notifications are sent only to subscriptions belonging to the intended application and member.

Delivery status

The delivery engine uses the following statuses:

Status Meaning
pending Delivery record created
sent Push provider accepted the message
failed Delivery attempt failed

sent does not mean the user has opened or read the notification.

Expired subscriptions

If a Push Service returns HTTP 404 or 410, the subscription is revoked and excluded from future delivery attempts.


7. VAPID Configuration

FlashNotify uses VAPID authentication.

The API server stores:

  • VAPID public key.

  • VAPID private key.

  • VAPID subject.

Current subject:

mailto:admin@neybee.com

The same VAPID key pair is used for the initial nChat and nEDC applications.

Rules:

  1. Private key must remain on the API server.

  2. Public key may be supplied to the browser.

  3. Never include the private key in API responses.

  4. Do not regenerate keys during normal application deployment.

  5. Changing the key pair requires browser subscriptions to be recreated.


8. Error Handling

The API may return errors for the following conditions:

Error Meaning
application_not_found Application is not registered or inactive
integration_not_active Integration is not active
member_identity_not_active Member identity is missing, inactive or unverified
Invalid API authentication HMAC authentication failed
Missing scope API client does not have flash_notify scope
Invalid registration token Token is invalid, expired or already used
Origin not allowed Browser origin is not registered
Invalid subscription Subscription data or endpoint is invalid

HTTP response codes and exact validation messages should be taken from the active controller implementation.

Applications should log request identifiers and error responses, but never log private keys, browser authentication secrets or registration tokens.


9. Planned Endpoints

The following endpoints are not yet available in v1.0.0 and must not be used in production integration until implemented and announced.

Method Endpoint Purpose
GET /api/flash-notify/v1/public-config Retrieve public VAPID configuration
GET /api/flash-notify/v1/notifications Retrieve member notification inbox
POST /api/flash-notify/v1/notifications/{id}/read Mark notification as read
DELETE /api/flash-notify/v1/subscriptions/{id} Revoke browser subscription

10. Developer Security Checklist

  • Use HTTPS for all API and application origins.

  • Use the existing NeyBee HMAC signing implementation.

  • Keep API private credentials on the backend.

  • Never expose VAPID private key.

  • Never accept arbitrary member_ref from the client.

  • Use verified Member Identity.

  • Use unique and stable event_key.

  • Keep application origins isolated.

  • Store browser subscription credentials securely.

  • Do not reuse registration tokens.

  • Validate notification destination URLs in the application.

  • Do not treat queue acceptance as proof of browser delivery.


11. Version History

v1.0.0

Initial FlashNotify API specification.

Included:

  • HMAC-authenticated event submission.

  • Member Identity validation.

  • Browser registration token.

  • Browser subscription registration.

  • Application-specific origins.

  • VAPID-based Web Push architecture.

  • Redis delivery queue.

  • Idempotent event submission.

  • Delivery isolation by application and member.

Implementation note: This document describes the current v1.0.0 backend contract and identifies planned endpoints separately. Production readiness remains subject to delivery testing, recovery validation, inbox API implementation and PWA integration.