Registry / devops / rest-client-sdk

rest-client-sdk

JSON →
library7.2.3jsnpmunverified

A JavaScript SDK generator that avoids custom API client implementations by letting you define entity mappings, attributes, and relations declaratively. Version 7.2.3 is current; the project has a slow release cadence with occasional minor bumps. Integrates token management (OAuth refresh), UnitOfWork for batch operations, and storage adapters (localforage, AsyncStorage). Ships TypeScript definitions. Differentiates from generic clients (Axios, Fetch) by providing a metadata-driven ORM-like layer over REST endpoints.

npm install rest-client-sdk
INSTALL
IMPORT
SIG · REST-CLIENT-SDK
R
rest-client-sdk
devopsjavascriptv7.2.3
harness data pending
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));
Debug
Known issues
breakingPackage converted to ESM-only in v7.0.0. CommonJS require() will not work.
fix
Switch to import syntax. If you must use require, use dynamic import() or stick to v6.x.
affects: >=7.0.0
deprecatedMapping constructor argument changed: in v7, the prefix is passed to the Mapping constructor, not the pathRoot of each ClassMetadata. Older usage with pathRoot as second argument to ClassMetadata will break.
fix
Pass the API prefix to new Mapping('/prefix') and omit the second argument to ClassMetadata (or use it as the endpoint path).
affects: >=7.0.0
gotchaTokenStorage requires storage.getItem and storage.setItem to return Promises. Passing synchronous storage (like raw localStorage) will fail silently.
fix
Wrap synchronous storage in a Promise-based adapter, e.g., use localforage or a custom wrapper.
affects: all
gotchaUnitOfWork uses a proxy that may not support all operations (e.g., Map/Set as entity properties). Serialization can fail for non-plain objects.
fix
Disable unitOfWork if you encounter 'Object could not be cloned' errors or use plain JSON-serializable entities.
affects: all
breakingRelation constants changed from static strings to numeric enums internally. Relation.ONE_TO_MANY etc. are still available as static getters, but direct string comparison will fail.
fix
Use Relation.ONE_TO_MANY, Relation.MANY_TO_ONE, or Relation.MANY_TO_MANY consistently.
affects: >=7.0.0
gotchaToken generator must return an object with an access_token key. Refreshed token also must contain access_token. Failure to do so will cause 'Invalid token' errors.
fix
Ensure generateToken and refreshToken return { access_token: string }.
affects: all
Errors
Common errors & fixes
TypeError: rest_client_sdk_1.default is not a constructor
Using CommonJS require() on ESM-only package (v7+).
fix
Replace 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.
fix
Use import { Mapping } from 'rest-client-sdk'.
TokenStorage is not a constructor
Importing TokenStorage as a default export, but it is a named export.
fix
Use import { TokenStorage } from 'rest-client-sdk'.
Invalid token: access_token missing
Token generator function returned an object without an access_token property.
fix
Return { 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).
fix
Disable unitOfWork in config (unitOfWorkEnabled: false) or ensure all entity properties are plain JSON types.
Upgrade
Version history
7.2.3latest on npm
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.
Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources