@sdkwork/app-sdk
v1.0.18
Published
sdkwork-app-sdk
Downloads
463
Readme
sdkwork-app-sdk
Professional TypeScript SDK for SDKWork API.
Installation
npm install @sdkwork/app-sdk
# or
yarn add @sdkwork/app-sdk
# or
pnpm add @sdkwork/app-sdkQuick Start
import { SdkworkAppClient } from '@sdkwork/app-sdk';
const client = new SdkworkAppClient({
baseUrl: 'http://localhost:8080',
timeout: 30000,
});
// Mode A: API Key (recommended for server-to-server calls)
client.setApiKey('your-api-key');
// Use the SDK
const result = await client.tenant.getTenantTypes();Authentication Modes (Mutually Exclusive)
Choose exactly one mode for the same client instance.
Mode A: API Key
const client = new SdkworkAppClient({ baseUrl: 'http://localhost:8080' });
client.setApiKey('your-api-key');
// Sends: Authorization: Bearer <apiKey>Mode B: Dual Token
const client = new SdkworkAppClient({ baseUrl: 'http://localhost:8080' });
client.setAuthToken('your-auth-token');
client.setAccessToken('your-access-token');
// Sends:
// Authorization: Bearer <authToken>
// Access-Token: <accessToken>Do not call
setApiKey(...)together withsetAuthToken(...)+setAccessToken(...)on the same client.
Configuration (Non-Auth)
import { SdkworkAppClient } from '@sdkwork/app-sdk';
const client = new SdkworkAppClient({
baseUrl: 'http://localhost:8080',
timeout: 30000, // Request timeout in ms
headers: { // Custom headers
'X-Custom-Header': 'value',
},
});API Modules
client.workspace- workspace APIclient.voiceSpeaker- voice_speaker APIclient.video- video APIclient.user- user APIclient.tool- tool APIclient.tenant- tenant APIclient.social- social APIclient.skill- skill APIclient.shop- shop APIclient.share- share APIclient.setting- setting APIclient.prompt- prompt APIclient.project- project APIclient.product- product APIclient.partner- partner APIclient.notification- notification APIclient.note- note APIclient.news- news APIclient.music- music APIclient.knowledgeBase- knowledge_base APIclient.invoice- invoice APIclient.image- image APIclient.generation- generation APIclient.filesystem- filesystem APIclient.feedback- feedback APIclient.favorite- favorite APIclient.drive- drive APIclient.document- document APIclient.dashboard- dashboard APIclient.collection- collection APIclient.chat- chat APIclient.character- character APIclient.category- category APIclient.cart- cart APIclient.asset- asset APIclient.app- app APIclient.announcement- announcement APIclient.agent- agent APIclient.advert- advert APIclient.wallet- wallet APIclient.vote- vote APIclient.vip- vip APIclient.upload- upload APIclient.search- search APIclient.rtc- rtc APIclient.payment- payment APIclient.organization- organization APIclient.order- order APIclient.ordering- ordering APIclient.model- model APIclient.history- history APIclient.game- game APIclient.feed- feed APIclient.email- email APIclient.currency- currency APIclient.coupon- coupon APIclient.comment- comment APIclient.claw- claw APIclient.billing- billing APIclient.auth- auth APIclient.audit- audit APIclient.analytic- analytic APIclient.activity- activity APIclient.account- account APIclient.abtest- abtest APIclient.skus- skus API
Usage Examples
workspace
// 获取工作空间列表
const result = await client.workspace.listWorkspaces();voice_speaker
// 获取发音人统计
const result = await client.voiceSpeaker.getStatistics();video
// 获取视频统计
const result = await client.video.getVideoStatistics();user
// 获取用户设置
const result = await client.user.getUserSettings();tool
// List my tools
const result = await client.tool.listMine();tenant
// 获取租户类型列表
const result = await client.tenant.getTenantTypes();social
// 获取好友申请列表
const result = await client.social.listFriendRequests();skill
// List skill packages
const result = await client.skill.listPackages();shop
// 获取店铺统计
const result = await client.shop.getStatistics();share
// 获取分享平台配置
const result = await client.share.getSharePlatforms();setting
// 获取界面设置
const result = await client.setting.getUi();prompt
// 获取热门提示语
const params = {} as Record<string, any>;
const result = await client.prompt.getPopularPrompts(params);project
// 最近访问项目
const params = {} as Record<string, any>;
const result = await client.project.listRecentProjects(params);product
// 获取商品分类树
const result = await client.product.getProductCategoryTree();partner
// Get partner statistics
const result = await client.partner.getPartnerStatistics();notification
// Get notification settings
const result = await client.notification.getNotificationSettings();note
// Notes API
const result = await client.note.listFolders();news
// 获取我的新闻
const params = {} as Record<string, any>;
const result = await client.news.getMy(params);music
// 获取音乐统计
const result = await client.music.getMusicStatistics();knowledge_base
// Batch delete knowledge documents
const knowledgeBaseId = 1;
const result = await client.knowledgeBase.batchDeleteKnowledgeDocuments(knowledgeBaseId);invoice
// 获取发票统计
const result = await client.invoice.getInvoiceStatistics();image
// 获取图片统计
const result = await client.image.getImageStatistics();generation
// 获取风格类型列表
const result = await client.generation.getStyleTypes();filesystem
// List disks
const result = await client.filesystem.listDisks();feedback
// 客服信息
const result = await client.feedback.getSupportInfo();favorite
// 收藏夹列表
const result = await client.favorite.listFavoriteFolders();drive
// Clear drive trash
const result = await client.drive.clearTrash();document
// Batch delete documents
const result = await client.document.batchDeleteDocuments();dashboard
// 快捷入口
const result = await client.dashboard.getShortcuts();collection
// 获取合集树
const params = {} as Record<string, any>;
const result = await client.collection.getCollectionTree(params);chat
// 获取会话列表
const params = {} as Record<string, any>;
const result = await client.chat.listSessions(params);character
// 获取热门角色
const params = {} as Record<string, any>;
const result = await client.character.getPopularCharacters(params);category
// 获取分类类型
const result = await client.category.getCategoryTypes();cart
// Get cart items
const result = await client.cart.getCartItems();asset
// 获取文件夹列表
const result = await client.asset.listFolders();app
// Get app statistics
const result = await client.app.getAppStatistics();announcement
// 未读公告
const result = await client.announcement.getUnreadAnnouncements();agent
// List agents
const params = {} as Record<string, any>;
const result = await client.agent.getList(params);advert
// 广告设置
const result = await client.advert.getAdvertSettings();wallet
// Get wallet overview
const result = await client.wallet.getOverview();vote
// 获取我的投票历史
const params = {} as Record<string, any>;
const result = await client.vote.getMyVotes(params);vip
// 获取VIP状态
const result = await client.vip.getVipStatus();upload
// 获取存储使用情况
const result = await client.upload.getStorageUsage();search
// 搜索统计
const result = await client.search.getSearchStatistics();rtc
// List RTC records
const params = {} as Record<string, any>;
const result = await client.rtc.listRecords(params);payment
// Get payment statistics
const result = await client.payment.getPaymentStatistics();organization
// 获取组织统计
const result = await client.organization.getOrganizationStatistics();order
// Get order statistics
const result = await client.order.getOrderStatistics();ordering
// Get menu categories
const result = await client.ordering.getMenuCategories();model
// Get model types
const result = await client.model.getModelTypes();history
// 历史统计
const result = await client.history.getHistoryStatistics();game
// 获取我的荣誉
const params = {} as Record<string, any>;
const result = await client.game.listHonors(params);feed
// Get top feeds
const params = {} as Record<string, any>;
const result = await client.feed.getTopFeeds(params);// Get SaaS managed email account config
const result = await client.email.getAccountConfig();currency
// 获取货币类型列表
const result = await client.currency.getCurrencyTypes();coupon
// 获取优惠券统计
const result = await client.coupon.getStatistics();comment
// 获取我的评论
const params = {} as Record<string, any>;
const result = await client.comment.getMyComments(params);claw
// Get claw bootstrap
const result = await client.claw.bootstrap();billing
// 预扣冻结
const body = {} as any;
const result = await client.billing.prehold(body);auth
// 生成登录二维码
const result = await client.auth.generateQrCode();audit
// 敏感词库
const result = await client.audit.listSensitiveWord();analytic
// 使用统计
const result = await client.analytic.getUserUsageStats();activity
// 获取抽奖列表
const result = await client.activity.listLotteryActivities();account
// Get account summary
const result = await client.account.getAccountSummary();abtest
// 所有特性开关
const result = await client.abtest.listFeatureFlags();skus
// 检查SKU编码是否存在
const params = {} as Record<string, any>;
const result = await client.skus.checkSkuCodeExists(params);Error Handling
import { SdkworkAppClient, NetworkError, TimeoutError, AuthenticationError } from '@sdkwork/app-sdk';
try {
const result = await client.tenant.getTenantTypes();
} catch (error) {
if (error instanceof AuthenticationError) {
console.error('Authentication failed:', error.message);
} else if (error instanceof TimeoutError) {
console.error('Request timed out:', error.message);
} else if (error instanceof NetworkError) {
console.error('Network error:', error.message);
} else {
throw error;
}
}Publishing
This SDK includes cross-platform publish scripts in bin/:
bin/publish-core.mjsbin/publish.shbin/publish.ps1
Check
./bin/publish.sh --action checkPublish
./bin/publish.sh --action publish --channel release.\bin\publish.ps1 --action publish --channel test --dry-runSet
NPM_TOKEN(and optionalNPM_REGISTRY_URL) before release publish.
License
MIT
