Skip to content

SDK Overview

mini-sdk is the core SDK of MiniDev Studio, providing all client-side APIs required for the mini program runtime. Developers invoke all capabilities through the default-exported woo object.

Installation and import

The SDK is built into the MiniDev Studio runtime; no additional installation is required. Import it directly:

ts
import woo from 'mini-sdk'

// 或按命名空间导入
import { router, network, storage, ui, lifecycle } from 'mini-sdk'

API category overview

NamespaceDescriptionCommon methods
RouterPage routing and navigationnavigateTo navigateBack reLaunch
NetworkNetwork requestsrequest request.get request.post
StorageLocal data storagesetStorage getStorage removeStorage
UIUI interaction and feedbackshowToast showDialog showLoading
LifecyclePage lifecycleonLoad onShow onHide onUnload
ClipboardClipboardsetClipboard getClipboard
DeviceDevice capabilitiesgetSystemInfo scanCode getLocation
AuthAuthentication and authorizationrequestSSOLogin getUserProfile
AnalyticsAnalyticsrecordEvent enableAutoAnalytics
VehicleVehicle informationgetCurrentVehicleProfile getCurrentVehicleStatus
MapMap operationscreateMapContext
ComponentComponent controlcreateVideoContext createSelectorQuery
AppApp-level APIsgetLaunchOptionsSync onAppShow

Calling conventions

All APIs support both Promise and Callback calling styles.

ts
try {
  const result = await woo.getStorage({ key: 'userToken' })
  console.log(result.data)
} catch (err) {
  console.error('获取失败:', err.message)
}

Callback style

ts
woo.getStorage({
  key: 'userToken',
  success(result) {
    console.log(result.data)
  },
  fail(err) {
    console.error('获取失败:', err.message)
  },
  complete() {
    console.log('请求完成')
  },
})

ApiCallbacks type definition

ts
interface ApiCallbacks<T = unknown> {
  success?: (res: T) => void
  fail?: (err: BridgeError) => void
  complete?: () => void
}

Global woo object

woo is a flat object that aggregates methods from all namespaces. The following two forms are equivalent:

ts
// 通过 woo 调用
woo.navigateTo({ url: '/pages/detail/index' })

// 通过命名空间调用
import { router } from 'mini-sdk'
router.navigateTo({ url: '/pages/detail/index' })

Core exports

In addition to API methods, the SDK exports the following core capabilities:

ts
// Bridge 实例与构造器
export { bridge, Bridge } from 'mini-sdk'

// 环境检测
export { detectEnv, isSimulator, isNative } from 'mini-sdk'

// Transport 层
export { createTransport } from 'mini-sdk'

// 错误处理
export { setErrorHandler, getErrorMessage, BridgeErrorCode } from 'mini-sdk'

Type exports

The SDK fully exports all TypeScript types to support type-safe development:

ts
import type {
  BridgeEnvelope,
  BridgeError,
  BridgeType,
  ApiCallbacks,
  NavigateToOptions,
  RequestOptions,
  RequestResult,
  // ... 更多类型
} from 'mini-sdk'

MiniDev Studio — Mini-app Development Toolkit