LitePush
SDKPackage

Browser client

API reference for the importable @litepush/sdk browser client (LitePushClient).

LitePushClientConfig

interface
PropertyTypeDescription
projectIdstring

Project ID from the dashboard (prj_*).

vapidKeystring

The project's VAPID public key.

apiBase?string

Override the API origin. Defaults to https://api.litepush.dev.

swPath?string

Path the service worker is served from on your origin. Defaults to /litepush-sw.js.

LitePushClient

class

Constructor

constructor(config):LitePushClient
ParameterTypeDescription
configLitePushClientConfig

Properties

readonlyprojectId:string
readonlyvapidKey:string
readonlyapiBase:string
readonlyswPath:string
readonlyversion:"0.2.1"

Methods

canSubscribe():boolean

Whether this browser can actually complete a subscribe. Synchronous, safe anywhere.

isSubscribed():Promise<boolean>

Whether this browser currently has an active subscription for the project.

subscribe(opts?):Promise<SubscribeResult | null>

Request permission (if needed), register the service worker, create a PushSubscription, and register it with LitePush. Returns { id } on success or null if the user denied permission. Must be called from a user gesture. Throws on unsupported browsers — gate on canSubscribe().

ParameterTypeDescription
opts?SubscribeOptionsdefault: {}
unsubscribe():Promise<boolean>

Cancel the current browser's subscription and beacon /v1/unsubscribe so the dashboard updates immediately. Returns true if a subscription was actually removed.

LitePushApiError

class

Thrown for any non-2xx LitePush API response (from subscribe() on the browser client and from every method on the server client).

Branch on code — the stable machine-readable identifier — rather than on message, which is human-facing and may change:

try {
  await litepush.broadcasts.create({ … });
} catch (e) {
  if (isLitePushApiError(e)) {
    switch (e.code) {
      case "monthly_push_limit_reached": return showUpgradePrompt();
      case "rate_limited":               return retryAfter(e);
      default:                           throw e;
    }
  }
  throw e;
}

Constructor

constructor(code, message, status, body?):LitePushApiError
ParameterTypeDescription
codeLitePushErrorCode | string & object
messagestring
statusnumber
body?unknown

Properties

readonlycode:LitePushErrorCode | string & object

Stable identifier from the API error envelope (e.g. "project_locked"). Known values are listed in LitePushErrorCode; the string half of the type keeps unknown/future codes assignable. For a response with no LitePush error envelope (e.g. a proxy/gateway 502 with a non-JSON body) this falls back to http_<status> (e.g. "http_502").

readonlystatus:number

HTTP status of the failed response.

readonlybody?:unknown

The parsed JSON response body, when the error body was JSON.

isLitePushApiError

function
isLitePushApiError(e):e

Type guard: narrow an unknown caught value to a LitePushApiError.

ParameterTypeDescription
eunknown

canSubscribe

function
canSubscribe():boolean

VERSION

const
"0.2.1"

Re-exports

This entry point also re-exports the following shared types: