Skip to main content

Controller API

Use initializeSpaazaElements() to set up the controller and mount components. Returns Promise<SpaazaController>.

InitOptions

PropertyTypeRequiredDescription
targetstringYesCSS selector (e.g., '#spaaza-elements')
configSpaazaConfigYesAPI and authentication configuration
pageNamestringNoPage name to load (default: "home")
campaignIdnumberNoCampaign ID. Activates the detail view.
voucherIdnumberNoVoucher ID. Activates the detail view.
businessIdnumberNoFilter page content by store. From user.home_store.home_store_id.
componentBaseUrlstringNoBase URL the controller uses to load component bundles. By default, derived from the location of the controller script (spaaza-elements.js).
customZonesCustomZonesOptionsNoCustom zones for voucher and membercard display. See Custom Zones.
handlerOverridesobjectNoDisable automatic handling for specific operations. See Handler Overrides.
hostOverridesobjectNoSuppress UI the controller renders itself, so your app can render it instead. See Host Overrides.

SpaazaConfig

PropertyTypeRequiredDescription
originstringYesAPI origin. Set to https://{API hostname} for your environment. Spaaza provides a different hostname per environment.
authSpaazaAuthConfigYesAuthentication 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.

PropertyTypeRequiredDescription
sessionKeystringYesSession key from login
userIDstringYesUser ID from login
myPriceAppHoststringYesYour 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.

PropertyTypeRequiredDescription
jwtstringYesSigned JWT access token issued by your identity provider
myPriceAppHoststringYesYour Spaaza app hostname (e.g., {MyPrice App hostname})

Controller Methods

The controller returned by initializeSpaazaElements() provides:

MethodDescription
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...');