@laiye_packages/uci
v1.1.4
Published
A comprehensive utility library for frontend applications with HTTP client, storage, i18n, crypto, logger, and OpenTelemetry support
Downloads
1,084
Maintainers
Readme
UCI - 统一客户端基础设施
UCI 提供企业级应用核心功能:应用管理、认证、API、国际化、权限、加解密。
主要导出
// 应用管理
import { LYBaseApp, LYOrganizationApp, ORGANIZATION_APP_NAME } from '@monorepo/uci';
// 会话
import { LYSession } from '@monorepo/uci';
// 加解密
import { crypto } from '@monorepo/uci';
// 类型
import type { LYUserResponse, LYRoleItem, LYListResponse } from '@monorepo/uci';核心用法
获取 App 实例
// 获取你自己的 app(组件外使用)
const app = LYBaseApp.get('apa');
// 获取内置的 organization app
const orgApp = LYBaseApp.get<LYOrganizationApp>(ORGANIZATION_APP_NAME);获取用户信息
const session = LYSession.get();
console.log(session?.user_id, session?.display_name);调用 API
// 使用你的 app 的 httpClient
const httpClient = LYBaseApp.get('apa').httpClient;
const response = await httpClient.post('/api/endpoint', data);
// 使用 organization app 的 API
const orgApp = LYBaseApp.get<LYOrganizationApp>(ORGANIZATION_APP_NAME);
const users = await orgApp.userApi.query({ offset: 0, size: 20 });
const roles = await orgApp.permissionApi.getRoles({ offset: 0, size: 20 });
const layout = await orgApp.getLayout();退出登录
const orgApp = LYBaseApp.get<LYOrganizationApp>(ORGANIZATION_APP_NAME);
orgApp.getAuthorizer().signout({ redirect_uri: window.location.href });检查权限
const session = LYSession.get();
const permission = session?.permissions?.['organization'];
if (permission?.codes.includes('user_manage')) { /* 有权限 */ }加解密(国密算法)
// 通过 app 实例获取 crypto
const app = LYBaseApp.get('yourAppName');
// 哈希(SM3)
const hash = app.crypto.hash('数据', '可选密钥', 1);
// 对称加密/解密(SM4)
const encrypted = app.crypto.encryptSymmetric('敏感数据', 'iv', 'key');
const decrypted = app.crypto.decryptSymmetric(encrypted, 'iv', 'key');
// 非对称加密/解密(SM2)
const asymEncrypted = app.crypto.encryptAsymmetric('数据', '公钥');
const asymDecrypted = app.crypto.decryptAsymmetric(asymEncrypted, '私钥');
// 签名/验证
const signature = app.crypto.signature('数据', '私钥');
const isValid = app.crypto.verify('数据', signature, '公钥');详细使用指南请查看 PROJECT_GUIDE.md。
