NebulaNebula
Reference

@nebula-rn/sdk

Nebula SDK core package API reference, including host initialization, miniapp runtime, lifecycle hooks, and type definitions.

@nebula-rn/sdk is Nebula's core runtime package, providing both host initialization API (NebulaAPI) and miniapp client API (MiniAppAPI, which is an alias export of NebulaAPI).

Version: 0.1.0

Peer Dependencies: react >= 19, react-native >= 0.83


Host Initialization

NebulaAPI.wrap(options)

A higher-order component (HOC) that wraps the host app's root component and initializes the Nebula runtime. Automatically calls startApiServer() when the component mounts, and also calls setServerBaseURL() if serverBaseURL is non-empty.

PlatformSupport
iOS✅
Android✅
function wrap(
  options: NebulaHostOptions,
): <P>(Component: React.ComponentType<P>) => React.ComponentType<P>;

Parameters NebulaHostOptions:

ParameterTypeRequiredDefaultDescription
hostApisNebulaHostFeature[]No[]List of host API features to register with the runtime.
serverBaseURLstring | nullNonullBase URL for the miniapp resource service.

Example:

import { NebulaAPI } from '@nebula-rn/sdk';
import { defaultHostApis } from '@nebula-rn/host-apis';

export default NebulaAPI.wrap({
  serverBaseURL: 'https://api.example.com',
  hostApis: defaultHostApis,
})(App);

NebulaAPI.startApiServer()

Starts the host-side API message processing service, listening for protocol requests from miniapps. Typically called automatically by wrap(); calling it manually is idempotent.

PlatformSupport
iOS✅
Android✅
function startApiServer(): void;

Request types handled:

Request kindDescription
getCapabilitiesReturns version and support status of registered host APIs.
getApiDescriptionsReturns documentation descriptions of registered host APIs.
invokeRoutes to the corresponding API handler for execution.

Internal error codes:

Error codeDescription
UNSUPPORTED_APIThe requested API is not registered or not supported.
INTERNAL_ERRORAn exception was thrown during handler execution.

NebulaAPI.stopApiServer()

Stops the host-side API message listener and cancels bridge event subscriptions.

PlatformSupport
iOS✅
Android✅
function stopApiServer(): void;

NebulaAPI.setServerBaseURL(serverBaseURL)

Sets the base URL for the host service, persisting it to native storage. This URL is used to resolve relative paths when installing and updating miniapps.

PlatformSupport
iOS✅
Android✅
function setServerBaseURL(
  serverBaseURL?: string | null,
): Promise<ServerBaseURLResult>;

Parameters:

ParameterTypeRequiredDefaultDescription
serverBaseURLstring | nullNo—A valid http(s) URL; pass null or an empty string to clear.

Return value ServerBaseURLResult:

FieldTypeDescription
serverBaseURLstring | nullThe URL that was set.

Error codes:

Error codePlatformDescription
INVALID_SERVER_URLiOS / AndroidURL format validation failed.

NebulaAPI.getServerBaseURL()

Gets the currently configured service base URL.

PlatformSupport
iOS✅
Android✅
function getServerBaseURL(): Promise<ServerBaseURLResult>;

Return value ServerBaseURLResult:

FieldTypeDescription
serverBaseURLstring | nullThe current URL, or null if not set.

Miniapp Installation

NebulaAPI.installMiniApp(appId, bundleURL)

Downloads and installs a miniapp bundle from a remote URL (production mode). Automatically fetches and stores the app.json manifest.

PlatformSupport
iOS✅
Android✅
function installMiniApp(
  appId: string,
  bundleURL: string,
): Promise<MiniAppResult>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesUnique identifier of the miniapp.
bundleURLstringYesRemote URL of the bundle (http/https).

Return value MiniAppResult:

FieldTypeDescription
successbooleanWhether the installation was successful.
appIdstringThe miniapp ID.

Platform differences:

AndroidiOS
Bundle pathFiles/nebula/{appId}/index.android.bundleDocuments/MiniApps/{appId}/index.bundle
Network timeoutConnect 15s + read 15sURLSession default
Manifest fetchAutomatically replaces filename with app.jsonSame as Android

Error codes:

Error codeDescription
INSTALL_ERRORDownload or parsing failed.

NebulaAPI.installMiniAppWithBundleURL(appId, bundleURL, connectToURLMetroServer?)

Installs a miniapp with the specified bundle URL, using connectToURLMetroServer to determine whether to treat it as a Metro development runtime connected to that URL.

PlatformSupport
iOS✅
Android✅
function installMiniAppWithBundleURL(
  appId: string,
  bundleURL: string,
  connectToURLMetroServer?: boolean,
): Promise<MiniAppResult>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesUnique identifier of the miniapp.
bundleURLstringYesRemote URL of the bundle.
connectToURLMetroServerbooleanNofalse installs as production; true treats the URL as a Metro development entry point.

Return value MiniAppResult:

FieldTypeDescription
successbooleanWhether the installation was successful.
appIdstringThe miniapp ID.
modestringFinal installation mode: development or production.

Behavior differences:

connectToURLMetroServer = trueconnectToURLMetroServer = false
Installation modedevelopmentproduction
versionnull (version not tracked)Read from manifest
updateStrategyForced 'manual'Read from manifest, defaults to 'manual'
Dev URLSaves hot reload URLNot saved

Error codes:

Error codeDescription
INSTALL_ERRORDownload or parsing failed.
INVALID_MODEMode string is invalid (iOS only).

Opening and Preloading Miniapps

NebulaAPI.openMiniApp(appId, initialProps?, versionType?)

Opens an installed miniapp and displays it to the user. If not installed locally, it will automatically install the specified version type (defaults to release). If the miniapp is in production mode and updateStrategy is 'auto', it will automatically check for and apply updates before opening (update failure does not block opening).

PlatformSupport
iOS✅
Android✅
function openMiniApp(
  appId: string,
  initialProps?: Record<string, unknown>,
  versionType?: 'release' | 'experience',
): Promise<MiniAppResult>;

Parameters:

ParameterTypeRequiredDefaultDescription
appIdstringYes—Installed miniapp ID.
initialPropsRecord<string, unknown>No{}Initial properties passed to the miniapp root component.
versionType'release' | 'experience'No'release'Which cloud version to automatically install if not installed.

Return value MiniAppResult:

FieldTypeDescription
successbooleanWhether opening was successful.
appIdstringThe miniapp ID.

Platform differences:

AndroidiOS
Threading modelactivity.runOnUiThread()DispatchQueue.main.async
No UI container errorNO_ACTIVITYNO_ROOT_VC

Error codes:

Error codePlatformDescription
NO_ACTIVITYAndroidCurrent Activity not found.
NO_ROOT_VCiOSRoot view controller not found.
OPEN_ERRORAllRuntime error.

NebulaAPI.openMiniAppWithBundleURL(appId, bundleURL, initialProps?, connectToURLMetroServer?)

Installs and immediately opens a miniapp. Equivalent to calling installMiniAppWithBundleURL() followed by openMiniApp().

PlatformSupport
iOS✅
Android✅
function openMiniAppWithBundleURL(
  appId: string,
  bundleURL: string,
  initialProps?: Record<string, unknown>,
  connectToURLMetroServer?: boolean,
): Promise<MiniAppResult>;

Parameters:

ParameterTypeRequiredDefaultDescription
appIdstringYes—Unique identifier of the miniapp.
bundleURLstringYes—Remote URL of the bundle.
initialPropsRecord<string, unknown>No{}Initial properties passed to the root component.
connectToURLMetroServerbooleanNofalseWhen true, treats as development mode connecting to Metro at that URL; otherwise installs and opens as production.

NebulaAPI.preloadMiniApp(appId)

Preloads an installed miniapp in the background, creating the runtime and root view in advance to reduce subsequent open time.

PlatformSupport
iOS✅
Android✅
function preloadMiniApp(appId: string): Promise<MiniAppResult>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesInstalled miniapp ID.

Return value MiniAppResult:

FieldTypeDescription
successbooleanWhether preloading was successful.
appIdstringThe miniapp ID.

Platform implementation differences:

iOSAndroid
Caching strategySingle-slot cache + generation counterReactHost cache pool (ConcurrentHashMap)
Container approachViewController hidden at bottom layerBackground ReactHost instance

Error codes:

Error codeDescription
PRELOAD_ERRORRuntime error during preloading.

NebulaAPI.preloadMiniAppWithBundleURL(appId, bundleURL, connectToURLMetroServer?)

Installs then preloads a miniapp. Equivalent to calling installMiniAppWithBundleURL() followed by preloadMiniApp().

PlatformSupport
iOS✅
Android✅
function preloadMiniAppWithBundleURL(
  appId: string,
  bundleURL: string,
  connectToURLMetroServer?: boolean,
): Promise<MiniAppResult>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesUnique identifier of the miniapp.
bundleURLstringYesRemote URL of the bundle.
connectToURLMetroServerbooleanNoWhen false, preloads as production; when true, connects to Metro at that URL.

Error codes:

Error codeDescription
PRELOAD_ERRORRuntime error during preloading.

Version and Update

NebulaAPI.checkMiniAppUpdate(appId)

Checks whether an update is available for a miniapp. Fetches the remote app.json manifest and compares version numbers using semver numeric segment comparison.

PlatformSupport
iOS✅
Android✅
function checkMiniAppUpdate(appId: string): Promise<MiniAppUpdateInfo>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesInstalled miniapp ID.

Return value MiniAppUpdateInfo:

FieldTypeDescription
appIdstringThe miniapp ID.
currentVersionstring | nullCurrently installed version.
latestVersionstring | nullLatest remote version.
hasUpdatebooleanWhether an update is available.
updateStrategy'auto' | 'manual'Update strategy.
modestring | nullRuntime mode.
sourceUrlstring | nullBundle source URL.

Cases where hasUpdate: false is returned:

  • Miniapp is not installed
  • In development mode
  • No sourceUrl (non-remote app)
  • Unable to derive manifest URL

Version comparison logic: Split by . into numeric segments and compare segment by segment; missing segments default to 0.


NebulaAPI.applyMiniAppUpdate(appId)

Checks for and applies a miniapp update. Internally calls checkMiniAppUpdate() first; if an update is available, calls installMiniAppWithBundleURL() to download and install.

PlatformSupport
iOS✅
Android✅
function applyMiniAppUpdate(appId: string): Promise<MiniAppUpdateInfo>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesInstalled miniapp ID.

Return value: Same as MiniAppUpdateInfo.


Miniapp Information

NebulaAPI.getInstalledMiniAppInfo(appId)

Gets local installation information for a miniapp.

PlatformSupport
iOS✅
Android✅
function getInstalledMiniAppInfo(
  appId: string,
): Promise<InstalledMiniAppInfoResult>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesMiniapp ID.

Return value InstalledMiniAppInfoResult:

FieldTypeDescription
installedbooleanWhether installed.
appInstalledMiniAppInfo | undefinedInstallation info object, undefined if not installed.

InstalledMiniAppInfo fields:

FieldTypeDescription
appIdstringMiniapp ID.
modestring | nullRuntime mode.
bundlePathstring | nullLocal bundle file path.
sourceUrlstring | nullRemote bundle source URL.
versionstring | nullVersion from manifest.
updateStrategy'auto' | 'manual' | nullUpdate strategy.

NebulaAPI.getInstalledMiniApps()

Gets the list of IDs of all installed miniapps.

PlatformSupport
iOS✅
Android✅
function getInstalledMiniApps(): Promise<InstalledMiniAppsResult>;

Return value InstalledMiniAppsResult:

FieldTypeDescription
appsstring[]Array of installed miniapp IDs.

MiniAppAPI.navigateTo(url)

Navigates to a new page, pushing the current page onto the page stack.

PlatformSupport
iOS✅
Android✅
function navigateTo(url: string): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDescription
urlstringYesTarget page URL, e.g., "/detail?id=123".

Return value NavigationResult:

FieldTypeDescription
errMsgstringFormat: "navigateTo:ok" or "navigateTo:fail <reason>".

Platform differences:

AndroidiOS
Threadactivity.runOnUiThread()DispatchQueue.main.async

MiniAppAPI.redirectTo(url)

Navigates to a new page, replacing the current page (cannot go back).

PlatformSupport
iOS✅
Android✅
function redirectTo(url: string): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDescription
urlstringYesTarget page URL.

MiniAppAPI.reLaunch(url)

Clears all page stacks and opens the target page.

PlatformSupport
iOS✅
Android✅
function reLaunch(url: string): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDescription
urlstringYesTarget page URL.

MiniAppAPI.navigateBack(delta?)

Pops pages from the page stack.

PlatformSupport
iOS✅
Android✅
function navigateBack(delta?: number): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDefaultDescription
deltanumberNo1Number of pages to pop.

Page Styling

MiniAppAPI.setPageStyle(style)

Sets the appearance style of the current page.

PlatformSupport
iOS✅
Android✅
function setPageStyle(style: NebulaPageStyle): Promise<NavigationResult>;

Parameters NebulaPageStyle:

ParameterTypeRequiredDescription
backgroundColorstringNoPage background color.
navigationBarBackgroundColorstringNoNavigation bar background color.
navigationBarTextColorstringNoNavigation bar text color.
navigationBarTitleTextstringNoNavigation bar title.
navigationStyle'default' | 'custom'NoNavigation bar style; 'custom' hides the default navigation bar.
visualEffectInBackground'blur' | 'none'NoVisual effect when app enters background. iOS only.

MiniAppAPI.setNavigationBarTitle(title)

Convenience method for setting the navigation bar title. Internally calls setPageStyle({ navigationBarTitleText: title }).

PlatformSupport
iOS✅
Android✅
function setNavigationBarTitle(title: string): Promise<NavigationResult>;

MiniAppAPI.setNavigationBarColor(options)

Convenience method for setting the navigation bar color.

PlatformSupport
iOS✅
Android✅
function setNavigationBarColor(options: {
  backgroundColor?: string;
  frontColor?: string;
}): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDescription
backgroundColorstringNoNavigation bar background color.
frontColorstringNoNavigation bar foreground color (text/icons).

Device and App

MiniAppAPI.getAppId()

Gets the current miniapp ID. Synchronous method.

PlatformSupport
iOS✅
Android✅
function getAppId(): string | null;

Return value: Current miniapp ID, or null if not initialized.


MiniAppAPI.getSandboxPath()

Gets the miniapp's file sandbox path.

PlatformSupport
iOS✅
Android✅
function getSandboxPath(): string;

Return value: Sandbox path string, e.g., /Documents/MiniApps/{appId}.


MiniAppAPI.getDeviceInfo()

Gets device information. Synchronous blocking call.

PlatformSupport
iOS✅
Android✅
function getDeviceInfo(): DeviceInfo;

Return value DeviceInfo:

FieldTypeDescription
platform'iOS' | 'Android'Current platform.
systemVersionstringSystem version number.
modelstringDevice model.

Platform differences:

AndroidiOS
systemVersionBuild.VERSION.RELEASEUIDevice.current.systemVersion
modelBuild.MODELUIDevice.current.model

MiniAppAPI.showToast(title)

Displays a brief toast message.

PlatformSupport
iOS✅
Android✅
function showToast(title: string): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDescription
titlestringYesToast text.

Platform differences:

AndroidiOS
ImplementationToast.LENGTH_SHORTUIAlertController
Duration~2 seconds1.5 seconds

Host Communication

MiniAppAPI.invokeHostApi(apiName, payload?, version?, timeoutMs?)

Calls a host-registered API from a miniapp. Sends a request through the Nebula protocol layer (api.v1) and waits for a response.

PlatformSupport
iOS✅
Android✅
function invokeHostApi<TData = unknown>(
  apiName: string,
  payload?: Record<string, unknown>,
  version?: string,
  timeoutMs?: number,
): Promise<NebulaApiInvokeResult<TData>>;

Parameters:

ParameterTypeRequiredDefaultDescription
apiNamestringYes—Name of the host API to call.
payloadRecord<string, unknown>No{}Data to pass to the API handler.
versionstringNo'1.0.0'Requested API version.
timeoutMsnumberNo15000Request timeout in milliseconds. 0 means no timeout.

Return value NebulaApiInvokeResult<TData>:

// Success
{ ok: true, data: TData }

// Failure
{ ok: false, error: { code: string, message: string, details?: Record<string, unknown> } }

Error codes:

Error codeDescription
UNSUPPORTED_APIAPI is not registered or not supported.
INTERNAL_ERRORException during handler execution.

Timeout: 15000ms. After timeout, the request is cleaned up and the Promise rejects with "Timed out waiting for host API: {apiName}".


MiniAppAPI.postMessageToHost(message)

Sends a message to the host.

PlatformSupport
iOS✅
Android✅
function postMessageToHost(
  message: Record<string, unknown>,
): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDescription
messageRecord<string, unknown>YesAny JSON-serializable object.

MiniAppAPI.onHostMessage(listener)

Subscribes to messages from the host.

PlatformSupport
iOS✅
Android✅
function onHostMessage(listener: (event: BridgeMessage) => void): () => void;

BridgeMessage fields:

FieldTypeDescription
appIdstringID of the app sending the message.
messageobjectMessage content.
timestampnumberMessage timestamp.

Return value: Unsubscribe function.


NebulaAPI.postMessageToMiniApp(appId, message)

Sends a message from the host to a specified miniapp.

PlatformSupport
iOS✅
Android✅
function postMessageToMiniApp(
  appId: string,
  message: Record<string, unknown>,
): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesTarget miniapp ID.
messageRecord<string, unknown>YesAny JSON-serializable object.

NebulaAPI.addMiniAppMessageListener(listener)

Subscribes to messages from miniapps (for host-side use).

PlatformSupport
iOS✅
Android✅
function addMiniAppMessageListener(
  listener: (event: BridgeMessage) => void,
): () => void;

Return value: Unsubscribe function.


Capability Detection

MiniAppAPI.getCapabilities()

Gets the list of all API capabilities registered by the host.

PlatformSupport
iOS✅
Android✅
function getCapabilities(): Promise<{
  bridgeVersion: string;
  capabilities: NebulaHostCapabilityMap;
}>;

Return value:

FieldTypeDescription
bridgeVersionstringProtocol version, currently fixed at '1.0.0'.
capabilitiesNebulaHostCapabilityMapMapping from API name to capability description.

NebulaHostCapabilityDescriptor fields:

FieldTypeDescription
supportedbooleanWhether supported.
versionstringAPI version number.

Timeout: 15000ms (fixed).


MiniAppAPI.isSupported(apiName, minimumVersion?)

Checks whether a specified API is supported by the host, optionally validating a minimum version.

PlatformSupport
iOS✅
Android✅
function isSupported(
  apiName: string,
  minimumVersion?: string,
): Promise<boolean>;

Parameters:

ParameterTypeRequiredDescription
apiNamestringYesAPI name.
minimumVersionstringNoRequired minimum version, e.g., "1.0.0".

Return value: true if supported and meets version requirements.


MiniAppAPI.getHostApiDescriptions(timeoutMs?)

Gets detailed documentation descriptions of host-registered APIs.

PlatformSupport
iOS✅
Android✅
function getHostApiDescriptions(
  timeoutMs?: number,
): Promise<NebulaHostApiDescriptionMap>;

Parameters:

ParameterTypeRequiredDefaultDescription
timeoutMsnumberNo15000Request timeout in milliseconds.

Return value NebulaHostApiDescriptionMap:

Record<string, NebulaHostApiDescription>;

NebulaHostApiDescription fields:

FieldTypeDescription
summarystringAPI summary.
descriptionstring | undefinedDetailed description.
paramsNebulaApiFieldDescriptor[]Parameter list.
returns{ type: string; description: string }Return value description.
tagsstring[]Tag list.
examplesNebulaApiExampleDescriptor[]Example code.

Host Visibility and Modal

MiniAppAPI.bringHostToFront()

Brings the host app to the foreground while hiding the miniapp (preserves state for restoration).

PlatformSupport
iOS✅
Android✅
function bringHostToFront(): Promise<HostVisibilityResult>;

Return value HostVisibilityResult:

FieldTypeDescription
successbooleanWhether the operation was successful.
tokenstring | undefinedRestoration token to pass to restoreMiniApp().

MiniAppAPI.restoreMiniApp(token?)

Restores a miniapp previously hidden via bringHostToFront().

PlatformSupport
iOS✅
Android✅
function restoreMiniApp(token?: string | null): Promise<HostVisibilityResult>;

Parameters:

ParameterTypeRequiredDefaultDescription
tokenstring | nullNonullRestoration token; null restores the most recent one.

MiniAppAPI.presentHostModal(moduleName, props?)

Presents a host-side React Native module as a Modal.

PlatformSupport
iOS✅
Android✅
function presentHostModal(
  moduleName: string,
  props?: Record<string, unknown>,
): Promise<NavigationResult>;

Parameters:

ParameterTypeRequiredDefaultDescription
moduleNamestringYes—Registered RN component name.
propsRecord<string, unknown>No{}Properties to pass to the Modal component.

Platform differences:

AndroidiOS
PresentationNew Activity (FLAG_ACTIVITY_NO_ANIMATION)overFullScreen + crossDissolve transition

Error codes:

Error codePlatformDescription
NO_ACTIVITYAndroidCurrent Activity not found.
PRESENT_HOST_MODAL_ERRORAndroidFailed to present Modal.

MiniAppAPI.dismissHostModal()

Dismisses the currently presented host Modal.

PlatformSupport
iOS✅
Android✅
function dismissHostModal(): Promise<NavigationResult>;

Page Lifecycle

MiniAppAPI.onPageLifecycle(listener)

Subscribes to page lifecycle events.

PlatformSupport
iOS✅
Android✅
function onPageLifecycle(
  listener: (event: PageLifecycleEvent) => void,
): () => void;

PageLifecycleEvent fields:

FieldTypeDescription
appIdstringMiniapp ID.
instanceIdstringPage instance ID.
routePathstring | undefinedCurrent page path.
type'show' | 'hide' | 'unload'Event type.

Return value: Unsubscribe function.


Lifecycle Hooks

usePageOnLoad(callback)

Executes when the page loads for the first time, receiving route parameters. Triggers once when the component mounts.

PlatformSupport
iOS✅
Android✅
function usePageOnLoad(
  callback: (params: Record<string, unknown>) => void,
): void;

Parameters:

ParameterTypeDescription
callback(params) => voidCallback that receives route query parameters.

usePageOnShow(callback)

Executes every time the page becomes visible. Triggers when the component mounts, then on every 'show' lifecycle event.

PlatformSupport
iOS✅
Android✅
function usePageOnShow(callback: () => void): void;

usePageOnReady(callback)

Executes after the page has rendered (after the first animation frame). Uses requestAnimationFrame() internally.

PlatformSupport
iOS✅
Android✅
function usePageOnReady(callback: () => void): void;

usePageOnHide(callback)

Executes when the page becomes invisible. Triggers on the 'hide' lifecycle event.

PlatformSupport
iOS✅
Android✅
function usePageOnHide(callback: () => void): void;

usePageOnUnload(callback)

Executes when the page is unloaded. Triggers when the component unmounts (cleanup function).

PlatformSupport
iOS✅
Android✅
function usePageOnUnload(callback: () => void): void;

Route Registration

NebulaAPI.registerRoutes(appId, routes)

Registers the miniapp's route table, typically called when the miniapp starts.

PlatformSupport
iOS✅
Android✅
function registerRoutes(
  appId: string,
  routes: Record<string, string>,
): Promise<void>;

Parameters:

ParameterTypeRequiredDescription
appIdstringYesCurrent miniapp ID.
routesRecord<string, string>YesMapping from path to component name, e.g., { "/": "Home", "/detail": "Detail" }.

NebulaAPI.registerManifest(appId, manifest)

Registers the complete miniapp manifest (extended route table with page configurations).

PlatformSupport
iOS✅
Android✅
function registerManifest(
  appId: string,
  manifest: RegisteredMiniAppManifest,
): Promise<void>;

Parameters RegisteredMiniAppManifest:

ParameterTypeRequiredDescription
pagesRecord<string, string>YesMapping from path to component name.
entryPagePathstringNoEntry page path, e.g., "/".
pageConfigsRecord<string, NebulaPageStyle>NoPage-level style overrides.
windowNebulaPageStyleNoGlobal window style.
updateStrategy'auto' | 'manual'NoUpdate strategy.
versionstringNoVersion number.

Error codes:

Error codeDescription
INVALID_MANIFESTManifest JSON parsing failed.

Host API Registration

NebulaAPI.registerApiHandler(apiName, handler)

Manually registers a host API handler. Automatically calls startApiServer() if the API Server has not been started.

PlatformSupport
iOS✅
Android✅
function registerApiHandler(
  apiName: string,
  handler: NebulaHostApiHandler,
): void;

Parameters NebulaHostApiHandler:

ParameterTypeRequiredDefaultDescription
versionstringYes—API version number, e.g., "1.0.0".
supportedboolean | () => Promise<boolean>NotrueWhether supported; can be an async function.
descriptionNebulaHostApiDescriptionNo—API documentation description.
handle(payload, context) => Promise<NebulaApiInvokeResult>Yes—Request handler function.

NebulaAPI.unregisterApiHandler(apiName)

Unregisters a host API handler.

PlatformSupport
iOS✅
Android✅
function unregisterApiHandler(apiName: string): void;

NebulaAPI.getRegisteredCapabilities()

Gets the version and support status of all registered APIs (asynchronously resolves supported functions).

PlatformSupport
iOS✅
Android✅
function getRegisteredCapabilities(): Promise<NebulaHostCapabilityMap>;

NebulaAPI.getRegisteredApiDescriptions()

Synchronously gets the documentation descriptions of all registered APIs.

PlatformSupport
iOS✅
Android✅
function getRegisteredApiDescriptions(): NebulaHostApiDescriptionMap;

Host Feature Factories

createHostApiFeature(options)

Creates a UI-less host API feature for registration with hostApis in NebulaAPI.wrap().

PlatformSupport
iOS✅
Android✅
function createHostApiFeature(
  options: RegisterHostApiOptions,
): NebulaHostFeature;

Parameters RegisterHostApiOptions:

ParameterTypeRequiredDefaultDescription
apiNamestringYes—API name identifier.
versionstringNo'1.0'API version number.
supportedboolean | () => Promise<boolean>NotrueWhether this API is supported.
descriptionNebulaHostApiDescriptionNo—API documentation description.
handle(payload, context) => Promise<NebulaApiInvokeResult>Yes—Request handler function.

Return value NebulaHostFeature: A feature object containing name, description, and a register() method.


createHostModalApiFeature(options)

Creates a host API feature that requires Modal UI. Automatically presents a Modal when called, and returns the result when the Modal closes.

PlatformSupport
iOS✅
Android✅
function createHostModalApiFeature<TPayload, TRequest>(
  options: RegisterHostModalApiOptions<TPayload, TRequest>,
): NebulaHostFeature;

Parameters RegisterHostModalApiOptions:

ParameterTypeRequiredDescription
apiNamestringYesAPI name identifier.
componentReact.ComponentTypeYesReact component to render in the Modal.
channelHostModalChannel<TRequest>YesModal request channel.
createRequest(payload: TPayload) => TRequestYesCreates a Modal request from the API payload.
modalPropsRecord | (payload, request) => RecordNoAdditional properties to pass to the Modal component.
onBeforeOpen(payload) => Promise<NebulaApiInvokeResult | null>NoPre-processing before Modal opens (e.g., permission check); returning non-null skips the Modal.
onUnmountErrorMessagestringNoError message when Modal unmounts abnormally.
versionstringNoAPI version number.
descriptionNebulaHostApiDescriptionNoAPI documentation description.

createHostModalChannel()

Creates a bidirectional request-response channel for Modals, used for communication between host components and API calls.

PlatformSupport
iOS✅
Android✅
function createHostModalChannel<
  TRequest extends object,
>(): HostModalChannel<TRequest>;

Return value HostModalChannel<TRequest>:

MethodSignatureDescription
open(request: TRequest) => Promise<NebulaApiInvokeResult>Opens the channel and waits for a result.
settle(result: NebulaApiInvokeResult) => voidSubmits a result from the Modal side.
getCurrent() => TRequest | nullGets the current request.
clear() => voidClears the current request.
subscribe(listener: (request: TRequest | null) => void) => () => voidListens for request changes.

Helper Functions

createHostApiSuccess(data)

Creates a successful API return result.

function createHostApiSuccess<TData>(data: TData): NebulaApiInvokeResult<TData>;
// Returns { ok: true, data }

createHostApiFailure(code, message)

Creates a failed API return result.

function createHostApiFailure(
  code: string,
  message: string,
): NebulaApiInvokeResult;
// Returns { ok: false, error: { code, message } }

definePageConfig(config)

TypeScript helper function for page configuration (pass-through, provides type constraints only).

PlatformSupport
iOS✅
Android✅
function definePageConfig<T extends MiniAppPageConfig>(config: T): T;

Parameters MiniAppPageConfig:

ParameterTypeRequiredDescription
routestringNoPage route path.
backgroundColorstringNoPage background color.
navigationBarBackgroundColorstringNoNavigation bar background color.
navigationBarTextColorstringNoNavigation bar text color.
navigationBarTitleTextstringNoNavigation bar title.
navigationStyle'default' | 'custom'NoNavigation bar style.
visualEffectInBackground'blur' | 'none'NoVisual effect when in background. iOS only.

createMiniAppPage(Component)

Higher-order component that wraps a miniapp page component, providing Nebula context. Automatically calls MiniAppAPI.bootstrap() and provides MiniAppPageContext.

PlatformSupport
iOS✅
Android✅
function createMiniAppPage<P extends Record<string, unknown>>(
  Component: React.ComponentType<P>,
): React.ComponentType<P>;

Reserved Props (not passed to child component): appId, instanceId, sandboxPath, title, __pageConfig, __routePath, __routeUrl.


Type Definitions

type MiniAppUpdateStrategy = 'auto' | 'manual';

type MiniAppResult = {
  success: boolean;
  appId: string;
  mode?: string;
};

type MiniAppUpdateInfo = {
  appId: string;
  currentVersion?: string | null;
  latestVersion?: string | null;
  hasUpdate: boolean;
  updateStrategy: 'auto' | 'manual';
  mode?: string | null;
  sourceUrl?: string | null;
};

type NebulaApiInvokeResult<T = unknown> =
  | { ok: true; data: T }
  | { ok: false; error: NebulaApiError };

type NebulaApiError = {
  code: string;
  message: string;
  details?: Record<string, unknown>;
};

type NebulaHostCapabilityDescriptor = {
  supported: boolean;
  version: string;
};

type NebulaHostCapabilityMap = Record<string, NebulaHostCapabilityDescriptor>;

type PageLifecycleEvent = {
  appId: string;
  instanceId: string;
  routePath?: string;
  type: 'show' | 'hide' | 'unload';
};

type NebulaPageStyle = {
  backgroundColor?: string;
  navigationBarBackgroundColor?: string;
  navigationBarTextColor?: string;
  navigationBarTitleText?: string;
  navigationStyle?: 'default' | 'custom';
  visualEffectInBackground?: 'blur' | 'none';
};

type NavigationResult = {
  errMsg: string;
};

type HostVisibilityResult = {
  success: boolean;
  token?: string | null;
};

type ServerBaseURLResult = {
  serverBaseURL?: string | null;
};

Native Module

@nebula-rn/sdk communicates with the native layer via NebulaNativeModule.

Synchronous methods: getDeviceInfo()

Asynchronous methods: All other native calls return Promises.

Platform configuration constants:

ConfigurationiOS DefaultDescription
Max concurrent miniapps3Maximum number of miniapps in memory simultaneously.
Max page stack depth10Maximum number of pages in a single miniapp's stack.

Default timeouts:

OperationTimeout
invokeHostApi()15000ms
getCapabilities()15000ms (fixed)
getHostApiDescriptions()15000ms (configurable)
Network download (Android)Connect 15s + read 15s
Network download (iOS)URLSession default

Error code summary:

Error codePlatformContext
NO_ACTIVITYAndroidActivity not found when opening/presenting Modal
NO_ROOT_VCiOSRoot view controller not found when opening
OPEN_ERRORAllRuntime error opening miniapp
PRELOAD_ERRORAllRuntime error during preloading
INSTALL_ERRORAllDownload or parsing failed
INVALID_SERVER_URLAllURL format validation failed
INVALID_MANIFESTAllManifest JSON parsing failed
INVALID_MODEiOSRuntime mode string invalid
UNSUPPORTED_APIAllAPI not registered or not supported
INTERNAL_ERRORAllHandler execution exception
PRESENT_HOST_MODAL_ERRORAndroidFailed to present Modal

On this page

Host InitializationNebulaAPI.wrap(options)NebulaAPI.startApiServer()NebulaAPI.stopApiServer()NebulaAPI.setServerBaseURL(serverBaseURL)NebulaAPI.getServerBaseURL()Miniapp InstallationNebulaAPI.installMiniApp(appId, bundleURL)NebulaAPI.installMiniAppWithBundleURL(appId, bundleURL, connectToURLMetroServer?)Opening and Preloading MiniappsNebulaAPI.openMiniApp(appId, initialProps?, versionType?)NebulaAPI.openMiniAppWithBundleURL(appId, bundleURL, initialProps?, connectToURLMetroServer?)NebulaAPI.preloadMiniApp(appId)NebulaAPI.preloadMiniAppWithBundleURL(appId, bundleURL, connectToURLMetroServer?)Version and UpdateNebulaAPI.checkMiniAppUpdate(appId)NebulaAPI.applyMiniAppUpdate(appId)Miniapp InformationNebulaAPI.getInstalledMiniAppInfo(appId)NebulaAPI.getInstalledMiniApps()NavigationMiniAppAPI.navigateTo(url)MiniAppAPI.redirectTo(url)MiniAppAPI.reLaunch(url)MiniAppAPI.navigateBack(delta?)Page StylingMiniAppAPI.setPageStyle(style)MiniAppAPI.setNavigationBarTitle(title)MiniAppAPI.setNavigationBarColor(options)Device and AppMiniAppAPI.getAppId()MiniAppAPI.getSandboxPath()MiniAppAPI.getDeviceInfo()MiniAppAPI.showToast(title)Host CommunicationMiniAppAPI.invokeHostApi(apiName, payload?, version?, timeoutMs?)MiniAppAPI.postMessageToHost(message)MiniAppAPI.onHostMessage(listener)NebulaAPI.postMessageToMiniApp(appId, message)NebulaAPI.addMiniAppMessageListener(listener)Capability DetectionMiniAppAPI.getCapabilities()MiniAppAPI.isSupported(apiName, minimumVersion?)MiniAppAPI.getHostApiDescriptions(timeoutMs?)Host Visibility and ModalMiniAppAPI.bringHostToFront()MiniAppAPI.restoreMiniApp(token?)MiniAppAPI.presentHostModal(moduleName, props?)MiniAppAPI.dismissHostModal()Page LifecycleMiniAppAPI.onPageLifecycle(listener)Lifecycle HooksusePageOnLoad(callback)usePageOnShow(callback)usePageOnReady(callback)usePageOnHide(callback)usePageOnUnload(callback)Route RegistrationNebulaAPI.registerRoutes(appId, routes)NebulaAPI.registerManifest(appId, manifest)Host API RegistrationNebulaAPI.registerApiHandler(apiName, handler)NebulaAPI.unregisterApiHandler(apiName)NebulaAPI.getRegisteredCapabilities()NebulaAPI.getRegisteredApiDescriptions()Host Feature FactoriescreateHostApiFeature(options)createHostModalApiFeature(options)createHostModalChannel()Helper FunctionscreateHostApiSuccess(data)createHostApiFailure(code, message)definePageConfig(config)createMiniAppPage(Component)Type DefinitionsNative Module