Controller API
Use initializeSpaazaElements() to set up the controller and mount components. Returns Promise<SpaazaController>.
InitOptions
| Property | Type | Required | Description |
|---|---|---|---|
target | string | Yes | CSS selector (e.g., '#spaaza-elements') |
config | SpaazaConfig | Yes | API and authentication configuration |
pageName | string | No | Page name to load (default: "home") |
campaignId | number | No | Campaign ID. Activates the detail view. |
voucherId | number | No | Voucher ID. Activates the detail view. |
businessId | number | No | Filter page content by store. From user.home_store.home_store_id. |
componentBaseUrl | string | No | Base URL the controller uses to load component bundles. By default, derived from the location of the controller script (spaaza-elements.js). |
customZones | CustomZonesOptions | No | Custom zones for voucher and membercard display. See Custom Zones. |
handlerOverrides | object | No | Disable automatic handling for specific operations. See Handler Overrides. |
hostOverrides | object | No | Suppress UI the controller renders itself, so your app can render it instead. See Host Overrides. |
SpaazaConfig
| Property | Type | Required | Description |
|---|---|---|---|
origin | string | Yes | API origin. Set to https://{API hostname} for your environment. Spaaza provides a different hostname per environment. |
auth | SpaazaAuthConfig | Yes | Authentication credentials. Either session-based or JWT-based. See SpaazaAuthConfig below. |
SpaazaAuthConfig
The auth field accepts one of two shapes. Session-based and JWT-based auth are mutually exclusive: pick one per initializeSpaazaElements() call.
Session-based auth
Use when your application authenticates against Spaaza directly via the /login or /signup endpoints.
| Property | Type | Required | Description |
|---|---|---|---|
sessionKey | string | Yes | Session key from login |
userID | string | Yes | User ID from login |
myPriceAppHost | string | Yes | Your Spaaza app hostname (e.g., {MyPrice App hostname}) |
JWT-based auth
Use when an external identity provider issues JWT access tokens that Spaaza can verify. The controller attaches the token as the X-Spaaza-Access-Token-JWT header on every authenticated request. See Responsibilities > JWT-based auth for the host's role in the token lifecycle.
| Property | Type | Required | Description |
|---|---|---|---|
jwt | string | Yes | Signed JWT access token issued by your identity provider |
myPriceAppHost | string | Yes | Your Spaaza app hostname (e.g., {MyPrice App hostname}) |
Controller Methods
The controller returned by initializeSpaazaElements() provides:
| Method | Description |
|---|---|
parseImageLink(imageLink) | Parse image_link string. See parseImageLink() for the full return-value table. |
refresh() | Refresh current view (re-fetches data) |
setJwt(token) | Replace the active JWT access token, SPA-style. Valid only in JWT-based auth mode. See Responsibilities > JWT-based auth. |
const controller = await initializeSpaazaElements({ ... });
// Refresh current view
await controller.refresh();
// Replace the JWT access token (JWT-based auth only)
controller.setJwt('eyJhbGciOiJSUzI1NiI...');