@xapps-platform/widget-runtime
v0.1.7
Published
Public React runtime components for rendering Xapps widgets outside publisher iframes.
Readme
@xapps-platform/widget-runtime
Public React runtime components for rendering Xapps widgets outside publisher iframes.
Status
This package is now prepared for public distribution for React integrators who want the platform-rendered widget runtime above the lower-level embed/widget bridge.
Exports
UiKitWidgetAppShellWidgetWidgetRuntimeuseWidgetSessionuseWidgetUiBridgecreateWindowXappsHostAdapter- Types:
WidgetHostAdapter,WidgetContext,UiKitWidgetProps,AppShellWidgetProps,WidgetRuntimeProps
Bridge events supported
XAPPS_UI_NOTIFICATIONXAPPS_UI_ALERTXAPPS_UI_MODAL_OPENXAPPS_UI_MODAL_CLOSEXAPPS_UI_NAVIGATEXAPPS_UI_REFRESHXAPPS_UI_GET_CONTEXT->XAPPS_UI_GET_CONTEXT_RESULTXAPPS_UI_STATE_UPDATE(optional, if host providesupdateState)XAPPS_UI_EXPAND_REQUEST->XAPPS_UI_EXPAND_RESULT(optional, if host providesexpandWidget)XAPPS_OPEN_OPERATIONAL_SURFACE(optional, if host providesopenOperationalSurface)XAPPS_GUARD_REQUEST->XAPPS_GUARD_RESULT+XAPPS_GUARD_STATUS(optional, if host providesrequestGuard; otherwise config-driven fallback evaluator is used)- Fallback supports
config.policy.kind(confirmation,step_up,payment,subscription,allow,deny) - Fallback supports predicate rules:
config.policy.pass_if_any,pass_if_all,fail_if_any
- Fallback supports
XAPPS_REQUEST_CREATE_SUCCESS(request-id tracking convenience inuseWidgetSession)
UiKitWidget usage
import { UiKitWidget, type WidgetHostAdapter } from "@xapps-platform/widget-runtime";
const host: WidgetHostAdapter = {
showNotification: (msg, variant) => console.log("notify", variant, msg),
showAlert: (msg, title) => window.alert(`${title ?? "Alert"}\n\n${msg}`),
openModal: (title, message) => console.log("modal-open", title, message),
closeModal: () => console.log("modal-close"),
navigate: (path) => console.log("navigate", path),
refresh: () => window.location.reload(),
expandWidget: async (input) => {
// Map widget request to your app shell overlay/fullscreen logic.
const stage = input.stage || (input.expanded ? "focus" : "inline");
setWidgetOverlayStage(stage);
return {
hostManaged: true,
expanded: stage !== "inline",
stage,
};
},
};
<UiKitWidget
apiBaseUrl={window.location.origin}
installationId="inst_123"
widgetToken={token}
widget={widget}
tool={tool}
host={host}
/>;AppShellWidget usage
import { AppShellWidget } from "@xapps-platform/widget-runtime";
<AppShellWidget
apiBaseUrl={window.location.origin}
installationId="inst_123"
shellWidget={shellWidget}
xappWidgets={xappWidgets}
createWidgetSession={({ installationId, widgetId }) =>
api.createWidgetSession({ installationId, widgetId })
}
host={host}
/>;Minimal usage
import { WidgetRuntime } from "@xapps-platform/widget-runtime";
<WidgetRuntime
apiBaseUrl={window.location.origin}
installationId="inst_123"
widgetId="w_123"
createWidgetSession={createWidgetSession}
host={hostAdapter}
/>;Notes
- Runtime: host/platform React app rendering widget UIs.
- Can be used in the same host app with
@xapps-platform/marketplace-uiwhen product combines marketplace pages and runtime-rendered widgets. - Separate concern from
@xapps-platform/widget-sdk(publisher iframe widgets) and@xapps-platform/embed-sdk(host iframe bridge/orchestration). - Host UI actions are delegated through
WidgetHostAdapter(notification/modal/navigation/refresh). WidgetHostAdapter.expandWidget(...)enables host-managedinline/focus/fullscreenUX for widgets using the UI bridge.WidgetHostAdapter.openOperationalSurface(...)lets runtime-rendered widgets open marketplace surfaces forrequests,payments,invoices, andnotifications.- No implicit
window.XappsHostrequirement; compatibility is opt-in withcreateWindowXappsHostAdapter. - See package/runtime ownership:
docs/guides/12-package-usage-and-ownership.md.
