Skip to main content

Bootstrapping the Configurator

ProductConfigurator is the heart of the SDK: it owns the store, the API client, and the systems (mapping, product rules) that turn a product into a live configuration. This page walks you through the recommended startup sequence, from install to the moment your hooks become safe to use.

Step 1: Install and import​

import { ProductConfigurator } from "@expivi/sdk";

Step 2: Register the UI web components (optional)​

If your UI uses Expivi web components (the xpv-* elements), register them once before you render them. Each group of components has its own entry point with a defineCustomElements function:

import { defineCustomElements as defineUiKitElements } from "@expivi/sdk/ui-kit/components";
import { defineCustomElements as defineUiComposerElements } from "@expivi/sdk/ui-composer/components";
import { defineCustomElements as defineFormRendererElements } from "@expivi/sdk/form-renderer/components";
import { defineCustomElements as defineOfferInquiryElements } from "@expivi/sdk/offer-inquiry/components";
import { defineCustomElements as definePriceBreakdownElements } from "@expivi/sdk/price-breakdown/components";
import { defineCustomElements as defineBomBreakdownElements } from "@expivi/sdk/bom-breakdown/components";

defineUiKitElements();
defineUiComposerElements();
defineFormRendererElements();
defineOfferInquiryElements();
definePriceBreakdownElements();
defineBomBreakdownElements();

Register only the groups you render. If you are building a fully custom UI on top of the hooks, you can skip this step. See How the UI components work for which group contains which elements.

note

Use the …/components entry points with a bundler such as Vite or webpack. The …/loader entry points load each component from a separate file at runtime, which only works when the SDK files are served as they are, without a bundler.

Step 3: Create the ProductConfigurator​

Construct the configurator with your API credentials and optional locale metadata. apiBaseUrl and apiToken are the only required options; everything else has a sensible default.

const productConfigurator = new ProductConfigurator({
apiBaseUrl: "https://api.example.expivi.net",
apiToken: "your-api-token",
locale: "nl-NL",
country: "nl",
currency: "EUR",
});

Constructor options​

OptionTypeRequiredDefaultDescription
apiBaseUrlstringyes—Base URL for the Expivi API.
apiTokenstringyes—Access token used by the generated service clients.
localestringnoAccount defaultLocale for the API client and formatting-sensitive UI. When omitted, the API uses the account default.
countrystringnoAccount defaultCountry passed into the API client global config. When omitted, the API uses the account default.
currencystringnoAccount defaultCurrency passed into the API client global config. When omitted, the API uses the account default.
versionstringno—Version metadata.
snapshotIdstringno—Snapshot to restore while the product loads. Takes precedence over productConfigurationIdentifier.
productConfigurationIdentifierstringno—Identifier of a saved product configuration to restore while the product loads. Ignored when snapshotId is set.
getConfigurationLink(snapshotId: string) => stringno—Builds the shareable configuration link used by quote/download flows. Must be a function if provided.

The constructor validates its input and throws if apiBaseUrl or apiToken is missing, or if getConfigurationLink is provided but is not a function. On success it creates the store and sets the status to INIT.

Step 4: Load a product​

await productConfigurator.loadProduct(productId);

loadProduct(...) drives the configurator through its lifecycle. Each stage sets a ProductConfiguratorStatus you can observe (see the app shell guide):

  1. Status → LOADING.
  2. Loads the product offer.
  3. Loads the product layout.
  4. Status → LOADED.
  5. Initializes the internal systems (mapping engine, product rules engine).
  6. If snapshotId or productConfigurationIdentifier was configured, restores that saved configuration.
  7. Starts the systems, so the first rules evaluation runs on the restored configuration.
  8. Status → READY.

The full set of statuses is INIT, LOADING, LOADED, READY, ERROR, and DESTROYED. If loading fails, the status is set to ERROR and an error message is added to the store.

Step 5: Create hooks once the store is populated​

Most hook controllers (everything built on HookController) require the configurator to already be initialized. They throw Product configurator is not initialized. unless the status is LOADED or READY, so create them only after loadProduct has reached at least the LOADED stage.

The one exception is useProductConfigurator, which is safe to create at any time — it exists specifically so your shell can observe the lifecycle before the product is ready.

Full example​

import { ProductConfigurator } from "@expivi/sdk";

const productConfigurator = new ProductConfigurator({
apiBaseUrl: "https://api.example.expivi.net",
apiToken: "your-api-token",
});

await productConfigurator.loadProduct(productId);

// Safe now that the configurator is READY:
const productStore = useStoreProductOffers(productConfigurator);
const layout = useProductOfferLayout(productConfigurator);

If you would rather not block on the load, you can kick it off without awaiting and let your app shell react to the status instead:

const productConfigurator = new ProductConfigurator({ apiBaseUrl, apiToken });

void productConfigurator.loadProduct(productId);

// Mount your UI immediately; it renders a loader until status is READY,
// and only then adds the Expivi web components.

See Understanding the App Shell for that non-blocking pattern in detail.