@sdkwork/backend-sdk
v1.0.10
Published
sdkwork-backend-sdk
Readme
sdkwork-backend-sdk
Professional TypeScript SDK for SDKWork API.
Installation
npm install @sdkwork/backend-sdk
# or
yarn add @sdkwork/backend-sdk
# or
pnpm add @sdkwork/backend-sdkQuick Start
import { SdkworkBackendClient } from '@sdkwork/backend-sdk';
const client = new SdkworkBackendClient({
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.user.getProfile();Authentication Modes (Mutually Exclusive)
Choose exactly one mode for the same client instance.
Mode A: API Key
const client = new SdkworkBackendClient({ baseUrl: 'http://localhost:8080' });
client.setApiKey('your-api-key');
// Sends: Authorization: Bearer <apiKey>Mode B: Dual Token
const client = new SdkworkBackendClient({ 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 { SdkworkBackendClient } from '@sdkwork/backend-sdk';
const client = new SdkworkBackendClient({
baseUrl: 'http://localhost:8080',
timeout: 30000, // Request timeout in ms
headers: { // Custom headers
'X-Custom-Header': 'value',
},
});API Modules
client.workspace- workspace APIclient.vote- vote APIclient.voice- voice APIclient.visitHistory- visit_history APIclient.vip- vip APIclient.video- video APIclient.user- user APIclient.usage- usage APIclient.trade- trade APIclient.tool- tool APIclient.tenant- tenant APIclient.table- table APIclient.sku- sku APIclient.skill- skill APIclient.shortUrl- short_url APIclient.shop- shop APIclient.share- share APIclient.sharding- sharding APIclient.security- security APIclient.schema- schema APIclient.role- role APIclient.record- record APIclient.rbac- rbac APIclient.prompt- prompt APIclient.project- project APIclient.product- product APIclient.ppt- ppt APIclient.permission- permission APIclient.partner- partner APIclient.participant- participant APIclient.oss- oss APIclient.organization- organization APIclient.organizationMember- organization_member APIclient.notification- notification APIclient.note- note APIclient.news- news APIclient.net- net APIclient.music- music APIclient.model- model APIclient.message- message APIclient.member- member APIclient.knowledgeBase- knowledge_base APIclient.invitation- invitation APIclient.image- image APIclient.im- im APIclient.generation- generation APIclient.game- game APIclient.file- file APIclient.feed- feed APIclient.feedback- feedback APIclient.favorite- favorite APIclient.disk- disk APIclient.detail- detail APIclient.department- department APIclient.datasource- datasource APIclient.coupon- coupon APIclient.conversation- conversation APIclient.contentWriting- content_writing APIclient.comment- comment APIclient.column- column APIclient.collection- collection APIclient.collectionItem- collection_item APIclient.chat- chat APIclient.character- character APIclient.channel- channel APIclient.category- category APIclient.card- card APIclient.attribute- attribute APIclient.article- article APIclient.app- app APIclient.apikey- apikey APIclient.agent- agent APIclient.account- account APIclient.system- system APIclient.search- search APIclient.auth- auth API
Usage Examples
workspace
// Get all workspaces
const body = {} as any;
const result = await client.workspace.listAllEntities(body);vote
// Get all content votes
const body = {} as any;
const result = await client.vote.listAllEntities(body);voice
// Get all voice speakers
const body = {} as any;
const result = await client.voice.listAllEntities(body);visit_history
// List All Visit Histories
const body = {} as any;
const result = await client.visitHistory.listAllEntities(body);vip
// Get a VIP user by ID
const result = await client.vip.getCurrentUser();video
// Get all videos
const body = {} as any;
const result = await client.video.listAllEntities(body);user
// Get current user profile
const result = await client.user.getProfile();usage
// Get all usage records
const body = {} as any;
const result = await client.usage.listAllEntities(body);trade
// Get all shopping carts
const body = {} as any;
const result = await client.trade.createListAllEntities(body);tool
// Get all AI tools
const body = {} as any;
const result = await client.tool.listAllEntities(body);tenant
// Get all tenants
const body = {} as any;
const result = await client.tenant.listAllEntities(body);table
// Get all database tables
const body = {} as any;
const result = await client.table.listAllEntities(body);sku
// Get all SKUs
const body = {} as any;
const result = await client.sku.listAllEntities(body);skill
// Query all skill packages
const body = {} as any;
const result = await client.skill.createListAll(body);short_url
// Get all short URLs
const body = {} as any;
const result = await client.shortUrl.listAllEntities(body);shop
// Get all shops
const body = {} as any;
const result = await client.shop.listAllEntities(body);share
// Get all visit records
const body = {} as any;
const result = await client.share.createListAllEntities(body);sharding
// List All Sharding Keys
const body = {} as any;
const result = await client.sharding.listAllEntities(body);security
// List all policies
const body = {} as any;
const result = await client.security.listAllEntities(body);schema
// Get all database schemas
const body = {} as any;
const result = await client.schema.listAllEntities(body);role
// Get all role-permission associations
const body = {} as any;
const result = await client.role.createListAllEntities(body);record
// Get all invocation records
const body = {} as any;
const result = await client.record.listAllEntities(body);rbac
// Get all user-role relationships
const body = {} as any;
const result = await client.rbac.listAllEntities(body);prompt
// Get all AI prompts
const body = {} as any;
const result = await client.prompt.listAllEntities(body);project
// Get all projects
const body = {} as any;
const result = await client.project.listAllEntities(body);product
// Get a product by ID
const params = {} as Record<string, any>;
const result = await client.product.getDetail(params);ppt
// Get all PPT template slides
const body = {} as any;
const result = await client.ppt.createListAllEntities(body);permission
// List all permissions
const body = {} as any;
const result = await client.permission.listAllEntities(body);partner
// Get all partners
const body = {} as any;
const result = await client.partner.listAllEntities(body);participant
// Get all chat participants
const body = {} as any;
const result = await client.participant.listAllEntities(body);oss
// List files
const params = {} as Record<string, any>;
const result = await client.oss.listFiles(params);organization
// Get all positions
const body = {} as any;
const result = await client.organization.createListAllEntities(body);organization_member
// Get all organization members
const body = {} as any;
const result = await client.organizationMember.listAllEntities(body);notification
// Get all notifications
const body = {} as any;
const result = await client.notification.listAllEntities(body);note
// List all notes
const result = await client.note.listAll();news
// Get all news
const body = {} as any;
const result = await client.news.listAllEntities(body);net
// 获取所有域名
const body = {} as any;
const result = await client.net.createListAllEntities(body);music
// Get all music records
const body = {} as any;
const result = await client.music.listAllEntities(body);model
// Get all AI model prices
const body = {} as any;
const result = await client.model.createListAllEntities(body);message
// Get all chat messages
const body = {} as any;
const result = await client.message.listAllEntities(body);member
// Get all member levels
const body = {} as any;
const result = await client.member.createListAllEntities(body);knowledge_base
// List files
const params = {} as Record<string, any>;
const result = await client.knowledgeBase.listFiles(params);invitation
// Get all invitation relations
const body = {} as any;
const result = await client.invitation.createListAllEntities(body);image
// Get all images
const body = {} as any;
const result = await client.image.listAllEntities(body);im
// Get all chat groups
const body = {} as any;
const result = await client.im.listAllEntities(body);generation
// Get all AI generation records
const body = {} as any;
const result = await client.generation.createListAllEntities(body);game
// List growth reward claims
const body = {} as any;
const result = await client.game.listGrowthRewardClaims(body);file
// Get all file parts
const body = {} as any;
const result = await client.file.createListAllEntities(body);feed
// Get all feeds entries
const body = {} as any;
const result = await client.feed.listAllEntities(body);feedback
// Get all feedback records
const body = {} as any;
const result = await client.feedback.listAllEntities(body);favorite
// Get all favorites
const body = {} as any;
const result = await client.favorite.listAllEntities(body);disk
// List files
const params = {} as Record<string, any>;
const result = await client.disk.getListFiles(params);detail
// Get all detail contents
const body = {} as any;
const result = await client.detail.listAllEntities(body);department
// Get all departments
const body = {} as any;
const result = await client.department.listAllEntities(body);datasource
// Get all data sources
const body = {} as any;
const result = await client.datasource.listAllEntities(body);coupon
// Get all coupon templates
const body = {} as any;
const result = await client.coupon.createListAllEntities(body);conversation
// Get all open conversations
const body = {} as any;
const result = await client.conversation.open(body);content_writing
// Get all contents
const result = await client.contentWriting.getAllContents();comment
// Get all comments
const body = {} as any;
const result = await client.comment.listAllEntities(body);column
// Get all columns
const body = {} as any;
const result = await client.column.listAllEntities(body);collection
// Get all collections
const body = {} as any;
const result = await client.collection.listAllEntities(body);collection_item
// Get all collection items
const body = {} as any;
const result = await client.collectionItem.listAllEntities(body);chat
// Get all chat messages
const body = {} as any;
const result = await client.chat.createListAllEntities(body);character
// Get all characters
const body = {} as any;
const result = await client.character.listAllEntities(body);channel
// Get all channel resources
const body = {} as any;
const result = await client.channel.createListAllEntities(body);category
// Get all categories
const body = {} as any;
const result = await client.category.listAllEntities(body);card
// Get all card templates
const body = {} as any;
const result = await client.card.createListAllEntities(body);attribute
// Get all attributes
const body = {} as any;
const result = await client.attribute.listAllEntities(body);article
// Get all AI articles
const body = {} as any;
const result = await client.article.listAllEntities(body);app
// Get app info
const result = await client.app.getAppInfo();apikey
// List API keys for current user
const result = await client.apikey.listMyApiKeys();agent
// Get all agent-tool relationships
const body = {} as any;
const result = await client.agent.createListAllEntities(body);account
// Get points-to-cash rate
const result = await client.account.getPointsToCashRate();system
// Query invoice page
const params = {} as Record<string, any>;
const result = await client.system.listByPage(params);search
// POST /backend/v3/api/search/chat/stop
const params = {} as Record<string, any>;
const headers = {} as Record<string, string>;
const result = await client.search.stop(params, headers);auth
// Get roles
const result = await client.auth.getRoles();Error Handling
import { SdkworkBackendClient, NetworkError, TimeoutError, AuthenticationError } from '@sdkwork/backend-sdk';
try {
const result = await client.user.getProfile();
} 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
