Browser SDK API Reference
Auto-generated from TypeDoc annotations in @hoberhq/browser-sdk. All methods are available on the default Hober export.
Hober.init(options)
Initializes the SDK. Must be called before any other method.
Signature
Hober.init(options: HoberInitOptions): void
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
options.sdkKey | string | Yes | Your Hober SDK key from the dashboard. |
options.serviceWorkerPath | string | No | Path to hober-sw.js. Defaults to "/hober-sw.js". |
options.baseUrl | string | No | Override the Hober API base URL (e.g. for staging). |
Returns: void
Throws: HoberError if sdkKey is empty or options is not provided.
Hober.requestPermission()
Requests the Notification permission from the browser. Returns Promise<boolean>.
Signature
Hober.requestPermission(): Promise<boolean>
Returns: Promise<boolean> — resolves to true if the user grants permission, false if denied or dismissed.
Throws: HoberError if the SDK has not been initialized.
Hober.identifySubscriber(subscriber)
Associates the current user with a Hober subscriber record by calling POST /v1/subscribers/upsert.
Signature
Hober.identifySubscriber(subscriber: HoberSubscriberOptions): Promise<void>
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
subscriber.externalId | string | Yes | Your application's user identifier. |
subscriber.email | string | No | Subscriber email address. |
subscriber.attributes | Record<string, string | number | boolean> | No | Additional subscriber attributes. |
Returns: Promise<void>
Throws: HoberError if externalId is empty or the API returns a non-2xx response.
Hober.registerDevice()
Registers the current browser as a push-enabled device by subscribing to the Web Push service and calling POST /v1/devices.
Signature
Hober.registerDevice(): Promise<void>
Returns: Promise<void>
Throws: HoberError if the SDK has not been initialized, if the service worker is not registered, or the API returns a non-2xx response.
Types
HoberInitOptions
interface HoberInitOptions {
sdkKey: string;
serviceWorkerPath?: string;
baseUrl?: string;
}
HoberSubscriberOptions
interface HoberSubscriberOptions {
externalId: string;
email?: string;
attributes?: Record<string, string | number | boolean>;
}
HoberError
class HoberError extends Error {
code: string;
}