@paritydeals/js-sdk
is a lightweight, plain TypeScript library designed for interacting with the ParityDeals entitlement service. It allows you to:
- Fetch all feature entitlements for a specific organization and customer.
- Cache these entitlements client-side for efficient and repeated access.
- Check if a user has access to a particular feature.
- Retrieve specific entitlement details, including boolean flags, numeric configurations, and metered usage data.
- Manually refresh entitlement data from the server.
If you are using React, you can use the React SDK instead.
Installation
Install the SDK using your preferred package manager or include it directly via CDN.Basic Usage
Get started with the SDK in just a few lines of code.API Reference
Complete documentation of all SDK methods and configuration options.Initialization
Create and configure your SDK instance with the required parameters.Options
Option | Type | Description | |
---|---|---|---|
customerId | string | Unique identifier for the customer | |
accessToken | string | - | Authentication token for API requests |
environment | sandbox|production | ’production’ | The environment to use. If you want to use the sandbox, you must provide this. |
initializeAndFetch | boolean | true | Automatically fetch entitlements on initialization |
onError | (error: Error) => void | - | Error callback function |
Core Methods
hasAccess(featureId: string): boolean
Check if the user has access to a specific feature.
getEntitlement<T>(featureId: string, type: T['type']): T | null
Get detailed entitlement information for a specific feature.
getAllEntitlements(): EntitlementMap | null
Get all cached entitlements.
fetchAllEntitlements(forceRefresh?: boolean): Promise<EntitlementMap>
Manually fetch or refresh entitlements from the server.
isLoading(): boolean
Check if entitlements are currently being fetched.
getLastError(): Error | null
Get the last error that occurred during entitlement fetching.
clearCache(): void
Clear the cached entitlements.
Entitlement Types
Different types of entitlements supported by the SDK.Examples
Real-world usage patterns and common implementation scenarios.Feature Gating
Control access to features based on user entitlements.Usage-Based Features
Implement usage limits and quota management.Configuration-Based Features
Apply dynamic configuration based on user entitlements.Error Handling
Robust error handling for production applications.Custom API Request Service
Integrate with your existing HTTP client or add custom logic.TypeScript Support
Full TypeScript support with comprehensive type definitions. The SDK is written in TypeScript and provides full type safety:Advanced Configuration
Advanced options for customizing SDK behavior and API integration.API Configuration
Configure API request behavior and retry logic.Custom Error Handling
Implement sophisticated error handling and recovery strategies.Advanced Options
Additional configuration options for specialized use cases. Default values are:Option | Type | Description |
---|---|---|
apiUrl | string | Base URL for the API |
entitlementsPath | string | Path for fetching entitlements |
apiConfig.maxRetries | number | Maximum number of retries for API requests |
apiConfig.timeout | number | Timeout for API requests in milliseconds |
apiConfig.backoffBaseDelay | number | Base delay for exponential backoff strategy |
Using the Sandbox
If you want to use the sandbox, you need to set theenvironment
option to sandbox
in the init
function.