@kelvininc/js-client-sdk
v8.16.0
Published
Kelvin SDK Client creates a communication layer that abstract all business logic
Readme
Kelvin SDK Client - JavaScript Overview
Kelvin SDK Client abstracts all the communication layer with the KICS Platform, so the developers can be more focused on building what provides value for their applications - the user experience (UX) and business logic. This approach increases developer productivity and aims to enable higher quality apps by leveraging the server communication with this library.
Supported Platforms
We currently support the following JavaScript platforms:
Kelvin SDK Client API Documentation
You can find the full Client API reference here.
Kelvin Resource Name (KRN) Parsing
The KRN parser provides multiple parsing options optimized for different use cases, with significant performance improvements (3-308x speedup) through caching and specialized parsing.
General KRN Parsing
Parse any KRN using the general parser with automatic optimizations:
const textToParse = 'krn:asset:test';
const result = KvKRNParser.parse(textToParse);If the krn is valid, the expected result should return the content of the resource asset.
export type KrnParseSuccessResult<T> = {
parseState: EKrnParseState.ValidKRN;
resource: EKrnResource;
resourceContent: T;
};Where T is from type IAssetKrnResource, represented by:
export interface IAssetKrnResource {
name: string;
}High-Performance Specialized Parsing
For maximum performance when you know the KRN type, use specialized resource parsers:
import { AppKRN, AssetKRN, UserKRN } from '@kelvininc/js-client-sdk';
// Direct parsing - up to 308x faster for known resource types
const appResult = AppKRN.parse('krn:app:my-app');
const assetResult = AssetKRN.parse('krn:asset:sensor-001');
const userResult = UserKRN.parse('krn:user:[email protected]');
// Direct KRN creation
const appKrn = AppKRN.build({ app: 'my-app' });
const assetKrn = AssetKRN.build({ asset: 'sensor-001' });Available specialized parsers:
ActionKRN,AppKRN,AppParameterKRN,AppVersionKRNAssetKRN,AssetCustomActionKRN,AssetDatastreamKRN,AssetParameterKRN,AssetTypeKRNDatastreamKRN,JobKRN,RecommendationKRN,ScheduleKRNServiceAccountKRN,TaskKRN,UserKRN,WorkloadKRN,WorkloadAppVersionKRN
Performance Features
- Automatic Caching: Frequently parsed KRNs are cached for 3-6x speedup
- Fast Path Detection: Common patterns are automatically detected and use optimized parsing
- Memory Management: Built-in cache size limits prevent memory leaks
- Type Safety: Full TypeScript support with proper resource typing
// Clear cache if needed (useful for long-running applications)
KvKRNParser.clearCache();
// Check cache statistics
console.log('Cache size:', KvKRNParser.getCacheSize());Error Handling
If the krn is invalid, the result is going to be represented by the type:
export type IKrnParseError = {
parseState: EKrnParseState.InvalidKRN;
errorMessage: string;
};Both general parsing and specialized parsing provide consistent error messages and validation.
Recommended approach:
// Use specialized parsers instead
const appKrn = AppKRN.build({ app: 'api-name' });
const userKrn = UserKRN.build({ user: '[email protected]' });