
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@skyfox2000/microbase
Advanced tools
这是一个专为微前端架构设计的基础类型库,提供了微前端应用间通信、数据类型定义、路由管理和模块加载等核心功能。该库是微前端生态系统的基础组件,为主应用和子应用之间的协作提供标准化的接口和数据结构。
npm install -S @skyfox2000/microbase
import {
isMicroApp,
initMainAppData,
mainAppApis,
AppInfo,
UserInfo
} from '@skyfox2000/microbase';
// 检测是否在微应用环境中运行
if (isMicroApp()) {
// 初始化主应用数据
initMainAppData();
// 使用主应用提供的API
if (mainAppApis.value?.getUserInfo) {
const userInfo = mainAppApis.value.getUserInfo();
console.log('当前用户:', userInfo);
}
}
isMicroApp(): boolean检测当前应用是否运行在微前端环境中
if (isMicroApp()) {
console.log('运行在微前端环境');
}
isBaseMicroApp(): boolean检测当前应用是否为微前端基座应用
if (isBaseMicroApp()) {
console.log('当前是基座应用');
}
initMainAppData(): void初始化主应用数据,建立与主应用的通信连接
// 在微应用启动时调用
initMainAppData();
mainAppApis: Ref<MainOpenApis | undefined>主应用开放的API接口集合
// 获取用户信息
const userInfo = mainAppApis.value?.getUserInfo?.();
// 路由跳转
mainAppApis.value?.mainAppPush?.('/target-path');
// 用户登录
await mainAppApis.value?.userLogin?.(loginInfo);
mainAppEvents: Ref<MainOpenEvents | undefined>主应用开放的事件监听接口
// 监听设置变更事件
mainAppEvents.value?.onSettingChanged?.();
EnvConfig: { [key: string]: string }统一的环境变量配置对象
initEnv(metaEnv: ImportMetaEnv): void初始化环境变量配置
import { initEnv } from '@skyfox2000/microbase';
// 在应用启动时初始化环境变量
initEnv(import.meta.env);
combineParams(params: any): any参数组合和处理工具函数
import { combineParams } from '@skyfox2000/microbase';
const combinedParams = combineParams({
param1: 'value1',
param2: 'value2'
});
LoaderRouter动态路由加载器,支持路由的动态注册和管理
import { LoaderRouter } from '@skyfox2000/microbase';
// 使用路由加载器
const router = new LoaderRouter(routeConfig);
import {
loadModule,
initModuleLoader,
moduleAttrs,
moduleUrl,
moduleRecords,
moduleCom
} from '@skyfox2000/microbase';
// 初始化模块加载器
initModuleLoader();
// 动态加载模块
await loadModule('module-name');
interface AppInfo {
readonly Id: string; // 应用唯一标识
readonly Name: string; // 应用名称
readonly AppCode: string; // 应用编码(路由前缀)
readonly Version: string; // 版本号
readonly Icon: string; // 应用图标
readonly Source: AppSource; // 应用来源
readonly Action: AppAction; // 应用动作类型
readonly Host: string; // 应用加载地址
readonly Enabled: boolean | number; // 启用状态
Page?: string; // 默认页面
Default?: boolean; // 是否默认应用
Description?: string; // 应用描述
}
interface UserInfo {
readonly Id: string; // 用户ID
readonly Name: string; // 用户名称
readonly Code: string; // 用户编码
readonly TenantId: string | null; // 租户ID
readonly UserLevel: string; // 用户级别
readonly Roles?: string[]; // 角色列表
readonly Permissions?: string[]; // 权限列表
}
interface LoginInfo {
UserName: string; // 用户名
UserPass: string; // 密码
UserInfo?: UserInfo; // 用户信息
readonly token?: string; // 访问令牌
readonly refreshToken?: string; // 刷新令牌
}
interface MainOpenApis {
getHostInfo: () => HostInfo; // 获取主机信息
getAppInfo?: () => AppInfo; // 获取应用信息
userRegister?: () => void; // 用户注册
userLogin?: (loginInfo: LoginInfo) => Promise<ApiResponse<LoginInfo> | void>; // 用户登录
userLogout?: () => Promise<ApiResponse<any> | void>; // 用户登出
getToken?: () => string; // 获取授权令牌
getUserInfo?: () => UserInfo; // 获取用户信息
getSettingInfo?: () => SettingInfo; // 获取设置信息
mainAppPush?: (subPath: string) => void; // 路由跳转
}
enum AppSource {
Market = "Market", // 从市场安装
Manual = "Manual" // 手动输入
}
enum AppAction {
App = "App", // 应用模式加载
MenuApp = "MenuApp", // 托管应用模式加载
Link = "Link", // 链接方式打开
Iframe = "Iframe" // Iframe内嵌方式打开
}
该库使用 Vite 进行构建,支持:
// 在主应用中提供API给子应用
const mainApis: MainOpenApis = {
getHostInfo: () => hostInfo,
getUserInfo: () => currentUser,
mainAppPush: (path) => router.push(path)
};
// 传递给子应用
microApp.setData('child-app', { MainApis: mainApis });
// 在子应用中接收主应用数据
if (isMicroApp()) {
initMainAppData();
// 使用主应用提供的功能
const userInfo = mainAppApis.value?.getUserInfo?.();
if (userInfo) {
// 处理用户信息
}
}
// 在独立应用中也可以使用类型定义
import type { AppInfo, UserInfo } from '@skyfox2000/microbase';
const appConfig: AppInfo = {
Id: 'app-001',
Name: '我的应用',
AppCode: 'my-app',
// ... 其他配置
};
该库是微前端生态系统的核心基础库,为构建大型企业级微前端应用提供坚实的技术基础。
FAQs
We found that @skyfox2000/microbase demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.