Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RestClientSdk
✓ import RestClientSdk from 'rest-client-sdk'
✗ const RestClientSdk = require('rest-client-sdk')
Package is ESM-only since v7. Use default import for the SDK factory.
Mapping
✓ import { Mapping } from 'rest-client-sdk'
✗ import Mapping from 'rest-client-sdk/Mapping'
Mapping is a named export, not a default one.
TokenStorage
✓ import { TokenStorage } from 'rest-client-sdk'
✗ import { TokenStorage } from 'rest-client-sdk/TokenStorage'
TokenStorage is exported from the main package, not a subpath.
ClassMetadata
✓ import { ClassMetadata } from 'rest-client-sdk'
✗ import classMetadata from 'rest-client-sdk'
ClassMetadata is a named export. The package does not export defaults per class.
Attribute
✓ import { Attribute } from 'rest-client-sdk'
✗ import { Attribute } from 'rest-client-sdk/Attribute'
Attribute is exported from the main index.
Relation
✓ import { Relation } from 'rest-client-sdk'
✗ import Relation from 'rest-client-sdk'
Relation is a named export. Its static properties like ONE_TO_MANY are accessed via Relation.ONE_TO_MANY.
Creates a mapping with Product and Category entities, configures token storage via a custom generator and localStorage, then initializes the SDK client and fetches a product list.
import RestClientSdk from 'rest-client-sdk';
import { Mapping, ClassMetadata, Attribute, Relation, TokenStorage } from 'rest-client-sdk';
const mapping = new Mapping('/api');
const productMeta = new ClassMetadata('products', 'products');
productMeta.setAttributeList([
new Attribute('@id', 'id', 'string', true),
new Attribute('name', 'name', 'string', false),
]);
productMeta.setRelationList([
new Relation(Relation.ONE_TO_MANY, 'categories', 'categories', 'categories'),
]);
const categoryMeta = new ClassMetadata('categories', 'categories');
categoryMeta.setAttributeList([
new Attribute('@id', 'id', 'string', true),
new Attribute('name', 'name', 'string', false),
]);
mapping.setMapping([productMeta, categoryMeta]);
const config = {
path: 'api.example.com',
scheme: 'https',
port: 443,
segment: '/v1',
authorizationType: 'Bearer',
useDefaultParameters: true,
unitOfWorkEnabled: true,
};
const tokenStorage = new TokenStorage({
async generateToken() {
return { access_token: 'tok' };
},
async refreshToken() {
return { access_token: 'newtok' };
},
}, globalThis.localStorage);
const client = new RestClientSdk(mapping, config, tokenStorage);
client.getList('products').then(products => console.log(products));
Errors
Common errors & fixes
TypeError: rest_client_sdk_1.default is not a constructor
Using CommonJS require() on ESM-only package (v7+).
fixReplace const RestClientSdk = require('rest-client-sdk') with import RestClientSdk from 'rest-client-sdk'. Cannot find module 'rest-client-sdk/Mapping'
Importing from a subpath that does not exist in v7+; all exports are from the main index.
fixUse import { Mapping } from 'rest-client-sdk'. TokenStorage is not a constructor
Importing TokenStorage as a default export, but it is a named export.
fixUse import { TokenStorage } from 'rest-client-sdk'. Invalid token: access_token missing
Token generator function returned an object without an access_token property.
fixReturn { access_token: 'your-token' } from generateToken and refreshToken. SerializationError: Object could not be cloned
UnitOfWork is enabled and entity contains non-serializable fields (e.g., Date, Map, Set).
fixDisable unitOfWork in config (unitOfWorkEnabled: false) or ensure all entity properties are plain JSON types.
Audit
Dependencies
localforageoptionalDefault storage for token persistence in browser/Node; optional if custom storage is provided.
@react-native-async-storage/async-storageoptionalDefault storage for token persistence in React Native; optional if custom storage is provided.