Skip to content

API reference

The SDK exports a default singleton. Every method returns the singleton so you can chain calls.

ts
import packedge from '@packedge/js-sdk';

init(publicKey, options?)

Configure the SDK with your product's public key. Safe to call multiple times — later calls merge into the existing state.

ts
packedge.init('pk_your_public_key', {
  licenseKey: 'XXXX-XXXX-XXXX-XXXX',
  site: 'subdomain.example.com',
  baseUrl: 'https://api.packedge.dev',
  debug: false,
});
OptionTypeDefaultNotes
licenseKeystringAttributes events to a customer license
sitestringwindow.location.hostnameDomain identifier
baseUrlstringhttps://api.packedge.devOverride for staging/local
debugbooleanfalseLogs send failures to console.warn

track(event, properties?)

Record a feature-usage event. Fire-and-forget — never throws, never blocks the caller.

ts
packedge.track('feature_used', { feature: 'export', format: 'pdf' });

Returns true if the request was dispatched, false if the SDK was not initialized or the input was invalid.

setLicense(key | null)

Update the active license key without re-initializing.

ts
packedge.setLicense('MYPLUGIN-XXXX-XXXX-XXXX-XXXX');
packedge.setLicense(null); // clear

setSite(site | null)

Update the site/domain identifier.

ts
packedge.setSite('shop.example.com');

Transport behavior

  1. navigator.sendBeacon when available — queued by the browser, survives page unload, never blocks.
  2. fetch(..., { keepalive: true }) fallback for Safari, older browsers, and Node/edge runtimes.
  3. No transport → returns false; with debug: true a warning is logged.

Errors are always swallowed. track() never rejects a promise and never throws.

TypeScript

Type declarations ship with the package — no @types/... install needed.

ts
import packedge, { Packedge } from '@packedge/js-sdk';

// Singleton (default export)
packedge.init('pk_…');

// Or instantiate your own for advanced cases
const custom = new Packedge();
custom.init('pk_…', { baseUrl: 'https://staging.api.packedge.dev' });