Skip to main content

UI & Cookies

Two small helper modules: sdk.ui for talking to the SitePack host environment, and sdk.cookies for first-party cookies.

UI

The sdk.ui module is primarily useful for apps rendered inside an iframe.

setHeight(height)

Tell the host page the iframe's new height in pixels, so it can resize the frame to fit your content.

// After rendering, report your content height
sdk.ui.setHeight(document.body.scrollHeight);

notify(message, type?)

Show a notification in the SitePack host environment.

sdk.ui.notify('Product added to cart.', 'success');
sdk.ui.notify('Something went wrong.', 'error');

type is one of 'success', 'info' (default), 'warning', or 'error'.

Messages are posted to the trusted origin only

setHeight and notify use postMessage targeted at the site's own origin (SITEPACK_DOMAIN) — never the * wildcard — so notification text and dimensions are not leaked to arbitrary embedding frames.

Cookies

The sdk.cookies module provides simple first-party cookie helpers. Cookies are written with SameSite=Lax and path=/.

set(name, value, days)

sdk.cookies.set('preferred_view', 'grid', 30); // expires in 30 days

get(name)

Returns the value, or null if the cookie is not set.

const view = sdk.cookies.get('preferred_view'); // 'grid' | null
Don't store sensitive data in cookies

These helpers write ordinary, non-HttpOnly cookies readable by any script on the page. Never store tokens, personal data, or anything security-sensitive with them — keep those on the server session.