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
| Namespace | Description | Common methods |
|---|---|---|
| Router | Page routing and navigation | navigateTo navigateBack reLaunch |
| Network | Network requests | request request.get request.post |
| Storage | Local data storage | setStorage getStorage removeStorage |
| UI | UI interaction and feedback | showToast showDialog showLoading |
| Lifecycle | Page lifecycle | onLoad onShow onHide onUnload |
| Clipboard | Clipboard | setClipboard getClipboard |
| Device | Device capabilities | getSystemInfo scanCode getLocation |
| Auth | Authentication and authorization | requestSSOLogin getUserProfile |
| Analytics | Analytics | recordEvent enableAutoAnalytics |
| Vehicle | Vehicle information | getCurrentVehicleProfile getCurrentVehicleStatus |
| Map | Map operations | createMapContext |
| Component | Component control | createVideoContext createSelectorQuery |
| App | App-level APIs | getLaunchOptionsSync onAppShow |
Calling conventions
All APIs support both Promise and Callback calling styles.
Promise style (recommended)
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'