XuqmGroup-RNSDK/packages/common
XuqmGroup ac7e941744 fix(metro): 取消 withBugCollect 自动链式,避免破坏 Metro 0.84 dev 打包
- common/metro: withXuqmConfig 不再自动链式 withBugCollect(保留 .xuqmconfig 单点同步)。
  customSerializer 方式的 sourcemap 上传在 Metro 0.84 下不可靠:覆盖默认 serializer 后
  无法经 package exports 取回默认序列化,dev 打包会报 "Cannot read properties of undefined (reading 'code')"。
- bugcollect/metro: 还原 customSerializer 回退实现;该插件仅建议显式包裹在已有 serializer 之上。
- sourcemap 上传后续改为 react-native bundle 后独立脚本上传。

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-25 19:04:55 +08:00
..
metro fix(metro): 取消 withBugCollect 自动链式,避免破坏 Metro 0.84 dev 打包 2026-06-25 19:04:55 +08:00
src feat(sdk): 下载相册/进度、XWebView内联config、上报限频采样、版本忽略、push桥接原生sdk-push 2026-06-25 17:50:29 +08:00
package.json fix(common): 对齐 @szyx-mobile useRequest 行为并修复 POST body 丢失 2026-06-20 18:26:45 +08:00
README.md docs: 更新 README + 配置文件规范 + 架构总览(BugCollect/withXuqmConfig) 2026-06-18 15:34:48 +08:00
tsconfig.json feat: rn-update 进度回调 + rn-xwebview JSBridge + rn-log v0.1.0 新建 2026-06-16 12:10:28 +08:00

@xuqm/rn-common

XuqmGroup RN SDK 核心模块。负责 SDK 初始化、HTTP 请求、Token 管理、设备信息、XWebView Bridge、API hooks。

安装

yarn add @xuqm/rn-common @react-native-async-storage/async-storage

Peer dependenciesreact >= 18react-native >= 0.76axios >= 1.0.0

初始化

方式 A — 配置文件自动初始化(推荐)

将平台下载的 .xuqmconfig 文件放入 src/assets/config/,然后用 withXuqmConfig Metro 插件自动发现:

// metro.config.js
const { getDefaultConfig } = require('@react-native/metro-config');
const { withXuqmConfig } = require('@xuqm/rn-common/metro');
const baseConfig = getDefaultConfig(__dirname);
module.exports = withXuqmConfig(baseConfig);

SDK 在 import 时自动调用 initWithConfigFile(),App 无需任何 init 代码。

兼容方式:也可手动配置 Babel alias @xuqm/autoinit-config.ts 包装文件。

方式 B — 手动初始化

import { XuqmSDK } from '@xuqm/rn-common'

await XuqmSDK.initialize({ appKey: 'xxx' })               // 公有平台
await XuqmSDK.initialize({ appKey: 'xxx', platformUrl: 'https://xxx' })  // 私有化
await XuqmSDK.awaitInitialization()                        // 等待配置拉取

API

初始化

API 说明
XuqmSDK.initialize(opts) 初始化,拉取平台配置
XuqmSDK.awaitInitialization() 等待异步初始化完成
isInitialized() 检查 SDK 是否就绪
getConfig() 获取已解析的平台配置

用户信息

API 说明
XuqmSDK.setUserInfo(info) 设置用户信息,触发所有子 SDK 登录
XuqmSDK.setUserInfo(null) 登出,触发全局登出
getUserId() 获取当前 userId
getUserInfo() 获取当前用户信息
setUserId(id) 直接设置 userId内部用

HTTP

API 说明
apiRequest(url, options?) 带 Bearer token 的 HTTP 请求
configureHttp(opts) 覆盖 HTTP 基础配置
_getToken() 获取当前 token内部用
_saveToken(token) 保存 token内部用
_clearToken() 清除 token内部用

设备

API 说明
getDeviceId() 获取设备稳定 UUID
getDeviceInfo() 获取设备品牌/型号/系统信息
detectPushVendor() 检测设备推送厂商

XWebView Bridge

API 说明
openXWebView(url, options?) 打开 WebView
setXWebViewController(controller) 设置全局 WebView 控制器
getXWebViewConfig() 获取当前 WebView 配置
XWebViewControl WebView 控制器类

API Hooks

API 说明
useApi(method, url, opts?) React hook带 loading/error 的 API 调用
usePageApi(method, url, opts?) React hook分页 API
useRequest(opts?) React hook通用请求
setGlobalApiErrorHandler(handler) 设置全局 API 错误处理

UI

API 说明
showToast(msg) 显示 toast
showAlert(title, msg) 显示 alert
showConfirm(title, msg) 显示确认对话框
ScaledImage 等比缩放图片组件

Metro 插件

导出 来源 说明
withXuqmConfig @xuqm/rn-common/metro 自动发现 .xuqmconfig 配置文件并注入虚拟模块,推荐方式

常量

常量 说明
DEFAULT_TENANT_PLATFORM_URL 默认公有平台地址
DEFAULT_IM_WS_URL 默认 IM WebSocket 地址