Browser client
API reference for the importable @litepush/sdk browser client (LitePushClient).
LitePushClientConfig
interface| Property | Type | Description |
|---|---|---|
| projectId | string | Project ID from the dashboard ( |
| vapidKey | string | The project's VAPID public key. |
| apiBase? | string | Override the API origin. Defaults to |
| swPath? | string | Path the service worker is served from on your origin. Defaults to |
LitePushClient
classConstructor
| Parameter | Type | Description |
|---|---|---|
| config | LitePushClientConfig | — |
Properties
Methods
Whether this browser can actually complete a subscribe. Synchronous, safe anywhere.
Whether this browser currently has an active subscription for the project.
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().
| Parameter | Type | Description |
|---|---|---|
| opts? | SubscribeOptions | default: {} |
Cancel the current browser's subscription and beacon /v1/unsubscribe so the dashboard updates immediately. Returns true if a subscription was actually removed.
LitePushApiError
classThrown 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
| Parameter | Type | Description |
|---|---|---|
| code | LitePushErrorCode | string & object | — |
| message | string | — |
| status | number | — |
| body? | unknown | — |
Properties
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").
HTTP status of the failed response.
The parsed JSON response body, when the error body was JSON.
isLitePushApiError
functionType guard: narrow an unknown caught value to a LitePushApiError.
| Parameter | Type | Description |
|---|---|---|
| e | unknown | — |
canSubscribe
functionVERSION
constRe-exports
This entry point also re-exports the following shared types: